source: trunk/source/digits_hits/scorer/src/G4PSSphereSurfaceFlux.cc@ 834

Last change on this file since 834 was 814, checked in by garnier, 17 years ago

import all except CVS

File size: 7.2 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// $Id: G4PSSphereSurfaceFlux.cc,v 1.1 2007/07/11 01:31:03 asaim Exp $
28// GEANT4 tag $Name: $
29//
30// G4PSSphereSurfaceFlux
31#include "G4PSSphereSurfaceFlux.hh"
32#include "G4StepStatus.hh"
33#include "G4Track.hh"
34#include "G4UnitsTable.hh"
35#include "G4GeometryTolerance.hh"
36////////////////////////////////////////////////////////////////////////////////
37// (Description)
38// This is a primitive scorer class for scoring only Surface Flux.
39// Flux version assumes only for G4Sphere shape.
40//
41// Surface is defined at the inside of sphere.
42// Direction -Rmin +Rmax
43// 0 IN || OUT ->|<- |
44// 1 IN ->| |
45// 2 OUT |<- |
46//
47// Created: 2005-11-14 Tsukasa ASO, Akinori Kimura.
48// 29-Mar-2007 T.Aso, Bug fix for momentum direction at outgoing flux.
49//
50///////////////////////////////////////////////////////////////////////////////
51
52G4PSSphereSurfaceFlux::G4PSSphereSurfaceFlux(G4String name,
53 G4int direction, G4int depth)
54 :G4VPrimitiveScorer(name,depth),HCID(-1),fDirection(direction)
55{;}
56
57G4PSSphereSurfaceFlux::~G4PSSphereSurfaceFlux()
58{;}
59
60G4bool G4PSSphereSurfaceFlux::ProcessHits(G4Step* aStep,G4TouchableHistory*)
61{
62 G4StepPoint* preStep = aStep->GetPreStepPoint();
63 G4VSolid * solid =
64 preStep->GetPhysicalVolume()->GetLogicalVolume()->GetSolid();
65 if( solid->GetEntityType() != "G4Sphere" ){
66 G4Exception("G4PSSphereSurfaceFluxScorer. - Solid type is not supported.");
67 return FALSE;
68 }
69 G4Sphere* sphereSolid = (G4Sphere*)(solid);
70
71 G4int dirFlag =IsSelectedSurface(aStep,sphereSolid);
72 if ( dirFlag > 0 ) {
73 if ( fDirection == fFlux_InOut || fDirection == dirFlag ){
74
75 G4StepPoint* thisStep=0;
76 if ( dirFlag == fFlux_In ){
77 thisStep = preStep;
78 }else if ( dirFlag == fFlux_Out ){
79 thisStep = aStep->GetPreStepPoint();
80 }else{
81 return FALSE;
82 }
83
84 G4TouchableHandle theTouchable = thisStep->GetTouchableHandle();
85 G4ThreeVector pdirection = thisStep->GetMomentumDirection();
86 G4ThreeVector localdir =
87 theTouchable->GetHistory()->GetTopTransform().TransformAxis(pdirection);
88 G4double localdirL2 = localdir.x()*localdir.x()
89 +localdir.y()*localdir.y()
90 +localdir.z()*localdir.z();
91 G4ThreeVector stppos1= aStep->GetPreStepPoint()->GetPosition();
92 G4ThreeVector localpos1 =
93 theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos1);
94 G4double localR2 = localpos1.x()*localpos1.x()
95 +localpos1.y()*localpos1.y()
96 +localpos1.z()*localpos1.z();
97 G4double anglefactor = (localdir.x()*localpos1.x()
98 +localdir.y()*localpos1.y()
99 +localdir.z()*localpos1.z())
100 /std::sqrt(localdirL2)/std::sqrt(localR2);
101
102 G4double radi = sphereSolid->GetInsideRadius();
103 G4double dph = sphereSolid->GetDeltaPhiAngle()/radian;
104 G4double stth = sphereSolid->GetStartThetaAngle()/radian;
105 G4double enth = stth+sphereSolid->GetDeltaThetaAngle()/radian;
106 G4double square = radi*radi*dph*( -std::cos(enth) + std::cos(stth) );
107
108 G4double current = thisStep->GetWeight(); // Flux (Particle Weight)
109 current = current/square; // Flux with angle.
110
111 current /= anglefactor;
112
113 G4int index = GetIndex(aStep);
114 EvtMap->add(index,current);
115 }
116 }
117
118 return TRUE;
119}
120
121G4int G4PSSphereSurfaceFlux::IsSelectedSurface(G4Step* aStep, G4Sphere* sphereSolid){
122
123 G4TouchableHandle theTouchable =
124 aStep->GetPreStepPoint()->GetTouchableHandle();
125 G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
126
127 if (aStep->GetPreStepPoint()->GetStepStatus() == fGeomBoundary ){
128 // Entering Geometry
129 G4ThreeVector stppos1= aStep->GetPreStepPoint()->GetPosition();
130 G4ThreeVector localpos1 =
131 theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos1);
132 G4double localR2 = localpos1.x()*localpos1.x()
133 +localpos1.y()*localpos1.y()
134 +localpos1.z()*localpos1.z();
135 G4double InsideRadius2 =
136 sphereSolid->GetInsideRadius()*sphereSolid->GetInsideRadius();
137 if(std::fabs( localR2 - InsideRadius2 ) < kCarTolerance ){
138 return fFlux_In;
139 }
140 }
141
142 if (aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary ){
143 // Exiting Geometry
144 G4ThreeVector stppos2= aStep->GetPostStepPoint()->GetPosition();
145 G4ThreeVector localpos2 =
146 theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos2);
147 G4double localR2 = localpos2.x()*localpos2.x()
148 +localpos2.y()*localpos2.y()
149 +localpos2.z()*localpos2.z();
150 G4double InsideRadius2 =
151 sphereSolid->GetInsideRadius()*sphereSolid->GetInsideRadius();
152 if(std::fabs( localR2 - InsideRadius2 ) < kCarTolerance ){
153 return fFlux_Out;
154 }
155 }
156
157 return -1;
158}
159
160void G4PSSphereSurfaceFlux::Initialize(G4HCofThisEvent* HCE)
161{
162 EvtMap = new G4THitsMap<G4double>(detector->GetName(), GetName());
163 if ( HCID < 0 ) HCID = GetCollectionID(0);
164 HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap);
165}
166
167void G4PSSphereSurfaceFlux::EndOfEvent(G4HCofThisEvent*)
168{;}
169
170void G4PSSphereSurfaceFlux::clear(){
171 EvtMap->clear();
172}
173
174void G4PSSphereSurfaceFlux::DrawAll()
175{;}
176
177void G4PSSphereSurfaceFlux::PrintAll()
178{
179 G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl;
180 G4cout << " PrimitiveScorer " << GetName() <<G4endl;
181 G4cout << " Number of entries " << EvtMap->entries() << G4endl;
182 std::map<G4int,G4double*>::iterator itr = EvtMap->GetMap()->begin();
183 for(; itr != EvtMap->GetMap()->end(); itr++) {
184 G4cout << " copy no.: " << itr->first
185 << " current : " << *(itr->second)
186 << G4endl;
187 }
188}
189
Note: See TracBrowser for help on using the repository browser.