ATLAS Offline Software
Loading...
Searching...
No Matches
HIPileupTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// HIPileupTool.cxx
6
13
16
17#include "TSystem.h"
18#include "TH1D.h"
19#include "TH2D.h"
20#include "TFile.h"
21#include <vector>
22#include <exception>
23
24namespace HI
25
26{
27
28HIPileupTool::HIPileupTool( const std::string& myname) : AsgTool(myname),
29 m_accept("HIPileup")
30 {
31 declareProperty("EtCutAndPurity", m_etCutAndPurity, "Et and purity for efficiency calculation");
32 declareProperty("inpFilePath", m_fname, "Calibration file path");
33
34 m_setup = 0;
35}
36
38
39 if (m_setup) {
40 delete m_hEvents; delete m_hPileUp;
41 delete m_hCut; delete m_hEff; delete m_hPurity;
42 }
43}
44
46
47 ATH_MSG_VERBOSE( "Initialising tool " << name() );
48
49 m_accept.addCut("pileupVeto","for pileup rejection");
50
51 const char* fullInpFilePath;
52 if (!m_fname.empty()) fullInpFilePath = gSystem->ExpandPathName (m_fname.c_str());
53 else fullInpFilePath = gSystem->ExpandPathName ("$ROOTCOREBIN/data/HIEventUtils/HIRun2PileUp_PbPb5p02_v2.root");
54 if (gSystem->AccessPathName(fullInpFilePath)) throw std::invalid_argument(("File not found at \"" + (std::string)fullInpFilePath + "\"").c_str());
55
56 ATH_MSG_INFO(("Read pileup cuts from " + (std::string)fullInpFilePath).c_str());
57 TFile* fIn = new TFile(fullInpFilePath);
58
59 std::string hname;
60 hname = "hEvents"; if (!(fIn->GetListOfKeys()->Contains(hname.c_str()))) {
61 fIn->Close(); throw std::invalid_argument(("Expected histogram \"" + hname + "\" not found in \"" + m_fname + "\"").c_str());}
62 hname = "hPileUp"; if (!(fIn->GetListOfKeys()->Contains(hname.c_str()))) {
63 fIn->Close(); throw std::invalid_argument(("Expected histogram \"" + hname + "\" not found in \"" + m_fname + "\"").c_str());}
64 hname = "hCut"; if (!(fIn->GetListOfKeys()->Contains(hname.c_str()))) {
65 fIn->Close(); throw std::invalid_argument(("Expected histogram \"" + hname + "\" not found in \"" + m_fname + "\"").c_str());}
66 hname = "hEff"; if (!(fIn->GetListOfKeys()->Contains(hname.c_str()))) {
67 fIn->Close(); throw std::invalid_argument(("Expected histogram \"" + hname + "\" not found in \"" + m_fname + "\"").c_str());}
68 hname = "hPurity"; if (!(fIn->GetListOfKeys()->Contains(hname.c_str()))) {
69 fIn->Close(); throw std::invalid_argument(("Expected histogram \"" + hname + "\" not found in \"" + m_fname + "\"").c_str());}
70
71 m_hEvents = (TH2D*)((TH2D*)fIn->Get("hEvents"))->Clone("hEvents_HIPileupTool"); m_hEvents->SetDirectory(0);
72 m_hPileUp = (TH2D*)((TH2D*)fIn->Get("hPileUp"))->Clone("hPileUp_HIPileupTool"); m_hPileUp->SetDirectory(0);
73 m_hCut = (TH1D*)((TH1D*)fIn->Get("hCut"))->Clone("hCut_HIPileupTool"); m_hCut->SetDirectory(0);
74 m_hEff = (TH1D*)((TH1D*)fIn->Get("hEff"))->Clone("hEff_HIPileupTool"); m_hEff->SetDirectory(0);
75 m_hPurity = (TH1D*)((TH1D*)fIn->Get("hPurity"))->Clone("hPurity_HIPileupTool"); m_hPurity->SetDirectory(0);
76 m_setup = 1;
77
78 fIn->Close();
79
80 m_etThreshold = 6.0;
81 m_purityCut = -1.0;
82 if (!m_etCutAndPurity.empty()) {
83 if (m_etCutAndPurity.size()<2) ATH_MSG_WARNING("Cuts vector should have two elements. Will use default settings");
84 else {
85 if (m_etCutAndPurity.at(1)<0 || m_etCutAndPurity.at(1)>1) ATH_MSG_WARNING("Purity cut should be between 0 and 1. Will use default settings");
86 else {
89 if (fabs(m_purityCut-1)<1e-6) m_purityCut -= 1e-3;
90 }
91 }
92 }
93
94 if (m_purityCut<0) {
95 ATH_MSG_INFO("ET threshold for purity cut = NONE");
96 ATH_MSG_INFO("Purity cut = DEFAULT");
97 }
98 else {
99 ATH_MSG_INFO("ET threshold for purity cut = " << m_etThreshold << " TeV");
100 ATH_MSG_INFO("Purity cut = " << m_purityCut );
101 }
102
103 for (int ibx=0;ibx<m_hPileUp->GetNbinsX();ibx++) {
104 if (m_hPileUp->GetXaxis()->GetBinCenter(ibx+1) < m_etThreshold) continue;
105 int NY = m_hPileUp->GetNbinsY();
106 if (m_hPileUp->Integral(ibx+1,ibx+1,1,NY) == 0) {m_hCut->SetBinContent(ibx+1,0); continue;}
107 //Cut on 5.0 because efficiency is calculated only for FCal < 5 TeV
108 if (m_hPileUp->GetXaxis()->GetBinCenter(ibx+1)>5.0 && fabs(m_purityCut-1)<1e-6) {m_hCut->SetBinContent(ibx+1,0); continue;}
109 for (int iby=0;iby<NY;iby++) {
110 if (m_hPileUp->Integral(ibx+1,ibx+1,NY-iby,NY)/m_hPileUp->Integral(ibx+1,ibx+1,1,NY) < m_purityCut) continue;
111 m_hCut->SetBinContent(ibx+1,m_hPileUp->GetYaxis()->GetBinCenter(NY-iby)); break;
112 }
113 }
114
115 for (int ibx=0;ibx<m_hEvents->GetNbinsX();ibx++) {
116 if (m_hEvents->GetXaxis()->GetBinCenter(ibx+1) < m_etThreshold) {m_hEff->SetBinContent(ibx+1,1-m_hEff->GetBinContent(ibx+1)); continue;}
117 double cut = m_hEvents->Integral(ibx+1,ibx+1,m_hEvents->GetYaxis()->FindBin(m_hCut->GetBinContent(ibx+1)), m_hEvents->GetNbinsY());
118 double all = m_hEvents->Integral(ibx+1,ibx+1,1,m_hEvents->GetYaxis()->GetNbins()) - m_hPileUp->Integral(ibx+1,ibx+1,1,m_hPileUp->GetYaxis()->GetNbins());
119 double pu_cut = m_hPileUp->Integral(ibx+1,ibx+1,m_hPileUp->GetYaxis()->FindBin(m_hCut->GetBinContent(ibx+1)), m_hPileUp->GetNbinsY());
120 double pu_all = m_hPileUp->Integral(ibx+1,ibx+1,1,m_hPileUp->GetYaxis()->GetNbins());
121 double eff = 1 - (cut - pu_cut)/all; if ((cut - pu_cut) < 0) eff=1;
122 double pty = pu_cut/pu_all;
123 if (all!=0) m_hEff->SetBinContent(ibx+1,eff);
124 if (pu_all!=0) m_hPurity->SetBinContent(ibx+1,pty);
125 }
126
127 return StatusCode::SUCCESS;
128}
129
131
132 bool kPileup = false;
133 double FCal_Et = get_et(evShCont);
134 double nNeutrons;
135 nNeutrons = get_nNeutrons(ZdcCont);
136 if (nNeutrons > m_hCut->GetBinContent(m_hCut->FindFixBin(FCal_Et))) kPileup = true;
137
138 return kPileup;
139}
140
141double HIPileupTool::get_efficiency(const xAOD::HIEventShapeContainer& evShCont, double FCal_Et) const{
142
143 FCal_Et = get_et(evShCont);
144 return m_hEff->GetBinContent(m_hEff->FindFixBin(FCal_Et));
145}
146
147double HIPileupTool::get_purity(const xAOD::HIEventShapeContainer& evShCont, double& FCal_Et) {
148
149 FCal_Et = get_et(evShCont);
150 return m_hPurity->GetBinContent(m_hPurity->FindFixBin(FCal_Et));
151}
152
153
155 double Fcal_Et=0;
156 Fcal_Et = evShCont.at(5)->et()*1e-6;
157 return Fcal_Et;
158}
159
161
162 bool isCalib=1;
163 double ZdcE=0;
164 for (const auto *zdcModule : ZdcCont) {
165 if (zdcModule->zdcType()!=0) continue;
166
167 static const SG::ConstAccessor<float> CalibEnergyAcc("CalibEnergy");
168 if (!(CalibEnergyAcc.isAvailable(*zdcModule))) {isCalib = 0; continue;}
169 float modE = CalibEnergyAcc(*zdcModule);
170 ZdcE += modE;
171 }
172 if (!isCalib) throw std::invalid_argument("ZDC Module not Calibrated");
173
174 return ZdcE/m_npeak;
175}
176
178 AsgTool::print();
179 if (m_purityCut<0) {
180 ATH_MSG_INFO("ET threshold for purity cut = NONE");
181 ATH_MSG_INFO("Purity cut = DEFAULT");
182 }
183 else {
184 ATH_MSG_INFO("ET threshold for purity cut = " << m_etThreshold << " TeV");
185 ATH_MSG_INFO("Purity cut = " << m_purityCut );
186 }
187}
188
189void HIPileupTool::write(TFile* fOut) {
190
191 fOut->cd(0);
192 m_hEvents->Write();
193 m_hPileUp->Write();
194 m_hCut->Write();
195 m_hEff->Write();
196 m_hPurity->Write();
197}
198//R.Longo 13-10-2019 - Replacing PATCore/TAccept (inherited from 21.0 HI-equalization)
200{
202 bool pileup_dec = !is_pileup(evShCont, ZdcCont);
203 asg::AcceptData(&m_accept).setCutResult("pileupVeto", pileup_dec);
204 return m_accept;
205}
206
207} // HI
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
Helper class to provide constant type-safe access to aux data.
bool isCalib()
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const T * at(size_type n) const
Access an element, as an rvalue.
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
double get_efficiency(const xAOD::HIEventShapeContainer &, double) const
virtual void print() const override
Print the state of the tool.
const double m_npeak
double get_nNeutrons(const xAOD::ZdcModuleContainer &ZdcCont) const
asg::AcceptInfo m_accept
double get_et(const xAOD::HIEventShapeContainer &evShCont) const
std::vector< double > m_etCutAndPurity
std::string m_fname
double get_purity(const xAOD::HIEventShapeContainer &, double &)
HIPileupTool(const std::string &myname="HIPileupTool")
void write(TFile *fOut)
virtual const asg::AcceptInfo & getAcceptInfo(const xAOD::HIEventShapeContainer &evShCont, const xAOD::ZdcModuleContainer &ZdcCont) const override
bool is_pileup(const xAOD::HIEventShapeContainer &, const xAOD::ZdcModuleContainer &) const override
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
void setCutResult(const std::string &cutName, bool cutResult)
Set the result of a cut, based on the cut name (safer)
Definition AcceptData.h:134
void clear()
Clear all bits.
Definition AcceptData.h:54
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
ZdcModuleContainer_v1 ZdcModuleContainer
HIEventShapeContainer_v2 HIEventShapeContainer
Define the latest version of the container.