Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members
PisaVMCStackv1.C
Go to the documentation of this file.00001 #include "PisaVMCStackv1.h" 00002 00003 #include <cassert> 00004 #include <iostream> 00005 00006 #include "TClonesArray.h" 00007 #include "TParticle.h" 00008 00009 ClassImp(PisaVMCStackv1) 00010 00011 //_____________________________________________________________________________ 00012 PisaVMCStackv1::PisaVMCStackv1() 00013 : fParticles(0), 00014 fCurrentTrack(-1), 00015 fNPrimary(0) 00016 { 00017 } 00018 00019 //_____________________________________________________________________________ 00020 PisaVMCStackv1::PisaVMCStackv1(size_t thesize) 00021 : fParticles(new TClonesArray("TParticle",thesize)), 00022 fCurrentTrack(-1), 00023 fNPrimary(0) 00024 { 00025 } 00026 00027 //_____________________________________________________________________________ 00028 PisaVMCStackv1::~PisaVMCStackv1() 00029 { 00030 if ( fParticles ) 00031 { 00032 fParticles->Delete(); 00033 } 00034 delete fParticles; 00035 } 00036 00037 //_____________________________________________________________________________ 00038 void 00039 PisaVMCStackv1::PushTrack(Int_t toBeDone, Int_t parent, Int_t pdg, 00040 Double_t px, Double_t py, Double_t pz, Double_t e, 00041 Double_t vx, Double_t vy, Double_t vz, Double_t tof, 00042 Double_t polx, Double_t poly, Double_t polz, 00043 TMCProcess mech, Int_t& ntr, Double_t weight, 00044 Int_t is) 00045 { 00046 // Creates a new particle with specified properties, 00047 // adds it to the particles array (fParticles) and if not done to the 00048 // stack (fStack). 00049 // Use TParticle::fMother[1] to store Track ID. 00050 // --- 00051 00052 const Int_t kFirstDaughter=-1; 00053 const Int_t kLastDaughter=-1; 00054 00055 TClonesArray& particlesRef = *fParticles; 00056 Int_t trackId = GetNtrack(); 00057 assert(trackId>=0); 00058 TParticle* particle 00059 = new(particlesRef[trackId]) 00060 TParticle(pdg, is, parent, trackId, kFirstDaughter, kLastDaughter, 00061 px, py, pz, e, vx, vy, vz, tof); 00062 00063 particle->SetPolarisation(polx, poly, polz); 00064 particle->SetWeight(weight); 00065 particle->SetUniqueID(mech); 00066 00067 if (parent<0) fNPrimary++; 00068 00069 if (toBeDone) fStack.push(particle); 00070 ntr = trackId; 00071 } 00072 00073 //_____________________________________________________________________________ 00074 TParticle* 00075 PisaVMCStackv1::PopNextTrack(Int_t& itrack) 00076 { 00077 // Gets next particle for tracking from the stack. 00078 // --- 00079 00080 itrack = -1; 00081 if (fStack.empty()) return 0; 00082 00083 TParticle* particle = fStack.top(); 00084 fStack.pop(); 00085 00086 if (!particle) return 0; 00087 00088 fCurrentTrack = particle->GetSecondMother(); 00089 itrack = fCurrentTrack; 00090 00091 return particle; 00092 } 00093 00094 //_____________________________________________________________________________ 00095 TParticle* 00096 PisaVMCStackv1::PopPrimaryForTracking(Int_t i) 00097 { 00098 // Returns i-th particle in fParticles. 00099 // --- 00100 00101 if (i < 0 || i >= fNPrimary) 00102 Fatal("GetPrimaryForTracking", "Index out of range"); 00103 00104 return (TParticle*)fParticles->At(i); 00105 } 00106 00107 //_____________________________________________________________________________ 00108 void 00109 PisaVMCStackv1::Print(Option_t*) const 00110 { 00111 //Prints info for all particles. 00112 00113 std::cout << "PisaVMCStackv1 Info " << std::endl; 00114 std::cout << "Total number of particles: " << GetNtrack() << std::endl; 00115 std::cout << "Number of primary particles: " << GetNprimary() << std::endl; 00116 00117 for (Int_t i=0; i<GetNtrack(); i++) 00118 { 00119 GetParticle(i)->Print(); 00120 } 00121 } 00122 00123 //_____________________________________________________________________________ 00124 void 00125 PisaVMCStackv1::Reset() 00126 { 00127 //Deletes contained particles, resets particles array and stack. 00128 00129 fCurrentTrack = -1; 00130 fNPrimary = 0; 00131 fParticles->Clear(); 00132 } 00133 00134 //_____________________________________________________________________________ 00135 void 00136 PisaVMCStackv1::SetCurrentTrack(Int_t track) 00137 { 00138 // Sets the current track to a given value. 00139 // --- 00140 00141 fCurrentTrack = track; 00142 } 00143 00144 //_____________________________________________________________________________ 00145 Int_t 00146 PisaVMCStackv1::GetNtrack() const 00147 { 00148 // Returns the number of all tracks. 00149 // --- 00150 00151 return fParticles->GetEntriesFast(); 00152 } 00153 00154 //_____________________________________________________________________________ 00155 Int_t 00156 PisaVMCStackv1::GetNprimary() const 00157 { 00158 // Returns the number of primary tracks. 00159 // --- 00160 00161 return fNPrimary; 00162 } 00163 00164 //_____________________________________________________________________________ 00165 TParticle* 00166 PisaVMCStackv1::GetCurrentTrack() const 00167 { 00168 // Returns the current track parent ID. 00169 // --- 00170 00171 TParticle* current = GetParticle(fCurrentTrack); 00172 00173 if (!current) 00174 Warning("GetCurrentTrack", "Current track not found in the stack"); 00175 00176 return current; 00177 } 00178 00179 //_____________________________________________________________________________ 00180 Int_t 00181 PisaVMCStackv1::GetCurrentTrackNumber() const 00182 { 00183 // Returns the current track ID. 00184 // --- 00185 00186 return fCurrentTrack; 00187 } 00188 00189 //_____________________________________________________________________________ 00190 Int_t 00191 PisaVMCStackv1::GetCurrentParentTrackNumber() const 00192 { 00193 // Returns the current track parent ID. 00194 // --- 00195 00196 TParticle* current = GetCurrentTrack(); 00197 00198 if (current) 00199 return current->GetFirstMother(); 00200 else 00201 return -1; 00202 } 00203 00204 //_____________________________________________________________________________ 00205 TParticle* 00206 PisaVMCStackv1::GetParticle(Int_t id) const 00207 { 00208 // Returns id-th particle in fParticles. 00209 // --- 00210 00211 if (id < 0 || id >= fParticles->GetEntriesFast()) 00212 Fatal("GetParticle", "Index out of range"); 00213 00214 return (TParticle*)fParticles->At(id); 00215 } 00216 00217 00218