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 ~HistoSys() override {}
189 void PrintXML(std::ostream&) const override;
190};
191
192/** \class HistoFactor
193 * \ingroup HistFactory
194 * Configuration for an *un*constrained, coherent shape variation of affected samples.
195 */
197 public:
198 ~HistoFactor() override {}
199 void PrintXML(std::ostream&) const override;
200 };
201
202/** \class ShapeSys
203 * \ingroup HistFactory
204 * Constrained bin-by-bin variation of affected histogram.
205 */
206 class ShapeSys final : public HistogramUncertaintyBase {
207
208 public:
209
212 fConstraintType(Constraint::Gaussian) {}
213 ShapeSys(const ShapeSys& other) :
217 if (this == &oth) return *this;
220 return *this;
221 }
223
224 void SetInputFile( const std::string& InputFile ) { fInputFileHigh = InputFile; }
225 std::string GetInputFile() const { return fInputFileHigh; }
226
227 void SetHistoName( const std::string& HistoName ) { fHistoNameHigh = HistoName; }
228 std::string GetHistoName() const { return fHistoNameHigh; }
229
230 void SetHistoPath( const std::string& HistoPath ) { fHistoPathHigh = HistoPath; }
231 std::string GetHistoPath() const { return fHistoPathHigh; }
232
233 void Print(std::ostream& = std::cout) const override;
234 void PrintXML(std::ostream&) const override;
235 void writeToFile( const std::string& FileName, const std::string& DirName ) override;
236
237 const TH1* GetErrorHist() const {
238 return fhHigh.get();
239 }
240 void SetErrorHist(TH1* hError) {
241 fhHigh.reset(hError);
242 }
243
244 void SetConstraintType( Constraint::Type ConstrType ) { fConstraintType = ConstrType; }
246
247 protected:
249 };
250
251/** \class ShapeFactor
252 * \ingroup HistFactory
253 * *Un*constrained bin-by-bin variation of affected histogram.
254 */
256
257 public:
258
261 fConstant{false},
262 fHasInitialShape{false} {}
263
264 void Print(std::ostream& = std::cout) const override;
265 void PrintXML(std::ostream&) const override;
266 void writeToFile( const std::string& FileName, const std::string& DirName) override;
267
268 void SetInitialShape(TH1* shape) {
269 fhHigh.reset(shape);
270 }
271 const TH1* GetInitialShape() const { return fhHigh.get(); }
272
273 void SetConstant(bool constant) { fConstant = constant; }
274 bool IsConstant() const { return fConstant; }
275
276 bool HasInitialShape() const { return fHasInitialShape; }
277
278 void SetInputFile( const std::string& InputFile ) {
279 fInputFileHigh = InputFile;
280 fHasInitialShape=true;
281 }
282 const std::string& GetInputFile() const { return fInputFileHigh; }
283
284 void SetHistoName( const std::string& HistoName ) {
285 fHistoNameHigh = HistoName;
286 fHasInitialShape=true;
287 }
288 const std::string& GetHistoName() const { return fHistoNameHigh; }
289
290 void SetHistoPath( const std::string& HistoPath ) {
291 fHistoPathHigh = HistoPath;
292 fHasInitialShape=true;
293 }
294 const std::string& GetHistoPath() const { return fHistoPathHigh; }
295
296 protected:
297
299
300 // A histogram representing
301 // the initial shape
303 };
304
305/** \class StatError
306 * \ingroup HistFactory
307 * Statistical error of Monte Carlo predictions.
308 */
310
311 public:
312
315 fActivate(false), fUseHisto(false) {}
316
317 void Print(std::ostream& = std::cout) const override;
318 void PrintXML(std::ostream&) const override;
319 void writeToFile( const std::string& FileName, const std::string& DirName ) override;
320
321 void Activate( bool IsActive=true ) { fActivate = IsActive; }
322 bool GetActivate() const { return fActivate; }
323
324 void SetUseHisto( bool UseHisto=true ) { fUseHisto = UseHisto; }
325 bool GetUseHisto() const { return fUseHisto; }
326
327 void SetInputFile( const std::string& InputFile ) { fInputFileHigh = InputFile; }
328 const std::string& GetInputFile() const { return fInputFileHigh; }
329
330 void SetHistoName( const std::string& HistoName ) { fHistoNameHigh = HistoName; }
331 const std::string& GetHistoName() const { return fHistoNameHigh; }
332
333 void SetHistoPath( const std::string& HistoPath ) { fHistoPathHigh = HistoPath; }
334 const std::string& GetHistoPath() const { return fHistoPathHigh; }
335
336
337 const TH1* GetErrorHist() const {
338 return fhHigh.get();
339 }
341 fhHigh.reset(Error);
342 }
343
344 protected:
345
347 bool fUseHisto; // Use an external histogram for the errors
348 };
349
350/** \class StatErrorConfig
351 * \ingroup HistFactory
352 * Configuration to automatically assign nuisance parameters for the statistical
353 * error of the Monte Carlo simulations.
354 * The default is to assign a Poisson uncertainty to a bin when its statistical uncertainty
355 * is larger than 5% of the bin content.
356 */
358
359 public:
360
361 StatErrorConfig() : fRelErrorThreshold( .05 ), fConstraintType( Constraint::Poisson ) {;}
362 void Print(std::ostream& = std::cout) const;
363 void PrintXML(std::ostream&) const;
364
365 void SetRelErrorThreshold( double Threshold ) { fRelErrorThreshold = Threshold; }
366 double GetRelErrorThreshold() const { return fRelErrorThreshold; }
367
368 void SetConstraintType( Constraint::Type ConstrType ) { fConstraintType = ConstrType; }
370
371 protected:
372
375
376 };
377
378
379}
380}
381
382#endif
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:197
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:58
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:8803
Type GetType(const std::string &Name)
std::string Name(Type type)
Namespace for the RooStats classes.
Definition Asimov.h:19