39 fPOI(), fLumi( 1.0 ), fLumiRelErr( .10 ),
40 fBinLow( 0 ), fBinHigh( 1 ), fExportOnly( false )
56 fPOI(), fLumi( 1.0 ), fLumiRelErr( .10 ),
57 fBinLow( 0 ), fBinHigh( 1 ), fExportOnly( false )
75 if( std::find(fConstantParams.begin(), fConstantParams.end(), param) != fConstantParams.end() ) {
76 cxcoutWHF <<
"Warning: Setting parameter: " << param
77 <<
" to constant, but it is already listed as constant. "
78 <<
"You may ignore this warning."
83 fConstantParams.push_back( param );
95 if( fParamValues.find(param) != fParamValues.end() ) {
96 cxcoutWHF <<
"Warning: Chainging parameter: " << param
97 <<
" value from: " << fParamValues[param]
103 cxcoutIHF <<
"Setting parameter: " << param
104 <<
" value to " << value
107 fParamValues[param] = value;
119 AddFunctionObject(func);
128 std::vector<std::string> PreprocessFunctionExpressions;
129 for(
unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
130 std::string expression = fFunctionObjects.at(i).GetCommand();
131 PreprocessFunctionExpressions.push_back( expression );
133 return PreprocessFunctionExpressions;
139 fGammaSyst[syst] = uncert;
145 fLogNormSyst[syst] = uncert;
151 fUniformSyst[syst] = 1.0;
165 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
167 Channel& chan = fChannels.at(i);
168 if( chan.
GetName() == ChanName ) {
183 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
185 Channel& chan = fChannels.at(i);
186 if( chan.
GetName() == ChanName ) {
194 cxcoutEHF <<
"Error: Did not find channel: " << ChanName
195 <<
" in measurement: " << GetName() << std::endl;
216 stream <<
"Measurement Name: " << GetName()
217 <<
"\t OutputFilePrefix: " << fOutputFilePrefix
219 for(
unsigned int i = 0; i < fPOI.size(); ++i) {
220 stream << fPOI.at(i);
222 stream <<
"\t Lumi: " << fLumi
223 <<
"\t LumiRelErr: " << fLumiRelErr
224 <<
"\t BinLow: " << fBinLow
225 <<
"\t BinHigh: " << fBinHigh
226 <<
"\t ExportOnly: " << fExportOnly
230 if( fConstantParams.size() != 0 ) {
231 stream <<
"Constant Params: ";
232 for(
unsigned int i = 0; i < fConstantParams.size(); ++i ) {
233 stream <<
" " << fConstantParams.at(i);
238 if( fFunctionObjects.size() != 0 ) {
239 stream <<
"Preprocess Functions: ";
240 for(
unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
241 stream <<
" " << fFunctionObjects.at(i).GetCommand();
246 if( fChannels.size() != 0 ) {
247 stream <<
"Channels:" << std::endl;
248 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
249 fChannels.at(i).Print( stream );
253 cxcoutIHF <<
"End Measurement: " << GetName() << std::endl;
266 auto testExists = [](
const std::string& theDirectory) {
268 bool exists = dir !=
nullptr;
275 if ( !directory.empty() && !testExists(directory) ) {
278 cxcoutEHF <<
"Error: Failed to make directory: " << directory << std::endl;
285 cxcoutPHF <<
"Printing XML Files for measurement: " << GetName() << std::endl;
287 std::string XMLName = std::string(GetName()) +
".xml";
288 if( directory !=
"" ) XMLName = directory +
"/" + XMLName;
290 ofstream xml( XMLName.c_str() );
292 if( ! xml.is_open() ) {
293 cxcoutEHF <<
"Error opening xml file: " << XMLName << std::endl;
299 xml <<
"<!--" << std::endl;
300 xml <<
"This xml file created automatically on: " << std::endl;
314 t.
GetDate(
true, 0, &year, &month, &day);
320 xml <<
"-->" << std::endl;
323 xml <<
"<!DOCTYPE Combination SYSTEM 'HistFactorySchema.dtd'>" << std::endl << std::endl;
326 if (newOutputPrefix.empty() ) newOutputPrefix = fOutputFilePrefix;
327 xml <<
"<Combination OutputFilePrefix=\"" << newOutputPrefix <<
"\" >" << std::endl << std::endl;
330 for(
unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
344 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
345 xml <<
" <Input>" <<
"./";
346 if (!directory.empty() ) xml << directory <<
"/";
347 xml << GetName() <<
"_" << fChannels.at(i).GetName() <<
".xml" <<
"</Input>" << std::endl;
353 xml <<
" <Measurement Name=\"" << GetName() <<
"\" "
354 <<
"Lumi=\"" << fLumi <<
"\" "
355 <<
"LumiRelErr=\"" << fLumiRelErr <<
"\" "
358 <<
"ExportOnly=\"" << (fExportOnly ? std::string(
"True") : std::string(
"False")) <<
"\" "
359 <<
" >" << std::endl;
364 for(
unsigned int i = 0; i < fPOI.size(); ++i) {
365 if(i==0) xml << fPOI.at(i);
366 else xml <<
" " << fPOI.at(i);
368 xml <<
"</POI> " << std::endl;
371 if(fConstantParams.size()) {
372 xml <<
" <ParamSetting Const=\"True\">";
373 for(
unsigned int i = 0; i < fConstantParams.size(); ++i ) {
374 if (i==0) xml << fConstantParams.at(i);
375 else xml <<
" " << fConstantParams.at(i);;
377 xml <<
"</ParamSetting>" << std::endl;
381 std::map<std::string, double>::iterator ConstrItr;
384 for( ConstrItr = fGammaSyst.begin(); ConstrItr != fGammaSyst.end(); ++ConstrItr ) {
385 xml <<
"<ConstraintTerm Type=\"Gamma\" RelativeUncertainty=\""
386 << ConstrItr->second <<
"\">" << ConstrItr->first
387 <<
"</ConstraintTerm>" << std::endl;
390 for( ConstrItr = fUniformSyst.begin(); ConstrItr != fUniformSyst.end(); ++ConstrItr ) {
391 xml <<
"<ConstraintTerm Type=\"Uniform\" RelativeUncertainty=\""
392 << ConstrItr->second <<
"\">" << ConstrItr->first
393 <<
"</ConstraintTerm>" << std::endl;
396 for( ConstrItr = fLogNormSyst.begin(); ConstrItr != fLogNormSyst.end(); ++ConstrItr ) {
397 xml <<
"<ConstraintTerm Type=\"LogNormal\" RelativeUncertainty=\""
398 << ConstrItr->second <<
"\">" << ConstrItr->first
399 <<
"</ConstraintTerm>" << std::endl;
402 for( ConstrItr = fNoSyst.begin(); ConstrItr != fNoSyst.end(); ++ConstrItr ) {
403 xml <<
"<ConstraintTerm Type=\"NoSyst\" RelativeUncertainty=\""
404 << ConstrItr->second <<
"\">" << ConstrItr->first
405 <<
"</ConstraintTerm>" << std::endl;
410 xml <<
" </Measurement> " << std::endl << std::endl;
413 xml <<
"</Combination>" << std::endl;
420 std::string prefix = std::string(GetName()) +
"_";
422 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
423 fChannels.at(i).PrintXML( directory, prefix );
427 cxcoutPHF <<
"Finished printing XML files" << std::endl;
448 std::string OutputFileName =
file->GetName();
454 for(
unsigned int chanItr = 0; chanItr < outMeas.
fChannels.size(); ++chanItr ) {
463 std::string chanName = channel.
GetName();
467 cxcoutEHF <<
"Measurement.writeToFile(): Channel: " << chanName
468 <<
" has uninitialized histogram pointers" << std::endl;
481 TDirectory* chanDir =
file->mkdir( (chanName +
"_hists").c_str() );
482 if( chanDir == NULL ) {
483 cxcoutEHF <<
"Error: Cannot create channel " << (chanName +
"_hists")
491 if( dataDir == NULL ) {
492 cxcoutEHF <<
"Error: Cannot make directory " << chanDir << std::endl;
514 for(
unsigned int sampItr = 0; sampItr < channel.
GetSamples().
size(); ++sampItr ) {
517 std::string sampName = sample.
GetName();
519 cxcoutPHF <<
"Writing sample: " << sampName << std::endl;
524 if( sampleDir == NULL ) {
525 cxcoutEHF <<
"Error: Directory " << sampName <<
" not created properly" << std::endl;
528 std::string sampleDirPath = GetDirPath( sampleDir );
531 cxcoutEHF <<
"Error making directory: " << sampName
532 <<
" in directory: " << chanName
540 sample.
writeToFile( OutputFileName, sampleDirPath );
602 cxcoutPHF <<
"Saved all histograms" << std::endl;
607 cxcoutPHF <<
"Saved Measurement" << std::endl;
617 std::string path = dir->
GetPath();
619 if( path.find(
":") != std::string::npos ) {
620 size_t index = path.find(
":");
621 path.replace( 0, index+1,
"" );
651 for(
unsigned int chanItr = 0; chanItr < fChannels.size(); ++chanItr) {
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
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 a suite of consecutive data records (TKey instances) with a well defined format.
The TNamed class is the base class for all named ROOT classes.
virtual Int_t Write(const char *name=0, 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=0, UInt_t *month=0, UInt_t *day=0) const
Return date in form of 19971224 (i.e.