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
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 NULL " << 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 NULL" << 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 NULL" << std::endl;
58 throw hf_exc();
59 }
60 if( observables_in_mc->getSize() == 0 ) {
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 TFile* file = new 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.c_str());
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 NULL" << 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 NULL" << std::endl;
123 throw hf_exc();
124 }
125 if( observables_in_mc->getSize() == 0 ) {
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 NULL" << 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 NULL" << std::endl;
160 throw hf_exc();
161 }
162 if( observables->getSize() == 0 ) {
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 NULL;
206 }
207
208 RooAbsPdf* pdf = itr->second;
209 if( pdf == NULL ) {
210 std::cout << "Warning: Pdf associated with channel: " << channel
211 << " is NULL" << std::endl;
212 return NULL;
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 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
251 delete sample_hist;
252
253 }
254
255 // Make the line break as a set of "===============" ...
256 std::string line_break;
257 int high_bin = _maxBinToPrint==-1 ? num_bins : TMath::Min(_maxBinToPrint, (int)num_bins);
258 int low_bin = _minBinToPrint==-1 ? 1 : _minBinToPrint;
259 int break_length = (high_bin - low_bin + 1) * _bin_print_width;
260 break_length += _label_print_width;
261 for(int i = 0; i < break_length; ++i) {
262 line_break += "=";
263 }
264 std::cout << line_break << std::endl;
265
266 std::string tmp_name = channel + "_pretty_tmp";
267 TH1* channel_hist = GetChannelHist(channel, tmp_name);
268 std::cout << std::setw(_label_print_width) << "TOTAL:";
269
270 // Print the Histogram
271 PrintMultiDimHist(channel_hist, _bin_print_width);
272 delete channel_hist;
273
274 return;
275
276 }
277
278
280 // Loop over channels and print their states, one after another
281 for(unsigned int i = 0; i < fChannelNameVec.size(); ++i) {
283 }
284 }
285
286
287 void HistFactoryNavigation::SetPrintWidths(const std::string& channel) {
288
289 // Get the map of Samples for this channel
290 std::map< std::string, RooAbsReal*> SampleFunctionMap = GetSampleFunctionMap(channel);
291
292 // Get the max of the samples
293 for( std::map< std::string, RooAbsReal*>::iterator itr = SampleFunctionMap.begin();
294 itr != SampleFunctionMap.end(); ++itr) {
295 std::string sample_name = itr->first;
296 _label_print_width = TMath::Max(_label_print_width, (int)sample_name.size()+2);
297 }
298
299 _label_print_width = TMath::Max( _label_print_width, (int)channel.size() + 7);
300 }
301
302
304 const std::string& channel_to_print) {
305
306 // Print the contents of a 'HistFactory' RooDataset
307 // These are stored in a somewhat odd way that makes
308 // them difficult to inspect for humans.
309 // They have the following layout:
310 // =====================================================
311 // ChannelA ChannelB ChannelCat Weight
312 // -----------------------------------------------------
313 // bin_1_center 0 ChannelA bin_1_height
314 // bin_2_center 0 ChannelA bin_2_height
315 // 0 bin_1_center ChannelB bin_1_height
316 // 0 bin_2_center ChannelB bin_2_height
317 // ...etc...
318 // =====================================================
319
320 // int label_print_width = 20;
321 // int bin_print_width = 12;
322
323 // Get the Data Histogram for this channel
324 for( unsigned int i_chan=0; i_chan < fChannelNameVec.size(); ++i_chan) {
325
326 std::string channel_name = fChannelNameVec.at(i_chan);
327
328 // If we pass a channel string, we only print that one channel
329 if( channel_to_print != "" && channel_name != channel_to_print) continue;
330
331 TH1* data_hist = GetDataHist(data, channel_name, channel_name+"_tmp");
332 std::cout << std::setw(_label_print_width) << channel_name + " (data)";
333
334 // Print the Histogram
336 delete data_hist;
337 }
338 }
339
340
342 // Loop over all channels and print model
343 // (including all samples) and compare
344 // it to the supplied dataset
345
346 for( unsigned int i = 0; i < fChannelNameVec.size(); ++i) {
347 std::string channel = fChannelNameVec.at(i);
348 SetPrintWidths(channel);
349 PrintState(channel);
350 PrintDataSet(data, channel);
351 }
352
353 std::cout << std::endl;
354 }
355
356
357 void HistFactoryNavigation::PrintParameters(bool IncludeConstantParams) {
358
359 // Get the list of parameters
361
362 std::cout << std::endl;
363
364 // Create the title row
365 std::cout << std::setw(30) << "Parameter";
366 std::cout << std::setw(15) << "Value"
367 << std::setw(15) << "Error Low"
368 << std::setw(15) << "Error High"
369 << std::endl;
370
371 // Loop over the parameters and print their values, etc
372 TIter paramItr = params->createIterator();
373 RooRealVar* param = NULL;
374 while( (param=(RooRealVar*)paramItr.Next()) ) {
375
376 if( !IncludeConstantParams && param->isConstant() ) continue;
377
378 std::cout << std::setw(30) << param->GetName();
379 std::cout << std::setw(15) << param->getVal();
380 if( !param->isConstant() ) {
381 std::cout << std::setw(15) << param->getErrorLo() << std::setw(15) << param->getErrorHi();
382 }
383 std::cout<< std::endl;
384 }
385
386 std::cout << std::endl;
387 }
388
389 void HistFactoryNavigation::PrintChannelParameters(const std::string& channel,
390 bool IncludeConstantParams) {
391
392 // Get the list of parameters
394
395 // Get the pdf for this channel
396 RooAbsPdf* channel_pdf = GetChannelPdf(channel);
397
398 std::cout << std::endl;
399
400 // Create the title row
401 std::cout << std::setw(30) << "Parameter";
402 std::cout << std::setw(15) << "Value"
403 << std::setw(15) << "Error Low"
404 << std::setw(15) << "Error High"
405 << std::endl;
406
407 // Loop over the parameters and print their values, etc
408 TIter paramItr = params->createIterator();
409 RooRealVar* param = NULL;
410 while( (param=(RooRealVar*)paramItr.Next()) ) {
411
412 if( !IncludeConstantParams && param->isConstant() ) continue;
413
414 if( findChild(param->GetName(), channel_pdf)==NULL ) continue;
415
416 std::cout << std::setw(30) << param->GetName();
417 std::cout << std::setw(15) << param->getVal();
418 if( !param->isConstant() ) {
419 std::cout << std::setw(15) << param->getErrorLo() << std::setw(15) << param->getErrorHi();
420 }
421 std::cout<< std::endl;
422 }
423
424 std::cout << std::endl;
425 }
426
427
428 void HistFactoryNavigation::PrintSampleParameters(const std::string& channel,
429 const std::string& sample,
430 bool IncludeConstantParams) {
431
432 // Get the list of parameters
434
435 // Get the pdf for this channel
436 RooAbsReal* sample_func = SampleFunction(channel, sample);
437
438 std::cout << std::endl;
439
440 // Create the title row
441 std::cout << std::setw(30) << "Parameter";
442 std::cout << std::setw(15) << "Value"
443 << std::setw(15) << "Error Low"
444 << std::setw(15) << "Error High"
445 << std::endl;
446
447 // Loop over the parameters and print their values, etc
448 TIter paramItr = params->createIterator();
449 RooRealVar* param = NULL;
450 while( (param=(RooRealVar*)paramItr.Next()) ) {
451
452 if( !IncludeConstantParams && param->isConstant() ) continue;
453
454 if( findChild(param->GetName(), sample_func)==NULL ) continue;
455
456 std::cout << std::setw(30) << param->GetName();
457 std::cout << std::setw(15) << param->getVal();
458 if( !param->isConstant() ) {
459 std::cout << std::setw(15) << param->getErrorLo() << std::setw(15) << param->getErrorHi();
460 }
461 std::cout<< std::endl;
462 }
463
464 std::cout << std::endl;
465 }
466
467
468
469 double HistFactoryNavigation::GetBinValue(int bin, const std::string& channel) {
470 // Get the total bin height for the ith bin (ROOT indexing convention)
471 // in channel 'channel'
472 // (Could be optimized, it uses an intermediate histogram for now...)
473
474 // Get the histogram, fetch the bin content, and return
475 TH1* channel_hist_tmp = GetChannelHist(channel, (channel+"_tmp").c_str());
476 double val = channel_hist_tmp->GetBinContent(bin);
477 delete channel_hist_tmp;
478 return val;
479 }
480
481
482 double HistFactoryNavigation::GetBinValue(int bin, const std::string& channel, const std::string& sample){
483 // Get the total bin height for the ith bin (ROOT indexing convention)
484 // in channel 'channel'
485 // (This will be slow if you plan on looping over it.
486 // Could be optimized, it uses an intermediate histogram for now...)
487
488 // Get the histogram, fetch the bin content, and return
489 TH1* sample_hist_tmp = GetSampleHist(channel, sample, (channel+"_tmp").c_str());
490 double val = sample_hist_tmp->GetBinContent(bin);
491 delete sample_hist_tmp;
492 return val;
493 }
494
495
496 std::map< std::string, RooAbsReal*> HistFactoryNavigation::GetSampleFunctionMap(const std::string& channel) {
497 // Get a map of strings to function pointers,
498 // which each function corresponds to a sample
499
500 std::map< std::string, std::map< std::string, RooAbsReal*> >::iterator channel_itr;
501 channel_itr = fChannelSampleFunctionMap.find(channel);
502 if( channel_itr==fChannelSampleFunctionMap.end() ){
503 std::cout << "Error: Channel: " << channel << " not found in Navigation" << std::endl;
504 throw hf_exc();
505 }
506
507 return channel_itr->second;
508 }
509
510
511 RooAbsReal* HistFactoryNavigation::SampleFunction(const std::string& channel, const std::string& sample){
512 // Return the function object pointer cooresponding
513 // to a particular sample in a particular channel
514
515 std::map< std::string, std::map< std::string, RooAbsReal*> >::iterator channel_itr;
516 channel_itr = fChannelSampleFunctionMap.find(channel);
517 if( channel_itr==fChannelSampleFunctionMap.end() ){
518 std::cout << "Error: Channel: " << channel << " not found in Navigation" << std::endl;
519 throw hf_exc();
520 }
521
522 std::map< std::string, RooAbsReal*>& SampleMap = channel_itr->second;
523 std::map< std::string, RooAbsReal*>::iterator sample_itr;
524 sample_itr = SampleMap.find(sample);
525 if( sample_itr==SampleMap.end() ){
526 std::cout << "Error: Sample: " << sample << " not found in Navigation" << std::endl;
527 throw hf_exc();
528 }
529
530 return sample_itr->second;
531
532 }
533
534
536 // Get the observables for a particular channel
537
538 std::map< std::string, RooArgSet*>::iterator channel_itr;
539 channel_itr = fChannelObservMap.find(channel);
540 if( channel_itr==fChannelObservMap.end() ){
541 std::cout << "Error: Channel: " << channel << " not found in Navigation" << std::endl;
542 throw hf_exc();
543 }
544
545 return channel_itr->second;
546
547 }
548
549
550 TH1* HistFactoryNavigation::GetSampleHist(const std::string& channel, const std::string& sample,
551 const std::string& hist_name) {
552 // Get a histogram of the expected values for
553 // a particular sample in a particular channel
554 // Give a name, or a default one will be used
555
556 RooArgList observable_list( *GetObservableSet(channel) );
557
558 std::string name = hist_name;
559 if(hist_name=="") name = channel + "_" + sample + "_hist";
560
561 RooAbsReal* sample_function = SampleFunction(channel, sample);
562
563 return MakeHistFromRooFunction( sample_function, observable_list, name );
564
565 }
566
567
568 TH1* HistFactoryNavigation::GetChannelHist(const std::string& channel, const std::string& hist_name) {
569 // Get a histogram of the total expected value
570 // per bin for this channel
571 // Give a name, or a default one will be used
572
573 RooArgList observable_list( *GetObservableSet(channel) );
574
575 std::map< std::string, RooAbsReal*> SampleFunctionMap = GetSampleFunctionMap(channel);
576
577 // Okay, 'loop' once
578 TH1* total_hist = nullptr;
579 std::map< std::string, RooAbsReal*>::iterator itr = SampleFunctionMap.begin();
580 for( ; itr != SampleFunctionMap.end(); ++itr) {
581 std::string sample_name = itr->first;
582 std::string tmp_hist_name = sample_name + "_hist_tmp";
583 RooAbsReal* sample_function = itr->second;
584 TH1* sample_hist = MakeHistFromRooFunction(sample_function, observable_list,
585 tmp_hist_name);
586 total_hist = (TH1*) sample_hist->Clone("TotalHist");
587 delete sample_hist;
588 break;
589 }
590 if (!total_hist)
591 return nullptr;
592
593 total_hist->Reset();
594
595 // Loop over the SampleFunctionMap and add up all the histograms
596 // to get the total histogram for the channel
597 itr = SampleFunctionMap.begin();
598 for( ; itr != SampleFunctionMap.end(); ++itr) {
599 std::string sample_name = itr->first;
600 std::string tmp_hist_name = sample_name + "_hist_tmp";
601 RooAbsReal* sample_function = itr->second;
602 TH1* sample_hist = MakeHistFromRooFunction(sample_function, observable_list,
603 tmp_hist_name);
604 total_hist->Add(sample_hist);
605 delete sample_hist;
606 }
607
608 if(hist_name=="") total_hist->SetName(hist_name.c_str());
609 else total_hist->SetName( (channel + "_hist").c_str() );
610
611 return total_hist;
612
613 }
614
615
616 std::vector< std::string > HistFactoryNavigation::GetChannelSampleList(const std::string& channel) {
617
618 std::vector<std::string> sample_list;
619
620 std::map< std::string, RooAbsReal*> sample_map = fChannelSampleFunctionMap[channel];
621 std::map< std::string, RooAbsReal*>::iterator itr = sample_map.begin();;
622 for( ; itr != sample_map.end(); ++itr) {
623 sample_list.push_back( itr->first );
624 }
625
626 return sample_list;
627
628 }
629
630
632 const std::string& name) {
633
634 THStack* stack = new THStack(name.c_str(), "");
635
636 std::vector< std::string > samples = GetChannelSampleList(channel);
637
638 // Add the histograms
639 for( unsigned int i=0; i < samples.size(); ++i) {
640 std::string sample_name = samples.at(i);
641 TH1* hist = GetSampleHist(channel, sample_name, sample_name+"_tmp");
642 hist->SetLineColor(2+i);
643 hist->SetFillColor(2+i);
644 stack->Add(hist);
645 }
646
647 return stack;
648
649 }
650
651
652 TH1* HistFactoryNavigation::GetDataHist(RooDataSet* data, const std::string& channel,
653 const std::string& name) {
654
655 // TO DO:
656 // MAINTAIN THE ACTUAL RANGE, USING THE OBSERVABLES
657 // MAKE IT WORK FOR MULTI-DIMENSIONAL
658 //
659
660 TList *dataset_list = nullptr;
661
662 // If the dataset covers multiple categories,
663 // Split the dataset based on the categories
664 if(strcmp(fModel->ClassName(),"RooSimultaneous")==0){
665
666 // If so, get a list of the component pdf's:
668 RooCategory* channelCat = (RooCategory*) (&simPdf->indexCat());
669
670 dataset_list = data->split(*channelCat);
671
672 data = dynamic_cast<RooDataSet*>( dataset_list->FindObject(channel.c_str()) );
673
674 }
675
676 RooArgList vars( *GetObservableSet(channel) );
677
678 int dim = vars.getSize();
679
680 TH1* hist = NULL;
681
682 if (!data) {
683 std::cout << "Error: To Create Histogram from RooDataSet" << std::endl;
684 if (dataset_list) {
685 dataset_list->Delete();
686 delete dataset_list;
687 dataset_list = nullptr;
688 }
689 throw hf_exc();
690 } else if( dim==1 ) {
691 RooRealVar* varX = (RooRealVar*) vars.at(0);
692 hist = data->createHistogram( name.c_str(),*varX, RooFit::Binning(varX->getBinning()) );
693 }
694 else if( dim==2 ) {
695 RooRealVar* varX = (RooRealVar*) vars.at(0);
696 RooRealVar* varY = (RooRealVar*) vars.at(1);
697 hist = data->createHistogram( name.c_str(),*varX, RooFit::Binning(varX->getBinning()),
698 RooFit::YVar(*varY, RooFit::Binning(varY->getBinning())) );
699 }
700 else if( dim==3 ) {
701 RooRealVar* varX = (RooRealVar*) vars.at(0);
702 RooRealVar* varY = (RooRealVar*) vars.at(1);
703 RooRealVar* varZ = (RooRealVar*) vars.at(2);
704 hist = data->createHistogram( name.c_str(),*varX, RooFit::Binning(varX->getBinning()),
705 RooFit::YVar(*varY, RooFit::Binning(varY->getBinning())),
706 RooFit::YVar(*varZ, RooFit::Binning(varZ->getBinning())) );
707 }
708 else {
709 std::cout << "Error: To Create Histogram from RooDataSet, Dimension must be 1, 2, or 3" << std::endl;
710 std::cout << "Observables: " << std::endl;
711 vars.Print("V");
712 if (dataset_list) {
713 dataset_list->Delete();
714 delete dataset_list;
715 dataset_list = nullptr;
716 }
717 throw hf_exc();
718 }
719
720 if (dataset_list) {
721 dataset_list->Delete();
722 delete dataset_list;
723 dataset_list = nullptr;
724 }
725
726 return hist;
727
728 }
729
730
731 void HistFactoryNavigation::DrawChannel(const std::string& channel, RooDataSet* data) {
732
733 // Get the stack
734 THStack* stack = GetChannelStack(channel, channel+"_stack_tmp");
735
736 stack->Draw();
737
738 if( data!=NULL ) {
739 TH1* data_hist = GetDataHist(data, channel, channel+"_data_tmp");
740 data_hist->Draw("SAME");
741 }
742
743 }
744
745
746
748
749 // An internal method to recursively get all products,
750 // including if a RooProduct is a Product of RooProducts
751 // etc
752
753 RooArgSet allTerms;
754
755 // Get All Subnodes of this product
756 RooArgSet productComponents = node->components();
757
758 // Loop over the subnodes and add
759 TIterator* itr = productComponents.createIterator();
760 RooAbsArg* arg = NULL;
761 while( (arg=(RooAbsArg*)itr->Next()) ) {
762 std::string ClassName = arg->ClassName();
763 if( ClassName == "RooProduct" ) {
764 RooProduct* prod = dynamic_cast<RooProduct*>(arg);
765 allTerms.add( _GetAllProducts(prod) );
766 }
767 else {
768 allTerms.add(*arg);
769 }
770 }
771 delete itr;
772
773 return allTerms;
774
775 }
776
777
778
779
780 void HistFactoryNavigation::_GetNodes(RooAbsPdf* modelPdf, const RooArgSet* observables) {
781
782 // Get the pdf from the ModelConfig
783 //RooAbsPdf* modelPdf = mc->GetPdf();
784 //RooArgSet* observables = mc->GetObservables();
785
786 // Create vectors to hold the channel pdf's
787 // as well as the set of observables for each channel
788 //std::map< std::string, RooAbsPdf* > channelPdfMap;
789 //std::map< std::string, RooArgSet* > channelObservMap;
790
791 // Check if it is a simultaneous pdf or not
792 // (if it's an individual channel, it won't be, if it's
793 // combined, it's simultaneous)
794 // Fill the channel vectors based on the structure
795 // (Obviously, if it's not simultaneous, there will be
796 // only one entry in the vector for the single channel)
797 if(strcmp(modelPdf->ClassName(),"RooSimultaneous")==0){
798
799 // If so, get a list of the component pdf's:
800 RooSimultaneous* simPdf = (RooSimultaneous*) modelPdf;
801 RooCategory* channelCat = (RooCategory*) (&simPdf->indexCat());
802
803 // Iterate over the categories and get the
804 // pdf and observables for each category
805 for (const auto& nameIdx : *channelCat) {
806 const std::string& ChannelName = nameIdx.first;
807 fChannelNameVec.push_back( ChannelName );
808 RooAbsPdf* pdftmp = simPdf->getPdf(ChannelName.c_str()) ;
809 RooArgSet* obstmp = pdftmp->getObservables(*observables) ;
810 fChannelPdfMap[ChannelName] = pdftmp;
811 fChannelObservMap[ChannelName] = obstmp;
812 }
813
814 } else {
815 RooArgSet* obstmp = modelPdf->getObservables(*observables) ;
816 // The channel name is model_CHANNEL
817 std::string ChannelName = modelPdf->GetName();
818 ChannelName = ChannelName.replace(0, 6, "");
819 fChannelNameVec.push_back(ChannelName);
820 fChannelPdfMap[ChannelName] = modelPdf;
821 fChannelObservMap[ChannelName] = obstmp;
822
823 }
824
825 // Okay, now we have maps of the pdfs
826 // and the observable list per channel
827 // We then loop over the channel pdfs:
828 // and find their RooRealSumPdfs
829 // std::map< std::string, RooRealSumPdf* > channelSumNodeMap;
830
831 for( unsigned int i = 0; i < fChannelNameVec.size(); ++i ) {
832
833 std::string ChannelName = fChannelNameVec.at(i);
834 RooAbsPdf* pdf = fChannelPdfMap[ChannelName];
835 //std::string Name = fChannelNameMap[ChannelName];
836
837 // Loop over the pdf's components and find
838 // the (one) that is a RooRealSumPdf
839 // Based on the mode, we assume that node is
840 // the "unconstrained" pdf node for that channel
841 RooArgSet* components = pdf->getComponents();
842 TIter argItr = components->createIterator();
843 RooAbsArg* arg = NULL;
844 while( (arg=(RooAbsArg*)argItr.Next()) ) {
845 std::string ClassName = arg->ClassName();
846 if( ClassName == "RooRealSumPdf" ) {
847 fChannelSumNodeMap[ChannelName] = (RooRealSumPdf*) arg;
848 break;
849 }
850 }
851 }
852
853 // Okay, now we have all necessary
854 // nodes filled for each channel.
855 for( unsigned int i = 0; i < fChannelNameVec.size(); ++i ) {
856
857 std::string ChannelName = fChannelNameVec.at(i);
858 RooRealSumPdf* sumPdf = dynamic_cast<RooRealSumPdf*>(fChannelSumNodeMap[ChannelName]);
859
860 // We now take the RooRealSumPdf and loop over
861 // its component functions. The RooRealSumPdf turns
862 // a list of functions (expected events or bin heights
863 // per sample) and turns it into a pdf.
864 // Therefore, we loop over it to find the expected
865 // height for the various samples
866
867 // First, create a map to store the function nodes
868 // for each sample in this channel
869 std::map< std::string, RooAbsReal*> sampleFunctionMap;
870
871 // Loop over the sample nodes in this
872 // channel's RooRealSumPdf
873 RooArgList nodes = sumPdf->funcList();
874 TIter sampleItr = nodes.createIterator();
875 RooAbsArg* sample;
876 while( (sample=(RooAbsArg*)sampleItr.Next()) ) {
877
878 // Cast this node as a function
879 RooAbsReal* func = (RooAbsReal*) sample;
880
881 // Do a bit of work to get the name of each sample
882 std::string SampleName = sample->GetName();
883 if( SampleName.find("L_x_") != std::string::npos ) {
884 size_t index = SampleName.find("L_x_");
885 SampleName.replace( index, 4, "" );
886 }
887 if( SampleName.find(ChannelName.c_str()) != std::string::npos ) {
888 size_t index = SampleName.find(ChannelName.c_str());
889 SampleName = SampleName.substr(0, index-1);
890 }
891
892 // And simply save this node into our map
893 sampleFunctionMap[SampleName] = func;
894
895 }
896
897 fChannelSampleFunctionMap[ChannelName] = sampleFunctionMap;
898
899 // Okay, now we have a list of histograms
900 // representing the samples for this channel.
901
902 }
903
904 }
905
906
907 RooAbsArg* HistFactoryNavigation::findChild(const std::string& name, RooAbsReal* parent) const {
908
909 RooAbsArg* term=NULL;
910
911 // Check if it is a "component",
912 // ie a sub node:
913 RooArgSet* components = parent->getComponents();
914 TIterator* argItr = components->createIterator();
915 RooAbsArg* arg = NULL;
916 while( (arg=(RooAbsArg*)argItr->Next()) ) {
917 std::string ArgName = arg->GetName();
918 if( ArgName == name ) {
919 term = arg; //dynamic_cast<RooAbsReal*>(arg);
920 break;
921 }
922 }
923 delete components;
924 delete argItr;
925
926 if( term != NULL ) return term;
927
928 // If that failed,
929 // Check if it's a Parameter
930 // (ie a RooRealVar)
931 RooArgSet* args = new RooArgSet();
932 RooArgSet* paramSet = parent->getParameters(args);
933 TIterator* paramItr = paramSet->createIterator();
934 RooAbsArg* param = NULL;
935 while( (param=(RooAbsArg*)paramItr->Next()) ) {
936 std::string ParamName = param->GetName();
937 if( ParamName == name ) {
938 term = param; //dynamic_cast<RooAbsReal*>(arg);
939 break;
940 }
941 }
942 delete args;
943 delete paramSet;
944 delete paramItr;
945
946 /* Not sure if we want to be silent
947 But since we're returning a pointer which can be NULL,
948 I think it's the user's job to do checks on it.
949 A dereference will always cause a crash, so it won't
950 be silent for long...
951 if( term==NULL ) {
952 std::cout << "Error: Failed to find node: " << name
953 << " as a child of: " << parent->GetName()
954 << std::endl;
955 }
956 */
957
958 return term;
959
960 }
961
962
964
965 std::string ConstraintTermName = parameter + "Constraint";
966
967 // First, as a sanity check, let's see if the parameter
968 // itself actually exists and if the model depends on it:
969 RooRealVar* param = dynamic_cast<RooRealVar*>(findChild(parameter, fModel));
970 if( param==NULL ) {
971 std::cout << "Error: Couldn't Find parameter: " << parameter << " in model."
972 << std::endl;
973 return NULL;
974 }
975
976 // The "gamma"'s use a different constraint term name
977 if( parameter.find("gamma_stat_") != std::string::npos ) {
978 ConstraintTermName = parameter + "_constraint";
979 }
980
981 // Now, get the constraint itself
982 RooAbsReal* term = dynamic_cast<RooAbsReal*>(findChild(ConstraintTermName, fModel));
983
984 if( term==NULL ) {
985 std::cout << "Error: Couldn't Find constraint term for parameter: " << parameter
986 << " (Looked for '" << ConstraintTermName << "')" << std::endl;
987 return NULL;
988 }
989
990 return term;
991
992 }
993
994
995 double HistFactoryNavigation::GetConstraintUncertainty(const std::string& parameter) {
996
997 RooAbsReal* constraintTerm = GetConstraintTerm(parameter);
998 if( constraintTerm==NULL ) {
999 std::cout << "Error: Cannot get uncertainty because parameter: " << parameter
1000 << " has no constraint term" << std::endl;
1001 throw hf_exc();
1002 }
1003
1004 // Get the type of constraint
1005 std::string ConstraintType = constraintTerm->IsA()->GetName();
1006
1007 // Find its value
1008 double sigma = 0.0;
1009
1010 if( ConstraintType == "" ) {
1011 std::cout << "Error: Constraint type is an empty string."
1012 << " This simply should not be." << std::endl;
1013 throw hf_exc();
1014 }
1015 else if( ConstraintType == "RooGaussian" ){
1016
1017 // Gaussian errors are the 'sigma' in the constraint term
1018
1019 // Get the name of the 'sigma' for the gaussian
1020 // (I don't know of a way of doing RooGaussian::GetSigma() )
1021 // For alpha's, the sigma points to a global RooConstVar
1022 // with the name "1"
1023 // For gamma_stat_*, the sigma is named *_sigma
1024 std::string sigmaName = "";
1025 if( parameter.find("alpha_")!=std::string::npos ) {
1026 sigmaName = "1";;
1027 }
1028 else if( parameter.find("gamma_stat_")!=std::string::npos ) {
1029 sigmaName = parameter + "_sigma";
1030 }
1031
1032 // Get the sigma and its value
1033 RooAbsReal* sigmaVar = dynamic_cast<RooAbsReal*>(constraintTerm->findServer(sigmaName.c_str()));
1034 if( sigmaVar==NULL ) {
1035 std::cout << "Error: Failed to find the 'sigma' node: " << sigmaName
1036 << " in the RooGaussian: " << constraintTerm->GetName() << std::endl;
1037 throw hf_exc();
1038 }
1039 // If we find the uncertainty:
1040 sigma = sigmaVar->getVal();
1041 }
1042 else if( ConstraintType == "RooPoisson" ){
1043 // Poisson errors are given by inverting: tau = 1 / (sigma*sigma)
1044 std::string tauName = "nom_" + parameter;
1045 RooAbsReal* tauVar = dynamic_cast<RooAbsReal*>( constraintTerm->findServer(tauName.c_str()) );
1046 if( tauVar==NULL ) {
1047 std::cout << "Error: Failed to find the nominal 'tau' node: " << tauName
1048 << " for the RooPoisson: " << constraintTerm->GetName() << std::endl;
1049 throw hf_exc();
1050 }
1051 double tau_val = tauVar->getVal();
1052 sigma = 1.0 / TMath::Sqrt( tau_val );
1053 }
1054 else {
1055 std::cout << "Error: Encountered unknown constraint type for Stat Uncertainties: "
1056 << ConstraintType << std::endl;
1057 throw hf_exc();
1058 }
1059
1060 return sigma;
1061
1062 }
1063
1064 void HistFactoryNavigation::ReplaceNode(const std::string& ToReplace, RooAbsArg* ReplaceWith) {
1065
1066 // First, check that the node to replace is actually a node:
1067 RooAbsArg* nodeToReplace = findChild(ToReplace, fModel);
1068 if( nodeToReplace==NULL ) {
1069 std::cout << "Error: Cannot replace node: " << ToReplace
1070 << " because this node wasn't found in: " << fModel->GetName()
1071 << std::endl;
1072 throw hf_exc();
1073 }
1074
1075 // Now that we have the node we want to replace, we have to
1076 // get its parent node
1077
1078 // Do this by looping over the clients and replacing their servers
1079 // (NOTE: This happens for ALL clients across the pdf)
1080 for (auto client : nodeToReplace->clients()) {
1081
1082 // Check if this client is a member of our pdf
1083 // (We probably don't want to mess with clients
1084 // if they aren't...)
1085 if( findChild(client->GetName(), fModel) == nullptr) continue;
1086
1087 // Now, do the replacement:
1088 bool valueProp=false;
1089 bool shapeProp=false;
1090 client->replaceServer( *nodeToReplace, *ReplaceWith, valueProp, shapeProp );
1091 std::cout << "Replaced: " << ToReplace << " with: " << ReplaceWith->GetName()
1092 << " in node: " << client->GetName() << std::endl;
1093
1094 }
1095
1096 return;
1097
1098 }
1099
1100
1101 void HistFactoryNavigation::PrintSampleComponents(const std::string& channel,
1102 const std::string& sample) {
1103
1104 // Get the Sample Node
1105 RooAbsReal* sampleNode = SampleFunction(channel, sample);
1106
1107 // Get the observables for this channel
1108 RooArgList observable_list( *GetObservableSet(channel) );
1109
1110 // Make the total histogram for this sample
1111 std::string total_Name = sampleNode->GetName();
1112 TH1* total_hist= MakeHistFromRooFunction( sampleNode, observable_list, total_Name + "_tmp");
1113 unsigned int num_bins = total_hist->GetNbinsX()*total_hist->GetNbinsY()*total_hist->GetNbinsZ();
1114
1115 RooArgSet components;
1116
1117 // Let's see what it is...
1118 int label_print_width = 30;
1119 int bin_print_width = 12;
1120 if( strcmp(sampleNode->ClassName(),"RooProduct")==0){
1121 RooProduct* prod = dynamic_cast<RooProduct*>(sampleNode);
1122 components.add( _GetAllProducts(prod) );
1123 }
1124 else {
1125 components.add(*sampleNode);
1126 }
1127
1128 /////// NODE SIZE
1129 {
1130 TIter itr = components.createIterator();
1131 RooAbsArg* arg = NULL;
1132 while( (arg=(RooAbsArg*)itr.Next()) ) {
1133 RooAbsReal* component = dynamic_cast<RooAbsReal*>(arg);
1134 std::string NodeName = component->GetName();
1135 label_print_width = TMath::Max(label_print_width, (int)NodeName.size()+2);
1136 }
1137 }
1138
1139 // Now, loop over the components and print them out:
1140 std::cout << std::endl;
1141 std::cout << "Channel: " << channel << " Sample: " << sample << std::endl;
1142 std::cout << std::setw(label_print_width) << "Factor";
1143
1144 for(unsigned int i=0; i < num_bins; ++i) {
1145 if( _minBinToPrint != -1 && (int)i < _minBinToPrint) continue;
1146 if( _maxBinToPrint != -1 && (int)i > _maxBinToPrint) break;
1147 std::stringstream sstr;
1148 sstr << "Bin" << i;
1149 std::cout << std::setw(bin_print_width) << sstr.str();
1150 }
1151 std::cout << std::endl;
1152
1153 TIter itr = components.createIterator();
1154 RooAbsArg* arg = NULL;
1155 while( (arg=(RooAbsArg*)itr.Next()) ) {
1156 RooAbsReal* component = dynamic_cast<RooAbsReal*>(arg);
1157 std::string NodeName = component->GetName();
1158
1159 // Make a histogram for this node
1160 // Do some horrible things to prevent some really
1161 // annoying messages from being printed
1164 TH1* hist=NULL;
1165 try {
1166 hist = MakeHistFromRooFunction( component, observable_list, NodeName+"_tmp");
1167 } catch(...) {
1169 throw;
1170 }
1172
1173 // Print the hist
1174 std::cout << std::setw(label_print_width) << NodeName;
1175
1176 // Print the Histogram
1177 PrintMultiDimHist(hist, bin_print_width);
1178 delete hist;
1179 }
1180 /////
1181 std::string line_break;
1182 int high_bin = _maxBinToPrint==-1 ? num_bins : TMath::Min(_maxBinToPrint, (int)num_bins);
1183 int low_bin = _minBinToPrint==-1 ? 1 : _minBinToPrint;
1184 int break_length = (high_bin - low_bin + 1) * bin_print_width;
1185 break_length += label_print_width;
1186 for(int i = 0; i < break_length; ++i) {
1187 line_break += "=";
1188 }
1189 std::cout << line_break << std::endl;
1190
1191 std::cout << std::setw(label_print_width) << "TOTAL:";
1192 PrintMultiDimHist(total_hist, bin_print_width);
1193 /*
1194 for(unsigned int i = 0; i < num_bins; ++i) {
1195 if( _minBinToPrint != -1 && (int)i < _minBinToPrint) continue;
1196 if( _maxBinToPrint != -1 && (int)i > _maxBinToPrint) break;
1197 std::cout << std::setw(bin_print_width) << total_hist->GetBinContent(i+1);
1198 }
1199 std::cout << std::endl << std::endl;
1200 */
1201 delete total_hist;
1202
1203 return;
1204
1205 }
1206
1207
1209 std::string name ) {
1210
1211 // Turn a RooAbsReal* into a TH1* based
1212 // on a template histogram.
1213 // The 'vars' arg list defines the x (and y and z variables)
1214 // Loop over the bins of the Template,
1215 // find the bin centers,
1216 // Scan the input Var over those bin centers,
1217 // and use the value of the function
1218 // to make the new histogram
1219
1220 // Make the new histogram
1221 // Cone and empty the template
1222 // TH1* hist = (TH1*) histTemplate.Clone( name.c_str() );
1223
1224 int dim = vars.getSize();
1225
1226 TH1* hist=NULL;
1227
1228 if( dim==1 ) {
1229 RooRealVar* varX = (RooRealVar*) vars.at(0);
1230 hist = func->createHistogram( name.c_str(),*varX, RooFit::Binning(varX->getBinning()), RooFit::Scaling(false) );
1231 }
1232 else if( dim==2 ) {
1233 RooRealVar* varX = (RooRealVar*) vars.at(0);
1234 RooRealVar* varY = (RooRealVar*) vars.at(1);
1235 hist = func->createHistogram( name.c_str(),*varX, RooFit::Binning(varX->getBinning()), RooFit::Scaling(false),
1236 RooFit::YVar(*varY, RooFit::Binning(varY->getBinning())) );
1237 }
1238 else if( dim==3 ) {
1239 RooRealVar* varX = (RooRealVar*) vars.at(0);
1240 RooRealVar* varY = (RooRealVar*) vars.at(1);
1241 RooRealVar* varZ = (RooRealVar*) vars.at(2);
1242 hist = func->createHistogram( name.c_str(),*varX, RooFit::Binning(varX->getBinning()), RooFit::Scaling(false),
1243 RooFit::YVar(*varY, RooFit::Binning(varY->getBinning())),
1244 RooFit::YVar(*varZ, RooFit::Binning(varZ->getBinning())) );
1245 }
1246 else {
1247 std::cout << "Error: To Create Histogram from RooAbsReal function, Dimension must be 1, 2, or 3" << std::endl;
1248 throw hf_exc();
1249 }
1250
1251 return hist;
1252 }
1253
1254 // A simple wrapper to use a ModelConfig
1256 RooAbsPdf* modelPdf = mc->GetPdf();
1257 const RooArgSet* observables = mc->GetObservables();
1258 _GetNodes(modelPdf, observables);
1259 }
1260
1261
1262 void HistFactoryNavigation::SetConstant(const std::string& regExpr, bool constant) {
1263
1264 // Regex FTW
1265
1266 TString RegexTString(regExpr);
1267 TRegexp theRegExpr(RegexTString);
1268
1269 // Now, loop over all variables and
1270 // set the constant as
1271
1272 // Get the list of parameters
1274
1275 std::cout << std::endl;
1276
1277 // Create the title row
1278 std::cout << std::setw(30) << "Parameter";
1279 std::cout << std::setw(15) << "Value"
1280 << std::setw(15) << "Error Low"
1281 << std::setw(15) << "Error High"
1282 << std::endl;
1283
1284 // Loop over the parameters and print their values, etc
1285 TIter paramItr = params->createIterator();
1286 RooRealVar* param = NULL;
1287 while( (param=(RooRealVar*)paramItr.Next()) ) {
1288
1289 std::string ParamName = param->GetName();
1290 TString ParamNameTString(ParamName);
1291
1292 // Use the Regex to skip all parameters that don't match
1293 //if( theRegExpr.Index(ParamNameTString, ParamName.size()) == -1 ) continue;
1294 Ssiz_t dummy;
1295 if( theRegExpr.Index(ParamNameTString, &dummy) == -1 ) continue;
1296
1297 param->setConstant( constant );
1298 std::cout << "Setting param: " << ParamName << " constant"
1299 << " (matches regex: " << regExpr << ")" << std::endl;
1300 }
1301 }
1302
1303 RooRealVar* HistFactoryNavigation::var(const std::string& varName) const {
1304
1305 RooAbsArg* arg = findChild(varName, fModel);
1306 if( !arg ) return NULL;
1307
1308 RooRealVar* var_obj = dynamic_cast<RooRealVar*>(arg);
1309 return var_obj;
1310
1311 }
1312
1313 /*
1314 void HistFactoryNavigation::AddChannel(const std::string& channel, RooAbsPdf* pdf,
1315 RooDataSet* data=NULL) {
1316
1317 }
1318 */
1319
1320 } // namespace HistFactory
1321} // namespace RooStats
1322
1323
1324
1325
#define ClassImp(name)
Definition Rtypes.h:364
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:69
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Given a set of possible observables, return the observables that this PDF depends on.
Definition RooAbsArg.h:309
const RefCountList_t & clients() const
List of all clients of this object.
Definition RooAbsArg.h:182
RooArgSet * getComponents() const
Create a RooArgSet with all components (branch nodes) of the expression tree headed by this object.
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...
Bool_t isConstant() const
Check if the "Constant" attribute is set.
Definition RooAbsArg.h:377
RooAbsArg * findServer(const char *name) const
Return server of this with name name. Returns nullptr if not found.
Definition RooAbsArg.h:200
Int_t getSize() const
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
const char * GetName() const
Returns name of object.
TIterator * createIterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
RooAbsArg * find(const char *name) const
Find object with given name in list.
virtual TList * split(const RooAbsCategory &splitCat, Bool_t createEmptyDataSets=kFALSE) const
Split dataset into subsets based on states of given splitCat in this dataset.
void setConstant(Bool_t value=kTRUE)
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:64
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...
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:94
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:35
RooCategory is an object to represent discrete states.
Definition RooCategory.h:27
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:36
TH2F * createHistogram(const RooAbsRealLValue &var1, const RooAbsRealLValue &var2, const char *cuts="", const char *name="hist") const
Create a TH2F histogram of the distribution of the specified variable using this dataset.
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:47
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:39
Double_t getErrorHi() const
Definition RooRealVar.h:72
Double_t getErrorLo() const
Definition RooRealVar.h:71
const RooAbsBinning & getBinning(const char *name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const
Return binning definition with name.
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 DrawChannel(const std::string &channel, RooDataSet *data=NULL)
Draw a stack of the channel, and include data if the pointer is supplied.
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)
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 NULL if not existing)
RooAbsPdf * GetPdf() const
get model PDF (return NULL if pdf has not been specified or does not exist)
The RooWorkspace is a persistable container for RooFit projects.
TObject * obj(const char *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
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition TFile.h:54
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
virtual Int_t GetNbinsY() const
Definition TH1.h:297
virtual Int_t GetNbinsZ() const
Definition TH1.h:298
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
Definition TH1.cxx:7058
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
Definition TH1.cxx:2741
virtual Int_t GetNbinsX() const
Definition TH1.h:296
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:823
Bool_t IsBinUnderflow(Int_t bin, Int_t axis=0) const
Return true if the bin is underflow.
Definition TH1.cxx:5147
Bool_t IsBinOverflow(Int_t bin, Int_t axis=0) const
Return true if the bin is overflow.
Definition TH1.cxx:5115
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition TH1.cxx:3074
virtual void SetName(const char *name)
Change the name of this histogram.
Definition TH1.cxx:8790
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:4994
The Histogram stack class.
Definition THStack.h:38
virtual void Draw(Option_t *chopt="")
Draw this multihist with its current attributes.
Definition THStack.cxx:467
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:381
TObject * Next()
Iterator abstract base class.
Definition TIterator.h:30
virtual TObject * Next()=0
A doubly linked list.
Definition TList.h:38
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition TList.cxx:578
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:470
virtual const char * GetName() const
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 Scaling(Bool_t flag)
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
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)
Definition TMathBase.h:208
Double_t Sqrt(Double_t x)
Definition TMath.h:641
Short_t Min(Short_t a, Short_t b)
Definition TMathBase.h:176
Definition file.py:1