41 fPOI(), fLumi( 1.0 ), fLumiRelErr( .10 ),
42 fBinLow( 0 ), fBinHigh( 1 ), fExportOnly( false )
58 fPOI(), fLumi( 1.0 ), fLumiRelErr( .10 ),
59 fBinLow( 0 ), fBinHigh( 1 ), fExportOnly( false )
77 if( std::find(fConstantParams.begin(), fConstantParams.end(), param) != fConstantParams.end() ) {
78 cxcoutWHF <<
"Warning: Setting parameter: " << param
79 <<
" to constant, but it is already listed as constant. "
80 <<
"You may ignore this warning."
85 fConstantParams.push_back( param );
97 if( fParamValues.find(param) != fParamValues.end() ) {
98 cxcoutWHF <<
"Warning: Chainging parameter: " << param
99 <<
" value from: " << fParamValues[param]
105 cxcoutIHF <<
"Setting parameter: " << param
106 <<
" value to " <<
value
109 fParamValues[param] =
value;
121 AddFunctionObject(func);
130 std::vector<std::string> PreprocessFunctionExpressions;
131 for(
unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
132 std::string expression = fFunctionObjects.at(i).GetCommand();
133 PreprocessFunctionExpressions.push_back( expression );
135 return PreprocessFunctionExpressions;
141 fGammaSyst[syst] = uncert;
147 fLogNormSyst[syst] = uncert;
153 fUniformSyst[syst] = 1.0;
167 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
169 Channel& chan = fChannels.at(i);
170 if( chan.
GetName() == ChanName ) {
185 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
187 Channel& chan = fChannels.at(i);
188 if( chan.
GetName() == ChanName ) {
196 cxcoutEHF <<
"Error: Did not find channel: " << ChanName
197 <<
" in measurement: " << GetName() << std::endl;
218 stream <<
"Measurement Name: " << GetName()
219 <<
"\t OutputFilePrefix: " << fOutputFilePrefix
221 for(
unsigned int i = 0; i < fPOI.size(); ++i) {
222 stream << fPOI.at(i);
224 stream <<
"\t Lumi: " << fLumi
225 <<
"\t LumiRelErr: " << fLumiRelErr
226 <<
"\t BinLow: " << fBinLow
227 <<
"\t BinHigh: " << fBinHigh
228 <<
"\t ExportOnly: " << fExportOnly
232 if( !fConstantParams.empty() ) {
233 stream <<
"Constant Params: ";
234 for(
unsigned int i = 0; i < fConstantParams.size(); ++i ) {
235 stream <<
" " << fConstantParams.at(i);
240 if( !fFunctionObjects.empty() ) {
241 stream <<
"Preprocess Functions: ";
242 for(
unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
243 stream <<
" " << fFunctionObjects.at(i).GetCommand();
248 if( !fChannels.empty() ) {
249 stream <<
"Channels:" << std::endl;
250 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
251 fChannels.at(i).Print( stream );
255 cxcoutIHF <<
"End Measurement: " << GetName() << std::endl;
268 auto testExists = [](
const std::string& theDirectory) {
270 bool exists = dir !=
nullptr;
277 if ( !directory.empty() && !testExists(directory) ) {
280 cxcoutEHF <<
"Error: Failed to make directory: " << directory << std::endl;
287 cxcoutPHF <<
"Printing XML Files for measurement: " << GetName() << std::endl;
289 std::string XMLName = std::string(GetName()) +
".xml";
290 if( !directory.empty() ) XMLName = directory +
"/" + XMLName;
292 ofstream xml( XMLName.c_str() );
294 if( ! xml.is_open() ) {
295 cxcoutEHF <<
"Error opening xml file: " << XMLName << std::endl;
301 xml <<
"<!--" << std::endl;
302 xml <<
"This xml file created automatically on: " << std::endl;
316 t.
GetDate(
true, 0, &year, &month, &day);
322 xml <<
"-->" << std::endl;
325 xml <<
"<!DOCTYPE Combination SYSTEM 'HistFactorySchema.dtd'>" << std::endl << std::endl;
328 if (newOutputPrefix.empty() ) newOutputPrefix = fOutputFilePrefix;
329 xml <<
"<Combination OutputFilePrefix=\"" << newOutputPrefix <<
"\" >" << std::endl << std::endl;
332 for(
unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
346 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
347 xml <<
" <Input>" <<
"./";
348 if (!directory.empty() ) xml << directory <<
"/";
349 xml << GetName() <<
"_" << fChannels.at(i).GetName() <<
".xml" <<
"</Input>" << std::endl;
355 xml <<
" <Measurement Name=\"" << GetName() <<
"\" "
356 <<
"Lumi=\"" << fLumi <<
"\" "
357 <<
"LumiRelErr=\"" << fLumiRelErr <<
"\" "
360 <<
"ExportOnly=\"" << (fExportOnly ? std::string(
"True") : std::string(
"False")) <<
"\" "
361 <<
" >" << std::endl;
366 for(
unsigned int i = 0; i < fPOI.size(); ++i) {
367 if(i==0) xml << fPOI.at(i);
368 else xml <<
" " << fPOI.at(i);
370 xml <<
"</POI> " << std::endl;
373 if(!fConstantParams.empty()) {
374 xml <<
" <ParamSetting Const=\"True\">";
375 for(
unsigned int i = 0; i < fConstantParams.size(); ++i ) {
376 if (i==0) xml << fConstantParams.at(i);
377 else xml <<
" " << fConstantParams.at(i);;
379 xml <<
"</ParamSetting>" << std::endl;
383 std::map<std::string, double>::iterator ConstrItr;
386 for( ConstrItr = fGammaSyst.begin(); ConstrItr != fGammaSyst.end(); ++ConstrItr ) {
387 xml <<
"<ConstraintTerm Type=\"Gamma\" RelativeUncertainty=\""
388 << ConstrItr->second <<
"\">" << ConstrItr->first
389 <<
"</ConstraintTerm>" << std::endl;
392 for( ConstrItr = fUniformSyst.begin(); ConstrItr != fUniformSyst.end(); ++ConstrItr ) {
393 xml <<
"<ConstraintTerm Type=\"Uniform\" RelativeUncertainty=\""
394 << ConstrItr->second <<
"\">" << ConstrItr->first
395 <<
"</ConstraintTerm>" << std::endl;
398 for( ConstrItr = fLogNormSyst.begin(); ConstrItr != fLogNormSyst.end(); ++ConstrItr ) {
399 xml <<
"<ConstraintTerm Type=\"LogNormal\" RelativeUncertainty=\""
400 << ConstrItr->second <<
"\">" << ConstrItr->first
401 <<
"</ConstraintTerm>" << std::endl;
404 for( ConstrItr = fNoSyst.begin(); ConstrItr != fNoSyst.end(); ++ConstrItr ) {
405 xml <<
"<ConstraintTerm Type=\"NoSyst\" RelativeUncertainty=\""
406 << ConstrItr->second <<
"\">" << ConstrItr->first
407 <<
"</ConstraintTerm>" << std::endl;
412 xml <<
" </Measurement> " << std::endl << std::endl;
415 xml <<
"</Combination>" << std::endl;
422 std::string prefix = std::string(GetName()) +
"_";
424 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
425 fChannels.at(i).PrintXML( directory, prefix );
429 cxcoutPHF <<
"Finished printing XML files" << std::endl;
450 std::string OutputFileName =
file->GetName();
456 for(
unsigned int chanItr = 0; chanItr < outMeas.
fChannels.size(); ++chanItr ) {
465 std::string chanName = channel.
GetName();
469 cxcoutEHF <<
"Measurement.writeToFile(): Channel: " << chanName
470 <<
" has uninitialized histogram pointers" << std::endl;
483 TDirectory* chanDir =
file->mkdir( (chanName +
"_hists").c_str() );
484 if( chanDir ==
nullptr ) {
485 cxcoutEHF <<
"Error: Cannot create channel " << (chanName +
"_hists")
493 if( dataDir ==
nullptr ) {
494 cxcoutEHF <<
"Error: Cannot make directory " << chanDir << std::endl;
516 for(
unsigned int sampItr = 0; sampItr < channel.
GetSamples().
size(); ++sampItr ) {
519 std::string sampName = sample.
GetName();
521 cxcoutPHF <<
"Writing sample: " << sampName << std::endl;
526 if( sampleDir ==
nullptr ) {
527 cxcoutEHF <<
"Error: Directory " << sampName <<
" not created properly" << std::endl;
530 std::string sampleDirPath = GetDirPath( sampleDir );
533 cxcoutEHF <<
"Error making directory: " << sampName
534 <<
" in directory: " << chanName
542 sample.
writeToFile( OutputFileName, sampleDirPath );
604 cxcoutPHF <<
"Saved all histograms" << std::endl;
609 cxcoutPHF <<
"Saved Measurement" << std::endl;
619 std::string path = dir->
GetPath();
621 if( path.find(
':') != std::string::npos ) {
622 size_t index = path.find(
':');
623 path.replace( 0,
index+1,
"" );
653 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.