00001
00002
00003 #ifndef TrigMuonEfficiency_LeptonTriggerSF_H
00004 #define TrigMuonEfficiency_LeptonTriggerSF_H
00005
00033
00034 #include <vector>
00035 #include <map>
00036 #include <string>
00037
00038
00039 class TLorentzVector;
00040 class TH2;
00041 class TFile;
00042 class TDirectory;
00043
00044 namespace Root {
00045 class TElectronEfficiencyCorrectionTool;
00046 }
00047
00048
00049 namespace TrigMuonEff {
00050
00054 struct Configuration {
00055 mutable bool isData;
00056 bool isAFII;
00057 bool useGeV;
00058 bool setByUser;
00059 int replicaIndex;
00060 int runNumber;
00061 int systematics;
00062 std::string trigger;
00063 std::string period;
00064 std::string binning;
00066 Configuration(const bool isData_ = true,
00067 const bool isAFII_ = false,
00068 const bool useGeV_ = false,
00069 const bool setByUser_ = false,
00070 const int replicaIndex_ = -1,
00071 const int runNumber_ = 0,
00072 const int systematics_ = 0,
00073 const std::string& trigger_ = "",
00074 const std::string& period_ = "",
00075 const std::string& binning_ = "") :
00076 isData(isData_),
00077 isAFII(isAFII_),
00078 useGeV(useGeV_),
00079 setByUser(setByUser_),
00080 replicaIndex(replicaIndex_),
00081 runNumber(runNumber_),
00082 systematics(systematics_),
00083 trigger(trigger_),
00084 period(period_),
00085 binning(binning_) {}
00086 };
00087
00088
00092 typedef enum DataPeriod {
00093 period_undefined = -1, perUnDefined = -1,
00094 period_2011_BtoI = 0, per2011B_I = 0,
00095 period_2011_JtoMwithoutL3L4 = 1, per2011J_MwoL3_L4 = 1,
00096 period_2011_L3toL4 = 2, per2011L3_L4 = 2,
00097
00098
00099 per2011J = 3,
00100 per2011K = 4,
00101 per2011J_K = 5,
00102 per2011J_M = 6,
00103 per2011L_M = 7,
00104
00105
00106 period_2012_A = 8, per2012A = 8,
00107 period_2012_B = 9, per2012B = 9,
00108 period_2012_CtoE = 10, per2012CtoE = 10,
00109 period_2012_G = 11, per2012G = 11,
00110 period_2012_HtoL = 12, per2012HtoL = 12
00111 } SFDataPeriod;
00112 }
00113
00114
00115
00119 typedef enum MuonQuality {
00120 loose = 0,
00121 combined = 1,
00122 CaloMuon = 2
00123 } muon_quality;
00124
00128 typedef enum ElectronQuality {
00129 loosepp = 0,
00130 mediumpp = 1,
00131 tightpp = 2,
00132 MultiLepton = 3,
00133 ML = 3,
00134 LooseLLH = 4,
00135 VeryTightLLH = 5
00136 } electron_quality;
00137
00141 typedef enum DileptonTriggerName {
00142 kNoTrig = 0,
00143 EF_e12Tvh_medium1_mu8 = 1,
00144 EF_2e12Tvh_loose1 = 2,
00145 EF_mu18_mu8_EFFS = 3
00146 } dilepton_trigger_name;
00147
00151 enum SystematicVariation {
00152 noVariation = 0,
00153 plusOneSigma = 1,
00154 minusOneSigma = 2,
00155 plusOneSigmaElectron = 3,
00156 minusOneSigmaElectron = 4,
00157 plusOneSigmaMuon = 5,
00158 minusOneSigmaMuon = 6,
00159 statisticalOnlyMuon = 7,
00160 systematicOnlyMuon = 8
00161 };
00162
00163
00164
00174 class LeptonTriggerSF {
00175 public:
00176 struct Storage {
00177 const std::vector<std::string> *type;
00178 const std::vector<std::string> *region;
00179 const std::vector<std::string> *quality;
00180 const std::vector<std::string> *bins;
00181 const std::vector<std::string> *trigger;
00182 const std::vector<std::string> *period;
00183
00184 Storage(const std::vector<std::string> *type_=0,
00185 const std::vector<std::string> *region_=0,
00186 const std::vector<std::string> *quality_=0,
00187 const std::vector<std::string> *bins_=0,
00188 const std::vector<std::string> *trigger_=0,
00189 const std::vector<std::string> *period_=0) :
00190 type(type_),
00191 region(region_),
00192 quality(quality_),
00193 bins(bins_),
00194 trigger(trigger_),
00195 period(period_) {}
00196 };
00197
00210 LeptonTriggerSF(const std::string& directory = "",
00211 const std::string& directoryElectron = "",
00212 const std::string& electronFileVersion = "rel17p2.v02");
00213
00221 LeptonTriggerSF(const int year,
00222 const std::string& directory = "",
00223 const std::string& fileName = "",
00224 const std::string& directoryElectron = "",
00225 const std::string& electronFileVersion = "rel17p2.v02");
00226
00235 LeptonTriggerSF(const int year,
00236 const std::vector<std::string>& qualities,
00237 const std::string& directory = "",
00238 const std::string& fileName = "",
00239 const std::string& directoryElectron = "",
00240 const std::string& electronFileVersion = "rel17p2.v02");
00241
00243 ~LeptonTriggerSF();
00244
00245
00246
00257 std::pair<double, double>
00258 GetTriggerSF(const int runNumber,
00259 const bool useGeV,
00260 const std::vector<TLorentzVector>& muons,
00261 const MuonQuality muonQuality,
00262 const int systematicVariation = 0,
00263 TrigMuonEff::Configuration* configuration = 0) const;
00264
00265
00266
00277 std::pair<double, double>
00278 GetTriggerSF(const int runNumber,
00279 const bool useGeV,
00280 const std::vector<TLorentzVector>& muons,
00281 const std::vector<MuonQuality>& muonsQuality,
00282 const int systematicVariation = 0,
00283 TrigMuonEff::Configuration* configuration = 0) const;
00284
00285
00286
00298 std::pair<double, double>
00299 GetTriggerSF(const int runNumber,
00300 const bool useGeV,
00301 const std::vector<TLorentzVector>& muons,
00302 const std::vector<MuonQuality>& muonsQuality,
00303 const std::string& trigger,
00304 const int systematicVariation = 0,
00305 TrigMuonEff::Configuration* configuration = 0) const;
00306
00318 std::pair<double, double>
00319 GetTriggerSF(const int runNumber,
00320 const bool useGeV,
00321 const std::vector<TLorentzVector>& electrons,
00322 const std::vector<ElectronQuality>& electronsQuality,
00323 const std::string& trigger,
00324 const int systematicVariation = 0,
00325 TrigMuonEff::Configuration* configuration = 0) const;
00326
00339 std::pair<double, double>
00340 GetTriggerSF(const int runNumber,
00341 const bool useGeV,
00342 const std::vector<TLorentzVector>& muons,
00343 const MuonQuality muonQuality,
00344 const std::vector<TLorentzVector>& electrons,
00345 const ElectronQuality electronQuality,
00346 const int systematicVariation = 0,
00347 TrigMuonEff::Configuration* configuration = 0) const;
00348
00349
00350
00363 std::pair<double, double>
00364 GetTriggerSF(const int runNumber,
00365 const bool useGeV,
00366 const std::vector<TLorentzVector>& muons,
00367 const std::vector<MuonQuality>& muonsQuality,
00368 const std::vector<TLorentzVector>& electrons,
00369 const std::vector<ElectronQuality>& electronsQuality,
00370 const int systematicVariation = 0,
00371 TrigMuonEff::Configuration* configuration = 0) const;
00372
00373
00387 std::pair<double, double>
00388 GetTriggerSF(const int runNumber,
00389 const bool useGeV,
00390 const std::vector<TLorentzVector>& muons,
00391 const std::vector<MuonQuality>& muonsQuality,
00392 const std::vector<TLorentzVector>& electrons,
00393 const std::vector<ElectronQuality>& electronsQuality,
00394 const std::string& trigger,
00395 const int systematicVariation = 0,
00396 TrigMuonEff::Configuration* configuration = 0) const;
00397
00407 std::pair<double, double>
00408 GetTriggerSF(const TrigMuonEff::Configuration& configuration,
00409 const std::vector< TLorentzVector >& muons,
00410 const std::vector< MuonQuality >& muonsQuality,
00411 const std::vector< TLorentzVector >& electrons,
00412 const std::vector< ElectronQuality >& electronsQuality) const;
00413
00414
00415
00424 std::pair<double, double>
00425 GetTriggerSF(const TrigMuonEff::Configuration& configuration,
00426 const std::vector<TLorentzVector>& muons,
00427 const std::vector<MuonQuality>& muonsQuality,
00428 const std::string& trigger) const;
00429
00438 std::pair<double, double>
00439 GetTriggerSF(const TrigMuonEff::Configuration& configuration,
00440 const std::vector<TLorentzVector>& electrons,
00441 const std::vector<ElectronQuality>& electronsQuality,
00442 const std::string& trigger) const;
00443
00452 std::pair<double, double>
00453 getMuonEfficiency(const TrigMuonEff::Configuration& configuration,
00454 const TLorentzVector& muon,
00455 const MuonQuality muonQuality,
00456 const std::string& trigger = "") const;
00457
00458 std::pair<double, double>
00459 MuEff(const TrigMuonEff::Configuration& configuration,
00460 const TLorentzVector& muon,
00461 const MuonQuality muonQuality,
00462 const std::string& trigger = "") const
00463 {return getMuonEfficiency(configuration, muon, muonQuality, trigger);}
00464
00465
00466
00474 std::pair<double, double>
00475 getMuonEfficiency(const TrigMuonEff::DataPeriod period,
00476 const bool isData,
00477 const TLorentzVector& muon,
00478 const MuonQuality muonQuality) const
00479 {
00480 TrigMuonEff::Configuration config;
00481 config.isData = isData;
00482
00483 setConfiguration(config, period);
00484 return getMuonEfficiency(config, muon, muonQuality);
00485 };
00486
00487 std::pair<double, double>
00488 MuEff(const TrigMuonEff::DataPeriod period,
00489 const bool isData,
00490 const TLorentzVector& muon,
00491 const MuonQuality muonQuality) const
00492 {return getMuonEfficiency(period, isData, muon, muonQuality);}
00493
00494
00495
00507 std::pair<double, double>
00508 getMuonEfficiency(const int runNumber,
00509 const bool isData,
00510 const bool useGeV,
00511 const TLorentzVector& muon,
00512 const MuonQuality muonQuality,
00513 const int uncertainty = 0,
00514 TrigMuonEff::Configuration* configuration = 0) const
00515 {
00516 TrigMuonEff::Configuration config;
00517 config.runNumber = runNumber;
00518 config.isData = isData;
00519 config.useGeV = useGeV;
00520 config.setByUser = false;
00521 config.isAFII = m_IsAFII;
00522 config.systematics = uncertainty;
00523
00524 if (configuration) {
00525 config.setByUser = true;
00526 config.trigger = configuration->trigger;
00527 config.period = configuration->period;
00528 config.binning = configuration->binning;
00529
00530 } else {
00531 setConfiguration(config);
00532 }
00533
00534 return getMuonEfficiency(config, muon, muonQuality);
00535 }
00536
00537
00538
00547 std::pair<double, double>
00548 getDimuonEfficiency(const TrigMuonEff::Configuration& config,
00549 const std::vector<TLorentzVector>& muons,
00550 const std::vector<MuonQuality>& muonsQuality,
00551 const std::string& chain) const;
00552
00561 std::pair<double, double>
00562 getDielectronEfficiency(const TrigMuonEff::Configuration& config,
00563 const std::vector<TLorentzVector>& electrons,
00564 const std::vector<ElectronQuality>& electronsQuality,
00565 const std::string& chain) const;
00566
00567
00568
00577 std::pair<double, double>
00578 getSingleOrDimuonEfficiency(const TrigMuonEff::Configuration& config,
00579 const std::vector<TLorentzVector>& muons,
00580 const std::vector<MuonQuality>& muonsQuality,
00581 const std::string& chain) const;
00582
00591 std::pair<double, double>
00592 getSingleOrDielectronEfficiency(const TrigMuonEff::Configuration& config,
00593 const std::vector<TLorentzVector>& electrons,
00594 const std::vector<ElectronQuality>& electronsQuality,
00595 const std::string& chain) const;
00596
00605 std::pair<double, double>
00606 getElectronSF(const TLorentzVector& electron,
00607 const int combination,
00608 const int year,
00609 const TrigMuonEff::Configuration& configuration) const;
00610
00611
00612
00621 std::pair<double, double>
00622 ElEff_MC(const TLorentzVector& electron,
00623 const int combination,
00624 const int year,
00625 const TrigMuonEff::Configuration& configuration) const
00626 {return getElectronSF(electron, combination, year, configuration);}
00627
00628
00629
00639 std::pair<double, double>
00640 ElEff_MC(const TLorentzVector& electron,
00641 const int combination,
00642 const bool useGeV = false,
00643 const int year = 2011,
00644 const int runNumber = 200804) const
00645 {
00646 TrigMuonEff::Configuration configuration;
00647 configuration.runNumber = runNumber;
00648 configuration.useGeV = useGeV;
00649 configuration.setByUser = false;
00650 configuration.isAFII = m_IsAFII;
00651 return getElectronSF(electron, combination, year, configuration);
00652 }
00653
00654
00655
00665 std::pair<double, double>
00666 ElEff_Data(const TLorentzVector& electron,
00667 const int combinationSF,
00668 const int combinationEfficiency,
00669 const int year,
00670 const TrigMuonEff::Configuration& config) const;
00671
00672
00673
00684 std::pair<double, double>
00685 ElEff_Data(const TLorentzVector& electron,
00686 const int combinationSF,
00687 const int combinationEfficiency,
00688 const bool useGeV = false,
00689 const int year = 2011,
00690 const int runNumber = 200804) const
00691 {
00692 TrigMuonEff::Configuration configuration;
00693 configuration.runNumber = runNumber;
00694 configuration.useGeV = useGeV;
00695 configuration.setByUser = false;
00696 configuration.isAFII = m_IsAFII;
00697 return ElEff_Data(electron, combinationSF, combinationEfficiency, year, configuration);
00698 }
00699
00700
00701
00706 void setAFII(const bool flag=true) {m_IsAFII = flag;};
00707
00708 void setMaxPeriod(const TrigMuonEff::DataPeriod x) {m_max_period = x;};
00709
00710
00720 void
00721 createMcReplicaMuon(const int n,
00722 const std::string& trigger = std::string());
00723
00724
00725
00736 std::pair<double, double>
00737 getSfReplicaMuon(const int runNumber,
00738 const bool useGeV,
00739 const std::vector<TLorentzVector>& muons,
00740 const std::vector<MuonQuality>& muonsQuality,
00741 const int index = 0,
00742 TrigMuonEff::Configuration* configuration = 0) const;
00743
00752 int
00753 getElectronQuality(const int runNumber,
00754 const ElectronQuality quality,
00755 const bool isSF,
00756 const bool isditrig,
00757 const DileptonTriggerName dilepName = kNoTrig) const;
00758
00759
00760 private:
00761 void
00762 prepareForElectronSF(const std::string& directory);
00763
00764
00765
00772 std::string
00773 getPathName(const std::string& directory,
00774 const std::string& fileName) const;
00775
00776
00777
00782 void
00783 setStorage(Storage& storage) const;
00784
00785
00786
00790 TDirectory*
00791 getTemporaryDirectory(void) const;
00792
00793
00794
00805 void
00806 initialise(const std::string& directory,
00807 const std::string& fileName = "muon_trigger_sf.root",
00808 const std::vector<std::string>& qualities = std::vector<std::string>(),
00809 const std::string& directoryElectron = "");
00810
00811
00812
00818 static std::string
00819 getMuonQuality(const MuonQuality quality);
00820
00821
00822
00828 static std::pair<double, double>
00829 getThresholds(const TrigMuonEff::Configuration& configuration);
00830
00831
00832
00833 struct DileptonThresholds {
00834 double mu18_tight;
00835 double mu8_EFFS;
00836 double mu8;
00837 double mu13;
00838 double e12Tvh_loose1;
00839 double e12Tvh_medium1;
00840
00841 DileptonThresholds(const double mu18_tight_ = 20,
00842 const double mu8_EFFS_ = 10,
00843 const double mu13_ = 15,
00844 const double e12Tvh_loose1_ = 14) :
00845 mu18_tight(mu18_tight_), mu8_EFFS(mu8_EFFS_), mu8(mu8_EFFS_), mu13(mu13_), e12Tvh_loose1(e12Tvh_loose1_), e12Tvh_medium1(e12Tvh_loose1_) {}
00846
00847
00848
00849
00850
00851
00852
00853
00854 };
00855
00861 static void
00862 getDileptonThresholds(const TrigMuonEff::Configuration& config,
00863 DileptonThresholds& thresholds);
00864
00865
00866
00872 static TrigMuonEff::DataPeriod
00873 getDataPeriod(int runNumber);
00874
00875
00876
00885 static double
00886 getSfError(const double a,
00887 const double b,
00888 const double c,
00889 const double d);
00890
00907 static double
00908 getDiError(const double a1, const double a2,
00909 const double b1, const double b2,
00910 const double c1, const double c2,
00911 const double d1, const double d2,
00912 const double e1, const double e2,
00913 const double f1, const double f2);
00914
00935 static double
00936 getSingleOrDiError_asym(const double a1, const double a2,
00937 const double b1, const double b2,
00938 const double c1, const double c2,
00939 const double d1, const double d2,
00940 const double e1, const double e2,
00941 const double f1, const double f2,
00942 const double g1, const double g2,
00943 const double h1, const double h2);
00944
00945
00960 static double
00961 getSingleOrDiError_sym(const double a1, const double a2,
00962 const double b1, const double b2,
00963 const double c1, const double c2,
00964 const double d1, const double d2,
00965 bool ispT1above, bool ispT2above);
00966
00967
00968 struct DileptonTrigger {
00969 std::string leg1;
00970 std::string leg2;
00971 std::string bothLegs;
00972 DileptonTrigger(const std::string& leg1_ = std::string(),
00973 const std::string& leg2_ = std::string(),
00974 const std::string& bothLegs_ = std::string()) :
00975 leg1(leg1_), leg2(leg2_), bothLegs(bothLegs_) {}
00976 };
00977
00983 static void
00984 getDileptonLegs(const std::string& chain,
00985 DileptonTrigger& legs);
00986
00987
00988 bool
00989 setConfiguration(TrigMuonEff::Configuration& config,
00990 TrigMuonEff::DataPeriod period = TrigMuonEff::period_undefined) const;
00991
00992 void
00993 setPhiBoundary2011(const std::vector<std::string> *period);
00994
00995 void
00996 setPhiBoundary(TFile* file);
00997
00998
01004 double
01005 fixPhiRange(const TLorentzVector& muon) const;
01006
01007
01008 void
01009 initialiseElectronTool(const int key) const;
01010
01011
01012 int m_year;
01013 std::vector<std::string> m_qualities;
01014 typedef std::map<std::string, TH2*> EfficiencyMap;
01015 typedef std::pair<std::string, TH2*> EfficiencyPair;
01016 EfficiencyMap m_efficiencyMap;
01017 std::vector<EfficiencyMap> m_efficiencyMapReplicaArray;
01019 double m_phiBoundaryBarrel;
01020 double m_phiBoundaryEndcap;
01022 typedef std::map<int, Root::TElectronEfficiencyCorrectionTool*> ElectronEfficiencyToolMap;
01023 typedef std::pair<int, Root::TElectronEfficiencyCorrectionTool*> ElectronEfficiencyToolPair;
01024 mutable ElectronEfficiencyToolMap m_electronSF;
01025 mutable std::map<int, std::string> m_fileNameMap;
01026
01027 bool m_IsAFII;
01028 TrigMuonEff::DataPeriod m_max_period;
01029 std::string m_electronFileVersion;
01030
01031 };
01032
01033 #endif // TrigMuonEfficiency_LeptonTriggerSF_H