31CP::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);
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());
111 if (rootFile ==
nullptr) {
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());
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);
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()));
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;
310 m_pt_uplimit = (*it).second.at(0)->GetXaxis()->GetXmax();
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();
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";
417 "Pileup tool not run before using ElectronEfficiencyTool! SFs do not "
418 "reflect PU distribution in data");
421 runnumber = randomrunnumber(*(eventInfo));
429 bool isInRunNumberRange =
false;
435 cutRunNumber.clear();
439 isInRunNumberRange =
true;
450 if ( !isInRunNumberRange ) {
458 ATH_MSG_DEBUG(
"Got an electron outside of the range of eta validity " << ele_eta);
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)
518 std::vector<float> systs;
519 double val_sys{ 0.0 };
521 for (
unsigned int s = 2; s < OShistograms.size(); s++) {
538 systs.push_back(
static_cast<float>(val_sys));
547 sf = (sf + (val_stat));
551 sf = (sf - (val_stat));
558 Form(
"EL_CHARGEID_SYS%s",
m_systematics.at(i).c_str()), 1)) {
559 sf = (sf + (val_sys));
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&)");
609 int bin2D = hrates->FindBin(
pt,
eta);
610 flipRate = hrates->GetBinContent(bin2D);
613 << hrates->GetName());
626 return sys.find(systematic) != sys.end();
643 Form(
"EL_CHARGEID_SYS%s",
m_systematics.at(i).c_str()), -1));
667 "Unsupported combination of systematics passed to the tool! ");
668 return StatusCode::FAILURE;
671 return StatusCode::SUCCESS;
679 ATH_MSG_ERROR(
"Failed to add systematic to list of recommended systematics.");
680 return StatusCode::FAILURE;
683 return StatusCode::SUCCESS;
Scalar eta() const
pseudorapidity method
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
ServiceHandle< StoreGateSvc > & evtStore()
Return value from object correction CP tools.
@ Error
Some error happened during the object correction.
@ OutOfValidityRange
Input object is out of validity range.
@ Ok
The correction was done successfully.
This module implements the central registry for handling systematic uncertainties with CP tools.
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
StatusCode registerSystematics(const IReentrantSystematicsTool &tool)
effects: register all the systematics from the tool
Class to wrap a set of SystematicVariations.
static StatusCode filterForAffectingSystematics(const SystematicSet &systConfig, const SystematicSet &affectingSystematics, SystematicSet &filteredSystematics)
description: filter the systematics for the affected systematics returns: success guarantee: strong f...
SG::Decorator< T, ALLOC > Decorator
SG::Accessor< T, ALLOC > Accessor
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
float etaBE(const unsigned layer) const
Get the eta in one layer of the EM Calo.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
const xAOD::CaloCluster * caloCluster(size_t index=0) const
Pointer to the xAOD::CaloCluster/s that define the electron candidate.
float charge() const
Obtain the charge of the object.
static std::vector< uint32_t > runnumber
CP::CorrectionCode getEleTruthCharge(const xAOD::Electron &ele, int &truthcharge)
Get the charge of the original electron.
CP::CorrectionCode isGoodEle(const xAOD::Electron &ele, bool &goodEle)
Return true if it's good ele for charge flip measurements.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
setRcore setEtHad setFside pt
EventInfo_v1 EventInfo
Definition of the latest event info version.
static const SG::AuxElement::Accessor< std::vector< std::string > > names("thrNames")
Accessor for the names of the passed thresholds.
JetConstituentVector::iterator iterator
Electron_v1 Electron
Definition of the current "egamma version".