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 class HistHandler {
00045 public:
00046
00047 virtual double GetBinContent(int bin) = 0;
00048 virtual void SetBinContent(int bin, float val) = 0;
00049 virtual double GetBinError(int bin) = 0;
00050 virtual void SetBinError(int bin, float val) = 0;
00051 virtual TH1* GetHist() const = 0;
00052
00053 virtual int NBins() = 0;
00054 virtual CorrectionCode FindBin(const xAOD::Muon & muon, int & bin) = 0;
00055 virtual ~HistHandler() {
00056 }
00057 ;
00058 };
00059
00060 class AxisHandler {
00061 public:
00062
00063 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value)=0;
00064
00065 virtual ~AxisHandler() {
00066 }
00067 ;
00068 static std::string EraseWhiteSpaces(std::string str);
00069 };
00070
00071 class HistHandler_TH1F: public HistHandler {
00072
00073 public:
00074
00075 HistHandler_TH1F(TH1F* hist);
00076 HistHandler_TH1F(const HistHandler_TH1F & other);
00077 virtual HistHandler_TH1F & operator =(const HistHandler_TH1F & other);
00078 virtual ~HistHandler_TH1F();
00079 virtual double GetBinContent(int bin) {
00080 return m_h->GetBinContent(bin);
00081 }
00082 virtual void SetBinContent(int bin, float val) {
00083 m_h->SetBinContent(bin, val);
00084 }
00085 virtual double GetBinError(int bin) {
00086 return m_h->GetBinError(bin);
00087 }
00088 virtual void SetBinError(int bin, float val) {
00089 m_h->SetBinError(bin, val);
00090 }
00091 virtual TH1* GetHist() const {
00092 return m_h;
00093 }
00094
00095 virtual int NBins();
00096 virtual CorrectionCode FindBin(const xAOD::Muon & muon, int & bin);
00097
00098 private:
00099 TH1F* m_h;
00100 AxisHandler *m_x_handler;
00101 };
00102
00103 class HistHandler_TH2F: public HistHandler {
00104
00105 public:
00106
00107 HistHandler_TH2F(TH2F* hist);
00108 HistHandler_TH2F(const HistHandler_TH2F & other);
00109 virtual HistHandler_TH2F & operator =(const HistHandler_TH2F & other);
00110 virtual ~HistHandler_TH2F();
00111 virtual double GetBinContent(int bin) {
00112 return m_h->GetBinContent(bin);
00113 }
00114 virtual void SetBinContent(int bin, float val) {
00115 m_h->SetBinContent(bin, val);
00116 }
00117 virtual double GetBinError(int bin) {
00118 return m_h->GetBinError(bin);
00119 }
00120 virtual void SetBinError(int bin, float val) {
00121 m_h->SetBinError(bin, val);
00122 }
00123 virtual TH1* GetHist() const {
00124 return m_h;
00125 }
00126
00127 virtual int NBins();
00128 virtual CorrectionCode FindBin(const xAOD::Muon & muon, int & bin);
00129
00130 private:
00131 TH2F* m_h;
00132 AxisHandler *m_x_handler;
00133 AxisHandler *m_y_handler;
00134 };
00135
00136 class HistHandler_TH3F: public HistHandler {
00137
00138 public:
00139
00140 HistHandler_TH3F(TH3F* hist);
00141 HistHandler_TH3F(const HistHandler_TH3F & other);
00142 virtual HistHandler_TH3F & operator =(const HistHandler_TH3F & other);
00143 virtual ~HistHandler_TH3F();
00144 virtual double GetBinContent(int bin) {
00145 return m_h->GetBinContent(bin);
00146 }
00147 virtual void SetBinContent(int bin, float val) {
00148 m_h->SetBinContent(bin, val);
00149 }
00150 virtual double GetBinError(int bin) {
00151 return m_h->GetBinError(bin);
00152 }
00153 virtual void SetBinError(int bin, float val) {
00154 m_h->SetBinError(bin, val);
00155 }
00156 virtual TH1* GetHist() const {
00157 return m_h;
00158 }
00159
00160 virtual int NBins();
00161 virtual CorrectionCode FindBin(const xAOD::Muon & muon, int & bin);
00162
00163 private:
00164 TH3F* m_h;
00165 AxisHandler *m_x_handler;
00166 AxisHandler *m_y_handler;
00167 AxisHandler *m_z_handler;
00168 };
00169
00170 class HistHandler_TH2Poly: public HistHandler {
00171
00172 public:
00173
00174 HistHandler_TH2Poly(TH2Poly* hist);
00175 HistHandler_TH2Poly(const HistHandler_TH2Poly & other);
00176 virtual HistHandler_TH2Poly & operator =(const HistHandler_TH2Poly & other);
00177 virtual ~HistHandler_TH2Poly();
00178 virtual double GetBinContent(int bin) {
00179 return m_h->GetBinContent(bin);
00180 }
00181 virtual void SetBinContent(int bin, float val) {
00182 m_h->SetBinContent(bin, val);
00183 }
00184 virtual double GetBinError(int bin) {
00185 return m_h->GetBinError(bin);
00186 }
00187 virtual void SetBinError(int bin, float val) {
00188 m_h->SetBinError(bin, val);
00189 }
00190 virtual TH1* GetHist() const {
00191 return m_h;
00192 }
00193
00194 virtual int NBins();
00195 virtual CorrectionCode FindBin(const xAOD::Muon & muon, int & bin);
00196
00197 private:
00198 TH2Poly* m_h;
00199 AxisHandler *m_x_handler;
00200 AxisHandler *m_y_handler;
00201 };
00202
00203 class PtAxisHandler: public AxisHandler {
00204 public:
00205 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) {
00206 value = mu.pt() / 1000.;
00207 return CorrectionCode::Ok;
00208 }
00209 virtual ~PtAxisHandler() {
00210 }
00211 ;
00212 };
00213
00214 class ChargeAxisHandler: public AxisHandler {
00215 public:
00216 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) {
00217 value = mu.charge();
00218 return CorrectionCode::Ok;
00219 }
00220 virtual ~ChargeAxisHandler() {
00221 }
00222 ;
00223 };
00224
00225 class SignedDetRegionAxisHandler: public AxisHandler {
00226 public:
00227 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) {
00228 static TLorentzVector tlv;
00229
00230 tlv.SetPtEtaPhiM(mu.pt(), mu.eta(), mu.phi(), mu.m());
00231 value = m_drb.bin(tlv);
00232 return CorrectionCode::Ok;
00233 }
00234 virtual ~SignedDetRegionAxisHandler() {
00235 }
00236 ;
00237 private:
00238 DetRegionBinning m_drb;
00239 };
00240
00241 class DetRegionAxisHandler: public AxisHandler {
00242 public:
00243 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) {
00244 static TLorentzVector tlv;
00245
00246 tlv.SetPtEtaPhiM(mu.pt(), mu.eta(), mu.phi(), mu.m());
00247 value = m_drb.symmetricBin(tlv);
00248 return CorrectionCode::Ok;
00249 }
00250 virtual ~DetRegionAxisHandler() {
00251 }
00252 ;
00253 private:
00254 DetRegionBinning m_drb;
00255 };
00256
00257 class FineEtaPhiAxisHandler: public AxisHandler {
00258 public:
00259 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) {
00260 static TLorentzVector tlv;
00261
00262 tlv.SetPtEtaPhiM(mu.pt(), mu.eta(), mu.phi(), mu.m());
00263 value = m_fepb.bin(tlv);
00264 return CorrectionCode::Ok;
00265 }
00266 virtual ~FineEtaPhiAxisHandler() {
00267 }
00268 ;
00269 private:
00270 fineEtaPhiBinning m_fepb;
00271 };
00272 class EtaAxisHandler: public AxisHandler {
00273 public:
00274 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) {
00275 value = mu.eta();
00276 return CorrectionCode::Ok;
00277 }
00278 virtual ~EtaAxisHandler() {
00279 }
00280 ;
00281 };
00282 class AbsEtaAxisHandler: public AxisHandler {
00283 public:
00284 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) {
00285 value = fabs(mu.eta());
00286 return CorrectionCode::Ok;
00287 }
00288 virtual ~AbsEtaAxisHandler() {
00289 }
00290 ;
00291 };
00292 class PhiAxisHandler: public AxisHandler {
00293 public:
00294 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) {
00295 value = mu.phi();
00296 return CorrectionCode::Ok;
00297 }
00298 virtual ~PhiAxisHandler() {
00299 }
00300 ;
00301 };
00302 class dRJetAxisHandler: public AxisHandler {
00303 public:
00304 virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) {
00305 static SG::AuxElement::ConstAccessor<float> dRJet("dRJet");
00306 value = dRJet.isAvailable(mu) ? dRJet(mu) : -1;
00307 return CorrectionCode::Ok;
00308 }
00309 virtual ~dRJetAxisHandler() {
00310 }
00311 ;
00312 };
00313 class UndefinedAxisHandler: public AxisHandler {
00314 public:
00315 virtual CorrectionCode GetBinningParameter(const xAOD::Muon &, float &) {
00316 return CorrectionCode::Error;
00317 }
00318 virtual ~UndefinedAxisHandler() {
00319 }
00320 ;
00321 };
00322 class AxisHandlerProvider {
00323 public:
00324 static AxisHandler *GetAxisHandler(TAxis* axis);
00325 };
00326
00327 }
00328 #endif