Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 const 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) :
236 if (this == &oth) return *this;
239 return *this;
240 }
242
243 void SetInputFile( const std::string& InputFile ) { fInputFileHigh = InputFile; }
244 std::string GetInputFile() const { return fInputFileHigh; }
245
246 void SetHistoName( const std::string& HistoName ) { fHistoNameHigh = HistoName; }
247 std::string GetHistoName() const { return fHistoNameHigh; }
248
249 void SetHistoPath( const std::string& HistoPath ) { fHistoPathHigh = HistoPath; }
250 std::string GetHistoPath() const { return fHistoPathHigh; }
251
252 void Print(std::ostream& = std::cout) const override;
253 void PrintXML(std::ostream&) const override;
254 void writeToFile( const std::string& FileName, const std::string& DirName ) override;
255
256 const TH1* GetErrorHist() const {
257 return fhHigh.get();
258 }
259 void SetErrorHist(TH1* hError) {
260 fhHigh.reset(hError);
261 }
262
263 void SetConstraintType( Constraint::Type ConstrType ) { fConstraintType = ConstrType; }
265
266 protected:
268 };
269
270/** \class ShapeFactor
271 * \ingroup HistFactory
272 * *Un*constrained bin-by-bin variation of affected histogram.
273 */
275
276 public:
277
280 fConstant{false},
281 fHasInitialShape{false} {}
282
283 void Print(std::ostream& = std::cout) const override;
284 void PrintXML(std::ostream&) const override;
285 void writeToFile( const std::string& FileName, const std::string& DirName) override;
286
287 void SetInitialShape(TH1* shape) {
288 fhHigh.reset(shape);
289 }
290 const TH1* GetInitialShape() const { return fhHigh.get(); }
291
292 void SetConstant(bool constant) { fConstant = constant; }
293 bool IsConstant() const { return fConstant; }
294
295 bool HasInitialShape() const { return fHasInitialShape; }
296
297 void SetInputFile( const std::string& InputFile ) {
298 fInputFileHigh = InputFile;
299 fHasInitialShape=true;
300 }
301 const std::string& GetInputFile() const { return fInputFileHigh; }
302
303 void SetHistoName( const std::string& HistoName ) {
304 fHistoNameHigh = HistoName;
305 fHasInitialShape=true;
306 }
307 const std::string& GetHistoName() const { return fHistoNameHigh; }
308
309 void SetHistoPath( const std::string& HistoPath ) {
310 fHistoPathHigh = HistoPath;
311 fHasInitialShape=true;
312 }
313 const std::string& GetHistoPath() const { return fHistoPathHigh; }
314
315 protected:
316
318
319 // A histogram representing
320 // the initial shape
322 };
323
324/** \class StatError
325 * \ingroup HistFactory
326 * Statistical error of Monte Carlo predictions.
327 */
329
330 public:
331
334 fActivate(false), fUseHisto(false) {}
335
336 void Print(std::ostream& = std::cout) const override;
337 void PrintXML(std::ostream&) const override;
338 void writeToFile( const std::string& FileName, const std::string& DirName ) override;
339
340 void Activate( bool IsActive=true ) { fActivate = IsActive; }
341 bool GetActivate() const { return fActivate; }
342
343 void SetUseHisto( bool UseHisto=true ) { fUseHisto = UseHisto; }
344 bool GetUseHisto() const { return fUseHisto; }
345
346 void SetInputFile( const std::string& InputFile ) { fInputFileHigh = InputFile; }
347 const std::string& GetInputFile() const { return fInputFileHigh; }
348
349 void SetHistoName( const std::string& HistoName ) { fHistoNameHigh = HistoName; }
350 const std::string& GetHistoName() const { return fHistoNameHigh; }
351
352 void SetHistoPath( const std::string& HistoPath ) { fHistoPathHigh = HistoPath; }
353 const std::string& GetHistoPath() const { return fHistoPathHigh; }
354
355
356 const TH1* GetErrorHist() const {
357 return fhHigh.get();
358 }
360 fhHigh.reset(Error);
361 }
362
363 protected:
364
366 bool fUseHisto; // Use an external histogram for the errors
367 };
368
369/** \class StatErrorConfig
370 * \ingroup HistFactory
371 * Configuration to automatically assign nuisance parameters for the statistical
372 * error of the Monte Carlo simulations.
373 * The default is to assign a Poisson uncertainty to a bin when its statistical uncertainty
374 * is larger than 5% of the bin content.
375 */
377
378 public:
379
380 StatErrorConfig() : fRelErrorThreshold( .05 ), fConstraintType( Constraint::Poisson ) {;}
381 void Print(std::ostream& = std::cout) const;
382 void PrintXML(std::ostream&) const;
383
384 void SetRelErrorThreshold( double Threshold ) { fRelErrorThreshold = Threshold; }
385 double GetRelErrorThreshold() const { return fRelErrorThreshold; }
386
387 void SetConstraintType( Constraint::Type ConstrType ) { fConstraintType = ConstrType; }
389
390 protected:
391
394
395 };
396
397
398}
399}
400
401#endif
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:187
int type
Definition TGX11.cxx:121
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.
virtual void PrintXML(std::ostream &) const override
////////////////////////////////////////////////////////////////////////////////////////////Base clas...
void SetInputFileHigh(const std::string &InputFileHigh)
HistogramUncertaintyBase(const HistogramUncertaintyBase &oth)
virtual void writeToFile(const std::string &FileName, const std::string &DirName)
virtual void PrintXML(std::ostream &) const =0
void SetHistoPathHigh(const std::string &HistoPathHigh)
HistogramUncertaintyBase & operator=(HistogramUncertaintyBase &&)=default
void SetInputFileLow(const std::string &InputFileLow)
const std::string & GetHistoNameHigh() const
const std::string & GetHistoNameLow() const
void SetHistoNameHigh(const std::string &HistoNameHigh)
void SetHistoNameLow(const std::string &HistoNameLow)
virtual void Print(std::ostream &=std::cout) const
HistogramUncertaintyBase & operator=(const HistogramUncertaintyBase &oth)
const std::string & GetHistoPathLow() const
const std::string & GetInputFileHigh() const
const std::string & GetInputFileLow() const
HistogramUncertaintyBase(const std::string &Name)
void SetHistoPathLow(const std::string &HistoPathLow)
const std::string & GetHistoPathHigh() const
HistogramUncertaintyBase(HistogramUncertaintyBase &&)=default
Configuration for an un- constrained overall systematic to scale sample normalisations.
Definition Systematics.h:77
void Print(std::ostream &=std::cout) const
void PrintXML(std::ostream &) const
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
const std::string & GetName() const
Definition Systematics.h:56
void PrintXML(std::ostream &) const
void Print(std::ostream &=std::cout) const
*Un*constrained bin-by-bin variation of affected histogram.
void PrintXML(std::ostream &) const override
const std::string & GetHistoPath() const
const TH1 * GetInitialShape() const
void SetInputFile(const std::string &InputFile)
void SetHistoName(const std::string &HistoName)
void writeToFile(const std::string &FileName, const std::string &DirName) override
void Print(std::ostream &=std::cout) const override
const std::string & GetInputFile() const
void SetHistoPath(const std::string &HistoPath)
const std::string & GetHistoName() const
Constrained bin-by-bin variation of affected histogram.
std::string GetHistoPath() const
void PrintXML(std::ostream &) const override
Constraint::Type GetConstraintType() const
const TH1 * GetErrorHist() const
std::string GetHistoName() const
ShapeSys & operator=(ShapeSys &&)=default
ShapeSys(const ShapeSys &other)
void SetInputFile(const std::string &InputFile)
void writeToFile(const std::string &FileName, const std::string &DirName) override
void Print(std::ostream &=std::cout) const override
ShapeSys & operator=(const ShapeSys &oth)
void SetHistoName(const std::string &HistoName)
void SetConstraintType(Constraint::Type ConstrType)
std::string GetInputFile() const
void SetHistoPath(const std::string &HistoPath)
Configuration to automatically assign nuisance parameters for the statistical error of the Monte Carl...
void PrintXML(std::ostream &) const
void SetConstraintType(Constraint::Type ConstrType)
void SetRelErrorThreshold(double Threshold)
Constraint::Type GetConstraintType() const
void Print(std::ostream &=std::cout) const
Statistical error of Monte Carlo predictions.
const std::string & GetHistoPath() const
void Activate(bool IsActive=true)
void SetHistoPath(const std::string &HistoPath)
void SetInputFile(const std::string &InputFile)
const TH1 * GetErrorHist() const
const std::string & GetInputFile() const
void SetHistoName(const std::string &HistoName)
const std::string & GetHistoName() const
void SetUseHisto(bool UseHisto=true)
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
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
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:8777
Type GetType(const std::string &Name)
std::string Name(Type type)
Namespace for the RooStats classes.
Definition Asimov.h:19