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: OlapSteppingAction.cc,v 1.3 2006/06/29 17:23:13 gunter Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-04-beta-01 $ |
---|
29 | // |
---|
30 | // |
---|
31 | // -------------------------------------------------------------- |
---|
32 | // OlapSteppingAction |
---|
33 | // |
---|
34 | // Author: Martin Liendl - Martin.Liendl@cern.ch |
---|
35 | // |
---|
36 | // -------------------------------------------------------------- |
---|
37 | // |
---|
38 | #include "OlapSteppingAction.hh" |
---|
39 | #include "OlapEventAction.hh" |
---|
40 | #include "G4EventManager.hh" |
---|
41 | #include "G4RunManager.hh" |
---|
42 | #include "G4Track.hh" |
---|
43 | #include "G4TouchableHistory.hh" |
---|
44 | #include "G4NavigationHistory.hh" |
---|
45 | #include "G4Step.hh" |
---|
46 | #include "G4VSolid.hh" |
---|
47 | #include "SolidAnalyser.hh" |
---|
48 | |
---|
49 | std::ostream& |
---|
50 | operator << (std::ostream& os, std::vector<OlapStepInfo*>& vec) |
---|
51 | { |
---|
52 | std::vector<OlapStepInfo*>::iterator it = vec.begin(); |
---|
53 | while (it!=vec.end()) |
---|
54 | { |
---|
55 | G4VPhysicalVolume * pv = (*it)->theHist.GetTopVolume(); |
---|
56 | os << (*it)->thePoint << " [" << pv->GetName() << ":" << pv->GetCopyNo() |
---|
57 | << "]" << G4endl; |
---|
58 | it++; |
---|
59 | } |
---|
60 | return os; |
---|
61 | } |
---|
62 | |
---|
63 | std::ostream& |
---|
64 | operator << (std::ostream& os, const OlapStepInfo& aStepInfo) |
---|
65 | { |
---|
66 | //G4cout << "History depth="<<aStepInfo.theHist.GetDepth()<< G4endl; |
---|
67 | for (G4int i=0;i<=aStepInfo.theHist.GetDepth();i++) |
---|
68 | { |
---|
69 | G4VSolid * solid = |
---|
70 | aStepInfo.theHist.GetVolume(i)->GetLogicalVolume()->GetSolid(); |
---|
71 | SolidAnalyser * solAna = SolidAnalyser::GetSolidAnalyser(); |
---|
72 | std::vector< std::pair<G4String,G4double> > param; |
---|
73 | solAna->GetParam(solid,param); |
---|
74 | |
---|
75 | os << "["<<i<<"]: " ; |
---|
76 | const G4AffineTransform & transP = aStepInfo.theHist.GetTransform(i); |
---|
77 | G4ThreeVector locP(transP.TransformPoint(aStepInfo.thePoint)); |
---|
78 | char c = '?'; |
---|
79 | if (solid->Inside(locP)==kInside) |
---|
80 | c='i'; |
---|
81 | if (solid->Inside(locP)==kOutside) |
---|
82 | c='o'; |
---|
83 | if (solid->Inside(locP)==kSurface) |
---|
84 | c='s'; |
---|
85 | os << " ins=[" << c << "] " ; // << "lok.pt.=" << locP; |
---|
86 | if( aStepInfo.theHist.GetVolume(i) != 0 ) { |
---|
87 | os << " PVName=["<< aStepInfo.theHist.GetVolume(i)->GetName() << ":" |
---|
88 | << aStepInfo.theHist.GetVolume(i)->GetCopyNo() |
---|
89 | << "] Type=["; |
---|
90 | switch(aStepInfo.theHist.GetVolumeType(i)) |
---|
91 | { |
---|
92 | case kNormal: |
---|
93 | os <<"N"; |
---|
94 | break; |
---|
95 | case kReplica: |
---|
96 | os <<"R" << aStepInfo.theHist.GetReplicaNo(i); |
---|
97 | break; |
---|
98 | case kParameterised: |
---|
99 | os <<"P" << aStepInfo.theHist.GetReplicaNo(i); |
---|
100 | break; |
---|
101 | } |
---|
102 | os << "] "; |
---|
103 | }else{ |
---|
104 | os << "Phys = <Null>"; |
---|
105 | } |
---|
106 | |
---|
107 | const G4AffineTransform & trans = |
---|
108 | aStepInfo.theHist.GetTransform(i).Inverse(); |
---|
109 | |
---|
110 | os << "P=" << trans.NetTranslation() |
---|
111 | << " R=[" << trans.NetRotation().phiX()/degree << "," |
---|
112 | << trans.NetRotation().thetaX()/degree << "," |
---|
113 | << trans.NetRotation().phiY()/degree << "," |
---|
114 | << trans.NetRotation().thetaY()/degree << "," |
---|
115 | << trans.NetRotation().phiZ()/degree << "," |
---|
116 | << trans.NetRotation().thetaZ()/degree << "] "; |
---|
117 | |
---|
118 | // solid specification |
---|
119 | |
---|
120 | os << " " << solid->GetEntityType() << ": "; |
---|
121 | std::vector< std::pair<G4String,G4double> >::iterator it = |
---|
122 | param.begin(); |
---|
123 | while ( it != param.end() ) |
---|
124 | { |
---|
125 | os << (*it).first << '=' << (*it).second << " "; |
---|
126 | it++; |
---|
127 | } |
---|
128 | os << G4endl; |
---|
129 | } |
---|
130 | return os; |
---|
131 | } |
---|
132 | |
---|
133 | |
---|
134 | OlapSteppingAction::OlapSteppingAction(OlapEventAction * aEvAct) |
---|
135 | : theEventAction(aEvAct) |
---|
136 | { |
---|
137 | } |
---|
138 | |
---|
139 | |
---|
140 | OlapSteppingAction::~OlapSteppingAction() |
---|
141 | { |
---|
142 | } |
---|
143 | |
---|
144 | |
---|
145 | void OlapSteppingAction::UserSteppingAction(const G4Step * aStep) |
---|
146 | { |
---|
147 | const G4Track * aTrack = aStep->GetTrack(); |
---|
148 | const G4NavigationHistory & aHist = *(aTrack->GetTouchable()->GetHistory()); |
---|
149 | G4int aTrackID = aTrack->GetTrackID(); |
---|
150 | G4int aStepNo = aTrack->GetCurrentStepNumber(); |
---|
151 | //G4cout << "Stepping: " << aTrack->GetVolume()->GetName() |
---|
152 | // << " CpNr: " << aTrack->GetVolume()->GetCopyNo() << G4endl; |
---|
153 | |
---|
154 | if (aStepNo>999) { |
---|
155 | G4cerr << "OlapSteppingAction(): to many steps, killing track" << G4endl |
---|
156 | << " pv=[" << aTrack->GetVolume()->GetName() |
---|
157 | << "] cpnr=[" << aTrack->GetVolume()->GetCopyNo() |
---|
158 | << "] pos=" << aTrack->GetPosition() |
---|
159 | << G4endl; |
---|
160 | //G4EventManager::GetEventManager()->AbortCurrentEvent(); |
---|
161 | //G4RunManager::GetRunManager()->AbortRun(); |
---|
162 | G4Track * aNonConstTrack = const_cast<G4Track*>(aTrack); |
---|
163 | aNonConstTrack->SetTrackStatus(fStopAndKill); |
---|
164 | return; |
---|
165 | } |
---|
166 | OlapStepInfo * aStepInfo = new OlapStepInfo; |
---|
167 | |
---|
168 | aStepInfo->thePoint = aTrack->GetPosition(); |
---|
169 | aStepInfo->theHist = aHist; |
---|
170 | |
---|
171 | if (aTrackID % 2) |
---|
172 | { |
---|
173 | theEventAction->ABSteps.push_back(aStepInfo); |
---|
174 | } |
---|
175 | else |
---|
176 | { |
---|
177 | theEventAction->BASteps.push_back(aStepInfo); |
---|
178 | } |
---|
179 | //G4cout << *aStepInfo << G4endl; |
---|
180 | } |
---|