62 namespace HistFactory{
81 stream <<
"\t Channel Name: " <<
fName 85 stream <<
"\t Data:" << std::endl;
89 stream <<
"\t statErrorConfig:" << std::endl;
95 stream <<
"\t Samples: " << std::endl;
96 for(
unsigned int i = 0; i <
fSamples.size(); ++i ) {
102 stream <<
"\t End of Channel " <<
fName << std::endl;
111 std::cout <<
"Printing XML Files for channel: " <<
GetName() << std::endl;
113 std::string XMLName = prefix +
fName +
".xml";
114 if( directory !=
"" ) XMLName = directory +
"/" + XMLName;
116 ofstream xml( XMLName.c_str() );
119 xml <<
"<!--" << std::endl;
120 xml <<
"This xml file created automatically on: " << std::endl;
126 t.
GetDate(
true, 0, &year, &month, &day);
131 xml <<
"-->" << std::endl;
134 xml <<
"<!DOCTYPE Channel SYSTEM 'HistFactorySchema.dtd'> " << std::endl << std::endl;
137 xml <<
" <Channel Name=\"" << fName <<
"\" InputFile=\"" <<
fInputFile <<
"\" >" << std::endl << std::endl;
154 for(
unsigned int i = 0; i <
fSamples.size(); ++i ) {
156 xml << std::endl << std::endl;
160 xml <<
" </Channel> " << std::endl;
163 std::cout <<
"Finished printing XML files" << std::endl;
193 std::string DataHistName =
fName +
"_data";
196 TH1F* hData =
new TH1F( DataHistName.c_str(), DataHistName.c_str(), 1, 0, 1 );
244 for(
unsigned int sampItr = 0; sampItr <
fSamples.size(); ++sampItr ) {
250 std::cout <<
"Collecting Nominal Histogram" << std::endl;
267 for(
unsigned int histoSysItr = 0; histoSysItr < sample.
GetHistoSysList().size(); ++histoSysItr ) {
282 for(
unsigned int histoFactorItr = 0; histoFactorItr < sample.
GetHistoFactorList().size(); ++histoFactorItr ) {
297 for(
unsigned int shapeSysItr = 0; shapeSysItr < sample.
GetShapeSysList().size(); ++shapeSysItr ) {
308 for(
unsigned int shapeFactorItr = 0; shapeFactorItr < sample.
GetShapeFactorList().size(); ++shapeFactorItr ) {
336 std::cout <<
"Error: Data Histogram for channel " <<
GetName() <<
" is NULL." << std::endl;
341 for(
unsigned int sampItr = 0; sampItr <
fSamples.size(); ++sampItr ) {
347 std::cout <<
"Error: Nominal Histogram for sample " << sample.
GetName() <<
" is NULL." << std::endl;
353 std::vector<int> NegativeBinNumber;
354 std::vector<double> NegativeBinContent;
356 for(
int ibin=1; ibin<=histNominal->
GetNbinsX(); ++ibin) {
358 NegativeBinNumber.push_back(ibin);
359 NegativeBinContent.push_back(histNominal->
GetBinContent(ibin));
362 if(NegativeBinNumber.size()>0) {
363 std::cout <<
"WARNING: Nominal Histogram " << histNominal->
GetName() <<
" for Sample = " << sample.
GetName()
364 <<
" in Channel = " <<
GetName() <<
" has negative entries in bin numbers = ";
366 for(
unsigned int ibin=0; ibin<NegativeBinNumber.size(); ++ibin) {
367 if(ibin>0) std::cout <<
" , " ;
368 std::cout << NegativeBinNumber[ibin] <<
" : " << NegativeBinContent[ibin] ;
370 std::cout << std::endl;
378 std::cout <<
"Error: Statistical Error Histogram for sample " << sample.
GetName() <<
" is NULL." << std::endl;
385 for(
unsigned int histoSysItr = 0; histoSysItr < sample.
GetHistoSysList().size(); ++histoSysItr ) {
390 std::cout <<
"Error: HistoSyst Low for Systematic " << histoSys.
GetName()
391 <<
" in sample " << sample.
GetName() <<
" is NULL." << std::endl;
395 std::cout <<
"Error: HistoSyst High for Systematic " << histoSys.
GetName()
396 <<
" in sample " << sample.
GetName() <<
" is NULL." << std::endl;
404 for(
unsigned int histoFactorItr = 0; histoFactorItr < sample.
GetHistoFactorList().size(); ++histoFactorItr ) {
409 std::cout <<
"Error: HistoSyst Low for Systematic " << histoFactor.
GetName()
410 <<
" in sample " << sample.
GetName() <<
" is NULL." << std::endl;
414 std::cout <<
"Error: HistoSyst High for Systematic " << histoFactor.
GetName()
415 <<
" in sample " << sample.
GetName() <<
" is NULL." << std::endl;
423 for(
unsigned int shapeSysItr = 0; shapeSysItr < sample.
GetShapeSysList().size(); ++shapeSysItr ) {
428 std::cout <<
"Error: HistoSyst High for Systematic " << shapeSys.
GetName()
429 <<
" in sample " << sample.
GetName() <<
" is NULL." << std::endl;
438 catch(std::exception&
e)
440 std::cout << e.what() << std::endl;
456 std::cout <<
"Getting histogram. " 457 <<
" InputFile " << InputFile
458 <<
" HistoPath " << HistoPath
459 <<
" HistoName " << HistoName
466 std::cout <<
"Error: Unable to open input file: " << InputFile << std::endl;
470 std::cout <<
"Opened input file: " << InputFile <<
": " << inFile << std::endl;
472 std::string HistNameFull = HistoPath + HistoName;
474 if( HistoPath != std::string(
"") ) {
475 if( HistoPath[ HistoPath.length()-1 ] != std::string(
"/") ) {
476 std::cout <<
"WARNING: Histogram path is set to: " << HistoPath
477 <<
" but it should end with a '/' " << std::endl;
478 std::cout <<
"Total histogram path is now: " << HistNameFull << std::endl;
484 hist =
dynamic_cast<TH1*
>( inFile->Get( HistNameFull.c_str() ) );
486 catch(std::exception&
e)
488 std::cout <<
"Failed to cast object to TH1*" << std::endl;
489 std::cout << e.what() << std::endl;
493 std::cout <<
"Failed to get histogram: " << HistNameFull
494 <<
" in file: " << InputFile << std::endl;
502 std::cerr <<
"Not all necessary info are set to access the input file. Check your config" << std::endl;
503 std::cerr <<
"filename: " << InputFile
504 <<
"path: " << HistoPath
505 <<
"obj: " << HistoName << std::endl;
514 std::cout <<
"Found Histogram: " << HistoName
" at address: " << ptr
515 <<
" with integral " << ptr->
Integral() <<
" and mean " << ptr->
GetMean()
virtual const char * GetName() const
Returns name of object.
RooStats::HistFactory::StatError & GetStatError()
void SetInitialShape(TH1 *shape)
void SetData(const RooStats::HistFactory::Data &data)
void SetStatErrorConfig(double RelErrorThreshold, Constraint::Type ConstraintType)
std::string GetHistoName()
std::string GetHistoNameHigh()
virtual void SetDirectory(TDirectory *dir)
By default when an histogram is created, it is added to the list of histogram objects in the current ...
void SetHistoName(const std::string &HistoName)
std::string GetInputFileHigh()
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
std::string GetHistoPath()
virtual Double_t Integral(Option_t *option="") const
Return integral of bin contents.
std::string GetHistoName()
std::string GetInputFile()
std::string GetInputFileLow()
virtual Double_t GetMean(Int_t axis=1) const
For axis = 1,2 or 3 returns the mean value of the histogram along X,Y or Z axis.
tomato 1-D histogram with a float per channel (see TH1 documentation)}
void Print(std::ostream &=std::cout)
std::string GetHistoNameHigh()
void SetConstraintType(Constraint::Type ConstrType)
Type GetType(const std::string &Name)
void PrintXML(std::ostream &)
void SetInputFile(const std::string &InputFile)
std::vector< RooStats::HistFactory::HistoSys > & GetHistoSysList()
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
std::string GetHistoNameLow()
std::string GetHistoPath()
std::string GetHistoPathHigh()
std::string GetHistoName()
void SetHistoHigh(TH1 *High)
void SetChannelName(const std::string &ChannelName)
std::string GetInputFile()
std::string GetInputFileHigh()
void SetHistoLow(TH1 *Low)
std::string GetInputFile()
std::string GetInputFile()
void PrintXML(std::string Directory, std::string Prefix="")
void SetErrorHist(TH1 *Error)
void Print(std::ostream &=std::cout)
std::string GetHistoPath()
std::vector< RooStats::HistFactory::Data > fAdditionalData
HistFactory::StatErrorConfig fStatErrorConfig
void SetHistoPath(const std::string &HistoPath)
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
std::vector< RooStats::HistFactory::ShapeSys > & GetShapeSysList()
std::string GetHistoPath()
std::vector< RooStats::HistFactory::HistoFactor > & GetHistoFactorList()
void SetHistoHigh(TH1 *High)
std::string GetHistoName()
void AddSample(RooStats::HistFactory::Sample sample)
Namespace for the RooStats classes.
std::string GetHistoPath()
The TTimeStamp encapsulates seconds and ns since EPOCH.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
TH1 * GetHistogram(std::string InputFile, std::string HistoPath, std::string HistoName)
std::string GetHistoPathHigh()
std::string GetHistoPathLow()
void PrintXML(std::ostream &)
std::string GetHistoPathLow()
UInt_t GetDate(Bool_t inUTC=kTRUE, Int_t secOffset=0, UInt_t *year=0, UInt_t *month=0, UInt_t *day=0) const
Return date in form of 19971224 (i.e.
void Print(std::ostream &=std::cout)
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
std::string GetHistoName()
void SetHisto(TH1 *histo)
std::string GetInputFileLow()
std::vector< RooStats::HistFactory::Sample > fSamples
void SetHistoLow(TH1 *Low)
virtual Int_t GetNbinsX() const
std::string GetHistoNameLow()
void SetRelErrorThreshold(double Threshold)
void SetErrorHist(TH1 *hError)
std::vector< RooStats::HistFactory::ShapeFactor > & GetShapeFactorList()
std::string GetInputFile()