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