Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Zbeam Class Reference

#include <Zbeam.h>

List of all members.

Public Types

typedef Zbeam::ZbeamData ZbeamData_t

Public Member Functions

 Zbeam (const char *dir="")
virtual ~Zbeam ()
void SetReweightConfig (std::string cnf)
double GetWeight (ZbeamData_t zbmdata, BeamSys::BeamSys_t sys, double nSigma)
double GetWeight (ZbeamData_t zbmdata, std::map< BeamSys::BeamSys_t, double > nSigma)
double GetFarOverNearError (ZbeamData_t zbmdata, BeamSys::BeamSys_t sys, double nSigma)
double GetWeight (int iDet, int iBeam, int nEffect, double nSigma, int ntype, double Enu)
double GetWeight (int iDet, int iBeam, std::vector< double > nSigma, int ntype, double Enu)
double GetWeight (int iDet, int iBeam, int nEffect, double nSigma, double Enu)
void MakeHistogram (std::string name, std::vector< double > vec)
void SaveHistogram (std::string name, std::string config, std::string file)
void DeleteHistogram (std::string name, std::string config, std::string file)
void FillVector (TH1D *hist, int ntype, int eff, int beam, int det)

Private Types

typedef std::map< int, double * > EffMap_t
typedef std::map< int, EffMap_tBeamMap_t
typedef std::map< int, BeamMap_tDetMap_t

Private Attributes

TFile * fBeamSysFile
std::string fCurrentConfig
std::string fTopDir
std::map< int, DetMap_tfBeamSysMap
std::map< std::string, TH1D * > fHistMap


Member Typedef Documentation

typedef std::map<int , EffMap_t > Zbeam::BeamMap_t [private]
 

Definition at line 200 of file Zbeam.h.

Referenced by FillVector().

typedef std::map<int , BeamMap_t > Zbeam::DetMap_t [private]
 

Definition at line 201 of file Zbeam.h.

Referenced by FillVector().

typedef std::map<int , double* > Zbeam::EffMap_t [private]
 

Definition at line 199 of file Zbeam.h.

Referenced by FillVector().

typedef struct Zbeam::ZbeamData Zbeam::ZbeamData_t
 

Referenced by SKZPWeightCalculator::GetBeamWeight(), GetFarOverNearError(), SKZPWeightCalculator::GetRunPeriodWeight(), and GetWeight().


Constructor & Destructor Documentation

Zbeam::Zbeam const char *  dir = ""  ) 
 

Definition at line 137 of file Zbeam.cxx.

References base, gSystem(), and MSG.

00138 {
00139   // fTopDir is where the beamsys_hists.root is
00140   fTopDir=dir; // user may set location of input data
00141   if(fTopDir=="") { // by default, this code looks in a standard place
00142     fTopDir="MCReweight/data";
00143     std::string base="";
00144     base=getenv("SRT_PRIVATE_CONTEXT");
00145     if (base!="" && base!=".")
00146       {
00147         // check if directory exists in SRT_PRIVATE_CONTEXT
00148         std::string path = base + "/" + fTopDir;
00149         void *dir_ptr = gSystem -> OpenDirectory(path.c_str());
00150         if(!dir_ptr) base=getenv("SRT_PUBLIC_CONTEXT"); // if it doesn't exist then use SRT_PUBLIC_CONTEXT
00151       }
00152     else base=getenv("SRT_PUBLIC_CONTEXT");
00153     
00154     if(base=="") {
00155       MSG("MCReweight",Msg::kFatal)<<"No SRT_PUBLIC_CONTEXT set"<<std::endl;
00156       assert(false);
00157     }
00158     fTopDir = base+ "/" + fTopDir;
00159   }
00160   MSG("Zbeam",Msg::kDebug) <<"Zbeam getting hists from: "<<fTopDir<<"/beamsys_hists.root"<<std::endl;
00161    
00162   SetReweightConfig("PRL"); //default config
00163 }

Zbeam::~Zbeam  )  [virtual]
 

Definition at line 165 of file Zbeam.cxx.

00165               {
00166 
00167 }


Member Function Documentation

void Zbeam::DeleteHistogram std::string  name,
std::string  config,
std::string  file
 

Definition at line 415 of file Zbeam.cxx.

00416 {
00417   TFile* f=new TFile(filename.c_str(),"UPDATE");
00418   f->cd(config.c_str());
00419   f->rmdir(name.c_str());
00420   f->Close();
00421   delete f;
00422   f=0;
00423 }

