BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnTriggerEfficiencyRun8.cxx
Go to the documentation of this file.
2
3#include "BmnTofHit.h"
4#include "BmnTrigDigit.h"
5#include "BmnTrigWaveDigit.h"
6#include "FairLogger.h"
7
8#include <TClonesArray.h>
9#include <stdlib.h>
10
12 : isValid(kTRUE)
13 , fNBd(-1)
14 , fEffFile1(nullptr)
15 , fEffFile2(nullptr)
16 , fEffFile3(nullptr)
17 , fHBd(nullptr)
18 , fHFd(nullptr)
19 , fHCctSyst(nullptr)
20 , fHFrf(nullptr)
21 , fDstFile(nullptr)
22 , fDstTree(nullptr)
23 , fBTrigInfo(nullptr)
24 , fBPrimaryVertex(nullptr)
25 , fBTof400Hit(nullptr)
26 , fBTof700Hit(nullptr)
27 , fRunId(-1.)
28 , fBC2IntCut(-1.)
30 , fFDPeakLimit(-1)
31{
33}
34
36 : isValid(kTRUE)
37 , fNBd(-1)
38 , fEffFile1(nullptr)
39 , fEffFile2(nullptr)
40 , fEffFile3(nullptr)
41 , fHBd(nullptr)
42 , fHFd(nullptr)
43 , fHCctSyst(nullptr)
44 , fHFrf(nullptr)
45 , fDstFile(nullptr)
46 , fDstTree(nullptr)
47 , fBTrigInfo(nullptr)
48 , fBPrimaryVertex(nullptr)
49 , fBTof400Hit(nullptr)
50 , fBTof700Hit(nullptr)
51 , fRunId(-1.)
52 , fBC2IntCut(-1.)
54 , fFDPeakLimit(-1)
55{
57
58 fDstFile = TFile::Open(dstFileName, "READONLY");
59 // fDstFile = new TFile(dstFileName, "READ");
60 if (!fDstFile || !fDstFile->IsOpen() || fDstFile->IsZombie()) {
61 LOGF(error, "Cannot open file %s", dstFileName.Data());
63 return;
64 }
65 fDstTree = (TTree*)fDstFile->Get("bmndata");
66 if (!fDstTree) {
67 LOGF(error, "Cannot find tree bmndata in the file");
69 return;
70 }
71
72 Int_t ret = fDstTree->SetBranchAddress("BmnTrigInfo.", &fBTrigInfo);
73 if ((ret < 0) || (ret > 2)) {
74 LOGF(error, "Cannot match branch BmnTrigInfo.");
76 return;
77 }
78 ret = fDstTree->SetBranchAddress("MpdVertex.", &fBPrimaryVertex);
79 if ((ret < 0) || (ret > 2)) {
80 LOGF(error, "Cannot match branch MpdVertex.");
82 return;
83 }
84 ret = fDstTree->SetBranchAddress("BmnTof400Hit", &fBTof400Hit);
85 if ((ret < 0) || (ret > 2)) {
86 LOGF(error, "Cannot match branch BmnTof400Hit");
88 return;
89 }
90 ret = fDstTree->SetBranchAddress("BmnTof700Hit", &fBTof700Hit);
91 if ((ret < 0) || (ret > 2)) {
92 LOGF(error, "Cannot match branch BmnTof700Hit");
94 return;
95 }
96
97 // Get cuts for this run id
98 Ssiz_t startCh = dstFileName.Index("mpd_run_Top_");
99 if (startCh == -1) {
100 LOGF(error, "Dst file name must contain \"mpd_run_Top_<RunId>\"");
101 isValid = kFALSE;
102 return;
103 }
104 startCh = dstFileName.Index("mpd_run_Top_") + TString("mpd_run_Top_").Sizeof() - 1;
105 fRunId = (TString(dstFileName(startCh, 4))).Atoi();
106 LOGF(info, "runId = %d", fRunId);
107
111
112 LOGF(info, "File %s successfully opened", dstFileName.Data());
113}
114
116 BmnTrigInfoDst* trigInfo,
117 CbmVertex* primaryVertex,
118 TClonesArray* tof400Hits,
119 TClonesArray* tof700Hits)
120 : isValid(kTRUE)
121 , fNBd(-1)
122 , fEffFile1(nullptr)
123 , fEffFile2(nullptr)
124 , fEffFile3(nullptr)
125 , fHBd(nullptr)
126 , fHFd(nullptr)
127 , fHCctSyst(nullptr)
128 , fHFrf(nullptr)
129 , fDstFile(nullptr)
130 , fDstTree(nullptr)
131 , fBTrigInfo(trigInfo)
132 , fBPrimaryVertex(primaryVertex)
133 , fBTof400Hit(tof400Hits)
134 , fBTof700Hit(tof700Hits)
135 , fRunId(runId)
136 , fBC2IntCut(-1.)
138 , fFDPeakLimit(-1)
139{
141
142 LOGF(info, "runId = %d", fRunId);
143
147}
148
150{
151 LOGF(debug, "BmnTriggerEfficiencyRun8::GetBDEfficiency(): Start");
152 return GetEfficiencyOrError(fHBd, runId, ntrPV, kTRUE);
153}
154
156{
157 LOGF(debug, "BmnTriggerEfficiencyRun8::GetFDEfficiency(): Start");
158 return GetEfficiencyOrError(fHFd, runId, ntrPV, kTRUE);
159}
160
162{
163 LOGF(debug, "BmnTriggerEfficiencyRun8::GetTriggerEfficiency(): Start");
164
165 Double_t bdEff = GetEfficiencyOrError(fHBd, runId, ntrPV, kTRUE);
166 if (bdEff < 0)
167 return -1.;
168
169 return bdEff * GetEfficiencyOrError(fHFd, runId, ntrPV, kTRUE);
170}
171
173 Int_t ntrPV,
174 Double_t& eff,
175 Double_t& statErr,
176 Double_t& systErr,
177 Double_t& errSystErr)
178{
179 statErr = systErr = errSystErr = -1.;
180
181 eff = GetTriggerEfficiency(runId, ntrPV);
182 if (eff < 0.)
183 return kFALSE;
184 else if (eff == 0.) {
185 statErr = systErr = errSystErr = 0.;
186 return kTRUE;
187 }
188
189 Double_t relStatErrBD =
190 GetEfficiencyOrError(fHBd, runId, ntrPV, kFALSE) / GetEfficiencyOrError(fHBd, runId, ntrPV, kTRUE);
191 Double_t relStatErrFD =
192 GetEfficiencyOrError(fHFd, runId, ntrPV, kFALSE) / GetEfficiencyOrError(fHFd, runId, ntrPV, kTRUE);
193 statErr = eff * sqrt(relStatErrBD * relStatErrBD + relStatErrFD * relStatErrFD);
194
195 systErr = abs(GetEfficiencyOrError(fHCctSyst, runId, ntrPV, kTRUE));
196
197 errSystErr = GetEfficiencyOrError(fHCctSyst, runId, ntrPV, kFALSE);
198
199 return kTRUE;
200}
201
203 Double_t& statErr,
204 Double_t& systErr,
205 Double_t& errSystErr)
206{
207 if (!fBPrimaryVertex) {
208 LOGF(debug, "Primary Vertex branch should be defined");
209 return kFALSE;
210 }
211 Int_t pvntr = fBPrimaryVertex->GetNTracks();
212
213 return GetTriggerEfficiencyWithErrors(fRunId, pvntr, eff, statErr, systErr, errSystErr);
214}
215
217{
218 factor = err = -1.;
219
220 if (!IsValid()) {
221 LOGF(error, "This BmnTriggerEfficiencyRun8 object is not valid");
222 return kFALSE;
223 }
224
225 Int_t bin = fHFrf->FindBin(runId);
226 LOGF(debug, "BmnTriggerEfficiencyRun8::GetFluxRejectionFactorWithError(): bin = %d", bin);
227 Int_t binx, biny, binz;
228 fHFrf->GetBinXYZ(bin, binx, biny, binz);
229 LOGF(debug, "BmnTriggerEfficiencyRun8::GetFluxRejectionFactorWithError(): binx = %d, biny = %d, binz = %d", binx,
230 biny, binz);
231
232 if ((binx < 1) || (binx > fHFrf->GetNbinsX())) {
233 LOGF(error, "Run id is out of analysis range");
234 return kFALSE;
235 }
236
237 factor = fHFrf->GetBinContent(bin);
238 if (factor <= 0.)
239 return kFALSE;
240
241 err = fHFrf->GetBinError(bin);
242
243 return kTRUE;
244}
245
250
252{
253 Double_t pvx, pvy, pvz;
254 Int_t pvntr;
255 pvx = fBPrimaryVertex->GetX();
256 pvy = fBPrimaryVertex->GetY();
257 pvz = fBPrimaryVertex->GetZ();
258 pvntr = fBPrimaryVertex->GetNTracks();
259
260 LOGF(debug, "(pvx,pvy,pvz,pvntr) = (%f,%f,%f,%d)", pvx, pvy, pvz, pvntr);
261
262 TVector3 vtxPos;
263 vtxPos.SetXYZ(0.3179, 0., -0.0169);
264 if ((abs(pvz - vtxPos.Z()) > 1.) || (pow(pvx - vtxPos.X(), 2) + pow(pvy - vtxPos.Y(), 2) > pow(1.5, 2))
265 || (pvntr < 2))
266 {
267 LOGF(debug, "Event primary vertex does not pass analysis conditions");
268 return kFALSE;
269 }
270
271 Double_t pv_chi2tondf = fBPrimaryVertex->GetChi2() / fBPrimaryVertex->GetNDF();
272 if ((pv_chi2tondf < 0.1) || (pv_chi2tondf > 10)) {
273 LOGF(debug, "Event primary vertex does not pass analysis conditions");
274 return kFALSE;
275 }
276
277 // Reject close pile up
278 Int_t bc2inttw40 = GetBC2Int(258, 267);
279 if ((bc2inttw40 > fBC2IntCut) || (fBC2IntCut < 0)) {
280 LOGF(debug, "This event does not pass BC2 analysis conditions for pile up");
281 return kFALSE;
282 }
283
284 // Reject distant pile up
285 Int_t threshold = 10;
286 Bool_t isPileupTof400 = HasDistantPileup(fBTof400Hit, threshold);
287 Bool_t isPileupTof700 = HasDistantPileup(fBTof700Hit, threshold);
288
289 if (isPileupTof400 || isPileupTof700) {
290 LOGF(debug, "This event does not pass ToF analysis conditions for pile up");
291 return kFALSE;
292 }
293
294 auto TrigPattern = fBTrigInfo->GetInputSignalsAR();
295 auto bitCCT2 = (TrigPattern >> 7) & 1;
296 if ((bitCCT2 != 1) || !IsBDTriggered() || !IsFDTriggered()) {
297 LOGF(debug, "This event does not pass trigger conditions");
298 return kFALSE;
299 }
300
301 return kTRUE;
302}
303
305{
306 if ((evId >= fDstTree->GetEntries()) || (evId < 0)) {
307 LOGF(debug, "Event id is out of range for this file");
308 return kFALSE;
309 }
310
311 fDstTree->GetEntry(evId);
312
313 return IsEventAnalysable();
314}
315
317{
318 if (ntrPV < 2) {
319 LOGF(error, "Number of tracks in PV is out of analysis range");
320 return -1.;
321 }
322 if (!IsValid()) {
323 LOGF(error, "This BmnTriggerEfficiencyRun8 object is not valid");
324 return -1.;
325 }
326
327 Int_t bin = hist->FindBin(runId, ntrPV);
328 LOGF(debug, "BmnTriggerEfficiencyRun8::GetEfficiencyOrError(): bin = %d", bin);
329 Int_t binx, biny, binz;
330 hist->GetBinXYZ(bin, binx, biny, binz);
331 LOGF(debug, "BmnTriggerEfficiencyRun8::GetEfficiencyOrError(): binx = %d, biny = %d, binz = %d", binx, biny, binz);
332
333 if ((binx < 1) || (binx > hist->GetNbinsX())) {
334 LOGF(error, "Run id is out of analysis range");
335 return -1.;
336 }
337
338 if (biny > hist->GetNbinsY()) {
339 if (isEff)
340 return hist->GetBinContent(binx, hist->GetNbinsY());
341 else
342 return hist->GetBinError(binx, hist->GetNbinsY());
343 }
344
345 Double_t ret;
346
347 if (isEff)
348 ret = hist->GetBinContent(bin);
349 else
350 ret = hist->GetBinError(bin);
351
352 return ret;
353}
354
356{
357 // EffBdFd_Run8_v2.root - with PrimaryVertex
358 // EffBdFd_Run8_v3.root - with MpdVertex and ToF cuts for pile up
359 TString fileName1 = TString(getenv("VMCWORKDIR")) + TString("/parameters/triggerefficiency/EffBdFd_Run8_v3.root");
360 fEffFile1 = new TFile(fileName1, "READ");
361 if (!fEffFile1->IsOpen() || fEffFile1->IsZombie()) {
362 LOGF(error, "Cannot open file %s", fileName1.Data());
363 isValid = kFALSE;
364 return;
365 }
366
367 fHBd = (TH2D*)fEffFile1->Get("hbd");
368 if (!fHBd) {
369 LOGF(error, "Cannot find histogram hbd in the file");
370 isValid = kFALSE;
371 return;
372 }
373 fHFd = (TH2D*)fEffFile1->Get("hfd");
374 if (!fHFd) {
375 LOGF(error, "Cannot find histogram hfd in the file");
376 isValid = kFALSE;
377 return;
378 }
379
380 LOGF(info, "File %s successfully opened", fileName1.Data());
381
382 TString fileName2 = TString(getenv("VMCWORKDIR")) + TString("/parameters/triggerefficiency/EffCctSyst_Run8.root");
383 fEffFile2 = new TFile(fileName2, "READ");
384 if (!fEffFile2->IsOpen() || fEffFile2->IsZombie()) {
385 LOGF(error, "Cannot open file %s", fileName2.Data());
386 isValid = kFALSE;
387 return;
388 }
389
390 fHCctSyst = (TH2D*)fEffFile2->Get("herr");
391 if (!fHCctSyst) {
392 LOGF(error, "Cannot find histogram herr in the file");
393 isValid = kFALSE;
394 return;
395 }
396
397 LOGF(info, "File %s successfully opened", fileName2.Data());
398
399 // FluxRejectionFactor_Run8.root - without ToF cuts for pile up
400 // FluxRejectionFactor_Run8_v2.root - with ToF cuts for pile up
401 TString fileName3 =
402 TString(getenv("VMCWORKDIR")) + TString("/parameters/triggerefficiency/FluxRejectionFactor_Run8_v2.root");
403 fEffFile3 = new TFile(fileName3, "READ");
404 if (!fEffFile3->IsOpen() || fEffFile3->IsZombie()) {
405 LOGF(error, "Cannot open file %s", fileName3.Data());
406 isValid = kFALSE;
407 return;
408 }
409
410 fHFrf = (TH1D*)fEffFile3->Get("hfrc_bt");
411 if (!fHFrf) {
412 LOGF(error, "Cannot find histogram hfrc_bt in the file");
413 isValid = kFALSE;
414 return;
415 }
416
417 LOGF(info, "File %s successfully opened", fileName3.Data());
418
419 return;
420}
421
423{
424 if (runId < 7840)
425 fBC2IntCut = 9000.;
426 else if (runId < 7984)
427 fBC2IntCut = 11000.;
428 else if (runId < 8005)
429 fBC2IntCut = 14000.;
430 else if (runId < 8011)
431 fBC2IntCut = 13000.;
432 else if (runId < 8030)
433 fBC2IntCut = 12000.;
434 else if (runId < 8060)
435 fBC2IntCut = 10000.;
436 else
437 fBC2IntCut = 11000.;
438
439 return;
440}
441
443{
445 if (runId < 7069)
447 else if (runId < 7114)
449 else if (runId < 7237)
451 else if (runId < 7560)
453 else if (runId < 7594)
455
456 return;
457}
458
460{
461 fFDPeakLimit = 4250;
462 if (runId < 7069)
463 fFDPeakLimit = 3500;
464 else if (runId < 7114)
465 fFDPeakLimit = 4250;
466 else if (runId < 7148)
467 fFDPeakLimit = 3500;
468 else if (runId < 7237)
469 fFDPeakLimit = 2500;
470 else if (runId < 7258)
471 fFDPeakLimit = 3500;
472 else if (runId < 7429)
473 fFDPeakLimit = 4000;
474 else if (runId < 7486)
475 fFDPeakLimit = 3750;
476 else if (runId < 7560)
477 fFDPeakLimit = 4000;
478 else if (runId < 7594)
479 fFDPeakLimit = 3500;
480
481 return;
482}
483
485{
486 Int_t bcIntTW = 0;
487
488 // Search for a number of BC1 signals between leftEdge and rightEdge
489 TClonesArray* bc2Digits = fBTrigInfo->GetBC2Digits();
490 if (bc2Digits->GetEntriesFast() != 1) {
491 LOGF(error, "Unexpected behaviour. bc2Digits->GetEntriesFast() = %d", bc2Digits->GetEntriesFast());
492 return -1;
493 }
494 BmnTrigWaveDigit* bc2Digit = (BmnTrigWaveDigit*)bc2Digits->UncheckedAt(0);
495 for (Int_t i = leftEl; i <= rightEl; ++i) {
496 if (bc2Digit->GetValue()[i] > 100)
497 bcIntTW += bc2Digit->GetValue()[i];
498 }
499
500 return bcIntTW;
501}
502
504{
505 Bool_t bdTrig = kFALSE;
506
507 // Search for a number of BD signals inside the trigger window (+-50 ns)
508 TClonesArray* bdDigits = fBTrigInfo->GetBDDigits();
509 Int_t nBd = 0;
510 // Int_t aBd[40] = {0};
511 for (Int_t iBd = 0; iBd < bdDigits->GetEntriesFast(); iBd++) {
512 BmnTrigDigit* bdDigit = (BmnTrigDigit*)bdDigits->UncheckedAt(iBd);
513 if ((bdDigit->GetMod() < 0) || (bdDigit->GetMod() > 39)) {
514 LOGF(error, "Unexpected BD module number %d", bdDigit->GetMod());
515 return kFALSE;
516 }
517 // 7988 - mean=1950., delta=50.
518 // 7842 - mean=1930., delta=30.
519 if (abs(bdDigit->GetTime() - 1930.) < 30.) {
520 // aBd[bdDigit->GetMod()]++;
521 nBd++;
522 }
523 }
524 if (nBd >= 2)
525 bdTrig = kTRUE;
526
527 fNBd = nBd;
528
529 return bdTrig;
530}
531
533{
534 Bool_t fdTrig = kFALSE;
535
536 // Search for a number of FD signals inside the trigger window (+-35 ns)
537 TClonesArray* fdDigits = fBTrigInfo->GetFDDigits();
538 // Double_t fdamp = 0.;
540 Int_t stop = start + 2 * FDTrigWindow;
541 Int_t peak = -100000;
542 // fdamp = (Double_t)trInfo->GetFDAmp(); // Could be out of trig window
543 BmnTrigWaveDigit* fdDigit0 = (BmnTrigWaveDigit*)fdDigits->UncheckedAt(0);
544 for (Int_t i = start; i <= stop; ++i)
545 if (fdDigit0->GetValue()[i] > peak)
546 peak = fdDigit0->GetValue()[i];
547
548 // cout << "peak=" << peak << endl;
549 // 7988 (same for 7842) - 4500, 4250 - half the threshold height
550 if (peak < fFDPeakLimit)
551 fdTrig = kTRUE;
552
553 return fdTrig;
554}
555
557{
558 Int_t bins[34] = {0};
559 Int_t maxBin = 0;
560
561 for (Int_t i = 0; i < hits->GetEntriesFast(); i++) {
562 BmnTofHit* hit = (BmnTofHit*)hits->At(i);
563 if (!hit)
564 continue;
565
566 Double_t t = hit->GetTimeStamp();
567 if (t >= -1766.0 && t <= -66.0) {
568 Int_t bin = (Int_t)((t + 1766.0) / 50.0);
569 if (bin >= 0 && bin < 34) {
570 bins[bin]++;
571 if (bins[bin] > maxBin)
572 maxBin = bins[bin];
573 }
574 }
575 }
576 return maxBin;
577}
578
580{
581 return GetMaxTofHitsInBin(hits) >= threshold;
582}
int i
Definition P4_F32vec4.h:22
bool Bool_t
int Int_t
int Ssiz_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
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...
vector< int16_t > & GetValue()
Int_t GetBC2Int(Int_t leftEl, Int_t rightEl)
Double_t GetFDEfficiency(Int_t runId, Int_t ntrPV)
Double_t GetEfficiencyOrError(TH2D *hist, Int_t runId, Int_t ntrPV, Bool_t isEff)
Int_t GetMaxTofHitsInBin(TClonesArray *hits)
Double_t GetTriggerEfficiency(Int_t runId, Int_t ntrPV)
Bool_t GetFluxRejectionFactorWithError(Int_t runId, Double_t &factor, Double_t &err)
Bool_t GetTriggerEfficiencyWithErrors(Int_t runId, Int_t ntrPV, Double_t &eff, Double_t &statErr, Double_t &systErr, Double_t &errSystErr)
Double_t GetBDEfficiency(Int_t runId, Int_t ntrPV)
Bool_t HasDistantPileup(TClonesArray *hits, Int_t threshold)
CbmVertex.h.
Definition CbmVertex.h:21
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
virtual Int_t GetNbinsY() const
virtual Double_t GetBinError(Int_t bin) const
virtual void GetBinXYZ(Int_t binglobal, Int_t &binx, Int_t &biny, Int_t &binz) const
virtual Int_t GetNbinsX() const
virtual Int_t FindBin(Double_t x, Double_t y=0, Double_t z=0)
virtual Double_t GetBinContent(Int_t bin) const
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
TObject * UncheckedAt(Int_t i) const
friend friend class TClonesArray
const char * Data() const
virtual Int_t Sizeof() const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Double_t Z() const
void SetXYZ(Double_t x, Double_t y, Double_t z)
Double_t Y() const
Double_t X() const
RVec< PromoteType< T > > abs(const RVec< T > &v)
RVec< PromoteTypes< T0, T1 > > pow(const RVec< T0 > &v, const T1 &y)
RVec< PromoteType< T > > sqrt(const RVec< T > &v)