ATLAS Offline Software
Loading...
Searching...
No Matches
CP::MuonTriggerScaleFactors Class Reference

#include <MuonTriggerScaleFactors.h>

Inheritance diagram for CP::MuonTriggerScaleFactors:

Public Member Functions

 MuonTriggerScaleFactors (const std::string &name)
virtual ~MuonTriggerScaleFactors ()
virtual StatusCode initialize (void)
virtual CorrectionCode getTriggerScaleFactor (const xAOD::MuonContainer &mucont, Double_t &triggersf, const std::string &trigger) const
virtual CorrectionCode getTriggerScaleFactor (const xAOD::Muon &muon, Double_t &triggersf, const std::string &trigger) const
virtual CorrectionCode getTriggerEfficiency (const xAOD::Muon &mu, Double_t &efficiency, const std::string &trigger, Bool_t dataType) const
virtual bool isAffectedBySystematic (const CP::SystematicVariation &systematic) const
 Declare the interface that this class provides.
virtual CP::SystematicSet affectingSystematics () const
 returns: the list of all systematics this tool can be affected by
virtual CP::SystematicSet recommendedSystematics () const
 returns: the list of all systematics this tool recommends to use
virtual StatusCode applySystematicVariation (const CP::SystematicSet &systConfig)
 effects: configure this tool for the given list of systematic variations.
virtual int getBinNumber (const xAOD::Muon &muon, const std::string &trigger) const
virtual int getReplica_index (const std::string &sysBaseName, const std::string &trigStr) const
virtual bool isTriggerSupported (const std::string &trigger) const
 Returns whether the trigger is supported by the tool or not. The decision depends on the present (random)RunNumber.
virtual void print () const
 Print the state of the tool.
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysInitialize () override
 Perform system initialization for an algorithm.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const
Additional helper functions, not directly mimicking Athena
template<class T>
const T * getProperty (const std::string &name) const
 Get one of the tool's properties.
const std::string & msg_level_name () const __attribute__((deprecated))
 A deprecated function for getting the message level's name.
const std::string & getName (const void *ptr) const
 Get the name of an object that is / should be in the event store.
SG::sgkey_t getKey (const void *ptr) const
 Get the (hashed) key of an object that is in the event store.

Protected Member Functions

virtual std::shared_ptr< TH1 > getEfficiencyHistogram (unsigned int year, const std::string &period, const std::string &trigger, bool isData, const std::string &Systematic, bool isBarrel=true) const
virtual std::shared_ptr< TH1 > getEfficiencyHistogram (const std::string &trigger, bool isData, const std::string &Systematic, bool isBarrel=true) const
std::string getDataPeriod () const
unsigned int getRunNumber () const
unsigned int getYear (unsigned int run) const
std::string getDataPeriod (unsigned int run) const
std::string getDataPeriod (unsigned int runNumber, unsigned int year) const
void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Private Types

typedef std::pair< unsigned int, std::string > YearPeriod
typedef std::pair< YearPeriod, unsigned intEffiHistoIdent
typedef std::map< EffiHistoIdent, TH1_PtrEfficiencyMap
typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

virtual CorrectionCode getMuonEfficiency (Double_t &eff, const TrigMuonEff::Configuration &configuration, const xAOD::Muon &muon, const std::string &trigger, const std::string &systematic) const
virtual CorrectionCode GetTriggerSF_dimu (Double_t &TriggerSF, TrigMuonEff::Configuration &configuration, const xAOD::MuonContainer &mucont, const std::string &trigger) const
virtual CorrectionCode GetTriggerSF (Double_t &TriggerSF, TrigMuonEff::Configuration &configuration, const xAOD::MuonContainer &mucont, const std::string &trigger) const
virtual CorrectionCode GetTriggerSF (Double_t &TriggerSF, TrigMuonEff::Configuration &configuration, const xAOD::Muon &muon, const std::string &trigger) const
virtual CorrectionCode getDimuonEfficiency (Double_t &eff, const TrigMuonEff::Configuration &configuration, const xAOD::MuonContainer &mucont, const std::string &chain, const std::string &systematic) const
const CP::SystematicSetappliedSystematics () const
StatusCode registerSystematics ()
StatusCode LoadTriggerMap (unsigned int year)
unsigned int encodeHistoName (const std::string &period, const std::string &Trigger, bool isData, const std::string &Systematic, bool isBarrel=true) const
unsigned int encodeHistoName (const std::string &Trigger, const TrigMuonEff::Configuration &configuration, const std::string &Systematic, bool isBarrel=true) const
CorrectionCode getThreshold (Int_t &threshold, const std::string &trigger) const
std::string getTriggerCorrespondingToDimuonTrigger (const std::string &trigger) const
TDirectory * getTemporaryDirectory (void) const
std::vector< TH1_PtrgenerateReplicas (TH1_Ptr h, int nrep, int seed) const
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

SG::ReadHandleKey< xAOD::EventInfom_eventInfo {this, "EventInfoContName", "EventInfo", "event info key"}
std::unordered_map< CP::SystematicSet, CP::SystematicSetm_systFilter
CP::SystematicSetm_appliedSystematics
std::string m_fileName
EfficiencyMap m_efficiencyMap
std::map< EffiHistoIdent, std::vector< TH1_Ptr > > m_efficiencyMapReplicaArray
std::string m_muonquality
std::string m_calibration_version
std::string m_custom_dir
std::string m_binning
bool m_allowZeroSF
bool m_experimental
int m_forceYear
std::string m_forcePeriod
std::vector< std::string > m_replicaTriggerList
std::set< std::string > m_replicaSet
int m_nReplicas
int m_ReplicaRandomSeed
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default)
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default)
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Static Private Attributes

static const std::map< unsigned int, intm_runNumber_year

Detailed Description

Definition at line 30 of file MuonTriggerScaleFactors.h.

Member Typedef Documentation

◆ EfficiencyMap

Definition at line 92 of file MuonTriggerScaleFactors.h.

◆ EffiHistoIdent

Definition at line 91 of file MuonTriggerScaleFactors.h.

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< AlgTool > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

◆ YearPeriod

typedef std::pair<unsigned int, std::string> CP::MuonTriggerScaleFactors::YearPeriod
private

Definition at line 90 of file MuonTriggerScaleFactors.h.

Constructor & Destructor Documentation

◆ MuonTriggerScaleFactors()

CP::MuonTriggerScaleFactors::MuonTriggerScaleFactors ( const std::string & name)

Definition at line 43 of file MuonTriggerScaleFactors.cxx.

43 :
44 asg::AsgTool(name),
46 m_appliedSystematics(nullptr),
47 m_fileName(),
50 m_muonquality("Medium"),
51 m_calibration_version("250731_SummerUpdate"),
53 m_binning("fine"),
54 m_allowZeroSF(false),
55 m_experimental(false),
56 m_forceYear(-1),
57 m_forcePeriod(""),
60 m_nReplicas(100),
61 m_ReplicaRandomSeed(12345) {
62
63 declareProperty("MuonQuality", m_muonquality); // HighPt,Tight,Medium,Loose,LowPt
64 declareProperty("CalibrationRelease", m_calibration_version);
65 // these are for debugging / testing, *not* for general use!
66 declareProperty("filename", m_fileName);
67 declareProperty("CustomInputFolder", m_custom_dir);
68 declareProperty("Binning", m_binning); // fine or coarse
69 declareProperty("UseExperimental", m_experimental); // enable experimental features like single muon SF
70 //Properties needed for TOY setup for a given trigger: No replicas if m_replicaTriggerList is empty
71 declareProperty("ReplicaTriggerList", m_replicaTriggerList, "List of triggers on which we want to generate stat. uncertainty toy replicas.");
72 declareProperty("NReplicas", m_nReplicas, "Number of generated toy replicas, if replicas are required.");
73 declareProperty("ReplicaRandomSeed", m_ReplicaRandomSeed, "Random seed for toy replica generation.");
74 declareProperty("AllowZeroSF", m_allowZeroSF, "If a trigger is not available will return 0 instead of throwing an error. More difficult to spot configuration issues. Use at own risk");
75 declareProperty("forceYear", m_forceYear, "Only for developers. Never use this in any analysis!!!!!!");
76 declareProperty("forcePeriod", m_forcePeriod, "Only for developers. Never use this in any analysis!!!!!!");
77 }
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
std::vector< std::string > m_replicaTriggerList
std::set< std::string > m_replicaSet
std::map< EffiHistoIdent, std::vector< TH1_Ptr > > m_efficiencyMapReplicaArray
std::unordered_map< CP::SystematicSet, CP::SystematicSet > m_systFilter

