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

Diff of /PamVMC/src/PamVMCStack.cxx

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by nikolas, Thu Jun 28 07:16:58 2007 UTC revision 1.2 by nikolas, Wed Feb 18 17:38:17 2009 UTC
# Line 1  Line 1 
1  // $Id: PamVMCStack.cxx,v 1.0 2007/06/03  // $Id: PamVMCStack.cxx,v 1.0 2007/06/03
 //  
2  // Class PamVMCStack  // Class PamVMCStack
3    
4  #include <TParticle.h>  #include <PamVMCParticle.h>
5  #include <TClonesArray.h>  #include <TClonesArray.h>
6  #include <TError.h>  #include <TError.h>
7    #include <TString.h>
8  #include <Riostream.h>  #include <Riostream.h>
9    
10  #include "PamVMCStack.h"  #include "PamVMCStack.h"
# Line 16  PamVMCStack::PamVMCStack(Int_t size) Line 16  PamVMCStack::PamVMCStack(Int_t size)
16      fCurrentTrack(-1),      fCurrentTrack(-1),
17      fNPrimary(0)      fNPrimary(0)
18  {  {
19    fParticles = new TClonesArray("TParticle", size);    fParticles = new TClonesArray("PamVMCParticle", size);
20  }  }
21    
22  PamVMCStack::PamVMCStack()  PamVMCStack::PamVMCStack()
# Line 40  void  PamVMCStack::PushTrack(Int_t toBeD Line 40  void  PamVMCStack::PushTrack(Int_t toBeD
40                           Double_t px, Double_t py, Double_t pz, Double_t e,                           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,                           Double_t vx, Double_t vy, Double_t vz, Double_t tof,
42                           Double_t polx, Double_t poly, Double_t polz,                           Double_t polx, Double_t poly, Double_t polz,
43                           TMCProcess mech, Int_t& /*ntr*/, Double_t weight,                           TMCProcess mech, Int_t& ntr, Double_t weight,
44                           Int_t is)                           Int_t is)
45  {  {
46  // Creates a new particle with specified properties,  // Creates a new particle with specified properties,
47  // adds it to the particles array (fParticles) and if not done to the  // adds it to the particles array (fParticles) and if not done to the
48  // stack (fStack).  // stack (fStack).
49  // Use TParticle::fMother[1] to store Track ID.  // Use PamVMCParticle::fMother[1] to store Track ID.
50    
51    const Int_t kFirstDaughter=-1;    const Int_t kFirstDaughter=-1;
52    const Int_t kLastDaughter=-1;    const Int_t kLastDaughter=-1;
53        
54    TClonesArray& particlesRef = *fParticles;    TClonesArray& particlesRef = *fParticles;
55    Int_t trackId = GetNtrack();    Int_t trackId = GetNtrack();
56    TParticle* particle    PamVMCParticle* particle
57      = new(particlesRef[trackId])      = new(particlesRef[trackId])
58        TParticle(pdg, is, parent, trackId, kFirstDaughter, kLastDaughter,        PamVMCParticle(pdg, is, parent, trackId, kFirstDaughter, kLastDaughter,
59                  px, py, pz, e, vx, vy, vz, tof);                  px, py, pz, e, vx, vy, vz, tof);
60        
61    particle->SetPolarisation(polx, poly, polz);    particle->SetPolarisation(polx, poly, polz);
# Line 65  void  PamVMCStack::PushTrack(Int_t toBeD Line 65  void  PamVMCStack::PushTrack(Int_t toBeD
65    if (parent<0) fNPrimary++;      if (parent<0) fNPrimary++;  
66            
67    if (toBeDone) fStack.push(particle);      if (toBeDone) fStack.push(particle);  
68      ntr=trackId-1;
69  }                          }                        
70    
71  TParticle* PamVMCStack::PopNextTrack(Int_t& itrack)  PamVMCParticle* PamVMCStack::PopNextTrack(Int_t& itrack)
72  {  {
73  // Gets next particle for tracking from the stack.  // Gets next particle for tracking from the stack.
74    
75    itrack = -1;    itrack = -1;
76    if  (fStack.empty()) return 0;    if  (fStack.empty()) return 0;
77                                                
78    TParticle* particle = fStack.top();    PamVMCParticle* particle = fStack.top();
79    fStack.pop();    fStack.pop();
80    
81    if (!particle) return 0;      if (!particle) return 0;  
# Line 85  TParticle* PamVMCStack::PopNextTrack(Int Line 86  TParticle* PamVMCStack::PopNextTrack(Int
86    return particle;    return particle;
87  }      }    
88    
89  TParticle* PamVMCStack::PopPrimaryForTracking(Int_t i)  PamVMCParticle* PamVMCStack::PopPrimaryForTracking(Int_t i)
90  {  {
91  // Returns i-th particle in fParticles.  // Returns i-th particle in fParticles.
92    
# Line 93  TParticle* PamVMCStack::PopPrimaryForTra Line 94  TParticle* PamVMCStack::PopPrimaryForTra
94    if (i < 0 || i >= fNPrimary)    if (i < 0 || i >= fNPrimary)
95      Fatal("GetPrimaryForTracking", "Index out of range");      Fatal("GetPrimaryForTracking", "Index out of range");
96        
97    return (TParticle*)fParticles->At(i);    return (PamVMCParticle*)fParticles->At(i);
98  }      }    
99    
100  void PamVMCStack::Print(Option_t* /*option*/) const  void PamVMCStack::Print(Option_t* /*option*/) const
# Line 104  void PamVMCStack::Print(Option_t* /*opti Line 105  void PamVMCStack::Print(Option_t* /*opti
105    cout << "Total number of particles:   " <<  GetNtrack() << endl;    cout << "Total number of particles:   " <<  GetNtrack() << endl;
106    cout << "Number of primary particles: " <<  GetNprimary() << endl;    cout << "Number of primary particles: " <<  GetNprimary() << endl;
107    
108    for (Int_t i=0; i<GetNtrack(); i++)    for (Int_t i=0; i<GetNtrack(); i++){
109      GetParticle(i)->Print();    GetParticle(i)->Print();
110        
111      }
112  }  }
113    
114  void PamVMCStack::Reset()  void PamVMCStack::Reset()
# Line 114  void PamVMCStack::Reset() Line 117  void PamVMCStack::Reset()
117    
118    fCurrentTrack = -1;    fCurrentTrack = -1;
119    fNPrimary = 0;    fNPrimary = 0;
120    fParticles->Clear();    fParticles->Clear("C");
121      fParticles->Compress();
122  }        }      
123    
124  void  PamVMCStack::SetCurrentTrack(Int_t track)  void  PamVMCStack::SetCurrentTrack(Int_t track)
# Line 138  Int_t  PamVMCStack::GetNprimary() const Line 142  Int_t  PamVMCStack::GetNprimary() const
142    return fNPrimary;    return fNPrimary;
143  }    }  
144    
145  TParticle*  PamVMCStack::GetCurrentTrack() const  PamVMCParticle*  PamVMCStack::GetCurrentTrack() const
146  {  {
147  // Returns the current track parent ID.  // Returns the current track parent ID.
148    
149    TParticle* current = GetParticle(fCurrentTrack);    PamVMCParticle* current = GetParticle(fCurrentTrack);
150    
151    if (!current)        if (!current)    
152      Warning("GetCurrentTrack", "Current track not found in the stack");      Warning("GetCurrentTrack", "Current track not found in the stack");
# Line 161  Int_t  PamVMCStack::GetCurrentParentTrac Line 165  Int_t  PamVMCStack::GetCurrentParentTrac
165  {  {
166  // Returns the current track parent ID.  // Returns the current track parent ID.
167    
168    TParticle* current = GetCurrentTrack();    PamVMCParticle* current = GetCurrentTrack();
169    
170    if (current)    if (current)
171      return current->GetFirstMother();      return current->GetFirstMother();
# Line 169  Int_t  PamVMCStack::GetCurrentParentTrac Line 173  Int_t  PamVMCStack::GetCurrentParentTrac
173      return -1;      return -1;
174  }    }  
175    
176  TParticle*  PamVMCStack::GetParticle(Int_t id) const  PamVMCParticle*  PamVMCStack::GetParticle(Int_t id) const
177  {  {
178  // Returns id-th particle in fParticles.  // Returns id-th particle in fParticles.
179    
180    if (id < 0 || id >= fParticles->GetEntriesFast())    if (id < 0 || id >= fParticles->GetEntriesFast()){
181      Fatal("GetParticle", "Index out of range");      TString e="Index out of range ";
182          e+=id;
183    return (TParticle*)fParticles->At(id);      //    Fatal("GetParticle", "Index out of range");
184        Fatal("GetParticle", e.Data());
185      }  
186      return (PamVMCParticle*)fParticles->At(id);
187  }  }
188    
189    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.23