-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasePart.h
269 lines (184 loc) · 5.42 KB
/
BasePart.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// Compton Scattering and Pi0 Photoproduction Event Generator
// Designed for use with the MAMI A2 Geant4 Simulation
//
// Base particle class for use in the event generator
//
// Author - P. Martel
class BasePart {
protected:
TString sPartName;
void FillCM();
void FillLab();
public:
BasePart(TString, Float_t);
~BasePart();
TLorentzVector P4, P4CM;
Float_t Mass, Ener, KEner, Mom, Theta, Phi;
Float_t EnerCM, KEnerCM, MomCM, ThetaCM, PhiCM;
TH1F *hKEner, *hMom, *hTheta, *hPhi, *hMass;
void BoostCM(TVector3);
void BoostLab(TVector3);
void HistCM();
void HistLab();
void Reset();
void SetP4CM(Float_t, Float_t, Float_t, Float_t);
void SetP4Lab(Float_t, Float_t, Float_t, Float_t);
void SetP4CM(Float_t, Float_t);
void SetP4Lab(Float_t, Float_t);
void RotateCM(Float_t);
void RotateLab(Float_t);
void RotatePhi(Float_t);
TString WhichDet();
void WriteHists();
void FillNtuple(Float_t*, Int_t);
};
BasePart::BasePart(TString name, Float_t mass){
sPartName = name;
Mass = mass;
cout << ("Constructing "+sPartName) << endl;
// Create some histograms for testing
hKEner = new TH1F(sPartName+"KEner",sPartName+" Kinetic E (MeV)",100,0,500);
hKEner->GetXaxis()->SetTitle("Kinetic Energy (MeV)");
hKEner->GetYaxis()->SetTitle("# of Events");
hMom = new TH1F(sPartName+"Mom",sPartName+" Momentum (MeV)",100,0,500);
hMom->GetXaxis()->SetTitle("Momentum (MeV)");
hMom->GetYaxis()->SetTitle("# of Events");
hTheta = new TH1F(sPartName+"Theta",sPartName+" Theta (deg)",180,0,180);
hTheta->GetXaxis()->SetTitle("Theta (deg)");
hTheta->GetYaxis()->SetTitle("# of Events");
hPhi = new TH1F(sPartName+"Phi",sPartName+" Phi (deg)",360,-180,180);
hPhi->GetXaxis()->SetTitle("Phi (deg)");
hPhi->GetYaxis()->SetTitle("# of Events");
Int_t MassCent = ((TMath::Nint(Mass/50.))*50);
hMass = new TH1F(sPartName+"Mass",sPartName+" Mass (MeV)",60,MassCent-150,MassCent+150);
hMass->GetXaxis()->SetTitle("Mass (MeV)");
hMass->GetYaxis()->SetTitle("# of Events");
};
BasePart::~BasePart(){
cout << ("Deleting "+sPartName) << endl;
delete hKEner;
delete hMom;
delete hTheta;
delete hPhi;
delete hMass;
};
void BasePart::FillCM(){
// Fill CM variables using the already set Lorentz vector
EnerCM = P4CM.E();
KEnerCM = (EnerCM-Mass);
MomCM = P4CM.Rho();
ThetaCM = (P4CM.Theta()*kR2D);
PhiCM = (P4CM.Phi()*kR2D);
};
void BasePart::FillLab(){
// Fill lab variables using the already set Lorentz vector
Ener = P4.E();
KEner = (Ener-Mass);
Mom = P4.Rho();
Theta = (P4.Theta()*kR2D);
Phi = (P4.Phi()*kR2D);
};
void BasePart::BoostCM(TVector3 v){
// Boost INTO the CM frame, and fill its variables
P4CM = P4;
P4CM.Boost(v);
FillCM();
};
void BasePart::BoostLab(TVector3 v){
// Boost INTO the lab frame, and fill its variables
P4 = P4CM;
P4.Boost(v);
FillLab();
};
void BasePart::HistCM(){
// Fill CM histograms
hKEner->Fill(KEnerCM);
hMom->Fill(MomCM);
hTheta->Fill(ThetaCM);
hPhi->Fill(PhiCM);
hMass->Fill(Mass);
};
void BasePart::HistLab(){
// Fill lab histograms
hKEner->Fill(KEner);
hMom->Fill(Mom);
hTheta->Fill(Theta);
hPhi->Fill(Phi);
hMass->Fill(Mass);
};
void BasePart::Reset(){
// Reset CM and lab Lorentz vectors and variables
P4CM.SetPxPyPzE(0,0,0,0);
P4.SetPxPyPzE(0,0,0,0);
FillCM();
FillLab();
};
void BasePart::SetP4CM(Float_t ener,Float_t mom,Float_t theta,Float_t phi){
// Set the CM Lorentz Vector with the supplied values
P4CM.SetPxPyPzE(1,1,1,ener);
P4CM.SetRho(mom);
P4CM.SetTheta(theta*kD2R);
P4CM.SetPhi(phi*kD2R);
FillCM();
};
void BasePart::SetP4Lab(Float_t ener,Float_t mom,Float_t theta,Float_t phi){
// Set the lab Lorentz Vector with the supplied values
P4.SetPxPyPzE(1,1,1,ener);
P4.SetRho(mom);
P4.SetTheta(theta*kD2R);
P4.SetPhi(phi*kD2R);
FillLab();
};
void BasePart::SetP4CM(Float_t ener, Float_t mom){
// Set the CM Lorentz Vector with the supplied values
// providing an isotropic distribution
Float_t theta = acos(-1+2*gRandom->Rndm());
Float_t phi = kPI*(-1+2*gRandom->Rndm());
SetP4CM(ener, mom, (theta*kR2D), (phi*kR2D));
};
void BasePart::SetP4Lab(Float_t ener, Float_t mom){
// Set the lab Lorentz Vector with the supplied values
// providing an isotropic distribution
Float_t theta = acos(-1+2*gRandom->Rndm());
Float_t phi = kPI*(-1+2*gRandom->Rndm());
SetP4Lab(ener, mom, (theta*kR2D), (phi*kR2D));
};
void BasePart::RotateCM(Float_t phi){
// Rotate CM frame about z-axis by phi
P4CM.RotateZ(kD2R*phi);
FillCM();
};
void BasePart::RotateLab(Float_t phi){
// Rotate lab frame about z-axis by phi
P4.RotateZ(kD2R*phi);
FillLab();
};
void BasePart::RotatePhi(Float_t phi){
// Rotate both frames about z-axis by phi
RotateCM(phi);
RotateLab(phi);
};
TString BasePart::WhichDet(){
// Simple determination of which detector the particle will hit
TString sDet;
if(Theta<=20) sDet = "TAPS";
else if(Theta<=160) sDet = "CB";
else sDet = "Out";
return sDet;
};
void BasePart::WriteHists(){
// Write out the particle histograms
hKEner->Write();
hMom->Write();
hTheta->Write();
hPhi->Write();
hMass->Write();
};
void BasePart::FillNtuple(Float_t* var, Int_t index){
// Construct the Geant4 Ntuple for this particle
var[index++] = sin(Theta*kD2R)*cos(Phi*kD2R);
var[index++] = sin(Theta*kD2R)*sin(Phi*kD2R);
var[index++] = cos(Theta*kD2R);
var[index++] = Mom/1000;
var[index++] = Ener/1000;
};