Logo ROOT  
Reference Guide
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
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
358
359 std::cout << std::endl;
360
361 // Create the title row
362 std::cout << std::setw(30) << "Parameter";
363 std::cout << std::setw(15) << "Value"
364 << std::setw(15) << "Error Low"
365 << std::setw(15) << "Error High"
366 << std::endl;
367
368 // Loop over the parameters and print their values, etc
369 for (auto const *param : static_range_cast<RooRealVar *>(*params)) {
370 if( !IncludeConstantParams && param->isConstant() ) continue;
371
372 std::cout << std::setw(30) << param->GetName();
373 std::cout << std::setw(15) << param->getVal();
374 if( !param->isConstant() ) {
375 std::cout << std::setw(15) << param->getErrorLo() << std::setw(15) << param->getErrorHi();
376 }
377 std::cout<< std::endl;
378 }
379 std::cout << std::endl;
380 }
381
382 void HistFactoryNavigation::PrintChannelParameters(const std::string& channel,
383 bool IncludeConstantParams) {
384
385 // Get the list of parameters
387
388 // Get the pdf for this channel
389 RooAbsPdf* channel_pdf = GetChannelPdf(channel);
390
391 std::cout << std::endl;
392
393 // Create the title row
394 std::cout << std::setw(30) << "Parameter";
395 std::cout << std::setw(15) << "Value"
396 << std::setw(15) << "Error Low"
397 << std::setw(15) << "Error High"
398 << std::endl;
399
400 // Loop over the parameters and print their values, etc
401 for (auto const *param : static_range_cast<RooRealVar *>(*params)) {
402 if( !IncludeConstantParams && param->isConstant() ) continue;
403 if( findChild(param->GetName(), channel_pdf)==nullptr ) continue;
404 std::cout << std::setw(30) << param->GetName();
405 std::cout << std::setw(15) << param->getVal();
406 if( !param->isConstant() ) {
407 std::cout << std::setw(15) << param->getErrorLo() << std::setw(15) << param->getErrorHi();
408 }
409 std::cout<< std::endl;
410 }
411 std::cout << std::endl;
412 }
413
414
415 void HistFactoryNavigation::PrintSampleParameters(const std::string& channel,
416 const std::string& sample,
417 bool IncludeConstantParams) {
418
419 // Get the list of parameters
421
422 // Get the pdf for this channel
423 RooAbsReal* sample_func = SampleFunction(channel, sample);
424
425 std::cout << std::endl;
426
427 // Create the title row
428 std::cout << std::setw(30) << "Parameter";
429 std::cout << std::setw(15) << "Value"
430 << std::setw(15) << "Error Low"
431 << std::setw(15) << "Error High"
432 << std::endl;
433
434 // Loop over the parameters and print their values, etc
435 for (auto const *param : static_range_cast<RooRealVar *>(*params)) {
436 if( !IncludeConstantParams && param->isConstant() ) continue;
437 if( findChild(param->GetName(), sample_func)==nullptr ) continue;
438 std::cout << std::setw(30) << param->GetName();
439 std::cout << std::setw(15) << param->getVal();
440 if( !param->isConstant() ) {
441 std::cout << std::setw(15) << param->getErrorLo() << std::setw(15) << param->getErrorHi();
442 }
443 std::cout<< std::endl;
444 }
445 std::cout << std::endl;
446 }
447
448
449 double HistFactoryNavigation::GetBinValue(int bin, const std::string& channel) {
450 // Get the total bin height for the ith bin (ROOT indexing convention)
451 // in channel 'channel'
452 // (Could be optimized, it uses an intermediate histogram for now...)
453
454 // Get the histogram, fetch the bin content, and return
455 std::unique_ptr<TH1> channel_hist_tmp{GetChannelHist(channel, (channel+"_tmp").c_str())};
456 return channel_hist_tmp->GetBinContent(bin);
457 }
458
459
460 double HistFactoryNavigation::GetBinValue(int bin, const std::string& channel, const std::string& sample){
461 // Get the total bin height for the ith bin (ROOT indexing convention)
462 // in channel 'channel'
463 // (This will be slow if you plan on looping over it.
464 // Could be optimized, it uses an intermediate histogram for now...)
465
466 // Get the histogram, fetch the bin content, and return
467 std::unique_ptr<TH1> sample_hist_tmp{GetSampleHist(channel, sample, (channel+"_tmp").c_str())};
468 return sample_hist_tmp->GetBinContent(bin);
469 }
470
471
472 std::map< std::string, RooAbsReal*> HistFactoryNavigation::GetSampleFunctionMap(const std::string& channel) {
473 // Get a map of strings to function pointers,
474 // which each function corresponds to a sample
475
476 std::map< std::string, std::map< std::string, RooAbsReal*> >::iterator channel_itr;
477 channel_itr = fChannelSampleFunctionMap.find(channel);
478 if( channel_itr==fChannelSampleFunctionMap.end() ){
479 std::cout << "Error: Channel: " << channel << " not found in Navigation" << std::endl;
480 throw hf_exc();
481 }
482
483 return channel_itr->second;
484 }
485
486
487 RooAbsReal* HistFactoryNavigation::SampleFunction(const std::string& channel, const std::string& sample){
488 // Return the function object pointer cooresponding
489 // to a particular sample in a particular channel
490
491 std::map< std::string, std::map< std::string, RooAbsReal*> >::iterator channel_itr;
492 channel_itr = fChannelSampleFunctionMap.find(channel);
493 if( channel_itr==fChannelSampleFunctionMap.end() ){
494 std::cout << "Error: Channel: " << channel << " not found in Navigation" << std::endl;
495 throw hf_exc();
496 }
497
498 std::map< std::string, RooAbsReal*>& SampleMap = channel_itr->second;
499 std::map< std::string, RooAbsReal*>::iterator sample_itr;
500 sample_itr = SampleMap.find(sample);
501 if( sample_itr==SampleMap.end() ){
502 std::cout << "Error: Sample: " << sample << " not found in Navigation" << std::endl;
503 throw hf_exc();
504 }
505
506 return sample_itr->second;
507
508 }
509
510
512 // Get the observables for a particular channel
513
514 std::map< std::string, RooArgSet*>::iterator channel_itr;
515 channel_itr = fChannelObservMap.find(channel);
516 if( channel_itr==fChannelObservMap.end() ){
517 std::cout << "Error: Channel: " << channel << " not found in Navigation" << std::endl;
518 throw hf_exc();
519 }
520
521 return channel_itr->second;
522
523 }
524
525
526 TH1* HistFactoryNavigation::GetSampleHist(const std::string& channel, const std::string& sample,
527 const std::string& hist_name) {
528 // Get a histogram of the expected values for
529 // a particular sample in a particular channel
530 // Give a name, or a default one will be used
531
532 RooArgList observable_list( *GetObservableSet(channel) );
533
534 std::string name = hist_name;
535 if(hist_name=="") name = channel + "_" + sample + "_hist";
536
537 RooAbsReal* sample_function = SampleFunction(channel, sample);
538
539 return MakeHistFromRooFunction( sample_function, observable_list, name );
540
541 }
542
543
544 TH1* HistFactoryNavigation::GetChannelHist(const std::string& channel, const std::string& hist_name) {
545 // Get a histogram of the total expected value
546 // per bin for this channel
547 // Give a name, or a default one will be used
548
549 RooArgList observable_list( *GetObservableSet(channel) );
550
551 std::map< std::string, RooAbsReal*> SampleFunctionMap = GetSampleFunctionMap(channel);
552
553 // Okay, 'loop' once
554 TH1* total_hist = nullptr;
555 std::map< std::string, RooAbsReal*>::iterator itr = SampleFunctionMap.begin();
556 for( ; itr != SampleFunctionMap.end(); ++itr) {
557 std::string sample_name = itr->first;
558 std::string tmp_hist_name = sample_name + "_hist_tmp";
559 RooAbsReal* sample_function = itr->second;
560 std::unique_ptr<TH1> sample_hist{MakeHistFromRooFunction(sample_function, observable_list,
561 tmp_hist_name)};
562 total_hist = (TH1*) sample_hist->Clone("TotalHist");
563 break;
564 }
565 if (!total_hist)
566 return nullptr;
567
568 total_hist->Reset();
569
570 // Loop over the SampleFunctionMap and add up all the histograms
571 // to get the total histogram for the channel
572 itr = SampleFunctionMap.begin();
573 for( ; itr != SampleFunctionMap.end(); ++itr) {
574 std::string sample_name = itr->first;
575 std::string tmp_hist_name = sample_name + "_hist_tmp";
576 RooAbsReal* sample_function = itr->second;
577 std::unique_ptr<TH1> sample_hist{MakeHistFromRooFunction(sample_function, observable_list,
578 tmp_hist_name)};
579 total_hist->Add(sample_hist.get());
580 }
581
582 if(hist_name=="") total_hist->SetName(hist_name.c_str());
583 else total_hist->SetName( (channel + "_hist").c_str() );
584
585 return total_hist;
586
587 }
588
589
590 std::vector< std::string > HistFactoryNavigation::GetChannelSampleList(const std::string& channel) {
591
592 std::vector<std::string> sample_list;
593
594 std::map< std::string, RooAbsReal*> sample_map = fChannelSampleFunctionMap[channel];
595 std::map< std::string, RooAbsReal*>::iterator itr = sample_map.begin();;
596 for( ; itr != sample_map.end(); ++itr) {
597 sample_list.push_back( itr->first );
598 }
599
600 return sample_list;
601
602 }
603
604
606 const std::string& name) {
607
608 THStack* stack = new THStack(name.c_str(), "");
609
610 std::vector< std::string > samples = GetChannelSampleList(channel);
611
612 // Add the histograms
613 for( unsigned int i=0; i < samples.size(); ++i) {
614 std::string sample_name = samples.at(i);
615 TH1* hist = GetSampleHist(channel, sample_name, sample_name+"_tmp");
616 hist->SetLineColor(2+i);
617 hist->SetFillColor(2+i);
618 stack->Add(hist);
619 }
620
621 return stack;
622
623 }
624
625
627 const std::string& name) {
628
629 // TO DO:
630 // MAINTAIN THE ACTUAL RANGE, USING THE OBSERVABLES
631 // MAKE IT WORK FOR MULTI-DIMENSIONAL
632 //
633
634 std::unique_ptr<TList> dataset_list;
635
636 // If the dataset covers multiple categories,
637 // Split the dataset based on the categories
638 if(strcmp(fModel->ClassName(),"RooSimultaneous")==0){
639
640 // If so, get a list of the component pdf's:
642 RooCategory* channelCat = (RooCategory*) (&simPdf->indexCat());
643
644 dataset_list.reset(data->split(*channelCat));
645
646 data = dynamic_cast<RooDataSet*>( dataset_list->FindObject(channel.c_str()) );
647
648 }
649
650 RooArgList vars( *GetObservableSet(channel) );
651
652 int dim = vars.getSize();
653
654 TH1* hist = nullptr;
655
656 if (!data) {
657 std::cout << "Error: To Create Histogram from RooDataSet" << std::endl;
658 if (dataset_list) {
659 dataset_list.reset();
660 }
661 throw hf_exc();
662 } else if( dim==1 ) {
663 RooRealVar* varX = (RooRealVar*) vars.at(0);
664 hist = data->createHistogram( name.c_str(),*varX, RooFit::Binning(varX->getBinning()) );
665 }
666 else if( dim==2 ) {
667 RooRealVar* varX = (RooRealVar*) vars.at(0);
668 RooRealVar* varY = (RooRealVar*) vars.at(1);
669 hist = data->createHistogram( name.c_str(),*varX, RooFit::Binning(varX->getBinning()),
670 RooFit::YVar(*varY, RooFit::Binning(varY->getBinning())) );
671 }
672 else if( dim==3 ) {
673 RooRealVar* varX = (RooRealVar*) vars.at(0);
674 RooRealVar* varY = (RooRealVar*) vars.at(1);
675 RooRealVar* varZ = (RooRealVar*) vars.at(2);
676 hist = data->createHistogram( name.c_str(),*varX, RooFit::Binning(varX->getBinning()),
677 RooFit::YVar(*varY, RooFit::Binning(varY->getBinning())),
678 RooFit::YVar(*varZ, RooFit::Binning(varZ->getBinning())) );
679 }
680 else {
681 std::cout << "Error: To Create Histogram from RooDataSet, Dimension must be 1, 2, or 3" << std::endl;
682 std::cout << "Observables: " << std::endl;
683 vars.Print("V");
684 if (dataset_list) {
685 dataset_list->Delete();
686 dataset_list.reset();
687 }
688 throw hf_exc();
689 }
690
691 if (dataset_list) {
692 dataset_list->Delete();
693 dataset_list.reset();
694 }
695
696 return hist;
697
698 }
699
700
701 void HistFactoryNavigation::DrawChannel(const std::string& channel, RooDataSet* data) {
702
703 // Get the stack
704 THStack* stack = GetChannelStack(channel, channel+"_stack_tmp");
705
706 stack->Draw();
707
708 if( data!=nullptr ) {
709 TH1* data_hist = GetDataHist(data, channel, channel+"_data_tmp");
710 data_hist->Draw("SAME");
711 }
712
713 }
714
715
716
718
719 // An internal method to recursively get all products,
720 // including if a RooProduct is a Product of RooProducts
721 // etc
722
723 RooArgSet allTerms;
724
725 // Get All Subnodes of this product
726 // Loop over the subnodes and add
727 for (auto *arg : node->components()) {
728 std::string ClassName = arg->ClassName();
729 if( ClassName == "RooProduct" ) {
730 RooProduct* prod = static_cast<RooProduct*>(arg);
731 allTerms.add( _GetAllProducts(prod) );
732 }
733 else {
734 allTerms.add(*arg);
735 }
736 }
737 return allTerms;
738 }
739
740
741
742
743 void HistFactoryNavigation::_GetNodes(RooAbsPdf* modelPdf, const RooArgSet* observables) {
744
745 // Get the pdf from the ModelConfig
746 //RooAbsPdf* modelPdf = mc->GetPdf();
747 //RooArgSet* observables = mc->GetObservables();
748
749 // Create vectors to hold the channel pdf's
750 // as well as the set of observables for each channel
751 //std::map< std::string, RooAbsPdf* > channelPdfMap;
752 //std::map< std::string, RooArgSet* > channelObservMap;
753
754 // Check if it is a simultaneous pdf or not
755 // (if it's an individual channel, it won't be, if it's
756 // combined, it's simultaneous)
757 // Fill the channel vectors based on the structure
758 // (Obviously, if it's not simultaneous, there will be
759 // only one entry in the vector for the single channel)
760 if(strcmp(modelPdf->ClassName(),"RooSimultaneous")==0){
761
762 // If so, get a list of the component pdf's:
763 RooSimultaneous* simPdf = (RooSimultaneous*) modelPdf;
764 RooCategory* channelCat = (RooCategory*) (&simPdf->indexCat());
765
766 // Iterate over the categories and get the
767 // pdf and observables for each category
768 for (const auto& nameIdx : *channelCat) {
769 const std::string& ChannelName = nameIdx.first;
770 fChannelNameVec.push_back( ChannelName );
771 RooAbsPdf* pdftmp = simPdf->getPdf(ChannelName.c_str()) ;
772 RooArgSet* obstmp = pdftmp->getObservables(*observables) ;
773 fChannelPdfMap[ChannelName] = pdftmp;
774 fChannelObservMap[ChannelName] = obstmp;
775 }
776
777 } else {
778 RooArgSet* obstmp = modelPdf->getObservables(*observables) ;
779 // The channel name is model_CHANNEL
780 std::string ChannelName = modelPdf->GetName();
781 ChannelName = ChannelName.replace(0, 6, "");
782 fChannelNameVec.push_back(ChannelName);
783 fChannelPdfMap[ChannelName] = modelPdf;
784 fChannelObservMap[ChannelName] = obstmp;
785
786 }
787
788 // Okay, now we have maps of the pdfs
789 // and the observable list per channel
790 // We then loop over the channel pdfs:
791 // and find their RooRealSumPdfs
792 // std::map< std::string, RooRealSumPdf* > channelSumNodeMap;
793
794 for( unsigned int i = 0; i < fChannelNameVec.size(); ++i ) {
795
796 std::string ChannelName = fChannelNameVec.at(i);
797 RooAbsPdf* pdf = fChannelPdfMap[ChannelName];
798
799 // Loop over the pdf's components and find
800 // the (one) that is a RooRealSumPdf
801 // Based on the mode, we assume that node is
802 // the "unconstrained" pdf node for that channel
803 for (auto *arg : *pdf->getComponents()) {
804 std::string ClassName = arg->ClassName();
805 if( ClassName == "RooRealSumPdf" ) {
806 fChannelSumNodeMap[ChannelName] = static_cast <RooRealSumPdf*>(arg);
807 break;
808 }
809 }
810 }
811
812 // Okay, now we have all necessary
813 // nodes filled for each channel.
814 for( unsigned int i = 0; i < fChannelNameVec.size(); ++i ) {
815
816 std::string ChannelName = fChannelNameVec.at(i);
817 RooRealSumPdf* sumPdf = dynamic_cast<RooRealSumPdf*>(fChannelSumNodeMap[ChannelName]);
818
819 // We now take the RooRealSumPdf and loop over
820 // its component functions. The RooRealSumPdf turns
821 // a list of functions (expected events or bin heights
822 // per sample) and turns it into a pdf.
823 // Therefore, we loop over it to find the expected
824 // height for the various samples
825
826 // First, create a map to store the function nodes
827 // for each sample in this channel
828 std::map< std::string, RooAbsReal*> sampleFunctionMap;
829
830 // Loop over the sample nodes in this
831 // channel's RooRealSumPdf
832 for (auto *func : static_range_cast<RooAbsReal *>(sumPdf->funcList())) {
833 // Do a bit of work to get the name of each sample
834 std::string SampleName = func->GetName();
835 if( SampleName.find("L_x_") != std::string::npos ) {
836 size_t index = SampleName.find("L_x_");
837 SampleName.replace( index, 4, "" );
838 }
839 if( SampleName.find(ChannelName.c_str()) != std::string::npos ) {
840 size_t index = SampleName.find(ChannelName.c_str());
841 SampleName = SampleName.substr(0, index-1);
842 }
843
844 // And simply save this node into our map
845 sampleFunctionMap[SampleName] = func;
846 }
847
848 fChannelSampleFunctionMap[ChannelName] = sampleFunctionMap;
849
850 // Okay, now we have a list of histograms
851 // representing the samples for this channel.
852
853 }
854
855 }
856
857
858 RooAbsArg* HistFactoryNavigation::findChild(const std::string& name, RooAbsReal* parent) const {
859
860 RooAbsArg* term=nullptr;
861
862 // Check if it is a "component",
863 // ie a sub node:
864 for (auto arg : *parent->getComponents()) {
865 std::string ArgName = arg->GetName();
866 if (ArgName == name) {
867 term = arg;
868 break;
869 }
870 }
871
872 if( term != nullptr ) return term;
873
874 // If that failed,
875 // Check if it's a Parameter
876 // (ie a RooRealVar)
877 RooArgSet args;
878 for (auto *param : *parent->getParameters(&args)) {
879 std::string ParamName = param->GetName();
880 if( ParamName == name ) {
881 term = param;
882 break;
883 }
884 }
885
886 /* Not sure if we want to be silent
887 But since we're returning a pointer which can be nullptr,
888 I think it's the user's job to do checks on it.
889 A dereference will always cause a crash, so it won't
890 be silent for long...
891 if( term==nullptr ) {
892 std::cout << "Error: Failed to find node: " << name
893 << " as a child of: " << parent->GetName()
894 << std::endl;
895 }
896 */
897
898 return term;
899
900 }
901
902
904
905 std::string ConstraintTermName = parameter + "Constraint";
906
907 // First, as a sanity check, let's see if the parameter
908 // itself actually exists and if the model depends on it:
909 RooRealVar* param = dynamic_cast<RooRealVar*>(findChild(parameter, fModel));
910 if( param==nullptr ) {
911 std::cout << "Error: Couldn't Find parameter: " << parameter << " in model."
912 << std::endl;
913 return nullptr;
914 }
915
916 // The "gamma"'s use a different constraint term name
917 if( parameter.find("gamma_stat_") != std::string::npos ) {
918 ConstraintTermName = parameter + "_constraint";
919 }
920
921 // Now, get the constraint itself
922 RooAbsReal* term = dynamic_cast<RooAbsReal*>(findChild(ConstraintTermName, fModel));
923
924 if( term==nullptr ) {
925 std::cout << "Error: Couldn't Find constraint term for parameter: " << parameter
926 << " (Looked for '" << ConstraintTermName << "')" << std::endl;
927 return nullptr;
928 }
929
930 return term;
931
932 }
933
934
935 double HistFactoryNavigation::GetConstraintUncertainty(const std::string& parameter) {
936
937 RooAbsReal* constraintTerm = GetConstraintTerm(parameter);
938 if( constraintTerm==nullptr ) {
939 std::cout << "Error: Cannot get uncertainty because parameter: " << parameter
940 << " has no constraint term" << std::endl;
941 throw hf_exc();
942 }
943
944 // Get the type of constraint
945 std::string ConstraintType = constraintTerm->ClassName();
946
947 // Find its value
948 double sigma = 0.0;
949
950 if( ConstraintType == "" ) {
951 std::cout << "Error: Constraint type is an empty string."
952 << " This simply should not be." << std::endl;
953 throw hf_exc();
954 }
955 else if( ConstraintType == "RooGaussian" ){
956
957 // Gaussian errors are the 'sigma' in the constraint term
958
959 // Get the name of the 'sigma' for the gaussian
960 // (I don't know of a way of doing RooGaussian::GetSigma() )
961 // For alpha's, the sigma points to a global RooConstVar
962 // with the name "1"
963 // For gamma_stat_*, the sigma is named *_sigma
964 std::string sigmaName = "";
965 if( parameter.find("alpha_")!=std::string::npos ) {
966 sigmaName = "1";;
967 }
968 else if( parameter.find("gamma_stat_")!=std::string::npos ) {
969 sigmaName = parameter + "_sigma";
970 }
971
972 // Get the sigma and its value
973 RooAbsReal* sigmaVar = dynamic_cast<RooAbsReal*>(constraintTerm->findServer(sigmaName.c_str()));
974 if( sigmaVar==nullptr ) {
975 std::cout << "Error: Failed to find the 'sigma' node: " << sigmaName
976 << " in the RooGaussian: " << constraintTerm->GetName() << std::endl;
977 throw hf_exc();
978 }
979 // If we find the uncertainty:
980 sigma = sigmaVar->getVal();
981 }
982 else if( ConstraintType == "RooPoisson" ){
983 // Poisson errors are given by inverting: tau = 1 / (sigma*sigma)
984 std::string tauName = "nom_" + parameter;
985 RooAbsReal* tauVar = dynamic_cast<RooAbsReal*>( constraintTerm->findServer(tauName.c_str()) );
986 if( tauVar==nullptr ) {
987 std::cout << "Error: Failed to find the nominal 'tau' node: " << tauName
988 << " for the RooPoisson: " << constraintTerm->GetName() << std::endl;
989 throw hf_exc();
990 }
991 double tau_val = tauVar->getVal();
992 sigma = 1.0 / TMath::Sqrt( tau_val );
993 }
994 else {
995 std::cout << "Error: Encountered unknown constraint type for Stat Uncertainties: "
996 << ConstraintType << std::endl;
997 throw hf_exc();
998 }
999
1000 return sigma;
1001
1002 }
1003
1004 void HistFactoryNavigation::ReplaceNode(const std::string& ToReplace, RooAbsArg* ReplaceWith) {
1005
1006 // First, check that the node to replace is actually a node:
1007 RooAbsArg* nodeToReplace = findChild(ToReplace, fModel);
1008 if( nodeToReplace==nullptr ) {
1009 std::cout << "Error: Cannot replace node: " << ToReplace
1010 << " because this node wasn't found in: " << fModel->GetName()
1011 << std::endl;
1012 throw hf_exc();
1013 }
1014
1015 // Now that we have the node we want to replace, we have to
1016 // get its parent node
1017
1018 // Do this by looping over the clients and replacing their servers
1019 // (NOTE: This happens for ALL clients across the pdf)
1020 for (auto client : nodeToReplace->clients()) {
1021
1022 // Check if this client is a member of our pdf
1023 // (We probably don't want to mess with clients
1024 // if they aren't...)
1025 if( findChild(client->GetName(), fModel) == nullptr) continue;
1026
1027 // Now, do the replacement:
1028 bool valueProp=false;
1029 bool shapeProp=false;
1030 client->replaceServer( *nodeToReplace, *ReplaceWith, valueProp, shapeProp );
1031 std::cout << "Replaced: " << ToReplace << " with: " << ReplaceWith->GetName()
1032 << " in node: " << client->GetName() << std::endl;
1033
1034 }
1035
1036 return;
1037
1038 }
1039
1040
1041 void HistFactoryNavigation::PrintSampleComponents(const std::string& channel,
1042 const std::string& sample) {
1043
1044 // Get the Sample Node
1045 RooAbsReal* sampleNode = SampleFunction(channel, sample);
1046
1047 // Get the observables for this channel
1048 RooArgList observable_list( *GetObservableSet(channel) );
1049
1050 // Make the total histogram for this sample
1051 std::string total_Name = sampleNode->GetName();
1052 std::unique_ptr<TH1> total_hist{MakeHistFromRooFunction( sampleNode, observable_list, total_Name + "_tmp")};
1053 unsigned int num_bins = total_hist->GetNbinsX()*total_hist->GetNbinsY()*total_hist->GetNbinsZ();
1054
1055 RooArgSet components;
1056
1057 // Let's see what it is...
1058 int label_print_width = 30;
1059 int bin_print_width = 12;
1060 if( strcmp(sampleNode->ClassName(),"RooProduct")==0){
1061 RooProduct* prod = dynamic_cast<RooProduct*>(sampleNode);
1062 components.add( _GetAllProducts(prod) );
1063 }
1064 else {
1065 components.add(*sampleNode);
1066 }
1067
1068 /////// NODE SIZE
1069 {
1070 for (auto *component : static_range_cast<RooAbsReal*>(components)) {
1071 std::string NodeName = component->GetName();
1072 label_print_width = TMath::Max(label_print_width, static_cast<int>(NodeName.size())+2);
1073 }
1074 }
1075
1076 // Now, loop over the components and print them out:
1077 std::cout << std::endl;
1078 std::cout << "Channel: " << channel << " Sample: " << sample << std::endl;
1079 std::cout << std::setw(label_print_width) << "Factor";
1080
1081 for(unsigned int i=0; i < num_bins; ++i) {
1082 if( _minBinToPrint != -1 && (int)i < _minBinToPrint) continue;
1083 if( _maxBinToPrint != -1 && (int)i > _maxBinToPrint) break;
1084 std::stringstream sstr;
1085 sstr << "Bin" << i;
1086 std::cout << std::setw(bin_print_width) << sstr.str();
1087 }
1088 std::cout << std::endl;
1089
1090
1091 for (auto *component : static_range_cast<RooAbsReal*>(components)) {
1092 std::string NodeName = component->GetName();
1093 // Make a histogram for this node
1094 // Do some horrible things to prevent some really
1095 // annoying messages from being printed
1098 std::unique_ptr<TH1> hist;
1099 try {
1100 hist.reset(MakeHistFromRooFunction( component, observable_list, NodeName+"_tmp"));
1101 } catch(...) {
1103 throw;
1104 }
1106
1107 // Print the hist
1108 std::cout << std::setw(label_print_width) << NodeName;
1109
1110 // Print the Histogram
1111 PrintMultiDimHist(hist.get(), bin_print_width);
1112 }
1113 /////
1114 std::string line_break;
1115 int high_bin = _maxBinToPrint==-1 ? num_bins : TMath::Min(_maxBinToPrint, (int)num_bins);
1116 int low_bin = _minBinToPrint==-1 ? 1 : _minBinToPrint;
1117 int break_length = (high_bin - low_bin + 1) * bin_print_width;
1118 break_length += label_print_width;
1119 for(int i = 0; i < break_length; ++i) {
1120 line_break += "=";
1121 }
1122 std::cout << line_break << std::endl;
1123
1124 std::cout << std::setw(label_print_width) << "TOTAL:";
1125 PrintMultiDimHist(total_hist.get(), bin_print_width);
1126 }
1127
1128
1130 std::string name ) {
1131
1132 // Turn a RooAbsReal* into a TH1* based
1133 // on a template histogram.
1134 // The 'vars' arg list defines the x (and y and z variables)
1135 // Loop over the bins of the Template,
1136 // find the bin centers,
1137 // Scan the input Var over those bin centers,
1138 // and use the value of the function
1139 // to make the new histogram
1140
1141 // Make the new histogram
1142 // Cone and empty the template
1143 // TH1* hist = (TH1*) histTemplate.Clone( name.c_str() );
1144
1145 int dim = vars.getSize();
1146
1147 TH1* hist=nullptr;
1148
1149 if( dim==1 ) {
1150 RooRealVar* varX = (RooRealVar*) vars.at(0);
1151 hist = func->createHistogram( name.c_str(),*varX, RooFit::Binning(varX->getBinning()), RooFit::Scaling(false) );
1152 }
1153 else if( dim==2 ) {
1154 RooRealVar* varX = (RooRealVar*) vars.at(0);
1155 RooRealVar* varY = (RooRealVar*) vars.at(1);
1156 hist = func->createHistogram( name.c_str(),*varX, RooFit::Binning(varX->getBinning()), RooFit::Scaling(false),
1157 RooFit::YVar(*varY, RooFit::Binning(varY->getBinning())) );
1158 }
1159 else if( dim==3 ) {
1160 RooRealVar* varX = (RooRealVar*) vars.at(0);
1161 RooRealVar* varY = (RooRealVar*) vars.at(1);
1162 RooRealVar* varZ = (RooRealVar*) vars.at(2);
1163 hist = func->createHistogram( name.c_str(),*varX, RooFit::Binning(varX->getBinning()), RooFit::Scaling(false),
1164 RooFit::YVar(*varY, RooFit::Binning(varY->getBinning())),
1165 RooFit::YVar(*varZ, RooFit::Binning(varZ->getBinning())) );
1166 }
1167 else {
1168 std::cout << "Error: To Create Histogram from RooAbsReal function, Dimension must be 1, 2, or 3" << std::endl;
1169 throw hf_exc();
1170 }
1171
1172 return hist;
1173 }
1174
1175 // A simple wrapper to use a ModelConfig
1177 RooAbsPdf* modelPdf = mc->GetPdf();
1178 const RooArgSet* observables = mc->GetObservables();
1179 _GetNodes(modelPdf, observables);
1180 }
1181
1182
1183 void HistFactoryNavigation::SetConstant(const std::string& regExpr, bool constant) {
1184
1185 // Regex FTW
1186
1187 TString RegexTString(regExpr);
1188 TRegexp theRegExpr(RegexTString);
1189
1190 // Now, loop over all variables and
1191 // set the constant as
1192
1193 // Get the list of parameters
1195
1196 std::cout << std::endl;
1197
1198 // Create the title row
1199 std::cout << std::setw(30) << "Parameter";
1200 std::cout << std::setw(15) << "Value"
1201 << std::setw(15) << "Error Low"
1202 << std::setw(15) << "Error High"
1203 << std::endl;
1204
1205 // Loop over the parameters and print their values, etc
1206 for (auto *param : static_range_cast<RooRealVar *>(*params)) {
1207
1208 std::string ParamName = param->GetName();
1209 TString ParamNameTString(ParamName);
1210
1211 // Use the Regex to skip all parameters that don't match
1212 //if( theRegExpr.Index(ParamNameTString, ParamName.size()) == -1 ) continue;
1213 Ssiz_t dummy;
1214 if( theRegExpr.Index(ParamNameTString, &dummy) == -1 ) continue;
1215
1216 param->setConstant( constant );
1217 std::cout << "Setting param: " << ParamName << " constant"
1218 << " (matches regex: " << regExpr << ")" << std::endl;
1219 }
1220 }
1221
1222 RooRealVar* HistFactoryNavigation::var(const std::string& varName) const {
1223
1224 RooAbsArg* arg = findChild(varName, fModel);
1225 if( !arg ) return nullptr;
1226
1227 RooRealVar* var_obj = dynamic_cast<RooRealVar*>(arg);
1228 return var_obj;
1229
1230 }
1231
1232 } // namespace HistFactory
1233} // namespace RooStats
1234
1235
1236
1237
#define ClassImp(name)
Definition: Rtypes.h:375
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:71
RooArgSet * getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
Definition: RooAbsArg.h:293
const RefCountList_t & clients() const
List of all clients of this object.
Definition: RooAbsArg.h:184
RooArgSet * getComponents() const
Create a RooArgSet with all components (branch nodes) of the expression tree headed by this object.
Definition: RooAbsArg.cxx:754
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...
Definition: RooAbsArg.cxx:541
RooAbsArg * findServer(const char *name) const
Return server of this with name name. Returns nullptr if not found.
Definition: RooAbsArg.h:202
bool empty() const
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.
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(const char *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:56
RooCategory is an object to represent discrete states.
Definition: RooCategory.h:28
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:55
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:
Definition: RooRealSumPdf.h:24
const RooArgList & funcList() const
Definition: RooRealSumPdf.h:45
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.
Definition: RooRealVar.cxx:317
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
const RooAbsCategoryLValue & indexCat() const
RooAbsPdf * getPdf(const char *catName) const
Return the p.d.f associated with the given index category name.
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 funciton 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:30
const RooArgSet * GetObservables() const
get RooArgSet for observables (return nullptr if not existing)
Definition: ModelConfig.h:246
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)
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:8827
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:365
void Draw(Option_t *chopt="") override
Draw this multihist with its current attributes.
Definition: THStack.cxx:450
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:200
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:136
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
RooCmdArg ClassName(const char *name)
RooCmdArg Scaling(bool flag)
RooCmdArg Binning(const RooAbsBinning &binning)
const Double_t sigma
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
Definition: RooGlobalFunc.h:59
@ HistFactory
Definition: RooGlobalFunc.h:63
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