Logo ROOT   6.18/05
Reference Guide
Systematics.h
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Author: George Lewis, Kyle Cranmer
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#ifndef HISTFACTORY_SYSTEMATICS_H
12#define HISTFACTORY_SYSTEMATICS_H
13
14#include <string>
15#include <fstream>
16#include <iostream>
17
18#include "TH1.h"
20
21namespace RooStats{
22namespace HistFactory {
23
24 namespace Constraint {
26 std::string Name( Type type );
27 Type GetType( const std::string& Name );
28 }
29
30
31 // Base class for common functions
32 /*
33 class Systematic {
34
35 public:
36
37 virtual void Print(std::ostream& = std::cout);
38 virtual void writeToFile(const std::string& FileName,
39 const std::string& Directory);
40
41
42 };
43 */
44
45/** \class OverallSys
46 * \ingroup HistFactory
47 * Configuration for a constrained overall systematic to scale sample normalisations.
48 */
49 class OverallSys {
50
51 public:
52
53 OverallSys() : fLow(0), fHigh(0) {}
54
55 void SetName( const std::string& Name ) { fName = Name; }
56 std::string GetName() const { return fName; }
57
58 void SetLow( double Low ) { fLow = Low; }
59 void SetHigh( double High ) { fHigh = High; }
60 double GetLow() const { return fLow; }
61 double GetHigh() const { return fHigh; }
62
63 void Print(std::ostream& = std::cout) const;
64 void PrintXML(std::ostream&) const;
65
66 protected:
67 std::string fName;
68 double fLow;
69 double fHigh;
70
71 };
72
73/** \class NormFactor
74 * \ingroup HistFactory
75 * Configuration for an \a un- constrained overall systematic to scale sample normalisations.
76 */
77 class NormFactor {
78
79 public:
80
81 NormFactor();
82
83 void SetName( const std::string& Name ) { fName = Name; }
84 std::string GetName() const { return fName; }
85
86 void SetVal( double Val ) { fVal = Val; }
87 double GetVal() const { return fVal; }
88
89 void SetConst( bool Const=true ) { fConst = Const; }
90 bool GetConst() const { return fConst; }
91
92 void SetLow( double Low ) { fLow = Low; }
93 void SetHigh( double High ) { fHigh = High; }
94 double GetLow() const { return fLow; }
95 double GetHigh() const { return fHigh; }
96
97 void Print(std::ostream& = std::cout) const;
98 void PrintXML(std::ostream&) const;
99
100 protected:
101
102 std::string fName;
103 double fVal;
104 double fLow;
105 double fHigh;
106 bool fConst;
107
108 };
109
110
111 /** ////////////////////////////////////////////////////////////////////////////////////////////
112 * \class HistogramUncertaintyBase
113 * \ingroup HistFactory
114 * Base class to store the up and down variations for histogram uncertainties.
115 * Use the derived classes for actual models.
116 */
118
119 public:
120
121 HistogramUncertaintyBase() : fhLow(nullptr), fhHigh(nullptr) {}
122 HistogramUncertaintyBase(const std::string& Name) : fName(Name), fhLow(nullptr), fhHigh(nullptr) {}
124 fName{oth.fName},
127 fhLow{oth.fhLow ? static_cast<TH1*>(oth.fhLow->Clone()) : nullptr},
128 fhHigh{oth.fhHigh ? static_cast<TH1*>(oth.fhHigh->Clone()) : nullptr} {
129
130 }
132
134
135
136 // Need deep copies because the class owns its histograms.
138 fName = oth.fName;
145 fhLow.reset(oth.fhLow ? static_cast<TH1*>(oth.fhLow->Clone()) : nullptr);
146 fhHigh.reset(oth.fhHigh ? static_cast<TH1*>(oth.fhHigh->Clone()) : nullptr);
147
148 return *this;
149 }
151
152 virtual void Print(std::ostream& = std::cout) const;
153 virtual void PrintXML(std::ostream&) const = 0;
154 virtual void writeToFile( const std::string& FileName, const std::string& DirName );
155
156 void SetHistoLow(TH1* Low ) {Low->SetDirectory(nullptr); fhLow.reset(Low);}
157 void SetHistoHigh(TH1* High ) {High->SetDirectory(nullptr); fhHigh.reset(High);}
158
159 const TH1* GetHistoLow() const {return fhLow.get();}
160 const TH1* GetHistoHigh() const {return fhHigh.get();}
161
162 void SetName( const std::string& Name ) { fName = Name; }
163 const std::string& GetName() const { return fName; }
164
165 void SetInputFileLow( const std::string& InputFileLow ) { fInputFileLow = InputFileLow; }
166 void SetInputFileHigh( const std::string& InputFileHigh ) { fInputFileHigh = InputFileHigh; }
167
168 const std::string& GetInputFileLow() const { return fInputFileLow; }
169 const std::string& GetInputFileHigh() const { return fInputFileHigh; }
170
171 void SetHistoNameLow( const std::string& HistoNameLow ) { fHistoNameLow = HistoNameLow; }
172 void SetHistoNameHigh( const std::string& HistoNameHigh ) { fHistoNameHigh = HistoNameHigh; }
173
174 const std::string& GetHistoNameLow() const { return fHistoNameLow; }
175 const std::string& GetHistoNameHigh() const { return fHistoNameHigh; }
176
177 void SetHistoPathLow( const std::string& HistoPathLow ) { fHistoPathLow = HistoPathLow; }
178 void SetHistoPathHigh( const std::string& HistoPathHigh ) { fHistoPathHigh = HistoPathHigh; }
179
180 const std::string& GetHistoPathLow() const { return fHistoPathLow; }
181 const std::string& GetHistoPathHigh() const { return fHistoPathHigh; }
182
183 protected:
184
185 std::string fName;
186
187 std::string fInputFileLow;
188 std::string fHistoNameLow;
189 std::string fHistoPathLow;
190
191 std::string fInputFileHigh;
192 std::string fHistoNameHigh;
193 std::string fHistoPathHigh;
194
195 // The Low and High Histograms
196 std::unique_ptr<TH1> fhLow;
197 std::unique_ptr<TH1> fhHigh;
198
199 };
200
201/** \class HistoSys
202 * \ingroup HistFactory
203 * Configuration for a constrained, coherent shape variation of affected samples.
204 */
205class HistoSys final : public HistogramUncertaintyBase {
206public:
207 virtual ~HistoSys() {}
208 virtual void PrintXML(std::ostream&) const override;
209};
210
211/** \class HistoFactor
212 * \ingroup HistFactory
213 * Configuration for an *un*constrained, coherent shape variation of affected samples.
214 */
216 public:
217 virtual ~HistoFactor() {}
218 void PrintXML(std::ostream&) const override;
219 };
220
221/** \class ShapeSys
222 * \ingroup HistFactory
223 * Constrained bin-by-bin variation of affected histogram.
224 */
225 class ShapeSys final : public HistogramUncertaintyBase {
226
227 public:
228
231 fConstraintType(Constraint::Gaussian) {}
232 ShapeSys(const ShapeSys& other) :
235
236 void SetInputFile( const std::string& InputFile ) { fInputFileHigh = InputFile; }
237 std::string GetInputFile() const { return fInputFileHigh; }
238
239 void SetHistoName( const std::string& HistoName ) { fHistoNameHigh = HistoName; }
240 std::string GetHistoName() const { return fHistoNameHigh; }
241
242 void SetHistoPath( const std::string& HistoPath ) { fHistoPathHigh = HistoPath; }
243 std::string GetHistoPath() const { return fHistoPathHigh; }
244
245 void Print(std::ostream& = std::cout) const override;
246 void PrintXML(std::ostream&) const override;
247 void writeToFile( const std::string& FileName, const std::string& DirName ) override;
248
249 const TH1* GetErrorHist() const {
250 return fhHigh.get();
251 }
252 void SetErrorHist(TH1* hError) {
253 fhHigh.reset(hError);
254 }
255
256 void SetConstraintType( Constraint::Type ConstrType ) { fConstraintType = ConstrType; }
258
259 protected:
261 };
262
263/** \class ShapeFactor
264 * \ingroup HistFactory
265 * *Un*constrained bin-by-bin variation of affected histogram.
266 */
268
269 public:
270
273 fConstant{false},
274 fHasInitialShape{false} {}
275
276 void Print(std::ostream& = std::cout) const override;
277 void PrintXML(std::ostream&) const override;
278 void writeToFile( const std::string& FileName, const std::string& DirName) override;
279
280 void SetInitialShape(TH1* shape) {
281 fhHigh.reset(shape);
282 }
283 const TH1* GetInitialShape() const { return fhHigh.get(); }
284
285 void SetConstant(bool constant) { fConstant = constant; }
286 bool IsConstant() const { return fConstant; }
287
288 bool HasInitialShape() const { return fHasInitialShape; }
289
290 void SetInputFile( const std::string& InputFile ) {
291 fInputFileHigh = InputFile;
292 fHasInitialShape=true;
293 }
294 const std::string& GetInputFile() const { return fInputFileHigh; }
295
296 void SetHistoName( const std::string& HistoName ) {
297 fHistoNameHigh = HistoName;
298 fHasInitialShape=true;
299 }
300 const std::string& GetHistoName() const { return fHistoNameHigh; }
301
302 void SetHistoPath( const std::string& HistoPath ) {
303 fHistoPathHigh = HistoPath;
304 fHasInitialShape=true;
305 }
306 const std::string& GetHistoPath() const { return fHistoPathHigh; }
307
308 protected:
309
311
312 // A histogram representing
313 // the initial shape
315 };
316
317/** \class StatError
318 * \ingroup HistFactory
319 * Statistical error of Monte Carlo predictions.
320 */
322
323 public:
324
327 fActivate(false), fUseHisto(false) {}
328
329 void Print(std::ostream& = std::cout) const override;
330 void PrintXML(std::ostream&) const override;
331 void writeToFile( const std::string& FileName, const std::string& DirName ) override;
332
333 void Activate( bool IsActive=true ) { fActivate = IsActive; }
334 bool GetActivate() const { return fActivate; }
335
336 void SetUseHisto( bool UseHisto=true ) { fUseHisto = UseHisto; }
337 bool GetUseHisto() const { return fUseHisto; }
338
339 void SetInputFile( const std::string& InputFile ) { fInputFileHigh = InputFile; }
340 const std::string& GetInputFile() const { return fInputFileHigh; }
341
342 void SetHistoName( const std::string& HistoName ) { fHistoNameHigh = HistoName; }
343 const std::string& GetHistoName() const { return fHistoNameHigh; }
344
345 void SetHistoPath( const std::string& HistoPath ) { fHistoPathHigh = HistoPath; }
346 const std::string& GetHistoPath() const { return fHistoPathHigh; }
347
348
349 const TH1* GetErrorHist() const {
350 return fhHigh.get();
351 }
353 fhHigh.reset(Error);
354 }
355
356 protected:
357
359 bool fUseHisto; // Use an external histogram for the errors
360 };
361
362/** \class StatErrorConfig
363 * \ingroup HistFactory
364 * Configuration to automatically assign nuisance parameters for the statistical
365 * error of the Monte Carlo simulations.
366 */
368
369 public:
370
372 void Print(std::ostream& = std::cout) const;
373 void PrintXML(std::ostream&) const;
374
375 void SetRelErrorThreshold( double Threshold ) { fRelErrorThreshold = Threshold; }
376 double GetRelErrorThreshold() const { return fRelErrorThreshold; }
377
378 void SetConstraintType( Constraint::Type ConstrType ) { fConstraintType = ConstrType; }
380
381 protected:
382
385
386 };
387
388
389}
390}
391
392#endif
void Error(const char *location, const char *msgfmt,...)
int type
Definition: TGX11.cxx:120
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
////////////////////////////////////////////////////////////////////////////////////////////Base clas...
Definition: Systematics.h:117
void SetInputFileHigh(const std::string &InputFileHigh)
Definition: Systematics.h:166
HistogramUncertaintyBase(const HistogramUncertaintyBase &oth)
Definition: Systematics.h:123
void SetName(const std::string &Name)
Definition: Systematics.h:162
virtual void writeToFile(const std::string &FileName, const std::string &DirName)
virtual void PrintXML(std::ostream &) const =0
void SetHistoPathHigh(const std::string &HistoPathHigh)
Definition: Systematics.h:178
HistogramUncertaintyBase & operator=(HistogramUncertaintyBase &&)=default
void SetInputFileLow(const std::string &InputFileLow)
Definition: Systematics.h:165
const std::string & GetHistoNameHigh() const
Definition: Systematics.h:175
const std::string & GetHistoNameLow() const
Definition: Systematics.h:174
void SetHistoNameHigh(const std::string &HistoNameHigh)
Definition: Systematics.h:172
void SetHistoNameLow(const std::string &HistoNameLow)
Definition: Systematics.h:171
virtual void Print(std::ostream &=std::cout) const
Definition: Systematics.cxx:95
HistogramUncertaintyBase & operator=(const HistogramUncertaintyBase &oth)
Definition: Systematics.h:137
const std::string & GetHistoPathLow() const
Definition: Systematics.h:180
const std::string & GetInputFileHigh() const
Definition: Systematics.h:169
const std::string & GetInputFileLow() const
Definition: Systematics.h:168
HistogramUncertaintyBase(const std::string &Name)
Definition: Systematics.h:122
void SetHistoPathLow(const std::string &HistoPathLow)
Definition: Systematics.h:177
const std::string & GetHistoPathHigh() const
Definition: Systematics.h:181
HistogramUncertaintyBase(HistogramUncertaintyBase &&)=default
Configuration for an un- constrained overall systematic to scale sample normalisations.
Definition: Systematics.h:77
std::string GetName() const
Definition: Systematics.h:84
void Print(std::ostream &=std::cout) const
Definition: Systematics.cxx:61
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
std::string GetName() const
Definition: Systematics.h:56
void SetName(const std::string &Name)
Definition: Systematics.h:55
void PrintXML(std::ostream &) const
Definition: Systematics.cxx:87
void Print(std::ostream &=std::cout) const
Definition: Systematics.cxx:80
*Un*constrained bin-by-bin variation of affected histogram.
Definition: Systematics.h:267
void PrintXML(std::ostream &) const override
const std::string & GetHistoPath() const
Definition: Systematics.h:306
const TH1 * GetInitialShape() const
Definition: Systematics.h:283
void SetInputFile(const std::string &InputFile)
Definition: Systematics.h:290
void SetHistoName(const std::string &HistoName)
Definition: Systematics.h:296
void writeToFile(const std::string &FileName, const std::string &DirName) override
void Print(std::ostream &=std::cout) const override
const std::string & GetInputFile() const
Definition: Systematics.h:294
void SetConstant(bool constant)
Definition: Systematics.h:285
void SetHistoPath(const std::string &HistoPath)
Definition: Systematics.h:302
const std::string & GetHistoName() const
Definition: Systematics.h:300
Constrained bin-by-bin variation of affected histogram.
Definition: Systematics.h:225
std::string GetHistoPath() const
Definition: Systematics.h:243
void PrintXML(std::ostream &) const override
Constraint::Type GetConstraintType() const
Definition: Systematics.h:257
const TH1 * GetErrorHist() const
Definition: Systematics.h:249
Constraint::Type fConstraintType
Definition: Systematics.h:260
std::string GetHistoName() const
Definition: Systematics.h:240
ShapeSys(const ShapeSys &other)
Definition: Systematics.h:232
void SetInputFile(const std::string &InputFile)
Definition: Systematics.h:236
void writeToFile(const std::string &FileName, const std::string &DirName) override
void Print(std::ostream &=std::cout) const override
void SetHistoName(const std::string &HistoName)
Definition: Systematics.h:239
void SetConstraintType(Constraint::Type ConstrType)
Definition: Systematics.h:256
std::string GetInputFile() const
Definition: Systematics.h:237
void SetErrorHist(TH1 *hError)
Definition: Systematics.h:252
void SetHistoPath(const std::string &HistoPath)
Definition: Systematics.h:242
Configuration to automatically assign nuisance parameters for the statistical error of the Monte Carl...
Definition: Systematics.h:367
void PrintXML(std::ostream &) const
void SetConstraintType(Constraint::Type ConstrType)
Definition: Systematics.h:378
void SetRelErrorThreshold(double Threshold)
Definition: Systematics.h:375
Constraint::Type GetConstraintType() const
Definition: Systematics.h:379
void Print(std::ostream &=std::cout) const
Statistical error of Monte Carlo predictions.
Definition: Systematics.h:321
const std::string & GetHistoPath() const
Definition: Systematics.h:346
void Activate(bool IsActive=true)
Definition: Systematics.h:333
void SetHistoPath(const std::string &HistoPath)
Definition: Systematics.h:345
void SetInputFile(const std::string &InputFile)
Definition: Systematics.h:339
const TH1 * GetErrorHist() const
Definition: Systematics.h:349
const std::string & GetInputFile() const
Definition: Systematics.h:340
void SetHistoName(const std::string &HistoName)
Definition: Systematics.h:342
const std::string & GetHistoName() const
Definition: Systematics.h:343
void SetUseHisto(bool UseHisto=true)
Definition: Systematics.h:336
void Print(std::ostream &=std::cout) const override
void PrintXML(std::ostream &) const override
void writeToFile(const std::string &FileName, const std::string &DirName) override
The TH1 histogram class.
Definition: TH1.h:56
virtual void SetDirectory(TDirectory *dir)
By default when an histogram is created, it is added to the list of histogram objects in the current ...
Definition: TH1.cxx:8351
Type GetType(const std::string &Name)
Definition: Systematics.cxx:34
std::string Name(Type type)
Definition: Systematics.cxx:27
Namespace for the RooStats classes.
Definition: Asimov.h:20