ATLAS Offline Software
JetTileCorrectionTester.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 
11 
12 // System includes
13 #include <memory>
14 #include <cstdlib>
15 
16 // ROOT includes
17 #include "TFile.h"
18 #include "TError.h"
19 #include "TString.h"
20 
21 // Infrastructure includes
22 #ifdef ROOTCORE
23 # include "xAODRootAccess/Init.h"
24 # include "xAODRootAccess/TEvent.h"
25 #endif // ROOTCORE
26 
27 // EDM includes
29 #include "xAODJet/JetContainer.h"
30 #include "xAODCore/ShallowCopy.h"
31 
33 #include "AsgTools/AsgTool.h"
35 
36 
37 // Local includes
39 
40 using namespace JTC;
41 
42 //-----------------------------------------------------------------------------
43 // Error checking macro
44 //-----------------------------------------------------------------------------
45 #define CHECK( ARG ) \
46  do { \
47  const bool result = ARG; \
48  if(!result) { \
49  ::Error(APP_NAME, "Failed to execute: \"%s\"", \
50  #ARG ); \
51  return 1; \
52  } \
53  } while( false )
54 
55 
56 //-----------------------------------------------------------------------------
57 // Global accessors and decorators
58 //-----------------------------------------------------------------------------
59 static SG::AuxElement::Accessor<unsigned int> acc_tileok("TileStatus");
60 static SG::AuxElement::Accessor<float> acc_ptraw("Ptraw");
61 
62 //-----------------------------------------------------------------------------
63 // Main function
64 //-----------------------------------------------------------------------------
65 int main( int argc, char* argv[] )
66 {
67 
68  // The application's name
69  const char* APP_NAME = argv[ 0 ];
70 
71  // Check if we received a file name
72  if(argc < 2) {
73  Error( APP_NAME, "No file name received!" );
74  Error( APP_NAME, " Usage: %s [xAOD file name] [num events]", APP_NAME );
75  return 1;
76  }
77 
78  // Initialise the application
80  StatusCode::enableFailure();
81 
82  // Open the input file
83  const TString fileName = argv[ 1 ];
84  Info(APP_NAME, "Opening file: %s", fileName.Data());
85  std::unique_ptr<TFile> ifile(TFile::Open(fileName, "READ"));
86  CHECK( ifile.get() );
87 
88  // Create a TEvent object
91  CHECK( event.readFrom(ifile.get()) );
92  Info(APP_NAME, "Number of events in the file: %i",
93  static_cast<int>(event.getEntries()));
94 
95  // Decide how many events to run over
96  Long64_t entries = event.getEntries();
97  if(argc > 2) {
98  const Long64_t e = atoll(argv[2]);
100  }
101 
102  // Initialize the tool
104  tool_jtc.setTypeAndName("CP::JetTileCorrectionTool/JetTileCorrectionTool");
105 
106  //Set properties if needed
107  CHECK( tool_jtc.setProperty("CorrectionFileName", "JetTileCorrection/JetTile_pFile_010216.root") ); //default anyway
108  // std::vector<std::string> dead_modules = {"1 04","1 05","1 06","1 07","1 08","1 09",
109  // "2 04","2 05","2 06","2 07","2 08","2 09" }; // LBA/C5-10 : NOT REAL SCENARIO !! just trying to get some magnified effect for testing!
110  // CHECK( tool_jtc.setProperty("UserMaskedRegions", dead_modules));
111 
112  CHECK( tool_jtc.retrieve() );
113 
114  // Loop over the events
115  std::cout << "Starting loop" << std::endl;
116  for(Long64_t entry = 0; entry < entries; ++entry){
117 
118  event.getEntry(entry);
119 
120  // Print some event information for fun
121  const xAOD::EventInfo* evtInfo = 0;
122  CHECK( event.retrieve(evtInfo, "EventInfo") );
123  if ( entry%100==0 ){
124  Info(APP_NAME, "===>>> Processing entry %lli, run %u, event %lu <<<===",
125  entry, evtInfo->runNumber(), evtInfo->eventNumber());
126  }
127 
128  // Get jets
129  const xAOD::JetContainer* jets = 0;
130  CHECK( event.retrieve(jets, "AntiKt4EMTopoJets") );
131 
132  std::pair<xAOD::JetContainer*, xAOD::ShallowAuxContainer*> shallowcopy =
134  std::unique_ptr< xAOD::JetContainer > jets_sc( shallowcopy.first );
135  std::unique_ptr< xAOD::ShallowAuxContainer >
136  jets_scaux( shallowcopy.second );
137 
138  for( xAOD::Jet* jet : *jets_sc ){
139 
140  if (jet->pt() < 20000. || fabs(jet->eta()) > 2.8) continue;
141 
142  //--- apply tile dead module correction
143  const CP::CorrectionCode retCode = tool_jtc->applyCorrection(*jet);
144 
145  if ( retCode == CP::CorrectionCode::OutOfValidityRange ){
146  Warning("JetTileCorrectionTester","No valid pt/eta range. No correction applied."); // It might get too verbosed, just here to illustrate all return values.
147  }
148  else if( retCode != CP::CorrectionCode::Ok ){
149  Error("JetTileCorrectionTester","Failed to apply JetTileCorrection!");
150  //return StatusCode::FAILURE;
151  }
152 
153  unsigned int j_status = acc_tileok(*jet);
154 
155  std::string str_status="";
156  if(j_status == (unsigned int)JTC::TS::GOOD)
157  str_status = "NotAffected";
158  else if(j_status == (unsigned int)JTC::TS::EDGE)
159  str_status = "EdgeAffected";
160  else if(j_status == (unsigned int)JTC::TS::CORE)
161  str_status = "CoreAffected";
162  else
163  str_status = "Unknown";
164 
165  Info(APP_NAME, "Jet status : %s, Pt raw = %.3f GeV, Pt corrected %.3f GeV", str_status.c_str(), acc_ptraw(*jet)*0.001, jet->pt()*0.001);
166  }
167 
168 
169 
170  // //Check status only
171  // tool_jtc->setRJET(0.1); //change jet radius (for tile status checks only!)
172  // for( xAOD::Jet* jet : *jets_sc ){
173 
174  // JTC::TS j_status = tool_jtc->getTileStatus(*jet);
175 
176  // //or well:
177  // //CHECK( tool_jtc->addTileStatus(*jet) );
178  // //unsigned int j_status = acc_tileok(*jet);
179 
180  // std::string str_status="";
181  // if(j_status == JTC::TS::GOOD)
182  // str_status = "NotAffected";
183  // else if(j_status == JTC::TS::EDGE)
184  // str_status = "EdgeAffected";
185  // else if(j_status == JTC::TS::CORE)
186  // str_status = "CoreAffected";
187  // else
188  // str_status = "Unknown";
189 
190  // Info(APP_NAME, "Jet status : %s, Pt raw = %.3f GeV, Pt corrected %.3f GeV", str_status.c_str(), acc_ptraw(*jet)*0.001, jet->pt()*0.001);
191 
192  // }
193  // //back to default
194  // tool_jtc->setRJET(0.4);
195 
196  }
197 
198  Info(APP_NAME, "Application finished successfully");
199 
200  return 0;
201 }
ShallowCopy.h
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:71
JetTileCorrectionTool.h
xAOD::EventInfo_v1::eventNumber
uint64_t eventNumber() const
The current event's event number.
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
CP::IJetTileCorrectionTool::applyCorrection
virtual CorrectionCode applyCorrection(xAOD::Jet &jet)=0
Declare the interface that the class provides.
xAOD::TEvent::kAthenaAccess
@ kAthenaAccess
Access containers/objects like Athena does.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:101
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
CP::CorrectionCode::OutOfValidityRange
@ OutOfValidityRange
Input object is out of validity range.
Definition: CorrectionCode.h:37
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:133
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
asg::StandaloneToolHandle::setProperty
StatusCode setProperty(const std::string &name, T2 &&value)
Definition: StandaloneToolHandle.h:105
POOL::TEvent::getEntries
long getEntries()
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:124
asg::StandaloneToolHandle
an "initializing" ToolHandle for stand-alone applications
Definition: StandaloneToolHandle.h:44
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
TEvent.h
Init.h
JTC::TS::EDGE
@ EDGE
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
asg::StandaloneToolHandle::retrieve
StatusCode retrieve()
initialize the tool, will succeed if the tool was already initialized
Definition: StandaloneToolHandle.h:147
min
#define min(a, b)
Definition: cfImp.cxx:40
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
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
CHECK
#define CHECK(ARG)
Definition: JetTileCorrectionTester.cxx:45
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
JTC
Definition: IJetTileCorrectionTool.h:23
asg::StandaloneToolHandle::setTypeAndName
void setTypeAndName(const std::string &typeAndName)
Definition: StandaloneToolHandle.h:101
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
xAOD::TStore
A relatively simple transient store for objects created in analysis.
Definition: TStore.h:44
JetContainer.h
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:74
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
entries
double entries
Definition: listroot.cxx:49
JTC::TS::GOOD
@ GOOD
CorrectionCode.h
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
LArCellNtuple.ifile
string ifile
Definition: LArCellNtuple.py:133
StandaloneToolHandle.h
AsgTool.h
main
int main(int argc, char *argv[])
Definition: JetTileCorrectionTester.cxx:65
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:84
JTC::TS::CORE
@ CORE
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31