3#include "BmnTrigDigit.h"
4#include "BmnTrigWaveDigit.h"
7#include <TClonesArray.h>
23 , fBPrimaryVertex(nullptr)
26 , fFDTrigWindowLeftEdge(-1)
29 InitEfficiencyInput();
45 , fBPrimaryVertex(nullptr)
48 , fFDTrigWindowLeftEdge(-1)
51 InitEfficiencyInput();
53 fDstFile = TFile::Open(dstFileName,
"READONLY");
55 if (!fDstFile || !fDstFile->IsOpen() || fDstFile->IsZombie()) {
56 LOGF(error,
"Cannot open file %s", dstFileName.Data());
60 fDstTree = (TTree*)fDstFile->Get(
"bmndata");
62 LOGF(error,
"Cannot find tree bmndata in the file");
67 Int_t ret = fDstTree->SetBranchAddress(
"BmnTrigInfo.", &fBTrigInfo);
68 if ((ret < 0) || (ret > 2)) {
69 LOGF(error,
"Cannot match branch BmnTrigInfo.");
73 ret = fDstTree->SetBranchAddress(
"PrimaryVertex.", &fBPrimaryVertex);
74 if ((ret < 0) || (ret > 2)) {
75 LOGF(error,
"Cannot match branch PrimaryVertex.");
81 Ssiz_t startCh = dstFileName.Index(
"mpd_run_Top_");
83 LOGF(error,
"Dst file name must contain \"mpd_run_Top_<RunId>\"");
87 startCh = dstFileName.Index(
"mpd_run_Top_") + TString(
"mpd_run_Top_").Sizeof() - 1;
88 fRunId = (TString(dstFileName(startCh, 4))).Atoi();
89 LOGF(info,
"runId = %d", fRunId);
91 SetBC2IntCutByRun(fRunId);
92 SetFDTrigWindowLeftEdgeByRun(fRunId);
93 SetFDPeakLimitByRun(fRunId);
95 LOGF(info,
"File %s successfully opened", dstFileName.Data());
110 , fBTrigInfo(trigInfo)
111 , fBPrimaryVertex(primaryVertex)
114 , fFDTrigWindowLeftEdge(-1)
117 InitEfficiencyInput();
119 LOGF(info,
"runId = %d", fRunId);
121 SetBC2IntCutByRun(fRunId);
122 SetFDTrigWindowLeftEdgeByRun(fRunId);
123 SetFDPeakLimitByRun(fRunId);
128 LOGF(debug,
"BmnTriggerEfficiencyRun8::GetBDEfficiency(): Start");
129 return GetEfficiencyOrError(fHBd, runId, ntrPV, kTRUE);
134 LOGF(debug,
"BmnTriggerEfficiencyRun8::GetFDEfficiency(): Start");
135 return GetEfficiencyOrError(fHFd, runId, ntrPV, kTRUE);
140 LOGF(debug,
"BmnTriggerEfficiencyRun8::GetTriggerEfficiency(): Start");
142 Double_t bdEff = GetEfficiencyOrError(fHBd, runId, ntrPV, kTRUE);
146 return bdEff * GetEfficiencyOrError(fHFd, runId, ntrPV, kTRUE);
154 Double_t& errSystErr)
156 statErr = systErr = errSystErr = -1.;
161 else if (eff == 0.) {
162 statErr = systErr = errSystErr = 0.;
166 Double_t relStatErrBD =
167 GetEfficiencyOrError(fHBd, runId, ntrPV, kFALSE) / GetEfficiencyOrError(fHBd, runId, ntrPV, kTRUE);
168 Double_t relStatErrFD =
169 GetEfficiencyOrError(fHFd, runId, ntrPV, kFALSE) / GetEfficiencyOrError(fHFd, runId, ntrPV, kTRUE);
170 statErr = eff *
sqrt(relStatErrBD * relStatErrBD + relStatErrFD * relStatErrFD);
172 systErr = abs(GetEfficiencyOrError(fHCctSyst, runId, ntrPV, kTRUE));
174 errSystErr = GetEfficiencyOrError(fHCctSyst, runId, ntrPV, kFALSE);
182 Double_t& errSystErr)
184 if (!fBPrimaryVertex) {
185 LOGF(debug,
"Primary Vertex branch should be defined");
198 LOGF(error,
"This BmnTriggerEfficiencyRun8 object is not valid");
202 Int_t bin = fHFrf->FindBin(runId);
203 LOGF(debug,
"BmnTriggerEfficiencyRun8::GetFluxRejectionFactorWithError(): bin = %d", bin);
204 Int_t binx, biny, binz;
205 fHFrf->GetBinXYZ(bin, binx, biny, binz);
206 LOGF(debug,
"BmnTriggerEfficiencyRun8::GetFluxRejectionFactorWithError(): binx = %d, biny = %d, binz = %d", binx,
209 if ((binx < 1) || (binx > fHFrf->GetNbinsX())) {
210 LOGF(error,
"Run id is out of analysis range");
214 factor = fHFrf->GetBinContent(bin);
218 err = fHFrf->GetBinError(bin);
230 Double_t pvx, pvy, pvz;
232 pvx = fBPrimaryVertex->
GetX();
233 pvy = fBPrimaryVertex->
GetY();
234 pvz = fBPrimaryVertex->
GetZ();
237 LOGF(debug,
"(pvx,pvy,pvz,pvntr) = (%f,%f,%f,%d)", pvx, pvy, pvz, pvntr);
240 vtxPos.SetXYZ(0.3179, 0., -0.0169);
241 if ((abs(pvz - vtxPos.Z()) > 1.) || (pow(pvx - vtxPos.X(), 2) + pow(pvy - vtxPos.Y(), 2) > pow(1.5, 2))
244 LOGF(debug,
"Event primary vertex does not pass analysis conditions");
248 Double_t pv_chi2tondf = fBPrimaryVertex->
GetChi2() / fBPrimaryVertex->
GetNDF();
249 if ((pv_chi2tondf < 0.1) || (pv_chi2tondf > 10)) {
250 LOGF(debug,
"Event primary vertex does not pass analysis conditions");
254 Int_t bc2inttw40 = GetBC2Int(258, 267);
255 if ((bc2inttw40 > fBC2IntCut) || (fBC2IntCut < 0)) {
256 LOGF(debug,
"This event does not pass BC2 analysis conditions for pile up");
261 auto bitCCT2 = (TrigPattern >> 7) & 1;
262 if ((bitCCT2 != 1) || !IsBDTriggered() || !IsFDTriggered()) {
263 LOGF(debug,
"This event does not pass trigger conditions");
272 if ((evId >= fDstTree->GetEntries()) || (evId < 0)) {
273 LOGF(debug,
"Event id is out of range for this file");
277 fDstTree->GetEntry(evId);
282Double_t BmnTriggerEfficiencyRun8::GetEfficiencyOrError(TH2D* hist, Int_t runId, Int_t ntrPV, Bool_t isEff)
285 LOGF(error,
"Number of tracks in PV is out of analysis range");
289 LOGF(error,
"This BmnTriggerEfficiencyRun8 object is not valid");
293 Int_t bin = hist->FindBin(runId, ntrPV);
294 LOGF(debug,
"BmnTriggerEfficiencyRun8::GetEfficiencyOrError(): bin = %d", bin);
295 Int_t binx, biny, binz;
296 hist->GetBinXYZ(bin, binx, biny, binz);
297 LOGF(debug,
"BmnTriggerEfficiencyRun8::GetEfficiencyOrError(): binx = %d, biny = %d, binz = %d", binx, biny, binz);
299 if ((binx < 1) || (binx > hist->GetNbinsX())) {
300 LOGF(error,
"Run id is out of analysis range");
304 if (biny > hist->GetNbinsY()) {
306 return hist->GetBinContent(binx, hist->GetNbinsY());
308 return hist->GetBinError(binx, hist->GetNbinsY());
314 ret = hist->GetBinContent(bin);
316 ret = hist->GetBinError(bin);
321void BmnTriggerEfficiencyRun8::InitEfficiencyInput()
323 TString fileName1 = TString(getenv(
"VMCWORKDIR")) + TString(
"/parameters/triggerefficiency/EffBdFd_Run8_v2.root");
324 fEffFile1 =
new TFile(fileName1,
"READ");
325 if (!fEffFile1->IsOpen() || fEffFile1->IsZombie()) {
326 LOGF(error,
"Cannot open file %s", fileName1.Data());
331 fHBd = (TH2D*)fEffFile1->Get(
"hbd");
333 LOGF(error,
"Cannot find histogram hbd in the file");
337 fHFd = (TH2D*)fEffFile1->Get(
"hfd");
339 LOGF(error,
"Cannot find histogram hfd in the file");
344 LOGF(info,
"File %s successfully opened", fileName1.Data());
346 TString fileName2 = TString(getenv(
"VMCWORKDIR")) + TString(
"/parameters/triggerefficiency/EffCctSyst_Run8.root");
347 fEffFile2 =
new TFile(fileName2,
"READ");
348 if (!fEffFile2->IsOpen() || fEffFile2->IsZombie()) {
349 LOGF(error,
"Cannot open file %s", fileName2.Data());
354 fHCctSyst = (TH2D*)fEffFile2->Get(
"herr");
356 LOGF(error,
"Cannot find histogram herr in the file");
361 LOGF(info,
"File %s successfully opened", fileName2.Data());
364 TString(getenv(
"VMCWORKDIR")) + TString(
"/parameters/triggerefficiency/FluxRejectionFactor_Run8.root");
365 fEffFile3 =
new TFile(fileName3,
"READ");
366 if (!fEffFile3->IsOpen() || fEffFile3->IsZombie()) {
367 LOGF(error,
"Cannot open file %s", fileName3.Data());
372 fHFrf = (TH1D*)fEffFile3->Get(
"hfrc_bt");
374 LOGF(error,
"Cannot find histogram hfrc_bt in the file");
379 LOGF(info,
"File %s successfully opened", fileName3.Data());
384void BmnTriggerEfficiencyRun8::SetBC2IntCutByRun(Int_t runId)
388 else if (runId < 7984)
390 else if (runId < 8005)
392 else if (runId < 8011)
394 else if (runId < 8030)
396 else if (runId < 8060)
404void BmnTriggerEfficiencyRun8::SetFDTrigWindowLeftEdgeByRun(Int_t runId)
406 fFDTrigWindowLeftEdge = 279 - FDTrigWindow;
408 fFDTrigWindowLeftEdge += 2;
409 else if (runId < 7114)
410 fFDTrigWindowLeftEdge += 3;
411 else if (runId < 7237)
412 fFDTrigWindowLeftEdge += 2;
413 else if (runId < 7560)
414 fFDTrigWindowLeftEdge += 0;
415 else if (runId < 7594)
416 fFDTrigWindowLeftEdge += 3;
421void BmnTriggerEfficiencyRun8::SetFDPeakLimitByRun(Int_t runId)
426 else if (runId < 7114)
428 else if (runId < 7148)
430 else if (runId < 7237)
432 else if (runId < 7258)
434 else if (runId < 7429)
436 else if (runId < 7486)
438 else if (runId < 7560)
440 else if (runId < 7594)
446Int_t BmnTriggerEfficiencyRun8::GetBC2Int(Int_t leftEl, Int_t rightEl)
452 if (bc2Digits->GetEntriesFast() != 1) {
453 LOGF(error,
"Unexpected behaviour. bc2Digits->GetEntriesFast() = %d", bc2Digits->GetEntriesFast());
457 for (Int_t
i = leftEl;
i <= rightEl; ++
i) {
465Bool_t BmnTriggerEfficiencyRun8::IsBDTriggered()
467 Bool_t bdTrig = kFALSE;
470 TClonesArray* bdDigits = fBTrigInfo->
GetBDDigits();
473 for (Int_t iBd = 0; iBd < bdDigits->GetEntriesFast(); iBd++) {
475 if ((bdDigit->
GetMod() < 0) || (bdDigit->
GetMod() > 39)) {
476 LOGF(error,
"Unexpected BD module number %d", bdDigit->
GetMod());
481 if (abs(bdDigit->
GetTime() - 1930.) < 30.) {
494Bool_t BmnTriggerEfficiencyRun8::IsFDTriggered()
496 Bool_t fdTrig = kFALSE;
499 TClonesArray* fdDigits = fBTrigInfo->
GetFDDigits();
501 Int_t start = fFDTrigWindowLeftEdge;
502 Int_t stop = start + 2 * FDTrigWindow;
503 Int_t peak = -100000;
506 for (Int_t
i = start;
i <= stop; ++
i)
512 if (peak < fFDPeakLimit)
friend F32vec4 sqrt(const F32vec4 &a)
UInt_t GetInputSignalsAR()
TClonesArray * GetBDDigits()
TClonesArray * GetBC2Digits()
TClonesArray * GetFDDigits()
Short_t * GetShortValue() const
BmnTriggerEfficiencyRun8()
Double_t GetFDEfficiency(Int_t runId, Int_t ntrPV)
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 IsEventAnalysable()