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 std::map<std::string, std::string> m_overrideThresholds;
00062 unsigned long m_numberOfToys;
00063
00064
00065 std::hash<std::string> m_hasher;
00066
00067
00068 std::vector<std::tuple<std::string,float,float> > m_declaredHierarchies;
00069 std::map<size_t, std::tuple<int,size_t,size_t,size_t> > m_declaredTriggers;
00070 std::map<std::string, std::pair<int,int> > m_declaredPeriods;
00071
00072
00073 std::map<size_t,float > m_declaredThresholds;
00074 std::multimap<size_t,std::tuple<float,float,unsigned long> > m_cachedLegRankings;
00075 std::map<size_t, ToolHandle<IAsgElectronEfficiencyCorrectionTool>* > m_electronSfTools;
00076 std::map<size_t, ToolHandle<IAsgElectronEfficiencyCorrectionTool>* > m_electronEffTools;
00077 std::map<size_t, ToolHandle<CP::IMuonTriggerScaleFactors>* > m_muonTools;
00078 std::set<size_t> m_validLegTagPairs;
00079 std::map<size_t, std::string> m_muonTriggerNames;
00080 std::map<size_t, std::string> m_dictionary;
00081
00082 struct Hierarchy;
00083 Hierarchy* m_hierarchies = nullptr;
00084 size_t* m_hierarchyData = nullptr;
00085 short m_nHierarchies = 0;
00086
00087 CachedEfficiencies* m_cachedEfficiencies = nullptr;
00088 unsigned short m_cachedEfficienciesSize = 0;
00089 unsigned short m_cachedEfficienciesCapacity = 0;
00090
00091 bool m_usingTags = false;
00092
00093 bool m_initialized = false;
00094 CP::CorrectionCode m_cpCode = CP::CorrectionCode::Ok;
00095
00096 std::vector<std::tuple<SG::AuxElement::Decorator<char>,size_t,bool> > m_leptonTagDecorators;
00097 SG::AuxElement::Decorator<unsigned int> m_runNumberDecorator;
00098
00099 std::map<std::pair<unsigned,unsigned>, std::function<bool(const Leptons&,unsigned,Efficiencies&)> > m_globalEfficiencyFunctions;
00100
00101
00102 template<typename Key> using flat_set = boost::container::flat_set<Key>;
00103 void declareHierarchies();
00104 void declareTriggers();
00105 void declareThresholds();
00106 void declarePeriods();
00107 bool loadHierarchies();
00108 bool enumerateTools(bool& useDefaultTools);
00109 bool loadTriggerCombination(bool useDefaultTools);
00110 bool loadTagsConfiguration();
00111 bool getPeriodBoundaries(const std::string& period, std::pair<unsigned,unsigned>& boundaries);
00112 bool retrieveRunNumber(unsigned& runNumber);
00113 bool aboveThreshold(const LeptonDetails& p,size_t leg) const;
00114 bool chooseLegs(float pt, const std::map<size_t,bool>& legs, size_t& tightestMatchedLeg, size_t& loosestUnmatchedLeg);
00115 unsigned long getCachedTriggerLegsRanking(float pt, const flat_set<size_t>& legs);
00116 size_t getLoosestLegAboveThreshold(const LeptonDetails& lepton, const flat_set<size_t>& legs, bool& success);
00117 int getLoosestLegIndex(const LeptonDetails& lepton, const flat_set<size_t>& legs, bool& success);
00118 size_t getLoosestLeg(const LeptonDetails& lepton, const flat_set<size_t>& legs, bool& success);
00119 std::pair<size_t,size_t> getTwoLoosestLegs(const LeptonDetails& lepton, const flat_set<size_t>& legs, bool& success);
00120 bool rankTriggerLegs(float pt, const flat_set<size_t>& legs, unsigned long& ranking, float&ptmin, float&ptmax);
00121 std::vector<std::pair<size_t,unsigned>> sortLegs(float pt,const std::map<size_t,bool>& legs,float&ptmin,float&ptmax);
00122 template<class Particle> bool updateLeptonsContainer(Leptons& leptons, const std::vector<const Particle*>& particles);
00123 void updateMuonTriggerNames(size_t leg, const std::string& name);
00124 bool getTriggerLegEfficiencies(const xAOD::Electron* p, size_t leg, size_t tag, Efficiencies& efficiencies);
00125 bool getTriggerLegEfficiencies(const xAOD::Muon* p, unsigned runNumber, size_t leg, Efficiencies& efficiencies);
00126 Efficiencies getCachedTriggerLegEfficiencies(const LeptonDetails& p, unsigned runNumber, size_t leg, bool& success);
00127 CP::CorrectionCode getEfficiencyScaleFactor(unsigned runNumber, const Leptons& leptons, double& efficiencyScaleFactor);
00128 CP::CorrectionCode getEfficiency(unsigned runNumber, const Leptons& leptons, double& efficiencyData, double& efficiencyMc);
00129 bool checkAndRecord(CP::CorrectionCode&& cc)
00130 {
00131 cc.setChecked();
00132 if(cc>m_cpCode) m_cpCode = cc;
00133 return cc==CP::CorrectionCode::Ok;
00134 }
00135
00136 enum
00137 {
00138 TT_GENERIC_SINGLELEPTON = 0x100,
00139 TT_SINGLE_E, TT_SINGLE_MU,
00140 TT_GENERIC_DILEPTON = 0x200,
00141 TT_2E_SYM, TT_2E_ASYM, TT_EMU, TT_2MU_SYM, TT_2MU_ASYM,
00142 TT_GENERIC_TRILEPTON = 0x400,
00143 TT_3E_SYM, TT_3E_HALFSYM, TT_3E_ASYM, TT_2E_MU_SYM, TT_2E_MU_ASYM,
00144 TT_2MU_E_SYM, TT_2MU_E_ASYM, TT_3MU_SYM, TT_3MU_HALFSYM, TT_3MU_ASYM
00145
00146 };
00147
00148 bool globalEfficiency_One1L(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t leg, Efficiencies&);
00149 bool globalEfficiency_One1EOne1Mu(const Leptons&, unsigned, size_t electronLeg, size_t muonLeg, Efficiencies&);
00150 bool globalEfficiency_Several1L(const Leptons&, unsigned, const flat_set<size_t>& electronLegs, const flat_set<size_t>& muonLegs, Efficiencies&);
00151 bool globalEfficiency_Several1L(const Leptons&, unsigned, xAOD::Type::ObjectType type, const flat_set<size_t>& legs, Efficiencies&);
00152 bool globalEfficiency_One2Lsym(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t leg, Efficiencies&);
00153 bool globalEfficiency_One2Lasym(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t leg1, size_t leg2, Efficiencies&);
00154 bool globalEfficiency_OneEMu(const Leptons&, unsigned, size_t electronLeg, size_t muonLeg, Efficiencies&);
00155 bool globalEfficiency_OneEMuSeveral1L(const Leptons&, unsigned, size_t dilepElectronLeg, size_t dilepMuonLeg,
00156 const flat_set<size_t>& singleElectronLegs, const flat_set<size_t>& singleMuonLegs, Efficiencies&);
00157 bool globalEfficiency_One2LsymSeveral1L(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t leg2L, const flat_set<size_t>& legs1L, Efficiencies&);
00158 bool globalEfficiency_One2LasymSeveral1L(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t leg2L1, size_t leg2L2, const flat_set<size_t>& legs1L, Efficiencies&);
00159 bool globalEfficiency_Two2LsymSeveral1L(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t leg2Lsym1, size_t leg2Lsym2, const flat_set<size_t>& legs1L, Efficiencies&);
00160 bool globalEfficiency_One2LasymOne2LsymSeveral1L(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t leg2Lasym1, size_t leg2Lasym2,
00161 size_t leg2Lsym, const flat_set<size_t>& legs1L, Efficiencies&);
00162 bool globalEfficiency_One3Lsym(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t leg, Efficiencies&);
00163 bool globalEfficiency_One3Lhalfsym(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t legAsym, size_t legSym, Efficiencies&);
00164 bool globalEfficiency_One2LOneEmu(const Leptons&, unsigned, xAOD::Type::ObjectType type, size_t dilepLeg1, size_t dilepLeg2,
00165 size_t emuElectronLeg, size_t emuMuonLeg, Efficiencies&);
00166 bool globalEfficiency_One2EOneEmuOne2Mu(const Leptons&, unsigned, size_t diELeg1, size_t diELeg2, size_t emuELeg, size_t emuMuLeg,
00167 size_t diMuLeg1, size_t diMuLeg2, Efficiencies&);
00168 bool globalEfficiency_One2EOneEmuOne2MuSeveral1L(const Leptons&, unsigned, size_t diELeg1, size_t diELeg2, size_t emuELeg, size_t emuMuLeg,
00169 size_t diMuLeg1, size_t diMuLeg2, const flat_set<size_t>& singleElectronLegs, const flat_set<size_t>& singleMuonLegs, Efficiencies&);
00170 bool globalEfficiency_Two2ETwoEmuTwo2MuSeveral1L(const Leptons&, unsigned, size_t diELegAsym1, size_t diELegAsym2, size_t diELegSym,
00171 size_t emu1ELeg, size_t emu1MuLeg, size_t emu2ELeg, size_t emu2MuLeg, size_t diMuLegAsym1, size_t diMuLegAsym2, size_t diMuLegSym,
00172 const flat_set<size_t>& singleElectronLegs, const flat_set<size_t>& singleMuonLegs, Efficiencies&);
00173 bool globalEfficiency_One3Lmixed(const Leptons& leptons, unsigned runNumber,
00174 xAOD::Type::ObjectType dominantType, size_t leg1a, size_t leg1b, size_t leg2, Efficiencies& globalEfficiencies);
00175 bool globalEfficiency_Two3LmixedCompl(const Leptons&, unsigned,
00176 size_t legE1a, size_t legE1b, size_t legE2, size_t legM1, size_t legM2a, size_t legM2b, Efficiencies&);
00177
00178 bool globalEfficiency_Toys(const Leptons&, unsigned, const std::vector<std::tuple<int,size_t,size_t,size_t> >& triggers, Efficiencies&);
00179 };
00180
00181 #endif //> !TOOLPROTOTYPES_TRIGGLOBALEFFICIENCYCORRECTION_H