00001 #ifndef HISTOHANDLERFORMCPTOOL
00002 #define HISTOHANDLERFORMCPTOOL
00003
00004
00005 #include "xAODMuon/Muon.h"
00006
00007 #ifdef ROOTCORE
00008 # include "xAODRootAccess/Init.h"
00009 # include "xAODRootAccess/TEvent.h"
00010 #endif // ROOTCORE
00011
00012
00013 #include "xAODEventInfo/EventInfo.h"
00014 #include "xAODMuon/MuonContainer.h"
00015
00016
00017 #include <TH1F.h>
00018 #include <TH2F.h>
00019 #include <TH3F.h>
00020 #include <TH2Poly.h>
00021
00022 #include "PATInterfaces/CorrectionCode.h"
00023 #include "MuonEfficiencyCorrections/fineEtaPhiBinning.h"
00024 #include "MuonEfficiencyCorrections/DetRegionBinning.h"
00025
00026
00027 #include <TFile.h>
00028 #include <TDirectory.h>
00029
00030
00031 #include <string>
00032 #include <iostream>
00033 #include <exception>
00034 #include <map>
00035 #include <cmath>
00036
00037 namespace CP {
00038
00039 class AxisHandler;
00040 class HistHandler {
00047 public:
00048
00049 double GetBinContent(int bin) const;
00050 void SetBinContent(int bin, float val) const;
00051 double GetBinError(int bin) const;
00052 void SetBinError(int bin, float val) const;
00053 TH1* GetHist() const;
00054
00055
00056 virtual CorrectionCode FindBin(const xAOD::Muon & muon, int & bin) const = 0;
00057 virtual int NBins() const = 0;
00058 virtual ~HistHandler();
00059 protected:
00060 HistHandler(TH1* Hist);
00061 HistHandler(const HistHandler & other);
00062 void Copy(const HistHandler & other);
00063 private:
00064 TH1* m_H;
00065
00066 };
00067
00068 class HistHandler_TH1F: public HistHandler {
00069
00070 public:
00071
00072 HistHandler_TH1F(TH1F* hist);
00073 HistHandler_TH1F(const HistHandler_TH1F & other);
00074 virtual HistHandler_TH1F & operator =(const HistHandler_TH1F & other);
00075 virtual ~HistHandler_TH1F();
00076
00077 virtual int NBins() const;
00078 virtual CorrectionCode FindBin(const xAOD::Muon & muon, int & bin) const;
00079 private:
00080 AxisHandler *m_x_handler;
00081 };
00082
00083 class HistHandler_TH2F: public HistHandler {
00084
00085 public:
00086
00087 HistHandler_TH2F(TH2F* hist);
00088 HistHandler_TH2F(const HistHandler_TH2F & other);
00089 virtual HistHandler_TH2F & operator =(const HistHandler_TH2F & other);
00090 virtual ~HistHandler_TH2F();
00091
00092 virtual int NBins() const;
00093 virtual CorrectionCode FindBin(const xAOD::Muon & muon, int & bin) const;
00094 private:
00095 TH2F* m_h;
00096 AxisHandler *m_x_handler;
00097 AxisHandler *m_y_handler;
00098 };
00099
00100 class HistHandler_TH3F: public HistHandler {
00101
00102 public:
00103
00104 HistHandler_TH3F(TH3F* hist);
00105 HistHandler_TH3F(const HistHandler_TH3F & other);
00106 virtual HistHandler_TH3F & operator =(const HistHandler_TH3F & other);
00107 virtual ~HistHandler_TH3F();
00108 virtual int NBins() const;
00109 virtual CorrectionCode FindBin(const xAOD::Muon & muon, int & bin) const;
00110
00111 private:
00112 TH3F* m_h;
00113 AxisHandler *m_x_handler;
00114 AxisHandler *m_y_handler;
00115 AxisHandler *m_z_handler;
00116 };
00117
00118 class HistHandler_TH2Poly: public HistHandler {
00119
00120 public:
00121
00122 HistHandler_TH2Poly(TH2Poly* hist);
00123 HistHandler_TH2Poly(const HistHandler_TH2Poly & other);
00124 virtual HistHandler_TH2Poly & operator =(const HistHandler_TH2Poly & other);
00125 virtual ~HistHandler_TH2Poly();
00126 virtual int NBins() const;
00127 virtual CorrectionCode FindBin(const xAOD::Muon & muon, int & bin) const;
00128
00129 private:
00130 TH2Poly* m_h;
00131 AxisHandler *m_x_handler;
00132 AxisHandler *m_y_handler;
00133 };
00134
00135 class AxisHandler {
00136 public:
00137 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value)=0;
00138 virtual ~AxisHandler() {
00139 }
00140 };
00141 class AxisHandlerProvider {
00142 public:
00143 static AxisHandler *GetAxisHandler(const TAxis* axis);
00144 static std::string EraseWhiteSpaces(std::string str);
00145 };
00146
00147 class PtAxisHandler: public AxisHandler {
00148 public:
00149 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) {
00150 value = mu.pt() / 1000.;
00151 return CorrectionCode::Ok;
00152 }
00153 virtual ~PtAxisHandler() {
00154 }
00155
00156 };
00157
00158 class ChargeAxisHandler: public AxisHandler {
00159 public:
00160 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) {
00161 value = mu.charge();
00162 return CorrectionCode::Ok;
00163 }
00164 virtual ~ChargeAxisHandler() {
00165 }
00166
00167 };
00168
00169 class SignedDetRegionAxisHandler: public AxisHandler {
00170 public:
00171 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) {
00172 static TLorentzVector tlv;
00173
00174 tlv.SetPtEtaPhiM(mu.pt(), mu.eta(), mu.phi(), mu.m());
00175 value = m_drb.bin(tlv);
00176 return CorrectionCode::Ok;
00177 }
00178 virtual ~SignedDetRegionAxisHandler() {
00179 }
00180
00181 private:
00182 DetRegionBinning m_drb;
00183 };
00184
00185 class DetRegionAxisHandler: public AxisHandler {
00186 public:
00187 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) {
00188 static TLorentzVector tlv;
00189
00190 tlv.SetPtEtaPhiM(mu.pt(), mu.eta(), mu.phi(), mu.m());
00191 value = m_drb.symmetricBin(tlv);
00192 return CorrectionCode::Ok;
00193 }
00194 virtual ~DetRegionAxisHandler() {
00195 }
00196
00197 private:
00198 DetRegionBinning m_drb;
00199 };
00200
00201 class FineEtaPhiAxisHandler: public AxisHandler {
00202 public:
00203 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) {
00204 static TLorentzVector tlv;
00205
00206 tlv.SetPtEtaPhiM(mu.pt(), mu.eta(), mu.phi(), mu.m());
00207 value = m_fepb.bin(tlv);
00208 return CorrectionCode::Ok;
00209 }
00210 virtual ~FineEtaPhiAxisHandler() {
00211 }
00212
00213 private:
00214 fineEtaPhiBinning m_fepb;
00215 };
00216 class EtaAxisHandler: public AxisHandler {
00217 public:
00218 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) {
00219 value = mu.eta();
00220 return CorrectionCode::Ok;
00221 }
00222 virtual ~EtaAxisHandler() {
00223 }
00224
00225 };
00226 class AbsEtaAxisHandler: public AxisHandler {
00227 public:
00228 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) {
00229 value = fabs(mu.eta());
00230 return CorrectionCode::Ok;
00231 }
00232 virtual ~AbsEtaAxisHandler() {
00233 }
00234
00235 };
00236 class PhiAxisHandler: public AxisHandler {
00237 public:
00238 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) {
00239 value = mu.phi();
00240 return CorrectionCode::Ok;
00241 }
00242 virtual ~PhiAxisHandler() {
00243 }
00244
00245 };
00246 class dRJetAxisHandler: public AxisHandler {
00247 public:
00248 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) {
00249 static SG::AuxElement::ConstAccessor<float> dRJet("dRJet");
00250 value = dRJet.isAvailable(mu) ? dRJet(mu) : -1;
00251 return CorrectionCode::Ok;
00252 }
00253 virtual ~dRJetAxisHandler() {
00254 }
00255
00256 };
00257 class UndefinedAxisHandler: public AxisHandler {
00258 public:
00259 virtual CorrectionCode GetBinningParameter(const xAOD::Muon &, float &) {
00260 return CorrectionCode::Error;
00261 }
00262 virtual ~UndefinedAxisHandler() {
00263 }
00264
00265 };
00266
00267 }
00268 #endif