Logo ROOT   6.14/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 /*
14 BEGIN_HTML
15 <p>
16 </p>
17 END_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" ) {
42  return Constraint::Gaussian;
43  }
44 
45  else if ( Name == "Poisson" || Name == "Pois" ) {
46  return Constraint::Poisson;
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 
61 void RooStats::HistFactory::NormFactor::Print( std::ostream& stream ) {
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 
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
80 void RooStats::HistFactory::OverallSys::Print( std::ostream& stream ) {
81  stream << "\t \t Name: " << fName
82  << "\t Low: " << fLow
83  << "\t High: " << fHigh
84  << std::endl;
85 }
86 
88  xml << " <OverallSys Name=\"" << GetName() << "\" "
89  << " High=\"" << GetHigh() << "\" "
90  << " Low=\"" << GetLow() << "\" "
91  << " /> " << std::endl;
92 }
93 
94 // HistoSys
96  TH1* histo_low = (TH1*) fhLow.GetObject();
97  return histo_low;
98 }
99 
101  TH1* histo_high = (TH1*) fhHigh.GetObject();
102  return histo_high;
103 }
104 
105 void RooStats::HistFactory::HistoSys::Print( std::ostream& stream ) {
106  stream << "\t \t Name: " << fName
107  << "\t HistoFileLow: " << fInputFileLow
108  << "\t HistoNameLow: " << fHistoNameLow
109  << "\t HistoPathLow: " << fHistoPathLow
110  << "\t HistoFileHigh: " << fInputFileHigh
111  << "\t HistoNameHigh: " << fHistoNameHigh
112  << "\t HistoPathHigh: " << fHistoPathHigh
113  << std::endl;
114 }
115 
116 void RooStats::HistFactory::HistoSys::PrintXML( std::ostream& xml ) {
117  xml << " <HistoSys Name=\"" << GetName() << "\" "
118  << " HistoFileLow=\"" << GetInputFileLow() << "\" "
119  << " HistoNameLow=\"" << GetHistoNameLow() << "\" "
120  << " HistoPathLow=\"" << GetHistoPathLow() << "\" "
121 
122  << " HistoFileHigh=\"" << GetInputFileHigh() << "\" "
123  << " HistoNameHigh=\"" << GetHistoNameHigh() << "\" "
124  << " HistoPathHigh=\"" << GetHistoPathHigh() << "\" "
125  << " /> " << std::endl;
126 }
127 
128 void RooStats::HistFactory::HistoSys::writeToFile( const std::string& FileName,
129  const std::string& DirName ) {
130 
131  // This saves the histograms to a file and
132  // changes the name of the local file and histograms
133 
134  TH1* histLow = GetHistoLow();
135  if( histLow==NULL ) {
136  std::cout << "Error: Cannot write " << GetName()
137  << " to file: " << FileName
138  << " HistoLow is NULL"
139  << std::endl;
140  throw hf_exc();
141  }
142  histLow->Write();
143  fInputFileLow = FileName;
144  fHistoPathLow = DirName;
145  fHistoNameLow = histLow->GetName();
146 
147  TH1* histHigh = GetHistoHigh();
148  if( histHigh==NULL ) {
149  std::cout << "Error: Cannot write " << GetName()
150  << " to file: " << FileName
151  << " HistoHigh is NULL"
152  << std::endl;
153  throw hf_exc();
154  }
155  histHigh->Write();
156  fInputFileHigh = FileName;
157  fHistoPathHigh = DirName;
158  fHistoNameHigh = histHigh->GetName();
159 
160  return;
161 
162 }
163 
164 
165 // Shape Sys
166 
168  TH1* error_hist = (TH1*) fhError.GetObject();
169  return error_hist;
170 }
171 
172 
173 void RooStats::HistFactory::ShapeSys::Print( std::ostream& stream ) {
174  stream << "\t \t Name: " << fName
175  << "\t InputFile: " << fInputFile
176  << "\t HistoName: " << fHistoName
177  << "\t HistoPath: " << fHistoPath
178  << std::endl;
179 }
180 
181 
182 void RooStats::HistFactory::ShapeSys::PrintXML( std::ostream& xml ) {
183  xml << " <ShapeSys Name=\"" << GetName() << "\" "
184  << " InputFile=\"" << GetInputFile() << "\" "
185  << " HistoName=\"" << GetHistoName() << "\" "
186  << " HistoPath=\"" << GetHistoPath() << "\" "
187  << " ConstraintType=\"" << std::string(Constraint::Name(GetConstraintType())) << "\" "
188  << " /> " << std::endl;
189 }
190 
191 
192 void RooStats::HistFactory::ShapeSys::writeToFile( const std::string& FileName,
193  const std::string& DirName ) {
194 
195  TH1* histError = GetErrorHist();
196  if( histError==NULL ) {
197  std::cout << "Error: Cannot write " << GetName()
198  << " to file: " << FileName
199  << " ErrorHist is NULL"
200  << std::endl;
201  throw hf_exc();
202  }
203  histError->Write();
204  fInputFile = FileName;
205  fHistoPath = DirName;
206  fHistoName = histError->GetName();
207 
208  return;
209 
210 }
211 
212 
213 
214 
215 // HistoFactor
216 
217 void RooStats::HistFactory::HistoFactor::Print( std::ostream& stream ) {
218  stream << "\t \t Name: " << fName
219  << "\t InputFileLow: " << fInputFileLow
220  << "\t HistoNameLow: " << fHistoNameLow
221  << "\t HistoPathLow: " << fHistoPathLow
222  << "\t InputFileHigh: " << fInputFileHigh
223  << "\t HistoNameHigh: " << fHistoNameHigh
224  << "\t HistoPathHigh: " << fHistoPathHigh
225  << std::endl;
226 }
227 
228 
230  TH1* histo_low = (TH1*) fhLow.GetObject();
231  return histo_low;
232 }
233 
235  TH1* histo_high = (TH1*) fhHigh.GetObject();
236  return histo_high;
237 }
238 
239 
240 void RooStats::HistFactory::HistoFactor::writeToFile( const std::string& FileName,
241  const std::string& DirName ) {
242 
243 
244  // This saves the histograms to a file and
245  // changes the name of the local file and histograms
246 
247  TH1* histLow = GetHistoLow();
248  if( histLow==NULL ) {
249  std::cout << "Error: Cannot write " << GetName()
250  << " to file: " << FileName
251  << " HistoLow is NULL"
252  << std::endl;
253  throw hf_exc();
254  }
255  histLow->Write();
256  fInputFileLow = FileName;
257  fHistoPathLow = DirName;
258  fHistoNameLow = histLow->GetName();
259 
260  TH1* histHigh = GetHistoHigh();
261  if( histHigh==NULL ) {
262  std::cout << "Error: Cannot write " << GetName()
263  << " to file: " << FileName
264  << " HistoHigh is NULL"
265  << std::endl;
266  throw hf_exc();
267  }
268  histHigh->Write();
269  fInputFileHigh = FileName;
270  fHistoPathHigh = DirName;
271  fHistoNameHigh = histHigh->GetName();
272 
273  return;
274 
275 }
276 
278  xml << " <HistoFactor Name=\"" << GetName() << "\" "
279 
280  << " InputFileLow=\"" << GetInputFileLow() << "\" "
281  << " HistoNameLow=\"" << GetHistoNameLow() << "\" "
282  << " HistoPathLow=\"" << GetHistoPathLow() << "\" "
283 
284  << " InputFileHigh=\"" << GetInputFileHigh() << "\" "
285  << " HistoNameHigh=\"" << GetHistoNameHigh() << "\" "
286  << " HistoPathHigh=\"" << GetHistoPathHigh() << "\" "
287  << " /> " << std::endl;
288 }
289 
290 
291 // Shape Factor
293  fHasInitialShape(false),
294  fhInitialShape(NULL) {;}
295 
296 void RooStats::HistFactory::ShapeFactor::Print( std::ostream& stream ) {
297 
298  stream << "\t \t Name: " << fName << std::endl;
299 
300  if( fHistoName != "" ) {
301  stream << "\t \t "
302  << " Shape Hist Name: " << fHistoName
303  << " Shape Hist Path Name: " << fHistoPath
304  << " Shape Hist FileName: " << fInputFile
305  << std::endl;
306  }
307 
308  if( fConstant ) { stream << "\t \t ( Constant ): " << std::endl; }
309 
310 }
311 
312 
313 void RooStats::HistFactory::ShapeFactor::writeToFile( const std::string& FileName,
314  const std::string& DirName ) {
315 
316  if( HasInitialShape() ) {
317  TH1* histInitialShape = GetInitialShape();
318  if( histInitialShape==NULL ) {
319  std::cout << "Error: Cannot write " << GetName()
320  << " to file: " << FileName
321  << " InitialShape is NULL"
322  << std::endl;
323  throw hf_exc();
324  }
325  histInitialShape->Write();
326  fInputFile = FileName;
327  fHistoPath = DirName;
328  fHistoName = histInitialShape->GetName();
329  }
330 
331  return;
332 
333 }
334 
335 
337  xml << " <ShapeFactor Name=\"" << GetName() << "\" ";
338  if( fHasInitialShape ) {
339  xml << " InputFile=\"" << GetInputFile() << "\" "
340  << " HistoName=\"" << GetHistoName() << "\" "
341  << " HistoPath=\"" << GetHistoPath() << "\" ";
342  }
343  xml << " /> " << std::endl;
344 }
345 
346 
347 // Stat Error Config
348 void RooStats::HistFactory::StatErrorConfig::Print( std::ostream& stream ) {
349  stream << "\t \t RelErrorThreshold: " << fRelErrorThreshold
350  << "\t ConstraintType: " << Constraint::Name( fConstraintType )
351  << std::endl;
352 }
353 
355  xml << " <StatErrorConfig RelErrorThreshold=\"" << GetRelErrorThreshold()
356  << "\" "
357  << "ConstraintType=\"" << Constraint::Name( GetConstraintType() )
358  << "\" "
359  << "/> " << std::endl << std::endl;
360 
361 }
362 
363 
364 // Stat Error
366  return (TH1*) fhError.GetObject();
367 }
368 
369 
370 void RooStats::HistFactory::StatError::Print( std::ostream& stream ) {
371  stream << "\t \t Activate: " << fActivate
372  << "\t InputFile: " << fInputFile
373  << "\t HistoName: " << fHistoName
374  << "\t histoPath: " << fHistoPath
375  << std::endl;
376 }
377 
379 
380  if( GetActivate() ) {
381  xml << " <StatError Activate=\""
382  << (GetActivate() ? std::string("True") : std::string("False"))
383  << "\" "
384  << " InputFile=\"" << GetInputFile() << "\" "
385  << " HistoName=\"" << GetHistoName() << "\" "
386  << " HistoPath=\"" << GetHistoPath() << "\" "
387  << " /> " << std::endl;
388  }
389 
390 }
391 
392 
393 void RooStats::HistFactory::StatError::writeToFile( const std::string& OutputFileName,
394  const std::string& DirName ) {
395 
396  if( fUseHisto ) {
397 
398  std::string statErrorHistName = "statisticalErrors";
399 
400  TH1* hStatError = GetErrorHist();
401  if( hStatError == NULL ) {
402  std::cout << "Error: Stat Error error hist is NULL" << std::endl;
403  throw hf_exc();
404  }
405  hStatError->Write(statErrorHistName.c_str());
406 
407  fInputFile = OutputFileName;
408  fHistoName = statErrorHistName;
409  fHistoPath = DirName;
410 
411  }
412 
413  return;
414 
415 }
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition: TObject.cxx:785
void Print(std::ostream &=std::cout)
void PrintXML(std::ostream &)
void Print(std::ostream &=std::cout)
Type GetType(const std::string &Name)
Definition: Systematics.cxx:34
const char * Name
Definition: TXMLSetup.cxx:66
void writeToFile(const std::string &FileName, const std::string &DirName)
void Print(std::ostream &=std::cout)
void PrintXML(std::ostream &)
Definition: Systematics.cxx:87
void Print(std::ostream &=std::cout)
void writeToFile(const std::string &FileName, const std::string &DirName)
void Print(std::ostream &=std::cout)
Definition: Systematics.cxx:80
void writeToFile(const std::string &FileName, const std::string &DirName)
void PrintXML(std::ostream &)
Definition: Systematics.cxx:70
void Print(std::ostream &=std::cout)
Definition: Systematics.cxx:61
int type
Definition: TGX11.cxx:120
void PrintXML(std::ostream &)
The TH1 histogram class.
Definition: TH1.h:56
std::string Name(Type type)
Definition: Systematics.cxx:27
void writeToFile(const std::string &FileName, const std::string &DirName)
void writeToFile(const std::string &FileName, const std::string &DirName)
void Print(std::ostream &=std::cout)
void PrintXML(std::ostream &)
void Print(std::ostream &=std::cout)