36 fPOI(), fLumi( 1.0 ), fLumiRelErr( .10 ),
37 fBinLow( 0 ), fBinHigh( 1 ), fExportOnly( false )
52 fPOI(), fLumi( 1.0 ), fLumiRelErr( .10 ),
53 fBinLow( 0 ), fBinHigh( 1 ), fExportOnly( false )
70 if( std::find(fConstantParams.begin(), fConstantParams.end(), param) != fConstantParams.end() ) {
71 std::cout <<
"Warning: Setting parameter: " << param
72 <<
" to constant, but it is already listed as constant. "
73 <<
"You may ignore this warning."
78 fConstantParams.push_back( param );
90 if( fParamValues.find(param) != fParamValues.end() ) {
91 std::cout <<
"Warning: Chainging parameter: " << param
92 <<
" value from: " << fParamValues[param]
98 std::cout <<
"Setting parameter: " << param
99 <<
" value to " << value
102 fParamValues[param] = value;
112 AddFunctionObject(func);
121 std::vector<std::string> PreprocessFunctionExpressions;
122 for(
unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
123 std::string expression = fFunctionObjects.at(i).GetCommand();
124 PreprocessFunctionExpressions.push_back( expression );
126 return PreprocessFunctionExpressions;
133 fGammaSyst[syst] = uncert;
140 fLogNormSyst[syst] = uncert;
147 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;
212 stream <<
"Measurement Name: " <<
GetName()
213 <<
"\t OutputFilePrefix: " << fOutputFilePrefix
215 for(
unsigned int i = 0; i < fPOI.size(); ++i) {
216 stream << fPOI.at(i);
218 stream <<
"\t Lumi: " << fLumi
219 <<
"\t LumiRelErr: " << fLumiRelErr
220 <<
"\t BinLow: " << fBinLow
221 <<
"\t BinHigh: " << fBinHigh
222 <<
"\t ExportOnly: " << fExportOnly
226 if( fConstantParams.size() != 0 ) {
227 stream <<
"Constant Params: ";
228 for(
unsigned int i = 0; i < fConstantParams.size(); ++i ) {
229 stream <<
" " << fConstantParams.at(i);
234 if( fFunctionObjects.size() != 0 ) {
235 stream <<
"Preprocess Functions: ";
236 for(
unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
237 stream <<
" " << fFunctionObjects.at(i).GetCommand();
242 if( fChannels.size() != 0 ) {
243 stream <<
"Channels:" << std::endl;
244 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
245 fChannels.at(i).Print( stream );
249 std::cout <<
"End Measurement: " <<
GetName() << std::endl;
265 auto testExists = [](
const std::string& theDirectory) {
267 bool exists = dir !=
nullptr;
274 if ( !directory.empty() && !testExists(directory) ) {
277 std::cout <<
"Error: Failed to make directory: " << directory << std::endl;
284 std::cout <<
"Printing XML Files for measurement: " <<
GetName() << std::endl;
286 std::string XMLName = std::string(
GetName()) +
".xml";
287 if( directory !=
"" ) XMLName = directory +
"/" + XMLName;
289 ofstream xml( XMLName.c_str() );
291 if( ! xml.is_open() ) {
292 std::cout <<
"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.size()) {
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 std::cout <<
"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 std::cout <<
"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 std::cout <<
"Error: Cannot create channel " << (chanName +
"_hists")
491 if( dataDir == NULL ) {
492 std::cout <<
"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 std::cout <<
"Writing sample: " << sampName << std::endl;
524 if( sampleDir == NULL ) {
525 std::cout <<
"Error: Directory " << sampName <<
" not created properly" << std::endl;
528 std::string sampleDirPath = GetDirPath( sampleDir );
531 std::cout <<
"Error making directory: " << sampName
532 <<
" in directory: " << chanName
540 sample.
writeToFile( OutputFileName, sampleDirPath );
602 std::cout <<
"Saved all histograms" << std::endl;
607 std::cout <<
"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,
"" );
652 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)
void AddGammaSyst(std::string syst, double uncert)
std::string GetDirPath(TDirectory *dir)
void AddLogNormSyst(std::string syst, double uncert)
void PrintXML(std::string Directory="", std::string NewOutputPrefix="")
Print to a stream.
RooStats::HistFactory::Channel & GetChannel(std::string)
void SetParamValue(const std::string ¶m, double value)
Set a parameter to a specific value (And optionally fix it)
bool HasChannel(std::string)
void AddUniformSyst(std::string syst)
void PrintTree(std::ostream &=std::cout)
void AddNoSyst(std::string syst)
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)
std::vector< std::string > GetPreprocessFunctions()
std::vector< RooStats::HistFactory::Channel > fChannels
Channels that make up this measurement.
void PrintXML(std::ostream &)
std::string GetName()
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(const char *path=0)
Change current directory to "this" directory.
virtual TDirectory * mkdir(const char *name, const char *title="")
Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".
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)