42 fPOI(), fLumi( 1.0 ), fLumiRelErr( .10 ),
43 fBinLow( 0 ), fBinHigh( 1 ), fExportOnly(
false )
58 fPOI(), fLumi( 1.0 ), fLumiRelErr( .10 ),
59 fBinLow( 0 ), fBinHigh( 1 ), fExportOnly(
false )
76 if( std::find(fConstantParams.begin(), fConstantParams.end(), param) != fConstantParams.end() ) {
77 std::cout <<
"Warning: Setting parameter: " << param
78 <<
" to constant, but it is already listed as constant. "
79 <<
"You may ignore this warning."
84 fConstantParams.push_back( param );
96 if( fParamValues.find(param) != fParamValues.end() ) {
97 std::cout <<
"Warning: Chainging parameter: " << param
98 <<
" value from: " << fParamValues[param]
104 std::cout <<
"Setting parameter: " << param
105 <<
" value to " << value
108 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;
139 fGammaSyst[syst] = uncert;
146 fLogNormSyst[syst] = uncert;
153 fUniformSyst[syst] = 1.0;
168 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
170 Channel& chan = fChannels.at(i);
171 if( chan.
GetName() == ChanName ) {
186 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
188 Channel& chan = fChannels.at(i);
189 if( chan.
GetName() == ChanName ) {
197 std::cout <<
"Error: Did not find channel: " << ChanName
198 <<
" 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.size() != 0 ) {
233 stream <<
"Constant Params: ";
234 for(
unsigned int i = 0; i < fConstantParams.size(); ++i ) {
235 stream <<
" " << fConstantParams.at(i);
240 if( fFunctionObjects.size() != 0 ) {
241 stream <<
"Preprocess Functions: ";
242 for(
unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
243 stream <<
" " << fFunctionObjects.at(i).GetCommand();
248 if( fChannels.size() != 0 ) {
249 stream <<
"Channels:" << std::endl;
250 for(
unsigned int i = 0; i < fChannels.size(); ++i ) {
251 fChannels.at(i).Print( stream );
255 std::cout <<
"End Measurement: " << GetName() << std::endl;
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;
446 std::string OutputFileName = file->
GetName();
452 for(
unsigned int chanItr = 0; chanItr < outMeas.
fChannels.size(); ++chanItr ) {
461 std::string chanName = channel.
GetName();
465 std::cout <<
"Measurement.writeToFile(): Channel: " << chanName
466 <<
" has uninitialized histogram pointers" << std::endl;
480 if( chanDir ==
NULL ) {
481 std::cout <<
"Error: Cannot create channel " << (chanName +
"_hists")
489 if( dataDir ==
NULL ) {
490 std::cout <<
"Error: Cannot make directory " << chanDir << std::endl;
512 for(
unsigned int sampItr = 0; sampItr < channel.
GetSamples().size(); ++sampItr ) {
515 std::string sampName = sample.
GetName();
517 std::cout <<
"Writing sample: " << sampName << std::endl;
522 if( sampleDir ==
NULL ) {
523 std::cout <<
"Error: Directory " << sampName <<
" not created properly" << std::endl;
526 std::string sampleDirPath = GetDirPath( sampleDir );
529 std::cout <<
"Error making directory: " << sampName
530 <<
" in directory: " << chanName
538 sample.
writeToFile( OutputFileName, sampleDirPath );
600 std::cout <<
"Saved all histograms" << std::endl;
605 std::cout <<
"Saved Measurement" << std::endl;
615 std::string path = dir->
GetPath();
617 if( path.find(
":") != std::string::npos ) {
618 size_t index = path.find(
":");
619 path.replace( 0, index+1,
"" );
650 for(
unsigned int chanItr = 0; chanItr < fChannels.size(); ++chanItr) {
void AddUniformSyst(std::string syst)
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
virtual TDirectory * mkdir(const char *name, const char *title="")
Create a sub-directory and return a pointer to the created directory.
void PrintXML(std::string Directory="", std::string NewOutputPrefix="")
virtual void Flush()
Synchronize a file's in-memory and on-disk states.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
virtual int MakeDirectory(const char *name)
Make a directory.
void AddPreprocessFunction(std::string name, std::string expression, std::string dependencies)
virtual TDirectory * mkdir(const char *name, const char *title="")
Create a sub-directory and return a pointer to the created directory.
ClassImp(TIterator) Bool_t TIterator return false
Compare two iterator objects.
virtual const char * GetPath() const
Returns the full path of the directory.
std::vector< std::string > GetPreprocessFunctions()
std::vector< RooStats::HistFactory::Channel > fChannels
The TNamed class is the base class for all named ROOT classes.
bool HasChannel(std::string)
std::string GetDirPath(TDirectory *dir)
void writeToFile(std::string FileName, std::string DirName)
void AddGammaSyst(std::string syst, double uncert)
R__EXTERN TSystem * gSystem
void AddConstantParam(const std::string ¶m)
virtual const char * GetName() const
Returns name of object.
Describe directory structure in memory.
The TTimeStamp encapsulates seconds and ns since EPOCH.
double func(double *x, double *p)
void AddNoSyst(std::string syst)
std::vector< RooStats::HistFactory::Sample > & GetSamples()
RooStats::HistFactory::Channel & GetChannel(std::string)
ClassImp(RooStats::HistFactory::Measurement)
void SetParamValue(const std::string ¶m, double value)
void writeToFile(std::string FileName, std::string DirName)
void PrintXML(std::ostream &)
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
void AddLogNormSyst(std::string syst, double uncert)
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.
void PrintTree(std::ostream &=std::cout)
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
void writeToFile(TFile *file)