void Zbeam::FillVector TH1D *  hist,
int  ntype,
int  eff,
int  beam,
int  det
 

Definition at line 425 of file Zbeam.cxx.

References BeamMap_t, det, DetMap_t, EffMap_t, and fBeamSysMap.

Referenced by SetReweightConfig().

00426 {
00427   EffMap_t map1;
00428   BeamMap_t map2;
00429   DetMap_t map3;
00430 
00431   const int NBINS=hist->GetNbinsX();
00432   double* vec=new double[NBINS];
00433 
00434   for (int i=1; i<hist->GetNbinsX()+1;i++) vec[i-1]=hist->GetBinContent(i);
00435 
00436   map1.insert(EffMap_t::value_type(eff, vec));
00437   map2.insert(BeamMap_t::value_type(beam, map1));
00438   map3.insert(DetMap_t::value_type(det, map2));
00439 
00440   std::map<int, DetMap_t>::iterator bsmit = fBeamSysMap.find(ntype);
00441 
00442   if (bsmit == fBeamSysMap.end()) {
00443     fBeamSysMap.insert(std::map<int, DetMap_t>::value_type(ntype, map3));
00444   } else {
00445     DetMap_t::iterator dmit = (bsmit->second).find(det);
00446     if (dmit == (bsmit->second).end() ) {
00447       ((*bsmit).second).insert(DetMap_t::value_type(det,map2));
00448     } else {
00449       BeamMap_t::iterator bmit = (dmit->second).find(beam);
00450       if (bmit == (dmit->second).end() ) {
00451         ((*dmit).second).insert(BeamMap_t::value_type(beam,map1));
00452       } else {
00453         EffMap_t::iterator effit = (bmit->second).find(eff);
00454         if (effit == (bmit->second).end() ) {
00455           ((*bmit).second).insert(EffMap_t::value_type(eff,vec));
00456         } else {
00457           cout << "Already loaded vector for: " 
00458                << "beam "<<beam<< " det "<<det<<" nu "<<ntype<<" eff "<<eff<<endl;
00459           return;
00460         }
00461       }
00462     }
00463   } 
00464 }

double Zbeam::GetFarOverNearError ZbeamData_t  zbmdata,
BeamSys::BeamSys_t  sys,
double  nSigma
[inline]
 

Definition at line 164 of file Zbeam.h.

References Zbeam::ZbeamData::detector, and ZbeamData_t.

00165   {
00166     zbmdata.detector = Detector::kUnknown;
00167     return GetWeight(zbmdata, sys, nSigma);
00168   };

double Zbeam::GetWeight int  iDet,
int  iBeam,
int  nEffect,
double  nSigma,
double  Enu
[inline]
 

Definition at line 180 of file Zbeam.h.

00181   { return GetWeight(iDet, iBeam, nEffect, nSigma, 56, Enu);} 

double Zbeam::GetWeight int  iDet,
int  iBeam,
std::vector< double >  nSigma,
int  ntype,
double  Enu
 

Definition at line 335 of file Zbeam.cxx.

References Zbeam::ZbeamData::beam, Zbeam::ZbeamData::detector, BeamSys::EBeamSys, Detector::EDetector, BeamType::FromZarko(), GetWeight(), Zbeam::ZbeamData::ntype, Zbeam::ZbeamData::true_enu, and ZbeamData_t.

00337 {
00338   ZbeamData_t zbm;
00339   zbm.beam = BeamType::FromZarko(iBeam);
00340   zbm.detector = (iDet != 3) ?  Detector::EDetector(iDet) : Detector::kUnknown;
00341   zbm.ntype = ntype;
00342   zbm.true_enu = Enu;
00343 
00344   std::map<BeamSys::BeamSys_t, double> sgm;
00345   for (unsigned int nEffect=0; nEffect<nSigma.size();nEffect++)
00346     {
00347       BeamSys::BeamSys_t sys = BeamSys::EBeamSys(nEffect+1);
00348       const std::pair<BeamSys::BeamSys_t, double> sp(sys, nSigma[nEffect]);
00349       sgm.insert(sp);
00350     }
00351   return GetWeight(zbm, sgm);
00352 }

double Zbeam::GetWeight int  iDet,
int  iBeam,
int  nEffect,
double  nSigma,
int  ntype,
double  Enu
 

Definition at line 322 of file Zbeam.cxx.

