DataCheckMonopole_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: DataCheckMonopole
3 // Module Type: analyzer
4 // File: DataCheckMonopole_module.cc
5 //
6 // Generated at Thu Mar 10 10:16:17 2016 by Martin Frank using artmod
7 // from cetpkgsupport v1_08_07.
8 ////////////////////////////////////////////////////////////////////////
9 
17 // #include <canvas/Utilities/InputTag.h>
18 #include <art/Utilities/InputTag.h>
19 #include <fhiclcpp/ParameterSet.h>
21 
22 #include "Monopole/Constants.h"
23 #include "RawData/RawTrigger.h"
24 #include "RecoBase/CellHit.h"
26 
27 #include <DAQDataFormats/TriggerDefines.h>
28 
29 #include <TTree.h>
30 
31 #include <map>
32 
33 namespace mono
34 {
36  typedef unsigned long long tdc_t;
37 }
38 
40 {
41 public:
42  explicit DataCheckMonopole(fhicl::ParameterSet const & p);
43 
44  DataCheckMonopole(DataCheckMonopole const &) = delete;
48 
49  void analyze(art::Event const & e) override;
50  void beginSubRun(art::SubRun const & s) override;
51  void endSubRun(art::SubRun const & s) override;
52  void beginJob() override;
53 
54 private:
55  bool farm70_in_configuration() const;
56  void initialize();
57  void tset(std::string const& branch_name, double const& value);
58 
59  uint32_t prescale_max_;
63  std::map<std::string, unsigned> c_;
64 
65  const double branch_default_value_ = -9999;
66  TTree *tree_;
67  std::map<std::string, double> t_;
70 };
71 
72 
73 
75 (std::string const& branch_name, double const& value)
76 {
77  auto it = t_.find(branch_name);
78  if (it == t_.end())
80  << __FILE__ << ":" << __LINE__ << "\n"
81  << "Branch " << branch_name << " does not exist!"
82  << std::endl;
83 
84  it->second = value;
85 }
86 
87 
88 
90  EDAnalyzer(p)
91 {
92  initialize();
93 }
94 
95 
96 
98 {
100  prescale_total_ = 0.0;
103 
104  std::vector<std::string> counter_names =
105  { "subrun_n_events", "subrun_n_events_slowmono", "subrun_n_events_empty",
106  "subrun_n_hits" };
107 
108  for (auto const& name : counter_names)
109  c_[name] = 0;
110 }
111 
112 
113 
115 {
116  tree_ = tfs_->make<TTree>("Subrun", "Data Check Subrun Tree");
117 
118  std::vector<std::string> branch_names =
119  { "run_duration_in_seconds",
120  "run_farm70_in_configuration",
121  "run_n_active_channels",
122  "run_n_active_dcms",
123  "run_n_active_diblocks",
124  "run_n_buffer_nodes",
125  "run_n_subruns",
126  "run_n_triggers",
127  "run_number",
128  "run_partition",
129  "subrun_duration_in_seconds",
130  "subrun_end_in_seconds",
131  "subrun_n_events",
132  "subrun_n_events_empty",
133  "subrun_n_events_slowmono",
134  "subrun_n_hits",
135  "subrun_number",
136  "subrun_prescale_max",
137  "subrun_prescale_mean",
138  "subrun_prescale_total",
139  "subrun_start_in_seconds"
140  };
141 
142  for (auto const& bname : branch_names)
143  tree_->Branch(bname.c_str(), &t_[bname], (bname + "/D").c_str());
144 }
145 
146 
147 
149 {
150  initialize();
151 
152  for (auto & branch : t_)
153  branch.second = branch_default_value_;
154 }
155 
156 
157 
159 {
160  //
161  // Extract Objects from the Event
162  //
163  // Raw Trigger Header
165  e.getByLabel("daq", raw_triggers);
166  if (raw_triggers->size() != 1)
168  << __FILE__ << ":" << __LINE__ << "\n"
169  << "RawTrigger vector has incorrect size: " << raw_triggers->size()
170  << std::endl;
171  auto rt = raw_triggers->front();
172  tdc_t t0 = rt.fTriggerTimingMarker_TimeStart;
173  uint8_t type = rt.fTriggerMask_TriggerType;
174  uint32_t prescale = rt.fTriggerMask_Prescale;
175 
176  // Raw Hits
178  e.getByLabel("daq", hits);
179 
180 
181 
182  //
183  // Analyze
184  //
185  ++c_.at("subrun_n_events");
186 
187  c_.at("subrun_n_hits") += hits->size();
188 
189  if (hits->empty())
190  ++c_.at("subrun_n_events_empty");
191 
192  // offset of 1 between trigger mask decoding and trigID enum
194  ++c_.at("subrun_n_events_slowmono");
195 
196  prescale_total_ += prescale;
197  prescale_max_ = std::max(prescale, prescale_max_);
198 
199  for (auto const& hit : *hits)
200  {
201  if (static_cast<int64_t>(hit.TDC()) + static_cast<int64_t>(t0) < 0)
203  << __FILE__ << ":" << __LINE__
204  << "\nAbsolute TDC is negative!"
205  << "\n\t(relative TDC, event t0) = (" << hit.TDC() << ", " << t0 << ")"
206  << std::endl;
207 
208  tdc_t tdc = static_cast<int64_t>(hit.TDC()) + static_cast<int64_t>(t0);
209  tdc_min_ = std::min(tdc, tdc_min_);
210  tdc_max_ = std::max(tdc, tdc_max_);
211  }
212 }
213 
214 
215 
217 {
218  tset("run_number", s.run());
219  tset("subrun_number", s.subRun());
220 
221  tset("run_duration_in_seconds", rh_->Duration());
222  tset("run_n_subruns", rh_->NSubruns());
223  tset("run_n_active_channels", rh_->NActiveChannels());
224  tset("run_n_active_dcms", rh_->NLiveDCMs());
225  tset("run_n_active_diblocks", rh_->NDiBlocks());
226  tset("run_n_buffer_nodes", rh_->NBNEVBs());
227  tset("run_farm70_in_configuration", farm70_in_configuration());
228  tset("run_n_triggers", rh_->NTriggers());
229  tset("run_partition", rh_->Partition());
230 
231  for (auto const& counter : c_)
232  tset(counter.first, counter.second);
233 
234  tset("subrun_prescale_max", prescale_max_);
235  tset("subrun_prescale_total", prescale_total_);
236 
237  double n_events = c_.at("subrun_n_events");
238  double prescale_mean = 0.0;
239  if (n_events)
240  prescale_mean = prescale_total_ / n_events;
241  tset("subrun_prescale_mean", prescale_mean);
242 
243  double subrun_duration_hits =
245  tset("subrun_duration_in_seconds", subrun_duration_hits);
246  tset("subrun_start_in_seconds", tdc_min_ * Constants::TDC_TICK_S);
247  tset("subrun_end_in_seconds", tdc_max_ * Constants::TDC_TICK_S);
248 
249  tree_->Fill();
250 }
251 
252 
253 
255 {
256  auto nodes = rh_->GetBNEVBList();
257  auto it = std::find_if(nodes.begin(), nodes.end(),
258  [](auto const& node)
259  { return node.appname == "bnevb070"; });
260 
261  if (it != nodes.end())
262  return true;
263 
264  return false;
265 }
266 
267 
268 
T max(const caf::Proxy< T > &a, T b)
const XML_Char * name
Definition: expat.h:151
int NDiBlocks()
gives number of active diblocks only, may be less than 14
Definition: RunHistory.h:394
void tset(std::string const &branch_name, double const &value)
set< int >::iterator it
SubRunNumber_t subRun() const
Definition: SubRun.h:44
Definition: Cluster.h:13
const char * p
Definition: xmltok.h:285
DEFINE_ART_MODULE(TestTMapFile)
std::map< std::string, unsigned > c_
art::ServiceHandle< art::TFileService > tfs_
const XML_Char * s
Definition: expat.h:262
void hits()
Definition: readHits.C:15
void endSubRun(art::SubRun const &s) override
std::map< std::string, double > t_
DataCheckMonopole(fhicl::ParameterSet const &p)
const XML_Char int const XML_Char * value
Definition: expat.h:331
void beginSubRun(art::SubRun const &s) override
std::vector< BNEVB > GetBNEVBList()
Definition: RunHistory.h:398
int Duration()
in units of seconds
Definition: RunHistory.h:389
dictionary nodes
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
static float min(const float a, const float b, const float c)
Definition: absgeo.cxx:45
const double TDC_TICK_S
Definition: Constants.h:12
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
T * make(ARGS...args) const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
Definition: event.h:1
DataCheckMonopole & operator=(DataCheckMonopole const &)=delete
art::ServiceHandle< nova::dbi::RunHistoryService > rh_
unsigned long long tdc_t
T min(const caf::Proxy< T > &a, T b)
void analyze(art::Event const &e) override
Float_t e
Definition: plot.C:35
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:68
int n_events
Definition: test_Tier.py:22
RunNumber_t run() const
Definition: SubRun.h:49