BmnRoot
Loading...
Searching...
No Matches
BmnHistTrigger.cxx
Go to the documentation of this file.
1#include "BmnHistTrigger.h"
2
3#include "BmnAliases.h"
4#include "BmnRawDataDecoder.h"
5
6#include <TProfile.h>
7
9 TString path,
10 Int_t periodID,
12 BmnTrigRaw2Digit* trigMapper)
13 : BmnHist(periodID, setup)
14 , fRows(0)
15 , fCols(TRIG_COLS)
16 // BDEvents(new TClonesArray(BmnTrigDigit::Class())),
17 // histTriggers(nullptr),
18 // histTrigTimeByChannel(nullptr),
19 , fTrigMapper(trigMapper)
20 , histBDAmpByChannel(nullptr)
21 , histBDChannels(nullptr)
22 , histBDSimult(nullptr)
23 , can2d(nullptr)
24 , canTimes(nullptr)
25 , canAmp(nullptr)
26 , canInitDone(kFALSE)
27 , indexBD(0)
28 , canGridBD(nullptr)
29 , fSelectedBDChannel(-1)
30 , fLastSpillId(0)
31 , fLastSpillStartTS(0, 0)
32{
33 fTitle = title;
34 fName = title + "_cl";
35 TString name;
36 const Int_t rows4Summary = 3;
37 // const Int_t rows4Spectrum = 2;
38 TPRegexp re("TQDC_(\\S+)");
39 vector<TClonesArray*>* arrays = fTrigMapper->GetTrigArrays();
40 // for (auto &map : *fTrigMapper->GetMap()) {
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());
46 // re.Substitute(trName, "$1");
47 if (trName.Contains("BD") || trName.Contains("SI")) {
48 Bool_t dupl = kFALSE;
49 for (auto& tr : trigNames) {
50 if (!strcmp(tr.Data(), trName.Data())) {
51 dupl = kTRUE;
52 break;
53 }
54 }
55 if (dupl)
56 continue;
57 trigNames.push_back(trName);
58 shortNames.push_back(trName);
59 name = fTitle + "_" + trName + "_Time";
60 TH1F* h = new TH1F(name, name, 300, 0, TRIG_TIME_WIN);
61 mapTime.insert(make_pair(iArr, h));
62 hists.push_back(h);
63 } else {
64 name = Form("%s", trName.Data()); //, map.module);
65 trigNames.push_back(name);
66 name = fTitle + "_" + name + "_Time";
67 TH1F* h2 = new TH1F(name, name, 300, 0, TRIG_TIME_WIN);
68 mapTime.insert(make_pair(iArr, h2));
69 // printf("to map %s %d\n",name.Data(),iArr);
70 hists.push_back(h2);
71 Bool_t dupl = kFALSE;
72 for (auto& tr : shortNames) {
73 if (!strcmp(tr.Data(), trName.Data())) {
74 dupl = kTRUE;
75 break;
76 }
77 }
78 if (dupl)
79 continue;
80 shortNames.push_back(trName);
81 }
82 }
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";
88 // can2d = new TCanvas(name, name, PAD_WIDTH * fCols, PAD_HEIGHT * rows4Spectrum);
89 // can2d->Divide(fCols, rows4Spectrum);
90 // can2dPads.resize(fCols * rows4Spectrum);
91 name = fTitle + "CanvasTimes";
92 canTimes = new TCanvas(name, name, PAD_WIDTH * fCols, PAD_HEIGHT * fRows);
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++) {
96 PadInfo* p = new PadInfo();
97 canTimesPads[iPad] = p;
98 canTimes->GetPad(iPad + 1)->SetGrid();
99 }
100 name = fTitle + "_BD_Channels";
101 histBDChannels = new TH1I(name, name, BD_CHANNELS, 0, BD_CHANNELS);
102 histBDChannels->GetXaxis()->SetTitle("Channel #");
103 histBDChannels->GetYaxis()->SetTitle("Activation Count");
104 name = fTitle + "_BD_Amp_by_Channels";
105 histBDAmpByChannel = new TH2I(name, name, BD_CHANNELS, 0, BD_CHANNELS, TRIG_AMP_BINS_BD, 0, MaxAmpTDC);
106 histBDAmpByChannel->GetXaxis()->SetTitle("Channel #");
107 histBDAmpByChannel->GetYaxis()->SetTitle("Amplitude, ns");
108 name = fTitle + "_BD_Simultaneous";
109 histBDSimult = new TH1I(name, name, TRIG_MULTIPL, 1, TRIG_MULTIPL + 1);
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");
120 }
121 for (size_t iPad = 0; iPad < canTimesPads.size(); ++iPad) {
122 PadInfo* pad = canTimesPads[iPad];
123 TH1* h = pad->current;
124 if (h) {
126 }
127 }
128 InitGrids();
129 InitTrigMasked();
130 InitScalers();
131}
132
134{
135 delete canTimes;
136 if (fDir)
137 return;
138 for (auto& pad : canProfilePads)
139 if (pad)
140 delete pad;
141 for (auto& pad : canTimesPads)
142 if (pad)
143 delete pad;
144 // for (auto &pad : can2dPads)
145 // delete pad;
146 for (auto& pad : padsGridBD)
147 if (pad)
148 delete pad;
149 for (auto& pad : padsGridND)
150 if (pad)
151 delete pad;
152 for (auto& pad : padsTrigStates)
153 if (pad)
154 delete pad;
155 for (auto& pad : padsCorrTQDC)
156 if (pad)
157 delete pad;
158 for (auto& pad : padsScalers)
159 if (pad)
160 delete pad;
161}
162
163void BmnHistTrigger::InitTrigMasked()
164{
165 DBG("start")
166 const vector<string> TrigName{"TQDC_BC1", "TQDC_BC2", "TQDC_FD", "TQDC_FHCAL", "TQDC_tFHCal", "BD"};
167 // const vector<string> TrigName2DX{
168 // "ВС1T vs BC1B", "ВС2T vs BC2B", "VCT vs VCB", "BC1S vs BC2S", "VCS vs BC2S", "FD vs BC2S"};
169 // const vector<string> TrigName2DY{"BD", "SI", "TQDC_FHCAL", "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();
174 auto bit_map = fTrigMapper->GetTrcMap();
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);
179 }
180 }
181 // canvas for 1D trig hists for different trig bits
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;
190 // make a legend
191 Double_t l_x0 = 0.75;
192 Double_t l_y0 = 0.5;
193 Double_t l_w = 0.15;
194 Double_t l_h = 0.25;
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);
199 // run over trig states
200 for (auto& state : TrigState) {
201 TString hName(fTitle + "_" + detName + "_" + state.Name + "_Amp");
202 TString hTitle(detName + "_" /* + state.Name + */ "_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);
213 }
214 // fill pad vectors
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));
224 }
225 }
226
227 // Create correlation histograms
228 for (auto& corrPair : TrigNameCorrTQDC) {
229 string full_name_first = "TQDC_" + corrPair.first;
230 string full_name_second = "TQDC_" + corrPair.second;
231 uint32_t iFirst(0);
232 uint32_t iSecond(0);
233 auto itf = mapArrayNames.find(full_name_first);
234 if (itf != mapArrayNames.end())
235 iFirst = itf->second;
236 else
237 continue;
238 auto its = mapArrayNames.find(full_name_second);
239 if (its != mapArrayNames.end())
240 iSecond = its->second;
241 else
242 continue;
243 idxCorrTQDC.push_back(make_pair(iFirst, iSecond));
244 TString hName(fTitle + "_" + corrPair.first + "_vs_" + corrPair.second + "_Amp");
245 TH2I* h = new TH2I(hName, hName, TRIG_AMP_BINS, 0, MaxAmpTQDC_Corr, TRIG_AMP_BINS, 0, MaxAmpTQDC_Corr);
247 h->GetXaxis()->SetTitle((corrPair.first + " Amplitude").data());
248 h->GetYaxis()->SetTitle((corrPair.second + " Amplitude").data());
249 histCorrTQDC.push_back(h);
250 PadInfo* pad = new PadInfo(h);
251 pad->opt = "colz";
252 padsCorrTQDC.push_back(pad);
253 }
254 canName = fTitle + "_Trig_States_2D";
255 size_t Cols2D = 3;
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);
260 DBG("end")
261}
262
263void BmnHistTrigger::InitScalers()
264{ // on rewriting
265 // printf("Init scalers: %s\n", fTitle.Data());
266 // MscMap& smap = fTrigMapper->GetScalerMap();
267 // const Int_t ColsStates = 2;
268 // const size_t RowsStates = ScalerNames.size();
269 // // canvas for 1D trig hists for different trig bits
270 // TString canName = fTitle + "_Scalers";
271 // canScalers = make_unique<TCanvas>(canName, canName, PAD_WIDTH * ColsStates, PAD_HEIGHT * RowsStates);
272 // canScalers->Divide(ColsStates, RowsStates, 0.01 / ColsStates, 0.01 / RowsStates);
273 // for (const string& trig_name : ScalerNames) {
274 // TString hName(fTitle + "_" + trig_name + "__profile");
275 // TString hTitle(trig_name + "__profile");
276 // TH1* hp = new TH1D(hName, hTitle, TRIG_TIME_BINS, 0.0, SCALER_TIME_WIN);
277 // BmnHist::SetHistStyleTH1(hp);
278 // hp->GetXaxis()->SetTitle("Time [s]");
279 // hp->GetYaxis()->SetTitle("Count");
280 // PadInfo* p_profile = new PadInfo(hp);
281 // padsScalers.push_back(p_profile);
282 // hName = fTitle + "_" + trig_name + "__spill";
283 // hTitle = trig_name + "__spill";
284 // TH1* h = new TProfile(hName, hTitle, TRIG_TIME_BINS, 0.0, SCALER_TIME_WIN);
285 // BmnHist::SetHistStyleTH1(h);
286 // h->GetXaxis()->SetTitle("Time [s]");
287 // h->GetYaxis()->SetTitle("Count");
288 // PadInfo* p = new PadInfo(h);
289 // padsScalers.push_back(p);
290 // auto it_sm = smap.find(trig_name);
291 // if (it_sm != smap.end()) {
292 // fill_scaler_vec_profile.push_back(make_pair(it_sm->second, p_profile));
293 // fill_scaler_vec_spill.push_back(make_pair(it_sm->second, p));
294 // }
295 // }
296}
297
298void BmnHistTrigger::InitGrids()
299{
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;
303 // Barrel
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);
308 Int_t iMod(0);
309 for (Int_t iRow = 0; iRow < GridRowsBD; ++iRow) {
310 for (Int_t iCol = 0; iCol < GridColsBD; ++iCol) {
311 PadInfo* p = new PadInfo();
312 // p->opt = "nostat";
313 for (Int_t iGr = 0; iGr < GroupSizeBD; ++iGr) {
314 TString name = Form(fTitle + "_BD_Amp_mod_%d", iMod++);
315 TH1F* h = new TH1F(name, name, TRIG_AMP_BINS_BD, 0, MaxAmpTDC_BD);
316 h->GetXaxis()->SetTitle("Amplitude, ns");
317 h->GetYaxis()->SetTitle("Activation Count");
318 h->SetLineColor(GridColors[iGr]);
320 histsGridBD.push_back(h);
321 p->aux.push_back(h);
322 }
323 padsGridBD.push_back(p);
324 }
325 }
326 // Neutron Detector Trigger
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);
333 iMod = 0;
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));
337 PadInfo* p = new PadInfo();
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));
342 }
343 p->opt = "nostat";
344 TString name = Form(fTitle + "_%s_Amp", detName);
345 {
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);
351 p->current = h;
352 }
353 {
354 name += "_match";
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);
360 p->aux.push_back(h);
361 }
362 padsGridND.push_back(p);
363 }
364 }
365}
366
367void BmnHistTrigger::InitHistsFromArr(vector<TClonesArray*>* trigAr)
368{
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.*");
375 // const Int_t rows4Spectrum = 2;
376 Int_t arLen = trigAr->size();
377 TString name;
378 fCols = LIN_LOG_COLS;
379 fRows = 0; // / fSrcCols;
380 // hists.resize(fRows);
381 // histsAux.resize(fRows);
382 // for (Int_t i = 0; i < hists.size(); i++) {
383 // hists[i].resize(fCols, nullptr);
384 // histsAux[i].resize(fCols, nullptr);
385 // }
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)) {
390
391 } else {
392 // if (ar->GetClass() == BmnTrigWaveDigit::Class()) {
393 // regex re("TQDC_(.+)");
394 // TString pureName(regex_replace(ar->GetName(), re, "$1"));
395 // NamesAmp.push_back(pureName);
396 // } else
397 // NamesAmpTDC.push_back(arName);
398
399 Int_t maxTime = (ar->GetClass() == BmnTrigWaveDigit::Class())
400 ? (regex_match(ar->GetName(), reQBC2)
401 ? MaxAmpTQDC_BC2
402 : (regex_match(ar->GetName(), reQUnit)
403 ? MaxAmpTQDC_Unit
404 : (regex_match(ar->GetName(), reQBC1) ? MaxAmpTQDC_Beam : MaxAmpTQDC)))
405 : (regex_match(ar->GetName(), reBD) ? MaxAmpTDC_BD : MaxAmpTDC);
406 name =
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);
413 PadInfo* pad_lin = new PadInfo(h);
414 mapAmpLin.insert(make_pair(i, pad_lin));
415 TH1F* h_log = static_cast<TH1F*>(h->Clone(TString(h->GetName()) + "_log"));
416 PadInfo* pad_log = new PadInfo(h_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);
421 // NamesAmp.push_back(pad_lin->current->GetName());
422 // NamesAmp.push_back(pad_log->current->GetName());
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);
435 }
436 ++fRows;
437 }
438 }
439 name = fTitle + "Canvas_Amplitudes";
440 canAmp = new TCanvas(name, name, PAD_WIDTH * fCols, PAD_HEIGHT * fRows);
441 canAmp->Divide(fCols, fRows, 0.01 / fCols, 0.01 / fRows);
442 if (fServer) {
443 TString path = "/" + fTitle + "/";
444 fServer->Register(path, canAmp);
445 }
446}
447
449{
450 const uint32_t timewin_begin = 312;
451 const uint32_t timewin_end = 362;
452 // const double timewin_begin_ns = timewin_begin * ADC_CLOCK_TQDC16VS;
453 // const double timewin_end_ns = timewin_end * ADC_CLOCK_TQDC16VS;
454 // const vector<uint8_t> trc_map = {};
455 BmnEventHeader* eHdr = fDigiArrays->header;
456 // if ((eHdr->GetEventType() == kBMNSTAT) || (eHdr->GetEventType() == kBMNEOS)) {
457 // FillMSC(fDigiArrays);
458 // return;
459 // } // else
460 // return; // temporary
461 UInt_t bitsAR = eHdr->GetInputSignalsAR();
462 // UInt_t bitsBR = eHdr->GetInputSignalsBR();
463 vector<TClonesArray*>* trigAr = fDigiArrays->trigAr;
464 Int_t bdCount = 0;
465 if (!canInitDone) {
466 InitHistsFromArr(trigAr);
467 canInitDone = kTRUE;
468 // if (isShown) Register(fServer);
469 // SetDir(fDir);
470
471 for (auto& el : padsCanAmp) {
472 if (el)
473 if (el->current)
474 el->current->SetDirectory(fDir);
475 }
476 for (auto& el : mapAmpLin) {
477 if (el.second) {
478 if (el.second->current)
479 el.second->current->SetDirectory(fDir);
480 for (auto& aux_hist : el.second->aux)
481 aux_hist->SetDirectory(fDir);
482 }
483 }
484 for (auto& el : mapAmpLog) {
485 if (el.second) {
486 if (el.second->current)
487 el.second->current->SetDirectory(fDir);
488 for (auto& aux_hist : el.second->aux)
489 aux_hist->SetDirectory(fDir);
490 }
491 }
492 }
493 // BDEvents->Clear();
494 for (size_t iArr = 0; iArr < (*trigAr).size(); ++iArr) {
495 TClonesArray* ar = (*trigAr)[iArr];
496 // const char* arName = ar->GetName();
497 if (ar->GetClass() == BmnTrigDigit::Class()) { // TDC data
498 Bool_t isBarrel = (iArr == indexBD);
499 // Bool_t isSiMD = (iArr == indexSI); //! strcmp(arName, "SI");
500 for (Int_t digIndex = 0; digIndex < ar->GetEntriesFast(); digIndex++) {
501 BmnTrigDigit* td = static_cast<BmnTrigDigit*>(ar->At(digIndex));
502 Short_t iMod = td->GetMod();
503 // Double_t time = td->GetTime();
504 Double_t amp = td->GetAmp();
505 if (isBarrel) {
506 bdCount++;
507 histBDChannels->Fill(iMod);
508 histBDAmpByChannel->Fill(iMod, amp, 1);
509 histsGridBD[iMod]->Fill(amp);
510 }
511 {
512 auto it = mapTime.find(iArr);
513 if (it != mapTime.end()) {
514 TH1* h = it->second;
515 h->Fill(td->GetTime());
516 }
517 }
518 {
519 auto it = mapAmpLin.find(iArr);
520 if (it != mapAmpLin.end()) {
521 PadInfo* p = it->second;
522 p->current->Fill(td->GetAmp());
523 }
524 }
525 {
526 auto it = mapAmpLog.find(iArr);
527 if (it != mapAmpLog.end()) {
528 PadInfo* p = it->second;
529 p->current->Fill(td->GetAmp());
530 }
531 }
532 {
533 auto it = mapTBLin.find(iArr);
534 if (it != mapTBLin.end()) {
535 PadInfo* p = it->second;
536 for (size_t iState = 0; iState < trig_state_bit_index.size(); ++iState) {
537 if (bitsAR & BIT(trig_state_bit_index[iState]))
538 p->aux[iState]->Fill(td->GetAmp());
539 }
540 }
541 }
542 {
543 auto it = mapTBLog.find(iArr);
544 if (it != mapTBLog.end()) {
545 PadInfo* p = it->second;
546 for (size_t iState = 0; iState < trig_state_bit_index.size(); ++iState) {
547 if (bitsAR & BIT(trig_state_bit_index[iState]))
548 p->aux[iState]->Fill(td->GetAmp());
549 }
550 }
551 }
552 }
553 }
554 if (ar->GetClass() == BmnTrigWaveDigit::Class()) { // TQDC ADC data
555 for (Int_t digIndex = 0; digIndex < ar->GetEntriesFast(); digIndex++) {
556 BmnTrigWaveDigit* td = static_cast<BmnTrigWaveDigit*>(ar->At(digIndex));
557 storeAmpTQDC[iArr] = td->GetPeak(timewin_begin, timewin_end);
558
559 vector<double>& vec = td->TdcVector();
560 // vector<double> vec_in_win;
561 // std::copy_if(vec.begin(), vec.end(), std::back_inserter(vec_in_win), [=](double
562 // tdc_time) {
563 // return ((tdc_time >= timewin_begin_ns) && (tdc_time <= timewin_end_ns));
564 // });
565
566 double time = vec.size() ? vec[0] : -DBL_MAX;
567 // double time = vec_in_win.size() ? vec_in_win[0] : -DBL_MAX;
568 // printf("time %f\n",time);
569 {
570 auto it = mapGridND.find(iArr);
571 if (it != mapGridND.end()) {
572 PadInfo* p = it->second;
573 p->current->Fill(storeAmpTQDC[iArr]);
574 if (p->aux.size())
575 if (time > -900)
576 p->aux[0]->Fill(storeAmpTQDC[iArr]);
577 }
578 }
579 {
580 auto it = mapTime.find(iArr);
581 if (it != mapTime.end()) {
582 TH1* h = it->second;
583 h->Fill(time);
584 }
585 }
586 {
587 auto it = mapAmpLin.find(iArr);
588 if (it != mapAmpLin.end()) {
589 PadInfo* p = it->second;
590 p->current->Fill(storeAmpTQDC[iArr]);
591 if (p->aux.size())
592 if (time > -900)
593 p->aux[0]->Fill(storeAmpTQDC[iArr]);
594 }
595 }
596 {
597 auto it = mapAmpLog.find(iArr);
598 if (it != mapAmpLog.end()) {
599 PadInfo* p = it->second;
600 p->current->Fill(storeAmpTQDC[iArr]);
601 if (p->aux.size())
602 if (time > -900)
603 p->aux[0]->Fill(storeAmpTQDC[iArr]);
604 }
605 }
606 {
607 auto it = mapTBLin.find(iArr);
608 if (it != mapTBLin.end()) {
609 PadInfo* p = it->second;
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]);
613 }
614 }
615 }
616 {
617 auto it = mapTBLog.find(iArr);
618 if (it != mapTBLog.end()) {
619 PadInfo* p = it->second;
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]);
623 }
624 }
625 }
626 }
627 }
628 }
629 // fill correlation histograms
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]);
633 }
634 if (bdCount)
635 histBDSimult->Fill(bdCount);
636}
637
638void BmnHistTrigger::FillMSC(DigiArrays* fDigiArrays)
639{
640 BmnEventHeader* eHdr = fDigiArrays->header;
641 if (fLastSpillId != eHdr->GetSpillId()) {
642 fLastSpillId = eHdr->GetSpillId();
643 fLastSpillStartTS = eHdr->GetSpillStartTS();
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));
648 }
649 }
650 // // printf("ts :\t %10ld %9d spill start\n", fLastSpillStartTS.GetSec(),
651 // fLastSpillStartTS.GetNanoSec()); TClonesArray* msc = fDigiArrays->msc; for (Int_t i = 0; i <
652 // msc->GetEntriesFast(); i++) {
653 // BmnMSCDigit* td = static_cast<BmnMSCDigit*> (msc->At(i));
654 // UInt_t* sc = td->GetValue();
655 // for (auto& el : fill_scaler_vec_profile) {
656 // uint16_t index = el.first;
657 // PadInfo * info = el.second;
658 // Double_t time_ms = (td->GetTime().AsDouble() - fLastSpillStartTS.AsDouble()); // microseconds
660 // // printf("ts :\t %10ld %9d msc\n", td->GetTime().GetSec(),
661 // td->GetTime().GetNanoSec()); info->current->Fill(time_ms, sc[index]);
662 //
663 // }
664 // for (auto& el : fill_scaler_vec_spill) {
665 // uint16_t index = el.first;
666 // PadInfo * info = el.second;
667 // Double_t time_ms = (td->GetTime().AsDouble() - fLastSpillStartTS.AsDouble()); // microseconds
668 // // printf("time %f\n", time_ms);
669 // // printf("ts :\t %10ld %9d msc\n", td->GetTime().GetSec(),
670 // td->GetTime().GetNanoSec()); info->current->Fill(time_ms, sc[index]);
671 //
672 // }
673 // }
674}
675
676void BmnHistTrigger::SetBDChannel(Int_t iSelChannel)
677{
678 // TString title;
679 // if (iSelChannel > (histBDSpecific->GetNbinsX() - 1)) {
680 // printf("Wrong channel!\n");
681 // return;
682 // }
683 // printf("Set channel: %d\n", fSelectedBDChannel);
684 // fSelectedBDChannel = iSelChannel;
685 // TString command;
686 // if (fSelectedBDChannel >= 0)
687 // command = Form("fMod == %d", fSelectedBDChannel);
688 // if (iSelChannel == -1)
689 // title = Form("BD for All Channels");
690 //
691 // else
692 // title = "BD Time Length For: " + command;
693 // histBDSpecific->SetTitle(title);
694 // histBDSpecific->Reset();
695 // TString direction = "fTime>>" + TString(histBDSpecific->GetName());
696 // frecoTree->Draw(direction, command, "");
697}
698
699void BmnHistTrigger::Register(THttpServer* serv)
700{
701 isShown = kTRUE;
702 fServer = serv;
703 if (canTimes == nullptr)
704
705 return;
706 fServer->Register("/", this);
707 TString path = "/" + fTitle + "/";
708 fServer->Register(path, canTimes);
709 // fServer->Register(path, can2d);
710 fServer->Register(path, canGridBD.get());
711 fServer->Register(path, canGridND.get());
712 fServer->Register(path, canTrigStates.get());
713 fServer->Register(path, canCorrTQDC.get());
714 // fServer->Register(path, canScalers.get());
715
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");
733}
734
735void BmnHistTrigger::SetDir(TFile* outFile = nullptr, TTree* recoTree = nullptr)
736{
737 frecoTree = recoTree;
738 fDir = nullptr;
739 if (outFile)
740 fDir = outFile->mkdir(fTitle + "_hists");
741 // dir->cd();
742 // if (BDEvents)
743 // delete BDEvents;
744 // BDEvents = new TClonesArray("BmnTrigDigit");
745 // if (recoTree)
746 // recoTree->Branch(fTitle + "_BD", &BDEvents);
747 if (!canTimes)
748
749 return;
750 SetDir(fDir);
751}
752
753void BmnHistTrigger::SetDir(TDirectory* Dir)
754{
755 fDir = Dir;
756 // for (auto &el : can2dPads) {
757 // if (el->current)
758 // el->current->SetDirectory(fDir);
759 // }
760 for (auto& el : canTimesPads) {
761 if (el->current)
762 el->current->SetDirectory(fDir);
763 }
764 for (auto& el : padsGridBD) {
765 if (el)
766 if (el->current)
767 el->current->SetDirectory(fDir);
768 }
769 for (auto& el : padsGridND) {
770 if (el)
771 if (el->current)
772 el->current->SetDirectory(fDir);
773 }
774 for (auto& el : padsCanAmp) {
775 if (el)
776 if (el->current)
777 el->current->SetDirectory(fDir);
778 }
779 for (auto& el : padsTrigStates) {
780 if (el) {
781 if (el->current)
782 el->current->SetDirectory(fDir);
783 for (auto& aux_hist : el->aux)
784 aux_hist->SetDirectory(fDir);
785 }
786 }
787 for (auto& el : padsCorrTQDC) {
788 if (el)
789 if (el->current)
790 el->current->SetDirectory(fDir);
791 }
792 for (auto& el : padsScalers) {
793 if (el)
794 if (el->current)
795 el->current->SetDirectory(fDir);
796 }
797 for (auto& el : mapGridND) {
798 if (el.second) {
799 if (el.second->current)
800 el.second->current->SetDirectory(fDir);
801
802 for (auto& aux_hist : el.second->aux)
803 aux_hist->SetDirectory(fDir);
804 }
805 }
806}
807
809{
810 // for (auto &el : can2dPads)
811 // el->Reset();
812 for (auto& el : canTimesPads)
813 if (el)
814 el->Reset();
815 for (auto& el : canProfilePads)
816 if (el)
817 el->Reset();
818 for (auto& el : padsCanAmp)
819 el->Reset();
820 for (auto& el : padsGridBD)
821 el->Reset();
822 for (auto& el : padsGridND)
823 el->Reset();
824 for (auto& el : padsTrigStates)
825 el->Reset();
826 for (auto& el : padsCorrTQDC)
827 if (el)
828 el->Reset();
829 // for (auto& el : padsScalers)
830 // el->Reset();
831}
832
834{
835 if (canTimes)
836 BmnHist::DrawRef(canTimes, &canTimesPads);
837 if (canGridBD)
838 BmnHist::DrawRef(canGridBD, &padsGridBD);
839 if (canGridND)
840 BmnHist::DrawRef(canGridND, &padsGridND);
841 if (canAmp)
842 BmnHist::DrawRef(canAmp, &padsCanAmp);
843 if (canTrigStates)
844 BmnHist::DrawRef(canTrigStates, &padsTrigStates);
845 if (canCorrTQDC)
846 BmnHist::DrawRef(canCorrTQDC, &padsCorrTQDC);
847
848 if (canScalers)
849 BmnHist::DrawRef(canScalers, &padsScalers);
850}
851
853{
854 if (refID != id) {
855
856 TString FileName = Form("bmn_run%04d_hist.root", id);
857 printf("SetRefRun: %s\n", FileName.Data());
858 refRunName = FileName;
859 refID = id;
860 BmnHist::LoadRefRun(refID, refPath + FileName, fTitle, canTimesPads);
861 BmnHist::LoadRefRun(refID, refPath + FileName, fTitle, padsCanAmp);
862 // BmnHist::LoadRefRun(refID, refPath + FileName, fTitle, canPadsPeakTQDC);
863 DrawBoth();
864 }
865 return kBMNSUCCESS;
866}
867
869{
870 for (auto& pad : canTimesPads) {
871 if (pad->ref)
872 delete pad->ref;
873 pad->ref = nullptr;
874 }
875 for (auto& pad : padsCanAmp) {
876 if (pad->ref)
877 delete pad->ref;
878 pad->ref = nullptr;
879 }
880 refID = 0;
881}
#define PAD_WIDTH
Definition BmnAdcQA.cxx:3
#define PAD_HEIGHT
Definition BmnAdcQA.cxx:4
TCanvas * can2d(nullptr)
int i
Definition P4_F32vec4.h:22
BmnStatus
Definition BmnEnums.h:24
@ kBMNSUCCESS
Definition BmnEnums.h:25
BmnSetup
Definition BmnEnums.h:89
#define DBG(a)
Definition BmnMath.h:24
TTimeStamp GetSpillStartTS()
Int_t & GetSpillId()
UInt_t GetInputSignalsAR()
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)
TTree * frecoTree
Definition BmnHist.h:88
Int_t refID
Definition BmnHist.h:92
Bool_t isShown
Definition BmnHist.h:86
TString refPath
Definition BmnHist.h:90
TDirectory * fDir
Definition BmnHist.h:89
static void DrawRef(unique_ptr< TCanvas > &canGemStrip, vector< PadInfo * > *canGemStripPads)
Definition BmnHist.cxx:15
static void SetHistStyleTH1(TH1 *h)
Definition BmnHist.cxx:195
TString refRunName
Definition BmnHist.h:91
static BmnStatus LoadRefRun(Int_t refID, TString FullName, TString fTitle, vector< PadInfo * > canPads, vector< TString > Names)
Definition BmnHist.cxx:100
THttpServer * fServer
Definition BmnHist.h:87
Double_t GetAmp() const
Double_t GetTime() const
Short_t GetMod() const
vector< TClonesArray * > * GetTrigArrays()
NameChMap & GetTrcMap()
int GetPeak(UInt_t start=0, UInt_t stop=1e9) const
vector< Double_t > & TdcVector()
std::vector< TClonesArray * > * trigAr
Definition DigiArrays.h:144
BmnEventHeader * header
Definition DigiArrays.h:146
Storage for pad content and it's options.
Definition PadInfo.h:20
string opt
Definition PadInfo.h:88
bool logy
Definition PadInfo.h:85
TH1 * ref
Definition PadInfo.h:79
vector< TH1 * > aux
Definition PadInfo.h:80
vector< TString > auxOpt
Definition PadInfo.h:81
TH1 * current
Definition PadInfo.h:78
#define TRIG_COLS
#define LIN_LOG_COLS
#define BD_CHANNELS
#define TRIG_MULTIPL
#define TRIG_TIME_WIN
#define TRIG_AMP_BINS
#define TRIG_AMP_BINS_BD
Definition setup.py:1
name
Definition setup.py:7