ATLAS Offline Software
Functions
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 ( )

◆ ElectronIso()

std::string ElectronIso ( ""  )

◆ ElectronPt()

float ElectronPt ( )

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 90 of file testIsolationCloseByCorrectionTool.cxx.

90  {
91  ANA_CHECK_SET_TYPE (int);
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 ];
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 }

◆ MuonEta()

float MuonEta ( )

◆ MuonIso()

std::string MuonIso ( ""  )

◆ MuonPt()

float MuonPt ( )

◆ PhotonEta()

float PhotonEta ( )

◆ PhotonIso()

std::string PhotonIso ( ""  )

◆ PhotonPt()

float PhotonPt ( )

◆ 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 }

◆ 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 }
MuonIso
std::string MuonIso("")
TestSUSYToolsAlg.ifile
ifile
Definition: TestSUSYToolsAlg.py:92
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
asg::AnaToolHandle< CP::IIsolationSelectionTool >
taskman.configFile
configFile
Definition: taskman.py:311
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
AthenaPoolExample_ReadWrite.Key
Key
Definition: AthenaPoolExample_ReadWrite.py:53
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
tree
TChain * tree
Definition: tile_monitor.h:30
DMTest::C
C_v1 C
Definition: C.h:26
validation.ofile
ofile
Definition: validation.py:96
xAOD::ShallowAuxContainer
Class creating a shallow copy of an existing auxiliary container.
Definition: ShallowAuxContainer.h:54
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
MuonPt
float MuonPt(0)
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
PhotonPt
float PhotonPt(0)
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:97
MuonEta
float MuonEta(0)
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
setConfigWP
StatusCode setConfigWP(TString conf)
Definition: testIsolationCloseByCorrectionTool.cxx:48
CP::CorrectionCode::Error
@ Error
Some error happened during the object correction.
Definition: CorrectionCode.h:36
python.ConfigurableDb.conf
def conf
Definition: ConfigurableDb.py:282
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:132
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
ElectronPt
float ElectronPt(0)
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:58
POOL::TEvent::getEntries
long getEntries()
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:123
PhotonIso
std::string PhotonIso("")
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
CP::IsoCorrectionTestHelper
Definition: TestMacroHelpers.h:18
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
gErrorIgnoreLevel
int gErrorIgnoreLevel
PhotonEta
float PhotonEta(0)
xAOD::shallowCopyContainer
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, [[maybe_unused]] const EventContext &ctx)
Function making a shallow copy of a constant container.
Definition: ShallowCopy.h:110
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
xAOD::TStore
A relatively simple transient store for objects created in analysis.
Definition: TStore.h:44
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
ANA_CHECK_SET_TYPE
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:314
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:73
xAOD::setOriginalObjectLink
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...
Definition: IParticleHelpers.cxx:30
xAOD::TEvent::retrieve
StatusCode retrieve(const T *&obj, const std::string &key)
Retrieve either an input or an output object from the event.
DEBUG
#define DEBUG
Definition: page_access.h:11
entries
double entries
Definition: listroot.cxx:49
ElectronIso
std::string ElectronIso("")
python.DataFormatRates.env
env
Definition: DataFormatRates.py:32
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:81
RetrieveContainer
StatusCode RetrieveContainer(xAOD::TEvent &Ev, const std::string &Key, Container *&C, xAOD::ShallowAuxContainer *&Aux)
Definition: testIsolationCloseByCorrectionTool.cxx:71
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31
ElectronEta
float ElectronEta(0)