00001
00002
00003 #ifndef TOOLPROTOTYPES_TRIGGLOBALEFFICIENCYCORRECTIONTOOL_H
00004 #define TOOLPROTOTYPES_TRIGGLOBALEFFICIENCYCORRECTIONTOOL_H 1
00005
00006 #include "TriggerAnalysisInterfaces/ITrigGlobalEfficiencyCorrectionTool.h"
00007
00008 #include "AsgTools/AsgTool.h"
00009 #include "AsgTools/ToolHandleArray.h"
00010 #include "ElectronEfficiencyCorrection/IAsgElectronEfficiencyCorrectionTool.h"
00011 #include "MuonEfficiencyCorrections/IMuonTriggerScaleFactors.h"
00012
00013 #include <string>
00014 #include <vector>
00015 #include <map>
00016 #include <set>
00017 #include <tuple>
00018 #include <functional>
00019 #include <boost/container/container_fwd.hpp>
00020
00021 class TrigGlobalEfficiencyCorrectionTool: public asg::AsgTool, public virtual ITrigGlobalEfficiencyCorrectionTool
00022 {
00023 public:
00024 ASG_TOOL_CLASS(TrigGlobalEfficiencyCorrectionTool,ITrigGlobalEfficiencyCorrectionTool)
00025
00026 TrigGlobalEfficiencyCorrectionTool(const std::string& name);
00027 virtual ~TrigGlobalEfficiencyCorrectionTool();
00028
00029 virtual StatusCode initialize() override;
00030
00031 virtual CP::CorrectionCode getEfficiencyScaleFactor(const std::vector<const xAOD::Electron*>& electrons, const std::vector<const xAOD::Muon*>& muons, double& efficiencyScaleFactor) override;
00032 virtual CP::CorrectionCode getEfficiencyScaleFactor(unsigned runNumber, const std::vector<const xAOD::Electron*>& electrons, const std::vector<const xAOD::Muon*>& muons, double& efficiencyScaleFactor) override;
00033 virtual CP::CorrectionCode getEfficiency(const std::vector<const xAOD::Electron*>& electrons, const std::vector<const xAOD::Muon*>& muons, double& efficiencyData, double& efficiencyMc) override;
00034 virtual CP::CorrectionCode getEfficiency(unsigned runNumber, const std::vector<const xAOD::Electron*>& electrons, const std::vector<const xAOD::Muon*>& muons, double& efficiencyData, double& efficiencyMc) override;
00035
00036 virtual CP::CorrectionCode getEfficiencyScaleFactor(const std::vector<const xAOD::IParticle*>& particles, double& efficiencyScaleFactor) override;
00037 virtual CP::CorrectionCode getEfficiencyScaleFactor(unsigned runNumber, const std::vector<const xAOD::IParticle*>& particles, double& efficiencyScaleFactor) override;
00038 virtual CP::CorrectionCode getEfficiency(const std::vector<const xAOD::IParticle*>& particles, double& efficiencyData, double& efficiencyMc) override;
00039 virtual CP::CorrectionCode getEfficiency(unsigned runNumber, const std::vector<const xAOD::IParticle*>& particles, double& efficiencyData, double& efficiencyMc) override;
00040
00041 class Efficiencies;
00042 struct CachedEfficiencies;
00043 class LeptonDetails;
00044
00045 private:
00046 class Leptons;
00047
00048
00049 ToolHandleArray<IAsgElectronEfficiencyCorrectionTool> m_suppliedElectronEfficiencyTools;
00050 ToolHandleArray<IAsgElectronEfficiencyCorrectionTool> m_suppliedElectronScaleFactorTools;
00051 ToolHandleArray<CP::IMuonTriggerScaleFactors> m_suppliedMuonTools;
00052 std::map<std::string, std::string> m_legsPerTool;
00053 std::map<std::string, std::string> m_triggerCb;
00054 std::string m_triggerCb15;
00055 std::string m_triggerCb16;
00056 bool m_guessHierarchy = false;
00057 std::string m_leptonTagDecorations;
00058 std::map<std::string, std::string> m_tagsPerTool;
00059 std::map<std::string, std::string> m_electronLegsPerTag;
00060 std::map<std::string, std::string> m_muonLegsPerTag;
00061 unsigned long m_numberOfToys;
00062
00063
00064 std::hash<std::string> m_hasher;
00065
00066
00067 std::vector<std::tuple<std::string,float,float> > m_declaredHierarchies;
00068 std::map<size_t, std::tuple<int,size_t,size_t,size_t> > m_declaredTriggers;
00069 std::map<std::string, std::pair<int,int> > m_declaredPeriods;
00070
00071
00072 std::map<size_t,float > m_declaredThresholds;
00073 std::multimap<size_t,std::tuple<float,float,unsigned long> > m_cachedLegRankings;
00074 std::map<size_t, ToolHandle<IAsgElectronEfficiencyCorrectionTool>* > m_electronSfTools;
00075 std::map<size_t, ToolHandle<IAsgElectronEfficiencyCorrectionTool>* > m_electronEffTools;
00076 std::map<size_t, ToolHandle<CP::IMuonTriggerScaleFactors>* > m_muonTools;
00077 std::set<size_t> m_validLegTagPairs;
00078 std::map<size_t, std::string> m_muonTriggerNames;
00079 std::map<size_t, std::string> m_dictionary;
00080
00081 struct Hierarchy;
00082 Hierarchy* m_hierarchies = nullptr;
00083 size_t* m_hierarchyData = nullptr;
00084 short m_nHierarchies = 0;
00085
00086 CachedEfficiencies* m_cachedEfficiencies = nullptr;
00087 unsigned short m_cachedEfficienciesSize = 0;
00088 unsigned short m_cachedEfficienciesCapacity = 0;
00089
00090 bool m_usingTags = false;
00091
00092 bool m_initialized = false;
00093 CP::CorrectionCode m_cpCode = CP::CorrectionCode::Ok;
00094
00095 std::vector<std::tuple<SG::AuxElement::Decorator<char>,size_t,bool> > m_leptonTagDecorators;
00096 SG::AuxElement::Decorator<unsigned int> m_runNumberDecorator;
00097
00098 std::map<std::pair<unsigned,unsigned>, std::function<bool(const Leptons&,unsigned,Efficiencies&)> > m_globalEfficiencyFunctions;
00099
00100
00101 template<typename Key> using flat_set = boost::container::flat_set<Key>;
00102 void declareHierarchies();
00103 void declareTriggers();
00104 void declareThresholds();
00105 void declarePeriods();
00106 bool loadHierarchies();
00107 bool enumerateTools(bool& useDefaultTools);
00108 bool loadTriggerCombination(bool useDefaultTools);
00109 bool loadTagsConfiguration();
00110 bool getPeriodBoundaries(const std::string& period, std::pair<unsigned,unsigned>& boundaries);
00111 bool retrieveRunNumber(unsigned& runNumber);
00112 bool aboveThreshold(const LeptonDetails& p,size_t leg) const;
00113 bool chooseLegs(float pt, const std::map<size_t,bool>& legs, size_t& tightestMatchedLeg, size_t& loosestUnmatchedLeg);
00114 unsigned long getCachedTriggerLegsRanking(float pt, const flat_set<size_t>& legs);
00115 size_t getLoosestLegAboveThreshold(const LeptonDetails& lepton, const flat_set<size_t>& legs, bool& success);
00116 int getLoosestLegIndex(const LeptonDetails& lepton, const flat_set<size_t>& legs, bool& success);
00117 size_t getLoosestLeg(const LeptonDetails& lepton, const flat_set<size_t>& legs, bool& success);
00118 std::pair<size_t,size_t> getTwoLoosestLegs(const LeptonDetails& lepton, const flat_set<size_t>& legs, bool& success);
00119 bool rankTriggerLegs(float pt, const flat_set<size_t>& legs, unsigned long& ranking, float&ptmin, float&ptmax);
00120 std::vector<std::pair<size_t,unsigned>> sortLegs(float pt,const std::map<size_t,bool>& legs,float&ptmin,float&ptmax);
00121 template<class Particle> bool updateLeptonsContainer(Leptons& leptons, const std::vector<const Particle*>& particles);
00122 void updateMuonTriggerNames(size_t leg, const std::string& name);
00123 bool getTriggerLegEfficiencies(const xAOD::Electron* p, size_t leg, size_t tag, Efficiencies& efficiencies);
00124 bool getTriggerLegEfficiencies(const xAOD::Muon* p, unsigned runNumber, size_t leg, Efficiencies& efficiencies);
00125 Efficiencies getCachedTriggerLegEfficiencies(const LeptonDetails& p, unsigned runNumber, size_t leg, bool& success);
00126 CP::CorrectionCode getEfficiencyScaleFactor(unsigned runNumber, const Leptons& leptons, double& efficiencyScaleFactor);
00127 CP::CorrectionCode getEfficiency(unsigned runNumber, const Leptons& leptons, double& efficiencyData, double& efficiencyMc);
00128 bool checkAndRecord(CP::CorrectionCode&& cc)
00129 {
00130 cc.ignore();
00131 if(cc>m_cpCode) m_cpCode = cc;
00132 return cc==CP::CorrectionCode::Ok;
00133 }
00134
00135 enum
00136 {
00137 TT_GENERIC_SINGLELEPTON = 0x100,
00138 TT_SINGLE_E, TT_SINGLE_MU,
00139 TT_GENERIC_DILEPTON = 0x200,
00140 TT_2E_SYM, TT_2E_ASYM, TT_EMU, TT_2MU_SYM, TT_2MU_ASYM,
00141 TT_GENERIC_TRILEPTON = 0x400,
00142 TT_3E_SYM, TT_3E_HALFSYM, TT_3E_ASYM, TT_2E_MU_SYM, TT_2E_MU_ASYM,
00143 TT_2MU_E_SYM, TT_2MU_E_ASYM, TT_3MU_SYM, TT_3MU_HALFSYM, TT_3MU_ASYM
00144
00145 };
00146
00147 bool globalEfficiency_One1L(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t leg, Efficiencies&);
00148 bool globalEfficiency_One1EOne1Mu(const Leptons&, unsigned, size_t electronLeg, size_t muonLeg, Efficiencies&);
00149 bool globalEfficiency_Several1L(const Leptons&, unsigned, const flat_set<size_t>& electronLegs, const flat_set<size_t>& muonLegs, Efficiencies&);
00150 bool globalEfficiency_Several1L(const Leptons&, unsigned, xAOD::Type::ObjectType type, const flat_set<size_t>& legs, Efficiencies&);
00151 bool globalEfficiency_One2Lsym(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t leg, Efficiencies&);
00152 bool globalEfficiency_One2Lasym(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t leg1, size_t leg2, Efficiencies&);
00153 bool globalEfficiency_OneEMu(const Leptons&, unsigned, size_t electronLeg, size_t muonLeg, Efficiencies&);
00154 bool globalEfficiency_OneEMuSeveral1L(const Leptons&, unsigned, size_t dilepElectronLeg, size_t dilepMuonLeg,
00155 const flat_set<size_t>& singleElectronLegs, const flat_set<size_t>& singleMuonLegs, Efficiencies&);
00156 bool globalEfficiency_One2LsymSeveral1L(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t leg2L, const flat_set<size_t>& legs1L, Efficiencies&);
00157 bool globalEfficiency_One2LasymSeveral1L(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t leg2L1, size_t leg2L2, const flat_set<size_t>& legs1L, Efficiencies&);
00158 bool globalEfficiency_Two2LsymSeveral1L(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t leg2Lsym1, size_t leg2Lsym2, const flat_set<size_t>& legs1L, Efficiencies&);
00159 bool globalEfficiency_One2LasymOne2LsymSeveral1L(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t leg2Lasym1, size_t leg2Lasym2,
00160 size_t leg2Lsym, const flat_set<size_t>& legs1L, Efficiencies&);
00161 bool globalEfficiency_One3Lsym(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t leg, Efficiencies&);
00162 bool globalEfficiency_One3Lhalfsym(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t legAsym, size_t legSym, Efficiencies&);
00163 bool globalEfficiency_One2LOneEmu(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t dilepLeg1, size_t dilepLeg2,
00164 size_t emuElectronLeg, size_t emuMuonLeg, Efficiencies&);
00165 bool globalEfficiency_One2EOneEmuOne2Mu(const Leptons&, unsigned, size_t diELeg1, size_t diELeg2, size_t emuELeg, size_t emuMuLeg,
00166 size_t diMuLeg1, size_t diMuLeg2, Efficiencies&);
00167 bool globalEfficiency_One2EOneEmuOne2MuSeveral1L(const Leptons&, unsigned, size_t diELeg1, size_t diELeg2, size_t emuELeg, size_t emuMuLeg,
00168 size_t diMuLeg1, size_t diMuLeg2, const flat_set<size_t>& singleElectronLegs, const flat_set<size_t>& singleMuonLegs, Efficiencies&);
00169 bool globalEfficiency_Two2ETwoEmuTwo2MuSeveral1L(const Leptons&, unsigned, size_t diELegAsym1, size_t diELegAsym2, size_t diELegSym,
00170 size_t emu1ELeg, size_t emu1MuLeg, size_t emu2ELeg, size_t emu2MuLeg, size_t diMuLegAsym1, size_t diMuLegAsym2, size_t diMuLegSym,
00171 const flat_set<size_t>& singleElectronLegs, const flat_set<size_t>& singleMuonLegs, Efficiencies&);
00172 bool globalEfficiency_One3Lmixed(const Leptons& leptons, unsigned runNumber,
00173 xAOD::Type::ObjectType dominantType, size_t leg1a, size_t leg1b, size_t leg2, Efficiencies& globalEfficiencies);
00174 bool globalEfficiency_Two3LmixedCompl(const Leptons&, unsigned,
00175 size_t legE1a, size_t legE1b, size_t legE2, size_t legM1, size_t legM2a, size_t legM2b, Efficiencies&);
00176
00177 bool globalEfficiency_Toys(const Leptons&, unsigned, const std::vector<std::tuple<int,size_t,size_t,size_t> >& triggers, Efficiencies&);
00178 };
00179
00180 #endif //> !TOOLPROTOTYPES_TRIGGLOBALEFFICIENCYCORRECTION_H