/[PAMELA software]/trieste/pamVMC/src/PamVMCPrimaryGenerator.cxx
ViewVC logotype

Annotation of /trieste/pamVMC/src/PamVMCPrimaryGenerator.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (hide annotations) (download) (vendor branch)
Wed Mar 4 12:51:18 2009 UTC (15 years, 9 months ago) by pamelats
Branch: pamVMC
CVS Tags: start, v0r00
Changes since 1.1: +0 -0 lines
Test pamVMC

1 pamelats 1.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     using TMath::Sqrt;
15     using TMath::Sin;
16     using TMath::Cos;
17     using TMath::ACos;
18     using TMath::Tan;
19     using TMath::ATan;
20     using TMath::ATan2;
21     using TMath::Log;
22     using TMath::Power;
23     using TMath::Exp;
24     using TMath::Pi;
25     using TMath::Abs;
26    
27     ClassImp(PamVMCPrimary)
28    
29     PamVMCPrimary & operator+=(PamVMCPrimary &a, const PamVMCPrimary &b)
30     {
31     a.fPDG=b.fPDG;
32     a.fX0=b.fX0;
33     a.fY0=b.fY0;
34     a.fZ0=b.fZ0;
35     a.fTHETA=b.fTHETA;
36     a.fPHI=b.fPHI;
37     a.fP0=b.fP0;
38     a.fGOOD=b.fGOOD;
39    
40     return a;
41     }
42    
43    
44     ClassImp(PamVMCPrimaryGenerator)
45    
46     PamVMCPrimaryGenerator::PamVMCPrimaryGenerator(TVirtualMCStack* stack)
47     : TObject(),
48     fStack(stack),
49     fevno(0),
50     fmass(0.),
51     fcharge(0.),
52     frnd(0)
53     {
54     // Standard constructor
55     fprimColl = new TClonesArray("PamVMCPrimary");
56     frnd = new TRandom3(0);
57    
58     fprim.fPDG=kProton;
59     fprim.fX0=1.;
60     fprim.fY0=1.;
61     fprim.fZ0=130.;
62     fprim.fTHETA=0.;
63     fprim.fPHI=0.;
64     fprim.fP0=1.; //1GV
65    
66     }
67    
68     PamVMCPrimaryGenerator::PamVMCPrimaryGenerator()
69     : TObject(),
70     fStack(0),
71     fevno(0),
72     fmass(0.),
73     fcharge(0.),
74     fprimColl(0),
75     frnd(0)
76     {
77     frnd = new TRandom3(0);
78     // Default constructor
79     //Default primary proton
80     fprim.fPDG=kProton;
81     fprim.fX0=1.;
82     fprim.fY0=1.;
83     fprim.fZ0=130.;
84     fprim.fTHETA=0.;
85     fprim.fPHI=0.;
86     fprim.fP0=1.; //1GV
87     }
88    
89     PamVMCPrimaryGenerator::~PamVMCPrimaryGenerator()
90     {
91     // Destructor
92     delete frnd;
93     delete fprimColl;
94     }
95    
96     // private methods
97    
98     #include <Riostream.h>
99    
100     void PamVMCPrimaryGenerator::GeneratePrimary()
101     {
102     // Add one primary particle to the user stack (derived from TVirtualMCStack).
103    
104     // Track ID (filled by stack)
105     Int_t ntr;
106    
107     // Option: to be tracked
108     Int_t toBeDone = 1;
109    
110     // Particle type
111     Int_t pdg = fprim.fPDG;
112    
113     Double_t fvx, fvy, fvz;
114     fvx=fprim.fX0;
115     fvy=fprim.fY0;
116     fvz=fprim.fZ0;
117    
118     // Position
119    
120     Double_t tof = 0.;
121    
122     // Energy (in GeV)
123     Double_t kinEnergy = MomentumToKinE(fprim.fP0);
124     Double_t e = fmass + kinEnergy;
125    
126     // Particle momentum
127     Double_t px, py, pz;
128    
129     px = -fprim.fP0*Sin((Pi()/180.)*(fprim.fTHETA))*Cos((Pi()/180.)*(fprim.fPHI));
130     py = -fprim.fP0*Sin((Pi()/180.)*(fprim.fTHETA))*Sin((Pi()/180.)*(fprim.fPHI));
131     pz = -fprim.fP0*Cos((Pi()/180.)*(fprim.fTHETA)); // converting in radian
132     //px = fprim.fP0*Sin(fprim.fTHETA)*Cos(fprim.fPHI);
133     //py = fprim.fP0*Sin(fprim.fTHETA)*Sin(fprim.fPHI);
134     //pz = -fprim.fP0*Cos(fprim.fTHETA);
135    
136     // Polarization
137     TVector3 polar;
138    
139     // Add particle to stack
140     fStack->PushTrack(toBeDone, -1, pdg, px, py, pz, e, fvx, fvy, fvz, tof,
141     polar.X(), polar.Y(), polar.Z(),
142     kPPrimary, ntr, 1., 0);
143    
144     PamVMCPrimary * pc = (PamVMCPrimary *)fprimColl->New(fevno++);
145    
146     *pc = fprim;
147     }
148    
149    
150     void PamVMCPrimaryGenerator::SetParticle(Int_t pdg){
151     fprim.fPDG=pdg;
152     //TParticlePDG* particlePDG = TDatabasePDG::Instance()->GetParticle(fprim.fPDG);
153     fmass = (TDatabasePDG::Instance()->GetParticle(fprim.fPDG))->Mass();
154     fcharge = ((TDatabasePDG::Instance()->GetParticle(fprim.fPDG))->Charge())/3.;
155     }
156    
157     void PamVMCPrimaryGenerator::SetMomentum(
158     Double_t px, Double_t py, Double_t pz)
159     {
160     fprim.fP0= Sqrt(px*px+py*py+pz*pz);
161     fprim.fTHETA=ATan(Sqrt(px*px+py*py)/pz);
162     fprim.fPHI=ATan(py/px);
163     }
164    
165     void PamVMCPrimaryGenerator::GenSpe(Double_t PEmin, Double_t PEmax, Bool_t isEnergy)
166     {
167     if(isEnergy) {
168     fprim.fP0=frnd->Uniform(KinEToMomentum(PEmin),KinEToMomentum(PEmax));
169     } else{
170     fprim.fP0=frnd->Uniform(PEmin,PEmax);
171     }
172    
173     }
174    
175     void PamVMCPrimaryGenerator::GenSpe(Double_t PEmin, Double_t PEmax, Double_t gamma, Bool_t isEnergy)
176     {
177     Double_t alpha = 1.+gamma; //integral spectral index
178     if(alpha==0.){
179     fprim.fP0=Exp(Log(PEmin)+frnd->Uniform(0.,1.)*(Log(PEmax)-Log(PEmin)));
180     } else {
181     if(PEmin==0.) PEmin=1.E-10;
182     fprim.fP0=Power((frnd->Uniform(0.,1.)*(Power(PEmax,alpha)-Power(PEmin,alpha))+Power(PEmin,alpha)),1./alpha);
183     }
184    
185     if(isEnergy) fprim.fP0=KinEToMomentum(fprim.fP0);
186    
187     }
188    
189     void PamVMCPrimaryGenerator::GenSphDist(Double_t r, Double_t Thmin, Double_t Thmax, Double_t Phmin, Double_t Phmax)
190     {
191     Double_t theta, phi, y, f;
192     phi = (Pi()/180.)*frnd->Uniform(Phmin,Phmax);
193    
194     do
195     { y = frnd->Uniform(0.,1.);
196     theta = (Pi()/180.)*frnd->Uniform(Thmin,Thmax);
197     f = Sin(theta);
198     } while (y>f);
199    
200     //theta = phi = (Pi()/180.)*45.;
201     SetPosition((r*Sin(theta)*Cos(phi)), (r*Sin(theta)*Sin(phi)), (r*Cos(theta)));
202    
203     //random distribution of theta phi in the angle at the vertex at (0,0,r)
204     //by the S3 max distant corners.
205     static const Double_t s3_x=9.0, s3_y=7.5, s3_pz=25.3159;
206     Double_t ang = ATan((Sqrt(s3_x*s3_x+s3_y*s3_y))/(r-s3_pz));
207    
208     //SetDirection((frnd->Uniform((theta-ang),(theta+ang)))/(Pi()/180.), (frnd->Uniform((phi-ang),(phi+ang)))/(Pi()/180.));
209     SetDirection((frnd->Uniform((theta-ang),(theta+ang)))/(Pi()/180.), (frnd->Uniform(0.,2*Pi()))/(Pi()/180.));
210     //SetDirection(0., 0.);
211     }
212    
213     void PamVMCPrimaryGenerator::GenSphDist(Double_t r)
214     {
215     //cout << "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+" << endl;
216     static const Double_t s1_x=20.4, s1_y=16.5, s1_pz=102.8866;
217     static const Double_t s2_x=9.0, s2_y=7.5, s2_pz=73.489;
218     static const Double_t s3_x=9.0, s3_y=7.5, s3_pz=25.3159;
219    
220     //calculate max theta and phi angles to be allowed (calculating wrt one
221     //corner of s3 to opposite corner of s1)
222     Double_t rx = s1_x+s3_x;
223     Double_t ry = s1_y+s3_y;
224     Double_t rz = s1_pz-s3_pz;
225    
226     Double_t thmax = (180./Pi())*(ACos(rz/Sqrt(rx*rx+ry*ry+rz*rz)));
227     Double_t phmax = (180./Pi())*(ATan2(ry,rx));
228     //cout << "~~~~~~Theta max Phi max : " << thmax <<", "<< phmax << endl;
229    
230     //generate a track check and let it go only if it is passing through all
231     //the 3 TOF
232     Bool_t trkGood = kFALSE;
233    
234     do
235     {
236     //cout << "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+" << endl;
237     GenSphDist(r, 0., thmax, 0., phmax);
238    
239     Double_t th = (Pi()/180.)*fprim.fTHETA;
240     Double_t ph = (Pi()/180.)*fprim.fPHI;
241     //cout << "~~~~~~Theta Phi : " << fprim.fTHETA <<", "<< fprim.fPHI << endl;
242    
243     Double_t x1, y1, x2, y2, x3, y3;
244    
245     x1 = s1_pz*Tan(th)*Cos(ph);
246     y1 = s1_pz*Tan(th)*Sin(ph);
247     x2 = s2_pz*Tan(th)*Cos(ph);
248     y2 = s2_pz*Tan(th)*Sin(ph);
249     x3 = s3_pz*Tan(th)*Cos(ph);
250     y3 = s3_pz*Tan(th)*Sin(ph);
251    
252     if ( Abs(x1) <= Abs(s1_x) && Abs(y1) <= Abs(s1_y) &&
253     Abs(x2) <= Abs(s2_x) && Abs(y2) <= Abs(s2_y) &&
254     Abs(x3) <= Abs(s3_x) && Abs(y3) <= Abs(s3_y) ) trkGood = kTRUE;
255     //cout << "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+" << endl;
256     }while (!trkGood);
257     //cout << "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+" << endl;
258     }

  ViewVC Help
Powered by ViewVC 1.1.23