References Zbeam::ZbeamData::beam, Zbeam::ZbeamData::detector, BeamSys::EBeamSys, Detector::EDetector, BeamType::FromZarko(), GetWeight(), Zbeam::ZbeamData::ntype, Zbeam::ZbeamData::true_enu, and ZbeamData_t.

00324 {
00325   ZbeamData_t zbm;
00326   zbm.beam = BeamType::FromZarko(iBeam);
00327   zbm.detector = (iDet != 3) ?  Detector::EDetector(iDet) : Detector::kUnknown;
00328   zbm.ntype = ntype;
00329   zbm.true_enu = Enu; 
00330   BeamSys::BeamSys_t sys = BeamSys::EBeamSys(nEffect);
00331 
00332   return GetWeight(zbm,sys, nSigma);
00333 }

double Zbeam::GetWeight ZbeamData_t  zbmdata,
std::map< BeamSys::BeamSys_t, double >  nSigma
 

Definition at line 310 of file Zbeam.cxx.

References GetWeight(), and ZbeamData_t.

00311 { 
00312   double wgh=1.;
00313   std::map<BeamSys::BeamSys_t, double>::const_iterator bsit;
00314 
00315   for (bsit=nSigma.begin();bsit != nSigma.end() ;bsit++)
00316     {
00317       wgh*=GetWeight(zbmdata,bsit->first, bsit->second); 
00318     }
00319   return wgh; 
00320 } 

double Zbeam::GetWeight ZbeamData_t  zbmdata,
BeamSys::BeamSys_t  sys,
double  nSigma
 

Definition at line 217 of file Zbeam.cxx.

References Zbeam::ZbeamData::beam, det, Zbeam::ZbeamData::detector, BeamSys::EBeamSys, fBeamSysMap, Zbeam::ZbeamData::ntype, Zbeam::ZbeamData::true_enu, and ZbeamData_t.

Referenced by SKZPWeightCalculator::GetBeamWeight(), SKZPWeightCalculator::GetFluxError(), SKZPWeightCalculator::GetRunPeriodWeight(), and GetWeight().

00218 {
00219   int ntype  = zbmdata.ntype;
00220   double Enu = zbmdata.true_enu;
00221   Detector::Detector_t det = zbmdata.detector;
00222   BeamType::BeamType_t beam = zbmdata.beam;
00223 
00224   int bin;
00225   bin=int(2*Enu);
00226   if (bin<0) bin=0;
00227   if (bin>99) bin=99;
00228 
00229   if (ntype == 14) ntype = 56;
00230   else if (ntype == -14) ntype = 55;
00231   else if (ntype == 12) ntype = 53;
00232   else if (ntype == -12) ntype = 52;
00233 
00234   double weight = 1. ;
00235   double totError=0.;
00236   BeamSys::BeamSys_t first=sys; 
00237   BeamSys::BeamSys_t last=sys;
00238   if (sys == BeamSys::kTotalBefore || sys == BeamSys::kTotalAfter) //Total Error
00239     {
00240       first = BeamSys::kFirst;
00241       last = BeamSys::kEndOfList; 
00242     }
00243   else if(sys == BeamSys::kTotalFocusing)
00244     {
00245       first = BeamSys::kFirst;
00246       last = BeamSys::kHornIDist;
00247     } 
00248 
00249   std::map<int, DetMap_t>::iterator bsmit = fBeamSysMap.find(ntype);   
00250   DetMap_t::iterator dmit;
00251   BeamMap_t::iterator bmit;
00252   bool beam_it_exists = true;
00253   if (bsmit == fBeamSysMap.end()) {
00254     weight = 0.; 
00255     beam_it_exists = false;
00256   } else {
00257     dmit = (bsmit->second).find(det);
00258     if (dmit == (bsmit->second).end() ) {
00259       weight = 0.; 
00260       beam_it_exists = false;
00261     } else {
00262       bmit = (dmit->second).find(beam);
00263       if (bmit == (dmit->second).end() ) {
00264         weight = 0.; 
00265         beam_it_exists = false;
00266       } 
00267     }
00268   }
00269 
00270   if (beam_it_exists) {
00271     for (int eff=first;eff<=last;eff++) {    
00272       if (BeamSys::EBeamSys(eff) != BeamSys::kTotalBefore && 
00273           BeamSys::EBeamSys(eff) != BeamSys::kTotalAfter &&
00274           BeamSys::EBeamSys(eff) != BeamSys::kHadProdBefore && 
00275           BeamSys::EBeamSys(eff) != BeamSys::kHadProdAfter &&
00276           BeamSys::EBeamSys(eff) != BeamSys::kTotalFocusing )
00277         {
00278           EffMap_t::iterator effit = (bmit->second).find(eff);
00279           weight =  ( effit == (bmit->second).end() ) ?  0. : ((*effit).second)[bin];
00280           totError += weight*weight;
00281         }
00282     } // loop over all effects 
00283     
00284     if ((sys == BeamSys::kTotalBefore || sys == BeamSys::kHadProdBefore )) {
00285       EffMap_t::iterator effit = (bmit->second).find(BeamSys::kHadProdBefore);
00286       weight =  ( effit == (bmit->second).end() ) ?  0. : ((*effit).second)[bin];
00287       totError += weight*weight;
00288     }
00289     if ((sys == BeamSys::kTotalAfter || sys == BeamSys::kHadProdAfter )) {
00290       EffMap_t::iterator effit = (bmit->second).find(BeamSys::kHadProdAfter);
00291       weight =  ( effit == (bmit->second).end() ) ?  0. : ((*effit).second)[bin];
00292       totError += weight*weight;
00293     }
00294   }
00295 
00296   totError=sqrt(totError);
00297   
00298   if (!(sys == BeamSys::kTotalBefore || sys == BeamSys::kTotalAfter 
00299         || sys == BeamSys::kTotalFocusing))  totError *= ( (weight>0.) - (weight<0.) );
00300   
00301   double nS = (sys == BeamSys::kBeamWidth) ? nSigma + 1. : nSigma; // by default reweights pME, pHE and lowint 
00302 
00303   //some of the effects are symmetric and only abs(nS) makes sense
00304   totError = ((sys == BeamSys::kHorn1Offset) ||
00305               (sys == BeamSys::kBaffleScraping)) ? totError*fabs(nS)+1.0 :  totError*nS+1.; 
00306  
00307   return totError;  
00308 } 

