Logo ROOT   6.18/05
Reference Guide
Systematics.cxx
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Author: Kyle Cranmer, George Lewis
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////////////////////////////////////////////////////////////////////////////////
12
13/*
14BEGIN_HTML
15<p>
16</p>
17END_HTML
18*/
19//
20
21
24
25
26// Constraints
28
29 if( type == Constraint::Gaussian ) return "Gaussian";
30 if( type == Constraint::Poisson ) return "Poisson";
31 return "";
32}
33
35
36 if( Name == "" ) {
37 std::cout << "Error: Given empty name for ConstraintType" << std::endl;
38 throw hf_exc();
39 }
40
41 else if ( Name == "Gaussian" || Name == "Gauss" ) {
43 }
44
45 else if ( Name == "Poisson" || Name == "Pois" ) {
47 }
48
49 else {
50 std::cout << "Error: Unknown name given for Constraint Type: " << Name << std::endl;
51 throw hf_exc();
52 }
53
54}
55
56// Norm Factor
58 fLow(1.0), fHigh(1.0),
59 fConst(true) {;}
60
61void RooStats::HistFactory::NormFactor::Print( std::ostream& stream ) const {
62 stream << "\t \t Name: " << fName
63 << "\t Val: " << fVal
64 << "\t Low: " << fLow
65 << "\t High: " << fHigh
66 << "\t Const: " << fConst
67 << std::endl;
68}
69
70void RooStats::HistFactory::NormFactor::PrintXML( std::ostream& xml ) const {
71 xml << " <NormFactor Name=\"" << GetName() << "\" "
72 << " Val=\"" << GetVal() << "\" "
73 << " High=\"" << GetHigh() << "\" "
74 << " Low=\"" << GetLow() << "\" "
75 << " Const=\"" << (GetConst() ? std::string("True") : std::string("False")) << "\" "
76 << " /> " << std::endl;
77}
78
79// Overall Sys
80void RooStats::HistFactory::OverallSys::Print( std::ostream& stream ) const {
81 stream << "\t \t Name: " << fName
82 << "\t Low: " << fLow
83 << "\t High: " << fHigh
84 << std::endl;
85}
86
87void RooStats::HistFactory::OverallSys::PrintXML( std::ostream& xml ) const {
88 xml << " <OverallSys Name=\"" << GetName() << "\" "
89 << " High=\"" << GetHigh() << "\" "
90 << " Low=\"" << GetLow() << "\" "
91 << " /> " << std::endl;
92}
93
94
96 stream << "\t \t Name: " << fName
97 << "\t HistoFileLow: " << fInputFileLow
98 << "\t HistoNameLow: " << fHistoNameLow
99 << "\t HistoPathLow: " << fHistoPathLow
100 << "\t HistoFileHigh: " << fInputFileHigh
101 << "\t HistoNameHigh: " << fHistoNameHigh
102 << "\t HistoPathHigh: " << fHistoPathHigh
103 << std::endl;
104}
105
107 const std::string& DirName ) {
108
109 // This saves the histograms to a file and
110 // changes the name of the local file and histograms
111
112 auto histLow = GetHistoLow();
113 if( histLow==NULL ) {
114 std::cout << "Error: Cannot write " << GetName()
115 << " to file: " << FileName
116 << " HistoLow is NULL"
117 << std::endl;
118 throw hf_exc();
119 }
120 histLow->Write();
121 fInputFileLow = FileName;
122 fHistoPathLow = DirName;
123 fHistoNameLow = histLow->GetName();
124
125 auto histHigh = GetHistoHigh();
126 if( histHigh==NULL ) {
127 std::cout << "Error: Cannot write " << GetName()
128 << " to file: " << FileName
129 << " HistoHigh is NULL"
130 << std::endl;
131 throw hf_exc();
132 }
133 histHigh->Write();
134 fInputFileHigh = FileName;
135 fHistoPathHigh = DirName;
136 fHistoNameHigh = histHigh->GetName();
137
138 return;
139
140}
141
142
143void RooStats::HistFactory::HistoSys::PrintXML( std::ostream& xml ) const {
144 xml << " <HistoSys Name=\"" << GetName() << "\" "
145 << " HistoFileLow=\"" << GetInputFileLow() << "\" "
146 << " HistoNameLow=\"" << GetHistoNameLow() << "\" "
147 << " HistoPathLow=\"" << GetHistoPathLow() << "\" "
148
149 << " HistoFileHigh=\"" << GetInputFileHigh() << "\" "
150 << " HistoNameHigh=\"" << GetHistoNameHigh() << "\" "
151 << " HistoPathHigh=\"" << GetHistoPathHigh() << "\" "
152 << " /> " << std::endl;
153}
154
155// Shape Sys
156
157void RooStats::HistFactory::ShapeSys::Print( std::ostream& stream ) const {
158 stream << "\t \t Name: " << fName
159 << "\t InputFile: " << fInputFileHigh
160 << "\t HistoName: " << fHistoNameHigh
161 << "\t HistoPath: " << fHistoPathHigh
162 << std::endl;
163}
164
165
166void RooStats::HistFactory::ShapeSys::PrintXML( std::ostream& xml ) const {
167 xml << " <ShapeSys Name=\"" << GetName() << "\" "
168 << " InputFile=\"" << GetInputFile() << "\" "
169 << " HistoName=\"" << GetHistoName() << "\" "
170 << " HistoPath=\"" << GetHistoPath() << "\" "
171 << " ConstraintType=\"" << std::string(Constraint::Name(GetConstraintType())) << "\" "
172 << " /> " << std::endl;
173}
174
175
176void RooStats::HistFactory::ShapeSys::writeToFile( const std::string& FileName,
177 const std::string& DirName ) {
178
179 auto histError = GetErrorHist();
180 if( histError==NULL ) {
181 std::cout << "Error: Cannot write " << GetName()
182 << " to file: " << FileName
183 << " ErrorHist is NULL"
184 << std::endl;
185 throw hf_exc();
186 }
187 histError->Write();
188 fInputFileHigh = FileName;
189 fHistoPathHigh = DirName;
190 fHistoNameHigh = histError->GetName();
191
192 return;
193
194}
195
196
197
198
199// HistoFactor
200
201void RooStats::HistFactory::HistoFactor::PrintXML( std::ostream& xml ) const {
202 xml << " <HistoFactor Name=\"" << GetName() << "\" "
203
204 << " InputFileLow=\"" << GetInputFileLow() << "\" "
205 << " HistoNameLow=\"" << GetHistoNameLow() << "\" "
206 << " HistoPathLow=\"" << GetHistoPathLow() << "\" "
207
208 << " InputFileHigh=\"" << GetInputFileHigh() << "\" "
209 << " HistoNameHigh=\"" << GetHistoNameHigh() << "\" "
210 << " HistoPathHigh=\"" << GetHistoPathHigh() << "\" "
211 << " /> " << std::endl;
212}
213
214
215// Shape Factor
216void RooStats::HistFactory::ShapeFactor::Print( std::ostream& stream ) const {
217
218 stream << "\t \t Name: " << fName << std::endl;
219
220 if( fHistoNameHigh != "" ) {
221 stream << "\t \t "
222 << " Shape Hist Name: " << fHistoNameHigh
223 << " Shape Hist Path Name: " << fHistoPathHigh
224 << " Shape Hist FileName: " << fInputFileHigh
225 << std::endl;
226 }
227
228 if( fConstant ) { stream << "\t \t ( Constant ): " << std::endl; }
229
230}
231
232
233void RooStats::HistFactory::ShapeFactor::writeToFile( const std::string& FileName,
234 const std::string& DirName ) {
235
236 if( HasInitialShape() ) {
237 auto histInitialShape = GetInitialShape();
238 if( histInitialShape==NULL ) {
239 std::cout << "Error: Cannot write " << GetName()
240 << " to file: " << FileName
241 << " InitialShape is NULL"
242 << std::endl;
243 throw hf_exc();
244 }
245 histInitialShape->Write();
246 fInputFileHigh = FileName;
247 fHistoPathHigh = DirName;
248 fHistoNameHigh = histInitialShape->GetName();
249 }
250
251 return;
252
253}
254
255
256void RooStats::HistFactory::ShapeFactor::PrintXML( std::ostream& xml ) const {
257 xml << " <ShapeFactor Name=\"" << GetName() << "\" ";
258 if( fHasInitialShape ) {
259 xml << " InputFile=\"" << GetInputFile() << "\" "
260 << " HistoName=\"" << GetHistoName() << "\" "
261 << " HistoPath=\"" << GetHistoPath() << "\" ";
262 }
263 xml << " /> " << std::endl;
264}
265
266
267// Stat Error Config
268void RooStats::HistFactory::StatErrorConfig::Print( std::ostream& stream ) const {
269 stream << "\t \t RelErrorThreshold: " << fRelErrorThreshold
270 << "\t ConstraintType: " << Constraint::Name( fConstraintType )
271 << std::endl;
272}
273
275 xml << " <StatErrorConfig RelErrorThreshold=\"" << GetRelErrorThreshold()
276 << "\" "
277 << "ConstraintType=\"" << Constraint::Name( GetConstraintType() )
278 << "\" "
279 << "/> " << std::endl << std::endl;
280
281}
282
283
284// Stat Error
285void RooStats::HistFactory::StatError::Print( std::ostream& stream ) const {
286 stream << "\t \t Activate: " << fActivate
287 << "\t InputFile: " << fInputFileHigh
288 << "\t HistoName: " << fHistoNameHigh
289 << "\t histoPath: " << fHistoPathHigh
290 << std::endl;
291}
292
293void RooStats::HistFactory::StatError::PrintXML( std::ostream& xml ) const {
294
295 if( GetActivate() ) {
296 xml << " <StatError Activate=\""
297 << (GetActivate() ? std::string("True") : std::string("False"))
298 << "\" "
299 << " InputFile=\"" << GetInputFile() << "\" "
300 << " HistoName=\"" << GetHistoName() << "\" "
301 << " HistoPath=\"" << GetHistoPath() << "\" "
302 << " /> " << std::endl;
303 }
304
305}
306
307
308void RooStats::HistFactory::StatError::writeToFile( const std::string& OutputFileName,
309 const std::string& DirName ) {
310
311 if( fUseHisto ) {
312
313 std::string statErrorHistName = "statisticalErrors";
314
315 auto hStatError = GetErrorHist();
316 if( hStatError == NULL ) {
317 std::cout << "Error: Stat Error error hist is NULL" << std::endl;
318 throw hf_exc();
319 }
320 hStatError->Write(statErrorHistName.c_str());
321
322 fInputFileHigh = OutputFileName;
323 fHistoNameHigh = statErrorHistName;
324 fHistoPathHigh = DirName;
325
326 }
327
328 return;
329
330}
int type
Definition: TGX11.cxx:120
void PrintXML(std::ostream &) const override
virtual void PrintXML(std::ostream &) const override
virtual void writeToFile(const std::string &FileName, const std::string &DirName)
virtual void Print(std::ostream &=std::cout) const
Definition: Systematics.cxx:95
void Print(std::ostream &=std::cout) const
Definition: Systematics.cxx:61
void PrintXML(std::ostream &) const
Definition: Systematics.cxx:70
void PrintXML(std::ostream &) const
Definition: Systematics.cxx:87
void Print(std::ostream &=std::cout) const
Definition: Systematics.cxx:80
void PrintXML(std::ostream &) const override
void writeToFile(const std::string &FileName, const std::string &DirName) override
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
void Print(std::ostream &=std::cout) const override
void PrintXML(std::ostream &) const
void Print(std::ostream &=std::cout) const
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
std::string GetName(const std::string &scope_name)
Definition: Cppyy.cxx:146
Type GetType(const std::string &Name)
Definition: Systematics.cxx:34
std::string Name(Type type)
Definition: Systematics.cxx:27
const char * Name
Definition: TXMLSetup.cxx:66