ATLAS Offline Software
Macros | Functions
TrigGlobEffCorrExample6.cxx File Reference
#include <TFile.h>
#include <TError.h>
#include "AthAnalysisBaseComps/AthAnalysisHelper.h"
#include "POOLRootAccess/TEvent.h"
#include "AsgMessaging/MessageCheck.h"
#include "AsgTools/AnaToolHandle.h"
#include "TriggerAnalysisInterfaces/ITrigGlobalEfficiencyCorrectionTool.h"
#include "TrigConfInterfaces/ITrigConfigTool.h"
#include "TrigDecisionTool/TrigDecisionTool.h"
#include "TriggerMatchingTool/IMatchingTool.h"
#include "xAODEventInfo/EventInfo.h"
#include "xAODEgamma/ElectronContainer.h"
#include "xAODMuon/MuonContainer.h"
#include "PATCore/PATCoreEnums.h"
#include "AthContainers/AuxElement.h"
#include "AthContainers/ConstAccessor.h"
#include "AthContainers/Decorator.h"
#include <random>
#include <vector>
#include <array>

Go to the source code of this file.

Macros

#define MSGSOURCE   "Example 6"
 

Functions

int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ MSGSOURCE

#define MSGSOURCE   "Example 6"

Definition at line 51 of file TrigGlobEffCorrExample6.cxx.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Uniform random run number generation spanning the target dataset. In real life, use the PileupReweightingTool instead!

2015 periods D-H, J

2016 periods A-L

Get a random run number, and decorate the event info

Events must contain at least one lepton above trigger threshold

Definition at line 55 of file TrigGlobEffCorrExample6.cxx.

