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