BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnEventSelector.cxx
Go to the documentation of this file.
1#include "BmnEventSelector.h"
2
3#include "BmnEventHeader.h"
4#include "BmnStripDigit.h"
5#include "BmnTof1Digit.h"
6#include "BmnTrigDigit.h"
7#include "BmnTrigWaveDigit.h"
8#include "FairRootManager.h"
9
10#include <TClonesArray.h>
11#include <TF1.h>
12#include <TFile.h>
13#include <TH2F.h>
14#include <THnSparse.h>
15#include <TProfile.h>
16#include <numeric>
17#include <string>
18#include <vector>
19
20using namespace std;
21
22// ---- Default constructor -------------------------------------------
24 : FairTask("BmnEventSelector")
25{
26 LOG(debug) << "Default Constructor of BmnEventSelector";
27}
28
29// ---- Destructor ----------------------------------------------------
31{
32 LOG(debug) << "Destructor of BmnEventSelector";
33}
34
35// ---- Initialisation ----------------------------------------------
37{
38 LOG(debug) << "SetParContainers of BmnEventSelector";
39 // Load all necessary parameter containers from the runtime data base
40 /*
41 FairRunAna* ana = FairRunAna::Instance();
42 FairRuntimeDb* rtdb = ana->GetRuntimeDb();
43
44 <BmnEventSelectorDataMember> = (<ClassPointer>*)
45 (rtdb->getContainer("<ContainerName>"));
46 */
47}
48
49template<typename T>
51{
52 auto branch = (T)ioman->GetObject(name);
53 if (!branch)
54 LOG(fatal) << Form("BmnEventSelector: %s branch not found!!!\n", name);
55 return branch;
56}
57
58bool BmnEventSelector::FitRunDistr(std::string histName, std::vector<double>& fitPar, float fitMin, float fitMax)
59{
60 cout << endl;
61 LOG(info) << __func__ << ": " << histName;
62 fitPar.clear();
63 auto h2 = static_cast<TH2*>(fInputFile->Get(histName.c_str()));
64 if (!h2) {
65 fNoCalibrationData = true;
66 LOG(error) << "No input histogram: " << histName;
67 return false;
68 }
69 auto runBin = h2->GetXaxis()->FindBin(fRunId);
70 auto h1 = h2->ProjectionY(Form("%s_fit", h2->GetName()), runBin, runBin);
71 if (!h1 || h1->GetEntries() == 0) {
72 fNoCalibrationData = true;
73 LOG(error) << "No input histogram " << histName << " for run number " << fRunId;
74 }
75 h1->Fit("gaus", "", "", fitMin, fitMax);
76 auto f = (TF1*)h1->GetListOfFunctions()->FindObject("gaus");
77 if (!f) {
78 fNoCalibrationData = true;
79 LOG(error) << "ERROR fitting distribution for run number " << fRunId;
80 return false;
81 }
83 fOutputList->Add(h1);
84 fitPar = {f->GetParameter(0), f->GetParameter(1), f->GetParameter(2)};
85 return true;
86}
87
88// ---- Init ----------------------------------------------------------
90{
91 LOG(debug) << "Initilization of BmnEventSelector";
92
94 fOutputFile = new TFile(fOutputFileName.c_str(), "recreate");
95 fOutputList = new TList;
97 }
98
99 fInputFile = new TFile(fInputFileName.c_str());
100 if (fInputFile->IsOpen()) {
101 vector<double> fitPar;
102 if (FitRunDistr("h2runId_time_SingleBC1S", fitPar, 2000, 2500))
103 fSingleBC1hitTimeMean = fitPar.at(1);
104 LOG(info) << "fSingleBC1hitTimeMean=" << fSingleBC1hitTimeMean;
105
106 if (FitRunDistr("h2runId_shapeShifted_SingleBC1S", fitPar, 0, 100)) {
107 fBC1SpeakTimeMin = fitPar.at(1) - 2 * fitPar.at(2);
108 fBC1SpeakTimeMax = fitPar.at(1) + 2 * fitPar.at(2);
109 }
110 LOG(info) << "fBC1SpeakTimeMin=" << fBC1SpeakTimeMin << "\tfBC1SpeakTimeMax=" << fBC1SpeakTimeMax;
111
112 if (FitRunDistr("h2runId_time_SingleVCS_BC1S", fitPar, -10, 10)) {
113 fSingleVCS_BC1S_hitTimeMin = fitPar.at(1) - 10;
114 fSingleVCS_BC1S_hitTimeMax = fitPar.at(1) + 10;
115 }
116 LOG(info) << "fSingleVCS_BC1S_hitTimeMin=" << fSingleVCS_BC1S_hitTimeMin
117 << "\tfSingleVCS_BC1S_hitTimeMax=" << fSingleVCS_BC1S_hitTimeMax;
118
119 if (FitRunDistr("h2runId_shapeShiftedBC1S_SingleVCS", fitPar, 0, 80)) {
120 fVCSpeakTimeMin = fitPar.at(1) - 2 * fitPar.at(2);
121 fVCSpeakTimeMax = fitPar.at(1) + 2 * fitPar.at(2);
122 }
123 LOG(info) << "fVCSpeakTimeMin=" << fVCSpeakTimeMin << "\tfVCSpeakTimeMax=" << fVCSpeakTimeMax;
124
125 if (FitRunDistr("h2runId_time_SingleBC2AS_BC1S", fitPar, -20, 0)) {
126 fSingleBC2AS_BC1S_hitTimeMin = fitPar.at(1) - 2;
127 fSingleBC2AS_BC1S_hitTimeMax = fitPar.at(1) + 2;
128 }
129 LOG(info) << "fSingleBC2AS_BC1S_hitTimeMin=" << fSingleBC2AS_BC1S_hitTimeMin
130 << "\tfSingleBC2AS_BC1S_hitTimeMax=" << fSingleBC2AS_BC1S_hitTimeMax;
131
132 if (FitRunDistr("h2runId_shapeShiftedBC1S_SingleBC2AS", fitPar, 0, 80)) {
133 fBC2ASpeakTimeMin = fitPar.at(1) - 2 * fitPar.at(2);
134 fBC2ASpeakTimeMax = fitPar.at(1) + 2 * fitPar.at(2);
135 }
136 LOG(info) << "fBC2ASpeakTimeMin=" << fBC2ASpeakTimeMin << "\tfBC2ASpeakTimeMax=" << fBC2ASpeakTimeMax;
137
138 if (FitRunDistr("h2runId_peak_BC2AS", fitPar, 0., 1.e4))
139 fSingleBC2ASpeakMin = fitPar.at(1) - 3 * fitPar.at(2);
140 LOG(info) << "\tfSingleBC2ASpeakMin=" << fSingleBC2ASpeakMin;
141
142 if (FitRunDistr("h2runId_time_SingleFD_BC1S", fitPar, 100, 200)) {
143 fSingleFD_BC1S_hitTimeMin = fitPar.at(1) - 10;
144 fSingleFD_BC1S_hitTimeMax = fitPar.at(1) + 20;
145 }
146 LOG(info) << "fSingleFD_BC1S_hitTimeMin=" << fSingleFD_BC1S_hitTimeMin
147 << "\tfSingleFD_BC1S_hitTimeMax=" << fSingleFD_BC1S_hitTimeMax;
148
149 if (FitRunDistr("h2runId_shapeShiftedBC1S_SingleFD", fitPar, 150, 250)) {
150 fFDpeakTimeMin = fitPar.at(1) - 2 * fitPar.at(2);
151 fFDpeakTimeMax = fitPar.at(1) + 2 * fitPar.at(2);
152 }
153 LOG(info) << "fFDpeakTimeMin=" << fFDpeakTimeMin << "\tfFDpeakTimeMax=" << fFDpeakTimeMax;
154
155 if (FitRunDistr("h2runId_peak_FD_nc", fitPar, 4.e3, 7.e3))
156 fSingleFDpeakMin = fitPar.at(1) - 3 * fitPar.at(2);
157 LOG(info) << "\tfSingleFDpeakMin=" << fSingleFDpeakMin;
158
159 if (FitRunDistr("h2runId_shapeShiftedBC1S_BD", fitPar, -150, -50)) {
160 fBDtimeMin = fitPar.at(1) - 3 * fitPar.at(2);
161 fBDtimeMax = fitPar.at(1) + 3 * fitPar.at(2);
162 }
163 LOG(info) << "fBDtimeMin=" << fBDtimeMin << "\tfBDtimeMax=" << fBDtimeMax;
164
165 if (FitRunDistr("h2runId_shapeShiftedBC1S_TOF400digit", fitPar)) {
166 fTOF400digitTimeMin = fitPar.at(1) - 3 * fitPar.at(2);
167 fTOF400digitTimeMax = fitPar.at(1) + 3 * fitPar.at(2);
168 }
169 LOG(info) << "fTOF400digitTimeMin=" << fTOF400digitTimeMin << "\tfTOF400digitTimeMax=" << fTOF400digitTimeMax;
170
171 if (FitRunDistr("h2runId_shapeShiftedBC1S_TOF700digit", fitPar, -520, -450)) {
172 fTOF700digitTimeMin = fitPar.at(1) - 3 * fitPar.at(2);
173 fTOF700digitTimeMax = fitPar.at(1) + 3 * fitPar.at(2);
174 }
175 LOG(info) << "fTOF700digitTimeMin=" << fTOF700digitTimeMin << "\tfTOF700digitTimeMax=" << fTOF700digitTimeMax;
176
177 } else {
178 fNoCalibrationData = true;
179 LOG(error) << "No input histogram file!!!";
180 }
181 // Get a handle from the IO manager
182 ioman = FairRootManager::Instance();
183 if (!ioman)
184 LOG(fatal) << "Init"
185 << "FairRootManager is not instantiated";
186
187 // Get a pointer to the previous already existing data level
188 fEventHeader = ReadBranch<BmnEventHeader*>("BmnEventHeader.");
196 "TOF701"); // new tof700 digits are stored in TOF701 branch (09.2025). Will be fixed later
199
200 ioman->Register("BmnBC1hitInfo.", "BC1hitInfo", &fBC1hitInfo, fWriteBC1hitInfo);
201
202 return kSUCCESS;
203}
204
206{
207 h2runId_eventClass = AddHist(new TH2F("h2runId_eventClass", "Event class;runId;Event class", 1, fRunId, fRunId + 1,
209 for (int i = 0; i < BmnEventClass::kNclasses; i++)
210 h2runId_eventClass->GetYaxis()->SetBinLabel(i + 1, BmnEventClass::names.at(i).c_str());
211 auto h2runId_time =
212 new TH2F("h2runId_time", "TDC time;runId;TDC time (ns);N entries", 1, fRunId, fRunId + 1, 900, 0, 3600);
213 h2runId_time_SingleBC1S = AddHistClone(h2runId_time, "_SingleBC1S");
214 h2runId_time_BC1S_k0 = AddHistClone(h2runId_time, "_BC1S_k0");
215 h2runId_time_BC1S_k1 = AddHistClone(h2runId_time, "_BC1S_k1");
216 h2runId_time_BC1S_kV0 = AddHistClone(h2runId_time, "_BC1S_kV0");
217 h2runId_time_BC1S_kV1 = AddHistClone(h2runId_time, "_BC1S_kV1");
218 h2runId_time_SingleVCS_BC1S = AddHistClone(h2runId_time, "_SingleVCS_BC1S");
219 h2runId_time_SingleVCS_BC1S->GetYaxis()->SetLimits(-50, 50);
220 h2runId_time_SingleBC2AS_BC1S = AddHistClone(h2runId_time, "_SingleBC2AS_BC1S");
221 h2runId_time_SingleBC2AS_BC1S->GetYaxis()->SetLimits(-20, 0);
222 h2runId_time_SingleFD_BC1S = AddHistClone(h2runId_time, "_SingleFD_BC1S");
223 h2runId_time_SingleFD_BC1S->GetYaxis()->SetLimits(-50, 200);
224 auto h2runId_shape =
225 new TH2F("h2runId_shape", "TQDC shape;runId;Time (ns);TQDC signal", 1, fRunId, fRunId + 1, 500, -400, 3600);
226 h2runId_shapeShifted_SingleBC1S = AddHistClone(h2runId_shape, "Shifted_SingleBC1S");
227 h2runId_shapeShiftedBC1S_SingleVCS = AddHistClone(h2runId_shape, "ShiftedBC1S_SingleVCS");
228 h2runId_shapeShiftedBC1S_SingleBC2AS = AddHistClone(h2runId_shape, "ShiftedBC1S_SingleBC2AS");
229 h2runId_shapeShiftedBC1S_SingleFD = AddHistClone(h2runId_shape, "ShiftedBC1S_SingleFD");
230 h2runId_shapeShiftedBC1S_BD = AddHistClone(h2runId_shape, "ShiftedBC1S_BD");
231 h2runId_shapeShiftedBC1S_BD->GetYaxis()->SetLimits(-450, 0);
233 AddHist(new TH2F("h2runId_NdigitsBD", "NdigitsBD;runId;NdigitsBD", 1, fRunId, fRunId + 1, 50, 0, 50));
235 AddHist(new TH2F("h2runId_SumAmpBD", "SumAmpBD;runId;SumAmpBD", 1, fRunId, fRunId + 1, 200, 0, 800));
240 auto h2runId_NdigitsTOF =
241 new TH2F("h2runId_NdigitsTOF", "NdigitsTOF;runId;NdigitsTOF", 1, fRunId, fRunId + 1, 400, 0, 400);
242 h2runId_NdigitsTOF400 = AddHistClone(h2runId_NdigitsTOF, "400");
243 h2runId_NdigitsTOF400_SingleBC1S = AddHistClone(h2runId_NdigitsTOF, "400_SingleBC1S");
244 h2runId_NdigitsTOF400_nc = AddHistClone(h2runId_NdigitsTOF, "400_nc");
245 h2runId_NdigitsTOF700 = AddHistClone(h2runId_NdigitsTOF, "700");
246 h2runId_NdigitsTOF700_SingleBC1S = AddHistClone(h2runId_NdigitsTOF, "700_SingleBC1S");
247 h2runId_NdigitsTOF700_nc = AddHistClone(h2runId_NdigitsTOF, "700_nc");
248 auto h2runId_peak = new TH2F("h2runId_peak", "Peak;runId;Peak;N entries", 1, fRunId, fRunId + 1, 300, 0, 3e4);
249 h2runId_peak_SingleBC1S = AddHistClone(h2runId_peak, "_SingleBC1S");
250 h2runId_peak_BC1S = AddHistClone(h2runId_peak, "_BC1S");
251 h2runId_peak_SingleVCS = AddHistClone(h2runId_peak, "_SingleVCS");
252 h2runId_peak_VCS = AddHistClone(h2runId_peak, "_VCS");
253 h2runId_peak_SingleBC2AS = AddHistClone(h2runId_peak, "_SingleBC2AS");
254 h2runId_peak_BC2AS = AddHistClone(h2runId_peak, "_BC2AS");
255 h2runId_peak_SingleFD = AddHistClone(h2runId_peak, "_SingleFD");
256 h2runId_peak_FD = AddHistClone(h2runId_peak, "_FD");
257 h2runId_peak_FD_nc = AddHistClone(h2runId_peak, "_FD_nc");
258
260 AddHist(new TH2F("h2runId_shapeShiftedBC1S_TOF400digit", "TOF400 digit times;runId;Time (ns)", 1, fRunId,
261 fRunId + 1, 500, -700, -600));
263 AddHist(new TH2F("h2runId_shapeShiftedBC1S_TOF700digit", "TOF700 digit times;runId;Time (ns)", 1, fRunId,
264 fRunId + 1, 500, -550, -450));
265
267 vector<string> trigNames{"BT", "CCT1", "CCT2", "MBT"};
268 vector<int> bins{
269 fRunMax - fRunMin, int(trigNames.size()), BmnEventClass::kNclasses, 185, 10000,
270 };
271 vector<double> xmin{
272 double(fRunMin), 0, 0, -2200, 0,
273 };
274 vector<double> xmax{
275 double(fRunMax), double(trigNames.size()), double(BmnEventClass::kNclasses), 1500, 10000,
276 };
277 auto h5runId_trigger_eventClass_dt_n =
278 new THnSparseI("h5runId_trigger_eventClass_dt_n", "Number of;runId;trigger;Event class;#Deltat (ns);N",
279 bins.size(), bins.data(), xmin.data(), xmax.data());
280 for (uint i = 0; i < trigNames.size(); i++)
281 h5runId_trigger_eventClass_dt_n->GetAxis(1)->SetBinLabel(i + 1, trigNames.at(i).c_str());
282 for (int i = 0; i < BmnEventClass::kNclasses; i++)
283 h5runId_trigger_eventClass_dt_n->GetAxis(2)->SetBinLabel(i + 1, BmnEventClass::names.at(i).c_str());
284
285 int n = 400;
286 vector<int> rebin = {1, 1, 1, 1, int(xmax.at(4) / n)};
287 auto h5runId_trigger_eventClass_dt_nTOF =
288 static_cast<THnSparse*>(h5runId_trigger_eventClass_dt_n->Clone())->Rebin(rebin.data());
289 h5runId_trigger_eventClass_dt_nTOF->SetName("h5runId_trigger_eventClass_dt_nTOF");
290 h5runId_trigger_eventClass_dt_nTOF->SetTitle("Number of TOF");
291 h5runId_trigger_eventClass_dt_nTOF->GetAxis(4)->SetLimits(0, n);
292 h5runId_trigger_eventClass_dt_nTOF400digits = AddHistClone(h5runId_trigger_eventClass_dt_nTOF, "400digits");
293 h5runId_trigger_eventClass_dt_nTOF700digits = AddHistClone(h5runId_trigger_eventClass_dt_nTOF, "700digits");
294
295 n = 5000;
296 rebin = {1, 1, 1, 1, int(xmax.at(4) / n)};
297 auto h5runId_trigger_eventClass_dt_nSILICON =
298 static_cast<THnSparse*>(h5runId_trigger_eventClass_dt_n->Clone())->Rebin(rebin.data());
299 h5runId_trigger_eventClass_dt_nSILICON->SetName("h5runId_trigger_eventClass_dt_nSILICON");
300 h5runId_trigger_eventClass_dt_nSILICON->SetTitle("Number of SILICON");
301 h5runId_trigger_eventClass_dt_nSILICON->GetAxis(4)->SetLimits(0, n);
302 h5runId_trigger_eventClass_dt_nSILICONdigits = AddHistClone(h5runId_trigger_eventClass_dt_nSILICON, "digits");
303
304 h5runId_trigger_eventClass_dt_nGEMdigits = AddHistClone(h5runId_trigger_eventClass_dt_n, "GEMdigits");
305 }
306}
307
308// ---- ReInit -------------------------------------------------------
310{
311 LOG(debug) << "Initilization of BmnEventSelector";
312 return kSUCCESS;
313}
314
315int BmnEventSelector::GetClosestHitIndex(std::vector<double> hitTimes, float refTime)
316{
317 if (hitTimes.size() == 0)
318 return -1;
319 int index = 0;
320 float min = fabs(hitTimes.at(0) - refTime);
321 for (uint i = 1; i < hitTimes.size(); i++) {
322 auto dt = fabs(hitTimes.at(i) - refTime);
323 if (dt < min) {
324 min = dt;
325 index = i;
326 }
327 }
328 return index;
329}
330
331int BmnEventSelector::GetPeak(BmnTrigWaveDigit* digit, float timeMin, float timeMax)
332{
333 if (!digit)
334 return 0;
335 int binMin = timeMin / fNsPerChannel;
336 uint binMax = timeMax / fNsPerChannel;
337 if (binMin < 0 || binMax >= digit->GetNSamples())
338 return -999;
339 return digit->GetPeak(binMin, binMax);
340}
341
342template<typename T>
344 std::vector<double> hitTimes,
345 float relTimeMin,
346 float relTimeMax)
347{
348 std::vector<float> sum(hitTimes.size(), 0.);
349 for (uint i = 0; i < hitTimes.size(); i++) {
350 for (auto obj : *array) {
351 auto digit = static_cast<T>(obj);
352 auto relTime = digit->GetTime() - hitTimes.at(i);
353 if (relTimeMin < relTime && relTime < relTimeMax)
354 sum.at(i) += digit->GetAmp();
355 }
356 }
357 return sum;
358}
359
360template<typename T>
362 std::vector<double> hitTimes,
363 float relTimeMin,
364 float relTimeMax)
365{
366 std::vector<int> n(hitTimes.size(), 0);
367 for (uint i = 0; i < hitTimes.size(); i++) {
368 for (auto obj : *array) {
369 auto relTime = static_cast<T>(obj)->GetTime() - hitTimes.at(i);
370 if (relTimeMin < relTime && relTime < relTimeMax)
371 n.at(i)++;
372 }
373 }
374 return n;
375}
376
378 std::vector<double> hitTimes,
379 float relTimeMin,
380 float relTimeMax,
381 float relHitTimeMin,
382 float relHitTimeMax)
383{
384 std::vector<int> ret(hitTimes.size(), -999);
385 if (!digit)
386 return ret;
387 auto hitTimesDigit = digit->TdcVector();
388 auto tMax = fNsPerChannel * digit->GetNSamples();
389 for (uint i = 0; i < hitTimes.size(); i++) {
390 auto hitTime = hitTimes.at(i);
391 auto hitTimeMin = hitTime + relHitTimeMin;
392 auto hitTimeMax = hitTime + relHitTimeMax;
393 if (hitTimeMin < 0 || hitTimeMax > tMax)
394 continue;
395 auto hitFound = true; // FIX ME!!! -> false
396 for (uint j = 0; j < hitTimesDigit.size(); j++) {
397 auto hitTimeDigit = hitTimesDigit.at(j);
398 if (hitTimeMin <= hitTimeDigit && hitTimeDigit <= hitTimeMax) {
399 hitFound = true;
400 break;
401 }
402 }
403 auto timeMin = hitTime + relTimeMin;
404 auto timeMax = hitTime + relTimeMax;
405 if (hitFound)
406 ret.at(i) = GetPeak(digit, timeMin, timeMax);
407 else
408 ret.at(i) = 0;
409 }
410 return ret;
411}
412
414{
419
420 if (!fTQDC_BC1S || !fTQDC_VCS || !fTQDC_FD)
421 return;
422
423 fTimesBC1S = fTQDC_BC1S->TdcVector();
424 fNhitsBC1S = fTimesBC1S.size();
425 if (fNhitsBC1S == 0) {
428 return;
429 }
430 fTimesVCS = fTQDC_VCS->TdcVector();
431 fNhitsVCS = fTimesVCS.size();
432 fTimesBC2AS = fTQDC_BC2AS->TdcVector();
433 fNhitsBC2AS = fTimesBC2AS.size();
434 fTimesFD = fTQDC_FD->TdcVector();
435 fNhitsFD = fTimesFD.size();
436
448}
449
451{
452 using namespace BmnEventClass;
453 BmnEventClass::id status;
454
455 for (int i = 0; i < fNhitsBC1S; i++) {
456 status = k0;
457 if (fNoCalibrationData || fBC1Speaks.at(i) < -998 || fVCSpeaks.at(i) < -998 || fBC2ASpeaks.at(i) < -998
458 || fFDpeaks.at(i) < -998)
459 {
460 fBC1hitClasses.push_back(kUndef);
461 continue;
462 }
463
464 if (fFDpeaks.at(i) < fSingleFDpeakMin)
465 status = k1;
467 if (status == k0)
468 status = kV0;
469 if (status == k1)
470 status = kV1;
471 }
472 fBC1hitClasses.push_back(status);
473 }
474
476 if (fCentralHitIndexBC1S < 0)
477 return kNull;
478
480 || fBC1hitClasses.at(fCentralHitIndexBC1S) == kV0) // search backwards
481 {
482 const float DTmax = 300; // ns around mean for single BC1S hit
483 for (int i = fCentralHitIndexBC1S - 1; i >= 0 && fSingleBC1hitTimeMean - fTimesBC1S.at(i) < DTmax; i--) {
484 if (fBC1hitClasses.at(i) == k1 || fBC1hitClasses.at(i) == kV1) {
486 break;
487 }
488 }
489 }
492 for (auto& t : fRelTimesBC1S)
494
495 if (fNhitsBC1S == 1)
496 return status;
497 if (fNhitsBC1S == 2) {
498 int c = fCentralHitIndexBC1S;
499 int nc = abs(c - 1);
500
501 if (fBC1hitClasses.at(c) == k0 && fBC1hitClasses.at(nc) == k0)
502 return k00;
503 if (fBC1hitClasses.at(c) == k0 && fBC1hitClasses.at(nc) == k1)
504 return k01;
505 if (fBC1hitClasses.at(c) == k0 && fBC1hitClasses.at(nc) == kV0)
506 return k0V0;
507 if (fBC1hitClasses.at(c) == k0 && fBC1hitClasses.at(nc) == kV1)
508 return k0V1;
509 if (fBC1hitClasses.at(c) == k1 && fBC1hitClasses.at(nc) == k0)
510 return k10;
511 if (fBC1hitClasses.at(c) == k1 && fBC1hitClasses.at(nc) == k1)
512 return k11;
513 if (fBC1hitClasses.at(c) == k1 && fBC1hitClasses.at(nc) == kV0)
514 return k1V0;
515 if (fBC1hitClasses.at(c) == k1 && fBC1hitClasses.at(nc) == kV1)
516 return k1V1;
517 }
518 if (fNhitsBC1S > 2)
519 return kMult;
520 return kUndef;
521}
522
523// ---- FillHistograms
524// ----------------------------------------------------------
526{
527 using namespace BmnTriggerBits;
528 bool isBT_AR = fTrigAR & BIT(kBT);
529 bool isMBT_AR = fTrigAR & BIT(kMBT);
530 bool isCCT1_AR = fTrigAR & BIT(kCCT1);
531 bool isCCT2_AR = fTrigAR & BIT(kCCT2);
532 vector<bool> trigAR = {isBT_AR, isCCT1_AR, isCCT2_AR, isMBT_AR};
533
534 fNdigitsSILICON = 0;
535 for (auto digit : *fArrSILICONdigits)
536 if (static_cast<BmnStripDigit*>(digit)->IsGoodDigit())
538
539 fNdigitsGEM = 0;
540 for (auto digit : *fArrGEMdigits)
541 if (static_cast<BmnStripDigit*>(digit)->IsGoodDigit())
542 fNdigitsGEM++;
543
545 for (int i = 0; i < fNhitsBC1S; i++) {
548 else if (fBC1hitClasses.at(i) == BmnEventClass::k1)
550 else if (fBC1hitClasses.at(i) == BmnEventClass::kV0)
552 else if (fBC1hitClasses.at(i) == BmnEventClass::kV1)
557 h2runId_peak_FD->Fill(fRunId, fFDpeaks.at(i));
562 if (i != fCentralHitIndexBC1S) {
568 }
569 }
570
571 if (fNhitsBC1S == 1) {
573 auto& pulseBC1S = fTQDC_BC1S->GetValue();
574 for (uint i = 0; i < fTQDC_BC1S->GetNSamples(); i++) {
575 auto channelTime = i * fNsPerChannel;
576 h2runId_shapeShifted_SingleBC1S->Fill(fRunId, channelTime - fTimesBC1S.at(0), pulseBC1S[i]);
577 }
579
580 for (auto digit : *fArrBDdigits) {
581 auto time = static_cast<BmnTrigDigit*>(digit)->GetTime() - fTimesBC1S.at(0);
583 }
588
589 for (auto digit : *fArrTOF400digits) {
590 auto time = static_cast<BmnTof1Digit*>(digit)->GetTime() - fTimesBC1S.at(0);
592 }
593
594 for (auto digit : *fArrTOF700digits) {
595 auto time = static_cast<BmnTof1Digit*>(digit)->GetTime() - fTimesBC1S.at(0);
597 }
598
599 if (fNhitsFD == 1) {
602 auto pulseFD = fTQDC_FD->GetValue();
603 for (uint i = 0; i < fTQDC_FD->GetNSamples(); i++) {
604 auto channelTime = i * fNsPerChannel;
605 h2runId_shapeShiftedBC1S_SingleFD->Fill(fRunId, channelTime - fTimesBC1S.at(0), pulseFD[i]);
606 }
607 }
608 if (fNhitsBC2AS == 1) {
611 auto pulseBC2AS = fTQDC_BC2AS->GetValue();
612 for (uint i = 0; i < fTQDC_BC2AS->GetNSamples(); i++) {
613 auto channelTime = i * fNsPerChannel;
614 h2runId_shapeShiftedBC1S_SingleBC2AS->Fill(fRunId, channelTime - fTimesBC1S.at(0), pulseBC2AS[i]);
615 }
616 }
617 }
618
619 if (fNhitsBC1S == 2 && fNhitsVCS == 1) {
622 auto closestBC1Sindex = GetClosestHitIndex(fTimesBC1S, fTimesVCS.at(0));
623 auto closestBC1Stime = fTimesBC1S.at(closestBC1Sindex);
624 auto pulseVCS = fTQDC_VCS->GetValue();
625 for (uint i = 0; i < fTQDC_VCS->GetNSamples(); i++) {
626 auto channelTime = i * fNsPerChannel;
627 h2runId_shapeShiftedBC1S_SingleVCS->Fill(fRunId, channelTime - closestBC1Stime, pulseVCS[i]);
628 }
629 }
630
632 float dt = 0;
633 if (fNhitsBC1S > 1) {
634 float dtLeft = 1e10, dtRight = 1e10;
635 if (fCentralHitIndexBC1S > 0)
636 dtLeft = fRelTimesBC1S.at(fCentralHitIndexBC1S - 1);
638 dtRight = fRelTimesBC1S.at(fCentralHitIndexBC1S + 1);
639 if (fabs(dtLeft) < dtRight)
640 dt = dtLeft;
641 else
642 dt = dtRight;
643 }
644
645 vector<double> x = {fRunId + 0.5, 0., fEventClass + 0.5, dt, 0.};
646 for (uint i = 0; i < trigAR.size(); i++) {
647 if (trigAR.at(i)) {
648 x.at(1) = i + 0.5;
653 x.at(4) = fNdigitsSILICON;
655 x.at(4) = fNdigitsGEM;
657 }
658 }
659 }
660}
661
662// ---- Exec ----------------------------------------------------------
664{
665 // cout << "Event " << ++iEvent << endl;
666 fTrigAR = fEventHeader->GetInputSignalsAR();
668 fNhitsBC1S = 0;
670 fTimesBC1S.clear();
671 fRelTimesBC1S.clear();
672 fBC1Speaks.clear();
673 fBC1hitClasses.clear();
674 fNdigitsBD.clear();
675 fSumAmpBD.clear();
676 fBC2ASpeaks.clear();
677 fVCSpeaks.clear();
678 fFDpeaks.clear();
679 fNdigitsTOF400.clear();
680 fNdigitsTOF700.clear();
681 fNdigitsSILICON = -999;
682 fNdigitsGEM = -999;
683 Calculate();
685
686 fBC1hitInfo.fEventClass = fEventClass;
687 fBC1hitInfo.fCentralHitIndexBC1S = fCentralHitIndexBC1S;
688 fBC1hitInfo.fTimesBC1S = fTimesBC1S;
689 fBC1hitInfo.fRelTimesBC1S = fRelTimesBC1S;
690 fBC1hitInfo.fBC1hitClasses = fBC1hitClasses;
691 fBC1hitInfo.fBC1Speaks = fBC1Speaks;
692 fBC1hitInfo.fVCSpeaks = fVCSpeaks;
693 fBC1hitInfo.fBC2ASpeaks = fBC2ASpeaks;
694 fBC1hitInfo.fFDpeaks = fFDpeaks;
695 fBC1hitInfo.fNdigitsBD = fNdigitsBD;
696 fBC1hitInfo.fSumAmpBD = fSumAmpBD;
697 fBC1hitInfo.fNdigitsTOF400 = fNdigitsTOF400;
698 fBC1hitInfo.fNdigitsTOF700 = fNdigitsTOF700;
699
702}
703
704// ---- Finish --------------------------------------------------------
706{
707 LOG(debug) << "Finish of BmnEventSelector";
709 fOutputFile->cd();
710 for (auto h : *fOutputList) {
711 string className = h->ClassName();
712 if (className.find("THn") == 0) {
713 vector<int> axes = {0, 1, 2, 4};
714 static_cast<THnSparse*>(h)->Projection(axes.size(), axes.data())->Write();
715 axes = {1, 2, 3, 4};
716 static_cast<THnSparse*>(h)->Projection(axes.size(), axes.data())->Write();
717 } else
718 h->Write();
719 }
720 for (auto h : *fOutputList) {
721 string name = h->GetName();
722 string className = h->ClassName();
723 if (className.find("TH2") == 0 && name.find("h2runId") == 0) {
724 // static_cast<TH2*>(h)->ProfileX()->Write();
725 static_cast<TH2*>(h)->ProjectionY()->Write();
726 }
727 }
728 fOutputFile->Close();
729 }
730}
friend F32vec4 fabs(const F32vec4 &a)
Definition P4_F32vec4.h:52
int i
Definition P4_F32vec4.h:22
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition P4_F32vec4.h:30
const char Option_t
#define BIT(n)
THnSparseT< TArrayI > THnSparseI
char * Form(const char *fmt,...)
TClonesArray * fArrBDdigits
TClonesArray * fArrTOF400digits
TH2F * h2runId_shapeShiftedBC1S_SingleVCS
BmnEventHeader * fEventHeader
TClonesArray * fArrTOF700digits
TClonesArray * fArrTQDC_BC1S
std::vector< int > fBC2ASpeaks
THnSparse * h5runId_trigger_eventClass_dt_nTOF700digits
TH2F * h2runId_shapeShiftedBC1S_SingleFD
TH2F * h2runId_SumAmpBD_SingleBC1S
virtual InitStatus ReInit()
ReInitiliazation of task when the runID changes.
BmnTrigWaveDigit * fTQDC_FD
TClonesArray * fArrGEMdigits
std::vector< double > fTimesBC1S
std::vector< double > fTimesBC2AS
std::string fInputFileName
BmnEventClass::id fEventClass
std::vector< int > fBC1hitClasses
int GetClosestHitIndex(std::vector< double > hitTimes, float refTime)
TH2F * h2runId_time_SingleFD_BC1S
std::vector< int > GetPeaks(BmnTrigWaveDigit *digit, std::vector< double > hitTimes, float relTimeMin, float relTimeMax, float relHitTimeMin=-1, float relHitTimeMax=1)
TH2F * h2runId_shapeShiftedBC1S_SingleBC2AS
THnSparse * h5runId_trigger_eventClass_dt_nTOF400digits
std::string fOutputFileName
T AddHistClone(T h, const char *postfix="")
T ReadBranch(const char *name)
std::vector< int > fNdigitsBD
std::vector< int > fFDpeaks
std::vector< int > fNdigitsTOF400
~BmnEventSelector()
Constructor with parameters (Optional).
TH2F * h2runId_time_SingleVCS_BC1S
std::vector< int > GetNdigits(TClonesArray *array, std::vector< double > hitTimes, float relTimeMin, float relTimeMax)
std::vector< double > fRelTimesBC1S
virtual void Finish()
Finish task called at the end of the run.
BmnBC1hitInfo fBC1hitInfo
std::vector< int > fBC1Speaks
std::vector< double > fTimesVCS
THnSparse * h5runId_trigger_eventClass_dt_nGEMdigits
BmnTrigWaveDigit * fTQDC_VCS
TH2F * h2runId_NdigitsTOF400_SingleBC1S
virtual void Exec(Option_t *opt)
Executed for each event.
bool FitRunDistr(std::string histName, std::vector< double > &fitPar, float fitMin=0, float fitMax=0)
TH2F * h2runId_shapeShiftedBC1S_TOF700digit
std::vector< float > GetSumAmp(TClonesArray *digits, std::vector< double > hitTimes, float relTimeMin, float relTimeMax)
TH2F * h2runId_shapeShiftedBC1S_TOF400digit
unsigned int fNdigitsSILICON
BmnTrigWaveDigit * fTQDC_BC1S
THnSparse * h5runId_trigger_eventClass_dt_nSILICONdigits
TH2F * h2runId_NdigitsTOF700_SingleBC1S
std::vector< float > fSumAmpBD
int GetPeak(BmnTrigWaveDigit *digit, float timeMin=0, float timeMax=1e9)
virtual void SetParContainers()
Load the parameter container from the runtime database.
TClonesArray * fArrTQDC_FD
BmnEventSelector()
Default constructor.
TH2F * h2runId_shapeShiftedBC1S_BD
TClonesArray * fArrSILICONdigits
TH2F * h2runId_NdigitsBD_SingleBC1S
unsigned int fNdigitsGEM
virtual InitStatus Init()
Initiliazation of task at the beginning of a run.
TClonesArray * fArrTQDC_VCS
BmnEventClass::id Classify()
FairRootManager * ioman
TH2F * h2runId_shapeShifted_SingleBC1S
BmnTrigWaveDigit * fTQDC_BC2AS
std::vector< int > fNdigitsTOF700
std::vector< double > fTimesFD
TClonesArray * fArrTQDC_BC2AS
TH2F * h2runId_time_SingleBC2AS_BC1S
std::vector< int > fVCSpeaks
Class BmnStripDigit Base class for strip detector digits.
class for TQDC data including waveform can be initialized both from an std::vector and raw pointer to...
size_t GetNSamples() const
int16_t GetPeak(size_t start=0, size_t stop=SIZE_MAX) const
vector< Double_t > & TdcVector()
virtual Int_t FindBin(const char *label)
TAxis * GetXaxis()
THnSparse * Rebin(const Int_t *group) const
virtual void SetName(const char *name)
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
RVec< PromoteType< T > > abs(const RVec< T > &v)
*brief user defined string literal for JSON values *sa std::size_t n
Definition json.hpp:20362
const std::map< int, std::string > names
Definition json.hpp:4446