46 fInputFile( other.fInputFile ),
47 fHistoPath( other.fHistoPath ),
49 fAdditionalData( other.fAdditionalData ),
50 fStatErrorConfig( other.fStatErrorConfig ),
51 fSamples( other.fSamples )
56 fName( ChanName ), fInputFile( ChanInputFile )
62 namespace HistFactory{
75 fSamples.push_back( sample );
81 stream <<
"\t Channel Name: " << fName
82 <<
"\t InputFile: " << fInputFile
85 stream <<
"\t Data:" << std::endl;
86 fData.Print( stream );
89 stream <<
"\t statErrorConfig:" << std::endl;
90 fStatErrorConfig.Print( stream );
93 if( fSamples.size() != 0 ) {
95 stream <<
"\t Samples: " << std::endl;
96 for(
unsigned int i = 0; i < fSamples.size(); ++i ) {
97 fSamples.at(i).Print( stream );
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;
139 fData.PrintXML( xml );
147 fStatErrorConfig.PrintXML( xml );
154 for(
unsigned int i = 0; i < fSamples.size(); ++i ) {
155 fSamples.at(i).PrintXML( xml );
156 xml << std::endl << std::endl;
160 xml <<
" </Channel> " << std::endl;
163 std::cout <<
"Finished printing XML files" << std::endl;
173 fData.SetHistoName( DataHistoName );
174 fData.SetInputFile( DataInputFile );
175 fData.SetHistoPath( DataHistoPath );
183 fData.SetHisto( hData );
193 std::string DataHistName = fName +
"_data";
196 TH1F* hData =
new TH1F( DataHistName.c_str(), DataHistName.c_str(), 1, 0, 1 );
197 hData->SetBinContent( 1, val );
208 fStatErrorConfig.SetRelErrorThreshold( StatRelErrorThreshold );
209 fStatErrorConfig.SetConstraintType( StatConstraintType );
215 fStatErrorConfig.SetRelErrorThreshold( StatRelErrorThreshold );
229 if( fData.GetInputFile() !=
"" ) {
230 fData.SetHisto( GetHistogram(fData.GetInputFile(),
231 fData.GetHistoPath(),
232 fData.GetHistoName()) );
236 for(
unsigned int i=0; i < fAdditionalData.size(); ++i) {
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 ) {
335 if( fData.GetHisto() ==
NULL && fData.GetInputFile() !=
"" ) {
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()
RooStats::HistFactory::StatError & GetStatError()
void SetInitialShape(TH1 *shape)
void SetData(const RooStats::HistFactory::Data &data)
void SetStatErrorConfig(double RelErrorThreshold, Constraint::Type ConstraintType)
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
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 ...
std::string GetInputFileHigh()
std::string GetHistoPath()
std::string GetHistoName()
std::string GetInputFile()
std::string GetInputFileLow()
void Print(std::ostream &=std::cout)
std::string GetHistoNameHigh()
Type GetType(const std::string &Name)
virtual Int_t GetNbinsX() const
std::vector< RooStats::HistFactory::HistoSys > & GetHistoSysList()
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
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)
std::string GetHistoPath()
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.
virtual Double_t Integral(Option_t *option="") const
Return integral of bin contents.
std::vector< RooStats::HistFactory::ShapeSys > & GetShapeSysList()
std::string GetHistoPath()
virtual const char * GetName() const
Returns name of object.
std::vector< RooStats::HistFactory::HistoFactor > & GetHistoFactorList()
void SetHistoHigh(TH1 *High)
std::string GetHistoName()
void AddSample(RooStats::HistFactory::Sample sample)
std::string GetHistoPath()
The TTimeStamp encapsulates seconds and ns since EPOCH.
TH1 * GetHistogram(std::string InputFile, std::string HistoPath, std::string HistoName)
std::string GetHistoPathHigh()
std::string GetHistoPathLow()
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.
std::string GetHistoName()
void SetHisto(TH1 *histo)
std::string GetInputFileLow()
void SetHistoLow(TH1 *Low)
std::string GetHistoNameLow()
void SetErrorHist(TH1 *hError)
std::vector< RooStats::HistFactory::ShapeFactor > & GetShapeFactorList()
std::string GetInputFile()