Logo ROOT  
Reference Guide
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 ) {
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
313// Some helper functions
314// (Not strictly necessary because
315// methods are publicly accessable)
316
317
319
320 fStatError.Activate( true );
321 fStatError.SetUseHisto( false );
322
323}
324
325
326void RooStats::HistFactory::Sample::ActivateStatError( std::string StatHistoName, std::string StatInputFile, std::string StatHistoPath ) {
327
328
329 fStatError.Activate( true );
330 fStatError.SetUseHisto( true );
331
332 fStatError.SetInputFile( StatInputFile );
333 fStatError.SetHistoName( StatHistoName );
334 fStatError.SetHistoPath( StatHistoPath );
335
336}
337
338
339void RooStats::HistFactory::Sample::AddOverallSys( std::string SysName, Double_t SysLow, Double_t SysHigh ) {
340
342 sys.SetName( SysName );
343 sys.SetLow( SysLow );
344 sys.SetHigh( SysHigh );
345
346 fOverallSysList.push_back( sys );
347
348}
349
351 fOverallSysList.push_back(Sys);
352}
353
354void RooStats::HistFactory::Sample::AddNormFactor( std::string SysName, Double_t SysVal, Double_t SysLow, Double_t SysHigh, bool SysConst ) {
355
357
358 norm.SetName( SysName );
359 norm.SetVal( SysVal );
360 norm.SetLow( SysLow );
361 norm.SetHigh( SysHigh );
362 norm.SetConst( SysConst );
363
364 fNormFactorList.push_back( norm );
365
366}
367
369 fNormFactorList.push_back( Factor );
370}
371
372
374std::string SysHistoNameLow, std::string SysHistoFileLow, std::string SysHistoPathLow,
375 std::string SysHistoNameHigh, std::string SysHistoFileHigh, std::string SysHistoPathHigh ) {
376
378 sys.SetName( SysName );
379
380 sys.SetHistoNameLow( SysHistoNameLow );
381 sys.SetHistoPathLow( SysHistoPathLow );
382 sys.SetInputFileLow( SysHistoFileLow );
383
384 sys.SetHistoNameHigh( SysHistoNameHigh );
385 sys.SetHistoPathHigh( SysHistoPathHigh );
386 sys.SetInputFileHigh( SysHistoFileHigh );
387
388 fHistoSysList.push_back( sys );
389
390}
391
393 fHistoSysList.push_back( Sys );
394}
395
396
397void 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 ) {
399
401 factor.SetName( SysName );
402
403 factor.SetHistoNameLow( SysHistoNameLow );
404 factor.SetHistoPathLow( SysHistoPathLow );
405 factor.SetInputFileLow( SysHistoFileLow );
406
407 factor.SetHistoNameHigh( SysHistoNameHigh );
408 factor.SetHistoPathHigh( SysHistoPathHigh );
409 factor.SetInputFileHigh( SysHistoFileHigh );
410
411 fHistoFactorList.push_back( factor );
412
413}
414
416 fHistoFactorList.push_back(Factor);
417}
418
419
421
423 factor.SetName( SysName );
424 fShapeFactorList.push_back( factor );
425
426}
427
428
430 fShapeFactorList.push_back(Factor);
431}
432
433
434void RooStats::HistFactory::Sample::AddShapeSys( std::string SysName, Constraint::Type SysConstraintType, std::string SysHistoName, std::string SysHistoFile, std::string SysHistoPath ) {
435
437 sys.SetName( SysName );
438 sys.SetConstraintType( SysConstraintType );
439
440 sys.SetHistoName( SysHistoName );
441 sys.SetHistoPath( SysHistoPath );
442 sys.SetInputFile( SysHistoFile );
443
444 fShapeSysList.push_back( sys );
445
446}
447
449 fShapeSysList.push_back(Sys);
450}
double Double_t
Definition: RtypesCore.h:55
Configuration for an *un*constrained, coherent shape variation of affected samples.
Definition: Systematics.h:215
void PrintXML(std::ostream &) const override
Configuration for a constrained, coherent shape variation of affected samples.
Definition: Systematics.h:205
virtual void PrintXML(std::ostream &) const override
void SetInputFileHigh(const std::string &InputFileHigh)
Definition: Systematics.h:166
void SetName(const std::string &Name)
Definition: Systematics.h:162
void SetHistoPathHigh(const std::string &HistoPathHigh)
Definition: Systematics.h:178
void SetInputFileLow(const std::string &InputFileLow)
Definition: Systematics.h:165
void SetHistoNameHigh(const std::string &HistoNameHigh)
Definition: Systematics.h:172
void SetHistoNameLow(const std::string &HistoNameLow)
Definition: Systematics.h:171
void SetHistoPathLow(const std::string &HistoPathLow)
Definition: Systematics.h:177
Configuration for an un- constrained overall systematic to scale sample normalisations.
Definition: Systematics.h:77
void PrintXML(std::ostream &) const
Definition: Systematics.cxx:70
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
Definition: Systematics.cxx:87
std::vector< RooStats::HistFactory::OverallSys > fOverallSysList
Definition: Sample.h:138
void AddShapeSys(std::string Name, Constraint::Type ConstraintType, std::string HistoName, std::string HistoFile, std::string HistoPath="")
Definition: Sample.cxx:434
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:142
RooStats::HistFactory::StatError fStatError
Properties.
Definition: Sample.h:149
std::vector< RooStats::HistFactory::NormFactor > fNormFactorList
Definition: Sample.h:139
std::vector< RooStats::HistFactory::HistoSys > fHistoSysList
Definition: Sample.h:141
std::string fChannelName
The Name of the parent channel.
Definition: Sample.h:132
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:354
Sample & operator=(const Sample &other)
Definition: Sample.cxx:51
std::vector< RooStats::HistFactory::ShapeSys > fShapeSysList
Definition: Sample.h:144
void SetValue(Double_t Val)
Definition: Sample.cxx:140
void PrintXML(std::ofstream &xml)
Definition: Sample.cxx:204
void AddOverallSys(std::string Name, Double_t Low, Double_t High)
Definition: Sample.cxx:339
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:397
HistRef fhNominal
The Nominal Shape.
Definition: Sample.h:156
void AddShapeFactor(std::string Name)
Definition: Sample.cxx:420
std::vector< RooStats::HistFactory::ShapeFactor > fShapeFactorList
Definition: Sample.h:145
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:373
*Un*constrained bin-by-bin variation of affected histogram.
Definition: Systematics.h:267
void PrintXML(std::ostream &) const override
Constrained bin-by-bin variation of affected histogram.
Definition: Systematics.h:225
void PrintXML(std::ostream &) const override
void SetInputFile(const std::string &InputFile)
Definition: Systematics.h:236
void SetHistoName(const std::string &HistoName)
Definition: Systematics.h:239
void SetConstraintType(Constraint::Type ConstrType)
Definition: Systematics.h:256
void SetHistoPath(const std::string &HistoPath)
Definition: Systematics.h:242
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:571
The TH1 histogram class.
Definition: TH1.h:56
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:4899
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:785
TH1 * GetHisto(TFile *inFile, const std::string name)
Definition: Helper.cxx:115