Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WLSTrajectory.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
28 //
29 //
30 //
31 
32 #include "G4AttDef.hh"
33 #include "G4AttValue.hh"
34 #include "G4AttDefStore.hh"
35 
36 #include "G4UIcommand.hh"
37 #include "G4UnitsTable.hh"
38 
39 #include "WLSTrajectory.hh"
40 #include "WLSTrajectoryPoint.hh"
41 #include "G4ParticleTable.hh"
42 #include "G4ParticleTypes.hh"
43 
44 #include "G4Polyline.hh"
45 #include "G4Colour.hh"
46 #include "G4VisAttributes.hh"
47 #include "G4VVisManager.hh"
48 #include "G4Polymarker.hh"
49 
50 //#define G4ATTDEBUG
51 #ifdef G4ATTDEBUG
52 #include "G4AttCheck.hh"
53 #endif
54 
56 
58  : fpPointsContainer(0), fTrackID(0), fParentID(0),
59  PDGCharge(0.0), PDGEncoding(0), ParticleName(""),
60  initialMomentum(G4ThreeVector())
61 {
62  wls = false;
63  drawit = false;
64  forceNoDraw = false;
65  forceDraw = false;
66 
67  particleDefinition = NULL;
68 }
69 
71 {
72  particleDefinition = aTrack->GetDefinition();
73  ParticleName = particleDefinition->GetParticleName();
74  PDGCharge = particleDefinition->GetPDGCharge();
75  PDGEncoding = particleDefinition->GetPDGEncoding();
76  fTrackID = aTrack->GetTrackID();
77  fParentID = aTrack->GetParentID();
78  initialMomentum = aTrack->GetMomentum();
79  fpPointsContainer = new WLSTrajectoryPointContainer();
80  // Following is for the first trajectory point
81  fpPointsContainer->push_back(new WLSTrajectoryPoint(aTrack));
82 
83  wls = false;
84  drawit = false;
85  forceNoDraw = false;
86  forceDraw = false;
87 }
88 
90 {
91  particleDefinition=right.particleDefinition;
92  ParticleName = right.ParticleName;
93  PDGCharge = right.PDGCharge;
94  PDGEncoding = right.PDGEncoding;
95  fTrackID = right.fTrackID;
96  fParentID = right.fParentID;
97  initialMomentum = right.initialMomentum;
98  fpPointsContainer = new WLSTrajectoryPointContainer();
99 
100  for(size_t i=0;i<right.fpPointsContainer->size();++i) {
101  WLSTrajectoryPoint* rightPoint
102  = (WLSTrajectoryPoint*)((*(right.fpPointsContainer))[i]);
103  fpPointsContainer->push_back(new WLSTrajectoryPoint(*rightPoint));
104  }
105 
106  wls = right.wls;
107  drawit = right.drawit;
108  forceNoDraw = right.forceNoDraw;
109  forceDraw = right.forceDraw;
110 }
111 
113 {
114  for(size_t i=0;i<fpPointsContainer->size();++i){
115  delete (*fpPointsContainer)[i];
116  }
117  fpPointsContainer->clear();
118 
119  delete fpPointsContainer;
120 }
121 
122 void WLSTrajectory::ShowTrajectory(std::ostream& os) const
123 {
124  // Invoke the default implementation in G4VTrajectory...
126  // ... or override with your own code here.
127 }
128 
130 {
131  // Invoke the default implementation in G4VTrajectory...
133  // ... or override with your own code here.
134 }
135 
137 {
138  // Invoke the default implementation in G4VTrajectory...
139  // G4VTrajectory::DrawTrajectory(i_mode);
140  // ... or override with your own code here.
141 
142  //Taken from G4VTrajectory and modified to select colours based on particle
143  //type and to selectively eliminate drawing of certain trajectories.
144 
145  if (!forceDraw && (!drawit || forceNoDraw)) return;
146 
147  // If i_mode>=0, draws a trajectory as a polyline and, if i_mode!=0,
148  // adds markers - yellow circles for step points and magenta squares
149  // for auxiliary points, if any - whose screen size in pixels is
150  // given by std::abs(i_mode)/1000. E.g: i_mode = 5000 gives easily
151  // visible markers.
152 
154  if (!pVVisManager) return;
155 
156  const G4double markerSize = std::abs(i_mode)/1000;
157  G4bool lineRequired (i_mode >= 0);
158  G4bool markersRequired (markerSize > 0.);
159 
160  G4Polyline trajectoryLine;
161  G4Polymarker stepPoints;
162  G4Polymarker auxiliaryPoints;
163 
164  for (G4int i = 0; i < GetPointEntries() ; i++) {
165  G4VTrajectoryPoint* aTrajectoryPoint = GetPoint(i);
166  const std::vector<G4ThreeVector>* auxiliaries
167  = aTrajectoryPoint->GetAuxiliaryPoints();
168  if (auxiliaries) {
169  for (size_t iAux = 0; iAux < auxiliaries->size(); ++iAux) {
170  const G4ThreeVector pos((*auxiliaries)[iAux]);
171  if (lineRequired) {
172  trajectoryLine.push_back(pos);
173  }
174  if (markersRequired) {
175  auxiliaryPoints.push_back(pos);
176  }
177  }
178  }
179  const G4ThreeVector pos(aTrajectoryPoint->GetPosition());
180  if (lineRequired) {
181  trajectoryLine.push_back(pos);
182  }
183  if (markersRequired) {
184  stepPoints.push_back(pos);
185  }
186  }
187 
188  if (lineRequired) {
189  G4Colour colour;
190 
191  if(particleDefinition==G4OpticalPhoton::OpticalPhotonDefinition()){
192  if(wls) //WLS photons are red
193  colour = G4Colour(1.,0.,0.);
194  else{ //Scintillation and Cerenkov photons are green
195  colour = G4Colour(0.,1.,0.);
196  }
197  }
198  else //All other particles are blue
199  colour = G4Colour(0.,0.,1.);
200 
201  G4VisAttributes trajectoryLineAttribs(colour);
202  trajectoryLine.SetVisAttributes(&trajectoryLineAttribs);
203  pVVisManager->Draw(trajectoryLine);
204  }
205  if (markersRequired) {
206  auxiliaryPoints.SetMarkerType(G4Polymarker::squares);
207  auxiliaryPoints.SetScreenSize(markerSize);
208  auxiliaryPoints.SetFillStyle(G4VMarker::filled);
209  G4VisAttributes auxiliaryPointsAttribs(G4Colour(0.,1.,1.)); // Magenta
210  auxiliaryPoints.SetVisAttributes(&auxiliaryPointsAttribs);
211  pVVisManager->Draw(auxiliaryPoints);
212 
214  stepPoints.SetScreenSize(markerSize);
215  stepPoints.SetFillStyle(G4VMarker::filled);
216  G4VisAttributes stepPointsAttribs(G4Colour(1.,1.,0.)); // Yellow.
217  stepPoints.SetVisAttributes(&stepPointsAttribs);
218  pVVisManager->Draw(stepPoints);
219  }
220 }
221 
223 {
224  fpPointsContainer->push_back(new WLSTrajectoryPoint(aStep));
225 }
226 
228 {
229  return (G4ParticleTable::GetParticleTable()->FindParticle(ParticleName));
230 }
231 
233 {
234  if(!secondTrajectory) return;
235 
236  WLSTrajectory* second = (WLSTrajectory*)secondTrajectory;
237  G4int ent = second->GetPointEntries();
238  // initial point of the second trajectory should not be merged
239  for(G4int i=1; i<ent; ++i) {
240  fpPointsContainer->push_back((*(second->fpPointsContainer))[i]);
241  }
242  delete (*second->fpPointsContainer)[0];
243  second->fpPointsContainer->clear();
244 }
245 
246 const std::map<G4String,G4AttDef>* WLSTrajectory::GetAttDefs() const
247 {
248  G4bool isNew;
249  std::map<G4String,G4AttDef>* store
250  = G4AttDefStore::GetInstance("Trajectory",isNew);
251 
252  if (isNew) {
253 
254  G4String ID("ID");
255  (*store)[ID] = G4AttDef(ID,"Track ID","Bookkeeping","","G4int");
256 
257  G4String PID("PID");
258  (*store)[PID] = G4AttDef(PID,"Parent ID","Bookkeeping","","G4int");
259 
260  G4String PN("PN");
261  (*store)[PN] = G4AttDef(PN,"Particle Name","Physics","","G4String");
262 
263  G4String Ch("Ch");
264  (*store)[Ch] = G4AttDef(Ch,"Charge","Physics","e+","G4double");
265 
266  G4String PDG("PDG");
267  (*store)[PDG] = G4AttDef(PDG,"PDG Encoding","Physics","","G4int");
268 
269  G4String IMom("IMom");
270  (*store)[IMom] = G4AttDef(IMom,
271  "Momentum of track at start of trajectory",
272  "Physics","G4BestUnit","G4ThreeVector");
273 
274  G4String IMag("IMag");
275  (*store)[IMag] = G4AttDef(IMag,
276  "Magnitude of momentum of track at start of trajectory",
277  "Physics","G4BestUnit","G4double");
278 
279  G4String NTP("NTP");
280  (*store)[NTP] = G4AttDef(NTP,"No. of points","Bookkeeping","","G4int");
281 
282  }
283  return store;
284 }
285 
286 std::vector<G4AttValue>* WLSTrajectory::CreateAttValues() const
287 {
288  std::vector<G4AttValue>* values = new std::vector<G4AttValue>;
289 
290  values->push_back
291  (G4AttValue("ID",G4UIcommand::ConvertToString(fTrackID),""));
292 
293  values->push_back
294  (G4AttValue("PID",G4UIcommand::ConvertToString(fParentID),""));
295 
296  values->push_back(G4AttValue("PN",ParticleName,""));
297 
298  values->push_back
299  (G4AttValue("Ch",G4UIcommand::ConvertToString(PDGCharge),""));
300 
301  values->push_back
302  (G4AttValue("PDG",G4UIcommand::ConvertToString(PDGEncoding),""));
303 
304  values->push_back
305  (G4AttValue("IMom",G4BestUnit(initialMomentum,"Energy"),""));
306 
307  values->push_back
308  (G4AttValue("IMag",G4BestUnit(initialMomentum.mag(),"Energy"),""));
309 
310  values->push_back
312 
313 #ifdef G4ATTDEBUG
314  G4cout << G4AttCheck(values,GetAttDefs());
315 #endif
316  return values;
317 }