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 | // $Id: TiaraVisEventAction.cc,v 1.4 2006/06/29 15:45:52 gunter Exp $ |
---|
28 | // GEANT4 tag $Name: $ |
---|
29 | // |
---|
30 | // |
---|
31 | |
---|
32 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
33 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
34 | |
---|
35 | #include "TiaraVisEventAction.hh" |
---|
36 | |
---|
37 | |
---|
38 | #include "G4Event.hh" |
---|
39 | #include "G4EventManager.hh" |
---|
40 | #include "G4HCofThisEvent.hh" |
---|
41 | #include "G4TrajectoryContainer.hh" |
---|
42 | #include "G4Trajectory.hh" |
---|
43 | #include "G4VVisManager.hh" |
---|
44 | #include "G4SDManager.hh" |
---|
45 | #include "G4UImanager.hh" |
---|
46 | #include "G4ios.hh" |
---|
47 | #include "G4UnitsTable.hh" |
---|
48 | #include "G4Polyline.hh" |
---|
49 | #include "G4Colour.hh" |
---|
50 | #include "G4VisAttributes.hh" |
---|
51 | #include "TiaraCellScorerStore.hh" |
---|
52 | |
---|
53 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
54 | |
---|
55 | TiaraVisEventAction::TiaraVisEventAction(): |
---|
56 | fScorerStore(0) |
---|
57 | { |
---|
58 | } |
---|
59 | |
---|
60 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
61 | |
---|
62 | TiaraVisEventAction::~TiaraVisEventAction() |
---|
63 | { |
---|
64 | } |
---|
65 | |
---|
66 | void TiaraVisEventAction::Clear() { |
---|
67 | |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | |
---|
72 | void TiaraVisEventAction::BeginOfEventAction(const G4Event* ) |
---|
73 | { |
---|
74 | } |
---|
75 | |
---|
76 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
77 | |
---|
78 | void TiaraVisEventAction:: |
---|
79 | SetScorerStore(TiaraCellScorerStore *scorerStore){ |
---|
80 | fScorerStore = scorerStore; |
---|
81 | } |
---|
82 | |
---|
83 | void TiaraVisEventAction::EndOfEventAction(const G4Event* evt) |
---|
84 | { |
---|
85 | |
---|
86 | if (fScorerStore) { |
---|
87 | fScorerStore->EndOfEventAction(); |
---|
88 | } |
---|
89 | |
---|
90 | if (G4VVisManager::GetConcreteInstance()) { |
---|
91 | G4TrajectoryContainer* trajectoryContainer(0); |
---|
92 | trajectoryContainer = evt->GetTrajectoryContainer(); |
---|
93 | G4int n_trajectories = 0; |
---|
94 | if (trajectoryContainer) { |
---|
95 | n_trajectories = trajectoryContainer->entries(); |
---|
96 | } |
---|
97 | |
---|
98 | for (G4int i=0; i<n_trajectories; i++) { |
---|
99 | |
---|
100 | G4Trajectory* trj = 0; |
---|
101 | trj = dynamic_cast<G4Trajectory*>((*trajectoryContainer)[i]); |
---|
102 | if (trj) { |
---|
103 | G4bool charged(false); |
---|
104 | charged = std::fabs(trj->GetCharge()) > 0; |
---|
105 | DrawTrajectory(*trj); |
---|
106 | } |
---|
107 | else { |
---|
108 | G4cerr << " TiaraVisEventAction::EndOfEventAction: failed to dynamic cast to G4Trajectory!" << G4endl; |
---|
109 | } |
---|
110 | } |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
115 | |
---|
116 | |
---|
117 | /////////////////////////////////////////////// |
---|
118 | void TiaraVisEventAction::DrawTrajectory(G4Trajectory &trj) const |
---|
119 | /////////////////////////////////////////////// |
---|
120 | { |
---|
121 | |
---|
122 | G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance(); |
---|
123 | G4ThreeVector pos; |
---|
124 | |
---|
125 | G4ParticleDefinition* pdf = trj.GetParticleDefinition(); |
---|
126 | G4String ParticleName(pdf->GetParticleName()); |
---|
127 | G4double PDGCharge(pdf->GetPDGCharge()); |
---|
128 | |
---|
129 | |
---|
130 | G4Polyline pPolyline; |
---|
131 | for (int i = 0; i < trj.GetPointEntries() ; i++) { |
---|
132 | G4VTrajectoryPoint* trjPoint = trj.GetPoint(i); |
---|
133 | pos = trjPoint->GetPosition(); |
---|
134 | pPolyline.push_back( pos ); |
---|
135 | } |
---|
136 | |
---|
137 | G4Colour colour; |
---|
138 | if (ParticleName == "proton") { |
---|
139 | colour = G4Colour(1,0,1); // magenta |
---|
140 | } |
---|
141 | else if (ParticleName == "neutron") { |
---|
142 | colour = G4Colour(0,1,1); // cyan |
---|
143 | } |
---|
144 | else if (ParticleName == "gamma") { |
---|
145 | colour = G4Colour(1,1,0); // yellow |
---|
146 | } |
---|
147 | else { |
---|
148 | if(PDGCharge<0.) |
---|
149 | colour = G4Colour(1.,0.,0.); // red |
---|
150 | else if(PDGCharge>0.) |
---|
151 | colour = G4Colour(0.,0.,1.); // blue |
---|
152 | else |
---|
153 | colour = G4Colour(0.,1.,0.); // green |
---|
154 | } |
---|
155 | G4VisAttributes attribs(colour); |
---|
156 | pPolyline.SetVisAttributes(attribs); |
---|
157 | if(pVVisManager) { |
---|
158 | pVVisManager->Draw(pPolyline); |
---|
159 | } |
---|
160 | } |
---|