Zbeam Class Reference

#include <Zbeam.h>

List of all members.

Classes

struct  ZbeamData

Public Types

typedef struct 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)
TFile * GetBeamSysFile ()

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

Detailed Description

Definition at line 149 of file Zbeam.h.


Member Typedef Documentation

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

Definition at line 204 of file Zbeam.h.

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

Definition at line 205 of file Zbeam.h.

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

Definition at line 203 of file Zbeam.h.


Constructor & Destructor Documentation

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

Definition at line 149 of file Zbeam.cxx.

References base, gSystem(), Msg::kDebug, Msg::kFatal, and MSG.

00150 {
00151   // fTopDir is where the beamsys_hists.root is
00152   fTopDir=dir; // user may set location of input data
00153   if(fTopDir=="") { // by default, this code looks in a standard place
00154     fTopDir="MCReweight/data";
00155     std::string base="";
00156     base=getenv("SRT_PRIVATE_CONTEXT");
00157     if (base!="" && base!=".")
00158       {
00159         // check if directory exists in SRT_PRIVATE_CONTEXT
00160         std::string path = base + "/" + fTopDir;
00161         void *dir_ptr = gSystem -> OpenDirectory(path.c_str());
00162         if(!dir_ptr) base=getenv("SRT_PUBLIC_CONTEXT"); // if it doesn't exist then use SRT_PUBLIC_CONTEXT
00163       }
00164     else base=getenv("SRT_PUBLIC_CONTEXT");
00165     
00166     if(base=="") {
00167       MSG("MCReweight",Msg::kFatal)<<"No SRT_PUBLIC_CONTEXT set"<<std::endl;
00168       assert(false);
00169     }
00170     fTopDir = base+ "/" + fTopDir;
00171   }
00172     MSG("Zbeam",Msg::kDebug) <<"Zbeam getting hists from: "<<fTopDir<<"/beamsys_hists.root"<<std::endl;
00173   
00174   SetReweightConfig("DetXs"); //default config
00175 }

Zbeam::~Zbeam (  )  [virtual]

Definition at line 177 of file Zbeam.cxx.

00177               {
00178 
00179 }


Member Function Documentation

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

Definition at line 445 of file Zbeam.cxx.

00446 {
00447   TFile* f=new TFile(filename.c_str(),"UPDATE");
00448   f->cd(config.c_str());
00449   f->rmdir(name.c_str());
00450   f->Close();
00451   delete f;
00452   f=0;
00453 }

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

Definition at line 455 of file Zbeam.cxx.

References fBeamSysMap, and find().

Referenced by SetReweightConfig().

00456 {
00457   EffMap_t map1;
00458   BeamMap_t map2;
00459   DetMap_t map3;
00460 
00461   const int NBINS=hist->GetNbinsX();
00462   double* vec=new double[NBINS];
00463 
00464   for (int i=1; i<hist->GetNbinsX()+1;i++) vec[i-1]=hist->GetBinContent(i);
00465 
00466   map1.insert(EffMap_t::value_type(eff, vec));
00467   map2.insert(BeamMap_t::value_type(beam, map1));
00468   map3.insert(DetMap_t::value_type(det, map2));
00469 
00470   std::map<int, DetMap_t>::iterator bsmit = fBeamSysMap.find(ntype);
00471 
00472   if (bsmit == fBeamSysMap.end()) {
00473     fBeamSysMap.insert(std::map<int, DetMap_t>::value_type(ntype, map3));
00474   } else {
00475     DetMap_t::iterator dmit = (bsmit->second).find(det);
00476     if (dmit == (bsmit->second).end() ) {
00477       ((*bsmit).second).insert(DetMap_t::value_type(det,map2));
00478     } else {
00479       BeamMap_t::iterator bmit = (dmit->second).find(beam);
00480       if (bmit == (dmit->second).end() ) {
00481         ((*dmit).second).insert(BeamMap_t::value_type(beam,map1));
00482       } else {
00483         EffMap_t::iterator effit = (bmit->second).find(eff);
00484         if (effit == (bmit->second).end() ) {
00485           ((*bmit).second).insert(EffMap_t::value_type(eff,vec));
00486         } else {
00487           cout << "Already loaded vector for: " 
00488                << "beam "<<beam<< " det "<<det<<" nu "<<ntype<<" eff "<<eff<<endl;
00489           return;
00490         }
00491       }
00492     }
00493   } 
00494 }

