108 TFile* outFile = NULL;
109 FILE* tableFile=NULL;
116 cxcoutIHF <<
"Making Model and Measurements (Fast) for measurement: " << measurement.
GetName() << std::endl;
120 cxcoutIHF <<
"using lumi = " << measurement.
GetLumi() <<
" and lumiError = " << lumiError
121 <<
" including bins between " << measurement.
GetBinLow() <<
" and " << measurement.
GetBinHigh() << std::endl;
123 std::ostringstream parameterMessage;
124 parameterMessage <<
"fixing the following parameters:" << std::endl;
127 parameterMessage <<
" " << *itr <<
'\n';
131 std::string rowTitle = measurement.
GetName();
133 std::vector<RooWorkspace*> channel_workspaces;
134 std::vector<std::string> channel_names;
143 size_t pos = prefix.rfind(
"/");
144 if (pos != std::string::npos) {
145 std::string outputDir = prefix.substr(0,pos);
146 cxcoutDHF <<
"Checking if output directory : " << outputDir <<
" - exists" << std::endl;
148 cxcoutDHF <<
"Output directory : " << outputDir <<
" - does not exist, try to create" << std::endl;
151 std::string fullOutputDir = std::string(
gSystem->
pwd()) + std::string(
"/") + outputDir;
152 cxcoutEHF <<
"Error: Failed to make output directory: " << fullOutputDir << std::endl;
160 cxcoutIHF <<
"Creating the output file: " << outputFileName << std::endl;
161 outFile =
new TFile(outputFileName.c_str(),
"recreate");
166 cxcoutIHF <<
"Creating the table file: " << tableFileName << std::endl;
167 tableFile = fopen( tableFileName.c_str(),
"a");
169 cxcoutIHF <<
"Creating the HistoToWorkspaceFactoryFast factory" << std::endl;
170 HistoToWorkspaceFactoryFast factory( measurement );
174 cxcoutIHF <<
"Setting preprocess functions" << std::endl;
178 fprintf(tableFile,
" %s &", rowTitle.c_str() );
181 for(
unsigned int chanItr = 0; chanItr < measurement.
GetChannels().size(); ++chanItr ) {
183 HistFactory::Channel& channel = measurement.
GetChannels().at( chanItr );
184 if( ! channel.CheckHistograms() ) {
185 cxcoutEHF <<
"MakeModelAndMeasurementsFast: Channel: " << channel.GetName()
186 <<
" has uninitialized histogram pointers" << std::endl;
191 std::string ch_name = channel.GetName();
192 cxcoutPHF <<
"Starting to process channel: " << ch_name << std::endl;
193 channel_names.push_back(ch_name);
194 RooWorkspace* ws_single = factory.MakeSingleChannelModel( measurement, channel );
195 channel_workspaces.push_back(ws_single);
199 + ch_name +
"_" + rowTitle +
"_model.root";
205 meas_chan.GetChannels().clear();
206 meas_chan.GetChannels().push_back( channel );
207 cxcoutIHF <<
"Opening File to hold channel: " << ChannelFileName << std::endl;
209 cxcoutIHF <<
"About to write channel measurement to file" << std::endl;
210 meas_chan.writeToFile( chanFile );
211 cxcoutPHF <<
"Successfully wrote channel to file" << std::endl;
221 <<
", no parameter of interest" << std::endl;
223 if(ws_single->
data(
"obsData")) {
225 ch_name,
"obsData", outFile, tableFile);
228 ch_name,
"asimovData", outFile, tableFile);
233 fprintf(tableFile,
" & " );
243 ws = factory.MakeCombinedModel(channel_names, channel_workspaces);
246 HistoToWorkspaceFactoryFast::ConfigureWorkspaceForMeasurement(
"simPdf",
ws, measurement );
252 + rowTitle +
"_model.root";
253 cxcoutPHF <<
"Writing combined workspace to file: " << CombinedFileName << std::endl;
254 ws->writeToFile( CombinedFileName.c_str() );
255 cxcoutPHF <<
"Writing combined measurement to file: " << CombinedFileName << std::endl;
257 if( combFile == NULL ) {
258 cxcoutEHF <<
"Error: Failed to open file " << CombinedFileName << std::endl;
268 <<
", no parameter of interest" << std::endl;
271 if(
ws->data(
"obsData")){
273 "obsData", outFile, tableFile);
277 "asimovData", outFile, tableFile);
282 fprintf(tableFile,
" \\\\ \n");
291 if( tableFile ) fclose(tableFile);
292 if(outFile) outFile->
Close();
305 const std::string& FileNamePrefix,
307 std::string data_name,
308 TFile* outFile, FILE* tableFile ) {
310 if( outFile == NULL ) {
311 cxcoutEHF <<
"Error: Output File in FitModelAndPlot is NULL" << std::endl;
315 if( tableFile == NULL ) {
316 cxcoutEHF <<
"Error: tableFile in FitModelAndPlot is NULL" << std::endl;
320 if( combined == NULL ) {
321 cxcoutEHF <<
"Error: Supplied workspace in FitModelAndPlot is NULL" << std::endl;
326 if(!combined_config){
327 cxcoutEHF <<
"Error: no ModelConfig found in Measurement: "
328 << MeasurementName << std::endl;
334 cxcoutEHF <<
"Error: Failed to get dataset: " << data_name
335 <<
" in measurement: " << MeasurementName << std::endl;
341 cxcoutEHF <<
"Not Fitting Model for measurement: " << MeasurementName
342 <<
", no poi found" << std::endl;
349 cxcoutEHF <<
"Error: Failed to find pdf in ModelConfig: " << combined_config->
GetName()
360 combined->
saveSnapshot(
"InitialValues", PoiPlusNuisance);
365 <<
"\nDoing "<< channel <<
" Fit"
366 <<
"\n---------------\n\n" << std::endl;
372 cxcoutWHF <<
"WARNING: No POIs found in measurement: " << MeasurementName << std::endl;
380 while( (poi_obj=params_itr->
Next()) ) {
384 <<
" at " << poi->
getVal()<<
" high "
399 if( profile==NULL ) {
400 cxcoutEHF <<
"Error: Failed to make ProfileLikelihood for: " << poi->
GetName()
401 <<
" using model: " << model->
GetName()
402 <<
" and data: " << simData->
GetName()
408 if( frame == NULL ) {
409 cxcoutEHF <<
"Error: Failed to create RooPlot frame for: " << poi->
GetName() << std::endl;
415 TCanvas* ProfileLikelihoodCanvas =
new TCanvas( channel.c_str(),
"",800,600);
421 std::string ProfilePlotName = FileNamePrefix+
"_"+channel+
"_"+MeasurementName+
"_profileLR.eps";
422 ProfileLikelihoodCanvas->
SaveAs( ProfilePlotName.c_str() );
423 delete ProfileLikelihoodCanvas;
432 if( channel_dir == NULL ) {
433 cxcoutEHF <<
"Error: Failed to make channel directory: " << channel << std::endl;
437 if( summary_dir == NULL ) {
438 cxcoutEHF <<
"Error: Failed to make Summary directory for channel: "
439 << channel << std::endl;
452 for(
int i=0; i<curve_N; i++){
456 y_arr_nll[i]=nll->
getVal();
462 g->SetName( (FileNamePrefix +
"_nll").c_str() );
476 cxcoutIHF <<
"In Fit Model" << std::endl;
478 if(!combined_config){
479 cxcoutEHF <<
"no model config " <<
"ModelConfig" <<
" exiting" << std::endl;
485 cxcoutEHF <<
"no data " << data_name <<
" exiting" << std::endl;
491 cxcoutEHF <<
"no poi " << data_name <<
" exiting" << std::endl;
R__EXTERN TStyle * gStyle
R__EXTERN TSystem * gSystem
RooAbsArg * first() const
TIterator * createIterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
RooAbsData is the common abstract base class for binned and unbinned datasets.
virtual RooAbsReal * createNLL(RooAbsData &data, const RooLinkedList &cmdList)
Construct representation of -log(L) of PDFwith given dataset.
virtual RooFitResult * fitTo(RooAbsData &data, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none())
Fit PDF to given dataset.
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
virtual Double_t getMax(const char *name=0) const
Get maximum of currently defined range.
RooPlot * frame(const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Create a new RooPlot on the heap with a drawing frame initialized for this object,...
virtual Double_t getMin(const char *name=0) const
Get miniminum of currently defined range.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg(), const RooCmdArg &arg9=RooCmdArg(), const RooCmdArg &arg10=RooCmdArg()) const
Plot (project) PDF on specified frame.
virtual RooAbsReal * createProfile(const RooArgSet ¶msOfInterest)
Create a RooProfileLL object that eliminates all nuisance parameters in the present function.
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Add element to non-owning set.
A RooCurve is a one-dimensional graphical representation of a real-valued function.
static RooMsgService & instance()
Return reference to singleton instance.
A RooPlot is a plot frame and a container for graphics objects within that frame.
void addObject(TObject *obj, Option_t *drawOptions="", Bool_t invisible=kFALSE)
Add a generic object to this plot.
void SetTitle(const char *name)
Set the title of the RooPlot to 'title'.
virtual void SetMinimum(Double_t minimum=-1111)
Set minimum value of Y axis.
RooAbsRealLValue * getPlotVar() const
virtual void SetMaximum(Double_t maximum=-1111)
Set maximum value of Y axis.
RooCurve * getCurve(const char *name=0) const
Return a RooCurve pointer of the named object in this plot, or zero if the named object does not exis...
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
RooRealVar represents a variable that can be changed from the outside.
Double_t getErrorHi() const
Double_t getErrorLo() const
virtual void setVal(Double_t value)
Set value of variable to 'value'.
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.
double GetLumiRelErr()
retrieve relative uncertainty on luminosity
std::vector< std::string > & GetConstantParams()
get vector of all constant parameters
std::vector< RooStats::HistFactory::Channel > & GetChannels()
std::string GetOutputFilePrefix()
retrieve prefix for output files
std::vector< std::string > GetPreprocessFunctions() const
Returns a list of defined preprocess function expressions.
double GetLumi()
retrieve integrated luminosity
std::string GetPOI(unsigned int i=0)
get name of PoI at given index
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
const RooArgSet * GetParametersOfInterest() const
get RooArgSet containing the parameter of interest (return NULL if not existing)
const RooArgSet * GetNuisanceParameters() const
get RooArgSet containing the nuisance parameters (return NULL if not existing)
RooAbsPdf * GetPdf() const
get model PDF (return NULL if pdf has not been specified or does not exist)
The RooWorkspace is a persistable container for RooFit projects.
RooAbsData * data(const char *name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
Bool_t writeToFile(const char *fileName, Bool_t recreate=kTRUE)
Save this current workspace into given file.
Bool_t saveSnapshot(const char *name, const char *paramNames)
Save snapshot of values and attributes (including "Constant") of given parameters.
Bool_t loadSnapshot(const char *name)
Load the values and attributes of the parameters in the snapshot saved with the given name.
RooRealVar * var(const char *name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found.
TObject * obj(const char *name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name)
virtual void SetLineColor(Color_t lcolor)
Set the line color.
TDirectory * mkdir(const char *name, const char *title="", Bool_t returnExistingDirectory=kFALSE) override
Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".
Describe directory structure in memory.
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.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
void Close(Option_t *option="") override
Close a file.
A TGraph is an object made of two arrays X and Y with npoints each.
Iterator abstract base class.
virtual TObject * Next()=0
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
virtual const char * GetTitle() const
Returns title of object.
virtual const char * GetName() const
Returns name of object.
Mother of all ROOT objects.
void SaveAs(const char *filename="", Option_t *option="") const override
Save Pad contents in a file in one of various formats.
void SetPadBorderMode(Int_t mode=1)
void SetCanvasBorderMode(Int_t mode=1)
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.
RooCmdArg PrintLevel(Int_t code)
RooCmdArg Minos(Bool_t flag=kTRUE)
RooCmdArg LineColor(Color_t color)
RooCmdArg LineStyle(Style_t style)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
void FitModel(RooWorkspace *, std::string data_name="obsData")
void FormatFrameForLikelihood(RooPlot *frame, std::string xTitle=std::string("#sigma / #sigma_{SM}"), std::string yTitle=std::string("-log likelihood"))
void FitModelAndPlot(const std::string &measurementName, const std::string &fileNamePrefix, RooWorkspace *, std::string, std::string, TFile *, FILE *)
RooWorkspace * MakeModelAndMeasurementFast(RooStats::HistFactory::Measurement &measurement)