ATLAS Offline Software
TElectronTestAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
9 //
12 //
13 #include "xAODEgamma/Electron.h"
14 //
15 #include <cmath>
16 #include <optional>
17 
19 
20  // input
22 
23  // Decorations
24  m_pimpl = std::make_unique<Root::TElectronEfficiencyCorrectionTool>(
25  (this->name() + ".TElectronEfficiencyCorrection").c_str());
26  //
27  m_pimpl->msg().setLevel(this->msg().level());
28  //
29  std::string mapFileName = PathResolverFindCalibFile(m_mapFile);
32  std::string value = ElRecomFileHelpers::getValueByKey(mapFileName, key);
34  if (filename.empty()) {
35  ATH_MSG_ERROR("Could NOT resolve file name " << value);
36  return StatusCode::FAILURE;
37  } else {
38  ATH_MSG_INFO(" Using recommendations file = " << filename);
39  }
40  m_pimpl->addFileName(filename);
41  //
42  if (m_mode == Toys || m_mode == All) {
43  m_pimpl->bookCombToyMCScaleFactors(m_number_of_toys);
44  }
45  // We use 0 as failure ...
46  if (m_pimpl->initialize() == 0) {
48  "Could not initialize the TElectronEfficiencyCorrectionTool!");
49  return StatusCode::FAILURE;
50  }
51 
52  // Auxiliary info
53  m_numberCorr = m_pimpl->getNSyst();
54  std::map<float, std::vector<float>> tmp;
55  m_pimpl->getNbins(tmp);
56  m_lowestEt = tmp.begin()->first;
57  m_doDetail = (m_mode != Toys && m_mode != Total);
58  m_doToys = (m_mode == Toys || m_mode == All);
59 
60  // decorations if requested
61  const std::string baseName = m_electronContainer.key();
62  m_SF = baseName + ".EFF_" + key + "_SF";
63  m_TotalUp = baseName + ".EFF_" + key + "_Total__Up";
64  m_TotalDown = baseName + ".EFF_" + key + "_Total__Down";
65  m_uncorrUp = baseName + ".EFF_" + key + "_UnCorr__Up";
66  m_uncorrDown = baseName + ".EFF_" + key + "_UnCorr__Down";
67  m_HistIndex = baseName + ".EFF_" + key + "_HistIndex";
68  m_HistBin = baseName + ".EFF_" + key + "_HistBin";
69  m_corrUp = baseName + ".EFF_" + key + "_Corr__Up";
70  m_corrDown = baseName + ".EFF_" + key + "_Corr__Down";
71  m_toys = baseName + ".EFF_" + key + "__toys";
72 
83 
84  return StatusCode::SUCCESS;
85 }
86 
87 StatusCode CP::TElectronTestAlg::execute(const EventContext& ctx) const {
88 
89  //
90  unsigned int runNumber = 428648; // use a dummy default for testing
91 
92  int dataType = m_dataType;
93  //
94  SG::ReadHandle<xAOD::ElectronContainer> electrons{m_electronContainer, ctx};
95 
96  std::optional<SG::WriteDecorHandle<xAOD::ElectronContainer, double>> SF;
97  std::optional<SG::WriteDecorHandle<xAOD::ElectronContainer, double>> TotalUp;
98  std::optional<SG::WriteDecorHandle<xAOD::ElectronContainer, double>>
99  TotalDown;
100  std::optional<SG::WriteDecorHandle<xAOD::ElectronContainer, double>> uncorrUp;
101  std::optional<SG::WriteDecorHandle<xAOD::ElectronContainer, double>>
102  uncorrDown;
103  std::optional<SG::WriteDecorHandle<xAOD::ElectronContainer, int>> HistIndex;
104  std::optional<SG::WriteDecorHandle<xAOD::ElectronContainer, int>> HistBin;
105  std::optional<
107  corrUp;
108  std::optional<
110  corrDown;
111  std::optional<
113  toys;
114 
115  if (m_decorate) {
116  SF.emplace(m_SF, ctx);
117  TotalUp.emplace(m_TotalUp, ctx);
118  TotalDown.emplace(m_TotalDown, ctx);
119  if (m_doDetail) {
120  uncorrUp.emplace(m_uncorrUp, ctx);
121  uncorrDown.emplace(m_uncorrDown, ctx);
122  HistIndex.emplace(m_HistIndex, ctx);
123  HistBin.emplace(m_HistBin, ctx);
124  corrUp.emplace(m_corrUp, ctx);
125  corrDown.emplace(m_corrDown, ctx);
126  }
127  if (m_doToys) {
128  toys.emplace(m_toys, ctx);
129  }
130  }
131 
132  for (const xAOD::Electron* el : *electrons) {
133 
135 
136  // In case we fail
137  if (std::abs(el->eta()) > 2.469 || el->pt() < 10000) {
138  // if we decorate we need to set everything to dummy
139  // avoid decorating partially the collection ...
140  if (m_decorate) {
141  SF.value()(*el) = result.SF;
142  TotalUp.value()(*el) = result.SF + result.Total;
143  TotalDown.value()(*el) = result.SF - result.Total;
144  if (m_doDetail) {
145  uncorrUp.value()(*el) = result.SF + result.UnCorr;
146  uncorrDown.value()(*el) = result.SF - result.UnCorr;
147  HistIndex.value()(*el) = result.histIndex;
148  HistBin.value()(*el) = result.histBinNum;
149  corrUp.value()(*el) = result.Corr;
150  corrDown.value()(*el) = result.Corr;
151  }
152  if (m_doToys) {
153  toys.value()(*el) = result.toys;
154  }
155  }
156  continue;
157  }
158 
159  // Some logic for validity
160  double cluster_eta(-9999.9);
161  const xAOD::CaloCluster* cluster = el->caloCluster();
162  if (!cluster) {
163  ATH_MSG_ERROR("ERROR no cluster associated to the Electron \n");
164  return StatusCode::FAILURE;
165  }
166  // we need to use different variables for central and forward electrons
167  static const SG::AuxElement::ConstAccessor<uint16_t> accAuthor("author");
168  if (accAuthor.isAvailable(*el) &&
170  cluster_eta = cluster->eta();
171  } else {
172  cluster_eta = cluster->etaBE(2);
173  }
174 
175  // use et from cluster because it is immutable under syst variations of
176  // electron energy scale
177  const double energy = cluster->e();
178  const double parEta = el->eta();
179  const double coshEta = std::cosh(parEta);
180  double et = (coshEta != 0.) ? energy / coshEta : 0.;
181  // allow for a 5% margin at the lowest pT bin boundary
182  if (et < m_lowestEt) {
183  et = et * 1.05;
184  }
185 
186  // do the calculations
187  const int status = m_pimpl->calculate(
189  cluster_eta, et, /* in MeV */
190  result, (m_mode == Total) /* do work only for Total*/);
191  if (!status) {
192  ATH_MSG_ERROR("Something went wrong in the calculation");
193  return StatusCode::FAILURE;
194  }
195 
196  // print outs
197  ATH_MSG_INFO("--------------------------------------------");
198  ATH_MSG_INFO("Electron pt : " << el->pt() << " eta " << el->eta());
199  ATH_MSG_INFO("SF = " << result.SF << " +- " << result.Total);
200  if (m_doDetail) {
201  ATH_MSG_INFO("SF = " << result.SF << " +- " << result.UnCorr
202  << " stat only ");
203  ATH_MSG_INFO("At histo " << result.histIndex << " at bin "
204  << result.histBinNum);
205  ATH_MSG_INFO("Num correlated " << result.Corr.size());
206  for (double res : result.Corr) {
207  ATH_MSG_INFO("+- " << res);
208  }
209  }
210  if (m_doToys) {
211  ATH_MSG_INFO("Run " << result.toys.size() << " Toys ");
212  for (double res : result.toys) {
213  ATH_MSG_INFO("+- " << res);
214  }
215  }
216  if (m_decorate) {
217  SF.value()(*el) = result.SF;
218  TotalUp.value()(*el) = result.SF + result.Total;
219  TotalDown.value()(*el) = result.SF - result.Total;
220  if (m_doDetail) {
221  uncorrUp.value()(*el) = result.SF + result.UnCorr;
222  uncorrDown.value()(*el) = result.SF - result.UnCorr;
223  HistIndex.value()(*el) = result.histIndex;
224  HistBin.value()(*el) = result.histBinNum;
225  const size_t corrsize = result.Corr.size();
226  std::vector<double> up(corrsize, 0);
227  std::vector<double> down(corrsize, 0);
228  for (size_t i = 0; i < corrsize; ++i) {
229  up[i] = result.SF + result.Corr[i];
230  down[i] = result.SF - result.Corr[i];
231  }
232  corrUp.value()(*el) = std::move(up);
233  corrDown.value()(*el) = std::move(down);
234  }
235  if (m_doToys) {
236  toys.value()(*el) = std::move(result.toys);
237  }
238  }
239 
240  } // end of loop over electrons
241  return StatusCode::SUCCESS;
242 }
243 
et
Extra patterns decribing particle interation process.
CP::TElectronTestAlg::m_TotalUp
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_TotalUp
Definition: TElectronTestAlg.h:74
get_generator_info.result
result
Definition: get_generator_info.py:21
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::et
et
Definition: TrigEMCluster_v1.cxx:25
CP::TElectronTestAlg::m_TotalDown
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_TotalDown
Definition: TElectronTestAlg.h:76
CP::TElectronTestAlg::m_corrUp
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_corrUp
Definition: TElectronTestAlg.h:86
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
CP::TElectronTestAlg::m_doToys
bool m_doToys
Definition: TElectronTestAlg.h:34
ElRecomFileHelpers.h
TRT_PAI_gasdata::SF
const float SF[NF]
Cross sections for Fluor.
Definition: TRT_PAI_gasdata.h:285
CP::TElectronTestAlg::m_uncorrDown
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_uncorrDown
Definition: TElectronTestAlg.h:80
downloadSingle.dataType
string dataType
Definition: downloadSingle.py:18
CP::TElectronTestAlg::m_doDetail
bool m_doDetail
Definition: TElectronTestAlg.h:33
athena.value
value
Definition: athena.py:124
CP::TElectronTestAlg::m_electronContainer
SG::ReadHandleKey< xAOD::ElectronContainer > m_electronContainer
Input collection name.
Definition: TElectronTestAlg.h:41
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
CP::TElectronTestAlg::m_uncorrUp
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_uncorrUp
Definition: TElectronTestAlg.h:78
xAOD::EgammaParameters::AuthorFwdElectron
const uint16_t AuthorFwdElectron
Electron reconstructed by the Forward cluster-based algorithm.
Definition: EgammaDefs.h:30
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
CP::TElectronTestAlg::m_HistIndex
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_HistIndex
Definition: TElectronTestAlg.h:82
CP::TElectronTestAlg::m_mapFile
Gaudi::Property< std::string > m_mapFile
Label for the collection.
Definition: TElectronTestAlg.h:45
CP::TElectronTestAlg::m_HistBin
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_HistBin
Definition: TElectronTestAlg.h:84
PATCore::ParticleDataType::DataType
DataType
Definition: PATCoreEnums.h:22
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
Analysis::Total
@ Total
Definition: CalibrationDataInterfaceROOT.h:70
xAOD::CaloCluster_v1::etaBE
float etaBE(const unsigned layer) const
Get the eta in one layer of the EM Calo.
Definition: CaloCluster_v1.cxx:644
Root::TElectronEfficiencyCorrectionTool::Result
Definition: TElectronEfficiencyCorrectionTool.h:42
CP::TElectronTestAlg::m_isoKey
Gaudi::Property< std::string > m_isoKey
Definition: TElectronTestAlg.h:55
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
xAOD::CaloCluster_v1::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
Definition: CaloCluster_v1.cxx:251
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
CP::TElectronTestAlg::m_toys
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_toys
Definition: TElectronTestAlg.h:90
CalibCoolCompareRT.up
up
Definition: CalibCoolCompareRT.py:109
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
CP::TElectronTestAlg::m_idKey
Gaudi::Property< std::string > m_idKey
Definition: TElectronTestAlg.h:52
CP::TElectronTestAlg::All
@ All
Definition: TElectronTestAlg.h:65
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
WriteDecorHandle.h
Handle class for adding a decoration to an object.
CP::TElectronTestAlg::m_numberCorr
int m_numberCorr
Definition: TElectronTestAlg.h:35
CP::TElectronTestAlg::initialize
virtual StatusCode initialize() override final
Definition: TElectronTestAlg.cxx:18
CP::TElectronTestAlg::m_mode
Gaudi::Property< int > m_mode
Definition: TElectronTestAlg.h:66
PathResolver.h
CP::TElectronTestAlg::Toys
@ Toys
Definition: TElectronTestAlg.h:65
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
CP::TElectronTestAlg::m_SF
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_SF
Definition: TElectronTestAlg.h:72
ReadHandle.h
Handle class for reading from StoreGate.
CP::TElectronTestAlg::m_corrDown
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_corrDown
Definition: TElectronTestAlg.h:88
CP::TElectronTestAlg::m_lowestEt
double m_lowestEt
Number of Correlated syst.
Definition: TElectronTestAlg.h:36
xAOD::Electron_v1
Definition: Electron_v1.h:34
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
CP::TElectronTestAlg::m_pimpl
std::unique_ptr< Root::TElectronEfficiencyCorrectionTool > m_pimpl
Lowest Et for the reccomendations.
Definition: TElectronTestAlg.h:39
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
ElRecomFileHelpers::convertToOneKey
std::string convertToOneKey(const std::string &recokey, const std::string &idkey, const std::string &isokey, const std::string &trigkey)
Definition: ElRecomFileHelpers.cxx:38
CP::TElectronTestAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: TElectronTestAlg.cxx:87
CP::TElectronTestAlg::Total
@ Total
Definition: TElectronTestAlg.h:65
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
CP::TElectronTestAlg::m_recoKey
Gaudi::Property< std::string > m_recoKey
Definition: TElectronTestAlg.h:50
CP::TElectronTestAlg::m_triggerKey
Gaudi::Property< std::string > m_triggerKey
Definition: TElectronTestAlg.h:58
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
CP::TElectronTestAlg::m_decorate
Gaudi::Property< bool > m_decorate
Definition: TElectronTestAlg.h:70
merge.status
status
Definition: merge.py:17
Electron.h
ElRecomFileHelpers::getValueByKey
std::string getValueByKey(const std::string &mapFile, const std::string &key)
Definition: ElRecomFileHelpers.cxx:75
CP::TElectronTestAlg::m_number_of_toys
Gaudi::Property< int > m_number_of_toys
Definition: TElectronTestAlg.h:67
TElectronTestAlg.h
xAOD::CaloCluster_v1::e
virtual double e() const
The total energy of the particle.
Definition: CaloCluster_v1.cxx:265
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37