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