source: trunk/source/geometry/solids/test/fred/src/FredEventAction.cc@ 1350

Last change on this file since 1350 was 1316, checked in by garnier, 15 years ago

update geant4-09-04-beta-cand-01 interfaces-V09-03-09 vis-V09-03-08

File size: 4.9 KB
Line 
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// FredEventAction.cc
28//
29// Implementation of Fred's user action
30//
31
32#include "FredEventAction.hh"
33#include "G4UImanager.hh"
34#include "G4VVisManager.hh"
35#include "G4TrajectoryContainer.hh"
36#include "G4Event.hh"
37#include "G4EventManager.hh"
38#include "G4SDManager.hh"
39
40#include "FredHit.hh"
41#include "FredMessenger.hh"
42
43#include "FredTrackCheck.hh"
44
45//
46// Constructor
47//
48FredEventAction::FredEventAction( FredMessenger *ourMessenger )
49{
50 hitID = -1;
51 hitIDMother = -1;
52 messenger = ourMessenger;
53}
54
55//
56// Destructor
57//
58FredEventAction::~FredEventAction() {;}
59
60//
61// BeginOfEventAction
62//
63// Do something interesting at the beginning of each event
64//
65void FredEventAction::BeginOfEventAction(const G4Event*)
66{
67 //
68 // Get the hit collection id for our test hits
69 //
70 if (hitID < 0) {
71 G4SDManager *sensitiveMan = G4SDManager::GetSDMpointer();
72 hitID = sensitiveMan->GetCollectionID( "fredsStuff" );
73 hitIDMother = sensitiveMan->GetCollectionID( "fredsMotherStuff" );
74 }
75}
76
77//
78// EndOfEventAction
79//
80// Do something interesting at the end of each event
81//
82void FredEventAction::EndOfEventAction(const G4Event*)
83{
84
85 G4UImanager *UI = G4UImanager::GetUIpointer();
86
87 //
88 // Draw the event automatically
89 //
90 G4VVisManager *visManager = G4VVisManager::GetConcreteInstance();
91
92 if (visManager) {
93
94 // Prepare
95 UI->ApplyCommand( "/vis~/clear/view" );
96
97 // Draw detector
98 UI->ApplyCommand( "/vis~/draw/current" );
99
100 // Draw stuff
101 if (messenger->SelectedDrawing() == NORMAL)
102 DrawNormal();
103 else
104 DrawShadow();
105
106 // Finish
107 UI->ApplyCommand( "/vis~/show/view" );
108 }
109}
110
111
112//
113// DrawNormal
114//
115// Standard type GEANT4 display
116//
117void FredEventAction::DrawNormal()
118{
119 const G4Event *evt = fpEventManager->GetConstCurrentEvent();
120
121 // Draw trajectories, all in this case
122 G4TrajectoryContainer *trajectoryContainer = evt->GetTrajectoryContainer();
123 G4int numTraj = (trajectoryContainer) ? trajectoryContainer->entries() : 0;
124
125 while(numTraj--) {
126 G4VTrajectory *trajectory = (*trajectoryContainer)[numTraj];
127 trajectory->DrawTrajectory( 0 );
128 }
129
130 // Draw hits
131 G4HCofThisEvent *HCE = evt->GetHCofThisEvent();
132 FredHitCollection *hits = (FredHitCollection *)HCE->GetHC( hitID );
133 if (hits) hits->DrawAllHits();
134}
135
136
137//
138// DrawShadow
139//
140// Draw tracks that miss or have errors
141//
142void FredEventAction::DrawShadow()
143{
144 const G4Event *evt = fpEventManager->GetConstCurrentEvent();
145 G4HCofThisEvent *HCE = evt->GetHCofThisEvent();
146 FredHitCollection *hits = (FredHitCollection *)HCE->GetHC( hitID );
147
148 //
149 // Build a list of hit/track associations
150 //
151 FredTrackCheck checkTracks;
152
153 G4int numHit = (hits) ? hits->entries() : 0;
154 while(numHit--) {
155 FredHit *hit = (*hits)[numHit];
156 if (hit->GetEnters())
157 checkTracks.AddInHit( hit->GetTrack() );
158 else
159 checkTracks.AddOutHit( hit->GetTrack() );
160 }
161
162 //
163 // Now, loop over mother hits
164 //
165 hits = (FredHitCollection *)HCE->GetHC( hitIDMother );
166
167 numHit = (hits) ? hits->entries() : 0;
168 while(numHit--) {
169 G4int nIn, nOut;
170
171 FredHit *hit = (*hits)[numHit];
172
173 checkTracks.GetTrackStat( hit->GetTrack(), &nIn, &nOut );
174
175 if ((nIn == 0) && (nOut == 0)) {
176
177 // Pristeen track
178 hit->DrawShadowHit();
179 }
180 else if (nIn != nOut) {
181
182 // Oh oh! Track error
183 hit->DrawErrorHit();
184 }
185 else {
186
187 // Hit track
188 hit->DrawMaskHit();
189 }
190 }
191
192}
Note: See TracBrowser for help on using the repository browser.