Logo ROOT   6.16/01
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
51
52RooStats::HistFactory::Sample::Sample(std::string SampName, std::string SampHistoName, std::string SampInputFile, std::string SampHistoPath) :
53 fName( SampName ), fInputFile( SampInputFile),
54 fHistoName( SampHistoName ), fHistoPath( SampHistoPath ),
55 fNormalizeByTheory(true), fStatErrorActivate(false), fhNominal(),
56 fhCountingHist(0) { ; }
57
59 fName( SampName ), fInputFile( "" ),
60 fHistoName( "" ), fHistoPath( "" ),
61 fNormalizeByTheory(true), fStatErrorActivate(false),fhNominal(),
62 fhCountingHist(0) { ; }
63
65 if(fhCountingHist)
66 delete fhCountingHist;
67}
68
70 TH1* histo = (TH1*) fhNominal.GetObject();
71 return histo;
72}
73
74
75void RooStats::HistFactory::Sample::writeToFile( std::string OutputFileName, std::string DirName ) {
76
77 TH1* histNominal = GetHisto();
78 histNominal->Write();
79
80 // Set the location of the data
81 // in the output measurement
82
83 fInputFile = OutputFileName;
84 fHistoName = histNominal->GetName();
85 fHistoPath = DirName;
86
87 // Write this sample's StatError
88 GetStatError().writeToFile( OutputFileName, DirName );
89
90 // Must write all systematics that contain internal histograms
91 // (This is not all systematics)
92 for( unsigned int i = 0; i < GetHistoSysList().size(); ++i ) {
93 GetHistoSysList().at(i).writeToFile( OutputFileName, DirName );
94 }
95 for( unsigned int i = 0; i < GetHistoFactorList().size(); ++i ) {
96 GetHistoFactorList().at(i).writeToFile( OutputFileName, DirName );
97 }
98 for( unsigned int i = 0; i < GetShapeSysList().size(); ++i ) {
99 GetShapeSysList().at(i).writeToFile( OutputFileName, DirName );
100 }
101 for( unsigned int i = 0; i < GetShapeFactorList().size(); ++i ) {
102 GetShapeFactorList().at(i).writeToFile( OutputFileName, DirName );
103 }
104
105 return;
106
107}
108
109
111
112 // For use in a number counting measurement
113 // Create a 1-bin histogram,
114 // fill it with this input value,
115 // and set this Sample's histogram to that hist
116
117 std::string SampleHistName = fName + "_hist";
118
119 // Histogram has 1-bin (hard-coded)
120 if(fhCountingHist)
121 delete fhCountingHist;
122
123 fhCountingHist = new TH1F( SampleHistName.c_str(), SampleHistName.c_str(), 1, 0, 1 );
124 fhCountingHist->SetBinContent( 1, val );
125
126 // Set the histogram of the internally held data
127 // node of this channel to this newly created histogram
128 SetHisto( fhCountingHist );
129
130}
131
132
133
134void RooStats::HistFactory::Sample::Print( std::ostream& stream ) {
135
136
137 stream << "\t \t Name: " << fName
138 << "\t \t Channel: " << fChannelName
139 << "\t NormalizeByTheory: " << (fNormalizeByTheory ? "True" : "False")
140 << "\t StatErrorActivate: " << (fStatErrorActivate ? "True" : "False")
141 << std::endl;
142
143 stream << "\t \t \t \t "
144 << "\t InputFile: " << fInputFile
145 << "\t HistName: " << fHistoName
146 << "\t HistoPath: " << fHistoPath
147 << "\t HistoAddress: " << GetHisto()
148 // << "\t Type: " << GetHisto()->ClassName()
149 << std::endl;
150
151 if( fStatError.GetActivate() ) {
152 stream << "\t \t \t StatError Activate: " << fStatError.GetActivate()
153 << "\t InputFile: " << fInputFile
154 << "\t HistName: " << fStatError.GetHistoName()
155 << "\t HistoPath: " << fStatError.GetHistoPath()
156 << "\t HistoAddress: " << fStatError.GetErrorHist()
157 << std::endl;
158 }
159
160
161 /*
162 stream<< " NormalizeByTheory: ";
163 if(NormalizeByTheory) stream << "True";
164 else stream << "False";
165
166 stream<< " StatErrorActivate: ";
167 if(StatErrorActivate) stream << "True";
168 else stream << "False";
169 */
170
171
172}
173
174void RooStats::HistFactory::Sample::PrintXML( std::ofstream& xml ) {
175
176
177 // Create the sample tag
178 xml << " <Sample Name=\"" << fName << "\" "
179 << " HistoPath=\"" << fHistoPath << "\" "
180 << " HistoName=\"" << fHistoName << "\" "
181 << " InputFile=\"" << fInputFile << "\" "
182 << " NormalizeByTheory=\"" << (fNormalizeByTheory ? std::string("True") : std::string("False")) << "\" "
183 << ">" << std::endl;
184
185
186 // Print Stat Error (if necessary)
187 fStatError.PrintXML( xml );
188 /*
189 if( fStatError.GetActivate() ) {
190 xml << " <StatError Activate=\"" << (fStatError.GetActivate() ? std::string("True") : std::string("False")) << "\" "
191 << " InputFile=\"" << fStatError.GetInputFile() << "\" "
192 << " HistoName=\"" << fStatError.GetHistoName() << "\" "
193 << " HistoPath=\"" << fStatError.GetHistoPath() << "\" "
194 << " /> " << std::endl;
195 }
196 */
197
198
199 // Now, print the systematics:
200 for( unsigned int i = 0; i < fOverallSysList.size(); ++i ) {
201 RooStats::HistFactory::OverallSys sys = fOverallSysList.at(i);
202 sys.PrintXML(xml);
203 /*
204 xml << " <OverallSys Name=\"" << sys.GetName() << "\" "
205 << " High=\"" << sys.GetHigh() << "\" "
206 << " Low=\"" << sys.GetLow() << "\" "
207 << " /> " << std::endl;
208 */
209 }
210 for( unsigned int i = 0; i < fNormFactorList.size(); ++i ) {
211 RooStats::HistFactory::NormFactor sys = fNormFactorList.at(i);
212 sys.PrintXML(xml);
213 /*
214 xml << " <NormFactor Name=\"" << sys.GetName() << "\" "
215 << " Val=\"" << sys.GetVal() << "\" "
216 << " High=\"" << sys.GetHigh() << "\" "
217 << " Low=\"" << sys.GetLow() << "\" "
218 << " Const=\"" << (sys.GetConst() ? std::string("True") : std::string("False")) << "\" "
219 << " /> " << std::endl;
220 */
221 }
222 for( unsigned int i = 0; i < fHistoSysList.size(); ++i ) {
223 RooStats::HistFactory::HistoSys sys = fHistoSysList.at(i);
224 sys.PrintXML(xml);
225 /*
226 xml << " <HistoSys Name=\"" << sys.GetName() << "\" "
227
228 << " InputFileLow=\"" << sys.GetInputFileLow() << "\" "
229 << " HistoNameLow=\"" << sys.GetHistoNameLow() << "\" "
230 << " HistoPathLow=\"" << sys.GetHistoPathLow() << "\" "
231
232 << " InputFileHigh=\"" << sys.GetInputFileHigh() << "\" "
233 << " HistoNameHigh=\"" << sys.GetHistoNameHigh() << "\" "
234 << " HistoPathHigh=\"" << sys.GetHistoPathHigh() << "\" "
235 << " /> " << std::endl;
236 */
237 }
238 for( unsigned int i = 0; i < fHistoFactorList.size(); ++i ) {
239 RooStats::HistFactory::HistoFactor sys = fHistoFactorList.at(i);
240 sys.PrintXML(xml);
241 /*
242 xml << " <HistoFactor Name=\"" << sys.GetName() << "\" "
243
244 << " InputFileLow=\"" << sys.GetInputFileLow() << "\" "
245 << " HistoNameLow=\"" << sys.GetHistoNameLow() << "\" "
246 << " HistoPathLow=\"" << sys.GetHistoPathLow() << "\" "
247
248 << " InputFileHigh=\"" << sys.GetInputFileHigh() << "\" "
249 << " HistoNameHigh=\"" << sys.GetHistoNameHigh() << "\" "
250 << " HistoPathHigh=\"" << sys.GetHistoPathHigh() << "\" "
251 << " /> " << std::endl;
252 */
253 }
254 for( unsigned int i = 0; i < fShapeSysList.size(); ++i ) {
255 RooStats::HistFactory::ShapeSys sys = fShapeSysList.at(i);
256 sys.PrintXML(xml);
257 /*
258 xml << " <ShapeSys Name=\"" << sys.GetName() << "\" "
259
260 << " InputFile=\"" << sys.GetInputFile() << "\" "
261 << " HistoName=\"" << sys.GetHistoName() << "\" "
262 << " HistoPath=\"" << sys.GetHistoPath() << "\" "
263 << " ConstraintType=\"" << std::string(Constraint::Name(sys.GetConstraintType())) << "\" "
264 << " /> " << std::endl;
265 */
266 }
267 for( unsigned int i = 0; i < fShapeFactorList.size(); ++i ) {
268 RooStats::HistFactory::ShapeFactor sys = fShapeFactorList.at(i);
269 sys.PrintXML(xml);
270 /*
271 xml << " <ShapeFactor Name=\"" << sys.GetName() << "\" "
272 << " /> " << std::endl;
273 */
274 }
275
276 // Finally, close the tag
277 xml << " </Sample>" << std::endl;
278
279}
280
281
282
283// Some helper functions
284// (Not strictly necessary because
285// methods are publicly accessable)
286
287
289
290 fStatError.Activate( true );
291 fStatError.SetUseHisto( false );
292
293}
294
295
296void RooStats::HistFactory::Sample::ActivateStatError( std::string StatHistoName, std::string StatInputFile, std::string StatHistoPath ) {
297
298
299 fStatError.Activate( true );
300 fStatError.SetUseHisto( true );
301
302 fStatError.SetInputFile( StatInputFile );
303 fStatError.SetHistoName( StatHistoName );
304 fStatError.SetHistoPath( StatHistoPath );
305
306}
307
308
309void RooStats::HistFactory::Sample::AddOverallSys( std::string SysName, Double_t SysLow, Double_t SysHigh ) {
310
312 sys.SetName( SysName );
313 sys.SetLow( SysLow );
314 sys.SetHigh( SysHigh );
315
316 fOverallSysList.push_back( sys );
317
318}
319
321 fOverallSysList.push_back(Sys);
322}
323
324void RooStats::HistFactory::Sample::AddNormFactor( std::string SysName, Double_t SysVal, Double_t SysLow, Double_t SysHigh, bool SysConst ) {
325
327
328 norm.SetName( SysName );
329 norm.SetVal( SysVal );
330 norm.SetLow( SysLow );
331 norm.SetHigh( SysHigh );
332 norm.SetConst( SysConst );
333
334 fNormFactorList.push_back( norm );
335
336}
337
339 fNormFactorList.push_back( Factor );
340}
341
342
344std::string SysHistoNameLow, std::string SysHistoFileLow, std::string SysHistoPathLow,
345 std::string SysHistoNameHigh, std::string SysHistoFileHigh, std::string SysHistoPathHigh ) {
346
348 sys.SetName( SysName );
349
350 sys.SetHistoNameLow( SysHistoNameLow );
351 sys.SetHistoPathLow( SysHistoPathLow );
352 sys.SetInputFileLow( SysHistoFileLow );
353
354 sys.SetHistoNameHigh( SysHistoNameHigh );
355 sys.SetHistoPathHigh( SysHistoPathHigh );
356 sys.SetInputFileHigh( SysHistoFileHigh );
357
358 fHistoSysList.push_back( sys );
359
360}
361
363 fHistoSysList.push_back( Sys );
364}
365
366
367void RooStats::HistFactory::Sample::AddHistoFactor( std::string SysName, std::string SysHistoNameLow, std::string SysHistoFileLow, std::string SysHistoPathLow,
368 std::string SysHistoNameHigh, std::string SysHistoFileHigh, std::string SysHistoPathHigh ) {
369
371 factor.SetName( SysName );
372
373 factor.SetHistoNameLow( SysHistoNameLow );
374 factor.SetHistoPathLow( SysHistoPathLow );
375 factor.SetInputFileLow( SysHistoFileLow );
376
377 factor.SetHistoNameHigh( SysHistoNameHigh );
378 factor.SetHistoPathHigh( SysHistoPathHigh );
379 factor.SetInputFileHigh( SysHistoFileHigh );
380
381 fHistoFactorList.push_back( factor );
382
383}
384
386 fHistoFactorList.push_back(Factor);
387}
388
389
391
393 factor.SetName( SysName );
394 fShapeFactorList.push_back( factor );
395
396}
397
398
400 fShapeFactorList.push_back(Factor);
401}
402
403
404void RooStats::HistFactory::Sample::AddShapeSys( std::string SysName, Constraint::Type SysConstraintType, std::string SysHistoName, std::string SysHistoFile, std::string SysHistoPath ) {
405
407 sys.SetName( SysName );
408 sys.SetConstraintType( SysConstraintType );
409
410 sys.SetHistoName( SysHistoName );
411 sys.SetHistoPath( SysHistoPath );
412 sys.SetInputFile( SysHistoFile );
413
414 fShapeSysList.push_back( sys );
415
416}
417
419 fShapeSysList.push_back(Sys);
420}
double Double_t
Definition: RtypesCore.h:55
Configuration for an unconstrained, coherent shape variation of affected samples.
Definition: Systematics.h:174
void SetName(const std::string &Name)
Definition: Systematics.h:180
void SetHistoPathLow(const std::string &HistoPathLow)
Definition: Systematics.h:195
void SetHistoPathHigh(const std::string &HistoPathHigh)
Definition: Systematics.h:196
void SetHistoNameHigh(const std::string &HistoNameHigh)
Definition: Systematics.h:190
void SetInputFileHigh(const std::string &InputFileHigh)
Definition: Systematics.h:184
void SetInputFileLow(const std::string &InputFileLow)
Definition: Systematics.h:183
void SetHistoNameLow(const std::string &HistoNameLow)
Definition: Systematics.h:189
Configuration for a constrained, coherent shape variation of affected samples.
Definition: Systematics.h:114
void SetHistoNameLow(const std::string &HistoNameLow)
Definition: Systematics.h:140
void PrintXML(std::ostream &)
void SetHistoPathHigh(const std::string &HistoPathHigh)
Definition: Systematics.h:147
void SetName(const std::string &Name)
Definition: Systematics.h:131
void SetInputFileLow(const std::string &InputFileLow)
Definition: Systematics.h:134
void SetHistoPathLow(const std::string &HistoPathLow)
Definition: Systematics.h:146
void SetInputFileHigh(const std::string &InputFileHigh)
Definition: Systematics.h:135
void SetHistoNameHigh(const std::string &HistoNameHigh)
Definition: Systematics.h:141
Configuration for an un- constrained overall systematic to scale sample normalisations.
Definition: Systematics.h:77
void PrintXML(std::ostream &)
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 PrintXML(std::ostream &)
Definition: Systematics.cxx:87
void SetName(const std::string &Name)
Definition: Systematics.h:55
void AddShapeSys(std::string Name, Constraint::Type ConstraintType, std::string HistoName, std::string HistoFile, std::string HistoPath="")
Definition: Sample.cxx:404
void writeToFile(std::string FileName, std::string DirName)
Definition: Sample.cxx:75
void AddNormFactor(std::string Name, Double_t Val, Double_t Low, Double_t High, bool Const=false)
Definition: Sample.cxx:324
void SetValue(Double_t Val)
Definition: Sample.cxx:110
void PrintXML(std::ofstream &xml)
Definition: Sample.cxx:174
void AddOverallSys(std::string Name, Double_t Low, Double_t High)
Definition: Sample.cxx:309
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:367
void Print(std::ostream &=std::cout)
Definition: Sample.cxx:134
void AddShapeFactor(std::string Name)
Definition: Sample.cxx:390
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:343
Unconstrained bin-by-bin variation of affected histogram.
Definition: Systematics.h:277
void SetName(const std::string &Name)
Definition: Systematics.h:283
Constrained bin-by-bin variation of affected histogram.
Definition: Systematics.h:232
void SetName(const std::string &Name)
Definition: Systematics.h:238
void PrintXML(std::ostream &)
void SetInputFile(const std::string &InputFile)
Definition: Systematics.h:241
void SetHistoName(const std::string &HistoName)
Definition: Systematics.h:244
void SetConstraintType(Constraint::Type ConstrType)
Definition: Systematics.h:257
void SetHistoPath(const std::string &HistoPath)
Definition: Systematics.h:247
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:4790
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