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