Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
HistFactoryNavigation.cxx
Go to the documentation of this file.
1
2/** \class RooStats::HistFactory::HistFactoryNavigation
3 * \ingroup HistFactory
4 */
5
6#include <iomanip>
7#include <sstream>
8
9#include "TFile.h"
10#include "TRegexp.h"
11#include "TMath.h"
12
13#include "RooRealSumPdf.h"
14#include "RooProduct.h"
15#include "RooMsgService.h"
16#include "RooCategory.h"
17#include "RooSimultaneous.h"
18#include "RooWorkspace.h"
19#include "RooFit/ModelConfig.h"
20
23
24
26
27
28namespace RooStats {
29 namespace HistFactory {
30
31
32 // CONSTRUCTOR
34 : _minBinToPrint(-1), _maxBinToPrint(-1),
35 _label_print_width(20), _bin_print_width(12) {
36
37 if( !mc ) {
38 std::cout << "Error: The supplied ModelConfig is nullptr " << std::endl;
39 throw hf_exc();
40 }
41
42 // Save the model pointer
43 RooAbsPdf* pdf_in_mc = mc->GetPdf();
44 if( !pdf_in_mc ) {
45 std::cout << "Error: The pdf found in the ModelConfig: " << mc->GetName()
46 << " is nullptr" << std::endl;
47 throw hf_exc();
48 }
49
50 // Set the PDF member
51 fModel = mc->GetPdf();
52
53 // Get the observables
54 RooArgSet* observables_in_mc = const_cast<RooArgSet*>(mc->GetObservables());
55 if( !observables_in_mc ) {
56 std::cout << "Error: Observable set in the ModelConfig: " << mc->GetName()
57 << " is nullptr" << std::endl;
58 throw hf_exc();
59 }
60 if( observables_in_mc->empty() ) {
61 std::cout << "Error: Observable list: " << observables_in_mc->GetName()
62 << " found in ModelConfig: " << mc->GetName()
63 << " has no entries." << std::endl;
64 throw hf_exc();
65 }
66
67 // Set the observables member
68 fObservables = observables_in_mc;
69
70 // Initialize the rest of the members
72
73 }
74
75
76 // CONSTRUCTOR
78 const std::string& WorkspaceName,
79 const std::string& ModelConfigName) :
80 _minBinToPrint(-1), _maxBinToPrint(-1),
81 _label_print_width(20), _bin_print_width(12) {
82
83 // Open the File
84 auto file = std::make_unique<TFile>(FileName.c_str());
85 if( !file ) {
86 std::cout << "Error: Failed to open file: " << FileName << std::endl;
87 throw hf_exc();
88 }
89
90 // Get the workspace
91 RooWorkspace* wspace = (RooWorkspace*) file->Get(WorkspaceName.c_str());
92 if( !wspace ) {
93 std::cout << "Error: Failed to get workspace: " << WorkspaceName
94 << " from file: " << FileName << std::endl;
95 throw hf_exc();
96 }
97
98 // Get the ModelConfig
99 ModelConfig* mc = (ModelConfig*) wspace->obj(ModelConfigName);
100 if( !mc ) {
101 std::cout << "Error: Failed to find ModelConfig: " << ModelConfigName
102 << " from workspace: " << WorkspaceName
103 << " in file: " << FileName << std::endl;
104 throw hf_exc();
105 }
106
107 // Save the model pointer
108 RooAbsPdf* pdf_in_mc = mc->GetPdf();
109 if( !pdf_in_mc ) {
110 std::cout << "Error: The pdf found in the ModelConfig: " << ModelConfigName
111 << " is nullptr" << std::endl;
112 throw hf_exc();
113 }
114
115 // Set the PDF member
116 fModel = pdf_in_mc;
117
118 // Get the observables
119 RooArgSet* observables_in_mc = const_cast<RooArgSet*>(mc->GetObservables());
120 if( !observables_in_mc ) {
121 std::cout << "Error: Observable set in the ModelConfig: " << ModelConfigName
122 << " is nullptr" << std::endl;
123 throw hf_exc();
124 }
125 if( observables_in_mc->empty() ) {
126 std::cout << "Error: Observable list: " << observables_in_mc->GetName()
127 << " found in ModelConfig: " << ModelConfigName
128 << " in file: " << FileName
129 << " has no entries." << std::endl;
130 throw hf_exc();
131 }
132
133 // Set the observables member
134 fObservables = observables_in_mc;
135
136 // Initialize the rest of the members
138
139 }
140
141
142 // CONSTRUCTOR
144 _minBinToPrint(-1), _maxBinToPrint(-1),
145 _label_print_width(20), _bin_print_width(12) {
146
147 // Save the model pointer
148 if( !model ) {
149 std::cout << "Error: The supplied pdf is nullptr" << std::endl;
150 throw hf_exc();
151 }
152
153 // Set the PDF member
154 fModel = model;
155 fObservables = observables;
156
157 // Get the observables
158 if( !observables ) {
159 std::cout << "Error: Supplied Observable set is nullptr" << std::endl;
160 throw hf_exc();
161 }
162 if( observables->empty() ) {
163 std::cout << "Error: Observable list: " << observables->GetName()
164 << " has no entries." << std::endl;
165 throw hf_exc();
166 }
167
168 // Initialize the rest of the members
170
171 }
172
173
174 void HistFactoryNavigation::PrintMultiDimHist(TH1* hist, int bin_print_width) {
175
176 // This is how ROOT makes us loop over histograms :(
177 int current_bin = 0;
178 int num_bins = hist->GetNbinsX()*hist->GetNbinsY()*hist->GetNbinsZ();
179 for(int i = 0; i < num_bins; ++i) {
180 // Avoid the overflow/underflow
181 current_bin++;
182 while( hist->IsBinUnderflow(current_bin) ||
183 hist->IsBinOverflow(current_bin) ) {
184 current_bin++;
185 }
186 // Check that we should print this bin
187 if( _minBinToPrint != -1 && i < _minBinToPrint) continue;
188 if( _maxBinToPrint != -1 && i > _maxBinToPrint) break;
189 std::cout << std::setw(bin_print_width) << hist->GetBinContent(current_bin);
190 }
191 std::cout << std::endl;
192
193 }
194
195
196
197 RooAbsPdf* HistFactoryNavigation::GetChannelPdf(const std::string& channel) {
198
199 std::map< std::string, RooAbsPdf* >::iterator itr;
200 itr = fChannelPdfMap.find(channel);
201
202 if( itr == fChannelPdfMap.end() ) {
203 std::cout << "Warning: Could not find channel: " << channel
204 << " in pdf: " << fModel->GetName() << std::endl;
205 return nullptr;
206 }
207
208 RooAbsPdf* pdf = itr->second;
209 if( pdf == nullptr ) {
210 std::cout << "Warning: Pdf associated with channel: " << channel
211 << " is nullptr" << std::endl;
212 return nullptr;
213 }
214
215 return pdf;
216
217 }
218
219 void HistFactoryNavigation::PrintState(const std::string& channel) {
220
221 //int label_print_width = 20;
222 //int bin_print_width = 12;
223 std::cout << std::endl << channel << ":" << std::endl;
224
225 // Get the map of Samples for this channel
226 std::map< std::string, RooAbsReal*> SampleFunctionMap = GetSampleFunctionMap(channel);
227
228 // Set the size of the print width if necessary
229 /*
230 for( std::map< std::string, RooAbsReal*>::iterator itr = SampleFunctionMap.begin();
231 itr != SampleFunctionMap.end(); ++itr) {
232 std::string sample_name = itr->first;
233 label_print_width = TMath::Max(label_print_width, (int)sample_name.size()+2);
234 }
235 */
236
237 // Loop over the SampleFunctionMap and print the individual histograms
238 // to get the total histogram for the channel
239 int num_bins = 0;
240 std::map< std::string, RooAbsReal*>::iterator itr = SampleFunctionMap.begin();
241 for( ; itr != SampleFunctionMap.end(); ++itr) {
242
243 std::string sample_name = itr->first;
244 std::string tmp_name = sample_name + channel + "_pretty_tmp";
245 std::unique_ptr<TH1> sample_hist{GetSampleHist(channel, sample_name, tmp_name)};
246 num_bins = sample_hist->GetNbinsX()*sample_hist->GetNbinsY()*sample_hist->GetNbinsZ();
247 std::cout << std::setw(_label_print_width) << sample_name;
248
249 // Print the content of the histogram
250 PrintMultiDimHist(sample_hist.get(), _bin_print_width);
251
252 }
253
254 // Make the line break as a set of "===============" ...
255 std::string line_break;
256 int high_bin = _maxBinToPrint==-1 ? num_bins : TMath::Min(_maxBinToPrint, (int)num_bins);
257 int low_bin = _minBinToPrint==-1 ? 1 : _minBinToPrint;
258 int break_length = (high_bin - low_bin + 1) * _bin_print_width;
259 break_length += _label_print_width;
260 for(int i = 0; i < break_length; ++i) {
261 line_break += "=";
262 }
263 std::cout << line_break << std::endl;
264
265 std::string tmp_name = channel + "_pretty_tmp";
266 std::unique_ptr<TH1> channel_hist{GetChannelHist(channel, tmp_name)};
267 std::cout << std::setw(_label_print_width) << "TOTAL:";
268
269 // Print the Histogram
270 PrintMultiDimHist(channel_hist.get(), _bin_print_width);
271
272 return;
273
274 }
275
276
278 // Loop over channels and print their states, one after another
279 for(unsigned int i = 0; i < fChannelNameVec.size(); ++i) {
281 }
282 }
283
284
285 void HistFactoryNavigation::SetPrintWidths(const std::string& channel) {
286
287 // Get the map of Samples for this channel
288 std::map< std::string, RooAbsReal*> SampleFunctionMap = GetSampleFunctionMap(channel);
289
290 // Get the max of the samples
291 for( std::map< std::string, RooAbsReal*>::iterator itr = SampleFunctionMap.begin();
292 itr != SampleFunctionMap.end(); ++itr) {
293 std::string sample_name = itr->first;
294 _label_print_width = TMath::Max(_label_print_width, (int)sample_name.size()+2);
295 }
296
297 _label_print_width = TMath::Max( _label_print_width, (int)channel.size() + 7);
298 }
299
300
302 const std::string& channel_to_print) {
303
304 // Print the contents of a 'HistFactory' RooDataset
305 // These are stored in a somewhat odd way that makes
306 // them difficult to inspect for humans.
307 // They have the following layout:
308 // =====================================================
309 // ChannelA ChannelB ChannelCat Weight
310 // -----------------------------------------------------
311 // bin_1_center 0 ChannelA bin_1_height
312 // bin_2_center 0 ChannelA bin_2_height
313 // 0 bin_1_center ChannelB bin_1_height
314 // 0 bin_2_center ChannelB bin_2_height
315 // ...etc...
316 // =====================================================
317
318 // int label_print_width = 20;
319 // int bin_print_width = 12;
320
321 // Get the Data Histogram for this channel
322 for( unsigned int i_chan=0; i_chan < fChannelNameVec.size(); ++i_chan) {
323
324 std::string channel_name = fChannelNameVec.at(i_chan);
325
326 // If we pass a channel string, we only print that one channel
327 if( channel_to_print != "" && channel_name != channel_to_print) continue;
328
329 std::unique_ptr<TH1> data_hist{GetDataHist(data, channel_name, channel_name+"_tmp")};
330 std::cout << std::setw(_label_print_width) << channel_name + " (data)";
331
332 // Print the Histogram
333 PrintMultiDimHist(data_hist.get(), _bin_print_width);
334 }
335 }
336
337
339 // Loop over all channels and print model
340 // (including all samples) and compare
341 // it to the supplied dataset
342
343 for( unsigned int i = 0; i < fChannelNameVec.size(); ++i) {
344 std::string channel = fChannelNameVec.at(i);
345 SetPrintWidths(channel);
346 PrintState(channel);
347 PrintDataSet(data, channel);
348 }
349
350 std::cout << std::endl;
351 }
352
353
354 void HistFactoryNavigation::PrintParameters(bool IncludeConstantParams) {
355
356 // Get the list of parameters
357 RooArgSet params;
359
360 std::cout << std::endl;
361
362 // Create the title row
363 std::cout << std::setw(30) << "Parameter";
364 std::cout << std::setw(15) << "Value"
365 << std::setw(15) << "Error Low"
366 << std::setw(15) << "Error High"
367 << std::endl;
368
369 // Loop over the parameters and print their values, etc
370 for (auto const *param : static_range_cast<RooRealVar *>(params)) {
371 if( !IncludeConstantParams && param->isConstant() ) continue;
372
373 std::cout << std::setw(30) << param->GetName();
374 std::cout << std::setw(15) << param->getVal();
375 if( !param->isConstant() ) {
376 std::cout << std::setw(15) << param->getErrorLo() << std::setw(15) << param->getErrorHi();
377 }
378 std::cout<< std::endl;
379 }
380 std::cout << std::endl;
381 }
382
383 void HistFactoryNavigation::PrintChannelParameters(const std::string& channel,
384 bool IncludeConstantParams) {
385
386 // Get the list of parameters
387 RooArgSet params;
389
390 // Get the pdf for this channel
391 RooAbsPdf* channel_pdf = GetChannelPdf(channel);
392
393 std::cout << std::endl;
394
395 // Create the title row
396 std::cout << std::setw(30) << "Parameter";
397 std::cout << std::setw(15) << "Value"
398 << std::setw(15) << "Error Low"
399 << std::setw(15) << "Error High"
400 << std::endl;
401
402 // Loop over the parameters and print their values, etc
403 for (auto const *param : static_range_cast<RooRealVar *>(params)) {
404 if( !IncludeConstantParams && param->isConstant() ) continue;
405 if( findChild(param->GetName(), channel_pdf)==nullptr ) continue;
406 std::cout << std::setw(30) << param->GetName();
407 std::cout << std::setw(15) << param->getVal();
408 if( !param->isConstant() ) {
409 std::cout << std::setw(15) << param->getErrorLo() << std::setw(15) << param->getErrorHi();
410 }
411 std::cout<< std::endl;
412 }
413 std::cout << std::endl;
414 }
415
416
417 void HistFactoryNavigation::PrintSampleParameters(const std::string& channel,
418 const std::string& sample,
419 bool IncludeConstantParams) {
420
421 // Get the list of parameters
422 RooArgSet params;
424
425 // Get the pdf for this channel
426 RooAbsReal* sample_func = SampleFunction(channel, sample);
427
428 std::cout << std::endl;
429
430 // Create the title row
431 std::cout << std::setw(30) << "Parameter";
432 std::cout << std::setw(15) << "Value"
433 << std::setw(15) << "Error Low"
434 << std::setw(15) << "Error High"
435 << std::endl;
436
437 // Loop over the parameters and print their values, etc
438 for (auto const *param : static_range_cast<RooRealVar *>(params)) {
439 if( !IncludeConstantParams && param->isConstant() ) continue;
440 if( findChild(param->GetName(), sample_func)==nullptr ) continue;
441 std::cout << std::setw(30) << param->GetName();
442 std::cout << std::setw(15) << param->getVal();
443 if( !param->isConstant() ) {
444 std::cout << std::setw(15) << param->getErrorLo() << std::setw(15) << param->getErrorHi();
445 }
446 std::cout<< std::endl;
447 }
448 std::cout << std::endl;
449 }
450
451
452 double HistFactoryNavigation::GetBinValue(int bin, const std::string& channel) {
453 // Get the total bin height for the ith bin (ROOT indexing convention)
454 // in channel 'channel'
455 // (Could be optimized, it uses an intermediate histogram for now...)
456
457 // Get the histogram, fetch the bin content, and return
458 std::unique_ptr<TH1> channel_hist_tmp{GetChannelHist(channel, (channel+"_tmp").c_str())};
459 return channel_hist_tmp->GetBinContent(bin);
460 }
461
462
463 double HistFactoryNavigation::GetBinValue(int bin, const std::string& channel, const std::string& sample){
464 // Get the total bin height for the ith bin (ROOT indexing convention)
465 // in channel 'channel'
466 // (This will be slow if you plan on looping over it.
467 // Could be optimized, it uses an intermediate histogram for now...)
468
469 // Get the histogram, fetch the bin content, and return
470 std::unique_ptr<TH1> sample_hist_tmp{GetSampleHist(channel, sample, (channel+"_tmp").c_str())};
471 return sample_hist_tmp->GetBinContent(bin);
472 }
473
474
475 std::map< std::string, RooAbsReal*> HistFactoryNavigation::GetSampleFunctionMap(const std::string& channel) {
476 // Get a map of strings to function pointers,
477 // which each function corresponds to a sample
478
479 std::map< std::string, std::map< std::string, RooAbsReal*> >::iterator channel_itr;
480 channel_itr = fChannelSampleFunctionMap.find(channel);
481 if( channel_itr==fChannelSampleFunctionMap.end() ){
482 std::cout << "Error: Channel: " << channel << " not found in Navigation" << std::endl;
483 throw hf_exc();
484 }
485
486 return channel_itr->second;
487 }
488
489
490 RooAbsReal* HistFactoryNavigation::SampleFunction(const std::string& channel, const std::string& sample){
491 // Return the function object pointer cooresponding
492 // to a particular sample in a particular channel
493
494 std::map< std::string, std::map< std::string, RooAbsReal*> >::iterator channel_itr;
495 channel_itr = fChannelSampleFunctionMap.find(channel);
496 if( channel_itr==fChannelSampleFunctionMap.end() ){
497 std::cout << "Error: Channel: " << channel << " not found in Navigation" << std::endl;
498 throw hf_exc();
499 }
500
501 std::map< std::string, RooAbsReal*>& SampleMap = channel_itr->second;
502 std::map< std::string, RooAbsReal*>::iterator sample_itr;
503 sample_itr = SampleMap.find(sample);
504 if( sample_itr==SampleMap.end() ){
505 std::cout << "Error: Sample: " << sample << " not found in Navigation" << std::endl;
506 throw hf_exc();
507 }
508
509 return sample_itr->second;
510
511 }
512
513
515 // Get the observables for a particular channel
516
517 std::map< std::string, RooArgSet*>::iterator channel_itr;
518 channel_itr = fChannelObservMap.find(channel);
519 if( channel_itr==fChannelObservMap.end() ){
520 std::cout << "Error: Channel: " << channel << " not found in Navigation" << std::endl;
521 throw hf_exc();
522 }
523
524 return channel_itr->second;
525
526 }
527
528
529 TH1* HistFactoryNavigation::GetSampleHist(const std::string& channel, const std::string& sample,
530 const std::string& hist_name) {
531 // Get a histogram of the expected values for
532 // a particular sample in a particular channel
533 // Give a name, or a default one will be used
534
535 RooArgList observable_list( *GetObservableSet(channel) );
536
537 std::string name = hist_name;
538 if(hist_name=="") name = channel + "_" + sample + "_hist";
539
540 RooAbsReal* sample_function = SampleFunction(channel, sample);
541
542 return MakeHistFromRooFunction( sample_function, observable_list, name );
543
544 }
545
546
547 TH1* HistFactoryNavigation::GetChannelHist(const std::string& channel, const std::string& hist_name) {
548 // Get a histogram of the total expected value
549 // per bin for this channel
550 // Give a name, or a default one will be used
551
552 RooArgList observable_list( *GetObservableSet(channel) );
553
554 std::map< std::string, RooAbsReal*> SampleFunctionMap = GetSampleFunctionMap(channel);
555
556 // Okay, 'loop' once
557 TH1* total_hist = nullptr;
558 std::map< std::string, RooAbsReal*>::iterator itr = SampleFunctionMap.begin();
559 for( ; itr != SampleFunctionMap.end(); ++itr) {
560 std::string sample_name = itr->first;
561 std::string tmp_hist_name = sample_name + "_hist_tmp";
562 RooAbsReal* sample_function = itr->second;
563 std::unique_ptr<TH1> sample_hist{MakeHistFromRooFunction(sample_function, observable_list,
564 tmp_hist_name)};
565 total_hist = (TH1*) sample_hist->Clone("TotalHist");
566 break;
567 }
568 if (!total_hist)
569 return nullptr;
570
571 total_hist->Reset();
572
573 // Loop over the SampleFunctionMap and add up all the histograms
574 // to get the total histogram for the channel
575 itr = SampleFunctionMap.begin();
576 for( ; itr != SampleFunctionMap.end(); ++itr) {
577 std::string sample_name = itr->first;
578 std::string tmp_hist_name = sample_name + "_hist_tmp";
579 RooAbsReal* sample_function = itr->second;
580 std::unique_ptr<TH1> sample_hist{MakeHistFromRooFunction(sample_function, observable_list,
581 tmp_hist_name)};
582 total_hist->Add(sample_hist.get());
583 }
584
585 if(hist_name=="") total_hist->SetName(hist_name.c_str());
586 else total_hist->SetName( (channel + "_hist").c_str() );
587
588 return total_hist;
589
590 }
591
592
593 std::vector< std::string > HistFactoryNavigation::GetChannelSampleList(const std::string& channel) {
594
595 std::vector<std::string> sample_list;
596
597 std::map< std::string, RooAbsReal*> sample_map = fChannelSampleFunctionMap[channel];
598 std::map< std::string, RooAbsReal*>::iterator itr = sample_map.begin();;
599 for( ; itr != sample_map.end(); ++itr) {
600 sample_list.push_back( itr->first );
601 }
602
603 return sample_list;
604
605 }
606
607
609 const std::string& name) {
610
611 THStack* stack = new THStack(name.c_str(), "");
612
613 std::vector< std::string > samples = GetChannelSampleList(channel);
614
615 // Add the histograms
616 for( unsigned int i=0; i < samples.size(); ++i) {
617 std::string sample_name = samples.at(i);
618 TH1* hist = GetSampleHist(channel, sample_name, sample_name+"_tmp");
619 hist->SetLineColor(2+i);
620 hist->SetFillColor(2+i);
621 stack->Add(hist);
622 }
623
624 return stack;
625
626 }
627
628
630 const std::string& name) {
631
632 // TO DO:
633 // MAINTAIN THE ACTUAL RANGE, USING THE OBSERVABLES
634 // MAKE IT WORK FOR MULTI-DIMENSIONAL
635 //
636
637 std::unique_ptr<TList> dataset_list;
638
639 // If the dataset covers multiple categories,
640 // Split the dataset based on the categories
641 if(strcmp(fModel->ClassName(),"RooSimultaneous")==0){
642
643 // If so, get a list of the component pdf's:
645 RooCategory* channelCat = (RooCategory*) (&simPdf->indexCat());
646
647 dataset_list.reset(data->split(*channelCat));
648
649 data = dynamic_cast<RooDataSet*>( dataset_list->FindObject(channel.c_str()) );
650
651 }
652
653 RooArgList vars( *GetObservableSet(channel) );
654
655 int dim = vars.getSize();
656
657 TH1* hist = nullptr;
658
659 if (!data) {
660 std::cout << "Error: To Create Histogram from RooDataSet" << std::endl;
661 if (dataset_list) {
662 dataset_list.reset();
663 }
664 throw hf_exc();
665 } else if( dim==1 ) {
666 RooRealVar* varX = (RooRealVar*) vars.at(0);
667 hist = data->createHistogram( name.c_str(),*varX, RooFit::Binning(varX->getBinning()) );
668 }
669 else if( dim==2 ) {
670 RooRealVar* varX = (RooRealVar*) vars.at(0);
671 RooRealVar* varY = (RooRealVar*) vars.at(1);
672 hist = data->createHistogram( name.c_str(),*varX, RooFit::Binning(varX->getBinning()),
673 RooFit::YVar(*varY, RooFit::Binning(varY->getBinning())) );
674 }
675 else if( dim==3 ) {
676 RooRealVar* varX = (RooRealVar*) vars.at(0);
677 RooRealVar* varY = (RooRealVar*) vars.at(1);
678 RooRealVar* varZ = (RooRealVar*) vars.at(2);
679 hist = data->createHistogram( name.c_str(),*varX, RooFit::Binning(varX->getBinning()),
680 RooFit::YVar(*varY, RooFit::Binning(varY->getBinning())),
681 RooFit::YVar(*varZ, RooFit::Binning(varZ->getBinning())) );
682 }
683 else {
684 std::cout << "Error: To Create Histogram from RooDataSet, Dimension must be 1, 2, or 3" << std::endl;
685 std::cout << "Observables: " << std::endl;
686 vars.Print("V");
687 if (dataset_list) {
688 dataset_list->Delete();
689 dataset_list.reset();
690 }
691 throw hf_exc();
692 }
693
694 if (dataset_list) {
695 dataset_list->Delete();
696 dataset_list.reset();
697 }
698
699 return hist;
700
701 }
702
703
704 void HistFactoryNavigation::DrawChannel(const std::string& channel, RooDataSet* data) {
705
706 // Get the stack
707 THStack* stack = GetChannelStack(channel, channel+"_stack_tmp");
708
709 stack->Draw();
710
711 if( data!=nullptr ) {
712 TH1* data_hist = GetDataHist(data, channel, channel+"_data_tmp");
713 data_hist->Draw("SAME");
714 }
715
716 }
717
718
719
721
722 // An internal method to recursively get all products,
723 // including if a RooProduct is a Product of RooProducts
724 // etc
725
726 RooArgSet allTerms;
727
728 // Get All Subnodes of this product
729 // Loop over the subnodes and add
730 for (auto *arg : node->components()) {
731 std::string ClassName = arg->ClassName();
732 if( ClassName == "RooProduct" ) {
733 RooProduct* prod = static_cast<RooProduct*>(arg);
734 allTerms.add( _GetAllProducts(prod) );
735 }
736 else {
737 allTerms.add(*arg);
738 }
739 }
740 return allTerms;
741 }
742
743
744
745
746 void HistFactoryNavigation::_GetNodes(RooAbsPdf* modelPdf, const RooArgSet* observables) {
747
748 // Get the pdf from the ModelConfig
749 //RooAbsPdf* modelPdf = mc->GetPdf();
750 //RooArgSet* observables = mc->GetObservables();
751
752 // Create vectors to hold the channel pdf's
753 // as well as the set of observables for each channel
754 //std::map< std::string, RooAbsPdf* > channelPdfMap;
755 //std::map< std::string, RooArgSet* > channelObservMap;
756
757 // Check if it is a simultaneous pdf or not
758 // (if it's an individual channel, it won't be, if it's
759 // combined, it's simultaneous)
760 // Fill the channel vectors based on the structure
761 // (Obviously, if it's not simultaneous, there will be
762 // only one entry in the vector for the single channel)
763 if(strcmp(modelPdf->ClassName(),"RooSimultaneous")==0){
764
765 // If so, get a list of the component pdf's:
766 RooSimultaneous* simPdf = (RooSimultaneous*) modelPdf;
767 RooCategory* channelCat = (RooCategory*) (&simPdf->indexCat());
768
769 // Iterate over the categories and get the
770 // pdf and observables for each category
771 for (const auto& nameIdx : *channelCat) {
772 const std::string& ChannelName = nameIdx.first;
773 fChannelNameVec.push_back( ChannelName );
774 RooAbsPdf* pdftmp = simPdf->getPdf(ChannelName.c_str()) ;
775 RooArgSet* obstmp = std::unique_ptr<RooArgSet>{pdftmp->getObservables(*observables)}.release();
776 fChannelPdfMap[ChannelName] = pdftmp;
777 fChannelObservMap[ChannelName] = obstmp;
778 }
779
780 } else {
781 RooArgSet* obstmp = std::unique_ptr<RooArgSet>{modelPdf->getObservables(*observables)}.release();
782 // The channel name is model_CHANNEL
783 std::string ChannelName = modelPdf->GetName();
784 ChannelName = ChannelName.replace(0, 6, "");
785 fChannelNameVec.push_back(ChannelName);
786 fChannelPdfMap[ChannelName] = modelPdf;
787 fChannelObservMap[ChannelName] = obstmp;
788
789 }
790
791 // Okay, now we have maps of the pdfs
792 // and the observable list per channel
793 // We then loop over the channel pdfs:
794 // and find their RooRealSumPdfs
795 // std::map< std::string, RooRealSumPdf* > channelSumNodeMap;
796
797 for( unsigned int i = 0; i < fChannelNameVec.size(); ++i ) {
798
799 std::string ChannelName = fChannelNameVec.at(i);
800 RooAbsPdf* pdf = fChannelPdfMap[ChannelName];
801
802 // Loop over the pdf's components and find
803 // the (one) that is a RooRealSumPdf
804 // Based on the mode, we assume that node is
805 // the "unconstrained" pdf node for that channel
806 std::unique_ptr<RooArgSet> comps{pdf->getComponents()};
807 for (auto *arg : *comps) {
808 std::string ClassName = arg->ClassName();
809 if( ClassName == "RooRealSumPdf" ) {
810 fChannelSumNodeMap[ChannelName] = static_cast <RooRealSumPdf*>(arg);
811 break;
812 }
813 }
814 }
815
816 // Okay, now we have all necessary
817 // nodes filled for each channel.
818 for( unsigned int i = 0; i < fChannelNameVec.size(); ++i ) {
819
820 std::string ChannelName = fChannelNameVec.at(i);
821 RooRealSumPdf* sumPdf = dynamic_cast<RooRealSumPdf*>(fChannelSumNodeMap[ChannelName]);
822
823 // We now take the RooRealSumPdf and loop over
824 // its component functions. The RooRealSumPdf turns
825 // a list of functions (expected events or bin heights
826 // per sample) and turns it into a pdf.
827 // Therefore, we loop over it to find the expected
828 // height for the various samples
829
830 // First, create a map to store the function nodes
831 // for each sample in this channel
832 std::map< std::string, RooAbsReal*> sampleFunctionMap;
833
834 // Loop over the sample nodes in this
835 // channel's RooRealSumPdf
836 for (auto *func : static_range_cast<RooAbsReal *>(sumPdf->funcList())) {
837 // Do a bit of work to get the name of each sample
838 std::string SampleName = func->GetName();
839 if( SampleName.find("L_x_") != std::string::npos ) {
840 size_t index = SampleName.find("L_x_");
841 SampleName.replace( index, 4, "" );
842 }
843 if( SampleName.find(ChannelName.c_str()) != std::string::npos ) {
844 size_t index = SampleName.find(ChannelName.c_str());
845 SampleName = SampleName.substr(0, index-1);
846 }
847
848 // And simply save this node into our map
849 sampleFunctionMap[SampleName] = func;
850 }
851
852 fChannelSampleFunctionMap[ChannelName] = sampleFunctionMap;
853
854 // Okay, now we have a list of histograms
855 // representing the samples for this channel.
856
857 }
858
859 }
860
861
862 RooAbsArg* HistFactoryNavigation::findChild(const std::string& name, RooAbsReal* parent) const {
863
864 RooAbsArg* term=nullptr;
865
866 // Check if it is a "component",
867 // ie a sub node:
868 std::unique_ptr<RooArgSet> comps{parent->getComponents()};
869 for (auto arg : *comps) {
870 std::string ArgName = arg->GetName();
871 if (ArgName == name) {
872 term = arg;
873 break;
874 }
875 }
876
877 if( term != nullptr ) return term;
878
879 // If that failed,
880 // Check if it's a Parameter
881 // (ie a RooRealVar)
882 RooArgSet args;
883 std::unique_ptr<RooArgSet> parameters{parent->getParameters(&args)};
884 for (auto *param : *parameters) {
885 std::string ParamName = param->GetName();
886 if( ParamName == name ) {
887 term = param;
888 break;
889 }
890 }
891
892 /* Not sure if we want to be silent
893 But since we're returning a pointer which can be nullptr,
894 I think it's the user's job to do checks on it.
895 A dereference will always cause a crash, so it won't
896 be silent for long...
897 if( term==nullptr ) {
898 std::cout << "Error: Failed to find node: " << name
899 << " as a child of: " << parent->GetName()
900 << std::endl;
901 }
902 */
903
904 return term;
905
906 }
907
908
910
911 std::string ConstraintTermName = parameter + "Constraint";
912
913 // First, as a sanity check, let's see if the parameter
914 // itself actually exists and if the model depends on it:
915 RooRealVar* param = dynamic_cast<RooRealVar*>(findChild(parameter, fModel));
916 if( param==nullptr ) {
917 std::cout << "Error: Couldn't Find parameter: " << parameter << " in model."
918 << std::endl;
919 return nullptr;
920 }
921
922 // The "gamma"'s use a different constraint term name
923 if( parameter.find("gamma_stat_") != std::string::npos ) {
924 ConstraintTermName = parameter + "_constraint";
925 }
926
927 // Now, get the constraint itself
928 RooAbsReal* term = dynamic_cast<RooAbsReal*>(findChild(ConstraintTermName, fModel));
929
930 if( term==nullptr ) {
931 std::cout << "Error: Couldn't Find constraint term for parameter: " << parameter
932 << " (Looked for '" << ConstraintTermName << "')" << std::endl;
933 return nullptr;
934 }
935
936 return term;
937
938 }
939
940
941 double HistFactoryNavigation::GetConstraintUncertainty(const std::string& parameter) {
942
943 RooAbsReal* constraintTerm = GetConstraintTerm(parameter);
944 if( constraintTerm==nullptr ) {
945 std::cout << "Error: Cannot get uncertainty because parameter: " << parameter
946 << " has no constraint term" << std::endl;
947 throw hf_exc();
948 }
949
950 // Get the type of constraint
951 std::string ConstraintType = constraintTerm->ClassName();
952
953 // Find its value
954 double sigma = 0.0;
955
956 if( ConstraintType == "" ) {
957 std::cout << "Error: Constraint type is an empty string."
958 << " This simply should not be." << std::endl;
959 throw hf_exc();
960 }
961 else if( ConstraintType == "RooGaussian" ){
962
963 // Gaussian errors are the 'sigma' in the constraint term
964
965 // Get the name of the 'sigma' for the gaussian
966 // (I don't know of a way of doing RooGaussian::GetSigma() )
967 // For alpha's, the sigma points to a global RooConstVar
968 // with the name "1"
969 // For gamma_stat_*, the sigma is named *_sigma
970 std::string sigmaName = "";
971 if( parameter.find("alpha_")!=std::string::npos ) {
972 sigmaName = "1";;
973 }
974 else if( parameter.find("gamma_stat_")!=std::string::npos ) {
975 sigmaName = parameter + "_sigma";
976 }
977
978 // Get the sigma and its value
979 RooAbsReal* sigmaVar = dynamic_cast<RooAbsReal*>(constraintTerm->findServer(sigmaName.c_str()));
980 if( sigmaVar==nullptr ) {
981 std::cout << "Error: Failed to find the 'sigma' node: " << sigmaName
982 << " in the RooGaussian: " << constraintTerm->GetName() << std::endl;
983 throw hf_exc();
984 }
985 // If we find the uncertainty:
986 sigma = sigmaVar->getVal();
987 }
988 else if( ConstraintType == "RooPoisson" ){
989 // Poisson errors are given by inverting: tau = 1 / (sigma*sigma)
990 std::string tauName = "nom_" + parameter;
991 RooAbsReal* tauVar = dynamic_cast<RooAbsReal*>( constraintTerm->findServer(tauName.c_str()) );
992 if( tauVar==nullptr ) {
993 std::cout << "Error: Failed to find the nominal 'tau' node: " << tauName
994 << " for the RooPoisson: " << constraintTerm->GetName() << std::endl;
995 throw hf_exc();
996 }
997 double tau_val = tauVar->getVal();
998 sigma = 1.0 / TMath::Sqrt( tau_val );
999 }
1000 else {
1001 std::cout << "Error: Encountered unknown constraint type for Stat Uncertainties: "
1002 << ConstraintType << std::endl;
1003 throw hf_exc();
1004 }
1005
1006 return sigma;
1007
1008 }
1009
1010 void HistFactoryNavigation::ReplaceNode(const std::string& ToReplace, RooAbsArg* ReplaceWith) {
1011
1012 // First, check that the node to replace is actually a node:
1013 RooAbsArg* nodeToReplace = findChild(ToReplace, fModel);
1014 if( nodeToReplace==nullptr ) {
1015 std::cout << "Error: Cannot replace node: " << ToReplace
1016 << " because this node wasn't found in: " << fModel->GetName()
1017 << std::endl;
1018 throw hf_exc();
1019 }
1020
1021
1022 const std::string attrib = "ORIGNAME:" + ToReplace;
1023 const bool oldAttrib = ReplaceWith->getAttribute(attrib.c_str());
1024 ReplaceWith->setAttribute(attrib.c_str());
1025 RooArgSet newServerSet{*ReplaceWith};
1026
1027 // Now that we have the node we want to replace, we have to
1028 // get its parent node
1029
1030 // Do this by looping over the clients and replacing their servers
1031 // (NOTE: This happens for ALL clients across the pdf)
1032 for (auto client : nodeToReplace->clients()) {
1033
1034 // Check if this client is a member of our pdf
1035 // (We probably don't want to mess with clients
1036 // if they aren't...)
1037 if( findChild(client->GetName(), fModel) == nullptr) continue;
1038
1039 // Now, do the replacement:
1040 client->redirectServers(newServerSet);
1041 std::cout << "Replaced: " << ToReplace << " with: " << ReplaceWith->GetName()
1042 << " in node: " << client->GetName() << std::endl;
1043
1044 }
1045
1046 // reset temporary attribute for server redirection
1047 ReplaceWith->setAttribute(attrib.c_str(), oldAttrib);
1048
1049 return;
1050
1051 }
1052
1053
1054 void HistFactoryNavigation::PrintSampleComponents(const std::string& channel,
1055 const std::string& sample) {
1056
1057 // Get the Sample Node
1058 RooAbsReal* sampleNode = SampleFunction(channel, sample);
1059
1060 // Get the observables for this channel
1061 RooArgList observable_list( *GetObservableSet(channel) );
1062
1063 // Make the total histogram for this sample
1064 std::string total_Name = sampleNode->GetName();
1065 std::unique_ptr<TH1> total_hist{MakeHistFromRooFunction( sampleNode, observable_list, total_Name + "_tmp")};
1066 unsigned int num_bins = total_hist->GetNbinsX()*total_hist->GetNbinsY()*total_hist->GetNbinsZ();
1067
1068 RooArgSet components;
1069
1070 // Let's see what it is...
1071 int label_print_width = 30;
1072 int bin_print_width = 12;
1073 if( strcmp(sampleNode->ClassName(),"RooProduct")==0){
1074 RooProduct* prod = dynamic_cast<RooProduct*>(sampleNode);
1075 components.add( _GetAllProducts(prod) );
1076 }
1077 else {
1078 components.add(*sampleNode);
1079 }
1080
1081 /////// NODE SIZE
1082 {
1083 for (auto *component : static_range_cast<RooAbsReal*>(components)) {
1084 std::string NodeName = component->GetName();
1085 label_print_width = TMath::Max(label_print_width, static_cast<int>(NodeName.size())+2);
1086 }
1087 }
1088
1089 // Now, loop over the components and print them out:
1090 std::cout << std::endl;
1091 std::cout << "Channel: " << channel << " Sample: " << sample << std::endl;
1092 std::cout << std::setw(label_print_width) << "Factor";
1093
1094 for(unsigned int i=0; i < num_bins; ++i) {
1095 if( _minBinToPrint != -1 && (int)i < _minBinToPrint) continue;
1096 if( _maxBinToPrint != -1 && (int)i > _maxBinToPrint) break;
1097 std::stringstream sstr;
1098 sstr << "Bin" << i;
1099 std::cout << std::setw(bin_print_width) << sstr.str();
1100 }
1101 std::cout << std::endl;
1102
1103
1104 for (auto *component : static_range_cast<RooAbsReal*>(components)) {
1105 std::string NodeName = component->GetName();
1106 // Make a histogram for this node
1107 // Do some horrible things to prevent some really
1108 // annoying messages from being printed
1111 std::unique_ptr<TH1> hist;
1112 try {
1113 hist.reset(MakeHistFromRooFunction( component, observable_list, NodeName+"_tmp"));
1114 } catch(...) {
1116 throw;
1117 }
1119
1120 // Print the hist
1121 std::cout << std::setw(label_print_width) << NodeName;
1122
1123 // Print the Histogram
1124 PrintMultiDimHist(hist.get(), bin_print_width);
1125 }
1126 /////
1127 std::string line_break;
1128 int high_bin = _maxBinToPrint==-1 ? num_bins : TMath::Min(_maxBinToPrint, (int)num_bins);
1129 int low_bin = _minBinToPrint==-1 ? 1 : _minBinToPrint;
1130 int break_length = (high_bin - low_bin + 1) * bin_print_width;
1131 break_length += label_print_width;
1132 for(int i = 0; i < break_length; ++i) {
1133 line_break += "=";
1134 }
1135 std::cout << line_break << std::endl;
1136
1137 std::cout << std::setw(label_print_width) << "TOTAL:";
1138 PrintMultiDimHist(total_hist.get(), bin_print_width);
1139 }
1140
1141
1143 std::string name ) {
1144
1145 // Turn a RooAbsReal* into a TH1* based
1146 // on a template histogram.
1147 // The 'vars' arg list defines the x (and y and z variables)
1148 // Loop over the bins of the Template,
1149 // find the bin centers,
1150 // Scan the input Var over those bin centers,
1151 // and use the value of the function
1152 // to make the new histogram
1153
1154 // Make the new histogram
1155 // Cone and empty the template
1156 // TH1* hist = (TH1*) histTemplate.Clone( name.c_str() );
1157
1158 int dim = vars.getSize();
1159
1160 TH1* hist=nullptr;
1161
1162 if( dim==1 ) {
1163 RooRealVar* varX = (RooRealVar*) vars.at(0);
1164 hist = func->createHistogram( name.c_str(),*varX, RooFit::Binning(varX->getBinning()), RooFit::Scaling(false) );
1165 }
1166 else if( dim==2 ) {
1167 RooRealVar* varX = (RooRealVar*) vars.at(0);
1168 RooRealVar* varY = (RooRealVar*) vars.at(1);
1169 hist = func->createHistogram( name.c_str(),*varX, RooFit::Binning(varX->getBinning()), RooFit::Scaling(false),
1170 RooFit::YVar(*varY, RooFit::Binning(varY->getBinning())) );
1171 }
1172 else if( dim==3 ) {
1173 RooRealVar* varX = (RooRealVar*) vars.at(0);
1174 RooRealVar* varY = (RooRealVar*) vars.at(1);
1175 RooRealVar* varZ = (RooRealVar*) vars.at(2);
1176 hist = func->createHistogram( name.c_str(),*varX, RooFit::Binning(varX->getBinning()), RooFit::Scaling(false),
1177 RooFit::YVar(*varY, RooFit::Binning(varY->getBinning())),
1178 RooFit::YVar(*varZ, RooFit::Binning(varZ->getBinning())) );
1179 }
1180 else {
1181 std::cout << "Error: To Create Histogram from RooAbsReal function, Dimension must be 1, 2, or 3" << std::endl;
1182 throw hf_exc();
1183 }
1184
1185 return hist;
1186 }
1187
1188 // A simple wrapper to use a ModelConfig
1190 RooAbsPdf* modelPdf = mc->GetPdf();
1191 const RooArgSet* observables = mc->GetObservables();
1192 _GetNodes(modelPdf, observables);
1193 }
1194
1195
1196 void HistFactoryNavigation::SetConstant(const std::string& regExpr, bool constant) {
1197
1198 // Regex FTW
1199
1200 TString RegexTString(regExpr);
1201 TRegexp theRegExpr(RegexTString);
1202
1203 // Now, loop over all variables and
1204 // set the constant as
1205
1206 // Get the list of parameters
1207 RooArgSet params;
1209
1210 std::cout << std::endl;
1211
1212 // Create the title row
1213 std::cout << std::setw(30) << "Parameter";
1214 std::cout << std::setw(15) << "Value"
1215 << std::setw(15) << "Error Low"
1216 << std::setw(15) << "Error High"
1217 << std::endl;
1218
1219 // Loop over the parameters and print their values, etc
1220 for (auto *param : static_range_cast<RooRealVar *>(params)) {
1221
1222 std::string ParamName = param->GetName();
1223 TString ParamNameTString(ParamName);
1224
1225 // Use the Regex to skip all parameters that don't match
1226 //if( theRegExpr.Index(ParamNameTString, ParamName.size()) == -1 ) continue;
1227 Ssiz_t dummy;
1228 if( theRegExpr.Index(ParamNameTString, &dummy) == -1 ) continue;
1229
1230 param->setConstant( constant );
1231 std::cout << "Setting param: " << ParamName << " constant"
1232 << " (matches regex: " << regExpr << ")" << std::endl;
1233 }
1234 }
1235
1236 RooRealVar* HistFactoryNavigation::var(const std::string& varName) const {
1237
1238 RooAbsArg* arg = findChild(varName, fModel);
1239 if( !arg ) return nullptr;
1240
1241 RooRealVar* var_obj = dynamic_cast<RooRealVar*>(arg);
1242 return var_obj;
1243
1244 }
1245
1246 } // namespace HistFactory
1247} // namespace RooStats
1248
1249
1250
1251
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
char name[80]
Definition TGX11.cxx:110
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition RooAbsArg.h:74
RooFit::OwningPtr< RooArgSet > getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
RooFit::OwningPtr< RooArgSet > getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
bool redirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool isRecursionStep=false)
Replace all direct servers of this object with the new servers in newServerList.
RooFit::OwningPtr< RooArgSet > getComponents() const
Create a RooArgSet with all components (branch nodes) of the expression tree headed by this object.
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
const RefCountList_t & clients() const
List of all clients of this object.
Definition RooAbsArg.h:190
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
RooAbsArg * findServer(const char *name) const
Return server of this with name name. Returns nullptr if not found.
Definition RooAbsArg.h:208
Int_t getSize() const
Return the number of elements in the collection.
const char * GetName() const override
Returns name of object.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooAbsArg * find(const char *name) const
Find object with given name in list.
void Print(Option_t *options=nullptr) const override
This method must be overridden when a class wants to print itself.
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
TH1 * createHistogram(RooStringView varNameList, Int_t xbins=0, Int_t ybins=0, Int_t zbins=0) const
Create and fill a ROOT histogram TH1, TH2 or TH3 with the values of this function for the variables w...
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition RooArgList.h:110
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
RooCategory is an object to represent discrete states.
Definition RooCategory.h:28
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:57
static RooMsgService & instance()
Return reference to singleton instance.
void setGlobalKillBelow(RooFit::MsgLevel level)
RooFit::MsgLevel globalKillBelow() const
A RooProduct represents the product of a given set of RooAbsReal objects.
Definition RooProduct.h:29
RooArgList components()
Definition RooProduct.h:48
The class RooRealSumPdf implements a PDF constructed from a sum of functions:
const RooArgList & funcList() const
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:40
const RooAbsBinning & getBinning(const char *name=nullptr, bool verbose=true, bool createOnTheFly=false) const override
Return binning definition with name.
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
RooAbsPdf * getPdf(RooStringView catName) const
Return the p.d.f associated with the given index category name.
const RooAbsCategoryLValue & indexCat() const
void PrintParameters(bool IncludeConstantParams=false)
Print the current values and errors of pdf parameters.
std::vector< std::string > fChannelNameVec
The list of channels.
RooArgSet * GetObservableSet(const std::string &channel)
Get the set of observables for a given channel.
TH1 * GetDataHist(RooDataSet *data, const std::string &channel, const std::string &name="")
Get a histogram from the dataset for this channel.
void _GetNodes(ModelConfig *mc)
Fetch the node information for the pdf in question, and save it in the varous collections in this cla...
std::map< std::string, RooAbsPdf * > fChannelSumNodeMap
Map of channel names to pdf without constraint.
void ReplaceNode(const std::string &ToReplace, RooAbsArg *ReplaceWith)
Find a node in the pdf and replace it with a new node These nodes can be functions,...
void PrintState()
Should pretty print all channels and the current values

