forked from alisw/AliRoot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AliGenMC.cxx
501 lines (454 loc) · 12.7 KB
/
AliGenMC.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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
/**************************************************************************
* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
* *
* Author: The ALICE Off-line Project. *
* Contributors are mentioned in the code where appropriate. *
* *
* Permission to use, copy, modify and distribute this software and its *
* documentation strictly for non-commercial purposes is hereby granted *
* without fee, provided that the above copyright notice appears in all *
* copies and that both the copyright notice and this permission notice *
* appear in the supporting documentation. The authors make no claims *
* about the suitability of this software for any purpose. It is *
* provided "as is" without express or implied warranty. *
**************************************************************************/
/* $Id$ */
// Base class for generators using external MC generators.
// For example AliGenPythia using Pythia.
// Provides basic functionality: setting of kinematic cuts on
// decay products and particle selection.
#include <TClonesArray.h>
#include <TMath.h>
#include <TPDGCode.h>
#include <TParticle.h>
#include <TLorentzVector.h>
#include <TVector3.h>
#include "AliGenMC.h"
#include "AliGenEventHeader.h"
#include "AliRun.h"
#include "AliGeometry.h"
#include "AliDecayer.h"
#include "AliLog.h"
ClassImp(AliGenMC)
AliGenMC::AliGenMC()
:AliGenerator(),
fParticles("TParticle", 1000),
fParentSelect(8),
fChildSelect(8),
fCutOnChild(0),
fChildPtMin(0.),
fChildPtMax(1.e10),
fChildPMin(0.),
fChildPMax(1.e10),
fChildPhiMin(0.),
fChildPhiMax(2. * TMath::Pi()),
fChildThetaMin(0.),
fChildThetaMax(TMath::Pi()),
fChildYMin(-12.),
fChildYMax(12.),
fXingAngleX(0.),
fXingAngleY(0.),
fForceDecay(kAll),
fMaxLifeTime(1.e-15),
fDyBoost(0.),
fSpace2TimeCoeff(1.),
fTime2SpaceCoeff(1.),
fGeometryAcceptance(0),
fPdgCodeParticleforAcceptanceCut(0),
fNumberOfAcceptedParticles(0),
fNprimaries(0)
{
// Default Constructor
fAProjectile = 1;
fZProjectile = 1;
fATarget = 1;
fZTarget = 1;
fProjectile = "P";
fTarget = "P";
}
AliGenMC::AliGenMC(Int_t npart)
:AliGenerator(npart),
fParticles("TParticle", 1000),
fParentSelect(8),
fChildSelect(8),
fCutOnChild(0),
fChildPtMin(0.),
fChildPtMax(1.e10),
fChildPMin(0.),
fChildPMax(1.e10),
fChildPhiMin(0.),
fChildPhiMax(2. * TMath::Pi()),
fChildThetaMin(0.),
fChildThetaMax(TMath::Pi()),
fChildYMin(-12.),
fChildYMax(12.),
fXingAngleX(0.),
fXingAngleY(0.),
fForceDecay(kAll),
fMaxLifeTime(1.e-15),
fDyBoost(0.),
fSpace2TimeCoeff(1.),
fTime2SpaceCoeff(1.),
fGeometryAcceptance(0),
fPdgCodeParticleforAcceptanceCut(0),
fNumberOfAcceptedParticles(0),
fNprimaries(0)
{
// Constructor
//
fAProjectile = 1;
fZProjectile = 1;
fATarget = 1;
fZTarget = 1;
fProjectile = "P";
fTarget = "P";
for (Int_t i=0; i<8; i++) fParentSelect[i]=fChildSelect[i]=0;
}
AliGenMC::~AliGenMC()
{
// Destructor
}
void AliGenMC::Init()
{
//
// Initialization
switch (fForceDecay) {
case kBSemiElectronic:
case kSemiElectronic:
case kDiElectron:
case kBJpsiDiElectron:
case kBPsiPrimeDiElectron:
case kElectronEM:
case kDiElectronEM:
fChildSelect[0] = kElectron;
break;
case kHardMuons:
case kBSemiMuonic:
case kDSemiMuonic:
case kSemiMuonic:
case kDiMuon:
case kJpsiDiMuon:
case kBJpsiDiMuon:
case kBPsiPrimeDiMuon:
case kPiToMu:
case kKaToMu:
case kWToMuon:
case kWToCharmToMuon:
case kZDiMuon:
case kZDiElectron:
fChildSelect[0]=kMuonMinus;
break;
case kWToCharm:
break;
case kHadronicD:
case kHadronicDWithout4Bodies:
case kHadronicDWithV0:
case kHadronicDWithout4BodiesWithV0:
fChildSelect[0]=kPiPlus;
fChildSelect[1]=kKPlus;
break;
case kPhiKK:
fChildSelect[0]=kKPlus;
break;
case kBJpsi:
case kBJpsiUndecayed:
fChildSelect[0]= 443;
break;
case kChiToJpsiGammaToMuonMuon:
fChildSelect[0]= 22;
fChildSelect[1]= 13;
break;
case kChiToJpsiGammaToElectronElectron:
fChildSelect[0]= 22;
fChildSelect[1]= 11;
break;
case kLambda:
fChildSelect[0]= kProton;
fChildSelect[1]= 211;
break;
case kPsiPrimeJpsiDiElectron:
fChildSelect[0]= 211;
fChildSelect[1]= 11;
break;
case kGammaEM:
fChildSelect[0] = kGamma;
break;
case kOmega:
case kAllEM:
case kAll:
case kAllMuonic:
case kNoDecay:
case kNoDecayHeavy:
case kNoDecayBeauty:
case kNeutralPion:
case kBeautyUpgrade:
break;
case kLcpKpi:
fChildSelect[0] = kProton;
fChildSelect[1] = kKPlus;
fChildSelect[2] = kPiPlus;
break;
case kLcpK0S:
fChildSelect[0] = kProton;
fChildSelect[1] = kK0;
break;
}
if (fZTarget != 0 && fAProjectile != 0)
{
fDyBoost = - 0.5 * TMath::Log(Double_t(fZProjectile) * Double_t(fATarget) /
(Double_t(fZTarget) * Double_t(fAProjectile)));
}
}
Bool_t AliGenMC::ParentSelected(Int_t ip) const
{
// True if particle is in list of parent particles to be selected
for (Int_t i=0; i<8; i++)
{
if (fParentSelect.At(i) == ip) return kTRUE;
}
return kFALSE;
}
Bool_t AliGenMC::ChildSelected(Int_t ip) const
{
// True if particle is in list of decay products to be selected
for (Int_t i=0; i<5; i++)
{
if (fChildSelect.At(i) == ip) return kTRUE;
}
return kFALSE;
}
Bool_t AliGenMC::KinematicSelection(const TParticle *particle, Int_t flag) const
{
// Perform kinematic selection
Double_t pz = particle->Pz();
Double_t pt = particle->Pt();
Double_t p = particle->P();
Double_t theta = particle->Theta();
Double_t mass = particle->GetCalcMass();
Double_t mt2 = pt * pt + mass * mass;
Double_t phi = particle->Phi();
Double_t e = particle->Energy();
if (e == 0.)
e = TMath::Sqrt(p * p + mass * mass);
Double_t y, y0;
if (TMath::Abs(pz) < e) {
y = 0.5*TMath::Log((e+pz)/(e-pz));
} else {
y = 1.e10;
}
if (mt2) {
y0 = 0.5*TMath::Log((e+TMath::Abs(pz))*(e+TMath::Abs(pz))/mt2);
} else {
if (TMath::Abs(y) < 1.e10) {
y0 = y;
} else {
y0 = 1.e10;
}
}
y = (pz < 0) ? -y0 : y0;
if (flag == 0) {
//
// Primary particle cuts
//
// transverse momentum cut
if (pt > fPtMax || pt < fPtMin) {
// printf("\n failed pt cut %f %f %f \n",pt,fPtMin,fPtMax);
return kFALSE;
}
//
// momentum cut
if (p > fPMax || p < fPMin) {
// printf("\n failed p cut %f %f %f \n",p,fPMin,fPMax);
return kFALSE;
}
//
// theta cut
if (theta > fThetaMax || theta < fThetaMin) {
// printf("\n failed theta cut %f %f %f \n",theta,fThetaMin,fThetaMax);
return kFALSE;
}
//
// rapidity cut
if (y > fYMax || y < fYMin) {
// printf("\n failed y cut %f %f %f \n",y,fYMin,fYMax);
return kFALSE;
}
//
// phi cut
if (phi > fPhiMax || phi < fPhiMin) {
// printf("\n failed phi cut %f %f %f \n",phi,fPhiMin,fPhiMax);
return kFALSE;
}
} else {
//
// Decay product cuts
//
// transverse momentum cut
if (pt > fChildPtMax || pt < fChildPtMin) {
// printf("\n failed pt cut %f %f %f \n",pt,fChildPtMin,fChildPtMax);
return kFALSE;
}
//
// momentum cut
if (p > fChildPMax || p < fChildPMin) {
// printf("\n failed p cut %f %f %f \n",p,fChildPMin,fChildPMax);
return kFALSE;
}
//
// theta cut
if (theta > fChildThetaMax || theta < fChildThetaMin) {
// printf("\n failed theta cut %f %f %f \n",theta,fChildThetaMin,fChildThetaMax);
return kFALSE;
}
//
// rapidity cut
if (y > fChildYMax || y < fChildYMin) {
// printf("\n failed y cut %f %f %f \n",y,fChildYMin,fChildYMax);
return kFALSE;
}
//
// phi cut
if (phi > fChildPhiMax || phi < fChildPhiMin) {
// printf("\n failed phi cut %f %f %f \n",phi,fChildPhiMin,fChildPhiMax);
return kFALSE;
}
}
return kTRUE;
}
Bool_t AliGenMC::CheckAcceptanceGeometry(Int_t np, TClonesArray* particles)
{
// Check the geometrical acceptance for particle.
Bool_t check ;
Int_t numberOfPdgCodeParticleforAcceptanceCut = 0;
Int_t numberOfAcceptedPdgCodeParticleforAcceptanceCut = 0;
TParticle * particle;
Int_t i;
for (i = 0; i < np; i++) {
particle = (TParticle *) particles->At(i);
if( TMath::Abs( particle->GetPdgCode() ) == TMath::Abs( fPdgCodeParticleforAcceptanceCut ) ) {
numberOfPdgCodeParticleforAcceptanceCut++;
if (fGeometryAcceptance->Impact(particle)) numberOfAcceptedPdgCodeParticleforAcceptanceCut++;
}
}
if ( numberOfAcceptedPdgCodeParticleforAcceptanceCut > (fNumberOfAcceptedParticles-1) )
check = kTRUE;
else
check = kFALSE;
return check;
}
Int_t AliGenMC::CheckPDGCode(Int_t pdgcode) const
{
//
// If the particle is in a diffractive state, then take action accordingly
switch (pdgcode) {
case 91:
return 92;
case 110:
//rho_diff0 -- difficult to translate, return rho0
return 113;
case 210:
//pi_diffr+ -- change to pi+
return 211;
case 220:
//omega_di0 -- change to omega0
return 223;
case 330:
//phi_diff0 -- return phi0
return 333;
case 440:
//J/psi_di0 -- return J/psi
return 443;
case 2110:
//n_diffr -- return neutron
return 2112;
case 2210:
//p_diffr+ -- return proton
return 2212;
}
//non diffractive state -- return code unchanged
return pdgcode;
}
void AliGenMC::Boost()
{
//
// Boost cms into LHC lab frame
//
Double_t beta = TMath::TanH(fDyBoost);
Double_t gamma = 1./TMath::Sqrt((1.-beta)*(1.+beta));
Double_t gb = gamma * beta;
Double_t c = 299792458.;
Double_t c_1 = 1. / 299792458.;
// printf("\n Boosting particles to lab frame %f %f %f", fDyBoost, beta, gamma);
Int_t i;
Int_t np = fParticles.GetEntriesFast();
for (i = 0; i < np; i++)
{
TParticle* iparticle = (TParticle*) fParticles.At(i);
Double_t e = iparticle->Energy();
Double_t px = iparticle->Px();
Double_t py = iparticle->Py();
Double_t pz = iparticle->Pz();
Double_t eb = gamma * e - gb * pz;
Double_t pzb = -gb * e + gamma * pz;
iparticle->SetMomentum(px, py, pzb, eb);
Double_t ct = iparticle->T() * c;
Double_t vx = iparticle->Vx();
Double_t vy = iparticle->Vy();
Double_t vz = iparticle->Vz();
Double_t ctb = gamma * ct - gb * vz * fSpace2TimeCoeff;
Double_t vzb = -gb * ct * fTime2SpaceCoeff + gamma * vz;
iparticle->SetProductionVertex(vx, vy, vzb, ctb * c_1);
}
}
void AliGenMC::BeamCrossAngle()
{
// Applies a boost in the y-direction in order to take into account the
// beam crossing angle
Double_t thetaPr0, pyPr2, pzPr2;
TVector3 beta;
thetaPr0 = fXingAngleY / 2.;
// Momentum of the CMS system
pyPr2 = TMath::Sqrt(fEnergyCMS * fEnergyCMS/ 4 - 0.938 * 0.938) * TMath::Sin(thetaPr0);
pzPr2 = TMath::Sqrt(fEnergyCMS * fEnergyCMS/ 4 - 0.938 * 0.938) * TMath::Cos(thetaPr0);
TLorentzVector proj1Vect, proj2Vect, projVect;
proj1Vect.SetPxPyPzE(0., pyPr2, pzPr2, fEnergyCMS/2);
proj2Vect.SetPxPyPzE(0., pyPr2,-pzPr2, fEnergyCMS/2);
projVect = proj1Vect + proj2Vect;
beta=(1. / projVect.E()) * (projVect.Vect());
Int_t i;
Int_t np = fParticles.GetEntriesFast();
for (i = 0; i < np; i++)
{
TParticle* iparticle = (TParticle*) fParticles.At(i);
Double_t e = iparticle->Energy();
Double_t px = iparticle->Px();
Double_t py = iparticle->Py();
Double_t pz = iparticle->Pz();
TLorentzVector partIn;
partIn.SetPxPyPzE(px,py,pz,e);
partIn.Boost(beta);
iparticle->SetMomentum(partIn.Px(),partIn.Py(),partIn.Pz(),partIn.E());
}
}
void AliGenMC::AddHeader(AliGenEventHeader* header)
{
// Passes header either to the container or to gAlice
if (fContainer) {
header->SetName(fName);
fContainer->AddHeader(header);
} else {
if (gAlice) gAlice->SetGenEventHeader(header);
}
}
void AliGenMC::SetGeneratorUnitsForMeterSecond(double lengthC, double timeC)
{
// set scaling coeffs to convert length and time units used by generator to
// m and s. We store only their ratio, relevant for the Boost
if (timeC<1e-30 || lengthC<1e-30) {
AliFatal("Provided lenght and time units must be positive");
}
AliInfoF("Boost will scale length by %e and time by %e to obtain meter and second",lengthC,timeC);
fSpace2TimeCoeff = lengthC/timeC;
fTime2SpaceCoeff = timeC/lengthC;
}