Logo ROOT  
Reference Guide
MakeModelAndMeasurementsFast.cxx
Go to the documentation of this file.
1// @(#)root/roostats:$Id: cranmer $
2// Author: Kyle Cranmer, Akira Shibata
3/*************************************************************************
4 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
12
13// from std
14#include <string>
15#include <vector>
16#include <map>
17#include <iostream>
18#include <sstream>
19
20// from root
21#include "TFile.h"
22#include "TH1F.h"
23#include "TCanvas.h"
24#include "TStyle.h"
25#include "TLine.h"
26#include "TSystem.h"
27
28
29// from roofit
31
32// from this package
35
36#include "HFMsgService.h"
37
38using namespace RooFit;
39//using namespace RooStats;
40//using namespace HistFactory;
41
42//using namespace std;
43
44
45/** ********************************************************************************************
46 \ingroup HistFactory
47
48 <p>
49 This is a package that creates a RooFit probability density function from ROOT histograms
50 of expected distributions and histograms that represent the +/- 1 sigma variations
51 from systematic effects. The resulting probability density function can then be used
52 with any of the statistical tools provided within RooStats, such as the profile
53 likelihood ratio, Feldman-Cousins, etc. In this version, the model is directly
54 fed to a likelihood ratio test, but it needs to be further factorized.</p>
55
56 <p>
57 The user needs to provide histograms (in picobarns per bin) and configure the job
58 with XML. The configuration XML is defined in the file `$ROOTSYS/config/HistFactorySchema.dtd`, but essentially
59 it is organized as follows (see the examples in `${ROOTSYS}/tutorials/histfactory/`)</p>
60
61 <ul>
62 <li> a top level 'Combination' that is composed of:</li>
63 <ul>
64 <li> several 'Channels' (eg. ee, emu, mumu), which are composed of:</li>
65 <ul>
66 <li> several 'Samples' (eg. signal, bkg1, bkg2, ...), each of which has:</li>
67 <ul>
68 <li> a name</li>
69 <li> if the sample is normalized by theory (eg N = L*sigma) or not (eg. data driven)</li>
70 <li> a nominal expectation histogram</li>
71 <li> a named 'Normalization Factor' (which can be fixed or allowed to float in a fit)</li>
72 <li> several 'Overall Systematics' in normalization with:</li>
73 <ul>
74 <li> a name</li>
75 <li> +/- 1 sigma variations (eg. 1.05 and 0.95 for a 5% uncertainty)</li>
76 </ul>
77 <li> several 'Histogram Systematics' in shape with:</li>
78 <ul>
79 <li> a name (which can be shared with the OverallSyst if correlated)</li>
80 <li> +/- 1 sigma variational histograms</li>
81 </ul>
82 </ul>
83 </ul>
84 <li> several 'Measurements' (corresponding to a full fit of the model) each of which specifies</li>
85 <ul>
86 <li> a name for this fit to be used in tables and files</li>
87 <li> what is the luminosity associated to the measurement in picobarns</li>
88 <li> which bins of the histogram should be used</li>
89 <li> what is the relative uncertainty on the luminosity </li>
90 <li> what is (are) the parameter(s) of interest that will be measured</li>
91 <li> which parameters should be fixed/floating (eg. nuisance parameters)</li>
92 </ul>
93 </ul>
94 </ul>
95*/
97{
98 // This will be returned
99 RooWorkspace* ws = nullptr;
100 TFile* outFile = nullptr;
101 FILE* tableFile=nullptr;
102
103 auto& msgSvc = RooMsgService::instance();
104 msgSvc.getStream(1).removeTopic(RooFit::ObjectHandling);
105
106 try {
107
108 cxcoutIHF << "Making Model and Measurements (Fast) for measurement: " << measurement.GetName() << std::endl;
109
110 double lumiError = measurement.GetLumi()*measurement.GetLumiRelErr();
111
112 cxcoutIHF << "using lumi = " << measurement.GetLumi() << " and lumiError = " << lumiError
113 << " including bins between " << measurement.GetBinLow() << " and " << measurement.GetBinHigh() << std::endl;
114
115 std::ostringstream parameterMessage;
116 parameterMessage << "fixing the following parameters:" << std::endl;
117
118 for(std::vector<std::string>::iterator itr=measurement.GetConstantParams().begin(); itr!=measurement.GetConstantParams().end(); ++itr){
119 parameterMessage << " " << *itr << '\n';
120 }
121 cxcoutIHF << parameterMessage.str();
122
123 std::string rowTitle = measurement.GetName();
124
125 std::vector<std::unique_ptr<RooWorkspace>> channel_workspaces;
126 std::vector<std::string> channel_names;
127
128 // Create the outFile - first check if the outputfile exists
129 std::string prefix = measurement.GetOutputFilePrefix();
130 // parse prefix to find output directory -
131 // assume there is a file prefix after the last "/" that we remove
132 // to get the directory name.
133 // We do by finding last occurrence of "/" and using as directory name what is before
134 // if we do not have a "/" in the prefix there is no output directory to be checked or created
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;
139 if (gSystem->OpenDirectory( outputDir.c_str() ) == 0 ) {
140 cxcoutDHF << "Output directory : " << outputDir << " - does not exist, try to create" << std::endl;
141 int success = gSystem->MakeDirectory( outputDir.c_str() );
142 if( success != 0 ) {
143 std::string fullOutputDir = std::string(gSystem->pwd()) + std::string("/") + outputDir;
144 cxcoutEHF << "Error: Failed to make output directory: " << fullOutputDir << std::endl;
145 throw hf_exc();
146 }
147 }
148 }
149
150 // This holds the TGraphs that are created during the fit
151 std::string outputFileName = measurement.GetOutputFilePrefix() + "_" + measurement.GetName() + ".root";
152 cxcoutIHF << "Creating the output file: " << outputFileName << std::endl;
153 outFile = new TFile(outputFileName.c_str(), "recreate");
154
155 // Create the table file
156 // This holds the table of fitted values and errors
157 std::string tableFileName = measurement.GetOutputFilePrefix() + "_results.table";
158 cxcoutIHF << "Creating the table file: " << tableFileName << std::endl;
159 tableFile = fopen( tableFileName.c_str(), "a");
160
161 cxcoutIHF << "Creating the HistoToWorkspaceFactoryFast factory" << std::endl;
162 HistoToWorkspaceFactoryFast factory{measurement, cfg};
163
164 // Make the factory, and do some preprocessing
165 // HistoToWorkspaceFactoryFast factory(measurement, rowTitle, outFile);
166 cxcoutIHF << "Setting preprocess functions" << std::endl;
167 factory.SetFunctionsToPreprocess( measurement.GetPreprocessFunctions() );
168
169 // for results tables
170 fprintf(tableFile, " %s &", rowTitle.c_str() );
171
172 // First: Loop to make the individual channels
173 for( unsigned int chanItr = 0; chanItr < measurement.GetChannels().size(); ++chanItr ) {
174
175 HistFactory::Channel& channel = measurement.GetChannels().at( chanItr );
176 if( ! channel.CheckHistograms() ) {
177 cxcoutEHF << "MakeModelAndMeasurementsFast: Channel: " << channel.GetName()
178 << " has uninitialized histogram pointers" << std::endl;
179 throw hf_exc();
180 }
181
182 // Make the workspace for this individual channel
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);
188
189 // Make the output
190 std::string ChannelFileName = measurement.GetOutputFilePrefix() + "_"
191 + ch_name + "_" + rowTitle + "_model.root";
192 ws_single->writeToFile( ChannelFileName.c_str() );
193
194 // Now, write the measurement to the file
195 // Make a new measurement for only this channel
196 RooStats::HistFactory::Measurement meas_chan( measurement );
197 meas_chan.GetChannels().clear();
198 meas_chan.GetChannels().push_back( channel );
199 cxcoutIHF << "Opening File to hold channel: " << ChannelFileName << std::endl;
200 {
201 std::unique_ptr<TFile> chanFile{TFile::Open( ChannelFileName.c_str(), "UPDATE" )};
202 cxcoutIHF << "About to write channel measurement to file" << std::endl;
203 meas_chan.writeToFile( chanFile.get() );
204 cxcoutPHF << "Successfully wrote channel to file" << std::endl;
205 }
206
207 // Get the Paramater of Interest as a RooRealVar
208 RooRealVar* poi = dynamic_cast<RooRealVar*>( ws_single->var(measurement.GetPOI()));
209
210 // do fit unless exportOnly requested
211 if(! measurement.GetExportOnly()){
212 if(!poi) {
213 cxcoutWHF << "Can't do fit for: " << measurement.GetName()
214 << ", no parameter of interest" << std::endl;
215 } else {
216 if(ws_single->data("obsData")) {
217 FitModelAndPlot(measurement.GetName(), measurement.GetOutputFilePrefix(), ws_single,
218 ch_name, "obsData", outFile, tableFile);
219 } else {
220 FitModelAndPlot(measurement.GetName(), measurement.GetOutputFilePrefix(), ws_single,
221 ch_name, "asimovData", outFile, tableFile);
222 }
223 }
224 }
225
226 fprintf(tableFile, " & " );
227 } // End loop over channels
228
229 /***
230 Second: Make the combined model:
231 If you want output histograms in root format, create and pass it to the combine routine.
232 "combine" : will do the individual cross-section measurements plus combination
233 ***/
234
235 // Use HistFactory to combine the individual channel workspaces
236 ws = factory.MakeCombinedModel(channel_names, channel_workspaces);
237
238 // Configure that workspace
239 HistoToWorkspaceFactoryFast::ConfigureWorkspaceForMeasurement( "simPdf", ws, measurement );
240
241 // Get the Parameter of interest as a RooRealVar
242 RooRealVar* poi = dynamic_cast<RooRealVar*>( ws->var(measurement.GetPOI()));
243
244 std::string CombinedFileName = measurement.GetOutputFilePrefix() + "_combined_"
245 + rowTitle + "_model.root";
246 cxcoutPHF << "Writing combined workspace to file: " << CombinedFileName << std::endl;
247 ws->writeToFile( CombinedFileName.c_str() );
248 cxcoutPHF << "Writing combined measurement to file: " << CombinedFileName << std::endl;
249 {
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;
253 throw hf_exc();
254 }
255 measurement.writeToFile( combFile.get() );
256 }
257
258 // Fit the combined model
259 if(! measurement.GetExportOnly()){
260 if(!poi) {
261 cxcoutWHF << "Can't do fit for: " << measurement.GetName()
262 << ", no parameter of interest" << std::endl;
263 }
264 else {
265 if(ws->data("obsData")){
266 FitModelAndPlot(measurement.GetName(), measurement.GetOutputFilePrefix(), ws,"combined",
267 "obsData", outFile, tableFile);
268 }
269 else {
270 FitModelAndPlot(measurement.GetName(), measurement.GetOutputFilePrefix(), ws,"combined",
271 "asimovData", outFile, tableFile);
272 }
273 }
274 }
275
276 fprintf(tableFile, " \\\\ \n");
277
278 outFile->Close();
279 delete outFile;
280
281 fclose( tableFile );
282
283 }
284 catch(...) {
285 if( tableFile ) fclose(tableFile);
286 if(outFile) outFile->Close();
287 throw;
288 }
289
290 msgSvc.getStream(1).addTopic(RooFit::ObjectHandling);
291
292 return ws;
293
294}
295
296
297///////////////////////////////////////////////
298void RooStats::HistFactory::FitModelAndPlot(const std::string& MeasurementName,
299 const std::string& FileNamePrefix,
300 RooWorkspace * combined, std::string channel,
301 std::string data_name,
302 TFile* outFile, FILE* tableFile ) {
303
304 if( outFile == nullptr ) {
305 cxcoutEHF << "Error: Output File in FitModelAndPlot is nullptr" << std::endl;
306 throw hf_exc();
307 }
308
309 if( tableFile == nullptr ) {
310 cxcoutEHF << "Error: tableFile in FitModelAndPlot is nullptr" << std::endl;
311 throw hf_exc();
312 }
313
314 if( combined == nullptr ) {
315 cxcoutEHF << "Error: Supplied workspace in FitModelAndPlot is nullptr" << std::endl;
316 throw hf_exc();
317 }
318
319 ModelConfig* combined_config = (ModelConfig *) combined->obj("ModelConfig");
320 if(!combined_config){
321 cxcoutEHF << "Error: no ModelConfig found in Measurement: "
322 << MeasurementName << std::endl;
323 throw hf_exc();
324 }
325
326 RooAbsData* simData = combined->data(data_name.c_str());
327 if(!simData){
328 cxcoutEHF << "Error: Failed to get dataset: " << data_name
329 << " in measurement: " << MeasurementName << std::endl;
330 throw hf_exc();
331 }
332
333 const RooArgSet* POIs = combined_config->GetParametersOfInterest();
334 if(!POIs) {
335 cxcoutEHF << "Not Fitting Model for measurement: " << MeasurementName
336 << ", no poi found" << std::endl;
337 // Should I throw an exception here?
338 return;
339 }
340
341 RooAbsPdf* model = combined_config->GetPdf();
342 if( model==nullptr ) {
343 cxcoutEHF << "Error: Failed to find pdf in ModelConfig: " << combined_config->GetName()
344 << std::endl;
345 throw hf_exc();
346 }
347
348 // Save a Snapshot
349 RooArgSet PoiPlusNuisance;
350 if( combined_config->GetNuisanceParameters() ) {
351 PoiPlusNuisance.add( *combined_config->GetNuisanceParameters() );
352 }
353 PoiPlusNuisance.add( *combined_config->GetParametersOfInterest() );
354 combined->saveSnapshot("InitialValues", PoiPlusNuisance);
355
356 ///////////////////////////////////////
357 // Do the fit
358 cxcoutPHF << "\n---------------"
359 << "\nDoing "<< channel << " Fit"
360 << "\n---------------\n\n" << std::endl;
361 model->fitTo(*simData, Minos(true), PrintLevel(RooMsgService::instance().isActive(static_cast<TObject*>(nullptr), RooFit::HistFactory, RooFit::DEBUG) ? 1 : -1));
362
363 // If there are no parameters of interest,
364 // we exit the function here
365 if( POIs->empty() ) {
366 cxcoutWHF << "WARNING: No POIs found in measurement: " << MeasurementName << std::endl;
367 return;
368 }
369
370 // Loop over all POIs and print their fitted values
371 for (auto const *poi : static_range_cast<RooRealVar *>(*POIs)) {
372 cxcoutIHF << "printing results for " << poi->GetName()
373 << " at " << poi->getVal()<< " high "
374 << poi->getErrorLo() << " low "
375 << poi->getErrorHi() << std::endl;
376 }
377
378 // But we only make detailed plots and tables
379 // for the 'first' POI
380 RooRealVar* poi = static_cast<RooRealVar *>(POIs->first());
381
382 // Print the MINOS errors to the TableFile
383 fprintf(tableFile, " %.4f / %.4f ", poi->getErrorLo(), poi->getErrorHi());
384
385 // Make the Profile Likelihood Plot
386 RooAbsReal* nll = model->createNLL(*simData);
387 RooAbsReal* profile = nll->createProfile(*poi);
388 if( profile==nullptr ) {
389 cxcoutEHF << "Error: Failed to make ProfileLikelihood for: " << poi->GetName()
390 << " using model: " << model->GetName()
391 << " and data: " << simData->GetName()
392 << std::endl;
393 throw hf_exc();
394 }
395
396 RooPlot* frame = poi->frame();
397 if( frame == nullptr ) {
398 cxcoutEHF << "Error: Failed to create RooPlot frame for: " << poi->GetName() << std::endl;
399 throw hf_exc();
400 }
401
402 // Draw the likelihood curve
404 TCanvas* ProfileLikelihoodCanvas = new TCanvas( channel.c_str(), "",800,600);
406 profile->plotOn(frame);
407 frame->SetMinimum(0);
408 frame->SetMaximum(2.);
409 frame->Draw();
410 std::string ProfilePlotName = FileNamePrefix+"_"+channel+"_"+MeasurementName+"_profileLR.eps";
411 ProfileLikelihoodCanvas->SaveAs( ProfilePlotName.c_str() );
412 delete ProfileLikelihoodCanvas;
413
414 // Now, we save our results to the 'output' file
415 // (I'm not sure if users actually look into this file,
416 // but adding additional information and useful plots
417 // may make it more attractive)
418
419 // Save to the output file
420 TDirectory* channel_dir = outFile->mkdir(channel.c_str());
421 if( channel_dir == nullptr ) {
422 cxcoutEHF << "Error: Failed to make channel directory: " << channel << std::endl;
423 throw hf_exc();
424 }
425 TDirectory* summary_dir = channel_dir->mkdir("Summary");
426 if( summary_dir == nullptr ) {
427 cxcoutEHF << "Error: Failed to make Summary directory for channel: "
428 << channel << std::endl;
429 throw hf_exc();
430 }
431 summary_dir->cd();
432
433 // Save a graph of the profile likelihood curve
434 RooCurve* curve=frame->getCurve();
435 Int_t curve_N=curve->GetN();
436 double* curve_x=curve->GetX();
437
438 double * x_arr = new double[curve_N];
439 double * y_arr_nll = new double[curve_N];
440
441 for(int i=0; i<curve_N; i++){
442 double f=curve_x[i];
443 poi->setVal(f);
444 x_arr[i]=f;
445 y_arr_nll[i]=nll->getVal();
446 }
447
448 delete frame;
449
450 TGraph* g = new TGraph(curve_N, x_arr, y_arr_nll);
451 g->SetName( (FileNamePrefix +"_nll").c_str() );
452 g->Write();
453 delete g;
454 delete [] x_arr;
455 delete [] y_arr_nll;
456
457 // Finally, restore the initial values
458 combined->loadSnapshot("InitialValues");
459
460}
461
462
463void RooStats::HistFactory::FitModel(RooWorkspace * combined, std::string data_name ) {
464
465 cxcoutIHF << "In Fit Model" << std::endl;
466 ModelConfig * combined_config = (ModelConfig *) combined->obj("ModelConfig");
467 if(!combined_config){
468 cxcoutEHF << "no model config " << "ModelConfig" << " exiting" << std::endl;
469 return;
470 }
471
472 RooAbsData* simData = combined->data(data_name.c_str());
473 if(!simData){
474 cxcoutEHF << "no data " << data_name << " exiting" << std::endl;
475 return;
476 }
477
478 const RooArgSet * POIs=combined_config->GetParametersOfInterest();
479 if(!POIs){
480 cxcoutEHF << "no poi " << data_name << " exiting" << std::endl;
481 return;
482 }
483
484 RooAbsPdf* model=combined_config->GetPdf();
485 model->fitTo(*simData, Minos(true), PrintLevel(1));
486
487 }
488
489
491 std::string YTitle){
492
495 // gStyle->SetPadColor(0);
496 // gStyle->SetCanvasColor(255);
497 // gStyle->SetTitleFillColor(255);
498 // gStyle->SetFrameFillColor(0);
499 // gStyle->SetStatColor(255);
500
501 RooAbsRealLValue* var = frame->getPlotVar();
502 double xmin = var->getMin();
503 double xmax = var->getMax();
504
505 frame->SetTitle("");
506 // frame->GetXaxis()->SetTitle(XTitle.c_str());
507 frame->GetXaxis()->SetTitle(var->GetTitle());
508 frame->GetYaxis()->SetTitle(YTitle.c_str());
509 frame->SetMaximum(2.);
510 frame->SetMinimum(0.);
511 TLine * line = new TLine(xmin,.5,xmax,.5);
513 TLine * line90 = new TLine(xmin,2.71/2.,xmax,2.71/2.);
514 line90->SetLineColor(kGreen);
515 TLine * line95 = new TLine(xmin,3.84/2.,xmax,3.84/2.);
516 line95->SetLineColor(kGreen);
517 frame->addObject(line);
518 frame->addObject(line90);
519 frame->addObject(line95);
520}
#define cxcoutPHF
Definition: HFMsgService.h:18
#define cxcoutDHF
Definition: HFMsgService.h:16
#define cxcoutIHF
Definition: HFMsgService.h:17
#define cxcoutWHF
Definition: HFMsgService.h:19
#define cxcoutEHF
Definition: HFMsgService.h:20
#define f(i)
Definition: RSha256.hxx:104
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
@ kRed
Definition: Rtypes.h:66
@ kGreen
Definition: Rtypes.h:66
@ kDashed
Definition: TAttLine.h:48
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
float xmin
Definition: THbookFile.cxx:95
float xmax
Definition: THbookFile.cxx:95
R__EXTERN TStyle * gStyle
Definition: TStyle.h:414
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
bool empty() const
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.
Definition: RooAbsData.h:62
virtual RooAbsReal * createNLL(RooAbsData &data, const RooLinkedList &cmdList)
Construct representation of -log(L) of PDFwith given dataset.
Definition: RooAbsPdf.cxx:998
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.
Definition: RooAbsPdf.cxx:1460
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...
Definition: RooAbsReal.h:62
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
virtual RooAbsReal * createProfile(const RooArgSet &paramsOfInterest)
Create a RooProfileLL object that eliminates all nuisance parameters in the present function.
Definition: RooAbsReal.cxx:484
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.
Definition: RooArgSet.h:56
A RooCurve is a one-dimensional graphical representation of a real-valued function.
Definition: RooCurve.h:32
static RooMsgService & instance()
Return reference to singleton instance.
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:43
void SetTitle(const char *name) override
Set the title of the RooPlot to 'title'.
Definition: RooPlot.cxx:1249
void addObject(TObject *obj, Option_t *drawOptions="", bool invisible=false)
Add a generic object to this plot.
Definition: RooPlot.cxx:410
void Draw(Option_t *options=0) override
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:679
virtual void SetMinimum(double minimum=-1111)
Set minimum value of Y axis.
Definition: RooPlot.cxx:1089
virtual void SetMaximum(double maximum=-1111)
Set maximum value of Y axis.
Definition: RooPlot.cxx:1079
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1270
RooAbsRealLValue * getPlotVar() const
Definition: RooPlot.h:140
TAxis * GetXaxis() const
Definition: RooPlot.cxx:1268
RooCurve * getCurve(const char *name=nullptr) const
Return a RooCurve pointer of the named object in this plot, or zero if the named object does not exis...
Definition: RooPlot.cxx:890
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
void setVal(double value) override
Set value of variable to 'value'.
Definition: RooRealVar.cxx:254
double getErrorLo() const
Definition: RooRealVar.h:71
double getErrorHi() const
Definition: RooRealVar.h:72
This class encapsulates all information for the statistical interpretation of one experiment.
Definition: Channel.h:30
std::string GetName() const
get name of channel
Definition: Channel.h:43
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...
Definition: Measurement.h:31
void writeToFile(TFile *file)
A measurement, once fully configured, can be saved into a ROOT file.
double GetLumiRelErr()
retrieve relative uncertainty on luminosity
Definition: Measurement.h:91
std::vector< std::string > & GetConstantParams()
get vector of all constant parameters
Definition: Measurement.h:60
std::vector< RooStats::HistFactory::Channel > & GetChannels()
Definition: Measurement.h:105
std::string GetOutputFilePrefix()
retrieve prefix for output files
Definition: Measurement.h:42
std::vector< std::string > GetPreprocessFunctions() const
Returns a list of defined preprocess function expressions.
double GetLumi()
retrieve integrated luminosity
Definition: Measurement.h:89
std::string GetPOI(unsigned int i=0)
get name of PoI at given index
Definition: Measurement.h:49
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition: ModelConfig.h:30
const RooArgSet * GetParametersOfInterest() const
get RooArgSet containing the parameter of interest (return nullptr if not existing)
Definition: ModelConfig.h:234
const RooArgSet * GetNuisanceParameters() const
get RooArgSet containing the nuisance parameters (return nullptr if not existing)
Definition: ModelConfig.h:237
RooAbsPdf * GetPdf() const
get model PDF (return nullptr if pdf has not been specified or does not exist)
Definition: ModelConfig.h:231
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:43
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.
Definition: TAttLine.h:40
The Canvas class.
Definition: TCanvas.h:23
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.
Definition: TDirectory.h:45
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.
Definition: TDirectory.cxx:504
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
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.
Definition: TFile.cxx:4019
void Close(Option_t *option="") override
Close a file.
Definition: TFile.cxx:891
A TGraph is an object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
Int_t GetN() const
Definition: TGraph.h:126
Double_t * GetX() const
Definition: TGraph.h:133
Use the TLine constructor to create a simple line.
Definition: TLine.h:22
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition: TNamed.h:48
Mother of all ROOT objects.
Definition: TObject.h:37
void SaveAs(const char *filename="", Option_t *option="") const override
Save the pad content in a file.
Definition: TPad.cxx:5606
void SetPadBorderMode(Int_t mode=1)
Definition: TStyle.h:341
void SetCanvasBorderMode(Int_t mode=1)
Definition: TStyle.h:330
const char * pwd()
Definition: TSystem.h:422
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Definition: TSystem.cxx:837
virtual int MakeDirectory(const char *name)
Make a directory.
Definition: TSystem.cxx:828
TLine * line
RooCmdArg Minos(bool flag=true)
RooCmdArg PrintLevel(Int_t code)
RooWorkspace * MakeModelAndMeasurementFast(RooStats::HistFactory::Measurement &measurement, HistoToWorkspaceFactoryFast::Configuration const &cfg={})
RooCmdArg ShiftToZero()
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...
Definition: Common.h:18
@ HistFactory
Definition: RooGlobalFunc.h:65
@ ObjectHandling
Definition: RooGlobalFunc.h:64
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 *)