56 {
57  ANA_CHECK_SET_TYPE(bool)
58  const char* filename = nullptr;
59  bool debug = false, fast = false, cmdline_error = false;
60  for(int i=1;i<argc;++i)
61  {
62  if(string(argv[i]) == "--debug") debug = true;
63  if(string(argv[i]) == "--fast") fast = true;
64  else if(!filename && *argv[i]!='-') filename = argv[i];
65  else cmdline_error = true;
66  }
67  if(!filename || cmdline_error)
68  {
69  Error(MSGSOURCE, "No file name received!");
70  Error(MSGSOURCE, " Usage: %s [--debug] [--fast] [DxAOD file name]", argv[0]);
71  return 1;
72  }
73  #ifdef XAOD_STANDALONE
74  xAOD::Init(MSGSOURCE).ignore();
75  TFile* file = TFile::Open(filename, "READ");
76  if(!file)
77  {
78  Error(MSGSOURCE, "Unable to open file!");
79  return 2;
80  }
83  StatusCode::enableFailure();
84  #else
85  IAppMgrUI* app = POOL::Init();
87  TString file(filename);
88  #endif
89  event.readFrom(file).ignore();
90  Long64_t entries = event.getEntries();
91  Info(MSGSOURCE, "Number of events in the file: %lli", entries);
92  if(fast) entries = std::min(entries, 1000LL);
93 
94  /* ********************************************************************** */
95  asg::AnaToolHandle<TrigConf::ITrigConfigTool> trigConfTool("TrigConf::xAODConfigTool/TrigConfig");
96  if(trigConfTool.initialize() != StatusCode::SUCCESS)
97  {
98  Error(MSGSOURCE, "Unable to initialize the trigger config tool!");
99  return 3;
100  }
101  asg::AnaToolHandle<Trig::TrigDecisionTool> trigDecTool("Trig::TrigDecisionTool/TrigDecision");
102  trigDecTool.setProperty("ConfigTool", trigConfTool.getHandle()).ignore();
103  trigDecTool.setProperty("TrigDecisionKey", "xTrigDecision").ignore();
104  if(trigDecTool.initialize() != StatusCode::SUCCESS)
105  {
106  Error(MSGSOURCE, "Unable to initialize the trigger matching tool!");
107  return 3;
108  }
109  asg::AnaToolHandle<Trig::IMatchingTool> trigMatchTool("Trig::MatchingTool/TrigMatch");
110  trigMatchTool.setProperty("TrigDecisionTool", trigDecTool.getHandle()).ignore();
111  if(trigMatchTool.initialize() != StatusCode::SUCCESS)
112  {
113  Error(MSGSOURCE, "Unable to initialize the trigger matching tool!");
114  return 3;
115  }
116 
117  /* ********************************************************************** */
118 
119  Info(MSGSOURCE, "Configuring the global trigger SF tool");
120  asg::AnaToolHandle<ITrigGlobalEfficiencyCorrectionTool> myTool("TrigGlobalEfficiencyCorrectionTool/TrigGlobal");
121  const char* triggers2015 =
122  "mu20_iloose_L1MU15_OR_mu50"
123  "|| mu18_mu8noL1"
124  "|| e24_lhmedium_L1EM20VH_OR_e60_lhmedium_OR_e120_lhloose"
125  "|| 2e12_lhloose_L12EM10VH";
126  myTool.setProperty("TriggerCombination2015", triggers2015).ignore();
127  const char* triggers2016 =
128  "mu26_ivarmedium_OR_mu50"
129  "|| mu22_mu8noL1"
130  "|| e26_lhtight_nod0_ivarloose_OR_e60_lhmedium_nod0_OR_e140_lhloose_nod0"
131  "|| 2e17_lhvloose_nod0";
132  myTool.setProperty("TriggerCombination2016", triggers2016).ignore();
133  myTool.setProperty("TriggerMatchingTool", trigMatchTool.getHandle()).ignore();
134  if(debug) myTool.setProperty("OutputLevel", MSG::DEBUG).ignore();
135  if(myTool.initialize() != StatusCode::SUCCESS)
136  {
137  Error(MSGSOURCE, "Unable to initialize the TrigGlob tool!");
138  return 3;
139  }
140 
143  const unsigned periodRuns[] = {
144  276073, 278727, 279932, 280423, 281130, 282625,
145  296939, 300345, 301912, 302737, 303638, 303943, 305291, 307124,
146  305359, 309311, 310015
147  };
148  std::uniform_int_distribution<unsigned> uniformPdf(0,
149  sizeof(periodRuns)/sizeof(*periodRuns) - 1);
150  std::default_random_engine randomEngine;
151 
152  static const SG::ConstAccessor<int> truthType("truthType");
153  static const SG::ConstAccessor<int> truthOrigin("truthOrigin");
154 
155  /* ********************************************************************** */
156 
157  Info(MSGSOURCE, "Starting the event loop");
158  unsigned errors = 0;
159  double nSuitableEvents = 0., nMatched = 0.;
160  static const SG::Decorator<unsigned> RandomRunNumberDec("RandomRunNumber");
161  for(Long64_t entry = 0; entry < entries; ++entry)
162  {
163  event.getEntry(entry);
164 
166  const xAOD::EventInfo* eventInfo = nullptr;
167  event.retrieve(eventInfo,"EventInfo").ignore();
168  unsigned runNumber = periodRuns[uniformPdf(randomEngine)];
169  RandomRunNumberDec(*eventInfo) = runNumber;
170  vector<const xAOD::Electron*> myTriggeringElectrons;
171  const xAOD::ElectronContainer* electrons = nullptr;
172  event.retrieve(electrons,"Electrons").ignore();
173  for(auto electron : *electrons)
174  {
175  if(!electron->caloCluster()) continue;
176  float eta = fabs(electron->caloCluster()->etaBE(2));
177  float pt = electron->pt();
178  if(pt<10e3f || eta>=2.47) continue;
179  if(!truthType.isAvailable(*electron)) continue;
180  if(!truthOrigin.isAvailable(*electron)) continue;
181  int t = truthType(*electron), o = truthOrigin(*electron);
182  if(t!=2 || !(o==10 || (o>=12 && o<=22) || o==43)) continue;
183  myTriggeringElectrons.push_back(electron);
184  }
185 
186  vector<const xAOD::Muon*> myTriggeringMuons;
187  const xAOD::MuonContainer* muons = nullptr;
188  event.retrieve(muons,"Muons").ignore();
189  for(auto muon : *muons)
190  {
191  float pt = muon->pt();
192  if(pt<10e3f || fabs(muon->eta())>=2.5) continue;
193  auto mt = muon->muonType();
194  if(mt!=xAOD::Muon::Combined && mt!=xAOD::Muon::MuonStandAlone) continue;
195  auto& mtp = *(muon->primaryTrackParticle());
196  if(!truthType.isAvailable(mtp)) continue;
197  if(!truthOrigin.isAvailable(mtp)) continue;
198  int t = truthType(mtp), o = truthOrigin(mtp);
199  if(t!=6 || !(o==10 || (o>=12 && o<=22) || o==43)) continue;
200  myTriggeringMuons.push_back(muon);
201  }
203  if(myTriggeringElectrons.size()+myTriggeringMuons.size() < 1) continue;
204  nSuitableEvents += 1;
205 
206  bool matched = false;
207  if(myTool->checkTriggerMatching(matched, myTriggeringElectrons, myTriggeringMuons) != CP::CorrectionCode::Ok)
208  {
209  Error(MSGSOURCE, "trigger matching could not be checked, interrupting execution");
210  ++errors;
211  break;
212  }
213 
214  if(matched) nMatched += 1;
215  }
216 
217  if(errors < nSuitableEvents)
218  {
219  Info(MSGSOURCE, "Fraction of trigger-matched events: %f (over %ld events)",
220  nMatched / nSuitableEvents, long(nSuitableEvents));
221  }
222 
223  #ifndef XAOD_STANDALONE
224  ANA_CHECK(app->finalize())
225  #endif
226  return errors? 4 : 0;
227 }
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
asg::AnaToolHandle< TrigConf::ITrigConfigTool >
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
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 >
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:97
ZDCMsg::Info
@ Info
Definition: ZDCMsg.h:20
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:45
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:58
lumiFormat.i
int i
Definition: lumiFormat.py:92
file
TFile * file
Definition: tile_monitor.h:29
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
Trk::Combined
@ Combined
Definition: TrackSummaryTool.h:32
min
#define min(a, b)
Definition: cfImp.cxx:40
mergePhysValFiles.errors
list errors
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:43
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
POOL::TEvent
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:39
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
python.ElectronD3PDObject.matched
matched
Definition: ElectronD3PDObject.py:138
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
fast
bool fast
Definition: TrigGlobEffCorrValidation.cxx:190
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
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
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
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
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
MSGSOURCE
#define MSGSOURCE
Definition: TrigGlobEffCorrExample6.cxx:50
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:81
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31