41 fInputFile( other.fInputFile ),
42 fHistoPath( other.fHistoPath ),
44 fAdditionalData( other.fAdditionalData ),
45 fStatErrorConfig( other.fStatErrorConfig ),
46 fSamples( other.fSamples )
51 fName( ChanName ), fInputFile( ChanInputFile )
57 namespace HistFactory{
70 fSamples.push_back( sample );
76 stream <<
"\t Channel Name: " << fName
77 <<
"\t InputFile: " << fInputFile
80 stream <<
"\t Data:" << std::endl;
81 fData.Print( stream );
84 stream <<
"\t statErrorConfig:" << std::endl;
85 fStatErrorConfig.Print( stream );
88 if( fSamples.size() != 0 ) {
90 stream <<
"\t Samples: " << std::endl;
91 for(
unsigned int i = 0; i < fSamples.size(); ++i ) {
92 fSamples.at(i).Print( stream );
97 stream <<
"\t End of Channel " << fName << std::endl;
106 std::cout <<
"Printing XML Files for channel: " <<
GetName() << std::endl;
108 std::string XMLName = prefix + fName +
".xml";
109 if( directory !=
"" ) XMLName = directory +
"/" + XMLName;
111 ofstream xml( XMLName.c_str() );
114 xml <<
"<!--" << std::endl;
115 xml <<
"This xml file created automatically on: " << std::endl;
121 t.
GetDate(
true, 0, &year, &month, &day);
126 xml <<
"-->" << std::endl;
129 xml <<
"<!DOCTYPE Channel SYSTEM 'HistFactorySchema.dtd'> " << std::endl << std::endl;
132 xml <<
" <Channel Name=\"" << fName <<
"\" InputFile=\"" << fInputFile <<
"\" >" << std::endl << std::endl;
134 fData.PrintXML( xml );
142 fStatErrorConfig.PrintXML( xml );
149 for(
unsigned int i = 0; i < fSamples.size(); ++i ) {
150 fSamples.at(i).PrintXML( xml );
151 xml << std::endl << std::endl;
155 xml <<
" </Channel> " << std::endl;
158 std::cout <<
"Finished printing XML files" << std::endl;
168 fData.SetHistoName( DataHistoName );
169 fData.SetInputFile( DataInputFile );
170 fData.SetHistoPath( DataHistoPath );
178 fData.SetHisto( hData );
188 std::string DataHistName = fName +
"_data";
191 TH1F* hData =
new TH1F( DataHistName.c_str(), DataHistName.c_str(), 1, 0, 1 );
203 fStatErrorConfig.SetRelErrorThreshold( StatRelErrorThreshold );
204 fStatErrorConfig.SetConstraintType( StatConstraintType );
210 fStatErrorConfig.SetRelErrorThreshold( StatRelErrorThreshold );
224 if( fData.GetInputFile() !=
"" ) {
225 fData.SetHisto( GetHistogram(fData.GetInputFile(),
226 fData.GetHistoPath(),
227 fData.GetHistoName()) );
231 for(
unsigned int i=0; i < fAdditionalData.size(); ++i) {
239 for(
unsigned int sampItr = 0; sampItr < fSamples.size(); ++sampItr ) {
245 std::cout <<
"Collecting Nominal Histogram" << std::endl;
262 for(
unsigned int histoSysItr = 0; histoSysItr < sample.
GetHistoSysList().size(); ++histoSysItr ) {
277 for(
unsigned int histoFactorItr = 0; histoFactorItr < sample.
GetHistoFactorList().size(); ++histoFactorItr ) {
292 for(
unsigned int shapeSysItr = 0; shapeSysItr < sample.
GetShapeSysList().size(); ++shapeSysItr ) {
303 for(
unsigned int shapeFactorItr = 0; shapeFactorItr < sample.
GetShapeFactorList().size(); ++shapeFactorItr ) {
330 if( fData.GetHisto() == NULL && fData.GetInputFile() !=
"" ) {
331 std::cout <<
"Error: Data Histogram for channel " <<
GetName() <<
" is NULL." << std::endl;
336 for(
unsigned int sampItr = 0; sampItr < fSamples.size(); ++sampItr ) {
342 std::cout <<
"Error: Nominal Histogram for sample " << sample.
GetName() <<
" is NULL." << std::endl;
348 std::vector<int> NegativeBinNumber;
349 std::vector<double> NegativeBinContent;
351 for(
int ibin=1; ibin<=histNominal->
GetNbinsX(); ++ibin) {
353 NegativeBinNumber.push_back(ibin);
354 NegativeBinContent.push_back(histNominal->
GetBinContent(ibin));
357 if(NegativeBinNumber.size()>0) {
358 std::cout <<
"WARNING: Nominal Histogram " << histNominal->
GetName() <<
" for Sample = " << sample.
GetName()
359 <<
" in Channel = " <<
GetName() <<
" has negative entries in bin numbers = ";
361 for(
unsigned int ibin=0; ibin<NegativeBinNumber.size(); ++ibin) {
362 if(ibin>0) std::cout <<
" , " ;
363 std::cout << NegativeBinNumber[ibin] <<
" : " << NegativeBinContent[ibin] ;
365 std::cout << std::endl;
373 std::cout <<
"Error: Statistical Error Histogram for sample " << sample.
GetName() <<
" is NULL." << std::endl;
380 for(
unsigned int histoSysItr = 0; histoSysItr < sample.
GetHistoSysList().size(); ++histoSysItr ) {
385 std::cout <<
"Error: HistoSyst Low for Systematic " << histoSys.
GetName()
386 <<
" in sample " << sample.
GetName() <<
" is NULL." << std::endl;
390 std::cout <<
"Error: HistoSyst High for Systematic " << histoSys.
GetName()
391 <<
" in sample " << sample.
GetName() <<
" is NULL." << std::endl;
399 for(
unsigned int histoFactorItr = 0; histoFactorItr < sample.
GetHistoFactorList().size(); ++histoFactorItr ) {
404 std::cout <<
"Error: HistoSyst Low for Systematic " << histoFactor.
GetName()
405 <<
" in sample " << sample.
GetName() <<
" is NULL." << std::endl;
409 std::cout <<
"Error: HistoSyst High for Systematic " << histoFactor.
GetName()
410 <<
" in sample " << sample.
GetName() <<
" is NULL." << std::endl;
418 for(
unsigned int shapeSysItr = 0; shapeSysItr < sample.
GetShapeSysList().size(); ++shapeSysItr ) {
423 std::cout <<
"Error: HistoSyst High for Systematic " << shapeSys.
GetName()
424 <<
" in sample " << sample.
GetName() <<
" is NULL." << std::endl;
433 catch(std::exception&
e)
435 std::cout <<
e.what() << std::endl;
451 std::cout <<
"Getting histogram. "
452 <<
" InputFile " << InputFile
453 <<
" HistoPath " << HistoPath
454 <<
" HistoName " << HistoName
461 std::cout <<
"Error: Unable to open input file: " << InputFile << std::endl;
465 std::cout <<
"Opened input file: " << InputFile <<
": " << inFile << std::endl;
467 std::string HistNameFull = HistoPath + HistoName;
469 if( HistoPath != std::string(
"") ) {
470 if( HistoPath[ HistoPath.length()-1 ] != std::string(
"/") ) {
471 std::cout <<
"WARNING: Histogram path is set to: " << HistoPath
472 <<
" but it should end with a '/' " << std::endl;
473 std::cout <<
"Total histogram path is now: " << HistNameFull << std::endl;
479 hist =
dynamic_cast<TH1*
>( inFile->
Get( HistNameFull.c_str() ) );
481 catch(std::exception&
e)
483 std::cout <<
"Failed to cast object to TH1*" << std::endl;
484 std::cout <<
e.what() << std::endl;
488 std::cout <<
"Failed to get histogram: " << HistNameFull
489 <<
" in file: " << InputFile << std::endl;
497 std::cerr <<
"Not all necessary info are set to access the input file. Check your config" << std::endl;
498 std::cerr <<
"filename: " << InputFile
499 <<
"path: " << HistoPath
500 <<
"obj: " << HistoName << std::endl;
509 std::cout <<
"Found Histogram: " << HistoName
" at address: " << ptr
510 <<
" with integral " << ptr->
Integral() <<
" and mean " << ptr->
GetMean()
This class encapsulates all information for the statistical interpretation of one experiment.
void Print(std::ostream &=std::cout)
TH1 * GetHistogram(std::string InputFile, std::string HistoPath, std::string HistoName)
Open a file and copy a histogram.
void PrintXML(std::string Directory, std::string Prefix="")
void SetData(const RooStats::HistFactory::Data &data)
set data object
void AddSample(RooStats::HistFactory::Sample sample)
void SetStatErrorConfig(double RelErrorThreshold, Constraint::Type ConstraintType)
std::string GetInputFile()
std::string GetHistoName()
std::string GetHistoPath()
Configuration for an *un*constrained, coherent shape variation of affected samples.
Configuration for a constrained, coherent shape variation of affected samples.
void SetHistoHigh(TH1 *High)
const std::string & GetName() const
const TH1 * GetHistoHigh() const
const std::string & GetHistoNameHigh() const
const std::string & GetHistoNameLow() const
const std::string & GetHistoPathLow() const
const std::string & GetInputFileHigh() const
const std::string & GetInputFileLow() const
void SetHistoLow(TH1 *Low)
const std::string & GetHistoPathHigh() const
const TH1 * GetHistoLow() const
std::string GetHistoName() const
get histogram name
std::string GetName() const
get name of sample
const TH1 * GetHisto() const
void SetChannelName(const std::string &ChannelName)
set name of associated channel
void SetHisto(TH1 *histo)
std::string GetHistoPath() const
get histogram path
RooStats::HistFactory::StatError & GetStatError()
std::vector< RooStats::HistFactory::ShapeFactor > & GetShapeFactorList()
std::vector< RooStats::HistFactory::HistoFactor > & GetHistoFactorList()
std::string GetInputFile() const
get input ROOT file
std::vector< RooStats::HistFactory::HistoSys > & GetHistoSysList()
std::vector< RooStats::HistFactory::ShapeSys > & GetShapeSysList()
*Un*constrained bin-by-bin variation of affected histogram.
const std::string & GetHistoPath() const
void SetInitialShape(TH1 *shape)
const std::string & GetInputFile() const
bool HasInitialShape() const
const std::string & GetHistoName() const
Constrained bin-by-bin variation of affected histogram.
std::string GetHistoPath() const
const TH1 * GetErrorHist() const
std::string GetHistoName() const
std::string GetInputFile() const
void SetErrorHist(TH1 *hError)
const std::string & GetHistoPath() const
const TH1 * GetErrorHist() const
void SetErrorHist(TH1 *Error)
const std::string & GetInputFile() const
const std::string & GetHistoName() const
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
void Close(Option_t *option="") override
Close a file.
1-D histogram with a float per channel (see TH1 documentation)}
virtual void SetDirectory(TDirectory *dir)
By default when an histogram is created, it is added to the list of histogram objects in the current ...
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.
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
virtual Int_t GetNbinsX() const
virtual Double_t Integral(Option_t *option="") const
Return integral of bin contents.
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...
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
virtual const char * GetName() const
Returns name of object.
The TTimeStamp encapsulates seconds and ns since EPOCH.
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 GetName(const std::string &scope_name)
Type GetType(const std::string &Name)
Namespace for the RooStats classes.