Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DMXSteppingAction.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 //
26 //
27 // --------------------------------------------------------------
28 // GEANT 4 - Underground Dark Matter Detector Advanced Example
29 //
30 // For information related to this code contact: Alex Howard
31 // e-mail: alexander.howard@cern.ch
32 // --------------------------------------------------------------
33 // Comments
34 //
35 // Underground Advanced
36 // by A. Howard and H. Araujo
37 // (27th November 2001)
38 //
39 // History:
40 // 21 Feb 2002 AH: Added Analysis
41 //
42 // SteppingAction program
43 // --------------------------------------------------------------
44 
45 #include "DMXSteppingAction.hh"
47 
48 #include "DMXEventAction.hh"
49 
50 #ifdef G4ANALYSIS_USE
51 #include "DMXAnalysisManager.hh"
52 #endif
53 
54 #include "G4Track.hh"
55 #include "G4Step.hh"
56 #include "G4StepPoint.hh"
57 #include "G4TrackStatus.hh"
58 #include "G4ParticleDefinition.hh"
59 #include "G4ParticleTypes.hh"
60 #include "G4VVisManager.hh"
61 #include "G4Colour.hh"
62 #include "G4Polyline.hh"
63 #include "G4VisAttributes.hh"
64 #include "globals.hh"
65 #include "G4ios.hh"
66 
67 
68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
69 
71  : evtAction(eventAction) {
72 
73  steppingMessenger = new DMXSteppingActionMessenger(this);
74 
75  // defaults for messenger
76  colourNeutronFlag = "magenta";
77  colourGammaFlag = "cyan";
78  colourOpticalFlag = "white";
79  colourChargedPlusFlag = "red";
80  colourChargedMinusFlag = "blue";
81 
82 }
83 
84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
85 
87 {
88 
89  delete steppingMessenger;
90 
91 }
92 
93 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
94 
96 {
97 
98  // removed 28/11/01 - unnecessary unless program "freezes"
99  // kill track if too many steps
100  // NB: This is set to DBL_MAX - therefore may cause program to "hang"
101  // G4int MaxNoSteps = DBL_MAX;
102  // G4int StepNo = fStep->GetTrack()->GetCurrentStepNumber();
103  // if(StepNo >= MaxNoSteps) fStep->GetTrack()->SetTrackStatus(fStopAndKill);
104 
105 #ifdef G4ANALYSIS_USE
106  G4int StepNo = fStep->GetTrack()->GetCurrentStepNumber();
107  if(StepNo == 1)
108  {
109  G4double partEnergy = fStep->GetPreStepPoint()->GetKineticEnergy();
110  G4ParticleDefinition* particleType = fStep->GetTrack()->GetDefinition();
111  G4String particleName = particleType->GetParticleName();
112  DMXAnalysisManager* analysis = DMXAnalysisManager::getInstance();
113  analysis->analyseParticleSource(partEnergy, particleName);
114  }
115 #endif
116 
117  // check what is to be drawn from EventAction/EventActionMessenger
118  G4String drawColsFlag = evtAction->GetDrawColsFlag();
119  G4String drawTrksFlag = evtAction->GetDrawTrksFlag();
120 
121  // draw by step (here) instead of by event (event action)
122  if (drawColsFlag=="custom" && drawTrksFlag!="none") {
123 
124  // check that VisManager exists
126  if(pVVisManager) {
127 
128  // particle colour in a string
130  G4String strColour;
131  if(name=="neutron") {
132  if(drawTrksFlag=="charged") return;
133  strColour = colourNeutronFlag;
134  } else if (name=="gamma") {
135  if(drawTrksFlag=="charged") return;
136  strColour = colourGammaFlag;
137  } else if (name=="opticalphoton") {
138  if(drawTrksFlag!="all") return;
139  strColour = colourOpticalFlag;
140  }
141  else if (name=="alpha" || name=="e+")
142  strColour = colourChargedPlusFlag;
143  else
144  strColour = colourChargedMinusFlag;
145 
146  // convert string to G4Colour
147  G4Colour colour;
148  if (strColour=="white") colour=G4Colour(1.0, 1.0, 1.0);
149  else if(strColour=="grey" ) colour=G4Colour(0.5, 0.5, 0.5);
150  else if(strColour=="lgrey") colour=G4Colour(.75, .75, .75);
151  else if(strColour=="black") colour=G4Colour(0.0, 0.0, 0.0);
152  else if(strColour=="red") colour=G4Colour(1.0, 0.0, 0.0);
153  else if(strColour=="green") colour=G4Colour(0.0, 1.0, 0.0);
154  else if(strColour=="blue") colour=G4Colour(0.0, 0.0, 1.0);
155  else if(strColour=="cyan") colour=G4Colour(0.0, 1.0, 1.0);
156  else if(strColour=="magenta") colour=G4Colour(1.0, 0.0, 1.0);
157  else if(strColour=="yellow") colour=G4Colour(1.0, 1.0, 0.0);
158  else if(strColour=="lgreen") colour=G4Colour(0.0, .75, 0.0);
159  else if(strColour=="lblue") colour=G4Colour(0.0, 0.0, .75);
160  else colour=G4Colour(1.0, 1.0, 1.0);
161 
162  // create line with colour
163  G4VisAttributes attribs(colour);
164  G4Polyline polyline;
165  polyline.SetVisAttributes(attribs);
166 
167  // draw line
168  G4Point3D start(fStep->GetPreStepPoint()->GetPosition());
169  G4Point3D end(fStep->GetPostStepPoint()->GetPosition());
170  polyline.push_back(start);
171  polyline.push_back(end);
172  pVVisManager->Draw(polyline);
173  }
174 
175  }
176 
177 }
178 
179