19{
20
22
23
24 ATH_CHECK(m_electronContainer.initialize());
25
26
27 m_pimpl = std::make_unique<Root::TElectronEfficiencyCorrectionTool>(
28 (this->
name() +
".TElectronEfficiencyCorrection").c_str());
29
30 m_pimpl->msg().setLevel(this->
msg().
level());
31
34 m_isoKey, m_triggerKey);
39 return StatusCode::FAILURE;
40 } else {
41 ATH_MSG_INFO(
" Using recommendations file = " << filename);
42 }
43 m_pimpl->addFileName(filename);
44
45 if (m_mode == Toys || m_mode == All) {
46 m_pimpl->bookCombToyMCScaleFactors(m_number_of_toys);
47 }
48
49 if (m_pimpl->initialize() == 0) {
51 "Could not initialize the TElectronEfficiencyCorrectionTool!");
52 return StatusCode::FAILURE;
53 }
54
55
56 m_numberCorr = m_pimpl->getNSyst();
57 std::map<float, std::vector<float>>
tmp;
58 m_pimpl->getNbins(tmp);
59 m_lowestEt =
tmp.begin()->first;
60 m_doDetail = (m_mode != Toys && m_mode !=
Total);
61 m_doToys = (m_mode == Toys || m_mode ==
All);
62
63
64 const std::string baseName = m_electronContainer.key();
65 m_SF = baseName +
".EFF_" +
key +
"_SF";
66 m_TotalUp = baseName +
".EFF_" +
key +
"_Total__Up";
67 m_TotalDown = baseName +
".EFF_" +
key +
"_Total__Down";
68 m_uncorrUp = baseName +
".EFF_" +
key +
"_UnCorr__Up";
69 m_uncorrDown = baseName +
".EFF_" +
key +
"_UnCorr__Down";
70 m_HistIndex = baseName +
".EFF_" +
key +
"_HistIndex";
71 m_HistBin = baseName +
".EFF_" +
key +
"_HistBin";
72 m_corrUp = baseName +
".EFF_" +
key +
"_Corr__Up";
73 m_corrDown = baseName +
".EFF_" +
key +
"_Corr__Down";
74 m_toys = baseName +
".EFF_" +
key +
"__toys";
75
77 ATH_CHECK(m_TotalUp.initialize(m_decorate));
78 ATH_CHECK(m_TotalDown.initialize(m_decorate));
79 ATH_CHECK(m_uncorrUp.initialize(m_decorate && m_doDetail));
80 ATH_CHECK(m_uncorrDown.initialize(m_decorate && m_doDetail));
81 ATH_CHECK(m_HistIndex.initialize(m_decorate && m_doDetail));
82 ATH_CHECK(m_HistBin.initialize(m_decorate && m_doDetail));
83 ATH_CHECK(m_corrUp.initialize(m_decorate && m_doDetail));
84 ATH_CHECK(m_corrDown.initialize(m_decorate && m_doDetail));
85 ATH_CHECK(m_toys.initialize(m_decorate && m_doToys));
86
87 return StatusCode::SUCCESS;
88}
89
90StatusCode TElectronTestAlg::execute(
const EventContext& ctx)
const {
91
92
94
96
97 SG::ReadHandle<xAOD::ElectronContainer>
electrons{m_electronContainer, ctx};
98
99 std::optional<SG::WriteDecorHandle<xAOD::ElectronContainer, double>>
SF;
100 std::optional<SG::WriteDecorHandle<xAOD::ElectronContainer, double>> TotalUp;
101 std::optional<SG::WriteDecorHandle<xAOD::ElectronContainer, double>>
102 TotalDown;
103 std::optional<SG::WriteDecorHandle<xAOD::ElectronContainer, double>> uncorrUp;
104 std::optional<SG::WriteDecorHandle<xAOD::ElectronContainer, double>>
105 uncorrDown;
106 std::optional<SG::WriteDecorHandle<xAOD::ElectronContainer, int>> HistIndex;
107 std::optional<SG::WriteDecorHandle<xAOD::ElectronContainer, int>> HistBin;
108 std::optional<
109 SG::WriteDecorHandle<xAOD::ElectronContainer, std::vector<double>>>
110 corrUp;
111 std::optional<
112 SG::WriteDecorHandle<xAOD::ElectronContainer, std::vector<double>>>
113 corrDown;
114 std::optional<
115 SG::WriteDecorHandle<xAOD::ElectronContainer, std::vector<double>>>
116 toys;
117
118 if (m_decorate) {
119 SF.emplace(m_SF, ctx);
120 TotalUp.emplace(m_TotalUp, ctx);
121 TotalDown.emplace(m_TotalDown, ctx);
122 if (m_doDetail) {
123 uncorrUp.emplace(m_uncorrUp, ctx);
124 uncorrDown.emplace(m_uncorrDown, ctx);
125 HistIndex.emplace(m_HistIndex, ctx);
126 HistBin.emplace(m_HistBin, ctx);
127 corrUp.emplace(m_corrUp, ctx);
128 corrDown.emplace(m_corrDown, ctx);
129 }
130 if (m_doToys) {
131 toys.emplace(m_toys, ctx);
132 }
133 }
134
136
137 Root::TElectronEfficiencyCorrectionTool::Result
result;
138
139
140 if (std::abs(
el->eta()) > 2.469 ||
el->pt() < 10000) {
141
142
143 if (m_decorate) {
147 if (m_doDetail) {
150 HistIndex.value()(*el) =
result.histIndex;
151 HistBin.value()(*el) =
result.histBinNum;
152 corrUp.value()(*el) =
result.Corr;
153 corrDown.value()(*el) =
result.Corr;
154 }
155 if (m_doToys) {
156 toys.value()(*el) =
result.toys;
157 }
158 }
159 continue;
160 }
161
162
163 double cluster_eta(-9999.9);
165 if (!cluster) {
166 ATH_MSG_ERROR(
"ERROR no cluster associated to the Electron \n");
167 return StatusCode::FAILURE;
168 }
169
170 static const SG::ConstAccessor<uint16_t> accAuthor("author");
171 if (accAuthor.isAvailable(*el) &&
173 cluster_eta = cluster->
eta();
174 } else {
175 cluster_eta = cluster->
etaBE(2);
176 }
177
178
179
180 const double energy = cluster->
e();
181 const double parEta =
el->eta();
182 const double coshEta = std::cosh(parEta);
183 double et = (coshEta != 0.) ? energy / coshEta : 0.;
184
185 if (
et < m_lowestEt) {
187 }
188
189
190 const int status = m_pimpl->calculate(
193 result, (m_mode ==
Total) );
194 if (!status) {
196 return StatusCode::FAILURE;
197 }
198
199
200 ATH_MSG_INFO(
"--------------------------------------------");
203 if (m_doDetail) {
205 << " stat only ");
211 }
212 }
213 if (m_doToys) {
217 }
218 }
219 if (m_decorate) {
223 if (m_doDetail) {
226 HistIndex.value()(*el) =
result.histIndex;
227 HistBin.value()(*el) =
result.histBinNum;
228 const size_t corrsize =
result.Corr.size();
229 std::vector<double>
up(corrsize, 0);
230 std::vector<double> down(corrsize, 0);
231 for (
size_t i = 0;
i < corrsize; ++
i) {
234 }
235 corrUp.value()(*el) = std::move(up);
236 corrDown.value()(*el) = std::move(down);
237 }
238 if (m_doToys) {
239 toys.value()(*el) = std::move(
result.toys);
240 }
241 }
242
243 }
244 return StatusCode::SUCCESS;
245}
246
247}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
std::pair< std::vector< unsigned int >, bool > res
float et(const xAOD::jFexSRJetRoI *j)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double e() const
The total energy of the particle.
float etaBE(const unsigned layer) const
Get the eta in one layer of the EM Calo.
::StatusCode StatusCode
StatusCode definition for legacy code.
std::string getValueByKey(const std::string &mapFile, const std::string &key)
std::string convertToOneKey(const std::string &recokey, const std::string &idkey, const std::string &isokey, const std::string &trigkey)
const float SF[NF]
Cross sections for Fluor.
const uint16_t AuthorFwdElectron
Electron reconstructed by the Forward cluster-based algorithm.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Electron_v1 Electron
Definition of the current "egamma version".