BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
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#include "BmnTrigWaveDigit.h"
6
7#include <TProfile.h>
8
10 TString path,
11 Int_t periodID,
12 BmnSetup setup,
13 BmnTrigRaw2Digit* trigMapper)
14 : BmnHist(periodID, setup)
15 , fRows(0)
17 // BDEvents(new TClonesArray(BmnTrigDigit::Class())),
18 // histTriggers(nullptr),
19 // histTrigTimeByChannel(nullptr),
20 , fTrigMapper(trigMapper)
21 , histBDAmpByChannel(nullptr)
22 , histBDChannels(nullptr)
23 , histBDSimult(nullptr)
24 , can2d(nullptr)
25 , canTimes(nullptr)
26 , canAmp(nullptr)
28 , indexBD(0)
29 , canGridBD(nullptr)
31 , fLastSpillId(0)
32 , fLastSpillStartTS(0, 0)
33{
34 fTitle = title;
35 fName = title + "_cl";
36 TString name;
37 const Int_t rows4Summary = 3;
38 // const Int_t rows4Spectrum = 2;
39 TPRegexp re("TQDC_(\\S+)");
40 vector<TClonesArray*>* arrays = fTrigMapper->GetTrigArrays();
41 // for (auto &map : *fTrigMapper->GetMap()) {
42 storeAmpTQDC.resize(arrays->size());
43 for (UInt_t iArr = 0; iArr < arrays->size(); ++iArr) {
44 TClonesArray* ar = arrays->at(iArr);
45 mapArrayNames.insert(make_pair(string(ar->GetName()), iArr));
46 TString trName(ar->GetName());
47 // re.Substitute(trName, "$1");
48 if (trName.Contains("BD") || trName.Contains("SI")) {
49 Bool_t dupl = kFALSE;
50 for (auto& tr : trigNames) {
51 if (!strcmp(tr.Data(), trName.Data())) {
52 dupl = kTRUE;
53 break;
54 }
55 }
56 if (dupl)
57 continue;
58 trigNames.push_back(trName);
59 shortNames.push_back(trName);
60 name = fTitle + "_" + trName + "_Time";
61 TH1F* h = new TH1F(name, name, 300, 0, TRIG_TIME_WIN);
62 mapTime.insert(make_pair(iArr, h));
63 hists.push_back(h);
64 } else {
65 name = Form("%s", trName.Data()); //, map.module);
66 trigNames.push_back(name);
67 name = fTitle + "_" + name + "_Time";
68 TH1F* h2 = new TH1F(name, name, 300, 0, TRIG_TIME_WIN);
69 mapTime.insert(make_pair(iArr, h2));
70 // printf("to map %s %d\n",name.Data(),iArr);
71 hists.push_back(h2);
72 Bool_t dupl = kFALSE;
73 for (auto& tr : shortNames) {
74 if (!strcmp(tr.Data(), trName.Data())) {
75 dupl = kTRUE;
76 break;
77 }
78 }
79 if (dupl)
80 continue;
81 shortNames.push_back(trName);
82 }
83 }
84 auto itBD = mapArrayNames.find("BD");
85 if (itBD != mapArrayNames.end())
86 indexBD = itBD->second;
87 fRows = hists.size() / fCols + rows4Summary + (hists.size() % fCols > 0);
88 name = fTitle + "CanvasTimesByChannel";
89 // can2d = new TCanvas(name, name, PAD_WIDTH * fCols, PAD_HEIGHT * rows4Spectrum);
90 // can2d->Divide(fCols, rows4Spectrum);
91 // can2dPads.resize(fCols * rows4Spectrum);
92 name = fTitle + "CanvasTimes";
93 canTimes = new TCanvas(name, name, PAD_WIDTH * fCols, PAD_HEIGHT * fRows);
94 canTimes->Divide(fCols, fRows, 0.01 / fCols, 0.01 / fRows);
95 canTimesPads.resize(fCols * fRows);
96 for (Int_t iPad = 0; iPad < fRows * fCols; iPad++) {
97 PadInfo* p = new PadInfo();
98 canTimesPads[iPad] = p;
99 canTimes->GetPad(iPad + 1)->SetGrid();
100 }
101 name = fTitle + "_BD_Channels";
102 histBDChannels = new TH1I(name, name, BD_CHANNELS, 0, BD_CHANNELS);
103 histBDChannels->GetXaxis()->SetTitle("Channel #");
104 histBDChannels->GetYaxis()->SetTitle("Activation Count");
105 name = fTitle + "_BD_Amp_by_Channels";
107 histBDAmpByChannel->GetXaxis()->SetTitle("Channel #");
108 histBDAmpByChannel->GetYaxis()->SetTitle("Amplitude, ns");
109 name = fTitle + "_BD_Simultaneous";
110 histBDSimult = new TH1I(name, name, TRIG_MULTIPL, 1, TRIG_MULTIPL + 1);
111 histBDSimult->GetXaxis()->SetTitle("Channels #");
112 histBDSimult->GetYaxis()->SetTitle("Activation Count");
113 canTimesPads[1]->current = histBDChannels;
114 canTimesPads[4]->current = histBDAmpByChannel;
115 canTimesPads[4]->opt = "colz";
116 canTimesPads[7]->current = histBDSimult;
117 for (size_t i = 0; i < hists.size(); ++i) {
118 canTimesPads[i + rows4Summary * fCols]->current = hists[i];
119 hists[i]->GetYaxis()->SetTitle("Activation Count");
120 hists[i]->GetXaxis()->SetTitle("Time, ns");
121 }
122 for (size_t iPad = 0; iPad < canTimesPads.size(); ++iPad) {
123 PadInfo* pad = canTimesPads[iPad];
124 TH1* h = pad->current;
125 if (h) {
127 }
128 }
129 InitGrids();
131 InitScalers();
132}
133
135{
136 delete canTimes;
137 if (fDir)
138 return;
139 for (auto& pad : canProfilePads)
140 if (pad)
141 delete pad;
142 for (auto& pad : canTimesPads)
143 if (pad)
144 delete pad;
145 // for (auto &pad : can2dPads)
146 // delete pad;
147 for (auto& pad : padsGridBD)
148 if (pad)
149 delete pad;
150 for (auto& pad : padsGridND)
151 if (pad)
152 delete pad;
153 for (auto& pad : padsTrigStates)
154 if (pad)
155 delete pad;
156 for (auto& pad : padsCorrTQDC)
157 if (pad)
158 delete pad;
159 for (auto& pad : padsScalers)
160 if (pad)
161 delete pad;
162}
163
165{
166 DBG("start")
167 const vector<string> TrigName{"TQDC_BC1", "TQDC_BC2", "TQDC_FD", "TQDC_FHCAL", "TQDC_tFHCal", "BD"};
168 // const vector<string> TrigName2DX{
169 // "ВС1T vs BC1B", "ВС2T vs BC2B", "VCT vs VCB", "BC1S vs BC2S", "VCS vs BC2S", "FD vs BC2S"};
170 // const vector<string> TrigName2DY{"BD", "SI", "TQDC_FHCAL", "BD"};
171 TString canName = fTitle + "_Trig_States";
172 const size_t TrigBitsCnt = TrigState.size();
173 const Int_t ColsStates = 2;
174 const size_t RowsStates = TrigName.size();
175 auto bit_map = fTrigMapper->GetTrcMap();
176 for (auto& state : TrigState) {
177 auto it_bm = bit_map.find(string(state.Name.Data()));
178 if (it_bm != bit_map.end()) {
179 trig_state_bit_index.push_back(it_bm->second);
180 }
181 }
182 // canvas for 1D trig hists for different trig bits
183 canTrigStates = make_unique<TCanvas>(canName, canName, PAD_WIDTH * ColsStates, PAD_HEIGHT * RowsStates);
184 canTrigStates->Divide(ColsStates, RowsStates, 0.01 / ColsStates, 0.01 / RowsStates);
185 for (const string& detName : TrigName) {
186 bool isTDC = (detName.find("BD") != string::npos) || (detName.find("SI") != string::npos);
187 vector<TH1*> hist_vec;
188 vector<TH1*> hist_vec_log;
189 vector<TString> hist_vec_opt;
190 vector<TString> hist_vec_opt_log;
191 // make a legend
192 Double_t l_x0 = 0.75;
193 Double_t l_y0 = 0.5;
194 Double_t l_w = 0.15;
195 Double_t l_h = 0.25;
196 TLegend* legend_lin = new TLegend(l_x0, l_y0, l_x0 + l_w, l_y0 + l_h);
197 legend_lin->SetTextSize(0.08);
198 TLegend* legend_log = new TLegend(l_x0, l_y0, l_x0 + l_w, l_y0 + l_h);
199 legend_log->SetTextSize(0.08);
200 // run over trig states
201 for (auto& state : TrigState) {
202 TString hName(fTitle + "_" + detName + "_" + state.Name + "_Amp");
203 TString hTitle(detName + "_" /* + state.Name + */ "_Amp");
204 TH1* h = new TH1I(hName, hTitle, TRIG_AMP_BINS, 0, isTDC ? MaxAmpTDC : MaxAmpTQDC);
205 legend_lin->AddEntry(h, state.Name);
207 h->GetXaxis()->SetTitle("Amplitude, ns");
208 h->GetYaxis()->SetTitle("Activation Count");
209 h->SetLineColor(state.Color);
210 TH1* h_log = static_cast<TH1I*>(h->Clone(TString(h->GetName()) + "_log"));
211 legend_log->AddEntry(h_log, state.Name);
212 hist_vec.push_back(h);
213 hist_vec_log.push_back(h_log);
214 }
215 // fill pad vectors
216 PadInfo* pad_lin = new PadInfo(nullptr, move(hist_vec), move(hist_vec_opt), legend_lin);
217 PadInfo* pad_log = new PadInfo(nullptr, move(hist_vec_log), move(hist_vec_opt_log), legend_log);
218 padsTrigStates.push_back(pad_lin);
219 padsTrigStates.push_back(pad_log);
220 auto it = mapArrayNames.find(detName);
221 if (it != mapArrayNames.end()) {
222 mapTBLin.insert(make_pair(it->second, pad_lin));
223 pad_log->logy = true;
224 mapTBLog.insert(make_pair(it->second, pad_log));
225 }
226 }
227
228 // Create correlation histograms
229 for (auto& corrPair : TrigNameCorrTQDC) {
230 string full_name_first = "TQDC_" + corrPair.first;
231 string full_name_second = "TQDC_" + corrPair.second;
232 uint32_t iFirst(0);
233 uint32_t iSecond(0);
234 auto itf = mapArrayNames.find(full_name_first);
235 if (itf != mapArrayNames.end())
236 iFirst = itf->second;
237 else
238 continue;
239 auto its = mapArrayNames.find(full_name_second);
240 if (its != mapArrayNames.end())
241 iSecond = its->second;
242 else
243 continue;
244 idxCorrTQDC.push_back(make_pair(iFirst, iSecond));
245 TString hName(fTitle + "_" + corrPair.first + "_vs_" + corrPair.second + "_Amp");
246 TH2I* h = new TH2I(hName, hName, TRIG_AMP_BINS, 0, MaxAmpTQDC_Corr, TRIG_AMP_BINS, 0, MaxAmpTQDC_Corr);
248 h->GetXaxis()->SetTitle((corrPair.first + " Amplitude").data());
249 h->GetYaxis()->SetTitle((corrPair.second + " Amplitude").data());
250 histCorrTQDC.push_back(h);
251 PadInfo* pad = new PadInfo(h);
252 pad->opt = "colz";
253 padsCorrTQDC.push_back(pad);
254 }
255 canName = fTitle + "_Trig_States_2D";
256 size_t Cols2D = 3;
257 size_t corrLen = histCorrTQDC.size();
258 size_t Rows2D = corrLen / Cols2D + ((corrLen % Cols2D) ? 1 : 0);
259 canCorrTQDC = make_unique<TCanvas>(canName, canName, PAD_WIDTH * Cols2D, PAD_HEIGHT * Rows2D);
260 canCorrTQDC->Divide(Cols2D, Rows2D, 0.01 / TrigBitsCnt, 0.01 / Rows2D);
261 DBG("end")
262}
263
265{ // on rewriting
266 // printf("Init scalers: %s\n", fTitle.Data());
267 // MscMap& smap = fTrigMapper->GetScalerMap();
268 // const Int_t ColsStates = 2;
269 // const size_t RowsStates = ScalerNames.size();
270 // // canvas for 1D trig hists for different trig bits
271 // TString canName = fTitle + "_Scalers";
272 // canScalers = make_unique<TCanvas>(canName, canName, PAD_WIDTH * ColsStates, PAD_HEIGHT * RowsStates);
273 // canScalers->Divide(ColsStates, RowsStates, 0.01 / ColsStates, 0.01 / RowsStates);
274 // for (const string& trig_name : ScalerNames) {
275 // TString hName(fTitle + "_" + trig_name + "__profile");
276 // TString hTitle(trig_name + "__profile");
277 // TH1* hp = new TH1D(hName, hTitle, TRIG_TIME_BINS, 0.0, SCALER_TIME_WIN);
278 // BmnHist::SetHistStyleTH1(hp);
279 // hp->GetXaxis()->SetTitle("Time [s]");
280 // hp->GetYaxis()->SetTitle("Count");
281 // PadInfo* p_profile = new PadInfo(hp);
282 // padsScalers.push_back(p_profile);
283 // hName = fTitle + "_" + trig_name + "__spill";
284 // hTitle = trig_name + "__spill";
285 // TH1* h = new TProfile(hName, hTitle, TRIG_TIME_BINS, 0.0, SCALER_TIME_WIN);
286 // BmnHist::SetHistStyleTH1(h);
287 // h->GetXaxis()->SetTitle("Time [s]");
288 // h->GetYaxis()->SetTitle("Count");
289 // PadInfo* p = new PadInfo(h);
290 // padsScalers.push_back(p);
291 // auto it_sm = smap.find(trig_name);
292 // if (it_sm != smap.end()) {
293 // fill_scaler_vec_profile.push_back(make_pair(it_sm->second, p_profile));
294 // fill_scaler_vec_spill.push_back(make_pair(it_sm->second, p));
295 // }
296 // }
297}
298
300{
301 const vector<Color_t> GridColors{kYellow + 2, kBlue, kRed, kGreen + 1, kCyan, kMagenta, kGray, kBlack};
302 const Int_t GridColsBD = 4;
303 const Int_t GroupSizeBD = 5;
304 // Barrel
305 TString canName = fTitle + "_BD_Grid";
306 Int_t GridRowsBD = BD_CHANNELS / (GroupSizeBD * GridColsBD);
307 canGridBD = make_unique<TCanvas>(canName, canName, PAD_WIDTH * GridColsBD, PAD_HEIGHT * GridRowsBD);
308 canGridBD->Divide(GridColsBD, GridRowsBD, 0.01 / GridColsBD, 0.01 / GridRowsBD);
309 Int_t iMod(0);
310 for (Int_t iRow = 0; iRow < GridRowsBD; ++iRow) {
311 for (Int_t iCol = 0; iCol < GridColsBD; ++iCol) {
312 PadInfo* p = new PadInfo();
313 // p->opt = "nostat";
314 for (Int_t iGr = 0; iGr < GroupSizeBD; ++iGr) {
315 TString name = Form(fTitle + "_BD_Amp_mod_%d", iMod++);
316 TH1F* h = new TH1F(name, name, TRIG_AMP_BINS_BD, 0, MaxAmpTDC_BD);
317 h->GetXaxis()->SetTitle("Amplitude, ns");
318 h->GetYaxis()->SetTitle("Activation Count");
319 h->SetLineColor(GridColors[iGr]);
321 histsGridBD.push_back(h);
322 p->aux.push_back(h);
323 }
324 padsGridBD.push_back(p);
325 }
326 }
327 // Neutron Detector Trigger
328 canName = fTitle + "_ND_Grid";
329 Int_t GridRowsND = 4;
330 vector<string> endnamesND{"F1", "F2", "S1", "S2", "V"};
331 Int_t GridColsND = endnamesND.size();
332 canGridND = make_unique<TCanvas>(canName, canName, PAD_WIDTH * GridColsND, PAD_HEIGHT * GridRowsND);
333 canGridND->Divide(GridColsND, GridRowsND, 0.01 / GridColsND, 0.01 / GridRowsND);
334 iMod = 0;
335 for (Int_t iRow = 0; iRow < GridRowsND; ++iRow) {
336 for (Int_t iCol = 0; iCol < GridColsND; ++iCol) {
337 char* detName = Form("ND%s%d", endnamesND[iCol].data(), (iRow + 1));
338 PadInfo* p = new PadInfo();
339 string full_det_name(string("TQDC_") + detName);
340 auto it = mapArrayNames.find(full_det_name);
341 if (it != mapArrayNames.end()) {
342 mapGridND.insert(make_pair(it->second, p));
343 }
344 p->opt = "nostat";
345 TString name = Form(fTitle + "_%s_Amp", detName);
346 {
347 TH1F* h = new TH1F(name, name, TRIG_AMP_BINS, 0, MaxAmpTQDC);
348 h->GetXaxis()->SetTitle("Amplitude");
349 h->GetYaxis()->SetTitle("Activation Count");
352 p->current = h;
353 }
354 {
355 name += "_match";
356 TH1F* h = new TH1F(name, name, TRIG_AMP_BINS, 0, MaxAmpTQDC);
357 h->GetXaxis()->SetTitle("Amplitude");
358 h->GetYaxis()->SetTitle("Activation Count");
361 p->aux.push_back(h);
362 }
363 padsGridND.push_back(p);
364 }
365 }
366}
367
368void BmnHistTrigger::InitHistsFromArr(vector<TClonesArray*>* trigAr)
369{
370 regex reBD("BD\\S+");
371 regex reND("TQDC_ND\\S+");
372 regex reQBC2("TQDC_BC2\\S+");
373 regex reQBC1("TQDC_BC1");
374 regex reQUnit("TQDC_UNIT_\\d+");
375 regex reX10("TQDC_.+_X10.*");
376 // const Int_t rows4Spectrum = 2;
377 Int_t arLen = trigAr->size();
378 TString name;
380 fRows = 0; // / fSrcCols;
381 // hists.resize(fRows);
382 // histsAux.resize(fRows);
383 // for (Int_t i = 0; i < hists.size(); i++) {
384 // hists[i].resize(fCols, nullptr);
385 // histsAux[i].resize(fCols, nullptr);
386 // }
387 for (Int_t i = 0; i < arLen; ++i) {
388 TClonesArray* ar = trigAr->at(i);
389 TString arName(ar->GetName());
390 if (regex_match(arName.Data(), reBD) || regex_match(arName.Data(), reND)) {
391
392 } else {
393 // if (ar->GetClass() == BmnTrigWaveDigit::Class()) {
394 // regex re("TQDC_(.+)");
395 // TString pureName(regex_replace(ar->GetName(), re, "$1"));
396 // NamesAmp.push_back(pureName);
397 // } else
398 // NamesAmpTDC.push_back(arName);
399
400 Int_t maxTime = (ar->GetClass() == BmnTrigWaveDigit::Class())
401 ? (regex_match(ar->GetName(), reQBC2)
403 : (regex_match(ar->GetName(), reQUnit)
405 : (regex_match(ar->GetName(), reQBC1) ? MaxAmpTQDC_Beam : MaxAmpTQDC)))
406 : (regex_match(ar->GetName(), reBD) ? MaxAmpTDC_BD : MaxAmpTDC);
407 name =
408 fTitle + "_" + ar->GetName() + ((ar->GetClass() == BmnTrigWaveDigit::Class()) ? "_Peak" : "_Amplitude");
409 TH1F* h = new TH1F(name, name, 800, 0, maxTime);
410 h->GetXaxis()->SetTitle("Amplitude" + (ar->GetClass() == BmnTrigWaveDigit::Class()) ? "" : ", ns");
411 h->GetYaxis()->SetTitle("Activation Count");
414 PadInfo* pad_lin = new PadInfo(h);
415 mapAmpLin.insert(make_pair(i, pad_lin));
416 TH1F* h_log = static_cast<TH1F*>(h->Clone(TString(h->GetName()) + "_log"));
417 PadInfo* pad_log = new PadInfo(h_log);
418 pad_log->logy = true;
419 mapAmpLog.insert(make_pair(i, pad_log));
420 padsCanAmp.push_back(pad_lin);
421 padsCanAmp.push_back(pad_log);
422 // NamesAmp.push_back(pad_lin->current->GetName());
423 // NamesAmp.push_back(pad_log->current->GetName());
424 if (ar->GetClass() == BmnTrigWaveDigit::Class()) {
425 name = fTitle + "_" + ar->GetName()
426 + ((ar->GetClass() == BmnTrigWaveDigit::Class()) ? "_Peak" : "_Amplitude") + "_filtered";
427 TH1F* h_match = new TH1F(name, name, 800, 0, maxTime);
428 h_match->GetXaxis()->SetTitle((ar->GetClass() == BmnTrigWaveDigit::Class()) ? "_Peak" : "_Amplitude");
429 h_match->GetYaxis()->SetTitle("Activation Count");
431 h_match->SetLineColor(kMagenta);
432 pad_lin->aux.push_back(h_match);
433 pad_lin->auxOpt.push_back("");
434 TH1F* h_match_log = static_cast<TH1F*>(h_match->Clone(TString(h_match->GetName()) + "_log"));
435 pad_log->aux.push_back(h_match_log);
436 }
437 ++fRows;
438 }
439 }
440 name = fTitle + "Canvas_Amplitudes";
441 canAmp = new TCanvas(name, name, PAD_WIDTH * fCols, PAD_HEIGHT * fRows);
442 canAmp->Divide(fCols, fRows, 0.01 / fCols, 0.01 / fRows);
443 if (fServer) {
444 TString path = "/" + fTitle + "/";
445 fServer->Register(path, canAmp);
446 }
447}
448
450{
451 const uint32_t timewin_begin = 312;
452 const uint32_t timewin_end = 362;
453 // const double timewin_begin_ns = timewin_begin * ADC_CLOCK_TQDC16VS;
454 // const double timewin_end_ns = timewin_end * ADC_CLOCK_TQDC16VS;
455 // const vector<uint8_t> trc_map = {};
456 BmnEventHeader* eHdr = fDigiArrays->header;
457 // if ((eHdr->GetEventType() == kBMNSTAT) || (eHdr->GetEventType() == kBMNEOS)) {
458 // FillMSC(fDigiArrays);
459 // return;
460 // } // else
461 // return; // temporary
462 UInt_t bitsAR = eHdr->GetInputSignalsAR();
463 // UInt_t bitsBR = eHdr->GetInputSignalsBR();
464 vector<TClonesArray*>* trigAr = fDigiArrays->trigAr;
465 Int_t bdCount = 0;
466 if (!canInitDone) {
467 InitHistsFromArr(trigAr);
469 // if (isShown) Register(fServer);
470 // SetDir(fDir);
471
472 for (auto& el : padsCanAmp) {
473 if (el)
474 if (el->current)
475 el->current->SetDirectory(fDir);
476 }
477 for (auto& el : mapAmpLin) {
478 if (el.second) {
479 if (el.second->current)
480 el.second->current->SetDirectory(fDir);
481 for (auto& aux_hist : el.second->aux)
482 aux_hist->SetDirectory(fDir);
483 }
484 }
485 for (auto& el : mapAmpLog) {
486 if (el.second) {
487 if (el.second->current)
488 el.second->current->SetDirectory(fDir);
489 for (auto& aux_hist : el.second->aux)
490 aux_hist->SetDirectory(fDir);
491 }
492 }
493 }
494 // BDEvents->Clear();
495 for (size_t iArr = 0; iArr < (*trigAr).size(); ++iArr) {
496 TClonesArray* ar = (*trigAr)[iArr];
497 // const char* arName = ar->GetName();
498 if (ar->GetClass() == BmnTrigDigit::Class()) { // TDC data
499 Bool_t isBarrel = (iArr == indexBD); //! strcmp(arName, "BD");
500 // Bool_t isSiMD = (iArr == indexSI); //! strcmp(arName, "SI");
501 for (Int_t digIndex = 0; digIndex < ar->GetEntriesFast(); digIndex++) {
502 BmnTrigDigit* td = static_cast<BmnTrigDigit*>(ar->At(digIndex));
503 Short_t iMod = td->GetMod();
504 // Double_t time = td->GetTime();
505 Double_t amp = td->GetAmp();
506 if (isBarrel) {
507 bdCount++;
508 histBDChannels->Fill(iMod);
509 histBDAmpByChannel->Fill(iMod, amp, 1);
510 histsGridBD[iMod]->Fill(amp);
511 }
512 {
513 auto it = mapTime.find(iArr);
514 if (it != mapTime.end()) {
515 TH1* h = it->second;
516 h->Fill(td->GetTime());
517 }
518 }
519 {
520 auto it = mapAmpLin.find(iArr);
521 if (it != mapAmpLin.end()) {
522 PadInfo* p = it->second;
523 p->current->Fill(td->GetAmp());
524 }
525 }
526 {
527 auto it = mapAmpLog.find(iArr);
528 if (it != mapAmpLog.end()) {
529 PadInfo* p = it->second;
530 p->current->Fill(td->GetAmp());
531 }
532 }
533 {
534 auto it = mapTBLin.find(iArr);
535 if (it != mapTBLin.end()) {
536 PadInfo* p = it->second;
537 for (size_t iState = 0; iState < trig_state_bit_index.size(); ++iState) {
538 if (bitsAR & BIT(trig_state_bit_index[iState]))
539 p->aux[iState]->Fill(td->GetAmp());
540 }
541 }
542 }
543 {
544 auto it = mapTBLog.find(iArr);
545 if (it != mapTBLog.end()) {
546 PadInfo* p = it->second;
547 for (size_t iState = 0; iState < trig_state_bit_index.size(); ++iState) {
548 if (bitsAR & BIT(trig_state_bit_index[iState]))
549 p->aux[iState]->Fill(td->GetAmp());
550 }
551 }
552 }
553 }
554 }
555 if (ar->GetClass() == BmnTrigWaveDigit::Class()) { // TQDC ADC data
556 for (Int_t digIndex = 0; digIndex < ar->GetEntriesFast(); digIndex++) {
557 BmnTrigWaveDigit* td = static_cast<BmnTrigWaveDigit*>(ar->At(digIndex));
558 storeAmpTQDC[iArr] = td->GetPeak(timewin_begin, timewin_end);
559
560 vector<double>& vec = td->TdcVector();
561 // vector<double> vec_in_win;
562 // std::copy_if(vec.begin(), vec.end(), std::back_inserter(vec_in_win), [=](double
563 // tdc_time) {
564 // return ((tdc_time >= timewin_begin_ns) && (tdc_time <= timewin_end_ns));
565 // });
566
567 double time = vec.size() ? vec[0] : -DBL_MAX;
568 // double time = vec_in_win.size() ? vec_in_win[0] : -DBL_MAX;
569 // printf("time %f\n",time);
570 {
571 auto it = mapGridND.find(iArr);
572 if (it != mapGridND.end()) {
573 PadInfo* p = it->second;
574 p->current->Fill(storeAmpTQDC[iArr]);
575 if (p->aux.size())
576 if (time > -900)
577 p->aux[0]->Fill(storeAmpTQDC[iArr]);
578 }
579 }
580 {
581 auto it = mapTime.find(iArr);
582 if (it != mapTime.end()) {
583 TH1* h = it->second;
584 h->Fill(time);
585 }
586 }
587 {
588 auto it = mapAmpLin.find(iArr);
589 if (it != mapAmpLin.end()) {
590 PadInfo* p = it->second;
591 p->current->Fill(storeAmpTQDC[iArr]);
592 if (p->aux.size())
593 if (time > -900)
594 p->aux[0]->Fill(storeAmpTQDC[iArr]);
595 }
596 }
597 {
598 auto it = mapAmpLog.find(iArr);
599 if (it != mapAmpLog.end()) {
600 PadInfo* p = it->second;
601 p->current->Fill(storeAmpTQDC[iArr]);
602 if (p->aux.size())
603 if (time > -900)
604 p->aux[0]->Fill(storeAmpTQDC[iArr]);
605 }
606 }
607 {
608 auto it = mapTBLin.find(iArr);
609 if (it != mapTBLin.end()) {
610 PadInfo* p = it->second;
611 for (size_t iState = 0; iState < trig_state_bit_index.size(); ++iState) {
612 if (bitsAR & BIT(trig_state_bit_index[iState]))
613 p->aux[iState]->Fill(storeAmpTQDC[iArr]);
614 }
615 }
616 }
617 {
618 auto it = mapTBLog.find(iArr);
619 if (it != mapTBLog.end()) {
620 PadInfo* p = it->second;
621 for (size_t iState = 0; iState < trig_state_bit_index.size(); ++iState) {
622 if (bitsAR & BIT(trig_state_bit_index[iState]))
623 p->aux[iState]->Fill(storeAmpTQDC[iArr]);
624 }
625 }
626 }
627 }
628 }
629 }
630 // fill correlation histograms
631 for (size_t iCorr = 0; iCorr < idxCorrTQDC.size(); ++iCorr) {
632 auto& idxPair = idxCorrTQDC[iCorr];
633 histCorrTQDC[iCorr]->Fill(storeAmpTQDC[idxPair.first], storeAmpTQDC[idxPair.second]);
634 }
635 if (bdCount)
636 histBDSimult->Fill(bdCount);
637}
638
640{
641 // TString title;
642 // if (iSelChannel > (histBDSpecific->GetNbinsX() - 1)) {
643 // printf("Wrong channel!\n");
644 // return;
645 // }
646 // printf("Set channel: %d\n", fSelectedBDChannel);
647 // fSelectedBDChannel = iSelChannel;
648 // TString command;
649 // if (fSelectedBDChannel >= 0)
650 // command = Form("fMod == %d", fSelectedBDChannel);
651 // if (iSelChannel == -1)
652 // title = Form("BD for All Channels");
653 //
654 // else
655 // title = "BD Time Length For: " + command;
656 // histBDSpecific->SetTitle(title);
657 // histBDSpecific->Reset();
658 // TString direction = "fTime>>" + TString(histBDSpecific->GetName());
659 // frecoTree->Draw(direction, command, "");
660}
661
663{
664 isShown = kTRUE;
665 fServer = serv;
666 if (canTimes == nullptr)
667
668 return;
669 fServer->Register("/", this);
670 TString path = "/" + fTitle + "/";
671 fServer->Register(path, canTimes);
672 // fServer->Register(path, can2d);
673 fServer->Register(path, canGridBD.get());
674 fServer->Register(path, canGridND.get());
675 fServer->Register(path, canTrigStates.get());
676 fServer->Register(path, canCorrTQDC.get());
677 // fServer->Register(path, canScalers.get());
678
679 TString cmd = "/" + fName + "/->SetRefRun(%arg1%)";
680 TString cmdTitle = path + "SetRefRun";
681 fServer->RegisterCommand(cmdTitle.Data(), cmd.Data(), "button;");
682 fServer->Restrict(cmdTitle.Data(), "visible=shift");
683 fServer->Restrict(cmdTitle.Data(), "allow=shift");
684 fServer->Restrict(cmdTitle.Data(), "deny=guest");
685 cmdTitle = path + "ChangeBDChannel";
686 fServer->RegisterCommand(cmdTitle.Data(), "/" + fName + "/->SetBDChannel(%arg1%)", "button;");
687 fServer->Restrict(cmdTitle.Data(), "visible=shift");
688 fServer->Restrict(cmdTitle.Data(), "allow=shift");
689 fServer->Restrict(cmdTitle.Data(), "hidden=guest");
690 fServer->Restrict(cmdTitle.Data(), "deny=guest");
691 cmdTitle = path + "Reset";
692 fServer->RegisterCommand(cmdTitle.Data(), "/" + fName + "/->Reset()", "button;");
693 fServer->Restrict(cmdTitle.Data(), "visible=shift");
694 fServer->Restrict(cmdTitle.Data(), "allow=shift");
695 fServer->Restrict(cmdTitle.Data(), "deny=guest");
696}
697
698void BmnHistTrigger::SetDir(TFile* outFile = nullptr, TTree* recoTree = nullptr)
699{
700 frecoTree = recoTree;
701 fDir = nullptr;
702 if (outFile)
703 fDir = outFile->mkdir(fTitle + "_hists");
704 // dir->cd();
705 // if (BDEvents)
706 // delete BDEvents;
707 // BDEvents = new TClonesArray("BmnTrigDigit");
708 // if (recoTree)
709 // recoTree->Branch(fTitle + "_BD", &BDEvents);
710 if (!canTimes)
711
712 return;
713 SetDir(fDir);
714}
715
717{
718 fDir = Dir;
719 // for (auto &el : can2dPads) {
720 // if (el->current)
721 // el->current->SetDirectory(fDir);
722 // }
723 for (auto& el : canTimesPads) {
724 if (el->current)
725 el->current->SetDirectory(fDir);
726 }
727 for (auto& el : padsGridBD) {
728 if (el)
729 if (el->current)
730 el->current->SetDirectory(fDir);
731 }
732 for (auto& el : padsGridND) {
733 if (el)
734 if (el->current)
735 el->current->SetDirectory(fDir);
736 }
737 for (auto& el : padsCanAmp) {
738 if (el)
739 if (el->current)
740 el->current->SetDirectory(fDir);
741 }
742 for (auto& el : padsTrigStates) {
743 if (el) {
744 if (el->current)
745 el->current->SetDirectory(fDir);
746 for (auto& aux_hist : el->aux)
747 aux_hist->SetDirectory(fDir);
748 }
749 }
750 for (auto& el : padsCorrTQDC) {
751 if (el)
752 if (el->current)
753 el->current->SetDirectory(fDir);
754 }
755 for (auto& el : padsScalers) {
756 if (el)
757 if (el->current)
758 el->current->SetDirectory(fDir);
759 }
760 for (auto& el : mapGridND) {
761 if (el.second) {
762 if (el.second->current)
763 el.second->current->SetDirectory(fDir);
764
765 for (auto& aux_hist : el.second->aux)
766 aux_hist->SetDirectory(fDir);
767 }
768 }
769}
770
772{
773 // for (auto &el : can2dPads)
774 // el->Reset();
775 for (auto& el : canTimesPads)
776 if (el)
777 el->Reset();
778 for (auto& el : canProfilePads)
779 if (el)
780 el->Reset();
781 for (auto& el : padsCanAmp)
782 el->Reset();
783 for (auto& el : padsGridBD)
784 el->Reset();
785 for (auto& el : padsGridND)
786 el->Reset();
787 for (auto& el : padsTrigStates)
788 el->Reset();
789 for (auto& el : padsCorrTQDC)
790 if (el)
791 el->Reset();
792 // for (auto& el : padsScalers)
793 // el->Reset();
794}
795
814
816{
817 if (refID != id) {
818
819 TString FileName = Form("bmn_run%04d_hist.root", id);
820 printf("SetRefRun: %s\n", FileName.Data());
821 refRunName = FileName;
822 refID = id;
825 // BmnHist::LoadRefRun(refID, refPath + FileName, fTitle, canPadsPeakTQDC);
826 DrawBoth();
827 }
828 return kBMNSUCCESS;
829}
830
832{
833 for (auto& pad : canTimesPads) {
834 if (pad->ref)
835 delete pad->ref;
836 pad->ref = nullptr;
837 }
838 for (auto& pad : padsCanAmp) {
839 if (pad->ref)
840 delete pad->ref;
841 pad->ref = nullptr;
842 }
843 refID = 0;
844}
int i
Definition P4_F32vec4.h:22
bool Bool_t
int Int_t
unsigned int UInt_t
short Short_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
#define BIT(n)
kGray
kRed
kBlack
kGreen
kMagenta
kCyan
kBlue
kYellow
char * Form(const char *fmt,...)
BmnStatus
Define status code.
Definition BmnEnums.h:93
@ kBMNSUCCESS
Success.
Definition BmnEnums.h:94
BmnSetup
Define experimental setup.
Definition BmnEnums.h:165
#define DBG(a)
Definition BmnMath.h:24
UInt_t GetInputSignalsAR()
Get Input signal states, after reduction.
const vector< TrigStateDesc > TrigState
vector< TString > shortNames
vector< TH1 * > histsGridBD
const Int_t MaxAmpTQDC_Beam
virtual ~BmnHistTrigger()
map< UInt_t, PadInfo * > mapTBLog
vector< PadInfo * > padsCanAmp
const Int_t MaxAmpTQDC_Corr
vector< PadInfo * > padsGridBD
map< UInt_t, PadInfo * > mapGridND
void SetDir(TFile *outFile, TTree *recoTree)
vector< TH2I * > histCorrTQDC
void InitHistsFromArr(vector< TClonesArray * > *trigAr)
vector< TH1 * > hists
vector< TString > trigNames
void SetBDChannel(Int_t iSelChannel)
map< string, UInt_t > mapArrayNames
vector< PadInfo * > padsCorrTQDC
const Int_t MaxAmpTDC
map< UInt_t, TH1 * > mapTime
BmnTrigRaw2Digit * fTrigMapper
unique_ptr< TCanvas > canTrigStates
const Int_t MaxAmpTDC_BD
const Int_t MaxAmpTQDC_BC2
TTimeStamp fLastSpillStartTS
vector< PadInfo * > padsGridND
void FillFromDigi(DigiArrays *fDigiArrays)
vector< PadInfo * > canTimesPads
vector< pair< uint32_t, uint32_t > > idxCorrTQDC
void Register(THttpServer *serv)
const Int_t MaxAmpTQDC_Unit
unique_ptr< TCanvas > canGridND
vector< PadInfo * > padsScalers
unique_ptr< TCanvas > canGridBD
BmnHistTrigger(TString title="Triggers", TString path="", Int_t periodID=9, BmnSetup=kBMNSETUP, BmnTrigRaw2Digit *trigMapper=nullptr)
TH2I * histBDAmpByChannel
vector< uint16_t > trig_state_bit_index
map< UInt_t, PadInfo * > mapTBLin
BmnStatus SetRefRun(Int_t id)
vector< PadInfo * > canProfilePads
unique_ptr< TCanvas > canCorrTQDC
unique_ptr< TCanvas > canScalers
vector< PadInfo * > padsTrigStates
map< UInt_t, PadInfo * > mapAmpLin
const Int_t MaxAmpTQDC
vector< double > storeAmpTQDC
const vector< pair< string, string > > TrigNameCorrTQDC
map< UInt_t, PadInfo * > mapAmpLog
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
BmnHist(Int_t periodID=7, BmnSetup setup=kBMNSETUP)
Definition BmnHist.cxx:3
Double_t GetAmp() const
Double_t GetTime() const
Short_t GetMod() const
class for TQDC data including waveform can be initialized both from an std::vector and raw pointer to...
int16_t GetPeak(size_t start=0, size_t stop=SIZE_MAX) 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
vector< TH1 * > aux
Definition PadInfo.h:80
vector< TString > auxOpt
Definition PadInfo.h:81
TH1 * current
Definition PadInfo.h:78
virtual void SetLineColor(Color_t lcolor)
virtual void SetTextSize(Float_t tsize=1)
TClass * GetClass() const
const char * GetName() const override
TAxis * GetXaxis()
TAxis * GetYaxis()
virtual Int_t Fill(const char *name, Double_t w)
TObject * Clone(const char *newname="") const override
TLegendEntry * AddEntry(const char *name, const char *label="", Option_t *option="lpf")
virtual void SetTitle(const char *title="")
const char * GetName() const override
TString fTitle
TString fName
static TClass * Class()
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
friend friend class TClonesArray
static TClass * Class()
const char * Data() const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
#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