50 {
51
53
54
55 using namespace msgMMC;
57
58 bool useCorrectedCopy = true;
59
60
61
62
63 if (argc < 2) {
64 Error(
APP_NAME,
"==============================================");
69 Error(
APP_NAME,
" $> %s [xAOD file name] -event X | X = specific number of the event to run on - for debugging",
APP_NAME);
70 Error(
APP_NAME,
"==============================================");
71 return 1;
72 }
73
75
79
80 int Ievent = -1;
81
82 if (
options.find(
"-event") != std::string::npos) {
83 for (
int ipos = 0; ipos <
argc; ipos++) {
84 if (std::string(argv[ipos]).
compare(
"-event") == 0) {
85 Ievent =
atoi(argv[ipos + 1]);
86 Info(
APP_NAME,
"Argument (-event) : Running only on event # %i", Ievent);
87 break;
88 }
89 }
90 }
91
93 if (
options.find(
"-n") != std::string::npos) {
94 for (
int ipos = 0; ipos <
argc; ipos++) {
95 if (std::string(argv[ipos]).
compare(
"-n") == 0) {
98 break;
99 }
100 }
101 }
102
103 TString limitSys = "";
104 if (
options.find(
"-s") != std::string::npos) {
105 for (
int ipos = 0; ipos <
argc; ipos++) {
106 if (std::string(argv[ipos]).
compare(
"-s") == 0) {
107 limitSys = TString(argv[ipos + 1]);
108 break;
109 }
110 }
111 }
112
113 bool doSys = false;
114 if (
options.find(
"-doSys") != std::string::npos) {
115 doSys = true;
116 }
118
121
122
125 std::unique_ptr<TFile>
ifile(TFile::Open(
fileName.c_str(),
"READ"));
127
128 std::unique_ptr<TChain>
chain = std::make_unique<TChain>(
"CollectionTree",
"CollectionTree");
130
131
133 Info(
APP_NAME,
"Number of events in the file: %i",
static_cast<int>(
event.getEntries()));
134
135
137
138
139 Long64_t
entries =
event.getEntries();
141
142
144
146
147
148
150
151
152 bool isRun3Geo = false;
153 if(
fileName.find(
"mc21") != std::string::npos) isRun3Geo =
true;
154 if(
fileName.find(
"data22") != std::string::npos) isRun3Geo =
true;
155
158 corrTool.
setProperty(
"IsRun3Geo", isRun3Geo).ignore();
159
160
161
163
164
165
166 bool isDebug = false;
167 if (
nEvents >= 0 || Ievent >= 0) isDebug =
true;
168
169 if (isDebug) corrTool.
setProperty(
"OutputLevel", MSG::VERBOSE).ignore();
170
172 if (
sc.isFailure()) {
174 return 1;
175 }
176
177
179 if (
sc.isFailure()) {
181 return 1;
182 }
183
184
186
187
188
190
192 selTool.
setTypeAndName(
"CP::MuonSelectionTool/MuonSelectionTool");
193
194
195 selTool.
setProperty(
"IsRun3Geo", isRun3Geo).ignore();
197 selTool.
setProperty(
"MuQuality", (
int)xAOD::Muon::Quality::Loose).ignore();
198
199
200 if (selTool.
retrieve().isFailure() ||
sc.isFailure()) {
202 return 1;
203 }
204
206
208 std::vector<CP::SystematicSet> sysList;
210
211 if(doSys)
212 {
216 if(!TString(sysItr->name()).Contains(limitSys) && limitSys.Length() > 0) continue;
218 sysList.back().insert(*sysItr);
219 }
220 }
221
222 std::vector<CP::SystematicSet>::const_iterator sysListItr;
223
224 msgMMC::ANA_MSG_INFO("main() - Systematics are ");
225 for (sysListItr = sysList.begin(); sysListItr != sysList.end(); ++sysListItr) msgMMC::ANA_MSG_INFO(sysListItr->name());
226
227
228 Float_t InitPtCB(0.), InitPtID(0.), InitPtMS(0.);
229 Float_t CorrPtCB(0.), CorrPtID(0.), CorrPtMS(0.);
231 Float_t ExpResoCB(0.), ExpResoID(0.), ExpResoMS(0.);
232 long long unsigned int eventNum(0);
233
234
235 TFile*
outputFile = TFile::Open(
"output.root",
"recreate");
236
237
238 std::unordered_map<CP::SystematicSet, TTree*> sysTreeMap;
239 for (sysListItr = sysList.begin(); sysListItr != sysList.end(); ++sysListItr) {
240
241 std::string
treeName =
"test_tree_" + (sysListItr->name().
size() == 0 ?
"NOMINAL" : sysListItr->name());
242 TTree* sysTree =
new TTree(
treeName.c_str(),
"test tree for MCAST");
243
244
245 sysTree->Branch("InitPtCB", &InitPtCB, "InitPtCB/F");
246 sysTree->Branch("InitPtID", &InitPtID, "InitPtID/F");
247 sysTree->Branch("InitPtMS", &InitPtMS, "InitPtMS/F");
248 sysTree->Branch("CorrPtCB", &CorrPtCB, "CorrPtCB/F");
249 sysTree->Branch("CorrPtID", &CorrPtID, "CorrPtID/F");
250 sysTree->Branch("CorrPtMS", &CorrPtMS, "CorrPtMS/F");
251 sysTree->Branch(
"Eta", &
Eta,
"Eta/F");
252 sysTree->Branch(
"Phi", &
Phi,
"Phi/F");
253 sysTree->Branch("Charge", &Charge, "Charge/F");
254 sysTree->Branch("ExpResoCB", &ExpResoCB, "ExpResoCB/F");
255 sysTree->Branch("ExpResoID", &ExpResoID, "ExpResoID/F");
256 sysTree->Branch("ExpResoMS", &ExpResoMS, "ExpResoMS/F");
257 sysTree->Branch("eventNum", &eventNum);
258
259 sysTreeMap[*sysListItr] = sysTree;
260 }
261
263
267
268 event.getEntry(entry);
269
270
273 if (Ievent != -1 &&
static_cast<int>(evtInfo->
eventNumber()) != Ievent) {
continue; }
274
276
277
280
281
282 for (sysListItr = sysList.begin(); sysListItr != sysList.end(); ++sysListItr) {
283
285
287
288 if (isDebug) {
289 Info(
APP_NAME,
"-----------------------------------------------------------");
290 Info(
APP_NAME,
"Looking at %s systematic", (sysListItr->name()).c_str());
291 }
292
293 if (corrTool->applySystematicVariation(*sysListItr) != StatusCode::SUCCESS) {
294 Error(
APP_NAME,
"Cannot configure muon calibration tool for systematic");
295 }
296
297
298 for (auto muon : *muonsCorr) {
299
300 if (!selTool->accept(*muon)) {
301 if (isDebug)
Info(
APP_NAME,
"This muon doesn't pass the ID hits quality cuts");
302 continue;
303 }
304
305
306 InitPtCB =
muon->pt();
307 InitPtID = -999;
308 if (
const auto* id_track =
muon->trackParticle(xAOD::Muon::TrackParticleType::InnerDetectorTrackParticle); id_track !=
nullptr) {
309 InitPtID = id_track->pt();
310 }
311 InitPtMS = -999;
312 if (
const auto* ms_track =
muon->trackParticle(xAOD::Muon::TrackParticleType::ExtrapolatedMuonSpectrometerTrackParticle); ms_track !=
nullptr) {
313 InitPtMS = ms_track->pt();
314 }
315
319
320
321 if (isDebug)
Info(
APP_NAME,
"Selected muon: eta = %g, phi = %g, pt = %g",
muon->eta(),
muon->phi(),
muon->pt() / 1e3);
322
323 float ptCB = 0;
324 if (
const auto* cb_track =
muon->trackParticle(xAOD::Muon::TrackParticleType::CombinedTrackParticle); cb_track !=
nullptr) {
325 ptCB = cb_track->pt();
326 } else {
327 if (isDebug){
328 std::stringstream sstr{};
329 sstr<<
"Missing primary track particle link for --> CB "<<ptCB<<
", author: "<<
muon->author()
330 <<
"type: "<<
muon->muonType();
332 }
333 }
334 float ptID = 0;
335 if (
const auto* id_track =
muon->trackParticle(xAOD::Muon::TrackParticleType::InnerDetectorTrackParticle); id_track !=
nullptr) {
336 ptID = id_track->pt();
337 }
338 float ptME = 0;
339 if (
const auto* ms_track =
muon->trackParticle(xAOD::Muon::TrackParticleType::ExtrapolatedMuonSpectrometerTrackParticle); ms_track !=
nullptr) {
340 ptME = ms_track->pt();
341 }
342
343 if (isDebug){
344 std::stringstream sstr{};
345 sstr<<
"--> CB "<<(ptCB / 1
e3)<<
", ID "<<(ptID / 1e3)
346 <<
", ME "<<(ptME / 1
e3)<<
", author: "<<
muon->author()<<
", type:"<<
muon->muonType();
348 }
349
352 if (useCorrectedCopy) {
353
355 if (!corrTool->correctedCopy(*muon, mu)) {
356 Error(
APP_NAME,
"Cannot really apply calibration nor smearing");
357 continue;
358 }
360 CorrPtID = InnerDetectorPtAcc (*mu);
361 CorrPtMS = MuonSpectrometerPtAcc (*mu);
362
363
364 sysTreeMap[*sysListItr]->Fill();
365
367 }
368 else {
369 if (!corrTool->applyCorrection(*muon)) {
370 Error(
APP_NAME,
"Cannot really apply calibration nor smearing");
371 continue;
372 }
373 CorrPtCB =
muon->pt();
374 CorrPtID = InnerDetectorPtAcc (*muon);
375 CorrPtMS = MuonSpectrometerPtAcc (*muon);
376 ExpResoCB = corrTool->expectedResolution("CB", *muon, true);
377 ExpResoID = corrTool->expectedResolution("ID", *muon, true);
378 ExpResoMS = corrTool->expectedResolution("MS", *muon, true);
379 if (isDebug)
380 Info(
APP_NAME,
"Calibrated muon: eta = %g, phi = %g, pt(CB) = %g, pt(ID) = %g, pt(MS) = %g",
muon->eta(),
381 muon->phi(),
muon->pt() / 1e3, CorrPtID / 1e3, CorrPtMS / 1e3);
382 if (isDebug)
383 Info(
APP_NAME,
" expReso : ExpResoCB = %g , ExpResoID = %g , ExpResoMS = %g", ExpResoCB, ExpResoID, ExpResoMS);
384 sysTreeMap[*sysListItr]->Fill();
385 }
386 }
387 if (isDebug)
Info(
APP_NAME,
"-----------------------------------------------------------");
388
389 }
390
391 if (entry % 5 == 0)
393 "===>>> done processing event #%i, run #%i %i events processed so far <<<===",
static_cast<int>(evtInfo->
eventNumber()),
394 static_cast<int>(evtInfo->
runNumber()),
static_cast<int>(entry + 1));
395 }
396
397 for (sysListItr = sysList.begin(); sysListItr != sysList.end(); ++sysListItr) { sysTreeMap[*sysListItr]->Write(); }
398
399
401
403
404
405 return 0;
406}
size_t size() const
Number of registered mappings.
This module implements the central registry for handling systematic uncertainties with CP tools.
const SystematicSet & recommendedSystematics() const
returns: the recommended set of systematics
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
Class to wrap a set of SystematicVariations.
const_iterator end() const
description: const iterator to the end of the set
std::set< SystematicVariation >::const_iterator const_iterator
const_iterator begin() const
description: const iterator to the beginning of the set
Helper class to provide constant type-safe access to aux data.
uint32_t runNumber() const
The current event's run number.
uint64_t eventNumber() const
The current event's event number.
ReadStats & stats()
Access the object belonging to the current thread.
static IOStats & instance()
Singleton object accessor.
void printSmartSlimmingBranchList(bool autoIncludeLinks=false) const
Print the accessed variables, formatted for smart slimming.
Tool for accessing xAOD files outside of Athena.
@ kAthenaAccess
Access containers/objects like Athena does.
A relatively simple transient store for objects created in analysis.
std::pair< int, int > compare(const AmgSymMatrix(N) &m1, const AmgSymMatrix(N) &m2, double precision=1e-9, bool relative=false)
compare two matrices, returns the indices of the first element that fails the condition,...
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
::StatusCode StatusCode
StatusCode definition for legacy code.
Error
The different types of error that can be flagged in the L1TopoRDO.
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
typename ShallowCopyResult< T >::type ShallowCopyResult_t
Return type of xAOD::shallowCopy.
EventInfo_v1 EventInfo
Definition of the latest event info version.
ShallowCopyResult_t< T > shallowCopy(const T &cont, const EventContext &ctx)
Create a shallow copy of an existing container.
Muon_v1 Muon
Reference the current persistent version:
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".