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