36 fName( ChanName ), fInputFile( ChanInputFile )
42 namespace HistFactory{
55 fSamples.push_back( sample );
61 stream <<
"\t Channel Name: " << fName
62 <<
"\t InputFile: " << fInputFile
65 stream <<
"\t Data:" << std::endl;
66 fData.Print( stream );
69 stream <<
"\t statErrorConfig:" << std::endl;
70 fStatErrorConfig.Print( stream );
73 if( !fSamples.empty() ) {
75 stream <<
"\t Samples: " << std::endl;
76 for(
unsigned int i = 0; i < fSamples.size(); ++i ) {
77 fSamples.at(i).Print( stream );
82 stream <<
"\t End of Channel " << fName << std::endl;
91 cxcoutPHF <<
"Printing XML Files for channel: " << GetName() << std::endl;
93 std::string XMLName = prefix + fName +
".xml";
94 if(!directory.empty()) XMLName = directory +
"/" + XMLName;
96 ofstream xml( XMLName.c_str() );
99 xml <<
"<!--" << std::endl;
100 xml <<
"This xml file created automatically on: " << std::endl;
106 t.
GetDate(
true, 0, &year, &month, &day);
111 xml <<
"-->" << std::endl;
114 xml <<
"<!DOCTYPE Channel SYSTEM 'HistFactorySchema.dtd'> " << std::endl << std::endl;
117 xml <<
" <Channel Name=\"" << fName <<
"\" InputFile=\"" << fInputFile <<
"\" >" << std::endl << std::endl;
119 fData.PrintXML( xml );
120 for(
auto const&
data : fAdditionalData) {
124 fStatErrorConfig.PrintXML( xml );
131 for(
auto const& sample : fSamples) {
132 sample.PrintXML( xml );
133 xml << std::endl << std::endl;
137 xml <<
" </Channel> " << std::endl;
140 cxcoutPHF <<
"Finished printing XML files" << std::endl;
149 fData.SetHistoName( DataHistoName );
150 fData.SetInputFile( DataInputFile );
151 fData.SetHistoPath( DataHistoPath );
159 fData.SetHisto( hData );
169 std::string DataHistName = fName +
"_data";
172 TH1F* hData =
new TH1F( DataHistName.c_str(), DataHistName.c_str(), 1, 0, 1 );
184 fStatErrorConfig.SetRelErrorThreshold( StatRelErrorThreshold );
185 fStatErrorConfig.SetConstraintType( StatConstraintType );
191 fStatErrorConfig.SetRelErrorThreshold( StatRelErrorThreshold );
204 std::map<std::string,std::unique_ptr<TFile>> fileHandles;
208 if( !fData.GetInputFile().empty() ) {
209 fData.SetHisto( GetHistogram(fData.GetInputFile(),
210 fData.GetHistoPath(),
211 fData.GetHistoName(),
216 for(
auto&
data : fAdditionalData) {
217 if( !
data.GetInputFile().empty() ) {
218 data.SetHisto( GetHistogram(
data.GetInputFile(),
data.GetHistoPath(),
data.GetHistoName(), fileHandles) );
223 for(
unsigned int sampItr = 0; sampItr < fSamples.size(); ++sampItr ) {
229 cxcoutDHF <<
"Collecting Nominal Histogram" << std::endl;
248 for(
unsigned int histoSysItr = 0; histoSysItr < sample.
GetHistoSysList().
size(); ++histoSysItr ) {
265 for(
unsigned int histoFactorItr = 0; histoFactorItr < sample.
GetHistoFactorList().
size(); ++histoFactorItr ) {
282 for(
unsigned int shapeSysItr = 0; shapeSysItr < sample.
GetShapeSysList().
size(); ++shapeSysItr ) {
294 for(
unsigned int shapeFactorItr = 0; shapeFactorItr < sample.
GetShapeFactorList().
size(); ++shapeFactorItr ) {
316 if( fData.GetHisto() ==
nullptr && !fData.GetInputFile().empty() ) {
317 cxcoutEHF <<
"Error: Data Histogram for channel " << GetName() <<
" is nullptr." << std::endl;
322 for(
unsigned int sampItr = 0; sampItr < fSamples.size(); ++sampItr ) {
327 if( sample.
GetHisto() ==
nullptr ) {
328 cxcoutEHF <<
"Error: Nominal Histogram for sample " << sample.
GetName() <<
" is nullptr." << std::endl;
334 std::vector<int> NegativeBinNumber;
335 std::vector<double> NegativeBinContent;
337 for(
int ibin=1; ibin<=histNominal->
GetNbinsX(); ++ibin) {
339 NegativeBinNumber.push_back(ibin);
340 NegativeBinContent.push_back(histNominal->
GetBinContent(ibin));
343 if(!NegativeBinNumber.empty()) {
345 <<
" in Channel = " << GetName() <<
" has negative entries in bin numbers = ";
347 for(
unsigned int ibin=0; ibin<NegativeBinNumber.size(); ++ibin) {
348 if(ibin>0) std::cout <<
" , " ;
349 std::cout << NegativeBinNumber[ibin] <<
" : " << NegativeBinContent[ibin] ;
351 std::cout << std::endl;
359 cxcoutEHF <<
"Error: Statistical Error Histogram for sample " << sample.
GetName() <<
" is nullptr." << std::endl;
366 for(
unsigned int histoSysItr = 0; histoSysItr < sample.
GetHistoSysList().
size(); ++histoSysItr ) {
372 <<
" in sample " << sample.
GetName() <<
" is nullptr." << std::endl;
377 <<
" in sample " << sample.
GetName() <<
" is nullptr." << std::endl;
385 for(
unsigned int histoFactorItr = 0; histoFactorItr < sample.
GetHistoFactorList().
size(); ++histoFactorItr ) {
390 cxcoutEHF <<
"Error: HistoSyst Low for Systematic " << histoFactor.
GetName()
391 <<
" in sample " << sample.
GetName() <<
" is nullptr." << std::endl;
395 cxcoutEHF <<
"Error: HistoSyst High for Systematic " << histoFactor.
GetName()
396 <<
" in sample " << sample.
GetName() <<
" is nullptr." << std::endl;
404 for(
unsigned int shapeSysItr = 0; shapeSysItr < sample.
GetShapeSysList().
size(); ++shapeSysItr ) {
410 <<
" in sample " << sample.
GetName() <<
" is nullptr." << std::endl;
430 cxcoutPHF <<
"Getting histogram " << InputFile <<
":" << HistoPath <<
"/" << HistoName << std::endl;
432 auto& inFile = lsof[InputFile];
433 if (!inFile || !inFile->IsOpen()) {
435 if ( !inFile || !inFile->IsOpen() ) {
436 cxcoutEHF <<
"Error: Unable to open input file: " << InputFile << std::endl;
439 cxcoutIHF <<
"Opened input file: " << InputFile <<
": " << std::endl;
443 if (dir ==
nullptr) {
444 cxcoutEHF <<
"Histogram path '" << HistoPath
445 <<
"' wasn't found in file '" << InputFile <<
"'." << std::endl;
451 auto key = dir->
GetKey(HistoName.c_str());
452 if (key ==
nullptr) {
454 <<
"' wasn't found in file '" << InputFile
455 <<
"' in directory '" << HistoPath <<
"'." << std::endl;
459 auto hist = key->ReadObject<
TH1>();
462 <<
"' wasn't found in file '" << InputFile
463 <<
"' in directory '" << HistoPath <<
"'." << std::endl;
468 TH1 * ptr =
static_cast<TH1 *
>(hist->Clone());
471 std::cerr <<
"Not all necessary info are set to access the input file. Check your config" << std::endl;
472 std::cerr <<
"filename: " << InputFile
473 <<
"path: " << HistoPath
474 <<
"obj: " << HistoName << std::endl;
482 std::cout <<
"Found Histogram: " << HistoName
" at address: " << ptr
483 <<
" with integral " << ptr->
Integral() <<
" and mean " << ptr->
GetMean()
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
This class encapsulates all information for the statistical interpretation of one experiment.
void Print(std::ostream &=std::cout)
void SetData(const RooStats::HistFactory::Data &data)
set data object
void AddSample(RooStats::HistFactory::Sample sample)
bool CheckHistograms() const
TH1 * GetHistogram(std::string InputFile, std::string HistoPath, std::string HistoName, std::map< std::string, std::unique_ptr< TFile > > &lsof)
Open a file and copy a histogram.
void SetStatErrorConfig(double RelErrorThreshold, Constraint::Type ConstraintType)
void PrintXML(std::string const &directory, std::string const &prefix="") const
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
Describe directory structure in memory.
virtual TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory using apath.
virtual TKey * GetKey(const char *, Short_t=9999) const
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.
1-D histogram with a float per channel (see TH1 documentation)
TH1 is the base class of all histogram classes in ROOT.
virtual void SetDirectory(TDirectory *dir)
By default, when a 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.
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.
const char * GetName() const override
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=nullptr, UInt_t *month=nullptr, UInt_t *day=nullptr) const
Return date in form of 19971224 (i.e.
Type GetType(const std::string &Name)
Namespace for the RooStats classes.