1 #ifndef __JRUNHISTOGRAMS__
2 #define __JRUNHISTOGRAMS__
23 #include "TProfile2D.h"
26 #include "TPaveText.h"
31 #include "TDirectory.h"
33 #include "TObjArray.h"
34 #include "TObjString.h"
38 using namespace JLANG ;
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];
57 for (
int i = 0; i <= bins; i++) {
58 new_bins[i] = TMath::Power(10, from + i * width);
61 axis->Set(bins, new_bins);
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];
82 for (
int i = 0; i <= bins; i++) {
83 new_bins[i] = TMath::Power(10, from + i * width);
86 axis->Set(bins, new_bins);
101 h -> Scale(
n / h -> Integral());
125 h_fifo_per_dom = NULL;
126 h_daq_status_per_dom = NULL;
127 h_hrv_per_dom = NULL;
128 h_rate_summary = NULL;
129 h_pmt_rate_distribution = NULL;
130 h_dom_rate_distribution = NULL;
131 m_mean_summary_rate = NULL;
132 m_mean_summary_rate_distribution = NULL;
133 m_summary_rate_distribution = NULL;
141 init_h_fifo_per_dom (du_ids , modules_per_string);
142 init_h_daq_status_per_dom (du_ids , modules_per_string);
143 init_h_hrv_per_dom (du_ids , modules_per_string);
144 init_h_rate_summary (du_ids , modules_per_string);
145 init_h_pmt_rate_distribution ();
146 init_h_dom_rate_distribution ();
147 init_m_mean_summary_rate (modules_per_string);
148 init_m_mean_summary_rate_distribution ();
149 init_m_summary_rate_distribution ();
161 string title =
MAKE_STRING (
" FIFO ; String ; Floor ; Number of slices with FIFO almost full ");
163 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 );
174 string name =
MAKE_STRING (
"h_daq_status_per_dom");
175 string title =
MAKE_STRING (
" DAQ Status ; String ; Floor ; Number of slices with wrong DAQ status of packets ");
177 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 );
189 string title =
MAKE_STRING (
"HRV ; String ; Floor ; Number of slices with at least 1 PMT in HRV");
191 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 );
203 string title =
MAKE_STRING (
"Summary slices ; String ; Floor ; Mean rate over all summary slices [kHz]");
205 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 );
213 string name =
MAKE_STRING (
"h_pmt_rate_distribution");
214 string title =
MAKE_STRING (
"PMT rate distribution from summary slices ; rate [kHz] ; Counts");
216 h_pmt_rate_distribution =
new TH1D (name.c_str() , title.c_str() , 40 , 0 , log10(1000));
218 BinLogX (h_pmt_rate_distribution);
220 h_pmt_rate_distribution -> SetMinimum(1);
228 string name =
MAKE_STRING (
"h_dom_rate_distribution");
229 string title =
MAKE_STRING (
"DOM rate distribution from summary slices ; rate [kHz] ; Counts");
231 h_dom_rate_distribution =
new TH1D (name.c_str() , title.c_str() , 50 , log10(50) , log10(50000));
233 BinLogX (h_dom_rate_distribution);
235 h_dom_rate_distribution -> SetMinimum(1);
245 string name =
MAKE_STRING (
"%/h_mean_summary_rate_distribution");
246 string title =
MAKE_STRING (
" ; rate [kHz] ; # PMTs");
248 TH1D* h =
new TH1D(name.c_str() , title.c_str() , 40 , 0 , log10(1000));
262 string name =
MAKE_STRING (
"%/h_mean_summary_rate");
263 string title =
MAKE_STRING (
" ; PMT ; Floor ; rate [kHz]");
274 string name =
MAKE_STRING (
"%/h_pmt_rate_distributions_Summaryslice");
275 string title =
MAKE_STRING (
"Summaryslice ; TDC channel ; rate [kHz] ; counts");
277 TH2D* h_summary_rate_distribution =
new TH2D (name.c_str() , title.c_str(),
279 100 , -1 , log10(10000));
281 BinLogY (h_summary_rate_distribution);
325 h_dom_mean_rates .resize (number_of_timeslice_types , NULL);
326 h_ToT_255_vs_time .resize (number_of_timeslice_types , NULL);
327 h_ToT_255_Floor_vs_time .resize (number_of_timeslice_types , NULL);
328 h_ToT_255_Floor_vs_time_2.resize (number_of_timeslice_types , NULL);
329 m_mean_ToT .resize (number_of_timeslice_types , NULL);
330 m_mean_ToT_distribution .resize (number_of_timeslice_types , NULL);
331 m_ToT_255 .resize (number_of_timeslice_types , NULL);
332 m_pmt_tot_distributions .resize (number_of_timeslice_types , NULL);
333 m_pmt_rate_distributions .resize (number_of_timeslice_types , NULL);
334 m_pmt_dt_consecutive_hits.resize (number_of_timeslice_types , NULL);
347 init_h_dom_mean_rates (ts_type , du_ids , modules_per_string , ts_name);
348 init_h_ToT_255_vs_time (ts_type , ts_name);
349 init_h_ToT_255_Floor_vs_time (ts_type , modules_per_string , ts_name);
350 init_h_ToT_255_Floor_vs_time_2 (ts_type , modules_per_string , ts_name);
351 init_m_mean_ToT (ts_type , modules_per_string , ts_name);
352 init_m_mean_ToT_distribution (ts_type , ts_name);
353 init_m_ToT_255 (ts_type , modules_per_string , ts_name);
354 init_m_pmt_tot_distributions (ts_type , ts_name);
355 init_m_pmt_rate_distributions (ts_type , ts_name);
356 init_m_pmt_dt_consecutive_hits (ts_type , ts_name);
370 for (
typename vector <
JManager < string , TH2D >* >::const_iterator it = m_pmt_tot_distributions.begin() ; it != m_pmt_tot_distributions.end() ; ++it , ++i){
377 TPRegexp
r (
"(\\w+)/(\\DU)(\\d+)/(F)(\\d+)");
379 TObjArray* o =
r.MatchS(s);
381 int String = ((TObjString *)o->At(3))->GetString().Atoi();
382 int Floor = ((TObjString *)o->At(5))->GetString().Atoi();
384 for (
int pmt = 1 ; pmt <= (
j -> second) -> GetXaxis() -> GetNbins() ; pmt++){
386 (*m_mean_ToT[i])[
MAKE_STRING(
"Detector/DU" +
to_string(
String))] -> Fill(Floor , (
j->second) -> GetXaxis() -> GetBinCenter(pmt) , (
j -> second) -> ProjectionY (
"" , pmt , pmt) -> GetMean () );
387 (*m_mean_ToT_distribution[i])[
MAKE_STRING(
"Detector/DU" +
to_string(
String))] -> Fill((
j -> second) -> ProjectionY (
"" , pmt , pmt) -> GetMean () );
403 string name =
MAKE_STRING (
"h_mean_dom_rates_" + ts_name);
404 string title =
MAKE_STRING (ts_name +
" ; Floor number ; DU number ; time slice averaged rate [Hz]");
406 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);
417 string name =
MAKE_STRING (
"h_ToT_255_vs_time_" + ts_name);
418 string title =
MAKE_STRING (
" (" + ts_name +
") Hits with ToT = 255 ns. All PMTs, all timeslices ; Time since beginning of slice [ns] ; counts ");
420 h_ToT_255_vs_time[ts_type] =
new TH1D (name.c_str() , title.c_str() , 100 , 0 , log10(
getFrameTime()));
422 BinLogX (h_ToT_255_vs_time[ts_type]);
434 string name =
MAKE_STRING (
"h_ToT_255_Floor_vs_time_" + ts_name);
435 string title =
MAKE_STRING (
" (" + ts_name +
") Hits with ToT = 255 ns. All DUs , all timeslices ; Time since beginning of slice [ns] ; Floor number ; counts ");
437 h_ToT_255_Floor_vs_time[ts_type] =
new TH2D (name.c_str() , title.c_str() , 100 , 0 , log10(
getFrameTime()) , modules_per_string , 0.5 , 0.5 + modules_per_string);
439 BinLogX(h_ToT_255_Floor_vs_time[ts_type]);
451 string name =
MAKE_STRING (
"h_ToT_255_Floor_vs_time_2_" + ts_name);
452 string title =
MAKE_STRING (
" (" + ts_name +
") Hits with ToT = 255 ns. All DUs , all timeslices ; Time since beginning of slice [ns] ; Floor number ; counts ");
454 h_ToT_255_Floor_vs_time_2[ts_type] =
new TH2D (name.c_str() , title.c_str() , 100 , 0 ,
getFrameTime() , modules_per_string , 0.5 , 0.5 + modules_per_string);
466 string name =
MAKE_STRING (
"%/h_mean_ToT_" + ts_name);
467 string title =
MAKE_STRING (ts_name +
" ; Floor number ; TDC channel ; mean ToT over all timeslices [ns] ");
481 string name =
MAKE_STRING (
"%/h_mean_ToT_distribution" + ts_name);
482 string title =
MAKE_STRING (ts_name +
" ; ToT [ns] ; # PMTS ");
484 m_mean_ToT_distribution[ts_type] =
new JManager < string , TH1D > (
new TH1D (name.c_str() , title.c_str() , 255 , 0.5 , 255.5));
496 string name =
MAKE_STRING (
"%/h_ToT_255_" + ts_name);
497 string title =
MAKE_STRING (ts_name +
" ; Floor number ; TDC channel ; number of hits with ToT = 255 ns ");
510 string name =
MAKE_STRING (
"%_" + ts_name +
"_2SToT");
511 string title =
MAKE_STRING (ts_name +
" ; TDC channel ; ToT [ns] ; counts");
513 double bins[] = {-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 , 16.5 , 17.5 , 18.5 , 19.5 ,
514 20.5 , 21.5 , 22.5 , 23.5 , 24.5 , 25.5 , 26.5 , 27.5 , 28.5 , 29.5 , 30.5 , 35.5 , 40.5 , 45.5 , 55.5 , 60.5 , 65.5 , 70.5 , 75.5 , 80.5 ,
515 85.5 , 90.5 , 95.5 , 100.5 , 120.5 , 140.5 , 160.5 , 180.5 , 200.5 , 254.5 , 255.5 , 256.5};
533 string name =
MAKE_STRING (
"%/h_pmt_rate_distributions_" + ts_name);
534 string title =
MAKE_STRING (ts_name +
" ; TDC channel ; rate [kHz] ; counts ");
536 TH2D* h_pmt_rate_distributions =
new TH2D (name.c_str() , title.c_str(),
538 60 , -6 , log10(1000));
540 BinLogY (h_pmt_rate_distributions);
553 string name =
MAKE_STRING (
"%/h_dt_consecutive_hits_" + ts_name);
554 string title =
MAKE_STRING (ts_name +
" ; log(dt [ns]); TDC channel ; counts");
585 h_Trigger_bit_event = NULL;
586 h_Trigger_bit_hit = NULL;
587 h_Snapshot_hits = NULL;
588 h_Triggered_hits = NULL;
589 h_Snapshot_hits_per_module = NULL;
590 h_Triggered_hits_per_module = NULL;
591 m_Snapshot_hits_per_pmt = NULL;
592 h_pmt_distribution_triggered_hits = NULL;
593 h_tot_distribution_triggered_hits = NULL;
594 h_pmt_distribution_snapshot_hits = NULL;
595 h_tot_distribution_snapshot_hits = NULL;
606 init_h_Trigger_bit_event ();
607 init_h_Trigger_bit_hit ();
608 init_h_Snapshot_hits ();
609 init_h_Triggered_hits ();
610 init_h_Snapshot_hits_per_module (modules_per_string , du_ids);
611 init_h_Triggered_hits_per_module (modules_per_string , du_ids);
612 init_m_Snapshot_hits_per_pmt (modules_per_string);
613 init_h_pmt_distribution_triggered_hits();
614 init_h_tot_distribution_triggered_hits();
615 init_h_pmt_distribution_snapshot_hits ();
616 init_h_tot_distribution_snapshot_hits ();
625 string title =
MAKE_STRING (
"Number of events as a function of trigger bit in event ; Trigger Bit ; Counts ");
633 h_Trigger_bit_event -> GetXaxis() -> SetBinLabel(i+1 ,
getTriggerName(i) );
637 h_Trigger_bit_event -> GetXaxis() -> SetBinLabel(i+1 ,
"" );
641 h_Trigger_bit_event -> GetXaxis() -> LabelsOption(
"v");
651 string title =
MAKE_STRING (
"Number of hits per event as a function of trigger bit in hit ; Trigger Bit ; #Events ");
659 h_Trigger_bit_hit -> GetXaxis() -> SetBinLabel(i+1 ,
getTriggerName(i) );
662 h_Trigger_bit_hit -> GetXaxis() -> SetBinLabel(i+1 ,
"" );
666 h_Trigger_bit_hit -> GetXaxis() -> LabelsOption(
"v");
675 string title =
MAKE_STRING (
" ; Number of snapshot hits; Events ");
677 h_Snapshot_hits =
new TH1D (name.c_str() , title.c_str() , 50, 0, 4 );
688 string title =
MAKE_STRING (
" ; Number of triggered hits; Events ");
690 h_Triggered_hits =
new TH1D (name.c_str() , title.c_str() , 50 , 0, 4 );
702 string name =
MAKE_STRING (
"h_Snapshot_hits_per_module");
703 string title =
MAKE_STRING (
" ; String ; Floor ; Number of snapshot hits ");
705 h_Snapshot_hits_per_module =
new TH2D (name.c_str() , title.c_str() ,
706 *du_ids.rbegin() , 0.5 , *du_ids.rbegin() + 0.5 ,
707 modules_per_string , 0.5 , modules_per_string + 0.5 );
717 string name =
MAKE_STRING (
"h_Triggered_hits_per_module");
718 string title =
MAKE_STRING (
" ; String ; Floor ; Number of triggered hits ");
720 h_Triggered_hits_per_module =
new TH2D (name.c_str() , title.c_str() ,
721 *du_ids.rbegin() , 0.5 , *du_ids.rbegin() + 0.5 ,
722 modules_per_string , 0.5 , modules_per_string + 0.5 );
732 string name =
MAKE_STRING (
"%/h_Snapshot_hits_per_pmt");
733 string title =
MAKE_STRING (
" ; PMT ; Floor ; Number of snapshot hits ");
736 modules_per_string , 0.5 , modules_per_string + 0.5 ) );
746 string name =
MAKE_STRING (
"h_pmt_distribution_triggered_hits");
747 string title =
MAKE_STRING (
" ; PMT number ; Counts [a.u.]");
757 string name =
MAKE_STRING (
"h_tot_distribution_triggered_hits");
758 string title =
MAKE_STRING (
" ; ToT [ns] ; Counts [a.u.]");
760 h_tot_distribution_triggered_hits =
new TH1D (name.c_str() , title.c_str() , 255 , 0.5 , 255.5 );
769 string name =
MAKE_STRING (
"h_pmt_distribution_snapshot_hits");
770 string title =
MAKE_STRING (
" ; PMT number ; Counts [a.u.]");
781 string name =
MAKE_STRING (
"h_tot_distribution_snapshot_hits");
782 string title =
MAKE_STRING (
" ; ToT [ns] ; Counts [a.u.]");
784 h_tot_distribution_snapshot_hits =
new TH1D (name.c_str() , title.c_str() , 255 , 0.5 , 255.5 );
822 h_summary.
initialize(du_ids , modules_per_string);
835 const string prefix =
"KM3NETDAQ::JDAQ" ;
836 string ts_name = T::Class_Name();
837 string::size_type pos = ts_name.find(prefix);
839 if (pos != string::npos) ts_name.replace(ts_name.find(prefix) , prefix.length() ,
"");
841 h_timeslice.
initialize(du_ids , modules_per_string , index , ts_name);
849 h_trigger.
initialize (du_ids , modules_per_string);
862 if(f.GetDirectory(dirname.c_str()) == 0) f.mkdir (dirname.c_str());
864 f.cd (dirname.c_str());
866 for (
int i=0 ; i < (int)table.size(); i++){
868 for (
int j=0 ;
j< (int)table[i].size();
j++){
870 if (table[i][
j]) table [i][
j] -> Write();
885 if(f.GetDirectory(dirname.c_str()) == 0) f.mkdir (dirname.c_str());
887 f.cd (dirname.c_str());
889 for (
int i=0 ; i < (int)table.size(); i++){
891 if (table[i]) table[i] -> Write();
902 template <
class T ,
class V>
905 if(f.GetDirectory(dirname.c_str()) == 0) f.mkdir (dirname.c_str());
907 f.cd (dirname.c_str());
911 i -> second -> Write();
920 template <
class T ,
class V>
925 if (i -> second -> GetTitle()){
927 std::string buffer = i -> second -> GetTitle();
928 string::size_type ipos = buffer.find(wc);
930 if (ipos!=std::string::npos){
936 buffer.replace(ipos, 1, os.str());
938 i -> second -> SetTitle(buffer.c_str());
949 template <
class T ,
class V >
954 std::string fullpath =
MAKE_STRING(i->second->GetName());
956 int pos = fullpath.rfind (
'/');
957 std::string name = fullpath.substr (pos + 1);
958 std::string path = fullpath.substr (0 , pos);
960 if (f.GetDirectory(path.c_str()) == 0) f.mkdir (path.c_str());
964 i -> second -> SetName(name.c_str());
965 i -> second -> Write();
974 template <
class T ,
class V >
983 std::string fullpath =
MAKE_STRING(
j-> second -> GetName());
985 int pos = fullpath.rfind (
'/');
986 std::string name = fullpath.substr (pos + 1);
987 std::string path = fullpath.substr (0 , pos);
989 if (f.GetDirectory(path.c_str()) == 0) f.mkdir (path.c_str());
993 j -> second -> SetName(name.c_str());
994 j -> second -> Write();
1006 f.mkdir(
"Detector");
1027 for(
int k=1 ; k <
j -> second -> GetNbinsX() ; ++k){
1029 for(
int t=1 ; t <
j -> second -> GetNbinsY() ; ++t){
1031 double width =
j -> second -> GetYaxis() -> GetBinWidth(t);
1033 j -> second -> SetBinContent(k,t,
j -> second -> GetBinContent(k,t) / width);
1034 j -> second -> SetBinError(k,t,
j -> second -> GetBinError(k,t) / width);
1045 Write_manager_table_in_key_dir (f , h_timeslice.
m_ToT_255);
1052 Write_manager_table_in_key_dir (f , h_timeslice.
m_mean_ToT);
1061 f.mkdir (
MAKE_STRING (
"JDAQEvent/hits_per_event").c_str());
1062 f.cd (
"JDAQEvent/hits_per_event");
1067 f.mkdir (
MAKE_STRING (
"JDAQEvent/hits_pmt_distributions").c_str());
1068 f.cd (
"JDAQEvent/hits_pmt_distributions");
1073 f.mkdir (
MAKE_STRING (
"JDAQEvent/hits_tot_distributions").c_str());
1074 f.cd (
"JDAQEvent/hits_tot_distributions");