Logo ROOT  
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
21namespace RooStats{
22namespace HistFactory {
23
24 namespace Constraint {
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 const 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 SetLow( double Low ) { fLow = Low; }
90 void SetHigh( double High ) { fHigh = High; }
91 double GetLow() const { return fLow; }
92 double GetHigh() const { return fHigh; }
93
94 void Print(std::ostream& = std::cout) const;
95 void PrintXML(std::ostream&) const;
96
97 protected:
98
99 std::string fName;
100 double fVal;
101 double fLow;
102 double fHigh;
103
104 };
105
106
107 /** ////////////////////////////////////////////////////////////////////////////////////////////
108 * \class HistogramUncertaintyBase
109 * \ingroup HistFactory
110 * Base class to store the up and down variations for histogram uncertainties.
111 * Use the derived classes for actual models.
112 */
114
115 public:
116
117 HistogramUncertaintyBase() : fhLow(nullptr), fhHigh(nullptr) {}
118 HistogramUncertaintyBase(const std::string& Name) : fName(Name), fhLow(nullptr), fhHigh(nullptr) {}
120 fName{oth.fName},
123 fhLow{oth.fhLow ? static_cast<TH1*>(oth.fhLow->Clone()) : nullptr},
124 fhHigh{oth.fhHigh ? static_cast<TH1*>(oth.fhHigh->Clone()) : nullptr} {
125
126 }
128
130
131
132 // Need deep copies because the class owns its histograms.
134 fName = oth.fName;
141 fhLow.reset(oth.fhLow ? static_cast<TH1*>(oth.fhLow->Clone()) : nullptr);
142 fhHigh.reset(oth.fhHigh ? static_cast<TH1*>(oth.fhHigh->Clone()) : nullptr);
143
144 return *this;
145 }
147
148 virtual void Print(std::ostream& = std::cout) const;
149 virtual void PrintXML(std::ostream&) const = 0;
150 virtual void writeToFile( const std::string& FileName, const std::string& DirName );
151
152 void SetHistoLow(TH1* Low ) {Low->SetDirectory(nullptr); fhLow.reset(Low);}
153 void SetHistoHigh(TH1* High ) {High->SetDirectory(nullptr); fhHigh.reset(High);}
154
155 const TH1* GetHistoLow() const {return fhLow.get();}
156 const TH1* GetHistoHigh() const {return fhHigh.get();}
157
158 void SetName( const std::string& Name ) { fName = Name; }
159 const std::string& GetName() const { return fName; }
160
161 void SetInputFileLow( const std::string& InputFileLow ) { fInputFileLow = InputFileLow; }
162 void SetInputFileHigh( const std::string& InputFileHigh ) { fInputFileHigh = InputFileHigh; }
163
164 const std::string& GetInputFileLow() const { return fInputFileLow; }
165 const std::string& GetInputFileHigh() const { return fInputFileHigh; }
166
167 void SetHistoNameLow( const std::string& HistoNameLow ) { fHistoNameLow = HistoNameLow; }
168 void SetHistoNameHigh( const std::string& HistoNameHigh ) { fHistoNameHigh = HistoNameHigh; }
169
170 const std::string& GetHistoNameLow() const { return fHistoNameLow; }
171 const std::string& GetHistoNameHigh() const { return fHistoNameHigh; }
172
173 void SetHistoPathLow( const std::string& HistoPathLow ) { fHistoPathLow = HistoPathLow; }
174 void SetHistoPathHigh( const std::string& HistoPathHigh ) { fHistoPathHigh = HistoPathHigh; }
175
176 const std::string& GetHistoPathLow() const { return fHistoPathLow; }
177 const std::string& GetHistoPathHigh() const { return fHistoPathHigh; }
178
179 protected:
180
181 std::string fName;
182
183 std::string fInputFileLow;
184 std::string fHistoNameLow;
185 std::string fHistoPathLow;
186
187 std::string fInputFileHigh;
188 std::string fHistoNameHigh;
189 std::string fHistoPathHigh;
190
191 // The Low and High Histograms
192 std::unique_ptr<TH1> fhLow;
193 std::unique_ptr<TH1> fhHigh;
194
195 };
196
197/** \class HistoSys
198 * \ingroup HistFactory
199 * Configuration for a constrained, coherent shape variation of affected samples.
200 */
201class HistoSys final : public HistogramUncertaintyBase {
202public:
203 ~HistoSys() override {}
204 void PrintXML(std::ostream&) const override;
205};
206
207/** \class HistoFactor
208 * \ingroup HistFactory
209 * Configuration for an *un*constrained, coherent shape variation of affected samples.
210 */
212 public:
213 ~HistoFactor() override {}
214 void PrintXML(std::ostream&) const override;
215 };
216
217/** \class ShapeSys
218 * \ingroup HistFactory
219 * Constrained bin-by-bin variation of affected histogram.
220 */
221 class ShapeSys final : public HistogramUncertaintyBase {
222
223 public:
224
227 fConstraintType(Constraint::Gaussian) {}
228 ShapeSys(const ShapeSys& other) :
232 if (this == &oth) return *this;
235 return *this;
236 }
238
239 void SetInputFile( const std::string& InputFile ) { fInputFileHigh = InputFile; }
240 std::string GetInputFile() const { return fInputFileHigh; }
241
242 void SetHistoName( const std::string& HistoName ) { fHistoNameHigh = HistoName; }
243 std::string GetHistoName() const { return fHistoNameHigh; }
244
245 void SetHistoPath( const std::string& HistoPath ) { fHistoPathHigh = HistoPath; }
246 std::string GetHistoPath() const { return fHistoPathHigh; }
247
248 void Print(std::ostream& = std::cout) const override;
249 void PrintXML(std::ostream&) const override;
250 void writeToFile( const std::string& FileName, const std::string& DirName ) override;
251
252 const TH1* GetErrorHist() const {
253 return fhHigh.get();
254 }
255 void SetErrorHist(TH1* hError) {
256 fhHigh.reset(hError);
257 }
258
259 void SetConstraintType( Constraint::Type ConstrType ) { fConstraintType = ConstrType; }
261
262 protected:
264 };
265
266/** \class ShapeFactor
267 * \ingroup HistFactory
268 * *Un*constrained bin-by-bin variation of affected histogram.
269 */
271
272 public:
273
276 fConstant{false},
277 fHasInitialShape{false} {}
278
279 void Print(std::ostream& = std::cout) const override;
280 void PrintXML(std::ostream&) const override;
281 void writeToFile( const std::string& FileName, const std::string& DirName) override;
282
283 void SetInitialShape(TH1* shape) {
284 fhHigh.reset(shape);
285 }
286 const TH1* GetInitialShape() const { return fhHigh.get(); }
287
288 void SetConstant(bool constant) { fConstant = constant; }
289 bool IsConstant() const { return fConstant; }
290
291 bool HasInitialShape() const { return fHasInitialShape; }
292
293 void SetInputFile( const std::string& InputFile ) {
294 fInputFileHigh = InputFile;
295 fHasInitialShape=true;
296 }
297 const std::string& GetInputFile() const { return fInputFileHigh; }
298
299 void SetHistoName( const std::string& HistoName ) {
300 fHistoNameHigh = HistoName;
301 fHasInitialShape=true;
302 }
303 const std::string& GetHistoName() const { return fHistoNameHigh; }
304
305 void SetHistoPath( const std::string& HistoPath ) {
306 fHistoPathHigh = HistoPath;
307 fHasInitialShape=true;
308 }
309 const std::string& GetHistoPath() const { return fHistoPathHigh; }
310
311 protected:
312
314
315 // A histogram representing
316 // the initial shape
318 };
319
320/** \class StatError
321 * \ingroup HistFactory
322 * Statistical error of Monte Carlo predictions.
323 */
325
326 public:
327
330 fActivate(false), fUseHisto(false) {}
331
332 void Print(std::ostream& = std::cout) const override;
333 void PrintXML(std::ostream&) const override;
334 void writeToFile( const std::string& FileName, const std::string& DirName ) override;
335
336 void Activate( bool IsActive=true ) { fActivate = IsActive; }
337 bool GetActivate() const { return fActivate; }
338
339 void SetUseHisto( bool UseHisto=true ) { fUseHisto = UseHisto; }
340 bool GetUseHisto() const { return fUseHisto; }
341
342 void SetInputFile( const std::string& InputFile ) { fInputFileHigh = InputFile; }
343 const std::string& GetInputFile() const { return fInputFileHigh; }
344
345 void SetHistoName( const std::string& HistoName ) { fHistoNameHigh = HistoName; }
346 const std::string& GetHistoName() const { return fHistoNameHigh; }
347
348 void SetHistoPath( const std::string& HistoPath ) { fHistoPathHigh = HistoPath; }
349 const std::string& GetHistoPath() const { return fHistoPathHigh; }
350
351
352 const TH1* GetErrorHist() const {
353 return fhHigh.get();
354 }
356 fhHigh.reset(Error);
357 }
358
359 protected:
360
362 bool fUseHisto; // Use an external histogram for the errors
363 };
364
365/** \class StatErrorConfig
366 * \ingroup HistFactory
367 * Configuration to automatically assign nuisance parameters for the statistical
368 * error of the Monte Carlo simulations.
369 * The default is to assign a Poisson uncertainty to a bin when its statistical uncertainty
370 * is larger than 5% of the bin content.
371 */
373
374 public:
375
377 void Print(std::ostream& = std::cout) const;
378 void PrintXML(std::ostream&) const;
379
380 void SetRelErrorThreshold( double Threshold ) { fRelErrorThreshold = Threshold; }
381 double GetRelErrorThreshold() const { return fRelErrorThreshold; }
382
383 void SetConstraintType( Constraint::Type ConstrType ) { fConstraintType = ConstrType; }
385
386 protected:
387
390
391 };
392
393
394}
395}
396
397#endif
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition: TError.cxx:188
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.
Definition: Systematics.h:211
void PrintXML(std::ostream &) const override
Configuration for a constrained, coherent shape variation of affected samples.
Definition: Systematics.h:201
void PrintXML(std::ostream &) const override
////////////////////////////////////////////////////////////////////////////////////////////Base clas...
Definition: Systematics.h:113
void SetInputFileHigh(const std::string &InputFileHigh)
Definition: Systematics.h:162
HistogramUncertaintyBase(const HistogramUncertaintyBase &oth)
Definition: Systematics.h:119
void SetName(const std::string &Name)
Definition: Systematics.h:158
virtual void writeToFile(const std::string &FileName, const std::string &DirName)
virtual void PrintXML(std::ostream &) const =0
void SetHistoPathHigh(const std::string &HistoPathHigh)
Definition: Systematics.h:174
HistogramUncertaintyBase & operator=(HistogramUncertaintyBase &&)=default
void SetInputFileLow(const std::string &InputFileLow)
Definition: Systematics.h:161
const std::string & GetHistoNameHigh() const
Definition: Systematics.h:171
const std::string & GetHistoNameLow() const
Definition: Systematics.h:170
void SetHistoNameHigh(const std::string &HistoNameHigh)
Definition: Systematics.h:168
void SetHistoNameLow(const std::string &HistoNameLow)
Definition: Systematics.h:167
virtual void Print(std::ostream &=std::cout) const
Definition: Systematics.cxx:92
HistogramUncertaintyBase & operator=(const HistogramUncertaintyBase &oth)
Definition: Systematics.h:133
const std::string & GetHistoPathLow() const
Definition: Systematics.h:176
const std::string & GetInputFileHigh() const
Definition: Systematics.h:165
const std::string & GetInputFileLow() const
Definition: Systematics.h:164
HistogramUncertaintyBase(const std::string &Name)
Definition: Systematics.h:118
void SetHistoPathLow(const std::string &HistoPathLow)
Definition: Systematics.h:173
const std::string & GetHistoPathHigh() const
Definition: Systematics.h:177
HistogramUncertaintyBase(HistogramUncertaintyBase &&)=default
Configuration for an un- constrained overall systematic to scale sample normalisations.
Definition: Systematics.h:77
std::string GetName() const
Definition: Systematics.h:84
void Print(std::ostream &=std::cout) const
Definition: Systematics.cxx:60
void PrintXML(std::ostream &) const
Definition: Systematics.cxx:68
void SetName(const std::string &Name)
Definition: Systematics.h:83
Configuration for a constrained overall systematic to scale sample normalisations.
Definition: Systematics.h:49
void SetName(const std::string &Name)
Definition: Systematics.h:55
const std::string & GetName() const
Definition: Systematics.h:56
void PrintXML(std::ostream &) const
Definition: Systematics.cxx:84
void Print(std::ostream &=std::cout) const
Definition: Systematics.cxx:77
*Un*constrained bin-by-bin variation of affected histogram.
Definition: Systematics.h:270
void PrintXML(std::ostream &) const override
const std::string & GetHistoPath() const
Definition: Systematics.h:309
const TH1 * GetInitialShape() const
Definition: Systematics.h:286
void SetInputFile(const std::string &InputFile)
Definition: Systematics.h:293
void SetHistoName(const std::string &HistoName)
Definition: Systematics.h:299
void writeToFile(const std::string &FileName, const std::string &DirName) override
void Print(std::ostream &=std::cout) const override
const std::string & GetInputFile() const
Definition: Systematics.h:297
void SetConstant(bool constant)
Definition: Systematics.h:288
void SetHistoPath(const std::string &HistoPath)
Definition: Systematics.h:305
const std::string & GetHistoName() const
Definition: Systematics.h:303
Constrained bin-by-bin variation of affected histogram.
Definition: Systematics.h:221
std::string GetHistoPath() const
Definition: Systematics.h:246
void PrintXML(std::ostream &) const override
Constraint::Type GetConstraintType() const
Definition: Systematics.h:260
const TH1 * GetErrorHist() const
Definition: Systematics.h:252
Constraint::Type fConstraintType
Definition: Systematics.h:263
std::string GetHistoName() const
Definition: Systematics.h:243
ShapeSys & operator=(ShapeSys &&)=default
ShapeSys(const ShapeSys &other)
Definition: Systematics.h:228
void SetInputFile(const std::string &InputFile)
Definition: Systematics.h:239
void writeToFile(const std::string &FileName, const std::string &DirName) override
void Print(std::ostream &=std::cout) const override
ShapeSys & operator=(const ShapeSys &oth)
Definition: Systematics.h:231
void SetHistoName(const std::string &HistoName)
Definition: Systematics.h:242
void SetConstraintType(Constraint::Type ConstrType)
Definition: Systematics.h:259
std::string GetInputFile() const
Definition: Systematics.h:240
void SetErrorHist(TH1 *hError)
Definition: Systematics.h:255
void SetHistoPath(const std::string &HistoPath)
Definition: Systematics.h:245
Configuration to automatically assign nuisance parameters for the statistical error of the Monte Carl...
Definition: Systematics.h:372
void PrintXML(std::ostream &) const
void SetConstraintType(Constraint::Type ConstrType)
Definition: Systematics.h:383
void SetRelErrorThreshold(double Threshold)
Definition: Systematics.h:380
Constraint::Type GetConstraintType() const
Definition: Systematics.h:384
void Print(std::ostream &=std::cout) const
Statistical error of Monte Carlo predictions.
Definition: Systematics.h:324
const std::string & GetHistoPath() const
Definition: Systematics.h:349
void Activate(bool IsActive=true)
Definition: Systematics.h:336
void SetHistoPath(const std::string &HistoPath)
Definition: Systematics.h:348
void SetInputFile(const std::string &InputFile)
Definition: Systematics.h:342
const TH1 * GetErrorHist() const
Definition: Systematics.h:352
const std::string & GetInputFile() const
Definition: Systematics.h:343
void SetHistoName(const std::string &HistoName)
Definition: Systematics.h:345
const std::string & GetHistoName() const
Definition: Systematics.h:346
void SetUseHisto(bool UseHisto=true)
Definition: Systematics.h:339
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:8804
@ HistFactory
Definition: RooGlobalFunc.h:63
Type GetType(const std::string &Name)
Definition: Systematics.cxx:34
std::string Name(Type type)
Definition: Systematics.cxx:27
Namespace for the RooStats classes.
Definition: Asimov.h:19