ATLAS Offline Software
EventSaverxAODNext.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 
7 #include "TopEvent/Event.h"
8 #include "TopEvent/EventTools.h"
10 
12 
15 
16 #include "xAODRootAccess/TEvent.h"
17 
20 #include "xAODMuon/MuonContainer.h"
22 #include "xAODJet/JetContainer.h"
25 
26 #include "TFile.h"
27 
28 namespace top {
30  asg::AsgMetadataTool("top::EventSaverxAODNext"),
31  m_config(nullptr),
32  m_outputFile(nullptr),
33  m_saveAllObjects(false) {
34  }
35 
37  }
38 
39  void EventSaverxAODNext::initialize(std::shared_ptr<top::TopConfig> config, TFile* file,
40  const std::vector<std::string>& extraBranches) {
41  m_config = config;
43  top::check(evtStore()->event()->writeTo(m_outputFile), "EventSaverxAODNext trying to call writeTo on output file");
44 
45  // Persist the top::TopConfig settings - we'll need this to make sense of the output when reading it back
46  top::check(outputMetaStore()->record(
47  m_config->createPersistentSettings(), "TopPersistentSettings"),
48  "Failed to save TopPersistentSettings");
49  auto* const settings = top::ConfigurationSettings::get();
50 
51  //EventInfo
52  std::string eventInfoList = settings->value("EventVariableSaveList");
53  if (config->isMC()) eventInfoList += ".mcChannelNumber.mcEventWeights";
54 
55  //Add extra branches - e.g. if it passed the ee / mumu / emu selection per event
56  for (const auto& branchName : extraBranches)
57  eventInfoList += "." + branchName;
58 
59  evtStore()->event()->setAuxItemList("EventInfoAux.", eventInfoList);
60 
61  // Photons
62  if (m_config->usePhotons()) {
63  std::string photonVariableSaveList = settings->value("PhotonVariableSaveList");
64  if (config->isMC()) {
65  photonVariableSaveList += ".truthType.truthOrigin";
66  }
67 
68  for (const auto& currentSystematic : *m_config->systSgKeyMapPhotons()) {
69  std::string sgKey = currentSystematic.second;
70  evtStore()->event()->setAuxItemList(sgKey + "Aux.", photonVariableSaveList);
71  }
72  } // Photons
73 
74  // Electrons
75  if (m_config->useElectrons()) {
76  std::string electronVariableSaveList = settings->value("ElectronVariableSaveList");
77  if (config->isMC()) {
78  electronVariableSaveList += ".truthType.truthOrigin";
79  }
80 
81  for (const auto& currentSystematic : *m_config->systSgKeyMapElectrons()) {
82  std::string sgKey = currentSystematic.second;
83  evtStore()->event()->setAuxItemList(sgKey + "Aux.", electronVariableSaveList);
84  }
85  } // Electrons
86 
87  // Muons
88  if (m_config->useMuons()) {
89  std::string muonVariableSaveList = settings->value("MuonVariableSaveList");
90 
91  // When these variables exist
92  // if (config->isMC()) {
93  // muonVariableSaveList += ".truthType.truthOrigin";
94  // }
95 
96  for (const auto& currentSystematic : *m_config->systSgKeyMapMuons()) {
97  std::string sgKey = currentSystematic.second;
98  evtStore()->event()->setAuxItemList(sgKey + "Aux.", muonVariableSaveList);
99  }
100  } // Muons
101 
102  // Taus
103  if (m_config->useTaus()) {
104  std::string tauVariableSaveList = settings->value("TauVariableSaveList");
105 
106  for (const auto& currentSystematic : *m_config->systSgKeyMapTaus()) {
107  std::string sgKey = currentSystematic.second;
108  evtStore()->event()->setAuxItemList(sgKey + "Aux.", tauVariableSaveList);
109  }
110  } // Taus
111 
112 
113  // Jets
114  if (m_config->useJets()) {
115  std::string jetVariableSaveList = settings->value("JetVariableSaveList");
116 
117  for (const auto& currentSystematic : *m_config->systSgKeyMapJets(false)) {
118  std::string sgKey = currentSystematic.second;
119  evtStore()->event()->setAuxItemList(sgKey + "Aux.", jetVariableSaveList);
120  }
121  }
122 
123  if (m_config->useLargeRJets()) {
124  std::string jetVariableSaveList = settings->value("JetVariableSaveList");
125 
126  for (const auto& currentSystematic : *m_config->systSgKeyMapLargeRJets()) {
127  std::string sgKey = currentSystematic.second;
128  evtStore()->event()->setAuxItemList(sgKey + "Aux.", jetVariableSaveList);
129  }
130  }
131 
132  if (m_config->useTrackJets()) {
133  std::string jetVariableSaveList = settings->value("JetVariableSaveList");
134 
135  for (const auto& currentSystematic : *m_config->systSgKeyMapTrackJets()) {
136  std::string sgKey = currentSystematic.second;
137  evtStore()->event()->setAuxItemList(sgKey + "Aux.", jetVariableSaveList);
138  }
139  }
140 
141  if (m_config->useJets() || m_config->useLargeRJets() || m_config->useTrackJets()) {
142  // B-tagging
143  std::string bTagVariableSaveList = settings->value("BTagVariableSaveList");
144  evtStore()->event()->setAuxItemList("BTagging_AntiKt4EMTopoAux.", bTagVariableSaveList);
145  } // B-tagging
146  }
147 
149  // Systematic Event
150  const xAOD::SystematicEventContainer* allSystematics(nullptr);
151 
152  top::check(evtStore()->retrieve(allSystematics,
153  m_config->sgKeyTopSystematicEvents()),
154  "Failed to retrieve xAOD::SystematicEventContainer");
155 
156  // Save all reco event objects?
157  // If no systematic in the event passes the event selection
158  // We don't fill the collections - this saves a lot of disk space
159  bool saveEvent(false), saveEventObjects(false);
160  if (!m_config->saveOnlySelectedEvents()) {
161  saveEvent = true;
162  }
163  if (m_config->saveOnlySelectedEvents()) {
164  for (const auto *x : *allSystematics) {
165  if (x->auxdataConst<char>(m_config->passEventSelectionDecoration()) == 1) {
166  saveEvent = true;
167  saveEventObjects = true;
168  break;
169  }
170  }
171  } // Save reco event?
172 
173  if (saveEvent) {
174  //Event Info
175  top::check(evtStore()->event()->copy("EventInfo"), "copying event info failed");
176 
177  // BTagging - can consider thinning this at some point.
178  // Tricky computation as all jet collections need updated ElementLinks
179  top::check(evtStore()->event()->copy("BTagging_AntiKt4EMTopo"), "copying btagging failed");
180 
181  top::check(evtStore()->event()->copy("egammaClusters"), "copying egamma clusters failed");
182 
183  // Object Thinning maps
184  std::shared_ptr<ThinningMap_t> photonThinningMap = savePhotons(saveEventObjects);
185  std::shared_ptr<ThinningMap_t> electronThinningMap = saveElectrons(saveEventObjects);
186  std::shared_ptr<ThinningMap_t> muonThinningMap = saveMuons(saveEventObjects);
187  std::shared_ptr<ThinningMap_t> tauThinningMap = saveTaus(saveEventObjects);
188  std::shared_ptr<ThinningMap_t> jetThinningMap = saveJets(saveEventObjects);
189  std::shared_ptr<ThinningMap_t> largeRJetThinningMap = saveLargeRJets(saveEventObjects);
190  std::shared_ptr<ThinningMap_t> trackJetThinningMap = saveTrackJets(saveEventObjects);
191 
192  // Save SystematicEventContainer
193  xAOD::SystematicEventContainer* allSystematics_output = new xAOD::SystematicEventContainer {};
194  SG::IAuxStore* allSystematics_output_aux = evtStore()->event()->recordAux(
195  m_config->sgKeyTopSystematicEvents() + "Aux.");
196  allSystematics_output->setStore(allSystematics_output_aux);
197  if (saveEventObjects) {
198  for (const auto *systematicPtr : *allSystematics) {
199  if (!(systematicPtr->hashValue() == m_config->nominalHashValue() || m_config->doTightSysts() ||
200  m_config->doLooseSysts())) continue;
202  out->makePrivateStore(*systematicPtr);
203  out->setGoodPhotons(thinObjectSelection(systematicPtr->hashValue(), systematicPtr->goodPhotons(),
204  photonThinningMap));
205  out->setGoodElectrons(thinObjectSelection(systematicPtr->hashValue(), systematicPtr->goodElectrons(),
206  electronThinningMap));
207  out->setGoodMuons(thinObjectSelection(systematicPtr->hashValue(), systematicPtr->goodMuons(),
208  muonThinningMap));
209  out->setGoodTaus(thinObjectSelection(systematicPtr->hashValue(), systematicPtr->goodTaus(), tauThinningMap));
210  out->setGoodJets(thinObjectSelection(systematicPtr->hashValue(), systematicPtr->goodJets(), jetThinningMap));
211  out->setGoodLargeRJets(thinObjectSelection(systematicPtr->hashValue(), systematicPtr->goodLargeRJets(),
212  largeRJetThinningMap));
213  out->setGoodTrackJets(thinObjectSelection(systematicPtr->hashValue(), systematicPtr->goodTrackJets(),
214  trackJetThinningMap));
215  allSystematics_output->push_back(out);
216 
217  // Missing ET
218  xAOD::MissingETContainer* met(nullptr);
219  top::check(evtStore()->retrieve(met, m_config->sgKeyMissingEt(
220  systematicPtr->hashValue())), "Failed to retrieve MET");
221 
223  SG::IAuxStore* output_met_aux =
224  evtStore()->event()->recordAux(m_config->sgKeyMissingEt(systematicPtr->hashValue()) + "Aux.");
225  output_met->setStore(output_met_aux);
226  for (auto x : *met) {
228  out->makePrivateStore(*x);
229  output_met->push_back(out);
230  }
231  top::check(evtStore()->event()->record(output_met, m_config->sgKeyMissingEt(
232  systematicPtr->hashValue())), "Failed to save MET");
233  }
234  }
235  top::check(evtStore()->event()->record(allSystematics_output,
236  m_config->sgKeyTopSystematicEvents()),
237  "Failed to record xAOD::SystematicEventContainer");
238 
239  // Write to disk
240  top::check(evtStore()->event()->fill(), "xAOD::TEvent fill failed");
241  }
242  }
243 
244  std::vector<unsigned int> EventSaverxAODNext::thinObjectSelection(const std::size_t hashValue,
245  const std::vector<unsigned int>& objectList,
246  const std::shared_ptr<ThinningMap_t>& thinningMap)
247  const {
248  // reduced output
249  std::vector<unsigned int> out;
250 
251  // Find the correct systematic in the thinningMap
252  ThinningMap_Itr Itr = thinningMap->find(hashValue);
253  // If the systematic is not in the map, then we use the nominal hashValue
254  // This happens, for example, when we look at a jet systematic and are looping over electrons
255  if (Itr == thinningMap->end()) {
256  Itr = thinningMap->find(m_config->nominalHashValue());
257  }
258 
259  // double check that we have a valid systematic
260  if (Itr != thinningMap->end()) {
261  // Get the relevant thinningMap for this specific systematic
262  std::map<unsigned int, unsigned int> currentSystematicThinningMap = (*Itr).second;
263 
264  // Loop over the original good object list, this contains information about objects we are not going to save
265  // Use the thinningMap to build a new good object list based on the objects we are saving
266  for (auto i : objectList) {
267  std::map<unsigned int, unsigned int>::const_iterator Itr2 = currentSystematicThinningMap.find(i);
268  if (Itr2 != currentSystematicThinningMap.end()) {
269  out.push_back((*Itr2).second);
270  }
271  }
272  }
273 
274  return out;
275  }
276 
297  std::shared_ptr<std::map<std::size_t, std::map<unsigned int, unsigned int> > > EventSaverxAODNext::savePhotons(
298  const bool saveEventObjects) {
299  std::shared_ptr<ThinningMap_t> thinningMap(new ThinningMap_t);
300  if (m_config->usePhotons()) {
301  for (const auto& currentSystematic : *m_config->systSgKeyMapPhotons()) {
302  std::map<unsigned int, unsigned int> currentSystematicThinningMap;
303  std::string sgKey = currentSystematic.second;
304  const xAOD::PhotonContainer* xaod(nullptr);
305  top::check(evtStore()->retrieve(xaod, sgKey), "Failed to retrieve photons");
306 
308  SG::IAuxStore* output_aux = evtStore()->event()->recordAux(sgKey + "Aux.");
309  output->setStore(output_aux);
310 
311  if (saveEventObjects) {
312  unsigned int index(0), indexReduced(0);
313  for (const auto *x : *xaod) {
314  bool save(m_saveAllObjects);
315  if (x->isAvailable<char>("passPreORSelection")) {
316  if (x->auxdataConst<char>("passPreORSelection") == 1) {
317  save = true;
318  }
319  }
320  if (x->isAvailable<char>("passPreORSelectionLoose")) {
321  if (x->auxdataConst<char>("passPreORSelectionLoose") == 1) {
322  save = true;
323  }
324  }
325 
326  if (save) {
327  currentSystematicThinningMap.insert(std::make_pair(index, indexReduced));
328  xAOD::Photon* out = new xAOD::Photon {};
329  out->makePrivateStore(*x);
330  output->push_back(out);
331  ++indexReduced;
332  }
333  ++index;
334  } // Loop over container
335  } // saveEventObjects
336  top::check(evtStore()->event()->record(output, sgKey), "Failed to record xAOD::PhotonContainer");
337  thinningMap->insert(std::make_pair(currentSystematic.first, currentSystematicThinningMap));
338  } // Loop over all systematics;
339  } // use object type
340 
341  return thinningMap;
342  }
343 
344  std::shared_ptr<std::map<std::size_t, std::map<unsigned int, unsigned int> > > EventSaverxAODNext::saveElectrons(
345  const bool saveEventObjects) {
346  std::shared_ptr<ThinningMap_t> thinningMap(new ThinningMap_t);
347  if (m_config->useElectrons()) {
348  for (const auto& currentSystematic : *m_config->systSgKeyMapElectrons()) {
349  std::map<unsigned int, unsigned int> currentSystematicThinningMap;
350  std::string sgKey = currentSystematic.second;
351  const xAOD::ElectronContainer* xaod(nullptr);
352  top::check(evtStore()->retrieve(xaod, sgKey), "Failed to retrieve electrons");
353 
355  SG::IAuxStore* output_aux = evtStore()->event()->recordAux(sgKey + "Aux.");
356  output->setStore(output_aux);
357 
358  if (saveEventObjects) {
359  unsigned int index(0), indexReduced(0);
360  for (const auto *x : *xaod) {
361  bool save(m_saveAllObjects);
362  if (x->isAvailable<char>("passPreORSelection")) {
363  if (x->auxdataConst<char>("passPreORSelection") == 1) {
364  save = true;
365  }
366  }
367  if (x->isAvailable<char>("passPreORSelectionLoose")) {
368  if (x->auxdataConst<char>("passPreORSelectionLoose") == 1) {
369  save = true;
370  }
371  }
372 
373  if (save) {
374  currentSystematicThinningMap.insert(std::make_pair(index, indexReduced));
376  out->makePrivateStore(*x);
377  output->push_back(out);
378  ++indexReduced;
379  }
380  ++index;
381  } // Loop over container
382  // Reset calo cluster links
383  for (std::map<unsigned int, unsigned int>::const_iterator i = currentSystematicThinningMap.begin();
384  i != currentSystematicThinningMap.end(); ++i) {
385  output->at((*i).second)->setCaloClusterLinks(xaod->at((*i).first)->caloClusterLinks());
386  }
387  } // saveEventObjects
388  top::check(evtStore()->event()->record(output, sgKey), "Failed to record xAOD::ElectronContainer");
389  thinningMap->insert(std::make_pair(currentSystematic.first, currentSystematicThinningMap));
390  } // Loop over all systematics
391  } // use object type
392 
393  return thinningMap;
394  }
395 
396  std::shared_ptr<std::map<std::size_t, std::map<unsigned int, unsigned int> > > EventSaverxAODNext::saveMuons(
397  const bool saveEventObjects) {
398  std::shared_ptr<ThinningMap_t> thinningMap(new ThinningMap_t);
399  if (m_config->useMuons()) {
400  for (const auto& currentSystematic : *m_config->systSgKeyMapMuons()) {
401  std::map<unsigned int, unsigned int> currentSystematicThinningMap;
402  std::string sgKey = currentSystematic.second;
403  const xAOD::MuonContainer* xaod(nullptr);
404  top::check(evtStore()->retrieve(xaod, sgKey), "Failed to retrieve muons");
405 
407  SG::IAuxStore* output_aux = evtStore()->event()->recordAux(sgKey + "Aux.");
408  output->setStore(output_aux);
409 
410  if (saveEventObjects) {
411  unsigned int index(0), indexReduced(0);
412  for (const auto *x : *xaod) {
413  bool save(m_saveAllObjects);
414  if (x->isAvailable<char>("passPreORSelection")) {
415  if (x->auxdataConst<char>("passPreORSelection") == 1) {
416  save = true;
417  }
418  }
419  if (x->isAvailable<char>("passPreORSelectionLoose")) {
420  if (x->auxdataConst<char>("passPreORSelectionLoose") == 1) {
421  save = true;
422  }
423  }
424 
425  if (save) {
426  currentSystematicThinningMap.insert(std::make_pair(index, indexReduced));
427  xAOD::Muon* out = new xAOD::Muon {};
428  out->makePrivateStore(*x);
429  output->push_back(out);
430  ++indexReduced;
431  }
432  ++index;
433  } // Loop over container
434  } // saveEventObjects
435  top::check(evtStore()->event()->record(output, sgKey), "Failed to record xAOD::MuonContainer");
436  thinningMap->insert(std::make_pair(currentSystematic.first, currentSystematicThinningMap));
437  } // Loop over all systematics
438  } // use object type
439 
440  return thinningMap;
441  }
442 
443  std::shared_ptr<std::map<std::size_t, std::map<unsigned int, unsigned int> > > EventSaverxAODNext::saveTaus(
444  const bool saveEventObjects) {
445  std::shared_ptr<ThinningMap_t> thinningMap(new ThinningMap_t);
446  if (m_config->useTaus()) {
447  for (const auto& currentSystematic : *m_config->systSgKeyMapTaus()) {
448  std::map<unsigned int, unsigned int> currentSystematicThinningMap;
449  std::string sgKey = currentSystematic.second;
450  const xAOD::TauJetContainer* xaod(nullptr);
451  top::check(evtStore()->retrieve(xaod, sgKey), "Failed to retrieve taus");
452 
454  SG::IAuxStore* output_aux = evtStore()->event()->recordAux(sgKey + "Aux.");
455  output->setStore(output_aux);
456 
457  if (saveEventObjects) {
458  unsigned int index(0), indexReduced(0);
459  for (const auto *x : *xaod) {
460  bool save(m_saveAllObjects);
461  if (x->isAvailable<char>("passPreORSelection")) {
462  if (x->auxdataConst<char>("passPreORSelection") == 1) {
463  save = true;
464  }
465  }
466  if (x->isAvailable<char>("passPreORSelectionLoose")) {
467  if (x->auxdataConst<char>("passPreORSelectionLoose") == 1) {
468  save = true;
469  }
470  }
471 
472  if (save) {
473  currentSystematicThinningMap.insert(std::make_pair(index, indexReduced));
474  xAOD::TauJet* out = new xAOD::TauJet {};
475  out->makePrivateStore(*x);
476  output->push_back(out);
477  ++indexReduced;
478  }
479  ++index;
480  } // Loop over container
481  } // saveEventObjects
482  top::check(evtStore()->event()->record(output, sgKey), "Failed to record xAOD::TauJetContainer");
483  thinningMap->insert(std::make_pair(currentSystematic.first, currentSystematicThinningMap));
484  } // Loop over all systematics
485  } // use object type
486 
487  return thinningMap;
488  }
489 
490  std::shared_ptr<std::map<std::size_t, std::map<unsigned int, unsigned int> > > EventSaverxAODNext::saveJets(
491  const bool saveEventObjects) {
492  std::shared_ptr<ThinningMap_t> thinningMap(new ThinningMap_t);
493  if (m_config->useJets()) {
494  for (const auto& currentSystematic : *m_config->systSgKeyMapJets(false)) {
495  std::map<unsigned int, unsigned int> currentSystematicThinningMap;
496  std::string sgKey = currentSystematic.second;
497  const xAOD::JetContainer* xaod(nullptr);
498  top::check(evtStore()->retrieve(xaod, sgKey), "Failed to retrieve jets");
499 
501  SG::IAuxStore* output_aux = evtStore()->event()->recordAux(sgKey + "Aux.");
502  output->setStore(output_aux);
503 
504  if (saveEventObjects) {
505  unsigned int index(0), indexReduced(0);
506  for (const auto *x : *xaod) {
507  bool save(m_saveAllObjects);
508  if (x->isAvailable<char>("passPreORSelection")) {
509  if (x->auxdataConst<char>("passPreORSelection") == 1) {
510  save = true;
511  }
512  }
513  if (x->isAvailable<char>("passPreORSelectionLoose")) {
514  if (x->auxdataConst<char>("passPreORSelectionLoose") == 1) {
515  save = true;
516  }
517  }
518 
519  if (save) {
520  currentSystematicThinningMap.insert(std::make_pair(index, indexReduced));
521  xAOD::Jet* out = new xAOD::Jet {};
522  out->makePrivateStore(*x);
523  output->push_back(out);
524  ++indexReduced;
525  }
526  ++index;
527  } // Loop over container
528 
529  // Reset b-tagging links
530  for (auto i : currentSystematicThinningMap) {
531  const xAOD::Jet *jet = output->at(i.second);
534  }
535 
536  } // saveEventObjects
537  top::check(evtStore()->event()->record(output, sgKey), "Failed to record xAOD::JetContainer");
538  thinningMap->insert(std::make_pair(currentSystematic.first, currentSystematicThinningMap));
539  } // Loop over all systematics
540  } // use object type
541 
542  return thinningMap;
543  }
544 
545  std::shared_ptr<std::map<std::size_t, std::map<unsigned int, unsigned int> > > EventSaverxAODNext::saveLargeRJets(
546  const bool saveEventObjects) {
547  std::shared_ptr<ThinningMap_t> thinningMap(new ThinningMap_t);
548  if (m_config->useLargeRJets()) {
549  for (const auto& currentSystematic : *m_config->systSgKeyMapLargeRJets()) {
550  std::map<unsigned int, unsigned int> currentSystematicThinningMap;
551  std::string sgKey = currentSystematic.second;
552  const xAOD::JetContainer* xaod(nullptr);
553  top::check(evtStore()->retrieve(xaod, sgKey), "Failed to retrieve LargeRjets");
554 
556  SG::IAuxStore* output_aux = evtStore()->event()->recordAux(sgKey + "Aux.");
557  output->setStore(output_aux);
558 
559  if (saveEventObjects) {
560  unsigned int index(0), indexReduced(0);
561  for (const auto *x : *xaod) {
562  bool save(m_saveAllObjects);
563  if (x->isAvailable<char>("passPreORSelection")) {
564  if (x->auxdataConst<char>("passPreORSelection") == 1) {
565  save = true;
566  }
567  }
568  if (x->isAvailable<char>("passPreORSelectionLoose")) {
569  if (x->auxdataConst<char>("passPreORSelectionLoose") == 1) {
570  save = true;
571  }
572  }
573 
574  if (save) {
575  currentSystematicThinningMap.insert(std::make_pair(index, indexReduced));
576  xAOD::Jet* out = new xAOD::Jet {};
577  out->makePrivateStore(*x);
578  output->push_back(out);
579  ++indexReduced;
580  }
581  ++index;
582  } // Loop over container
583 
584  // Reset b-tagging links
585  for (auto i : currentSystematicThinningMap) {
586  const xAOD::Jet *jet = output->at(i.second);
589  }
590  } // saveEventObjects
591  top::check(evtStore()->event()->record(output, sgKey), "Failed to record xAOD::JetContainer");
592  thinningMap->insert(std::make_pair(currentSystematic.first, currentSystematicThinningMap));
593  } // Loop over all systematics
594  } // use object type
595 
596  return thinningMap;
597  }
598 
599  std::shared_ptr<std::map<std::size_t, std::map<unsigned int, unsigned int> > > EventSaverxAODNext::saveTrackJets(
600  const bool saveEventObjects) {
601  std::shared_ptr<ThinningMap_t> thinningMap(new ThinningMap_t);
602  if (m_config->useTrackJets()) {
603  for (const auto& currentSystematic : *m_config->systSgKeyMapTrackJets()) {
604  std::map<unsigned int, unsigned int> currentSystematicThinningMap;
605  std::string sgKey = currentSystematic.second;
606  const xAOD::JetContainer* xaod(nullptr);
607  top::check(evtStore()->retrieve(xaod, sgKey), "Failed to retrieve trackjets");
608 
610  SG::IAuxStore* output_aux = evtStore()->event()->recordAux(sgKey + "Aux.");
611  output->setStore(output_aux);
612 
613  if (saveEventObjects) {
614  unsigned int index(0), indexReduced(0);
615  for (const auto *x : *xaod) {
616  bool save(m_saveAllObjects);
617  if (x->isAvailable<char>("passPreORSelection")) {
618  if (x->auxdataConst<char>("passPreORSelection") == 1) {
619  save = true;
620  }
621  }
622  if (x->isAvailable<char>("passPreORSelectionLoose")) {
623  if (x->auxdataConst<char>("passPreORSelectionLoose") == 1) {
624  save = true;
625  }
626  }
627 
628  if (save) {
629  currentSystematicThinningMap.insert(std::make_pair(index, indexReduced));
630  xAOD::Jet* out = new xAOD::Jet {};
631  out->makePrivateStore(*x);
632  output->push_back(out);
633  ++indexReduced;
634  }
635  ++index;
636  } // Loop over container
637 
638  // Reset b-tagging links
639  for (auto i : currentSystematicThinningMap) {
640  const xAOD::Jet *jet = output->at(i.second);
643  }
644  } // saveEventObjects
645  top::check(evtStore()->event()->record(output, sgKey), "Failed to record xAOD::JetContainer");
646  thinningMap->insert(std::make_pair(currentSystematic.first, currentSystematicThinningMap));
647  } // Loop over all systematics
648  } // use object type
649 
650  return thinningMap;
651  }
652 
654  m_outputFile->Write();
655  top::check(evtStore()->event()->finishWritingTo(
656  m_outputFile), "EventSaverxAODNext::finalise trying to call finishWritingTo");
657  }
658 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
BTaggingUtilities.h
EventSaverxAODNext.h
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
top::EventSaverxAODNext::thinObjectSelection
std::vector< unsigned int > thinObjectSelection(const std::size_t hashValue, const std::vector< unsigned int > &objectList, const std::shared_ptr< ThinningMap_t > &thinningMap) const
Definition: EventSaverxAODNext.cxx:244
top::EventSaverxAODNext::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: EventSaverxAODNext.h:47
xAOD::BTaggingUtilities::setBTaggingLink
void setBTaggingLink(const SG::AuxElement &part, const ElementLink< xAOD::BTaggingContainer > &el)
Set the default xAOD::BTagging link for an object.
Definition: BTaggingUtilities.cxx:64
index
Definition: index.py:1
top::EventSaverxAODNext::m_config
std::shared_ptr< top::TopConfig > m_config
We need access to the configuration file to get the container names.
Definition: EventSaverxAODNext.h:56
top::EventSaverxAODNext::m_outputFile
TFile * m_outputFile
We need to hold on to the output file.
Definition: EventSaverxAODNext.h:59
asg
Definition: DataHandleTestTool.h:28
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
top::EventSaverxAODNext::ThinningMap_Itr
ThinningMap_t::const_iterator ThinningMap_Itr
Definition: EventSaverxAODNext.h:65
top::EventSaverBase::saveEvent
virtual void saveEvent(const top::Event &)
I guess you want to save an event sometimes to.
Definition: EventSaverBase.h:59
top::EventSaverxAODNext::saveLargeRJets
std::shared_ptr< ThinningMap_t > saveLargeRJets(const bool saveEventObjects)
Definition: EventSaverxAODNext.cxx:545
top::EventSaverxAODNext::finalize
virtual void finalize()
xAOD needs to write some more stuff to the file at the end of a job
Definition: EventSaverxAODNext.cxx:653
x
#define x
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
EventTools.h
A few functions for doing operations on particles / events. Currently holds code for dR,...
top::EventSaverxAODNext::saveEventToxAOD
virtual void saveEventToxAOD()
Definition: EventSaverxAODNext.cxx:148
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
checkTP.save
def save(self, fileName="./columbo.out")
Definition: checkTP.py:178
top::EventSaverxAODNext::saveTrackJets
std::shared_ptr< ThinningMap_t > saveTrackJets(const bool saveEventObjects)
Definition: EventSaverxAODNext.cxx:599
met
Definition: IMETSignificance.h:24
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
PartonHistory.h
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
ElectronContainer.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
top::EventSaverxAODNext::saveElectrons
std::shared_ptr< ThinningMap_t > saveElectrons(const bool saveEventObjects)
Definition: EventSaverxAODNext.cxx:344
top::ConfigurationSettings::get
static ConfigurationSettings * get(bool reset=false)
Design patterns 101.
Definition: ConfigurationSettings.cxx:714
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
TEvent.h
file
TFile * file
Definition: tile_monitor.h:29
xAOD::MissingET_v1
Principal data object for Missing ET.
Definition: MissingET_v1.h:25
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
top::check
void check(bool thingToCheck, const std::string &usefulFailureMessage)
Print an error message and terminate if thingToCheck is false.
Definition: EventTools.cxx:15
TauJetContainer.h
Event.h
top::EventSaverxAODNext::saveTaus
std::shared_ptr< ThinningMap_t > saveTaus(const bool saveEventObjects)
Definition: EventSaverxAODNext.cxx:443
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
ConfigurationSettings.h
merge.output
output
Definition: merge.py:17
xAOD::MissingETContainer_v1
Container for xAOD::MissingET_v1 objects.
Definition: MissingETContainer_v1.h:21
top::EventSaverxAODNext::EventSaverxAODNext
EventSaverxAODNext()
Definition: EventSaverxAODNext.cxx:29
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
top::EventSaverxAODNext::saveMuons
std::shared_ptr< ThinningMap_t > saveMuons(const bool saveEventObjects)
Definition: EventSaverxAODNext.cxx:396
TopConfig.h
xAOD::Electron_v1
Definition: Electron_v1.h:34
MuonContainer.h
SG::IAuxStore
Interface for non-const operations on an auxiliary store.
Definition: IAuxStore.h:48
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
top::EventSaverxAODNext::savePhotons
std::shared_ptr< ThinningMap_t > savePhotons(const bool saveEventObjects)
All the saveObject functions work the same way.
Definition: EventSaverxAODNext.cxx:297
DeMoScan.index
string index
Definition: DeMoScan.py:362
xAOD::SystematicEvent
SystematicEvent A simple xAOD class which we can persist into a mini-xAOD The xAOD EDM is way too com...
Definition: SystematicEvent.h:27
JetContainer.h
xAOD::Photon_v1
Definition: Photon_v1.h:37
lumiFormat.fill
fill
Definition: lumiFormat.py:111
top::EventSaverxAODNext::ThinningMap_t
std::map< std::size_t, std::map< unsigned int, unsigned int > > ThinningMap_t
Definition: EventSaverxAODNext.h:64
asg::AsgMetadataTool::outputMetaStore
MetaStorePtr_t outputMetaStore() const
Accessor for the output metadata store.
Definition: AsgMetadataTool.cxx:97
config
std::vector< std::string > config
Definition: fbtTestBasics.cxx:72
top::EventSaverxAODNext::~EventSaverxAODNext
virtual ~EventSaverxAODNext()
Definition: EventSaverxAODNext.cxx:36
calibdata.copy
bool copy
Definition: calibdata.py:27
top::EventSaverxAODNext::m_saveAllObjects
bool m_saveAllObjects
Definition: EventSaverxAODNext.h:61
xAOD::BTaggingUtilities::getBTaggingLink
const ElementLink< xAOD::BTaggingContainer > & getBTaggingLink(const SG::AuxElement &part)
Access the default xAOD::BTagging link for an object.
Definition: BTaggingUtilities.cxx:50
SystematicEventContainer.h
PhotonContainer.h
MissingETContainer.h
top::EventSaverxAODNext::saveJets
std::shared_ptr< ThinningMap_t > saveJets(const bool saveEventObjects)
Definition: EventSaverxAODNext.cxx:490