void Zbeam::MakeHistogram std::string  name,
std::vector< double >  vec
 

Definition at line 354 of file Zbeam.cxx.

References det, and fHistMap.

00355 {
00356   //Function creates a histogram using a vector vec (assumes 0.5GeV bins)
00357   //Check if the name contains the detector, beam and effect
00358   //This doesn't guarantee that the name is correct. 
00359   //The name should look like this NuMu_Horn1Offset_L010z185i_Near ...
00360   bool validname=false;
00361   std::string numu="NuMu";
00362   std::string numubar="NuMuBar";
00363   std::string nue="NuE";
00364   std::string nuebar="NuEBar";
00365   
00366   for (int det=Detector::kNear;det<=Detector::kFar;det++) {
00367     for (int beam=BeamType::kUnknown;beam<BeamType::kEndOfList;beam++) {
00368       for (int eff=BeamSys::kFirst;eff<BeamSys::kEndOfList;eff++) {
00369         if (((name.find(Detector::AsString(Detector::Detector_t(det))) != string::npos)||name.find("FN") != string::npos) &&
00370             (name.find(BeamType::AsString(BeamType::BeamType_t(beam))) != string::npos) &&
00371             (name.find(BeamSys::AsString(BeamSys::BeamSys_t(eff))) != string::npos) &&
00372             ((name.find(numu) != string::npos) || (name.find(numubar) != string::npos) ||
00373              (name.find(nue) != string::npos) || (name.find(nuebar) != string::npos))) {
00374           validname=true;
00375         } 
00376       }
00377     }
00378   }
00379   if (!validname) {
00380     cout<<"Invalid histogram name! "<<name <<endl;
00381     cout<<"Name should include beam (as in BeamType), detector (as in Detector)" 
00382         <<" and beam systematics type"<<endl;
00383     return;
00384   }
00385   cout<<"Creating "<<name<<" histogram"<<endl;
00386   unsigned int nbins=vec.size()-1;
00387   double maxx=0.5*nbins;
00388 
00389   TH1D* hist=new TH1D(name.c_str(),name.c_str(),nbins,0.,maxx);
00390   for (unsigned int i=1;i<nbins+1;i++)
00391     hist->SetBinContent(i,vec[i-1]);
00392   
00393   fHistMap[name]=hist;
00394 }

void Zbeam::SaveHistogram std::string  name,
std::string  config,
std::string  file
 

Definition at line 396 of file Zbeam.cxx.

References fHistMap.