TFile* Zbeam::GetBeamSysFile (  )  [inline]

Definition at line 196 of file Zbeam.h.

References fBeamSysFile.

00196 {return fBeamSysFile;}

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

Definition at line 167 of file Zbeam.h.

References Zbeam::ZbeamData::detector, GetWeight(), and Detector::kUnknown.

00168   {
00169     zbmdata.detector = Detector::kUnknown;
00170     return GetWeight(zbmdata, sys, nSigma);
00171   };

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

Definition at line 183 of file Zbeam.h.

References GetWeight().

Referenced by GetWeight().

00184   { 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 365 of file Zbeam.cxx.

References Zbeam::ZbeamData::beam, Zbeam::ZbeamData::detector, BeamType::FromZarko(), GetWeight(), Detector::kUnknown, Zbeam::ZbeamData::ntype, and Zbeam::ZbeamData::true_enu.

00367 {
00368   ZbeamData_t zbm;
00369   zbm.beam = BeamType::FromZarko(iBeam);
00370   zbm.detector = (iDet != 3) ?  Detector::EDetector(iDet) : Detector::kUnknown;
00371   zbm.ntype = ntype;
00372   zbm.true_enu = Enu;
00373 
00374   std::map<BeamSys::BeamSys_t, double> sgm;
00375   for (unsigned int nEffect=0; nEffect<nSigma.size();nEffect++)
00376     {
00377       BeamSys::BeamSys_t sys = BeamSys::EBeamSys(nEffect+1);
00378       const std::pair<BeamSys::BeamSys_t, double> sp(sys, nSigma[nEffect]);
00379       sgm.insert(sp);
00380     }
00381   return GetWeight(zbm, sgm);
00382 }

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

Definition at line 352 of file Zbeam.cxx.

References Zbeam::ZbeamData::beam, Zbeam::ZbeamData::detector, BeamType::FromZarko(), GetWeight(), Detector::kUnknown, Zbeam::ZbeamData::ntype, and Zbeam::ZbeamData::true_enu.

00354 {
00355   ZbeamData_t zbm;
00356   zbm.beam = BeamType::FromZarko(iBeam);
00357   zbm.detector = (iDet != 3) ?  Detector::EDetector(iDet) : Detector::kUnknown;
00358   zbm.ntype = ntype;
00359   zbm.true_enu = Enu; 
00360   BeamSys::BeamSys_t sys = BeamSys::EBeamSys(nEffect);
00361 
00362   return GetWeight(zbm,sys, nSigma);
00363 }

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

Definition at line 339 of file Zbeam.cxx.

References GetWeight().

00340 { 
00341   double wgh=1.;
00342   std::map<BeamSys::BeamSys_t, double>::const_iterator bsit;
00343 
00344   for (bsit=nSigma.begin();bsit != nSigma.end() ;bsit++)
00345     {
00346       wgh*=GetWeight(zbmdata,bsit->first, bsit->second); 
00347     }
00348   cout<<"zbeam weight= "<<wgh<<endl;
00349   return wgh; 
00350 } 

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

Definition at line 234 of file Zbeam.cxx.

References Zbeam::ZbeamData::beam, det, Zbeam::ZbeamData::detector, fBeamSysMap, find(), BeamSys::kBaffleScraping, BeamSys::kBeamWidth, BeamSys::kEndOfList, BeamSys::kFirst, BeamSys::kHadProdAfter, BeamSys::kHadProdBefore, BeamSys::kHorn1Offset, BeamSys::kHornIDist, BeamSys::kTotalAfter, BeamSys::kTotalBefore, BeamSys::kTotalFocusing, Zbeam::ZbeamData::ntype, and Zbeam::ZbeamData::true_enu.

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

00235 {
00236   int ntype  = zbmdata.ntype;
00237   double Enu = zbmdata.true_enu;
00238   Detector::Detector_t det = zbmdata.detector;
00239   BeamType::BeamType_t beam = zbmdata.beam;
00240 
00241   //   cout<<"beam type = "<<beam<<endl;
00242 
00243   int bin;
00244   bin=int(2*Enu);
00245   if (bin<0) bin=0;
00246      if (beam==44||beam==47){
00247      if (bin>59) bin=59;
00248      } 
00249      else {
00250        if (bin>99) bin=99;
00251      }
00252      //MINOS+ hists only go to 30GeV, MINOS to 50GeV - ANNA
00253  
00254 
00255 
00256 
00257   if (ntype == 14) ntype = 56;
00258   else if (ntype == -14) ntype = 55;
00259   else if (ntype == 12) ntype = 53;
00260   else if (ntype == -12) ntype = 52;
00261 
00262   double weight = 1. ;
00263   double totError=0.;
00264   BeamSys::BeamSys_t first=sys; 
00265   BeamSys::BeamSys_t last=sys;
00266   if (sys == BeamSys::kTotalBefore || sys == BeamSys::kTotalAfter) //Total Error
00267     {
00268       first = BeamSys::kFirst;
00269       last = BeamSys::kEndOfList; 
00270     }
00271   else if(sys == BeamSys::kTotalFocusing)
00272     {
00273       first = BeamSys::kFirst;
00274       last = BeamSys::kHornIDist;
00275     } 
00276 
00277   std::map<int, DetMap_t>::iterator bsmit = fBeamSysMap.find(ntype);   
00278   DetMap_t::iterator dmit;
00279   BeamMap_t::iterator bmit;
00280   bool beam_it_exists = true;
00281   if (bsmit == fBeamSysMap.end()) {
00282     weight = 0.; 
00283     beam_it_exists = false;
00284   } else {
00285     dmit = (bsmit->second).find(det);
00286     if (dmit == (bsmit->second).end() ) {
00287       weight = 0.; 
00288       beam_it_exists = false;
00289     } else {
00290       bmit = (dmit->second).find(beam);
00291       if (bmit == (dmit->second).end() ) {
00292         weight = 0.; 
00293         beam_it_exists = false;
00294       } 
00295     }
00296   }
00297 
00298   if (beam_it_exists) {
00299     for (int eff=first;eff<=last;eff++) {    
00300       if (BeamSys::EBeamSys(eff) != BeamSys::kTotalBefore && 
00301           BeamSys::EBeamSys(eff) != BeamSys::kTotalAfter &&
00302           BeamSys::EBeamSys(eff) != BeamSys::kHadProdBefore && 
00303           BeamSys::EBeamSys(eff) != BeamSys::kHadProdAfter &&
00304           BeamSys::EBeamSys(eff) != BeamSys::kTotalFocusing )
00305         {
00306           EffMap_t::iterator effit = (bmit->second).find(eff);
00307           weight =  ( effit == (bmit->second).end() ) ?  0. : ((*effit).second)[bin];
00308           totError += weight*weight;
00309         }
00310     } // loop over all effects 
00311     
00312     if ((sys == BeamSys::kTotalBefore || sys == BeamSys::kHadProdBefore )) {
00313       EffMap_t::iterator effit = (bmit->second).find(BeamSys::kHadProdBefore);
00314       weight =  ( effit == (bmit->second).end() ) ?  0. : ((*effit).second)[bin];
00315       totError += weight*weight;
00316     }
00317     if ((sys == BeamSys::kTotalAfter || sys == BeamSys::kHadProdAfter )) {
00318       EffMap_t::iterator effit = (bmit->second).find(BeamSys::kHadProdAfter);
00319       weight =  ( effit == (bmit->second).end() ) ?  0. : ((*effit).second)[bin];
00320       totError += weight*weight;
00321     }
00322   }
00323 
00324   totError=sqrt(totError);  
00325   
00326   if (!(sys == BeamSys::kTotalBefore || sys == BeamSys::kTotalAfter 
00327         || sys == BeamSys::kTotalFocusing))  totError *= ( (weight>0.) - (weight<0.) );
00328   
00329   double nS = (sys == BeamSys::kBeamWidth) ? nSigma + 1. : nSigma; // by default reweights pME, pHE and lowint 
00330 
00331   //some of the effects are symmetric and only abs(nS) makes sense
00332   totError = ((sys == BeamSys::kHorn1Offset) ||
00333               (sys == BeamSys::kBaffleScraping)) ? totError*fabs(nS)+1.0 :  totError*nS+1.;        // modified later: totError = totError*nS+1.;
00334  
00335   return totError;  
00336 } 

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

Definition at line 384 of file Zbeam.cxx.

References BeamType::AsString(), BeamSys::AsString(), Detector::AsString(), det, fHistMap, BeamType::kEndOfList, BeamSys::kEndOfList, Detector::kFar, BeamSys::kFirst, Detector::kNear, BeamType::kUnknown, NueConvention::nue, and NueConvention::numu.

00385 {
00386   //Function creates a histogram using a vector vec (assumes 0.5GeV bins)
00387   //Check if the name contains the detector, beam and effect
00388   //This doesn't guarantee that the name is correct. 
00389   //The name should look like this NuMu_Horn1Offset_L010z185i_Near ...
00390   bool validname=false;
00391   std::string numu="NuMu";
00392   std::string numubar="NuMuBar";
00393   std::string nue="NuE";
00394   std::string nuebar="NuEBar";
00395   
00396   for (int det=Detector::kNear;det<=Detector::kFar;det++) {
00397     for (int beam=BeamType::kUnknown;beam<BeamType::kEndOfList;beam++) {
00398       for (int eff=BeamSys::kFirst;eff<BeamSys::kEndOfList;eff++) {
00399         if (((name.find(Detector::AsString(Detector::Detector_t(det))) != string::npos)||name.find("FN") != string::npos) &&
00400             (name.find(BeamType::AsString(BeamType::BeamType_t(beam))) != string::npos) &&
00401             (name.find(BeamSys::AsString(BeamSys::BeamSys_t(eff))) != string::npos) &&
00402             ((name.find(numu) != string::npos) || (name.find(numubar) != string::npos) ||
00403              (name.find(nue) != string::npos) || (name.find(nuebar) != string::npos))) {
00404           validname=true;
00405         } 
00406       }
00407     }
00408   }
00409   if (!validname) {
00410     cout<<"Invalid histogram name! "<<name <<endl;
00411     cout<<"Name should include beam (as in BeamType), detector (as in Detector)" 
00412         <<" and beam systematics type"<<endl;
00413     return;
00414   }
00415   cout<<"Creating "<<name<<" histogram"<<endl;
00416   unsigned int nbins=vec.size()-1;
00417   double maxx=0.5*nbins;
00418 
00419   TH1D* hist=new TH1D(name.c_str(),name.c_str(),nbins,0.,maxx);
00420   for (unsigned int i=1;i<nbins+1;i++)
00421     hist->SetBinContent(i,vec[i-1]);
00422   
00423   fHistMap[name]=hist;
00424 }

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

Definition at line 426 of file Zbeam.cxx.

References fHistMap, and it.

00427 {
00428   map<std::string, TH1D* >::iterator it = fHistMap.find(name);
00429   if ( it == fHistMap.end() ) {
00430     cout << name <<" does not exist!"<<endl;
00431     return;
00432   }
00433   TFile* f=new TFile(filename.c_str(),"UPDATE");
00434   if (!f->GetListOfKeys()->Contains(config.c_str())) {
00435     cout << "Creating directory for " << config << " configuration" << endl;
00436     f->mkdir(config.c_str());
00437   }
00438   f->cd(config.c_str());
00439   fHistMap[name]->Write();
00440   f->Close();
00441   delete f;
00442   f=0;
00443 }

void Zbeam::SetReweightConfig ( std::string  cnf  ) 

Definition at line 181 of file Zbeam.cxx.

References bfld::AsString(), det, fBeamSysFile, fBeamSysMap, fCurrentConfig, FillVector(), Form(), fTopDir, BeamType::kEndOfList, BeamSys::kEndOfList, Detector::kFar, Msg::kFatal, BeamSys::kFirst, Detector::kNear, Detector::kUnknown, BeamType::kUnknown, and MSG.

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

00182 {
00183   if ( cnf == fCurrentConfig) return;
00184   TDirectory *save = gDirectory;
00185 
00186    fBeamSysFile = new TFile(Form("%s/beamsys_%s.root",fTopDir.c_str(),cnf.c_str()));
00187 
00188   if (fBeamSysFile->IsZombie()) {
00189     MSG("Zbeam",Msg::kFatal)<<"Don't recognize "
00190                             <<cnf
00191                             <<" configuration."
00192                             <<" Config set to :"
00193                             <<fCurrentConfig<<endl;
00194     
00195     return;
00196   } 
00197 
00198   cout<<"The config version is: "<<cnf<<" and current config "<<fCurrentConfig<<endl;
00199   cout<<"The File Read in is: "<<cnf.c_str()<<endl;
00200 
00201   
00202   fBeamSysMap.clear();
00203   fCurrentConfig = cnf;
00204   std::string nus[]={"NuMu","NuMuBar","NuE","NuEBar"};
00205   int ntype[]    ={    56,       55  , 53  , 52};
00206   for (int inu=0;inu<4;inu++) {
00207     for (int eff=BeamSys::kFirst;eff<BeamSys::kEndOfList;eff++) {
00208       for (int beam=BeamType::kUnknown;beam<BeamType::kEndOfList;beam++) {
00209         for (int det=Detector::kNear;det<=Detector::kFar;det++) {
00210           std::string hname=nus[inu]+"_"+
00211             BeamSys::AsString(BeamSys::BeamSys_t(eff))+"_"+
00212             BeamType::AsString(BeamType::BeamType_t(beam))+"_"+
00213             Detector::AsString(Detector::Detector_t(det));
00214           TH1D* hist=dynamic_cast<TH1D*> (fBeamSysFile->Get(hname.c_str()));
00215           //      cout<<eff<<" hname is "<<hname<<endl;
00216           if (hist) FillVector(hist,ntype[inu],eff,beam,det);
00217         }
00218         //for far/near error bar internally use Detector::kUnknown
00219         std::string hname=nus[inu]+"_"+
00220           BeamSys::AsString(BeamSys::BeamSys_t(eff))+"_"+
00221           BeamType::AsString(BeamType::BeamType_t(beam))+"_FN";
00222         TH1D* hist=dynamic_cast<TH1D*> (fBeamSysFile->Get(hname.c_str()));
00223         if (hist) FillVector(hist,ntype[inu],eff,beam,Detector::kUnknown);
00224       }
00225     }
00226   }
00227   
00228   fBeamSysFile->Close();
00229   delete fBeamSysFile;
00230   fBeamSysFile = 0;
00231   save->cd();
00232 }


Member Data Documentation

TFile* Zbeam::fBeamSysFile [private]

Definition at line 199 of file Zbeam.h.

Referenced by GetBeamSysFile(), and SetReweightConfig().

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

Definition at line 206 of file Zbeam.h.

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

std::string Zbeam::fCurrentConfig [private]

Definition at line 200 of file Zbeam.h.

Referenced by SetReweightConfig().

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

Definition at line 208 of file Zbeam.h.

Referenced by MakeHistogram(), and SaveHistogram().

std::string Zbeam::fTopDir [private]

Definition at line 201 of file Zbeam.h.

Referenced by SetReweightConfig().


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

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1