ATLAS Offline Software
Loading...
Searching...
No Matches
testIsolationCloseByCorrectionTool.cxx File Reference
#include <memory>
#include <cstdlib>
#include <utility>
#include <ctime>
#include <TFile.h>
#include <TError.h>
#include <TString.h>
#include <TEnv.h>
#include "xAODRootAccess/Init.h"
#include "xAODRootAccess/TEvent.h"
#include "xAODRootAccess/TStore.h"
#include "xAODEventInfo/EventInfo.h"
#include "xAODEgamma/ElectronContainer.h"
#include "xAODEgamma/PhotonContainer.h"
#include "xAODMuon/MuonContainer.h"
#include <xAODCore/ShallowCopy.h>
#include <xAODBase/ObjectType.h>
#include <xAODBase/IParticleHelpers.h>
#include "IsolationSelection/IsolationCloseByCorrectionTool.h"
#include "IsolationSelection/TestMacroHelpers.h"
#include "IsolationSelection/IsolationSelectionTool.h"
#include "AsgMessaging/MessageCheck.h"
#include "AsgTools/AnaToolHandle.h"

Go to the source code of this file.

Functions

std::string MuonIso ("")
std::string ElectronIso ("")
std::string PhotonIso ("")
float MuonPt (0)
float ElectronPt (0)
float PhotonPt (0)
float MuonEta (0)
float ElectronEta (0)
float PhotonEta (0)
StatusCode setConfigWP (TString conf)
template<typename Container>
StatusCode RetrieveContainer (xAOD::TEvent &Ev, const std::string &Key, Container *&C, xAOD::ShallowAuxContainer *&Aux)
int main (int argc, char **argv)

Function Documentation

◆ ElectronEta()

float ElectronEta ( 0 )

◆ ElectronIso()

std::string ElectronIso ( "" )

◆ ElectronPt()

float ElectronPt ( 0 )

◆ main()

int main ( int argc,
char ** argv )

Definition at line 90 of file testIsolationCloseByCorrectionTool.cxx.

