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 std::unique_ptr<TFile> outFile;
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 = std::make_unique<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.get(), tableFile);
219 } else {
220 FitModelAndPlot(measurement.GetName(), measurement.GetOutputFilePrefix(), ws_single,
221 ch_name, "asimovData", outFile.get(), 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.get(), tableFile);
268 }
269 else {
270 FitModelAndPlot(measurement.GetName(), measurement.GetOutputFilePrefix(), ws,"combined",
271 "asimovData", outFile.get(), tableFile);
272 }
273 }
274 }
275
276 fprintf(tableFile, " \\\\ \n");
277
278 fclose( tableFile );
279
280 }
281 catch(...) {
282 if( tableFile ) fclose(tableFile);
283 throw;
284 }
285
286 msgSvc.getStream(1).addTopic(RooFit::ObjectHandling);
287
288 return ws;
289
290}
291
292
293///////////////////////////////////////////////
294void RooStats::HistFactory::FitModelAndPlot(const std::string& MeasurementName,
295 const std::string& FileNamePrefix,
296 RooWorkspace * combined, std::string channel,
297 std::string data_name,
298 TFile* outFile, FILE* tableFile ) {
299
300 if( outFile == nullptr ) {
301 cxcoutEHF << "Error: Output File in FitModelAndPlot is nullptr" << std::endl;
302 throw hf_exc();
303 }
304
305 if( tableFile == nullptr ) {
306 cxcoutEHF << "Error: tableFile in FitModelAndPlot is nullptr" << std::endl;
307 throw hf_exc();
308 }
309
310 if( combined == nullptr ) {
311 cxcoutEHF << "Error: Supplied workspace in FitModelAndPlot is nullptr" << std::endl;
312 throw hf_exc();
313 }
314
315 ModelConfig* combined_config = (ModelConfig *) combined->obj("ModelConfig");
316 if(!combined_config){
317 cxcoutEHF << "Error: no ModelConfig found in Measurement: "
318 << MeasurementName << std::endl;
319 throw hf_exc();
320 }
321
322 RooAbsData* simData = combined->data(data_name.c_str());
323 if(!simData){
324 cxcoutEHF << "Error: Failed to get dataset: " << data_name
325 << " in measurement: " << MeasurementName << std::endl;
326 throw hf_exc();
327 }
328
329 const RooArgSet* POIs = combined_config->GetParametersOfInterest();
330 if(!POIs) {
331 cxcoutEHF << "Not Fitting Model for measurement: " << MeasurementName
332 << ", no poi found" << std::endl;
333 // Should I throw an exception here?
334 return;
335 }
336
337 RooAbsPdf* model = combined_config->GetPdf();
338 if( model==nullptr ) {
339 cxcoutEHF << "Error: Failed to find pdf in ModelConfig: " << combined_config->GetName()
340 << std::endl;
341 throw hf_exc();
342 }
343
344 // Save a Snapshot
345 RooArgSet PoiPlusNuisance;
346 if( combined_config->GetNuisanceParameters() ) {
347 PoiPlusNuisance.add( *combined_config->GetNuisanceParameters() );
348 }
349 PoiPlusNuisance.add( *combined_config->GetParametersOfInterest() );
350 combined->saveSnapshot("InitialValues", PoiPlusNuisance);
351
352 ///////////////////////////////////////
353 // Do the fit
354 cxcoutPHF << "\n---------------"
355 << "\nDoing "<< channel << " Fit"
356 << "\n---------------\n\n" << std::endl;
357 model->fitTo(*simData, Minos(true), PrintLevel(RooMsgService::instance().isActive(static_cast<TObject*>(nullptr), RooFit::HistFactory, RooFit::DEBUG) ? 1 : -1));
358
359 // If there are no parameters of interest,
360 // we exit the function here
361 if( POIs->empty() ) {
362 cxcoutWHF << "WARNING: No POIs found in measurement: " << MeasurementName << std::endl;
363 return;
364 }
365
366 // Loop over all POIs and print their fitted values
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;
372 }
373
374 // But we only make detailed plots and tables
375 // for the 'first' POI
376 RooRealVar* poi = static_cast<RooRealVar *>(POIs->first());
377
378 // Print the MINOS errors to the TableFile
379 fprintf(tableFile, " %.4f / %.4f ", poi->getErrorLo(), poi->getErrorHi());
380
381 // Make the Profile Likelihood Plot
382 RooAbsReal* nll = model->createNLL(*simData);
383 RooAbsReal* profile = nll->createProfile(*poi);
384 if( profile==nullptr ) {
385 cxcoutEHF << "Error: Failed to make ProfileLikelihood for: " << poi->GetName()
386 << " using model: " << model->GetName()
387 << " and data: " << simData->GetName()
388 << std::endl;
389 throw hf_exc();
390 }
391
392 std::unique_ptr<RooPlot> frame{poi->frame()};
393
394 // Draw the likelihood curve
395 FormatFrameForLikelihood(frame.get());
396 {
397 TCanvas profileLikelihoodCanvas{channel.c_str(), "",800,600};
398 nll->plotOn(frame.get(), ShiftToZero(), LineColor(kRed), LineStyle(kDashed));
399 profile->plotOn(frame.get());
400 frame->SetMinimum(0);
401 frame->SetMaximum(2.);
402 frame->Draw();
403 std::string profilePlotName = FileNamePrefix+"_"+channel+"_"+MeasurementName+"_profileLR.eps";
404 profileLikelihoodCanvas.SaveAs( profilePlotName.c_str() );
405 }
406
407 // Now, we save our results to the 'output' file
408 // (I'm not sure if users actually look into this file,
409 // but adding additional information and useful plots
410 // may make it more attractive)
411
412 // Save to the output file
413 TDirectory* channel_dir = outFile->mkdir(channel.c_str());
414 if( channel_dir == nullptr ) {
415 cxcoutEHF << "Error: Failed to make channel directory: " << channel << std::endl;
416 throw hf_exc();
417 }
418 TDirectory* summary_dir = channel_dir->mkdir("Summary");
419 if( summary_dir == nullptr ) {
420 cxcoutEHF << "Error: Failed to make Summary directory for channel: "
421 << channel << std::endl;
422 throw hf_exc();
423 }
424 summary_dir->cd();
425
426 // Save a graph of the profile likelihood curve
427 RooCurve* curve=frame->getCurve();
428 Int_t curve_N=curve->GetN();
429 double* curve_x=curve->GetX();
430
431 std::vector<double> x_arr(curve_N);
432 std::vector<double> y_arr_nll(curve_N);
433
434 for(int i=0; i<curve_N; i++){
435 double f=curve_x[i];
436 poi->setVal(f);
437 x_arr[i]=f;
438 y_arr_nll[i]=nll->getVal();
439 }
440
441 TGraph g{curve_N, x_arr.data(), y_arr_nll.data()};
442 g.SetName( (FileNamePrefix +"_nll").c_str() );
443 g.Write();
444
445 // Finally, restore the initial values
446 combined->loadSnapshot("InitialValues");
447
448}
449
450
451void RooStats::HistFactory::FitModel(RooWorkspace * combined, std::string data_name ) {
452
453 cxcoutIHF << "In Fit Model" << std::endl;
454 ModelConfig * combined_config = (ModelConfig *) combined->obj("ModelConfig");
455 if(!combined_config){
456 cxcoutEHF << "no model config " << "ModelConfig" << " exiting" << std::endl;
457 return;
458 }
459
460 RooAbsData* simData = combined->data(data_name.c_str());
461 if(!simData){
462 cxcoutEHF << "no data " << data_name << " exiting" << std::endl;
463 return;
464 }
465
466 const RooArgSet * POIs=combined_config->GetParametersOfInterest();
467 if(!POIs){
468 cxcoutEHF << "no poi " << data_name << " exiting" << std::endl;
469 return;
470 }
471
472 RooAbsPdf* model=combined_config->GetPdf();
473 model->fitTo(*simData, Minos(true), PrintLevel(1));
474
475 }
476
477
479 std::string YTitle){
480
483 // gStyle->SetPadColor(0);
484 // gStyle->SetCanvasColor(255);
485 // gStyle->SetTitleFillColor(255);
486 // gStyle->SetFrameFillColor(0);
487 // gStyle->SetStatColor(255);
488
489 RooAbsRealLValue* var = frame->getPlotVar();
490 double xmin = var->getMin();
491 double xmax = var->getMax();
492
493 frame->SetTitle("");
494 // frame->GetXaxis()->SetTitle(XTitle.c_str());
495 frame->GetXaxis()->SetTitle(var->GetTitle());
496 frame->GetYaxis()->SetTitle(YTitle.c_str());
497 frame->SetMaximum(2.);
498 frame->SetMinimum(0.);
499 TLine * line = new TLine(xmin,.5,xmax,.5);
501 TLine * line90 = new TLine(xmin,2.71/2.,xmax,2.71/2.);
502 line90->SetLineColor(kGreen);
503 TLine * line95 = new TLine(xmin,3.84/2.,xmax,3.84/2.);
504 line95->SetLineColor(kGreen);
505 frame->addObject(line);
506 frame->addObject(line90);
507 frame->addObject(line95);
508}
#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:560
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:996
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:1501
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:480
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:1255
void addObject(TObject *obj, Option_t *drawOptions="", bool invisible=false)
Add a generic object to this plot.
Definition: RooPlot.cxx:380
virtual void SetMinimum(double minimum=-1111)
Set minimum value of Y axis.
Definition: RooPlot.cxx:1059
virtual void SetMaximum(double maximum=-1111)
Set maximum value of Y axis.
Definition: RooPlot.cxx:1049
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1276
RooAbsRealLValue * getPlotVar() const
Definition: RooPlot.h:137
TAxis * GetXaxis() const
Definition: RooPlot.cxx:1274
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:4053
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:41
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:423
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Definition: TSystem.cxx:839
virtual int MakeDirectory(const char *name)
Make a directory.
Definition: TSystem.cxx:830
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:63
@ ObjectHandling
Definition: RooGlobalFunc.h:62
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 *)