00397 {
00398   map<std::string, TH1D* >::iterator it = fHistMap.find(name);
00399   if ( it == fHistMap.end() ) {
00400     cout << name <<" does not exist!"<<endl;
00401     return;
00402   }
00403   TFile* f=new TFile(filename.c_str(),"UPDATE");
00404   if (!f->GetListOfKeys()->Contains(config.c_str())) {
00405     cout << "Creating directory for " << config << " configuration" << endl;
00406     f->mkdir(config.c_str());
00407   }
00408   f->cd(config.c_str());
00409   fHistMap[name]->Write();
00410   f->Close();
00411   delete f;
00412   f=0;
00413 }

void Zbeam::SetReweightConfig std::string  cnf  ) 
 

Definition at line 169 of file Zbeam.cxx.

References Detector::AsString(), BeamType::AsString(), BeamSys::AsString(), det, fBeamSysFile, fBeamSysMap, fCurrentConfig, FillVector(), Form(), fTopDir, and MSG.

Referenced by SKZPWeightCalculator::Config(), and SKZPWeightCalculator::GetFluxError().

00170 {
00171   if ( cnf == fCurrentConfig) return;
00172   TDirectory *save = gDirectory;
00173 
00174   fBeamSysFile = new TFile(Form("%s/beamsys_%s.root",fTopDir.c_str(),cnf.c_str()));
00175   if (fBeamSysFile->IsZombie()) {
00176     MSG("Zbeam",Msg::kFatal)<<"Don't recognize "
00177                             <<cnf
00178                             <<" configuration."
00179                             <<" Config set to :"
00180                             <<fCurrentConfig<<endl;
00181     
00182     return;
00183   }
00184   
00185   fBeamSysMap.clear();
00186   fCurrentConfig = cnf;
00187   std::string nus[]={"NuMu","NuMuBar","NuE","NuEBar"};
00188   int ntype[]    ={    56,       55  , 53  , 52};
00189   for (int inu=0;inu<4;inu++) {
00190     for (int eff=BeamSys::kFirst;eff<BeamSys::kEndOfList;eff++) {
00191       for (int beam=BeamType::kUnknown;beam<BeamType::kEndOfList;beam++) {
00192         for (int det=Detector::kNear;det<=Detector::kFar;det++) {
00193           std::string hname=nus[inu]+"_"+
00194             BeamSys::AsString(BeamSys::BeamSys_t(eff))+"_"+
00195             BeamType::AsString(BeamType::BeamType_t(beam))+"_"+
00196             Detector::AsString(Detector::Detector_t(det));
00197           TH1D* hist=dynamic_cast<TH1D*> (fBeamSysFile->Get(hname.c_str()));
00198           //      cout<<eff<<" hname is "<<hname<<endl;
00199           if (hist) FillVector(hist,ntype[inu],eff,beam,det);
00200         }
00201         //for far/near error bar internally use Detector::kUnknown
00202         std::string hname=nus[inu]+"_"+
00203           BeamSys::AsString(BeamSys::BeamSys_t(eff))+"_"+
00204           BeamType::AsString(BeamType::BeamType_t(beam))+"_FN";
00205         TH1D* hist=dynamic_cast<TH1D*> (fBeamSysFile->Get(hname.c_str()));
00206         if (hist) FillVector(hist,ntype[inu],eff,beam,Detector::kUnknown);
00207       }
00208     }
00209   }
00210   
00211   fBeamSysFile->Close();
00212   delete fBeamSysFile;
00213   fBeamSysFile = 0;
00214   save->cd();
00215 }


Member Data Documentation

TFile* Zbeam::fBeamSysFile [private]
 

Definition at line 195 of file Zbeam.h.

Referenced by SetReweightConfig().

std::map<int, DetMap_t > Zbeam::fBeamSysMap [private]
 

Definition at line 202 of file Zbeam.h.

Referenced by FillVector(), GetWeight(), and SetReweightConfig().

std::string Zbeam::fCurrentConfig [private]
 

Definition at line 196 of file Zbeam.h.

Referenced by SetReweightConfig().

std::map<std::string, TH1D* > Zbeam::fHistMap [private]
 

Definition at line 204 of file Zbeam.h.

Referenced by MakeHistogram(), and SaveHistogram().

std::string Zbeam::fTopDir [private]
 

Definition at line 197 of file Zbeam.h.

Referenced by SetReweightConfig().


The documentation for this class was generated from the following files:
Generated on Mon Feb 15 11:10:30 2010 for loon by  doxygen 1.3.9.1