22 RooStats::HistFactory::Sample::Sample() :
23 fNormalizeByTheory(false), fStatErrorActivate(false), fhNominal(), fhCountingHist(0) { ; }
26 RooStats::HistFactory::Sample::Sample(
const Sample& other) :
27 fName(other.fName), fInputFile(other.fInputFile),
28 fHistoName(other.fHistoName), fHistoPath(other.fHistoPath),
29 fChannelName(other.fChannelName),
31 fOverallSysList(other.fOverallSysList),
32 fNormFactorList(other.fNormFactorList),
33 fHistoSysList(other.fHistoSysList),
34 fHistoFactorList(other.fHistoFactorList),
35 fShapeSysList(other.fShapeSysList),
36 fShapeFactorList(other.fShapeFactorList),
38 fStatError(other.fStatError),
39 fNormalizeByTheory(other.fNormalizeByTheory),
40 fStatErrorActivate(other.fStatErrorActivate),
41 fhNominal(other.fhNominal),
44 if( other.fhCountingHist ) {
45 SetValue( other.fhCountingHist->GetBinContent(1) );
47 fhCountingHist = NULL;
51 RooStats::HistFactory::Sample& RooStats::HistFactory::Sample::operator=(
const Sample& other)
53 fName = other.fName; fInputFile = other.fInputFile;
54 fHistoName = other.fHistoName; fHistoPath = other.fHistoPath;
55 fChannelName = other.fChannelName;
57 fOverallSysList = other.fOverallSysList;
58 fNormFactorList = other.fNormFactorList;
59 fHistoSysList = other.fHistoSysList;
60 fHistoFactorList = other.fHistoFactorList;
61 fShapeSysList = other.fShapeSysList;
62 fShapeFactorList = other.fShapeFactorList;
64 fStatError = other.fStatError;
65 fNormalizeByTheory = other.fNormalizeByTheory;
66 fStatErrorActivate = other.fStatErrorActivate;
67 fhNominal = other.fhNominal;
70 delete fhCountingHist;
72 if( other.fhCountingHist ) {
73 SetValue( other.fhCountingHist->GetBinContent(1) );
75 fhCountingHist = NULL;
82 RooStats::HistFactory::Sample::Sample(std::string SampName, std::string SampHistoName, std::string SampInputFile, std::string SampHistoPath) :
83 fName( SampName ), fInputFile( SampInputFile),
84 fHistoName( SampHistoName ), fHistoPath( SampHistoPath ),
85 fNormalizeByTheory(true), fStatErrorActivate(false), fhNominal(),
86 fhCountingHist(0) { ; }
88 RooStats::HistFactory::Sample::Sample(std::string SampName) :
89 fName( SampName ), fInputFile(
"" ),
90 fHistoName(
"" ), fHistoPath(
"" ),
91 fNormalizeByTheory(true), fStatErrorActivate(false),fhNominal(),
92 fhCountingHist(0) { ; }
94 RooStats::HistFactory::Sample::~Sample() {
96 delete fhCountingHist;
99 const TH1* RooStats::HistFactory::Sample::GetHisto()
const {
100 TH1* histo = (TH1*) fhNominal.GetObject();
105 void RooStats::HistFactory::Sample::writeToFile( std::string OutputFileName, std::string DirName ) {
107 const TH1* histNominal = GetHisto();
108 histNominal->Write();
113 fInputFile = OutputFileName;
114 fHistoName = histNominal->GetName();
115 fHistoPath = DirName;
118 GetStatError().writeToFile( OutputFileName, DirName );
122 for(
unsigned int i = 0; i < GetHistoSysList().size(); ++i ) {
123 GetHistoSysList().at(i).writeToFile( OutputFileName, DirName );
125 for(
unsigned int i = 0; i < GetHistoFactorList().size(); ++i ) {
126 GetHistoFactorList().at(i).writeToFile( OutputFileName, DirName );
128 for(
unsigned int i = 0; i < GetShapeSysList().size(); ++i ) {
129 GetShapeSysList().at(i).writeToFile( OutputFileName, DirName );
131 for(
unsigned int i = 0; i < GetShapeFactorList().size(); ++i ) {
132 GetShapeFactorList().at(i).writeToFile( OutputFileName, DirName );
140 void RooStats::HistFactory::Sample::SetValue( Double_t val ) {
147 std::string SampleHistName = fName +
"_hist";
151 delete fhCountingHist;
153 fhCountingHist =
new TH1F( SampleHistName.c_str(), SampleHistName.c_str(), 1, 0, 1 );
154 fhCountingHist->SetBinContent( 1, val );
158 SetHisto( fhCountingHist );
164 void RooStats::HistFactory::Sample::Print( std::ostream& stream )
const {
167 stream <<
"\t \t Name: " << fName
168 <<
"\t \t Channel: " << fChannelName
169 <<
"\t NormalizeByTheory: " << (fNormalizeByTheory ?
"True" :
"False")
170 <<
"\t StatErrorActivate: " << (fStatErrorActivate ?
"True" :
"False")
173 stream <<
"\t \t \t \t "
174 <<
"\t InputFile: " << fInputFile
175 <<
"\t HistName: " << fHistoName
176 <<
"\t HistoPath: " << fHistoPath
177 <<
"\t HistoAddress: " << GetHisto()
181 if( fStatError.GetActivate() ) {
182 stream <<
"\t \t \t StatError Activate: " << fStatError.GetActivate()
183 <<
"\t InputFile: " << fInputFile
184 <<
"\t HistName: " << fStatError.GetHistoName()
185 <<
"\t HistoPath: " << fStatError.GetHistoPath()
186 <<
"\t HistoAddress: " << fStatError.GetErrorHist()
204 void RooStats::HistFactory::Sample::PrintXML( std::ofstream& xml ) {
208 xml <<
" <Sample Name=\"" << fName <<
"\" "
209 <<
" HistoPath=\"" << fHistoPath <<
"\" "
210 <<
" HistoName=\"" << fHistoName <<
"\" "
211 <<
" InputFile=\"" << fInputFile <<
"\" "
212 <<
" NormalizeByTheory=\"" << (fNormalizeByTheory ? std::string(
"True") : std::string(
"False")) <<
"\" "
217 fStatError.PrintXML( xml );
230 for(
unsigned int i = 0; i < fOverallSysList.size(); ++i ) {
231 RooStats::HistFactory::OverallSys sys = fOverallSysList.at(i);
240 for(
unsigned int i = 0; i < fNormFactorList.size(); ++i ) {
241 RooStats::HistFactory::NormFactor sys = fNormFactorList.at(i);
252 for(
unsigned int i = 0; i < fHistoSysList.size(); ++i ) {
253 RooStats::HistFactory::HistoSys sys = fHistoSysList.at(i);
268 for(
unsigned int i = 0; i < fHistoFactorList.size(); ++i ) {
269 RooStats::HistFactory::HistoFactor sys = fHistoFactorList.at(i);
284 for(
unsigned int i = 0; i < fShapeSysList.size(); ++i ) {
285 RooStats::HistFactory::ShapeSys sys = fShapeSysList.at(i);
297 for(
unsigned int i = 0; i < fShapeFactorList.size(); ++i ) {
298 RooStats::HistFactory::ShapeFactor sys = fShapeFactorList.at(i);
307 xml <<
" </Sample>" << std::endl;
318 void RooStats::HistFactory::Sample::ActivateStatError() {
320 fStatError.Activate(
true );
321 fStatError.SetUseHisto(
false );
326 void RooStats::HistFactory::Sample::ActivateStatError( std::string StatHistoName, std::string StatInputFile, std::string StatHistoPath ) {
329 fStatError.Activate(
true );
330 fStatError.SetUseHisto(
true );
332 fStatError.SetInputFile( StatInputFile );
333 fStatError.SetHistoName( StatHistoName );
334 fStatError.SetHistoPath( StatHistoPath );
339 void RooStats::HistFactory::Sample::AddOverallSys( std::string SysName, Double_t SysLow, Double_t SysHigh ) {
341 RooStats::HistFactory::OverallSys sys;
342 sys.SetName( SysName );
343 sys.SetLow( SysLow );
344 sys.SetHigh( SysHigh );
346 fOverallSysList.push_back( sys );
350 void RooStats::HistFactory::Sample::AddOverallSys(
const OverallSys& Sys ) {
351 fOverallSysList.push_back(Sys);
354 void RooStats::HistFactory::Sample::AddNormFactor( std::string SysName, Double_t SysVal, Double_t SysLow, Double_t SysHigh,
bool SysConst ) {
356 RooStats::HistFactory::NormFactor norm;
358 norm.SetName( SysName );
359 norm.SetVal( SysVal );
360 norm.SetLow( SysLow );
361 norm.SetHigh( SysHigh );
362 norm.SetConst( SysConst );
364 fNormFactorList.push_back( norm );
368 void RooStats::HistFactory::Sample::AddNormFactor(
const NormFactor& Factor ) {
369 fNormFactorList.push_back( Factor );
373 void RooStats::HistFactory::Sample::AddHistoSys( std::string SysName,
374 std::string SysHistoNameLow, std::string SysHistoFileLow, std::string SysHistoPathLow,
375 std::string SysHistoNameHigh, std::string SysHistoFileHigh, std::string SysHistoPathHigh ) {
377 RooStats::HistFactory::HistoSys sys;
378 sys.SetName( SysName );
380 sys.SetHistoNameLow( SysHistoNameLow );
381 sys.SetHistoPathLow( SysHistoPathLow );
382 sys.SetInputFileLow( SysHistoFileLow );
384 sys.SetHistoNameHigh( SysHistoNameHigh );
385 sys.SetHistoPathHigh( SysHistoPathHigh );
386 sys.SetInputFileHigh( SysHistoFileHigh );
388 fHistoSysList.push_back( sys );
392 void RooStats::HistFactory::Sample::AddHistoSys(
const HistoSys& Sys ) {
393 fHistoSysList.push_back( Sys );
397 void RooStats::HistFactory::Sample::AddHistoFactor( std::string SysName, std::string SysHistoNameLow, std::string SysHistoFileLow, std::string SysHistoPathLow,
398 std::string SysHistoNameHigh, std::string SysHistoFileHigh, std::string SysHistoPathHigh ) {
400 RooStats::HistFactory::HistoFactor factor;
401 factor.SetName( SysName );
403 factor.SetHistoNameLow( SysHistoNameLow );
404 factor.SetHistoPathLow( SysHistoPathLow );
405 factor.SetInputFileLow( SysHistoFileLow );
407 factor.SetHistoNameHigh( SysHistoNameHigh );
408 factor.SetHistoPathHigh( SysHistoPathHigh );
409 factor.SetInputFileHigh( SysHistoFileHigh );
411 fHistoFactorList.push_back( factor );
415 void RooStats::HistFactory::Sample::AddHistoFactor(
const HistoFactor& Factor ) {
416 fHistoFactorList.push_back(Factor);
420 void RooStats::HistFactory::Sample::AddShapeFactor( std::string SysName ) {
422 RooStats::HistFactory::ShapeFactor factor;
423 factor.SetName( SysName );
424 fShapeFactorList.push_back( factor );
429 void RooStats::HistFactory::Sample::AddShapeFactor(
const ShapeFactor& Factor ) {
430 fShapeFactorList.push_back(Factor);
434 void RooStats::HistFactory::Sample::AddShapeSys( std::string SysName, Constraint::Type SysConstraintType, std::string SysHistoName, std::string SysHistoFile, std::string SysHistoPath ) {
436 RooStats::HistFactory::ShapeSys sys;
437 sys.SetName( SysName );
438 sys.SetConstraintType( SysConstraintType );
440 sys.SetHistoName( SysHistoName );
441 sys.SetHistoPath( SysHistoPath );
442 sys.SetInputFile( SysHistoFile );
444 fShapeSysList.push_back( sys );
448 void RooStats::HistFactory::Sample::AddShapeSys(
const ShapeSys& Sys ) {
449 fShapeSysList.push_back(Sys);