ATLAS Offline Software
Loading...
Searching...
No Matches
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"
12
14
15#include "GaudiKernel/NTuple.h"
16#include "GaudiKernel/INTupleSvc.h"
17#include "GaudiKernel/SmartDataPtr.h"
18
19AODReader::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}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
static Double_t sc
INTupleSvc * ntupleSvc()
NTuple::Item< float > m_truth_pz
Definition AODReader.h:47
NTuple::Item< float > m_e237
Definition AODReader.h:31
NTuple::Item< float > m_et
Definition AODReader.h:40
NTuple::Item< float > m_eta
Definition AODReader.h:29
NTuple::Item< float > m_weta1
Definition AODReader.h:33
NTuple::Item< float > m_f1
Definition AODReader.h:38
NTuple::Item< float > m_truth_px
Definition AODReader.h:45
NTuple::Item< float > m_truth_energy
Definition AODReader.h:44
NTuple::Item< float > m_e277
Definition AODReader.h:32
NTuple::Item< float > m_wtots1
Definition AODReader.h:37
virtual ~AODReader()
Definition AODReader.cxx:26
NTuple::Item< float > m_truth_py
Definition AODReader.h:46
NTuple::Item< float > m_weta2
Definition AODReader.h:34
NTuple::Item< float > m_emins1
Definition AODReader.h:42
NTuple::Item< float > m_f1core
Definition AODReader.h:39
NTuple::Tuple * m_nt
Definition AODReader.h:27
AODReader(const std::string &name, ISvcLocator *pSvcLocator)
Definition AODReader.cxx:19
virtual StatusCode execute()
NTuple::Item< float > m_energy
Definition AODReader.h:28
NTuple::Item< float > m_fracs1
Definition AODReader.h:36
NTuple::Item< float > m_ethad1
Definition AODReader.h:41
virtual StatusCode finalize()
Definition AODReader.cxx:99
NTuple::Item< float > m_pt
Definition AODReader.h:30
NTuple::Item< float > m_e2tsts1
Definition AODReader.h:35
virtual StatusCode initialize()
Definition AODReader.cxx:28
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
MsgStream & msg() const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
EM shower property class data class.
Definition EMShower.h:24
double f1core() const
E1(3x1)/E = fraction of the energy reconstructed in the first longitudinal compartment of the electro...
double weta1() const
shower width using +/-3 strips around the one with the maximal energy deposit: w3 strips = sqrt{sum(E...
double ethad1() const
transverse energy in the first sampling of the hadronic calorimeters behind the cluster calculated fr...
double e237() const
uncalibrated energy (sum of cells) of the middle sampling in a rectangle of size 3x7
double e277() const
uncalibrated energy (sum of cells) of the middle sampling in a rectangle of size 7x7
double fracs1() const
shower shape in the shower core : [E(+/-3)-E(+/-1)]/E(+/-1), where E(+/-n) is the energy in +- n stri...
double weta2() const
the lateral width is calculated with a window of 3x5 cells using the energy weighted sum over all cel...
double e2tsts1() const
energy of the cell corresponding to second energy maximum in the first sampling
double emins1() const
energy reconstructed in the strip with the minimal value between the first and second maximum
double wtots1() const
shower width is determined in a window detaxdphi = 0,0625 x~0,2, corresponding typically to 20 strips...
double f1() const
E1/E = fraction of energy reconstructed in the first sampling, where E1 is energy in all strips belon...
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
virtual double et() const
transverse energy defined to be e*sin(theta)
virtual double e() const
energy
virtual double pt() const
transverse momentum
virtual double eta() const
pseudo rapidity
const T * detail(const std::string &name="", unsigned int index=0) const
retrieve eg-detail objects:
Definition egamma.h:318
const CaloCluster * cluster() const
pointer to CaloCluster
Definition egamma.cxx:360
GenEvent::particle_iterator begin(HepMC::GenEvent &e)
Definition GenEvent.h:622
const GenParticle * ConstGenParticlePtr
Definition GenParticle.h:38