◆ ~MuonTriggerScaleFactors()

CP::MuonTriggerScaleFactors::~MuonTriggerScaleFactors ( )
virtual

Definition at line 79 of file MuonTriggerScaleFactors.cxx.

79{ }

Member Function Documentation

◆ affectingSystematics()

CP::SystematicSet CP::MuonTriggerScaleFactors::affectingSystematics ( ) const
virtual

returns: the list of all systematics this tool can be affected by

Implements CP::IReentrantSystematicsTool.

Definition at line 880 of file MuonTriggerScaleFactors.cxx.

880 {
881 CP::SystematicSet mySysSet;
882
883 mySysSet.insert(CP::SystematicVariation("MUON_EFF_TrigSystUncertainty", 1));
884 mySysSet.insert(CP::SystematicVariation("MUON_EFF_TrigSystUncertainty", -1));
885
886 //Consider full statUncertainty if TOY replicas are not used
887 if (m_replicaTriggerList.size() == 0) {
888 mySysSet.insert(CP::SystematicVariation("MUON_EFF_TrigStatUncertainty", 1));
889 mySysSet.insert(CP::SystematicVariation("MUON_EFF_TrigStatUncertainty", -1));
890 } else {
891 for (int i = 0; i < m_nReplicas; ++i) { //TOFIX Hack with just up variations! needs ASG reserved words for a clean handling//+++++++
892 mySysSet.insert(CP::SystematicVariation(Form("MUON_EFF_Trig_MCTOY%03d", i), 1));
893 }
894 }
895
896 return mySysSet;
897 }
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set

◆ appliedSystematics()

const CP::SystematicSet & CP::MuonTriggerScaleFactors::appliedSystematics ( ) const
inlineprivate

Definition at line 74 of file MuonTriggerScaleFactors.h.

74 {
76 }

◆ applySystematicVariation()

StatusCode CP::MuonTriggerScaleFactors::applySystematicVariation ( const CP::SystematicSet & systConfig)
virtual

effects: configure this tool for the given list of systematic variations.

any requested systematics that are not affecting this tool will be silently ignored (unless they cause other errors). failures: systematic unknown failures: requesting multiple variations on the same systematic (e.g. up & down) failures: requesting an unsupported variation on an otherwise supported systematic (e.g. a 2 sigma variation and the tool only supports 1 sigma variations) failures: unsupported combination of supported systematic failures: other tool specific errors

Implements CP::ISystematicsTool.

Definition at line 914 of file MuonTriggerScaleFactors.cxx.

914 {
915 // First, check if we already know this systematic configuration
916 auto itr = m_systFilter.find(systConfig);
917
918 // If it's a new input set, we need to filter it
919 if (itr == m_systFilter.end()) {
920
921 // New systematic. We need to parse it.
922 static const CP::SystematicSet affectingSys = affectingSystematics();
923 CP::SystematicSet filteredSys;
924 if (!CP::SystematicSet::filterForAffectingSystematics(systConfig, affectingSys, filteredSys)) {
925 ATH_MSG_ERROR("Unsupported combination of systematics passed to the tool!");
926 return StatusCode::FAILURE;
927 }
928
929 // Insert filtered set into the map
930 itr = m_systFilter.insert(std::make_pair(systConfig, filteredSys)).first;
931 }
932
933 CP::SystematicSet& mySysConf = itr->second;
934
935 // Check to see if the set of variations tries to add in the uncertainty up and down. Since the errors
936 // are symetric this would result in 0 and so should not be done.
937 static const CP::SystematicVariation stat_up("MUON_EFF_TrigStatUncertainty", 1);
938 static const CP::SystematicVariation stat_down("MUON_EFF_TrigStatUncertainty", -1);
939 static const CP::SystematicVariation syst_up("MUON_EFF_TrigSystUncertainty", 1);
940 static const CP::SystematicVariation syst_down("MUON_EFF_TrigSystUncertainty", -1);
941
942 if ((mySysConf.matchSystematic(stat_up) && mySysConf.matchSystematic(stat_down)) || (mySysConf.matchSystematic(syst_up) && mySysConf.matchSystematic(syst_down))) {
943 return StatusCode::FAILURE;
944 }
945
946 m_appliedSystematics = &mySysConf;
947 return StatusCode::SUCCESS;
948 }
#define ATH_MSG_ERROR(x)
virtual CP::SystematicSet affectingSystematics() const
returns: the list of all systematics this tool can be affected by
bool matchSystematic(const SystematicVariation &systematic, MATCHTYPE type=FULL) const
static StatusCode filterForAffectingSystematics(const SystematicSet &systConfig, const SystematicSet &affectingSystematics, SystematicSet &filteredSystematics)
description: filter the systematics for the affected systematics returns: success guarantee: strong f...

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ encodeHistoName() [1/2]

unsigned int CP::MuonTriggerScaleFactors::encodeHistoName ( const std::string & period,
const std::string & Trigger,
bool isData,
const std::string & Systematic,
bool isBarrel = true ) const
private

Definition at line 392 of file MuonTriggerScaleFactors.cxx.

392 {
393 //keep the string as short as possible
394 const std::string histName = period + "_" + Trigger + "_" + (isBarrel ? "b" : "e") + "_" + (isData ? "data" : "mc") + Systematic;
395 return std::hash<std::string>()(histName);
396 }

◆ encodeHistoName() [2/2]

unsigned int CP::MuonTriggerScaleFactors::encodeHistoName ( const std::string & Trigger,
const TrigMuonEff::Configuration & configuration,
const std::string & Systematic,
bool isBarrel = true ) const
private

Definition at line 398 of file MuonTriggerScaleFactors.cxx.

398 {
399 //keep the string as short as possible
400 return encodeHistoName(getDataPeriod(), Trigger, configuration.isData, Systematic, isBarrel);
401
402 }
unsigned int encodeHistoName(const std::string &period, const std::string &Trigger, bool isData, const std::string &Systematic, bool isBarrel=true) const

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ generateReplicas()

std::vector< TH1_Ptr > CP::MuonTriggerScaleFactors::generateReplicas ( TH1_Ptr h,
int nrep,
int seed ) const
private

Definition at line 347 of file MuonTriggerScaleFactors.cxx.

347 {
348 TRandom3 Rndm(seed);
349 std::vector<TH1_Ptr> replica_v;
350 const int xbins = h->GetNbinsX(), ybins = h->GetNbinsY();
351
352 for (int t = 0; t < nrep; ++t) {
353 TH2* replica = dynamic_cast<TH2*>(h->Clone(Form("rep%d_%s", t, h->GetName())));
354
355 for (int x_i = 0; x_i <= xbins; ++x_i) {
356 for (int y_i = 0; y_i <= ybins; ++y_i) {
357 replica->SetBinContent(x_i, y_i, Rndm.Gaus(h->GetBinContent(x_i, y_i), h->GetBinError(x_i, y_i)));
358 }
359 }
360 replica_v.push_back(TH1_Ptr(replica));
361 }
362 return replica_v;
363 }
std::shared_ptr< TH1 > TH1_Ptr

◆ getBinNumber()

int CP::MuonTriggerScaleFactors::getBinNumber ( const xAOD::Muon & muon,
const std::string & trigger ) const
virtual

Implements CP::IMuonTriggerScaleFactors.

Definition at line 370 of file MuonTriggerScaleFactors.cxx.

