source: trunk/source/digits_hits/scorer/src/G4PSCylinderSurfaceCurrent.cc@ 1339

Last change on this file since 1339 was 1337, checked in by garnier, 15 years ago

tag geant4.9.4 beta 1 + modifs locales

File size: 7.3 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: G4PSCylinderSurfaceCurrent.cc,v 1.3 2009/11/14 00:01:13 asaim Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-01 $
29//
30// G4PSCylinderSurfaceCurrent
31#include "G4PSCylinderSurfaceCurrent.hh"
32#include "G4StepStatus.hh"
33#include "G4Track.hh"
34#include "G4VSolid.hh"
35#include "G4VPhysicalVolume.hh"
36#include "G4VPVParameterisation.hh"
37#include "G4UnitsTable.hh"
38#include "G4GeometryTolerance.hh"
39////////////////////////////////////////////////////////////////////////////////
40// (Description)
41// This is a primitive scorer class for scoring only Surface Current.
42// Current version assumes only for G4Tubs shape.
43//
44// Surface is defined at the inner surface of the tube.
45// Direction R R+dR
46// 0 IN || OUT ->|<- |
47// 1 IN ->| |
48// 2 OUT |<- |
49//
50// Created: 2007-03-21 Tsukasa ASO
51//
52///////////////////////////////////////////////////////////////////////////////
53
54
55G4PSCylinderSurfaceCurrent::G4PSCylinderSurfaceCurrent(G4String name,
56 G4int direction, G4int depth)
57 :G4VPrimitiveScorer(name,depth),HCID(-1),fDirection(direction),
58 weighted(true),divideByArea(true)
59{;}
60
61G4PSCylinderSurfaceCurrent::~G4PSCylinderSurfaceCurrent()
62{;}
63
64G4bool G4PSCylinderSurfaceCurrent::ProcessHits(G4Step* aStep,G4TouchableHistory*)
65{
66 G4StepPoint* preStep = aStep->GetPreStepPoint();
67 G4VPhysicalVolume* physVol = preStep->GetPhysicalVolume();
68 G4VPVParameterisation* physParam = physVol->GetParameterisation();
69 G4VSolid * solid = 0;
70 if(physParam)
71 { // for parameterized volume
72 G4int idx = ((G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable()))
73 ->GetReplicaNumber(indexDepth);
74 solid = physParam->ComputeSolid(idx, physVol);
75 solid->ComputeDimensions(physParam,idx,physVol);
76 }
77 else
78 { // for ordinary volume
79 solid = physVol->GetLogicalVolume()->GetSolid();
80 }
81
82// if( solid->GetEntityType() != "G4Tubs" ){
83// G4Exception("G4PSCylinderSurfaceCurrentScorer. - Solid type is not supported.");
84// return FALSE;
85// }
86 G4Tubs* tubsSolid = (G4Tubs*)(solid);
87
88 G4int dirFlag =IsSelectedSurface(aStep,tubsSolid);
89 G4cout << " pos " << preStep->GetPosition() <<" dirFlag " << G4endl;
90 if ( dirFlag > 0 ) {
91 if ( fDirection == fCurrent_InOut || fDirection == dirFlag ){
92 G4TouchableHandle theTouchable = preStep->GetTouchableHandle();
93 //
94 G4double current = 1.0;
95 if ( weighted ) current = preStep->GetWeight(); // Current (Particle Weight)
96 //
97 if ( divideByArea ){
98 G4double square = 2.*tubsSolid->GetZHalfLength()
99 *tubsSolid->GetInnerRadius()* tubsSolid->GetDeltaPhiAngle()/radian;
100 current = current/square; // Current normalized by Area
101 }
102
103 G4int index = GetIndex(aStep);
104 EvtMap->add(index,current);
105 }
106
107 }
108
109 return TRUE;
110}
111
112G4int G4PSCylinderSurfaceCurrent::IsSelectedSurface(G4Step* aStep, G4Tubs* tubsSolid){
113
114 G4TouchableHandle theTouchable =
115 aStep->GetPreStepPoint()->GetTouchableHandle();
116 G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
117
118 if (aStep->GetPreStepPoint()->GetStepStatus() == fGeomBoundary ){
119 // Entering Geometry
120 G4ThreeVector stppos1= aStep->GetPreStepPoint()->GetPosition();
121 G4ThreeVector localpos1 =
122 theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos1);
123 if ( std::fabs(localpos1.z()) > tubsSolid->GetZHalfLength() ) return -1;
124 //if(std::fabs( localpos1.x()*localpos1.x()+localpos1.y()*localpos1.y()
125 // -(tubsSolid->GetInnerRadius()*tubsSolid->GetInnerRadius()))
126 // < kCarTolerance ){
127 G4double localR2 = localpos1.x()*localpos1.x()+localpos1.y()*localpos1.y();
128 G4double InsideRadius = tubsSolid->GetInnerRadius();
129 if (localR2 > (InsideRadius-kCarTolerance)*(InsideRadius-kCarTolerance)
130 &&localR2 < (InsideRadius+kCarTolerance)*(InsideRadius+kCarTolerance)){
131 return fCurrent_In;
132 }
133 }
134
135 if (aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary ){
136 // Exiting Geometry
137 G4ThreeVector stppos2= aStep->GetPostStepPoint()->GetPosition();
138 G4ThreeVector localpos2 =
139 theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos2);
140 if ( std::fabs(localpos2.z()) > tubsSolid->GetZHalfLength() ) return -1;
141 //if(std::fabs( localpos2.x()*localpos2.x()+localpos2.y()*localpos2.y()
142 // - (tubsSolid->GetInnerRadius()*tubsSolid->GetInnerRadius()))
143 // <kCarTolerance ){
144 G4double localR2 = localpos2.x()*localpos2.x()+localpos2.y()*localpos2.y();
145 G4double InsideRadius = tubsSolid->GetInnerRadius();
146 if (localR2 > (InsideRadius-kCarTolerance)*(InsideRadius-kCarTolerance)
147 &&localR2 < (InsideRadius+kCarTolerance)*(InsideRadius+kCarTolerance)){
148 return fCurrent_Out;
149 }
150 }
151
152 return -1;
153}
154
155void G4PSCylinderSurfaceCurrent::Initialize(G4HCofThisEvent* HCE)
156{
157 EvtMap = new G4THitsMap<G4double>(detector->GetName(), GetName());
158 if ( HCID < 0 ) HCID = GetCollectionID(0);
159 HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap);
160}
161
162void G4PSCylinderSurfaceCurrent::EndOfEvent(G4HCofThisEvent*)
163{;}
164
165void G4PSCylinderSurfaceCurrent::clear(){
166 EvtMap->clear();
167}
168
169void G4PSCylinderSurfaceCurrent::DrawAll()
170{;}
171
172void G4PSCylinderSurfaceCurrent::PrintAll()
173{
174 G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl;
175 G4cout << " PrimitiveScorer " << GetName() <<G4endl;
176 G4cout << " Number of entries " << EvtMap->entries() << G4endl;
177 std::map<G4int,G4double*>::iterator itr = EvtMap->GetMap()->begin();
178 for(; itr != EvtMap->GetMap()->end(); itr++) {
179 G4cout << " copy no.: " << itr->first
180 << " current : " ;
181 if ( divideByArea ) G4cout << *(itr->second)*cm*cm << " [/cm2]";
182 else G4cout << *(itr->second) << " [track]";
183 G4cout << G4endl;
184 }
185}
186
Note: See TracBrowser for help on using the repository browser.