41 : fLumi(1.0), fLumiRelErr(.10), fBinLow(0), fBinHigh(1), fExportOnly(false)
56 :
TNamed(Name, Title), fLumi(1.0), fLumiRelErr(.10), fBinLow(0), fBinHigh(1), fExportOnly(false)
74 if( std::find(fConstantParams.begin(), fConstantParams.end(), param) != fConstantParams.end() ) {
75 cxcoutWHF <<
"Warning: Setting parameter: " << param
76 <<
" to constant, but it is already listed as constant. "
77 <<
"You may ignore this warning."
82 fConstantParams.push_back( param );
94 if( fParamValues.find(param) != fParamValues.end() ) {
95 cxcoutWHF <<
"Warning: Chainging parameter: " << param
96 <<
" value from: " << fParamValues[param]
102 cxcoutIHF <<
"Setting parameter: " << param
103 <<
" value to " <<
value
106 fParamValues[param] =
value;
118 AddFunctionObject(func);
127 std::vector<std::string> PreprocessFunctionExpressions;
128 for(
unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
129 std::string expression = fFunctionObjects.at(i).GetCommand();
130 PreprocessFunctionExpressions.push_back( expression );
132 return PreprocessFunctionExpressions;
138 fGammaSyst[syst] = uncert;
144 fLogNormSyst[syst] = uncert;
150 fUniformSyst[syst] = 1.0;
164 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
166 Channel& chan = fChannels.at(i);
167 if( chan.
GetName() == ChanName ) {
182 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
184 Channel& chan = fChannels.at(i);
185 if( chan.
GetName() == ChanName ) {
193 cxcoutEHF <<
"Error: Did not find channel: " << ChanName
194 <<
" in measurement: " << GetName() << std::endl;
215 stream <<
"Measurement Name: " << GetName()
216 <<
"\t OutputFilePrefix: " << fOutputFilePrefix
218 for(
unsigned int i = 0; i < fPOI.size(); ++i) {
219 stream << fPOI.at(i);
221 stream <<
"\t Lumi: " << fLumi
222 <<
"\t LumiRelErr: " << fLumiRelErr
223 <<
"\t BinLow: " << fBinLow
224 <<
"\t BinHigh: " << fBinHigh
225 <<
"\t ExportOnly: " << fExportOnly
229 if( !fConstantParams.empty() ) {
230 stream <<
"Constant Params: ";
231 for(
unsigned int i = 0; i < fConstantParams.size(); ++i ) {
232 stream <<
" " << fConstantParams.at(i);
237 if( !fFunctionObjects.empty() ) {
238 stream <<
"Preprocess Functions: ";
239 for(
unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
240 stream <<
" " << fFunctionObjects.at(i).GetCommand();
245 if( !fChannels.empty() ) {
246 stream <<
"Channels:" << std::endl;
247 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
248 fChannels.at(i).Print( stream );
252 cxcoutIHF <<
"End Measurement: " << GetName() << std::endl;
265 auto testExists = [](
const std::string& theDirectory) {
267 bool exists = dir !=
nullptr;
274 if ( !directory.empty() && !testExists(directory) ) {
277 cxcoutEHF <<
"Error: Failed to make directory: " << directory << std::endl;
284 cxcoutPHF <<
"Printing XML Files for measurement: " << GetName() << std::endl;
286 std::string XMLName = std::string(GetName()) +
".xml";
287 if( !directory.empty() ) XMLName = directory +
"/" + XMLName;
289 ofstream xml( XMLName.c_str() );
291 if( ! xml.is_open() ) {
292 cxcoutEHF <<
"Error opening xml file: " << XMLName << std::endl;
298 xml <<
"<!--" << std::endl;
299 xml <<
"This xml file created automatically on: " << std::endl;
313 t.
GetDate(
true, 0, &year, &month, &day);
319 xml <<
"-->" << std::endl;
322 xml <<
"<!DOCTYPE Combination SYSTEM 'HistFactorySchema.dtd'>" << std::endl << std::endl;
325 if (newOutputPrefix.empty() ) newOutputPrefix = fOutputFilePrefix;
326 xml <<
"<Combination OutputFilePrefix=\"" << newOutputPrefix <<
"\" >" << std::endl << std::endl;
329 for(
unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
343 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
344 xml <<
" <Input>" <<
"./";
345 if (!directory.empty() ) xml << directory <<
"/";
346 xml << GetName() <<
"_" << fChannels.at(i).GetName() <<
".xml" <<
"</Input>" << std::endl;
352 xml <<
" <Measurement Name=\"" << GetName() <<
"\" "
353 <<
"Lumi=\"" << fLumi <<
"\" "
354 <<
"LumiRelErr=\"" << fLumiRelErr <<
"\" "
357 <<
"ExportOnly=\"" << (fExportOnly ? std::string(
"True") : std::string(
"False")) <<
"\" "
358 <<
" >" << std::endl;
363 for(
unsigned int i = 0; i < fPOI.size(); ++i) {
364 if(i==0) xml << fPOI.at(i);
365 else xml <<
" " << fPOI.at(i);
367 xml <<
"</POI> " << std::endl;
370 if(!fConstantParams.empty()) {
371 xml <<
" <ParamSetting Const=\"True\">";
372 for(
unsigned int i = 0; i < fConstantParams.size(); ++i ) {
373 if (i==0) xml << fConstantParams.at(i);
374 else xml <<
" " << fConstantParams.at(i);;
376 xml <<
"</ParamSetting>" << std::endl;
380 std::map<std::string, double>::iterator ConstrItr;
383 for( ConstrItr = fGammaSyst.begin(); ConstrItr != fGammaSyst.end(); ++ConstrItr ) {
384 xml <<
"<ConstraintTerm Type=\"Gamma\" RelativeUncertainty=\""
385 << ConstrItr->second <<
"\">" << ConstrItr->first
386 <<
"</ConstraintTerm>" << std::endl;
389 for( ConstrItr = fUniformSyst.begin(); ConstrItr != fUniformSyst.end(); ++ConstrItr ) {
390 xml <<
"<ConstraintTerm Type=\"Uniform\" RelativeUncertainty=\""
391 << ConstrItr->second <<
"\">" << ConstrItr->first
392 <<
"</ConstraintTerm>" << std::endl;
395 for( ConstrItr = fLogNormSyst.begin(); ConstrItr != fLogNormSyst.end(); ++ConstrItr ) {
396 xml <<
"<ConstraintTerm Type=\"LogNormal\" RelativeUncertainty=\""
397 << ConstrItr->second <<
"\">" << ConstrItr->first
398 <<
"</ConstraintTerm>" << std::endl;
401 for( ConstrItr = fNoSyst.begin(); ConstrItr != fNoSyst.end(); ++ConstrItr ) {
402 xml <<
"<ConstraintTerm Type=\"NoSyst\" RelativeUncertainty=\""
403 << ConstrItr->second <<
"\">" << ConstrItr->first
404 <<
"</ConstraintTerm>" << std::endl;
409 xml <<
" </Measurement> " << std::endl << std::endl;
412 xml <<
"</Combination>" << std::endl;
419 std::string prefix = std::string(GetName()) +
"_";
421 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
422 fChannels.at(i).PrintXML( directory, prefix );
426 cxcoutPHF <<
"Finished printing XML files" << std::endl;
447 std::string OutputFileName =
file->GetName();
453 for(
unsigned int chanItr = 0; chanItr < outMeas.
fChannels.size(); ++chanItr ) {
462 std::string chanName = channel.
GetName();
466 cxcoutEHF <<
"Measurement.writeToFile(): Channel: " << chanName
467 <<
" has uninitialized histogram pointers" << std::endl;
480 TDirectory* chanDir =
file->mkdir( (chanName +
"_hists").c_str() );
481 if( chanDir ==
nullptr ) {
482 cxcoutEHF <<
"Error: Cannot create channel " << (chanName +
"_hists")
490 if( dataDir ==
nullptr ) {
491 cxcoutEHF <<
"Error: Cannot make directory " << chanDir << std::endl;
513 for(
unsigned int sampItr = 0; sampItr < channel.
GetSamples().
size(); ++sampItr ) {
516 std::string sampName = sample.
GetName();
518 cxcoutPHF <<
"Writing sample: " << sampName << std::endl;
523 if( sampleDir ==
nullptr ) {
524 cxcoutEHF <<
"Error: Directory " << sampName <<
" not created properly" << std::endl;
527 std::string sampleDirPath = GetDirPath( sampleDir );
530 cxcoutEHF <<
"Error making directory: " << sampName
531 <<
" in directory: " << chanName
539 sample.
writeToFile( OutputFileName, sampleDirPath );
601 cxcoutPHF <<
"Saved all histograms" << std::endl;
606 cxcoutPHF <<
"Saved Measurement" << std::endl;
616 std::string path = dir->
GetPath();
618 if( path.find(
':') != std::string::npos ) {
619 size_t index = path.find(
':');
620 path.replace( 0,
index+1,
"" );
650 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)
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 composed of a header, followed by consecutive data records (TKey instances) with a wel...
The TNamed class is the base class for all named ROOT classes.
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.