/[PAMELA software]/PamVMC/src/PamVMCStack.cxx
ViewVC logotype

Annotation of /PamVMC/src/PamVMCStack.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Thu Jun 28 07:16:58 2007 UTC (17 years, 5 months ago) by nikolas
Branch: MAIN
First release of the Pamela Virtual Montecarlo

1 nikolas 1.1 // $Id: PamVMCStack.cxx,v 1.0 2007/06/03
2     //
3     // Class PamVMCStack
4    
5     #include <TParticle.h>
6     #include <TClonesArray.h>
7     #include <TError.h>
8     #include <Riostream.h>
9    
10     #include "PamVMCStack.h"
11    
12     ClassImp(PamVMCStack)
13    
14     PamVMCStack::PamVMCStack(Int_t size)
15     : fParticles(0),
16     fCurrentTrack(-1),
17     fNPrimary(0)
18     {
19     fParticles = new TClonesArray("TParticle", size);
20     }
21    
22     PamVMCStack::PamVMCStack()
23     : fParticles(0),
24     fCurrentTrack(-1),
25     fNPrimary(0)
26     {
27    
28    
29     }
30    
31     PamVMCStack::~PamVMCStack()
32     {
33    
34     if (fParticles) fParticles->Delete();
35     delete fParticles;
36     }
37    
38    
39     void PamVMCStack::PushTrack(Int_t toBeDone, Int_t parent, Int_t pdg,
40     Double_t px, Double_t py, Double_t pz, Double_t e,
41     Double_t vx, Double_t vy, Double_t vz, Double_t tof,
42     Double_t polx, Double_t poly, Double_t polz,
43     TMCProcess mech, Int_t& /*ntr*/, Double_t weight,
44     Int_t is)
45     {
46     // Creates a new particle with specified properties,
47     // adds it to the particles array (fParticles) and if not done to the
48     // stack (fStack).
49     // Use TParticle::fMother[1] to store Track ID.
50    
51     const Int_t kFirstDaughter=-1;
52     const Int_t kLastDaughter=-1;
53    
54     TClonesArray& particlesRef = *fParticles;
55     Int_t trackId = GetNtrack();
56     TParticle* particle
57     = new(particlesRef[trackId])
58     TParticle(pdg, is, parent, trackId, kFirstDaughter, kLastDaughter,
59     px, py, pz, e, vx, vy, vz, tof);
60    
61     particle->SetPolarisation(polx, poly, polz);
62     particle->SetWeight(weight);
63     particle->SetUniqueID(mech);
64    
65     if (parent<0) fNPrimary++;
66    
67     if (toBeDone) fStack.push(particle);
68     }
69    
70     TParticle* PamVMCStack::PopNextTrack(Int_t& itrack)
71     {
72     // Gets next particle for tracking from the stack.
73    
74     itrack = -1;
75     if (fStack.empty()) return 0;
76    
77     TParticle* particle = fStack.top();
78     fStack.pop();
79    
80     if (!particle) return 0;
81    
82     fCurrentTrack = particle->GetSecondMother();
83     itrack = fCurrentTrack;
84    
85     return particle;
86     }
87    
88     TParticle* PamVMCStack::PopPrimaryForTracking(Int_t i)
89     {
90     // Returns i-th particle in fParticles.
91    
92    
93     if (i < 0 || i >= fNPrimary)
94     Fatal("GetPrimaryForTracking", "Index out of range");
95    
96     return (TParticle*)fParticles->At(i);
97     }
98    
99     void PamVMCStack::Print(Option_t* /*option*/) const
100     {
101     // Prints info for all particles.
102    
103     cout << "PamVMCStack Info " << endl;
104     cout << "Total number of particles: " << GetNtrack() << endl;
105     cout << "Number of primary particles: " << GetNprimary() << endl;
106    
107     for (Int_t i=0; i<GetNtrack(); i++)
108     GetParticle(i)->Print();
109     }
110    
111     void PamVMCStack::Reset()
112     {
113     // Deletes contained particles, resets particles array and stack.
114    
115     fCurrentTrack = -1;
116     fNPrimary = 0;
117     fParticles->Clear();
118     }
119    
120     void PamVMCStack::SetCurrentTrack(Int_t track)
121     {
122     // Sets the current track to a given value.
123    
124     fCurrentTrack = track;
125     }
126    
127     Int_t PamVMCStack::GetNtrack() const
128     {
129     // Returns the number of all tracks.
130    
131     return fParticles->GetEntriesFast();
132     }
133    
134     Int_t PamVMCStack::GetNprimary() const
135     {
136     // Returns the number of primary tracks.
137    
138     return fNPrimary;
139     }
140    
141     TParticle* PamVMCStack::GetCurrentTrack() const
142     {
143     // Returns the current track parent ID.
144    
145     TParticle* current = GetParticle(fCurrentTrack);
146    
147     if (!current)
148     Warning("GetCurrentTrack", "Current track not found in the stack");
149    
150     return current;
151     }
152    
153     Int_t PamVMCStack::GetCurrentTrackNumber() const
154     {
155     // Returns the current track ID.
156    
157     return fCurrentTrack;
158     }
159    
160     Int_t PamVMCStack::GetCurrentParentTrackNumber() const
161     {
162     // Returns the current track parent ID.
163    
164     TParticle* current = GetCurrentTrack();
165    
166     if (current)
167     return current->GetFirstMother();
168     else
169     return -1;
170     }
171    
172     TParticle* PamVMCStack::GetParticle(Int_t id) const
173     {
174     // Returns id-th particle in fParticles.
175    
176     if (id < 0 || id >= fParticles->GetEntriesFast())
177     Fatal("GetParticle", "Index out of range");
178    
179     return (TParticle*)fParticles->At(id);
180     }
181    
182    

  ViewVC Help
Powered by ViewVC 1.1.23