Jpp  15.0.1-rc.1-highQE
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
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 ");
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 with at least 1 PMT 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() , 40 , 0 , log10(1000));
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(50000));
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 
491 
492  /* One histogram per DU*/
493 
495 
500 
501  /*
502  * Constructor
503  */
505  h_Trigger_bit_event = NULL;
506  h_Trigger_bit_hit = NULL;
507  h_Trigger_time = NULL;
508  h_Snapshot_hits = NULL;
509  h_Triggered_hits = NULL;
510  h_Number_of_overlays = NULL;
511  h_Snapshot_hits_per_module = NULL;
512  h_Triggered_hits_per_module = NULL;
513  m_Snapshot_hits_per_pmt = NULL;
514  h_pmt_distribution_triggered_hits = NULL;
515  h_tot_distribution_triggered_hits = NULL;
516  h_pmt_distribution_snapshot_hits = NULL;
517  h_tot_distribution_snapshot_hits = NULL;
518  }
519 
520  /*
521  * Initializes the histograms.
522  * \param du_ids The list of du ids in the detector
523  * \param frame_index_range The range of frame indices
524  * \param modules_per_string The number of modules in a string.
525  */
526  void initialize(std::set<int> & du_ids , int modules_per_string){
527 
528  init_h_Trigger_bit_event ();
529  init_h_Trigger_bit_hit ();
530  init_h_Trigger_time ();
531  init_h_Snapshot_hits ();
532  init_h_Triggered_hits ();
533  init_h_Number_of_overlays ();
534  init_h_Snapshot_hits_per_module (modules_per_string , du_ids);
535  init_h_Triggered_hits_per_module (modules_per_string , du_ids);
536  init_m_Snapshot_hits_per_pmt (modules_per_string);
537  init_h_pmt_distribution_triggered_hits();
538  init_h_tot_distribution_triggered_hits();
539  init_h_pmt_distribution_snapshot_hits ();
540  init_h_tot_distribution_snapshot_hits ();
541  }
542 
543  /*
544  * Initializes the histogram.
545  */
547 
548  string name = MAKE_STRING ("h_Trigger_bit_event");
549  string title = MAKE_STRING ("Number of events as a function of trigger bit in event ; Trigger Bit ; Counts ");
550 
551  h_Trigger_bit_event = new TH1D (name.c_str() , title.c_str() , NUMBER_OF_TRIGGER_BITS , -0.5, NUMBER_OF_TRIGGER_BITS - 0.5 );
552 
553  for (int i = 0 ; i < (int) NUMBER_OF_TRIGGER_BITS ; i++){
554 
555  if (getTriggerName(i)){
556 
557  h_Trigger_bit_event -> GetXaxis() -> SetBinLabel(i+1 , getTriggerName(i) );
558 
559  }else{
560 
561  h_Trigger_bit_event -> GetXaxis() -> SetBinLabel(i+1 , "" );
562  }
563  }
564 
565  h_Trigger_bit_event -> GetXaxis() -> LabelsOption("v");
566  }
567 
568 
569  /*
570  * Initializes the histogram.
571  */
573 
574  string name = MAKE_STRING ("h_Trigger_bit_hit");
575  string title = MAKE_STRING ("Number of hits per event as a function of trigger bit in hit ; Trigger Bit ; #Events ");
576 
577  h_Trigger_bit_hit = new TH1D (name.c_str() , title.c_str() , NUMBER_OF_TRIGGER_BITS, -0.5, NUMBER_OF_TRIGGER_BITS - 0.5 );
578 
579  for (int i = 0 ; i < (int) NUMBER_OF_TRIGGER_BITS ; i++){
580 
581  if (getTriggerName(i)){
582 
583  h_Trigger_bit_hit -> GetXaxis() -> SetBinLabel(i+1 , getTriggerName(i) );
584  }else{
585 
586  h_Trigger_bit_hit -> GetXaxis() -> SetBinLabel(i+1 , "" );
587  }
588  }
589 
590  h_Trigger_bit_hit -> GetXaxis() -> LabelsOption("v");
591  }
592 
593 
594  /*
595  * Initializes the histogram.
596  */
598 
599  string name = MAKE_STRING ("h_Trigger_time");
600  string title = MAKE_STRING ("Time of first triggered hit ; time [ms] ; #Events ");
601 
602  h_Trigger_time = new TH1D (name.c_str() , title.c_str() , 50, -0.5, 100.5 );
603 
604  }
605 
606  /*
607  * Initializes the histogram.
608  */
610 
611  string name = MAKE_STRING ("h_Snapshot_hits");
612  string title = MAKE_STRING (" ; Number of snapshot hits; Events ");
613 
614  h_Snapshot_hits = new TH1D (name.c_str() , title.c_str() , 50, 0, 4 );
615 
616  BinLogX (h_Snapshot_hits);
617  }
618 
619  /*
620  * Initializes the histogram.
621  */
623 
624  string name = MAKE_STRING ("h_Triggered_hits");
625  string title = MAKE_STRING (" ; Number of triggered hits; Events ");
626 
627  h_Triggered_hits = new TH1D (name.c_str() , title.c_str() , 50 , 0, 4 );
628 
629  BinLogX (h_Triggered_hits);
630  }
631 
632  /*
633  * Initializes the histogram.
634  */
636 
637  string name = MAKE_STRING ("h_Number_of_overlays");
638  string title = MAKE_STRING (" ; Number of overlays; Events ");
639 
640  int MAX_OVERLAYS = 1000;
641 
642  h_Number_of_overlays = new TH1D (name.c_str() , title.c_str() , MAX_OVERLAYS , -0.5, MAX_OVERLAYS - 0.5 );
643  }
644 
645  /*
646  * Initializes the histogram.
647  * \param du_ids The list of du ids in the detector
648  * \param modules_per_string.
649  */
650  void init_h_Snapshot_hits_per_module(int modules_per_string , std::set<int> & du_ids){
651 
652  string name = MAKE_STRING ("h_Snapshot_hits_per_module");
653  string title = MAKE_STRING (" ; String ; Floor ; Number of snapshot hits ");
654 
655  h_Snapshot_hits_per_module = new TH2D (name.c_str() , title.c_str() ,
656  *du_ids.rbegin() , 0.5 , *du_ids.rbegin() + 0.5 ,
657  modules_per_string , 0.5 , modules_per_string + 0.5 );
658  }
659 
660  /*
661  * Initializes the histogram.
662  * \param du_ids The list of du ids in the detector
663  * \param modules_per_string.
664  */
665  void init_h_Triggered_hits_per_module(int modules_per_string , std::set<int> & du_ids){
666 
667  string name = MAKE_STRING ("h_Triggered_hits_per_module");
668  string title = MAKE_STRING (" ; String ; Floor ; Number of triggered hits ");
669 
670  h_Triggered_hits_per_module = new TH2D (name.c_str() , title.c_str() ,
671  *du_ids.rbegin() , 0.5 , *du_ids.rbegin() + 0.5 ,
672  modules_per_string , 0.5 , modules_per_string + 0.5 );
673  }
674 
675  /*
676  * Initializes the histogram.
677  *
678  * \param modules_per_string The number of modules in a string.
679  */
680  void init_m_Snapshot_hits_per_pmt(int modules_per_string){
681 
682  string name = MAKE_STRING ("%/h_Snapshot_hits_per_pmt");
683  string title = MAKE_STRING (" ; TDC Channel ; Floor ; Number of snapshot hits ");
684 
685  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 ,
686  modules_per_string , 0.5 , modules_per_string + 0.5 ) );
687  }
688 
689  /*
690  * Initializes the histogram.
691  *
692  * \param detector A JDetector.
693  */
695 
696  string name = MAKE_STRING ("h_pmt_distribution_triggered_hits");
697  string title = MAKE_STRING (" ; TDC Channel ; Counts [a.u.]");
698 
699  h_pmt_distribution_triggered_hits = new TH1D (name.c_str() , title.c_str() , NUMBER_OF_PMTS , -0.5 , NUMBER_OF_PMTS - 0.5);
700  }
701 
702  /*
703  * Initializes the histogram.
704  */
706 
707  string name = MAKE_STRING ("h_tot_distribution_triggered_hits");
708  string title = MAKE_STRING (" ; ToT [ns] ; Counts [a.u.]");
709 
710  h_tot_distribution_triggered_hits = new TH1D (name.c_str() , title.c_str() , nbinsToT , binsToT);
711 
712  }
713 
714  /*
715  * Initializes the histogram.
716  */
718 
719  string name = MAKE_STRING ("h_pmt_distribution_snapshot_hits");
720  string title = MAKE_STRING (" ; TDC Channel ; Counts [a.u.]");
721 
722  h_pmt_distribution_snapshot_hits = new TH1D (name.c_str() , title.c_str() , NUMBER_OF_PMTS , -0.5 , NUMBER_OF_PMTS - 0.5);
723 
724  }
725 
726  /*
727  * Initializes the histogram.
728  */
730 
731  string name = MAKE_STRING ("h_tot_distribution_snapshot_hits");
732  string title = MAKE_STRING (" ; ToT [ns] ; Counts [a.u.]");
733 
734  h_tot_distribution_snapshot_hits = new TH1D (name.c_str() , title.c_str() , nbinsToT , binsToT);
735 
736  }
737 };
738 
739 /*
740  * Class to manage the histograms produced by JRunAnalyzer.
741  */
743 
744 public:
745 
751 
753 
755 
756  du_ids = getStringIDs(detector);
757  modules_per_string = JDETECTOR::getNumberOfModules (detector) / getNumberOfStrings (detector);
758  h_summary = SummaryHistograms();
759  h_timeslice = TimesliceHistograms();
760  h_trigger = TriggerHistograms ();
761  }
762 
763  /*
764  * Initializes summary slice histograms.
765  *
766  * \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.
767  */
769 
770  h_summary.initialize(du_ids , modules_per_string);
771 
772  }
773 
774  /*
775  * Initializes summary slice histograms.
776  *
777  * \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.
778  */
779  template <class T>
781 
783  const string prefix = "KM3NETDAQ::JDAQ" ;
784  string ts_name = T::Class_Name();
785  string::size_type pos = ts_name.find(prefix);
786 
787  if (pos != string::npos) ts_name.replace(ts_name.find(prefix) , prefix.length() , "");
788 
789  h_timeslice.initialize(du_ids , modules_per_string , index , ts_name);
790  }
791 
792  /*
793  * Initializes JDAQEvent histograms.
794  */
796 
797  h_trigger.initialize (du_ids , modules_per_string);
798  }
799 
800  /*
801  * Checks if the histograms in a table have been initialized. If yes, it writes them on the indicated directory of a root file
802  *
803  * \param f The root file
804  * \param dirname The directory where the histograms will be written
805  * \param table A vector of histograms.
806  */
807  template <class T>
808  void Write_histogram_table_to_file(TFile & f , string dirname , vector < vector < T* > > table){
809 
810  if(f.GetDirectory(dirname.c_str()) == 0) f.mkdir (dirname.c_str());
811 
812  f.cd (dirname.c_str());
813 
814  for (int i=0 ; i < (int)table.size(); i++){
815 
816  for (int j=0 ; j< (int)table[i].size(); j++){
817 
818  if (table[i][j]) table [i][j] -> Write();
819  }
820  }
821  }
822 
823  /*
824  * Checks if the histograms in a table have been initialized. If yes, it writes them on the indicated directory of a root file
825  *
826  * \param f The root file
827  * \param dirname The directory where the histograms will be written
828  * \param table A vector of histograms.
829  */
830  template <class T>
831  void Write_histogram_table_to_file(TFile & f , string dirname , vector < T* > table){
832 
833  if(f.GetDirectory(dirname.c_str()) == 0) f.mkdir (dirname.c_str());
834 
835  f.cd (dirname.c_str());
836 
837  for (int i=0 ; i < (int)table.size(); i++){
838 
839  if (table[i]) table[i] -> Write();
840  }
841  }
842 
843  /*
844  * Checks if the histograms in a table have been initialized. If yes, it writes them on the indicated directory of a root file
845  *
846  * \param f The root file
847  * \param dirname The directory where the histograms will be written
848  * \param table A vector of histograms.
849  */
850  template <class T , class V>
851  void Write_manager_to_file(TFile & f , string dirname , JManager < T , V >* table){
852 
853  if(f.GetDirectory(dirname.c_str()) == 0) f.mkdir (dirname.c_str());
854 
855  f.cd (dirname.c_str());
856 
857  for (typename JManager < T , V >::const_iterator i = table -> begin() ; i != table -> end() ; ++i){
858 
859  i -> second -> Write();
860  }
861  }
862 
863  /*
864  * Replaces wildcard in manager objects titles by their keys.
865  * \param A manager.
866  * \param wc The wildcard
867  */
868  template <class T , class V>
869  void Replace_wildcard_in_name(JManager < T , V >* manager , char wc = '%'){
870 
871  for (typename JManager < T , V >::const_iterator i = manager -> begin() ; i != manager -> end() ; ++i){
872 
873  if (i -> second -> GetTitle()){
874 
875  std::string buffer = i -> second -> GetTitle();
876  string::size_type ipos = buffer.find(wc);
877 
878  if (ipos!=std::string::npos){
879 
880  ostringstream os;
881 
882  os << i -> first ;
883 
884  buffer.replace(ipos, 1, os.str());
885 
886  i -> second -> SetTitle(buffer.c_str());
887  }
888  }
889  }
890  }
891 
892  /*
893  * Writes the contents of a JManager into a file. Each object in each will be written in a directory specified by its key.
894  * \param f The root file
895  * \param A manager.
896  */
897  template < class T , class V >
898  void Write_manager_in_key_dir(TFile & f ,JManager <T , V>* manager){
899 
900  for (typename JManager < T , V >::const_iterator i = manager -> begin() ; i != manager -> end() ; ++i){
901 
902  std::string fullpath = MAKE_STRING(i->second->GetName());
903 
904  int pos = fullpath.rfind ('/');
905  std::string name = fullpath.substr (pos + 1);
906  std::string path = fullpath.substr (0 , pos);
907 
908  if (f.GetDirectory(path.c_str()) == 0) f.mkdir (path.c_str());
909 
910  f.cd(path.c_str());
911 
912  i -> second -> SetName(name.c_str());
913  i -> second -> Write();
914  }
915  }
916 
917  /*
918  * 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.
919  * \param f The root file
920  * \param table the list of JManager objects.
921  */
922  template < class T , class V >
924 
925  for (typename vector < JManager < T , V >* >::const_iterator i = table.begin() ; i != table.end() ; ++i){
926 
927  if ((*i)){
928 
929  for (typename JManager < T , V >::const_iterator j = (*i) -> begin() ; j != (*i) -> end() ; ++j){
930 
931  std::string fullpath = MAKE_STRING(j-> second -> GetName());
932 
933  int pos = fullpath.rfind ('/');
934  std::string name = fullpath.substr (pos + 1);
935  std::string path = fullpath.substr (0 , pos);
936 
937  if (f.GetDirectory(path.c_str()) == 0) f.mkdir (path.c_str());
938 
939  f.cd(path.c_str());
940 
941  j -> second -> SetName(name.c_str());
942  j -> second -> Write();
943  }
944  }
945  }
946  }
947 
948  /*
949  * Writes the histograms to a root file.
950  * \param f The root file.
951  */
952  void Write_to_file(TFile & f){
953 
954  f.mkdir("Detector");
955  f .cd("Detector");
956 
957  if (h_summary.h_fifo_per_dom) h_summary.h_fifo_per_dom -> Write();
958  if (h_summary.h_daq_status_per_dom) h_summary.h_daq_status_per_dom -> Write();
959  if (h_summary.h_hrv_per_dom) h_summary.h_hrv_per_dom -> Write();
960  if (h_summary.h_rate_summary) h_summary.h_rate_summary -> Write();
961  if (h_summary.h_pmt_rate_distribution) h_summary.h_pmt_rate_distribution -> Write();
962  if (h_summary.h_dom_rate_distribution) h_summary.h_dom_rate_distribution -> Write();
963 
964  Write_histogram_table_to_file(f , MAKE_STRING("Detector/DOM_mean_rates") , h_timeslice.h_dom_mean_rates);
965 
966  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){
967 
968  if ((*i)){
969 
970  for (typename JManager < string , TH2D >::const_iterator j = (*i) -> begin() ; j != (*i) -> end() ; ++j){
971 
972  for(int k=1 ; k < j -> second -> GetNbinsX() ; ++k){
973 
974  for(int t=1 ; t < j -> second -> GetNbinsY() ; ++t){
975 
976  double width = j -> second -> GetYaxis() -> GetBinWidth(t);
977 
978  j -> second -> SetBinContent(k,t,j -> second -> GetBinContent(k,t) / width);
979  j -> second -> SetBinError(k,t,j -> second -> GetBinError(k,t) / width);
980  }
981  }
982  }
983  }
984  }
985 
986  Write_manager_table_in_key_dir (f , h_timeslice.m_pmt_tot_distributions);
987  Write_manager_table_in_key_dir (f , h_timeslice.m_pmt_rate_distributions);
988  if (h_summary.m_summary_rate_distribution) Write_manager_in_key_dir (f , h_summary.m_summary_rate_distribution);
989 
990  if (h_summary.m_mean_summary_rate) Write_manager_in_key_dir( f , h_summary.m_mean_summary_rate);
991  if (h_summary.m_mean_summary_rate_distribution) Write_manager_in_key_dir( f , h_summary.m_mean_summary_rate_distribution);
992 
993  h_timeslice.Fill_mean_ToT_histograms();
994 
995  Write_manager_table_in_key_dir (f , h_timeslice.m_mean_ToT);
996  Write_manager_table_in_key_dir (f , h_timeslice.m_mean_ToT_distribution);
997 
998  f.mkdir ( MAKE_STRING ("JDAQEvent").c_str());
999  f.cd ("JDAQEvent");
1000 
1001  if (h_trigger.h_Trigger_bit_event) h_trigger.h_Trigger_bit_event -> Write();
1002  if (h_trigger.h_Trigger_bit_hit) h_trigger.h_Trigger_bit_hit -> Write();
1003  if (h_trigger.h_Trigger_time) h_trigger.h_Trigger_time -> Write();
1004 
1005  f.mkdir (MAKE_STRING ("JDAQEvent/hits_per_event").c_str());
1006  f.cd ("JDAQEvent/hits_per_event");
1007 
1008  if (h_trigger.h_Triggered_hits) h_trigger.h_Triggered_hits -> Write();
1009  if (h_trigger.h_Snapshot_hits) h_trigger.h_Snapshot_hits -> Write();
1010  if (h_trigger.h_Number_of_overlays) h_trigger.h_Number_of_overlays -> Write();
1011 
1012  f.mkdir ( MAKE_STRING ("JDAQEvent/hits_pmt_distributions").c_str());
1013  f.cd ("JDAQEvent/hits_pmt_distributions");
1014 
1015  if (h_trigger.h_pmt_distribution_triggered_hits) {h_trigger.h_pmt_distribution_triggered_hits -> Write();}
1016  if (h_trigger.h_pmt_distribution_snapshot_hits) {h_trigger.h_pmt_distribution_snapshot_hits -> Write();}
1017 
1018  f.mkdir ( MAKE_STRING ("JDAQEvent/hits_tot_distributions").c_str());
1019  f.cd ("JDAQEvent/hits_tot_distributions");
1020 
1021  if (h_trigger.h_tot_distribution_triggered_hits) {normalizeBW1D (h_trigger.h_tot_distribution_triggered_hits) ; h_trigger.h_tot_distribution_triggered_hits-> Write();}
1022  if (h_trigger.h_tot_distribution_snapshot_hits) {normalizeBW1D (h_trigger.h_tot_distribution_snapshot_hits) ; h_trigger.h_tot_distribution_snapshot_hits -> Write();}
1023 
1024  f.cd ("JDAQEvent");
1025 
1026  if (h_trigger.h_Triggered_hits_per_module) { h_trigger.h_Triggered_hits_per_module-> Write();}
1027  if (h_trigger.h_Snapshot_hits_per_module) { h_trigger.h_Snapshot_hits_per_module -> Write();}
1028 
1029  if (h_trigger.m_Snapshot_hits_per_pmt) Write_manager_in_key_dir(f , h_trigger.m_Snapshot_hits_per_pmt);
1030  }
1031 };
1032 
1033 #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)
then JMuonPostfit f
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
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()
$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
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:196
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
do $DIR JTransitTime o
Definition: JTransitTime.sh:44
void Write_histogram_table_to_file(TFile &f, string dirname, vector< vector< T * > > table)
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:122
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()
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.
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)
void init_h_pmt_rate_distribution()
void init_m_pmt_tot_distributions(int ts_type, string ts_name)