112 FILE* tableFile=
NULL;
116 std::cout <<
"Making Model and Measurements (Fast) for measurement: " << measurement.
GetName() << std::endl;
120 std::cout <<
"using lumi = " << measurement.
GetLumi() <<
" and lumiError = " << lumiError
121 <<
" including bins between " << measurement.
GetBinLow() <<
" and " << measurement.
GetBinHigh() << std::endl;
122 std::cout <<
"fixing the following parameters:" << std::endl;
125 std::cout <<
" " << *itr << std::endl;
128 std::string rowTitle = measurement.
GetName();
130 std::vector<RooWorkspace*> channel_workspaces;
131 std::vector<std::string> channel_names;
140 size_t pos = prefix.rfind(
"/");
141 if (pos != std::string::npos) {
142 std::string outputDir = prefix.substr(0,pos);
143 std::cout <<
"Checking if output directory : " << outputDir <<
" - exists" << std::endl;
145 std::cout <<
"Output directory : " << outputDir <<
" - does not exist, try to create" << std::endl;
148 std::string fullOutputDir = std::string(
gSystem->
pwd()) + std::string(
"/") + outputDir;
149 std::cout <<
"Error: Failed to make output directory: " << fullOutputDir << std::endl;
157 std::cout <<
"Creating the output file: " << outputFileName << std::endl;
158 outFile =
new TFile(outputFileName.c_str(),
"recreate");
163 std::cout <<
"Creating the table file: " << tableFileName << std::endl;
164 tableFile = fopen( tableFileName.c_str(),
"a");
166 std::cout <<
"Creating the HistoToWorkspaceFactoryFast factory" << std::endl;
171 std::cout <<
"Setting preprocess functions" << std::endl;
175 fprintf(tableFile,
" %s &", rowTitle.c_str() );
178 for(
unsigned int chanItr = 0; chanItr < measurement.
GetChannels().size(); ++chanItr ) {
182 std::cout <<
"MakeModelAndMeasurementsFast: Channel: " << channel.
GetName()
183 <<
" has uninitialized histogram pointers" << std::endl;
188 std::string ch_name = channel.
GetName();
189 std::cout <<
"Starting to process channel: " << ch_name << std::endl;
190 channel_names.push_back(ch_name);
192 channel_workspaces.push_back(ws_single);
196 + ch_name +
"_" + rowTitle +
"_model.root";
204 std::cout <<
"Opening File to hold channel: " << ChannelFileName << std::endl;
206 std::cout <<
"About to write channel measurement to file" << std::endl;
208 std::cout <<
"Successfully wrote channel to file" << std::endl;
217 std::cout <<
"Can't do fit for: " << measurement.
GetName()
218 <<
", no parameter of interest" << std::endl;
220 if(ws_single->
data(
"obsData")) {
222 ch_name,
"obsData", outFile, tableFile);
225 ch_name,
"asimovData", outFile, tableFile);
230 fprintf(tableFile,
" & " );
243 HistoToWorkspaceFactoryFast::ConfigureWorkspaceForMeasurement(
"simPdf", ws, measurement );
249 + rowTitle +
"_model.root";
250 std::cout <<
"Writing combined workspace to file: " << CombinedFileName << std::endl;
252 std::cout <<
"Writing combined measurement to file: " << CombinedFileName << std::endl;
254 if( combFile ==
NULL ) {
255 std::cout <<
"Error: Failed to open file " << CombinedFileName << std::endl;
264 std::cout <<
"Can't do fit for: " << measurement.
GetName()
265 <<
", no parameter of interest" << std::endl;
268 if(ws->
data(
"obsData")){
270 "obsData", outFile, tableFile);
274 "asimovData", outFile, tableFile);
279 fprintf(tableFile,
" \\\\ \n");
288 if( tableFile ) fclose(tableFile);
289 if(outFile) outFile->
Close();
300 const std::string& FileNamePrefix,
302 std::string data_name,
303 TFile* outFile, FILE* tableFile ) {
305 if( outFile ==
NULL ) {
306 std::cout <<
"Error: Output File in FitModelAndPlot is NULL" << std::endl;
310 if( tableFile ==
NULL ) {
311 std::cout <<
"Error: tableFile in FitModelAndPlot is NULL" << std::endl;
315 if( combined ==
NULL ) {
316 std::cout <<
"Error: Supplied workspace in FitModelAndPlot is NULL" << std::endl;
321 if(!combined_config){
322 std::cout <<
"Error: no ModelConfig found in Measurement: "
323 << MeasurementName << std::endl;
329 std::cout <<
"Error: Failed to get dataset: " << data_name
330 <<
" in measurement: " << MeasurementName << std::endl;
336 std::cout <<
"Not Fitting Model for measurement: " << MeasurementName
337 <<
", no poi found" << std::endl;
344 std::cout <<
"Error: Failed to find pdf in ModelConfig: " << combined_config->
GetName()
355 combined->
saveSnapshot(
"InitialValues", PoiPlusNuisance);
359 std::cout <<
"\n\n---------------" << std::endl;
360 std::cout <<
"---------------- Doing "<< channel <<
" Fit" << std::endl;
361 std::cout <<
"---------------\n\n" << std::endl;
367 std::cout <<
"WARNING: No POIs found in measurement: " << MeasurementName << std::endl;
375 while( (poi_obj=params_itr->
Next()) ) {
378 std::cout <<
"printing results for " << poi->
GetName()
379 <<
" at " << poi->
getVal()<<
" high "
394 if( profile==
NULL ) {
395 std::cout <<
"Error: Failed to make ProfileLikelihood for: " << poi->
GetName()
396 <<
" using model: " << model->
GetName()
397 <<
" and data: " << simData->
GetName()
403 if( frame ==
NULL ) {
404 std::cout <<
"Error: Failed to create RooPlot frame for: " << poi->
GetName() << std::endl;
410 TCanvas* ProfileLikelihoodCanvas =
new TCanvas( channel.c_str(),
"",800,600);
416 std::string ProfilePlotName = FileNamePrefix+
"_"+channel+
"_"+MeasurementName+
"_profileLR.eps";
417 ProfileLikelihoodCanvas->
SaveAs( ProfilePlotName.c_str() );
418 delete ProfileLikelihoodCanvas;
427 if( channel_dir ==
NULL ) {
428 std::cout <<
"Error: Failed to make channel directory: " << channel << std::endl;
432 if( summary_dir ==
NULL ) {
433 std::cout <<
"Error: Failed to make Summary directory for channel: "
434 << channel << std::endl;
448 for(
int i=0; i<curve_N; i++){
452 y_arr_nll[i]=nll->getVal();
456 g->
SetName( (FileNamePrefix +
"_nll").c_str() );
470 std::cout <<
"In Fit Model" << std::endl;
472 if(!combined_config){
473 std::cout <<
"no model config " <<
"ModelConfig" <<
" exiting" << std::endl;
479 std::cout <<
"no data " << data_name <<
" exiting" << std::endl;
485 std::cout <<
"no poi " << data_name <<
" exiting" << std::endl;
518 TLine * line90 =
new TLine(xmin,2.71/2.,xmax,2.71/2.);
520 TLine * line95 =
new TLine(xmin,3.84/2.,xmax,3.84/2.);
virtual RooAbsReal * createNLL(RooAbsData &data, const RooLinkedList &cmdList)
Construct representation of -log(L) of PDFwith given dataset.
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
virtual const char * GetTitle() const
Returns title of object.
Bool_t saveSnapshot(const char *name, const char *paramNames)
Save snapshot of values and attributes (including "Constant") of parameters 'params' If importValues ...
RooWorkspace * MakeCombinedModel(std::vector< std::string >, std::vector< RooWorkspace * >)
virtual TDirectory * mkdir(const char *name, const char *title="")
Create a sub-directory and return a pointer to the created directory.
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.
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
RooAbsPdf * GetPdf() const
get model PDF (return NULL if pdf has not been specified or does not exist)
RooCmdArg LineColor(Color_t color)
RooAbsData * data(const char *name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found...
RooWorkspace * MakeModelAndMeasurementFast(RooStats::HistFactory::Measurement &measurement)
void addObject(TObject *obj, Option_t *drawOptions="", Bool_t invisible=kFALSE)
Add a generic object to this plot.
RooCmdArg PrintLevel(Int_t code)
RooCmdArg Minos(Bool_t flag=kTRUE)
R__EXTERN TStyle * gStyle
virtual void SetName(const char *name)
Change (i.e.
std::string GetPOI(unsigned int i=0)
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.
virtual Double_t getMin(const char *name=0) const
virtual TDirectory * mkdir(const char *name, const char *title="")
Create a sub-directory and return a pointer to the created directory.
void SetTitle(const char *name)
Set the title of the RooPlot to 'title'.
RooWorkspace * MakeSingleChannelModel(Measurement &measurement, Channel &channel)
std::string GetOutputFilePrefix()
const RooArgSet * GetNuisanceParameters() const
get RooArgSet containing the nuisance parameters (return NULL if not existing)
Iterator abstract base class.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
std::vector< std::string > GetPreprocessFunctions()
void SetFunctionsToPreprocess(std::vector< std::string > lines)
RooAbsArg * first() const
virtual void SetMinimum(Double_t minimum=-1111)
Set minimum value of Y axis.
RooCmdArg LineStyle(Style_t style)
virtual void SaveAs(const char *filename="", Option_t *option="") const
Save Pad contents in a file in one of various formats.
std::vector< RooStats::HistFactory::Channel > & GetChannels()
TIterator * createIterator(Bool_t dir=kIterForward) const
Double_t getVal(const RooArgSet *set=0) const
virtual void setVal(Double_t value)
Set value of variable to 'value'.
virtual void SetLineColor(Color_t lcolor)
void SetPadBorderMode(Int_t mode=1)
void SetCanvasBorderMode(Int_t mode=1)
R__EXTERN TSystem * gSystem
virtual void SetMaximum(Double_t maximum=-1111)
Set maximum value of Y axis.
void FitModel(RooWorkspace *, std::string data_name="obsData")
virtual const char * GetName() const
Returns name of object.
Bool_t writeToFile(const char *fileName, Bool_t recreate=kTRUE)
Save this current workspace into given file.
Bool_t loadSnapshot(const char *name)
Load the values and attributes of the parameters in the snapshot saved with the given name...
RooAbsRealLValue * getPlotVar() 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
Double_t getErrorHi() const
RooRealVar * var(const char *name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found...
std::vector< std::string > & GetConstantParams()
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Describe directory structure in memory.
TObject * obj(const char *name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name) ...
Mother of all ROOT objects.
virtual Double_t getMax(const char *name=0) const
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
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 RooAbsReal * createProfile(const RooArgSet ¶msOfInterest)
Create a RooProfileLL object that eliminates all nuisance parameters in the present function...
virtual TObject * Next()=0
A Graph is a graphics object made of two arrays X and Y with npoints each.
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 *)
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
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.
const RooArgSet * GetParametersOfInterest() const
get RooArgSet containing the parameter of interest (return NULL if not existing)
Double_t getErrorLo() const
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
void writeToFile(TFile *file)
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add element to non-owning set.
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
virtual void Close(Option_t *option="")
Close a file.