90 {
93
94 const char* APP_NAME = argv[ 0 ];
95 if( argc < 3 ) {
96 ANA_MSG_ERROR("No input file name or WP config specified!");
97 ANA_MSG_ERROR("Usage: %s <WPconfig> <xAOD file> <NEvents>");
98 return EXIT_FAILURE;
99 }
101 auto start = std::time(nullptr);
102 ANA_MSG_INFO("Initialized " << std::ctime(&start));
103
104 TString outputTree = "testIsoCloseByTool_out.root";
105 ANA_MSG_INFO("Name of output file: " << outputTree);
106
107 // Open the input file:
108 const TString fileName = argv[ 2 ];
109 ANA_MSG_INFO("Opening file: " << fileName.Data());
110 std::unique_ptr< TFile > ifile( TFile::Open( fileName, "READ" ) );
111 if( !ifile.get() ) return EXIT_FAILURE;
112
113 const TString configFile = argv[ 1 ];
114 ANA_CHECK( setConfigWP(configFile) );
115
116 // Create a TEvent object:
118 ANA_CHECK( event.readFrom(ifile.get()) );
119 ANA_MSG_INFO("Number of events in the file " << static_cast<int>(event.getEntries()));
120
121 // Create a transient object store. Needed for the tools.
123
124 ANA_MSG_INFO("Initialize instance of the IsolationSelectionTool");
125 asg::AnaToolHandle<CP::IIsolationSelectionTool> IsoSelectionTool("CP::IsolationSelectionTool/IsoSelectionTool");
126
127 ANA_CHECK( IsoSelectionTool.setProperty("MuonWP", MuonIso) );
128 ANA_CHECK( IsoSelectionTool.setProperty("ElectronWP", ElectronIso) );
129 ANA_CHECK( IsoSelectionTool.setProperty("PhotonWP", PhotonIso) );
130 ANA_CHECK( IsoSelectionTool.setProperty("OutputLevel", MSG::FATAL) );
131 ANA_CHECK( IsoSelectionTool.retrieve() );
132
133 ANA_MSG_INFO("Initialize instance of the IsolationCloseByCorrectionTool");
134 asg::AnaToolHandle<CP::IIsolationCloseByCorrectionTool> IsoCloseByTool("CP::IsolationCloseByCorrectionTool/IsoCorrectionTool");
135
136 ANA_CHECK( IsoCloseByTool.setProperty("IsolationSelectionTool", IsoSelectionTool.getHandle()) ); //Pass the instance of the created isolation tool
137 ANA_CHECK( IsoCloseByTool.setProperty("SelectionDecorator", "isCloseByObject") ); //Name of the quality decorator defining all nearby particles used to correct the isolation of a given particle
138
139 //ANA_CHECK(m_isoCloseByTool.setProperty("PassOverlapDecorator","passOR")); //Usingnly using partilces after the OR (auxdata<char>("passOR") == 1)
140 ANA_CHECK( IsoCloseByTool.setProperty("IsolationSelectionDecorator", "correctedIsol") ); //The name of the final isolation decorator. The tool internally calls P->auxdata<char>("CorrectedIsol") = m_IsoTool->accept(*P)
141
142 //By default all particles in the container are corrected. For the purpose of saving processing time one can optionally
143 //define this property. Then the isolation of the particle is only corrected only if the particle passes the input quality or if this decorator is set to true
144 //ANA_CHECK(m_isoCloseByTool.setProperty("CorrectIsolationOf", "CorrectTheThing"));
145
146 //The closeByIsoCorrectionTool accesses the default variables of a particle via the original container links
147 //Optionally one can backup the isolation values before correction. Then the tool creates an auxelement called <BackupPrefix>_<IsoVariable> This might be interesting if the people are interested in writing
148 //out the default values using CxAODs
149 ANA_CHECK( IsoCloseByTool.setProperty("OutputLevel", MSG::DEBUG) );
150 ANA_CHECK( IsoCloseByTool.setProperty("BackupPrefix", "default") );
151 ANA_CHECK( IsoCloseByTool.retrieve() );
152
153 //Define the output
154 TFile* ofile;
155 ofile = TFile::Open(outputTree, "RECREATE");
156
157 TTree *tree = new TTree("otree", "otree");
158 CP::IsoCorrectionTestHelper eleBranches(tree, "Electrons", IsoSelectionTool->getElectronWPs());
159 CP::IsoCorrectionTestHelper muoBranches(tree, "Muons", IsoSelectionTool->getMuonWPs());
160 CP::IsoCorrectionTestHelper phoBranches(tree, "Photons", IsoSelectionTool->getPhotonWPs());
161
162 Long64_t maxEVT = atoll( argv[ 3 ] );
163 Long64_t entries = event.getEntries();
164 if ((entries < maxEVT) || (maxEVT <= 0)) {
165 maxEVT = entries;
166 }
167 ANA_MSG_INFO(Form("%lld events found, %lld events will be processed.", entries, maxEVT));
168
169 const int INTERVAL = maxEVT > 20000 ? 10000 : maxEVT / 10;
170
171 xAOD::ShallowAuxContainer *AuxMuons(nullptr), *AuxElectrons(nullptr), *AuxPhotons(nullptr);
172
173 xAOD::MuonContainer* Muons(nullptr);
174 xAOD::ElectronContainer* Electrons(nullptr);
175 xAOD::PhotonContainer* Photons(nullptr);
176
177 SG::AuxElement::Decorator<char> dec_PassQuality("isCloseByObject");
178 SG::AuxElement::Decorator<char> dec_PassIsol("defaultIso");
179
180 for (Long64_t entry(0); entry < maxEVT; ++entry) {
181 event.getEntry(entry);
182
183 const xAOD::EventInfo* ei(0);
184 ANA_CHECK(event.retrieve(ei, "EventInfo"));
185
186 if (entry % INTERVAL == 0)
187 ANA_MSG_INFO(Form("--> Event %lld \t EventNumber: %llu RunNumber: %u", entry, ei->eventNumber(), ei->runNumber()));
188
189 //Retrieve the Containers and create the ShallowAux links
190 ANA_CHECK( RetrieveContainer(event, "Muons", Muons, AuxMuons) );
191 ANA_CHECK( RetrieveContainer(event, "Electrons", Electrons, AuxElectrons).isSuccess() );
192 ANA_CHECK( RetrieveContainer(event, "Photons", Photons, AuxPhotons).isSuccess() );
193
194 for(const auto el : *Electrons) {
195 //Store if the electron passes the isolation
196 const char passIsol = IsoSelectionTool->accept(*el) ? 1 : 0;
197 dec_PassIsol(*el) = passIsol;
198 //Quality criteria only baseline kinematic selection
199 const char passQuality = (el->pt() > ElectronPt && std::abs(el->eta()) < ElectronEta) ? 1 : 0;
200 dec_PassQuality(*el) = passQuality;
201 }
202 for(const auto ph : *Photons) {
203 //Store if the photon passes the isolation (only needed for later comparisons)
204 const char passIsol = IsoSelectionTool->accept(*ph) ? 1 : 0;
205 dec_PassIsol(*ph) = passIsol;
206 //Quality criteria only baseline kinematic selection
207 const char passQuality = (ph->pt() > PhotonPt && std::abs(ph->eta()) < PhotonEta) ? 1 : 0;
208 dec_PassQuality(*ph) = passQuality;
209 }
210 for (const auto mu : *Muons) {
211 //Store if the muon passes the isolation
212 const char passIsol = IsoSelectionTool->accept(*mu) ? 1 : 0;
213 dec_PassIsol(*mu) = passIsol;
214 //Quality criteria only baseline kinematic selection
215 const char passQuality = (mu->pt() > MuonPt && std::abs(mu->eta()) < MuonEta) ? 1 : 0;
216 dec_PassQuality(*mu) = passQuality;
217 }
218
219 //Pass the things towards the IsoCorrectionTool
220 if (IsoCloseByTool->getCloseByIsoCorrection(Electrons, Muons, Photons).code() == CP::CorrectionCode::Error){
221 return EXIT_FAILURE;
222 }
223
224 // The isoCorrectionTool has now corrected everything using close-by objects satisfiyng the dec_PassQuality criteria
225 // The name of the decorator is set via the 'SelectionDecorator' property of the tool
226 // Optionally one can also define that the tool shall only objects surviving the overlap removal without changing the initial decorator
227 // Use therefore the 'PassOverlapDecorator' property to define the decorators name
228 // If you define the 'BackupPrefix' property then the original values are stored before correction <Prefix>_<IsolationCone>
229 // The final result whether the object passes the isolation criteria now can be stored in the 'IsolationSelectionDecorator' e.g. 'CorrectedIso'
230
231 //Store everything in the final ntuples
232 ANA_CHECK( eleBranches.Fill(Electrons) );
233 ANA_CHECK( muoBranches.Fill(Muons) );
234 ANA_CHECK( phoBranches.Fill(Photons) );
235 tree->Fill();
236
237 }
238 ofile->cd();
239 tree->Write();
240 ofile->Close();
241
242 auto end = std::time(nullptr);
243 ANA_MSG_INFO(Form("Ran on %i event for testing %s",(int)maxEVT, std::ctime(&end)));
244
245 return EXIT_SUCCESS;
246}
#define APP_NAME
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
@ Error
Some error happened during the object correction.
SG::Decorator< T, ALLOC > Decorator
Definition AuxElement.h:575
a modified tool handle that allows its owner to configure new tools from the C++ side
Class creating a shallow copy of an existing auxiliary container.
Tool for accessing xAOD files outside of Athena.
@ kClassAccess
Access auxiliary data using the aux containers.
A relatively simple transient store for objects created in analysis.
Definition TStore.h:45
double entries
Definition listroot.cxx:49
Definition Muons.py:1
TestStore store
Definition TestStore.cxx:23
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition Init.cxx:31
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
EventInfo_v1 EventInfo
Definition of the latest event info version.
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
float ElectronEta(0)
StatusCode setConfigWP(TString conf)
std::string ElectronIso("")
std::string PhotonIso("")
StatusCode RetrieveContainer(xAOD::TEvent &Ev, const std::string &Key, Container *&C, xAOD::ShallowAuxContainer *&Aux)
std::string MuonIso("")
float ElectronPt(0)
float MuonEta(0)
float MuonPt(0)
float PhotonPt(0)
float PhotonEta(0)
TChain * tree

