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();
321 ATH_MSG_ERROR(
"(registerSystematics() != CP::SystematicCode::Ok)");
322 return StatusCode::FAILURE;
325 return StatusCode::SUCCESS;
346 bool goodEle =
false;
351 ATH_MSG_DEBUG(
"This is the check of goodeleCC in getscalefactor. Scale "
352 "factor set to -999");
353 return goodEle_result;
363 int reco_ele_charge = ele.
charge();
368 int truth_ele_charge = 9999;
373 ATH_MSG_VERBOSE(
"This is check of geteletruthchargeCC in getscalefactor. "
374 "Scale factor set to -9999");
375 return charge_result;
378 if (truth_ele_charge == 0) {
384 <<
"; Truth charge = " << truth_ele_charge);
392 std::string cutRunNumber =
"all";
406 static const SG::AuxElement::Accessor<unsigned int> randomrunnumber(
408 if (!randomrunnumber.isAvailable(*eventInfo)) {
411 "Pileup tool not run before using ElectronEfficiencyTool! SFs do not "
412 "reflect PU distribution in data");
415 runnumber = randomrunnumber(*(eventInfo));
423 bool isInRunNumberRange =
false;
429 cutRunNumber.clear();
433 isInRunNumberRange =
true;
444 if ( !isInRunNumberRange ) {
452 ATH_MSG_DEBUG(
"Got an electron outside of the range of eta validity " << ele_eta);
458 ATH_MSG_DEBUG(
"Got an electron outside of the range of pt validity: pt lower than lower limit");
463 const std::vector<TH2*>& SShistograms =
m_SF_SS.at(cutRunNumber.c_str());
464 const std::vector<TH2*>& OShistograms =
m_SF_OS.at(cutRunNumber.c_str());
469 if (truth_ele_charge * reco_ele_charge > 0)
512 std::vector<float> systs;
513 double val_sys{ 0.0 };
515 for (
unsigned int s = 2; s < OShistograms.size(); s++) {
532 systs.push_back(
static_cast<float>(val_sys));
541 sf = (sf + (val_stat));
545 sf = (sf - (val_stat));
552 Form(
"EL_CHARGEID_SYS%s",
m_systematics.at(i).c_str()), 1)) {
553 sf = (sf + (val_sys));
559 Form(
"EL_CHARGEID_SYS%s",
m_systematics.at(i).c_str()), -1)) {
560 sf = (sf - (val_sys));
580 "CP::ElectronChargeEfficiencyCorrectionTool::applyEfficiencyScaleFactor("
581 "const xAOD::IParticle& part) const");
585 (*m_sfDec)(part) =
static_cast<float>(sf);
595 double& flipRate)
const
598 <<
" TH2, double&)");
603 int bin2D = hrates->FindBin(
pt,
eta);
604 flipRate = hrates->GetBinContent(bin2D);
607 << hrates->GetName());
620 return sys.find(systematic) != sys.end();
637 Form(
"EL_CHARGEID_SYS%s",
m_systematics.at(i).c_str()), -1));
661 "Unsupported combination of systematics passed to the tool! ");
662 return StatusCode::FAILURE;
665 return StatusCode::SUCCESS;
673 ATH_MSG_ERROR(
"Failed to add systematic to list of recommended systematics.");
674 return StatusCode::FAILURE;
677 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...
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 EventInfo_v1::Accessor< std::vector< std::string > > names("streamTagNames")
JetConstituentVector::iterator iterator
Electron_v1 Electron
Definition of the current "egamma version".