ATLAS Offline Software
TrigGlobEffCorrExample5a.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 /*
9  * This example shows how to configure the tool for photon triggers.
10  * Here, the minimal configuration is shown (one symmetric diphoton trigger)
11  */
12 
13 // ROOT include(s):
14 #include <TFile.h>
15 #include <TError.h>
16 
17 // Infrastructure include(s):
18 #ifdef XAOD_STANDALONE
19  #include "xAODRootAccess/Init.h"
20  #include "xAODRootAccess/TEvent.h"
21  #include "xAODRootAccess/TStore.h"
22 #else
24  #include "POOLRootAccess/TEvent.h"
25 #endif
26 
28 // EDM include(s):
29 #include "AsgTools/AnaToolHandle.h"
34 #include "PATCore/PATCoreEnums.h"
37 
38 // stdlib include(s):
39 #include <random>
40 #include <vector>
41 #include <array>
42 using std::vector;
43 using std::string;
44 
45 #define MSGSOURCE "Example 5a"
46 
47 ANA_MSG_HEADER(Test)
49 using namespace Test;
50 int main(int argc, char* argv[])
51 {
52  ANA_CHECK_SET_TYPE(bool)
53  const char* filename = nullptr;
54  bool debug = false, cmdline_error = false, toys = false;
55  for(int i=1;i<argc;++i)
56  {
57  if(string(argv[i]) == "--debug") debug = true;
58  else if(string(argv[i]) == "--toys") toys = true;
59  else if(!filename && *argv[i]!='-') filename = argv[i];
60  else cmdline_error = true;
61  }
62  if(!filename || cmdline_error)
63  {
64  Error(MSGSOURCE, "No file name received!");
65  Error(MSGSOURCE, " Usage: %s [--debug] [--toys] [DxAOD file name]", argv[0]);
66  return 1;
67  }
68  #ifdef XAOD_STANDALONE
69  xAOD::Init(MSGSOURCE).ignore();
70  TFile* file = TFile::Open(filename, "READ");
71  if(!file)
72  {
73  Error(MSGSOURCE, "Unable to open file!");
74  return 2;
75  }
78  StatusCode::enableFailure();
79  #else
80  IAppMgrUI* app = POOL::Init();
82  TString file(filename);
83  #endif
84  event.readFrom(file).ignore();
85  Long64_t entries = event.getEntries();
86  Info(MSGSOURCE, "Number of events in the file: %lli", entries);
87 
88  /* ********************************************************************** */
89 
90  Info(MSGSOURCE, "Configuring the photon CP tools");
92  ToolHandleArray<IAsgPhotonEfficiencyCorrectionTool> photonEffTools;
94  ToolHandleArray<IAsgPhotonEfficiencyCorrectionTool> photonSFTools;
95 
97  vector<asg::AnaToolHandle<IAsgPhotonEfficiencyCorrectionTool>> factory;
98 
99  const char* mapPath = "PhotonEfficiencyCorrection/2015_2018/"
100  "rel21.2/Summer2018_Rec_v1/map1.txt";
101  for(int j=0;j<2;++j)
102  {
103  string name = "AsgPhotonEfficiencyCorrectionTool/" + std::string(j? "PhTrigEff" : "PhTrigSF");
104  auto t = factory.emplace(factory.end(), name);
105  t->setProperty("MapFilePath", mapPath).ignore();
106  t->setProperty("TriggerKey", string(j?"":"Eff_") + "DI_PH_2015_2016_g20_tight_2016_g22_tight_2017_2018_g20_tight_icalovloose_L1EM15VHI").ignore();
107  t->setProperty("IsoKey", "Loose").ignore();
108  t->setProperty("ForceDataType", (int)PATCore::ParticleDataType::Full).ignore();
109  if(t->initialize() != StatusCode::SUCCESS)
110  {
111  Error(MSGSOURCE, "Unable to initialize the photon CP tool <%s>!",
112  t->name().c_str());
113  return 3;
114  }
115  auto& handles = (j? photonSFTools : photonEffTools);
116  handles.push_back(t->getHandle());
117  }
118 
119  /* ********************************************************************** */
120 
121  Info(MSGSOURCE, "Configuring the global trigger SF tool");
122  asg::AnaToolHandle<ITrigGlobalEfficiencyCorrectionTool> myTool("TrigGlobalEfficiencyCorrectionTool/TrigGlobal");
123  myTool.setProperty("PhotonEfficiencyTools", photonEffTools).ignore();
124  myTool.setProperty("PhotonScaleFactorTools", photonSFTools).ignore();
125  std::map<std::string, std::string> triggers;
126  triggers["266904-302872"] = "2g20_tight";
127  triggers["302919-311481"] = "2g22_tight";
128  triggers["2017"] = "2g22_tight_L12EM15VHI";
129  triggers["2018"] = "2g22_tight_L12EM15VHI";
130  myTool.setProperty("TriggerCombination", triggers).ignore();
131 
132  if(debug) myTool.setProperty("OutputLevel", MSG::DEBUG).ignore();
133  if(toys) myTool.setProperty("NumberOfToys", 1000).ignore();
134  if(myTool.initialize() != StatusCode::SUCCESS)
135  {
136  Error(MSGSOURCE, "Unable to initialize the TrigGlob tool!");
137  return 3;
138  }
139 
142  const unsigned periodRuns[] = {
144  276262, 278727, 279932, 280423, 281130, 282625,
146  297730, 300345, 301912, 302737, 303638, 303943, 305291, 307124,
147  305359, 309311, 310015,
149  325713, 329385, 330857, 332720, 334842, 336497, 336832, 338183,
151  348885, 349534, 350310, 352274, 354107, 354826, 355261, 355331,
152  355529, 357050, 359191
153  };
154  std::uniform_int_distribution<unsigned> uniformPdf(0,
155  sizeof(periodRuns)/sizeof(*periodRuns) - 1);
156  std::default_random_engine randomEngine;
157 
158  /* ********************************************************************** */
159 
160  Info(MSGSOURCE, "Starting the event loop");
161  unsigned errors = 0;
162  double nSuitableEvents = 0., sumW = 0.;
163  static const SG::Decorator<unsigned> RandomRunNumberDec("RandomRunNumber");
164  static const SG::ConstAccessor<int> truthTypeAcc("truthType");
165  for(Long64_t entry = 0; entry < entries; ++entry)
166  {
167  event.getEntry(entry);
168 
170  const xAOD::EventInfo* eventInfo = nullptr;
171  event.retrieve(eventInfo,"EventInfo").ignore();
172  unsigned runNumber = periodRuns[uniformPdf(randomEngine)];
173  RandomRunNumberDec(*eventInfo) = runNumber;
174 
175  vector<const xAOD::Photon*> myTriggeringPhotons;
176  const xAOD::PhotonContainer* photons = nullptr;
177  event.retrieve(photons,"Photons").ignore();
178  for(auto photon : *photons)
179  {
180  if(!photon->caloCluster()) continue;
181  float eta = fabs(photon->caloCluster()->etaBE(2));
182  float pt = photon->pt();
183  if(pt<10e3f || eta>=2.37 || (eta>1.37 && eta<1.52)) continue;
184  int t = truthTypeAcc(*photon);
185  if(t!=14) continue;
187  if(pt < (runNumber>=302919? 23e3f : 21e3f)) continue;
188  myTriggeringPhotons.push_back(photon);
189  }
190 
192  if(myTriggeringPhotons.size() < 2) continue;
193 
195  double sf = 1.;
196  auto cc = myTool->getEfficiencyScaleFactor(myTriggeringPhotons, sf);
198  {
199  nSuitableEvents += 1;
200  sumW += sf;
201  }
202  else
203  {
204  Warning(MSGSOURCE, "Scale factor evaluation failed");
205  ++errors;
206  }
207  if(errors>10)
208  {
209  Error(MSGSOURCE, "Too many errors reported!");
210  break;
211  }
212  }
213  Info(MSGSOURCE, "Average scale factor: %f (over %ld events)",
214  sumW / nSuitableEvents, long(nSuitableEvents));
215  #ifndef XAOD_STANDALONE
216  ANA_CHECK(app->finalize())
217  #endif
218  return errors? 4 : 0;
219 }
asg::AnaToolHandle::initialize
StatusCode initialize()
initialize the tool
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:71
asg::AnaToolHandle< ITrigGlobalEfficiencyCorrectionTool >
ITrigGlobalEfficiencyCorrectionTool.h
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
test_pyathena.pt
pt
Definition: test_pyathena.py:11
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
SG::ConstAccessor< int >
IAsgPhotonEfficiencyCorrectionTool.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
python.TrigTLAMonitorAlgorithm.triggers
triggers
Definition: TrigTLAMonitorAlgorithm.py:196
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:100
asg::AnaToolHandle::setProperty
StatusCode setProperty(const std::string &property, const T2 &value)
set the given property of the tool.
POOL::Init
IAppMgrUI * Init(const char *options="POOLRootAccess/basic.opts")
Bootstraps (creates and configures) the Gaudi Application with the provided options file.
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:29
POOL::TEvent::kClassAccess
@ kClassAccess
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:46
ANA_MSG_HEADER
#define ANA_MSG_HEADER(NAME)
for standalone code this creates a new message category
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:113
PATCore::ParticleDataType::Full
@ Full
Definition: PATCoreEnums.h:22
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
MessageCheck.h
macros for messaging and checking status codes
PATCoreEnums.h
TEvent.h
file
TFile * file
Definition: tile_monitor.h:29
Init.h
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
MSGSOURCE
#define MSGSOURCE
Definition: TrigGlobEffCorrExample5a.cxx:45
AnaToolHandle.h
mergePhysValFiles.errors
list errors
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:43
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
ANA_MSG_SOURCE
#define ANA_MSG_SOURCE(NAME, TITLE)
the source code part of ANA_MSG_SOURCE
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:133
POOL::TEvent
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:40
TEvent.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
AthAnalysisHelper.h
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
ITrigGlobalEfficiencyCorrectionTool::getEfficiencyScaleFactor
virtual CP::CorrectionCode getEfficiencyScaleFactor(const std::vector< const xAOD::IParticle * > &particles, double &efficiencyScaleFactor)=0
xAOD::TStore
A relatively simple transient store for objects created in analysis.
Definition: TStore.h:44
xAOD::photon
@ photon
Definition: TrackingPrimitives.h:199
main
int main(int argc, char *argv[])
Definition: TrigGlobEffCorrExample5a.cxx:50
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
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
DEBUG
#define DEBUG
Definition: page_access.h:11
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
entries
double entries
Definition: listroot.cxx:49
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
Decorator.h
Helper class to provide type-safe access to aux data.
PhotonContainer.h
TStore.h
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:84
python.handimod.cc
int cc
Definition: handimod.py:523
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31