100 std::unique_ptr<TFile> outFile;
101 FILE* tableFile=
nullptr;
108 cxcoutIHF <<
"Making Model and Measurements (Fast) for measurement: " << measurement.
GetName() << std::endl;
112 cxcoutIHF <<
"using lumi = " << measurement.
GetLumi() <<
" and lumiError = " << lumiError
113 <<
" including bins between " << measurement.
GetBinLow() <<
" and " << measurement.
GetBinHigh() << std::endl;
115 std::ostringstream parameterMessage;
116 parameterMessage <<
"fixing the following parameters:" << std::endl;
119 parameterMessage <<
" " << *itr <<
'\n';
123 std::string rowTitle = measurement.
GetName();
125 std::vector<std::unique_ptr<RooWorkspace>> channel_workspaces;
126 std::vector<std::string> channel_names;
135 size_t pos = prefix.rfind(
"/");
136 if (pos != std::string::npos) {
137 std::string outputDir = prefix.substr(0,pos);
138 cxcoutDHF <<
"Checking if output directory : " << outputDir <<
" - exists" << std::endl;
140 cxcoutDHF <<
"Output directory : " << outputDir <<
" - does not exist, try to create" << std::endl;
143 std::string fullOutputDir = std::string(
gSystem->
pwd()) + std::string(
"/") + outputDir;
144 cxcoutEHF <<
"Error: Failed to make output directory: " << fullOutputDir << std::endl;
152 cxcoutIHF <<
"Creating the output file: " << outputFileName << std::endl;
153 outFile = std::make_unique<TFile>(outputFileName.c_str(),
"recreate");
158 cxcoutIHF <<
"Creating the table file: " << tableFileName << std::endl;
159 tableFile = fopen( tableFileName.c_str(),
"a");
161 cxcoutIHF <<
"Creating the HistoToWorkspaceFactoryFast factory" << std::endl;
166 cxcoutIHF <<
"Setting preprocess functions" << std::endl;
170 fprintf(tableFile,
" %s &", rowTitle.c_str() );
173 for(
unsigned int chanItr = 0; chanItr < measurement.
GetChannels().
size(); ++chanItr ) {
178 <<
" has uninitialized histogram pointers" << std::endl;
183 std::string ch_name = channel.
GetName();
184 cxcoutPHF <<
"Starting to process channel: " << ch_name << std::endl;
185 channel_names.push_back(ch_name);
186 RooWorkspace* ws_single = factory.MakeSingleChannelModel( measurement, channel );
187 channel_workspaces.emplace_back(ws_single);
191 + ch_name +
"_" + rowTitle +
"_model.root";
199 cxcoutIHF <<
"Opening File to hold channel: " << ChannelFileName << std::endl;
201 std::unique_ptr<TFile> chanFile{
TFile::Open( ChannelFileName.c_str(),
"UPDATE" )};
202 cxcoutIHF <<
"About to write channel measurement to file" << std::endl;
204 cxcoutPHF <<
"Successfully wrote channel to file" << std::endl;
214 <<
", no parameter of interest" << std::endl;
216 if(ws_single->
data(
"obsData")) {
218 ch_name,
"obsData", outFile.get(), tableFile);
221 ch_name,
"asimovData", outFile.get(), tableFile);
226 fprintf(tableFile,
" & " );
236 ws = factory.MakeCombinedModel(channel_names, channel_workspaces);
239 HistoToWorkspaceFactoryFast::ConfigureWorkspaceForMeasurement(
"simPdf", ws, measurement );
245 + rowTitle +
"_model.root";
246 cxcoutPHF <<
"Writing combined workspace to file: " << CombinedFileName << std::endl;
248 cxcoutPHF <<
"Writing combined measurement to file: " << CombinedFileName << std::endl;
250 std::unique_ptr<TFile> combFile{
TFile::Open( CombinedFileName.c_str(),
"UPDATE" )};
251 if( combFile ==
nullptr ) {
252 cxcoutEHF <<
"Error: Failed to open file " << CombinedFileName << std::endl;
262 <<
", no parameter of interest" << std::endl;
265 if(ws->
data(
"obsData")){
267 "obsData", outFile.get(), tableFile);
271 "asimovData", outFile.get(), tableFile);
276 fprintf(tableFile,
" \\\\ \n");
282 if( tableFile ) fclose(tableFile);
295 const std::string& FileNamePrefix,
297 std::string data_name,
298 TFile* outFile, FILE* tableFile ) {
300 if( outFile ==
nullptr ) {
301 cxcoutEHF <<
"Error: Output File in FitModelAndPlot is nullptr" << std::endl;
305 if( tableFile ==
nullptr ) {
306 cxcoutEHF <<
"Error: tableFile in FitModelAndPlot is nullptr" << std::endl;
310 if( combined ==
nullptr ) {
311 cxcoutEHF <<
"Error: Supplied workspace in FitModelAndPlot is nullptr" << std::endl;
316 if(!combined_config){
317 cxcoutEHF <<
"Error: no ModelConfig found in Measurement: "
318 << MeasurementName << std::endl;
324 cxcoutEHF <<
"Error: Failed to get dataset: " << data_name
325 <<
" in measurement: " << MeasurementName << std::endl;
331 cxcoutEHF <<
"Not Fitting Model for measurement: " << MeasurementName
332 <<
", no poi found" << std::endl;
338 if( model==
nullptr ) {
339 cxcoutEHF <<
"Error: Failed to find pdf in ModelConfig: " << combined_config->
GetName()
350 combined->
saveSnapshot(
"InitialValues", PoiPlusNuisance);
355 <<
"\nDoing "<< channel <<
" Fit"
356 <<
"\n---------------\n\n" << std::endl;
361 if( POIs->
empty() ) {
362 cxcoutWHF <<
"WARNING: No POIs found in measurement: " << MeasurementName << std::endl;
367 for (
auto const *poi : static_range_cast<RooRealVar *>(*POIs)) {
368 cxcoutIHF <<
"printing results for " << poi->GetName()
369 <<
" at " << poi->getVal()<<
" high "
370 << poi->getErrorLo() <<
" low "
371 << poi->getErrorHi() << std::endl;
384 if( profile==
nullptr ) {
385 cxcoutEHF <<
"Error: Failed to make ProfileLikelihood for: " << poi->
GetName()
386 <<
" using model: " << model->
GetName()
387 <<
" and data: " << simData->
GetName()
392 std::unique_ptr<RooPlot> frame{poi->
frame()};
397 TCanvas profileLikelihoodCanvas{channel.c_str(),
"",800,600};
399 profile->
plotOn(frame.get());
401 frame->SetMaximum(2.);
403 std::string profilePlotName = FileNamePrefix+
"_"+channel+
"_"+MeasurementName+
"_profileLR.eps";
404 profileLikelihoodCanvas.SaveAs( profilePlotName.c_str() );
414 if( channel_dir ==
nullptr ) {
415 cxcoutEHF <<
"Error: Failed to make channel directory: " << channel << std::endl;
419 if( summary_dir ==
nullptr ) {
420 cxcoutEHF <<
"Error: Failed to make Summary directory for channel: "
421 << channel << std::endl;
429 double* curve_x=curve->
GetX();
431 std::vector<double> x_arr(curve_N);
432 std::vector<double> y_arr_nll(curve_N);
434 for(
int i=0; i<curve_N; i++){
438 y_arr_nll[i]=nll->
getVal();
441 TGraph g{curve_N, x_arr.data(), y_arr_nll.data()};
442 g.SetName( (FileNamePrefix +
"_nll").c_str() );
453 cxcoutIHF <<
"In Fit Model" << std::endl;
455 if(!combined_config){
456 cxcoutEHF <<
"no model config " <<
"ModelConfig" <<
" exiting" << std::endl;
462 cxcoutEHF <<
"no data " << data_name <<
" exiting" << std::endl;
468 cxcoutEHF <<
"no poi " << data_name <<
" exiting" << std::endl;
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t g
R__EXTERN TStyle * gStyle
R__EXTERN TSystem * gSystem
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooAbsArg * first() const
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 PDF with given dataset.
virtual RooFitResult * fitTo(RooAbsData &data, const RooLinkedList &cmdList={})
Fit PDF to given dataset.
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
virtual double getMax(const char *name=nullptr) 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 getMin(const char *name=nullptr) const
Get minimum of currently defined range.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
virtual RooAbsReal * createProfile(const RooArgSet ¶msOfInterest)
Create a RooProfileLL object that eliminates all nuisance parameters in the present function.
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.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
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 SetTitle(const char *name) override
Set the title of the RooPlot to 'title'.
void addObject(TObject *obj, Option_t *drawOptions="", bool invisible=false)
Add a generic object to this plot.
virtual void SetMinimum(double minimum=-1111)
Set minimum value of Y axis.
virtual void SetMaximum(double maximum=-1111)
Set maximum value of Y axis.
RooAbsRealLValue * getPlotVar() const
RooRealVar represents a variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
double getErrorLo() const
double getErrorHi() const
This class encapsulates all information for the statistical interpretation of one experiment.
bool CheckHistograms() const
std::string GetName() const
get name of channel
This class provides helper functions for creating likelihood models from histograms.
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 nullptr if not existing)
const RooArgSet * GetNuisanceParameters() const
get RooArgSet containing the nuisance parameters (return nullptr if not existing)
RooAbsPdf * GetPdf() const
get model PDF (return nullptr if pdf has not been specified or does not exist)
The RooWorkspace is a persistable container for RooFit projects.
TObject * obj(RooStringView name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name)
bool writeToFile(const char *fileName, bool recreate=true)
Save this current workspace into given file.
bool saveSnapshot(const char *name, const char *paramNames)
Save snapshot of values and attributes (including "Constant") of given parameters.
RooRealVar * var(RooStringView name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found.
RooAbsData * data(RooStringView name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
bool loadSnapshot(const char *name)
Load the values and attributes of the parameters in the snapshot saved with the 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 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.
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.
A TGraph is an object made of two arrays X and Y with npoints each.
Use the TLine constructor to create a simple line.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
Mother of all ROOT objects.
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 Minos(bool flag=true)
RooCmdArg PrintLevel(Int_t code)
RooWorkspace * MakeModelAndMeasurementFast(RooStats::HistFactory::Measurement &measurement, HistoToWorkspaceFactoryFast::Configuration const &cfg={})
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 *)