void PrintSampleComponents(const std::string &channel, const std::string &sample)
Print the different components that make up a sample (NormFactors, Statistical Uncertainties,...
void SetPrintWidths(const std::string &channel)
Set the title and bin widths.
RooAbsPdf * fModel
The HistFactory Pdf Pointer.
TH1 * GetChannelHist(const std::string &channel, const std::string &name="")
Get the total channel histogram for this channel.
TH1 * GetSampleHist(const std::string &channel, const std::string &sample, const std::string &name="")
The (current) histogram for that sample This includes all parameters and interpolation.
TH1 * MakeHistFromRooFunction(RooAbsReal *func, RooArgList vars, std::string name="Hist")
Make a histogram from a function Edit so it can take a RooArgSet of parameters.
void PrintMultiDimHist(TH1 *hist, int bin_print_width)
Print a histogram's contents to the screen void PrettyPrintHistogram(TH1* hist);.
void PrintSampleParameters(const std::string &channel, const std::string &sample, bool IncludeConstantParams=false)
Print parameters that effect a particular sample.
std::map< std::string, RooAbsReal * > GetSampleFunctionMap(const std::string &channel)
Get a map of sample names to their functions for a particular channel.
RooAbsReal * SampleFunction(const std::string &channel, const std::string &sample)
Get the RooAbsReal function for a given sample in a given channel.
HistFactoryNavigation(ModelConfig *mc)
Initialze based on an already-created HistFactory Model.
double GetBinValue(int bin, const std::string &channel)
The value of the ith bin for the total in that channel.
RooAbsArg * findChild(const std::string &name, RooAbsReal *parent) const
Internal method implementation of finding a daughter node from a parent node (looping over all genera...
std::map< std::string, std::map< std::string, RooAbsReal * > > fChannelSampleFunctionMap
Map of Map of Channel, Sample names to Function Nodes Used by doing: fChannelSampleFunctionMap["MyCha...
std::map< std::string, RooAbsPdf * > fChannelPdfMap
Map of channel names to their full pdf's.
std::vector< std::string > GetChannelSampleList(const std::string &channel)
void PrintModelAndData(RooDataSet *data)
Print the model and the data, comparing channel by channel.
std::map< std::string, RooArgSet * > fChannelObservMap
Map of channel names to their set of ovservables.
RooAbsPdf * GetChannelPdf(const std::string &channel)
void PrintDataSet(RooDataSet *data, const std::string &channel="")
Print a "HistFactory style" RooDataSet in a readable way.
void PrintChannelParameters(const std::string &channel, bool IncludeConstantParams=false)
Print parameters that effect a particular channel.
void SetConstant(const std::string &regExpr=".*", bool constant=true)
RooArgSet _GetAllProducts(RooProduct *node)
Recursively get all products of products.
THStack * GetChannelStack(const std::string &channel, const std::string &name="")
Get a stack of all samples in a channel.
RooAbsReal * GetConstraintTerm(const std::string &parameter)
Get the constraint term for a given systematic (alpha or gamma)
void DrawChannel(const std::string &channel, RooDataSet *data=nullptr)
Draw a stack of the channel, and include data if the pointer is supplied.
RooRealVar * var(const std::string &varName) const
double GetConstraintUncertainty(const std::string &parameter)
Get the uncertainty based on the constraint term for a given systematic.
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition ModelConfig.h:35
const RooArgSet * GetObservables() const
get RooArgSet for observables (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)
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
virtual Int_t GetNbinsY() const
Definition TH1.h:296
virtual Int_t GetNbinsZ() const
Definition TH1.h:297
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
Definition TH1.cxx:7091
virtual Int_t GetNbinsX() const
Definition TH1.h:295
virtual Bool_t Add(TF1 *h1, Double_t c1=1, Option_t *option="")
Performs the operation: this = this + c1*f1 if errors are defined (see TH1::Sumw2),...
Definition TH1.cxx:807
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3060
Bool_t IsBinUnderflow(Int_t bin, Int_t axis=0) const
Return true if the bin is underflow.
Definition TH1.cxx:5178
Bool_t IsBinOverflow(Int_t bin, Int_t axis=0) const
Return true if the bin is overflow.
Definition TH1.cxx:5146
void SetName(const char *name) override
Change the name of this histogram.
Definition TH1.cxx:8826
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:5025
TObject * Clone(const char *newname="") const override
Make a complete copy of the underlying object.
Definition TH1.cxx:2727
The Histogram stack class.
Definition THStack.h:38
virtual void Add(TH1 *h, Option_t *option="")
add a new histogram to the list Only 1-d and 2-d histograms currently supported.
Definition THStack.cxx:364
void Draw(Option_t *chopt="") override
Draw this multihist with its current attributes.
Definition THStack.cxx:449
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:207
Regular expression class.
Definition TRegexp.h:31
Ssiz_t Index(const TString &str, Ssiz_t *len, Ssiz_t start=0) const
Find the first occurrence of the regexp in string and return the position, or -1 if there is no match...
Definition TRegexp.cxx:209
Basic string class.
Definition TString.h:139
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
RooCmdArg Scaling(bool flag)
RooCmdArg Binning(const RooAbsBinning &binning)
const Double_t sigma
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
Namespace for the RooStats classes.
Definition Asimov.h:19
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:250
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:660
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:198
Definition file.py:1