MaCh3 2.2.1
Reference Guide
Loading...
Searching...
No Matches
SampleStructs.h
Go to the documentation of this file.
1#pragma once
2
3// C++ includes
4#include <set>
5#include <list>
6#include <unordered_map>
7
8// MaCh3 includes
10#include "Manager/MaCh3Logger.h"
11#include "Manager/Core.h"
12
14// ROOT include
15#include "TSpline.h"
16#include "TObjString.h"
17#include "TFile.h"
18#include "TF1.h"
19#include "TH2Poly.h"
20#include "TH1.h"
21// NuOscillator includes
22#include "Constants/OscillatorConstants.h"
24
32
33
34// *******************
36constexpr unsigned int str2int(const char* str, const int h = 0) {
37// *******************
38 return !str[h] ? 5381 : (str2int(str, h+1) * 33) ^ str[h];
39}
40
41
42// *****************
45// *****************
47 kTarget_C = 12,
48 kTarget_N = 14,
49 kTarget_O = 16,
54 kTarget_Pb = 207
55};
56
57// *****************
59inline std::string TargetMat_ToString(const TargetMat i) {
60// *****************
61 std::string name;
62
63 switch(i) {
64 case kTarget_H:
65 name = "Hydrogen";
66 break;
67 case kTarget_C:
68 name = "Carbon";
69 break;
70 case kTarget_N:
71 name = "Nitrogen";
72 break;
73 case kTarget_O:
74 name = "Oxygen";
75 break;
76 case kTarget_Al:
77 name = "Aluminium";
78 break;
79 case kTarget_Ar:
80 name = "Argon";
81 break;
82 case kTarget_Ti:
83 name = "Titanium";
84 break;
85 case kTarget_Fe:
86 name = "Iron";
87 break;
88 case kTarget_Pb:
89 name = "Lead";
90 break;
91 default:
92 name = "TargetMat_Undefined";
93 break;
94 }
95
96 return name;
97}
98
99// *****************
101enum NuPDG {
102// *****************
103 kNue = 12,
104 kNumu = 14,
105 kNutau = 16,
106 kNueBar = -12,
107 kNumuBar = -14,
108 kNutauBar = -16
110
120
121// **************************************************
124// **************************************************
125 std::string name = "";
126
127 switch(i) {
129 name = "Poisson";
130 break;
132 name = "Barlow-Beeston";
133 break;
135 name = "IceCube";
136 break;
138 name = "Pearson";
139 break;
141 name = "Dembinski-Abdelmotteleb";
142 break;
144 MACH3LOG_ERROR("kNTestStatistics is not a valid TestStatistic!");
145 throw MaCh3Exception(__FILE__, __LINE__);
146 default:
147 MACH3LOG_ERROR("UNKNOWN LIKELIHOOD SPECIFIED!");
148 MACH3LOG_ERROR("You gave test-statistic {}", static_cast<int>(i));
149 throw MaCh3Exception(__FILE__ , __LINE__ );
150 }
151 return name;
152}
153
154// ***************************
157// ***************************
164};
165
166// ***************************
169// ***************************
171 std::vector<double> XBinEdges;
173 std::vector<double> YBinEdges;
174
179
181 std::vector<double> rw_lower_xbinedge;
183 std::vector<double> rw_lower_lower_xbinedge;
185 std::vector<double> rw_upper_xbinedge;
187 std::vector<double> rw_upper_upper_xbinedge;
188
190 int FindXBin(const double XVar, const int NomXBin) const {
191 //DB Check to see if momentum shift has moved bins
192 //DB - First , check to see if the event is outside of the binning range and skip event if it is
193 if (XVar < XBinEdges[0] || XVar >= XBinEdges[nXBins]) {
194 return -1;
195 }
196 //DB - Second, check to see if the event is still in the nominal bin
197 else if (XVar < rw_upper_xbinedge[NomXBin] && XVar >= rw_lower_xbinedge[NomXBin]) {
198 return NomXBin;
199 }
200 //DB - Thirdly, check the adjacent bins first as Eb+CC+EScale shifts aren't likely to move an Erec more than 1bin width
201 //Shifted down one bin from the event bin at nominal
202 else if (XVar < rw_lower_xbinedge[NomXBin] && XVar >= rw_lower_lower_xbinedge[NomXBin]) {
203 return NomXBin-1;
204 }
205 //Shifted up one bin from the event bin at nominal
206 else if (XVar < rw_upper_upper_xbinedge[NomXBin] && XVar >= rw_upper_xbinedge[NomXBin]) {
207 return NomXBin+1;
208 }
209 //DB - If we end up in this loop, the event has been shifted outside of its nominal bin, but is still within the allowed binning range
210 else {
211 // KS: Perform binary search to find correct bin. We already checked if isn't outside of bounds
212 return static_cast<int>(std::distance(XBinEdges.begin(), std::upper_bound(XBinEdges.begin(), XBinEdges.end(), XVar)) - 1);
213 }
214 }
215};
216
217
218// ***************************
219// A handy namespace for variables extraction
220namespace MaCh3Utils {
221// ***************************
222
227 inline double GetMassFromPDG(const int PDG) {
228 // *****************************
229 switch (abs(PDG)) {
230 // Leptons
231 case 11: return 0.00051099895; // e
232 case 13: return 0.1056583755; // mu
233 case 15: return 1.77693; // tau
234 // Neutrinos
235 case 12:
236 case 14:
237 case 16:
238 return 0.;
239 // Photon
240 case 22: return 0.;
241 // Mesons
242 case 211: return 0.13957039; // pi_+/-
243 case 111: return 0.1349768; // pi_0
244 case 221: return 0.547862; // eta
245 case 311: // K_0
246 case 130: // K_0_L
247 case 310: // K_0_S
248 return 0.497611;
249 case 321: return 0.493677; // K_+/-
250 // Baryons
251 case 2112: return 0.939565; // n
252 case 2212: return 0.938272; // p
253 case 3122: return 1.115683; // lambda
254 case 3222: return 1.118937; // sig_+
255 case 3112: return 1.197449; // sig_-
256 case 3212: return 1.192642; // sig_0
257 // Nuclei
258 case 1000050110: return 10.255103; // Boron-11
259 case 1000060120: return 11.177929; // Carbon-12
260 case 1000070140: return 13.043781; // Nitrogen-14
261 case 1000080160: return 14.899169; // Oxygen-16
262 case 1000090190: return 17.696901; // Fluorine-19
263 case 1000110230: return 21.414835; // Sodium-23
264 case 1000130270: return 25.133144; // Aluminum-27
265 case 1000140280: return 26.060342; // Silicon-28
266 case 1000190390: return 36.294463; // Potassium-39
267 case 1000180400: return 37.224724; // Argon-40
268 case 1000220480: return 44.663224; // Titanium-48
269 case 1000300640: return 59.549619; // Zinc-64
270 default:
271 MACH3LOG_ERROR("Haven't got a saved mass for PDG: {}", PDG);
272 MACH3LOG_ERROR("Please implement me!");
273 throw MaCh3Exception(__FILE__, __LINE__);
274 } // End switch
275 MACH3LOG_ERROR("Warning, didn't catch a saved mass");
276 return 0;
277 }
278 // ***************************
279
280 // ***************************
284 inline int PDGToNuOscillatorFlavour(int NuPdg){
285 int NuOscillatorFlavour = M3::_BAD_INT_;
286 switch(std::abs(NuPdg)){
287 case NuPDG::kNue:
288 NuOscillatorFlavour = NuOscillator::kElectron;
289 break;
290 case NuPDG::kNumu:
291 NuOscillatorFlavour = NuOscillator::kMuon;
292 break;
293 case NuPDG::kNutau:
294 NuOscillatorFlavour = NuOscillator::kTau;
295 break;
296 default:
297 MACH3LOG_ERROR("Unknown Neutrino PDG {}, cannot convert to NuOscillator type", NuPdg);
298 break;
299 }
300
301 //This is very cheeky but if the PDG is negative then multiply the PDG by -1
302 // This is consistent with the treatment that NuOscillator expects as enums only
303 // exist for the generic matter flavour and not the anti-matter version
304 if(NuPdg < 0){NuOscillatorFlavour *= -1;}
305
306 return NuOscillatorFlavour;
307 }
308 // ***************************
309
310 // ***************************
312 inline std::string FormatDouble(const double value, const int precision) {
313 // ***************************
314 std::ostringstream oss;
315 oss << std::fixed << std::setprecision(precision) << value;
316 return oss.str();
317 }
318
319} // end MaCh3Utils namespace
#define _MaCh3_Safe_Include_Start_
KS: Avoiding warning checking for headers.
Definition: Core.h:106
#define _MaCh3_Safe_Include_End_
KS: Restore warning checking after including external headers.
Definition: Core.h:117
KS: Based on this https://github.com/gabime/spdlog/blob/a2b4262090fd3f005c2315dcb5be2f0f1774a005/incl...
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:25
NuPDG
Enum to track the incoming neutrino species.
@ kNutauBar
@ kNutau
@ kNumuBar
@ kNueBar
@ kNue
@ kNumu
std::string TargetMat_ToString(const TargetMat i)
Converted the Target Mat to a string.
Definition: SampleStructs.h:59
TargetMat
Enum to track the target material.
Definition: SampleStructs.h:44
@ kTarget_Fe
Iron (Atomic number 26)
Definition: SampleStructs.h:53
@ kTarget_C
Carbon 12 (Atomic number 6)
Definition: SampleStructs.h:47
@ kTarget_Al
Aluminum (Atomic number 13)
Definition: SampleStructs.h:50
@ kTarget_H
Hydrogen (Atomic number 1)
Definition: SampleStructs.h:46
@ kTarget_Ti
Titanium (Atomic number 22)
Definition: SampleStructs.h:52
@ kTarget_Ar
Argon (Atomic number 18)
Definition: SampleStructs.h:51
@ kTarget_N
Nitrogen (Atomic number 7)
Definition: SampleStructs.h:48
@ kTarget_Pb
Lead (Atomic number 82)
Definition: SampleStructs.h:54
@ kTarget_O
Oxygen 16 (Atomic number 8)
Definition: SampleStructs.h:49
TestStatistic
Make an enum of the test statistic that we're using.
@ 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 .
constexpr unsigned int str2int(const char *str, const int h=0)
KS: This is mad way of converting string to int. Why? To be able to use string with switch.
Definition: SampleStructs.h:36
std::string TestStatistic_ToString(TestStatistic i)
Convert a LLH type to a string.
Custom exception class for MaCh3 errors.
static constexpr const double _BAD_DOUBLE_
Default value used for double initialisation.
Definition: Core.h:43
static constexpr const int _BAD_INT_
Default value used for int initialisation.
Definition: Core.h:45
double GetMassFromPDG(const int PDG)
Return mass for given PDG.
std::string FormatDouble(const double value, const int precision)
Convert double into string for precision, useful for playing with yaml if you don't want to have in c...
int PDGToNuOscillatorFlavour(int NuPdg)
Convert from PDG flavour to NuOscillator type beware that in the case of anti-neutrinos the NuOscilla...
KS: Small struct used for applying kinematic cuts.
double UpperBound
Upper bound on which we apply cut.
double LowerBound
Lower bound on which we apply cut.
int ParamToCutOnIt
Index or enum value identifying the kinematic variable to cut on.
KS: Small struct storying info about used binning.
std::vector< double > YBinEdges
Vector to hold y-axis bin-edges.
std::vector< double > rw_upper_xbinedge
upper to check if Eb has moved the erec bin
size_t nXBins
Number of X axis bins in the histogram used for likelihood calculation.
std::vector< double > rw_lower_lower_xbinedge
lower to check if Eb has moved the erec bin
size_t nYBins
Number of Y axis bins in the histogram used for likelihood calculation.
std::vector< double > rw_lower_xbinedge
lower to check if Eb has moved the erec bin
std::vector< double > rw_upper_upper_xbinedge
upper to check if Eb has moved the erec bin
std::vector< double > XBinEdges
Vector to hold x-axis bin-edges.
int FindXBin(const double XVar, const int NomXBin) const
DB Find the relevant bin in the PDF for each event.