includeROOT.h
Go to the documentation of this file.
1 // A selection of includes & inlines for analysis
2 
3 
4 
5 #ifndef includeROOT_h
6 #define includeROOT_h
7 
8 
9 
10 #include <iostream>
11 #include <fstream>
12 #include <sstream>
13 #include <vector>
14 #include <algorithm>
15 #include <cmath>
16 #include <cstdlib>
17 #include <sys/stat.h>
18 #include <ctime>
19 #include <string>
20 using std::cout; using std::endl;
21 using std::string; using std::vector;
22 #define TABL <<"\t"<<
23 
24 
25 // Includes for common ROOT things
26 #include "Rtypes.h" // Look in $ROOT_DIR/source/root-<version>/core/base/inc
27 #include "TMath.h"
28 #include "TVector3.h"
29 #include "TCut.h"
30 #include "TH1.h"
31 #include "TH2.h"
32 #include "TF1.h"
33 #include "TProfile.h"
34 #include "TGraph.h"
35 #include "TGraphErrors.h"
36 #include "TTree.h"
37 #include "TLeaf.h"
38 #include "TFile.h"
39 #include "TChain.h"
40 #include "TCanvas.h"
41 #include "TLegend.h"
42 #include "TStyle.h"
43 #include "TROOT.h"
44 #include "TMinuit.h"
45 
46 
47 
48 // Math made E-Z. Too E-Z
49 #define BIG 1.79768e+308
50 #define BIGINT 2147483647
51 #define BIGSIZE 18446744073709551615
52 
53 // Why isn't this in cmath?
54 #define M_PI 3.14159265358979323846
55 // std::min and std::max are in <algorithm>
56 #define NINT(a) ( int(floor((a)+0.5)) )
57 #define SGN(a) ( (a)<0 ? -1 : ( (a)>0 ? +1 : 0 ) )
58 
59 inline int SQR(int b) {return b*b;}
60 inline float SQR(float b) {return b*b;}
61 inline double SQR(double b) {return b*b;}
62 inline long double SQR(long double b) {return b*b;}
63 
64 inline int CUBE(int b) {return b*b*b;}
65 inline float CUBE(float b) {return b*b*b;}
66 inline double CUBE(double b) {return b*b*b;}
67 inline long double CUBE(long double b) {return b*b*b;}
68 
69 inline int QUAD(int b) {int p = b*b; return p*p;}
70 inline float QUAD(float b) {float p = b*b; return p*p;}
71 inline double QUAD(double b) {double p = b*b; return p*p;}
72 inline long double QUAD(long double b) {long double p = b*b; return p*p;}
73 
74 
75 
76 // std::hypot appeared in C++17.
77 inline double Qadd(double const x, double const y){
78  return std::hypot(x,y);
79 }
80 inline double Qadd(double const x, double const y, double const z){
81  double absX,absY,absZ;
82  absX = fabs(x); absY = fabs(y); absZ = fabs(z);
83  if ( absX>absY && absX>absZ ) return std::hypot(x,std::hypot(y,z));
84  if ( absY>absX && absY>absZ ) return std::hypot(y,std::hypot(x,z));
85  return Qadd(z,Qadd(x,y));
86 }
87 inline double Qsub(double const x, double const y) {
88  if (std::fabs(x) < std::fabs(y)) {
89  std::cout << "Fatality in Qsub(double,double): Invalid arguments";
90  std::cout << std::endl;
91  std::exit(1);
92  }
93  long double x2 = x*x; long double y2 = y*y;
94  return double(std::sqrt( x2 - y2 ));
95 }
96 
97 
98 
99 // Primitive earth algorithm for uncertainty in binomial-distributed variables
100 inline double binerr(double const passed, double const tested) {
101  // Garbage input
102  if ((passed<0) || (tested<=0) || (passed>tested)) {
103  std::cout << "Fatality in binerr(double,double): Invalid arguments ";
104  std::cout << passed << "/" << tested << std::endl;
105  std::exit(1);
106  }
107  double err;
108  // Fairly ad-hoc statistical uncertainties for low stats
109  if ( tested==1.0 ) {
110  err = 0.393;
111  } else if ( passed==0.0 || passed==tested ) {
112  err = 0.421 / pow(tested,0.94);
113  } else {
114  err = std::sqrt( passed*(tested-passed)/tested );
115  }
116  err /= tested;
117  return err;
118 }
119 
120 
121 
122 // A string for std::cout that is a ratio and its binomial uncertainty
123 char* stringEffErr(int num, int den) {
124  // Yea, its a memory leak. Fight me.
125  char* temp = new char[32];
126  double rat = 1000.0*double(num)/double(den);
127  double err = 1000.0*binerr(double(num),double(den));
128 // Assuming UTF-8 encoding on your terminal or whatever
129  sprintf(temp,"%5.2f %c%c %5.2f m%c%c", rat, 0xC2,0xB1, err, 0xC2,0xB0);
130  return temp;
131 }
132 
133 
134 
135 // Yea does that file even exist? Probably doesn't work for xroot access.
136 inline bool filehamna(const std::string& filename) {
137  struct stat buf;
138  int retval = stat(filename.c_str(), &buf);
139  if (retval==0 && !S_ISREG(buf.st_mode)) {
140  cout << "filehamna(string) : Not a regular file" << endl;
141  }
142  // -1 is the error condition, meaning that the file isn't there
143  return (retval == -1);
144 }
145 
146 
147 
148 int const nothingPDG = 0;
149 int const protonPDG = 2212;
150 int const neutronPDG = 2112;
151 int const electronPDG = 11; // Means an electron not a positron
152 int const muonPDG = 13;
153 int const nuePDG = 12;
154 int const numuPDG = 14;
155 int const pichPDG = 211; // Means a pi+; pi- is -211
156 int const pi0PDG = 111;
157 int const etaPDG = 221;
158 int const etaPRPDG = 331;
159 int const rho0PDG = 113;
160 int const rhoCHPDG = 213;
161 int const KchPDG = 321; // Means a K+; K- is -321
162 int const KlongPDG = 130;
163 int const KshortPDG = 310;
164 int const KzeroPDG = 311;
165 int const gammaPDG = 22;
166 
167 int const ArgonPDG = 1000180400;
168 int const CarbonPDG = 1000060120;
169 int const DeuteronPDG = 1000010020;
170 int const HeliumPDG = 1000020040;
171 
172 int const lambdaPDG = 3122;
173 int const sigmaM_PDG = 3112;
174 int const sigma0_PDG = 3212;
175 int const sigmaP_PDG = 3222;
176 int const cascadeM_PDG = 3312;
177 int const cascade0_PDG = 3322;
178 
179 
180 
181 double const Melectron = 0.00051100; // in GeV
182 double const Mmuon = 0.10565837;
183 double const Mpi0 = 0.13497770;
184 double const Meta = 0.547862;
185 double const MetaPR = 0.95778;
186 double const Mrho = 0.77526;
187 double const MpiCH = 0.13957061;
188 double const MchK = 0.493677;
189 double const MneuK = 0.497611;
190 double const Mprot = 0.93827208;
191 double const Mneut = 0.93956541;
192 double const Mlambda = 1.115683;
193 double const MsigmaNeg = 1.197449;
194 double const Msigma0 = 1.192642;
195 double const MsigmaPos = 1.18937;
196 double const Mcasc0 = 1.31486;
197 double const McascNeg = 1.32171;
198 
199 
200 
201 // Mass of this particle, in GeV, from PDG code. Negative value
202 // means unstable particle!
203 double massPDG(int PDGcode) {
204 
205  if (PDGcode > 1000000000) {
206  int A = (PDGcode -1000000000)/10;
207  A = A%1000;
208  return A * (39.948 / 40.0);
209  }
210 
211  switch (PDGcode){
212  case +electronPDG: case -electronPDG:
213  return Melectron;
214  case +muonPDG: case -muonPDG:
215  return Mmuon;
216  case gammaPDG:
217  case +nuePDG: case -nuePDG:
218  case +numuPDG: case -numuPDG:
219  return 0.000000;
220  case +pichPDG: case -pichPDG:
221  return Mpi0;
222  case rho0PDG:
223  case +rhoCHPDG: case -rhoCHPDG:
224  return Mrho;
225  case +KchPDG: case -KchPDG:
226  return MpiCH;
227  case +protonPDG: case -protonPDG:
228  return Mprot;
229  case pi0PDG:
230  return Mpi0;
231  case etaPDG:
232  return Meta;
233  case etaPRPDG:
234  return MetaPR;
235  case KlongPDG:
236  return MneuK;
237  case +neutronPDG: case -neutronPDG:
238  return Mneut;
239 
240  case KshortPDG:
241  case +KzeroPDG: case -KzeroPDG:
242  return -MneuK;
243  case +lambdaPDG: case -lambdaPDG:
244  return -Mlambda;
245  case +sigmaM_PDG: case -sigmaM_PDG:
246  return -MsigmaNeg;
247  case +sigma0_PDG: case -sigma0_PDG:
248  return Msigma0;
249  case +sigmaP_PDG: case -sigmaP_PDG:
250  return -MsigmaPos;
251  case +cascade0_PDG: case -cascade0_PDG:
252  return -Mcasc0;
253  case +cascadeM_PDG: case -cascadeM_PDG:
254  return -McascNeg;
255 
256  default:
257  // Should be some wide, fast-decaying resonance.
258  return -2468;
259  }
260 }
261 
262 
263 
264 // Is this particle charged, from the PDG code
265 bool chargedPDG(int PDGcode) {
266 
267  if (PDGcode > 1000000000) return true;
268 
269  switch (PDGcode){
270  case +electronPDG: case -electronPDG:
271  case +muonPDG: case -muonPDG:
272  case +pichPDG: case -pichPDG:
273  case +rhoCHPDG: case -rhoCHPDG:
274  case +KchPDG: case -KchPDG:
275  case +protonPDG: case -protonPDG:
276  case +sigmaM_PDG: case -sigmaM_PDG:
277  case +sigmaP_PDG: case -sigmaP_PDG:
278  case +cascadeM_PDG: case -cascadeM_PDG:
279  return true;
280 
281  case gammaPDG:
282  case +nuePDG: case -nuePDG:
283  case +numuPDG: case -numuPDG:
284  case pi0PDG: case rho0PDG:
285  case etaPDG: case etaPRPDG:
286  case KlongPDG: case KshortPDG:
287  case +KzeroPDG: case -KzeroPDG:
288  case +neutronPDG: case -neutronPDG:
289  case +lambdaPDG: case -lambdaPDG:
290  case +sigma0_PDG: case -sigma0_PDG:
291  case +cascade0_PDG: case -cascade0_PDG:
292  return false;
293 
294  default:
295  // Should be some wide, fast-decaying resonance.
296  return false;
297  }
298 }
299 
300 
301 
302 #endif
double Qsub(double const x, double const y)
Definition: includeROOT.h:87
int const etaPDG
Definition: includeROOT.h:157
double binerr(double const passed, double const tested)
Definition: includeROOT.h:100
int const cascade0_PDG
Definition: includeROOT.h:177
int const HeliumPDG
Definition: includeROOT.h:170
bool chargedPDG(int PDGcode)
Definition: includeROOT.h:265
int const DeuteronPDG
Definition: includeROOT.h:169
int const cascadeM_PDG
Definition: includeROOT.h:176
double const Msigma0
Definition: includeROOT.h:194
int const pichPDG
Definition: includeROOT.h:155
std::string string
Definition: nybbler.cc:12
double const MneuK
Definition: includeROOT.h:189
int const rhoCHPDG
Definition: includeROOT.h:160
double const MchK
Definition: includeROOT.h:188
int QUAD(int b)
Definition: includeROOT.h:69
constexpr T pow(T x)
Definition: pow.h:72
double const MsigmaPos
Definition: includeROOT.h:195
struct vector vector
double Qadd(double const x, double const y)
Definition: includeROOT.h:77
int const KzeroPDG
Definition: includeROOT.h:164
int const protonPDG
Definition: includeROOT.h:149
double const Mrho
Definition: includeROOT.h:186
string filename
Definition: train.py:213
int const nuePDG
Definition: includeROOT.h:153
double const Meta
Definition: includeROOT.h:184
bool filehamna(const std::string &filename)
Definition: includeROOT.h:136
int const etaPRPDG
Definition: includeROOT.h:158
int const gammaPDG
Definition: includeROOT.h:165
std::enable_if_t< std::is_arithmetic_v< T >, T > hypot(T x, T y)
Definition: hypot.h:60
double const McascNeg
Definition: includeROOT.h:197
int const rho0PDG
Definition: includeROOT.h:159
int SQR(int b)
Definition: includeROOT.h:59
int const lambdaPDG
Definition: includeROOT.h:172
int const KlongPDG
Definition: includeROOT.h:162
int const ArgonPDG
Definition: includeROOT.h:167
double const MetaPR
Definition: includeROOT.h:185
int const sigmaP_PDG
Definition: includeROOT.h:175
double const Mcasc0
Definition: includeROOT.h:196
double const Melectron
Definition: includeROOT.h:181
double const Mmuon
Definition: includeROOT.h:182
p
Definition: test.py:223
int const pi0PDG
Definition: includeROOT.h:156
char * stringEffErr(int num, int den)
Definition: includeROOT.h:123
void err(const char *fmt,...)
Definition: message.cpp:226
int const CarbonPDG
Definition: includeROOT.h:168
int const neutronPDG
Definition: includeROOT.h:150
int const KshortPDG
Definition: includeROOT.h:163
double massPDG(int PDGcode)
Definition: includeROOT.h:203
double const Mpi0
Definition: includeROOT.h:183
double const Mprot
Definition: includeROOT.h:190
int const numuPDG
Definition: includeROOT.h:154
static bool * b
Definition: config.cpp:1043
int const sigma0_PDG
Definition: includeROOT.h:174
double const MsigmaNeg
Definition: includeROOT.h:193
list x
Definition: train.py:276
int const nothingPDG
Definition: includeROOT.h:148
double const Mlambda
Definition: includeROOT.h:192
int const sigmaM_PDG
Definition: includeROOT.h:173
int const muonPDG
Definition: includeROOT.h:152
int const electronPDG
Definition: includeROOT.h:151
double const Mneut
Definition: includeROOT.h:191
int CUBE(int b)
Definition: includeROOT.h:64
int const KchPDG
Definition: includeROOT.h:161
QTextStream & endl(QTextStream &s)
double const MpiCH
Definition: includeROOT.h:187