| 1 |
// $Id: PamVMCPrimaryGenerator.cxx,v 1.0 2006/06/03 |
| 2 |
// |
| 3 |
|
| 4 |
#include <TVirtualMC.h> |
| 5 |
#include <TVirtualMCStack.h> |
| 6 |
#include <TPDGCode.h> |
| 7 |
#include <TDatabasePDG.h> |
| 8 |
#include <TParticlePDG.h> |
| 9 |
#include <TVector3.h> |
| 10 |
#include <TMath.h> |
| 11 |
|
| 12 |
#include "PamVMCPrimaryGenerator.h" |
| 13 |
|
| 14 |
ClassImp(PamVMCPrimaryGenerator) |
| 15 |
|
| 16 |
PamVMCPrimaryGenerator::PamVMCPrimaryGenerator(TVirtualMCStack* stack) |
| 17 |
: TObject(), |
| 18 |
fStack(stack), |
| 19 |
fPdg(kProton), |
| 20 |
fKinEnergy(0.05),//100 GeV |
| 21 |
fDirX(0.), |
| 22 |
fDirY(0.), |
| 23 |
fDirZ(-1.), |
| 24 |
fPolAngle(0.), |
| 25 |
fNofPrimaries(1) |
| 26 |
{ |
| 27 |
// Standard constructor |
| 28 |
|
| 29 |
} |
| 30 |
|
| 31 |
PamVMCPrimaryGenerator::PamVMCPrimaryGenerator() |
| 32 |
: TObject(), |
| 33 |
fStack(0), |
| 34 |
fPdg(0), |
| 35 |
fKinEnergy(0.), |
| 36 |
fDirX(0.), |
| 37 |
fDirY(0.), |
| 38 |
fDirZ(0.), |
| 39 |
fPolAngle(0.), |
| 40 |
fNofPrimaries(0) |
| 41 |
{ |
| 42 |
// Default constructor |
| 43 |
} |
| 44 |
|
| 45 |
PamVMCPrimaryGenerator::~PamVMCPrimaryGenerator() |
| 46 |
{ |
| 47 |
// Destructor |
| 48 |
} |
| 49 |
|
| 50 |
// private methods |
| 51 |
|
| 52 |
#include <Riostream.h> |
| 53 |
|
| 54 |
void PamVMCPrimaryGenerator::GeneratePrimary() |
| 55 |
{ |
| 56 |
// Add one primary particle to the user stack (derived from TVirtualMCStack). |
| 57 |
|
| 58 |
// Track ID (filled by stack) |
| 59 |
Int_t ntr; |
| 60 |
|
| 61 |
// Option: to be tracked |
| 62 |
Int_t toBeDone = 1; |
| 63 |
|
| 64 |
// Particle type |
| 65 |
Int_t pdg = fPdg; |
| 66 |
TParticlePDG* particlePDG = TDatabasePDG::Instance()->GetParticle(fPdg); |
| 67 |
|
| 68 |
// Position |
| 69 |
Double_t vx = 1.; |
| 70 |
Double_t vy = 1.; |
| 71 |
Double_t vz = 130.; |
| 72 |
Double_t tof = 0.; |
| 73 |
|
| 74 |
// Energy (in GeV) |
| 75 |
Double_t kinEnergy = fKinEnergy; |
| 76 |
Double_t mass = particlePDG->Mass(); |
| 77 |
Double_t e = mass + kinEnergy; |
| 78 |
|
| 79 |
// Particle momentum |
| 80 |
Double_t p0, px, py, pz; |
| 81 |
p0 = sqrt(e*e - mass*mass); |
| 82 |
px = p0 * fDirX; |
| 83 |
py = p0 * fDirY; |
| 84 |
pz = p0 * fDirZ; |
| 85 |
|
| 86 |
// Polarization |
| 87 |
TVector3 polar; |
| 88 |
// if ( fPdg == 50000050 ) { |
| 89 |
// TVector3 normal (1., 0., 0.); |
| 90 |
// TVector3 kphoton = TVector3(fDirX, fDirY, fDirZ); |
| 91 |
// TVector3 product = normal.Cross(kphoton); |
| 92 |
// Double_t modul2 = product*product; |
| 93 |
|
| 94 |
// TVector3 e_perpend (0., 0., 1.); |
| 95 |
// if (modul2 > 0.) e_perpend = (1./sqrt(modul2))*product; |
| 96 |
// TVector3 e_paralle = e_perpend.Cross(kphoton); |
| 97 |
|
| 98 |
/// polar = TMath::Cos(fPolAngle*TMath::DegToRad())*e_paralle |
| 99 |
// + TMath::Sin(fPolAngle*TMath::DegToRad())*e_perpend; |
| 100 |
// } |
| 101 |
//else |
| 102 |
// Warning("GeneratePrimary", |
| 103 |
// "The primary particle is not an opticalphoton"); |
| 104 |
|
| 105 |
// Add particle to stack |
| 106 |
fStack->PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof, |
| 107 |
polar.X(), polar.Y(), polar.Z(), |
| 108 |
kPPrimary, ntr, 1., 0); |
| 109 |
} |
| 110 |
|
| 111 |
// public methods |
| 112 |
|
| 113 |
void PamVMCPrimaryGenerator::GeneratePrimaries() |
| 114 |
{ |
| 115 |
// Fill the user stack (derived from TVirtualMCStack) with primary particle |
| 116 |
|
| 117 |
for (Int_t i=0; i<fNofPrimaries; i++) GeneratePrimary(); |
| 118 |
} |
| 119 |
|
| 120 |
void PamVMCPrimaryGenerator::SetDirection( |
| 121 |
Double_t dirX, Double_t dirY, Double_t dirZ) |
| 122 |
{ |
| 123 |
// Set normalized direction |
| 124 |
|
| 125 |
Double_t norm = TMath::Sqrt(dirX*dirX + dirY*dirY + dirZ*dirZ); |
| 126 |
|
| 127 |
fDirX = dirX/norm; |
| 128 |
fDirY = dirY/norm; |
| 129 |
fDirZ = dirZ/norm; |
| 130 |
} |
| 131 |
|
| 132 |
|