370 {
371 if(!m_experimental){
372 ATH_MSG_ERROR("MuonTriggerScaleFactors::getTriggerScaleFactor This is an experimental function. If you really know what you are doing set UseExperimental property.");
374 }
375
376 const double mu_eta = muon.eta();
377 const double mu_phi = muon.phi();
378 bool isBarrel = std::abs(mu_eta) < muon_barrel_endcap_boundary;
379 TH1_Ptr cit = getEfficiencyHistogram(trigger, true, "nominal", isBarrel);
380 if(!cit.get()){
381 if(!m_allowZeroSF)
382 ATH_MSG_ERROR("Could not find efficiency map for muon with eta: " << mu_eta << " and phi: " << mu_phi << ". Something is inconsistent. Please check your settings for year, mc and trigger." );
383 return -1;
384 }
385 auto eff_h2 = cit;
386 double mu_phi_corr = mu_phi;
387 if (mu_phi_corr < eff_h2->GetYaxis()->GetXmin()) mu_phi_corr += 2.0 * M_PI;
388 if (mu_phi_corr > eff_h2->GetYaxis()->GetXmax()) mu_phi_corr -= 2.0 * M_PI;
389 return eff_h2->FindFixBin(mu_eta, mu_phi_corr);
390 }
#define M_PI
@ Error
Some error happened during the object correction.
virtual std::shared_ptr< TH1 > getEfficiencyHistogram(unsigned int year, const std::string &period, const std::string &trigger, bool isData, const std::string &Systematic, bool isBarrel=true) const
static const double muon_barrel_endcap_boundary

◆ getDataPeriod() [1/3]

std::string CP::MuonTriggerScaleFactors::getDataPeriod ( ) const
protected

Definition at line 737 of file MuonTriggerScaleFactors.cxx.

737 {
738 return getDataPeriod(getRunNumber());
739 }

◆ getDataPeriod() [2/3]

std::string CP::MuonTriggerScaleFactors::getDataPeriod ( unsigned int run) const
protected

Definition at line 741 of file MuonTriggerScaleFactors.cxx.

741 {
742 return getDataPeriod(run, getYear(run));
743 }
unsigned int getYear(unsigned int run) const

◆ getDataPeriod() [3/3]

std::string CP::MuonTriggerScaleFactors::getDataPeriod ( unsigned int runNumber,
unsigned int year ) const
protected

◆ getDimuonEfficiency()

CorrectionCode CP::MuonTriggerScaleFactors::getDimuonEfficiency ( Double_t & eff,
const TrigMuonEff::Configuration & configuration,
const xAOD::MuonContainer & mucont,
const std::string & chain,
const std::string & systematic ) const
privatevirtual

Definition at line 678 of file MuonTriggerScaleFactors.cxx.

678 {
679
680 std::string trigger = getTriggerCorrespondingToDimuonTrigger(chain);
681 Int_t threshold;
682 CorrectionCode result = getThreshold(threshold, trigger);
683 if (result != CorrectionCode::Ok) return result;
684
687
688 Double_t eff1 = 0;
689 if ((**mu1).pt() > threshold) {
690 CorrectionCode result1 = getMuonEfficiency(eff1, configuration, (**mu1), trigger, systematic);
691 if (result1 != CorrectionCode::Ok) return result1;
692 }
693 Double_t eff2 = 0;
694 if ((**mu2).pt() > threshold) {
695 CorrectionCode result2 = getMuonEfficiency(eff2, configuration, (**mu2), trigger, systematic);
696 if (result2 != CorrectionCode::Ok) return result2;
697 }
698
699 eff = eff1 * eff2;
700 return CorrectionCode::Ok;
701 }
@ Ok
The correction was done successfully.
virtual CorrectionCode getMuonEfficiency(Double_t &eff, const TrigMuonEff::Configuration &configuration, const xAOD::Muon &muon, const std::string &trigger, const std::string &systematic) const
std::string getTriggerCorrespondingToDimuonTrigger(const std::string &trigger) const
CorrectionCode getThreshold(Int_t &threshold, const std::string &trigger) const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.

◆ getEfficiencyHistogram() [1/2]

TH1_Ptr CP::MuonTriggerScaleFactors::getEfficiencyHistogram ( const std::string & trigger,
bool isData,
const std::string & Systematic,
bool isBarrel = true ) const
protectedvirtual

Definition at line 412 of file MuonTriggerScaleFactors.cxx.

412 {
413 unsigned int run = getRunNumber();
414 return getEfficiencyHistogram(getYear(run), getDataPeriod(run), trigger, isData, Systematic, isBarrel);
415 }

◆ getEfficiencyHistogram() [2/2]

TH1_Ptr CP::MuonTriggerScaleFactors::getEfficiencyHistogram ( unsigned int year,
const std::string & period,
const std::string & trigger,
bool isData,
const std::string & Systematic,
bool isBarrel = true ) const
protectedvirtual

Definition at line 403 of file MuonTriggerScaleFactors.cxx.

403 {
404 EffiHistoIdent Ident = EffiHistoIdent(YearPeriod(year, period), encodeHistoName(period, trigger, isData, Systematic, isBarrel));
405 EfficiencyMap::const_iterator Itr = m_efficiencyMap.find(Ident);
406
407 if (Itr == m_efficiencyMap.end()) {
408 return TH1_Ptr();
409 }
410 return Itr->second;
411 }
std::pair< YearPeriod, unsigned int > EffiHistoIdent
std::pair< unsigned int, std::string > YearPeriod

◆ getKey()

SG::sgkey_t asg::AsgTool::getKey ( const void * ptr) const
inherited

Get the (hashed) key of an object that is in the event store.

This is a bit of a special one. StoreGateSvc and xAOD::TEvent both provide ways for getting the SG::sgkey_t key for an object that is in the store, based on a bare pointer. But they provide different interfaces for doing so.

In order to allow tools to efficiently perform this operation, they can use this helper function.

See also
asg::AsgTool::getName
Parameters
ptrThe bare pointer to the object that the event store should know about
Returns
The hashed key of the object in the store. If not found, an invalid (zero) key.

Definition at line 119 of file AsgTool.cxx.

119 {
120
121#ifdef XAOD_STANDALONE
122 // In case we use @c xAOD::TEvent, we have a direct function call
123 // for this.
124 return evtStore()->event()->getKey( ptr );
125#else
126 const SG::DataProxy* proxy = evtStore()->proxy( ptr );
127 return ( proxy == nullptr ? 0 : proxy->sgkey() );
128#endif // XAOD_STANDALONE
129 }
ServiceHandle< StoreGateSvc > & evtStore()

◆ getMuonEfficiency()

CorrectionCode CP::MuonTriggerScaleFactors::getMuonEfficiency ( Double_t & eff,
const TrigMuonEff::Configuration & configuration,
const xAOD::Muon & muon,
const std::string & trigger,
const std::string & systematic ) const
privatevirtual

Definition at line 417 of file MuonTriggerScaleFactors.cxx.

