112 TFile* outFile = NULL;
113 FILE* tableFile=NULL;
117 std::cout <<
"Making Model and Measurements (Fast) for measurement: " << measurement.
GetName() << std::endl;
121 std::cout <<
"using lumi = " << measurement.
GetLumi() <<
" and lumiError = " << lumiError
122 <<
" including bins between " << measurement.
GetBinLow() <<
" and " << measurement.
GetBinHigh() << std::endl;
123 std::cout <<
"fixing the following parameters:" << std::endl;
126 std::cout <<
" " << *itr << std::endl;
129 std::string rowTitle = measurement.
GetName();
131 std::vector<RooWorkspace*> channel_workspaces;
132 std::vector<std::string> channel_names;
141 size_t pos = prefix.rfind(
"/");
142 if (pos != std::string::npos) {
143 std::string outputDir = prefix.substr(0,pos);
144 std::cout <<
"Checking if output directory : " << outputDir <<
" - exists" << std::endl;
146 std::cout <<
"Output directory : " << outputDir <<
" - does not exist, try to create" << std::endl;
149 std::string fullOutputDir = std::string(
gSystem->
pwd()) + std::string(
"/") + outputDir;
150 std::cout <<
"Error: Failed to make output directory: " << fullOutputDir << std::endl;
158 std::cout <<
"Creating the output file: " << outputFileName << std::endl;
159 outFile =
new TFile(outputFileName.c_str(),
"recreate");
164 std::cout <<
"Creating the table file: " << tableFileName << std::endl;
165 tableFile = fopen( tableFileName.c_str(),
"a");
167 std::cout <<
"Creating the HistoToWorkspaceFactoryFast factory" << std::endl;
172 std::cout <<
"Setting preprocess functions" << std::endl;
176 fprintf(tableFile,
" %s &", rowTitle.c_str() );
179 for(
unsigned int chanItr = 0; chanItr < measurement.
GetChannels().size(); ++chanItr ) {
183 std::cout <<
"MakeModelAndMeasurementsFast: Channel: " << channel.
GetName()
184 <<
" has uninitialized histogram pointers" << std::endl;
189 std::string ch_name = channel.
GetName();
190 std::cout <<
"Starting to process channel: " << ch_name << std::endl;
191 channel_names.push_back(ch_name);
193 channel_workspaces.push_back(ws_single);
197 + ch_name +
"_" + rowTitle +
"_model.root";
205 std::cout <<
"Opening File to hold channel: " << ChannelFileName << std::endl;
206 TFile* chanFile =
TFile::Open( ChannelFileName.c_str(),
"UPDATE" );
207 std::cout <<
"About to write channel measurement to file" << std::endl;
209 std::cout <<
"Successfully wrote channel to file" << std::endl;
218 std::cout <<
"Can't do fit for: " << measurement.
GetName()
219 <<
", no parameter of interest" << std::endl;
221 if(ws_single->
data(
"obsData")) {
223 ch_name,
"obsData", outFile, tableFile);
226 ch_name,
"asimovData", outFile, tableFile);
231 fprintf(tableFile,
" & " );
241 ws =
factory.MakeCombinedModel(channel_names, channel_workspaces);
244 HistoToWorkspaceFactoryFast::ConfigureWorkspaceForMeasurement(
"simPdf",
ws, measurement );
250 + rowTitle +
"_model.root";
251 std::cout <<
"Writing combined workspace to file: " << CombinedFileName << std::endl;
252 ws->writeToFile( CombinedFileName.c_str() );
253 std::cout <<
"Writing combined measurement to file: " << CombinedFileName << std::endl;
254 TFile* combFile =
TFile::Open( CombinedFileName.c_str(),
"UPDATE" );
255 if( combFile == NULL ) {
256 std::cout <<
"Error: Failed to open file " << CombinedFileName << std::endl;
265 std::cout <<
"Can't do fit for: " << measurement.
GetName()
266 <<
", no parameter of interest" << std::endl;
269 if(
ws->data(
"obsData")){
271 "obsData", outFile, tableFile);
275 "asimovData", outFile, tableFile);
280 fprintf(tableFile,
" \\\\ \n");
289 if( tableFile ) fclose(tableFile);
290 if(outFile) outFile->Close();
301 const std::string& FileNamePrefix,
303 std::string data_name,
304 TFile* outFile, FILE* tableFile ) {
306 if( outFile == NULL ) {
307 std::cout <<
"Error: Output File in FitModelAndPlot is NULL" << std::endl;
311 if( tableFile == NULL ) {
312 std::cout <<
"Error: tableFile in FitModelAndPlot is NULL" << std::endl;
316 if( combined == NULL ) {
317 std::cout <<
"Error: Supplied workspace in FitModelAndPlot is NULL" << std::endl;
322 if(!combined_config){
323 std::cout <<
"Error: no ModelConfig found in Measurement: "
324 << MeasurementName << std::endl;
330 std::cout <<
"Error: Failed to get dataset: " << data_name
331 <<
" in measurement: " << MeasurementName << std::endl;
337 std::cout <<
"Not Fitting Model for measurement: " << MeasurementName
338 <<
", no poi found" << std::endl;
345 std::cout <<
"Error: Failed to find pdf in ModelConfig: " << combined_config->
GetName()
356 combined->
saveSnapshot(
"InitialValues", PoiPlusNuisance);
360 std::cout <<
"\n\n---------------" << std::endl;
361 std::cout <<
"---------------- Doing "<< channel <<
" Fit" << std::endl;
362 std::cout <<
"---------------\n\n" << std::endl;
368 std::cout <<
"WARNING: No POIs found in measurement: " << MeasurementName << std::endl;
376 while( (poi_obj=params_itr->
Next()) ) {
379 std::cout <<
"printing results for " << poi->
GetName()
380 <<
" at " << poi->
getVal()<<
" high "
395 if( profile==NULL ) {
396 std::cout <<
"Error: Failed to make ProfileLikelihood for: " << poi->
GetName()
397 <<
" using model: " <<
model->GetName()
398 <<
" and data: " << simData->
GetName()
404 if( frame == NULL ) {
405 std::cout <<
"Error: Failed to create RooPlot frame for: " << poi->
GetName() << std::endl;
411 TCanvas* ProfileLikelihoodCanvas =
new TCanvas( channel.c_str(),
"",800,600);
417 std::string ProfilePlotName = FileNamePrefix+
"_"+channel+
"_"+MeasurementName+
"_profileLR.eps";
418 ProfileLikelihoodCanvas->
SaveAs( ProfilePlotName.c_str() );
419 delete ProfileLikelihoodCanvas;
428 if( channel_dir == NULL ) {
429 std::cout <<
"Error: Failed to make channel directory: " << channel << std::endl;
433 if( summary_dir == NULL ) {
434 std::cout <<
"Error: Failed to make Summary directory for channel: "
435 << channel << std::endl;
448 for(
int i=0; i<curve_N; i++){
452 y_arr_nll[i]=nll->
getVal();
458 g->SetName( (FileNamePrefix +
"_nll").c_str() );
472 std::cout <<
"In Fit Model" << std::endl;
474 if(!combined_config){
475 std::cout <<
"no model config " <<
"ModelConfig" <<
" exiting" << std::endl;
481 std::cout <<
"no data " << data_name <<
" exiting" << std::endl;
487 std::cout <<
"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
RooAbsData is the common abstract base class for binned and unbinned datasets.
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
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
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
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 *set=0) const
Evaluate object. Returns either cached value or triggers a recalculation.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
A RooCurve is a one-dimensional graphical representation of a real-valued function.
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 fundamental (non-derived) real valued object.
Double_t getErrorHi() const
Double_t getErrorLo() const
virtual void setVal(Double_t value)
Set value of variable to 'value'.
This class encapsulates all information for the statistical interpretation of one experiment.
std::string GetName()
get name of channel
The RooStats::HistFactory::Measurement class can be used to construct a model by combining multiple R...
void writeToFile(TFile *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
double GetLumi()
retrieve integrated luminosity
std::string GetPOI(unsigned int i=0)
get name of PoI at given index
std::vector< std::string > GetPreprocessFunctions()
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 parameters 'params' If importValues ...
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.
Describe directory structure in memory.
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/...".
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose, Int_t netopt=0)
Create / open a file.
A Graph is a graphics 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.
virtual void SaveAs(const char *filename="", Option_t *option="") const
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 LineColor(Color_t color)
RooCmdArg LineStyle(Style_t style)
RooCmdArg Minos(Bool_t flag=kTRUE)
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)
Make a model from histograms.