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"
19#include "TDirectory.h"
21
22namespace RooStats{
23namespace HistFactory {
24
25 namespace Constraint {
27 std::string Name( Type type );
28 Type GetType( const std::string& Name );
29 }
30
31/** \class OverallSys
32 * \ingroup HistFactory
33 * Configuration for a constrained overall systematic to scale sample normalisations.
34 */
35 class OverallSys {
36
37 public:
38
39 OverallSys() : fLow(0), fHigh(0) {}
40
41 void SetName( const std::string& Name ) { fName = Name; }
42 const std::string& GetName() const { return fName; }
43
44 void SetLow( double Low ) { fLow = Low; }
45 void SetHigh( double High ) { fHigh = High; }
46 double GetLow() const { return fLow; }
47 double GetHigh() const { return fHigh; }
48
49 void Print(std::ostream& = std::cout) const;
50 void PrintXML(std::ostream&) const;
51
52 protected:
53 std::string fName;
54 double fLow;
55 double fHigh;
56
57 };
58
59/** \class NormFactor
60 * \ingroup HistFactory
61 * Configuration for an \a un- constrained overall systematic to scale sample normalisations.
62 */
63 class NormFactor {
64
65 public:
66
67 NormFactor();
68
69 void SetName( const std::string& Name ) { fName = Name; }
70 std::string GetName() const { return fName; }
71
72 void SetVal( double Val ) { fVal = Val; }
73 double GetVal() const { return fVal; }
74
75 void SetLow( double Low ) { fLow = Low; }
76 void SetHigh( double High ) { fHigh = High; }
77 double GetLow() const { return fLow; }
78 double GetHigh() const { return fHigh; }
79
80 void Print(std::ostream& = std::cout) const;
81 void PrintXML(std::ostream&) const;
82
83 protected:
84
85 std::string fName;
86 double fVal;
87 double fLow;
88 double fHigh;
89
90 };
91
92
93 /** ////////////////////////////////////////////////////////////////////////////////////////////
94 * \class HistogramUncertaintyBase
95 * \ingroup HistFactory
96 * Base class to store the up and down variations for histogram uncertainties.
97 * Use the derived classes for actual models.
98 */
100
101 public:
102
103 HistogramUncertaintyBase() : fhLow(nullptr), fhHigh(nullptr) {}
104 HistogramUncertaintyBase(const std::string& Name) : fName(Name), fhLow(nullptr), fhHigh(nullptr) {}
117
119
120
121 // Need deep copies because the class owns its histograms.
123 fName = oth.fName;
124 fInputFileLow = oth.fInputFileLow;
125 fHistoNameLow = oth.fHistoNameLow;
126 fHistoPathLow = oth.fHistoPathLow;
127 fInputFileHigh = oth.fInputFileHigh;
128 fHistoNameHigh = oth.fHistoNameHigh;
129 fHistoPathHigh = oth.fHistoPathHigh;
130
131 TDirectory::TContext ctx{nullptr}; // Don't associate clones to directories
132 fhLow.reset(oth.fhLow ? static_cast<TH1*>(oth.fhLow->Clone()) : nullptr);
133 fhHigh.reset(oth.fhHigh ? static_cast<TH1*>(oth.fhHigh->Clone()) : nullptr);
134
135 return *this;
136 }
138
139 virtual void Print(std::ostream& = std::cout) const;
140 virtual void PrintXML(std::ostream&) const = 0;
141 virtual void writeToFile( const std::string& FileName, const std::string& DirName );
142
143 void SetHistoLow(TH1* Low ) {Low->SetDirectory(nullptr); fhLow.reset(Low);}
144 void SetHistoHigh(TH1* High ) {High->SetDirectory(nullptr); fhHigh.reset(High);}
145
146 const TH1* GetHistoLow() const {return fhLow.get();}
147 const TH1* GetHistoHigh() const {return fhHigh.get();}
148
149 void SetName( const std::string& Name ) { fName = Name; }
150 const std::string& GetName() const { return fName; }
151
152 void SetInputFileLow( const std::string& InputFileLow ) { fInputFileLow = InputFileLow; }
154
155 const std::string& GetInputFileLow() const { return fInputFileLow; }
156 const std::string& GetInputFileHigh() const { return fInputFileHigh; }
157
158 void SetHistoNameLow( const std::string& HistoNameLow ) { fHistoNameLow = HistoNameLow; }
160
161 const std::string& GetHistoNameLow() const { return fHistoNameLow; }
162 const std::string& GetHistoNameHigh() const { return fHistoNameHigh; }
163
164 void SetHistoPathLow( const std::string& HistoPathLow ) { fHistoPathLow = HistoPathLow; }
166
167 const std::string& GetHistoPathLow() const { return fHistoPathLow; }
168 const std::string& GetHistoPathHigh() const { return fHistoPathHigh; }
169
170 protected:
171
172 std::string fName;
173
174 std::string fInputFileLow;
175 std::string fHistoNameLow;
176 std::string fHistoPathLow;
177
178 std::string fInputFileHigh;
179 std::string fHistoNameHigh;
180 std::string fHistoPathHigh;
181
182 // The Low and High Histograms
183 std::unique_ptr<TH1> fhLow;
184 std::unique_ptr<TH1> fhHigh;
185
186 };
187
188/** \class HistoSys
189 * \ingroup HistFactory
190 * Configuration for a constrained, coherent shape variation of affected samples.
191 */
193public:
194 void PrintXML(std::ostream&) const override;
195};
196
197/** \class HistoFactor
198 * \ingroup HistFactory
199 * Configuration for an *un*constrained, coherent shape variation of affected samples.
200 */
202 public:
203 void PrintXML(std::ostream&) const override;
204 };
205
206/** \class ShapeSys
207 * \ingroup HistFactory
208 * Constrained bin-by-bin variation of affected histogram.
209 */
211
212 public:
213 ShapeSys() : fConstraintType(Constraint::Gaussian) {}
218 if (this == &oth) return *this;
220 fConstraintType = oth.fConstraintType;
221 return *this;
222 }
224
225 void SetInputFile( const std::string& InputFile ) { fInputFileHigh = InputFile; }
226 std::string GetInputFile() const { return fInputFileHigh; }
227
228 void SetHistoName( const std::string& HistoName ) { fHistoNameHigh = HistoName; }
229 std::string GetHistoName() const { return fHistoNameHigh; }
230
231 void SetHistoPath( const std::string& HistoPath ) { fHistoPathHigh = HistoPath; }
232 std::string GetHistoPath() const { return fHistoPathHigh; }
233
234 void Print(std::ostream& = std::cout) const override;
235 void PrintXML(std::ostream&) const override;
236 void writeToFile( const std::string& FileName, const std::string& DirName ) override;
237
238 const TH1* GetErrorHist() const {
239 return fhHigh.get();
240 }
242 fhHigh.reset(hError);
243 }
244
247
248 protected:
250 };
251
252/** \class ShapeFactor
253 * \ingroup HistFactory
254 * *Un*constrained bin-by-bin variation of affected histogram.
255 */
257
258 public:
259 void Print(std::ostream& = std::cout) const override;
260 void PrintXML(std::ostream&) const override;
261 void writeToFile( const std::string& FileName, const std::string& DirName) override;
262
263 void SetInitialShape(TH1* shape) {
264 fhHigh.reset(shape);
265 }
266 const TH1* GetInitialShape() const { return fhHigh.get(); }
267
269 bool IsConstant() const { return fConstant; }
270
271 bool HasInitialShape() const { return fHasInitialShape; }
272
273 void SetInputFile( const std::string& InputFile ) {
275 fHasInitialShape=true;
276 }
277 const std::string& GetInputFile() const { return fInputFileHigh; }
278
279 void SetHistoName( const std::string& HistoName ) {
281 fHasInitialShape=true;
282 }
283 const std::string& GetHistoName() const { return fHistoNameHigh; }
284
285 void SetHistoPath( const std::string& HistoPath ) {
287 fHasInitialShape=true;
288 }
289 const std::string& GetHistoPath() const { return fHistoPathHigh; }
290
291 protected:
292
293 bool fConstant = false;
294
295 // A histogram representing
296 // the initial shape
297 bool fHasInitialShape = false;
298 };
299
300/** \class StatError
301 * \ingroup HistFactory
302 * Statistical error of Monte Carlo predictions.
303 */
305
306 public:
307 void Print(std::ostream& = std::cout) const override;
308 void PrintXML(std::ostream&) const override;
309 void writeToFile( const std::string& FileName, const std::string& DirName ) override;
310
311 void Activate( bool IsActive=true ) { fActivate = IsActive; }
312 bool GetActivate() const { return fActivate; }
313
314 void SetUseHisto( bool UseHisto=true ) { fUseHisto = UseHisto; }
315 bool GetUseHisto() const { return fUseHisto; }
316
317 void SetInputFile( const std::string& InputFile ) { fInputFileHigh = InputFile; }
318 const std::string& GetInputFile() const { return fInputFileHigh; }
319
320 void SetHistoName( const std::string& HistoName ) { fHistoNameHigh = HistoName; }
321 const std::string& GetHistoName() const { return fHistoNameHigh; }
322
323 void SetHistoPath( const std::string& HistoPath ) { fHistoPathHigh = HistoPath; }
324 const std::string& GetHistoPath() const { return fHistoPathHigh; }
325
326
327 const TH1* GetErrorHist() const {
328 return fhHigh.get();
329 }
331 fhHigh.reset(Error);
332 }
333
334 protected:
335
336 bool fActivate = false;
337 bool fUseHisto = false; // Use an external histogram for the errors
338 };
339
340/** \class StatErrorConfig
341 * \ingroup HistFactory
342 * Configuration to automatically assign nuisance parameters for the statistical
343 * error of the Monte Carlo simulations.
344 * The default is to assign a Poisson uncertainty to a bin when its statistical uncertainty
345 * is larger than 5% of the bin content.
346 */
348
349 public:
350
351 StatErrorConfig() : fRelErrorThreshold( .05 ), fConstraintType( Constraint::Poisson ) {;}
352 void Print(std::ostream& = std::cout) const;
353 void PrintXML(std::ostream&) const;
354
356 double GetRelErrorThreshold() const { return fRelErrorThreshold; }
357
360
361 protected:
362
365
366 };
367
368
369}
370}
371
372#endif
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:99
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:63
void Print(std::ostream &=std::cout) const
void PrintXML(std::ostream &) const
void SetName(const std::string &Name)
Definition Systematics.h:69
Configuration for a constrained overall systematic to scale sample normalisations.
Definition Systematics.h:35
void SetName(const std::string &Name)
Definition Systematics.h:41
const std::string & GetName() const
Definition Systematics.h:42
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
TDirectory::TContext keeps track and restore the current directory.
Definition TDirectory.h:89
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:8933
Type GetType(const std::string &Name)
std::string Name(Type type)
Namespace for the RooStats classes.
Definition CodegenImpl.h:58