417 {
418 const double mu_eta = muon.eta();
419 const double mu_phi = muon.phi();
420 bool isBarrel = std::abs(mu_eta) < muon_barrel_endcap_boundary;
421
422 TH1_Ptr eff_h2 = nullptr;
423 if (configuration.replicaIndex >= 0) { //Only look into the replicas if asking for them
424
425 unsigned int run = getRunNumber();
426 EffiHistoIdent Ident = EffiHistoIdent(YearPeriod(getYear(run), getDataPeriod(run)), encodeHistoName(getDataPeriod(run), trigger, configuration.isData, "repl", isBarrel));
427 std::map<EffiHistoIdent, std::vector<TH1_Ptr> >::const_iterator cit = m_efficiencyMapReplicaArray.find(Ident);
428 if (cit == m_efficiencyMapReplicaArray.end()) {
429 if (m_allowZeroSF) {
430 ATH_MSG_WARNING("Could not find what you are looking for in the efficiency map. The trigger you are looking for, year and mc are not consistent, or the trigger is unavailable in this data period. Returning efficiency = 0.");
431 eff = 0.;
432 return CorrectionCode::Ok;
433 }
434
435 else {
436 ATH_MSG_ERROR("Could not find what you are looking for in the efficiency map. The trigger you are looking for, year and mc are not consistent, or the trigger is unavailable in this data period. Please check how you set up the tool.");
438 }
439 }
440
441 if (configuration.replicaIndex >= (int) cit->second.size()) {
442 ATH_MSG_ERROR("MuonTriggerScaleFactors::getMuonEfficiency ; index for replicated histograms is out of range.");
444 }
445
446 eff_h2 = cit->second[configuration.replicaIndex];
447 } else { //Standard case, look into the usual eff map
448 TH1_Ptr cit = getEfficiencyHistogram(trigger, configuration.isData, systematic, isBarrel);
449 if (cit.get() == nullptr) {
450 if (m_allowZeroSF) {
451 ATH_MSG_WARNING("Could not find what you are looking for in the efficiency map. The trigger you are looking for, year and mc are not consistent, or the trigger is unavailable in this data period. Returning efficiency = 0.");
452 eff = 0.;
453 return CorrectionCode::Ok;
454 } else {
455 ATH_MSG_ERROR("Could not find what you are looking for in the efficiency map. The trigger you are looking for, year and mc are not consistent, or the trigger is unavailable in this data period. Please check how you set up the tool.");
457 }
458 }
459 eff_h2 = cit;
460 }
461
462 double mu_phi_corr = mu_phi;
463 if (mu_phi_corr < eff_h2->GetYaxis()->GetXmin()) mu_phi_corr += 2.0 * M_PI;
464 if (mu_phi_corr > eff_h2->GetYaxis()->GetXmax()) mu_phi_corr -= 2.0 * M_PI;
465
466 const int bin = eff_h2->FindFixBin(mu_eta, mu_phi_corr);
467 const double efficiency = eff_h2->GetBinContent(bin);
468
469 eff = efficiency;
470
471 ATH_MSG_DEBUG("getMuonEfficiency [eta,phi,phi_corr]=[" << mu_eta << "," << mu_phi << "," << mu_phi_corr << "], ibin=" << bin << " eff=" << eff);
472
473 return CorrectionCode::Ok;
474
475 }
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
@ OutOfValidityRange
Input object is out of validity range.
void efficiency(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
int replicaIndex
index of replicated histograms to access

◆ getName()

const std::string & asg::AsgTool::getName ( const void * ptr) const
inherited

Get the name of an object that is / should be in the event store.

This is a bit of a special one. StoreGateSvc and xAOD::TEvent both provide ways for getting the std::string name for an object that is in the store, based on a bare pointer. But they provide different interfaces for doing so.

In order to allow tools to efficiently perform this operation, they can use this helper function.

See also
asg::AsgTool::getKey
Parameters
ptrThe bare pointer to the object that the event store should know about
Returns
The string name of the object in the store. If not found, an empty string.

Definition at line 106 of file AsgTool.cxx.

106 {
107
108#ifdef XAOD_STANDALONE
109 // In case we use @c xAOD::TEvent, we have a direct function call
110 // for this.
111 return evtStore()->event()->getName( ptr );
112#else
113 const SG::DataProxy* proxy = evtStore()->proxy( ptr );
114 static const std::string dummy = "";
115 return ( proxy == nullptr ? dummy : proxy->name() );
116#endif // XAOD_STANDALONE
117 }

◆ getProperty()

template<class T>
const T * asg::AsgTool::getProperty ( const std::string & name) const
inherited

Get one of the tool's properties.

◆ getReplica_index()

int CP::MuonTriggerScaleFactors::getReplica_index ( const std::string & sysBaseName,
const std::string & trigStr ) const
virtual

Definition at line 283 of file MuonTriggerScaleFactors.cxx.

283 {
284 if (m_replicaSet.find(trigStr) == m_replicaSet.end()) return -1; //No toys for this trigger
285 std::size_t pos = sysBaseName.find("MCTOY");
286 if (pos == std::string::npos) return -1; //sys variation not affected by TOYS
287 return atoi(sysBaseName.substr(pos + 5, pos + 8).c_str()); //toys for this trigger are around get the 3-digit number
288 }
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...

◆ getRunNumber()

unsigned int CP::MuonTriggerScaleFactors::getRunNumber ( ) const
protected

Definition at line 825 of file MuonTriggerScaleFactors.cxx.

825 {
826 static const SG::AuxElement::ConstAccessor<unsigned int> acc_rnd("RandomRunNumber");
827 SG::ReadHandle<xAOD::EventInfo> info(m_eventInfo);
828 if (info.operator->()==nullptr) {
829 ATH_MSG_FATAL("Could not retrieve the xAOD::EventInfo with name: " << m_eventInfo.key() << ". Exiting the code.");
830 throw std::invalid_argument{""};
831 }
832 if (!info->eventType(xAOD::EventInfo::IS_SIMULATION)) {
833 ATH_MSG_DEBUG("The current event is a data event. Return runNumber instead.");
834 return info->runNumber();
835 }
836 if (!acc_rnd.isAvailable(*info)) {
837 if(m_forceYear == -1 && m_forcePeriod == "")
838 ATH_MSG_FATAL("Failed to find the RandomRunNumber decoration. Please call the apply() method from the PileupReweightingTool beforehand in order to get period dependent SFs");
839 throw std::invalid_argument{""};
840 } else if (acc_rnd(*info) == 0) {
841 ATH_MSG_FATAL("Pile up tool has given runNumber 0. Exiting the code.");
842 throw std::invalid_argument{""};
843 }
844
845 // standard behaviour for MC, get the random RunNumber
846 return acc_rnd(*info);
847 }
#define ATH_MSG_FATAL(x)
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo
@ IS_SIMULATION
true: simulation, false: data

◆ getTemporaryDirectory()

TDirectory * CP::MuonTriggerScaleFactors::getTemporaryDirectory ( void ) const
private

Definition at line 849 of file MuonTriggerScaleFactors.cxx.

849 {
850 gROOT->cd();
851 TDirectory* tempDir = 0;
852 int counter = 0;
853 while (not tempDir) {
854 std::stringstream dirname;
855 dirname << "MuonTriggerScaleFactorsTempDir_%i" << counter;
856 if (gROOT->GetDirectory((dirname.str()).c_str())) {
857 ++counter;
858 continue;
859 }
860 tempDir = gROOT->mkdir((dirname.str()).c_str());
861 if (not tempDir) {
862 ATH_MSG_ERROR("getTemporaryDirectory::Temporary directory could not be created");
863 }
864 }
865 return tempDir;
866 }
std::string dirname(std::string name)
Definition utils.cxx:200

◆ getThreshold()

CorrectionCode CP::MuonTriggerScaleFactors::getThreshold ( Int_t & threshold,
const std::string & trigger ) const
private

Definition at line 709 of file MuonTriggerScaleFactors.cxx.

709 {
710 std::size_t index = trigger.find("HLT_mu");
711 if (index != std::string::npos) {
712 std::string rawNumber = trigger.substr(index + 6);
713 if (!rawNumber.empty() && isdigit(rawNumber[0])) {
714 std::stringstream(rawNumber) >> threshold;
715 if (threshold < 10) threshold = 10000;
716 else threshold = (threshold + 1) * 1000;
717 return CorrectionCode::Ok;
718 }
719 }
720 ATH_MSG_ERROR("MuonTriggerScaleFactors::getThreshold Could not extract threshold for trigger " << trigger);
722 }
str index
Definition DeMoScan.py:362

◆ getTriggerCorrespondingToDimuonTrigger()

std::string CP::MuonTriggerScaleFactors::getTriggerCorrespondingToDimuonTrigger ( const std::string & trigger) const
private

Definition at line 703 of file MuonTriggerScaleFactors.cxx.

703 {
704 if (trigger.find("2mu10") != std::string::npos) return "HLT_mu10";
705 if (trigger.find("2mu14") != std::string::npos) return "HLT_mu14";
706 throw std::runtime_error("Unknown dimuon trigger");
707 }

◆ getTriggerEfficiency()

CorrectionCode CP::MuonTriggerScaleFactors::getTriggerEfficiency ( const xAOD::Muon & mu,
Double_t & efficiency,
const std::string & trigger,
Bool_t dataType ) const
virtual

Implements CP::IMuonTriggerScaleFactors.

Definition at line 290 of file MuonTriggerScaleFactors.cxx.

290 {
291 if (trigger.empty()) {
292 ATH_MSG_ERROR("MuonTriggerScaleFactors::getTriggerEfficiency Trigger must have value.");
294 }
295 TrigMuonEff::Configuration configuration;
296 configuration.isData = dataType;
297 configuration.replicaIndex = -1;
298 Int_t threshold;
299 CorrectionCode result = getThreshold(threshold, trigger);
300 if (result != CorrectionCode::Ok) return result;
301 if (mu.pt() < threshold) {
302 efficiency = 0;
303 return CorrectionCode::Ok;
304 }
305
306 // Pre-define uncertainty variations
307 static const CP::SystematicVariation stat_up("MUON_EFF_TrigStatUncertainty", 1);
308 static const CP::SystematicVariation stat_down("MUON_EFF_TrigStatUncertainty", -1);
309 static const CP::SystematicVariation syst_up("MUON_EFF_TrigSystUncertainty", 1);
310 static const CP::SystematicVariation syst_down("MUON_EFF_TrigSystUncertainty", -1);
311
312 std::string systype = "";
313 if (appliedSystematics().matchSystematic(syst_down) && !dataType) {
314 systype = "syst_down";
315 } else if (appliedSystematics().matchSystematic(syst_up) && !dataType) {
316 systype = "syst_up";
317 } else if (appliedSystematics().matchSystematic(stat_down)) {
318 systype = "stat_down";
319 } else if (appliedSystematics().matchSystematic(stat_up)) {
320 systype = "stat_up";
321 } else {
322 systype = "nominal";
323 }
324
325 // Toys, if found, will overwrite the data hists stat with the generated toy
326 //+++++++++++++
327 // The best way is the use of filterByName with the 000MCTOY at the end. See:
328 // if( !(appliedSystematics().filterByBaseName("MUON_EFF_Trig_MCTOY000")).empty()){//The following is a hack!!!
329 //++++++++++THE FOLLOWING IS A PARTIAL HACK!!!
330 if (!appliedSystematics().empty() && configuration.isData == true) {
331 configuration.replicaIndex = getReplica_index(appliedSystematics().begin()->basename(), trigger);
332 if (configuration.replicaIndex != -1) systype = "replicas";
333 }
334 CorrectionCode cc = getMuonEfficiency(efficiency, configuration, mu, trigger, systype);
335 return cc;
336 }
static const Attributes_t empty
virtual int getReplica_index(const std::string &sysBaseName, const std::string &trigStr) const
const CP::SystematicSet & appliedSystematics() const
std::string basename(std::string name)
Definition utils.cxx:207

◆ getTriggerScaleFactor() [1/2]

CorrectionCode CP::MuonTriggerScaleFactors::getTriggerScaleFactor ( const xAOD::Muon & muon,
Double_t & triggersf,
const std::string & trigger ) const
virtual

Implements CP::IMuonTriggerScaleFactors.

Definition at line 234 of file MuonTriggerScaleFactors.cxx.

234 {
235 if(!m_experimental){
236 ATH_MSG_ERROR("MuonTriggerScaleFactors::getTriggerScaleFactor This is an experimental function. If you really know what you are doing set UseExperimental property.");
238 }
239
240 if (trigger.empty()) {
241 ATH_MSG_ERROR("MuonTriggerScaleFactors::getTriggerScaleFactor Trigger must have value.");
243 }
244
245 TrigMuonEff::Configuration configuration;
246
247 if (trigger == "HLT_mu8noL1")
248 ATH_MSG_WARNING("What you are trying to do is not correct. For di-muon triggers you should get the efficiency with getTriggerEfficiency and compute the SF by yourself.");
249 else if (trigger.find("HLT_2mu10") != std::string::npos || trigger.find("HLT_2mu14") != std::string::npos)
250 ATH_MSG_WARNING("Di-muon trigger scale factors for single reco muons are not supported!");
251 else
252 return GetTriggerSF(triggersf, configuration, muon, trigger);
253 return CorrectionCode::Ok;
254 }
virtual CorrectionCode GetTriggerSF(Double_t &TriggerSF, TrigMuonEff::Configuration &configuration, const xAOD::MuonContainer &mucont, const std::string &trigger) const

◆ getTriggerScaleFactor() [2/2]

CorrectionCode CP::MuonTriggerScaleFactors::getTriggerScaleFactor ( const xAOD::MuonContainer & mucont,
Double_t & triggersf,
const std::string & trigger ) const
virtual

Implements CP::IMuonTriggerScaleFactors.

Definition at line 256 of file MuonTriggerScaleFactors.cxx.

256 {
257 if (trigger.empty()) {
258 ATH_MSG_ERROR("MuonTriggerScaleFactors::getTriggerScaleFactor Trigger must have value.");
260 }
261
262 TrigMuonEff::Configuration configuration;
263
264 if (trigger == "HLT_mu8noL1") {
265 ATH_MSG_WARNING("What you are trying to do is not correct. For di-muon triggers you should get the efficiency with getTriggerEfficiency and compute the SF by yourself.");
266 }
267 else if (trigger.find("HLT_2mu10") != std::string::npos || trigger.find("HLT_2mu14") != std::string::npos) {
268 CorrectionCode cc = GetTriggerSF_dimu(triggersf, configuration, mucont, trigger);
269 return cc;
270 } else {
271 CorrectionCode cc = GetTriggerSF(triggersf, configuration, mucont, trigger);
272 return cc;
273 }
274 return CorrectionCode::Ok;
275 }
virtual CorrectionCode GetTriggerSF_dimu(Double_t &TriggerSF, TrigMuonEff::Configuration &configuration, const xAOD::MuonContainer &mucont, const std::string &trigger) const

◆ GetTriggerSF() [1/2]

CorrectionCode CP::MuonTriggerScaleFactors::GetTriggerSF ( Double_t & TriggerSF,
TrigMuonEff::Configuration & configuration,
const xAOD::Muon & muon,
const std::string & trigger ) const
privatevirtual

Definition at line 615 of file MuonTriggerScaleFactors.cxx.

615 {
616 Int_t threshold;
617 CorrectionCode result = getThreshold(threshold, trigger);
618 if (result != CorrectionCode::Ok)
619 return result;
620
621 double eff_data = 0., eff_mc = 0.;
622
623 if (mu.pt() < threshold) {
624 eff_data = 0.;
625 eff_mc = 0.;
626 TriggerSF = 1.;
627 return CorrectionCode::Ok;
628 }
629
630 std::string muon_trigger_name = trigger;
631 std::string data_err = "";
632 std::string mc_err = "";
633
634 // Pre-define uncertainty variations
635 static const CP::SystematicVariation stat_up("MUON_EFF_TrigStatUncertainty", 1);
636 static const CP::SystematicVariation stat_down("MUON_EFF_TrigStatUncertainty", -1);
637 static const CP::SystematicVariation syst_up("MUON_EFF_TrigSystUncertainty", 1);
638 static const CP::SystematicVariation syst_down("MUON_EFF_TrigSystUncertainty", -1);
639
640 if (appliedSystematics().matchSystematic(syst_down)) {
641 data_err = "nominal";
642 mc_err = "syst_up";
643 } else if (appliedSystematics().matchSystematic(syst_up)) {
644 data_err = "nominal";
645 mc_err = "syst_down";
646 } else if (appliedSystematics().matchSystematic(stat_down)) {
647 data_err = "stat_down";
648 mc_err = "nominal";
649 } else if (appliedSystematics().matchSystematic(stat_up)) {
650 data_err = "stat_up";
651 mc_err = "nominal";
652 } else {
653 data_err = "nominal";
654 mc_err = "nominal";
655 }
656
657 if (!appliedSystematics().empty()) {
658 configuration.replicaIndex = getReplica_index(appliedSystematics().begin()->basename(), trigger);
659 if (configuration.replicaIndex != -1) data_err = "replicas";
660 }
661
662 configuration.isData = true;
663 CorrectionCode result_data = getMuonEfficiency(eff_data, configuration, mu, muon_trigger_name, data_err);
664 if (result_data != CorrectionCode::Ok)
665 return result_data;
666 configuration.isData = false;
667 configuration.replicaIndex = -1;
668 CorrectionCode result_mc = getMuonEfficiency(eff_mc, configuration, mu, muon_trigger_name, mc_err);
669 if (result_mc != CorrectionCode::Ok)
670 return result_mc;
671 if (eff_data == 0)
672 TriggerSF = 0;
673 if (std::abs(eff_mc) > 0.0001)
674 TriggerSF = eff_data / eff_mc;
675 return CorrectionCode::Ok;
676 }

◆ GetTriggerSF() [2/2]

CorrectionCode CP::MuonTriggerScaleFactors::GetTriggerSF ( Double_t & TriggerSF,
TrigMuonEff::Configuration & configuration,
const xAOD::MuonContainer & mucont,
const std::string & trigger ) const
privatevirtual

Definition at line 536 of file MuonTriggerScaleFactors.cxx.

536 {
537 Int_t threshold;
538 CorrectionCode result = getThreshold(threshold, trigger);
539 if (result != CorrectionCode::Ok) return result;
540
541 double rate_not_fired_data = 1.;
542 double rate_not_fired_mc = 1.;
543
544 for (const auto mu : mucont) {
545
546 double eff_data = 0., eff_mc = 0.;
547
548 if (mu->pt() < threshold) {
549
550 eff_data = 0.;
551 eff_mc = 0.;
552
553 } else {
554
555 std::string muon_trigger_name = trigger;
556 std::string data_err = "";
557 std::string mc_err = "";
558
559 // Pre-define uncertainty variations
560 static const CP::SystematicVariation stat_up("MUON_EFF_TrigStatUncertainty", 1);
561 static const CP::SystematicVariation stat_down("MUON_EFF_TrigStatUncertainty", -1);
562 static const CP::SystematicVariation syst_up("MUON_EFF_TrigSystUncertainty", 1);
563 static const CP::SystematicVariation syst_down("MUON_EFF_TrigSystUncertainty", -1);
564
565 if (appliedSystematics().matchSystematic(syst_down)) {
566 data_err = "nominal";
567 mc_err = "syst_up";
568 } else if (appliedSystematics().matchSystematic(syst_up)) {
569 data_err = "nominal";
570 mc_err = "syst_down";
571 } else if (appliedSystematics().matchSystematic(stat_down)) {
572 data_err = "stat_down";
573 mc_err = "nominal";
574 } else if (appliedSystematics().matchSystematic(stat_up)) {
575 data_err = "stat_up";
576 mc_err = "nominal";
577 } else {
578 data_err = "nominal";
579 mc_err = "nominal";
580 }
581
582 //Toys, if found, will overwrite the data hists, on which toys for stat uncertainty have been generated
583 //+++++++++++++
584 //The best way is the use of filterByName with the 000MCTOY at the end. See:
585 // if( !(appliedSystematics().filterByBaseName("MUON_EFF_Trig_MCTOY000")).empty()){//The following is a hack!!!
586 //++++++++++The following is a hack!!!
587 if (!appliedSystematics().empty()) {
588 configuration.replicaIndex = getReplica_index(appliedSystematics().begin()->basename(), trigger);
589 if (configuration.replicaIndex != -1) data_err = "replicas";
590 }
591
592 configuration.isData = true;
593 CorrectionCode result_data = getMuonEfficiency(eff_data, configuration, *mu, muon_trigger_name, data_err);
594 if (result_data != CorrectionCode::Ok) return result_data;
595 configuration.isData = false;
596 configuration.replicaIndex = -1;
597 CorrectionCode result_mc = getMuonEfficiency(eff_mc, configuration, *mu, muon_trigger_name, mc_err);
598 if (result_mc != CorrectionCode::Ok) return result_mc;
599 }
600 rate_not_fired_data *= (1. - eff_data);
601 rate_not_fired_mc *= (1. - eff_mc);
602 }
603
604 double event_SF = 1.;
605 if (1 - rate_not_fired_data == 0) event_SF = 0;
606 if ((mucont.size()) and (std::abs(1. - rate_not_fired_mc) > 0.0001)) {
607
608 event_SF = (1. - rate_not_fired_data) / (1. - rate_not_fired_mc);
609 }
610 TriggerSF = event_SF;
611
612 return CorrectionCode::Ok;
613 }

◆ GetTriggerSF_dimu()

CorrectionCode CP::MuonTriggerScaleFactors::GetTriggerSF_dimu ( Double_t & TriggerSF,
TrigMuonEff::Configuration & configuration,
const xAOD::MuonContainer & mucont,
const std::string & trigger ) const
privatevirtual

Definition at line 477 of file MuonTriggerScaleFactors.cxx.

477 {
478
479 if (mucont.size() != 2) {
480 ATH_MSG_FATAL("MuonTriggerScaleFactors::GetTriggerSF;Currently dimuon trigger chains only implemented for events with exactly 2 muons.");
481 }
482 ATH_MSG_DEBUG("The trigger that you choose : " << trigger);
483
484 Double_t eff_data = 0;
485 Double_t eff_mc = 0;
486
487 std::string data_err = "";
488 std::string mc_err = "";
489
490 if (appliedSystematics().matchSystematic(CP::SystematicVariation("MUON_EFF_TrigSystUncertainty", -1))) {
491 data_err = "nominal";
492 mc_err = "syst_up";
493 } else if (appliedSystematics().matchSystematic(CP::SystematicVariation("MUON_EFF_TrigSystUncertainty", 1))) {
494 data_err = "nominal";
495 mc_err = "syst_down";
496 } else if (appliedSystematics().matchSystematic(CP::SystematicVariation("MUON_EFF_TrigStatUncertainty", -1))) {
497 data_err = "stat_down";
498 mc_err = "nominal";
499 } else if (appliedSystematics().matchSystematic(CP::SystematicVariation("MUON_EFF_TrigStatUncertainty", 1))) {
500 data_err = "stat_up";
501 mc_err = "nominal";
502 } else {
503 data_err = "nominal";
504 mc_err = "nominal";
505 }
506
507 //Toys, if found, will overwrite the data hists with the sys generated with one toy
508 //+++++++++++++
509 //The best way is the use of filterByName with the 000MCTOY at the end. See:
510 // if( !(appliedSystematics().filterByBaseName("MUON_EFF_Trig_MCTOY000")).empty()){//The following is a hack!!!
511 //++++++++++THE FOLLOWING IS A PARTIAL HACK!!!
512 if (!appliedSystematics().empty()) {
513 configuration.replicaIndex = getReplica_index(appliedSystematics().begin()->basename(), trigger);
514 if (configuration.replicaIndex != -1) data_err = "replicas";
515 }
516
517 configuration.isData = true;
518 CorrectionCode result = getDimuonEfficiency(eff_data, configuration, mucont, trigger, data_err);
519 if (result != CorrectionCode::Ok) return result;
520
521 configuration.isData = false;
522 configuration.replicaIndex = -1;
523 result = getDimuonEfficiency(eff_mc, configuration, mucont, trigger, mc_err);
524 if (result != CorrectionCode::Ok) return result;
525
526 double event_SF = 1.;
527
528 if (std::abs(1. - eff_mc) > 0.0001) {
529 event_SF = eff_data / eff_mc;
530 }
531
532 TriggerSF = event_SF;
533 return CorrectionCode::Ok;
534 }
virtual CorrectionCode getDimuonEfficiency(Double_t &eff, const TrigMuonEff::Configuration &configuration, const xAOD::MuonContainer &mucont, const std::string &chain, const std::string &systematic) const
size_type size() const noexcept
Returns the number of elements in the collection.

◆ getYear()

unsigned int CP::MuonTriggerScaleFactors::getYear ( unsigned int run) const
protected

Definition at line 724 of file MuonTriggerScaleFactors.cxx.

724 {
725 if(m_forceYear != -1){
726 return m_forceYear;
727 }
728
729 int year=2050;
730 auto lower = m_runNumber_year.lower_bound(run);
731 if (lower != m_runNumber_year.end()){
732 year=lower->second;
733 }
734 return year;
735 }
static const std::map< unsigned int, int > m_runNumber_year

◆ initialize()

StatusCode CP::MuonTriggerScaleFactors::initialize ( void )
virtual

Implements CP::IMuonTriggerScaleFactors.

Definition at line 203 of file MuonTriggerScaleFactors.cxx.

203 {
204
205 ATH_MSG_INFO("MuonQuality = '" << m_muonquality << "'");
206 ATH_MSG_INFO("Binning = '" << m_binning << "'");
207 ATH_MSG_INFO("CalibrationRelease = '" << m_calibration_version << "'");
208 ATH_MSG_INFO("CustomInputFolder = '" << m_custom_dir << "'");
209 ATH_MSG_INFO("AllowZeroSF = " << m_allowZeroSF);
210 ATH_MSG_INFO("experimental = " << m_experimental);
211
212 ATH_CHECK(m_eventInfo.initialize());
213
214 if (registerSystematics() != StatusCode::SUCCESS) {
215 return StatusCode::FAILURE;
216 }
217
218 if (applySystematicVariation(CP::SystematicSet()) != StatusCode::SUCCESS) {
219 ATH_MSG_ERROR("Could not configure for nominal settings");
220 return StatusCode::FAILURE;
221 }
222 // Initialize indexes of replicas for trigges which are asked
223 for (auto trigToy : m_replicaTriggerList)
224 m_replicaSet.insert(trigToy);
225
226 ATH_MSG_INFO("MuonTriggerScaleFactors::initialize");
227 constexpr auto years_to_run = std::to_array<int>({2015, 2016, 2017, 2018, 2022, 2023, 2024});
228 for (const int &year: years_to_run) {
230 }
231 return StatusCode::SUCCESS;
232 }
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
StatusCode LoadTriggerMap(unsigned int year)
virtual StatusCode applySystematicVariation(const CP::SystematicSet &systConfig)
effects: configure this tool for the given list of systematic variations.

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ isAffectedBySystematic()

bool CP::MuonTriggerScaleFactors::isAffectedBySystematic ( const CP::SystematicVariation & systematic) const
virtual

Declare the interface that this class provides.

returns: whether this tool is affected by the given systematics

Implements CP::ISystematicsTool.

Definition at line 871 of file MuonTriggerScaleFactors.cxx.

871 {
872 if (!systematic.empty()) {
873 CP::SystematicSet sys = affectingSystematics();
874 return sys.find(systematic) != sys.end();
875 }
876 return true;
877 }
bool empty() const
returns: whether this is an empty systematic, i.e.

◆ isTriggerSupported()

bool CP::MuonTriggerScaleFactors::isTriggerSupported ( const std::string & trigger) const
virtual

Returns whether the trigger is supported by the tool or not. The decision depends on the present (random)RunNumber.

Implements CP::IMuonTriggerScaleFactors.

Definition at line 365 of file MuonTriggerScaleFactors.cxx.

365 {
366 TH1_Ptr H1 = getEfficiencyHistogram(trigger, true, "nominal");
367 return H1.get() != nullptr;
368 }

◆ LoadTriggerMap()

StatusCode CP::MuonTriggerScaleFactors::LoadTriggerMap ( unsigned int year)
private

Definition at line 81 of file MuonTriggerScaleFactors.cxx.

81 {
82 std::string fileName = m_fileName;
83 if (fileName.empty()) {
84 if (year == 2015) fileName = "muontrigger_sf_2015_mc20a_v3.root";
85 else if (year == 2016) fileName = "muontrigger_sf_2016_mc20a_v3.root";
86 else if (year == 2017) fileName = "muontrigger_sf_2017_mc20d_v3.root";
87 else if (year == 2018) fileName = "muontrigger_sf_2018_mc20e_v3.root";
88 else if (year == 2022) fileName = "muontrigger_sf_2022_mc23a_v3.root";
89 else if (year == 2023) fileName = "muontrigger_sf_2023_mc23d_v3.root";
90 else if (year == 2024) fileName = "muontrigger_sf_2024_mc23e_v1.root";
91 else{
92 ATH_MSG_WARNING("There is no SF file for year " << year << " yet");
93 return StatusCode::SUCCESS;
94 }
95 }
96
97 TDirectory* origDir = gDirectory;
98
99 std::string filePath;
100
101 if (m_custom_dir.empty()) {
102 filePath = PathResolverFindCalibFile(Form("MuonEfficiencyCorrections/%s/%s", m_calibration_version.c_str(), fileName.c_str()));
103 if (filePath.empty()) {
104 ATH_MSG_ERROR("Unable to resolve the input file " << fileName << " via PathResolver.");
105 }
106 }
107 else {
108 ATH_MSG_INFO("Note: setting up with user specified input file location " << m_custom_dir << " - this is not encouraged!");
109 filePath = PathResolverFindCalibFile(Form("%s/%s", m_custom_dir.c_str(), fileName.c_str()));
110 }
111
112 TFile* file = TFile::Open(filePath.c_str());
113
114 if (file == nullptr || !file->IsOpen()) {
115 ATH_MSG_FATAL("MuonTriggerScaleFactors::initialize Couldn't open file " << filePath);
116 return StatusCode::FAILURE;
117 }
118 TDirectory* tempDir = getTemporaryDirectory();
119 tempDir->cd();
120
121 static const std::vector<std::string> type { "data", "mc" };
122 static const std::vector<std::string> region { "barrel", "endcap" };
123 static const std::vector<std::string> systematic { "nominal", "stat_up", "stat_down", "syst_up", "syst_down" };
124 if(m_muonquality.compare("LowPt") == 0)
125 m_muonquality = "Medium";
126 const std::string quality = m_muonquality;
127 TDirectory* qualityDirectory = file->GetDirectory(m_muonquality.c_str());
128 if (qualityDirectory == nullptr) {
129 ATH_MSG_FATAL("MuonTriggerScaleFactors::initialize cannot find directory with selected quality");
130 return StatusCode::FAILURE;
131 }
132 TKey* periodKey;
133 TIter nextPeriod(qualityDirectory->GetListOfKeys());
134 while ((periodKey = (TKey*) nextPeriod())) {
135 if (not periodKey->IsFolder()) continue;
136 TDirectory* periodDirectory = qualityDirectory->GetDirectory(periodKey->GetName());
137 std::string periodName = std::string(periodKey->GetName());
138 std::string periodName_InMap = periodName.substr(std::string("Period").size(), periodName.size());
139 YearPeriod period = YearPeriod(year, periodName_InMap);
140 TKey* triggerKey;
141 TIter nextTrigger(periodDirectory->GetListOfKeys());
142 while ((triggerKey = (TKey*) nextTrigger())) {
143 if (not triggerKey->IsFolder()) continue;
144 TDirectory* triggerDirectory = periodDirectory->GetDirectory(triggerKey->GetName());
145 std::string triggerName = std::string(triggerKey->GetName());
146 if(!std::set<std::string>{"HLT_mu26_ivarmedium", "HLT_mu50", "HLT_mu26_ivarmedium_OR_HLT_mu50"}.count(triggerName) && m_binning == "coarse"){
147 ATH_MSG_DEBUG("Coarse binning not supported for di-muon trigger legs at the moment");
148 continue;
149 }
150 for (const auto& iregion : region) {
151 bool isBarrel = iregion.find("barrel") != std::string::npos;
152 for (const auto& itype : type) {
153 bool isData = itype.find("data") != std::string::npos;
154 std::string histname = ("_MuonTrigEff_" + periodName + "_" + triggerName + "_" + quality + "_" + "_EtaPhi_" + m_binning + "_" + iregion + "_" + itype);
155 for (const auto& isys : systematic) {
156 if (itype.find("data") != std::string::npos && isys.find("syst") != std::string::npos) continue;
157 std::string path = "eff_etaphi_" + m_binning + "_" + iregion + "_" + itype + "_" + isys;
158 TH2* hist = dynamic_cast<TH2*>(triggerDirectory->Get(path.c_str()));
159 if (not hist) {
160
161 ATH_MSG_FATAL("MuonTriggerScaleFactors::initialize " << path << " not found under trigger " << triggerName << " and period " << periodName << " for year: " << year);
162 continue;
163 }
164 hist->SetDirectory(0);
165
166 EffiHistoIdent HistoId = EffiHistoIdent(period, encodeHistoName(periodName_InMap, triggerName, isData, isys, isBarrel));
167 if (m_efficiencyMap.find(HistoId) != m_efficiencyMap.end()) {
168 ATH_MSG_FATAL("MuonTriggerScaleFactors::initialize(): histogram " << path << " is duplicated for year" << year << " in period " << periodName);
169 return StatusCode::FAILURE;
170 }
171 m_efficiencyMap.insert(std::pair<EffiHistoIdent, TH1_Ptr>(HistoId, std::shared_ptr < TH1 > (hist)));
172
173 }
174 //If the trigger is chosen for toy evaluation, generate all the replicas from
175 // NOMINAL with STAT variations stored in the data hist, load them in corresponding vector
176 if (m_replicaSet.find(triggerName) != m_replicaSet.end() && itype.find("data") != std::string::npos) {
177
178 TH1_Ptr Nominal_H = getEfficiencyHistogram(year, periodName, triggerName, isData, "nominal", isBarrel);
179 TH1_Ptr StatUp_H = getEfficiencyHistogram(year, periodName, triggerName, isData, "stat_up", isBarrel);
180
181 TH1_Ptr tmp_h2 = TH1_Ptr(dynamic_cast<TH2F*>(Nominal_H->Clone(Form("tmp_h2_%s", Nominal_H->GetName()))));
182 const int xbins = tmp_h2->GetNbinsX(), ybins = tmp_h2->GetNbinsY();
183 for (int x_i = 0; x_i <= xbins; ++x_i) {
184 for (int y_i = 0; y_i <= ybins; ++y_i) {
185 double statErr = std::abs(tmp_h2->GetBinContent(x_i, y_i) - StatUp_H->GetBinContent(x_i, y_i));
186 tmp_h2->SetBinError(x_i, y_i, statErr);
187 }
188 }
189 m_efficiencyMapReplicaArray[EffiHistoIdent(period, encodeHistoName(periodName, triggerName, isData, "repl", isBarrel))] = generateReplicas(tmp_h2, m_nReplicas, m_ReplicaRandomSeed);
190 }
191 }
192 }
193 }
194 }
195 file->Close();
196 delete file;
197 origDir->cd();
198 return StatusCode::SUCCESS;
199 }
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
TDirectory * getTemporaryDirectory(void) const
std::vector< TH1_Ptr > generateReplicas(TH1_Ptr h, int nrep, int seed) const
path
python interpreter configuration --------------------------------------—
Definition athena.py:128
str filePath
Definition hancool.py:27
TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
TFile * file

◆ msg()

MsgStream & AthCommonMsg< AlgTool >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msg_level_name()

const std::string & asg::AsgTool::msg_level_name ( ) const
inherited

A deprecated function for getting the message level's name.

Instead of using this, weirdly named function, user code should get the string name of the current minimum message level (in case they really need it...), with:

MSG::name( msg().level() )

This function's name doesn't follow the ATLAS coding rules, and as such will be removed in the not too distant future.

Returns
The string name of the current minimum message level that's printed

Definition at line 101 of file AsgTool.cxx.

101 {
102
103 return MSG::name( msg().level() );
104 }
MsgStream & msg() const
const std::string & name(Level lvl)
Convenience function for translating message levels to strings.
Definition MsgLevel.cxx:19

◆ msgLvl()

bool AthCommonMsg< AlgTool >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ print()

◆ recommendedSystematics()

CP::SystematicSet CP::MuonTriggerScaleFactors::recommendedSystematics ( ) const
virtual

returns: the list of all systematics this tool recommends to use

Implements CP::IReentrantSystematicsTool.

Definition at line 910 of file MuonTriggerScaleFactors.cxx.

910 {
911 return affectingSystematics();
912 }

◆ registerSystematics()

StatusCode CP::MuonTriggerScaleFactors::registerSystematics ( )
private

Definition at line 900 of file MuonTriggerScaleFactors.cxx.

900 {
901 CP::SystematicRegistry& registry = CP::SystematicRegistry::getInstance();
902 if (registry.registerSystematics(*this) != StatusCode::SUCCESS) {
903 ATH_MSG_ERROR("Failed to add systematic to list of recommended systematics.");
904 return StatusCode::FAILURE;
905 }
906 return StatusCode::SUCCESS;
907 }
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

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< AlgTool > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ sysInitialize()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysInitialize ( )
overridevirtualinherited

Perform system initialization for an algorithm.

We override this to declare all the elements of handle key arrays at the end of initialization. See comments on updateVHKA.

Reimplemented in asg::AsgMetadataTool, AthCheckedComponent< AthAlgTool >, AthCheckedComponent<::AthAlgTool >, and DerivationFramework::CfAthAlgTool.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ m_allowZeroSF

bool CP::MuonTriggerScaleFactors::m_allowZeroSF
private

Definition at line 126 of file MuonTriggerScaleFactors.h.

◆ m_appliedSystematics

CP::SystematicSet* CP::MuonTriggerScaleFactors::m_appliedSystematics
private

Definition at line 115 of file MuonTriggerScaleFactors.h.

◆ m_binning

std::string CP::MuonTriggerScaleFactors::m_binning
private

Definition at line 125 of file MuonTriggerScaleFactors.h.

◆ m_calibration_version

std::string CP::MuonTriggerScaleFactors::m_calibration_version
private

Definition at line 123 of file MuonTriggerScaleFactors.h.

◆ m_custom_dir

std::string CP::MuonTriggerScaleFactors::m_custom_dir
private

Definition at line 124 of file MuonTriggerScaleFactors.h.

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default)

