-
Notifications
You must be signed in to change notification settings - Fork 0
/
particle.cxx
411 lines (321 loc) · 11 KB
/
particle.cxx
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include "particle.h"
#include "particleType.h"
#include "resonanceType.h"
#include "TF1.h"
#include "TMath.h"
#include "TRandom.h"
//ClassImp(particle)
int particle::fNparticleType = 0;
particleType *particle::fParticleType[particle::fMaxNumParticleType];
particle::particle(){
fIparticle =0;
fPx = 0;
fPy = 0;
fPz = 0;
fMother = -1;
}
particle::particle(const particle& p)//:TObject(p)
{
fIparticle = p.fIparticle;
fPx = p.fPx;
fPy = p.fPy;
fPz = p.fPz;
fMother = -1;
}
particle::particle(int iparticle,double px,double py, double pz):
fPx(px),
fPy(py),
fPz(pz)
{
fMother = -1;
if(iparticle < fNparticleType && iparticle >=0){
fIparticle = iparticle;
}
else{
printf("Particle %d doesn't exist in the stack\n",iparticle);
fIparticle = -1;
}
}
particle::particle(const char *name,double px,double py, double pz):
fPx(px),
fPy(py),
fPz(pz)
{
fMother = -1;
int ip=FindParticle(name);
if(ip != -1){
fIparticle = ip;
}
else{
printf("Particle \"%s\" doesn't exist in the stack\n",name);
fIparticle = -1;
}
}
particle::~particle(){
}
int particle::FindParticle(const char *name){
for(int i=0;i<fNparticleType;i++){
const char *currentType = fParticleType[i]->GetParticleName();
int k=0;
while((currentType[k] == name[k]) && currentType[k] != '\0' && name[k] != '\0'){
k++;
}
if(currentType[k] == name[k]) return i;
}
return -1; // if no match
}
int particle::AddParticleType(const char *name,double mass,int charge,double width){
if(fNparticleType < fMaxNumParticleType){
int ip = FindParticle(name);
if(ip != -1){
printf("A particle with this name (\"%s\") already exists in the stack (nothing done)\n",name);
return 2;
}
if(width > 0) fParticleType[fNparticleType] = new resonanceType(name,mass,charge,width);
else fParticleType[fNparticleType] = new particleType(name,mass,charge);
fNparticleType++;
}
else{
printf("Stack is full because you have already inserted %i particles (nothing done)\n",fMaxNumParticleType);
return 1;
}
return 0;
}
void particle::PrintParticleType(){
if(fNparticleType){
printf("%-20s %5s\n","Particle Name","charge");
for(int i=0;i<fNparticleType;i++){
if(!fParticleType[i]->IsResonance())
fParticleType[i]->Print();
else
((resonanceType *) fParticleType[i])->Print();
}
printf("\n");
}
else
printf("No particle types defined\n");
}
void particle:: Print() const{
if(fIparticle!=-1)
printf("type=%i) %-20s p=(%7.3f,%7.3f,%7.3f)\n",fIparticle,fParticleType[fIparticle]->GetParticleName(),fPx,fPy,fPz);
else{
printf("particle not valid!!! ");
printf("p=(%7.3f,%7.3f,%7.3f)\n",fPx,fPy,fPz);
}
}
particle& particle::operator=(const particle &value){
if (&value==this)return *this; //protezione contro autoassegnamenti
fPx = value.fPx;
fPy = value.fPy;
fPz = value.fPz;
fIparticle = value.fIparticle;
return *this;
}
particle& particle::operator+=(const particle & value){
fPx += value.fPx;
fPy += value.fPy;
fPz += value.fPz;
return *this;
}
particle particle::operator+(const particle &value) const{
particle result(*this);
result += value;
return result;
}
void particle::ChangeParticleType(int iparticle){
if(iparticle >=0 && iparticle < fNparticleType) fIparticle = iparticle;
else printf("Particle %d doesn't exist\n",iparticle);
}
void particle::ChangeParticleType(const char *name){
int ip=FindParticle(name);
if(ip != -1){
fIparticle = ip;
}
else{
printf("Particle \"%s\" doesn't exist in the stack\n",name);
}
}
// extra methods
double particle::GetMass() const {
if(fIparticle > -1){
return fParticleType[fIparticle]->GetMass();
}
else{
return 0.0;
}
}
double particle::GetEnergy() const {
double mass = GetMass();
return sqrt(fPx*fPx + fPy*fPy + fPz*fPz + mass*mass);
}
void particle::Boost(double bx, double by, double bz)
{
double energy = GetEnergy();
//Boost this Lorentz vector
double b2 = bx*bx + by*by + bz*bz;
double gamma = 1.0 / sqrt(1.0 - b2);
double bp = bx*fPx + by*fPy + bz*fPz;
double gamma2 = b2 > 0 ? (gamma - 1.0)/b2 : 0.0;
fPx += gamma2*bp*bx + gamma*bx*energy;
fPy += gamma2*bp*by + gamma*by*energy;
fPz += gamma2*bp*bz + gamma*bz*energy;
}
int particle::Decay2body(particle &dau1,particle &dau2) const {
if(GetMass() == 0.0){
printf("Decayment cannot be preformed if mass is zero\n");
return 1;
}
double massMot = GetMass();
double massDau1 = dau1.GetMass();
double massDau2 = dau2.GetMass();
if(fIparticle > -1 && fParticleType[fIparticle]->IsResonance()){ // add width effect
double invnum = 1./RAND_MAX;
Float_t addmass = -100;
Int_t counter = 0;
while(massMot + addmass < massDau1 + massDau2){
//Float_t ran = tan(rand()*invnum*3.14159265358979312)*0.5;
Float_t ran = gRandom->Gaus(0,1); // Gaussian
addmass = ran*((resonanceType *) fParticleType[fIparticle])->GetWidth();
counter++;
if(counter > 100) printf("counter = %i\n",counter);
}
massMot += addmass;
}
if(massMot < massDau1 + massDau2){
printf("Decayment cannot be preformed because mass is too low in this channel\n");
return 2;
}
double pout = sqrt((massMot*massMot - (massDau1+massDau2)*(massDau1+massDau2))*(massMot*massMot - (massDau1-massDau2)*(massDau1-massDau2)))/massMot*0.5;
double norm = 6.283/RAND_MAX;
double phi = gRandom->Rndm();//rand()*norm;
double theta = TMath::ACos(1-2*gRandom->Rndm());//rand()*norm*0.5 - 1.57075;
dau1.SetP(pout*sin(theta)*cos(phi),pout*sin(theta)*sin(phi),pout*cos(theta));
dau2.SetP(-pout*sin(theta)*cos(phi),-pout*sin(theta)*sin(phi),-pout*cos(theta));
double energy = sqrt(fPx*fPx + fPy*fPy + fPz*fPz + massMot*massMot);
double bx = fPx/energy;
double by = fPy/energy;
double bz = fPz/energy;
dau1.Boost(bx,by,bz);
dau2.Boost(bx,by,bz);
return 0;
}
double particle::InvMass(particle & other) const{
double energy = GetEnergy() + other.GetEnergy();
double p2 = (fPx+other.GetPx())*(fPx+other.GetPx()) + (fPy+other.GetPy())*(fPy+other.GetPy()) + (fPz+other.GetPz())*(fPz+other.GetPz());
return sqrt(energy*energy - p2);
}
double particle::InvMass(particle & other,particle & other2) const{
double energy = GetEnergy() + other.GetEnergy()+ other2.GetEnergy();
double p2 = (fPx+other.GetPx()+other2.GetPx())*(fPx+other.GetPx()+other2.GetPx()) + (fPy+other.GetPy()+other2.GetPy())*(fPy+other.GetPy()+other2.GetPy()) + (fPz+other.GetPz()+other2.GetPz())*(fPz+other.GetPz()+other2.GetPz());
return sqrt(energy*energy - p2);
}
int particle::Decay2body(particle &dau1,particle &dau2,float mass,float px,float py,float pz) {
if(mass == 0.0){
printf("Decayment cannot be preformed if mass is zero\n");
return 1;
}
double massMot = mass;
double massDau1 = dau1.GetMass();
double massDau2 = dau2.GetMass();
if(massMot < massDau1 + massDau2){
printf("Decayment cannot be preformed because mass is too low in this channel\n");
return 2;
}
double pout = sqrt((massMot*massMot - (massDau1+massDau2)*(massDau1+massDau2))*(massMot*massMot - (massDau1-massDau2)*(massDau1-massDau2)))/massMot*0.5;
double norm = 6.283/RAND_MAX;
double phi = rand()*norm;
double theta = TMath::ACos(1-2*rand()*norm);//rand()*norm*0.5 - 1.57075;
// double theta = rand()*norm*0.5 - 1.57075;
dau1.SetP(pout*sin(theta)*cos(phi),pout*sin(theta)*sin(phi),pout*cos(theta));
dau2.SetP(-pout*sin(theta)*cos(phi),-pout*sin(theta)*sin(phi),-pout*cos(theta));
double energy = sqrt(px*px + py*py + pz*pz + massMot*massMot);
double bx = px/energy;
double by = py/energy;
double bz = pz/energy;
dau1.Boost(bx,by,bz);
dau2.Boost(bx,by,bz);
return 0;
}
TF1 *flambdac = NULL;
int particle::Decay3body(particle &dau1,particle &dau2,particle &dau3) const {
if(! flambdac){
flambdac = new TF1("flaambdac","pol4",0.35,1.9);
flambdac->SetParameter(0,-96.5869);
flambdac->SetParameter(1,430.868);
flambdac->SetParameter(2,-550.087);
flambdac->SetParameter(3,303.083);
flambdac->SetParameter(4,-62.7228);
flambdac->Print();
}
if(GetMass() == 0.0){
printf("Decayment cannot be preformed if mass is zero\n");
return 1;
}
double massMot = GetMass();
double massDau1 = dau1.GetMass();
double massDau2 = dau2.GetMass();
double massDau3 = dau3.GetMass();
double massLimit2 = (massMot-massDau2)*(massMot-massDau2);
double invnum = 1./RAND_MAX;
if(fIparticle > -1 && fParticleType[fIparticle]->IsResonance()){ // add width effect
double invnum = 1./RAND_MAX;
// float_t ran = tan(rand()*invnum*3.14159265358979312)*0.5;
Float_t ran = gRandom->Gaus(0,1); // Gaussian
massMot += ((resonanceType *) fParticleType[fIparticle])->GetWidth() * ran;
}
if(massMot < massDau1 + massDau2 + massDau3){
printf("Decayment cannot be preformed because mass is too low in this channel\n");
return 2;
}
double xran = rand()*invnum;
double mass13 = 0;
double mass12 = 0;
double mass23 = 0;
int counter = 0;
int status = 2;
while(status == 2 || mass13*mass13/massLimit2*mass13*mass13/massLimit2*mass13*mass13/massLimit2 < xran){//mass12*mass12/massLimit2 < xran){ // to assure a dalitz homogenous plot
xran = rand()*invnum;
mass12 = (massDau1 + massDau2)*(massDau1 + massDau2);
mass12 += ((massMot-massDau3)*(massMot-massDau3) - mass12) * xran;
mass12 = sqrt(mass12);
xran = rand()*invnum;
double mass13ch = (massDau1 + massDau3)*(massDau1 + massDau2);
mass13ch += ((massMot-massDau2)*(massMot-massDau2) - mass13) * xran;
mass13ch = sqrt(mass13ch);
mass12 = flambdac->GetRandom(0.4,1.9);
mass12 = sqrt(mass12);
// perform decay mass3 and mass12 and then mass12 decay
double pout = sqrt((massMot*massMot - (massDau3+mass12)*(massDau3+mass12))*(massMot*massMot - (massDau3-mass12)*(massDau3-mass12)))/massMot*0.5;
double norm = 6.283/RAND_MAX;
double phi = rand()*norm;
double theta = TMath::ACos(1-2*rand()*norm);//rand()*norm*0.5 - 1.57075;
// double theta = rand()*norm*0.5 - 1.57075;
dau3.SetP(pout*sin(theta)*cos(phi),pout*sin(theta)*sin(phi),pout*cos(theta));
status = particle::Decay2body(dau1,dau2,mass12,-pout*sin(theta)*cos(phi),-pout*sin(theta)*sin(phi),-pout*cos(theta));
mass13 = dau3.InvMass(dau1);
mass23 = dau3.InvMass(dau2);
xran = rand()*invnum;
counter ++;
// if(counter > 20)
// printf("Some problems in performing decay -> counter = %i (m12 =%f, m13=%f)\n",counter,mass12,mass13);
}
double energy = sqrt(fPx*fPx + fPy*fPy + fPz*fPz + massMot*massMot);
double bx = fPx/energy;
double by = fPy/energy;
double bz = fPz/energy;
dau1.Boost(bx,by,bz);
dau2.Boost(bx,by,bz);
dau3.Boost(bx,by,bz);
return 0;
}
double particle::GetEta() const {
double p = GetP();
return 0.5*log((p+fPz)/(p-fPz));
}
double particle::GetY() const {
double e = GetEnergy();
return 0.5*log((e+fPz)/(e-fPz));
}