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 fShapeFactorList.emplace_back();
864 fShapeFactorList.back().SetName(SysName);
865}
866
867void Sample::AddShapeFactor(std::string SysName, double Val, double Low, double High)
868{
869
870 fShapeFactorList.emplace_back();
871 fShapeFactorList.back().SetName(SysName);
872 fShapeFactorList.back().SetVal(Val);
873 fShapeFactorList.back().SetLow(Low);
874 fShapeFactorList.back().SetHigh(High);
875}
876
878{
879 fShapeFactorList.push_back(Factor);
880}
881
883 std::string SysHistoFile, std::string SysHistoPath)
884{
885
886 ShapeSys sys;
887 sys.SetName(SysName);
888 sys.SetConstraintType(SysConstraintType);
889
890 sys.SetHistoName(SysHistoName);
891 sys.SetHistoPath(SysHistoPath);
892 sys.SetInputFile(SysHistoFile);
893
894 fShapeSysList.push_back(sys);
895}
896
898{
899 fShapeSysList.push_back(Sys);
900}
901
902////////////////////////////////////////////////////////////////////////////////
903/** \class RooStats::HistFactory::Channel
904 * \ingroup HistFactory
905 This class encapsulates all information for the statistical interpretation of one experiment.
906 It can be combined with other channels (e.g. for the combination of multiple experiments, or
907 to constrain nuisance parameters with information obtained in a control region).
908 A channel contains one or more samples which describe the contribution from different processes
909 to this measurement.
910*/
911
912Channel::Channel(std::string ChanName, std::string ChanInputFile) : fName(ChanName), fInputFile(ChanInputFile)
913{
914 // create channel with given name and input file
915}
916
917// BadChannel = Channel();
919// BadChannel.Name = "BadChannel"; // = Channel(); //.Name = "BadChannel";
920
922{
923 // add fully configured sample to channel
924
925 sample.SetChannelName(GetName());
926 fSamples.push_back(sample);
927}
928
929void Channel::Print(std::ostream &stream)
930{
931 // print information of channel to given stream
932
933 stream << "\t Channel Name: " << fName << "\t InputFile: " << fInputFile << std::endl;
934
935 stream << "\t Data:" << std::endl;
936 fData.Print(stream);
937
938 stream << "\t statErrorConfig:" << std::endl;
939 fStatErrorConfig.Print(stream);
940
941 if (!fSamples.empty()) {
942
943 stream << "\t Samples: " << std::endl;
944 for (unsigned int i = 0; i < fSamples.size(); ++i) {
945 fSamples.at(i).Print(stream);
946 }
947 }
948
949 stream << "\t End of Channel " << fName << std::endl;
950}
951
952void Channel::PrintXML(std::string const &directory, std::string const &prefix) const
953{
954
955 // Create an XML file for this channel
956 cxcoutPHF << "Printing XML Files for channel: " << GetName() << std::endl;
957
958 std::string XMLName = prefix + fName + ".xml";
959 if (!directory.empty())
960 XMLName = directory + "/" + XMLName;
961
962 std::ofstream xml(XMLName.c_str());
963
964 // Add the time
965 xml << "<!--" << std::endl;
966 xml << "This xml file created automatically on: " << std::endl;
967 // LM: use TTimeStamp since time_t does not work on Windows
968 TTimeStamp t;
969 UInt_t year = 0;
970 UInt_t month = 0;
971 UInt_t day = 0;
972 t.GetDate(true, 0, &year, &month, &day);
973 xml << year << '-' << month << '-' << day << std::endl;
974 xml << "-->" << std::endl;
975
976 // Add the DOCTYPE
977 xml << "<!DOCTYPE Channel SYSTEM 'HistFactorySchema.dtd'> " << std::endl << std::endl;
978
979 // Add the Channel
980 xml << " <Channel Name=\"" << fName << "\" InputFile=\"" << fInputFile << "\" >" << std::endl << std::endl;
981
983 for (auto const &data : fAdditionalData) {
984 data.PrintXML(xml);
985 }
986
988 /*
989 xml << " <StatErrorConfig RelErrorThreshold=\"" << fStatErrorConfig.GetRelErrorThreshold() << "\" "
990 << "ConstraintType=\"" << Constraint::Name( fStatErrorConfig.GetConstraintType() ) << "\" "
991 << "/> " << std::endl << std::endl;
992 */
993
994 for (auto const &sample : fSamples) {
995 sample.PrintXML(xml);
996 xml << std::endl << std::endl;
997 }
998
999 xml << std::endl;
1000 xml << " </Channel> " << std::endl;
1001 xml.close();
1002
1003 cxcoutPHF << "Finished printing XML files" << std::endl;
1004}
1005
1006void Channel::SetData(std::string DataHistoName, std::string DataInputFile, std::string DataHistoPath)
1007{
1008 // set data for this channel by specifying the name of the histogram,
1009 // the external ROOT file and the path to the histogram inside the ROOT file
1010
1014}
1015
1017{
1018 // set data directly to some histogram
1020}
1021
1022void Channel::SetData(double val)
1023{
1024
1025 // For a NumberCounting measurement only
1026 // Set the value of data in a particular channel
1027 //
1028 // Internally, this simply creates a 1-bin TH1F for you
1029
1030 std::string DataHistName = fName + "_data";
1031
1032 // Histogram has 1-bin (hard-coded)
1033 TH1F *hData = new TH1F(DataHistName.c_str(), DataHistName.c_str(), 1, 0, 1);
1034 hData->SetBinContent(1, val);
1035
1036 // Set the histogram of the internally held data
1037 // node of this channel to this newly created histogram
1038 SetData(hData);
1039}
1040
1047
1054
1056{
1057
1058 // Loop through all Samples and Systematics
1059 // and collect all necessary histograms
1060
1061 // Handles to open files for collecting histograms
1062 std::map<std::string, std::unique_ptr<TFile>> fileHandles;
1063
1064 // Get the Data Histogram:
1065
1066 if (!fData.GetInputFile().empty()) {
1068 }
1069
1070 // Collect any histograms for additional Datasets
1071 for (auto &data : fAdditionalData) {
1072 if (!data.GetInputFile().empty()) {
1073 data.SetHisto(GetHistogram(data.GetInputFile(), data.GetHistoPath(), data.GetHistoName(), fileHandles));
1074 }
1075 }
1076
1077 // Get the histograms for the samples:
1078 for (Sample &sample : fSamples) {
1079 // Get the nominal histogram:
1080 cxcoutDHF << "Collecting Nominal Histogram" << std::endl;
1081 TH1 *Nominal = GetHistogram(sample.GetInputFile(), sample.GetHistoPath(), sample.GetHistoName(), fileHandles);
1082
1083 sample.SetHisto(Nominal);
1084
1085 // Get the StatError Histogram (if necessary)
1086 if (sample.GetStatError().GetUseHisto()) {
1087 sample.GetStatError().SetErrorHist(GetHistogram(sample.GetStatError().GetInputFile(),
1088 sample.GetStatError().GetHistoPath(),
1089 sample.GetStatError().GetHistoName(), fileHandles));
1090 }
1091
1092 // Get the HistoSys Variations:
1093 for (HistoSys &histoSys : sample.GetHistoSysList()) {
1094 histoSys.SetHistoLow(GetHistogram(histoSys.GetInputFileLow(), histoSys.GetHistoPathLow(),
1095 histoSys.GetHistoNameLow(), fileHandles));
1096
1097 histoSys.SetHistoHigh(GetHistogram(histoSys.GetInputFileHigh(), histoSys.GetHistoPathHigh(),
1098 histoSys.GetHistoNameHigh(), fileHandles));
1099 } // End Loop over HistoSys
1100
1101 // Get the HistoFactor Variations:
1102 for (HistoFactor &histoFactor : sample.GetHistoFactorList()) {
1103 histoFactor.SetHistoLow(GetHistogram(histoFactor.GetInputFileLow(), histoFactor.GetHistoPathLow(),
1104 histoFactor.GetHistoNameLow(), fileHandles));
1105
1106 histoFactor.SetHistoHigh(GetHistogram(histoFactor.GetInputFileHigh(), histoFactor.GetHistoPathHigh(),
1107 histoFactor.GetHistoNameHigh(), fileHandles));
1108 } // End Loop over HistoFactor
1109
1110 // Get the ShapeSys Variations:
1111 for (ShapeSys &shapeSys : sample.GetShapeSysList()) {
1112 shapeSys.SetErrorHist(
1113 GetHistogram(shapeSys.GetInputFile(), shapeSys.GetHistoPath(), shapeSys.GetHistoName(), fileHandles));
1114 } // End Loop over ShapeSys
1115
1116 // Get any initial shape for a ShapeFactor
1117 for (ShapeFactor &shapeFactor : sample.GetShapeFactorList()) {
1118 // Check if we need an InitialShape
1119 if (shapeFactor.HasInitialShape()) {
1120 TH1 *hist = GetHistogram(shapeFactor.GetInputFile(), shapeFactor.GetHistoPath(), shapeFactor.GetHistoName(),
1121 fileHandles);
1122 shapeFactor.SetInitialShape(hist);
1123 }
1124
1125 } // End Loop over ShapeFactor
1126
1127 } // End Loop over Samples
1128}
1129
1131{
1132
1133 // Check that all internal histogram pointers
1134 // are properly configured (ie that they're not nullptr)
1135
1136 if (fData.GetHisto() == nullptr && !fData.GetInputFile().empty()) {
1137 cxcoutEHF << "Error: Data Histogram for channel " << GetName() << " is nullptr." << std::endl;
1138 return false;
1139 }
1140
1141 // Get the histograms for the samples:
1142 for (Sample const &sample : fSamples) {
1143 // Get the nominal histogram:
1144 if (sample.GetHisto() == nullptr) {
1145 cxcoutEHF << "Error: Nominal Histogram for sample " << sample.GetName() << " is nullptr." << std::endl;
1146 return false;
1147 } else {
1148
1149 // Check if any bins are negative
1150 std::vector<int> NegativeBinNumber;
1151 std::vector<double> NegativeBinContent;
1152 const TH1 *histNominal = sample.GetHisto();
1153 for (int ibin = 1; ibin <= histNominal->GetNbinsX(); ++ibin) {
1154 if (histNominal->GetBinContent(ibin) < 0) {
1155 NegativeBinNumber.push_back(ibin);
1156 NegativeBinContent.push_back(histNominal->GetBinContent(ibin));
1157 }
1158 }
1159 if (!NegativeBinNumber.empty()) {
1160 cxcoutWHF << "WARNING: Nominal Histogram " << histNominal->GetName() << " for Sample = " << sample.GetName()
1161 << " in Channel = " << GetName() << " has negative entries in bin numbers = ";
1162
1163 for (unsigned int ibin = 0; ibin < NegativeBinNumber.size(); ++ibin) {
1164 if (ibin > 0)
1165 std::cout << " , ";
1166 std::cout << NegativeBinNumber[ibin] << " : " << NegativeBinContent[ibin];
1167 }
1168 std::cout << std::endl;
1169 }
1170 }
1171
1172 // Get the StatError Histogram (if necessary)
1173 if (sample.GetStatError().GetUseHisto()) {
1174 if (sample.GetStatError().GetErrorHist() == nullptr) {
1175 cxcoutEHF << "Error: Statistical Error Histogram for sample " << sample.GetName() << " is nullptr."
1176 << std::endl;
1177 return false;
1178 }
1179 }
1180
1181 // Get the HistoSys Variations:
1182 for (const HistoSys &histoSys : sample.GetHistoSysList()) {
1183
1184 if (histoSys.GetHistoLow() == nullptr) {
1185 cxcoutEHF << "Error: HistoSyst Low for Systematic " << histoSys.GetName() << " in sample "
1186 << sample.GetName() << " is nullptr." << std::endl;
1187 return false;
1188 }
1189 if (histoSys.GetHistoHigh() == nullptr) {
1190 cxcoutEHF << "Error: HistoSyst High for Systematic " << histoSys.GetName() << " in sample "
1191 << sample.GetName() << " is nullptr." << std::endl;
1192 return false;
1193 }
1194
1195 } // End Loop over HistoSys
1196
1197 // Get the HistoFactor Variations:
1198 for (const HistoFactor &histoFactor : sample.GetHistoFactorList()) {
1199
1200 if (histoFactor.GetHistoLow() == nullptr) {
1201 cxcoutEHF << "Error: HistoSyst Low for Systematic " << histoFactor.GetName() << " in sample "
1202 << sample.GetName() << " is nullptr." << std::endl;
1203 return false;
1204 }
1205 if (histoFactor.GetHistoHigh() == nullptr) {
1206 cxcoutEHF << "Error: HistoSyst High for Systematic " << histoFactor.GetName() << " in sample "
1207 << sample.GetName() << " is nullptr." << std::endl;
1208 return false;
1209 }
1210
1211 } // End Loop over HistoFactor
1212
1213 // Get the ShapeSys Variations:
1214 for (const ShapeSys &shapeSys : sample.GetShapeSysList()) {
1215 if (shapeSys.GetErrorHist() == nullptr) {
1216 cxcoutEHF << "Error: HistoSyst High for Systematic " << shapeSys.GetName() << " in sample "
1217 << sample.GetName() << " is nullptr." << std::endl;
1218 return false;
1219 }
1220 } // End Loop over ShapeSys
1221
1222 } // End Loop over Samples
1223
1224 return true;
1225}
1226
1227/// Open a file and copy a histogram
1228/// \param InputFile File where the histogram resides.
1229/// \param HistoPath Path of the histogram in the file.
1230/// \param HistoName Name of the histogram to retrieve.
1231/// \param lsof List of open files. Helps to prevent opening and closing a file hundreds of times.
1232TH1 *Channel::GetHistogram(std::string InputFile, std::string HistoPath, std::string HistoName,
1233 std::map<std::string, std::unique_ptr<TFile>> &lsof)
1234{
1235
1236 cxcoutPHF << "Getting histogram " << InputFile << ":" << HistoPath << "/" << HistoName << std::endl;
1237
1238 auto &inFile = lsof[InputFile];
1239 if (!inFile || !inFile->IsOpen()) {
1240 inFile.reset(TFile::Open(InputFile.c_str()));
1241 if (!inFile || !inFile->IsOpen()) {
1242 cxcoutEHF << "Error: Unable to open input file: " << InputFile << std::endl;
1243 throw hf_exc();
1244 }
1245 cxcoutIHF << "Opened input file: " << InputFile << ": " << std::endl;
1246 }
1247
1248 TDirectory *dir = inFile->GetDirectory(HistoPath.c_str());
1249 if (dir == nullptr) {
1250 cxcoutEHF << "Histogram path '" << HistoPath << "' wasn't found in file '" << InputFile << "'." << std::endl;
1251 throw hf_exc();
1252 }
1253
1254 // Have to read histograms via keys, to ensure that the latest-greatest
1255 // name cycle is read from file. Otherwise, they might come from memory.
1256 auto key = dir->GetKey(HistoName.c_str());
1257 if (key == nullptr) {
1258 cxcoutEHF << "Histogram '" << HistoName << "' wasn't found in file '" << InputFile << "' in directory '"
1259 << HistoPath << "'." << std::endl;
1260 throw hf_exc();
1261 }
1262
1263 std::unique_ptr<TH1> hist(key->ReadObject<TH1>());
1264 if (!hist) {
1265 cxcoutEHF << "Histogram '" << HistoName << "' wasn't found in file '" << InputFile << "' in directory '"
1266 << HistoPath << "'." << std::endl;
1267 throw hf_exc();
1268 }
1269
1270 TDirectory::TContext ctx{nullptr};
1271 TH1 *ptr = static_cast<TH1 *>(hist->Clone());
1272
1273 if (!ptr) {
1274 std::cerr << "Not all necessary info are set to access the input file. Check your config" << std::endl;
1275 std::cerr << "filename: " << InputFile << "path: " << HistoPath << "obj: " << HistoName << std::endl;
1276 throw hf_exc();
1277 }
1278
1279#ifdef DEBUG
1280 std::cout << "Found Histogram: " << HistoName " at address: " << ptr << " with integral " << ptr->Integral()
1281 << " and mean " << ptr->GetMean() << std::endl;
1282#endif
1283
1284 // Done
1285 return ptr;
1286}
1287
1288////////////////////////////////////////////////////////////////////////////////
1289/** \class RooStats::HistFactory::Data
1290 * \ingroup HistFactory
1291 */
1292
1293Data::Data(std::string HistoName, std::string InputFile, std::string HistoPath)
1294 : fInputFile(InputFile), fHistoName(HistoName), fHistoPath(HistoPath)
1295{
1296}
1297
1299{
1300 return (TH1 *)fhData.GetObject();
1301}
1302
1303const TH1 *Data::GetHisto() const
1304{
1305 return (TH1 *)fhData.GetObject();
1306}
1307
1308void Data::Print(std::ostream &stream)
1309{
1310
1311 stream << "\t \t InputFile: " << fInputFile << "\t HistoName: " << fHistoName << "\t HistoPath: " << fHistoPath
1312 << "\t HistoAddress: " << GetHisto() << std::endl;
1313}
1314
1315void Data::writeToFile(std::string OutputFileName, std::string DirName)
1316{
1317
1318 TH1 *histData = GetHisto();
1319
1320 if (histData != nullptr) {
1321
1322 histData->Write();
1323
1324 // Set the location of the data
1325 // in the output measurement
1326
1328 fHistoName = histData->GetName();
1329 fHistoPath = DirName;
1330 }
1331}
1332
1333void Data::PrintXML(std::ostream &xml) const
1334{
1335
1336 xml << " <Data HistoName=\"" << GetHistoName() << "\" "
1337 << "InputFile=\"" << GetInputFile() << "\" "
1338 << "HistoPath=\"" << GetHistoPath() << "\" ";
1339 if (!GetName().empty()) {
1340 xml << "Name=\"" << GetName() << "\" ";
1341 }
1342 xml << " /> " << std::endl << std::endl;
1343}
1344
1345////////////////////////////////////////////////////////////////////////////////
1346/**
1347 * \ingroup HistFactory
1348 */
1349
1350namespace {
1351
1352/// Replaces the XML special characters with their escape codes.
1353std::string escapeXML(const std::string &src)
1354{
1355 std::stringstream dst;
1356 for (char ch : src) {
1357 switch (ch) {
1358 case '&': dst << "&amp;"; break;
1359 case '\'': dst << "&apos;"; break;
1360 case '"': dst << "&quot;"; break;
1361 case '<': dst << "&lt;"; break;
1362 case '>': dst << "&gt;"; break;
1363 default: dst << ch; break;
1364 }
1365 }
1366 return dst.str();
1367}
1368
1369} // namespace
1370
1371PreprocessFunction::PreprocessFunction(std::string const &name, std::string const &expression,
1372 std::string const &dependents)
1373 : fName(name), fExpression(expression), fDependents(dependents)
1374{
1375}
1376
1378{
1379 return "expr::" + fName + "('" + fExpression + "',{" + fDependents + "})";
1380}
1381
1382void PreprocessFunction::Print(std::ostream &stream) const
1383{
1384 stream << "\t \t Name: " << fName << "\t \t Expression: " << fExpression << "\t \t Dependents: " << fDependents
1385 << std::endl;
1386}
1387
1388void PreprocessFunction::PrintXML(std::ostream &xml) const
1389{
1390 xml << "<Function Name=\"" << fName << "\" "
1391 << "Expression=\"" << escapeXML(fExpression) << "\" "
1392 << "Dependents=\"" << fDependents << "\" "
1393 << "/>\n";
1394}
1395
1396////////////////////////////////////////////////////////////////////////////////
1397/** \class RooStats::HistFactory::Asimov
1398 * \ingroup HistFactory
1399 * TODO Here, we are missing some documentation.
1400 */
1401
1403{
1404
1405 // Here is where we set the values, and constantness
1406 // of all parameters in the workspace before creating
1407 // an asimov dataset
1408
1409 /*
1410 // Okay, y'all, first we're going to create a snapshot
1411 // of the current state of the variables in the workspace
1412
1413 std::string ListOfVariableNames = "";
1414 for( std::map< std::string, double >::iterator itr = fParamValsToSet.begin();
1415 itr != fParamValsToSet.end(); ++itr) {
1416 // Extend the Variable Name list
1417 ListOfVariableNames += "," + itr->first;
1418 }
1419 for( std::map< std::string, bool >::iterator itr = fParamsToFix.begin();
1420 itr != fParamsToFix.end(); ++itr) {
1421 // Extend the Variable Name list
1422 ListOfVariableNames += "," + itr->first;
1423 }
1424
1425 // Save a snapshot
1426 std::string SnapShotName = "NominalParamValues";
1427 wspace->saveSnapshot(SnapShotName.c_str(), ListOfVariableNames.c_str());
1428 */
1429
1430 //
1431 // First we set all parameters to their given values
1432 //
1433
1434 for (std::map<std::string, double>::iterator itr = fParamValsToSet.begin(); itr != fParamValsToSet.end(); ++itr) {
1435
1436 std::string param = itr->first;
1437 double val = itr->second;
1438
1439 // Try to get the variable in the workspace
1440 RooRealVar *var = wspace->var(param);
1441 if (!var) {
1442 std::cout << "Error: Trying to set variable: " << var
1443 << " to a specific value in creation of asimov dataset: " << fName
1444 << " but this variable doesn't appear to exist in the workspace" << std::endl;
1445 throw hf_exc();
1446 }
1447
1448 // Check that the desired value is in the range of the variable
1449 double inRange = var->inRange(val, nullptr);
1450 if (!inRange) {
1451 std::cout << "Error: Attempting to set variable: " << var << " to value: " << val << ", however it appears"
1452 << " that this is not withn the variable's range: "
1453 << "[" << var->getMin() << ", " << var->getMax() << "]" << std::endl;
1454 throw hf_exc();
1455 }
1456
1457 // Set its value
1458 std::cout << "Configuring Asimov Dataset: Setting " << param << " = " << val << std::endl;
1459 var->setVal(val);
1460 }
1461
1462 //
1463 // Then, we set any variables to constant
1464 //
1465
1466 for (auto &[param, isConstant] : fParamsToFix) {
1467
1468 // Try to get the variable in the workspace
1469 RooRealVar *var = wspace->var(param);
1470 if (!var) {
1471 std::cout << "Error: Trying to set variable: " << var << " constant in creation of asimov dataset: " << fName
1472 << " but this variable doesn't appear to exist in the workspace" << std::endl;
1473 throw hf_exc();
1474 }
1475
1476 std::cout << "Configuring Asimov Dataset: Setting " << param << " to constant " << std::endl;
1477 var->setConstant(isConstant);
1478 }
1479}
1480
1481/** \class RooStats::HistFactory::HistRef
1482 * \ingroup HistFactory
1483 * Internal class wrapping an histogram and managing its content.
1484 * convenient for dealing with histogram pointers in the
1485 * HistFactory class
1486 */
1487
1488/// constructor - use gives away ownerhip of the given pointer
1490
1492{
1493 if (other.fHist)
1494 fHist.reset(CopyObject(other.fHist.get()));
1495}
1496
1497HistRef::HistRef(HistRef &&other) : fHist(std::move(other.fHist)) {}
1498
1499HistRef::~HistRef() = default;
1500
1501/// assignment operator (delete previous contained histogram)
1503{
1504 if (this == &other)
1505 return *this;
1506
1507 fHist.reset(CopyObject(other.fHist.get()));
1508 return *this;
1509}
1510
1512{
1513 fHist = std::move(other.fHist);
1514 return *this;
1515}
1516
1518{
1519 // implementation of method copying the contained pointer
1520 // (just use Clone)
1521 if (!h)
1522 return nullptr;
1523
1524 TDirectory::TContext ctx{nullptr}; // Don't associate histogram with currently open file
1525 return static_cast<TH1 *>(h->Clone());
1526}
1527
1529{
1530 return fHist.get();
1531}
1532
1533/// set the object - user gives away the ownerhisp
1535{
1536 fHist.reset(h);
1537}
1538
1539/// operator= passing an object pointer : user gives away its ownerhisp
1541{
1542 SetObject(h);
1543}
1544
1545/// Release ownership of object.
1547{
1548 return fHist.release();
1549}
1550
1551// Constraints
1553{
1554
1556 return "Gaussian";
1558 return "Poisson";
1559 return "";
1560}
1561
1563{
1564
1565 if (Name.empty()) {
1566 std::cout << "Error: Given empty name for ConstraintType" << std::endl;
1567 throw hf_exc();
1568 }
1569
1570 else if (Name == "Gaussian" || Name == "Gauss") {
1571 return Constraint::Gaussian;
1572 }
1573
1574 else if (Name == "Poisson" || Name == "Pois") {
1575 return Constraint::Poisson;
1576 }
1577
1578 else {
1579 std::cout << "Error: Unknown name given for Constraint Type: " << Name << std::endl;
1580 throw hf_exc();
1581 }
1582}
1583
1584void NormFactor::Print(std::ostream &stream) const
1585{
1586 stream << "\t \t Name: " << fName << "\t Val: " << fVal << "\t Low: " << fLow << "\t High: " << fHigh << std::endl;
1587}
1588
1589void NormFactor::PrintXML(std::ostream &xml) const
1590{
1591 xml << " <NormFactor Name=\"" << GetName() << "\" "
1592 << " Val=\"" << GetVal() << "\" "
1593 << " High=\"" << GetHigh() << "\" "
1594 << " Low=\"" << GetLow() << "\" "
1595 << " /> " << std::endl;
1596}
1597
1598void OverallSys::Print(std::ostream &stream) const
1599{
1600 stream << "\t \t Name: " << fName << "\t Low: " << fLow << "\t High: " << fHigh << std::endl;
1601}
1602
1603void OverallSys::PrintXML(std::ostream &xml) const
1604{
1605 xml << " <OverallSys Name=\"" << GetName() << "\" "
1606 << " High=\"" << GetHigh() << "\" "
1607 << " Low=\"" << GetLow() << "\" "
1608 << " /> " << std::endl;
1609}
1610
1612
1614 : fName(Name), fhLow(nullptr), fhHigh(nullptr)
1615{
1616}
1617
1619
1621
1623
1624void HistogramUncertaintyBase::Print(std::ostream &stream) const
1625{
1626 stream << "\t \t Name: " << fName << "\t HistoFileLow: " << fInputFileLow << "\t HistoNameLow: " << fHistoNameLow
1627 << "\t HistoPathLow: " << fHistoPathLow << "\t HistoFileHigh: " << fInputFileHigh
1628 << "\t HistoNameHigh: " << fHistoNameHigh << "\t HistoPathHigh: " << fHistoPathHigh << std::endl;
1629}
1630
1631void HistogramUncertaintyBase::writeToFile(const std::string &FileName, const std::string &DirName)
1632{
1633
1634 // This saves the histograms to a file and
1635 // changes the name of the local file and histograms
1636
1637 auto histLow = GetHistoLow();
1638 if (histLow == nullptr) {
1639 std::cout << "Error: Cannot write " << GetName() << " to file: " << FileName << " HistoLow is nullptr"
1640 << std::endl;
1641 throw hf_exc();
1642 }
1643 histLow->Write();
1644 fInputFileLow = FileName;
1645 fHistoPathLow = DirName;
1646 fHistoNameLow = histLow->GetName();
1647
1648 auto histHigh = GetHistoHigh();
1649 if (histHigh == nullptr) {
1650 std::cout << "Error: Cannot write " << GetName() << " to file: " << FileName << " HistoHigh is nullptr"
1651 << std::endl;
1652 throw hf_exc();
1653 }
1654 histHigh->Write();
1655 fInputFileHigh = FileName;
1656 fHistoPathHigh = DirName;
1657 fHistoNameHigh = histHigh->GetName();
1658}
1659
1660void HistoSys::PrintXML(std::ostream &xml) const
1661{
1662 xml << " <HistoSys Name=\"" << GetName() << "\" "
1663 << " HistoFileLow=\"" << GetInputFileLow() << "\" "
1664 << " HistoNameLow=\"" << GetHistoNameLow() << "\" "
1665 << " HistoPathLow=\"" << GetHistoPathLow() << "\" "
1666
1667 << " HistoFileHigh=\"" << GetInputFileHigh() << "\" "
1668 << " HistoNameHigh=\"" << GetHistoNameHigh() << "\" "
1669 << " HistoPathHigh=\"" << GetHistoPathHigh() << "\" "
1670 << " /> " << std::endl;
1671}
1672
1674{
1675 fhHigh.reset(hError);
1676}
1677
1678void ShapeSys::Print(std::ostream &stream) const
1679{
1680 stream << "\t \t Name: " << fName << "\t InputFile: " << fInputFileHigh << "\t HistoName: " << fHistoNameHigh
1681 << "\t HistoPath: " << fHistoPathHigh << std::endl;
1682}
1683
1684void ShapeSys::PrintXML(std::ostream &xml) const
1685{
1686 xml << " <ShapeSys Name=\"" << GetName() << "\" "
1687 << " InputFile=\"" << GetInputFile() << "\" "
1688 << " HistoName=\"" << GetHistoName() << "\" "
1689 << " HistoPath=\"" << GetHistoPath() << "\" "
1690 << " ConstraintType=\"" << std::string(Constraint::Name(GetConstraintType())) << "\" "
1691 << " /> " << std::endl;
1692}
1693
1694void ShapeSys::writeToFile(const std::string &FileName, const std::string &DirName)
1695{
1696 auto histError = GetErrorHist();
1697 if (histError == nullptr) {
1698 std::cout << "Error: Cannot write " << GetName() << " to file: " << FileName << " ErrorHist is nullptr"
1699 << std::endl;
1700 throw hf_exc();
1701 }
1702 histError->Write();
1703 fInputFileHigh = FileName;
1704 fHistoPathHigh = DirName;
1705 fHistoNameHigh = histError->GetName();
1706}
1707
1708void HistoFactor::PrintXML(std::ostream &xml) const
1709{
1710 xml << " <HistoFactor Name=\"" << GetName() << "\" "
1711
1712 << " InputFileLow=\"" << GetInputFileLow() << "\" "
1713 << " HistoNameLow=\"" << GetHistoNameLow() << "\" "
1714 << " HistoPathLow=\"" << GetHistoPathLow() << "\" "
1715
1716 << " InputFileHigh=\"" << GetInputFileHigh() << "\" "
1717 << " HistoNameHigh=\"" << GetHistoNameHigh() << "\" "
1718 << " HistoPathHigh=\"" << GetHistoPathHigh() << "\" "
1719 << " /> " << std::endl;
1720}
1721
1723{
1724 fhHigh.reset(shape);
1725}
1726
1727void ShapeFactor::Print(std::ostream &stream) const
1728{
1729
1730 stream << "\t \t Name: " << fName << std::endl;
1731
1732 if (!fHistoNameHigh.empty()) {
1733 stream << "\t \t "
1734 << " Shape Hist Name: " << fHistoNameHigh << " Shape Hist Path Name: " << fHistoPathHigh
1735 << " Shape Hist FileName: " << fInputFileHigh << std::endl;
1736 }
1737 // Print value and range in RooRealVar style
1738 stream << "\t \t Value: " << GetVal() << " L(" << GetLow() << " - " << GetHigh() << ")\n";
1739
1740 if (fConstant) {
1741 stream << "\t \t ( Constant ): " << std::endl;
1742 }
1743}
1744
1745void ShapeFactor::writeToFile(const std::string &FileName, const std::string &DirName)
1746{
1747
1748 if (HasInitialShape()) {
1750 if (histInitialShape == nullptr) {
1751 std::cout << "Error: Cannot write " << GetName() << " to file: " << FileName << " InitialShape is nullptr"
1752 << std::endl;
1753 throw hf_exc();
1754 }
1755 histInitialShape->Write();
1756 fInputFileHigh = FileName;
1757 fHistoPathHigh = DirName;
1758 fHistoNameHigh = histInitialShape->GetName();
1759 }
1760}
1761
1762void ShapeFactor::PrintXML(std::ostream &xml) const
1763{
1764 xml << " <ShapeFactor Name=\"" << GetName() << "\" ";
1765 if (fHasInitialShape) {
1766 xml << " InputFile=\"" << GetInputFile() << "\" "
1767 << " HistoName=\"" << GetHistoName() << "\" "
1768 << " HistoPath=\"" << GetHistoPath() << "\" ";
1769 }
1770 xml << " Val=\"" << GetVal() << "\" "
1771 << " High=\"" << GetHigh() << "\" "
1772 << " Low=\"" << GetLow() << "\" "
1773 << " Const=\"" << (IsConstant() ? std::string("True") : std::string("False")) << "\" ";
1774 xml << " /> " << std::endl;
1775}
1776
1778{
1779 fhHigh.reset(Error);
1780}
1781
1782void StatErrorConfig::Print(std::ostream &stream) const
1783{
1784 stream << "\t \t RelErrorThreshold: " << fRelErrorThreshold
1785 << "\t ConstraintType: " << Constraint::Name(fConstraintType) << std::endl;
1786}
1787
1788void StatErrorConfig::PrintXML(std::ostream &xml) const
1789{
1790 xml << " <StatErrorConfig RelErrorThreshold=\"" << GetRelErrorThreshold() << "\" "
1791 << "ConstraintType=\"" << Constraint::Name(GetConstraintType()) << "\" "
1792 << "/> " << std::endl
1793 << std::endl;
1794}
1795
1796void StatError::Print(std::ostream &stream) const
1797{
1798 stream << "\t \t Activate: " << fActivate << "\t InputFile: " << fInputFileHigh << "\t HistoName: " << fHistoNameHigh
1799 << "\t histoPath: " << fHistoPathHigh << std::endl;
1800}
1801
1802void StatError::PrintXML(std::ostream &xml) const
1803{
1804
1805 if (GetActivate()) {
1806 xml << " <StatError Activate=\"" << (GetActivate() ? std::string("True") : std::string("False")) << "\" "
1807 << " InputFile=\"" << GetInputFile() << "\" "
1808 << " HistoName=\"" << GetHistoName() << "\" "
1809 << " HistoPath=\"" << GetHistoPath() << "\" "
1810 << " /> " << std::endl;
1811 }
1812}
1813
1814void StatError::writeToFile(const std::string &OutputFileName, const std::string &DirName)
1815{
1816
1817 if (fUseHisto) {
1818
1819 std::string statErrorHistName = "statisticalErrors";
1820
1821 auto hStatError = GetErrorHist();
1822 if (hStatError == nullptr) {
1823 std::cout << "Error: Stat Error error hist is nullptr" << std::endl;
1824 throw hf_exc();
1825 }
1826 hStatError->Write(statErrorHistName.c_str());
1827
1830 fHistoPathHigh = DirName;
1831 }
1832}
1833
1835 : fName{oth.fName},
1836 fInputFileLow{oth.fInputFileLow},
1837 fHistoNameLow{oth.fHistoNameLow},
1838 fHistoPathLow{oth.fHistoPathLow},
1839 fInputFileHigh{oth.fInputFileHigh},
1840 fHistoNameHigh{oth.fHistoNameHigh},
1841 fHistoPathHigh{oth.fHistoPathHigh},
1842 fhLow{oth.fhLow ? static_cast<TH1 *>(oth.fhLow->Clone()) : nullptr},
1843 fhHigh{oth.fhHigh ? static_cast<TH1 *>(oth.fhHigh->Clone()) : nullptr}
1844{
1845 if (fhLow)
1846 fhLow->SetDirectory(nullptr);
1847 if (fhHigh)
1848 fhHigh->SetDirectory(nullptr);
1849}
1850
1852{
1853 fName = oth.fName;
1854 fInputFileLow = oth.fInputFileLow;
1855 fHistoNameLow = oth.fHistoNameLow;
1856 fHistoPathLow = oth.fHistoPathLow;
1857 fInputFileHigh = oth.fInputFileHigh;
1858 fHistoNameHigh = oth.fHistoNameHigh;
1859 fHistoPathHigh = oth.fHistoPathHigh;
1860
1861 TDirectory::TContext ctx{nullptr}; // Don't associate clones to directories
1862 fhLow.reset(oth.fhLow ? static_cast<TH1 *>(oth.fhLow->Clone()) : nullptr);
1863 fhHigh.reset(oth.fhHigh ? static_cast<TH1 *>(oth.fhHigh->Clone()) : nullptr);
1864
1865 return *this;
1866}
1867
1869{
1870 Low->SetDirectory(nullptr);
1871 fhLow.reset(Low);
1872}
1873
1875{
1876 High->SetDirectory(nullptr);
1877 fhHigh.reset(High);
1878}
1879
1881{
1882 fhData = Hist;
1883 fHistoName = Hist->GetName();
1884}
1885
1887{
1888 fhNominal = histo;
1889 fHistoName = histo->GetName();
1890}
1891
1892} // 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:145
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
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:90
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:60
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:36
void SetName(const std::string &Name)
Definition Measurement.h:39
const std::string & GetName() const
Definition Measurement.h:40
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 file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
virtual void Flush()
Synchronize a file's in-memory and on-disk states.
Definition TFile.cxx:1152
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:3787
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:9090
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:7664
virtual Double_t Integral(Option_t *option="") const
Return integral of bin contents.
Definition TH1.cxx:8090
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition TSystem.cxx:859
virtual void * OpenDirectory(const char *name)
Open a directory.
Definition TSystem.cxx:850
virtual int MakeDirectory(const char *name)
Make a directory.
Definition TSystem.cxx:840
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)