|  | ATLAS Offline Software
    | 
 
 
 
Go to the documentation of this file.
   14                                   const std::string& 
file,
 
   15                                   const std::string& time_unit,
 
   16                                   const std::string& syst_name,
 
   17                                   int syst_type_bitmap):
 
   18             m_measurement(ref_tool.measurement()),
 
   19             m_syst_name(syst_name),
 
   22             m_respond_to_kineDepSyst(syst_type_bitmap & 
EffiCollection::PtDependent),
 
   23             m_separateBinSyst(syst_type_bitmap & 
EffiCollection::UnCorrelated),
 
   28             m_sf_decor(std::
make_unique<
FloatDecorator>(ref_tool.sf_decoration()+ (m_syst_name.empty()? 
"" :
"_"+ m_syst_name + (m_is_up? 
"_1UP": 
"_1DN")))),
 
   29             m_eff_decor(std::
make_unique<
FloatDecorator>(ref_tool.data_effi_decoration()+ (m_syst_name.empty()? 
"" :
"_"+ m_syst_name + (m_is_up? 
"_1UP": 
"_1DN")))),          
 
   30             m_mc_eff_decor(std::
make_unique<
FloatDecorator>(ref_tool.mc_effi_decoration()+ (m_syst_name.empty()? 
"" :
"_"+ m_syst_name + (m_is_up? 
"_1UP": 
"_1DN")))),
 
   31             m_sf_rep_decor(std::
make_unique<
FloatVectorDecorator>(ref_tool.sf_replica_decoration()+ (m_syst_name.empty()? 
"" :
"_"+ m_syst_name + (m_is_up? 
"_1UP": 
"_1DN")))),
 
   32             m_eff_rep_decor(std::
make_unique<
FloatVectorDecorator>(ref_tool.data_effi_replica_decoration()+ (m_syst_name.empty()? 
"" :
"_"+ m_syst_name + (m_is_up? 
"_1UP": 
"_1DN")))),
 
   33             m_mc_eff_rep_decor(std::
make_unique<
FloatVectorDecorator>(ref_tool.mc_effi_replica_deocration()+ (m_syst_name.empty()? 
"" :
"_"+ m_syst_name + (m_is_up? 
"_1UP": 
"_1DN")))),
 
   39             m_NominalFallBack(nominal),
 
   42             m_default_eff_ttva(1.),
 
   52         std::unique_ptr<TFile> 
