4#include "BmnRawDataDecoder.h"
19 , fTrigMapper(trigMapper)
20 , histBDAmpByChannel(nullptr)
21 , histBDChannels(nullptr)
22 , histBDSimult(nullptr)
29 , fSelectedBDChannel(-1)
31 , fLastSpillStartTS(0, 0)
34 fName = title +
"_cl";
36 const Int_t rows4Summary = 3;
38 TPRegexp re(
"TQDC_(\\S+)");
41 storeAmpTQDC.resize(arrays->size());
42 for (UInt_t iArr = 0; iArr < arrays->size(); ++iArr) {
43 TClonesArray* ar = arrays->at(iArr);
44 mapArrayNames.insert(make_pair(
string(ar->GetName()), iArr));
45 TString trName(ar->GetName());
47 if (trName.Contains(
"BD") || trName.Contains(
"SI")) {
49 for (
auto& tr : trigNames) {
50 if (!strcmp(tr.Data(), trName.Data())) {
57 trigNames.push_back(trName);
58 shortNames.push_back(trName);
59 name = fTitle +
"_" + trName +
"_Time";
61 mapTime.insert(make_pair(iArr, h));
64 name = Form(
"%s", trName.Data());
65 trigNames.push_back(name);
66 name = fTitle +
"_" + name +
"_Time";
68 mapTime.insert(make_pair(iArr, h2));
72 for (
auto& tr : shortNames) {
73 if (!strcmp(tr.Data(), trName.Data())) {
80 shortNames.push_back(trName);
83 auto itBD = mapArrayNames.find(
"BD");
84 if (itBD != mapArrayNames.end())
85 indexBD = itBD->second;
86 fRows = hists.size() / fCols + rows4Summary + (hists.size() % fCols > 0);
87 name = fTitle +
"CanvasTimesByChannel";
91 name = fTitle +
"CanvasTimes";
93 canTimes->Divide(fCols, fRows, 0.01 / fCols, 0.01 / fRows);
94 canTimesPads.resize(fCols * fRows);
95 for (Int_t iPad = 0; iPad < fRows * fCols; iPad++) {
97 canTimesPads[iPad] = p;
98 canTimes->GetPad(iPad + 1)->SetGrid();
100 name = fTitle +
"_BD_Channels";
102 histBDChannels->GetXaxis()->SetTitle(
"Channel #");
103 histBDChannels->GetYaxis()->SetTitle(
"Activation Count");
104 name = fTitle +
"_BD_Amp_by_Channels";
106 histBDAmpByChannel->GetXaxis()->SetTitle(
"Channel #");
107 histBDAmpByChannel->GetYaxis()->SetTitle(
"Amplitude, ns");
108 name = fTitle +
"_BD_Simultaneous";
110 histBDSimult->GetXaxis()->SetTitle(
"Channels #");
111 histBDSimult->GetYaxis()->SetTitle(
"Activation Count");
112 canTimesPads[1]->current = histBDChannels;
113 canTimesPads[4]->current = histBDAmpByChannel;
114 canTimesPads[4]->opt =
"colz";
115 canTimesPads[7]->current = histBDSimult;
116 for (
size_t i = 0;
i < hists.size(); ++
i) {
117 canTimesPads[
i + rows4Summary * fCols]->current = hists[
i];
118 hists[
i]->GetYaxis()->SetTitle(
"Activation Count");
119 hists[
i]->GetXaxis()->SetTitle(
"Time, ns");
121 for (
size_t iPad = 0; iPad < canTimesPads.size(); ++iPad) {
122 PadInfo* pad = canTimesPads[iPad];
138 for (
auto& pad : canProfilePads)
141 for (
auto& pad : canTimesPads)
146 for (
auto& pad : padsGridBD)
149 for (
auto& pad : padsGridND)
152 for (
auto& pad : padsTrigStates)
155 for (
auto& pad : padsCorrTQDC)
158 for (
auto& pad : padsScalers)
163void BmnHistTrigger::InitTrigMasked()
166 const vector<
string> TrigName{
"TQDC_BC1",
"TQDC_BC2",
"TQDC_FD",
"TQDC_FHCAL",
"TQDC_tFHCal",
"BD"};
170 TString canName = fTitle +
"_Trig_States";
171 const size_t TrigBitsCnt = TrigState.size();
172 const Int_t ColsStates = 2;
173 const size_t RowsStates = TrigName.size();
175 for (
auto& state : TrigState) {
176 auto it_bm = bit_map.find(
string(state.Name.Data()));
177 if (it_bm != bit_map.end()) {
178 trig_state_bit_index.push_back(it_bm->second);
182 canTrigStates = make_unique<TCanvas>(canName, canName,
PAD_WIDTH * ColsStates,
PAD_HEIGHT * RowsStates);
183 canTrigStates->Divide(ColsStates, RowsStates, 0.01 / ColsStates, 0.01 / RowsStates);
184 for (
const string& detName : TrigName) {
185 bool isTDC = (detName.find(
"BD") != string::npos) || (detName.find(
"SI") != string::npos);
186 vector<TH1*> hist_vec;
187 vector<TH1*> hist_vec_log;
188 vector<TString> hist_vec_opt;
189 vector<TString> hist_vec_opt_log;
191 Double_t l_x0 = 0.75;
195 TLegend* legend_lin =
new TLegend(l_x0, l_y0, l_x0 + l_w, l_y0 + l_h);
196 legend_lin->SetTextSize(0.08);
197 TLegend* legend_log =
new TLegend(l_x0, l_y0, l_x0 + l_w, l_y0 + l_h);
198 legend_log->SetTextSize(0.08);
200 for (
auto& state : TrigState) {
201 TString hName(fTitle +
"_" + detName +
"_" + state.Name +
"_Amp");
202 TString hTitle(detName +
"_" "_Amp");
203 TH1* h =
new TH1I(hName, hTitle,
TRIG_AMP_BINS, 0, isTDC ? MaxAmpTDC : MaxAmpTQDC);
204 legend_lin->AddEntry(h, state.Name);
206 h->GetXaxis()->SetTitle(
"Amplitude, ns");
207 h->GetYaxis()->SetTitle(
"Activation Count");
208 h->SetLineColor(state.Color);
209 TH1* h_log =
static_cast<TH1I*
>(h->Clone(TString(h->GetName()) +
"_log"));
210 legend_log->AddEntry(h_log, state.Name);
211 hist_vec.push_back(h);
212 hist_vec_log.push_back(h_log);
215 PadInfo* pad_lin =
new PadInfo(
nullptr, move(hist_vec), move(hist_vec_opt), legend_lin);
216 PadInfo* pad_log =
new PadInfo(
nullptr, move(hist_vec_log), move(hist_vec_opt_log), legend_log);
217 padsTrigStates.push_back(pad_lin);
218 padsTrigStates.push_back(pad_log);
219 auto it = mapArrayNames.find(detName);
220 if (it != mapArrayNames.end()) {
221 mapTBLin.insert(make_pair(it->second, pad_lin));
222 pad_log->
logy =
true;
223 mapTBLog.insert(make_pair(it->second, pad_log));
228 for (
auto& corrPair : TrigNameCorrTQDC) {
229 string full_name_first =
"TQDC_" + corrPair.first;
230 string full_name_second =
"TQDC_" + corrPair.second;
233 auto itf = mapArrayNames.find(full_name_first);
234 if (itf != mapArrayNames.end())
235 iFirst = itf->second;
238 auto its = mapArrayNames.find(full_name_second);
239 if (its != mapArrayNames.end())
240 iSecond = its->second;
243 idxCorrTQDC.push_back(make_pair(iFirst, iSecond));
244 TString hName(fTitle +
"_" + corrPair.first +
"_vs_" + corrPair.second +
"_Amp");
247 h->GetXaxis()->SetTitle((corrPair.first +
" Amplitude").data());
248 h->GetYaxis()->SetTitle((corrPair.second +
" Amplitude").data());
249 histCorrTQDC.push_back(h);
252 padsCorrTQDC.push_back(pad);
254 canName = fTitle +
"_Trig_States_2D";
256 size_t corrLen = histCorrTQDC.size();
257 size_t Rows2D = corrLen / Cols2D + ((corrLen % Cols2D) ? 1 : 0);
258 canCorrTQDC = make_unique<TCanvas>(canName, canName,
PAD_WIDTH * Cols2D,
PAD_HEIGHT * Rows2D);
259 canCorrTQDC->Divide(Cols2D, Rows2D, 0.01 / TrigBitsCnt, 0.01 / Rows2D);
263void BmnHistTrigger::InitScalers()
298void BmnHistTrigger::InitGrids()
300 const vector<Color_t> GridColors{kYellow + 2, kBlue, kRed, kGreen + 1, kCyan, kMagenta, kGray, kBlack};
301 const Int_t GridColsBD = 4;
302 const Int_t GroupSizeBD = 5;
304 TString canName = fTitle +
"_BD_Grid";
305 Int_t GridRowsBD =
BD_CHANNELS / (GroupSizeBD * GridColsBD);
306 canGridBD = make_unique<TCanvas>(canName, canName,
PAD_WIDTH * GridColsBD,
PAD_HEIGHT * GridRowsBD);
307 canGridBD->Divide(GridColsBD, GridRowsBD, 0.01 / GridColsBD, 0.01 / GridRowsBD);
309 for (Int_t iRow = 0; iRow < GridRowsBD; ++iRow) {
310 for (Int_t iCol = 0; iCol < GridColsBD; ++iCol) {
313 for (Int_t iGr = 0; iGr < GroupSizeBD; ++iGr) {
314 TString
name = Form(fTitle +
"_BD_Amp_mod_%d", iMod++);
316 h->GetXaxis()->SetTitle(
"Amplitude, ns");
317 h->GetYaxis()->SetTitle(
"Activation Count");
318 h->SetLineColor(GridColors[iGr]);
320 histsGridBD.push_back(h);
323 padsGridBD.push_back(p);
327 canName = fTitle +
"_ND_Grid";
328 Int_t GridRowsND = 4;
329 vector<string> endnamesND{
"F1",
"F2",
"S1",
"S2",
"V"};
330 Int_t GridColsND = endnamesND.size();
331 canGridND = make_unique<TCanvas>(canName, canName,
PAD_WIDTH * GridColsND,
PAD_HEIGHT * GridRowsND);
332 canGridND->Divide(GridColsND, GridRowsND, 0.01 / GridColsND, 0.01 / GridRowsND);
334 for (Int_t iRow = 0; iRow < GridRowsND; ++iRow) {
335 for (Int_t iCol = 0; iCol < GridColsND; ++iCol) {
336 char* detName = Form(
"ND%s%d", endnamesND[iCol].data(), (iRow + 1));
338 string full_det_name(
string(
"TQDC_") + detName);
339 auto it = mapArrayNames.find(full_det_name);
340 if (it != mapArrayNames.end()) {
341 mapGridND.insert(make_pair(it->second, p));
344 TString
name = Form(fTitle +
"_%s_Amp", detName);
346 TH1F* h =
new TH1F(name, name,
TRIG_AMP_BINS, 0, MaxAmpTQDC);
347 h->GetXaxis()->SetTitle(
"Amplitude");
348 h->GetYaxis()->SetTitle(
"Activation Count");
349 h->SetLineColor(kBlue);
355 TH1F* h =
new TH1F(name, name,
TRIG_AMP_BINS, 0, MaxAmpTQDC);
356 h->GetXaxis()->SetTitle(
"Amplitude");
357 h->GetYaxis()->SetTitle(
"Activation Count");
358 h->SetLineColor(kMagenta);
362 padsGridND.push_back(p);
367void BmnHistTrigger::InitHistsFromArr(vector<TClonesArray*>* trigAr)
369 regex reBD(
"BD\\S+");
370 regex reND(
"TQDC_ND\\S+");
371 regex reQBC2(
"TQDC_BC2\\S+");
372 regex reQBC1(
"TQDC_BC1");
373 regex reQUnit(
"TQDC_UNIT_\\d+");
374 regex reX10(
"TQDC_.+_X10.*");
376 Int_t arLen = trigAr->size();
386 for (Int_t
i = 0;
i < arLen; ++
i) {
387 TClonesArray* ar = trigAr->at(
i);
388 TString arName(ar->GetName());
389 if (regex_match(arName.Data(), reBD) || regex_match(arName.Data(), reND)) {
399 Int_t maxTime = (ar->GetClass() == BmnTrigWaveDigit::Class())
400 ? (regex_match(ar->GetName(), reQBC2)
402 : (regex_match(ar->GetName(), reQUnit)
404 : (regex_match(ar->GetName(), reQBC1) ? MaxAmpTQDC_Beam : MaxAmpTQDC)))
405 : (regex_match(ar->GetName(), reBD) ? MaxAmpTDC_BD : MaxAmpTDC);
407 fTitle +
"_" + ar->GetName() + ((ar->GetClass() == BmnTrigWaveDigit::Class()) ?
"_Peak" :
"_Amplitude");
408 TH1F* h =
new TH1F(name, name, 800, 0, maxTime);
409 h->GetXaxis()->SetTitle(
"Amplitude" + (ar->GetClass() == BmnTrigWaveDigit::Class()) ?
"" :
", ns");
410 h->GetYaxis()->SetTitle(
"Activation Count");
411 h->SetLineColor(kBlue);
414 mapAmpLin.insert(make_pair(
i, pad_lin));
415 TH1F* h_log =
static_cast<TH1F*
>(h->Clone(TString(h->GetName()) +
"_log"));
417 pad_log->
logy =
true;
418 mapAmpLog.insert(make_pair(
i, pad_log));
419 padsCanAmp.push_back(pad_lin);
420 padsCanAmp.push_back(pad_log);
423 if (ar->GetClass() == BmnTrigWaveDigit::Class()) {
424 name = fTitle +
"_" + ar->GetName()
425 + ((ar->GetClass() == BmnTrigWaveDigit::Class()) ?
"_Peak" :
"_Amplitude") +
"_filtered";
426 TH1F* h_match =
new TH1F(name, name, 800, 0, maxTime);
427 h_match->GetXaxis()->SetTitle((ar->GetClass() == BmnTrigWaveDigit::Class()) ?
"_Peak" :
"_Amplitude");
428 h_match->GetYaxis()->SetTitle(
"Activation Count");
430 h_match->SetLineColor(kMagenta);
431 pad_lin->
aux.push_back(h_match);
432 pad_lin->
auxOpt.push_back(
"");
433 TH1F* h_match_log =
static_cast<TH1F*
>(h_match->Clone(TString(h_match->GetName()) +
"_log"));
434 pad_log->
aux.push_back(h_match_log);
439 name = fTitle +
"Canvas_Amplitudes";
441 canAmp->Divide(fCols, fRows, 0.01 / fCols, 0.01 / fRows);
443 TString path =
"/" + fTitle +
"/";
444 fServer->Register(path, canAmp);
450 const uint32_t timewin_begin = 312;
451 const uint32_t timewin_end = 362;
463 vector<TClonesArray*>* trigAr = fDigiArrays->
trigAr;
466 InitHistsFromArr(trigAr);
471 for (
auto& el : padsCanAmp) {
474 el->current->SetDirectory(
fDir);
476 for (
auto& el : mapAmpLin) {
478 if (el.second->current)
479 el.second->current->SetDirectory(
fDir);
480 for (
auto& aux_hist : el.second->aux)
481 aux_hist->SetDirectory(
fDir);
484 for (
auto& el : mapAmpLog) {
486 if (el.second->current)
487 el.second->current->SetDirectory(
fDir);
488 for (
auto& aux_hist : el.second->aux)
489 aux_hist->SetDirectory(
fDir);
494 for (
size_t iArr = 0; iArr < (*trigAr).size(); ++iArr) {
495 TClonesArray* ar = (*trigAr)[iArr];
497 if (ar->GetClass() == BmnTrigDigit::Class()) {
498 Bool_t isBarrel = (iArr == indexBD);
500 for (Int_t digIndex = 0; digIndex < ar->GetEntriesFast(); digIndex++) {
502 Short_t iMod = td->
GetMod();
504 Double_t amp = td->
GetAmp();
507 histBDChannels->Fill(iMod);
508 histBDAmpByChannel->Fill(iMod, amp, 1);
509 histsGridBD[iMod]->Fill(amp);
512 auto it = mapTime.find(iArr);
513 if (it != mapTime.end()) {
519 auto it = mapAmpLin.find(iArr);
520 if (it != mapAmpLin.end()) {
526 auto it = mapAmpLog.find(iArr);
527 if (it != mapAmpLog.end()) {
533 auto it = mapTBLin.find(iArr);
534 if (it != mapTBLin.end()) {
536 for (
size_t iState = 0; iState < trig_state_bit_index.size(); ++iState) {
537 if (bitsAR & BIT(trig_state_bit_index[iState]))
543 auto it = mapTBLog.find(iArr);
544 if (it != mapTBLog.end()) {
546 for (
size_t iState = 0; iState < trig_state_bit_index.size(); ++iState) {
547 if (bitsAR & BIT(trig_state_bit_index[iState]))
554 if (ar->GetClass() == BmnTrigWaveDigit::Class()) {
555 for (Int_t digIndex = 0; digIndex < ar->GetEntriesFast(); digIndex++) {
557 storeAmpTQDC[iArr] = td->
GetPeak(timewin_begin, timewin_end);
566 double time = vec.size() ? vec[0] : -DBL_MAX;
570 auto it = mapGridND.find(iArr);
571 if (it != mapGridND.end()) {
573 p->
current->Fill(storeAmpTQDC[iArr]);
576 p->
aux[0]->Fill(storeAmpTQDC[iArr]);
580 auto it = mapTime.find(iArr);
581 if (it != mapTime.end()) {
587 auto it = mapAmpLin.find(iArr);
588 if (it != mapAmpLin.end()) {
590 p->
current->Fill(storeAmpTQDC[iArr]);
593 p->
aux[0]->Fill(storeAmpTQDC[iArr]);
597 auto it = mapAmpLog.find(iArr);
598 if (it != mapAmpLog.end()) {
600 p->
current->Fill(storeAmpTQDC[iArr]);
603 p->
aux[0]->Fill(storeAmpTQDC[iArr]);
607 auto it = mapTBLin.find(iArr);
608 if (it != mapTBLin.end()) {
610 for (
size_t iState = 0; iState < trig_state_bit_index.size(); ++iState) {
611 if (bitsAR & BIT(trig_state_bit_index[iState]))
612 p->
aux[iState]->Fill(storeAmpTQDC[iArr]);
617 auto it = mapTBLog.find(iArr);
618 if (it != mapTBLog.end()) {
620 for (
size_t iState = 0; iState < trig_state_bit_index.size(); ++iState) {
621 if (bitsAR & BIT(trig_state_bit_index[iState]))
622 p->
aux[iState]->Fill(storeAmpTQDC[iArr]);
630 for (
size_t iCorr = 0; iCorr < idxCorrTQDC.size(); ++iCorr) {
631 auto& idxPair = idxCorrTQDC[iCorr];
632 histCorrTQDC[iCorr]->Fill(storeAmpTQDC[idxPair.first], storeAmpTQDC[idxPair.second]);
635 histBDSimult->Fill(bdCount);
638void BmnHistTrigger::FillMSC(
DigiArrays* fDigiArrays)
644 for (
size_t i = 0;
i < ScalerNames.size(); ++
i) {
645 auto& el = fill_scaler_vec_spill[
i];
646 el.second->current->Reset();
647 el.second->current->SetTitle(Form(
"%s__spill_%d", ScalerNames[
i].data(), fLastSpillId));
703 if (canTimes ==
nullptr)
707 TString path =
"/" + fTitle +
"/";
708 fServer->Register(path, canTimes);
710 fServer->Register(path, canGridBD.get());
711 fServer->Register(path, canGridND.get());
712 fServer->Register(path, canTrigStates.get());
713 fServer->Register(path, canCorrTQDC.get());
716 TString cmd =
"/" + fName +
"/->SetRefRun(%arg1%)";
717 TString cmdTitle = path +
"SetRefRun";
718 fServer->RegisterCommand(cmdTitle.Data(), cmd.Data(),
"button;");
719 fServer->Restrict(cmdTitle.Data(),
"visible=shift");
720 fServer->Restrict(cmdTitle.Data(),
"allow=shift");
721 fServer->Restrict(cmdTitle.Data(),
"deny=guest");
722 cmdTitle = path +
"ChangeBDChannel";
723 fServer->RegisterCommand(cmdTitle.Data(),
"/" + fName +
"/->SetBDChannel(%arg1%)",
"button;");
724 fServer->Restrict(cmdTitle.Data(),
"visible=shift");
725 fServer->Restrict(cmdTitle.Data(),
"allow=shift");
726 fServer->Restrict(cmdTitle.Data(),
"hidden=guest");
727 fServer->Restrict(cmdTitle.Data(),
"deny=guest");
728 cmdTitle = path +
"Reset";
729 fServer->RegisterCommand(cmdTitle.Data(),
"/" + fName +
"/->Reset()",
"button;");
730 fServer->Restrict(cmdTitle.Data(),
"visible=shift");
731 fServer->Restrict(cmdTitle.Data(),
"allow=shift");
732 fServer->Restrict(cmdTitle.Data(),
"deny=guest");
740 fDir = outFile->mkdir(fTitle +
"_hists");
760 for (
auto& el : canTimesPads) {
762 el->current->SetDirectory(
fDir);
764 for (
auto& el : padsGridBD) {
767 el->current->SetDirectory(
fDir);
769 for (
auto& el : padsGridND) {
772 el->current->SetDirectory(
fDir);
774 for (
auto& el : padsCanAmp) {
777 el->current->SetDirectory(
fDir);
779 for (
auto& el : padsTrigStates) {
782 el->current->SetDirectory(
fDir);
783 for (
auto& aux_hist : el->aux)
784 aux_hist->SetDirectory(
fDir);
787 for (
auto& el : padsCorrTQDC) {
790 el->current->SetDirectory(
fDir);
792 for (
auto& el : padsScalers) {
795 el->current->SetDirectory(
fDir);
797 for (
auto& el : mapGridND) {
799 if (el.second->current)
800 el.second->current->SetDirectory(
fDir);
802 for (
auto& aux_hist : el.second->aux)
803 aux_hist->SetDirectory(
fDir);
812 for (
auto& el : canTimesPads)
815 for (
auto& el : canProfilePads)
818 for (
auto& el : padsCanAmp)
820 for (
auto& el : padsGridBD)
822 for (
auto& el : padsGridND)
824 for (
auto& el : padsTrigStates)
826 for (
auto& el : padsCorrTQDC)
856 TString FileName = Form(
"bmn_run%04d_hist.root",
id);
857 printf(
"SetRefRun: %s\n", FileName.Data());
870 for (
auto& pad : canTimesPads) {
875 for (
auto& pad : padsCanAmp) {
virtual ~BmnHistTrigger()
void SetDir(TFile *outFile, TTree *recoTree)
void SetBDChannel(Int_t iSelChannel)
void FillFromDigi(DigiArrays *fDigiArrays)
void Register(THttpServer *serv)
BmnHistTrigger(TString title="Triggers", TString path="", Int_t periodID=9, BmnSetup=kBMNSETUP, BmnTrigRaw2Digit *trigMapper=nullptr)
BmnStatus SetRefRun(Int_t id)
static void DrawRef(unique_ptr< TCanvas > &canGemStrip, vector< PadInfo * > *canGemStripPads)
static void SetHistStyleTH1(TH1 *h)
static BmnStatus LoadRefRun(Int_t refID, TString FullName, TString fTitle, vector< PadInfo * > canPads, vector< TString > Names)
vector< TClonesArray * > * GetTrigArrays()
int GetPeak(UInt_t start=0, UInt_t stop=1e9) const
vector< Double_t > & TdcVector()
std::vector< TClonesArray * > * trigAr
Storage for pad content and it's options.