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