Jpp  18.0.1-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTriggerMonitor.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 
6 #include "TROOT.h"
7 #include "TFile.h"
8 #include "TH1D.h"
9 
12 #include "JDAQ/JDAQEventIO.hh"
13 #include "JDAQ/JDAQTimesliceIO.hh"
15 
17 #include "JTrigger/JTriggerBits.hh"
18 
20 #include "JSupport/JSupport.hh"
22 #include "JROOT/JRootToolkit.hh"
23 
24 #include "Jeep/JPrint.hh"
25 #include "Jeep/JParser.hh"
26 #include "Jeep/JMessage.hh"
27 
28 
29 static const int WIDTH = 20;
30 
31 
32 /**
33  * Print histogram parameters.
34  *
35  * \param h1 histogram
36  * \param out output stream
37  */
38 inline void print(const TH1& h1, std::ostream& out)
39 {
40  using namespace std;
41 
42  out << setw(WIDTH) << left << h1.GetName() << ' '
43  << FIXED(8,0) << h1.GetEntries() << ' '
44  << FIXED(8,2) << h1.GetMean() << ' '
45  << FIXED(8,2) << h1.GetRMS() << ' '
46  << endl;
47 }
48 
49 
50 /**
51  * \file
52  *
53  * Auxiliary program to histogram and print trigger statistics.
54  * \author mdejong
55  */
56 int main(int argc, char **argv)
57 {
58  using namespace std;
59  using namespace JPP;
60  using namespace KM3NETDAQ;
61 
62  JMultipleFileScanner<> inputFile;
63  JLimit_t& numberOfEvents = inputFile.getLimit();
64  string outputFile;
65  int qaqc;
66  int debug;
67 
68  try {
69 
70  JParser<> zap("Auxiliary program to histogram and print trigger statistics.");
71 
72  zap['f'] = make_field(inputFile);
73  zap['o'] = make_field(outputFile) = "";
74  zap['n'] = make_field(numberOfEvents) = JLimit::max();
75  zap['Q'] = make_field(qaqc) = 0;
76  zap['d'] = make_field(debug) = 1;
77 
78  zap(argc, argv);
79  }
80  catch(const exception &error) {
81  FATAL(error.what() << endl);
82  }
83 
84 
85  TH1D h1("Event ", NULL, 100, 0.0, 1.0e1);
86  TH1D h2("Summary ", NULL, 100, 0.0, 1.0e1);
87 
88  TH1D hm("Trigger mask ", NULL, NUMBER_OF_TRIGGER_BITS, -0.5, NUMBER_OF_TRIGGER_BITS - 0.5);
89  TH1D hn("Trigger hits ", NULL, 1000, -0.5, 1000 - 0.5);
90  TH1D hs("Snapshot hits ", NULL, 1000, -0.5, 10000 - 0.5);
91  TH1D hr("PMT rate [kHz]", NULL, 100, 0.0, 50.0);
92 
93 
94  const JTriggerParameters trigger_parameters = getTriggerParameters(inputFile);
95 
96  NOTICE(trigger_parameters << endl);
97 
98 
99  for (JMultipleFileScanner<JDAQEvent> input = inputFile; input.hasNext(); ) {
100 
101  STATUS("entry: " << setw(10) << input.getCounter() << '\r'); DEBUG(endl);
102 
103  const JDAQEvent* object = input.next();
104 
105  h1.Fill((Double_t) getSizeof(*object) * 1e-6);
106 
107  hn.Fill((Double_t) object->size<JDAQTriggeredHit>());
108  hs.Fill((Double_t) object->size<JDAQSnapshotHit> ());
109 
110  for (unsigned int i = 0; i != NUMBER_OF_TRIGGER_BITS; ++i) {
111  if (object->hasTriggerBit(i)) {
112  hm.Fill((Double_t) i);
113  }
114  }
115 
116  {
117  unsigned int n = 0;
118 
119  typedef JDAQSnapshotHit JHit_t;
120 
121  for (JDAQEvent::const_iterator<JHit_t> i = object->begin<JHit_t>(); i != object->end<JHit_t>(); ++i) {
122 
123  if (object->getTriggerMask(*i) != 0) {
124  ++n;
125  }
126  }
127 
128  if (object->size<JHit_t>() != 0 && n != object->size<JDAQTriggeredHit>()) {
129  ERROR("Number of snapshot hits with trigger mask " << n << " != " << object->size<JDAQTriggeredHit>() << endl);
130  }
131  }
132  }
133 
134 
135  long long int numberOfSummaryslices = 0;
136 
137  for (JMultipleFileScanner<JDAQSummaryslice> input = inputFile; input.hasNext(); ++numberOfSummaryslices) {
138 
139  STATUS("entry: " << setw(10) << input.getCounter() << '\r'); DEBUG(endl);
140 
141  const JDAQSummaryslice* object = input.next();
142 
143  h2.Fill((Double_t) getSizeof(*object) * 1e-6);
144 
145  for (JDAQSummaryslice::const_iterator i = object->begin(); i != object->end(); ++i) {
146  for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
147  hr.Fill(i->getRate(pmt) * 1.0e-3);
148  }
149  }
150  }
151 
152 
153  if (debug >= JEEP::status_t) {
154  print(h1, cout);
155  print(h2, cout);
156  print(hn, cout);
157  print(hs, cout);
158  print(hr, cout);
159  }
160 
161  NOTICE(endl);
162  NOTICE("Background rate estimate from snapshot hits " << setprecision(2)
163  << (hs.GetMean() - hn.GetMean()) * numberOfSummaryslices / (hr.GetEntries() * 2e-6 * trigger_parameters.TMaxEvent_ns)
164  << " [kHz]" << endl);
165  NOTICE(endl);
166 
167 
168  const double T = numberOfSummaryslices * 1.0e-9 * getFrameTime(); // [s]
169 
170  NOTICE(setw(WIDTH) << left << "Total run duration (based on time slices) [s] " << FIXED(7,1) << T << endl);
171 
172 
173  for (Int_t i = 1; i <= hm.GetNbinsX(); ++i) {
174 
175  const JTriggerbit_t x = (JTriggerbit_t) hm.GetBinCenter (i);
176  const Double_t y = (Double_t) hm.GetBinContent(i);
177 
178  const char* const name = getTriggerName(x);
179 
180  if (name != NULL || y != 0.0) {
181 
182  NOTICE("Trigger"
183  << "[" << setw(2) << x << "]" << ' '
184  << setw(16) << left << (name != NULL ? name : "?") << ' '
185  << FIXED(9,0) << y);
186 
187  if (numberOfSummaryslices != 0) {
188  NOTICE(FIXED(12,2) << y / T << " [Hz]");
189  }
190 
191  NOTICE(endl);
192  }
193  }
194 
195  NOTICE("Total "
196  << setw(4) << " " << ' '
197  << setw(16) << " " << ' '
198  << FIXED(9,0) << h1.GetEntries());
199 
200  if (numberOfSummaryslices != 0) {
201  NOTICE(FIXED(12,2) << h1.GetEntries() / T << " [Hz]");
202  }
203 
204  NOTICE(endl);
205 
206  if (outputFile != "") {
207 
208  TFile out(outputFile.c_str(), "recreate");
209 
210  out << h1 << h2;
211  out << hm << hn << hs << hr;
212 
213  out.Write();
214  out.Close();
215  }
216 
217 
218  for (Int_t i = 1; i <= hm.GetNbinsX(); ++i) {
219 
220  const JTriggerbit_t x = (JTriggerbit_t) hm.GetBinCenter (i);
221  const Double_t y = (Double_t) hm.GetBinContent(i);
222 
223  const char* const name = getTriggerName(x);
224 
225  if (name != NULL) {
226  QAQC(' ' << FIXED(7,0) << y);
227  }
228  }
229 
230  QAQC(endl);
231 
232  return 0;
233 }
Utility class to parse command line options.
Definition: JParser.hh:1514
Auxiliary data structure for alignment of data.
Definition: JManip.hh:231
DAQ key hit.
Definition: JDAQKeyHit.hh:19
bool hasTriggerBit(const unsigned int bit) const
Check trigger bit.
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
static const unsigned int NUMBER_OF_TRIGGER_BITS
Number of trigger bits.
#define STATUS(A)
Definition: JMessage.hh:63
Template const_iterator.
Definition: JDAQEvent.hh:68
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
string outputFile
unsigned int size() const
Get number of hits.
static JTriggerMask_t getTriggerMask(const JDAQTriggeredHit &hit)
Get trigger mask of given hit.
Definition: JDAQEvent.hh:228
const int n
Definition: JPolint.hh:697
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
const_iterator< T > end() const
Get end of data.
I/O formatting auxiliaries.
status
Definition: JMessage.hh:30
virtual bool hasNext() override
Check availability of next element.
const_iterator< T > begin() const
Get begin of data.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
do set_variable OUTPUT_DIRECTORY $WORKDIR T
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
print
Definition: JConvertDusj.sh:44
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
const char * getTriggerName(JTriggerbit_t bit)
Get trigger name.
#define QAQC(A)
QA/QC output macro.
Definition: JMessage.hh:100
Auxiliary class to set-up Hit.
Definition: JSirene.hh:57
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
Setting of trigger bits.
KM3NeT DAQ constants, bit handling, etc.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
size_t getSizeof(const JDAQEvent &object)
Get size of object.
Definition: JDAQEventIO.hh:26
int qaqc
QA/QC file descriptor.
JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t &file_list)
Get trigger parameters.
int debug
debug level
JTriggerCounter_t next()
Increment trigger counter.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
unsigned int JTriggerbit_t
Type definition of trigger bit.