Jpp  15.0.3
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JRunHistograms.hh
Go to the documentation of this file.
1 #ifndef __JRUNHISTOGRAMS__
2 #define __JRUNHISTOGRAMS__
3 
4 /**
5  * \author rgruiz, adomi
6  */
7 
8 #include "JSupport/JSupport.hh"
10 
12 #include "JTrigger/JTriggerBits.hh"
13 
16 
20 
21 #include "JROOT/JManager.hh"
22 
23 #include "TH1D.h"
24 #include "TH2D.h"
25 #include "TProfile2D.h"
26 #include "TAxis.h"
27 #include "TCanvas.h"
28 #include "TPaveText.h"
29 #include "TStyle.h"
30 #include "TString.h"
31 #include "TMath.h"
32 #include "TColor.h"
33 #include "TDirectory.h"
34 #include "TPRegexp.h"
35 #include "TObjArray.h"
36 #include "TObjString.h"
37 
38 using namespace std ;
39 using namespace KM3NETDAQ ;
40 using namespace JLANG ;
41 using namespace JPP ;
42 using namespace JSUPPORT ;
43 
44 /*
45  * Rebins a histogram with constant bin width in a linear scale, so that the bins will have constant width in log10 scale.
46  *
47  * \param h The histogram.
48  */
49 template <class T>
50 void BinLogX (T* h){
51 
52  TAxis *axis = h->GetXaxis();
53  int bins = axis->GetNbins();
54  Axis_t from = axis->GetXmin();
55  Axis_t to = axis->GetXmax();
56  Axis_t width = (to - from) / bins;
57  Axis_t *new_bins = new Axis_t[bins + 1];
58 
59  for (int i = 0; i <= bins; i++) {
60  new_bins[i] = TMath::Power(10, from + i * width);
61  }
62 
63  axis->Set(bins, new_bins);
64 
65  delete new_bins;
66 }
67 
68 
69 /*
70  * Rebins a histogram with constant bin width in a linear scale, so that the bins will have constant width in log10 scale.
71  *
72  * \param h The histogram.
73  */
74 template <class T>
75 void BinLogY (T* h){
76 
77  TAxis *axis = h->GetYaxis();
78  int bins = axis->GetNbins();
79  Axis_t from = axis->GetXmin();
80  Axis_t to = axis->GetXmax();
81  Axis_t width = (to - from) / bins;
82  Axis_t *new_bins = new Axis_t[bins + 1];
83 
84  for (int i = 0; i <= bins; i++) {
85  new_bins[i] = TMath::Power(10, from + i * width);
86  }
87 
88  axis->Set(bins, new_bins);
89 
90  delete new_bins;
91 }
92 
93 double binsToT[] = {-0.5 , 0.5 , 1.5 , 2.5 , 3.5 , 4.5 , 5.5 , 6.5 , 7.5 , 8.5 , 9.5 , 10.5 , 11.5 , 12.5 , 13.5 , 14.5 , 15.5 ,
94  16.5 , 17.5 , 18.5 , 19.5 , 20.5 , 21.5 , 22.5 , 23.5 , 24.5 , 25.5 , 26.5 , 27.5 , 28.5 , 30.5 , 32.5 , 34.5 ,
95  36.5 , 38.5 , 40.5 , 45.5 , 50.5 , 55.5 , 60.5 , 65.5 , 70.5 , 75.5 , 80.5 , 85.5 , 90.5 , 95.5 , 100.5 , 120.5 , 140.5 ,
96  160.5 , 180.5 , 200.5 , 254.5 , 255.5 , 256.5};
97 
98 int nbinsToT = sizeof(binsToT)/sizeof(*binsToT) - 1;
99 
100 
101 /*
102  * Normalizes a histogram to a given value.
103  *
104  * \param h The histogram.
105  * \param n The normalization constant
106  */
107 void normalizeBW1D (TH1D* h){
108 
109  for(int i=0 ; i < h->GetNbinsX() ; i++){
110 
111  double width = h -> GetXaxis() -> GetBinWidth(i);
112 
113  h -> SetBinContent(i , h -> GetBinContent(i) / width);
114  h -> SetBinError (i , h -> GetBinError(i) / width);
115  }
116 }
117 
118 
119 /*
120  * Structure to store histograms obtained from the JDAQSummary TTree.
121  */
123  TH1D* h_mean_fifo;
130 
131  /* One histogram for each DU */
134 
135  /* One histogram for each module */
137 
139  h_fifo_per_dom = NULL;
140  h_daq_status_per_dom = NULL;
141  h_hrv_per_dom = NULL;
142  h_rate_summary = NULL;
143  h_pmt_rate_distribution = NULL;
144  h_dom_rate_distribution = NULL;
145  m_mean_summary_rate = NULL;
146  m_mean_summary_rate_distribution = NULL;
147  m_summary_rate_distribution = NULL;
148  }
149 
150  /*
151  * Initializes the histograms for summary slices
152  */
153  void initialize(std::set<int> & du_ids , int modules_per_string){
154 
155  init_h_fifo_per_dom (du_ids , modules_per_string);
156  init_h_daq_status_per_dom (du_ids , modules_per_string);
157  init_h_hrv_per_dom (du_ids , modules_per_string);
158  init_h_rate_summary (du_ids , modules_per_string);
159  init_h_pmt_rate_distribution ();
160  init_h_dom_rate_distribution ();
161  init_m_mean_summary_rate (modules_per_string);
162  init_m_mean_summary_rate_distribution ();
163  init_m_summary_rate_distribution ();
164  }
165 
166  /*
167  * Initializes the histogram.
168  *
169  * \param du_ids The list of ids for the DUs in the detector.
170  * \param modules_per_string the number of modules in a string.
171  */
172  void init_h_fifo_per_dom (std::set<int> & du_ids , int modules_per_string){
173 
174  string name = MAKE_STRING ("h_fifo_per_dom");
175  string title = MAKE_STRING (" FIFO ; String ; Floor ; Number of slices with FIFO almost full x number of PMTs ");
176 
177  h_fifo_per_dom = new TH2D (name.c_str() , title.c_str() , *du_ids.rbegin() , 0.5 , *du_ids.rbegin() + 0.5 , modules_per_string , 0.5 , modules_per_string + 0.5 );
178  }
179 
180  /*
181  * Initializes the histogram.
182  *
183  * \param du_ids The list of ids for the DUs in the detector.
184  * \param modules_per_string the number of modules in a string.
185  */
186  void init_h_daq_status_per_dom (std::set<int> & du_ids , int modules_per_string){
187 
188  string name = MAKE_STRING ("h_daq_status_per_dom");
189  string title = MAKE_STRING (" DAQ Status ; String ; Floor ; Number of slices with wrong DAQ status of packets ");
190 
191  h_daq_status_per_dom = new TH2D (name.c_str() , title.c_str() , *du_ids.rbegin() , 0.5 , *du_ids.rbegin() + 0.5 , modules_per_string , 0.5 , modules_per_string + 0.5 );
192  }
193 
194  /*
195  * Initializes the histogram.
196  *
197  * \param du_ids The list of ids for the DUs in the detector.
198  * \param modules_per_du the number of modules in a string.
199  */
200  void init_h_hrv_per_dom (set<int> & du_ids , int modules_per_string){
201 
202  string name = MAKE_STRING ("h_hrv_per_dom");
203  string title = MAKE_STRING ("HRV ; String ; Floor ; Number of slices x number of PMTs in HRV");
204 
205  h_hrv_per_dom = new TH2D (name.c_str() , title.c_str() , *du_ids.rbegin() , 0.5 , *du_ids.rbegin() + 0.5 , modules_per_string , 0.5 , modules_per_string + 0.5 );
206  }
207 
208  /*
209  * Initializes the histogram.
210  *
211  * \param du_ids The list of ids for the DUs in the detector.
212  * \param modules_per_du the number of modules in a string.
213  */
214  void init_h_rate_summary (set<int> & du_ids , int modules_per_string){
215 
216  string name = MAKE_STRING ("h_rate_summary");
217  string title = MAKE_STRING ("Summary slices ; String ; Floor ; Mean rate over all summary slices [kHz]");
218 
219  h_rate_summary = new TH2D (name.c_str() , title.c_str() , *du_ids.rbegin() , 0.5 , *du_ids.rbegin() + 0.5 , modules_per_string , 0.5 , modules_per_string + 0.5 );
220  }
221 
222  /*
223  * Initializes the histogram.
224  */
226 
227  string name = MAKE_STRING ("h_pmt_rate_distribution");
228  string title = MAKE_STRING ("PMT rate distribution from summary slices ; rate [kHz] ; Counts");
229 
230  h_pmt_rate_distribution = new TH1D (name.c_str() , title.c_str() , 20 , 0 , log10(100));
231 
232  BinLogX (h_pmt_rate_distribution);
233 
234  h_pmt_rate_distribution -> SetMinimum(1);
235  }
236 
237  /*
238  * Initializes the histogram.
239  */
241 
242  string name = MAKE_STRING ("h_dom_rate_distribution");
243  string title = MAKE_STRING ("DOM rate distribution from summary slices ; rate [kHz] ; Counts");
244 
245  h_dom_rate_distribution = new TH1D (name.c_str() , title.c_str() , 50 , log10(50) , log10(2000));
246 
247  BinLogX (h_dom_rate_distribution);
248 
249  h_dom_rate_distribution -> SetMinimum(1);
250  }
251 
252  /*
253  * Initializes the histogram.
254  *
255  * \param modules_per_string the number of modules in a string.
256  */
258 
259  string name = MAKE_STRING ("%/h_mean_summary_rate_distribution");
260  string title = MAKE_STRING (" ; rate [kHz] ; # PMTs");
261 
262  TH1D* h = new TH1D(name.c_str() , title.c_str() , 40 , 0 , log10(1000));
263 
264  BinLogX (h);
265 
266  m_mean_summary_rate_distribution = new JManager < string , TH1D > (h);
267  }
268 
269  /*
270  * Initializes the histogram.
271  *
272  * \param modules_per_string the number of modules in a string.
273  */
274  void init_m_mean_summary_rate (int modules_per_string){
275 
276  string name = MAKE_STRING ("%/h_mean_summary_rate");
277  string title = MAKE_STRING (" ; TDC Channel ; Floor ; rate [kHz]");
278 
279  m_mean_summary_rate = new JManager < string , TH2D > (new TH2D(name.c_str() , title.c_str() , NUMBER_OF_PMTS , -0.5 , NUMBER_OF_PMTS - 0.5 , modules_per_string , 0.5 , 0.5 + modules_per_string));
280  }
281 
282  /*
283  * Initializes the histograms. The frame index range information is needed.
284  *
285  */
287 
288  string name = MAKE_STRING ("%/h_pmt_rate_distributions_Summaryslice");
289  string title = MAKE_STRING ("Summaryslice ; TDC channel ; rate [kHz] ; counts");
290 
291  TH2D* h_summary_rate_distribution = new TH2D (name.c_str() , title.c_str(),
292  NUMBER_OF_PMTS , -0.5 , NUMBER_OF_PMTS - 0.5 ,
293  100 , -1 , log10(10000));
294 
295  BinLogY (h_summary_rate_distribution);
296 
297  m_summary_rate_distribution = new JManager < string , TH2D > (h_summary_rate_distribution);
298  }
299 };
300 
302 
303  int min_ToT;
304  int max_ToT;
309 
310  /* One histogram per timeslice type. I decided not to use a JManager here because the range of each histogram could be different for each timeslice type. */
311 
313 
314  /* One JManager per timeslice type. Each JManager hosts a histogram for each DU */
315 
318 
319  /* One JManager per timeslice type. Each manager hosts a histogram for an optical module. The key is expected to follow the pattern SXXFXX */
320 
323 
325  min_ToT (0),
326  max_ToT (255),
327  min_logdt (0),
328  max_logdt (9),
329  nbins_logdt (150),
330  nbins_time (200)
331  {
332  int number_of_timeslice_types = JLength<JDAQTimesliceTypes_t>::value ;
333 
334  h_dom_mean_rates .resize (number_of_timeslice_types , NULL);
335  m_mean_ToT .resize (number_of_timeslice_types , NULL);
336  m_mean_ToT_distribution .resize (number_of_timeslice_types , NULL);
337  m_pmt_tot_distributions .resize (number_of_timeslice_types , NULL);
338  m_pmt_rate_distributions .resize (number_of_timeslice_types , NULL);
339  }
340 
341  /*
342  * Initializes histograms for a given timeslice type.
343  *
344  * \param du_ids The list of ids for the DUs in the detector
345  * \param modules_per_string the number of modules in a string
346  * \param ts_type Index of the timeslice types on the JDAQTimesliceTypes_t typelist.
347  * \param ts_name The name of the timeslice type
348  */
349  void initialize(std::set<int> du_ids , int modules_per_string , int ts_type , std::string ts_name){
350 
351  init_h_dom_mean_rates (ts_type , du_ids , modules_per_string , ts_name);
352  init_m_mean_ToT (ts_type , modules_per_string , ts_name);
353  init_m_mean_ToT_distribution (ts_type , ts_name);
354  init_m_pmt_tot_distributions (ts_type , ts_name);
355  init_m_pmt_rate_distributions (ts_type , ts_name);
356  }
357 
358  /*
359  * Fills the mean ToT as a function of the PMT and floor number for a given DU
360  *
361  * \param table table with the ToT distributions for each PMT in a module, for every timeslice type
362  * \param string The string number
363  * \param floor The floor number
364  */
366 
367  int i = 0 ;
368 
369  for (typename vector < JManager < string , TH2D >* >::const_iterator it = m_pmt_tot_distributions.begin() ; it != m_pmt_tot_distributions.end() ; ++it , ++i){
370 
371  if ((*it)){
372 
373  for (typename JManager < string , TH2D >::const_iterator j = (*it) -> begin() ; j != (*it) -> end() ; ++j){
374 
375  TString s (MAKE_STRING(j -> first).c_str());
376  TPRegexp r ("(\\w+)/(\\DU)(\\d+)/(F)(\\d+)");
377 
378  TObjArray* o = r.MatchS(s);
379 
380  int String = ((TObjString *)o->At(3))->GetString().Atoi();
381  int Floor = ((TObjString *)o->At(5))->GetString().Atoi();
382 
383  for (int pmt = 1 ; pmt <= (j -> second) -> GetXaxis() -> GetNbins() ; pmt++){
384 
385  (*m_mean_ToT[i])[MAKE_STRING("Detector/DU" + to_string(String))] -> Fill((j->second) -> GetXaxis() -> GetBinCenter(pmt) , Floor , (j -> second) -> ProjectionY ("" , pmt , pmt) -> GetMean () );
386  (*m_mean_ToT_distribution[i])[MAKE_STRING("Detector/DU" + to_string(String))] -> Fill((j -> second) -> ProjectionY ("" , pmt , pmt) -> GetMean () );
387  }
388  }
389  }
390  }
391  }
392 
393  /*
394  * Initializes the histogram.
395  *
396  * \param ts_type index of the timeslicetype indicating its position on the JDAQTimeslicetypes_t typelist
397  * \param modules_per_string The number of modules in a string.
398  * \param ts_name String containing the timeslice type.
399  */
400  void init_h_dom_mean_rates (int ts_type , std::set<int> du_ids , int modules_per_string , std::string ts_name){
401 
402  string name = MAKE_STRING ("h_mean_dom_rates_" + ts_name);
403  string title = MAKE_STRING (ts_name + " ; DU number ; Floor number ; time slice averaged rate [Hz]");
404 
405  h_dom_mean_rates[ts_type] = new TH2D (name.c_str() , title.c_str() , *du_ids.rbegin() , 0.5 , *du_ids.rbegin() + 0.5 , modules_per_string , 0.5 , 0.5 + modules_per_string);
406  }
407 
408  /*
409  * Initializes the histogram.
410  *
411  * \param ts_type index of the timeslicetype indicating its position on the JDAQTimeslicetypes_t typelist
412  * \param modules_per_string the number of modules in a string.
413  * \param ts_name String containing the timeslice type.
414  */
415  void init_m_mean_ToT (int ts_type , int modules_per_string , string ts_name){
416 
417  string name = MAKE_STRING ("%/h_mean_ToT_" + ts_name);
418  string title = MAKE_STRING (ts_name + " ; TDC channel ; Floor number ; mean ToT [ns] ");
419 
420  m_mean_ToT[ts_type] = new JManager < string , TH2D > (new TH2D (name.c_str() , title.c_str() , NUMBER_OF_PMTS , -0.5 , NUMBER_OF_PMTS - 0.5 , modules_per_string , 0.5 , 0.5 + modules_per_string));
421  }
422 
423  /*
424  * Initializes the histogram.
425  *
426  * \param ts_type index of the timeslicetype indicating its position on the JDAQTimeslicetypes_t typelist
427  * \param modules_per_string the number of modules in a string.
428  * \param ts_name String containing the timeslice type.
429  */
430  void init_m_mean_ToT_distribution (int ts_type , string ts_name){
431 
432  string name = MAKE_STRING ("%/h_mean_ToT_distribution" + ts_name);
433  string title = MAKE_STRING (ts_name + " ; ToT [ns] ; # PMTS ");
434 
435  m_mean_ToT_distribution[ts_type] = new JManager < string , TH1D > (new TH1D (name.c_str() , title.c_str() , 255 , 0.5 , 255.5));
436  }
437 
438  /*
439  * Initializes the histograms. The frame index range information is needed.
440  *
441  * \param ts_type index for the timeslice type, according to the JDAQTimeslicetypes_t typelist
442  * \param ts_name suffix string
443  */
444  void init_m_pmt_tot_distributions (int ts_type , string ts_name){
445 
446  string name = MAKE_STRING ("%_" + ts_name + "_2SToT");
447  string title = MAKE_STRING (ts_name + " ; TDC channel ; ToT [ns] ; counts");
448 
449  TH2D* h = new TH2D (name.c_str() , title.c_str() , NUMBER_OF_PMTS , -0.5 , NUMBER_OF_PMTS - 0.5 , nbinsToT , binsToT);
450 
451  h->Sumw2();
452 
453  m_pmt_tot_distributions[ts_type] = new JManager < string , TH2D > (h);
454 
455  }
456 
457  /*
458  * Initializes the histograms. The frame index range information is needed.
459  *
460  * \param ts_type index for the timeslice type, according to the JDAQTimeslicetypes_t typelist
461  * \param ts_name suffix string
462  */
463  void init_m_pmt_rate_distributions(int ts_type , string ts_name){
464 
465  string name = MAKE_STRING ("%/h_pmt_rate_distributions_" + ts_name);
466  string title = MAKE_STRING (ts_name + " ; TDC channel ; rate [kHz] ; counts ");
467 
468  TH2D* h_pmt_rate_distributions = new TH2D (name.c_str() , title.c_str(),
469  NUMBER_OF_PMTS , -0.5 , NUMBER_OF_PMTS - 0.5 ,
470  60 , -6 , log10(1000));
471 
472  BinLogY (h_pmt_rate_distributions);
473 
474  m_pmt_rate_distributions[ts_type] = new JManager < string , TH2D > (h_pmt_rate_distributions);
475  }
476 };
477 
478 /*
479  * Structure to store histograms obtained from the JDAQEvent TTree
480  */
482 
493 
494  /* One histogram per DU*/
495 
497 
502 
503  /*
504  * Constructor
505  */
507  h_Trigger_bit_event = NULL;
508  h_Trigger_bit_hit = NULL;
509  h_Snapshot_hits = NULL;
510  h_Triggered_hits = NULL;
511  h_Triggered_hits_3dmuon = NULL;
512  h_Triggered_hits_3dmuon_per_module = NULL;
513  h_Triggered_over_Snapshot_hits = NULL;
514  h_Number_of_overlays = NULL;
515  h_Snapshot_hits_per_module = NULL;
516  h_Triggered_hits_per_module = NULL;
517  m_Snapshot_hits_per_pmt = NULL;
518  h_pmt_distribution_triggered_hits = NULL;
519  h_tot_distribution_triggered_hits = NULL;
520  h_pmt_distribution_snapshot_hits = NULL;
521  h_tot_distribution_snapshot_hits = NULL;
522  }
523 
524  /*
525  * Initializes the histograms.
526  * \param du_ids The list of du ids in the detector
527  * \param frame_index_range The range of frame indices
528  * \param modules_per_string The number of modules in a string.
529  */
530  void initialize(std::set<int> & du_ids , int modules_per_string){
531 
532  init_h_Trigger_bit_event ();
533  init_h_Trigger_bit_hit ();
534  init_h_Snapshot_hits ();
535  init_h_Triggered_hits ();
536  init_h_Triggered_hits_3dmuon ();
537  init_h_Triggered_hits_3dmuon_per_module (modules_per_string , du_ids);
538  init_h_Triggered_over_Snapshot_hits ();
539  init_h_Number_of_overlays ();
540  init_h_Snapshot_hits_per_module (modules_per_string , du_ids);
541  init_h_Triggered_hits_per_module (modules_per_string , du_ids);
542  init_m_Snapshot_hits_per_pmt (modules_per_string);
543  init_h_pmt_distribution_triggered_hits ();
544  init_h_tot_distribution_triggered_hits ();
545  init_h_pmt_distribution_snapshot_hits ();
546  init_h_tot_distribution_snapshot_hits ();
547  }
548 
549  /*
550  * Initializes the histogram.
551  */
553 
554  string name = MAKE_STRING ("h_Trigger_bit_event");
555  string title = MAKE_STRING ("Number of events as a function of trigger bit in event ; Trigger Bit ; Counts ");
556 
557  h_Trigger_bit_event = new TH1D (name.c_str() , title.c_str() , NUMBER_OF_TRIGGER_BITS , -0.5, NUMBER_OF_TRIGGER_BITS - 0.5 );
558 
559  for (int i = 0 ; i < (int) NUMBER_OF_TRIGGER_BITS ; i++){
560 
561  if (getTriggerName(i)){
562 
563  h_Trigger_bit_event -> GetXaxis() -> SetBinLabel(i+1 , getTriggerName(i) );
564 
565  }else{
566 
567  h_Trigger_bit_event -> GetXaxis() -> SetBinLabel(i+1 , "" );
568  }
569  }
570 
571  h_Trigger_bit_event -> GetXaxis() -> LabelsOption("v");
572  }
573 
574 
575  /*
576  * Initializes the histogram.
577  */
579 
580  string name = MAKE_STRING ("h_Trigger_bit_hit");
581  string title = MAKE_STRING ("Number of hits per event as a function of trigger bit in hit ; Trigger Bit ; #Events ");
582 
583  h_Trigger_bit_hit = new TH1D (name.c_str() , title.c_str() , NUMBER_OF_TRIGGER_BITS, -0.5, NUMBER_OF_TRIGGER_BITS - 0.5 );
584 
585  for (int i = 0 ; i < (int) NUMBER_OF_TRIGGER_BITS ; i++){
586 
587  if (getTriggerName(i)){
588 
589  h_Trigger_bit_hit -> GetXaxis() -> SetBinLabel(i+1 , getTriggerName(i) );
590  }else{
591 
592  h_Trigger_bit_hit -> GetXaxis() -> SetBinLabel(i+1 , "" );
593  }
594  }
595 
596  h_Trigger_bit_hit -> GetXaxis() -> LabelsOption("v");
597  }
598 
599 
600  /*
601  * Initializes the histogram.
602  */
604 
605  string name = MAKE_STRING ("h_Snapshot_hits");
606  string title = MAKE_STRING (" ; Number of snapshot hits; Events ");
607 
608  h_Snapshot_hits = new TH1D (name.c_str() , title.c_str() , 50, 0, 4 );
609 
610  BinLogX (h_Snapshot_hits);
611  }
612 
613  /*
614  * Initializes the histogram.
615  */
617 
618  string name = MAKE_STRING ("h_Triggered_hits");
619  string title = MAKE_STRING (" ; Number of triggered hits; Events ");
620 
621  h_Triggered_hits = new TH1D (name.c_str() , title.c_str() , 50 , 0, 4 );
622 
623  BinLogX (h_Triggered_hits);
624  }
625 
626  /*
627  * Initializes the histogram.
628  */
630 
631  string name = MAKE_STRING ("h_Triggered_hits_3dmuon");
632  string title = MAKE_STRING (" ; Number of triggered hits for JTRIGGER3DMUON; Events ");
633 
634  h_Triggered_hits_3dmuon = new TH1D (name.c_str() , title.c_str() , 50 , 0, 3 );
635 
636  BinLogX (h_Triggered_hits_3dmuon);
637  }
638 
639  /*
640  * Initializes the histogram.
641  */
642  void init_h_Triggered_hits_3dmuon_per_module (int modules_per_string , std::set<int> & du_ids){
643 
644  string name = MAKE_STRING ("h_Triggered_hits_3dmuon_per_module");
645  string title = MAKE_STRING ("Number of triggered hits for JTRIGGER3DMUON; String ; Floor ; Number of JTRIGGER3DMUON hits");
646 
647  h_Triggered_hits_3dmuon_per_module = new TH2D (name.c_str() , title.c_str() , *du_ids.rbegin() , 0.5 , *du_ids.rbegin() + 0.5 , modules_per_string , 0.5 , modules_per_string + 0.5 );
648  }
649 
650 
651  /*
652  * Initializes the histogram.
653  */
655 
656  string name = MAKE_STRING ("h_Triggered_over_Snapshot_hits");
657  string title = MAKE_STRING (" ; Triggered/Snapshot hits; Events ");
658 
659  h_Triggered_over_Snapshot_hits = new TH1D (name.c_str() , title.c_str() , 100 , 0, 0.5 );
660  }
661 
662 
663  /*
664  * Initializes the histogram.
665  */
667 
668  string name = MAKE_STRING ("h_Number_of_overlays");
669  string title = MAKE_STRING (" ; Number of overlays; Events ");
670 
671  int MAX_OVERLAYS = 1000;
672 
673  h_Number_of_overlays = new TH1D (name.c_str() , title.c_str() , MAX_OVERLAYS , -0.5, MAX_OVERLAYS - 0.5 );
674  }
675 
676  /*
677  * Initializes the histogram.
678  * \param du_ids The list of du ids in the detector
679  * \param modules_per_string.
680  */
681  void init_h_Snapshot_hits_per_module(int modules_per_string , std::set<int> & du_ids){
682 
683  string name = MAKE_STRING ("h_Snapshot_hits_per_module");
684  string title = MAKE_STRING (" ; String ; Floor ; Number of snapshot hits ");
685 
686  h_Snapshot_hits_per_module = new TH2D (name.c_str() , title.c_str() ,
687  *du_ids.rbegin() , 0.5 , *du_ids.rbegin() + 0.5 ,
688  modules_per_string , 0.5 , modules_per_string + 0.5 );
689  }
690 
691  /*
692  * Initializes the histogram.
693  * \param du_ids The list of du ids in the detector
694  * \param modules_per_string.
695  */
696  void init_h_Triggered_hits_per_module(int modules_per_string , std::set<int> & du_ids){
697 
698  string name = MAKE_STRING ("h_Triggered_hits_per_module");
699  string title = MAKE_STRING (" ; String ; Floor ; Number of triggered hits ");
700 
701  h_Triggered_hits_per_module = new TH2D (name.c_str() , title.c_str() ,
702  *du_ids.rbegin() , 0.5 , *du_ids.rbegin() + 0.5 ,
703  modules_per_string , 0.5 , modules_per_string + 0.5 );
704  }
705 
706  /*
707  * Initializes the histogram.
708  *
709  * \param modules_per_string The number of modules in a string.
710  */
711  void init_m_Snapshot_hits_per_pmt(int modules_per_string){
712 
713  string name = MAKE_STRING ("%/h_Snapshot_hits_per_pmt");
714  string title = MAKE_STRING (" ; TDC Channel ; Floor ; Number of snapshot hits ");
715 
716  m_Snapshot_hits_per_pmt = new JManager < string , TH2D > ( new TH2D (name.c_str() , title.c_str() , NUMBER_OF_PMTS , -0.5 , NUMBER_OF_PMTS - 0.5 ,
717  modules_per_string , 0.5 , modules_per_string + 0.5 ) );
718  }
719 
720  /*
721  * Initializes the histogram.
722  *
723  * \param detector A JDetector.
724  */
726 
727  string name = MAKE_STRING ("h_pmt_distribution_triggered_hits");
728  string title = MAKE_STRING (" ; TDC Channel ; Counts [a.u.]");
729 
730  h_pmt_distribution_triggered_hits = new TH1D (name.c_str() , title.c_str() , NUMBER_OF_PMTS , -0.5 , NUMBER_OF_PMTS - 0.5);
731  }
732 
733  /*
734  * Initializes the histogram.
735  */
737 
738  string name = MAKE_STRING ("h_tot_distribution_triggered_hits");
739  string title = MAKE_STRING (" ; ToT [ns] ; Counts [a.u.]");
740 
741  h_tot_distribution_triggered_hits = new TH1D (name.c_str() , title.c_str() , nbinsToT , binsToT);
742 
743  }
744 
745  /*
746  * Initializes the histogram.
747  */
749 
750  string name = MAKE_STRING ("h_pmt_distribution_snapshot_hits");
751  string title = MAKE_STRING (" ; TDC Channel ; Counts [a.u.]");
752 
753  h_pmt_distribution_snapshot_hits = new TH1D (name.c_str() , title.c_str() , NUMBER_OF_PMTS , -0.5 , NUMBER_OF_PMTS - 0.5);
754 
755  }
756 
757  /*
758  * Initializes the histogram.
759  */
761 
762  string name = MAKE_STRING ("h_tot_distribution_snapshot_hits");
763  string title = MAKE_STRING (" ; ToT [ns] ; Counts [a.u.]");
764 
765  h_tot_distribution_snapshot_hits = new TH1D (name.c_str() , title.c_str() , nbinsToT , binsToT);
766 
767  }
768 };
769 
770 /*
771  * Class to manage the histograms produced by JRunAnalyzer.
772  */
774 
775 public:
776 
782 
784 
786 
787  du_ids = getStringIDs(detector);
788  modules_per_string = JDETECTOR::getNumberOfModules (detector) / getNumberOfStrings (detector);
789  h_summary = SummaryHistograms();
790  h_timeslice = TimesliceHistograms();
791  h_trigger = TriggerHistograms ();
792  }
793 
794  /*
795  * Initializes summary slice histograms.
796  *
797  * \param range The range of values for the summary slice indices in the run. The range of some histograms is based on the number of time slices, and their indices.
798  */
800 
801  h_summary.initialize(du_ids , modules_per_string);
802 
803  }
804 
805  /*
806  * Initializes summary slice histograms.
807  *
808  * \param range The range of values for the summary slice indices in the run. The range of some histograms is based on the number of time slices, and their indices.
809  */
810  template <class T>
812 
814  const string prefix = "KM3NETDAQ::JDAQ" ;
815  string ts_name = T::Class_Name();
816  string::size_type pos = ts_name.find(prefix);
817 
818  if (pos != string::npos) ts_name.replace(ts_name.find(prefix) , prefix.length() , "");
819 
820  h_timeslice.initialize(du_ids , modules_per_string , index , ts_name);
821  }
822 
823  /*
824  * Initializes JDAQEvent histograms.
825  */
827 
828  h_trigger.initialize (du_ids , modules_per_string);
829  }
830 
831  /*
832  * Checks if the histograms in a table have been initialized. If yes, it writes them on the indicated directory of a root file
833  *
834  * \param f The root file
835  * \param dirname The directory where the histograms will be written
836  * \param table A vector of histograms.
837  */
838  template <class T>
839  void Write_histogram_table_to_file(TFile & f , string dirname , vector < vector < T* > > table){
840 
841  if(f.GetDirectory(dirname.c_str()) == 0) f.mkdir (dirname.c_str());
842 
843  f.cd (dirname.c_str());
844 
845  for (int i=0 ; i < (int)table.size(); i++){
846 
847  for (int j=0 ; j< (int)table[i].size(); j++){
848 
849  if (table[i][j]) table [i][j] -> Write();
850  }
851  }
852  }
853 
854  /*
855  * Checks if the histograms in a table have been initialized. If yes, it writes them on the indicated directory of a root file
856  *
857  * \param f The root file
858  * \param dirname The directory where the histograms will be written
859  * \param table A vector of histograms.
860  */
861  template <class T>
862  void Write_histogram_table_to_file(TFile & f , string dirname , vector < T* > table){
863 
864  if(f.GetDirectory(dirname.c_str()) == 0) f.mkdir (dirname.c_str());
865 
866  f.cd (dirname.c_str());
867 
868  for (int i=0 ; i < (int)table.size(); i++){
869 
870  if (table[i]) table[i] -> Write();
871  }
872  }
873 
874  /*
875  * Checks if the histograms in a table have been initialized. If yes, it writes them on the indicated directory of a root file
876  *
877  * \param f The root file
878  * \param dirname The directory where the histograms will be written
879  * \param table A vector of histograms.
880  */
881  template <class T , class V>
882  void Write_manager_to_file(TFile & f , string dirname , JManager < T , V >* table){
883 
884  if(f.GetDirectory(dirname.c_str()) == 0) f.mkdir (dirname.c_str());
885 
886  f.cd (dirname.c_str());
887 
888  for (typename JManager < T , V >::const_iterator i = table -> begin() ; i != table -> end() ; ++i){
889 
890  i -> second -> Write();
891  }
892  }
893 
894  /*
895  * Replaces wildcard in manager objects titles by their keys.
896  * \param A manager.
897  * \param wc The wildcard
898  */
899  template <class T , class V>
900  void Replace_wildcard_in_name(JManager < T , V >* manager , char wc = '%'){
901 
902  for (typename JManager < T , V >::const_iterator i = manager -> begin() ; i != manager -> end() ; ++i){
903 
904  if (i -> second -> GetTitle()){
905 
906  std::string buffer = i -> second -> GetTitle();
907  string::size_type ipos = buffer.find(wc);
908 
909  if (ipos!=std::string::npos){
910 
911  ostringstream os;
912 
913  os << i -> first ;
914 
915  buffer.replace(ipos, 1, os.str());
916 
917  i -> second -> SetTitle(buffer.c_str());
918  }
919  }
920  }
921  }
922 
923  /*
924  * Writes the contents of a JManager into a file. Each object in each will be written in a directory specified by its key.
925  * \param f The root file
926  * \param A manager.
927  */
928  template < class T , class V >
929  void Write_manager_in_key_dir(TFile & f ,JManager <T , V>* manager){
930 
931  for (typename JManager < T , V >::const_iterator i = manager -> begin() ; i != manager -> end() ; ++i){
932 
933  std::string fullpath = MAKE_STRING(i->second->GetName());
934 
935  int pos = fullpath.rfind ('/');
936  std::string name = fullpath.substr (pos + 1);
937  std::string path = fullpath.substr (0 , pos);
938 
939  if (f.GetDirectory(path.c_str()) == 0) f.mkdir (path.c_str());
940 
941  f.cd(path.c_str());
942 
943  i -> second -> SetName(name.c_str());
944  i -> second -> Write();
945  }
946  }
947 
948  /*
949  * Writes the contents of a vector of JManager objects into a file. Each object in each will be written in a directory specified by its key.
950  * \param f The root file
951  * \param table the list of JManager objects.
952  */
953  template < class T , class V >
955 
956  for (typename vector < JManager < T , V >* >::const_iterator i = table.begin() ; i != table.end() ; ++i){
957 
958  if ((*i)){
959 
960  for (typename JManager < T , V >::const_iterator j = (*i) -> begin() ; j != (*i) -> end() ; ++j){
961 
962  std::string fullpath = MAKE_STRING(j-> second -> GetName());
963 
964  int pos = fullpath.rfind ('/');
965  std::string name = fullpath.substr (pos + 1);
966  std::string path = fullpath.substr (0 , pos);
967 
968  if (f.GetDirectory(path.c_str()) == 0) f.mkdir (path.c_str());
969 
970  f.cd(path.c_str());
971 
972  j -> second -> SetName(name.c_str());
973  j -> second -> Write();
974  }
975  }
976  }
977  }
978 
979  /*
980  * Writes the histograms to a root file.
981  * \param f The root file.
982  */
983  void Write_to_file(TFile & f){
984 
985  f.mkdir("Detector");
986  f .cd("Detector");
987 
988  if (h_summary.h_fifo_per_dom) h_summary.h_fifo_per_dom -> Write();
989  if (h_summary.h_daq_status_per_dom) h_summary.h_daq_status_per_dom -> Write();
990  if (h_summary.h_hrv_per_dom) h_summary.h_hrv_per_dom -> Write();
991  if (h_summary.h_rate_summary) h_summary.h_rate_summary -> Write();
992  if (h_summary.h_pmt_rate_distribution) h_summary.h_pmt_rate_distribution -> Write();
993  if (h_summary.h_dom_rate_distribution) h_summary.h_dom_rate_distribution -> Write();
994 
995  Write_histogram_table_to_file(f , MAKE_STRING("Detector"), h_timeslice.h_dom_mean_rates);
996 
997  for (typename vector < JManager < string , TH2D >* >::const_iterator i = h_timeslice.m_pmt_tot_distributions.begin() ; i != h_timeslice.m_pmt_tot_distributions.end() ; ++i){
998 
999  if ((*i)){
1000 
1001  for (typename JManager < string , TH2D >::const_iterator j = (*i) -> begin() ; j != (*i) -> end() ; ++j){
1002 
1003  for(int k=1 ; k < j -> second -> GetNbinsX() ; ++k){
1004 
1005  for(int t=1 ; t < j -> second -> GetNbinsY() ; ++t){
1006 
1007  double width = j -> second -> GetYaxis() -> GetBinWidth(t);
1008 
1009  j -> second -> SetBinContent(k,t,j -> second -> GetBinContent(k,t) / width);
1010  j -> second -> SetBinError(k,t,j -> second -> GetBinError(k,t) / width);
1011  }
1012  }
1013  }
1014  }
1015  }
1016 
1017  Write_manager_table_in_key_dir (f , h_timeslice.m_pmt_tot_distributions);
1018  Write_manager_table_in_key_dir (f , h_timeslice.m_pmt_rate_distributions);
1019  if (h_summary.m_summary_rate_distribution) Write_manager_in_key_dir (f , h_summary.m_summary_rate_distribution);
1020 
1021  if (h_summary.m_mean_summary_rate) Write_manager_in_key_dir( f , h_summary.m_mean_summary_rate);
1022  if (h_summary.m_mean_summary_rate_distribution) Write_manager_in_key_dir( f , h_summary.m_mean_summary_rate_distribution);
1023 
1024  h_timeslice.Fill_mean_ToT_histograms();
1025 
1026  Write_manager_table_in_key_dir (f , h_timeslice.m_mean_ToT);
1027  Write_manager_table_in_key_dir (f , h_timeslice.m_mean_ToT_distribution);
1028 
1029  f.mkdir ( MAKE_STRING ("JDAQEvent").c_str());
1030  f.cd ("JDAQEvent");
1031 
1032  if (h_trigger.h_Trigger_bit_event) h_trigger.h_Trigger_bit_event -> Write();
1033  if (h_trigger.h_Trigger_bit_hit) h_trigger.h_Trigger_bit_hit -> Write();
1034  if (h_trigger.h_Triggered_hits) h_trigger.h_Triggered_hits -> Write();
1035  if (h_trigger.h_Triggered_hits_3dmuon) h_trigger.h_Triggered_hits_3dmuon -> Write();
1036  if (h_trigger.h_Triggered_hits_3dmuon_per_module) h_trigger.h_Triggered_hits_3dmuon_per_module -> Write();
1037  if (h_trigger.h_Snapshot_hits) h_trigger.h_Snapshot_hits -> Write();
1038  if (h_trigger.h_Triggered_over_Snapshot_hits) h_trigger.h_Triggered_over_Snapshot_hits -> Write();
1039  if (h_trigger.h_Number_of_overlays) h_trigger.h_Number_of_overlays -> Write();
1040  if (h_trigger.h_pmt_distribution_triggered_hits) {h_trigger.h_pmt_distribution_triggered_hits -> Write();}
1041  if (h_trigger.h_pmt_distribution_snapshot_hits) {h_trigger.h_pmt_distribution_snapshot_hits -> Write();}
1042  if (h_trigger.h_tot_distribution_triggered_hits) {normalizeBW1D (h_trigger.h_tot_distribution_triggered_hits) ; h_trigger.h_tot_distribution_triggered_hits-> Write();}
1043  if (h_trigger.h_tot_distribution_snapshot_hits) {normalizeBW1D (h_trigger.h_tot_distribution_snapshot_hits) ; h_trigger.h_tot_distribution_snapshot_hits -> Write();}
1044  if (h_trigger.h_Triggered_hits_per_module) { h_trigger.h_Triggered_hits_per_module-> Write();}
1045  if (h_trigger.h_Snapshot_hits_per_module) { h_trigger.h_Snapshot_hits_per_module -> Write();}
1046  if (h_trigger.m_Snapshot_hits_per_pmt) Write_manager_in_key_dir(f , h_trigger.m_Snapshot_hits_per_pmt);
1047  }
1048 };
1049 
1050 #endif
TH1D * h_pmt_distribution_snapshot_hits
void init_h_dom_mean_rates(int ts_type, std::set< int > du_ids, int modules_per_string, std::string ts_name)
TH2D * h_Snapshot_hits_per_module
std::set< int > du_ids
then fatal No hydrophone data file $HYDROPHONE_TXT fi sort gr k
void init_h_rate_summary(set< int > &du_ids, int modules_per_string)
void init_h_fifo_per_dom(std::set< int > &du_ids, int modules_per_string)
ROOT TTree parameter settings of various packages.
static const unsigned int NUMBER_OF_TRIGGER_BITS
Number of trigger bits.
TH1D * h_pmt_distribution_triggered_hits
vector< JManager< string, TH2D > * > m_pmt_tot_distributions
JManager< string, TH1D > * m_mean_summary_rate_distribution
void Write_histogram_table_to_file(TFile &f, string dirname, vector< T * > table)
vector< TH2D * > h_dom_mean_rates
void init_h_Trigger_bit_event()
void init_h_Triggered_hits_per_module(int modules_per_string, std::set< int > &du_ids)
TH2D * h_Triggered_hits_per_module
Detector data structure.
Definition: JDetector.hh:89
void init_h_Snapshot_hits_per_module(int modules_per_string, std::set< int > &du_ids)
std::set< int > getStringIDs(const JDetector &detector)
Get list of strings identifiers.
void initialize(std::set< int > &du_ids, int modules_per_string)
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
o $QUALITY_ROOT d $DEBUG!JPlot1D f
Definition: JDataQuality.sh:66
void init_h_Triggered_hits_3dmuon()
void init_h_Triggered_over_Snapshot_hits()
void initialize(std::set< int > &du_ids, int modules_per_string)
data_type r[M+1]
Definition: JPolint.hh:742
Dynamic ROOT object management.
void initialize_summary_histograms()
JManager< string, TH2D > * m_mean_summary_rate
void init_m_mean_ToT_distribution(int ts_type, string ts_name)
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
TH1D * h_dom_rate_distribution
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:142
Length of type list.
Definition: JTypeList.hh:176
void init_h_pmt_distribution_snapshot_hits()
void Write_to_file(TFile &f)
void init_m_summary_rate_distribution()
void init_h_tot_distribution_triggered_hits()
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
TimesliceHistograms h_timeslice
Detector file.
Definition: JHead.hh:224
void BinLogY(T *h)
void init_m_mean_summary_rate(int modules_per_string)
TH1D * h_tot_distribution_snapshot_hits
void init_h_Number_of_overlays()
TriggerHistograms h_trigger
do set_variable OUTPUT_DIRECTORY $WORKDIR T
void Replace_wildcard_in_name(JManager< T, V > *manager, char wc= '%')
void Write_manager_table_in_key_dir(TFile &f, vector< JManager< T, V > * > table)
Support methods.
JRA_Histograms(const JDetector &detector)
void init_m_pmt_rate_distributions(int ts_type, string ts_name)
TH1D * h_pmt_rate_distribution
void init_h_Triggered_hits_3dmuon_per_module(int modules_per_string, std::set< int > &du_ids)
$WORKDIR driver txt done cat $WORKDIR driver txt<< EOFprocess ${DATAFILTER}$FILTER_HOST csh-c '(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&(JDataFilter-H\$SERVER\$-M\$LOGGER\$-d $DEBUG-u ${DATAFILTER}-P $PORT</dev/null > &/dev/null &))';process ${DATAWRITER}$WRITER_HOST csh-c '(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&(JDataWriter-H\$SERVER\$-M\$LOGGER\$-d $DEBUG-u ${DATAWRITER}</dev/null > &/dev/null &))';print enterevent ev_init{RC_CMD}event ev_reset{RC_CMD}event ev_init{RC_CMD}event ev_configure{RC_DFLTR%<$WORKDIR/ev_configure_datafilter.txt > RC_DOM<$WORKDIR/ev_configure_domsimulator.txt > RC_DWRT path
void Write_histogram_table_to_file(TFile &f, string dirname, vector< vector< T * > > table)
then JConvertDetectorFormat a $DETECTOR[1] o
static const JStringCounter getNumberOfStrings
Function object to count unique strings.
void init_m_Snapshot_hits_per_pmt(int modules_per_string)
vector< JManager< string, TH1D > * > m_mean_ToT_distribution
SummaryHistograms h_summary
Direct access to module in detector data structure.
void init_m_mean_ToT(int ts_type, int modules_per_string, string ts_name)
void init_h_dom_rate_distribution()
void BinLogX(TH1 *h)
Definition: JDomAnalyser.cc:34
JManager< string, TH2D > * m_summary_rate_distribution
const char * getTriggerName(JTriggerbit_t bit)
Get trigger name.
void Write_manager_in_key_dir(TFile &f, JManager< T, V > *manager)
General purpose string class.
Definition: JHead.hh:150
std::string to_string(const T &value)
Convert value to string.
vector< JManager< string, TH2D > * > m_mean_ToT
vector< JManager< string, TH2D > * > m_pmt_rate_distributions
void init_h_tot_distribution_snapshot_hits()
TH1D * h_tot_distribution_triggered_hits
void init_h_pmt_distribution_triggered_hits()
TH1D * h_Triggered_hits_3dmuon
void normalizeBW1D(TH1D *h)
void initialize(std::set< int > du_ids, int modules_per_string, int ts_type, std::string ts_name)
void init_m_mean_summary_rate_distribution()
int j
Definition: JPolint.hh:666
double binsToT[]
Setting of trigger bits.
TH2D * h_Triggered_hits_3dmuon_per_module
int nbinsToT
Indexing of data type in type list.
Definition: JTypeList.hh:310
KM3NeT DAQ constants, bit handling, etc.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
void init_h_daq_status_per_dom(std::set< int > &du_ids, int modules_per_string)
int getNumberOfModules(const JDetector &detector)
Get number of modules.
void initialize_trigger_histograms()
void init_h_hrv_per_dom(set< int > &du_ids, int modules_per_string)
JManager< string, TH2D > * m_Snapshot_hits_per_pmt
void initialize_timeslice_histograms()
void Write_manager_to_file(TFile &f, string dirname, JManager< T, V > *table)
TH1D * h_Triggered_over_Snapshot_hits
void init_h_pmt_rate_distribution()
void init_m_pmt_tot_distributions(int ts_type, string ts_name)