QwGeant4
QweakSimTrajectory.cc
Go to the documentation of this file.
1 
2 //=============================================================================
3 //
4 // ---------------------------
5 // | Doxygen File Information |
6 // ---------------------------
7 //
8 /**
9 
10  \file QweakSimTrajectory.cc
11 
12  $Revision: 1.4 $
13  $Date: 2005/12/28 23:09:53 $
14 
15  \author Klaus Hans Grimm
16 
17 */
18 //=============================================================================
19 
20 //=============================================================================
21 // -----------------------
22 // | CVS File Information |
23 // -----------------------
24 //
25 // Last Update: $Author: grimm $
26 // Update Date: $Date: 2005/12/28 23:09:53 $
27 // CVS/RCS Revision: $Revision: 1.4 $
28 // Status: $State: Exp $
29 //
30 // ===================================
31 // CVS Revision Log at end of file !!
32 // ===================================
33 //
34 //============================================================================
35 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
36 
37 #include "QweakSimTrajectory.hh"
38 
39 // geant4 includes
40 #include "G4Track.hh"
41 #include "G4ParticleDefinition.hh"
42 #include "G4TrajectoryPoint.hh"
43 #include "G4Polyline.hh"
44 #include "G4ParticleTable.hh"
45 #include "G4UnitsTable.hh"
46 #include "G4VVisManager.hh"
47 #include "G4VisAttributes.hh"
48 #include "G4Gamma.hh"
49 #include "G4Electron.hh"
50 #include "G4Positron.hh"
51 #include "G4Neutron.hh"
52 #include "G4Proton.hh"
53 #include "G4OpticalPhoton.hh"
54 
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56 
57 G4Allocator<QweakSimTrajectory> myTrajectoryAllocator;
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
61 {
62  G4cout << G4endl << "###### Calling QweakSimTrajectory::QweakSimTrajectory()" << G4endl << G4endl;
63 
64  drawit = FALSE;
65  forceNoDraw = FALSE;
66  forceDraw = FALSE;
67 
68 
70  ParticleName = "";
71  PDGCharge = 0;
72  PDGEncoding = 0;
73  fTrackID = 0;
74  fParentID = 0;
75  positionRecord = 0;
76 
77  momentum = G4ThreeVector(0.,0.,0.);
78  vertexPosition = G4ThreeVector(0.,0.,0.);
79  globalTime = 0.;
80 
81  G4cout << G4endl << "###### Leaving QweakSimTrajectory::QweakSimTrajectory()" << G4endl << G4endl;
82 }
83 
84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
86 {
87  // G4cout << G4endl << "###### Calling QweakSimTrajectory::QweakSimTrajectory(aTrack)" << G4endl << G4endl;
88 
89  fpParticleDefinition = aTrack->GetDefinition();
90  ParticleName = fpParticleDefinition->GetParticleName();
91  PDGCharge = fpParticleDefinition->GetPDGCharge();
92  PDGEncoding = fpParticleDefinition->GetPDGEncoding();
93  fTrackID = aTrack->GetTrackID();
94  fParentID = aTrack->GetParentID();
95 
97  positionRecord -> push_back(new G4TrajectoryPoint(aTrack->GetPosition()));
98 
99  momentum = aTrack->GetMomentum();
100  vertexPosition = aTrack->GetPosition();
101  globalTime = aTrack->GetGlobalTime();
102 
103 
104  // G4cout << G4endl << "###### Leaving QweakSimTrajectory::QweakSimTrajectory(aTrack)" << G4endl << G4endl;
105 }
106 
107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
109  : G4VTrajectory()
110 {
111  ParticleName = right.ParticleName;
113  PDGCharge = right.PDGCharge;
114  PDGEncoding = right.PDGEncoding;
115  fTrackID = right.fTrackID;
116  fParentID = right.fParentID;
117 
119 
120  for(int i=0;i<(int)right.positionRecord->size();i++)
121  {
122  G4TrajectoryPoint* rightPoint = (G4TrajectoryPoint*)((*(right.positionRecord))[i]);
123 
124  positionRecord->push_back(new G4TrajectoryPoint(*rightPoint));
125  }
126 
127  momentum = right.momentum;
129  globalTime = right.globalTime;
130 }
131 
132 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
134 {
135  size_t i;
136  for(i=0;i<positionRecord->size();i++){
137  delete (*positionRecord)[i];
138  }
139  positionRecord->clear();
140 
141  delete positionRecord;
142 }
143 
144 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
145 void QweakSimTrajectory::ShowTrajectory(std::ostream& os) const
146 {
147 
148  os << G4endl << "TrackID =" << fTrackID
149  << " : ParentID=" << fParentID << G4endl;
150 
151  os << "Particle name : " << ParticleName << " PDG code : " << PDGEncoding
152  << " Charge : " << PDGCharge << G4endl;
153 
154  os << "Original momentum : " <<
155  G4BestUnit(momentum,"Energy") << G4endl;
156 
157  os << "Vertex : " << G4BestUnit(vertexPosition,"Length")
158  << " Global time : " << G4BestUnit(globalTime,"Time") << G4endl;
159 
160  os << " Current trajectory has " << positionRecord->size()
161  << " points." << G4endl;
162 
163  for( size_t i=0 ; i < positionRecord->size() ; i++){
164  G4TrajectoryPoint* aTrajectoryPoint = (G4TrajectoryPoint*)((*positionRecord)[i]);
165 
166  G4cout << "Point[" << i << "]" << " Position= " << aTrajectoryPoint->GetPosition() << G4endl;
167  }
168 }
169 
170 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
171 #if G4VERSION_NUMBER < 1000
173 #else
175 #endif
176 {
177  // G4cout << G4endl << "###### Calling QweakSimTrajectory::DrawTrajectory()" << G4endl << G4endl;
178 
179  //if(!forceDraw && (!drawit || forceNoDraw))
180 
181 // if( (forceNoDraw == true))
182 // return;
183 
184  // If i_mode>=0, draws a trajectory as a polyline (blue for
185  // positive, red for negative, green for neutral) and, if i_mode!=0,
186  // adds markers - yellow circles for step points and magenta squares
187  // for auxiliary points, if any - whose screen size in pixels is
188  // given by abs(i_mode)/1000. E.g: i_mode = 5000 gives easily
189  // visible markers.
190 
191  G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
192 
193  G4ThreeVector pos;
194  G4Polyline pPolyline;
195 
196  for (int i = 0; i < (int) positionRecord->size() ; i++) {
197 
198  G4TrajectoryPoint* aTrajectoryPoint = (G4TrajectoryPoint*)((*positionRecord)[i]);
199  pos = aTrajectoryPoint->GetPosition();
200  pPolyline.push_back( pos );
201  }
202 
203 
204  G4Colour colour(0.75,0.75,0.75); // LightGray
205 
206  G4Colour red ( 255/255., 0/255., 0/255.);
207  G4Colour blue ( 0/255., 0/255., 255/255.);
208  G4Colour green ( 0/255., 255/255., 0/255.);
209  G4Colour yellow ( 255/255., 255/255., 0/255.);
210 
211  G4Colour white ( 255/255., 255/255., 255/255.);
212 
213  G4Colour orange ( 255/255., 127/255., 0/255.);
214  G4Colour magenta ( 237/255., 173/255., 255/255.);
215  G4Colour magenta1 ( 104/255., 49/255., 94/255.);
216 
217 
218 
219  // Default colors for particlea
220  if ( PDGCharge < 0.) {colour = red;}
221  else if ( PDGCharge > 0.) {colour = blue;}
222  else
223  {
224  //G4cout << "%%%%% We have something neutral here !!!" << G4endl;
225  colour = green;
226  }
227 
228  if (fpParticleDefinition == G4Gamma ::GammaDefinition() ) {
229  //G4cout << "%%%%% We have a green Gamma here !!!" << G4endl;
230  colour = green;}
231  if (fpParticleDefinition == G4Electron ::ElectronDefinition() )
232  {
233  //G4cout << "%%%%% We have a red Electron here !!!" << G4endl;
234  colour = red;
235  //colour = white;
236  }
237  if (fpParticleDefinition == G4Positron ::PositronDefinition() )
238  {
239  //G4cout << "%%%%% We have a blue Positron here !!!" << G4endl;
240  colour = blue;
241  }
242 
243 // else if (fpParticleDefinition == G4MuonMinus ::MuonMinusDefinition()
244 // ||fpParticleDefinition == G4MuonPlus ::MuonPlusDefinition()) ) colour = G4Colour(1.,0.,1.); // Magenta
245 //
246 // else if(fpParticleDefinition->GetParticleType()=="meson")
247 // {
248 // if(PDGCharge!=0.)
249 // colour = yellow;
250 // else
251 // colour = G4Colour(0.5,0.,0.); // HalfRed
252 // }
253 // else if(fpParticleDefinition->GetParticleType()=="baryon")
254 // {
255 // if(PDGCharge!=0.)
256 // colour = orange; // Orange
257 // else
258 // colour = G4Colour(0.5,0.39,0.);// HalfOrange
259 // }
260 
261  if( fpParticleDefinition == G4Neutron ::NeutronDefinition())
262  {
263  //G4cout << "%%%%% We have a white Neutron here !!!" << G4endl;
264  colour = white;
265  }
266  if( fpParticleDefinition == G4Proton ::ProtonDefinition())
267  {
268  //G4cout << "%%%%% We have an orange Proton here !!!" << G4endl;
269  colour = orange;
270  }
271  if( fpParticleDefinition == G4OpticalPhoton ::OpticalPhotonDefinition())
272  {
273  //G4cout << "%%%%% We have a magenta OpticalPhoton here !!!" << G4endl;
274  colour = magenta;
275  }
276 
277  G4VisAttributes attribs(colour);
278  pPolyline.SetVisAttributes(attribs);
279 
280  // if(pVVisManager)
281  pVVisManager->Draw(pPolyline);
282 
283 
284  // G4cout << G4endl << "###### Leaving QweakSimTrajectory::DrawTrajectory()" << G4endl << G4endl;
285 }
286 
287 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
288 void QweakSimTrajectory::AppendStep(const G4Step* aStep)
289 {
290  positionRecord->push_back( new G4TrajectoryPoint(aStep->GetPostStepPoint()->GetPosition() ));
291 }
292 
293 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
295 {
296  return (G4ParticleTable::GetParticleTable()->FindParticle(ParticleName));
297 }
298 
299 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
300 void QweakSimTrajectory::MergeTrajectory(G4VTrajectory* secondTrajectory)
301 {
302  if(!secondTrajectory) return;
303 
304  QweakSimTrajectory* seco = (QweakSimTrajectory*)secondTrajectory;
305  G4int ent = seco->GetPointEntries();
306 
307  for(int i=1;i<ent;i++) // initial point of the second trajectory should not be merged
308  {
309  positionRecord->push_back((*(seco->positionRecord))[i]);
310  }
311 
312  delete (*seco->positionRecord)[0];
313 
314  seco->positionRecord->clear();
315 
316 }
317 
318 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
319 
320 //=======================================================
321 // -----------------------
322 // | CVS File Information |
323 // -----------------------
324 //
325 // $Revisions$
326 // $Log: QweakSimTrajectory.cc,v $
327 // Revision 1.4 2005/12/28 23:09:53 grimm
328 // Testing: added some bool variables taken from the LXe example for dis/enabling user trajectory storage
329 //
330 // Revision 1.3 2005/12/27 19:15:43 grimm
331 // - Redesign of Doxygen header containing CVS info like revision and date
332 // - Added CVS revision log at the end of file
333 //
334 //
Stores the information about the various tracks.
G4ThreeVector vertexPosition
G4ParticleDefinition * fpParticleDefinition
virtual void MergeTrajectory(G4VTrajectory *secondTrajectory)
std::vector< G4VTrajectoryPoint * > QweakSimTrajectoryPointContainer
virtual void DrawTrajectory(G4int i_mode=0) const
G4ParticleDefinition * GetParticleDefinition()
G4Allocator< QweakSimTrajectory > myTrajectoryAllocator
virtual void AppendStep(const G4Step *aStep)
virtual int GetPointEntries() const
virtual void ShowTrajectory(std::ostream &os=G4cout) const
QweakSimTrajectoryPointContainer * positionRecord