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()));
160 if (
name.contains(
"SFCentral_")) {
164 if (
name.contains(
"_OS")) {
169 std::string histid = (
name);
171 histid.erase(histid.size() - 3, 3);
174 if (histid.contains(
"RunNumber")) {
176 std::string runlow = histid;
177 runlow.erase(histid.find(
"RunNumber"), 9);
178 runlow.erase(runlow.find(
'_'), runlow.size());
180 static_cast<unsigned int>(atoi(runlow.c_str())));
181 std::string runhigh = histid;
182 runhigh.erase(histid.find(
"RunNumber"), 9);
183 runhigh.erase(0, runhigh.find(
'_') + 1);
185 static_cast<unsigned int>(atoi(runhigh.c_str())));
188 m_SF_OS[histid].push_back(
static_cast<TH2*
>(rootFile->Get(
name.c_str())));
190 std::string histid = (
name);
192 histid.erase(histid.size() - 3, 3);
194 m_SF_SS[histid].push_back(
static_cast<TH2*
>(rootFile->Get(
name.c_str())));
199 if (
name.contains(
"STAT_")) {
202 if (
name.contains(
"_OS")) {
207 std::string histid = (
name);
209 histid.erase(histid.size() - 3, 3);
212 m_SF_OS[histid].push_back(
static_cast<TH2*
>(rootFile->Get(
name.c_str())));
214 std::string histid = (
name);
217 histid.erase(histid.size() - 3, 3);
219 m_SF_SS[histid].push_back(
static_cast<TH2*
>(rootFile->Get(
name.c_str())));
225 if (
name.contains(
"SYST")) {
228 if (
name.contains(
"_OS")) {
233 std::string histid = (
name);
235 histid.erase(histid.size() - 3, 3);
237 std::string sysname = histid;
238 sysname.erase(sysname.find(
'_'), sysname.size());
239 set_systematics.insert(std::move(sysname));
241 histid.erase(0, histid.find(
'_') + 1);
244 m_SF_OS[histid].push_back(
static_cast<TH2*
>(rootFile->Get(
name.c_str())));
246 std::string histid = (
name);
248 histid.erase(histid.size() - 3, 3);
249 histid.erase(0, histid.find(
'_') + 1);
251 m_SF_SS[histid].push_back(
static_cast<TH2*
>(rootFile->Get(
name.c_str())));
261 "OS/SS SF vectors not filled or of different size. -- Problem with "
262 "files. -- Report to <hn-atlas-EGammaWG@cern.ch>");
263 return StatusCode::FAILURE;
282 m_pt_uplimit = (*it).second.at(0)->GetXaxis()->GetXmax();
293 ATH_MSG_ERROR(
"(registerSystematics() != CP::SystematicCode::Ok)");
294 return StatusCode::FAILURE;
297 return StatusCode::SUCCESS;
318 bool goodEle =
false;
323 ATH_MSG_DEBUG(
"This is the check of goodeleCC in getscalefactor. Scale "
324 "factor set to -999");
325 return goodEle_result;
335 int reco_ele_charge = ele.
charge();
340 int truth_ele_charge = 9999;
345 ATH_MSG_VERBOSE(
"This is check of geteletruthchargeCC in getscalefactor. "
346 "Scale factor set to -9999");
347 return charge_result;
350 if (truth_ele_charge == 0) {
356 <<
"; Truth charge = " << truth_ele_charge);
364 std::string cutRunNumber =
"all";
378 static const SG::AuxElement::Accessor<unsigned int> randomrunnumber(
380 if (!randomrunnumber.isAvailable(*eventInfo)) {
383 "Pileup tool not run before using ElectronEfficiencyTool! SFs do not "
384 "reflect PU distribution in data");
387 runnumber = randomrunnumber(*(eventInfo));
395 bool isInRunNumberRange =
false;
401 cutRunNumber.clear();
405 isInRunNumberRange =
true;
416 if ( !isInRunNumberRange ) {
424 ATH_MSG_DEBUG(
"Got an electron outside of the range of eta validity " << ele_eta);
430 ATH_MSG_DEBUG(
"Got an electron outside of the range of pt validity: pt lower than lower limit");
435 const std::vector<TH2*>& SShistograms =
m_SF_SS.at(cutRunNumber.c_str());
436 const std::vector<TH2*>& OShistograms =
m_SF_OS.at(cutRunNumber.c_str());
441 if (truth_ele_charge * reco_ele_charge > 0)
484 std::vector<float> systs;
485 double val_sys{ 0.0 };
487 for (
unsigned int s = 2; s < OShistograms.size(); s++) {
504 systs.push_back(
static_cast<float>(val_sys));
513 sf = (sf + (val_stat));
517 sf = (sf - (val_stat));
524 Form(
"EL_CHARGEID_SYS%s",
m_systematics.at(i).c_str()), 1)) {
525 sf = (sf + (val_sys));
531 Form(
"EL_CHARGEID_SYS%s",
m_systematics.at(i).c_str()), -1)) {
532 sf = (sf - (val_sys));
552 "CP::ElectronChargeEfficiencyCorrectionTool::applyEfficiencyScaleFactor("
553 "const xAOD::IParticle& part) const");
557 (*m_sfDec)(part) =
static_cast<float>(sf);
567 double& flipRate)
const
570 <<
" TH2, double&)");
575 int bin2D = hrates->FindBin(
pt,
eta);
576 flipRate = hrates->GetBinContent(bin2D);
579 << hrates->GetName());
592 return sys.find(systematic) != sys.end();
609 Form(
"EL_CHARGEID_SYS%s",
m_systematics.at(i).c_str()), -1));
633 "Unsupported combination of systematics passed to the tool! ");
634 return StatusCode::FAILURE;
637 return StatusCode::SUCCESS;
644 if (registry.registerSystematics(*
this) != StatusCode::SUCCESS) {
645 ATH_MSG_ERROR(
"Failed to add systematic to list of recommended systematics.");
646 return StatusCode::FAILURE;
649 return StatusCode::SUCCESS;
Scalar eta() const
pseudorapidity method
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(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.
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".