ATLAS Offline Software
TopEventMaker.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 // $Id: TopEventMaker.cxx 809847 2017-08-29 15:18:19Z iconnell $
7 #include "TopEvent/EventTools.h"
8 
10 
15 #include "xAODMuon/MuonContainer.h"
19 #include "xAODJet/JetContainer.h"
22 #include "xAODCore/ShallowCopy.h"
24 
26 
27 #include <boost/algorithm/string.hpp>
28 
29 #include <iostream>
30 
31 namespace top {
33 
34  TopEventMaker::TopEventMaker(const std::string& name) :
35  asg::AsgTool(name),
36  m_config(nullptr) {
37  declareProperty("config", m_config);
38  }
39 
41  if (m_config->useRCJets() == true) {
42  m_rc = std::unique_ptr<RCJet> (new RCJet("RCJet"));
43  top::check(m_rc->setProperty("config", m_config), "Failed to set config property of RCJet");
44  top::check(m_rc->initialize(), "Failed to initialize RCJet");
45  }
46 
47  if (m_config->useVarRCJets() == true) {
48  boost::split(m_VarRCJetRho, m_config->VarRCJetRho(), boost::is_any_of(","));
49  boost::split(m_VarRCJetMassScale, m_config->VarRCJetMassScale(), boost::is_any_of(","));
50 
51  for (auto& rho : m_VarRCJetRho) {
52  for (auto& mass_scale : m_VarRCJetMassScale) {
53  std::replace(rho.begin(), rho.end(), '.', '_');
54  std::string name = rho + mass_scale;
55  m_VarRC[name] = std::unique_ptr<RCJet> (new RCJet("VarRCJet_" + name));
56  top::check(m_VarRC[name]->setProperty("config", m_config), "Failed to set config property of VarRCJet");
57  top::check(m_VarRC[name]->setProperty("VarRCjets", true), "Failed to set VarRCjets property of VarRCJet");
58  top::check(m_VarRC[name]->setProperty("VarRCjets_rho",
59  rho), "Failed to set VarRCjets rho property of VarRCJet");
60  top::check(m_VarRC[name]->setProperty("VarRCjets_mass_scale",
61  mass_scale),
62  "Failed to set VarRCjets mass scale property of VarRCJet");
63  top::check(m_VarRC[name]->initialize(), "Failed to initialize VarRCJet");
64  } // end loop over mass scale parameters (e.g., top mass, w mass, etc.)
65  } // end loop over mass scale multiplies (e.g., 1.,2.,etc.)
66  }
67 
68  return StatusCode::SUCCESS;
69  }
70 
73  const xAOD::SystematicEventContainer* TopEventMaker::systematicEvents(const std::string& sgKey) const {
74  const xAOD::SystematicEventContainer* systEvents(nullptr);
75 
76  top::check(evtStore()->retrieve(systEvents, sgKey), "Failed to get xAOD::SystematicEventContainer");
77  return systEvents;
78  }
79 
81  xAOD::SystematicEvent const& currentSystematic = *currentSystematicPtr;
82  //create a new event object
84 
85  // Set systematic hash value
86  std::size_t hash = currentSystematic.hashValue();
87  event.m_hashValue = hash;
88 
89  // TTree index
90  event.m_ttreeIndex = currentSystematic.ttreeIndex();
91 
92  // Is Loose event?
93  event.m_isLoose = currentSystematic.isLooseEvent();
94 
95  //event info
96  top::check(evtStore()->retrieve(event.m_info, m_config->sgKeyEventInfo()), "Failed to retrieve EventInfo");
97  event.m_systematicEvent = currentSystematicPtr;
98 
99  //Primary Vertices
100  if (evtStore()->contains<xAOD::VertexContainer>(m_config->sgKeyPrimaryVertices())) {
101  top::check(evtStore()->retrieve(event.m_primaryVertices,
102  m_config->sgKeyPrimaryVertices()), "Failed to retrieve Primary Vertices");
103  }
104 
105  //Poisson bootstrap weights
106  if (m_config->saveBootstrapWeights()) {
107  int second_seed;
108  if (m_config->isMC()) {
109  second_seed = event.m_info->mcChannelNumber();
110  } else {
111  second_seed = event.m_info->runNumber();
112  }
113  std::vector<int> weight_poisson = top::calculateBootstrapWeights(m_config->getNumberOfBootstrapReplicas(),
114  event.m_info->eventNumber(),
115  second_seed);
116  event.m_info->auxdecor< std::vector<int> >("weight_poisson") = weight_poisson;
117  }
118 
119  //electrons
120  if (m_config->useElectrons()) {
122 
123  const xAOD::ElectronContainer* calibratedElectrons(nullptr);
124  top::check(evtStore()->retrieve(calibratedElectrons, m_config->sgKeyElectrons(
125  hash)), "Failed to retrieve electrons");
126 
128  if (!evtStore()->contains<xAOD::ElectronContainer>(m_config->sgKeyElectronsTDS(hash))) {
129  std::pair< xAOD::ElectronContainer*,
130  xAOD::ShallowAuxContainer* > shallow_electrons = xAOD::shallowCopyContainer(*calibratedElectrons);
131 
132  StatusCode save = evtStore()->tds()->record(shallow_electrons.first, m_config->sgKeyElectronsTDS(hash));
133  StatusCode saveAux =
134  evtStore()->tds()->record(shallow_electrons.second, m_config->sgKeyElectronsTDSAux(hash));
135  top::check((save && saveAux), "Failed to store object in TStore");
136  }
137 
139  xAOD::ElectronContainer* calibratedElectronsTDS(nullptr);
140  top::check(evtStore()->retrieve(calibratedElectronsTDS, m_config->sgKeyElectronsTDS(
141  hash)), "Failed to retrieve electrons");
142 
143 
144  // re-write overlap information if it is decorated onto currentSystematic
145  if (currentSystematic.isAvailable< std::vector<unsigned int> >("overlapsEl")) {
146  std::vector<unsigned int> overlapsEl =
147  currentSystematic.auxdataConst< std::vector<unsigned int> >("overlapsEl");
148  if (overlapsEl.size() == calibratedElectronsTDS->size()) {
149  unsigned int counter(0);
150  for (auto x : *calibratedElectronsTDS) {
151  x->auxdecor<char>("overlaps") = overlapsEl.at(counter);
152  ++counter;
153  }
154  }
155  }
156 
157  for (auto index : currentSystematic.goodElectrons()) {
158  event.m_electrons.push_back(calibratedElectronsTDS->at(index));
159  }
160 
161  //shallow copies aren't sorted!
162  //sort only the selected electrons (faster)
163  event.m_electrons.sort(top::descendingPtSorter);
164  }
165 
166  //forward electrons
167  if (m_config->useFwdElectrons()) {
168  const xAOD::ElectronContainer* calibratedFwdElectrons(nullptr);
169  top::check(evtStore()->retrieve(calibratedFwdElectrons, m_config->sgKeyFwdElectrons(
170  hash)), "Failed to retrieve fwd electrons");
171 
173  if (!evtStore()->contains<xAOD::ElectronContainer>(m_config->sgKeyFwdElectronsTDS(hash))) {
174  std::pair< xAOD::ElectronContainer*,
175  xAOD::ShallowAuxContainer* > shallow_fwdelectrons = xAOD::shallowCopyContainer(
176  *calibratedFwdElectrons);
177 
178  StatusCode save =
179  evtStore()->tds()->record(shallow_fwdelectrons.first, m_config->sgKeyFwdElectronsTDS(hash));
180  StatusCode saveAux = evtStore()->tds()->record(shallow_fwdelectrons.second, m_config->sgKeyFwdElectronsTDSAux(
181  hash));
182  top::check((save && saveAux), "Failed to store object in TStore");
183  }
184 
186  xAOD::ElectronContainer* calibratedFwdElectronsTDS(nullptr);
187  top::check(evtStore()->retrieve(calibratedFwdElectronsTDS, m_config->sgKeyFwdElectronsTDS(
188  hash)), "Failed to retrieve fwd electrons");
189 
190  for (const auto& index : currentSystematic.goodFwdElectrons()) {
191  event.m_fwdElectrons.push_back(calibratedFwdElectronsTDS->at(index));
192  }
193 
194  //shallow copies aren't sorted!
195  //sort only the selected fwd electrons (faster)
196  event.m_fwdElectrons.sort(top::descendingPtSorter);
197  }
198 
199  //photons
200  if (m_config->usePhotons()) {
202 
203  const xAOD::PhotonContainer* calibratedPhotons(nullptr);
204  top::check(evtStore()->retrieve(calibratedPhotons, m_config->sgKeyPhotons(hash)), "Failed to retrieve photons");
205 
207  if (!evtStore()->contains<xAOD::PhotonContainer>(m_config->sgKeyPhotonsTDS(hash))) {
208  std::pair< xAOD::PhotonContainer*, xAOD::ShallowAuxContainer* > shallow_photons = xAOD::shallowCopyContainer(
209  *calibratedPhotons);
210 
211  StatusCode save = evtStore()->tds()->record(shallow_photons.first, m_config->sgKeyPhotonsTDS(hash));
212  StatusCode saveAux =
213  evtStore()->tds()->record(shallow_photons.second, m_config->sgKeyPhotonsTDSAux(hash));
214  top::check((save && saveAux), "Failed to store object in TStore");
215  }
216 
218  xAOD::PhotonContainer* calibratedPhotonsTDS(nullptr);
219  top::check(evtStore()->retrieve(calibratedPhotonsTDS, m_config->sgKeyPhotonsTDS(
220  hash)), "Failed to retrieve photons");
221 
222  for (auto index : currentSystematic.goodPhotons()) {
223  event.m_photons.push_back(calibratedPhotonsTDS->at(index));
224  }
225  //shallow copies aren't sorted!
226  //sort only the selected photons (faster)
227  event.m_photons.sort(top::descendingPtSorter);
228  }
229 
230  //muons
231  if (m_config->useMuons()) {
233  const xAOD::MuonContainer* calibratedMuons(nullptr);
234  top::check(evtStore()->retrieve(calibratedMuons, m_config->sgKeyMuons(hash)), "Failed to retrieve muons");
235 
237  if (!evtStore()->contains<xAOD::MuonContainer>(m_config->sgKeyMuonsTDS(hash))) {
238  std::pair< xAOD::MuonContainer*, xAOD::ShallowAuxContainer* > shallow_muons = xAOD::shallowCopyContainer(
239  *calibratedMuons);
240 
241  StatusCode save = evtStore()->tds()->record(shallow_muons.first, m_config->sgKeyMuonsTDS(hash));
242  StatusCode saveAux = evtStore()->tds()->record(shallow_muons.second, m_config->sgKeyMuonsTDSAux(hash));
243  top::check((save && saveAux), "Failed to store object in TStore");
244  }
245 
247  xAOD::MuonContainer* calibratedMuonsTDS(nullptr);
248  top::check(evtStore()->retrieve(calibratedMuonsTDS, m_config->sgKeyMuonsTDS(hash)), "Failed to retrieve muons");
249 
250  // re-write overlap information if it is decorated onto currentSystematic
251  if (currentSystematic.isAvailable< std::vector<unsigned int> >("overlapsMu")) {
252  std::vector<unsigned int> overlapsMu =
253  currentSystematic.auxdataConst< std::vector<unsigned int> >("overlapsMu");
254  if (overlapsMu.size() == calibratedMuonsTDS->size()) {
255  unsigned int counter(0);
256  for (auto x : *calibratedMuons) {
257  x->auxdecor<char>("overlaps") = overlapsMu.at(counter);
258  ++counter;
259  }
260  }
261  }
262 
263  for (auto index : currentSystematic.goodMuons()) {
264  event.m_muons.push_back(calibratedMuonsTDS->at(index));
265  }
266 
267  //shallow copies aren't sorted!
268  //sort only the selected muons (faster)
269  event.m_muons.sort(top::descendingPtSorter);
270  }
271 
272  //soft muons
273  if (m_config->useSoftMuons()) {
275  const xAOD::MuonContainer* calibratedSoftMuons(nullptr);
276 
277  top::check(evtStore()->retrieve(calibratedSoftMuons, m_config->sgKeySoftMuons(hash)), "Failed to retrieve muons");
278 
279 
281  if (!evtStore()->contains<xAOD::MuonContainer>(m_config->sgKeySoftMuonsTDS(hash))) {
282  std::pair< xAOD::MuonContainer*, xAOD::ShallowAuxContainer* > shallow_softmuons = xAOD::shallowCopyContainer(
283  *calibratedSoftMuons);
284 
285  StatusCode save = evtStore()->tds()->record(shallow_softmuons.first, m_config->sgKeySoftMuonsTDS(hash));
286  StatusCode saveAux =
287  evtStore()->tds()->record(shallow_softmuons.second, m_config->sgKeySoftMuonsTDSAux(hash));
288  top::check((save && saveAux), "Failed to store object in TStore");
289  }
290 
292  xAOD::MuonContainer* calibratedSoftMuonsTDS(nullptr);
293  top::check(evtStore()->retrieve(calibratedSoftMuonsTDS, m_config->sgKeySoftMuonsTDS(
294  hash)), "Failed to retrieve soft muons");
295 
296  //no overlap procedure applied to soft muons for the time being
297 
298  for (auto index : currentSystematic.goodSoftMuons()) {
299  event.m_softmuons.push_back(calibratedSoftMuonsTDS->at(index));
300  }
301 
302  //shallow copies aren't sorted!
303  //sort only the selected soft muons (faster)
304  event.m_softmuons.sort(top::descendingPtSorter);
305  }
306 
307  //taus
308  if (m_config->useTaus()) {
310  const xAOD::TauJetContainer* calibratedTaus(nullptr);
311  top::check(evtStore()->retrieve(calibratedTaus, m_config->sgKeyTaus(hash)), "Failed to retrieve taus");
312 
314  if (!evtStore()->contains<xAOD::TauJetContainer>(m_config->sgKeyTausTDS(hash))) {
315  std::pair< xAOD::TauJetContainer*, xAOD::ShallowAuxContainer* > shallow_taus = xAOD::shallowCopyContainer(
316  *calibratedTaus);
317 
318  StatusCode save = evtStore()->tds()->record(shallow_taus.first, m_config->sgKeyTausTDS(hash));
319  StatusCode saveAux = evtStore()->tds()->record(shallow_taus.second, m_config->sgKeyTausTDSAux(hash));
320  top::check((save && saveAux), "Failed to store object in TStore");
321  }
322 
324  xAOD::TauJetContainer* calibratedTausTDS(nullptr);
325  top::check(evtStore()->retrieve(calibratedTausTDS, m_config->sgKeyTausTDS(hash)), "Failed to retrieve taus");
326 
327  for (auto index : currentSystematic.goodTaus()) {
328  event.m_tauJets.push_back(calibratedTausTDS->at(index));
329  }
330 
331  //shallow copies aren't sorted!
332  //sort only the selected taus (faster)
333  event.m_tauJets.sort(top::descendingPtSorter);
334  }
335 
336  //jets
337  // We need to be careful with the boosted analysis,
338  // Do we take the jets collection that has loose or tight leptons subtracted?
339  bool looseJets(false);
340  if (m_config->applyElectronInJetSubtraction()) {
341  if (m_config->doOverlapRemovalOnLooseLeptonDef() || currentSystematic.isLooseEvent()) {
342  looseJets = true;
343  }
344  }
345 
346  if (m_config->useJets()) {
348  std::string sgKeyCalibrated(m_config->sgKeyJets(hash, looseJets));
349  std::string sgKeyTmp = "tmp_" + sgKeyCalibrated;
350  std::string sgKeyTmpAux = sgKeyTmp + "Aux.";
351 
352  const xAOD::JetContainer* calibratedJets(nullptr);
353  top::check(evtStore()->retrieve(calibratedJets, m_config->sgKeyJets(hash, looseJets)), "Failed to retrieve jets");
354 
356  if (!evtStore()->contains<xAOD::JetContainer>(m_config->sgKeyJetsTDS(hash, looseJets))) {
357  std::pair< xAOD::JetContainer*, xAOD::ShallowAuxContainer* > shallow_jets = xAOD::shallowCopyContainer(
358  *calibratedJets);
359 
360  StatusCode save = evtStore()->tds()->record(shallow_jets.first, m_config->sgKeyJetsTDS(hash, looseJets));
361  StatusCode saveAux =
362  evtStore()->tds()->record(shallow_jets.second, m_config->sgKeyJetsTDSAux(hash, looseJets));
363  top::check((save && saveAux), "Failed to store object in TStore");
364  }
365 
367  xAOD::JetContainer* calibratedJetsTDS(nullptr);
368  top::check(evtStore()->retrieve(calibratedJetsTDS, m_config->sgKeyJetsTDS(hash,
369  looseJets)), "Failed to retrieve taus");
370 
371 
372  for (auto index : currentSystematic.goodJets()) {
373  auto jet = calibratedJetsTDS->at(index);
374 
375  if (m_config->isMC()) {
376  // JVT and fJVT, make product of SF (initialised to 1 in the header)
377  top::check(jet->isAvailable<float>(
378  "JET_SF_jvt"),
379  " Can't find jet decoration \"JET_SF_jvt\" - we need it to calculate the jet scale-factors!");
380  if (jet->auxdataConst<float>("JET_SF_jvt") > 0) {
381  event.m_jvtSF *= jet->auxdataConst<float>("JET_SF_jvt");
382  }
383 
384  // fJVT scale factors not added to jets unless fJVT is requested
385  if (m_config->getfJVTWP() != "None") {
386  top::check(jet->isAvailable<float>(
387  "JET_SF_fjvt"),
388  " Can't find jet decoration \"JET_SF_fjvt\" - we need it to calculate the forward jet scale-factors!");
389  event.m_fjvtSF *= jet->auxdataConst<float>("JET_SF_fjvt");
390  }
391  if (currentSystematic.hashValue() == m_config->nominalHashValue()) {// we only need the up/down JVT SF systs
392  // for nominal
393  top::check(jet->isAvailable<float>(
394  "JET_SF_jvt_UP"),
395  " Can't find jet decoration \"JET_SF_jvt_UP\" - we need it to calculate the jet scale-factors!");
396  event.m_jvtSF_UP *= jet->auxdataConst<float>("JET_SF_jvt_UP");
397  top::check(jet->isAvailable<float>(
398  "JET_SF_jvt_DOWN"),
399  " Can't find jet decoration \"JET_SF_jvt_DOWN\" - we need it to calculate the jet scale-factors!");
400  event.m_jvtSF_DOWN *= jet->auxdataConst<float>("JET_SF_jvt_DOWN");
401 
402  // fJVT scale factors not added to jets unless fJVT is requested
403  if (m_config->getfJVTWP() != "None") {
404  top::check(jet->isAvailable<float>(
405  "JET_SF_fjvt_UP"),
406  " Can't find jet decoration \"JET_SF_fjvt_UP\" - we need it to calculate the forward jet scale-factors!");
407  event.m_fjvtSF_UP *= jet->auxdataConst<float>("JET_SF_fjvt_UP");
408  top::check(jet->isAvailable<float>(
409  "JET_SF_fjvt_DOWN"),
410  " Can't find jet decoration \"JET_SF_fjvt_DOWN\" - we need it to calculate the forward jet scale-factors!");
411  event.m_fjvtSF_DOWN *= jet->auxdataConst<float>("JET_SF_fjvt_DOWN");
412  }
413  } //isNominal
414  } //isMC
415 
416  top::check(jet->isAvailable<char>(
417  "passJVT"),
418  " Can't find jet decoration \"passJVT\" - we need it to decide if we should keep the jet in the top::Event instance or not!");
419  bool passfJVT(true);
420  if (m_config->doForwardJVTinMET() || m_config->getfJVTWP() != "None") {
421  top::check(jet->isAvailable<char>("AnalysisTop_fJVTdecision"),
422  " Can't find jet decoration \"AnalysisTop_fJVTdecision\" - we need it to decide if we should keep forward jets in the top::Event instance or not!");
423  passfJVT = jet->auxdataConst<char>("AnalysisTop_fJVTdecision");
424  if (m_config->saveFailForwardJVTJets()) {
425  if (!passfJVT) event.m_failFJvt_jets.push_back(calibratedJetsTDS->at(index));
426  }
427  //Add to failFJVT collection but don't actually cut on fJVT if fJVT is only requested in MET calculation (I'm not sure people will ever actually do this)
428  if (m_config->getfJVTWP() == "None") passfJVT = true;
429  }
430 
431  if (jet->auxdataConst<char>("passJVT") && passfJVT) event.m_jets.push_back(calibratedJetsTDS->at(index));
432  if (m_config->saveFailJVTJets()) {
433  if (!jet->auxdataConst<char>("passJVT")) event.m_failJvt_jets.push_back(calibratedJetsTDS->at(index));
434  }
435  }
436 
437  //shallow copies aren't sorted!
438  //sort only the selected taus (faster)
439  event.m_jets.sort(top::descendingPtSorter);
440  if (m_config->saveFailJVTJets()) event.m_failJvt_jets.sort(top::descendingPtSorter);
441  if ( (m_config->doForwardJVTinMET() || m_config->getfJVTWP() != "None") && m_config->saveFailForwardJVTJets()){
442  event.m_failFJvt_jets.sort(top::descendingPtSorter);
443  }
444  }
445 
446  // Reclustered jets
447  if (m_config->useRCJets()) {
448  top::check(m_rc->execute(event), "Failed to execute RCJet container");
449  std::string rcJetContainerName = m_rc->rcjetContainerName(event.m_hashValue, event.m_isLoose);
450  const xAOD::JetContainer* rc_jets(nullptr);
451  top::check(evtStore()->retrieve(rc_jets, rcJetContainerName), "Failed to retrieve RC JetContainer");
452  //Object selection
453  for (auto rcjet : *rc_jets) {
454  top::check(rcjet->isAvailable<bool>(
455  "PassedSelection"),
456  " Can't find jet decoration \"PassedSelection\" - we need it to decide if we should keep the reclustered jet in the top::Event instance or not!");
457  if (rcjet->auxdataConst<bool>("PassedSelection")) event.m_RCJets.push_back((xAOD::Jet*) rcjet);
458  }
459  }
460  // Variable-R reclustered jets
461  if (m_config->useVarRCJets()) {
462  for (auto& rho : m_VarRCJetRho) {
463  for (auto& mass_scale : m_VarRCJetMassScale) {
464  std::replace(rho.begin(), rho.end(), '.', '_');
465  std::string name = rho + mass_scale;
466  top::check(m_VarRC[name]->execute(event), "Failed to execute RCJet container");
467 
468  // Get the name of the container of re-clustered jets in TStore
469  std::string varRCJetContainerName = m_VarRC[name]->rcjetContainerName(event.m_hashValue, event.m_isLoose);
470 
471  // -- Retrieve the re-clustered jets from TStore & save good re-clustered jets -- //
472  const xAOD::JetContainer* vrc_jets(nullptr);
473  top::check(evtStore()->retrieve(vrc_jets, varRCJetContainerName), "Failed to retrieve RC JetContainer");
474 
475  event.m_VarRCJets[name] = std::make_shared<xAOD::JetContainer>(SG::VIEW_ELEMENTS);
476  for (auto vrcjet : *vrc_jets) {
477  top::check(vrcjet->isAvailable<bool>(
478  "PassedSelection"),
479  " Can't find jet decoration \"PassedSelection\" - we need it to decide if we should keep the variable-R reclustered jet in the top::Event instance or not!");
480  if (vrcjet->auxdataConst<bool>("PassedSelection")) event.m_VarRCJets[name]->push_back((xAOD::Jet*) vrcjet);
481  }
482  }
483  }
484  }
485 
486 
487  //large-R jets
488  if (m_config->useLargeRJets()) {
490  const xAOD::JetContainer* calibratedJets(nullptr);
491  top::check(evtStore()->retrieve(calibratedJets, m_config->sgKeyLargeRJets(hash)),
492  "Failed to retrieve largeR jets");
493 
495  if (!evtStore()->contains<xAOD::JetContainer>(m_config->sgKeyLargeRJetsTDS(hash))) {
496  std::pair< xAOD::JetContainer*, xAOD::ShallowAuxContainer* > shallow_jets = xAOD::shallowCopyContainer(
497  *calibratedJets);
498 
499  StatusCode save = evtStore()->tds()->record(shallow_jets.first, m_config->sgKeyLargeRJetsTDS(hash));
500  StatusCode saveAux =
501  evtStore()->tds()->record(shallow_jets.second, m_config->sgKeyLargeRJetsTDSAux(hash));
502  top::check((save && saveAux), "Failed to store object in TStore");
503  }
504 
506  xAOD::JetContainer* calibratedJetsTDS(nullptr);
507  top::check(evtStore()->retrieve(calibratedJetsTDS, m_config->sgKeyLargeRJetsTDS(
508  hash)), "Failed to retrieve largeR jets");
509 
510  for (auto index : currentSystematic.goodLargeRJets()) {
511  event.m_largeJets.push_back(calibratedJetsTDS->at(index));
512  }
513 
514  //shallow copies aren't sorted!
515  //sort only the selected jets (faster)
516  event.m_largeJets.sort(top::descendingPtSorter);
517  }
518 
519  //track jets
520  if (m_config->useTrackJets()) {
522  const xAOD::JetContainer* calibratedJets(nullptr);
523  top::check(evtStore()->retrieve(calibratedJets, m_config->sgKeyTrackJets(hash)), "Failed to retrieve track jets");
524 
526  if (!evtStore()->contains<xAOD::JetContainer>(m_config->sgKeyTrackJetsTDS(hash))) {
527  std::pair< xAOD::JetContainer*, xAOD::ShallowAuxContainer* > shallow_jets = xAOD::shallowCopyContainer(
528  *calibratedJets);
529 
530  StatusCode save = evtStore()->tds()->record(shallow_jets.first, m_config->sgKeyTrackJetsTDS(hash));
531  StatusCode saveAux =
532  evtStore()->tds()->record(shallow_jets.second, m_config->sgKeyTrackJetsTDSAux(hash));
533  top::check((save && saveAux), "Failed to store object in TStore");
534  }
535 
537  xAOD::JetContainer* calibratedJetsTDS(nullptr);
538  top::check(evtStore()->retrieve(calibratedJetsTDS, m_config->sgKeyTrackJetsTDS(
539  hash)), "Failed to retrieve track jets");
540 
541 
542  for (auto index : currentSystematic.goodTrackJets()) {
543  event.m_trackJets.push_back(calibratedJetsTDS->at(index));
544  }
545 
546  //shallow copies aren't sorted!
547  //sort only the selected jets (faster)
548  event.m_trackJets.sort(top::descendingPtSorter);
549  }
550 
551  if (m_config->useTracks()) {
552 
554  const xAOD::TrackParticleContainer* calibratedTracks(nullptr);
555  top::check(evtStore()->retrieve(calibratedTracks, m_config->sgKeyTracks(hash)), "Failed to retrieve tracks");
556 
558  if (!evtStore()->contains<xAOD::TrackParticleContainer>(m_config->sgKeyTracksTDS(hash))) {
559 
560  std::pair< xAOD::TrackParticleContainer*, xAOD::ShallowAuxContainer* > shallow_tracks = xAOD::shallowCopyContainer(*calibratedTracks);
561 
562  StatusCode save = evtStore()->tds()->record(shallow_tracks.first, m_config->sgKeyTracksTDS(hash));
563  StatusCode saveAux =
564  evtStore()->tds()->record(shallow_tracks.second, m_config->sgKeyTracksTDSAux(hash));
565  top::check((save && saveAux), "Failed to store object in TStore");
566  }
567 
569  xAOD::TrackParticleContainer* calibratedTracksTDS(nullptr);
570  top::check(evtStore()->retrieve(calibratedTracksTDS, m_config->sgKeyTracksTDS(hash)), "Failed to retrieve tracks");
571 
572  for (auto index : currentSystematic.goodTracks()) {
573  event.m_tracks.push_back(calibratedTracksTDS->at(index));
574  }
575 
576  //shallow copies aren't sorted!
577  //sort only the selected tracks (faster)
578  event.m_tracks.sort(top::descendingPtSorter);
579 
580  }
581 
582 
583  //met
584  const xAOD::MissingETContainer* mets(nullptr);
585  if (!currentSystematic.isLooseEvent()) {
586  top::check(evtStore()->retrieve(mets, m_config->sgKeyMissingEt(hash)), "Failed to retrieve MET");
587  }
588  if (currentSystematic.isLooseEvent()) {
589  top::check(evtStore()->retrieve(mets, m_config->sgKeyMissingEtLoose(hash)), "Failed to retrieve MET");
590  }
591  event.m_met = (*mets)["FinalTrk"]; // MissingETBase::Source::total()];
592 
593  //MC
594  if (m_config->isMC()) {
595  // Truth particles (these are BIG)
596  if (m_config->useTruthParticles()) {
597  top::check(evtStore()->retrieve(event.m_truth,
598  m_config->sgKeyMCParticle()), "Failed to retrieve truth particles");
599  }
600 
601  // Truth Event
603  bool hasTruthEvent = evtStore()->retrieve(event.m_truthEvent, m_config->sgKeyTruthEvent());
604  if (!hasTruthEvent) {
605  ATH_MSG_WARNING("Failed to retrieve truth Event. TopEvent::m_truthEvent will be nullptr!");
607  }
608  }
609 
610  // Parton History
611  if (m_config->doTopPartonHistory()) {
612  if (evtStore()->contains<xAOD::PartonHistoryContainer>(m_config->sgKeyTopPartonHistory())) {
613  const xAOD::PartonHistoryContainer* partonHistory(nullptr);
614  top::check(evtStore()->retrieve(partonHistory,
615  m_config->sgKeyTopPartonHistory()), "Failed to retrieve Top Parton History");
616  if (partonHistory->size() == 1) {
617  event.m_partonHistory = partonHistory->at(0);
618  }
619  }
620  } // end doTopPartonHistory
621  } // end isMC
622 
624 
625  return event;
626  }
627 
629  {
630  if(m_config->useSoftMuons()) decorateTopEventSoftMuons(event);
631  }
632 
634  {
635  if(!m_config->useJets()) return;
636 
637  //first we initialize decorations for all jets
638  for(const xAOD::Jet* jet : event.m_jets)
639  {
640  jet->auxdecor<int>("AT_SoftMuonIndex")=-1;
641  jet->auxdecor<float>("AT_SoftMuonDR")=-1;
642  }
643 
644  int imuon=0;
645  for(const xAOD::Muon* sm : event.m_softmuons)
646  {
647  //writing auxiliary info for SMT jet tagging
648  double dRmin=100.;
649  int nearestJetIndex=-1;
650  int ijet=0;
651  for(const xAOD::Jet *jet : event.m_jets)
652  {
653  double dr= xAOD::P4Helpers::deltaR(sm,jet,m_config->softmuonDRJetcutUseRapidity());
654  if(dr<dRmin && dr<m_config->softmuonDRJetcut())
655  {
656  dRmin=dr;
657  nearestJetIndex=ijet;
658  }
659  ijet++;
660  }
661  sm->auxdecor<int>("AT_SMTJetIndex")=nearestJetIndex;
662  sm->auxdecor<float>("AT_SMTJetDR")=dRmin;
663 
664  if(nearestJetIndex>=0)
665  {
666  const xAOD::Jet *jet = event.m_jets[nearestJetIndex];
667  if(jet->auxdecor<int>("AT_SoftMuonIndex")<0) //in this way we only associate a jet with the highest pt soft muon
668  {
669  jet->auxdecor<int>("AT_SoftMuonIndex")=imuon;
670  jet->auxdecor<float>("AT_SoftMuonDR")=dRmin;
671  }
672  }//end of case where we found a jet nearby
673 
674  imuon++;
675  }//end of loop on muons
676 
677  }//end of TopEventMaker::decorateTopEvent
678 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ShallowCopy.h
xAOD::SystematicEvent::goodTaus
const std::vector< unsigned int > & goodTaus() const
get Taus
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
xAOD::SystematicEvent::goodMuons
const std::vector< unsigned int > & goodMuons() const
get Muons
top::TopEventMaker::m_VarRC
std::map< std::string, std::unique_ptr< RCJet > > m_VarRC
Definition: TopEventMaker.h:71
xAOD::SystematicEvent::goodPhotons
const std::vector< unsigned int > & goodPhotons() const
get Photons
top::TopEventMaker::decorateTopEventSoftMuons
void decorateTopEventSoftMuons(top::Event &event)
Definition: TopEventMaker.cxx:633
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
top::TopEventMaker::s_hasTruthEvent
static bool s_hasTruthEvent
Definition: TopEventMaker.h:75
xAOD::SystematicEvent::goodJets
const std::vector< unsigned int > & goodJets() const
get Jets
top::TopEventMaker::m_VarRCJetRho
std::vector< std::string > m_VarRCJetRho
Definition: TopEventMaker.h:72
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
index
Definition: index.py:1
xAODP4Helpers.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
top::TopEventMaker::makeTopEvent
top::Event makeTopEvent(const xAOD::SystematicEvent *currentSystematic)
Make a top::Event from a xAOD::SystematicEvent.
Definition: TopEventMaker.cxx:80
xAOD::ShallowAuxContainer
Class creating a shallow copy of an existing auxiliary container.
Definition: ShallowAuxContainer.h:54
asg
Definition: DataHandleTestTool.h:28
top::TopEventMaker::TopEventMaker
TopEventMaker(const std::string &name)
Definition: TopEventMaker.cxx:34
RCJet
Definition: RCJet.h:55
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:112
x
#define x
top::TopEventMaker::m_rc
std::unique_ptr< RCJet > m_rc
Definition: TopEventMaker.h:70
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
SG::AuxElement::auxdecor
Decorator< T, ALLOC >::reference_type auxdecor(const std::string &name) const
Fetch an aux decoration, as a non-const reference.
TauJetAuxContainer.h
EventTools.h
A few functions for doing operations on particles / events. Currently holds code for dR,...
top::TopEventMaker::m_VarRCJetMassScale
std::vector< std::string > m_VarRCJetMassScale
Definition: TopEventMaker.h:73
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
MuonAuxContainer.h
SG::AuxElement::auxdataConst
Accessor< T, ALLOC >::const_reference_type auxdataConst(const std::string &name) const
Fetch an aux data variable, as a const reference.
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::TopEventMaker::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: TopEventMaker.cxx:40
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
PartonHistory.h
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
ElectronContainer.h
ElectronAuxContainer.h
xAOD::P4Helpers::deltaR
double deltaR(double rapidity1, double phi1, double rapidity2, double phi2)
from bare bare rapidity,phi
Definition: xAODP4Helpers.h:150
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
top::TopEventMaker::m_config
std::shared_ptr< top::TopConfig > m_config
Definition: TopEventMaker.h:69
top::TopEventMaker::decorateTopEvent
void decorateTopEvent(top::Event &event)
Definition: TopEventMaker.cxx:628
top::check
void check(bool thingToCheck, const std::string &usefulFailureMessage)
Print an error message and terminate if thingToCheck is false.
Definition: EventTools.cxx:15
TopEventMaker.h
xAOD::SystematicEvent::hashValue
std::size_t hashValue() const
get hash value
TauJetContainer.h
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAOD::SystematicEvent::isLooseEvent
char isLooseEvent() const
get isLooseEvent
xAOD::SystematicEvent::goodTracks
const std::vector< unsigned int > & goodTracks() const
get Tracks
xAOD::MissingETContainer_v1
Container for xAOD::MissingET_v1 objects.
Definition: MissingETContainer_v1.h:21
SG::AuxElement::isAvailable
bool isAvailable(const std::string &name, const std::string &clsname="") const
Check if an aux variable is available for reading.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
xAOD::SystematicEvent::ttreeIndex
unsigned int ttreeIndex() const
get ttreeIndex
TopConfig.h
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
MuonContainer.h
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
PhotonAuxContainer.h
xAOD::SystematicEvent::goodLargeRJets
const std::vector< unsigned int > & goodLargeRJets() const
get LargeRJets
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
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::SystematicEvent::goodFwdElectrons
const std::vector< unsigned int > & goodFwdElectrons() const
get FWD Electrons
xAOD::SystematicEvent::goodElectrons
const std::vector< unsigned int > & goodElectrons() const
get Electrons
xAOD::SystematicEvent::goodTrackJets
const std::vector< unsigned int > & goodTrackJets() const
get TrackJets
JetAuxContainer.h
top::Event
Very simple class to hold event data after reading from a file.
Definition: Event.h:49
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
test_pyathena.counter
counter
Definition: test_pyathena.py:15
top::TopEventMaker::systematicEvents
const xAOD::SystematicEventContainer * systematicEvents(const std::string &sgKey) const
As top-xaod isn't an asg::AsgTool, it doesn't have access to all the information Very annoying.
Definition: TopEventMaker.cxx:73
top::descendingPtSorter
bool descendingPtSorter(const xAOD::IParticle *p1, const xAOD::IParticle *p2)
Used when sorting the e, mu, jet, tau containers after CP corrections.
Definition: EventTools.cxx:56
top::calculateBootstrapWeights
std::vector< int > calculateBootstrapWeights(int nreplicas, int eventNumber, int mcChannelNumber)
Function used to create poisson weights (mean of 1) for bootstrapping.
Definition: EventTools.cxx:60
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
PhotonContainer.h
MissingETContainer.h
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
fitman.rho
rho
Definition: fitman.py:532
xAOD::SystematicEvent::goodSoftMuons
const std::vector< unsigned int > & goodSoftMuons() const
get Soft Muons