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