40 : fLumi(1.0), fLumiRelErr(.10), fBinLow(0), fBinHigh(1), fExportOnly(false)
55 :
TNamed(Name, Title), fLumi(1.0), fLumiRelErr(.10), fBinLow(0), fBinHigh(1), fExportOnly(false)
73 if( std::find(fConstantParams.begin(), fConstantParams.end(), param) != fConstantParams.end() ) {
74 cxcoutWHF <<
"Warning: Setting parameter: " << param
75 <<
" to constant, but it is already listed as constant. "
76 <<
"You may ignore this warning."
81 fConstantParams.push_back( param );
93 if( fParamValues.find(param) != fParamValues.end() ) {
94 cxcoutWHF <<
"Warning: Chainging parameter: " << param
95 <<
" value from: " << fParamValues[param]
101 cxcoutIHF <<
"Setting parameter: " << param
102 <<
" value to " <<
value
105 fParamValues[param] =
value;
117 AddFunctionObject(func);
126 std::vector<std::string> PreprocessFunctionExpressions;
127 for(
unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
128 std::string expression = fFunctionObjects.at(i).GetCommand();
129 PreprocessFunctionExpressions.push_back( expression );
131 return PreprocessFunctionExpressions;
137 fGammaSyst[syst] = uncert;
143 fLogNormSyst[syst] = uncert;
149 fUniformSyst[syst] = 1.0;
163 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
165 Channel& chan = fChannels.at(i);
166 if( chan.
GetName() == ChanName ) {
181 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
183 Channel& chan = fChannels.at(i);
184 if( chan.
GetName() == ChanName ) {
192 cxcoutEHF <<
"Error: Did not find channel: " << ChanName
193 <<
" in measurement: " << GetName() << std::endl;
214 stream <<
"Measurement Name: " << GetName()
215 <<
"\t OutputFilePrefix: " << fOutputFilePrefix
217 for(
unsigned int i = 0; i < fPOI.size(); ++i) {
218 stream << fPOI.at(i);
220 stream <<
"\t Lumi: " << fLumi
221 <<
"\t LumiRelErr: " << fLumiRelErr
222 <<
"\t BinLow: " << fBinLow
223 <<
"\t BinHigh: " << fBinHigh
224 <<
"\t ExportOnly: " << fExportOnly
228 if( !fConstantParams.empty() ) {
229 stream <<
"Constant Params: ";
230 for(
unsigned int i = 0; i < fConstantParams.size(); ++i ) {
231 stream <<
" " << fConstantParams.at(i);
236 if( !fFunctionObjects.empty() ) {
237 stream <<
"Preprocess Functions: ";
238 for(
unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
239 stream <<
" " << fFunctionObjects.at(i).GetCommand();
244 if( !fChannels.empty() ) {
245 stream <<
"Channels:" << std::endl;
246 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
247 fChannels.at(i).Print( stream );
251 cxcoutIHF <<
"End Measurement: " << GetName() << std::endl;
264 auto testExists = [](
const std::string& theDirectory) {
266 bool exists = dir !=
nullptr;
273 if ( !directory.empty() && !testExists(directory) ) {
276 cxcoutEHF <<
"Error: Failed to make directory: " << directory << std::endl;
283 cxcoutPHF <<
"Printing XML Files for measurement: " << GetName() << std::endl;
285 std::string XMLName = std::string(GetName()) +
".xml";
286 if( !directory.empty() ) XMLName = directory +
"/" + XMLName;
288 ofstream xml( XMLName.c_str() );
290 if( ! xml.is_open() ) {
291 cxcoutEHF <<
"Error opening xml file: " << XMLName << std::endl;
297 xml <<
"<!--" << std::endl;
298 xml <<
"This xml file created automatically on: " << std::endl;
312 t.
GetDate(
true, 0, &year, &month, &day);
318 xml <<
"-->" << std::endl;
321 xml <<
"<!DOCTYPE Combination SYSTEM 'HistFactorySchema.dtd'>" << std::endl << std::endl;
324 if (newOutputPrefix.empty() ) newOutputPrefix = fOutputFilePrefix;
325 xml <<
"<Combination OutputFilePrefix=\"" << newOutputPrefix <<
"\" >" << std::endl << std::endl;
328 for(
unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
342 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
343 xml <<
" <Input>" <<
"./";
344 if (!directory.empty() ) xml << directory <<
"/";
345 xml << GetName() <<
"_" << fChannels.at(i).GetName() <<
".xml" <<
"</Input>" << std::endl;
351 xml <<
" <Measurement Name=\"" << GetName() <<
"\" "
352 <<
"Lumi=\"" << fLumi <<
"\" "
353 <<
"LumiRelErr=\"" << fLumiRelErr <<
"\" "
356 <<
"ExportOnly=\"" << (fExportOnly ? std::string(
"True") : std::string(
"False")) <<
"\" "
357 <<
" >" << std::endl;
362 for(
unsigned int i = 0; i < fPOI.size(); ++i) {
363 if(i==0) xml << fPOI.at(i);
364 else xml <<
" " << fPOI.at(i);
366 xml <<
"</POI> " << std::endl;
369 if(!fConstantParams.empty()) {
370 xml <<
" <ParamSetting Const=\"True\">";
371 for(
unsigned int i = 0; i < fConstantParams.size(); ++i ) {
372 if (i==0) xml << fConstantParams.at(i);
373 else xml <<
" " << fConstantParams.at(i);;
375 xml <<
"</ParamSetting>" << std::endl;
379 std::map<std::string, double>::iterator ConstrItr;
382 for( ConstrItr = fGammaSyst.begin(); ConstrItr != fGammaSyst.end(); ++ConstrItr ) {
383 xml <<
"<ConstraintTerm Type=\"Gamma\" RelativeUncertainty=\""
384 << ConstrItr->second <<
"\">" << ConstrItr->first
385 <<
"</ConstraintTerm>" << std::endl;
388 for( ConstrItr = fUniformSyst.begin(); ConstrItr != fUniformSyst.end(); ++ConstrItr ) {
389 xml <<
"<ConstraintTerm Type=\"Uniform\" RelativeUncertainty=\""
390 << ConstrItr->second <<
"\">" << ConstrItr->first
391 <<
"</ConstraintTerm>" << std::endl;
394 for( ConstrItr = fLogNormSyst.begin(); ConstrItr != fLogNormSyst.end(); ++ConstrItr ) {
395 xml <<
"<ConstraintTerm Type=\"LogNormal\" RelativeUncertainty=\""
396 << ConstrItr->second <<
"\">" << ConstrItr->first
397 <<
"</ConstraintTerm>" << std::endl;
400 for( ConstrItr = fNoSyst.begin(); ConstrItr != fNoSyst.end(); ++ConstrItr ) {
401 xml <<
"<ConstraintTerm Type=\"NoSyst\" RelativeUncertainty=\""
402 << ConstrItr->second <<
"\">" << ConstrItr->first
403 <<
"</ConstraintTerm>" << std::endl;
408 xml <<
" </Measurement> " << std::endl << std::endl;
411 xml <<
"</Combination>" << std::endl;
418 std::string prefix = std::string(GetName()) +
"_";
420 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
421 fChannels.at(i).PrintXML( directory, prefix );
425 cxcoutPHF <<
"Finished printing XML files" << std::endl;
446 std::string OutputFileName = file->
GetName();
452 for(
unsigned int chanItr = 0; chanItr < outMeas.
fChannels.size(); ++chanItr ) {
461 std::string chanName = channel.
GetName();
465 cxcoutEHF <<
"Measurement.writeToFile(): Channel: " << chanName
466 <<
" has uninitialized histogram pointers" << std::endl;
480 if( chanDir ==
nullptr ) {
481 cxcoutEHF <<
"Error: Cannot create channel " << (chanName +
"_hists")
489 if( dataDir ==
nullptr ) {
490 cxcoutEHF <<
"Error: Cannot make directory " << chanDir << std::endl;
512 for(
unsigned int sampItr = 0; sampItr < channel.
GetSamples().
size(); ++sampItr ) {
515 std::string sampName = sample.
GetName();
517 cxcoutPHF <<
"Writing sample: " << sampName << std::endl;
522 if( sampleDir ==
nullptr ) {
523 cxcoutEHF <<
"Error: Directory " << sampName <<
" not created properly" << std::endl;
526 std::string sampleDirPath = GetDirPath( sampleDir );
529 cxcoutEHF <<
"Error making directory: " << sampName
530 <<
" in directory: " << chanName
538 sample.
writeToFile( OutputFileName, sampleDirPath );
600 cxcoutPHF <<
"Saved all histograms" << std::endl;
605 cxcoutPHF <<
"Saved Measurement" << std::endl;
615 std::string path = dir->
GetPath();
617 if( path.find(
':') != std::string::npos ) {
618 size_t index = path.find(
':');
619 path.replace( 0,
index+1,
"" );
649 for(
unsigned int chanItr = 0; chanItr < fChannels.size(); ++chanItr) {
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
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
R__EXTERN TSystem * gSystem
This class encapsulates all information for the statistical interpretation of one experiment.
bool CheckHistograms() const
std::vector< RooStats::HistFactory::Sample > & GetSamples()
get vector of samples for this channel
std::string GetName() const
get name of channel
void writeToFile(std::string FileName, std::string DirName)
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.
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.
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.
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 SetParamValue(const std::string ¶m, double value)
Set a parameter to a specific value (And optionally fix it)
void CollectHistograms()
The most common way to add histograms to channels is to have them stored in ROOT files and to give Hi...
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 ¶m)
Add a parameter to be set as constant (Similar to ParamSetting method below)
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::vector< RooStats::HistFactory::Channel > fChannels
Channels that make up this measurement.
void PrintXML(std::ostream &) const
std::string GetName() const
get name of sample
void writeToFile(std::string FileName, std::string DirName)
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/...".
Describe directory structure in memory.
virtual const char * GetPath() const
Returns the full path of the directory.
virtual Bool_t cd()
Change current directory to "this" directory.
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 ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
virtual void Flush()
Synchronize a file's in-memory and on-disk states.
The TNamed class is the base class for all named ROOT classes.
const char * GetName() const override
Returns name of object.
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
virtual void FreeDirectory(void *dirp)
Free a directory.
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
virtual int MakeDirectory(const char *name)
Make a directory.
The TTimeStamp encapsulates seconds and ns since EPOCH.
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.