Logo ROOT   master
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 
21 namespace RooStats{
22 namespace HistFactory {
23 
24  namespace Constraint {
25  enum Type{ Gaussian, Poisson };
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},
125  fInputFileLow{oth.fInputFileLow}, fHistoNameLow{oth.fHistoNameLow}, fHistoPathLow{oth.fHistoPathLow},
126  fInputFileHigh{oth.fInputFileHigh}, fHistoNameHigh{oth.fHistoNameHigh}, fHistoPathHigh{oth.fHistoPathHigh},
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  */
205 class HistoSys final : public HistogramUncertaintyBase {
206 public:
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  */
215  class HistoFactor final : public HistogramUncertaintyBase {
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 
310  bool fConstant;
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 
358  bool fActivate;
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  * The default is to assign a Poisson uncertainty to a bin when its statistical uncertainty
367  * is larger than 5% of the bin content.
368  */
370 
371  public:
372 
374  void Print(std::ostream& = std::cout) const;
375  void PrintXML(std::ostream&) const;
376 
377  void SetRelErrorThreshold( double Threshold ) { fRelErrorThreshold = Threshold; }
378  double GetRelErrorThreshold() const { return fRelErrorThreshold; }
379 
380  void SetConstraintType( Constraint::Type ConstrType ) { fConstraintType = ConstrType; }
382 
383  protected:
384 
387 
388  };
389 
390 
391 }
392 }
393 
394 #endif
HistogramUncertaintyBase(const HistogramUncertaintyBase &oth)
Definition: Systematics.h:123
void SetName(const std::string &Name)
Definition: Systematics.h:55
Configuration for an *un*constrained, coherent shape variation of affected samples.
Definition: Systematics.h:215
Constraint::Type GetConstraintType() const
Definition: Systematics.h:381
virtual void PrintXML(std::ostream &) const =0
const std::string & GetHistoName() const
Definition: Systematics.h:300
void SetConstraintType(Constraint::Type ConstrType)
Definition: Systematics.h:256
void Print(std::ostream &=std::cout) const
Definition: Systematics.cxx:61
const std::string & GetHistoNameLow() const
Definition: Systematics.h:174
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:8371
void SetHistoNameHigh(const std::string &HistoNameHigh)
Definition: Systematics.h:172
void Print(std::ostream &=std::cout) const override
void writeToFile(const std::string &FileName, const std::string &DirName) override
Configuration for a constrained, coherent shape variation of affected samples.
Definition: Systematics.h:205
void SetName(const std::string &Name)
Definition: Systematics.h:162
const TH1 * GetInitialShape() const
Definition: Systematics.h:283
std::string GetName() const
Definition: Systematics.h:84
void SetConstraintType(Constraint::Type ConstrType)
Definition: Systematics.h:380
const std::string & GetHistoPathHigh() const
Definition: Systematics.h:181
////////////////////////////////////////////////////////////////////////////////////////////Base clas...
Definition: Systematics.h:117
Type GetType(const std::string &Name)
Definition: Systematics.cxx:34
void SetInputFileHigh(const std::string &InputFileHigh)
Definition: Systematics.h:166
void SetConstant(bool constant)
Definition: Systematics.h:285
void PrintXML(std::ostream &) const
virtual void PrintXML(std::ostream &) const override
const std::string & GetHistoPath() const
Definition: Systematics.h:306
const std::string & GetHistoNameHigh() const
Definition: Systematics.h:175
const std::string & GetInputFileLow() const
Definition: Systematics.h:168
void SetHistoPath(const std::string &HistoPath)
Definition: Systematics.h:302
Configuration for an un- constrained overall systematic to scale sample normalisations.
Definition: Systematics.h:77
const std::string & GetHistoPath() const
Definition: Systematics.h:346
std::string GetName() const
Definition: Systematics.h:56
const std::string & GetInputFile() const
Definition: Systematics.h:340
const std::string & GetInputFileHigh() const
Definition: Systematics.h:169
void SetHistoNameLow(const std::string &HistoNameLow)
Definition: Systematics.h:171
virtual void Print(std::ostream &=std::cout) const
Definition: Systematics.cxx:95
void PrintXML(std::ostream &) const override
void Print(std::ostream &=std::cout) const
*Un*constrained bin-by-bin variation of affected histogram.
Definition: Systematics.h:267
ShapeSys(const ShapeSys &other)
Definition: Systematics.h:232
const TH1 * GetErrorHist() const
Definition: Systematics.h:249
HistogramUncertaintyBase(const std::string &Name)
Definition: Systematics.h:122
void Error(const char *location, const char *msgfmt,...)
void Print(std::ostream &=std::cout) const override
Configuration for a constrained overall systematic to scale sample normalisations.
Definition: Systematics.h:49
virtual void writeToFile(const std::string &FileName, const std::string &DirName)
void PrintXML(std::ostream &) const override
void SetName(const std::string &Name)
Definition: Systematics.h:83
void SetHistoName(const std::string &HistoName)
Definition: Systematics.h:239
HistogramUncertaintyBase & operator=(const HistogramUncertaintyBase &oth)
Definition: Systematics.h:137
void PrintXML(std::ostream &) const override
void SetConst(bool Const=true)
Definition: Systematics.h:89
Configuration to automatically assign nuisance parameters for the statistical error of the Monte Carl...
Definition: Systematics.h:369
void SetHistoName(const std::string &HistoName)
Definition: Systematics.h:342
Statistical error of Monte Carlo predictions.
Definition: Systematics.h:321
const std::string & GetInputFile() const
Definition: Systematics.h:294
void SetHistoPath(const std::string &HistoPath)
Definition: Systematics.h:345
const std::string & GetHistoName() const
Definition: Systematics.h:343
void Activate(bool IsActive=true)
Definition: Systematics.h:333
void Print(std::ostream &=std::cout) const override
void writeToFile(const std::string &FileName, const std::string &DirName) override
Namespace for the RooStats classes.
Definition: Asimov.h:19
Constraint::Type fConstraintType
Definition: Systematics.h:260
void writeToFile(const std::string &FileName, const std::string &DirName) override
const std::string & GetHistoPathLow() const
Definition: Systematics.h:180
std::string GetInputFile() const
Definition: Systematics.h:237
int type
Definition: TGX11.cxx:120
std::string GetHistoPath() const
Definition: Systematics.h:243
const TH1 * GetErrorHist() const
Definition: Systematics.h:349
The TH1 histogram class.
Definition: TH1.h:56
void PrintXML(std::ostream &) const
Definition: Systematics.cxx:70
void SetInputFileLow(const std::string &InputFileLow)
Definition: Systematics.h:165
Constraint::Type GetConstraintType() const
Definition: Systematics.h:257
void SetHistoName(const std::string &HistoName)
Definition: Systematics.h:296
void Print(std::ostream &=std::cout) const
Definition: Systematics.cxx:80
void SetHistoPathHigh(const std::string &HistoPathHigh)
Definition: Systematics.h:178
std::string Name(Type type)
Definition: Systematics.cxx:27
void SetHistoPathLow(const std::string &HistoPathLow)
Definition: Systematics.h:177
void SetUseHisto(bool UseHisto=true)
Definition: Systematics.h:336
void SetHistoPath(const std::string &HistoPath)
Definition: Systematics.h:242
void PrintXML(std::ostream &) const
Definition: Systematics.cxx:87
void PrintXML(std::ostream &) const override
void SetInputFile(const std::string &InputFile)
Definition: Systematics.h:290
void SetRelErrorThreshold(double Threshold)
Definition: Systematics.h:377
void SetErrorHist(TH1 *hError)
Definition: Systematics.h:252
std::string GetHistoName() const
Definition: Systematics.h:240
void SetInputFile(const std::string &InputFile)
Definition: Systematics.h:236
void SetInputFile(const std::string &InputFile)
Definition: Systematics.h:339
Constrained bin-by-bin variation of affected histogram.
Definition: Systematics.h:225