ATLAS Offline Software
Loading...
Searching...
No Matches
EgammaFactory.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifdef XAOD_STANDALONE
7
8#include <AthLinks/ElementLink.h>
12#include <xAODRootAccess/Init.h>
15
16#include <cassert>
17#include <cmath>
18#include <string>
19#include <vector>
20
22#include "xAODTracking/Vertex.h"
25
26void EgammaFactory::create_structure() {
27 ATH_MSG_DEBUG("Creating calo cluster container");
28 m_clusters = new xAOD::CaloClusterContainer();
29 m_clAux = new xAOD::CaloClusterAuxContainer();
30 m_clusters->setStore(m_clAux);
31 if (!m_store.record(m_clusters, "Clusters").isSuccess()) {
32 ATH_MSG_ERROR("Cannot create cluster collection");
33 }
34 if (!m_store.record(m_clAux, "ClustersAux.").isSuccess()) {
35 ATH_MSG_ERROR("Canno create cluster aux collection");
36 };
37
38 ATH_MSG_DEBUG("Creating vertex container");
39 m_vertexes = new xAOD::VertexContainer();
40 m_vxAux = new xAOD::VertexAuxContainer();
41 m_vertexes->setStore(m_vxAux);
42 if (!m_store.record(m_vertexes, "Vertexes").isSuccess()) {
43 ATH_MSG_ERROR("Cannot create vertex collection");
44 };
45 if (!m_store.record(m_vxAux, "VertexesAux.").isSuccess()) {
46 ATH_MSG_ERROR("Cannot create vertex aux collection");
47 };
48
49 ATH_MSG_DEBUG("Creating track container");
50 m_tracks = new xAOD::TrackParticleContainer();
51 m_tracksAux = new xAOD::TrackParticleAuxContainer();
52 m_tracks->setStore(m_tracksAux);
53 if (!m_store.record(m_tracks, "Tracks").isSuccess()) {
54 ATH_MSG_ERROR("Cannot create track collection");
55 };
56 if (!m_store.record(m_tracksAux, "TracksAux.").isSuccess()) {
57 ATH_MSG_ERROR("Cannot create track aux collection");
58 };
59
60 ATH_MSG_DEBUG("Creating photon container");
61 m_photons = new xAOD::PhotonContainer();
62 m_photonsAux = new xAOD::PhotonAuxContainer();
63 m_photons->setStore(m_photonsAux);
64 if (!m_store.record(m_photons, "Photons").isSuccess()) {
65 ATH_MSG_ERROR("Cannot create photon collection");
66 };
67 if (!m_store.record(m_photonsAux, "PhotonsAux.").isSuccess()) {
68 ATH_MSG_ERROR("Cannot create photon aux collection");
69 };
70
71 ATH_MSG_DEBUG("Creating electron container");
72 m_electrons = new xAOD::ElectronContainer();
73 m_electronsAux = new xAOD::ElectronAuxContainer();
74 m_electrons->setStore(m_electronsAux);
75 if (!m_store.record(m_electrons, "Electrons").isSuccess()) {
76 ATH_MSG_ERROR("Cannot create electron collection");
77 };
78 if (!m_store.record(m_electronsAux, "ElectronsAux.").isSuccess()) {
79 ATH_MSG_ERROR("Cannot create electron aux collection");
80 };
81}
82
83EgammaFactory::EgammaFactory() : asg::AsgMessaging("EgammaFactory") {
84 create_structure();
85
86 TFile* f = TFile::Open(
88 "ElectronPhotonFourMomentumCorrection/v8/average_layers.root")
89 .c_str(),
90 "READ");
91 if (not f) {
93 "cannot open file "
95 "ElectronPhotonFourMomentumCorrection/v8/average_layers.root")
96 .c_str());
97 } else {
98 m_fave.reset(f);
99 }
100 m_histos_electron = std::array<TProfile2D*, 4>{
101 static_cast<TProfile2D*>(m_fave->Get("histo_electron_ratio_Es0_true_E")),
102 static_cast<TProfile2D*>(m_fave->Get("histo_electron_ratio_Es1_true_E")),
103 static_cast<TProfile2D*>(m_fave->Get("histo_electron_ratio_Es2_true_E")),
104 static_cast<TProfile2D*>(m_fave->Get("histo_electron_ratio_Es3_true_E"))};
105 m_histos_conv = std::array<TProfile2D*, 4>{
106 static_cast<TProfile2D*>(m_fave->Get("histo_conv_ratio_Es0_true_E")),
107 static_cast<TProfile2D*>(m_fave->Get("histo_conv_ratio_Es1_true_E")),
108 static_cast<TProfile2D*>(m_fave->Get("histo_conv_ratio_Es2_true_E")),
109 static_cast<TProfile2D*>(m_fave->Get("histo_conv_ratio_Es3_true_E"))};
110 m_histos_unconv = std::array<TProfile2D*, 4>{
111 static_cast<TProfile2D*>(m_fave->Get("histo_unconv_ratio_Es0_true_E")),
112 static_cast<TProfile2D*>(m_fave->Get("histo_unconv_ratio_Es1_true_E")),
113 static_cast<TProfile2D*>(m_fave->Get("histo_unconv_ratio_Es2_true_E")),
114 static_cast<TProfile2D*>(m_fave->Get("histo_unconv_ratio_Es3_true_E"))};
115 m_histo_rconv = static_cast<TProfile2D*>(m_fave->Get("histo_conv_ph_Rconv"));
116 m_histo_zconv = static_cast<TProfile2D*>(m_fave->Get("histo_conv_ph_zconv"));
117}
118
119std::array<double, 4> EgammaFactory::get_layers_fraction(
120 const std::array<TProfile2D*, 4>& prof, double eta, double pt) const {
121 std::array<double, 4> result;
122 for (int i = 0; i != 4; ++i) {
123 TProfile2D* p = prof[i];
124 assert(p);
125 result[i] = p->GetBinContent(p->FindBin(pt, std::abs(eta)));
126 }
127 return result;
128}
129
130void EgammaFactory::clear() {
131 m_store.clear();
132 create_structure();
133}
134
135EgammaFactory::~EgammaFactory() {
136 m_store.clear();
137}
138
139xAOD::EventInfo* EgammaFactory::create_eventinfo(
140 bool simulation, int runnumber, int eventnumber,
141 int average_interaction_per_crossing) {
143 ei->makePrivateStore();
145 ei->setEventNumber(eventnumber);
146 ei->setEventTypeBitmask(simulation);
147 ei->setAverageInteractionsPerCrossing(average_interaction_per_crossing);
148 return ei;
149}
150
151xAOD::CaloCluster* EgammaFactory::create_cluster(float eta, float phi, float e0,
152 float e1, float e2, float e3,
153 float e) {
154 ATH_MSG_DEBUG("creating cluster");
155 // create cluster
156 xAOD::CaloCluster* cluster = new xAOD::CaloCluster();
157 cluster->makePrivateStore();
158
159 ATH_MSG_DEBUG("setting cluster properties");
160 // set cluster properties
161
162 {
163 // set eta, phi for all the layers (barrel / endcap)
164 const std::set<CaloSampling::CaloSample> samplings{
165 CaloSampling::PreSamplerB, CaloSampling::EMB1,
166 CaloSampling::EMB2, CaloSampling::EMB3,
167 CaloSampling::PreSamplerE, CaloSampling::EME1,
168 CaloSampling::EME2, CaloSampling::EME3};
169 unsigned sampling_pattern = 0;
170 for (auto sample : samplings) {
171 sampling_pattern |= 0x1U << sample;
172 }
173 ATH_MSG_DEBUG("setting sampling pattern");
174 cluster->setSamplingPattern(sampling_pattern);
175 ATH_MSG_DEBUG("nsamples = " << cluster->nSamples());
176 for (auto sample : samplings) {
177 ATH_MSG_DEBUG("setting eta sampling");
178 cluster->setEta(sample, eta);
179 cluster->setPhi(sample, phi);
180 }
181
182 ATH_MSG_DEBUG("setting energies sampling");
183
184 if (std::abs(eta) < 1.45) {
185 cluster->setEnergy(CaloSampling::PreSamplerB, e0);
186 cluster->setEnergy(CaloSampling::EMB1, e1);
187 cluster->setEnergy(CaloSampling::EMB2, e2);
188 cluster->setEnergy(CaloSampling::EMB3, e3);
189 } else {
190 cluster->setEnergy(CaloSampling::PreSamplerE, e0);
191 cluster->setEnergy(CaloSampling::EME1, e1);
192 cluster->setEnergy(CaloSampling::EME2, e2);
193 cluster->setEnergy(CaloSampling::EME3, e3);
194 }
195 ATH_MSG_DEBUG("setting energy cluster");
196 cluster->setE(e > 0 ? e : e0 + e1 + e2 + e3);
197 ATH_MSG_DEBUG("setting eta cluster");
198 cluster->setEta(eta);
199 ATH_MSG_DEBUG("setting phi cluster");
200 cluster->setPhi(phi);
201 ATH_MSG_DEBUG("decorate cluster for etaCalo, phiCalo");
202 static const SG::Decorator<float> etaCaloDecor("etaCalo");
203 static const SG::Decorator<float> phiCaloDecor("phiCalo");
204 etaCaloDecor(*cluster) = eta;
205 phiCaloDecor(*cluster) = phi;
206 // void insertMoment( MomentType type, double value );
209 }
210 ATH_MSG_DEBUG("pushing cluster collection");
211 m_clusters->push_back(cluster);
212 return cluster;
213}
214
215xAOD::Photon* EgammaFactory::create_unconverted_photon(float eta, float phi,
216 float e) {
217 return create_photon(eta, phi, e, 0., 0.);
218}
219
220xAOD::Photon* EgammaFactory::create_converted_photon(float eta, float phi,
221 float e) {
222 assert(m_histo_rconv);
223 assert(m_histo_zconv);
224 const int bin = m_histo_rconv->FindBin(e / cosh(eta), std::abs(eta));
225 if (m_histo_rconv->IsBinOverflow(bin)) {
226 return create_photon(eta, phi, e, 0, 0);
227 } else {
228 const double rconv = m_histo_rconv->GetBinContent(bin);
229 const double zconv = m_histo_zconv->GetBinContent(
230 m_histo_zconv->FindBin(e / cosh(eta), std::abs(eta)));
231 assert(rconv > 0);
232 return create_photon(eta, phi, e, rconv, zconv);
233 }
234}
235
236xAOD::Photon* EgammaFactory::create_photon(float eta, float phi, float e,
237 float rconv, float zconv) {
238 const bool isconv = (rconv > 0 and rconv < 800);
239 const auto l = get_layers_fraction(isconv ? m_histos_conv : m_histos_unconv,
240 eta, e / cosh(eta));
241 return create_photon(eta, phi, l[0] * e, l[1] * e, l[2] * e, l[3] * e, e,
242 rconv, zconv);
243}
244
245xAOD::Electron* EgammaFactory::create_electron(float eta, float phi, float e) {
246 const auto l = get_layers_fraction(m_histos_electron, eta, e / cosh(eta));
247 return create_electron(eta, phi, l[0] * e, l[1] * e, l[2] * e, l[3] * e, e);
248}
249
250xAOD::Photon* EgammaFactory::create_photon(float eta, float phi, float e0,
251 float e1, float e2, float e3,
252 float e, float rconv, float zconv) {
253 xAOD::CaloCluster* cluster = create_cluster(eta, phi, e0, e1, e2, e3, e);
254 // create Vertex
255 xAOD::Vertex* vertex = nullptr;
256 if (rconv > 0 and rconv < 800) {
257 ATH_MSG_DEBUG("creating vertex");
258 vertex = new xAOD::Vertex();
259 vertex->makePrivateStore();
260 vertex->setZ(zconv);
261 vertex->setX(rconv);
262 vertex->setY(0);
263 // decorate with pt1, pt2
264 SG::Decorator<float> pt1Decor("pt1");
265 SG::Decorator<float> pt2Decor("pt2");
266 pt1Decor(*vertex) = e / cosh(eta) * 0.7;
267 pt2Decor(*vertex) = e / cosh(eta) * 0.3;
268 m_vertexes->push_back(vertex);
269 }
270
271 ATH_MSG_DEBUG("creating photon");
272 xAOD::Photon* ph = new xAOD::Photon();
273 ph->makePrivateStore();
274 m_photons->push_back(ph);
275
276 ATH_MSG_DEBUG("link cluster to photon");
277 // set link to clusters
278 std::vector<ElementLink<xAOD::CaloClusterContainer>> links_clusters;
279 ATH_MSG_DEBUG("push back cluster = " << cluster);
280 links_clusters.push_back(
281 ElementLink<xAOD::CaloClusterContainer>(cluster, *m_clusters));
282 ATH_MSG_DEBUG("set link");
283 ph->setCaloClusterLinks(links_clusters);
284
285 // set link to vertex
286 if (vertex) {
287 ATH_MSG_DEBUG("link vertex to photon");
288 std::vector<ElementLink<xAOD::VertexContainer>> links_vertexes;
289 links_vertexes.push_back(
290 ElementLink<xAOD::VertexContainer>(vertex, *m_vertexes));
291 ph->setVertexLinks(links_vertexes);
292 } else {
293 ATH_MSG_DEBUG("not converted");
294 }
295
296 // set particle properties
297
298 ph->setEta(eta);
299 ph->setPhi(phi);
300 ph->setPt(e / cosh(eta));
301
302 return ph;
303}
304
305xAOD::Electron* EgammaFactory::create_electron(float eta, float phi, float e0,
306 float e1, float e2, float e3,
307 float e) {
308 ATH_MSG_DEBUG("creating cluster");
309 xAOD::CaloCluster* cluster = create_cluster(eta, phi, e0, e1, e2, e3, e);
310
311 ATH_MSG_DEBUG("creating track");
313 track->makePrivateStore();
314 track->setDefiningParameters(0., 0., phi, 2 * atan(exp(-eta)), 1.);
315 m_tracks->push_back(track);
316
317 ATH_MSG_DEBUG("creating electron");
319 el->makePrivateStore();
320 m_electrons->push_back(el);
321
322 ATH_MSG_DEBUG("link track to electron");
323 std::vector<ElementLink<xAOD::TrackParticleContainer>> links_tracks;
324 links_tracks.push_back(
325 ElementLink<xAOD::TrackParticleContainer>(track, *m_tracks));
326 el->setTrackParticleLinks(links_tracks);
327
328 ATH_MSG_DEBUG("link cluster to electron");
329 std::vector<ElementLink<xAOD::CaloClusterContainer>> links_clusters;
330 ATH_MSG_DEBUG("push back cluster = " << cluster);
331 links_clusters.push_back(
332 ElementLink<xAOD::CaloClusterContainer>(cluster, *m_clusters));
333 ATH_MSG_DEBUG("set link");
334 el->setCaloClusterLinks(links_clusters);
335
336 // set particle properties
337
338 el->setEta(eta);
339 el->setPhi(phi);
340 el->setPt(e / cosh(eta));
341
342 return el;
343}
344#endif
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
void makePrivateStore()
Create a new (empty) private store for this object.
bool setPhi(const CaloSample sampling, const float phi)
Set in a given sampling. Returns false if the sample isn't part of the cluster.
void insertMoment(MomentType type, double value)
bool setEta(const CaloSample sampling, const float eta)
Set in a given sampling. Returns false if the sample isn't part of the cluster.
bool setEnergy(const CaloSample sampling, const float e)
Set energy for a given sampling. Returns false if the sample isn't part of the cluster.
void setSamplingPattern(const unsigned sp, const bool clearSamplingVars=false)
Set sampling pattern (one bit per sampling.
@ ETACALOFRAME
Eta in the calo frame (for egamma)
@ PHICALOFRAME
Phi in the calo frame (for egamma)
unsigned nSamples() const
void setCaloClusterLinks(const CLELVec_t &links)
set Pointer to the xAOD::CaloCluster
void setEta(float eta)
set the eta
void setPhi(float phi)
set the phi
void setPt(float pt)
set the Pt
void setAverageInteractionsPerCrossing(float value)
Set average interactions per crossing for all BCIDs.
void setEventNumber(uint64_t value)
Set the current event's event number.
void setEventTypeBitmask(uint32_t value)
Set the event type bitmask.
void setRunNumber(uint32_t value)
Set the current event's run number.
void setVertexLinks(const VxELVec_t &links)
set Pointer to the xAOD::vertex/vertices that match the photon candidate
static std::vector< uint32_t > runnumber
Definition iLumiCalc.h:37
l
Printing final latex table to .tex output file.
PhotonAuxContainer_v3 PhotonAuxContainer
Definition of the current photon auxiliary container.
VertexAuxContainer_v1 VertexAuxContainer
Definition of the current jet auxiliary container.
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
EventInfo_v1 EventInfo
Definition of the latest event info version.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
Photon_v1 Photon
Definition of the current "egamma version".
TrackParticleAuxContainer_v5 TrackParticleAuxContainer
Definition of the current TrackParticle auxiliary container.
ElectronAuxContainer_v3 ElectronAuxContainer
Definition of the current electron auxiliary container.
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
Electron_v1 Electron
Definition of the current "egamma version".
CaloClusterAuxContainer_v2 CaloClusterAuxContainer
Define the latest version of the calorimeter cluster auxiliary container.