source: trunk/source/geometry/solids/test/OpticalEscape/src/AXPETSteppingAction.cc @ 1316

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

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

File size: 6.1 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// $Id: AXPETSteppingAction.cc,v 1.1 2008/09/03 13:34:03 gcosmo Exp $
27// ------------------------------------------------------------
28// Geant4 class implementation file
29//
30// 03/09/2008, by T.Nikitina
31// ------------------------------------------------------------
32
33#include "G4SteppingManager.hh"
34#include "G4TrackVector.hh"
35
36#include "AXPETSteppingAction.hh"
37
38#include "AXPETDetectorConstruction.hh"
39#include "AXPETRunAction.hh"
40
41#include "G4Track.hh"
42#include "G4Event.hh"
43#include "G4EventManager.hh"
44#include "G4ParticleDefinition.hh"
45#include "G4ProcessManager.hh"
46#include "G4OpBoundaryProcess.hh"
47#include "G4ios.hh"
48#include <iomanip>
49#include "G4UImanager.hh"
50#include "G4VPhysicalVolume.hh"
51#include "G4VSolid.hh"
52#include "G4RotationMatrix.hh"
53#include "G4AffineTransform.hh"
54AXPETSteppingAction::AXPETSteppingAction(AXPETDetectorConstruction* DET,
55                                         AXPETRunAction* RA)
56:detector (DET), runaction (RA)
57{
58
59  G4cout << "Costructor of the Stepping Action class " << G4endl;
60 
61}
62
63
64AXPETSteppingAction::~AXPETSteppingAction()
65{;}
66
67
68void AXPETSteppingAction::UserSteppingAction(const G4Step* aStep)
69{
70
71  // track informations
72  //
73  // const G4StepPoint* prePoint = aStep->GetPreStepPoint();   
74  const G4StepPoint* endPoint = aStep->GetPostStepPoint();
75  const G4ParticleDefinition* particle = aStep->GetTrack()->GetDefinition(); 
76
77  G4String partName  = particle->GetParticleName();
78  G4VPhysicalVolume* postVolume_phys=endPoint->GetPhysicalVolume();
79  G4String solidName=" out of Crystal ";
80  if(postVolume_phys)    // Reach to out of the world
81  solidName = postVolume_phys->GetLogicalVolume()->GetSolid()->GetName();
82  //Detect optical photons going outside Volume
83
84  if(partName=="opticalphoton")
85  {
86    // Additional Printing on each Step
87    //
88    // G4cout<<aStep->GetTrack()->GetCurrentStepNumber()<<" StartPoint="<<prePoint->GetPosition()
89    // <<" EndPoint="<<endPoint->GetPosition()<<" NextSolid= "<<solidName<<G4endl;
90    // G4cout<<aStep->GetTrack()->GetCurrentStepNumber()<<" StartDirection="<<prePoint->GetMomentumDirection()
91    // <<" EndDirection="<<endPoint->GetMomentumDirection()<<" NextSolid= "<<solidName<<G4endl;
92    G4double x=endPoint->GetPosition().x()/mm;
93    G4double y=endPoint->GetPosition().y()/mm;
94    //
95    // Condition to detect Escaping Optical Photon:
96    //
97    if(std::sqrt(x*x+y*y)>(detector->GetExtend()*2.)){
98      G4cerr.precision(16);
99      G4cerr << "ERROR - UserSteppingAction::OpticalPhoton is out of Crystal Solid" << G4endl
100             <<" Wrong Point is "<<xStep<<"  "<<yStep<<"  "<<zStep << G4endl
101             <<" Wrong Direction is "<<xDirection<<"  "<<yDirection<<"  "<<zDirection<< G4endl;
102      G4VSolid *solid=detector->GetSolid();
103      G4ThreeVector point = G4ThreeVector(xStep,yStep,zStep);
104      G4ThreeVector dir = G4ThreeVector(xDirection,yDirection,zDirection); 
105        G4ThreeVector norm,*pNorm;
106        G4bool *pgoodNorm, goodNorm, calcNorm=true;
107        pNorm=&norm;
108        pgoodNorm=&goodNorm;
109
110       EInside surface=solid->Inside(point);
111       if(surface == kInside){
112         G4cout<<"WrongPoint is Inside DistanceToOut="<<solid->DistanceToOut(point,dir,calcNorm,pgoodNorm,pNorm)<<" Norm(DistToOut)="<<norm<<G4endl;
113       }
114       else if(surface == kOutside){
115       G4cout<<"WrongPoint is Outside DistanceToIn(p,+v)="<<solid->DistanceToIn(point,dir)<<G4endl;
116       G4cout<<"                      DistanceToIn(p,-v)="<<solid->DistanceToIn(point,-dir)<<G4endl;
117       }
118       else{
119       G4cout<<"WrongPoint is On Surface DistanceToIn(p,+v)="<<solid->DistanceToIn(point,dir)<<G4endl;
120       G4cout<<"                         DistanceToIn(p,-v)="<<solid->DistanceToIn(point,-dir)<<G4endl;
121       G4cout<<"                         DistanceToOut="<<solid->DistanceToOut(point,dir,calcNorm,pgoodNorm,pNorm)<<" Norm(DistanceToOut)="<<norm<<G4endl;
122       G4cout<<"                         SurfaceNormal=="<<solid->SurfaceNormal(point)<<G4endl;
123       }
124       if(detector->GetAbortAction()){
125       G4Exception( "  ", "Escaping Optical Photon",
126                  FatalException, "Optical Photon outside Crystal" );
127       }
128       else{
129       G4Exception( "  ", "Escaping Optical Photon",
130                  JustWarning, "Optical Photon outside Crystal" );
131       }
132    }
133    // Save values of Step
134   
135    xStep=x;
136    yStep=y;
137    zStep=endPoint->GetPosition().z()/mm;
138    xDirection=endPoint->GetMomentumDirection().x();
139    yDirection=endPoint->GetMomentumDirection().y();
140    zDirection=endPoint->GetMomentumDirection().z();
141  }
142}
Note: See TracBrowser for help on using the repository browser.