36 fPOI(), fLumi( 1.0 ), fLumiRelErr( .10 ),
37 fBinLow( 0 ), fBinHigh( 1 ), fExportOnly( false )
53 fPOI(), fLumi( 1.0 ), fLumiRelErr( .10 ),
54 fBinLow( 0 ), fBinHigh( 1 ), fExportOnly( false )
72 if( std::find(fConstantParams.begin(), fConstantParams.end(), param) != fConstantParams.end() ) {
73 std::cout <<
"Warning: Setting parameter: " << param
74 <<
" to constant, but it is already listed as constant. "
75 <<
"You may ignore this warning."
80 fConstantParams.push_back( param );
92 if( fParamValues.find(param) != fParamValues.end() ) {
93 std::cout <<
"Warning: Chainging parameter: " << param
94 <<
" value from: " << fParamValues[param]
100 std::cout <<
"Setting parameter: " << param
101 <<
" value to " << value
104 fParamValues[param] = value;
116 AddFunctionObject(func);
125 std::vector<std::string> PreprocessFunctionExpressions;
126 for(
unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
127 std::string expression = fFunctionObjects.at(i).GetCommand();
128 PreprocessFunctionExpressions.push_back( expression );
130 return PreprocessFunctionExpressions;
136 fGammaSyst[syst] = uncert;
142 fLogNormSyst[syst] = uncert;
148 fUniformSyst[syst] = 1.0;
162 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
164 Channel& chan = fChannels.at(i);
165 if( chan.
GetName() == ChanName ) {
180 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
182 Channel& chan = fChannels.at(i);
183 if( chan.
GetName() == ChanName ) {
191 std::cout <<
"Error: Did not find channel: " << ChanName
192 <<
" in measurement: " <<
GetName() << std::endl;
213 stream <<
"Measurement Name: " <<
GetName()
214 <<
"\t OutputFilePrefix: " << fOutputFilePrefix
216 for(
unsigned int i = 0; i < fPOI.size(); ++i) {
217 stream << fPOI.at(i);
219 stream <<
"\t Lumi: " << fLumi
220 <<
"\t LumiRelErr: " << fLumiRelErr
221 <<
"\t BinLow: " << fBinLow
222 <<
"\t BinHigh: " << fBinHigh
223 <<
"\t ExportOnly: " << fExportOnly
227 if( fConstantParams.size() != 0 ) {
228 stream <<
"Constant Params: ";
229 for(
unsigned int i = 0; i < fConstantParams.size(); ++i ) {
230 stream <<
" " << fConstantParams.at(i);
235 if( fFunctionObjects.size() != 0 ) {
236 stream <<
"Preprocess Functions: ";
237 for(
unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
238 stream <<
" " << fFunctionObjects.at(i).GetCommand();
243 if( fChannels.size() != 0 ) {
244 stream <<
"Channels:" << std::endl;
245 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
246 fChannels.at(i).Print( stream );
250 std::cout <<
"End Measurement: " <<
GetName() << std::endl;
263 auto testExists = [](
const std::string& theDirectory) {
265 bool exists = dir !=
nullptr;
272 if ( !directory.empty() && !testExists(directory) ) {
275 std::cout <<
"Error: Failed to make directory: " << directory << std::endl;
282 std::cout <<
"Printing XML Files for measurement: " <<
GetName() << std::endl;
284 std::string XMLName = std::string(
GetName()) +
".xml";
285 if( directory !=
"" ) XMLName = directory +
"/" + XMLName;
287 ofstream xml( XMLName.c_str() );
289 if( ! xml.is_open() ) {
290 std::cout <<
"Error opening xml file: " << XMLName << std::endl;
296 xml <<
"<!--" << std::endl;
297 xml <<
"This xml file created automatically on: " << std::endl;
311 t.
GetDate(
true, 0, &year, &month, &day);
317 xml <<
"-->" << std::endl;
320 xml <<
"<!DOCTYPE Combination SYSTEM 'HistFactorySchema.dtd'>" << std::endl << std::endl;
323 if (newOutputPrefix.empty() ) newOutputPrefix = fOutputFilePrefix;
324 xml <<
"<Combination OutputFilePrefix=\"" << newOutputPrefix <<
"\" >" << std::endl << std::endl;
327 for(
unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
341 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
342 xml <<
" <Input>" <<
"./";
343 if (!directory.empty() ) xml << directory <<
"/";
344 xml <<
GetName() <<
"_" << fChannels.at(i).GetName() <<
".xml" <<
"</Input>" << std::endl;
350 xml <<
" <Measurement Name=\"" <<
GetName() <<
"\" "
351 <<
"Lumi=\"" << fLumi <<
"\" "
352 <<
"LumiRelErr=\"" << fLumiRelErr <<
"\" "
355 <<
"ExportOnly=\"" << (fExportOnly ? std::string(
"True") : std::string(
"False")) <<
"\" "
356 <<
" >" << std::endl;
361 for(
unsigned int i = 0; i < fPOI.size(); ++i) {
362 if(i==0) xml << fPOI.at(i);
363 else xml <<
" " << fPOI.at(i);
365 xml <<
"</POI> " << std::endl;
368 if(fConstantParams.size()) {
369 xml <<
" <ParamSetting Const=\"True\">";
370 for(
unsigned int i = 0; i < fConstantParams.size(); ++i ) {
371 if (i==0) xml << fConstantParams.at(i);
372 else xml <<
" " << fConstantParams.at(i);;
374 xml <<
"</ParamSetting>" << std::endl;
378 std::map<std::string, double>::iterator ConstrItr;
381 for( ConstrItr = fGammaSyst.begin(); ConstrItr != fGammaSyst.end(); ++ConstrItr ) {
382 xml <<
"<ConstraintTerm Type=\"Gamma\" RelativeUncertainty=\""
383 << ConstrItr->second <<
"\">" << ConstrItr->first
384 <<
"</ConstraintTerm>" << std::endl;
387 for( ConstrItr = fUniformSyst.begin(); ConstrItr != fUniformSyst.end(); ++ConstrItr ) {
388 xml <<
"<ConstraintTerm Type=\"Uniform\" RelativeUncertainty=\""
389 << ConstrItr->second <<
"\">" << ConstrItr->first
390 <<
"</ConstraintTerm>" << std::endl;
393 for( ConstrItr = fLogNormSyst.begin(); ConstrItr != fLogNormSyst.end(); ++ConstrItr ) {
394 xml <<
"<ConstraintTerm Type=\"LogNormal\" RelativeUncertainty=\""
395 << ConstrItr->second <<
"\">" << ConstrItr->first
396 <<
"</ConstraintTerm>" << std::endl;
399 for( ConstrItr = fNoSyst.begin(); ConstrItr != fNoSyst.end(); ++ConstrItr ) {
400 xml <<
"<ConstraintTerm Type=\"NoSyst\" RelativeUncertainty=\""
401 << ConstrItr->second <<
"\">" << ConstrItr->first
402 <<
"</ConstraintTerm>" << std::endl;
407 xml <<
" </Measurement> " << std::endl << std::endl;
410 xml <<
"</Combination>" << std::endl;
417 std::string prefix = std::string(
GetName()) +
"_";
419 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
420 fChannels.at(i).PrintXML( directory, prefix );
424 std::cout <<
"Finished printing XML files" << std::endl;
445 std::string OutputFileName =
file->GetName();
451 for(
unsigned int chanItr = 0; chanItr < outMeas.
fChannels.size(); ++chanItr ) {
460 std::string chanName = channel.
GetName();
464 std::cout <<
"Measurement.writeToFile(): Channel: " << chanName
465 <<
" has uninitialized histogram pointers" << std::endl;
478 TDirectory* chanDir =
file->mkdir( (chanName +
"_hists").c_str() );
479 if( chanDir == NULL ) {
480 std::cout <<
"Error: Cannot create channel " << (chanName +
"_hists")
488 if( dataDir == NULL ) {
489 std::cout <<
"Error: Cannot make directory " << chanDir << std::endl;
511 for(
unsigned int sampItr = 0; sampItr < channel.
GetSamples().size(); ++sampItr ) {
514 std::string sampName = sample.
GetName();
516 std::cout <<
"Writing sample: " << sampName << std::endl;
521 if( sampleDir == NULL ) {
522 std::cout <<
"Error: Directory " << sampName <<
" not created properly" << std::endl;
525 std::string sampleDirPath = GetDirPath( sampleDir );
528 std::cout <<
"Error making directory: " << sampName
529 <<
" in directory: " << chanName
537 sample.
writeToFile( OutputFileName, sampleDirPath );
599 std::cout <<
"Saved all histograms" << std::endl;
604 std::cout <<
"Saved Measurement" << std::endl;
614 std::string path = dir->
GetPath();
616 if( path.find(
":") != std::string::npos ) {
617 size_t index = path.find(
":");
618 path.replace( 0, index+1,
"" );
649 for(
unsigned int chanItr = 0; chanItr < fChannels.size(); ++chanItr) {
R__EXTERN TSystem * gSystem
This class encapsulates all information for the statistical interpretation of one experiment.
std::string GetName()
get name of channel
std::vector< RooStats::HistFactory::Sample > & GetSamples()
get vector of samples for this 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()
Returns a list of defined preprocess function expressions.
std::vector< RooStats::HistFactory::Channel > fChannels
Channels that make up this measurement.
void PrintXML(std::ostream &)
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 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/...".
virtual Bool_t cd(const char *path=nullptr)
Change current directory to "this" directory.
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.
std::string GetName(const std::string &scope_name)