Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RunAnalyzer.hh
Go to the documentation of this file.
1 #ifndef __RUNANALYZER__
2 #define __RUNANALYZER__
3 
4 #include "JSupport/JSupport.hh"
9 #include "JGizmo/JManager.hh"
10 #include "JTools/JQuantile.hh"
11 #include "TFile.h"
12 #include "TH1D.h"
13 #include "JRunHistograms.hh"
14 
15 using namespace std ;
16 using namespace KM3NETDAQ ;
17 using namespace JDETECTOR ;
18 using namespace JLANG ;
19 using namespace JPP ;
20 
21 /**
22  * \author rgruiz
23  */
24 
25 /**
26  * Class dedicated to the analysis of KM3NeT runs.
27  *
28  */
29 class RunAnalyzer {
30 
31  string inputFile;
39 
40 public :
41 
42  /**
43  * Default constructor.
44  */
46 
47  /**
48  * Constructor.
49  *
50  * \param file Path to the file to be analyzed
51  * \param detectorFile path to a detector file
52  * \param nTimeslices Number of timeslices to be read
53  * \param nSummaryslices Number of summary slices to be read
54  * \param nEvents Number of frames to be read
55  */
56  RunAnalyzer (string file , string detectorFile , JLimit_t nTimeslices , JLimit_t nSummaryslices , JLimit_t nEvents):
57  inputFile (file),
58  router (NULL),
59  numberOfTimeslices (nTimeslices),
60  numberOfSummaryslices (nSummaryslices),
61  numberOfEvents (nEvents)
62  {
63  try {
64  load (detectorFile, detector);
65  }
66  catch(const JException & error) {
67  cerr << "FATAL ERROR. Could not open detector file '" << detectorFile << "'." << endl;
68  exit(1);
69  }
70 
71  histograms = JRA_Histograms(detector);
72  router = new JModuleRouter(detector);
74  }
75 
76  /**
77  * Destructor.
78  */
80 
81  /*
82  * Function template used to read time ordered events from a tree.
83  *
84  * \param scanner A JTreeScanner
85  * \param
86  */
88 
89  while (scanner.hasNext()) {
90 
91  JDAQEvent event = *(scanner.next());
92 
93  histograms.h_trigger.h_Snapshot_hits -> Fill((Double_t) event.size<JDAQSnapshotHit > ());
94  histograms.h_trigger.h_Triggered_hits -> Fill((Double_t) event.size<JDAQTriggeredHit> ());
95  histograms.h_trigger.h_Number_of_overlays -> Fill(event.getOverlays());
96 
97  for (unsigned int i = 0; i != NUMBER_OF_TRIGGER_BITS; ++i) {
98 
99  if (event.hasTriggerBit(i)) {
100 
101  histograms.h_trigger.h_Trigger_bit_event -> Fill((Double_t) i);
102  }
103  }
104 
105  histograms.h_trigger.h_Trigger_time->Fill(event.begin<JDAQTriggeredHit>()->getT() * 1e-6);
106 
107  for (JDAQEvent::const_iterator<JDAQTriggeredHit> hit = event.begin<JDAQTriggeredHit>(); hit != event.end<JDAQTriggeredHit>(); ++hit) {
108 
109  if (router->hasModule(hit->getModuleID())) {
110 
111  const JModule& module = router->getModule (hit->getModuleID());
112 
113  histograms.h_trigger.h_pmt_distribution_triggered_hits->Fill(hit->getPMT());
114  histograms.h_trigger.h_tot_distribution_triggered_hits->Fill(hit->getToT());
115 
116  int String = module.getString();
117  int Floor = module.getFloor();
118 
119  histograms.h_trigger.h_Triggered_hits_per_module -> Fill(String , Floor);
120 
121  for (unsigned int i = 0; i != NUMBER_OF_TRIGGER_BITS; ++i) {
122 
123  if (hit -> hasTriggerBit(i)) {
124 
125  histograms.h_trigger.h_Trigger_bit_hit->Fill((Double_t) i);
126  }
127  }
128  }else{
129  FATAL("JModuleRouter trying to access non existing identifier: "<< hit->getModuleID());
130  }
131  }
132 
133  for (JDAQEvent::const_iterator<JDAQSnapshotHit> hit = event.begin<JDAQSnapshotHit>() ; hit != event.end<JDAQSnapshotHit>() ; ++hit){
134 
135  if (router->hasModule(hit->getModuleID())) {
136 
137  const JModule& module = router->getModule (hit->getModuleID());
138 
139  int String = module.getString();
140  int Floor = module.getFloor();
141  int pmt = hit-> getPMT();
142 
143  (*histograms.h_trigger.m_Snapshot_hits_per_pmt)[MAKE_STRING("Detector/DU" + to_string(String))] -> Fill(pmt, Floor);
144  histograms.h_trigger.h_Snapshot_hits_per_module -> Fill(String, Floor);
145  histograms.h_trigger.h_pmt_distribution_snapshot_hits -> Fill(hit->getPMT());
146  histograms.h_trigger.h_tot_distribution_snapshot_hits -> Fill(hit->getToT());
147 
148  }else{
149  FATAL("JModuleRouter trying to access non existing identifier: "<< hit->getModuleID());
150  }
151  }
152  }
153  }
154 
155 
156  /*
157  * Function template to read and process time ordered summary slices.
158  *
159  * \param scanner A JTreeScanner from which time ordered summary slices are accessed.
160  */
162 
163  std::map <int,vector<vector <JQuantile>>> PMT_rate_quantiles;
164  std::map <int,vector<JQuantile>> DOM_rate_quantiles;
165 
166  while (scanner.hasNext()){
167 
168  JDAQSummaryslice slice = *(scanner.next());
169 
170  for (JDAQSummaryslice::const_iterator frame = slice.begin() ; frame != slice.end() ; ++ frame) {
171 
172  if (router->hasModule(frame->getModuleID())) {
173 
174  const JModule& module = router->getModule (frame->getModuleID());
175 
176  int string = module.getString();
177  int floor = module.getFloor ();
178 
179  PMT_rate_quantiles[string].resize(modulesPerString , vector <JQuantile>(NUMBER_OF_PMTS));
180 
181  JDAQFrameStatus status = frame -> getDAQFrameStatus();
182  int nFIFOcount = status.countFIFOStatus();
183  int nHRVcount = status.countHighRateVeto();
184 
185  if (nHRVcount > 0) {
186  histograms.h_summary.h_hrv_per_dom->Fill(string , floor);
187  }
188 
189  if (status.testDAQStatus() == false) {
190  histograms.h_summary.h_daq_status_per_dom->Fill(string , floor);
191  }
192 
193  histograms.h_summary.h_fifo_per_dom->Fill(string , floor , nFIFOcount);
194 
195  TH2D* h2 = (*histograms.h_summary.m_summary_rate_distribution)[MAKE_STRING("Detector/DU" + to_string(string) + "/F" + to_string(floor))];
196  double rate = 0;
197 
198  for (int i = 0 ; i < NUMBER_OF_PMTS ; i++){
199 
200  h2->Fill(i , frame->getRate(i) * 1e-3);
201 
202  rate += frame->getRate(i);
203  histograms.h_summary.h_pmt_rate_distribution->Fill(frame->getRate(i)*1e-3);
204  PMT_rate_quantiles[string][floor-1][i].put(frame->getRate(i)*1e-3);
205  }
206 
207  histograms.h_summary.h_dom_rate_distribution->Fill(rate*1e-3);
208 
209  DOM_rate_quantiles[string].resize(modulesPerString);
210 
211  DOM_rate_quantiles[string][floor-1].put(rate * 1e-3);
212 
213  }else{
214  FATAL("JModuleRouter trying to access non existing identifier: "<< frame->getModuleID());
215  }
216  }
217  }
218  for (std::map<int , vector<JQuantile> >::const_iterator i = DOM_rate_quantiles.begin() ; i!= DOM_rate_quantiles.end() ; ++i) {
219 
220  for (int j=1 ; j < modulesPerString + 1 ; j++) {
221 
222  if (i->second[j-1].getCount() > 0) histograms.h_summary.h_rate_summary->Fill(i->first, j, i->second[j-1].getMean());
223  }
224  }
225 
226  for (std::map<int , vector < vector<JQuantile> > >::const_iterator i = PMT_rate_quantiles.begin() ; i!= PMT_rate_quantiles.end() ; ++i) {
227 
228  for (int j=0 ; j < modulesPerString ; j++){
229 
230  for (int k=0 ; k < NUMBER_OF_PMTS ; k++){
231 
232  if (i -> second[j][k].getCount() > 0){
233 
234  (*histograms.h_summary.m_mean_summary_rate) [MAKE_STRING("Detector/DU" + to_string(i->first))]->Fill(k, j+1, i->second[j][k].getMean());
235  (*histograms.h_summary.m_mean_summary_rate_distribution)[MAKE_STRING("Detector/DU" + to_string(i->first))]->Fill( i->second[j][k].getMean());
236  }
237  }
238  }
239  }
240  }
241 
242  /*
243  * Function template to read and process time ordered timeslices.
244  *
245  * \param scanner A JTreeScanner from which time ordered timeslices are accessed.
246  * \param frame_index_range the range of the indices of the frames to be accessed.
247  */
248  template <class T>
250 
252 
253  std::map < int , std::map <int , JQuantile> > DOM_rate_quantiles;
254 
255  double inverseFrameTimeSec = 1. / (1.0e-9 * getFrameTime());
256 
257  while (scanner.hasNext()){
258 
259  T slice = *(scanner.next());
260 
261  for(auto & frame : slice) {
262  if (router->hasModule(frame.getModuleID())) {
263 
264  const JModule& module = router->getModule (frame.getModuleID());
265  double rate = frame.numberOfHits * inverseFrameTimeSec;
266  int string = module.getString();
267  int floor = module.getFloor ();
268 
269  DOM_rate_quantiles[string][floor].put(rate);
270 
271  vector <int> pmt_hit_count (NUMBER_OF_PMTS , 0) ;
272 
273  TH2D* h2 = (*histograms.h_timeslice.m_pmt_tot_distributions[ts_type])[MAKE_STRING("Detector/DU" + to_string(string) + "/F" + to_string(floor) + "/" + to_string(frame.getModuleID()))];
274 
275  for (JDAQSuperFrame::const_iterator hit = frame.begin() ; hit != frame.end() ; ++hit){
276 
277  h2 -> Fill(hit->getPMT() , hit->getToT()) ;
278 
279  pmt_hit_count[hit->getPMT()]++;
280 
281  }
282 
283  for (int pmt = 0 ; pmt != NUMBER_OF_PMTS ; ++pmt) {
284 
285  (*histograms.h_timeslice.m_pmt_rate_distributions[ts_type])[MAKE_STRING("Detector/DU" + to_string(string) + "/F" + to_string(floor))] -> Fill(pmt , 1e-3 * pmt_hit_count[pmt] * inverseFrameTimeSec);
286 
287  }
288 
289  }else{
290  FATAL("JModuleRouter trying to access non existing identifier: "<< frame.getModuleID());
291  }
292  }
293  }
294 
295  for (std::map< int , std::map<int,JQuantile>>::const_iterator i = DOM_rate_quantiles.begin() ; i != DOM_rate_quantiles.end() ; i++){
296 
297  for (std::map<int , JQuantile>::const_iterator j = i->second.begin() ; j != i->second.end() ; j++){
298 
299  if (j->second.getCount() > 0) histograms.h_timeslice.h_dom_mean_rates[ts_type] -> Fill (i->first , j->first , j->second.getMean() ) ;
300  }
301  }
302  }
303 
304 
305  /*
306  * Checks through the use of a JTreeScanner, if summary slices are present in the run file.
307  * In case they are, the corresponding tree is iterated.
308  *
309  */
311 
312  JTreeScanner <JDAQSummaryslice> scanner(inputFile, numberOfSummaryslices);
313  if (scanner.hasNext()) {
314  histograms.initialize_summary_histograms();
315  scanner.rewind();
316  iterateSummarysliceTree(scanner);
317  }
318  }
319 
320 
321  /*
322  * Function template that checks through the use of a JTreeScanner, if objects of different timeslice classes are present in the run file.
323  * In case they are, the corresponding tree is iterated.
324  *
325  */
326  template <class T>
328 
329  JTreeScanner <T> scanner(inputFile, numberOfTimeslices);
330  if(scanner.hasNext()) {
331 
332  histograms.initialize_timeslice_histograms <T>();
333  scanner.rewind();
334  iterateTimesliceTree(scanner);
335  }
336  }
337 
338 
339  /*
340  * Function template that checks through the use of a JTreeScanner, if JDAQEvent objects are present in the run file.
341  * In case they are, the corresponding tree is read.
342  *
343  */
344  void readEvents() {
345 
346  JTreeScanner <JDAQEvent> scanner(inputFile, numberOfEvents);
347 
348  if(scanner.hasNext()) {
349 
350  histograms.initialize_trigger_histograms();
351  scanner.rewind();
352  iterateEventTree(scanner);
353  }
354  }
355 
356  /*
357  * Returns the histograms produced from the data in the file.
358  */
360 
361  return histograms ;
362  }
363 };
364 
365 #endif
*fatal Wrong number of arguments esac JCookie sh JRuns D $DETECTOR d sort n k
Definition: JRunrange.sh:16
JLimit_t numberOfSummaryslices
Definition: RunAnalyzer.hh:37
JRA_Histograms histograms
Definition: RunAnalyzer.hh:34
General exception.
Definition: JException.hh:23
void readEvents()
Definition: RunAnalyzer.hh:344
DAQ key hit.
Definition: JDAQKeyHit.hh:19
void iterateEventTree(JTreeScanner< JDAQEvent > &scanner)
Definition: RunAnalyzer.hh:87
ROOT TTree parameter settings.
static const unsigned int NUMBER_OF_TRIGGER_BITS
Number of trigger bits.
void iterateSummarysliceTree(JTreeScanner< JDAQSummaryslice > &scanner)
Definition: RunAnalyzer.hh:161
int countFIFOStatus() const
Count FIFO status.
JLimit_t numberOfTimeslices
Definition: RunAnalyzer.hh:36
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
Data structure for a composite optical module.
Definition: JModule.hh:50
RunAnalyzer(string file, string detectorFile, JLimit_t nTimeslices, JLimit_t nSummaryslices, JLimit_t nEvents)
Constructor.
Definition: RunAnalyzer.hh:56
Detector data structure.
Definition: JDetector.hh:80
Template const_iterator.
Definition: JDAQEvent.hh:68
Router for direct addressing of module data in detector data structure.
JLimit_t numberOfEvents
Definition: RunAnalyzer.hh:38
then set_variable singlesRate set_variable doublesRate set_variable numberOfSlices echo Generating random background echo Singles rate
exit
Definition: JPizza.sh:36
Dynamic ROOT object management.
void iterateTimesliceTree(JTreeScanner< T > &scanner)
Definition: RunAnalyzer.hh:249
JTDC_t getT() const
Get time.
Definition: JDAQHit.hh:86
void readTimesliceData()
Definition: RunAnalyzer.hh:327
Template definition for direct access of elements in ROOT TChain.
Definition: JTreeScanner.hh:91
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:699
esac $JPP_DIR examples JDetector JTransitTime o $OUTPUT_FILE n N $NPE T $TTS_NS d $DEBUG for HISTOGRAM in tts tt2 pmt
Definition: JTransitTime.sh:36
string inputFile
Definition: RunAnalyzer.hh:31
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Detector file.
Definition: JHead.hh:130
~RunAnalyzer()
Destructor.
Definition: RunAnalyzer.hh:79
Class dedicated to the analysis of KM3NeT runs.
Definition: RunAnalyzer.hh:29
Hit data structure.
Definition: JDAQHit.hh:34
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
JRA_Histograms getHistograms()
Definition: RunAnalyzer.hh:359
do set_variable OUTPUT_DIRECTORY $WORKDIR T
int modulesPerString
Definition: RunAnalyzer.hh:35
Support methods.
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
static const JStringCounter getNumberOfStrings
Function object to count unique strings.
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Direct access to module in detector data structure.
int getString() const
Get string number.
Definition: JLocation.hh:134
int countHighRateVeto() const
Count high-rate veto status.
void readSummaryData()
Definition: RunAnalyzer.hh:310
General purpose string class.
Definition: JHead.hh:102
std::string to_string(const T &value)
Convert value to string.
int getCount(const T &hit)
Get hit count.
JModuleRouter * router
Definition: RunAnalyzer.hh:33
int j
Definition: JPolint.hh:634
JDetector detector
Definition: RunAnalyzer.hh:32
Indexing of data type in type list.
Definition: JTypeList.hh:310
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
bool testDAQStatus() const
Test DAQ status of packets.
int getNumberOfModules(const JDetector &detector)
Get number of modules.
RunAnalyzer()
Default constructor.
Definition: RunAnalyzer.hh:45