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/** \class OverallSys
31 * \ingroup HistFactory
32 * Configuration for a constrained overall systematic to scale sample normalisations.
33 */
34 class OverallSys {
35
36 public:
37
38 OverallSys() : fLow(0), fHigh(0) {}
39
40 void SetName( const std::string& Name ) { fName = Name; }
41 const std::string& GetName() const { return fName; }
42
43 void SetLow( double Low ) { fLow = Low; }
44 void SetHigh( double High ) { fHigh = High; }
45 double GetLow() const { return fLow; }
46 double GetHigh() const { return fHigh; }
47
48 void Print(std::ostream& = std::cout) const;
49 void PrintXML(std::ostream&) const;
50
51 protected:
52 std::string fName;
53 double fLow;
54 double fHigh;
55
56 };
57
58/** \class NormFactor
59 * \ingroup HistFactory
60 * Configuration for an \a un- constrained overall systematic to scale sample normalisations.
61 */
62 class NormFactor {
63
64 public:
65
66 NormFactor();
67
68 void SetName( const std::string& Name ) { fName = Name; }
69 std::string GetName() const { return fName; }
70
71 void SetVal( double Val ) { fVal = Val; }
72 double GetVal() const { return fVal; }
73
74 void SetLow( double Low ) { fLow = Low; }
75 void SetHigh( double High ) { fHigh = High; }
76 double GetLow() const { return fLow; }
77 double GetHigh() const { return fHigh; }
78
79 void Print(std::ostream& = std::cout) const;
80 void PrintXML(std::ostream&) const;
81
82 protected:
83
84 std::string fName;
85 double fVal;
86 double fLow;
87 double fHigh;
88
89 };
90
91
92 /** ////////////////////////////////////////////////////////////////////////////////////////////
93 * \class HistogramUncertaintyBase
94 * \ingroup HistFactory
95 * Base class to store the up and down variations for histogram uncertainties.
96 * Use the derived classes for actual models.
97 */
99
100 public:
101
102 HistogramUncertaintyBase() : fhLow(nullptr), fhHigh(nullptr) {}
103 HistogramUncertaintyBase(const std::string& Name) : fName(Name), fhLow(nullptr), fhHigh(nullptr) {}
105 fName{oth.fName},
108 fhLow{oth.fhLow ? static_cast<TH1*>(oth.fhLow->Clone()) : nullptr},
109 fhHigh{oth.fhHigh ? static_cast<TH1*>(oth.fhHigh->Clone()) : nullptr} {
110
111 }
113
115
116
117 // Need deep copies because the class owns its histograms.
119 fName = oth.fName;
126 fhLow.reset(oth.fhLow ? static_cast<TH1*>(oth.fhLow->Clone()) : nullptr);
127 fhHigh.reset(oth.fhHigh ? static_cast<TH1*>(oth.fhHigh->Clone()) : nullptr);
128
129 return *this;
130 }
132
133 virtual void Print(std::ostream& = std::cout) const;
134 virtual void PrintXML(std::ostream&) const = 0;
135 virtual void writeToFile( const std::string& FileName, const std::string& DirName );
136
137 void SetHistoLow(TH1* Low ) {Low->SetDirectory(nullptr); fhLow.reset(Low);}
138 void SetHistoHigh(TH1* High ) {High->SetDirectory(nullptr); fhHigh.reset(High);}
139
140 const TH1* GetHistoLow() const {return fhLow.get();}
141 const TH1* GetHistoHigh() const {return fhHigh.get();}
142
143 void SetName( const std::string& Name ) { fName = Name; }
144 const std::string& GetName() const { return fName; }
145
146 void SetInputFileLow( const std::string& InputFileLow ) { fInputFileLow = InputFileLow; }
147 void SetInputFileHigh( const std::string& InputFileHigh ) { fInputFileHigh = InputFileHigh; }
148
149 const std::string& GetInputFileLow() const { return fInputFileLow; }
150 const std::string& GetInputFileHigh() const { return fInputFileHigh; }
151
152 void SetHistoNameLow( const std::string& HistoNameLow ) { fHistoNameLow = HistoNameLow; }
153 void SetHistoNameHigh( const std::string& HistoNameHigh ) { fHistoNameHigh = HistoNameHigh; }
154
155 const std::string& GetHistoNameLow() const { return fHistoNameLow; }
156 const std::string& GetHistoNameHigh() const { return fHistoNameHigh; }
157
158 void SetHistoPathLow( const std::string& HistoPathLow ) { fHistoPathLow = HistoPathLow; }
159 void SetHistoPathHigh( const std::string& HistoPathHigh ) { fHistoPathHigh = HistoPathHigh; }
160
161 const std::string& GetHistoPathLow() const { return fHistoPathLow; }
162 const std::string& GetHistoPathHigh() const { return fHistoPathHigh; }
163
164 protected:
165
166 std::string fName;
167
168 std::string fInputFileLow;
169 std::string fHistoNameLow;
170 std::string fHistoPathLow;
171
172 std::string fInputFileHigh;
173 std::string fHistoNameHigh;
174 std::string fHistoPathHigh;
175
176 // The Low and High Histograms
177 std::unique_ptr<TH1> fhLow;
178 std::unique_ptr<TH1> fhHigh;
179
180 };
181
182/** \class HistoSys
183 * \ingroup HistFactory
184 * Configuration for a constrained, coherent shape variation of affected samples.
185 */
186class HistoSys final : public HistogramUncertaintyBase {
187public:
188 void PrintXML(std::ostream&) const override;
189};
190
191/** \class HistoFactor
192 * \ingroup HistFactory
193 * Configuration for an *un*constrained, coherent shape variation of affected samples.
194 */
196 public:
197 void PrintXML(std::ostream&) const override;
198 };
199
200/** \class ShapeSys
201 * \ingroup HistFactory
202 * Constrained bin-by-bin variation of affected histogram.
203 */
204 class ShapeSys final : public HistogramUncertaintyBase {
205
206 public:
207 ShapeSys() : fConstraintType(Constraint::Gaussian) {}
208 ShapeSys(const ShapeSys& other) :
212 if (this == &oth) return *this;
215 return *this;
216 }
218
219 void SetInputFile( const std::string& InputFile ) { fInputFileHigh = InputFile; }
220 std::string GetInputFile() const { return fInputFileHigh; }
221
222 void SetHistoName( const std::string& HistoName ) { fHistoNameHigh = HistoName; }
223 std::string GetHistoName() const { return fHistoNameHigh; }
224
225 void SetHistoPath( const std::string& HistoPath ) { fHistoPathHigh = HistoPath; }
226 std::string GetHistoPath() const { return fHistoPathHigh; }
227
228 void Print(std::ostream& = std::cout) const override;
229 void PrintXML(std::ostream&) const override;
230 void writeToFile( const std::string& FileName, const std::string& DirName ) override;
231
232 const TH1* GetErrorHist() const {
233 return fhHigh.get();
234 }
235 void SetErrorHist(TH1* hError) {
236 fhHigh.reset(hError);
237 }
238
239 void SetConstraintType( Constraint::Type ConstrType ) { fConstraintType = ConstrType; }
241
242 protected:
244 };
245
246/** \class ShapeFactor
247 * \ingroup HistFactory
248 * *Un*constrained bin-by-bin variation of affected histogram.
249 */
251
252 public:
253 void Print(std::ostream& = std::cout) const override;
254 void PrintXML(std::ostream&) const override;
255 void writeToFile( const std::string& FileName, const std::string& DirName) override;
256
257 void SetInitialShape(TH1* shape) {
258 fhHigh.reset(shape);
259 }
260 const TH1* GetInitialShape() const { return fhHigh.get(); }
261
262 void SetConstant(bool constant) { fConstant = constant; }
263 bool IsConstant() const { return fConstant; }
264
265 bool HasInitialShape() const { return fHasInitialShape; }
266
267 void SetInputFile( const std::string& InputFile ) {
268 fInputFileHigh = InputFile;
269 fHasInitialShape=true;
270 }
271 const std::string& GetInputFile() const { return fInputFileHigh; }
272
273 void SetHistoName( const std::string& HistoName ) {
274 fHistoNameHigh = HistoName;
275 fHasInitialShape=true;
276 }
277 const std::string& GetHistoName() const { return fHistoNameHigh; }
278
279 void SetHistoPath( const std::string& HistoPath ) {
280 fHistoPathHigh = HistoPath;
281 fHasInitialShape=true;
282 }
283 const std::string& GetHistoPath() const { return fHistoPathHigh; }
284
285 protected:
286
287 bool fConstant = false;
288
289 // A histogram representing
290 // the initial shape
291 bool fHasInitialShape = false;
292 };
293
294/** \class StatError
295 * \ingroup HistFactory
296 * Statistical error of Monte Carlo predictions.
297 */
299
300 public:
301 void Print(std::ostream& = std::cout) const override;
302 void PrintXML(std::ostream&) const override;
303 void writeToFile( const std::string& FileName, const std::string& DirName ) override;
304
305 void Activate( bool IsActive=true ) { fActivate = IsActive; }
306 bool GetActivate() const { return fActivate; }
307
308 void SetUseHisto( bool UseHisto=true ) { fUseHisto = UseHisto; }
309 bool GetUseHisto() const { return fUseHisto; }
310
311 void SetInputFile( const std::string& InputFile ) { fInputFileHigh = InputFile; }
312 const std::string& GetInputFile() const { return fInputFileHigh; }
313
314 void SetHistoName( const std::string& HistoName ) { fHistoNameHigh = HistoName; }
315 const std::string& GetHistoName() const { return fHistoNameHigh; }
316
317 void SetHistoPath( const std::string& HistoPath ) { fHistoPathHigh = HistoPath; }
318 const std::string& GetHistoPath() const { return fHistoPathHigh; }
319
320
321 const TH1* GetErrorHist() const {
322 return fhHigh.get();
323 }
325 fhHigh.reset(Error);
326 }
327
328 protected:
329
330 bool fActivate = false;
331 bool fUseHisto = false; // Use an external histogram for the errors
332 };
333
334/** \class StatErrorConfig
335 * \ingroup HistFactory
336 * Configuration to automatically assign nuisance parameters for the statistical
337 * error of the Monte Carlo simulations.
338 * The default is to assign a Poisson uncertainty to a bin when its statistical uncertainty
339 * is larger than 5% of the bin content.
340 */
342
343 public:
344
345 StatErrorConfig() : fRelErrorThreshold( .05 ), fConstraintType( Constraint::Poisson ) {;}
346 void Print(std::ostream& = std::cout) const;
347 void PrintXML(std::ostream&) const;
348
349 void SetRelErrorThreshold( double Threshold ) { fRelErrorThreshold = Threshold; }
350 double GetRelErrorThreshold() const { return fRelErrorThreshold; }
351
352 void SetConstraintType( Constraint::Type ConstrType ) { fConstraintType = ConstrType; }
354
355 protected:
356
359
360 };
361
362
363}
364}
365
366#endif
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
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
////////////////////////////////////////////////////////////////////////////////////////////Base clas...
Definition Systematics.h:98
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:62
void Print(std::ostream &=std::cout) const
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
const std::string & GetName() const
Definition Systematics.h:41
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:59
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
Definition TH1.cxx:8905
Type GetType(const std::string &Name)
std::string Name(Type type)
Namespace for the RooStats classes.
Definition Asimov.h:19