BMPTHistoWeightCalculator Class Reference

#include <BMPTHistoWeightCalculator.h>

Inheritance diagram for BMPTHistoWeightCalculator:
WeightCalculator

List of all members.

Public Member Functions

 BMPTHistoWeightCalculator (Registry *stdconfig=0)
 ~BMPTHistoWeightCalculator ()
void Config ()
void OpenReweightFile ()
double GetWeight (Registry *eventinfo)
double GetWeight (MCEventInfo *event, NuParent *parent)
void ReweightConfigReset ()
void PrintReweightConfig (ostream &)

Protected Attributes

Int_t fUseBMPTHistoReweighting
TFile * fBMPTHistofile
std::map< Int_t, TH2F * > fPidHist

Detailed Description

Definition at line 8 of file BMPTHistoWeightCalculator.h.


Constructor & Destructor Documentation

BMPTHistoWeightCalculator::BMPTHistoWeightCalculator ( Registry stdconfig = 0  ) 

Definition at line 10 of file BMPTHistoWeightCalculator.cxx.

References fBMPTHistofile, fPidHist, WeightCalculator::fReweightConfigChanged, WeightCalculator::fStandardConfigChanged, fUseBMPTHistoReweighting, WeightCalculator::fWCname, OpenReweightFile(), and WeightCalculator::SetStandardConfig().

00011   : WeightCalculator(config)
00012 {
00013 
00014   fWCname = "BMPTHistoWeightCalculator";
00015 
00016   fStandardConfigChanged = false;
00017   fReweightConfigChanged = false;
00018 
00019   if(config) SetStandardConfig(config);
00020   
00021   // 1 = std -> random, 0 = off, -1 = random -> std
00022   fUseBMPTHistoReweighting = 0; 
00023   fBMPTHistofile = 0;  
00024   fPidHist.clear();
00025 
00026   OpenReweightFile();
00027 
00028 }

BMPTHistoWeightCalculator::~BMPTHistoWeightCalculator (  ) 

Definition at line 80 of file BMPTHistoWeightCalculator.cxx.

References fBMPTHistofile.

00081 {
00082   
00083   if(fBMPTHistofile) {
00084     fBMPTHistofile->Close();
00085     delete fBMPTHistofile; 
00086   }
00087   
00088 }


Member Function Documentation

void BMPTHistoWeightCalculator::Config ( void   )  [virtual]

Reimplemented from WeightCalculator.

Definition at line 97 of file BMPTHistoWeightCalculator.cxx.

References WeightCalculator::fReweightConfig, WeightCalculator::fReweightConfigChanged, WeightCalculator::fStandardConfig, WeightCalculator::fStandardConfigChanged, fUseBMPTHistoReweighting, and Registry::Get().

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 }

double BMPTHistoWeightCalculator::GetWeight ( MCEventInfo event,
NuParent parent 
) [virtual]

Reimplemented from WeightCalculator.

Definition at line 114 of file BMPTHistoWeightCalculator.cxx.

00115 {
00116   if(!event) return 1;
00117   if(!parent) return 1;
00118   return 1;
00119 }

double BMPTHistoWeightCalculator::GetWeight ( Registry eventinfo  )  [virtual]

Reimplemented from WeightCalculator.

Definition at line 122 of file BMPTHistoWeightCalculator.cxx.

References fBMPTHistofile, fPidHist, fUseBMPTHistoReweighting, Registry::Get(), Msg::kWarning, and MSG.

00123 {
00124 
00125   if(!fBMPTHistofile) return 1;
00126   if(!abs(fUseBMPTHistoReweighting)==1) return 1;
00127   if(!event) return 1;
00128 
00129   //neutrino parent characteristics:
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   //get the appropriate histogram  
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 }

void BMPTHistoWeightCalculator::OpenReweightFile (  ) 

Definition at line 31 of file BMPTHistoWeightCalculator.cxx.

References fBMPTHistofile, fPidHist, Msg::kError, and MSG.

Referenced by BMPTHistoWeightCalculator().

00032 {
00033 
00034   //get directory from env variable
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   //open file:  
00044   fBMPTHistofile = new TFile(fullpath.c_str(),"READ");
00045 
00046   //check file is opened:  
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   //get histograms from file:
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   //add histograms to map with appropriate PID:
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 }

void BMPTHistoWeightCalculator::PrintReweightConfig ( ostream &  stream  ) 

Definition at line 167 of file BMPTHistoWeightCalculator.cxx.

References fUseBMPTHistoReweighting.

00168 {
00169   if(!fUseBMPTHistoReweighting) stream << "Not ";
00170   stream << "Using BMPT Histo Reweighting" << endl;
00171 }

void BMPTHistoWeightCalculator::ReweightConfigReset (  )  [virtual]

Member Data Documentation

std::map<Int_t,TH2F*> BMPTHistoWeightCalculator::fPidHist [protected]

The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1