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