f (TFile::Open(
file.c_str(), 
"READ"));
 
   53         if (!
f || !
f->IsOpen()) {
 
   54             Error(
"EfficiencyScaleFactor", 
"Unable to open file %s", 
file.c_str());
 
   62         if (syst_name.empty()) 
return;
 
   72         std::function<void(std::unique_ptr<HistHandler>&, 
const std::string& )> syst_loader = [
this, &
f, &time_unit, &syst_type_bitmap] (std::unique_ptr<HistHandler>& nominal, 
const std::string& hist_type) {
 
   74             std::unique_ptr<HistHandler> 
sys = 
ReadHistFromFile(
this, Form(
"%s_%s_%s", hist_type.c_str() ,
 
   79                 for (
int i = 1; 
i <= nominal->nBins(); ++
i) {
 
   80                     double content = nominal->GetBinContent(
i);
 
   82                     nominal->SetBinContent(
i,
content + variation);
 
   90                 std::unique_ptr<HistHandler> old_sys = 
ReadHistFromFile(
this, hist_type +
"_sys", 
f.get(), time_unit);
 
   97                 for (
int i = 1; 
i<= nominal->nBins(); ++
i) {
 
   98                      nominal->SetBinContent(
i, nominal->GetBinContent(
i) + (
IsUpVariation() ? 1. : -1.)*old_sys->GetBinContent(
i));
 
  103                 for (
int i = 1; 
i<= nominal->nBins(); ++
i) {
 
  104                      nominal->SetBinContent(
i, nominal->GetBinContent(
i) + (
IsUpVariation() ? 1. : -1.)*nominal->GetBinError(
i));
 
  113                 Error(
"EfficiencyScaleFactor()", 
"Failed to load sytstematic variation  %s for measurement %s and histo-type %s", 
sysname(
true).c_str(), 
 
  120         syst_loader(
m_sf,
"SF");
 
  121         syst_loader(
m_eff,
"Eff");
 
  135             TDirectory* SystDir = 
nullptr;
 
  136             f->GetObject((
"KinematicSystHandler_" + time_unit).c_str(), SystDir);
 
  142                 f->GetObject(
"BadMuonVetoSyst_3Stations", SystDir);
 
  143                 TDirectory* SystDir_2Stat = 
nullptr;
 
  144                 f->GetObject(
"BadMuonVetoSyst_2Stations", SystDir_2Stat);
 
  145                 m_sf_KineDepsys = std::make_unique<BadMuonVetoSystHandler>(SystDir, SystDir_2Stat);
 
  149                 Error(
"EfficiencyScaleFactor()", 
"Pt dependent systematic could not be loaded");
 
  158                 Error(
"EfficiencyScaleFactor()", 
"TTVA non closure systematic could not be loaded.");
 
  179                                   const std::string &
file, 
 
  180                                   const std::string &time_unit):
 
  182                                                         ref_tool,
file, time_unit, 
"",0){}
 
  209             Error(
"EfficiencyScaleFactor()", 
"Could not load the SF for  measurement %s and systematic %s",EfficiencyTypeName(
m_measurement).c_str(), 
sysname().c_str());
 
  213             Error(
"EfficiencyScaleFactor()", 
"Could not load the SF pt-dependent systematic for %s and systematic %s", EfficiencyTypeName(
m_measurement).c_str(), 
sysname().c_str() );
 
  217             Error(
"EfficiencyScaleFactor()", 
"The EfficiencyScaleFactor %s has itself as Nominal Fall back.", EfficiencyTypeName(
m_measurement).c_str());
 
  223                 Error(
"EfficiencyScaleFactor()", 
"Either nominal is assigned with a fall back (%s) or the nominal fall back is invald(%s).", 
sysname().c_str(), 
m_NominalFallBack->sysname().c_str() );
 
  228             Error(
"EfficiencyScaleFactor()", 
"Invalid run number range. Since the map is ranging from %u to %u.", 
firstRun(), 
lastRun());
 
  231         std::function<
bool(
const std::unique_ptr<HistHandler>&)> consistent_histo = [](
const std::unique_ptr<HistHandler>& 
histo)->
bool{
 
  234             if (!
histo) 
return true;
 
  235             for ( 
int i = 1; 
i <= 
histo->nBins(); ++
i){
 
  236                 if (std::isnan(
histo->GetBinContent(
i)) || std::isinf(
histo->GetBinContent(
i))){
 
  237                     Error(
"EfficiencyScaleFactor()", 
"The %d-th bin %s has not a number (%f)",
i, 
histo->GetBinName(
i).c_str(), 
histo->GetBinContent(
i));
 
  243         if (!consistent_histo(
m_sf)){
 
  244             Error(
"EfficiencyScaleFactor()", 
"Invalid scalefactor in %s", 
sysname().c_str());
 
  247         if (!consistent_histo(
m_eff)){
 
  248             Error(
"EfficiencyScaleFactor()", 
"Invalid data-efficiency in %s", 
sysname().c_str());
 
  252             Error(
"EfficiencyScaleFactor()", 
"Invalid MC-efficiency in %s", 
sysname().c_str());
 
  259         TH1* hist_from_file =  
nullptr;
 
  261         f->GetObject((
name + std::string(
"_") + time_unit).c_str(), hist_from_file);
 
  264         if (!hist_from_file && time_unit == 
"All") {
 
  265             f->GetObject(
name.c_str(), hist_from_file);
 
  267         if (!hist_from_file) {
 
  268             return std::unique_ptr<HistHandler>();
 
  275         if (!
h) 
return std::unique_ptr<HistHandler>();
 
  276         if (
dynamic_cast<TH2Poly*
>(
h)) {
 
  277             return std::make_unique<HistHandler_TH2Poly>(
parent, 
dynamic_cast<TH2Poly*
>(
h));
 
  278         }
else if (
h->GetDimension() == 3) {
 
  279             return std::make_unique<HistHandler_TH3>(
parent, 
h);
 
  280         }
else if (
h->GetDimension() == 2) {
 
  281             return std::make_unique<HistHandler_TH2>(
parent, 
h);
 
  282         } 
else if (
h->GetDimension() == 1) {
 
  283             return std::make_unique<HistHandler_TH1>(
parent, 
h);
 
  285         Error(
"EfficiencyScaleFactor", 
"Unable to package histo %s (%s) in a known HistHandler", 
h->GetName(), 
h->IsA()->GetName());
 
  286         return std::unique_ptr<HistHandler>();
 
  292         return m_sf ? 
m_sf->nOverFlowBins() : -1;
 
  295         return m_sf ? 
m_sf->isOverFlowBin(
b) : 
true;
 
  361                 Info(
"EfficiencyScaleFactor", 
"No TTVA sf/efficiency provided for standalone muons with 2.5<|eta|<2.7 for variation %s and muon with pt=%.4f, eta=%.2f and phi=%.2f, returning %.1f", 
sysname().c_str(), 
ptAcc(
mu), 
etaAcc(
mu), 
phiAcc(
mu), 
m_default_eff_ttva);
 
  380         (*m_sf_decor)(
mu) = 
sf;
 
  384         std::vector<float> replicas(n_replicas);
 
  386         (*m_sf_rep_decor)(
mu)= replicas;
 
  393         (*m_eff_decor)(
mu) = 
effi;
 
  397         std::vector<float> replicas(n_replicas);
 
  399         (*m_eff_rep_decor)(
mu) = replicas;
 
  405         (*m_mc_eff_decor)(
mu) = 
effi;
 
  409         std::vector<float> replicas(n_replicas);
 
  411         (*m_mc_eff_rep_decor)(
mu) = replicas;
 
  428                 Info(
"EfficiencyScaleFactor", 
"No TTVA sf/efficiency provided for standalone muons with 2.5<|eta|<2.7 for variation %s and muon with pt=%.4f, eta=%.2f and phi=%.2f, returning %.1f", 
sysname().c_str(), 
mu.pt(), 
mu.eta(), 
mu.phi(), 
m_default_eff_ttva);
 
  445             for (
size_t k = 0; 
k < 
SF.size(); 
k++) {
 
  446                 SF[
k] = replicas.at(
k)->GetBinContent(
bin) * extra_sys;
 
  460         replicas.reserve(nrep);
 
  462         for (
int t = 0; 
t < nrep; 
t++) {
 
  474             Error(
"EfficiencyScaleFactor::SetSystematicBin()", 
"No fallback has been given for %s", 
sysname().c_str());
 
  478             Error(
"EfficiencyScaleFactor::SetSystematicBin()", 
"The current bin %i is out of the maximum range %u ", 
bin, 
nBins());
 
  486             Error(
"EfficiencyScaleFactor::GetBinName()", 
"The current bin %i is out of the maximum range %u ", 
bin, 
nBins());
 
  487             return "Out of range";
 
  
std::string filename_Calo() const
Reconstruction scale-factors have a dedicated map for calo-tag muons around |\eta|<0....
std::string filename_Central() const
The following methods are meant to propagate information from the central tool to the subtool managin...
CorrectionCode DataEfficiency(const xAOD::Muon &mu, float &Eff) const
... and absolute efficiencies
std::atomic< unsigned int > m_warnsPrinted
CorrectionCode ScaleFactorReplicas(const xAOD::Muon &mu, std::vector< float > &SF)
bool isOverFlowBin(int b) const
Check whether the bin is overflow or not.
The EffiCollection class handles the 5 different scale-factor maps binned in time.
columnar::MuonAccessor< columnar::RetypeColumn< double, float > > etaAcc
CorrectionCode MCEfficiencyReplicas(const xAOD::Muon &mu, std::vector< float > &eff)
CorrectionCode GetContentReplicasFromHist(EfficiencyScaleFactor::SFReplicaVec &replicas, const xAOD::Muon &mu, std::vector< float > &SF, bool add_kine_syst)
read a vector of replica contents in the correct bin in one of my histos
std::unique_ptr< HistHandler > m_mc_eff
Int_t FindBin(const TAxis *axis, const double x)
std::unique_ptr< IKinematicSystHandler > m_sf_KineDepsys
bool IsUpVariation() const
std::unique_ptr< HistHandler > m_eff
bool m_is_lowpt
states that this SF should respond to low pt systematics rather than high pt ones
std::shared_ptr< EfficiencyScaleFactor > m_NominalFallBack
Nominal fall-back scale-factor.
const float SF[NF]
Cross sections for Fluor.
int FindBinSF(const xAOD::Muon &mu) const
Finds the bin to which the muon corresponds to.
CorrectionCode GetContentFromHist(const HistHandler *Hist, const xAOD::Muon &mu, float &SF, bool add_kine_syst) const
read the content of the correct bin in one of my histos. MCefficiencies actually do not need a pt-dep...
virtual CorrectionCode FindBin(columnar::MuonId muon, int &bin) const =0
Function that changes from Implementation to implementation.
double GetBinContent(int bin) const
Select isolated Photons, Electrons and Muons.
columnar::MuonAccessor< columnar::RetypeColumn< xAOD::Muon::MuonType, std::uint16_t > > muonTypeAcc
static const unsigned int m_warningLimit
CorrectionCode ApplyScaleFactor(const xAOD::Muon &mu) const
or you can just decorate the scale-factor to the muon
std::unique_ptr< HistHandler > ReadHistFromFile(columnar::ColumnarTool<> *parent, const std::string &name, TFile *f, const std::string &time_unit)
CorrectionCode DataEfficiencyReplicas(const xAOD::Muon &mu, std::vector< float > &eff)
CP::MuonEfficiencyType m_measurement
Section of variables of the tool.
columnar::MuonAccessor< columnar::RetypeColumn< double, float > > ptAcc
bool coversRunNumber(unsigned int run) const
Check if a run of data-taking is covered by this map.
float m_default_eff
default efficiency value (in case of OutOfValidityRange)
bool SetSystematicBin(int bin)
This function will let the world implode since it allows to decorrelate the sysstematics bin by bin.
@ OutOfValidityRange
Input object is out of validity range.
@ Error
Some error happened during the object correction.
bool m_separateBinSyst
Can the systematic be decorrelated.
Helper class to provide type-safe access to aux data.
void setFirstLastRun(unsigned int first, unsigned int last)
Set the run-number coverage.
void SetBinContent(int bin, float val)
std::pair< std::vector< unsigned int >, bool > res
SFReplicaVec m_sf_replicas
replicas, in case we use them
CorrectionCode MCEfficiency(const xAOD::Muon &mu, float &Eff) const
... mc efficiency
CorrectionCode ApplyDataEfficiency(const xAOD::Muon &mu) const
You can decorate the data efficiecny as well.
static void set_use_2D_sf(const bool)
CorrectionCode ApplyDataEfficiencyReplicas(const xAOD::Muon &mu, int n_replicas)
std::string filename_HighEta() const
High-eta reconstruction scale-factors are not obtained by the means of are not obtained by the means ...
float m_default_eff_ttva
default TTVA efficiency value (in case of MuonStandAlone for |eta|>2.5)
columnar::MuonAccessor< columnar::RetypeColumn< double, float > > phiAcc
unsigned int lastRun() const
Last run to which the map belongs to. The last run number is given exclusvely...
a class representing a single object (electron, muons, etc.)
SFReplicaVec m_mc_eff_replicas
int nOverFlowBins() const
Number of overflow bins in the map.
void GenerateReplicas(int nrep, int seed)
void GenerateReplicasFromHist(HistHandler *h, int nrep, int seed, EfficiencyScaleFactor::SFReplicaVec &repVector)
@ Ok
The correction was done successfully.
CorrectionCode ApplyMCEfficiency(const xAOD::Muon &mu) const
... or decorate them directly
CorrectionCode ApplyScaleFactorReplicas(const xAOD::Muon &mu, int n_replicas)
static void set_close_jet_decorator(const std::string &decor_name)
std::string sysname(bool with_direction=true) const
A string having the full name of the systematic including the measurement.
Return value from object correction CP tools.
CorrectionCode ScaleFactor(const xAOD::Muon &mu, float &SF) const
the important bits - extract SF info
std::string GetBinName(int bin) const
Returns the name of the bin using the axis title from the scale-factor map.
const std::string & close_by_jet_decoration() const
Returns the string telling the tool in which float AuxElement the information of the separation to th...
bool m_is_up
Boolean whether the scale-factor is varying upwards or downwards Only relevant if the systname is not...
std::vector< std::unique_ptr< HistHandler > > SFReplicaVec
int nBins() const
How many bins does the scale-factor map have.
CorrectionCode ApplyMCEfficiencyReplicas(const xAOD::Muon &mu, int n_replicas)
bool CheckConsistency()
check the consistency of the scale-factor map.
std::unique_ptr< HistHandler > package_histo(columnar::ColumnarTool<> *parent, TH1 *h)
EfficiencyScaleFactor(const MuonEfficiencyScaleFactors &ref_tool, const std::string &file, const std::string &time_unit)
Nominal constructor to use having the measurement (Reco/TTVA/Iso/BadMuon) path to the scale-factor ma...
bool use_2D_iso_corrections() const
option to set if we want to use 1D or 2D isolation SFs
unsigned int firstRun() const
First run to which the map belongs to.
bool m_respond_to_kineDepSyst
steers the pt dependent systematics
setBGCode setTAP setLVL2ErrorBits bool
std::unique_ptr< HistHandler > m_sf
the histograms needed to run
CP::MuonEfficiencyType measurement() const
Returns the type of the measurement to be carried out... E.g. Reco/TTVA/Iso.
SFReplicaVec m_eff_replicas
bool separateBinSyst() const