31 CP::ElectronChargeEfficiencyCorrectionTool::
32 ElectronChargeEfficiencyCorrectionTool(
const std::string&
name)
34 , m_dataTypeOverwrite(-1)
35 , m_eventInfoCollectionName(
"EventInfo")
39 , m_useRandomRunNumber(true)
40 , m_defaultRandomRunNumber(999999)
48 , m_filtered_sys_sets()
51 , m_appliedSystematics(nullptr)
52 , m_sf_decoration_name(
"chargeIDEffiSF")
56 declareProperty(
"CorrectionFileName",
58 "Name of the file with charge flipping rates");
60 "WorkingPoint", m_workingPoint,
"Name of working point folder in the file");
61 declareProperty(
"ScaleFactorDecorationName", m_sf_decoration_name);
62 declareProperty(
"ForceDataType",
64 "Force the DataType of the electron to specified value (to "
65 "circumvent problem of incorrect DataType for forward "
66 "electrons in some old releases)");
67 declareProperty(
"EventInfoCollectionName",
68 m_eventInfoCollectionName,
69 "The EventInfo Collection Name");
70 declareProperty(
"UseRandomRunNumber", m_useRandomRunNumber);
71 declareProperty(
"DefaultRandomRunNumber", m_defaultRandomRunNumber);
102 if (m_filename.empty()) {
103 ATH_MSG_ERROR(
" PathResolver was not able to find the file ... aborting");
104 return StatusCode::FAILURE;
108 TFile*
rootFile = TFile::Open(rootfilename.c_str());
113 <<
" ...... aborting");
114 return StatusCode::FAILURE;
147 TList* keyListfolder =
rootFile->GetListOfKeys();
148 std::vector<std::string>
names;
149 std::set<std::string> set_systematics;
151 names.reserve(keyListfolder->GetEntries());
152 for (
int j = 0; j < keyListfolder->GetEntries(); j++) {
153 names.emplace_back((keyListfolder->At(j)->GetName()));
157 for (
unsigned int j = 0; j <
names.size(); j++) {
161 if (
name.find(Form(
"SFCentral_")) != std::string::npos) {
165 if (
name.find(Form(
"_OS")) != std::string::npos) {
170 std::string histid = (
names.at(j));
172 histid.erase(histid.size() - 3, 3);
175 if (histid.find(
"RunNumber") != std::string::npos) {
177 std::string runlow = histid;
178 runlow.erase(histid.find(Form(
"RunNumber")), 9);
179 runlow.erase(runlow.find(
'_'), runlow.size());
180 m_RunNumbers.push_back(
181 static_cast<unsigned int>(
atoi(runlow.c_str())));
182 std::string runhigh = histid;
183 runhigh.erase(histid.find(Form(
"RunNumber")), 9);
184 runhigh.erase(0, runhigh.find(
'_') + 1);
185 m_RunNumbers.push_back(
186 static_cast<unsigned int>(
atoi(runhigh.c_str())));
189 m_SF_OS[histid].push_back((TH2*)
rootFile->Get(
names.at(j).c_str()));
191 std::string histid = (
names.at(j));
193 histid.erase(histid.size() - 3, 3);
195 m_SF_SS[histid].push_back((TH2*)
rootFile->Get(
names.at(j).c_str()));
200 if (
name.find(Form(
"STAT_")) != std::string::npos) {
203 if (
name.find(Form(
"_OS")) != std::string::npos) {
208 std::string histid = (
names.at(j));
210 histid.erase(histid.size() - 3, 3);
213 if (histid.find(
"RunNumber") != std::string::npos) {
215 std::string runlow = histid;
216 runlow.erase(histid.find(Form(
"RunNumber")), 9);
217 runlow.erase(runlow.find(
'_'), runlow.size());
220 std::string runhigh = histid;
221 runhigh.erase(histid.find(Form(
"RunNumber")), 9);
222 runhigh.erase(0, runhigh.find(
'_') + 1);
227 m_SF_OS[histid].push_back((TH2*)
rootFile->Get(
names.at(j).c_str()));
229 std::string histid = (
names.at(j));
232 histid.erase(histid.size() - 3, 3);
234 m_SF_SS[histid].push_back((TH2*)
rootFile->Get(
names.at(j).c_str()));
240 if (
name.find(Form(
"SYST")) != std::string::npos) {
243 if (
name.find(Form(
"_OS")) != std::string::npos) {
248 std::string histid = (
names.at(j));
250 histid.erase(histid.size() - 3, 3);
252 std::string sysname = histid;
253 sysname.erase(sysname.find(
'_'), sysname.size());
254 set_systematics.insert(sysname);
256 histid.erase(0, histid.find(
'_') + 1);
259 if (histid.find(
"RunNumber") != std::string::npos) {
260 std::string runlow = histid;
261 runlow.erase(histid.find(Form(
"RunNumber")), 9);
262 runlow.erase(runlow.find(
'_'), runlow.size());
265 std::string runhigh = histid;
266 runhigh.erase(histid.find(Form(
"RunNumber")), 9);
267 runhigh.erase(0, runhigh.find(
'_') + 1);
272 m_SF_OS[histid].push_back((TH2*)
rootFile->Get(
names.at(j).c_str()));
274 std::string histid = (
names.at(j));
276 histid.erase(histid.size() - 3, 3);
277 histid.erase(0, histid.find(
'_') + 1);
279 m_SF_SS[histid].push_back((TH2*)
rootFile->Get(
names.at(j).c_str()));
287 if (m_SF_OS.empty() || m_SF_SS.empty() || m_SF_SS.size() != m_SF_OS.size()) {
289 "OS/SS SF vectors not filled or of different size. -- Problem with "
290 "files. -- Report to <hn-atlas-EGammaWG@cern.ch>");
291 return StatusCode::FAILURE;
294 m_systematics.insert(m_systematics.end(), set_systematics.begin(), set_systematics.end());
296 std::sort(m_RunNumbers.begin(), m_RunNumbers.end());
302 std::map<std::string, std::vector<TH2*>>
::iterator it = m_SF_OS.begin();
305 m_eta_lowlimit = (*it).second.at(0)->GetYaxis()->GetXmin();
306 m_eta_uplimit = (*it).second.at(0)->GetYaxis()->GetXmax();
307 ATH_MSG_VERBOSE(
"|eta| limits " << m_eta_lowlimit <<
", " << m_eta_uplimit);
309 m_pt_lowlimit = (*it).second.at(0)->GetXaxis()->GetXmin();
310 m_pt_uplimit = (*it).second.at(0)->GetXaxis()->GetXmax();
311 ATH_MSG_VERBOSE(
"pt limits " << m_pt_lowlimit <<
", " << m_pt_uplimit);
314 if (m_pt_uplimit > 1500) {
323 m_affectingSys = affectingSystematics();
326 if (registerSystematics() != StatusCode::SUCCESS) {
327 ATH_MSG_ERROR(
"(registerSystematics() != CP::SystematicCode::Ok)");
328 return StatusCode::FAILURE;
331 return StatusCode::SUCCESS;
352 bool goodEle =
false;
357 ATH_MSG_DEBUG(
"This is the check of goodeleCC in getscalefactor. Scale "
358 "factor set to -999");
359 return goodEle_result;
369 int reco_ele_charge = ele.
charge();
370 const double ele_pt = ele.
pt() * m_gevmev;
374 int truth_ele_charge = 9999;
379 ATH_MSG_VERBOSE(
"This is check of geteletruthchargeCC in getscalefactor. "
380 "Scale factor set to -9999");
381 return charge_result;
384 if (truth_ele_charge == 0) {
390 <<
"; Truth charge = " << truth_ele_charge);
398 std::string cutRunNumber =
"all";
400 if (!m_RunNumbers.empty()) {
401 unsigned int runnumber = m_defaultRandomRunNumber;
403 << m_useRandomRunNumber);
404 if (m_useRandomRunNumber) {
406 evtStore()->retrieve<
const xAOD::EventInfo>(m_eventInfoCollectionName);
417 "Pileup tool not run before using ElectronEfficiencyTool! SFs do not "
418 "reflect PU distribution in data");
421 runnumber = randomrunnumber(*(eventInfo));
423 ATH_MSG_DEBUG(
"Number of RunNumbers in file: " << m_RunNumbers.size());
424 for (std::size_t
r = 0;
r < m_RunNumbers.size();
r++) {
429 bool isInRunNumberRange =
false;
430 for ( std::size_t
r=0;
r<m_RunNumbers.size()-1;
r+=2 ){
433 if (
runnumber >= (
unsigned int)m_RunNumbers.at(
r) &&
434 runnumber <= (
unsigned int)m_RunNumbers.at(
r+1) ) {
435 cutRunNumber.clear();
437 Form(
"RunNumber%d_%d", m_RunNumbers.at(
r), m_RunNumbers.at(
r + 1));
438 ATH_MSG_DEBUG(
"Random run number lies in range " << m_RunNumbers.at(
r) <<
" " << m_RunNumbers.at(
r+1));
439 isInRunNumberRange =
true;
444 (
runnumber > m_RunNumbers.at(m_RunNumbers.size() - 1))) {
450 if ( !isInRunNumberRange ) {
456 if ( ele_eta < m_eta_lowlimit || ele_eta > m_eta_uplimit ) {
458 ATH_MSG_DEBUG(
"Got an electron outside of the range of eta validity " << ele_eta);
462 if ( ele_pt < m_pt_lowlimit ) {
464 ATH_MSG_DEBUG(
"Got an electron outside of the range of pt validity: pt lower than lower limit");
469 const std::vector<TH2*>& SShistograms = m_SF_SS.at(cutRunNumber.c_str());
470 const std::vector<TH2*>& OShistograms = m_SF_OS.at(cutRunNumber.c_str());
475 if (truth_ele_charge * reco_ele_charge > 0)
479 retVal = this->getChargeFlipRate(ele_eta, ele_pt, OShistograms.at(0),
sf);
486 retVal = this->getChargeFlipRate(ele_eta, ele_pt, SShistograms.at(0),
sf);
503 this->getChargeFlipRate(ele_eta, ele_pt, OShistograms.at(1), val_stat);
511 this->getChargeFlipRate(ele_eta, ele_pt, SShistograms.at(1), val_stat);
518 std::vector<float> systs;
519 double val_sys{ 0.0 };
521 for (
unsigned int s = 2;
s < OShistograms.size();
s++) {
524 this->getChargeFlipRate(ele_eta, ele_pt, OShistograms.at(
s), val_sys);
532 this->getChargeFlipRate(ele_eta, ele_pt, SShistograms.at(
s), val_sys);
538 systs.push_back(
static_cast<float>(val_sys));
543 if (m_mySysConf.empty()) {
545 }
else if (*(m_mySysConf.begin()) ==
547 sf = (
sf + (val_stat));
549 }
else if (*(m_mySysConf.begin()) ==
551 sf = (
sf - (val_stat));
555 for (
unsigned int i = 0;
i < m_systematics.size();
i++) {
556 if (*(m_mySysConf.begin()) ==
558 Form(
"EL_CHARGEID_SYS%s", m_systematics.at(
i).c_str()), 1)) {
559 sf = (
sf + (val_sys));
563 if (*(m_mySysConf.begin()) ==
565 Form(
"EL_CHARGEID_SYS%s", m_systematics.at(
i).c_str()), -1)) {
566 sf = (
sf - (val_sys));
586 "CP::ElectronChargeEfficiencyCorrectionTool::applyEfficiencyScaleFactor("
587 "const xAOD::IParticle& part) const");
591 (*m_sfDec)(
part) =
static_cast<float>(
sf);
601 double& flipRate)
const
604 <<
" TH2, double&)");
606 if (
pt > m_pt_uplimit)
607 pt = m_pt_uplimit * 0.999;
609 int bin2D = hrates->FindBin(
pt, eta);
610 flipRate = hrates->GetBinContent(bin2D);
613 << hrates->GetName());
626 return sys.find(systematic) !=
sys.end();
639 for (
unsigned int i = 0;
i < m_systematics.size();
i++) {
641 Form(
"EL_CHARGEID_SYS%s", m_systematics.at(
i).c_str()), 1));
643 Form(
"EL_CHARGEID_SYS%s", m_systematics.at(
i).c_str()), -1));
654 return affectingSystematics();
665 systConfig, m_affectingSys, m_mySysConf)) {
667 "Unsupported combination of systematics passed to the tool! ");
668 return StatusCode::FAILURE;
671 return StatusCode::SUCCESS;
678 if (
registry.registerSystematics(*
this) != StatusCode::SUCCESS) {
679 ATH_MSG_ERROR(
"Failed to add systematic to list of recommended systematics.");
680 return StatusCode::FAILURE;
683 return StatusCode::SUCCESS;