ATLAS Offline Software
AODReader.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 #include "AODReader.h"
7 
8 #include "GaudiKernel/IToolSvc.h"
9 #include "egammaEvent/Electron.h"
11 #include "egammaEvent/EMShower.h"
12 
14 
15 #include "GaudiKernel/NTuple.h"
16 #include "GaudiKernel/INTupleSvc.h"
17 #include "GaudiKernel/SmartDataPtr.h"
18 
19 AODReader::AODReader (const std::string& name, ISvcLocator* pSvcLocator)
20  : AthAlgorithm(name, pSvcLocator),
21  m_nt(nullptr)
22 {
23 
24 }
25 
27 
29 {
30  msg(MSG::INFO) << "Initializing " << name() << endmsg;
31 
32 
33  msg(MSG::INFO) << "creating n tuple" << endmsg;
34  NTupleFilePtr file1(ntupleSvc(), "/NTUPLES/FILE");
35 
36  //Checking if the n tuple is already booked
37  NTuplePtr nt(ntupleSvc(),"/NTUPLES/FILE/AOD");
38 
39  if ( !nt ) { // Normally, this should always be true, but who knows...
40  nt = ntupleSvc()->book ("/NTUPLES/FILE/AOD", CLID_ColumnWiseTuple, "Readed info from aod container");
41 
42  if ( nt ) {
43  msg(MSG::INFO) << "booked ntuple " << endmsg;
44 
45  StatusCode sc = StatusCode::SUCCESS;
46 
47  sc = nt->addItem("eta" , this->m_eta);
48  if( sc.isFailure() ) msg(MSG::ERROR) << "Can not create ntuple entry for eta" << endmsg;
49  sc = nt->addItem("energy" , this->m_energy);
50  if( sc.isFailure() ) msg(MSG::ERROR) << "Can not create ntuple entry for erec" << endmsg;
51  sc = nt->addItem("pt" , this->m_pt);
52  if( sc.isFailure() ) msg(MSG::ERROR) << "Can not create ntuple entry for pt" << endmsg;
53  sc = nt->addItem("e237" , this->m_e237);
54  if( sc.isFailure() ) msg(MSG::ERROR) << "Can not create ntuple entry for e237" << endmsg;
55  sc = nt->addItem("e277" , this->m_e277);
56  if( sc.isFailure() ) msg(MSG::ERROR) << "Can not create ntuple entry for e277" << endmsg;
57  sc = nt->addItem("weta1" , this->m_weta1);
58  if( sc.isFailure() ) msg(MSG::ERROR) << "Can not create ntuple entry for weta1" << endmsg;
59  sc = nt->addItem("weta2" , this->m_weta2);
60  if( sc.isFailure() ) msg(MSG::ERROR) << "Can not create ntuple entry for weta2" << endmsg;
61  sc = nt->addItem("e2tsts1" , this->m_e2tsts1);
62  if( sc.isFailure() ) msg(MSG::ERROR) << "Can not create ntuple entry for e2tsts1" << endmsg;
63  sc = nt->addItem("emins1" , this->m_emins1);
64  if( sc.isFailure() ) msg(MSG::ERROR) << "Can not create ntuple entry for emins1" << endmsg;
65  sc = nt->addItem("fracs1" , this->m_fracs1);
66  if( sc.isFailure() ) msg(MSG::ERROR) << "Can not create ntuple entry for fracs1" << endmsg;
67  sc = nt->addItem("wtots1" , this->m_wtots1);
68  if( sc.isFailure() ) msg(MSG::ERROR) << "Can not create ntuple entry for wtots1" << endmsg;
69  sc = nt->addItem("f1" , this->m_f1);
70  if( sc.isFailure() ) msg(MSG::ERROR) << "Can not create ntuple entry for f1" << endmsg;
71  sc = nt->addItem("f1core" , this->m_f1core);
72  if( sc.isFailure() ) msg(MSG::ERROR) << "Can not create ntuple entry for f1core" << endmsg;
73  sc = nt->addItem("ethad1" , this->m_ethad1);
74  if( sc.isFailure() ) msg(MSG::ERROR) << "Can not create ntuple entry for ethad1" << endmsg;
75  sc = nt->addItem("et" , this->m_et);
76  if( sc.isFailure() ) msg(MSG::ERROR) << "Can not create ntuple entry for et" << endmsg;
77 
78  sc = nt->addItem("truth_energy" , this->m_truth_energy);
79  if( sc.isFailure() ) msg(MSG::ERROR) << "Can not create ntuple entry for egen" << endmsg;
80  sc = nt->addItem("truth_px" , this->m_truth_px);
81  if( sc.isFailure() ) msg(MSG::ERROR) << "Can not create ntuple entry for tr_px" << endmsg;
82  sc = nt->addItem("truth_py" , this->m_truth_py);
83  if( sc.isFailure() ) msg(MSG::ERROR) << "Can not create ntuple entry for tr_py" << endmsg;
84  sc = nt->addItem("truth_pz" , this->m_truth_pz);
85  if( sc.isFailure() ) msg(MSG::ERROR) << "Can not create ntuple entry for tr_pz" << endmsg;
86  }
87 
88  } else {
89  msg(MSG::ERROR) << "didn't manage to book ntuple" << endmsg;
90  return StatusCode::FAILURE;
91  }
92 
93 
94  m_nt = nt;
95 
96  return StatusCode::SUCCESS;
97 }
98 
100 {
101  msg(MSG::INFO) << "Finalised " << name() << endmsg;
102  return StatusCode::SUCCESS;
103 }
104 
106 {
107  StatusCode sc = StatusCode::SUCCESS;
108 
110  const ElectronContainer* elecTES = nullptr;
111  sc=evtStore()->retrieve( elecTES, "ElectronAODCollection");
112  if( sc.isFailure() || !elecTES ) {
113  msg(MSG::WARNING) << "No AOD electron container found in TDS" << endmsg;
114  return sc;
115  }
116  msg(MSG::INFO) << "ElectronContainer successfully retrieved" << endmsg;
117 
118  const McEventCollection * mcEvtColl = nullptr;
119 
120  if (( mcEvtColl = evtStore()->retrieve<const McEventCollection>() )) {
121  msg(MSG::INFO) << "TruthParticleContainer successfully retrieved" << endmsg;
122  } else {
123  msg(MSG::WARNING) << "Could not retrieve TruthParticleContainer" << endmsg;
124  }
125 
126  ElectronContainer::const_iterator elecItr = elecTES->begin();
127  ElectronContainer::const_iterator elecItrE = elecTES->end();
128 
129  HepMC::ConstGenParticlePtr trPart{nullptr};
130  if (mcEvtColl) {
131  McEventCollection::const_iterator mcTrPart = mcEvtColl->begin();
132  if (mcTrPart != mcEvtColl->end()) {
133  trPart = (*mcTrPart)->particles_size()?*HepMC::begin(**mcTrPart):nullptr;
134  if (!trPart) {
135  msg(MSG::WARNING) << "Not a single particle event. Truth information won't be available" << endmsg;
136  }
137  } else {
138  msg(MSG::WARNING) << "Empty TruthParticleContainer. Truth information won't be available" << endmsg;
139  }
140  }
141 
142  const Analysis::Electron * primElec = nullptr;
143 
144 
147  for (; elecItr != elecItrE; ++elecItr) {
148  if (((*elecItr)->author() & (8 + 1)) > 0) {
149  primElec = (*elecItr);
150 
151  const EMShower * emshower = primElec->detail<EMShower> ("egDetailAOD");
152  if (emshower) { //exist for non-forward electrons
153  m_e237 = emshower->e237();
154  m_e277 = emshower->e277();
155  m_weta1 = emshower->weta1();
156  m_weta2 = emshower->weta2();
157  m_e2tsts1 = emshower->e2tsts1();
158  m_emins1 = emshower->emins1();
159  m_fracs1 = emshower->fracs1();
160  m_wtots1 = emshower->wtots1();
161  m_f1 = emshower->f1();
162  m_f1core = emshower->f1core();
163  m_ethad1 = emshower->ethad1();
164  } else {
165  m_e237 = 0;
166  m_e277 = 0;
167  m_weta1 = 0;
168  m_weta2 = 0;
169  m_e2tsts1 = 0;
170  m_emins1 = 0;
171  m_fracs1 = 0;
172  m_wtots1 = 0;
173  m_f1 = 0;
174  m_f1core = 0;
175  m_ethad1 = 0;
176  m_et = 0;
177  }
178  if (primElec->cluster()) { // don't know if it's possible for this not to exist, but just in case
179  m_et = primElec->cluster()->et();
180  } else {
181  m_et = 0;
182  }
183  m_energy = primElec->e();
184  m_eta = primElec->eta();
185  m_pt = primElec->pt();
186  if (trPart) {
187  m_truth_energy = trPart->momentum().e();
188  m_truth_px = trPart->momentum().px();
189  m_truth_py = trPart->momentum().py();
190  m_truth_pz = trPart->momentum().pz();
191  } else {
192  m_truth_energy = 0;
193  m_truth_px = 0;
194  m_truth_py = 0;
195  m_truth_pz = 0;
196  }
197  // writing a record
198  ATH_CHECK(ntupleSvc()->writeRecord(m_nt));
199  msg(MSG::VERBOSE) << "n tuple entry writed" << endmsg;
200  }
201  }
202 
203  return StatusCode::SUCCESS;
204 }
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
ElectronContainer.h
ParticleImpl::pt
virtual double pt() const
transverse momentum
Definition: ParticleImpl.h:554
EMShower::e237
double e237() const
uncalibrated energy (sum of cells) of the middle sampling in a rectangle of size 3x7
AODReader::m_e2tsts1
NTuple::Item< float > m_e2tsts1
Definition: AODReader.h:35
AODReader::~AODReader
virtual ~AODReader()
Definition: AODReader.cxx:26
AODReader::finalize
virtual StatusCode finalize()
Definition: AODReader.cxx:99
AODReader::m_emins1
NTuple::Item< float > m_emins1
Definition: AODReader.h:42
Analysis::Electron
Definition: Reconstruction/egamma/egammaEvent/egammaEvent/Electron.h:20
AODReader::m_f1
NTuple::Item< float > m_f1
Definition: AODReader.h:38
EMShower::weta1
double weta1() const
shower width using +/-3 strips around the one with the maximal energy deposit: w3 strips = sqrt{sum(E...
AODReader::m_weta2
NTuple::Item< float > m_weta2
Definition: AODReader.h:34
AODReader.h
AODReader::m_e277
NTuple::Item< float > m_e277
Definition: AODReader.h:32
AODReader::m_truth_py
NTuple::Item< float > m_truth_py
Definition: AODReader.h:46
egamma::detail
const T * detail(const std::string &name="", unsigned int index=0) const
retrieve eg-detail objects:
Definition: egamma.h:318
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
EMShower
Definition: EMShower.h:24
ParticleImpl::e
virtual double e() const
energy
Definition: ParticleImpl.h:534
AODReader::m_e237
NTuple::Item< float > m_e237
Definition: AODReader.h:31
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
AODReader::execute
virtual StatusCode execute()
Definition: AODReader.cxx:105
McEventCollection.h
AODReader::m_ethad1
NTuple::Item< float > m_ethad1
Definition: AODReader.h:41
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
EMShower::e277
double e277() const
uncalibrated energy (sum of cells) of the middle sampling in a rectangle of size 7x7
EMShower::fracs1
double fracs1() const
shower shape in the shower core : [E(+/-3)-E(+/-1)]/E(+/-1), where E(+/-n) is the energy in +- n stri...
egamma::cluster
const CaloCluster * cluster() const
pointer to CaloCluster
Definition: egamma.cxx:360
AODReader::m_truth_pz
NTuple::Item< float > m_truth_pz
Definition: AODReader.h:47
AODReader::m_weta1
NTuple::Item< float > m_weta1
Definition: AODReader.h:33
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AODReader::m_energy
NTuple::Item< float > m_energy
Definition: AODReader.h:28
AODReader::m_eta
NTuple::Item< float > m_eta
Definition: AODReader.h:29
ParticleImpl::eta
virtual double eta() const
pseudo rapidity
Definition: ParticleImpl.h:514
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
EMShower::weta2
double weta2() const
the lateral width is calculated with a window of 3x5 cells using the energy weighted sum over all cel...
AODReader::m_et
NTuple::Item< float > m_et
Definition: AODReader.h:40
AthAlgorithm
Definition: AthAlgorithm.h:47
EMShower::e2tsts1
double e2tsts1() const
energy of the cell corresponding to second energy maximum in the first sampling
Electron.h
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
AODReader::m_pt
NTuple::Item< float > m_pt
Definition: AODReader.h:30
AODReader::m_fracs1
NTuple::Item< float > m_fracs1
Definition: AODReader.h:36
AODReader::m_f1core
NTuple::Item< float > m_f1core
Definition: AODReader.h:39
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
EMShower::wtots1
double wtots1() const
shower width is determined in a window detaxdphi = 0,0625 x~0,2, corresponding typically to 20 strips...
EMShower.h
EMShower::emins1
double emins1() const
energy reconstructed in the strip with the minimal value between the first and second maximum
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
EMShower::f1core
double f1core() const
E1(3x1)/E = fraction of the energy reconstructed in the first longitudinal compartment of the electro...
AODReader::m_nt
NTuple::Tuple * m_nt
Definition: AODReader.h:27
AODReader::m_wtots1
NTuple::Item< float > m_wtots1
Definition: AODReader.h:37
AODReader::m_truth_px
NTuple::Item< float > m_truth_px
Definition: AODReader.h:45
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
ElectronContainer
Definition: Reconstruction/egamma/egammaEvent/egammaEvent/ElectronContainer.h:32
HepMC::begin
GenEvent::particle_iterator begin(HepMC::GenEvent &e)
Definition: GenEvent.h:498
P4EEtaPhiMBase::et
virtual double et() const
transverse energy defined to be e*sin(theta)
Definition: P4EEtaPhiMBase.cxx:106
AODReader::m_truth_energy
NTuple::Item< float > m_truth_energy
Definition: AODReader.h:44
EMShower::ethad1
double ethad1() const
transverse energy in the first sampling of the hadronic calorimeters behind the cluster calculated fr...
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
beamspotnt.nt
def nt
Definition: bin/beamspotnt.py:1063
AODReader::AODReader
AODReader(const std::string &name, ISvcLocator *pSvcLocator)
Definition: AODReader.cxx:19
ntupleSvc
INTupleSvc * ntupleSvc()
Definition: ServiceAccessor.h:14
EMShower::f1
double f1() const
E1/E = fraction of energy reconstructed in the first sampling, where E1 is energy in all strips belon...
AODReader::initialize
virtual StatusCode initialize()
Definition: AODReader.cxx:28
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.