ATLAS Offline Software
CreateDummyEl.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 #include "CreateDummyEl.h"
6 // EDM include(s):
7 #include "xAODEgamma/Egamma.h"
15 
17 #include "AsgMessaging/MsgStream.h"
18 
19 namespace asg {
20 ANA_MSG_HEADER(CreateDummyEl)
21 ANA_MSG_SOURCE(CreateDummyEl, "")
22 }
23 
24 namespace {
25 
26 const std::set<CaloSampling::CaloSample> samplings{
30 };
31 
32 void
33 fill_cluster(xAOD::CaloCluster* cluster, float eta, float phi, float e)
34 {
35  unsigned sampling_pattern = 0;
36  for (auto sample : samplings) {
37  sampling_pattern |= 0x1U << sample;
38  }
39  cluster->setSamplingPattern(sampling_pattern);
40 
41  for (auto sample : samplings) {
42  cluster->setEta(sample, eta);
43  cluster->setPhi(sample, phi);
44  }
45 
46  if (std::abs(eta) < 1.45) {
47  cluster->setEnergy(CaloSampling::PreSamplerB, e / 4);
48  cluster->setEnergy(CaloSampling::EMB1, e / 4);
49  cluster->setEnergy(CaloSampling::EMB2, e / 4);
50  cluster->setEnergy(CaloSampling::EMB3, e / 4);
51  } else {
52  cluster->setEnergy(CaloSampling::PreSamplerE, e / 4);
53  cluster->setEnergy(CaloSampling::EME1, e / 4);
54  cluster->setEnergy(CaloSampling::EME2, e / 4);
55  cluster->setEnergy(CaloSampling::EME3, e / 4);
56  }
57  cluster->setE(e);
58  cluster->setEta(eta);
59  cluster->setPhi(phi);
60  cluster->auxdata<float>("etaCalo") = eta;
61  cluster->auxdata<float>("phiCalo") = phi;
64 }
65 }
66 /* This is a bit weird function at it "creates a dummy pseudo reconstruction
67  * sequence" The idea here is basically to record everything to the Store in the
68  * order reco would do. Then an analysis code should see the collections needed
69  */
71 getElectrons(const std::vector<std::pair<double, double>>& pt_eta,
72  int runNumber,
74 {
75  using namespace asg::CreateDummyEl;
76  ANA_CHECK_SET_TYPE(int);
77  setMsgLevel(MSG::INFO);
78  // This is what we will return back
79 
80  // create the EventInfo
81  std::unique_ptr<xAOD::EventInfo> eventInfo =
82  std::make_unique<xAOD::EventInfo>();
83  eventInfo->makePrivateStore();
84  eventInfo->setEventNumber(363636);
85  eventInfo->setRunNumber(runNumber);
86  static SG::AuxElement::Decorator<unsigned int> randomrunnumber(
87  "RandomRunNumber");
88  randomrunnumber(*eventInfo) = runNumber;
89  if (!store.record(std::move(eventInfo), "EventInfo").isSuccess()) {
90  ANA_MSG_ERROR("Could not record EventInfo");
91  return StatusCode::FAILURE;
92  }
93 
94  size_t numel = pt_eta.size();
95  // Create all clusters
96  std::unique_ptr<xAOD::CaloClusterContainer> clusters =
97  std::make_unique<xAOD::CaloClusterContainer>();
98  std::unique_ptr<xAOD::CaloClusterAuxContainer> clAux =
99  std::make_unique<xAOD::CaloClusterAuxContainer>();
100  clusters->setStore(clAux.get());
101  clusters->reserve(numel);
102  for (const auto& i : pt_eta) {
103  const double pt{ i.first };
104  const double eta{ i.second };
105  const double e{ pt * cosh(eta) };
106  xAOD::CaloCluster* cluster = new xAOD::CaloCluster();
107  clusters->push_back(cluster);
108  fill_cluster(cluster, eta, 0.0, e);
109  }
110 
111  if (!store.record(std::move(clusters), "MyClusters").isSuccess() ||
112  !store.record(std::move(clAux), "MyClustersAux.").isSuccess()) {
113  ANA_MSG_ERROR("Could not record clusters");
114  return StatusCode::FAILURE;
115  }
116  // Create all electrons one per cluster
117  std::vector<ElementLink<xAOD::CaloClusterContainer>> links{};
118  std::unique_ptr<xAOD::ElectronContainer> electrons =
119  std::make_unique<xAOD::ElectronContainer>();
120  std::unique_ptr<xAOD::ElectronAuxContainer> electronsAux =
121  std::make_unique<xAOD::ElectronAuxContainer>();
122  electrons->setStore(electronsAux.get());
123  electrons->reserve(numel);
124  for (const auto& i : pt_eta) {
125  const double pt{ i.first };
126  const double eta{ i.second };
128  electrons->push_back(el);
129  links.clear();
130  links.emplace_back("MyClusters", el->index());
131  el->setCaloClusterLinks(links);
132  el->setEta(eta);
133  el->setPhi(0.0);
134  el->setM(0.511);
135  el->setPt(pt);
136  }
137  if (!store.record(std::move(electrons), "MyElectrons").isSuccess() ||
138  !store.record(std::move(electronsAux), "MyElectronAux.").isSuccess()) {
139  ANA_MSG_ERROR("Could not record Electrons");
140  return StatusCode::FAILURE;
141  }
142 
143  return StatusCode::SUCCESS;
144 }
StoreGateSvc::record
StatusCode record(T *p2BRegistered, const TKEY &key)
Record an object with a key.
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
constants.EMB1
int EMB1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:53
xAOD::EventInfo_v1::setEventNumber
void setEventNumber(uint64_t value)
Set the current event's event number.
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
asg
Definition: DataHandleTestTool.h:28
test_pyathena.pt
pt
Definition: test_pyathena.py:11
xAOD::CaloCluster_v1::insertMoment
void insertMoment(MomentType type, double value)
Definition: CaloCluster_v1.cxx:754
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
xAOD::CaloCluster_v1::setSamplingPattern
void setSamplingPattern(const unsigned sp, const bool clearSamplingVars=false)
Set sampling pattern (one bit per sampling.
Definition: CaloCluster_v1.cxx:81
xAOD::CaloCluster_v1::setEnergy
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.
Definition: CaloCluster_v1.cxx:526
CaloClusterAuxContainer.h
xAOD::CaloCluster
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloCluster.h:19
Egamma.h
xAOD::CaloCluster_v1::setE
void setE(flt_t)
Definition: CaloCluster_v1.cxx:375
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
constants.EMB2
int EMB2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:54
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:58
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:100
ElectronContainer.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
CaloCluster.h
ElectronAuxContainer.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DMTest::links
links
Definition: CLinks_v1.cxx:22
MessageCheck.h
macros for messaging and checking status codes
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
constants.EME1
int EME1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:55
asg::ANA_MSG_HEADER
ANA_MSG_HEADER(msgSTT) ANA_MSG_SOURCE(msgSTT
ANA_MSG_SOURCE
#define ANA_MSG_SOURCE(NAME, TITLE)
the source code part of ANA_MSG_SOURCE
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:133
getElectrons
StatusCode getElectrons(const std::vector< std::pair< double, double >> &pt_eta, int runNumber, xAOD::TStore &store)
Definition: CreateDummyEl.cxx:71
CaloCell_ID_FCS::EME3
@ EME3
Definition: FastCaloSim_CaloCell_ID.h:26
SG::AuxElement::makePrivateStore
void makePrivateStore()
Create a new (empty) private store for this object.
Definition: AuxElement.cxx:172
xAOD::Electron_v1
Definition: Electron_v1.h:34
xAOD::CaloCluster_v1::PHICALOFRAME
@ PHICALOFRAME
Phi in the calo frame (for egamma)
Definition: CaloCluster_v1.h:188
EventInfo.h
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
xAOD::TStore
A relatively simple transient store for objects created in analysis.
Definition: TStore.h:44
CreateDummyEl.h
ANA_CHECK_SET_TYPE
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:314
xAOD::EventInfo_v1::setRunNumber
void setRunNumber(uint32_t value)
Set the current event's run number.
CaloCell_ID_FCS::PreSamplerE
@ PreSamplerE
Definition: FastCaloSim_CaloCell_ID.h:23
CaloCell_ID_FCS::PreSamplerB
@ PreSamplerB
Definition: FastCaloSim_CaloCell_ID.h:19
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
xAOD::IParticle::auxdata
T & auxdata(const std::string &name, const std::string &clsname="")
Fetch an aux data variable, as a non-const reference.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:96
CaloClusterContainer.h
xAOD::CaloCluster_v1::setPhi
bool setPhi(const CaloSample sampling, const float phi)
Set in a given sampling. Returns false if the sample isn't part of the cluster.
Definition: CaloCluster_v1.cxx:556
xAOD::CaloCluster_v1::setEta
bool setEta(const CaloSample sampling, const float eta)
Set in a given sampling. Returns false if the sample isn't part of the cluster.
Definition: CaloCluster_v1.cxx:541
xAOD::CaloCluster_v1::ETACALOFRAME
@ ETACALOFRAME
Eta in the calo frame (for egamma)
Definition: CaloCluster_v1.h:187
CaloCell_ID_FCS::EMB3
@ EMB3
Definition: FastCaloSim_CaloCell_ID.h:22
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
constants.EME2
int EME2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:56
MsgStream.h