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
210 fConstraintType(Constraint::Gaussian) {}
211 ShapeSys(const ShapeSys& other) :
215 if (this == &oth) return *this;
218 return *this;
219 }
221
222 void SetInputFile( const std::string& InputFile ) { fInputFileHigh = InputFile; }
223 std::string GetInputFile() const { return fInputFileHigh; }
224
225 void SetHistoName( const std::string& HistoName ) { fHistoNameHigh = HistoName; }
226 std::string GetHistoName() const { return fHistoNameHigh; }
227
228 void SetHistoPath( const std::string& HistoPath ) { fHistoPathHigh = HistoPath; }
229 std::string GetHistoPath() const { return fHistoPathHigh; }
230
231 void Print(std::ostream& = std::cout) const override;
232 void PrintXML(std::ostream&) const override;
233 void writeToFile( const std::string& FileName, const std::string& DirName ) override;
234
235 const TH1* GetErrorHist() const {
236 return fhHigh.get();
237 }
238 void SetErrorHist(TH1* hError) {
239 fhHigh.reset(hError);
240 }
241
242 void SetConstraintType( Constraint::Type ConstrType ) { fConstraintType = ConstrType; }
244
245 protected:
247 };
248
249/** \class ShapeFactor
250 * \ingroup HistFactory
251 * *Un*constrained bin-by-bin variation of affected histogram.
252 */
254
255 public:
256
259 fConstant{false},
260 fHasInitialShape{false} {}
261
262 void Print(std::ostream& = std::cout) const override;
263 void PrintXML(std::ostream&) const override;
264 void writeToFile( const std::string& FileName, const std::string& DirName) override;
265
266 void SetInitialShape(TH1* shape) {
267 fhHigh.reset(shape);
268 }
269 const TH1* GetInitialShape() const { return fhHigh.get(); }
270
271 void SetConstant(bool constant) { fConstant = constant; }
272 bool IsConstant() const { return fConstant; }
273
274 bool HasInitialShape() const { return fHasInitialShape; }
275
276 void SetInputFile( const std::string& InputFile ) {
277 fInputFileHigh = InputFile;
278 fHasInitialShape=true;
279 }
280 const std::string& GetInputFile() const { return fInputFileHigh; }
281
282 void SetHistoName( const std::string& HistoName ) {
283 fHistoNameHigh = HistoName;
284 fHasInitialShape=true;
285 }
286 const std::string& GetHistoName() const { return fHistoNameHigh; }
287
288 void SetHistoPath( const std::string& HistoPath ) {
289 fHistoPathHigh = HistoPath;
290 fHasInitialShape=true;
291 }
292 const std::string& GetHistoPath() const { return fHistoPathHigh; }
293
294 protected:
295
297
298 // A histogram representing
299 // the initial shape
301 };
302
303/** \class StatError
304 * \ingroup HistFactory
305 * Statistical error of Monte Carlo predictions.
306 */
308
309 public:
310
313 fActivate(false), fUseHisto(false) {}
314
315 void Print(std::ostream& = std::cout) const override;
316 void PrintXML(std::ostream&) const override;
317 void writeToFile( const std::string& FileName, const std::string& DirName ) override;
318
319 void Activate( bool IsActive=true ) { fActivate = IsActive; }
320 bool GetActivate() const { return fActivate; }
321
322 void SetUseHisto( bool UseHisto=true ) { fUseHisto = UseHisto; }
323 bool GetUseHisto() const { return fUseHisto; }
324
325 void SetInputFile( const std::string& InputFile ) { fInputFileHigh = InputFile; }
326 const std::string& GetInputFile() const { return fInputFileHigh; }
327
328 void SetHistoName( const std::string& HistoName ) { fHistoNameHigh = HistoName; }
329 const std::string& GetHistoName() const { return fHistoNameHigh; }
330
331 void SetHistoPath( const std::string& HistoPath ) { fHistoPathHigh = HistoPath; }
332 const std::string& GetHistoPath() const { return fHistoPathHigh; }
333
334
335 const TH1* GetErrorHist() const {
336 return fhHigh.get();
337 }
339 fhHigh.reset(Error);
340 }
341
342 protected:
343
345 bool fUseHisto; // Use an external histogram for the errors
346 };
347
348/** \class StatErrorConfig
349 * \ingroup HistFactory
350 * Configuration to automatically assign nuisance parameters for the statistical
351 * error of the Monte Carlo simulations.
352 * The default is to assign a Poisson uncertainty to a bin when its statistical uncertainty
353 * is larger than 5% of the bin content.
354 */
356
357 public:
358
359 StatErrorConfig() : fRelErrorThreshold( .05 ), fConstraintType( Constraint::Poisson ) {;}
360 void Print(std::ostream& = std::cout) const;
361 void PrintXML(std::ostream&) const;
362
363 void SetRelErrorThreshold( double Threshold ) { fRelErrorThreshold = Threshold; }
364 double GetRelErrorThreshold() const { return fRelErrorThreshold; }
365
366 void SetConstraintType( Constraint::Type ConstrType ) { fConstraintType = ConstrType; }
368
369 protected:
370
373
374 };
375
376
377}
378}
379
380#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: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:8854
Type GetType(const std::string &Name)
std::string Name(Type type)
Namespace for the RooStats classes.
Definition Asimov.h:19