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 }
100 return PreprocessFunctionExpressions;
101}
102
103/// Set constraint term for given systematic to Gamma distribution
104void Measurement::AddGammaSyst(std::string syst, double uncert)
105{
106 fGammaSyst[syst] = uncert;
107}
108
109/// Set constraint term for given systematic to LogNormal distribution
110void Measurement::AddLogNormSyst(std::string syst, double uncert)
111{
112 fLogNormSyst[syst] = uncert;
113}
114
115/// Set constraint term for given systematic to uniform distribution
116void Measurement::AddUniformSyst(std::string syst)
117{
118 fUniformSyst[syst] = 1.0; // Is this parameter simply a dummy?
119}
120
121/// Define given systematics to have no external constraint
122void Measurement::AddNoSyst(std::string syst)
123{
124 fNoSyst[syst] = 1.0; // dummy value
125}
126
127/// Check if the given channel is part of this measurement
128bool Measurement::HasChannel(std::string ChanName)
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
144Channel &Measurement::GetChannel(std::string ChanName)
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())
259 newOutputPrefix = fOutputFilePrefix;
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 }
300 xml << "</POI> " << std::endl;
301
302 // Set the Constant Parameters
303 if (!fConstantParams.empty()) {
304 xml << " <ParamSetting Const=\"True\">";
305 for (unsigned int i = 0; i < fConstantParams.size(); ++i) {
306 if (i == 0) {
307 xml << fConstantParams.at(i);
308 } else {
309 xml << " " << fConstantParams.at(i);
310 }
311 }
312 xml << "</ParamSetting>" << std::endl;
313 }
314
315 // Set the Parameters with new Constraint Terms
316 std::map<std::string, double>::iterator ConstrItr;
317
318 // Gamma
319 for (ConstrItr = fGammaSyst.begin(); ConstrItr != fGammaSyst.end(); ++ConstrItr) {
320 xml << "<ConstraintTerm Type=\"Gamma\" RelativeUncertainty=\"" << ConstrItr->second << "\">" << ConstrItr->first
321 << "</ConstraintTerm>" << std::endl;
322 }
323 // Uniform
324 for (ConstrItr = fUniformSyst.begin(); ConstrItr != fUniformSyst.end(); ++ConstrItr) {
325 xml << "<ConstraintTerm Type=\"Uniform\" RelativeUncertainty=\"" << ConstrItr->second << "\">" << ConstrItr->first
326 << "</ConstraintTerm>" << std::endl;
327 }
328 // LogNormal
329 for (ConstrItr = fLogNormSyst.begin(); ConstrItr != fLogNormSyst.end(); ++ConstrItr) {
330 xml << "<ConstraintTerm Type=\"LogNormal\" RelativeUncertainty=\"" << ConstrItr->second << "\">"
331 << ConstrItr->first << "</ConstraintTerm>" << std::endl;
332 }
333 // NoSyst
334 for (ConstrItr = fNoSyst.begin(); ConstrItr != fNoSyst.end(); ++ConstrItr) {
335 xml << "<ConstraintTerm Type=\"NoSyst\" RelativeUncertainty=\"" << ConstrItr->second << "\">" << ConstrItr->first
336 << "</ConstraintTerm>" << std::endl;
337 }
338
339 // Close the Measurement
340 xml << " </Measurement> " << std::endl << std::endl;
341
342 // Close the combination
343 xml << "</Combination>" << std::endl;
344
345 xml.close();
346
347 // Now, make the xml files
348 // for the individual channels:
349
350 std::string prefix = std::string(GetName()) + "_";
351
352 for (unsigned int i = 0; i < fChannels.size(); ++i) {
353 fChannels.at(i).PrintXML(directory, prefix);
354 }
355
356 cxcoutPHF << "Finished printing XML files" << std::endl;
357}
358
359/// A measurement, once fully configured, can be saved into a ROOT
360/// file. This will persitify the Measurement object, along with any
361/// channels and samples that have been added to it. It can then be
362/// loaded, potentially modified, and used to create new models.
363///
364/// Write every histogram to the file.
365/// Edit the measurement to point to this file
366/// and to point to each histogram in this file
367/// Then write the measurement itself.
369{
370
371 // Create a temporary measurement
372 // (This is the one that is actually written)
373 Measurement outMeas(*this);
374
375 std::string OutputFileName = file->GetName();
376
377 // Collect all histograms from file:
378 // HistCollector collector;
379
380 for (Channel &channel : fChannels) {
381 // Go to the main directory
382 // in the file
383 file->cd();
384 file->Flush();
385
386 // Get the name of the channel:
387 std::string chanName = channel.GetName();
388
389 if (!channel.CheckHistograms()) {
390 cxcoutEHF << "Measurement.writeToFile(): Channel: " << chanName << " has uninitialized histogram pointers"
391 << std::endl;
392 throw hf_exc();
393 return;
394 }
395
396 // Get and cache the histograms for this channel:
397 // collector.CollectHistograms( channel );
398 // Do I need this...?
399 // channel.CollectHistograms();
400
401 // Make a directory to store the histograms
402 // for this channel
403
404 TDirectory *chanDir = file->mkdir((chanName + "_hists").c_str());
405 if (chanDir == nullptr) {
406 cxcoutEHF << "Error: Cannot create channel " << (chanName + "_hists") << std::endl;
407 throw hf_exc();
408 }
409 chanDir->cd();
410
411 // Save the data:
412 TDirectory *dataDir = chanDir->mkdir("data");
413 if (dataDir == nullptr) {
414 cxcoutEHF << "Error: Cannot make directory " << chanDir << std::endl;
415 throw hf_exc();
416 }
417 dataDir->cd();
418
419 channel.fData.writeToFile(OutputFileName, GetDirPath(dataDir));
420
421 // Loop over samples:
422 for (Sample &sample : channel.GetSamples()) {
423 cxcoutPHF << "Writing sample: " << sample.GetName() << std::endl;
424
425 file->cd();
426 chanDir->cd();
427 TDirectory *sampleDir = chanDir->mkdir(sample.GetName().c_str());
428 if (sampleDir == nullptr) {
429 cxcoutEHF << "Error: Directory " << sample.GetName() << " not created properly" << std::endl;
430 throw hf_exc();
431 }
432 std::string sampleDirPath = GetDirPath(sampleDir);
433
434 if (!sampleDir) {
435 cxcoutEHF << "Error making directory: " << sample.GetName() << " in directory: " << chanName << std::endl;
436 throw hf_exc();
437 }
438
439 // Write the data file to this directory
440 sampleDir->cd();
441
442 sample.writeToFile(OutputFileName, sampleDirPath);
443 }
444 }
445
446 // Finally, write the measurement itself:
447
448 cxcoutPHF << "Saved all histograms" << std::endl;
449
450 file->cd();
451 outMeas.Write();
452
453 cxcoutPHF << "Saved Measurement" << std::endl;
454}
455
456/// Return the directory's path,
457/// stripped of unnecessary prefixes
459{
460 std::string path = dir->GetPath();
461
462 if (path.find(':') != std::string::npos) {
463 size_t index = path.find(':');
464 path.replace(0, index + 1, "");
465 }
466
467 return path + "/";
468}
469
470/// The most common way to add histograms to channels is to have them
471/// stored in ROOT files and to give HistFactory the location of these
472/// files. This means providing the path to the ROOT file and the path
473/// and name of the histogram within that file. When providing these
474/// in a script, HistFactory doesn't load the histogram from the file
475/// right away. Instead, once all such histograms have been supplied,
476/// one should run this method to open all ROOT files and to copy and
477/// save all necessary histograms.
479{
480 for (Channel &chan : fChannels) {
481 chan.CollectHistograms();
482 }
483}
484
485//////////////////////////////////////////////////////////////////////////////
486/** \class RooStats::HistFactory::Sample
487 * \ingroup HistFactory
488 */
489
490Sample::Sample() = default;
491
492Sample::~Sample() = default;
493
494// copy constructor (important for Python)
496 : fName(other.fName),
497 fInputFile(other.fInputFile),
498 fHistoName(other.fHistoName),
499 fHistoPath(other.fHistoPath),
500 fChannelName(other.fChannelName),
501
502 fOverallSysList(other.fOverallSysList),
503 fNormFactorList(other.fNormFactorList),
504 fHistoSysList(other.fHistoSysList),
505 fHistoFactorList(other.fHistoFactorList),
506 fShapeSysList(other.fShapeSysList),
507 fShapeFactorList(other.fShapeFactorList),
508
509 fStatError(other.fStatError),
510 fNormalizeByTheory(other.fNormalizeByTheory),
511 fStatErrorActivate(other.fStatErrorActivate),
512 fhNominal(other.fhNominal)
513{
514 if (other.fhCountingHist) {
515 SetValue(other.fhCountingHist->GetBinContent(1));
516 } else {
517 fhCountingHist.reset();
518 }
519}
520
522{
523 fName = other.fName;
524 fInputFile = other.fInputFile;
525 fHistoName = other.fHistoName;
526 fHistoPath = other.fHistoPath;
528
535
536 fStatError = other.fStatError;
539 fhNominal = other.fhNominal;
540
541 fhCountingHist.reset();
542
543 if (other.fhCountingHist) {
544 SetValue(other.fhCountingHist->GetBinContent(1));
545 } else {
546 fhCountingHist.reset();
547 }
548
549 return *this;
550}
551
552Sample::Sample(std::string SampName, std::string SampHistoName, std::string SampInputFile, std::string SampHistoPath)
553 : fName(SampName),
554 fInputFile(SampInputFile),
555 fHistoName(SampHistoName),
556 fHistoPath(SampHistoPath),
557 fNormalizeByTheory(true),
558 fStatErrorActivate(false)
559{
560}
561
562Sample::Sample(std::string SampName) : fName(SampName), fNormalizeByTheory(true), fStatErrorActivate(false) {}
563
564const TH1 *Sample::GetHisto() const
565{
566 TH1 *histo = (TH1 *)fhNominal.GetObject();
567 return histo;
568}
569
570void Sample::writeToFile(std::string OutputFileName, std::string DirName)
571{
572
573 const TH1 *histNominal = GetHisto();
574 histNominal->Write();
575
576 // Set the location of the data
577 // in the output measurement
578
579 fInputFile = OutputFileName;
580 fHistoName = histNominal->GetName();
581 fHistoPath = DirName;
582
583 // Write this sample's StatError
584 GetStatError().writeToFile(OutputFileName, DirName);
585
586 // Must write all systematics that contain internal histograms
587 // (This is not all systematics)
588 for (unsigned int i = 0; i < GetHistoSysList().size(); ++i) {
589 GetHistoSysList().at(i).writeToFile(OutputFileName, DirName);
590 }
591 for (unsigned int i = 0; i < GetHistoFactorList().size(); ++i) {
592 GetHistoFactorList().at(i).writeToFile(OutputFileName, DirName);
593 }
594 for (unsigned int i = 0; i < GetShapeSysList().size(); ++i) {
595 GetShapeSysList().at(i).writeToFile(OutputFileName, DirName);
596 }
597 for (unsigned int i = 0; i < GetShapeFactorList().size(); ++i) {
598 GetShapeFactorList().at(i).writeToFile(OutputFileName, DirName);
599 }
600}
601
602void Sample::SetValue(double val)
603{
604
605 // For use in a number counting measurement
606 // Create a 1-bin histogram,
607 // fill it with this input value,
608 // and set this Sample's histogram to that hist
609
610 std::string SampleHistName = fName + "_hist";
611
612 // Histogram has 1-bin (hard-coded)
613 fhCountingHist.reset();
614
615 fhCountingHist = std::make_unique<TH1F>(SampleHistName.c_str(), SampleHistName.c_str(), 1, 0, 1);
616 fhCountingHist->SetBinContent(1, val);
617
618 // Set the histogram of the internally held data
619 // node of this channel to this newly created histogram
621}
622
623void Sample::Print(std::ostream &stream) const
624{
625
626 stream << "\t \t Name: " << fName << "\t \t Channel: " << fChannelName
627 << "\t NormalizeByTheory: " << (fNormalizeByTheory ? "True" : "False")
628 << "\t StatErrorActivate: " << (fStatErrorActivate ? "True" : "False") << std::endl;
629
630 stream << "\t \t \t \t "
631 << "\t InputFile: " << fInputFile << "\t HistName: " << fHistoName << "\t HistoPath: " << fHistoPath
632 << "\t HistoAddress: "
633 << GetHisto()
634 // << "\t Type: " << GetHisto()->ClassName()
635 << std::endl;
636
637 if (fStatError.GetActivate()) {
638 stream << "\t \t \t StatError Activate: " << fStatError.GetActivate() << "\t InputFile: " << fInputFile
639 << "\t HistName: " << fStatError.GetHistoName() << "\t HistoPath: " << fStatError.GetHistoPath()
640 << "\t HistoAddress: " << fStatError.GetErrorHist() << std::endl;
641 }
642
643 /*
644 stream<< " NormalizeByTheory: ";
645 if(NormalizeByTheory) stream << "True";
646 else stream << "False";
647
648 stream<< " StatErrorActivate: ";
649 if(StatErrorActivate) stream << "True";
650 else stream << "False";
651 */
652}
653
654void Sample::PrintXML(std::ofstream &xml) const
655{
656
657 // Create the sample tag
658 xml << " <Sample Name=\"" << fName << "\" "
659 << " HistoPath=\"" << fHistoPath << "\" "
660 << " HistoName=\"" << fHistoName << "\" "
661 << " InputFile=\"" << fInputFile << "\" "
662 << " NormalizeByTheory=\"" << (fNormalizeByTheory ? std::string("True") : std::string("False")) << "\" "
663 << ">" << std::endl;
664
665 // Print Stat Error (if necessary)
666 fStatError.PrintXML(xml);
667 /*
668 if( fStatError.GetActivate() ) {
669 xml << " <StatError Activate=\"" << (fStatError.GetActivate() ? std::string("True") : std::string("False")) <<
670 "\" "
671 << " InputFile=\"" << fStatError.GetInputFile() << "\" "
672 << " HistoName=\"" << fStatError.GetHistoName() << "\" "
673 << " HistoPath=\"" << fStatError.GetHistoPath() << "\" "
674 << " /> " << std::endl;
675 }
676 */
677
678 // Now, print the systematics:
679 for (unsigned int i = 0; i < fOverallSysList.size(); ++i) {
680 OverallSys sys = fOverallSysList.at(i);
681 sys.PrintXML(xml);
682 /*
683 xml << " <OverallSys Name=\"" << sys.GetName() << "\" "
684 << " High=\"" << sys.GetHigh() << "\" "
685 << " Low=\"" << sys.GetLow() << "\" "
686 << " /> " << std::endl;
687 */
688 }
689 for (unsigned int i = 0; i < fNormFactorList.size(); ++i) {
690 NormFactor sys = fNormFactorList.at(i);
691 sys.PrintXML(xml);
692 /*
693 xml << " <NormFactor Name=\"" << sys.GetName() << "\" "
694 << " Val=\"" << sys.GetVal() << "\" "
695 << " High=\"" << sys.GetHigh() << "\" "
696 << " Low=\"" << sys.GetLow() << "\" "
697 << " /> " << std::endl;
698 */
699 }
700 for (unsigned int i = 0; i < fHistoSysList.size(); ++i) {
701 HistoSys sys = fHistoSysList.at(i);
702 sys.PrintXML(xml);
703 /*
704 xml << " <HistoSys Name=\"" << sys.GetName() << "\" "
705
706 << " InputFileLow=\"" << sys.GetInputFileLow() << "\" "
707 << " HistoNameLow=\"" << sys.GetHistoNameLow() << "\" "
708 << " HistoPathLow=\"" << sys.GetHistoPathLow() << "\" "
709
710 << " InputFileHigh=\"" << sys.GetInputFileHigh() << "\" "
711 << " HistoNameHigh=\"" << sys.GetHistoNameHigh() << "\" "
712 << " HistoPathHigh=\"" << sys.GetHistoPathHigh() << "\" "
713 << " /> " << std::endl;
714 */
715 }
716 for (unsigned int i = 0; i < fHistoFactorList.size(); ++i) {
717 HistoFactor sys = fHistoFactorList.at(i);
718 sys.PrintXML(xml);
719 /*
720 xml << " <HistoFactor Name=\"" << sys.GetName() << "\" "
721
722 << " InputFileLow=\"" << sys.GetInputFileLow() << "\" "
723 << " HistoNameLow=\"" << sys.GetHistoNameLow() << "\" "
724 << " HistoPathLow=\"" << sys.GetHistoPathLow() << "\" "
725
726 << " InputFileHigh=\"" << sys.GetInputFileHigh() << "\" "
727 << " HistoNameHigh=\"" << sys.GetHistoNameHigh() << "\" "
728 << " HistoPathHigh=\"" << sys.GetHistoPathHigh() << "\" "
729 << " /> " << std::endl;
730 */
731 }
732 for (unsigned int i = 0; i < fShapeSysList.size(); ++i) {
733 ShapeSys sys = fShapeSysList.at(i);
734 sys.PrintXML(xml);
735 /*
736 xml << " <ShapeSys Name=\"" << sys.GetName() << "\" "
737
738 << " InputFile=\"" << sys.GetInputFile() << "\" "
739 << " HistoName=\"" << sys.GetHistoName() << "\" "
740 << " HistoPath=\"" << sys.GetHistoPath() << "\" "
741 << " ConstraintType=\"" << std::string(Constraint::Name(sys.GetConstraintType())) << "\" "
742 << " /> " << std::endl;
743 */
744 }
745 for (unsigned int i = 0; i < fShapeFactorList.size(); ++i) {
746 ShapeFactor sys = fShapeFactorList.at(i);
747 sys.PrintXML(xml);
748 /*
749 xml << " <ShapeFactor Name=\"" << sys.GetName() << "\" "
750 << " /> " << std::endl;
751 */
752 }
753
754 // Finally, close the tag
755 xml << " </Sample>" << std::endl;
756}
757
758// Some helper functions
759// (Not strictly necessary because
760// methods are publicly accessible)
761
763{
764
765 fStatError.Activate(true);
766 fStatError.SetUseHisto(false);
767}
768
769void Sample::ActivateStatError(std::string StatHistoName, std::string StatInputFile, std::string StatHistoPath)
770{
771
772 fStatError.Activate(true);
774
775 fStatError.SetInputFile(StatInputFile);
776 fStatError.SetHistoName(StatHistoName);
777 fStatError.SetHistoPath(StatHistoPath);
778}
779
780void Sample::AddOverallSys(std::string SysName, double SysLow, double SysHigh)
781{
782
783 OverallSys sys;
784 sys.SetName(SysName);
785 sys.SetLow(SysLow);
786 sys.SetHigh(SysHigh);
787
788 fOverallSysList.push_back(sys);
789}
790
792{
793 fOverallSysList.push_back(Sys);
794}
795
796void Sample::AddNormFactor(std::string const &SysName, double SysVal, double SysLow, double SysHigh)
797{
798
799 NormFactor norm;
800
801 norm.SetName(SysName);
802 norm.SetVal(SysVal);
803 norm.SetLow(SysLow);
804 norm.SetHigh(SysHigh);
805
806 fNormFactorList.push_back(norm);
807}
808
810{
811 fNormFactorList.push_back(Factor);
812}
813
814void Sample::AddHistoSys(std::string SysName, std::string SysHistoNameLow, std::string SysHistoFileLow,
815 std::string SysHistoPathLow, std::string SysHistoNameHigh, std::string SysHistoFileHigh,
816 std::string SysHistoPathHigh)
817{
818
819 HistoSys sys;
820 sys.SetName(SysName);
821
822 sys.SetHistoNameLow(SysHistoNameLow);
823 sys.SetHistoPathLow(SysHistoPathLow);
824 sys.SetInputFileLow(SysHistoFileLow);
825
826 sys.SetHistoNameHigh(SysHistoNameHigh);
827 sys.SetHistoPathHigh(SysHistoPathHigh);
828 sys.SetInputFileHigh(SysHistoFileHigh);
829
830 fHistoSysList.push_back(sys);
831}
832
834{
835 fHistoSysList.push_back(Sys);
836}
837
838void Sample::AddHistoFactor(std::string SysName, std::string SysHistoNameLow, std::string SysHistoFileLow,
839 std::string SysHistoPathLow, std::string SysHistoNameHigh, std::string SysHistoFileHigh,
840 std::string SysHistoPathHigh)
841{
842
843 HistoFactor factor;
844 factor.SetName(SysName);
845
846 factor.SetHistoNameLow(SysHistoNameLow);
847 factor.SetHistoPathLow(SysHistoPathLow);
848 factor.SetInputFileLow(SysHistoFileLow);
849
850 factor.SetHistoNameHigh(SysHistoNameHigh);
851 factor.SetHistoPathHigh(SysHistoPathHigh);
852 factor.SetInputFileHigh(SysHistoFileHigh);
853
854 fHistoFactorList.push_back(factor);
855}
856
858{
859 fHistoFactorList.push_back(Factor);
860}
861
862void Sample::AddShapeFactor(std::string SysName)
863{
864
865 fShapeFactorList.emplace_back();
866 fShapeFactorList.back().SetName(SysName);
867}
868
869void Sample::AddShapeFactor(std::string SysName, double Val, double Low, double High)
870{
871
872 fShapeFactorList.emplace_back();
873 fShapeFactorList.back().SetName(SysName);
874 fShapeFactorList.back().SetVal(Val);
875 fShapeFactorList.back().SetLow(Low);
876 fShapeFactorList.back().SetHigh(High);
877}
878
880{
881 fShapeFactorList.push_back(Factor);
882}
883
884void Sample::AddShapeSys(std::string SysName, Constraint::Type SysConstraintType, std::string SysHistoName,
885 std::string SysHistoFile, std::string SysHistoPath)
886{
887
888 ShapeSys sys;
889 sys.SetName(SysName);
890 sys.SetConstraintType(SysConstraintType);
891
892 sys.SetHistoName(SysHistoName);
893 sys.SetHistoPath(SysHistoPath);
894 sys.SetInputFile(SysHistoFile);
895
896 fShapeSysList.push_back(sys);
897}
898
900{
901 fShapeSysList.push_back(Sys);
902}
903
904////////////////////////////////////////////////////////////////////////////////
905/** \class RooStats::HistFactory::Channel
906 * \ingroup HistFactory
907 This class encapsulates all information for the statistical interpretation of one experiment.
908 It can be combined with other channels (e.g. for the combination of multiple experiments, or
909 to constrain nuisance parameters with information obtained in a control region).
910 A channel contains one or more samples which describe the contribution from different processes
911 to this measurement.
912*/
913
914Channel::Channel(std::string ChanName, std::string ChanInputFile) : fName(ChanName), fInputFile(ChanInputFile)
915{
916 // create channel with given name and input file
917}
918
919// BadChannel = Channel();
921// BadChannel.Name = "BadChannel"; // = Channel(); //.Name = "BadChannel";
922
924{
925 // add fully configured sample to channel
926
927 sample.SetChannelName(GetName());
928 fSamples.push_back(sample);
929}
930
931void Channel::Print(std::ostream &stream)
932{
933 // print information of channel to given stream
934
935 stream << "\t Channel Name: " << fName << "\t InputFile: " << fInputFile << std::endl;
936
937 stream << "\t Data:" << std::endl;
938 fData.Print(stream);
939
940 stream << "\t statErrorConfig:" << std::endl;
941 fStatErrorConfig.Print(stream);
942
943 if (!fSamples.empty()) {
944
945 stream << "\t Samples: " << std::endl;
946 for (unsigned int i = 0; i < fSamples.size(); ++i) {
947 fSamples.at(i).Print(stream);
948 }
949 }
950
951 stream << "\t End of Channel " << fName << std::endl;
952}
953
954void Channel::PrintXML(std::string const &directory, std::string const &prefix) const
955{
956
957 // Create an XML file for this channel
958 cxcoutPHF << "Printing XML Files for channel: " << GetName() << std::endl;
959
960 std::string XMLName = prefix + fName + ".xml";
961 if (!directory.empty())
962 XMLName = directory + "/" + XMLName;
963
964 std::ofstream xml(XMLName.c_str());
965
966 // Add the time
967 xml << "<!--" << std::endl;
968 xml << "This xml file created automatically on: " << std::endl;
969 // LM: use TTimeStamp since time_t does not work on Windows
970 TTimeStamp t;
971 UInt_t year = 0;
972 UInt_t month = 0;
973 UInt_t day = 0;
974 t.GetDate(true, 0, &year, &month, &day);
975 xml << year << '-' << month << '-' << day << std::endl;
976 xml << "-->" << std::endl;
977
978 // Add the DOCTYPE
979 xml << "<!DOCTYPE Channel SYSTEM 'HistFactorySchema.dtd'> " << std::endl << std::endl;
980
981 // Add the Channel
982 xml << " <Channel Name=\"" << fName << "\" InputFile=\"" << fInputFile << "\" >" << std::endl << std::endl;
983
984 fData.PrintXML(xml);
985 for (auto const &data : fAdditionalData) {
986 data.PrintXML(xml);
987 }
988
990 /*
991 xml << " <StatErrorConfig RelErrorThreshold=\"" << fStatErrorConfig.GetRelErrorThreshold() << "\" "
992 << "ConstraintType=\"" << Constraint::Name( fStatErrorConfig.GetConstraintType() ) << "\" "
993 << "/> " << std::endl << std::endl;
994 */
995
996 for (auto const &sample : fSamples) {
997 sample.PrintXML(xml);
998 xml << std::endl << std::endl;
999 }
1000
1001 xml << std::endl;
1002 xml << " </Channel> " << std::endl;
1003 xml.close();
1004
1005 cxcoutPHF << "Finished printing XML files" << std::endl;
1006}
1007
1008void Channel::SetData(std::string DataHistoName, std::string DataInputFile, std::string DataHistoPath)
1009{
1010 // set data for this channel by specifying the name of the histogram,
1011 // the external ROOT file and the path to the histogram inside the ROOT file
1012
1013 fData.SetHistoName(DataHistoName);
1014 fData.SetInputFile(DataInputFile);
1015 fData.SetHistoPath(DataHistoPath);
1016}
1017
1019{
1020 // set data directly to some histogram
1021 fData.SetHisto(hData);
1022}
1023
1024void Channel::SetData(double val)
1025{
1026
1027 // For a NumberCounting measurement only
1028 // Set the value of data in a particular channel
1029 //
1030 // Internally, this simply creates a 1-bin TH1F for you
1031
1032 std::string DataHistName = fName + "_data";
1033
1034 // Histogram has 1-bin (hard-coded)
1035 TH1F *hData = new TH1F(DataHistName.c_str(), DataHistName.c_str(), 1, 0, 1);
1036 hData->SetBinContent(1, val);
1037
1038 // Set the histogram of the internally held data
1039 // node of this channel to this newly created histogram
1040 SetData(hData);
1041}
1042
1043void Channel::SetStatErrorConfig(double StatRelErrorThreshold, Constraint::Type StatConstraintType)
1044{
1045
1046 fStatErrorConfig.SetRelErrorThreshold(StatRelErrorThreshold);
1047 fStatErrorConfig.SetConstraintType(StatConstraintType);
1048}
1049
1050void Channel::SetStatErrorConfig(double StatRelErrorThreshold, std::string StatConstraintType)
1051{
1052
1053 fStatErrorConfig.SetRelErrorThreshold(StatRelErrorThreshold);
1055}
1056
1058{
1059
1060 // Loop through all Samples and Systematics
1061 // and collect all necessary histograms
1062
1063 // Handles to open files for collecting histograms
1064 std::map<std::string, std::unique_ptr<TFile>> fileHandles;
1065
1066 // Get the Data Histogram:
1067
1068 if (!fData.GetInputFile().empty()) {
1070 }
1071
1072 // Collect any histograms for additional Datasets
1073 for (auto &data : fAdditionalData) {
1074 if (!data.GetInputFile().empty()) {
1075 data.SetHisto(GetHistogram(data.GetInputFile(), data.GetHistoPath(), data.GetHistoName(), fileHandles));
1076 }
1077 }
1078
1079 // Get the histograms for the samples:
1080 for (Sample &sample : fSamples) {
1081 // Get the nominal histogram:
1082 cxcoutDHF << "Collecting Nominal Histogram" << std::endl;
1083 TH1 *Nominal = GetHistogram(sample.GetInputFile(), sample.GetHistoPath(), sample.GetHistoName(), fileHandles);
1084
1085 sample.SetHisto(Nominal);
1086
1087 // Get the StatError Histogram (if necessary)
1088 if (sample.GetStatError().GetUseHisto()) {
1089 sample.GetStatError().SetErrorHist(GetHistogram(sample.GetStatError().GetInputFile(),
1090 sample.GetStatError().GetHistoPath(),
1091 sample.GetStatError().GetHistoName(), fileHandles));
1092 }
1093
1094 // Get the HistoSys Variations:
1095 for (HistoSys &histoSys : sample.GetHistoSysList()) {
1096 histoSys.SetHistoLow(GetHistogram(histoSys.GetInputFileLow(), histoSys.GetHistoPathLow(),
1097 histoSys.GetHistoNameLow(), fileHandles));
1098
1099 histoSys.SetHistoHigh(GetHistogram(histoSys.GetInputFileHigh(), histoSys.GetHistoPathHigh(),
1100 histoSys.GetHistoNameHigh(), fileHandles));
1101 } // End Loop over HistoSys
1102
1103 // Get the HistoFactor Variations:
1104 for (HistoFactor &histoFactor : sample.GetHistoFactorList()) {
1105 histoFactor.SetHistoLow(GetHistogram(histoFactor.GetInputFileLow(), histoFactor.GetHistoPathLow(),
1106 histoFactor.GetHistoNameLow(), fileHandles));
1107
1108 histoFactor.SetHistoHigh(GetHistogram(histoFactor.GetInputFileHigh(), histoFactor.GetHistoPathHigh(),
1109 histoFactor.GetHistoNameHigh(), fileHandles));
1110 } // End Loop over HistoFactor
1111
1112 // Get the ShapeSys Variations:
1113 for (ShapeSys &shapeSys : sample.GetShapeSysList()) {
1114 shapeSys.SetErrorHist(
1115 GetHistogram(shapeSys.GetInputFile(), shapeSys.GetHistoPath(), shapeSys.GetHistoName(), fileHandles));
1116 } // End Loop over ShapeSys
1117
1118 // Get any initial shape for a ShapeFactor
1119 for (ShapeFactor &shapeFactor : sample.GetShapeFactorList()) {
1120 // Check if we need an InitialShape
1121 if (shapeFactor.HasInitialShape()) {
1122 TH1 *hist = GetHistogram(shapeFactor.GetInputFile(), shapeFactor.GetHistoPath(), shapeFactor.GetHistoName(),
1123 fileHandles);
1124 shapeFactor.SetInitialShape(hist);
1125 }
1126
1127 } // End Loop over ShapeFactor
1128
1129 } // End Loop over Samples
1130}
1131
1133{
1134
1135 // Check that all internal histogram pointers
1136 // are properly configured (ie that they're not nullptr)
1137
1138 if (fData.GetHisto() == nullptr && !fData.GetInputFile().empty()) {
1139 cxcoutEHF << "Error: Data Histogram for channel " << GetName() << " is nullptr." << std::endl;
1140 return false;
1141 }
1142
1143 // Get the histograms for the samples:
1144 for (Sample const &sample : fSamples) {
1145 // Get the nominal histogram:
1146 if (sample.GetHisto() == nullptr) {
1147 cxcoutEHF << "Error: Nominal Histogram for sample " << sample.GetName() << " is nullptr." << std::endl;
1148 return false;
1149 } else {
1150
1151 // Check if any bins are negative
1152 std::vector<int> NegativeBinNumber;
1153 std::vector<double> NegativeBinContent;
1154 const TH1 *histNominal = sample.GetHisto();
1155 for (int ibin = 1; ibin <= histNominal->GetNbinsX(); ++ibin) {
1156 if (histNominal->GetBinContent(ibin) < 0) {
1157 NegativeBinNumber.push_back(ibin);
1158 NegativeBinContent.push_back(histNominal->GetBinContent(ibin));
1159 }
1160 }
1161 if (!NegativeBinNumber.empty()) {
1162 cxcoutWHF << "WARNING: Nominal Histogram " << histNominal->GetName() << " for Sample = " << sample.GetName()
1163 << " in Channel = " << GetName() << " has negative entries in bin numbers = ";
1164
1165 for (unsigned int ibin = 0; ibin < NegativeBinNumber.size(); ++ibin) {
1166 if (ibin > 0)
1167 std::cout << " , ";
1168 std::cout << NegativeBinNumber[ibin] << " : " << NegativeBinContent[ibin];
1169 }
1170 std::cout << std::endl;
1171 }
1172 }
1173
1174 // Get the StatError Histogram (if necessary)
1175 if (sample.GetStatError().GetUseHisto()) {
1176 if (sample.GetStatError().GetErrorHist() == nullptr) {
1177 cxcoutEHF << "Error: Statistical Error Histogram for sample " << sample.GetName() << " is nullptr."
1178 << std::endl;
1179 return false;
1180 }
1181 }
1182
1183 // Get the HistoSys Variations:
1184 for (const HistoSys &histoSys : sample.GetHistoSysList()) {
1185
1186 if (histoSys.GetHistoLow() == nullptr) {
1187 cxcoutEHF << "Error: HistoSyst Low for Systematic " << histoSys.GetName() << " in sample "
1188 << sample.GetName() << " is nullptr." << std::endl;
1189 return false;
1190 }
1191 if (histoSys.GetHistoHigh() == nullptr) {
1192 cxcoutEHF << "Error: HistoSyst High for Systematic " << histoSys.GetName() << " in sample "
1193 << sample.GetName() << " is nullptr." << std::endl;
1194 return false;
1195 }
1196
1197 } // End Loop over HistoSys
1198
1199 // Get the HistoFactor Variations:
1200 for (const HistoFactor &histoFactor : sample.GetHistoFactorList()) {
1201
1202 if (histoFactor.GetHistoLow() == nullptr) {
1203 cxcoutEHF << "Error: HistoSyst Low for Systematic " << histoFactor.GetName() << " in sample "
1204 << sample.GetName() << " is nullptr." << std::endl;
1205 return false;
1206 }
1207 if (histoFactor.GetHistoHigh() == nullptr) {
1208 cxcoutEHF << "Error: HistoSyst High for Systematic " << histoFactor.GetName() << " in sample "
1209 << sample.GetName() << " is nullptr." << std::endl;
1210 return false;
1211 }
1212
1213 } // End Loop over HistoFactor
1214
1215 // Get the ShapeSys Variations:
1216 for (const ShapeSys &shapeSys : sample.GetShapeSysList()) {
1217 if (shapeSys.GetErrorHist() == nullptr) {
1218 cxcoutEHF << "Error: HistoSyst High for Systematic " << shapeSys.GetName() << " in sample "
1219 << sample.GetName() << " is nullptr." << std::endl;
1220 return false;
1221 }
1222 } // End Loop over ShapeSys
1223
1224 } // End Loop over Samples
1225
1226 return true;
1227}
1228
1229/// Open a file and copy a histogram
1230/// \param InputFile File where the histogram resides.
1231/// \param HistoPath Path of the histogram in the file.
1232/// \param HistoName Name of the histogram to retrieve.
1233/// \param lsof List of open files. Helps to prevent opening and closing a file hundreds of times.
1234TH1 *Channel::GetHistogram(std::string InputFile, std::string HistoPath, std::string HistoName,
1235 std::map<std::string, std::unique_ptr<TFile>> &lsof)
1236{
1237
1238 cxcoutPHF << "Getting histogram " << InputFile << ":" << HistoPath << "/" << HistoName << std::endl;
1239
1240 auto &inFile = lsof[InputFile];
1241 if (!inFile || !inFile->IsOpen()) {
1242 inFile.reset(TFile::Open(InputFile.c_str()));
1243 if (!inFile || !inFile->IsOpen()) {
1244 cxcoutEHF << "Error: Unable to open input file: " << InputFile << std::endl;
1245 throw hf_exc();
1246 }
1247 cxcoutIHF << "Opened input file: " << InputFile << ": " << std::endl;
1248 }
1249
1250 TDirectory *dir = inFile->GetDirectory(HistoPath.c_str());
1251 if (dir == nullptr) {
1252 cxcoutEHF << "Histogram path '" << HistoPath << "' wasn't found in file '" << InputFile << "'." << std::endl;
1253 throw hf_exc();
1254 }
1255
1256 // Have to read histograms via keys, to ensure that the latest-greatest
1257 // name cycle is read from file. Otherwise, they might come from memory.
1258 auto key = dir->GetKey(HistoName.c_str());
1259 if (key == nullptr) {
1260 cxcoutEHF << "Histogram '" << HistoName << "' wasn't found in file '" << InputFile << "' in directory '"
1261 << HistoPath << "'." << std::endl;
1262 throw hf_exc();
1263 }
1264
1265 std::unique_ptr<TH1> hist(key->ReadObject<TH1>());
1266 if (!hist) {
1267 cxcoutEHF << "Histogram '" << HistoName << "' wasn't found in file '" << InputFile << "' in directory '"
1268 << HistoPath << "'." << std::endl;
1269 throw hf_exc();
1270 }
1271
1272 TDirectory::TContext ctx{nullptr};
1273 TH1 *ptr = static_cast<TH1 *>(hist->Clone());
1274
1275 if (!ptr) {
1276 std::cerr << "Not all necessary info are set to access the input file. Check your config" << std::endl;
1277 std::cerr << "filename: " << InputFile << "path: " << HistoPath << "obj: " << HistoName << std::endl;
1278 throw hf_exc();
1279 }
1280
1281#ifdef DEBUG
1282 std::cout << "Found Histogram: " << HistoName " at address: " << ptr << " with integral " << ptr->Integral()
1283 << " and mean " << ptr->GetMean() << std::endl;
1284#endif
1285
1286 // Done
1287 return ptr;
1288}
1289
1290////////////////////////////////////////////////////////////////////////////////
1291/** \class RooStats::HistFactory::Data
1292 * \ingroup HistFactory
1293 */
1294
1295Data::Data(std::string HistoName, std::string InputFile, std::string HistoPath)
1296 : fInputFile(InputFile), fHistoName(HistoName), fHistoPath(HistoPath)
1297{
1298}
1299
1301{
1302 return (TH1 *)fhData.GetObject();
1303}
1304
1305const TH1 *Data::GetHisto() const
1306{
1307 return (TH1 *)fhData.GetObject();
1308}
1309
1310void Data::Print(std::ostream &stream)
1311{
1312
1313 stream << "\t \t InputFile: " << fInputFile << "\t HistoName: " << fHistoName << "\t HistoPath: " << fHistoPath
1314 << "\t HistoAddress: " << GetHisto() << std::endl;
1315}
1316
1317void Data::writeToFile(std::string OutputFileName, std::string DirName)
1318{
1319
1320 TH1 *histData = GetHisto();
1321
1322 if (histData != nullptr) {
1323
1324 histData->Write();
1325
1326 // Set the location of the data
1327 // in the output measurement
1328
1329 fInputFile = OutputFileName;
1330 fHistoName = histData->GetName();
1331 fHistoPath = DirName;
1332 }
1333}
1334
1335void Data::PrintXML(std::ostream &xml) const
1336{
1337
1338 xml << " <Data HistoName=\"" << GetHistoName() << "\" "
1339 << "InputFile=\"" << GetInputFile() << "\" "
1340 << "HistoPath=\"" << GetHistoPath() << "\" ";
1341 if (!GetName().empty()) {
1342 xml << "Name=\"" << GetName() << "\" ";
1343 }
1344 xml << " /> " << std::endl << std::endl;
1345}
1346
1347////////////////////////////////////////////////////////////////////////////////
1348/**
1349 * \ingroup HistFactory
1350 */
1351
1352namespace {
1353
1354/// Replaces the XML special characters with their escape codes.
1355std::string escapeXML(const std::string &src)
1356{
1357 std::stringstream dst;
1358 for (char ch : src) {
1359 switch (ch) {
1360 case '&': dst << "&amp;"; break;
1361 case '\'': dst << "&apos;"; break;
1362 case '"': dst << "&quot;"; break;
1363 case '<': dst << "&lt;"; break;
1364 case '>': dst << "&gt;"; break;
1365 default: dst << ch; break;
1366 }
1367 }
1368 return dst.str();
1369}
1370
1371} // namespace
1372
1373PreprocessFunction::PreprocessFunction(std::string const &name, std::string const &expression,
1374 std::string const &dependents)
1375 : fName(name), fExpression(expression), fDependents(dependents)
1376{
1377}
1378
1380{
1381 return "expr::" + fName + "('" + fExpression + "',{" + fDependents + "})";
1382}
1383
1384void PreprocessFunction::Print(std::ostream &stream) const
1385{
1386 stream << "\t \t Name: " << fName << "\t \t Expression: " << fExpression << "\t \t Dependents: " << fDependents
1387 << std::endl;
1388}
1389
1390void PreprocessFunction::PrintXML(std::ostream &xml) const
1391{
1392 xml << "<Function Name=\"" << fName << "\" "
1393 << "Expression=\"" << escapeXML(fExpression) << "\" "
1394 << "Dependents=\"" << fDependents << "\" "
1395 << "/>\n";
1396}
1397
1398////////////////////////////////////////////////////////////////////////////////
1399/** \class RooStats::HistFactory::Asimov
1400 * \ingroup HistFactory
1401 * TODO Here, we are missing some documentation.
1402 */
1403
1405{
1406
1407 // Here is where we set the values, and constantness
1408 // of all parameters in the workspace before creating
1409 // an asimov dataset
1410
1411 /*
1412 // Okay, y'all, first we're going to create a snapshot
1413 // of the current state of the variables in the workspace
1414
1415 std::string ListOfVariableNames = "";
1416 for( std::map< std::string, double >::iterator itr = fParamValsToSet.begin();
1417 itr != fParamValsToSet.end(); ++itr) {
1418 // Extend the Variable Name list
1419 ListOfVariableNames += "," + itr->first;
1420 }
1421 for( std::map< std::string, bool >::iterator itr = fParamsToFix.begin();
1422 itr != fParamsToFix.end(); ++itr) {
1423 // Extend the Variable Name list
1424 ListOfVariableNames += "," + itr->first;
1425 }
1426
1427 // Save a snapshot
1428 std::string SnapShotName = "NominalParamValues";
1429 wspace->saveSnapshot(SnapShotName.c_str(), ListOfVariableNames.c_str());
1430 */
1431
1432 //
1433 // First we set all parameters to their given values
1434 //
1435
1436 for (std::map<std::string, double>::iterator itr = fParamValsToSet.begin(); itr != fParamValsToSet.end(); ++itr) {
1437
1438 std::string param = itr->first;
1439 double val = itr->second;
1440
1441 // Try to get the variable in the workspace
1442 RooRealVar *var = wspace->var(param);
1443 if (!var) {
1444 std::cout << "Error: Trying to set variable: " << var
1445 << " to a specific value in creation of asimov dataset: " << fName
1446 << " but this variable doesn't appear to exist in the workspace" << std::endl;
1447 throw hf_exc();
1448 }
1449
1450 // Check that the desired value is in the range of the variable
1451 double inRange = var->inRange(val, nullptr);
1452 if (!inRange) {
1453 std::cout << "Error: Attempting to set variable: " << var << " to value: " << val << ", however it appears"
1454 << " that this is not withn the variable's range: "
1455 << "[" << var->getMin() << ", " << var->getMax() << "]" << std::endl;
1456 throw hf_exc();
1457 }
1458
1459 // Set its value
1460 std::cout << "Configuring Asimov Dataset: Setting " << param << " = " << val << std::endl;
1461 var->setVal(val);
1462 }
1463
1464 //
1465 // Then, we set any variables to constant
1466 //
1467
1468 for (auto &[param, isConstant] : fParamsToFix) {
1469
1470 // Try to get the variable in the workspace
1471 RooRealVar *var = wspace->var(param);
1472 if (!var) {
1473 std::cout << "Error: Trying to set variable: " << var << " constant in creation of asimov dataset: " << fName
1474 << " but this variable doesn't appear to exist in the workspace" << std::endl;
1475 throw hf_exc();
1476 }
1477
1478 std::cout << "Configuring Asimov Dataset: Setting " << param << " to constant " << std::endl;
1479 var->setConstant(isConstant);
1480 }
1481}
1482
1483/** \class RooStats::HistFactory::HistRef
1484 * \ingroup HistFactory
1485 * Internal class wrapping an histogram and managing its content.
1486 * convenient for dealing with histogram pointers in the
1487 * HistFactory class
1488 */
1489
1490/// constructor - use gives away ownerhip of the given pointer
1492
1494{
1495 if (other.fHist)
1496 fHist.reset(CopyObject(other.fHist.get()));
1497}
1498
1499HistRef::HistRef(HistRef &&other) : fHist(std::move(other.fHist)) {}
1500
1501HistRef::~HistRef() = default;
1502
1503/// assignment operator (delete previous contained histogram)
1505{
1506 if (this == &other)
1507 return *this;
1508
1509 fHist.reset(CopyObject(other.fHist.get()));
1510 return *this;
1511}
1512
1514{
1515 fHist = std::move(other.fHist);
1516 return *this;
1517}
1518
1520{
1521 // implementation of method copying the contained pointer
1522 // (just use Clone)
1523 if (!h)
1524 return nullptr;
1525
1526 TDirectory::TContext ctx{nullptr}; // Don't associate histogram with currently open file
1527 return static_cast<TH1 *>(h->Clone());
1528}
1529
1531{
1532 return fHist.get();
1533}
1534
1535/// set the object - user gives away the ownerhisp
1537{
1538 fHist.reset(h);
1539}
1540
1541/// operator= passing an object pointer : user gives away its ownerhisp
1543{
1544 SetObject(h);
1545}
1546
1547/// Release ownership of object.
1549{
1550 return fHist.release();
1551}
1552
1553// Constraints
1555{
1556
1558 return "Gaussian";
1560 return "Poisson";
1561 return "";
1562}
1563
1565{
1566
1567 if (Name.empty()) {
1568 std::cout << "Error: Given empty name for ConstraintType" << std::endl;
1569 throw hf_exc();
1570 }
1571
1572 else if (Name == "Gaussian" || Name == "Gauss") {
1573 return Constraint::Gaussian;
1574 }
1575
1576 else if (Name == "Poisson" || Name == "Pois") {
1577 return Constraint::Poisson;
1578 }
1579
1580 else {
1581 std::cout << "Error: Unknown name given for Constraint Type: " << Name << std::endl;
1582 throw hf_exc();
1583 }
1584}
1585
1586void NormFactor::Print(std::ostream &stream) const
1587{
1588 stream << "\t \t Name: " << fName << "\t Val: " << fVal << "\t Low: " << fLow << "\t High: " << fHigh << std::endl;
1589}
1590
1591void NormFactor::PrintXML(std::ostream &xml) const
1592{
1593 xml << " <NormFactor Name=\"" << GetName() << "\" "
1594 << " Val=\"" << GetVal() << "\" "
1595 << " High=\"" << GetHigh() << "\" "
1596 << " Low=\"" << GetLow() << "\" "
1597 << " /> " << std::endl;
1598}
1599
1600void OverallSys::Print(std::ostream &stream) const
1601{
1602 stream << "\t \t Name: " << fName << "\t Low: " << fLow << "\t High: " << fHigh << std::endl;
1603}
1604
1605void OverallSys::PrintXML(std::ostream &xml) const
1606{
1607 xml << " <OverallSys Name=\"" << GetName() << "\" "
1608 << " High=\"" << GetHigh() << "\" "
1609 << " Low=\"" << GetLow() << "\" "
1610 << " /> " << std::endl;
1611}
1612
1614
1616 : fName(Name), fhLow(nullptr), fhHigh(nullptr)
1617{
1618}
1619
1621
1623
1625
1626void HistogramUncertaintyBase::Print(std::ostream &stream) const
1627{
1628 stream << "\t \t Name: " << fName << "\t HistoFileLow: " << fInputFileLow << "\t HistoNameLow: " << fHistoNameLow
1629 << "\t HistoPathLow: " << fHistoPathLow << "\t HistoFileHigh: " << fInputFileHigh
1630 << "\t HistoNameHigh: " << fHistoNameHigh << "\t HistoPathHigh: " << fHistoPathHigh << std::endl;
1631}
1632
1633void HistogramUncertaintyBase::writeToFile(const std::string &FileName, const std::string &DirName)
1634{
1635
1636 // This saves the histograms to a file and
1637 // changes the name of the local file and histograms
1638
1639 auto histLow = GetHistoLow();
1640 if (histLow == nullptr) {
1641 std::cout << "Error: Cannot write " << GetName() << " to file: " << FileName << " HistoLow is nullptr"
1642 << std::endl;
1643 throw hf_exc();
1644 }
1645 histLow->Write();
1646 fInputFileLow = FileName;
1647 fHistoPathLow = DirName;
1648 fHistoNameLow = histLow->GetName();
1649
1650 auto histHigh = GetHistoHigh();
1651 if (histHigh == nullptr) {
1652 std::cout << "Error: Cannot write " << GetName() << " to file: " << FileName << " HistoHigh is nullptr"
1653 << std::endl;
1654 throw hf_exc();
1655 }
1656 histHigh->Write();
1657 fInputFileHigh = FileName;
1658 fHistoPathHigh = DirName;
1659 fHistoNameHigh = histHigh->GetName();
1660}
1661
1662void HistoSys::PrintXML(std::ostream &xml) const
1663{
1664 xml << " <HistoSys Name=\"" << GetName() << "\" "
1665 << " HistoFileLow=\"" << GetInputFileLow() << "\" "
1666 << " HistoNameLow=\"" << GetHistoNameLow() << "\" "
1667 << " HistoPathLow=\"" << GetHistoPathLow() << "\" "
1668
1669 << " HistoFileHigh=\"" << GetInputFileHigh() << "\" "
1670 << " HistoNameHigh=\"" << GetHistoNameHigh() << "\" "
1671 << " HistoPathHigh=\"" << GetHistoPathHigh() << "\" "
1672 << " /> " << std::endl;
1673}
1674
1676{
1677 fhHigh.reset(hError);
1678}
1679
1680void ShapeSys::Print(std::ostream &stream) const
1681{
1682 stream << "\t \t Name: " << fName << "\t InputFile: " << fInputFileHigh << "\t HistoName: " << fHistoNameHigh
1683 << "\t HistoPath: " << fHistoPathHigh << std::endl;
1684}
1685
1686void ShapeSys::PrintXML(std::ostream &xml) const
1687{
1688 xml << " <ShapeSys Name=\"" << GetName() << "\" "
1689 << " InputFile=\"" << GetInputFile() << "\" "
1690 << " HistoName=\"" << GetHistoName() << "\" "
1691 << " HistoPath=\"" << GetHistoPath() << "\" "
1692 << " ConstraintType=\"" << std::string(Constraint::Name(GetConstraintType())) << "\" "
1693 << " /> " << std::endl;
1694}
1695
1696void ShapeSys::writeToFile(const std::string &FileName, const std::string &DirName)
1697{
1698 auto histError = GetErrorHist();
1699 if (histError == nullptr) {
1700 std::cout << "Error: Cannot write " << GetName() << " to file: " << FileName << " ErrorHist is nullptr"
1701 << std::endl;
1702 throw hf_exc();
1703 }
1704 histError->Write();
1705 fInputFileHigh = FileName;
1706 fHistoPathHigh = DirName;
1707 fHistoNameHigh = histError->GetName();
1708}
1709
1710void HistoFactor::PrintXML(std::ostream &xml) const
1711{
1712 xml << " <HistoFactor Name=\"" << GetName() << "\" "
1713
1714 << " InputFileLow=\"" << GetInputFileLow() << "\" "
1715 << " HistoNameLow=\"" << GetHistoNameLow() << "\" "
1716 << " HistoPathLow=\"" << GetHistoPathLow() << "\" "
1717
1718 << " InputFileHigh=\"" << GetInputFileHigh() << "\" "
1719 << " HistoNameHigh=\"" << GetHistoNameHigh() << "\" "
1720 << " HistoPathHigh=\"" << GetHistoPathHigh() << "\" "
1721 << " /> " << std::endl;
1722}
1723
1725{
1726 fhHigh.reset(shape);
1727}
1728
1729void ShapeFactor::Print(std::ostream &stream) const
1730{
1731
1732 stream << "\t \t Name: " << fName << std::endl;
1733
1734 if (!fHistoNameHigh.empty()) {
1735 stream << "\t \t "
1736 << " Shape Hist Name: " << fHistoNameHigh << " Shape Hist Path Name: " << fHistoPathHigh
1737 << " Shape Hist FileName: " << fInputFileHigh << std::endl;
1738 }
1739 // Print value and range in RooRealVar style
1740 stream << "\t \t Value: " << GetVal() << " L(" << GetLow() << " - " << GetHigh() << ")\n";
1741
1742 if (fConstant) {
1743 stream << "\t \t ( Constant ): " << std::endl;
1744 }
1745}
1746
1747void ShapeFactor::writeToFile(const std::string &FileName, const std::string &DirName)
1748{
1749
1750 if (HasInitialShape()) {
1751 auto histInitialShape = GetInitialShape();
1752 if (histInitialShape == nullptr) {
1753 std::cout << "Error: Cannot write " << GetName() << " to file: " << FileName << " InitialShape is nullptr"
1754 << std::endl;
1755 throw hf_exc();
1756 }
1757 histInitialShape->Write();
1758 fInputFileHigh = FileName;
1759 fHistoPathHigh = DirName;
1760 fHistoNameHigh = histInitialShape->GetName();
1761 }
1762}
1763
1764void ShapeFactor::PrintXML(std::ostream &xml) const
1765{
1766 xml << " <ShapeFactor Name=\"" << GetName() << "\" ";
1767 if (fHasInitialShape) {
1768 xml << " InputFile=\"" << GetInputFile() << "\" "
1769 << " HistoName=\"" << GetHistoName() << "\" "
1770 << " HistoPath=\"" << GetHistoPath() << "\" ";
1771 }
1772 xml << " Val=\"" << GetVal() << "\" "
1773 << " High=\"" << GetHigh() << "\" "
1774 << " Low=\"" << GetLow() << "\" "
1775 << " Const=\"" << (IsConstant() ? std::string("True") : std::string("False")) << "\" ";
1776 xml << " /> " << std::endl;
1777}
1778
1780{
1781 fhHigh.reset(Error);
1782}
1783
1784void StatErrorConfig::Print(std::ostream &stream) const
1785{
1786 stream << "\t \t RelErrorThreshold: " << fRelErrorThreshold
1787 << "\t ConstraintType: " << Constraint::Name(fConstraintType) << std::endl;
1788}
1789
1790void StatErrorConfig::PrintXML(std::ostream &xml) const
1791{
1792 xml << " <StatErrorConfig RelErrorThreshold=\"" << GetRelErrorThreshold() << "\" "
1793 << "ConstraintType=\"" << Constraint::Name(GetConstraintType()) << "\" "
1794 << "/> " << std::endl
1795 << std::endl;
1796}
1797
1798void StatError::Print(std::ostream &stream) const
1799{
1800 stream << "\t \t Activate: " << fActivate << "\t InputFile: " << fInputFileHigh << "\t HistoName: " << fHistoNameHigh
1801 << "\t histoPath: " << fHistoPathHigh << std::endl;
1802}
1803
1804void StatError::PrintXML(std::ostream &xml) const
1805{
1806
1807 if (GetActivate()) {
1808 xml << " <StatError Activate=\"" << (GetActivate() ? std::string("True") : std::string("False")) << "\" "
1809 << " InputFile=\"" << GetInputFile() << "\" "
1810 << " HistoName=\"" << GetHistoName() << "\" "
1811 << " HistoPath=\"" << GetHistoPath() << "\" "
1812 << " /> " << std::endl;
1813 }
1814}
1815
1816void StatError::writeToFile(const std::string &OutputFileName, const std::string &DirName)
1817{
1818
1819 if (fUseHisto) {
1820
1821 std::string statErrorHistName = "statisticalErrors";
1822
1823 auto hStatError = GetErrorHist();
1824 if (hStatError == nullptr) {
1825 std::cout << "Error: Stat Error error hist is nullptr" << std::endl;
1826 throw hf_exc();
1827 }
1828 hStatError->Write(statErrorHistName.c_str());
1829
1830 fInputFileHigh = OutputFileName;
1831 fHistoNameHigh = statErrorHistName;
1832 fHistoPathHigh = DirName;
1833 }
1834}
1835
1837 : fName{oth.fName},
1838 fInputFileLow{oth.fInputFileLow},
1839 fHistoNameLow{oth.fHistoNameLow},
1840 fHistoPathLow{oth.fHistoPathLow},
1841 fInputFileHigh{oth.fInputFileHigh},
1842 fHistoNameHigh{oth.fHistoNameHigh},
1843 fHistoPathHigh{oth.fHistoPathHigh},
1844 fhLow{oth.fhLow ? static_cast<TH1 *>(oth.fhLow->Clone()) : nullptr},
1845 fhHigh{oth.fhHigh ? static_cast<TH1 *>(oth.fhHigh->Clone()) : nullptr}
1846{
1847 if (fhLow)
1848 fhLow->SetDirectory(nullptr);
1849 if (fhHigh)
1850 fhHigh->SetDirectory(nullptr);
1851}
1852
1854{
1855 fName = oth.fName;
1862
1863 TDirectory::TContext ctx{nullptr}; // Don't associate clones to directories
1864 fhLow.reset(oth.fhLow ? static_cast<TH1 *>(oth.fhLow->Clone()) : nullptr);
1865 fhHigh.reset(oth.fhHigh ? static_cast<TH1 *>(oth.fhHigh->Clone()) : nullptr);
1866
1867 return *this;
1868}
1869
1871{
1872 Low->SetDirectory(nullptr);
1873 fhLow.reset(Low);
1874}
1875
1877{
1878 High->SetDirectory(nullptr);
1879 fhHigh.reset(High);
1880}
1881
1883{
1884 fhData = Hist;
1885 fHistoName = Hist->GetName();
1886}
1887
1889{
1890 fhNominal = histo;
1891 fHistoName = histo->GetName();
1892}
1893
1894} // namespace RooStats::HistFactory
#define cxcoutPHF
#define cxcoutDHF
#define cxcoutIHF
#define cxcoutWHF
#define cxcoutEHF
#define h(i)
Definition RSha256.hxx:106
double * dst
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:142
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
void SetName(const std::string &Name)
Definition Measurement.h:63
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.
void SetChannelName(const std::string &ChannelName)
set name of associated channel
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 TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory using apath.
virtual const char * GetPath() const
Returns the full path of the directory.
virtual Bool_t cd()
Change current directory to "this" directory.
virtual TKey * GetKey(const char *, Short_t=9999) const
Definition TDirectory.h:222
virtual TDirectory * mkdir(const char *name, const char *title="", Bool_t returnExistingDirectory=kFALSE)
Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".
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:1166
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:3802
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:9170
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:7744
virtual Int_t GetNbinsX() const
Definition TH1.h:541
virtual Double_t Integral(Option_t *option="") const
Return integral of bin contents.
Definition TH1.cxx:8170
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
Definition TH1.cxx:9452
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:5239
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition TObject.cxx:987
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition TSystem.cxx:860
virtual void * OpenDirectory(const char *name)
Open a directory.
Definition TSystem.cxx:851
virtual int MakeDirectory(const char *name)
Make a directory.
Definition TSystem.cxx:841
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)