◆ MuonEta()

float MuonEta ( 0 )

◆ MuonIso()

std::string MuonIso ( "" )

◆ MuonPt()

float MuonPt ( 0 )

◆ PhotonEta()

float PhotonEta ( 0 )

◆ PhotonIso()

std::string PhotonIso ( "" )

◆ PhotonPt()

float PhotonPt ( 0 )

◆ RetrieveContainer()

template<typename Container>
StatusCode RetrieveContainer ( xAOD::TEvent & Ev,
const std::string & Key,
Container *& C,
xAOD::ShallowAuxContainer *& Aux )

Definition at line 71 of file testIsolationCloseByCorrectionTool.cxx.

71 {
72 if (Aux) delete Aux;
73 if (C) delete C;
74 const Container* InCont(0);
75 if (!Ev.retrieve(InCont, Key).isSuccess()) {
76 ANA_MSG_ERROR("RetrieveContainer() Could not retrieve " << Key.c_str());
77 return StatusCode::FAILURE;
78 }
79 typename std::pair<Container*, xAOD::ShallowAuxContainer*> shallowcopy = xAOD::shallowCopyContainer(*InCont);
80 Aux = shallowcopy.second;
81 C = shallowcopy.first;
82 if (!xAOD::setOriginalObjectLink(*InCont, *C)) {
83 ANA_MSG_ERROR("RetrieveContainer() Failed to set Object links to " << Key.c_str());
84 delete Aux;
85 return StatusCode::FAILURE;
86 }
87 return StatusCode::SUCCESS;
88}
storage of the time histories of all the cells
StatusCode retrieve(const T *&obj, const std::string &key)
Retrieve either an input or an output object from the event.
struct color C
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, const EventContext &ctx)
Function making a shallow copy of a constant container.
bool setOriginalObjectLink(const IParticle &original, IParticle &copy)
This function should be used by CP tools when they make a deep copy of an object in their correctedCo...

◆ setConfigWP()

StatusCode setConfigWP ( TString conf)

Definition at line 48 of file testIsolationCloseByCorrectionTool.cxx.

48 {
49 TEnv env;
50 if(env.ReadFile(conf, kEnvAll) != 0){
51 ANA_MSG_INFO("Cannot read config file: " << conf);
52 return StatusCode::FAILURE;
53 }
54 ANA_MSG_INFO("Reading config file: " << conf);
55 MuonIso = env.GetValue("MuonIso", "PflowTight_FixedRad");
56 MuonPt = env.GetValue("MuonPt", 7000.);
57 MuonEta = env.GetValue("MuonEta", 2.5);
58
59 ElectronIso = env.GetValue("ElectronIso", "PLImprovedTight");
60 ElectronPt = env.GetValue("ElectronPt", 7000.);
61 ElectronEta = env.GetValue("ElectronEta", 2.47);
62
63 PhotonIso = env.GetValue("PhotonIso", "FixedCutTight");
64 PhotonPt = env.GetValue("PhotonPt", 7000.);
65 PhotonEta = env.GetValue("PhotonEta", 2.47);
66
67 env.PrintEnv();
68 return StatusCode::SUCCESS;
69}