BCMTFAnalysisFacility.cxx
1 /*
2  * Copyright (C) 2007-2018, the BAT core developer team
3  * All rights reserved.
4  *
5  * For the licensing terms see doc/COPYING.
6  * For documentation see http://mpp.mpg.de/bat
7  */
8 
9 // ---------------------------------------------------------
10 
11 #include "BCMTFAnalysisFacility.h"
12 
13 #include "BCMTF.h"
14 #include "BCMTFChannel.h"
15 #include "BCMTFComparisonTool.h"
16 #include "BCMTFSystematic.h"
17 #include "BCMTFTemplate.h"
18 
19 #include "../../BAT/BCLog.h"
20 #include "../../BAT/BCH1D.h"
21 #include "../../BAT/BCParameter.h"
22 
23 #include <TCanvas.h>
24 #include <TFile.h>
25 #include <TH1D.h>
26 #include <TRandom3.h>
27 #include <TROOT.h>
28 #include <TTree.h>
29 
30 #include <sys/stat.h>
31 #include <unistd.h>
32 #include <iostream>
33 #include <stdexcept>
34 
35 namespace
36 {
37 void cd(const std::string& dir)
38 {
39  // shell conventions: 0=success
40  if (chdir(dir.data()))
41  throw std::runtime_error(std::string("Cannot change directory to ") + dir);
42 }
43 }
44 
45 // ---------------------------------------------------------
47  : fRandom(new TRandom3(0))
48  , fFlagMarginalize(false)
49  , fLogLevel(BCLog::nothing)
50 {
51  fMTF = mtf;
52  BCLog::OutDetail("Prepared Analysis Facility for MTF model \'" + mtf->GetName() + "\'");
53 }
54 
55 // ---------------------------------------------------------
57 {
58 }
59 
60 // ---------------------------------------------------------
61 std::vector<TH1D> BCMTFAnalysisFacility::BuildEnsemble(const std::vector<double>& parameters, const std::string& options)
62 {
63  // option flags
64  bool flag_data = false;
65 
66  // check content of options string
67  if (options.find("data") < options.size()) {
68  flag_data = true;
69  }
70 
71  // get number of channels
72  int nchannels = fMTF->GetNChannels();
73 
74  // create vector of histograms
75  std::vector<TH1D> histograms;
76 
77  // loop over channels
78  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
79 
80  // get channel
81  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
82 
83  // create new histogram
84  TH1D hist( *(channel->GetData()->GetHistogram()) );
85 
86  // get number of bins
87  int nbins = hist.GetNbinsX();
88 
89  // loop over all bins
90  for (int ibin = 1; ibin <= nbins; ++ibin) {
91  if (!flag_data) {
92  double expectation = fMTF->Expectation(ichannel, ibin, parameters);
93  double observation = fRandom->Poisson(expectation);
94 
95  hist.SetBinContent(ibin, observation);
96  }
97  }
98 
99  // add histogram
100  histograms.push_back(hist);
101  }
102 
103  // return histograms
104  return histograms;
105 }
106 
107 // ---------------------------------------------------------
108 TTree* BCMTFAnalysisFacility::BuildEnsembles(TTree* tree, int nensembles, const std::string& options)
109 {
110  // get number of channels
111  int nchannels = fMTF->GetNChannels();
112 
113  BCLog::OutDetail(Form("MTF Building %d ensembles for %d channels.", nensembles, nchannels));
114 
115  // get number of parameters
116  int nparameters = fMTF->GetNParameters();
117 
118  // create tree variables for input tree
119  std::vector<double> parameters(nparameters);
120 
121  // set branch addresses
122  for (int i = 0; i < nparameters; ++i) {
123  tree->SetBranchAddress(Form("Parameter%i", i), &(parameters[i]));
124  }
125 
126  // create tree
127  TTree* tree_out = new TTree("ensembles", "ensembles");
128 
129  // create matrix of number of bins
130  std::vector< std::vector<double> > nbins_matrix;
131 
132  // prepare the tree variables
133  // loop over channels
134  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
135  // get channel
136  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
137 
138  // get number of bins
139  int nbins = channel->GetData()->GetHistogram()->GetNbinsX();
140 
141  // create new matrix row
142  std::vector<double> nbins_column(nbins);
143 
144  // add matrix
145  nbins_matrix.push_back(nbins_column);
146  }
147 
148  std::vector<double> in_parameters(nparameters);
149 
150  // create branches
151  // loop over channels
152  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
153  // get channel
154  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
155 
156  // get number of bins
157  int nbins = channel->GetData()->GetHistogram()->GetNbinsX();
158 
159  // loop over bins
160  for (int ibin = 1; ibin <= nbins; ++ibin) {
161  // create branches
162  tree_out->Branch(Form("channel_%i_bin_%i", ichannel, ibin),
163  &(nbins_matrix[ichannel])[ibin - 1], "n/D");
164  }
165  }
166 
167  for (int i = 0; i < nparameters; ++i) {
168  tree_out->Branch(Form("parameter_%i", i), &in_parameters[i], Form("parameter_%i/D", i));
169  }
170 
171  // create vector of histograms
172  std::vector<TH1D> histograms;
173 
174  // loop over ensembles
175  for (int iensemble = 0; iensemble < nensembles; ++iensemble) {
176  // get random event from tree
177  int index = (int) fRandom->Uniform(tree->GetEntries());
178  tree->GetEntry(index);
179 
180  // create ensembles
181  histograms = BuildEnsemble(parameters, options);
182 
183  // copy information from histograms into tree variables
184  // loop over channels
185  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
186  // get channel
187  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
188 
189  // get number of bins
190  int nbins = channel->GetData()->GetHistogram()->GetNbinsX();
191 
192  // loop over bins
193  for (int ibin = 1; ibin <= nbins; ++ibin) {
194  // fill tree variable
195  (nbins_matrix[ichannel])[ibin - 1] = histograms.at(ichannel).GetBinContent(ibin);
196  }
197  }
198 
199  // copy parameter information
200  for (int i = 0; i < nparameters; ++i) {
201  in_parameters[i] = parameters.at(i);
202  }
203 
204  // fill tree
205  tree_out->Fill();
206  }
207 
208  // return tree
209  return tree_out;
210 }
211 
212 // ---------------------------------------------------------
213 TTree* BCMTFAnalysisFacility::BuildEnsembles(const std::vector<double>& parameters, int nensembles, const std::string& options)
214 {
215  // get number of channels
216  int nchannels = fMTF->GetNChannels();
217 
218  BCLog::OutDetail(Form("MTF Building %d ensambles for %d channels.", nensembles, nchannels));
219 
220  // create tree
221  TTree* tree = new TTree("ensembles", "ensembles");
222 
223  // create matrix of number of bins
224  std::vector< std::vector<double> > nbins_matrix;
225 
226  // prepare the tree variables
227  // loop over channels
228  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
229  // get channel
230  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
231 
232  // get number of bins
233  int nbins = channel->GetData()->GetHistogram()->GetNbinsX();
234 
235  // create new matrix row
236  std::vector<double> nbins_column(nbins);
237 
238  // add matrix
239  nbins_matrix.push_back(nbins_column);
240  }
241 
242  // get number of parameters
243  int nparameters = fMTF->GetNParameters();
244 
245  std::vector<double> in_parameters(nparameters);
246 
247  // create branches
248  // loop over channels
249  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
250  // get channel
251  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
252 
253  // get number of bins
254  int nbins = channel->GetData()->GetHistogram()->GetNbinsX();
255 
256  // loop over bins
257  for (int ibin = 1; ibin <= nbins; ++ibin) {
258  // create branches
259  tree->Branch(Form("channel_%i_bin_%i", ichannel, ibin),
260  &(nbins_matrix[ichannel])[ibin - 1], "n/D");
261  }
262  }
263 
264  for (int i = 0; i < nparameters; ++i) {
265  tree->Branch(Form("parameter_%i", i), &in_parameters[i], Form("parameter_%i/D", i));
266  }
267 
268  // create vector of histograms
269  std::vector<TH1D> histograms;
270 
271  // loop over ensembles
272  for (int iensemble = 0; iensemble < nensembles; ++iensemble) {
273  // create ensembles
274  histograms = BuildEnsemble(parameters, options);
275 
276  // copy information from histograms into tree variables
277  // loop over channels
278  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
279  // get channel
280  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
281 
282  // get number of bins
283  int nbins = channel->GetData()->GetHistogram()->GetNbinsX();
284 
285  // loop over bins
286  for (int ibin = 1; ibin <= nbins; ++ibin) {
287  // fill tree variable
288  (nbins_matrix[ichannel])[ibin - 1] = histograms.at(ichannel).GetBinContent(ibin);
289  }
290  }
291 
292  // copy parameter information
293  for (int i = 0; i < nparameters; ++i) {
294  if (parameters.size() > 0)
295  in_parameters[i] = parameters.at(i);
296  else
297  in_parameters[i] = 0;
298  }
299 
300  // fill tree
301  tree->Fill();
302  }
303 
304  // return tree
305  return tree;
306 }
307 
308 // ---------------------------------------------------------
309 TTree* BCMTFAnalysisFacility::PerformEnsembleTest(const std::vector<double>& parameters, int nensembles, const std::string& options)
310 {
311  // create new tree
312  TTree* tree = 0;
313 
314  // create ensembles
315  tree = BuildEnsembles(parameters, nensembles, options);
316 
317  // perform ensemble test
318  return PerformEnsembleTest(tree, nensembles, 0, options);
319 }
320 
321 // ---------------------------------------------------------
322 TTree* BCMTFAnalysisFacility::PerformEnsembleTest(TTree* tree, int nensembles, int start, const std::string& options)
323 {
324  BCLog::OutSummary("Running ensemble test.");
325  if (fFlagMarginalize) {
326  BCLog::OutSummary("Fit for each ensemble is going to be run using MCMC. It can take a while.");
327  }
328 
329  // option flags
330  bool flag_mc = false;
331 
332  // check content of options string
333  if (options.find("MC") < options.size()) {
334  flag_mc = true;
335  }
336 
337  // set log level
338  // It would be better to set the level for the screen and for the file
339  // separately. Perhaps in the future.
342  if (fLogLevel == BCLog::nothing) {
343  BCLog::OutSummary("No log messages for the ensemble fits are going to be printed.");
344  BCLog::SetLogLevel(fLogLevel);
345  } else if (fLogLevel != lls) {
346  BCLog::OutSummary("The log level for the ensemble test is set to '" + BCLog::ToString(fLogLevel) + "'.");
347  BCLog::SetLogLevel(fLogLevel);
348  }
349 
350  // get number of channels
351  int nchannels = fMTF->GetNChannels();
352 
353  // define set of histograms for the original data sets
354  std::vector<TH1D*> histograms_data(nchannels);
355 
356  // create matrix of number of bins
357  std::vector< std::vector<double> > nbins_matrix;
358 
359  // prepare the tree
360  // loop over channels
361  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
362  // get channel
363  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
364 
365  // get number of bins
366  int nbins = channel->GetData()->GetHistogram()->GetNbinsX();
367 
368  // create new matrix row
369  std::vector<double> nbins_column(nbins);
370 
371  // add matrix
372  nbins_matrix.push_back(nbins_column);
373  }
374 
375  // loop over channels
376  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
377  // get channel
378  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
379 
380  // get number of bins
381  int nbins = channel->GetData()->GetHistogram()->GetNbinsX();
382 
383  // loop over bins
384  for (int ibin = 1; ibin <= nbins; ++ibin) {
385  // create branches
386  tree->SetBranchAddress(Form("channel_%i_bin_%i", ichannel, ibin),
387  &(nbins_matrix[ichannel])[ibin - 1]);
388  }
389  }
390 
391  // get number of parameters
392  int nparameters = fMTF->GetNParameters();
393 
394  // define tree variables
395  std::vector<double> out_parameters(nparameters);
396 
397  for (int i = 0; i < nparameters; ++i) {
398  tree->SetBranchAddress(Form("parameter_%i", i), &out_parameters[i]);
399  }
400 
401  // copy the original data sets
402  // loop over channels
403  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
404  // get channel
405  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
406 
407  // set data pointer
408  histograms_data[ichannel] = channel->GetData()->GetHistogram();
409  }
410 
411  // create output tree
412  TTree* tree_out = new TTree("ensemble_test", "ensemble test");
413 
414  // define tree variables
415  std::vector<double> out_mode_global(nparameters);
416  std::vector<double> out_std_global(nparameters);
417  std::vector<double> out_mode_marginalized(nparameters);
418  std::vector<double> out_mean_marginalized(nparameters);
419  std::vector<double> out_median_marginalized(nparameters);
420  std::vector<double> out_5quantile_marginalized(nparameters);
421  std::vector<double> out_10quantile_marginalized(nparameters);
422  std::vector<double> out_16quantile_marginalized(nparameters);
423  std::vector<double> out_84quantile_marginalized(nparameters);
424  std::vector<double> out_90quantile_marginalized(nparameters);
425  std::vector<double> out_95quantile_marginalized(nparameters);
426  std::vector<double> out_std_marginalized(nparameters);
427  std::vector<double> out_chi2_generated(nchannels);
428  std::vector<double> out_chi2_mode(nchannels);
429  std::vector<double> out_cash_generated(nchannels);
430  std::vector<double> out_cash_mode(nchannels);
431  std::vector<int> out_nevents(nchannels);
432  double out_chi2_generated_total;
433  double out_chi2_mode_total;
434  double out_cash_generated_total;
435  double out_cash_mode_total;
436  int out_nevents_total;
437 
438  // create branches
439  for (int i = 0; i < nparameters; ++i) {
440  tree_out->Branch(Form("parameter_%i", i), &out_parameters[i], Form("parameter %i/D", i));
441  tree_out->Branch(Form("mode_global_%i", i), &out_mode_global[i], Form("global mode of par. %i/D", i));
442  tree_out->Branch(Form("std_global_%i", i), &out_std_global[i], Form("global std of par. %i/D", i));
443  if (fFlagMarginalize) {
444  tree_out->Branch(Form("mode_marginalized_%i", i), &out_mode_marginalized[i], Form("marginalized mode of par. %i/D", i));
445  tree_out->Branch(Form("mean_marginalized_%i", i), &out_mean_marginalized[i], Form("marginalized mean of par. %i/D", i));
446  tree_out->Branch(Form("median_marginalized_%i", i), &out_median_marginalized[i], Form("median of par. %i/D", i));
447  tree_out->Branch(Form("5quantile_marginalized_%i", i), &out_5quantile_marginalized[i], Form("marginalized 5 per cent quantile of par. %i/D", i));
448  tree_out->Branch(Form("10quantile_marginalized_%i", i), &out_10quantile_marginalized[i], Form("marginalized 10 per cent quantile of par. %i/D", i));
449  tree_out->Branch(Form("16quantile_marginalized_%i", i), &out_16quantile_marginalized[i], Form("marginalized 16 per cent quantile of par. %i/D", i));
450  tree_out->Branch(Form("84quantile_marginalized_%i", i), &out_84quantile_marginalized[i], Form("marginalized 84 per cent quantile of par. %i/D", i));
451  tree_out->Branch(Form("90quantile_marginalized_%i", i), &out_90quantile_marginalized[i], Form("marginalized 90 per cent quantile of par. %i/D", i));
452  tree_out->Branch(Form("95quantile_marginalized_%i", i), &out_95quantile_marginalized[i], Form("marginalized 95 per cent quantile of par. %i/D", i));
453  tree_out->Branch(Form("std_marginalized_%i", i), &out_std_marginalized[i], Form("marginalized std of par. %i/D", i));
454  }
455  }
456  for (int i = 0; i < nchannels; ++i) {
457  tree_out->Branch(Form("chi2_generated_%i", i), &out_chi2_generated[i], Form("chi2 (generated par.) in channel %i/D", i));
458  tree_out->Branch(Form("chi2_mode_%i", i), &out_chi2_mode[i], Form("chi2 (mode of par.) in channel %i/D", i));
459  tree_out->Branch(Form("cash_generated_%i", i), &out_cash_generated[i], Form("cash statistic (generated par.) in channel %i/D", i));
460  tree_out->Branch(Form("cash_mode_%i", i), &out_cash_mode[i], Form("cash statistic (mode of par.) in channel %i/D", i));
461  tree_out->Branch(Form("nevents_%i", i), &out_nevents[i], Form("nevents in channel %i/I", i));
462  }
463  tree_out->Branch("chi2_generated_total", &out_chi2_generated_total, "chi2 (generated par.) in all channels/D");
464  tree_out->Branch("chi2_mode_total", &out_chi2_mode_total, "chi2 (mode of par.) in all channels/D");
465  tree_out->Branch("cash_generated_total", &out_cash_generated_total, "cash statistic (generated par.) in all channels/D");
466  tree_out->Branch("cash_mode_total", &out_cash_mode_total, "cash statistic (mode of par.) in all channels/D");
467  tree_out->Branch("nevents_total", &out_nevents_total, "total number of events/I");
468 
469  // define temporary vector of histogram for fluctated templates
470  std::vector<TH1D*> histlist(0);
471 
472  // loop over ensembles
473  for (int iensemble = 0; iensemble < nensembles; ++iensemble) {
474  // print status
475  if ((iensemble + 1) % 100 == 0 && iensemble > 0) {
476  BCLog::SetLogLevel(lls, llf);
477  int frac = int (double(iensemble + 1) / double(nensembles) * 100.);
478  BCLog::OutDetail(Form("Fraction of ensembles analyzed: %i%%", frac));
479  BCLog::SetLogLevel(fLogLevel);
480  }
481 
482  // get next (commented out: random) event from tree
483  // int index = (int) fRandom->Uniform(tree->GetEntries());
484  int index = iensemble + start;
485  tree->GetEntry(index);
486 
487  // define histograms
488  std::vector<TH1D> histograms;
489 
490  // transform matrix into histograms
491  histograms = MatrixToHistograms(nbins_matrix);
492 
493  // loop over channels and set data
494  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
495  // get channel
496  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
497 
498  // overwrite data
499  if (iensemble == 0)
500  channel->GetData()->SetHistogram(0);
501 
502  // set data histogram
503  fMTF->SetData(channel->GetName(), histograms.at(ichannel));
504  }
505 
506  // fluctuate templates if option "MC" is chosen
507  if (flag_mc) {
508  // get number of templates
509  unsigned int ntemplates = fMTF->GetNProcesses();
510 
511  // loop over channels
512  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
513  // get channel
514  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
515 
516  // loop over all templates
517  for (unsigned int i = 0; i < ntemplates; ++i) {
518 
519  // get histogram
520  TH1D* temphist = channel->GetTemplate(i)->GetHistogram();
521  histlist.push_back(temphist);
522 
523  // replace by fluctuated histogram
524  if (temphist) {
525  TH1D* temphistfluc = new TH1D(channel->GetTemplate(i)->FluctuateHistogram(options, channel->GetTemplate(i)->GetOriginalNorm()));
526  channel->GetTemplate(i)->SetHistogram(temphistfluc, channel->GetTemplate(i)->GetNorm());
527  }
528  }
529  }
530  }
531 
532  // work-around: force initialization
533  fMTF->ResetResults();
534 
535  // check if marginalization should be run and perform analysis
536  if (fFlagMarginalize) {
537  BCLog::SetLogLevel(lls, llf);
538  BCLog::OutDetail(Form("Running MCMC for ensemble %i", iensemble));
539  BCLog::SetLogLevel(fLogLevel);
540 
541  // run mcmc
542  fMTF->MarginalizeAll();
543 
544  // find mode
545  fMTF->FindMode(fMTF->GetBestFitParameters());
546  } else {
547  // find mode
548  fMTF->FindMode();
549  }
550 
551  // fill tree variables
552  out_mode_global = fMTF->GetBestFitParameters();
553  out_std_global = fMTF->GetBestFitParameterErrors();
554  out_chi2_generated_total = 0;
555  out_chi2_mode_total = 0;
556  out_cash_generated_total = 0;
557  out_cash_mode_total = 0;
558  out_nevents_total = 0;
559 
560  double quantile_probsums[7] = {5e-2, 10e-2, 16e-2, 50e-2, 84e-2, 90e-2, 95e-2};
561  double quantile_values[7];
562 
563  for (int i = 0; i < nparameters; ++i) {
564  if (fFlagMarginalize) {
565  BCH1D hist = fMTF->GetMarginalized(i);
566  if (!hist.Valid())
567  continue;
568 
569  out_mode_marginalized[i] = hist.GetLocalMode(0);
570  out_mean_marginalized[i] = hist.GetHistogram()->GetMean();
571  out_std_marginalized[i] = hist.GetHistogram()->GetRMS();
572 
573  hist.GetHistogram()->GetQuantiles(6, quantile_values, quantile_probsums);
574  out_5quantile_marginalized[i] = quantile_values[0];
575  out_10quantile_marginalized[i] = quantile_values[1];
576  out_16quantile_marginalized[i] = quantile_values[2];
577  out_median_marginalized[i] = quantile_values[3];
578  out_84quantile_marginalized[i] = quantile_values[4];
579  out_90quantile_marginalized[i] = quantile_values[5];
580  out_95quantile_marginalized[i] = quantile_values[6];
581  }
582  }
583 
584  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
585  // get channel
586  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
587 
588  // get number of events
589  out_nevents[ichannel] = (int) channel->GetData()->GetHistogram()->Integral();
590 
591  // calculate chi2
592  out_chi2_generated[ichannel] = fMTF->CalculateChi2( ichannel, out_parameters );
593  out_chi2_mode[ichannel] = fMTF->CalculateChi2( ichannel, fMTF->GetBestFitParameters() );
594 
595  // calculate cash statistic
596  out_cash_generated[ichannel] = fMTF->CalculateCash( ichannel, out_parameters );
597  out_cash_mode[ichannel] = fMTF->CalculateCash( ichannel, fMTF->GetBestFitParameters() );
598 
599  // increase the total number of events
600  out_nevents_total += out_nevents[ichannel];
601 
602  // increase the total chi2
603  out_chi2_generated_total += out_chi2_generated[ichannel];
604  out_chi2_mode_total += out_chi2_mode[ichannel];
605 
606  // increase the total cash statistic
607  out_cash_generated_total += out_cash_generated[ichannel];
608  out_cash_mode_total += out_cash_mode[ichannel];
609  }
610 
611  // fill tree
612  tree_out->Fill();
613 
614  // but original template back if options "MC" is chosen
615  if (flag_mc) {
616  // get number of templates
617  unsigned int ntemplates = fMTF->GetNProcesses();
618 
619  // loop over channels
620  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
621  // get channel
622  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
623 
624  // loop over all templates
625  for (unsigned int i = 0; i < ntemplates; ++i) {
626 
627  // get histogram
628  TH1D* temphist = histlist.at(ichannel * ntemplates + i);
629  temphist->Scale(channel->GetTemplate(i)->GetOriginalNorm() / temphist->Integral());
630 
631  // replace by fluctuated histogram
632  TH1D* temphistfluc = channel->GetTemplate(i)->GetHistogram();
633  delete temphistfluc;
634  channel->GetTemplate(i)->SetHistogram(temphist, channel->GetTemplate(i)->GetNorm());
635  }
636  }
637  histlist.clear();
638  }
639  }
640 
641  // put the original data back in place
642  // loop over channels
643  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
644  // get channel
645  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
646 
647  // set data pointer
648  channel->GetData()->SetHistogram(histograms_data.at(ichannel));
649  }
650 
651  // reset log level
652  BCLog::SetLogLevel(lls, llf);
653 
654  // work-around: force initialization
655  fMTF->ResetResults();
656 
657  BCLog::OutSummary("Ensemble test ran successfully.");
658 
659  // return output tree
660  return tree_out;
661 }
662 
663 // ---------------------------------------------------------
664 std::vector<TH1D> BCMTFAnalysisFacility::MatrixToHistograms(const std::vector< std::vector<double> >& matrix)
665 {
666  // create vector of histograms
667  std::vector<TH1D> histograms;
668 
669  // get number of channels
670  int nchannels = matrix.size();;
671 
672  // loop over channels
673  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
674  // get channel
675  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
676 
677  // get column
678  std::vector<double> nbins_column = matrix[ichannel];
679 
680  // create new histogram
681  TH1D hist( *(channel->GetData()->GetHistogram()) );
682 
683  // get number of bins
684  int nbins = hist.GetNbinsX();
685 
686  // fill bin content
687  for (int ibin = 1; ibin <= nbins; ++ibin) {
688  hist.SetBinContent(ibin, nbins_column.at(ibin - 1));
689  }
690 
691  // add histogram to container
692  histograms.push_back(hist);
693  }
694 
695  // return histograms
696  return histograms;
697 
698 }
699 
700 // ---------------------------------------------------------
701 void BCMTFAnalysisFacility::PerformSingleChannelAnalyses(const std::string& dirname, const std::string& options)
702 {
703  BCLog::OutSummary("Running single channel analysis in directory \'" + dirname + "\'");
704 
705  // ---- create new directory ---- //
706  mkdir(dirname.data(), 0777);
707  cd(dirname);
708 
709  // ---- check options ---- //
710 
711  bool flag_syst = true;
712  bool flag_mcmc = true;
713 
714  if (options.find("nosyst") < options.size())
715  flag_syst = false;
716 
717  if (options.find("mcmc") < options.size())
718  flag_mcmc = true;
719 
720  // get number of channels
721  int nchannels = fMTF->GetNChannels();
722 
723  // get number of systematics
724  int nsystematics = fMTF->GetNSystematics();
725 
726  // container of flags for channels
727  std::vector<bool> flag_channel(nchannels);
728 
729  // container of flags for systematics
730  std::vector<bool> flag_systematic(nsystematics);
731 
732  // create new container of comparison tools
733  std::vector<BCMTFComparisonTool*> ctc;
734  std::vector<BCMTFComparisonTool*> ctc_mcmc;
735 
736  // get number of parameters
737  int nparameters = fMTF->GetNParameters();
738 
739  // ---- add one comparison tool for each parameter ---- //
740 
741  // loop over all parameters
742  for (int i = 0; i < nparameters; ++ i) {
743  // create new comparison tool
745  BCMTFComparisonTool* ct_mcmc = new BCMTFComparisonTool(fMTF->GetParameter(i).GetName());
746 
747  // add comparison tool to container
748  ctc.push_back(ct);
749  ctc_mcmc.push_back(ct_mcmc);
750  }
751 
752  // ---- switch on/off all systematics ---- //
753 
754  // loop over all systematics
755  for (int isystematic = 0; isystematic < nsystematics; ++isystematic) {
756  // get systematic
757  BCMTFSystematic* systematic = fMTF->GetSystematic(isystematic);
758 
759  // remember old setting
760  flag_systematic[isystematic] = systematic->GetFlagSystematicActive();
761 
762  // switch off systematic
763  if (flag_systematic[isystematic])
764  systematic->SetFlagSystematicActive(flag_syst);
765  }
766 
767  // ---- switch on all channels ---- //
768 
769  // loop over all channels
770  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
771  // get channel
772  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
773 
774  // remember old setting
775  flag_channel[ichannel] = channel->GetFlagChannelActive();
776 
777  // switch channel on/off
778  channel->SetFlagChannelActive(true);
779  }
780 
781  // ---- perform analysis for combination ---- //
782  if (flag_mcmc) {
783  // work-around: force initialization
784  fMTF->ResetResults();
785 
786  // run mcmc
787  fMTF->MarginalizeAll();
788 
789  // find mode
790  fMTF->FindMode(fMTF->GetBestFitParameters());
791  } else {
792  // find mode
793  fMTF->FindMode();
794  }
795 
796  // print results
797  if (flag_mcmc)
798  fMTF->PrintAllMarginalized("marginalized_combined.pdf");
799  fMTF->PrintFitSummary();
800 
801  // loop over all parameters
802  for (int i = 0; i < nparameters; ++ i) {
803  // get comparison tool
804  BCMTFComparisonTool* ct = ctc.at(i);
805  BCMTFComparisonTool* ct_mcmc = ctc_mcmc.at(i);
806 
807  ct->AddContribution("all channels", fMTF->GetBestFitParameters().at(i), fMTF->GetBestFitParameterErrors().at(i));
808  if (flag_mcmc) {
809  TH1* hist = fMTF->GetMarginalizedHistogram(i);
810  if (hist)
811  ct_mcmc->AddContribution("all channels", hist->GetMean(), hist->GetRMS());
812  }
813  }
814 
815  // ---- switch off all channels ----//
816 
817  // loop over all channels
818  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
819  // get channel
820  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
821 
822  // switch off channel
823  channel->SetFlagChannelActive(false);
824  }
825 
826  // ---- perform analysis on all channels separately ---- //
827 
828  // loop over all channels
829  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
830  // get channel
831  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
832 
833  // switch on one channel
834  channel->SetFlagChannelActive(true);
835 
836  // perform analysis
837 
838  if (flag_mcmc) {
839  // work-around: force initialization
840  fMTF->ResetResults();
841 
842  // run mcmc
843  fMTF->MarginalizeAll();
844 
845  // find mode
846  fMTF->FindMode(fMTF->GetBestFitParameters());
847  } else {
848  // find mode
849  fMTF->FindMode();
850  }
851 
852  // print results
853  if (flag_mcmc)
854  fMTF->PrintAllMarginalized(Form("marginalized_channel_%i.pdf", ichannel));
855  BCLog::OutSummary(Form("Summary for fitting channel %i", ichannel));
856  fMTF->PrintFitSummary();
857 
858  // ---- update comparison tools ---- //
859 
860  // loop over all parameters
861  for (int i = 0; i < nparameters; ++ i) {
862  // get comparison tool
863  BCMTFComparisonTool* ct = ctc.at(i);
864  BCMTFComparisonTool* ct_mcmc = ctc_mcmc.at(i);
865 
866  ct->AddContribution(channel->GetName(), fMTF->GetBestFitParameters().at(i), fMTF->GetBestFitParameterErrors().at(i));
867  if (flag_mcmc) {
868  TH1* hist = fMTF->GetMarginalizedHistogram(i);
869  if (hist)
870  ct_mcmc->AddContribution(channel->GetName(), hist->GetMean(), hist->GetRMS());
871  }
872 
873  // switch off channel
874  channel->SetFlagChannelActive(false);
875  }
876  }
877 
878  // ---- reset all systematics ---- //
879  // loop over all systematics
880  for (int isystematic = 0; isystematic < nsystematics; ++isystematic) {
881  // get systematic
882  BCMTFSystematic* systematic = fMTF->GetSystematic(isystematic);
883 
884  // switch off systematic
885  if (flag_systematic[isystematic])
886  systematic->SetFlagSystematicActive(flag_systematic[isystematic]);
887  }
888 
889  // ---- reset all channels ---- //
890 
891  // loop over all channels
892  for (int ichannel = 0; ichannel < nchannels; ++ichannel) {
893  // get channel
894  BCMTFChannel* channel = fMTF->GetChannel(ichannel);
895 
896  // switch channel on/off
897  channel->SetFlagChannelActive(flag_channel[ichannel]);
898  }
899 
900  // ---- workaround: reset MCMC ---- //
901  fMTF->ResetResults();
902 
903  // ---- print everything ---- //
904  TCanvas* c1 = new TCanvas();
905  c1->cd();
906 
907  // draw first one
908  BCMTFComparisonTool* ct = ctc.at(0);
909  ct->DrawOverview();
910  // c1->Print((std::string(filename)+std::string("(")).c_str());
911  c1->Print((std::string("overview.pdf") + std::string("(")).c_str());
912 
913  // loop over all parameters
914  for (int i = 1; i < nparameters - 1; ++ i) {
915  // create new comparison tool
916  BCMTFComparisonTool* ct = ctc.at(i);
917 
918  ct->DrawOverview();
919  c1->Print("overview.pdf");
920  }
921 
922  // draw last one
923  ct = ctc.at(nparameters - 1);
924  ct->DrawOverview();
925  c1->Print((std::string("overview.pdf") + std::string(")")).c_str());
926 
927  // ---- print everything (mcmc) ---- //
928  if (flag_mcmc) {
929  TCanvas* c2 = new TCanvas();
930  c2->cd();
931 
932  // draw first one
933  BCMTFComparisonTool* ct_mcmc = ctc_mcmc.at(0);
934  ct_mcmc->DrawOverview();
935  // c2->Print((std::string(filename)+std::string("(")).c_str());
936  c2->Print((std::string("overview_mcmc.pdf") + std::string("(")).c_str());
937 
938  // loop over all parameters
939  for (int i = 1; i < nparameters - 1; ++ i) {
940  // create new comparison tool
941  BCMTFComparisonTool* ct_mcmc = ctc_mcmc.at(i);
942 
943  ct_mcmc->DrawOverview();
944  c2->Print("overview_mcmc.pdf");
945  }
946 
947  // draw last one
948  ct_mcmc = ctc_mcmc.at(nparameters - 1);
949  ct_mcmc->DrawOverview();
950  c2->Print((std::string("overview_mcmc.pdf") + std::string(")")).c_str());
951  delete c2;
952  }
953 
954  // ---- free memory ---- //
955  for (int i = 0; i < nparameters; ++i) {
956  BCMTFComparisonTool* ct = ctc[i];
957  BCMTFComparisonTool* ct_mcmc = ctc_mcmc[i];
958  delete ct;
959  delete ct_mcmc;
960  }
961  ctc.clear();
962  ctc_mcmc.clear();
963 
964  delete c1;
965 
966  // ---- change directory ---- //
967 
968  cd("../");
969 
970  BCLog::OutSummary("Single channel analysis ran successfully");
971 }
972 
973 // ---------------------------------------------------------
974 void BCMTFAnalysisFacility::PerformSingleSystematicAnalyses(const std::string& dirname, const std::string& options)
975 {
976  BCLog::OutSummary("Running single channel systematic analysis in directory \'" + dirname + "\'.");
977 
978  // ---- create new directory ---- //
979 
980  mkdir(dirname.data(), 0777);
981  cd(dirname);
982 
983  // ---- check options ---- //
984 
985  bool flag_mcmc = true;
986 
987  if (options.find("mcmc") < options.size())
988  flag_mcmc = true;
989 
990  // get number of channels
991  int nchannels = fMTF->GetNChannels();
992 
993  // get number of systematics
994  int nsystematics = fMTF->GetNSystematics();
995 
996  // container of flags for channels
997  std::vector<bool> flag_channel(nchannels);
998 
999  // container of flags for systematics
1000  std::vector<bool> flag_systematic(nsystematics);
1001 
1002  // create new container of comparison tools
1003  std::vector<BCMTFComparisonTool*> ctc;
1004 
1005  // get number of parameters
1006  int nparameters = fMTF->GetNParameters();
1007 
1008  // ---- add one comparison tool for each systematic ---- //
1009 
1010  // loop over all parameters
1011  for (int i = 0; i < nparameters; ++ i) {
1012  // create new comparison tool
1014 
1015  // add comparison tool to container
1016  ctc.push_back(ct);
1017  }
1018 
1019  // ---- switch on all systematics ---- //
1020 
1021  for (int isystematic = 0; isystematic < nsystematics; ++ isystematic) {
1022  // get systematic
1023  BCMTFSystematic* systematic = fMTF->GetSystematic(isystematic);
1024 
1025  // remember old setting
1026  flag_systematic[isystematic] = systematic->GetFlagSystematicActive();
1027 
1028  // switch on
1029  systematic->SetFlagSystematicActive(true);
1030  }
1031 
1032  if (flag_mcmc) {
1033  // work-around: force initialization
1034  fMTF->ResetResults();
1035 
1036  // run mcmc
1037  fMTF->MarginalizeAll();
1038 
1039  // find mode
1040  fMTF->FindMode(fMTF->GetBestFitParameters());
1041  } else {
1042  // find mode
1043  fMTF->FindMode();
1044  }
1045 
1046  // print results
1047  if (flag_mcmc)
1048  fMTF->PrintAllMarginalized("marginalized_all.pdf");
1049  fMTF->PrintSummary();
1050 
1051  // loop over all parameters
1052  for (int i = 0; i < nparameters; ++ i) {
1053  // get comparison tool
1054  BCMTFComparisonTool* ct = ctc.at(i);
1055 
1056  ct->AddContribution("all systematics",
1057  fMTF->GetBestFitParameters().at(i),
1058  fMTF->GetBestFitParameterErrors().at(i));
1059  }
1060 
1061  // ---- switch off all systematics ---- //
1062 
1063  // loop over all systematics
1064  for (int isystematic = 0; isystematic < nsystematics; ++isystematic) {
1065  // get systematic
1066  BCMTFSystematic* systematic = fMTF->GetSystematic(isystematic);
1067 
1068  // switch off
1069  systematic->SetFlagSystematicActive(false);
1070  }
1071 
1072  // ---- perform analysis with all systematics separately ---- //
1073 
1074  // loop over all channels
1075  for (int isystematic = 0; isystematic < nsystematics; ++isystematic) {
1076  // get systematic
1077  BCMTFSystematic* systematic = fMTF->GetSystematic(isystematic);
1078 
1079  // switch on systematic
1080  systematic->SetFlagSystematicActive(true);
1081 
1082  // perform analysis
1083  if (flag_mcmc) {
1084  // work-around: force initialization
1085  fMTF->ResetResults();
1086 
1087  // run mcmc
1088  fMTF->MarginalizeAll();
1089 
1090  // find mode
1091  fMTF->FindMode(fMTF->GetBestFitParameters());
1092  } else {
1093  // find mode
1094  fMTF->FindMode();
1095  }
1096 
1097  // print results
1098  if (flag_mcmc)
1099  fMTF->PrintAllMarginalized(Form("marginalized_systematic_%i.pdf", isystematic));
1100  BCLog::OutSummary(Form("Summary from fitting systematic %i", isystematic));
1101  fMTF->PrintFitSummary();
1102 
1103  // ---- update comparison tools ---- //
1104 
1105  // loop over all parameters
1106  for (int i = 0; i < nparameters; ++ i) {
1107  // get comparison tool
1108  BCMTFComparisonTool* ct = ctc.at(i);
1109 
1110  ct->AddContribution(systematic->GetName(),
1111  fMTF->GetBestFitParameters().at(i),
1112  fMTF->GetBestFitParameterErrors().at(i));
1113  }
1114 
1115  // switch off systematic
1116  systematic->SetFlagSystematicActive(false);
1117  }
1118 
1119  // ---- analysis without any systematic uncertainty ---- //
1120 
1121  if (flag_mcmc) {
1122  // work-around: force initialization
1123  fMTF->ResetResults();
1124 
1125  // run mcmc
1126  fMTF->MarginalizeAll();
1127 
1128  // find mode
1129  fMTF->FindMode(fMTF->GetBestFitParameters());
1130  } else {
1131  // find mode
1132  fMTF->FindMode();
1133  }
1134 
1135  // print results
1136  if (flag_mcmc)
1137  fMTF->PrintAllMarginalized("marginalized_none.pdf");
1138  BCLog::OutSummary("Summary without systematics");
1139  fMTF->PrintFitSummary();
1140 
1141  // loop over all parameters
1142  for (int i = 0; i < nparameters; ++ i) {
1143  // get comparison tool
1144  BCMTFComparisonTool* ct = ctc.at(i);
1145 
1146  ct->AddContribution("no systematics",
1147  fMTF->GetBestFitParameters().at(i),
1148  fMTF->GetBestFitParameterErrors().at(i));
1149  }
1150 
1151 
1152 
1153  // ---- reset all systematics ---- //
1154 
1155  // loop over all systematics
1156  for (int isystematic = 0; isystematic < nsystematics; ++isystematic) {
1157  // get systematic
1158  BCMTFSystematic* systematic = fMTF->GetSystematic(isystematic);
1159 
1160  // switch off systematic
1161  if (flag_systematic[isystematic])
1162  systematic->SetFlagSystematicActive(flag_systematic[isystematic]);
1163  }
1164 
1165  // ---- workaround: reset MCMC ---- //
1166  fMTF->ResetResults();
1167 
1168  // ---- print everything ---- //
1169  TCanvas* c1 = new TCanvas();
1170  c1->cd();
1171 
1172  // draw first one
1173  BCMTFComparisonTool* ct = ctc.at(0);
1174  ct->DrawOverview();
1175  // c1->Print((std::string(filename)+std::string("(")).c_str());
1176  c1->Print((std::string("overview.pdf") + std::string("(")).c_str());
1177 
1178  // loop over all parameters
1179  for (int i = 1; i < nparameters - 1; ++i) {
1180  // create new comparison tool
1181  BCMTFComparisonTool* ct = ctc.at(i);
1182 
1183  ct->DrawOverview();
1184  c1->Print("overview.pdf");
1185  }
1186 
1187  // draw last one
1188  ct = ctc.at(nparameters - 1);
1189  ct->DrawOverview();
1190  c1->Print((std::string("overview.pdf") + std::string(")")).c_str());
1191 
1192  // ---- free memory ---- //
1193  for (int i = 0; i < nparameters; ++i) {
1194  BCMTFComparisonTool* ct = ctc[i];
1195  delete ct;
1196  }
1197  ctc.clear();
1198 
1199  delete c1;
1200 
1201  // ---- change directory ---- //
1202 
1203  cd("../");
1204 
1205  BCLog::OutSummary("Single channel analysis ran successfully");
1206 }
1207 
1208 // ---------------------------------------------------------
1209 void BCMTFAnalysisFacility::PerformCalibrationAnalysis(const std::string& dirname, const std::vector<double>& default_parameters, int index, const std::vector<double>& parametervalues, int nensembles)
1210 {
1211  BCLog::OutSummary("Running calibration analysis in directory \'" + dirname + "\'.");
1212 
1213  // ---- create new directory ---- //
1214 
1215  mkdir(dirname.data(), 0777);
1216  cd(dirname);
1217 
1218  // ---- loop over parameter values and perform analysis ---- //
1219 
1220  int nvalues = int(parametervalues.size());
1221  for (int ivalue = 0; ivalue < nvalues; ++ivalue) {
1222 
1223  // open file
1224  TFile* file = TFile::Open(Form("ensemble_%i.root", ivalue), "RECREATE");
1225  file->cd();
1226 
1227  // set parameters
1228  std::vector<double> parameters = default_parameters;
1229  parameters[index] = parametervalues.at(ivalue);
1230 
1231  // create ensemble
1232  TTree* tree = PerformEnsembleTest(parameters, nensembles);
1233 
1234  // write tree
1235  tree->Write();
1236 
1237  // close file
1238  file->Close();
1239 
1240  // free memory
1241  delete file;
1242  }
1243 
1244  // ---- change directory ---- //
1245  cd("../");
1246 
1247  BCLog::OutSummary("Calibration analysis ran successfully");
1248 }
1249 
1250 // ---------------------------------------------------------
static BCLog::LogLevel GetLogLevelFile()
Returns the minimum log level for file output.
Definition: BCLog.h:82
const std::vector< double > & GetBestFitParameterErrors() const
Returns the set of errors on the values of the parameters at the mode.
double GetLocalMode()
Definition: BCH1D.h:78
int GetNChannels() const
Definition: BCMTF.h:61
bool GetFlagChannelActive()
Definition: BCMTFChannel.h:88
~BCMTFAnalysisFacility()
The default destructor.
void PerformSingleSystematicAnalyses(const std::string &dirname, const std::string &options="")
Perform the analysis using one systematic at a time, without systematic and with all systematics...
int GetNProcesses() const
Definition: BCMTF.h:66
void PerformCalibrationAnalysis(const std::string &dirname, const std::vector< double > &default_parameters, int index, const std::vector< double > &parametervalues, int nensembles=1000)
Perform the analysis on pseudo-data generated by varying one of the parameters.
BCParameter & GetParameter(unsigned index)
Definition: BCEngineMCMC.h:630
static void SetLogLevel(BCLog::LogLevel loglevelfile, BCLog::LogLevel loglevelscreen)
Sets the minimum log level for file and screen output.
Definition: BCLog.h:117
int MarginalizeAll()
Marginalize all probabilities wrt.
TTree * BuildEnsembles(const std::vector< double > &parameters, int nensembles, const std::string &options="")
Build ensembles based on a single set of parameters.
std::vector< double > FindMode(std::vector< double > start=std::vector< double >())
Do the mode finding using a method set via SetOptimizationMethod.
void SetHistogram(TH1D *hist, double norm=1)
Set the histogram.
A helper class for BCMTFAnalysisFacility storing information.
LogLevel
Enumerator for the amount of details to put into the log file.
Definition: BCLog.h:59
const std::string & GetName() const
BCMTFTemplate * GetTemplate(int index)
Return a template.
Definition: BCMTFChannel.h:76
TH1D FluctuateHistogram(const std::string &options="GZ", double norm=1)
Fluctuate the original template histogram by the uncertainty on the bin content.
double Expectation(int channelindex, int binindex, const std::vector< double > &parameters)
Return the expected number of events for a channel and bin.
Definition: BCMTF.cxx:528
double GetOriginalNorm()
Definition: BCMTFTemplate.h:81
void SetFlagSystematicActive(bool flag)
Set a flag defining if this uncertainty is active or not.
void PerformSingleChannelAnalyses(const std::string &dirname, const std::string &options="")
Perform the full set of single channel analyses and the combination.
TH1D * GetHistogram()
Definition: BCMTFTemplate.h:71
double CalculateCash(int channelindex, const std::vector< double > &parameters)
Calculate the Cash statistic for a single channel.
Definition: BCMTF.cxx:969
const std::string & GetName() const
Definition: BCEngineMCMC.h:269
unsigned PrintAllMarginalized(const std::string &filename, unsigned hdiv=1, unsigned vdiv=1) const
Print all marginalizations.
BCMTFAnalysisFacility(BCMTF *mtf)
The default constructor.
bool GetFlagSystematicActive() const
int GetNSystematics() const
Definition: BCMTF.h:71
A class describing a physics channel.
Definition: BCMTFChannel.h:36
virtual bool Valid() const
Whether histogram has been set and filled.
Print nothing.
Definition: BCLog.h:65
void SetData(const std::string &channelname, TH1D hist, double minimum=-1, double maximum=-1)
Set the data histogram in a particular channel.
Definition: BCMTF.cxx:177
BCMTFTemplate * GetData()
Definition: BCMTFChannel.h:69
A class for handling 1D distributions.
Definition: BCH1D.h:34
void AddContribution(const std::string &name, TH1D hist)
Add a constribution.
void SetFlagChannelActive(bool flag)
Set flag to define if the channel is active or not.
Definition: BCMTFChannel.h:147
BCMTFSystematic * GetSystematic(int index)
Definition: BCMTF.h:119
void PrintFitSummary()
Print a summary of the fit to the log.
Definition: BCMTF.cxx:495
std::vector< TH1D > MatrixToHistograms(const std::vector< std::vector< double > > &matrix)
Transform a matrix to a set of histograms.
TH1 * GetMarginalizedHistogram(const std::string &name) const
Obtain the individual marginalized distributions with respect to one parameter as a ROOT TH1...
Definition: BCEngineMCMC.h:527
BCMTFChannel * GetChannel(int index)
Definition: BCMTF.h:104
const std::string & GetName() const
Definition: BCMTFChannel.h:59
void DrawOverview()
Draw an overview.
virtual void PrintSummary() const
Prints a summary to the logs.
virtual const std::string & GetName() const
Definition: BCVariable.h:72
double GetNorm()
Definition: BCMTFTemplate.h:76
double CalculateChi2(int channelindex, const std::vector< double > &parameters)
Calculate a chi2 for a single channel given a set of parameters.
Definition: BCMTF.cxx:910
static std::string ToString(BCLog::LogLevel)
Converts a log level to a string.
Definition: BCLog.cxx:119
static BCLog::LogLevel GetLogLevelScreen()
Returns the minimum log level for screen output.
Definition: BCLog.h:88
BCH1D GetMarginalized(const std::string &name) const
Obtain the individual marginalized distributions with respect to one parameter.
Definition: BCEngineMCMC.h:561
unsigned GetNParameters() const
Definition: BCEngineMCMC.h:656
virtual void ResetResults()
Reset all information on the best-fit parameters.
A class for fitting several templates to a data set.
Definition: BCMTF.h:38
std::vector< TH1D > BuildEnsemble(const std::vector< double > &parameters, const std::string &options="")
Build a single ensemble based on a single set of parameters.
TTree * PerformEnsembleTest(const std::vector< double > &parameters, int nensembles, const std::string &options="")
Perform ensemble test based on one set of parameters.
virtual const std::vector< double > & GetBestFitParameters() const
A class for managing log messages.
Definition: BCLog.h:51
A class desribing a systematic uncertainty.