Definition at line 393 of file AthCommonDataStore.h.

◆ m_efficiencyMap

EfficiencyMap CP::MuonTriggerScaleFactors::m_efficiencyMap
private

Definition at line 117 of file MuonTriggerScaleFactors.h.

◆ m_efficiencyMapReplicaArray

std::map<EffiHistoIdent, std::vector<TH1_Ptr> > CP::MuonTriggerScaleFactors::m_efficiencyMapReplicaArray
private

Definition at line 118 of file MuonTriggerScaleFactors.h.

◆ m_eventInfo

SG::ReadHandleKey<xAOD::EventInfo> CP::MuonTriggerScaleFactors::m_eventInfo {this, "EventInfoContName", "EventInfo", "event info key"}
private

Definition at line 105 of file MuonTriggerScaleFactors.h.

105{this, "EventInfoContName", "EventInfo", "event info key"};

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default)

Definition at line 390 of file AthCommonDataStore.h.

◆ m_experimental

bool CP::MuonTriggerScaleFactors::m_experimental
private

Definition at line 127 of file MuonTriggerScaleFactors.h.

◆ m_fileName

std::string CP::MuonTriggerScaleFactors::m_fileName
private

Definition at line 116 of file MuonTriggerScaleFactors.h.

◆ m_forcePeriod

