MaCh3  2.5.0
Reference Guide
samples.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 #include <pybind11/pybind11.h>
7 #include <pybind11/stl.h>
8 #include <pybind11/numpy.h>
9 
11 #include "TH1.h"
12 #include "TH2.h"
13 
14 namespace py = pybind11;
15 
16 // Helper function to convert TH1 to numpy arrays
17 std::tuple<py::array_t<M3::float_t>, py::array_t<M3::float_t>> TH1ToNumpy(const TH1* hist) {
18  if (!hist) {
19  throw std::runtime_error("Histogram pointer is null");
20  }
21 
22  int nbins = hist->GetNbinsX();
23 
24  // Create numpy array for bin contents
25  py::array_t<M3::float_t> contents(nbins);
26  auto contents_buf = contents.request();
27  M3::float_t* contents_ptr = static_cast<M3::float_t*>(contents_buf.ptr);
28 
29  // Create numpy array for bin edges (nbins + 1 edges)
30  py::array_t<M3::float_t> edges(nbins + 1);
31  auto edges_buf = edges.request();
32  M3::float_t* edges_ptr = static_cast<M3::float_t*>(edges_buf.ptr);
33 
34  // Copy bin contents (ROOT bins start at 1, not 0)
35  for (int i = 0; i < nbins; ++i) {
36  contents_ptr[i] = hist->GetBinContent(i + 1);
37  }
38 
39  // Copy bin edges
40  for (int i = 0; i <= nbins; ++i) {
41  edges_ptr[i] = hist->GetBinLowEdge(i + 1);
42  }
43  // Add the upper edge of the last bin
44  edges_ptr[nbins] = hist->GetBinLowEdge(nbins + 1) + hist->GetBinWidth(nbins + 1);
45 
46  return std::make_tuple(contents, edges);
47 }
48 
49 // Helper function to convert TH2 to numpy arrays
50 std::tuple<py::array_t<M3::float_t>, py::array_t<M3::float_t>, py::array_t<M3::float_t>> TH2ToNumpy(const TH2* hist) {
51  if (!hist) {
52  throw std::runtime_error("Histogram pointer is null");
53  }
54 
55  int nbinsX = hist->GetNbinsX();
56  int nbinsY = hist->GetNbinsY();
57 
58  // Create 2D numpy array for bin contents (shape: nbinsY x nbinsX to match numpy convention)
59  py::array_t<M3::float_t> contents({nbinsY, nbinsX});
60  auto contents_buf = contents.request();
61  M3::float_t* contents_ptr = static_cast<M3::float_t*>(contents_buf.ptr);
62 
63  // Create numpy arrays for bin edges
64  py::array_t<M3::float_t> edgesX(nbinsX + 1);
65  auto edgesX_buf = edgesX.request();
66  M3::float_t* edgesX_ptr = static_cast<M3::float_t*>(edgesX_buf.ptr);
67 
68  py::array_t<M3::float_t> edgesY(nbinsY + 1);
69  auto edgesY_buf = edgesY.request();
70  M3::float_t* edgesY_ptr = static_cast<M3::float_t*>(edgesY_buf.ptr);
71 
72  // Copy bin contents (ROOT bins start at 1, not 0)
73  // Note: numpy uses row-major order (C-style), so we iterate Y then X
74  for (int iy = 0; iy < nbinsY; ++iy) {
75  for (int ix = 0; ix < nbinsX; ++ix) {
76  contents_ptr[iy * nbinsX + ix] = hist->GetBinContent(ix + 1, iy + 1);
77  }
78  }
79 
80  // Copy X bin edges
81  for (int i = 0; i <= nbinsX; ++i) {
82  edgesX_ptr[i] = hist->GetXaxis()->GetBinLowEdge(i + 1);
83  }
84  edgesX_ptr[nbinsX] = hist->GetXaxis()->GetBinLowEdge(nbinsX + 1) +
85  hist->GetXaxis()->GetBinWidth(nbinsX + 1);
86 
87  // Copy Y bin edges
88  for (int i = 0; i <= nbinsY; ++i) {
89  edgesY_ptr[i] = hist->GetYaxis()->GetBinLowEdge(i + 1);
90  }
91  edgesY_ptr[nbinsY] = hist->GetYaxis()->GetBinLowEdge(nbinsY + 1) +
92  hist->GetYaxis()->GetBinWidth(nbinsY + 1);
93 
94  return std::make_tuple(contents, edgesX, edgesY);
95 }
96 
97 // Add these bindings to the PySampleHandlerBase class definition:
98 
101 public:
102  /* Inherit the constructors */
104 
105  /* Trampoline (need one for each virtual function) */
106  std::string GetName() const override {
107  PYBIND11_OVERRIDE_PURE(
108  std::string, /* Return type */
109  SampleHandlerInterface, /* Parent class */
110  GetName, /* Name of function in C++ (must match Python name) */
111  );
112  }
113 
114  /* Trampoline (need one for each virtual function) */
115  std::string GetSampleTitle(const int iSample) const override {
116  PYBIND11_OVERRIDE_PURE(
117  std::string, /* Return type */
118  SampleHandlerInterface, /* Parent class */
119  GetSampleTitle, /* Name of function in C++ (must match Python name) */
120  iSample /* Argument(s) */
121  );
122  }
123 
124  /* Trampoline (need one for each virtual function) */
125  int GetNOscChannels(const int iSample) const override {
126  PYBIND11_OVERRIDE_PURE(
127  int, /* Return type */
128  SampleHandlerInterface, /* Parent class */
129  GetNOscChannels, /* Name of function in C++ (must match Python name) */
130  iSample /* Argument(s) */
131  );
132  }
133 
134  /* Trampoline (need one for each virtual function) */
135  void Reweight() override {
136  PYBIND11_OVERRIDE_PURE_NAME(
137  void, /* Return type */
138  SampleHandlerInterface, /* Parent class */
139  "reweight",
140  Reweight /* Name of function in C++ (must match Python name) */
141  );
142  }
143 
144 
145  /* Trampoline (need one for each virtual function) */
146  double GetSampleLikelihood(const int iSample) const override {
147  PYBIND11_OVERRIDE_PURE_NAME(
148  double, /* Return type */
149  SampleHandlerInterface, /* Parent class */
150  "get_sample_likelihood",
151  GetSampleLikelihood, /* Name of function in C++ (must match Python name) */
152  iSample /* Argument(s) */
153  );
154  }
155 
156  /* Trampoline (need one for each virtual function) */
157  void CleanMemoryBeforeFit() override {
158  PYBIND11_OVERRIDE_PURE_NAME(
159  void, /* Return type */
160  SampleHandlerInterface, /* Parent class */
161  "clean_memory_before_fit",
162  CleanMemoryBeforeFit /* Name of function in C++ (must match Python name) */
163  );
164  }
165 
166  /* Trampoline (need one for each virtual function) */
167  void PrintRates(const bool DataOnly = false) override {
168  PYBIND11_OVERRIDE_PURE(
169  void, /* Return type */
170  SampleHandlerInterface, /* Parent class */
171  PrintRates, /* Name of function in C++ (must match Python name) */
172  DataOnly /* Argument(s) */
173  );
174  }
175 
176  /* Trampoline (need one for each virtual function) */
177  std::string GetKinVarName(const int iSample, const int Dimension) const override {
178  PYBIND11_OVERRIDE_PURE(
179  std::string, /* Return type */
180  SampleHandlerInterface, /* Parent class */
181  GetKinVarName, /* Name of function in C++ (must match Python name) */
182  iSample, /* Argument(s) */
183  Dimension /* Argument(s) */
184  );
185  }
186 
187  /* Trampoline (need one for each virtual function) */
188  std::vector<double> ReturnKinematicParameterBinning(const int Sample, const std::string &KinematicParameter) const override {
189  PYBIND11_OVERRIDE_PURE(
190  std::vector<double>, /* Return type */
191  SampleHandlerInterface, /* Parent class */
192  GetKinVarName, /* Name of function in C++ (must match Python name) */
193  Sample, /* Argument(s) */
194  KinematicParameter /* Argument(s) */
195  );
196  }
197 
198  TH1* GetDataHist(const int Sample) override {
199  PYBIND11_OVERRIDE_PURE(
200  TH1*, /* Return type */
201  SampleHandlerInterface, /* Parent class */
202  GetDataHist, /* Name of function in C++ (must match Python name) */
203  Sample /* Argument(s) */
204  );
205  }
206 
207  TH1* GetMCHist(const int Sample) override {
208  PYBIND11_OVERRIDE_PURE(
209  TH1*, /* Return type */
210  SampleHandlerInterface, /* Parent class */
211  GetMCHist, /* Name of function in C++ (must match Python name) */
212  Sample /* Argument(s) */
213  );
214  }
215 
216  TH1* GetW2Hist(const int Sample) override {
217  PYBIND11_OVERRIDE_PURE(
218  TH1*, /* Return type */
219  SampleHandlerInterface, /* Parent class */
220  GetW2Hist, /* Name of function in C++ (must match Python name) */
221  Sample /* Argument(s) */
222  );
223  }
224 
225  double GetLikelihood() const override {
226  PYBIND11_OVERRIDE_PURE_NAME(
227  double, /* Return type */
228  SampleHandlerInterface, /* Parent class */
229  "get_likelihood", /* Python name*/
230  GetLikelihood /* Name of function in C++ (must match Python name) */
231  /* Argument(s) */
232  );
233  }
234 
235  std::unique_ptr<TH1> Get1DVarHistByModeAndChannel(const int iSample,
236  const std::string& ProjectionVar_Str,
237  const int kModeToFill = -1,
238  const int kChannelToFill = -1,
239  const int WeightStyle = 0) override {
240  (void) iSample;
241  (void) ProjectionVar_Str;
242  (void) kModeToFill;
243  (void) kChannelToFill;
244  (void) WeightStyle;
245  return nullptr;
246  }
247 
248  std::unique_ptr<TH2> Get2DVarHistByModeAndChannel(const int iSample,
249  const std::string& ProjectionVar_StrX,
250  const std::string& ProjectionVar_StrY,
251  const int kModeToFill = -1,
252  const int kChannelToFill = -1,
253  const int WeightStyle = 0) override {
254  (void) iSample;
255  (void) ProjectionVar_StrX;
256  (void) ProjectionVar_StrY;
257  (void) kModeToFill;
258  (void) kChannelToFill;
259  (void) WeightStyle;
260  return nullptr;
261  }
262 
263  std::unique_ptr<TH1> Get1DVarHist(const int iSample,
264  const std::string &ProjectionVar,
265  const std::vector<KinematicCut> &EventSelectionVec = {},
266  const int WeightStyle = 0,
267  const std::vector<KinematicCut> &SubEventSelectionVec = {}) override {
268  (void) iSample;
269  (void) ProjectionVar;
270  (void) EventSelectionVec;
271  (void) WeightStyle;
272  (void) SubEventSelectionVec;
273  return nullptr;
274  }
275 
276  std::unique_ptr<TH2> Get2DVarHist(const int iSample,
277  const std::string& ProjectionVarX,
278  const std::string& ProjectionVarY,
279  const std::vector<KinematicCut>& EventSelectionVec = {},
280  const int WeightStyle = 0,
281  const std::vector<KinematicCut>& SubEventSelectionVec = {}) override {
282  (void) iSample;
283  (void) ProjectionVarX;
284  (void) ProjectionVarY;
285  (void) EventSelectionVec;
286  (void) WeightStyle;
287  (void) SubEventSelectionVec;
288  return nullptr;
289  }
290 
291  int GetNDim(const int Sample) const override {
292  PYBIND11_OVERRIDE_PURE(
293  int, /* Return type */
294  SampleHandlerInterface, /* Parent class */
295  GetNDim, /* Name of function in C++ */
296  Sample
297  );
298  }
299 
300  std::string GetFlavourName(const int iSample,
301  const int iChannel) const override {
302  PYBIND11_OVERRIDE_PURE(
303  std::string, /* Return type */
304  SampleHandlerInterface, /* Parent class */
305  GetFlavourName, /* Name of function in C++ */
306  iSample,
307  iChannel
308  );
309  }
310 };
311 
312 
315 public:
316  /* Inherit the constructors */
318 
319  /* Trampoline (need one for each virtual function) */
320  void AddAdditionalWeightPointers() override {
321  PYBIND11_OVERRIDE_PURE_NAME(
322  void, /* Return type */
323  SampleHandlerBase, /* Parent class */
324  "add_additional_weight_pointers", /*python name*/
325  AddAdditionalWeightPointers, /* Name of function in C++ */
326  /* Argument(s) */
327  );
328  }
329 
330  /* Trampoline (need one for each virtual function) */
331  void CleanMemoryBeforeFit() override {
332  PYBIND11_OVERRIDE_PURE(
333  void, /* Return type */
334  SampleHandlerBase, /* Parent class */
335  CleanMemoryBeforeFit /* Name of function in C++ (must match Python name) */
336  );
337  }
338 
339  /* Trampoline (need one for each virtual function) */
340  void SetupSplines() override {
341  PYBIND11_OVERRIDE_PURE_NAME(
342  void, /* Return type */
343  SampleHandlerBase, /* Parent class */
344  "setup_splines", /*python name*/
345  SetupSplines, /* Name of function in C++ */
346  /* Argument(s) */
347  );
348  }
349 
350  /* Trampoline (need one for each virtual function) */
351  void Init() override {
352  PYBIND11_OVERRIDE_PURE_NAME(
353  void, /* Return type */
354  SampleHandlerBase, /* Parent class */
355  "init", /*python name*/
356  Init, /* Name of function in C++ */
357  /* Argument(s) */
358  );
359  }
360 
361  /* Trampoline (need one for each virtual function) */
362  int SetupExperimentMC() override {
363  PYBIND11_OVERRIDE_PURE_NAME(
364  int, /* Return type */
365  SampleHandlerBase, /* Parent class */
366  "setup_experiment_MC", /*python name*/
367  SetupExperimentMC, /* Name of function in C++ */
368  );
369  }
370 
371  /* Trampoline (need one for each virtual function) */
372  void InititialiseData() override {
373  PYBIND11_OVERRIDE_PURE_NAME(
374  void, /* Return type */
375  SampleHandlerBase, /* Parent class */
376  "inititialis_data", /*python name*/
377  InititialiseData, /* Name of function in C++ */
378  );
379  }
380 
381  /* Trampoline (need one for each virtual function) */
382  void SetupMC() override {
383  PYBIND11_OVERRIDE_PURE_NAME(
384  void, /* Return type */
385  SampleHandlerBase, /* Parent class */
386  "setup_MC", /*python name*/
387  SetupMC, /* Name of function in C++ */
388  );
389  }
390 
391  double ReturnKinematicParameter(int, int) const override {
392  PYBIND11_OVERRIDE_PURE_NAME(
393  double, /* Return type */
394  SampleHandlerBase, /* Parent class */
395  "get_event_kinematic_value", /* python name*/
396  ReturnKinematicParameter, /* Name of function in C++ (must match Python name) */
397  py::arg("variable"),
398  py::arg("event") /* Argument(s) */
399  );
400  }
401 
402  const double *GetPointerToKinematicParameter(int, int) const override {
403  PYBIND11_OVERRIDE_PURE_NAME(
404  const double *, /* Return type */
405  SampleHandlerBase, /* Parent class */
406  "get_event_kinematic_value_reference", /* python name*/
407  GetPointerToKinematicParameter, /* Name of function in C++ (must match Python name) */
408  py::arg("variable"), /* Argument(s) */
409  py::arg("event") /* Argument(s) */
410  );
411  }
412 
414  PYBIND11_OVERRIDE_PURE_NAME(
415  void, /* Return type */
416  SampleHandlerBase, /* Parent class */
417  "register_functional_parameters",
418  RegisterFunctionalParameters /* Name of function in C++ (must match Python name) */
419  );
420  }
421 };
422 
423 void initSamplesModule(py::module &m_samples){
424 
425  // Bind the systematic type enum that lets us set different types of systematics
426  py::enum_<TestStatistic>(m_samples, "TestStatistic")
427  .value("Poisson", TestStatistic::kPoisson)
428  .value("Barlow_Beeston", TestStatistic::kBarlowBeeston)
429  .value("Ice_Cube", TestStatistic::kIceCube)
430  .value("Pearson", TestStatistic::kPearson)
431  .value("Dembinski_Abdelmottele", TestStatistic::kDembinskiAbdelmotteleb)
432  .value("N_Test_Statistics", TestStatistic::kNTestStatistics);
433 
434  py::class_<SampleHandlerInterface, PySampleHandlerInterface /* <--- trampoline*/>(m_samples, "SampleHandlerInterface")
435  .def(py::init())
436 
437  .def(
438  "reweight",
440  "reweight the MC events in this sample. You will need to override this."
441  )
442 
443  .def(
444  "get_likelihood",
446  "Get the sample likelihood at the current point in your model space. You will need to override this."
447  )
448 
449  .def(
450  "set_test_stat",
452  "Set the test statistic that should be used when calculating likelihoods. \n\
453  :param test_stat: The new test statistic to use",
454  py::arg("test_stat")
455  )
456 
457  .def(
458  "get_bin_LLH",
459  py::overload_cast<double, double, double>(&SampleHandlerInterface::GetTestStatLLH, py::const_),
460  "Get the LLH for a bin by comparing the data and MC. The result depends on having previously set the test statistic using :py:meth:`pyMaCh3.samples.SampleHandlerInterface.set_test_stat` \n\
461  :param data: The data content of the bin. \n\
462  :param mc: The mc content of the bin \n\
463  :param w2: The Sum(w_{i}^2) (sum of weights squared) in the bin, which is sigma^2_{MC stats}",
464  py::arg("data"),
465  py::arg("mc"),
466  py::arg("w2")
467  )
468  ; // End of SampleHandlerInterface binding
469 
470  py::class_<SampleHandlerBase, PySampleHandlerBase /* <--- trampoline*/,
471  SampleHandlerInterface>(m_samples, "SampleHandlerBase")
472  .def(
473  py::init<std::string, ParameterHandlerGeneric*>(),
474  "This should never be called directly as SampleHandlerBase is an abstract base class. \n\
475  However when creating a derived class, in the __init__() method, you should call the parent constructor i.e. this one by doing:: \n\
476  \n\
477  \tsuper(<your derived SampleHandler class>, self).__init__(*args) \n\
478  \n ",
479  py::arg("mc_version"), py::arg("xsec_cov"))
480 
481  .def(
482  "get_mc_hist",
483  [](SampleHandlerBase &self, const int sample) {
484 
485  int Dimension = self.GetNDim(sample);
486 
487  //self.Reweight();
488 
489  // Get the histogram pointer BEFORE cloning
490  const TH1 *hist_original = self.GetMCHist(sample);
491 
492  // Debug: Check the original histogram
493  if (!hist_original) {
494  throw std::runtime_error("GetMCHist returned null pointer");
495  }
496 
497  // Now clone it
498  TH1D *hist = static_cast<TH1D*>(hist_original->Clone("cloned_hist"));
499 
500  if (Dimension == 1) {
501  // 1D histogram
502  auto [contents, edgesX] = TH1ToNumpy(hist);
503  auto edgesY = py::array_t<M3::float_t>();
504  return py::make_tuple(contents, edgesX, edgesY);
505  } else if (Dimension == 2) {
506 
507  TH2Poly *hist2poly = dynamic_cast<TH2Poly *>(hist);
508  if (hist2poly) {
510  throw std::runtime_error("pyMaCh3 can't do non-uniform binning for now :(");
511  }
512 
513  // 2D histogram - cast to TH2
514  TH2 *hist2d = dynamic_cast<TH2 *>(hist);
515  if (!hist2d) {
516  throw std::runtime_error("Failed to cast to TH2");
517  }
518  auto [contents, edgesX, edgesY] = TH2ToNumpy(hist2d);
519  return py::make_tuple(contents, edgesX, edgesY);
520  } else {
524  throw std::invalid_argument("Dimension must be 1 or 2");
525  }
526  },
527  py::return_value_policy::reference_internal,
528  py::arg("sample"),
529  "Get MC histogram as numpy arrays.\n"
530  "For 1D: Returns (contents, edges)\n"
531  "For 2D: Returns (contents, edgesX, edgesY)\n"
532  "where contents is shape (nbinsY, nbinsX) for 2D")
533 
534  .def(
535  "get_data_hist",
536  [](SampleHandlerBase &self, const int sample) {
537  const TH1 *hist = self.GetDataHist(sample);
538 
539  int Dimension = self.GetNDim(sample);
540 
541  if (Dimension == 1) {
542  // 1D histogram
543  const auto [contents, edgesX] = TH1ToNumpy(hist);
544  const auto edgesY = py::array_t<M3::float_t>();
545  return py::make_tuple(contents, edgesX, edgesY);
546  } else if (Dimension == 2) {
547 
548  const TH2Poly *hist2poly = dynamic_cast<const TH2Poly *>(hist);
549  if (hist2poly) {
551  throw std::runtime_error("pyMaCh3 can't do non-uniform binning for now :(");
552  }
553 
555  throw std::runtime_error("pyMaCh3 can't do non-uniform binning for now :(");
556 
557  // 2D histogram - cast to TH2
558  const TH2 *hist2d = dynamic_cast<const TH2 *>(hist);
559  if (!hist2d) {
560  throw std::runtime_error("Failed to cast to TH2");
561  }
562  const auto [contents, edgesX, edgesY] = TH2ToNumpy(hist2d);
563  return py::make_tuple(contents, edgesX, edgesY);
564  } else {
568  throw std::invalid_argument("Dimension must be 1 or 2");
569  }
570  },
571  py::arg("Dimension"),
572  "Get Data histogram as numpy arrays.\n"
573  "For 1D: Returns (contents, edges)\n"
574  "For 2D: Returns (contents, edgesX, edgesY)\n"
575  "where contents is shape (nbinsY, nbinsX) for 2D")
576 
577  .def(
578  "get_w2_hist",
579  [](SampleHandlerBase &self, const int sample) {
580  const TH1 *hist = self.GetW2Hist(sample);
581 
582  int Dimension = self.GetNDim(sample);
583 
584  if (Dimension == 1) {
585  // 1D histogram
586  const auto [contents, edgesX] = TH1ToNumpy(hist);
587  const auto edgesY = py::array_t<M3::float_t>();
588  return py::make_tuple(contents, edgesX, edgesY);
589  } else if (Dimension == 2) {
590 
591  const TH2Poly *hist2poly = dynamic_cast<const TH2Poly *>(hist);
592  if (hist2poly) {
594  throw std::runtime_error("pyMaCh3 can't do non-uniform binning for now :(");
595  }
596 
597  // 2D histogram - cast to TH2
598  const TH2 *hist2d = dynamic_cast<const TH2 *>(hist);
599  if (!hist2d) {
600  throw std::runtime_error("Failed to cast to TH2");
601  }
602  const auto [contents, edgesX, edgesY] = TH2ToNumpy(hist2d);
603  return py::make_tuple(contents, edgesX, edgesY);
604  } else {
608  throw std::invalid_argument("Dimension must be 1 or 2");
609  }
610  },
611  py::arg("sample"),
612  "Get W2 histogram as numpy arrays.\n"
613  "For 1D: Returns (contents, edges)\n"
614  "For 2D: Returns (contents, edgesX, edgesY)\n"
615  "where contents is shape (nbinsY, nbinsX) for 2D");
616 
617  /* Not sure if this will be needed in future versions of MaCh3 so leaving commented for now
618  py::class_<fdmc_base>(m_samples, "MCstruct")
619  .def(py::init())
620 
621  // Because a lot of the variables in fdmc_base use c style arrays,
622  // we need to provide some setter functions to be able to set them using more
623  // "pythony" objects, e.g. lists and numpy arrays
624  .def(
625  "set_event_variable_values",
626  [](fdmc_base &self, int dim, py::array_t<M3::float_t, py::array::c_style> &array)
627  {
628  py::buffer_info bufInfo = array.request();
629 
630  if ( dim > 2 )
631  throw MaCh3Exception(__FILE__, __LINE__, "Currently only dimensions of 1 or 2 are supported sorry :(");
632 
633  if ( bufInfo.ndim != 1 )
634  throw MaCh3Exception(__FILE__, __LINE__, "Number of dimensions in parameter array must be one if setting only one of the event variable arrays!");
635 
636  if( dim ==1 )
637  self.x_var = array.data();
638 
639  else if ( dim == 2)
640  self.y_var = array.data();
641  }
642  )
643  ;
644  */
645 }
@ kNTestStatistics
Number of test statistics.
@ kPearson
Standard Pearson likelihood .
@ kBarlowBeeston
Barlow-Beeston () following Conway approximation ()
@ kIceCube
Based on .
@ kDembinskiAbdelmotteleb
Based on .
@ kPoisson
Standard Poisson likelihood .
As SampleHandlerBase is an abstract base class we have to do some gymnastics to get it to get it into...
Definition: samples.h:314
void SetupMC() override
Function which translates experiment struct into core struct.
Definition: samples.h:382
void InititialiseData() override
Function responsible for loading data from file or loading from file.
Definition: samples.h:372
void CleanMemoryBeforeFit() override
Allow to clean not used memory before fit starts.
Definition: samples.h:331
void Init() override
Initialise any variables that your experiment specific SampleHandler needs.
Definition: samples.h:351
int SetupExperimentMC() override
Experiment specific setup, returns the number of events which were loaded.
Definition: samples.h:362
const double * GetPointerToKinematicParameter(int, int) const override
Definition: samples.h:402
void SetupSplines() override
initialise your splineXX object and then use InitialiseSplineObject to conviently setup everything up
Definition: samples.h:340
double ReturnKinematicParameter(int, int) const override
Definition: samples.h:391
void RegisterFunctionalParameters() override
HH - a experiment-specific function where the maps to actual functions are set up.
Definition: samples.h:413
void AddAdditionalWeightPointers() override
DB Function to determine which weights apply to which types of samples.
Definition: samples.h:320
EW: As SampleHandlerBase is an abstract base class we have to do some gymnastics to get it to get it ...
Definition: samples.h:100
void Reweight() override
Definition: samples.h:135
std::string GetKinVarName(const int iSample, const int Dimension) const override
Return Kinematic Variable name for specified sample and dimension for example "Reconstructed_Neutrino...
Definition: samples.h:177
std::unique_ptr< TH2 > Get2DVarHist(const int iSample, const std::string &ProjectionVarX, const std::string &ProjectionVarY, const std::vector< KinematicCut > &EventSelectionVec={}, const int WeightStyle=0, const std::vector< KinematicCut > &SubEventSelectionVec={}) override
Definition: samples.h:276
std::unique_ptr< TH1 > Get1DVarHistByModeAndChannel(const int iSample, const std::string &ProjectionVar_Str, const int kModeToFill=-1, const int kChannelToFill=-1, const int WeightStyle=0) override
Definition: samples.h:235
std::vector< double > ReturnKinematicParameterBinning(const int Sample, const std::string &KinematicParameter) const override
Return the binning used to draw a kinematic parameter.
Definition: samples.h:188
TH1 * GetDataHist(const int Sample) override
Get Data histogram.
Definition: samples.h:198
void CleanMemoryBeforeFit() override
Allow to clean not used memory before fit starts.
Definition: samples.h:157
std::string GetSampleTitle(const int iSample) const override
Definition: samples.h:115
double GetSampleLikelihood(const int iSample) const override
Definition: samples.h:146
int GetNOscChannels(const int iSample) const override
Definition: samples.h:125
std::string GetName() const override
Definition: samples.h:106
TH1 * GetMCHist(const int Sample) override
Get MC histogram.
Definition: samples.h:207
std::string GetFlavourName(const int iSample, const int iChannel) const override
Definition: samples.h:300
std::unique_ptr< TH1 > Get1DVarHist(const int iSample, const std::string &ProjectionVar, const std::vector< KinematicCut > &EventSelectionVec={}, const int WeightStyle=0, const std::vector< KinematicCut > &SubEventSelectionVec={}) override
Definition: samples.h:263
int GetNDim(const int Sample) const override
DB Function to differentiate 1D or 2D binning.
Definition: samples.h:291
std::unique_ptr< TH2 > Get2DVarHistByModeAndChannel(const int iSample, const std::string &ProjectionVar_StrX, const std::string &ProjectionVar_StrY, const int kModeToFill=-1, const int kChannelToFill=-1, const int WeightStyle=0) override
Definition: samples.h:248
void PrintRates(const bool DataOnly=false) override
Helper function to print rates for the samples with LLH.
Definition: samples.h:167
double GetLikelihood() const override
Definition: samples.h:225
TH1 * GetW2Hist(const int Sample) override
Get W2 histogram.
Definition: samples.h:216
Class responsible for handling implementation of samples used in analysis, reweighting and returning ...
SampleHandlerBase(std::string ConfigFileName, ParameterHandlerGeneric *xsec_cov, const std::shared_ptr< OscillationHandler > &OscillatorObj_=nullptr)
Constructor.
Class responsible for handling implementation of samples used in analysis, reweighting and returning ...
virtual double GetLikelihood() const =0
double GetTestStatLLH(const double data, const double mc, const double w2) const
Calculate test statistic for a single bin. Calculation depends on setting of fTestStatistic....
virtual void Reweight()=0
SampleHandlerInterface()
The main constructor.
void SetTestStatistic(TestStatistic testStat)
Set the test statistic to be used when calculating the binned likelihoods.
double float_t
Definition: Core.h:37
std::tuple< py::array_t< M3::float_t >, py::array_t< M3::float_t > > TH1ToNumpy(const TH1 *hist)
Definition: samples.h:17
std::tuple< py::array_t< M3::float_t >, py::array_t< M3::float_t >, py::array_t< M3::float_t > > TH2ToNumpy(const TH2 *hist)
Definition: samples.h:50
void initSamplesModule(py::module &m_samples)
Definition: samples.h:423