00001 #ifndef bmpthistoweightcalculator_cxx
00002 #define bmpthistoweightcalculator_cxx
00003 #include "MessageService/MsgService.h"
00004 #include "MCReweight/BMPTHistoWeightCalculator.h"
00005 #include "TMath.h"
00006
00007 CVSID("$Id: BMPTHistoWeightCalculator.cxx,v 1.7 2007/01/15 20:20:26 rhatcher Exp $");
00008
00009
00010 BMPTHistoWeightCalculator::BMPTHistoWeightCalculator(Registry *config)
00011 : WeightCalculator(config)
00012 {
00013
00014 fWCname = "BMPTHistoWeightCalculator";
00015
00016 fStandardConfigChanged = false;
00017 fReweightConfigChanged = false;
00018
00019 if(config) SetStandardConfig(config);
00020
00021
00022 fUseBMPTHistoReweighting = 0;
00023 fBMPTHistofile = 0;
00024 fPidHist.clear();
00025
00026 OpenReweightFile();
00027
00028 }
00029
00030
00031 void BMPTHistoWeightCalculator::OpenReweightFile()
00032 {
00033
00034
00035 string directory = "";
00036 char *dir = getenv("GMINOSAUX");
00037 if(dir!=NULL) directory = dir;
00038 else directory = ".";
00039
00040 string file = "/bmpt-wght.root";
00041 string fullpath = directory+file;
00042
00043
00044 fBMPTHistofile = new TFile(fullpath.c_str(),"READ");
00045
00046
00047 if(!fBMPTHistofile->IsOpen() || fBMPTHistofile->IsZombie()) {
00048 MSG("BMPTHistoWC",Msg::kError)
00049 << "Could not open BMPTHisto reweight file!\n"
00050 << "Check that $GMINOSAUX points to the correct directory.\n"
00051 << "All weights will be 1" << endl;
00052 delete fBMPTHistofile;
00053 fBMPTHistofile = 0;
00054 return;
00055 }
00056
00057
00058 TH2F *piplushist = (TH2F*) fBMPTHistofile->Get("h9901008");
00059 TH2F *piminushist = (TH2F*) fBMPTHistofile->Get("h9901009");
00060 TH2F *kplushist = (TH2F*) fBMPTHistofile->Get("h9901011");
00061 TH2F *kminushist = (TH2F*) fBMPTHistofile->Get("h9901012");
00062 TH2F *k0longhist = (TH2F*) fBMPTHistofile->Get("h9901010");
00063 TH2F *k0shorthist = (TH2F*) fBMPTHistofile->Get("h9901016");
00064 TH2F *phist = (TH2F*) fBMPTHistofile->Get("h9901014");
00065 TH2F *pbarhist = (TH2F*) fBMPTHistofile->Get("h9901015");
00066
00067
00068 fPidHist[8] = piplushist;
00069 fPidHist[9] = piminushist;
00070 fPidHist[11] = kplushist;
00071 fPidHist[12] = kminushist;
00072 fPidHist[10] = k0longhist;
00073 fPidHist[16] = k0shorthist;
00074 fPidHist[14] = phist;
00075 fPidHist[15] = pbarhist;
00076
00077 }
00078
00079
00080 BMPTHistoWeightCalculator::~BMPTHistoWeightCalculator()
00081 {
00082
00083 if(fBMPTHistofile) {
00084 fBMPTHistofile->Close();
00085 delete fBMPTHistofile;
00086 }
00087
00088 }
00089
00090
00091 void BMPTHistoWeightCalculator::ReweightConfigReset()
00092 {
00093 if(fStandardConfig) SetReweightConfig(fStandardConfig);
00094 }
00095
00096
00097 void BMPTHistoWeightCalculator::Config()
00098 {
00099
00100 Int_t tempi = 0;
00101 if(fStandardConfigChanged) {
00102 if(fStandardConfig->Get("bmpt_histo:use",tempi))
00103 fUseBMPTHistoReweighting = tempi;
00104 fStandardConfigChanged = false;
00105 }
00106 if(fReweightConfigChanged) {
00107 if(fReweightConfig->Get("bmpt_histo:use",tempi))
00108 fUseBMPTHistoReweighting = tempi;
00109 fReweightConfigChanged = false;
00110 }
00111 }
00112
00113
00114 double BMPTHistoWeightCalculator::GetWeight(MCEventInfo *event,NuParent *parent)
00115 {
00116 if(!event) return 1;
00117 if(!parent) return 1;
00118 return 1;
00119 }
00120
00121
00122 double BMPTHistoWeightCalculator::GetWeight(Registry *event)
00123 {
00124
00125 if(!fBMPTHistofile) return 1;
00126 if(!abs(fUseBMPTHistoReweighting)==1) return 1;
00127 if(!event) return 1;
00128
00129
00130 double px = 0;
00131 double py = 0;
00132 double pz = 0;
00133 int pid = 0;
00134 if(!event->Get("event:nuparent_px",px)) return 1;
00135 if(!event->Get("event:nuparent_py",py)) return 1;
00136 if(!event->Get("event:nuparent_pz",pz)) return 1;
00137 if(!event->Get("event:nuparent_pid",pid)) return 1;
00138
00139
00140 std::map<int,TH2F*>::iterator pidHistIter = fPidHist.find(pid);
00141 if( pidHistIter == fPidHist.end() ) {
00142 MSG("BMPTHistoWC",Msg::kWarning) << "Unknown PID: " << pid << endl;
00143 return 1;
00144 }
00145
00146 TH2F *hist = pidHistIter->second;
00147 if(!hist) return 1;
00148
00149 Double_t log_pz = TMath::Log10(pz);
00150 Double_t log_pt = 0.5*TMath::Log10(px*px + py*py);
00151
00152 Int_t binx = hist->GetXaxis()->FindBin(log_pz);
00153 Int_t biny = hist->GetYaxis()->FindBin(log_pt);
00154
00155 if(binx>hist->GetNbinsX()) binx = hist->GetNbinsX();
00156 if(binx<1) binx = 1;
00157 if(biny>hist->GetNbinsY()) biny = hist->GetNbinsY();
00158 if(biny<1) biny = 1;
00159
00160 double weight = hist->GetBinContent(binx,biny);
00161 if(fUseBMPTHistoReweighting==-1) return 1./weight;
00162 return weight;
00163
00164 }
00165
00166
00167 void BMPTHistoWeightCalculator::PrintReweightConfig(ostream & stream)
00168 {
00169 if(!fUseBMPTHistoReweighting) stream << "Not ";
00170 stream << "Using BMPT Histo Reweighting" << endl;
00171 }
00172
00173 #endif