std::string CP::MuonTriggerScaleFactors::m_forcePeriod
private

Definition at line 129 of file MuonTriggerScaleFactors.h.

◆ m_forceYear

int CP::MuonTriggerScaleFactors::m_forceYear
private

Definition at line 128 of file MuonTriggerScaleFactors.h.

◆ m_muonquality

std::string CP::MuonTriggerScaleFactors::m_muonquality
private

Definition at line 120 of file MuonTriggerScaleFactors.h.

◆ m_nReplicas

int CP::MuonTriggerScaleFactors::m_nReplicas
private

Definition at line 133 of file MuonTriggerScaleFactors.h.

◆ m_ReplicaRandomSeed

int CP::MuonTriggerScaleFactors::m_ReplicaRandomSeed
private

Definition at line 134 of file MuonTriggerScaleFactors.h.

◆ m_replicaSet

std::set<std::string> CP::MuonTriggerScaleFactors::m_replicaSet
private

Definition at line 132 of file MuonTriggerScaleFactors.h.

◆ m_replicaTriggerList

std::vector<std::string> CP::MuonTriggerScaleFactors::m_replicaTriggerList
private

Definition at line 131 of file MuonTriggerScaleFactors.h.

◆ m_runNumber_year

const std::map< unsigned int, int > CP::MuonTriggerScaleFactors::m_runNumber_year
staticprivate
Initial value:
= {
{284484,2015},
{311481,2016},
{340453,2017},
{364292,2018},
{440613,2022},
{456749,2023},
{486706,2024}
}

Definition at line 137 of file MuonTriggerScaleFactors.h.

◆ m_systFilter

std::unordered_map<CP::SystematicSet, CP::SystematicSet> CP::MuonTriggerScaleFactors::m_systFilter
private

Definition at line 113 of file MuonTriggerScaleFactors.h.

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< AlgTool > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< AlgTool > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.


The documentation for this class was generated from the following files: