Public Member Functions | Protected Attributes | List of all members
ana::MultiHistContainer Class Reference

Public Member Functions

 MultiHistContainer (const std::string &filename, const std::vector< std::string > &histNameVec, const std::string &histDivisorName="")
 
TH1 * Hist (const std::string &key) const
 

Protected Attributes

std::string fFileName
 
std::vector< std::stringfHistNameVec
 
std::string fHistDivisorName
 
std::map< std::string, TH1 * > fHistMap
 

Detailed Description

Definition at line 17 of file NDPosWeights.cxx.

Constructor & Destructor Documentation

ana::MultiHistContainer::MultiHistContainer ( const std::string filename,
const std::vector< std::string > &  histNameVec,
const std::string histDivisorName = "" 
)

Definition at line 35 of file NDPosWeights.cxx.

39  fHistNameVec(histNameVec),
40  fHistDivisorName(histDivisorName)
41  {
42  }
string filename
Definition: shutoffs.py:106
std::vector< std::string > fHistNameVec
std::string fHistDivisorName

Member Function Documentation

TH1 * ana::MultiHistContainer::Hist ( const std::string key) const

Definition at line 44 of file NDPosWeights.cxx.

References abs(), om::cout, allTimeWatchdog::endl, fFileName, fHistDivisorName, fHistMap, fHistNameVec, file, caf::Proxy< caf::StandardRecord >::hdr, analysePickle::hist, if(), allTimeWatchdog::index, caf::Proxy< caf::SRHeader >::ismc, it, ana::kNDDetPosHistNumuCC, ana::kNDDetPosWeightNumuCCOff1, ana::kNDDetPosWeightNumuCCOff2, ana::kNDDetPosWeightNumuCCOff3, ana::kNDDetPosWeightNumuCCOff4, caf::Proxy< caf::StandardRecord >::mc, caf::Proxy< caf::SRTruthBranch >::nnu, caf::Proxy< caf::SRTruthBranch >::nu, sr, and string.

45  {
46  if(!fHistMap.empty()){
47  auto it = fHistMap.find(key);
48  if(it != fHistMap.end()){
49  return it->second;
50  }
51  else{
52  std::cout << "MultiHistContainer: unknown key " << key << std::endl;
53  abort();
54  }
55  }
56 
57  if(!gSystem->AccessPathName(fFileName.c_str())){
58  const std::unique_ptr<TFile> file(new TFile(fFileName.c_str(), "read"));
59  DontAddDirectory guard;
60  for(size_t index = 0; index < fHistNameVec.size(); ++index){
61  std::string histname = fHistNameVec.at(index);
62  TH1* hist = dynamic_cast<TH1*>(file->Get(histname.c_str()));
63  if(!hist)
64  throw std::runtime_error(Form("NDPosWeights.h: Couldn't load histogram '%s' from file: '%s'", histname.c_str(), fFileName.c_str()) );
65  fHistMap.insert(std::pair<std::string, TH1*>(histname, hist));
66  }//loop over hist name vec
67  }//if can accesspathname
68  else
69  throw std::runtime_error( Form("NDPosWeights.h: purported histogram file '%s' doesn't exist", fFileName.c_str()) );
70 
71  if(fHistDivisorName != ""){
72  std::map<std::string, TH1*>::iterator it = fHistMap.find(fHistDivisorName);
73  if(it == fHistMap.end())
74  throw std::runtime_error(Form("NDPosWeights.h: Couldn't find divisor histogram '%s' from file: '%s'", fHistDivisorName.c_str(), fFileName.c_str()));
75  TH1* histDivisor = it->second;
76 
77  for(it = fHistMap.begin(); it != fHistMap.end(); ++it){
78  if(it->first == fHistDivisorName) continue;
79  TH1* hist = it->second;
80  hist->Divide(histDivisor);
81  }//loop through histMap
82  }//if histDivisorName isn't blank
83 
84  // Map is filled now, search again
85  return Hist(key);
86  }
set< int >::iterator it
TH1 * Hist(const std::string &key) const
std::vector< std::string > fHistNameVec
std::string fHistDivisorName
OStream cout
Definition: OStream.cxx:6
std::map< std::string, TH1 * > fHistMap
TFile * file
Definition: cellShifts.C:17
enum BeamMode string

Member Data Documentation

std::string ana::MultiHistContainer::fFileName
protected

Definition at line 27 of file NDPosWeights.cxx.

Referenced by Hist().

std::string ana::MultiHistContainer::fHistDivisorName
protected

Definition at line 29 of file NDPosWeights.cxx.

Referenced by Hist().

std::map<std::string, TH1*> ana::MultiHistContainer::fHistMap
mutableprotected

Definition at line 31 of file NDPosWeights.cxx.

Referenced by Hist().

std::vector<std::string> ana::MultiHistContainer::fHistNameVec
protected

Definition at line 28 of file NDPosWeights.cxx.

Referenced by Hist().


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