Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Measurement.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/** \class RooStats::HistFactory::Measurement
12 * \ingroup HistFactory
13The RooStats::HistFactory::Measurement class can be used to construct a model
14by combining multiple RooStats::HistFactory::Channel objects. It also allows
15to set some general properties like the integrated luminosity, its relative
16uncertainty or the functional form of constraints on nuisance parameters.
17*/
18
20
22
23#include <HFMsgService.h>
24
25#include <RooRealVar.h>
26#include <RooWorkspace.h>
27
28#include <TDirectory.h>
29#include <TFile.h>
30#include <TH1.h>
31#include <TKey.h>
32#include <TSystem.h>
33#include <TTimeStamp.h>
34
35#include <algorithm>
36#include <cstdlib>
37#include <ctime>
38#include <iostream>
39#include <sstream>
40#include <sys/stat.h>
41
42namespace RooStats::HistFactory {
43
44/// Set a parameter in the model to be constant.
45/// the parameter does not have to exist yet, the information will be used when
46/// the model is actually created.
47///
48/// Also checks if the parameter is already set constant.
49/// We don't need to set it constant twice,
50/// and we issue a warning in case this is a hint
51/// of a possible bug
52void Measurement::AddConstantParam(const std::string &param)
53{
54
55 if (std::find(fConstantParams.begin(), fConstantParams.end(), param) != fConstantParams.end()) {
56 cxcoutWHF << "Warning: Setting parameter: " << param << " to constant, but it is already listed as constant. "
57 << "You may ignore this warning." << std::endl;
58 return;
59 }
60
61 fConstantParams.push_back(param);
62}
63
64/// Set parameter of the model to given value
65void Measurement::SetParamValue(const std::string &param, double value)
66{
67 // Check if this parameter is already set to a value
68 // If so, issue a warning
69 // (Not sure if we want to throw an exception here, or
70 // issue a warning and move along. Thoughts?)
71 if (fParamValues.find(param) != fParamValues.end()) {
72 cxcoutWHF << "Warning: Chainging parameter: " << param << " value from: " << fParamValues[param]
73 << " to: " << value << std::endl;
74 }
75
76 // Store the parameter and its value
77 cxcoutIHF << "Setting parameter: " << param << " value to " << value << std::endl;
78
79 fParamValues[param] = value;
80}
81
82/// Add a preprocessed function by giving the function a name,
83/// a functional expression, and a string with a bracketed list of dependencies (eg "SigXsecOverSM[0,3]")
84void Measurement::AddPreprocessFunction(std::string name, std::string expression, std::string dependencies)
85{
86
87 PreprocessFunction func(name, expression, dependencies);
89}
90
91/// Returns a list of defined preprocess function expressions
92std::vector<std::string> Measurement::GetPreprocessFunctions() const
93{
94
95 std::vector<std::string> PreprocessFunctionExpressions;
96 for (unsigned int i = 0; i < fFunctionObjects.size(); ++i) {
97 std::string expression = fFunctionObjects.at(i).GetCommand();
98 PreprocessFunctionExpressions.push_back(expression);
99 }
101}
102
103/// Set constraint term for given systematic to Gamma distribution
104void Measurement::AddGammaSyst(std::string syst, double uncert)
105{
107}
108
109/// Set constraint term for given systematic to LogNormal distribution
110void Measurement::AddLogNormSyst(std::string syst, double uncert)
111{
113}
114
115/// Set constraint term for given systematic to uniform distribution
117{
118 fUniformSyst[syst] = 1.0; // Is this parameter simply a dummy?
119}
120
121/// Define given systematics to have no external constraint
123{
124 fNoSyst[syst] = 1.0; // dummy value
125}
126
127/// Check if the given channel is part of this measurement
129{
130
131 for (unsigned int i = 0; i < fChannels.size(); ++i) {
132
133 Channel &chan = fChannels.at(i);
134 if (chan.GetName() == ChanName) {
135 return true;
136 }
137 }
138
139 return false;
140}
141
142/// Get channel with given name from this measurement
143/// throws an exception in case the channel is not found
145{
146 for (unsigned int i = 0; i < fChannels.size(); ++i) {
147
148 Channel &chan = fChannels.at(i);
149 if (chan.GetName() == ChanName) {
150 return chan;
151 }
152 }
153
154 // If we get here, we didn't find the channel
155
156 cxcoutEHF << "Error: Did not find channel: " << ChanName << " in measurement: " << GetName() << std::endl;
157 throw hf_exc();
158
159 // No Need to return after throwing exception
160 // return BadChannel;
161}
162
163/// Print information about measurement object in tree-like structure to given stream
164void Measurement::PrintTree(std::ostream &stream)
165{
166
167 stream << "Measurement Name: " << GetName() << "\t OutputFilePrefix: " << fOutputFilePrefix << "\t POI: ";
168 for (unsigned int i = 0; i < fPOI.size(); ++i) {
169 stream << fPOI.at(i);
170 }
171 stream << "\t Lumi: " << fLumi << "\t LumiRelErr: " << fLumiRelErr << "\t BinLow: " << fBinLow
172 << "\t BinHigh: " << fBinHigh << "\t ExportOnly: " << fExportOnly << std::endl;
173
174 if (!fConstantParams.empty()) {
175 stream << "Constant Params: ";
176 for (unsigned int i = 0; i < fConstantParams.size(); ++i) {
177 stream << " " << fConstantParams.at(i);
178 }
179 stream << std::endl;
180 }
181
182 if (!fFunctionObjects.empty()) {
183 stream << "Preprocess Functions: ";
184 for (unsigned int i = 0; i < fFunctionObjects.size(); ++i) {
185 stream << " " << fFunctionObjects.at(i).GetCommand();
186 }
187 stream << std::endl;
188 }
189
190 if (!fChannels.empty()) {
191 stream << "Channels:" << std::endl;
192 for (unsigned int i = 0; i < fChannels.size(); ++i) {
193 fChannels.at(i).Print(stream);
194 }
195 }
196
197 cxcoutIHF << "End Measurement: " << GetName() << std::endl;
198}
199
200/// Create XML files for this measurement in the given directory.
201/// XML files can be configured with a different output prefix
202/// Create an XML file for this measurement
203/// First, create the XML driver
204/// Then, create xml files for each channel
205void Measurement::PrintXML(std::string directory, std::string newOutputPrefix)
206{
207 // First, check that the directory exists:
208 auto testExists = [](const std::string &theDirectory) {
209 void *dir = gSystem->OpenDirectory(theDirectory.c_str());
210 bool exists = dir != nullptr;
211 if (exists)
213
214 return exists;
215 };
216
217 if (!directory.empty() && !testExists(directory)) {
218 int success = gSystem->MakeDirectory(directory.c_str());
219 if (success != 0) {
220 cxcoutEHF << "Error: Failed to make directory: " << directory << std::endl;
221 throw hf_exc();
222 }
223 }
224
225 // If supplied new Prefix, use that one:
226
227 cxcoutPHF << "Printing XML Files for measurement: " << GetName() << std::endl;
228
229 std::string XMLName = std::string(GetName()) + ".xml";
230 if (!directory.empty())
231 XMLName = directory + "/" + XMLName;
232
233 std::ofstream xml(XMLName.c_str());
234
235 if (!xml.is_open()) {
236 cxcoutEHF << "Error opening xml file: " << XMLName << std::endl;
237 throw hf_exc();
238 }
239
240 // Add the time
241 xml << "<!--" << std::endl;
242 xml << "This xml file created automatically on: " << std::endl;
243
244 // LM: use TTimeStamp
245 TTimeStamp t;
246 UInt_t year = 0;
247 UInt_t month = 0;
248 UInt_t day = 0;
249 t.GetDate(true, 0, &year, &month, &day);
250 xml << year << '-' << month << '-' << day << std::endl;
251
252 xml << "-->" << std::endl;
253
254 // Add the doctype
255 xml << "<!DOCTYPE Combination SYSTEM 'HistFactorySchema.dtd'>" << std::endl << std::endl;
256
257 // Add the combination name
258 if (newOutputPrefix.empty())
260 xml << "<Combination OutputFilePrefix=\"" << newOutputPrefix /*OutputFilePrefix*/ << "\" >" << std::endl
261 << std::endl;
262
263 // Add the Preprocessed Functions
264 for (unsigned int i = 0; i < fFunctionObjects.size(); ++i) {
266 func.PrintXML(xml);
267 }
268
269 xml << std::endl;
270
271 // Add the list of channels
272 for (unsigned int i = 0; i < fChannels.size(); ++i) {
273 xml << " <Input>" << "./";
274 if (!directory.empty())
275 xml << directory << "/";
276 xml << GetName() << "_" << fChannels.at(i).GetName() << ".xml" << "</Input>" << std::endl;
277 }
278
279 xml << std::endl;
280
281 // Open the Measurement, Set Lumi
282 xml << " <Measurement Name=\"" << GetName() << "\" "
283 << "Lumi=\"" << fLumi << "\" "
284 << "LumiRelErr=\"" << fLumiRelErr
285 << "\" "
286 //<< "BinLow=\"" << fBinLow << "\" "
287 // << "BinHigh=\"" << fBinHigh << "\" "
288 << "ExportOnly=\"" << (fExportOnly ? std::string("True") : std::string("False")) << "\" "
289 << " >" << std::endl;
290
291 // Set the POI
292 xml << " <POI>";
293 for (unsigned int i = 0; i < fPOI.size(); ++i) {
294 if (i == 0)
295 xml << fPOI.at(i);
296 else
297 xml << " " << fPOI.at(i);
298 }
299 xml << "</POI> " << std::endl;
300
301 // Set the Constant Parameters
302 if (!fConstantParams.empty()) {
303 xml << " <ParamSetting Const=\"True\">";
304 for (unsigned int i = 0; i < fConstantParams.size(); ++i) {
305 if (i == 0)
306 xml << fConstantParams.at(i);
307 else
308 xml << " " << fConstantParams.at(i);
309 }
310 xml << "</ParamSetting>" << std::endl;
311 }
312
313 // Set the Parameters with new Constraint Terms
314 std::map<std::string, double>::iterator ConstrItr;
315
316 // Gamma
317 for (ConstrItr = fGammaSyst.begin(); ConstrItr != fGammaSyst.end(); ++ConstrItr) {
318 xml << "<ConstraintTerm Type=\"Gamma\" RelativeUncertainty=\"" << ConstrItr->second << "\">" << ConstrItr->first
319 << "</ConstraintTerm>" << std::endl;
320 }
321 // Uniform
322 for (ConstrItr = fUniformSyst.begin(); ConstrItr != fUniformSyst.end(); ++ConstrItr) {
323 xml << "<ConstraintTerm Type=\"Uniform\" RelativeUncertainty=\"" << ConstrItr->second << "\">" << ConstrItr->first
324 << "</ConstraintTerm>" << std::endl;
325 }
326 // LogNormal
327 for (ConstrItr = fLogNormSyst.begin(); ConstrItr != fLogNormSyst.end(); ++ConstrItr) {
328 xml << "<ConstraintTerm Type=\"LogNormal\" RelativeUncertainty=\"" << ConstrItr->second << "\">"
329 << ConstrItr->first << "</ConstraintTerm>" << std::endl;
330 }
331 // NoSyst
332 for (ConstrItr = fNoSyst.begin(); ConstrItr != fNoSyst.end(); ++ConstrItr) {
333 xml << "<ConstraintTerm Type=\"NoSyst\" RelativeUncertainty=\"" << ConstrItr->second << "\">" << ConstrItr->first
334 << "</ConstraintTerm>" << std::endl;
335 }
336
337 // Close the Measurement
338 xml << " </Measurement> " << std::endl << std::endl;
339
340 // Close the combination
341 xml << "</Combination>" << std::endl;
342
343 xml.close();
344
345 // Now, make the xml files
346 // for the individual channels:
347
348 std::string prefix = std::string(GetName()) + "_";
349
350 for (unsigned int i = 0; i < fChannels.size(); ++i) {
351 fChannels.at(i).PrintXML(directory, prefix);
352 }
353
354 cxcoutPHF << "Finished printing XML files" << std::endl;
355}
356
357/// A measurement, once fully configured, can be saved into a ROOT
358/// file. This will persitify the Measurement object, along with any
359/// channels and samples that have been added to it. It can then be
360/// loaded, potentially modified, and used to create new models.
361///
362/// Write every histogram to the file.
363/// Edit the measurement to point to this file
364/// and to point to each histogram in this file
365/// Then write the measurement itself.
367{
368
369 // Create a temporary measurement
370 // (This is the one that is actually written)
371 Measurement outMeas(*this);
372
373 std::string OutputFileName = file->GetName();
374
375 // Collect all histograms from file:
376 // HistCollector collector;
377
378 for (Channel &channel : fChannels) {
379 // Go to the main directory
380 // in the file
381 file->cd();
382 file->Flush();
383
384 // Get the name of the channel:
385 std::string chanName = channel.GetName();
386
387 if (!channel.CheckHistograms()) {
388 cxcoutEHF << "Measurement.writeToFile(): Channel: " << chanName << " has uninitialized histogram pointers"
389 << std::endl;
390 throw hf_exc();
391 return;
392 }
393
394 // Get and cache the histograms for this channel:
395 // collector.CollectHistograms( channel );
396 // Do I need this...?
397 // channel.CollectHistograms();
398
399 // Make a directory to store the histograms
400 // for this channel
401
402 TDirectory *chanDir = file->mkdir((chanName + "_hists").c_str());
403 if (chanDir == nullptr) {
404 cxcoutEHF << "Error: Cannot create channel " << (chanName + "_hists") << std::endl;
405 throw hf_exc();
406 }
407 chanDir->cd();
408
409 // Save the data:
410 TDirectory *dataDir = chanDir->mkdir("data");
411 if (dataDir == nullptr) {
412 cxcoutEHF << "Error: Cannot make directory " << chanDir << std::endl;
413 throw hf_exc();
414 }
415 dataDir->cd();
416
417 channel.fData.writeToFile(OutputFileName, GetDirPath(dataDir));
418
419 // Loop over samples:
420 for (Sample &sample : channel.GetSamples()) {
421 cxcoutPHF << "Writing sample: " << sample.GetName() << std::endl;
422
423 file->cd();
424 chanDir->cd();
425 TDirectory *sampleDir = chanDir->mkdir(sample.GetName().c_str());
426 if (sampleDir == nullptr) {
427 cxcoutEHF << "Error: Directory " << sample.GetName() << " not created properly" << std::endl;
428 throw hf_exc();
429 }
430 std::string sampleDirPath = GetDirPath(sampleDir);
431
432 if (!sampleDir) {
433 cxcoutEHF << "Error making directory: " << sample.GetName() << " in directory: " << chanName << std::endl;
434 throw hf_exc();
435 }
436
437 // Write the data file to this directory
438 sampleDir->cd();
439
440 sample.writeToFile(OutputFileName, sampleDirPath);
441 }
442 }
443
444 // Finally, write the measurement itself:
445
446 cxcoutPHF << "Saved all histograms" << std::endl;
447
448 file->cd();
449 outMeas.Write();
450
451 cxcoutPHF << "Saved Measurement" << std::endl;
452}
453
454/// Return the directory's path,
455/// stripped of unnecessary prefixes
457{
458 std::string path = dir->GetPath();
459
460 if (path.find(':') != std::string::npos) {
461 size_t index = path.find(':');
462 path.replace(0, index + 1, "");
463 }
464
465 return path + "/";
466}
467
468/// The most common way to add histograms to channels is to have them
469/// stored in ROOT files and to give HistFactory the location of these
470/// files. This means providing the path to the ROOT file and the path
471/// and name of the histogram within that file. When providing these
472/// in a script, HistFactory doesn't load the histogram from the file
473/// right away. Instead, once all such histograms have been supplied,
474/// one should run this method to open all ROOT files and to copy and
475/// save all necessary histograms.
477{
478 for (Channel &chan : fChannels) {
479 chan.CollectHistograms();
480 }
481}
482
483//////////////////////////////////////////////////////////////////////////////
484/** \class RooStats::HistFactory::Sample
485 * \ingroup HistFactory
486 */
487
488Sample::Sample() = default;
489
490Sample::~Sample() = default;
491
492// copy constructor (important for Python)
494 : fName(other.fName),
495 fInputFile(other.fInputFile),
496 fHistoName(other.fHistoName),
497 fHistoPath(other.fHistoPath),
498 fChannelName(other.fChannelName),
499
500 fOverallSysList(other.fOverallSysList),
501 fNormFactorList(other.fNormFactorList),
502 fHistoSysList(other.fHistoSysList),
503 fHistoFactorList(other.fHistoFactorList),
504 fShapeSysList(other.fShapeSysList),
505 fShapeFactorList(other.fShapeFactorList),
506
507 fStatError(other.fStatError),
508 fNormalizeByTheory(other.fNormalizeByTheory),
509 fStatErrorActivate(other.fStatErrorActivate),
510 fhNominal(other.fhNominal)
511{
512 if (other.fhCountingHist) {
513 SetValue(other.fhCountingHist->GetBinContent(1));
514 } else {
515 fhCountingHist.reset();
516 }
517}
518
520{
521 fName = other.fName;
522 fInputFile = other.fInputFile;
523 fHistoName = other.fHistoName;
524 fHistoPath = other.fHistoPath;
525 fChannelName = other.fChannelName;
526
527 fOverallSysList = other.fOverallSysList;
528 fNormFactorList = other.fNormFactorList;
529 fHistoSysList = other.fHistoSysList;
530 fHistoFactorList = other.fHistoFactorList;
531 fShapeSysList = other.fShapeSysList;
532 fShapeFactorList = other.fShapeFactorList;
533
534 fStatError = other.fStatError;
535 fNormalizeByTheory = other.fNormalizeByTheory;
536 fStatErrorActivate = other.fStatErrorActivate;
537 fhNominal = other.fhNominal;
538
539 fhCountingHist.reset();
540
541 if (other.fhCountingHist) {
542 SetValue(other.fhCountingHist->GetBinContent(1));
543 } else {
544 fhCountingHist.reset();
545 }
546
547 return *this;
548}
549
550Sample::Sample(std::string SampName, std::string SampHistoName, std::string SampInputFile, std::string SampHistoPath)
551 : fName(SampName),
552 fInputFile(SampInputFile),
553 fHistoName(SampHistoName),
554 fHistoPath(SampHistoPath),
555 fNormalizeByTheory(true),
556 fStatErrorActivate(false)
557{
558}
559
560Sample::Sample(std::string SampName) : fName(SampName), fNormalizeByTheory(true), fStatErrorActivate(false) {}
561
562const TH1 *Sample::GetHisto() const
563{
564 TH1 *histo = (TH1 *)fhNominal.GetObject();
565 return histo;
566}
567
568void Sample::writeToFile(std::string OutputFileName, std::string DirName)
569{
570
571 const TH1 *histNominal = GetHisto();
572 histNominal->Write();
573
574 // Set the location of the data
575 // in the output measurement
576
578 fHistoName = histNominal->GetName();
579 fHistoPath = DirName;
580
581 // Write this sample's StatError
583
584 // Must write all systematics that contain internal histograms
585 // (This is not all systematics)
586 for (unsigned int i = 0; i < GetHistoSysList().size(); ++i) {
587 GetHistoSysList().at(i).writeToFile(OutputFileName, DirName);
588 }
589 for (unsigned int i = 0; i < GetHistoFactorList().size(); ++i) {
590 GetHistoFactorList().at(i).writeToFile(OutputFileName, DirName);
591 }
592 for (unsigned int i = 0; i < GetShapeSysList().size(); ++i) {
593 GetShapeSysList().at(i).writeToFile(OutputFileName, DirName);
594 }
595 for (unsigned int i = 0; i < GetShapeFactorList().size(); ++i) {
596 GetShapeFactorList().at(i).writeToFile(OutputFileName, DirName);
597 }
598}
599
600void Sample::SetValue(double val)
601{
602
603 // For use in a number counting measurement
604 // Create a 1-bin histogram,
605 // fill it with this input value,
606 // and set this Sample's histogram to that hist
607
608 std::string SampleHistName = fName + "_hist";
609
610 // Histogram has 1-bin (hard-coded)
611 fhCountingHist.reset();
612
613 fhCountingHist = std::make_unique<TH1F>(SampleHistName.c_str(), SampleHistName.c_str(), 1, 0, 1);
614 fhCountingHist->SetBinContent(1, val);
615
616 // Set the histogram of the internally held data
617 // node of this channel to this newly created histogram
619}
620
621void Sample::Print(std::ostream &stream) const
622{
623
624 stream << "\t \t Name: " << fName << "\t \t Channel: " << fChannelName
625 << "\t NormalizeByTheory: " << (fNormalizeByTheory ? "True" : "False")
626 << "\t StatErrorActivate: " << (fStatErrorActivate ? "True" : "False") << std::endl;
627
628 stream << "\t \t \t \t "
629 << "\t InputFile: " << fInputFile << "\t HistName: " << fHistoName << "\t HistoPath: " << fHistoPath
630 << "\t HistoAddress: "
631 << GetHisto()
632 // << "\t Type: " << GetHisto()->ClassName()
633 << std::endl;
634
635 if (fStatError.GetActivate()) {
636 stream << "\t \t \t StatError Activate: " << fStatError.GetActivate() << "\t InputFile: " << fInputFile
637 << "\t HistName: " << fStatError.GetHistoName() << "\t HistoPath: " << fStatError.GetHistoPath()
638 << "\t HistoAddress: " << fStatError.GetErrorHist() << std::endl;
639 }
640
641 /*
642 stream<< " NormalizeByTheory: ";
643 if(NormalizeByTheory) stream << "True";
644 else stream << "False";
645
646 stream<< " StatErrorActivate: ";
647 if(StatErrorActivate) stream << "True";
648 else stream << "False";
649 */
650}
651
652void Sample::PrintXML(std::ofstream &xml) const
653{
654
655 // Create the sample tag
656 xml << " <Sample Name=\"" << fName << "\" "
657 << " HistoPath=\"" << fHistoPath << "\" "
658 << " HistoName=\"" << fHistoName << "\" "
659 << " InputFile=\"" << fInputFile << "\" "
660 << " NormalizeByTheory=\"" << (fNormalizeByTheory ? std::string("True") : std::string("False")) << "\" "
661 << ">" << std::endl;
662
663 // Print Stat Error (if necessary)
665 /*
666 if( fStatError.GetActivate() ) {
667 xml << " <StatError Activate=\"" << (fStatError.GetActivate() ? std::string("True") : std::string("False")) <<
668 "\" "
669 << " InputFile=\"" << fStatError.GetInputFile() << "\" "
670 << " HistoName=\"" << fStatError.GetHistoName() << "\" "
671 << " HistoPath=\"" << fStatError.GetHistoPath() << "\" "
672 << " /> " << std::endl;
673 }
674 */
675
676 // Now, print the systematics:
677 for (unsigned int i = 0; i < fOverallSysList.size(); ++i) {
678 OverallSys sys = fOverallSysList.at(i);
679 sys.PrintXML(xml);
680 /*
681 xml << " <OverallSys Name=\"" << sys.GetName() << "\" "
682 << " High=\"" << sys.GetHigh() << "\" "
683 << " Low=\"" << sys.GetLow() << "\" "
684 << " /> " << std::endl;
685 */
686 }
687 for (unsigned int i = 0; i < fNormFactorList.size(); ++i) {
688 NormFactor sys = fNormFactorList.at(i);
689 sys.PrintXML(xml);
690 /*
691 xml << " <NormFactor Name=\"" << sys.GetName() << "\" "
692 << " Val=\"" << sys.GetVal() << "\" "
693 << " High=\"" << sys.GetHigh() << "\" "
694 << " Low=\"" << sys.GetLow() << "\" "
695 << " /> " << std::endl;
696 */
697 }
698 for (unsigned int i = 0; i < fHistoSysList.size(); ++i) {
699 HistoSys sys = fHistoSysList.at(i);
700 sys.PrintXML(xml);
701 /*
702 xml << " <HistoSys Name=\"" << sys.GetName() << "\" "
703
704 << " InputFileLow=\"" << sys.GetInputFileLow() << "\" "
705 << " HistoNameLow=\"" << sys.GetHistoNameLow() << "\" "
706 << " HistoPathLow=\"" << sys.GetHistoPathLow() << "\" "
707
708 << " InputFileHigh=\"" << sys.GetInputFileHigh() << "\" "
709 << " HistoNameHigh=\"" << sys.GetHistoNameHigh() << "\" "
710 << " HistoPathHigh=\"" << sys.GetHistoPathHigh() << "\" "
711 << " /> " << std::endl;
712 */
713 }
714 for (unsigned int i = 0; i < fHistoFactorList.size(); ++i) {
715 HistoFactor sys = fHistoFactorList.at(i);
716 sys.PrintXML(xml);
717 /*
718 xml << " <HistoFactor Name=\"" << sys.GetName() << "\" "
719
720 << " InputFileLow=\"" << sys.GetInputFileLow() << "\" "
721 << " HistoNameLow=\"" << sys.GetHistoNameLow() << "\" "
722 << " HistoPathLow=\"" << sys.GetHistoPathLow() << "\" "
723
724 << " InputFileHigh=\"" << sys.GetInputFileHigh() << "\" "
725 << " HistoNameHigh=\"" << sys.GetHistoNameHigh() << "\" "
726 << " HistoPathHigh=\"" << sys.GetHistoPathHigh() << "\" "
727 << " /> " << std::endl;
728 */
729 }
730 for (unsigned int i = 0; i < fShapeSysList.size(); ++i) {
731 ShapeSys sys = fShapeSysList.at(i);
732 sys.PrintXML(xml);
733 /*
734 xml << " <ShapeSys Name=\"" << sys.GetName() << "\" "
735
736 << " InputFile=\"" << sys.GetInputFile() << "\" "
737 << " HistoName=\"" << sys.GetHistoName() << "\" "
738 << " HistoPath=\"" << sys.GetHistoPath() << "\" "
739 << " ConstraintType=\"" << std::string(Constraint::Name(sys.GetConstraintType())) << "\" "
740 << " /> " << std::endl;
741 */
742 }
743 for (unsigned int i = 0; i < fShapeFactorList.size(); ++i) {
744 ShapeFactor sys = fShapeFactorList.at(i);
745 sys.PrintXML(xml);
746 /*
747 xml << " <ShapeFactor Name=\"" << sys.GetName() << "\" "
748 << " /> " << std::endl;
749 */
750 }
751
752 // Finally, close the tag
753 xml << " </Sample>" << std::endl;
754}
755
756// Some helper functions
757// (Not strictly necessary because
758// methods are publicly accessible)
759
761{
762
763 fStatError.Activate(true);
764 fStatError.SetUseHisto(false);
765}
766
777
778void Sample::AddOverallSys(std::string SysName, double SysLow, double SysHigh)
779{
780
781 OverallSys sys;
782 sys.SetName(SysName);
783 sys.SetLow(SysLow);
784 sys.SetHigh(SysHigh);
785
786 fOverallSysList.push_back(sys);
787}
788
790{
791 fOverallSysList.push_back(Sys);
792}
793
794void Sample::AddNormFactor(std::string const &SysName, double SysVal, double SysLow, double SysHigh)
795{
796
798
799 norm.SetName(SysName);
800 norm.SetVal(SysVal);
801 norm.SetLow(SysLow);
802 norm.SetHigh(SysHigh);
803
804 fNormFactorList.push_back(norm);
805}
806
808{
809 fNormFactorList.push_back(Factor);
810}
811
812void Sample::AddHistoSys(std::string SysName, std::string SysHistoNameLow, std::string SysHistoFileLow,
813 std::string SysHistoPathLow, std::string SysHistoNameHigh, std::string SysHistoFileHigh,
814 std::string SysHistoPathHigh)
815{
816
817 HistoSys sys;
818 sys.SetName(SysName);
819
820 sys.SetHistoNameLow(SysHistoNameLow);
821 sys.SetHistoPathLow(SysHistoPathLow);
822 sys.SetInputFileLow(SysHistoFileLow);
823
824 sys.SetHistoNameHigh(SysHistoNameHigh);
825 sys.SetHistoPathHigh(SysHistoPathHigh);
826 sys.SetInputFileHigh(SysHistoFileHigh);
827
828 fHistoSysList.push_back(sys);
829}
830
832{
833 fHistoSysList.push_back(Sys);
834}
835
836void Sample::AddHistoFactor(std::string SysName, std::string SysHistoNameLow, std::string SysHistoFileLow,
837 std::string SysHistoPathLow, std::string SysHistoNameHigh, std::string SysHistoFileHigh,
838 std::string SysHistoPathHigh)
839{
840
841 HistoFactor factor;
842 factor.SetName(SysName);
843
847
851
852 fHistoFactorList.push_back(factor);
853}
854
856{
857 fHistoFactorList.push_back(Factor);
858}
859
861{
862
863 ShapeFactor factor;
864 factor.SetName(SysName);
865 fShapeFactorList.push_back(factor);
866}
867
869{
870 fShapeFactorList.push_back(Factor);
871}
872
874 std::string SysHistoFile, std::string SysHistoPath)
875{
876
877 ShapeSys sys;
878 sys.SetName(SysName);
879 sys.SetConstraintType(SysConstraintType);
880
881 sys.SetHistoName(SysHistoName);
882 sys.SetHistoPath(SysHistoPath);
883 sys.SetInputFile(SysHistoFile);
884
885 fShapeSysList.push_back(sys);
886}
887
889{
890 fShapeSysList.push_back(Sys);
891}
892
893////////////////////////////////////////////////////////////////////////////////
894/** \class RooStats::HistFactory::Channel
895 * \ingroup HistFactory
896 This class encapsulates all information for the statistical interpretation of one experiment.
897 It can be combined with other channels (e.g. for the combination of multiple experiments, or
898 to constrain nuisance parameters with information obtained in a control region).
899 A channel contains one or more samples which describe the contribution from different processes
900 to this measurement.
901*/
902
903Channel::Channel(std::string ChanName, std::string ChanInputFile) : fName(ChanName), fInputFile(ChanInputFile)
904{
905 // create channel with given name and input file
906}
907
908// BadChannel = Channel();
910// BadChannel.Name = "BadChannel"; // = Channel(); //.Name = "BadChannel";
911
913{
914 // add fully configured sample to channel
915
916 sample.SetChannelName(GetName());
917 fSamples.push_back(sample);
918}
919
920void Channel::Print(std::ostream &stream)
921{
922 // print information of channel to given stream
923
924 stream << "\t Channel Name: " << fName << "\t InputFile: " << fInputFile << std::endl;
925
926 stream << "\t Data:" << std::endl;
927 fData.Print(stream);
928
929 stream << "\t statErrorConfig:" << std::endl;
930 fStatErrorConfig.Print(stream);
931
932 if (!fSamples.empty()) {
933
934 stream << "\t Samples: " << std::endl;
935 for (unsigned int i = 0; i < fSamples.size(); ++i) {
936 fSamples.at(i).Print(stream);
937 }
938 }
939
940 stream << "\t End of Channel " << fName << std::endl;
941}
942
943void Channel::PrintXML(std::string const &directory, std::string const &prefix) const
944{
945
946 // Create an XML file for this channel
947 cxcoutPHF << "Printing XML Files for channel: " << GetName() << std::endl;
948
949 std::string XMLName = prefix + fName + ".xml";
950 if (!directory.empty())
951 XMLName = directory + "/" + XMLName;
952
953 std::ofstream xml(XMLName.c_str());
954
955 // Add the time
956 xml << "<!--" << std::endl;
957 xml << "This xml file created automatically on: " << std::endl;
958 // LM: use TTimeStamp since time_t does not work on Windows
959 TTimeStamp t;
960 UInt_t year = 0;
961 UInt_t month = 0;
962 UInt_t day = 0;
963 t.GetDate(true, 0, &year, &month, &day);
964 xml << year << '-' << month << '-' << day << std::endl;
965 xml << "-->" << std::endl;
966
967 // Add the DOCTYPE
968 xml << "<!DOCTYPE Channel SYSTEM 'HistFactorySchema.dtd'> " << std::endl << std::endl;
969
970 // Add the Channel
971 xml << " <Channel Name=\"" << fName << "\" InputFile=\"" << fInputFile << "\" >" << std::endl << std::endl;
972
974 for (auto const &data : fAdditionalData) {
975 data.PrintXML(xml);
976 }
977
979 /*
980 xml << " <StatErrorConfig RelErrorThreshold=\"" << fStatErrorConfig.GetRelErrorThreshold() << "\" "
981 << "ConstraintType=\"" << Constraint::Name( fStatErrorConfig.GetConstraintType() ) << "\" "
982 << "/> " << std::endl << std::endl;
983 */
984
985 for (auto const &sample : fSamples) {
986 sample.PrintXML(xml);
987 xml << std::endl << std::endl;
988 }
989
990 xml << std::endl;
991 xml << " </Channel> " << std::endl;
992 xml.close();
993
994 cxcoutPHF << "Finished printing XML files" << std::endl;
995}
996
997void Channel::SetData(std::string DataHistoName, std::string DataInputFile, std::string DataHistoPath)
998{
999 // set data for this channel by specifying the name of the histogram,
1000 // the external ROOT file and the path to the histogram inside the ROOT file
1001
1005}
1006
1008{
1009 // set data directly to some histogram
1011}
1012
1013void Channel::SetData(double val)
1014{
1015
1016 // For a NumberCounting measurement only
1017 // Set the value of data in a particular channel
1018 //
1019 // Internally, this simply creates a 1-bin TH1F for you
1020
1021 std::string DataHistName = fName + "_data";
1022
1023 // Histogram has 1-bin (hard-coded)
1024 TH1F *hData = new TH1F(DataHistName.c_str(), DataHistName.c_str(), 1, 0, 1);
1025 hData->SetBinContent(1, val);
1026
1027 // Set the histogram of the internally held data
1028 // node of this channel to this newly created histogram
1029 SetData(hData);
1030}
1031
1038
1045
1047{
1048
1049 // Loop through all Samples and Systematics
1050 // and collect all necessary histograms
1051
1052 // Handles to open files for collecting histograms
1053 std::map<std::string, std::unique_ptr<TFile>> fileHandles;
1054
1055 // Get the Data Histogram:
1056
1057 if (!fData.GetInputFile().empty()) {
1059 }
1060
1061 // Collect any histograms for additional Datasets
1062 for (auto &data : fAdditionalData) {
1063 if (!data.GetInputFile().empty()) {
1064 data.SetHisto(GetHistogram(data.GetInputFile(), data.GetHistoPath(), data.GetHistoName(), fileHandles));
1065 }
1066 }
1067
1068 // Get the histograms for the samples:
1069 for (Sample &sample : fSamples) {
1070 // Get the nominal histogram:
1071 cxcoutDHF << "Collecting Nominal Histogram" << std::endl;
1072 TH1 *Nominal = GetHistogram(sample.GetInputFile(), sample.GetHistoPath(), sample.GetHistoName(), fileHandles);
1073
1074 sample.SetHisto(Nominal);
1075
1076 // Get the StatError Histogram (if necessary)
1077 if (sample.GetStatError().GetUseHisto()) {
1078 sample.GetStatError().SetErrorHist(GetHistogram(sample.GetStatError().GetInputFile(),
1079 sample.GetStatError().GetHistoPath(),
1080 sample.GetStatError().GetHistoName(), fileHandles));
1081 }
1082
1083 // Get the HistoSys Variations:
1084 for (HistoSys &histoSys : sample.GetHistoSysList()) {
1085 histoSys.SetHistoLow(GetHistogram(histoSys.GetInputFileLow(), histoSys.GetHistoPathLow(),
1086 histoSys.GetHistoNameLow(), fileHandles));
1087
1088 histoSys.SetHistoHigh(GetHistogram(histoSys.GetInputFileHigh(), histoSys.GetHistoPathHigh(),
1089 histoSys.GetHistoNameHigh(), fileHandles));
1090 } // End Loop over HistoSys
1091
1092 // Get the HistoFactor Variations:
1093 for (HistoFactor &histoFactor : sample.GetHistoFactorList()) {
1094 histoFactor.SetHistoLow(GetHistogram(histoFactor.GetInputFileLow(), histoFactor.GetHistoPathLow(),
1095 histoFactor.GetHistoNameLow(), fileHandles));
1096
1097 histoFactor.SetHistoHigh(GetHistogram(histoFactor.GetInputFileHigh(), histoFactor.GetHistoPathHigh(),
1098 histoFactor.GetHistoNameHigh(), fileHandles));
1099 } // End Loop over HistoFactor
1100
1101 // Get the ShapeSys Variations:
1102 for (ShapeSys &shapeSys : sample.GetShapeSysList()) {
1103 shapeSys.SetErrorHist(
1104 GetHistogram(shapeSys.GetInputFile(), shapeSys.GetHistoPath(), shapeSys.GetHistoName(), fileHandles));
1105 } // End Loop over ShapeSys
1106
1107 // Get any initial shape for a ShapeFactor
1108 for (ShapeFactor &shapeFactor : sample.GetShapeFactorList()) {
1109 // Check if we need an InitialShape
1110 if (shapeFactor.HasInitialShape()) {
1111 TH1 *hist = GetHistogram(shapeFactor.GetInputFile(), shapeFactor.GetHistoPath(), shapeFactor.GetHistoName(),
1112 fileHandles);
1113 shapeFactor.SetInitialShape(hist);
1114 }
1115
1116 } // End Loop over ShapeFactor
1117
1118 } // End Loop over Samples
1119}
1120
1122{
1123
1124 // Check that all internal histogram pointers
1125 // are properly configured (ie that they're not nullptr)
1126
1127 if (fData.GetHisto() == nullptr && !fData.GetInputFile().empty()) {
1128 cxcoutEHF << "Error: Data Histogram for channel " << GetName() << " is nullptr." << std::endl;
1129 return false;
1130 }
1131
1132 // Get the histograms for the samples:
1133 for (Sample const &sample : fSamples) {
1134 // Get the nominal histogram:
1135 if (sample.GetHisto() == nullptr) {
1136 cxcoutEHF << "Error: Nominal Histogram for sample " << sample.GetName() << " is nullptr." << std::endl;
1137 return false;
1138 } else {
1139
1140 // Check if any bins are negative
1141 std::vector<int> NegativeBinNumber;
1142 std::vector<double> NegativeBinContent;
1143 const TH1 *histNominal = sample.GetHisto();
1144 for (int ibin = 1; ibin <= histNominal->GetNbinsX(); ++ibin) {
1145 if (histNominal->GetBinContent(ibin) < 0) {
1146 NegativeBinNumber.push_back(ibin);
1147 NegativeBinContent.push_back(histNominal->GetBinContent(ibin));
1148 }
1149 }
1150 if (!NegativeBinNumber.empty()) {
1151 cxcoutWHF << "WARNING: Nominal Histogram " << histNominal->GetName() << " for Sample = " << sample.GetName()
1152 << " in Channel = " << GetName() << " has negative entries in bin numbers = ";
1153
1154 for (unsigned int ibin = 0; ibin < NegativeBinNumber.size(); ++ibin) {
1155 if (ibin > 0)
1156 std::cout << " , ";
1157 std::cout << NegativeBinNumber[ibin] << " : " << NegativeBinContent[ibin];
1158 }
1159 std::cout << std::endl;
1160 }
1161 }
1162
1163 // Get the StatError Histogram (if necessary)
1164 if (sample.GetStatError().GetUseHisto()) {
1165 if (sample.GetStatError().GetErrorHist() == nullptr) {
1166 cxcoutEHF << "Error: Statistical Error Histogram for sample " << sample.GetName() << " is nullptr."
1167 << std::endl;
1168 return false;
1169 }
1170 }
1171
1172 // Get the HistoSys Variations:
1173 for (const HistoSys &histoSys : sample.GetHistoSysList()) {
1174
1175 if (histoSys.GetHistoLow() == nullptr) {
1176 cxcoutEHF << "Error: HistoSyst Low for Systematic " << histoSys.GetName() << " in sample "
1177 << sample.GetName() << " is nullptr." << std::endl;
1178 return false;
1179 }
1180 if (histoSys.GetHistoHigh() == nullptr) {
1181 cxcoutEHF << "Error: HistoSyst High for Systematic " << histoSys.GetName() << " in sample "
1182 << sample.GetName() << " is nullptr." << std::endl;
1183 return false;
1184 }
1185
1186 } // End Loop over HistoSys
1187
1188 // Get the HistoFactor Variations:
1189 for (const HistoFactor &histoFactor : sample.GetHistoFactorList()) {
1190
1191 if (histoFactor.GetHistoLow() == nullptr) {
1192 cxcoutEHF << "Error: HistoSyst Low for Systematic " << histoFactor.GetName() << " in sample "
1193 << sample.GetName() << " is nullptr." << std::endl;
1194 return false;
1195 }
1196 if (histoFactor.GetHistoHigh() == nullptr) {
1197 cxcoutEHF << "Error: HistoSyst High for Systematic " << histoFactor.GetName() << " in sample "
1198 << sample.GetName() << " is nullptr." << std::endl;
1199 return false;
1200 }
1201
1202 } // End Loop over HistoFactor
1203
1204 // Get the ShapeSys Variations:
1205 for (const ShapeSys &shapeSys : sample.GetShapeSysList()) {
1206 if (shapeSys.GetErrorHist() == nullptr) {
1207 cxcoutEHF << "Error: HistoSyst High for Systematic " << shapeSys.GetName() << " in sample "
1208 << sample.GetName() << " is nullptr." << std::endl;
1209 return false;
1210 }
1211 } // End Loop over ShapeSys
1212
1213 } // End Loop over Samples
1214
1215 return true;
1216}
1217
1218/// Open a file and copy a histogram
1219/// \param InputFile File where the histogram resides.
1220/// \param HistoPath Path of the histogram in the file.
1221/// \param HistoName Name of the histogram to retrieve.
1222/// \param lsof List of open files. Helps to prevent opening and closing a file hundreds of times.
1223TH1 *Channel::GetHistogram(std::string InputFile, std::string HistoPath, std::string HistoName,
1224 std::map<std::string, std::unique_ptr<TFile>> &lsof)
1225{
1226
1227 cxcoutPHF << "Getting histogram " << InputFile << ":" << HistoPath << "/" << HistoName << std::endl;
1228
1229 auto &inFile = lsof[InputFile];
1230 if (!inFile || !inFile->IsOpen()) {
1231 inFile.reset(TFile::Open(InputFile.c_str()));
1232 if (!inFile || !inFile->IsOpen()) {
1233 cxcoutEHF << "Error: Unable to open input file: " << InputFile << std::endl;
1234 throw hf_exc();
1235 }
1236 cxcoutIHF << "Opened input file: " << InputFile << ": " << std::endl;
1237 }
1238
1239 TDirectory *dir = inFile->GetDirectory(HistoPath.c_str());
1240 if (dir == nullptr) {
1241 cxcoutEHF << "Histogram path '" << HistoPath << "' wasn't found in file '" << InputFile << "'." << std::endl;
1242 throw hf_exc();
1243 }
1244
1245 // Have to read histograms via keys, to ensure that the latest-greatest
1246 // name cycle is read from file. Otherwise, they might come from memory.
1247 auto key = dir->GetKey(HistoName.c_str());
1248 if (key == nullptr) {
1249 cxcoutEHF << "Histogram '" << HistoName << "' wasn't found in file '" << InputFile << "' in directory '"
1250 << HistoPath << "'." << std::endl;
1251 throw hf_exc();
1252 }
1253
1254 std::unique_ptr<TH1> hist(key->ReadObject<TH1>());
1255 if (!hist) {
1256 cxcoutEHF << "Histogram '" << HistoName << "' wasn't found in file '" << InputFile << "' in directory '"
1257 << HistoPath << "'." << std::endl;
1258 throw hf_exc();
1259 }
1260
1261 TDirectory::TContext ctx{nullptr};
1262 TH1 *ptr = static_cast<TH1 *>(hist->Clone());
1263
1264 if (!ptr) {
1265 std::cerr << "Not all necessary info are set to access the input file. Check your config" << std::endl;
1266 std::cerr << "filename: " << InputFile << "path: " << HistoPath << "obj: " << HistoName << std::endl;
1267 throw hf_exc();
1268 }
1269
1270#ifdef DEBUG
1271 std::cout << "Found Histogram: " << HistoName " at address: " << ptr << " with integral " << ptr->Integral()
1272 << " and mean " << ptr->GetMean() << std::endl;
1273#endif
1274
1275 // Done
1276 return ptr;
1277}
1278
1279////////////////////////////////////////////////////////////////////////////////
1280/** \class RooStats::HistFactory::Data
1281 * \ingroup HistFactory
1282 */
1283
1284Data::Data(std::string HistoName, std::string InputFile, std::string HistoPath)
1285 : fInputFile(InputFile), fHistoName(HistoName), fHistoPath(HistoPath)
1286{
1287}
1288
1290{
1291 return (TH1 *)fhData.GetObject();
1292}
1293
1294const TH1 *Data::GetHisto() const
1295{
1296 return (TH1 *)fhData.GetObject();
1297}
1298
1299void Data::Print(std::ostream &stream)
1300{
1301
1302 stream << "\t \t InputFile: " << fInputFile << "\t HistoName: " << fHistoName << "\t HistoPath: " << fHistoPath
1303 << "\t HistoAddress: " << GetHisto() << std::endl;
1304}
1305
1306void Data::writeToFile(std::string OutputFileName, std::string DirName)
1307{
1308
1309 TH1 *histData = GetHisto();
1310
1311 if (histData != nullptr) {
1312
1313 histData->Write();
1314
1315 // Set the location of the data
1316 // in the output measurement
1317
1319 fHistoName = histData->GetName();
1320 fHistoPath = DirName;
1321 }
1322}
1323
1324void Data::PrintXML(std::ostream &xml) const
1325{
1326
1327 xml << " <Data HistoName=\"" << GetHistoName() << "\" "
1328 << "InputFile=\"" << GetInputFile() << "\" "
1329 << "HistoPath=\"" << GetHistoPath() << "\" ";
1330 if (!GetName().empty()) {
1331 xml << "Name=\"" << GetName() << "\" ";
1332 }
1333 xml << " /> " << std::endl << std::endl;
1334}
1335
1336////////////////////////////////////////////////////////////////////////////////
1337/**
1338 * \ingroup HistFactory
1339 */
1340
1341namespace {
1342
1343/// Replaces the XML special characters with their escape codes.
1344std::string escapeXML(const std::string &src)
1345{
1346 std::stringstream dst;
1347 for (char ch : src) {
1348 switch (ch) {
1349 case '&': dst << "&amp;"; break;
1350 case '\'': dst << "&apos;"; break;
1351 case '"': dst << "&quot;"; break;
1352 case '<': dst << "&lt;"; break;
1353 case '>': dst << "&gt;"; break;
1354 default: dst << ch; break;
1355 }
1356 }
1357 return dst.str();
1358}
1359
1360} // namespace
1361
1362PreprocessFunction::PreprocessFunction(std::string const &name, std::string const &expression,
1363 std::string const &dependents)
1364 : fName(name), fExpression(expression), fDependents(dependents)
1365{
1366}
1367
1369{
1370 return "expr::" + fName + "('" + fExpression + "',{" + fDependents + "})";
1371}
1372
1373void PreprocessFunction::Print(std::ostream &stream) const
1374{
1375 stream << "\t \t Name: " << fName << "\t \t Expression: " << fExpression << "\t \t Dependents: " << fDependents
1376 << std::endl;
1377}
1378
1379void PreprocessFunction::PrintXML(std::ostream &xml) const
1380{
1381 xml << "<Function Name=\"" << fName << "\" "
1382 << "Expression=\"" << escapeXML(fExpression) << "\" "
1383 << "Dependents=\"" << fDependents << "\" "
1384 << "/>\n";
1385}
1386
1387////////////////////////////////////////////////////////////////////////////////
1388/** \class RooStats::HistFactory::Asimov
1389 * \ingroup HistFactory
1390 * TODO Here, we are missing some documentation.
1391 */
1392
1394{
1395
1396 // Here is where we set the values, and constantness
1397 // of all parameters in the workspace before creating
1398 // an asimov dataset
1399
1400 /*
1401 // Okay, y'all, first we're going to create a snapshot
1402 // of the current state of the variables in the workspace
1403
1404 std::string ListOfVariableNames = "";
1405 for( std::map< std::string, double >::iterator itr = fParamValsToSet.begin();
1406 itr != fParamValsToSet.end(); ++itr) {
1407 // Extend the Variable Name list
1408 ListOfVariableNames += "," + itr->first;
1409 }
1410 for( std::map< std::string, bool >::iterator itr = fParamsToFix.begin();
1411 itr != fParamsToFix.end(); ++itr) {
1412 // Extend the Variable Name list
1413 ListOfVariableNames += "," + itr->first;
1414 }
1415
1416 // Save a snapshot
1417 std::string SnapShotName = "NominalParamValues";
1418 wspace->saveSnapshot(SnapShotName.c_str(), ListOfVariableNames.c_str());
1419 */
1420
1421 //
1422 // First we set all parameters to their given values
1423 //
1424
1425 for (std::map<std::string, double>::iterator itr = fParamValsToSet.begin(); itr != fParamValsToSet.end(); ++itr) {
1426
1427 std::string param = itr->first;
1428 double val = itr->second;
1429
1430 // Try to get the variable in the workspace
1431 RooRealVar *var = wspace->var(param);
1432 if (!var) {
1433 std::cout << "Error: Trying to set variable: " << var
1434 << " to a specific value in creation of asimov dataset: " << fName
1435 << " but this variable doesn't appear to exist in the workspace" << std::endl;
1436 throw hf_exc();
1437 }
1438
1439 // Check that the desired value is in the range of the variable
1440 double inRange = var->inRange(val, nullptr);
1441 if (!inRange) {
1442 std::cout << "Error: Attempting to set variable: " << var << " to value: " << val << ", however it appears"
1443 << " that this is not withn the variable's range: "
1444 << "[" << var->getMin() << ", " << var->getMax() << "]" << std::endl;
1445 throw hf_exc();
1446 }
1447
1448 // Set its value
1449 std::cout << "Configuring Asimov Dataset: Setting " << param << " = " << val << std::endl;
1450 var->setVal(val);
1451 }
1452
1453 //
1454 // Then, we set any variables to constant
1455 //
1456
1457 for (auto &[param, isConstant] : fParamsToFix) {
1458
1459 // Try to get the variable in the workspace
1460 RooRealVar *var = wspace->var(param);
1461 if (!var) {
1462 std::cout << "Error: Trying to set variable: " << var << " constant in creation of asimov dataset: " << fName
1463 << " but this variable doesn't appear to exist in the workspace" << std::endl;
1464 throw hf_exc();
1465 }
1466
1467 std::cout << "Configuring Asimov Dataset: Setting " << param << " to constant " << std::endl;
1468 var->setConstant(isConstant);
1469 }
1470}
1471
1472/** \class RooStats::HistFactory::HistRef
1473 * \ingroup HistFactory
1474 * Internal class wrapping an histogram and managing its content.
1475 * convenient for dealing with histogram pointers in the
1476 * HistFactory class
1477 */
1478
1479/// constructor - use gives away ownerhip of the given pointer
1481
1483{
1484 if (other.fHist)
1485 fHist.reset(CopyObject(other.fHist.get()));
1486}
1487
1488HistRef::HistRef(HistRef &&other) : fHist(std::move(other.fHist)) {}
1489
1490HistRef::~HistRef() = default;
1491
1492/// assignment operator (delete previous contained histogram)
1494{
1495 if (this == &other)
1496 return *this;
1497
1498 fHist.reset(CopyObject(other.fHist.get()));
1499 return *this;
1500}
1501
1503{
1504 fHist = std::move(other.fHist);
1505 return *this;
1506}
1507
1509{
1510 // implementation of method copying the contained pointer
1511 // (just use Clone)
1512 if (!h)
1513 return nullptr;
1514
1515 TDirectory::TContext ctx{nullptr}; // Don't associate histogram with currently open file
1516 return static_cast<TH1 *>(h->Clone());
1517}
1518
1520{
1521 return fHist.get();
1522}
1523
1524/// set the object - user gives away the ownerhisp
1526{
1527 fHist.reset(h);
1528}
1529
1530/// operator= passing an object pointer : user gives away its ownerhisp
1532{
1533 SetObject(h);
1534}
1535
1536/// Release ownership of object.
1538{
1539 return fHist.release();
1540}
1541
1542// Constraints
1544{
1545
1547 return "Gaussian";
1549 return "Poisson";
1550 return "";
1551}
1552
1554{
1555
1556 if (Name.empty()) {
1557 std::cout << "Error: Given empty name for ConstraintType" << std::endl;
1558 throw hf_exc();
1559 }
1560
1561 else if (Name == "Gaussian" || Name == "Gauss") {
1562 return Constraint::Gaussian;
1563 }
1564
1565 else if (Name == "Poisson" || Name == "Pois") {
1566 return Constraint::Poisson;
1567 }
1568
1569 else {
1570 std::cout << "Error: Unknown name given for Constraint Type: " << Name << std::endl;
1571 throw hf_exc();
1572 }
1573}
1574
1575void NormFactor::Print(std::ostream &stream) const
1576{
1577 stream << "\t \t Name: " << fName << "\t Val: " << fVal << "\t Low: " << fLow << "\t High: " << fHigh << std::endl;
1578}
1579
1580void NormFactor::PrintXML(std::ostream &xml) const
1581{
1582 xml << " <NormFactor Name=\"" << GetName() << "\" "
1583 << " Val=\"" << GetVal() << "\" "
1584 << " High=\"" << GetHigh() << "\" "
1585 << " Low=\"" << GetLow() << "\" "
1586 << " /> " << std::endl;
1587}
1588
1589void OverallSys::Print(std::ostream &stream) const
1590{
1591 stream << "\t \t Name: " << fName << "\t Low: " << fLow << "\t High: " << fHigh << std::endl;
1592}
1593
1594void OverallSys::PrintXML(std::ostream &xml) const
1595{
1596 xml << " <OverallSys Name=\"" << GetName() << "\" "
1597 << " High=\"" << GetHigh() << "\" "
1598 << " Low=\"" << GetLow() << "\" "
1599 << " /> " << std::endl;
1600}
1601
1603
1605 : fName(Name), fhLow(nullptr), fhHigh(nullptr)
1606{
1607}
1608
1610
1612
1614
1615void HistogramUncertaintyBase::Print(std::ostream &stream) const
1616{
1617 stream << "\t \t Name: " << fName << "\t HistoFileLow: " << fInputFileLow << "\t HistoNameLow: " << fHistoNameLow
1618 << "\t HistoPathLow: " << fHistoPathLow << "\t HistoFileHigh: " << fInputFileHigh
1619 << "\t HistoNameHigh: " << fHistoNameHigh << "\t HistoPathHigh: " << fHistoPathHigh << std::endl;
1620}
1621
1622void HistogramUncertaintyBase::writeToFile(const std::string &FileName, const std::string &DirName)
1623{
1624
1625 // This saves the histograms to a file and
1626 // changes the name of the local file and histograms
1627
1628 auto histLow = GetHistoLow();
1629 if (histLow == nullptr) {
1630 std::cout << "Error: Cannot write " << GetName() << " to file: " << FileName << " HistoLow is nullptr"
1631 << std::endl;
1632 throw hf_exc();
1633 }
1634 histLow->Write();
1635 fInputFileLow = FileName;
1636 fHistoPathLow = DirName;
1637 fHistoNameLow = histLow->GetName();
1638
1639 auto histHigh = GetHistoHigh();
1640 if (histHigh == nullptr) {
1641 std::cout << "Error: Cannot write " << GetName() << " to file: " << FileName << " HistoHigh is nullptr"
1642 << std::endl;
1643 throw hf_exc();
1644 }
1645 histHigh->Write();
1646 fInputFileHigh = FileName;
1647 fHistoPathHigh = DirName;
1648 fHistoNameHigh = histHigh->GetName();
1649}
1650
1651void HistoSys::PrintXML(std::ostream &xml) const
1652{
1653 xml << " <HistoSys Name=\"" << GetName() << "\" "
1654 << " HistoFileLow=\"" << GetInputFileLow() << "\" "
1655 << " HistoNameLow=\"" << GetHistoNameLow() << "\" "
1656 << " HistoPathLow=\"" << GetHistoPathLow() << "\" "
1657
1658 << " HistoFileHigh=\"" << GetInputFileHigh() << "\" "
1659 << " HistoNameHigh=\"" << GetHistoNameHigh() << "\" "
1660 << " HistoPathHigh=\"" << GetHistoPathHigh() << "\" "
1661 << " /> " << std::endl;
1662}
1663
1665{
1666 fhHigh.reset(hError);
1667}
1668
1669void ShapeSys::Print(std::ostream &stream) const
1670{
1671 stream << "\t \t Name: " << fName << "\t InputFile: " << fInputFileHigh << "\t HistoName: " << fHistoNameHigh
1672 << "\t HistoPath: " << fHistoPathHigh << std::endl;
1673}
1674
1675void ShapeSys::PrintXML(std::ostream &xml) const
1676{
1677 xml << " <ShapeSys Name=\"" << GetName() << "\" "
1678 << " InputFile=\"" << GetInputFile() << "\" "
1679 << " HistoName=\"" << GetHistoName() << "\" "
1680 << " HistoPath=\"" << GetHistoPath() << "\" "
1681 << " ConstraintType=\"" << std::string(Constraint::Name(GetConstraintType())) << "\" "
1682 << " /> " << std::endl;
1683}
1684
1685void ShapeSys::writeToFile(const std::string &FileName, const std::string &DirName)
1686{
1687 auto histError = GetErrorHist();
1688 if (histError == nullptr) {
1689 std::cout << "Error: Cannot write " << GetName() << " to file: " << FileName << " ErrorHist is nullptr"
1690 << std::endl;
1691 throw hf_exc();
1692 }
1693 histError->Write();
1694 fInputFileHigh = FileName;
1695 fHistoPathHigh = DirName;
1696 fHistoNameHigh = histError->GetName();
1697}
1698
1699void HistoFactor::PrintXML(std::ostream &xml) const
1700{
1701 xml << " <HistoFactor Name=\"" << GetName() << "\" "
1702
1703 << " InputFileLow=\"" << GetInputFileLow() << "\" "
1704 << " HistoNameLow=\"" << GetHistoNameLow() << "\" "
1705 << " HistoPathLow=\"" << GetHistoPathLow() << "\" "
1706
1707 << " InputFileHigh=\"" << GetInputFileHigh() << "\" "
1708 << " HistoNameHigh=\"" << GetHistoNameHigh() << "\" "
1709 << " HistoPathHigh=\"" << GetHistoPathHigh() << "\" "
1710 << " /> " << std::endl;
1711}
1712
1714{
1715 fhHigh.reset(shape);
1716}
1717
1718void ShapeFactor::Print(std::ostream &stream) const
1719{
1720
1721 stream << "\t \t Name: " << fName << std::endl;
1722
1723 if (!fHistoNameHigh.empty()) {
1724 stream << "\t \t "
1725 << " Shape Hist Name: " << fHistoNameHigh << " Shape Hist Path Name: " << fHistoPathHigh
1726 << " Shape Hist FileName: " << fInputFileHigh << std::endl;
1727 }
1728
1729 if (fConstant) {
1730 stream << "\t \t ( Constant ): " << std::endl;
1731 }
1732}
1733
1734void ShapeFactor::writeToFile(const std::string &FileName, const std::string &DirName)
1735{
1736
1737 if (HasInitialShape()) {
1739 if (histInitialShape == nullptr) {
1740 std::cout << "Error: Cannot write " << GetName() << " to file: " << FileName << " InitialShape is nullptr"
1741 << std::endl;
1742 throw hf_exc();
1743 }
1744 histInitialShape->Write();
1745 fInputFileHigh = FileName;
1746 fHistoPathHigh = DirName;
1747 fHistoNameHigh = histInitialShape->GetName();
1748 }
1749}
1750
1751void ShapeFactor::PrintXML(std::ostream &xml) const
1752{
1753 xml << " <ShapeFactor Name=\"" << GetName() << "\" ";
1754 if (fHasInitialShape) {
1755 xml << " InputFile=\"" << GetInputFile() << "\" "
1756 << " HistoName=\"" << GetHistoName() << "\" "
1757 << " HistoPath=\"" << GetHistoPath() << "\" ";
1758 }
1759 xml << " /> " << std::endl;
1760}
1761
1763{
1764 fhHigh.reset(Error);
1765}
1766
1767void StatErrorConfig::Print(std::ostream &stream) const
1768{
1769 stream << "\t \t RelErrorThreshold: " << fRelErrorThreshold
1770 << "\t ConstraintType: " << Constraint::Name(fConstraintType) << std::endl;
1771}
1772
1773void StatErrorConfig::PrintXML(std::ostream &xml) const
1774{
1775 xml << " <StatErrorConfig RelErrorThreshold=\"" << GetRelErrorThreshold() << "\" "
1776 << "ConstraintType=\"" << Constraint::Name(GetConstraintType()) << "\" "
1777 << "/> " << std::endl
1778 << std::endl;
1779}
1780
1781void StatError::Print(std::ostream &stream) const
1782{
1783 stream << "\t \t Activate: " << fActivate << "\t InputFile: " << fInputFileHigh << "\t HistoName: " << fHistoNameHigh
1784 << "\t histoPath: " << fHistoPathHigh << std::endl;
1785}
1786
1787void StatError::PrintXML(std::ostream &xml) const
1788{
1789
1790 if (GetActivate()) {
1791 xml << " <StatError Activate=\"" << (GetActivate() ? std::string("True") : std::string("False")) << "\" "
1792 << " InputFile=\"" << GetInputFile() << "\" "
1793 << " HistoName=\"" << GetHistoName() << "\" "
1794 << " HistoPath=\"" << GetHistoPath() << "\" "
1795 << " /> " << std::endl;
1796 }
1797}
1798
1799void StatError::writeToFile(const std::string &OutputFileName, const std::string &DirName)
1800{
1801
1802 if (fUseHisto) {
1803
1804 std::string statErrorHistName = "statisticalErrors";
1805
1806 auto hStatError = GetErrorHist();
1807 if (hStatError == nullptr) {
1808 std::cout << "Error: Stat Error error hist is nullptr" << std::endl;
1809 throw hf_exc();
1810 }
1811 hStatError->Write(statErrorHistName.c_str());
1812
1815 fHistoPathHigh = DirName;
1816 }
1817}
1818
1820 : fName{oth.fName},
1821 fInputFileLow{oth.fInputFileLow},
1822 fHistoNameLow{oth.fHistoNameLow},
1823 fHistoPathLow{oth.fHistoPathLow},
1824 fInputFileHigh{oth.fInputFileHigh},
1825 fHistoNameHigh{oth.fHistoNameHigh},
1826 fHistoPathHigh{oth.fHistoPathHigh},
1827 fhLow{oth.fhLow ? static_cast<TH1 *>(oth.fhLow->Clone()) : nullptr},
1828 fhHigh{oth.fhHigh ? static_cast<TH1 *>(oth.fhHigh->Clone()) : nullptr}
1829{
1830 if (fhLow)
1831 fhLow->SetDirectory(nullptr);
1832 if (fhHigh)
1833 fhHigh->SetDirectory(nullptr);
1834}
1835
1837{
1838 fName = oth.fName;
1839 fInputFileLow = oth.fInputFileLow;
1840 fHistoNameLow = oth.fHistoNameLow;
1841 fHistoPathLow = oth.fHistoPathLow;
1842 fInputFileHigh = oth.fInputFileHigh;
1843 fHistoNameHigh = oth.fHistoNameHigh;
1844 fHistoPathHigh = oth.fHistoPathHigh;
1845
1846 TDirectory::TContext ctx{nullptr}; // Don't associate clones to directories
1847 fhLow.reset(oth.fhLow ? static_cast<TH1 *>(oth.fhLow->Clone()) : nullptr);
1848 fhHigh.reset(oth.fhHigh ? static_cast<TH1 *>(oth.fhHigh->Clone()) : nullptr);
1849
1850 return *this;
1851}
1852
1854{
1855 Low->SetDirectory(nullptr);
1856 fhLow.reset(Low);
1857}
1858
1860{
1861 High->SetDirectory(nullptr);
1862 fhHigh.reset(High);
1863}
1864
1866{
1867 fhData = Hist;
1868 fHistoName = Hist->GetName();
1869}
1870
1872{
1873 fhNominal = histo;
1874 fHistoName = histo->GetName();
1875}
1876
1877} // namespace RooStats::HistFactory
#define cxcoutPHF
#define cxcoutDHF
#define cxcoutIHF
#define cxcoutWHF
#define cxcoutEHF
#define h(i)
Definition RSha256.hxx:106
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
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
char name[80]
Definition TGX11.cxx:110
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
void setConstant(bool value=true)
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
bool inRange(const char *name) const override
Check if current value is inside range with given name.
Variable that can be changed from the outside.
Definition RooRealVar.h:37
void setVal(double value) override
Set value of variable to 'value'.
std::map< std::string, double > fParamValsToSet
void ConfigureWorkspace(RooWorkspace *)
std::map< std::string, bool > fParamsToFix
This class encapsulates all information for the statistical interpretation of one experiment.
std::vector< RooStats::HistFactory::Sample > fSamples
std::vector< RooStats::HistFactory::Data > fAdditionalData
One can add additional datasets These are simply added to the xml under a different name.
void Print(std::ostream &=std::cout)
HistFactory::StatErrorConfig fStatErrorConfig
void SetData(const RooStats::HistFactory::Data &data)
set data object
void AddSample(RooStats::HistFactory::Sample sample)
TH1 * GetHistogram(std::string InputFile, std::string HistoPath, std::string HistoName, std::map< std::string, std::unique_ptr< TFile > > &lsof)
Open a file and copy a histogram.
void SetStatErrorConfig(double RelErrorThreshold, Constraint::Type ConstraintType)
void PrintXML(std::string const &directory, std::string const &prefix="") const
std::string GetName() const
get name of channel
void Print(std::ostream &=std::cout)
std::string const & GetInputFile() const
void PrintXML(std::ostream &) const
void SetInputFile(const std::string &InputFile)
void SetHistoPath(const std::string &HistoPath)
void writeToFile(std::string FileName, std::string DirName)
std::string const & GetHistoName() const
void SetHistoName(const std::string &HistoName)
std::string const & GetHistoPath() const
std::string const & GetName() const
Internal class wrapping an histogram and managing its content.
HistRef(TH1 *h=nullptr)
constructor - use gives away ownerhip of the given pointer
HistRef & operator=(const HistRef &other)
assignment operator (delete previous contained histogram)
void SetObject(TH1 *h)
set the object - user gives away the ownerhisp
std::unique_ptr< TH1 > fHist
pointer to contained histogram
static TH1 * CopyObject(const TH1 *h)
TH1 * ReleaseObject()
Release ownership of object.
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 Measurement.h:99
void SetInputFileHigh(const std::string &InputFileHigh)
virtual void writeToFile(const std::string &FileName, const std::string &DirName)
void SetHistoPathHigh(const std::string &HistoPathHigh)
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
void SetHistoPathLow(const std::string &HistoPathLow)
const std::string & GetHistoPathHigh() const
The RooStats::HistFactory::Measurement class can be used to construct a model by combining multiple R...
void writeToFile(TFile *file)
A measurement, once fully configured, can be saved into a ROOT file.
std::map< std::string, double > fUniformSyst
std::string fOutputFilePrefix
Configurables of this measurement.
void AddGammaSyst(std::string syst, double uncert)
Set constraint term for given systematic to Gamma distribution.
std::string GetDirPath(TDirectory *dir)
Return the directory's path, stripped of unnecessary prefixes.
std::map< std::string, double > fNoSyst
std::vector< RooStats::HistFactory::Channel > fChannels
Channels that make up this measurement.
void AddLogNormSyst(std::string syst, double uncert)
Set constraint term for given systematic to LogNormal distribution.
void PrintXML(std::string Directory="", std::string NewOutputPrefix="")
Print to a stream.
void SetParamValue(const std::string &param, double value)
Set a parameter to a specific value (And optionally fix it)
std::map< std::string, double > fGammaSyst
List of Alternate constraint terms.
std::map< std::string, double > fParamValues
Map of parameter names to initial values to be set.
void CollectHistograms()
The most common way to add histograms to channels is to have them stored in ROOT files and to give Hi...
std::vector< RooStats::HistFactory::PreprocessFunction > fFunctionObjects
List of Preprocess Function objects.
RooStats::HistFactory::Channel & GetChannel(std::string)
Get channel with given name from this measurement throws an exception in case the channel is not foun...
bool HasChannel(std::string)
Check if the given channel is part of this measurement.
void AddUniformSyst(std::string syst)
Set constraint term for given systematic to uniform distribution.
void PrintTree(std::ostream &=std::cout)
Print information about measurement object in tree-like structure to given stream.
void AddNoSyst(std::string syst)
Define given systematics to have no external constraint.
void AddConstantParam(const std::string &param)
Add a parameter to be set as constant (Similar to ParamSetting method below)
void AddFunctionObject(const RooStats::HistFactory::PreprocessFunction function)
add a preprocess function object
void AddPreprocessFunction(std::string name, std::string expression, std::string dependencies)
Add a preprocessed function by giving the function a name, a functional expression,...
std::vector< std::string > GetPreprocessFunctions() const
Returns a list of defined preprocess function expressions.
std::map< std::string, double > fLogNormSyst
std::vector< std::string > fPOI
std::vector< std::string > fConstantParams
List of Parameters to be set constant.
Configuration for an un- constrained overall systematic to scale sample normalisations.
Definition Measurement.h:69
void Print(std::ostream &=std::cout) const
void PrintXML(std::ostream &) const
Configuration for a constrained overall systematic to scale sample normalisations.
Definition Measurement.h:45
void SetName(const std::string &Name)
Definition Measurement.h:48
const std::string & GetName() const
Definition Measurement.h:49
void PrintXML(std::ostream &) const
void Print(std::ostream &=std::cout) const
void Print(std::ostream &=std::cout) const
std::vector< RooStats::HistFactory::ShapeFactor > fShapeFactorList
std::unique_ptr< TH1 > fhCountingHist
void AddShapeSys(std::string Name, Constraint::Type ConstraintType, std::string HistoName, std::string HistoFile, std::string HistoPath="")
void AddOverallSys(std::string Name, double Low, double High)
void writeToFile(std::string FileName, std::string DirName)
const TH1 * GetHisto() const
RooStats::HistFactory::StatError fStatError
Properties.
std::vector< RooStats::HistFactory::NormFactor > fNormFactorList
void AddNormFactor(std::string const &Name, double Val, double Low, double High)
Sample & operator=(const Sample &other)
std::string fChannelName
The Name of the parent channel.
std::vector< RooStats::HistFactory::OverallSys > fOverallSysList
void Print(std::ostream &=std::cout) const
std::vector< RooStats::HistFactory::HistoSys > fHistoSysList
RooStats::HistFactory::StatError & GetStatError()
void AddHistoFactor(std::string Name, std::string HistoNameLow, std::string HistoFileLow, std::string HistoPathLow, std::string HistoNameHigh, std::string HistoFileHigh, std::string HistoPathHigh)
std::vector< RooStats::HistFactory::ShapeFactor > & GetShapeFactorList()
std::vector< RooStats::HistFactory::HistoFactor > & GetHistoFactorList()
std::vector< RooStats::HistFactory::HistoSys > & GetHistoSysList()
std::vector< RooStats::HistFactory::HistoFactor > fHistoFactorList
std::vector< RooStats::HistFactory::ShapeSys > fShapeSysList
HistRef fhNominal
The Nominal Shape.
void AddShapeFactor(std::string Name)
std::vector< RooStats::HistFactory::ShapeSys > & GetShapeSysList()
void AddHistoSys(std::string Name, std::string HistoNameLow, std::string HistoFileLow, std::string HistoPathLow, std::string HistoNameHigh, std::string HistoFileHigh, std::string HistoPathHigh)
void PrintXML(std::ofstream &xml) 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 writeToFile(const std::string &FileName, const std::string &DirName) override
void Print(std::ostream &=std::cout) const override
const std::string & GetInputFile() const
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
void writeToFile(const std::string &FileName, const std::string &DirName) override
void Print(std::ostream &=std::cout) const override
std::string GetInputFile() const
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
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
Persistable container for RooFit projects.
RooRealVar * var(RooStringView name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found.
Bool_t cd() override
Change current directory to "this" directory.
TDirectory * mkdir(const char *name, const char *title="", Bool_t returnExistingDirectory=kFALSE) override
Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".
TDirectory::TContext keeps track and restore the current directory.
Definition TDirectory.h:89
Describe directory structure in memory.
Definition TDirectory.h:45
virtual const char * GetPath() const
Returns the full path of the directory.
virtual TKey * GetKey(const char *, Short_t=9999) const
Definition TDirectory.h:222
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:131
virtual void Flush()
Synchronize a file's in-memory and on-disk states.
Definition TFile.cxx:1130
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:3764
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:878
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:109
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:8989
virtual Double_t GetMean(Int_t axis=1) const
For axis = 1,2 or 3 returns the mean value of the histogram along X,Y or Z axis.
Definition TH1.cxx:7582
virtual Double_t Integral(Option_t *option="") const
Return integral of bin contents.
Definition TH1.cxx:7993
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition TSystem.cxx:855
virtual void * OpenDirectory(const char *name)
Open a directory.
Definition TSystem.cxx:846
virtual int MakeDirectory(const char *name)
Make a directory.
Definition TSystem.cxx:836
The TTimeStamp encapsulates seconds and ns since EPOCH.
Definition TTimeStamp.h:45
UInt_t GetDate(Bool_t inUTC=kTRUE, Int_t secOffset=0, UInt_t *year=nullptr, UInt_t *month=nullptr, UInt_t *day=nullptr) const
Return date in form of 19971224 (i.e.
Type GetType(const std::string &Name)