Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Sample.cxx
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Author: Kyle Cranmer, George Lewis
3/*************************************************************************
4 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11//////////////////////////////////////////////////////////////////////////////
12/** \class RooStats::HistFactory::Sample
13 * \ingroup HistFactory
14 */
15
16#include "TH1.h"
19
20//#include "TClass.h"
21
23 fNormalizeByTheory(false), fStatErrorActivate(false), fhNominal(), fhCountingHist(0) { ; }
24
25// copy constructor (important for python)
27 fName(other.fName), fInputFile(other.fInputFile),
28 fHistoName(other.fHistoName), fHistoPath(other.fHistoPath),
29 fChannelName(other.fChannelName),
30
31 fOverallSysList(other.fOverallSysList),
32 fNormFactorList(other.fNormFactorList),
33 fHistoSysList(other.fHistoSysList),
34 fHistoFactorList(other.fHistoFactorList),
35 fShapeSysList(other.fShapeSysList),
36 fShapeFactorList(other.fShapeFactorList),
37
38 fStatError(other.fStatError),
39 fNormalizeByTheory(other.fNormalizeByTheory),
40 fStatErrorActivate(other.fStatErrorActivate),
41 fhNominal(other.fhNominal),
42 fhCountingHist(0)
43 {
44 if( other.fhCountingHist ) {
46 }else{
47 fhCountingHist = NULL;
48 }
49 }
50
52{
53 fName = other.fName; fInputFile = other.fInputFile;
54 fHistoName = other.fHistoName; fHistoPath = other.fHistoPath;
55 fChannelName = other.fChannelName;
56
57 fOverallSysList = other.fOverallSysList;
58 fNormFactorList = other.fNormFactorList;
59 fHistoSysList = other.fHistoSysList;
60 fHistoFactorList = other.fHistoFactorList;
61 fShapeSysList = other.fShapeSysList;
62 fShapeFactorList = other.fShapeFactorList;
63
64 fStatError = other.fStatError;
65 fNormalizeByTheory = other.fNormalizeByTheory;
66 fStatErrorActivate = other.fStatErrorActivate;
67 fhNominal = other.fhNominal;
68
69 if (fhCountingHist)
70 delete fhCountingHist;
71
72 if( other.fhCountingHist ) {
73 SetValue( other.fhCountingHist->GetBinContent(1) );
74 } else {
75 fhCountingHist = NULL;
76 }
77
78 return *this;
79}
80
81
82RooStats::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) { ; }
87
89 fName( SampName ), fInputFile( "" ),
90 fHistoName( "" ), fHistoPath( "" ),
91 fNormalizeByTheory(true), fStatErrorActivate(false),fhNominal(),
92 fhCountingHist(0) { ; }
93
95 if(fhCountingHist)
96 delete fhCountingHist;
97}
98
100 TH1* histo = (TH1*) fhNominal.GetObject();
101 return histo;
102}
103
104
105void RooStats::HistFactory::Sample::writeToFile( std::string OutputFileName, std::string DirName ) {
106
107 const TH1* histNominal = GetHisto();
108 histNominal->Write();
109
110 // Set the location of the data
111 // in the output measurement
112
113 fInputFile = OutputFileName;
114 fHistoName = histNominal->GetName();
115 fHistoPath = DirName;
116
117 // Write this sample's StatError
118 GetStatError().writeToFile( OutputFileName, DirName );
119
120 // Must write all systematics that contain internal histograms
121 // (This is not all systematics)
122 for( unsigned int i = 0; i < GetHistoSysList().size(); ++i ) {
123 GetHistoSysList().at(i).writeToFile( OutputFileName, DirName );
124 }
125 for( unsigned int i = 0; i < GetHistoFactorList().size(); ++i ) {
126 GetHistoFactorList().at(i).writeToFile( OutputFileName, DirName );
127 }
128 for( unsigned int i = 0; i < GetShapeSysList().size(); ++i ) {
129 GetShapeSysList().at(i).writeToFile( OutputFileName, DirName );
130 }
131 for( unsigned int i = 0; i < GetShapeFactorList().size(); ++i ) {
132 GetShapeFactorList().at(i).writeToFile( OutputFileName, DirName );
133 }
134
135 return;
136
137}
138
139
141
142 // For use in a number counting measurement
143 // Create a 1-bin histogram,
144 // fill it with this input value,
145 // and set this Sample's histogram to that hist
146
147 std::string SampleHistName = fName + "_hist";
148
149 // Histogram has 1-bin (hard-coded)
150 if(fhCountingHist)
151 delete fhCountingHist;
152
153 fhCountingHist = new TH1F( SampleHistName.c_str(), SampleHistName.c_str(), 1, 0, 1 );
154 fhCountingHist->SetBinContent( 1, val );
155
156 // Set the histogram of the internally held data
157 // node of this channel to this newly created histogram
158 SetHisto( fhCountingHist );
159
160}
161
162
163
164void RooStats::HistFactory::Sample::Print( std::ostream& stream ) const {
165
166
167 stream << "\t \t Name: " << fName
168 << "\t \t Channel: " << fChannelName
169 << "\t NormalizeByTheory: " << (fNormalizeByTheory ? "True" : "False")
170 << "\t StatErrorActivate: " << (fStatErrorActivate ? "True" : "False")
171 << std::endl;
172
173 stream << "\t \t \t \t "
174 << "\t InputFile: " << fInputFile
175 << "\t HistName: " << fHistoName
176 << "\t HistoPath: " << fHistoPath
177 << "\t HistoAddress: " << GetHisto()
178 // << "\t Type: " << GetHisto()->ClassName()
179 << std::endl;
180
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()
187 << std::endl;
188 }
189
190
191 /*
192 stream<< " NormalizeByTheory: ";
193 if(NormalizeByTheory) stream << "True";
194 else stream << "False";
195
196 stream<< " StatErrorActivate: ";
197 if(StatErrorActivate) stream << "True";
198 else stream << "False";
199 */
200
201
202}
203
204void RooStats::HistFactory::Sample::PrintXML( std::ofstream& xml ) const {
205
206
207 // Create the sample tag
208 xml << " <Sample Name=\"" << fName << "\" "
209 << " HistoPath=\"" << fHistoPath << "\" "
210 << " HistoName=\"" << fHistoName << "\" "
211 << " InputFile=\"" << fInputFile << "\" "
212 << " NormalizeByTheory=\"" << (fNormalizeByTheory ? std::string("True") : std::string("False")) << "\" "
213 << ">" << std::endl;
214
215
216 // Print Stat Error (if necessary)
217 fStatError.PrintXML( xml );
218 /*
219 if( fStatError.GetActivate() ) {
220 xml << " <StatError Activate=\"" << (fStatError.GetActivate() ? std::string("True") : std::string("False")) << "\" "
221 << " InputFile=\"" << fStatError.GetInputFile() << "\" "
222 << " HistoName=\"" << fStatError.GetHistoName() << "\" "
223 << " HistoPath=\"" << fStatError.GetHistoPath() << "\" "
224 << " /> " << std::endl;
225 }
226 */
227
228
229 // Now, print the systematics:
230 for( unsigned int i = 0; i < fOverallSysList.size(); ++i ) {
231 RooStats::HistFactory::OverallSys sys = fOverallSysList.at(i);
232 sys.PrintXML(xml);
233 /*
234 xml << " <OverallSys Name=\"" << sys.GetName() << "\" "
235 << " High=\"" << sys.GetHigh() << "\" "
236 << " Low=\"" << sys.GetLow() << "\" "
237 << " /> " << std::endl;
238 */
239 }
240 for( unsigned int i = 0; i < fNormFactorList.size(); ++i ) {
241 RooStats::HistFactory::NormFactor sys = fNormFactorList.at(i);
242 sys.PrintXML(xml);
243 /*
244 xml << " <NormFactor Name=\"" << sys.GetName() << "\" "
245 << " Val=\"" << sys.GetVal() << "\" "
246 << " High=\"" << sys.GetHigh() << "\" "
247 << " Low=\"" << sys.GetLow() << "\" "
248 << " Const=\"" << (sys.GetConst() ? std::string("True") : std::string("False")) << "\" "
249 << " /> " << std::endl;
250 */
251 }
252 for( unsigned int i = 0; i < fHistoSysList.size(); ++i ) {
253 RooStats::HistFactory::HistoSys sys = fHistoSysList.at(i);
254 sys.PrintXML(xml);
255 /*
256 xml << " <HistoSys Name=\"" << sys.GetName() << "\" "
257
258 << " InputFileLow=\"" << sys.GetInputFileLow() << "\" "
259 << " HistoNameLow=\"" << sys.GetHistoNameLow() << "\" "
260 << " HistoPathLow=\"" << sys.GetHistoPathLow() << "\" "
261
262 << " InputFileHigh=\"" << sys.GetInputFileHigh() << "\" "
263 << " HistoNameHigh=\"" << sys.GetHistoNameHigh() << "\" "
264 << " HistoPathHigh=\"" << sys.GetHistoPathHigh() << "\" "
265 << " /> " << std::endl;
266 */
267 }
268 for( unsigned int i = 0; i < fHistoFactorList.size(); ++i ) {
269 RooStats::HistFactory::HistoFactor sys = fHistoFactorList.at(i);
270 sys.PrintXML(xml);
271 /*
272 xml << " <HistoFactor Name=\"" << sys.GetName() << "\" "
273
274 << " InputFileLow=\"" << sys.GetInputFileLow() << "\" "
275 << " HistoNameLow=\"" << sys.GetHistoNameLow() << "\" "
276 << " HistoPathLow=\"" << sys.GetHistoPathLow() << "\" "
277
278 << " InputFileHigh=\"" << sys.GetInputFileHigh() << "\" "
279 << " HistoNameHigh=\"" << sys.GetHistoNameHigh() << "\" "
280 << " HistoPathHigh=\"" << sys.GetHistoPathHigh() << "\" "
281 << " /> " << std::endl;
282 */
283 }
284 for( unsigned int i = 0; i < fShapeSysList.size(); ++i ) {
285 RooStats::HistFactory::ShapeSys sys = fShapeSysList.at(i);
286 sys.PrintXML(xml);
287 /*
288 xml << " <ShapeSys Name=\"" << sys.GetName() << "\" "
289
290 << " InputFile=\"" << sys.GetInputFile() << "\" "
291 << " HistoName=\"" << sys.GetHistoName() << "\" "
292 << " HistoPath=\"" << sys.GetHistoPath() << "\" "
293 << " ConstraintType=\"" << std::string(Constraint::Name(sys.GetConstraintType())) << "\" "
294 << " /> " << std::endl;
295 */
296 }
297 for( unsigned int i = 0; i < fShapeFactorList.size(); ++i ) {
298 RooStats::HistFactory::ShapeFactor sys = fShapeFactorList.at(i);
299 sys.PrintXML(xml);
300 /*
301 xml << " <ShapeFactor Name=\"" << sys.GetName() << "\" "
302 << " /> " << std::endl;
303 */
304 }
305
306 // Finally, close the tag
307 xml << " </Sample>" << std::endl;
308
309}
310
311
312// Some helper functions
313// (Not strictly necessary because
314// methods are publicly accessable)
315
316
318
319 fStatError.Activate( true );
320 fStatError.SetUseHisto( false );
321
322}
323
324
325void RooStats::HistFactory::Sample::ActivateStatError( std::string StatHistoName, std::string StatInputFile, std::string StatHistoPath ) {
326
327
328 fStatError.Activate( true );
329 fStatError.SetUseHisto( true );
330
331 fStatError.SetInputFile( StatInputFile );
332 fStatError.SetHistoName( StatHistoName );
333 fStatError.SetHistoPath( StatHistoPath );
334
335}
336
337
338void RooStats::HistFactory::Sample::AddOverallSys( std::string SysName, Double_t SysLow, Double_t SysHigh ) {
339
341 sys.SetName( SysName );
342 sys.SetLow( SysLow );
343 sys.SetHigh( SysHigh );
344
345 fOverallSysList.push_back( sys );
346
347}
348
350 fOverallSysList.push_back(Sys);
351}
352
353void RooStats::HistFactory::Sample::AddNormFactor( std::string SysName, Double_t SysVal, Double_t SysLow, Double_t SysHigh, bool SysConst ) {
354
356
357 norm.SetName( SysName );
358 norm.SetVal( SysVal );
359 norm.SetLow( SysLow );
360 norm.SetHigh( SysHigh );
361 norm.SetConst( SysConst );
362
363 fNormFactorList.push_back( norm );
364
365}
366
368 fNormFactorList.push_back( Factor );
369}
370
371
373std::string SysHistoNameLow, std::string SysHistoFileLow, std::string SysHistoPathLow,
374 std::string SysHistoNameHigh, std::string SysHistoFileHigh, std::string SysHistoPathHigh ) {
375
377 sys.SetName( SysName );
378
379 sys.SetHistoNameLow( SysHistoNameLow );
380 sys.SetHistoPathLow( SysHistoPathLow );
381 sys.SetInputFileLow( SysHistoFileLow );
382
383 sys.SetHistoNameHigh( SysHistoNameHigh );
384 sys.SetHistoPathHigh( SysHistoPathHigh );
385 sys.SetInputFileHigh( SysHistoFileHigh );
386
387 fHistoSysList.push_back( sys );
388
389}
390
392 fHistoSysList.push_back( Sys );
393}
394
395
396void RooStats::HistFactory::Sample::AddHistoFactor( std::string SysName, std::string SysHistoNameLow, std::string SysHistoFileLow, std::string SysHistoPathLow,
397 std::string SysHistoNameHigh, std::string SysHistoFileHigh, std::string SysHistoPathHigh ) {
398
400 factor.SetName( SysName );
401
402 factor.SetHistoNameLow( SysHistoNameLow );
403 factor.SetHistoPathLow( SysHistoPathLow );
404 factor.SetInputFileLow( SysHistoFileLow );
405
406 factor.SetHistoNameHigh( SysHistoNameHigh );
407 factor.SetHistoPathHigh( SysHistoPathHigh );
408 factor.SetInputFileHigh( SysHistoFileHigh );
409
410 fHistoFactorList.push_back( factor );
411
412}
413
415 fHistoFactorList.push_back(Factor);
416}
417
418
420
422 factor.SetName( SysName );
423 fShapeFactorList.push_back( factor );
424
425}
426
427
429 fShapeFactorList.push_back(Factor);
430}
431
432
433void RooStats::HistFactory::Sample::AddShapeSys( std::string SysName, Constraint::Type SysConstraintType, std::string SysHistoName, std::string SysHistoFile, std::string SysHistoPath ) {
434
436 sys.SetName( SysName );
437 sys.SetConstraintType( SysConstraintType );
438
439 sys.SetHistoName( SysHistoName );
440 sys.SetHistoPath( SysHistoPath );
441 sys.SetInputFile( SysHistoFile );
442
443 fShapeSysList.push_back( sys );
444
445}
446
448 fShapeSysList.push_back(Sys);
449}
double Double_t
Definition RtypesCore.h:59
Configuration for an *un*constrained, coherent shape variation of affected samples.
void PrintXML(std::ostream &) const override
Configuration for a constrained, coherent shape variation of affected samples.
virtual void PrintXML(std::ostream &) const override
void SetInputFileHigh(const std::string &InputFileHigh)
void SetHistoPathHigh(const std::string &HistoPathHigh)
void SetInputFileLow(const std::string &InputFileLow)
void SetHistoNameHigh(const std::string &HistoNameHigh)
void SetHistoNameLow(const std::string &HistoNameLow)
void SetHistoPathLow(const std::string &HistoPathLow)
Configuration for an un- constrained overall systematic to scale sample normalisations.
Definition Systematics.h:77
void PrintXML(std::ostream &) const
void SetConst(bool Const=true)
Definition Systematics.h:89
void SetName(const std::string &Name)
Definition Systematics.h:83
Configuration for a constrained overall systematic to scale sample normalisations.
Definition Systematics.h:49
void SetName(const std::string &Name)
Definition Systematics.h:55
void PrintXML(std::ostream &) const
std::vector< RooStats::HistFactory::OverallSys > fOverallSysList
Definition Sample.h:145
void AddShapeSys(std::string Name, Constraint::Type ConstraintType, std::string HistoName, std::string HistoFile, std::string HistoPath="")
Definition Sample.cxx:433
void writeToFile(std::string FileName, std::string DirName)
Definition Sample.cxx:105
const TH1 * GetHisto() const
Definition Sample.cxx:99
std::vector< RooStats::HistFactory::HistoFactor > fHistoFactorList
Definition Sample.h:149
RooStats::HistFactory::StatError fStatError
Properties.
Definition Sample.h:156
std::vector< RooStats::HistFactory::NormFactor > fNormFactorList
Definition Sample.h:146
std::vector< RooStats::HistFactory::HistoSys > fHistoSysList
Definition Sample.h:148
std::string fChannelName
The Name of the parent channel.
Definition Sample.h:139
void Print(std::ostream &=std::cout) const
Definition Sample.cxx:164
void AddNormFactor(std::string Name, Double_t Val, Double_t Low, Double_t High, bool Const=false)
Definition Sample.cxx:353
Sample & operator=(const Sample &other)
Definition Sample.cxx:51
std::vector< RooStats::HistFactory::ShapeSys > fShapeSysList
Definition Sample.h:151
void SetValue(Double_t Val)
Definition Sample.cxx:140
void AddOverallSys(std::string Name, Double_t Low, Double_t High)
Definition Sample.cxx:338
void AddHistoFactor(std::string Name, std::string HistoNameLow, std::string HistoFileLow, std::string HistoPathLow, std::string HistoNameHigh, std::string HistoFileHigh, std::string HistoPathHigh)
Definition Sample.cxx:396
HistRef fhNominal
The Nominal Shape.
Definition Sample.h:163
void AddShapeFactor(std::string Name)
Definition Sample.cxx:419
std::vector< RooStats::HistFactory::ShapeFactor > fShapeFactorList
Definition Sample.h:152
void AddHistoSys(std::string Name, std::string HistoNameLow, std::string HistoFileLow, std::string HistoPathLow, std::string HistoNameHigh, std::string HistoFileHigh, std::string HistoPathHigh)
Definition Sample.cxx:372
void PrintXML(std::ofstream &xml) const
Definition Sample.cxx:204
*Un*constrained bin-by-bin variation of affected histogram.
void PrintXML(std::ostream &) const override
Constrained bin-by-bin variation of affected histogram.
void PrintXML(std::ostream &) const override
void SetInputFile(const std::string &InputFile)
void SetHistoName(const std::string &HistoName)
void SetConstraintType(Constraint::Type ConstrType)
void SetHistoPath(const std::string &HistoPath)
1-D histogram with a float per channel (see TH1 documentation)}
Definition TH1.h:575
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:4994
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition TObject.cxx:868
TH1 * GetHisto(TFile *inFile, const std::string name)
Definition Helper.cxx:115