source: trunk/source/digits_hits/scorer/src/G4PSFlatSurfaceCurrent.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: 6.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: G4PSFlatSurfaceCurrent.cc,v 1.3 2008/12/29 00:17:14 asaim Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-01 $
29//
30// G4PSFlatSurfaceCurrent
31#include "G4PSFlatSurfaceCurrent.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 Flux.
42// Current version assumes only for G4Box shape.
43//
44// Surface is defined at the -Z surface.
45// Direction -Z +Z
46// 0 IN || OUT ->|<- |
47// 1 IN ->| |
48// 2 OUT |<- |
49//
50// Created: 2005-11-14 Tsukasa ASO, Akinori Kimura.
51// 17-Nov-2005 T.Aso, Bug fix for area definition.
52// 31-Mar-2007 T.Aso, Add option for normalizing by the area.
53//
54///////////////////////////////////////////////////////////////////////////////
55
56
57G4PSFlatSurfaceCurrent::G4PSFlatSurfaceCurrent(G4String name,
58 G4int direction, G4int depth)
59 :G4VPrimitiveScorer(name,depth),HCID(-1),fDirection(direction),
60 weighted(true),divideByArea(true)
61{;}
62
63G4PSFlatSurfaceCurrent::~G4PSFlatSurfaceCurrent()
64{;}
65
66G4bool G4PSFlatSurfaceCurrent::ProcessHits(G4Step* aStep,G4TouchableHistory*)
67{
68 G4StepPoint* preStep = aStep->GetPreStepPoint();
69 G4VPhysicalVolume* physVol = preStep->GetPhysicalVolume();
70 G4VPVParameterisation* physParam = physVol->GetParameterisation();
71 G4VSolid * solid = 0;
72 if(physParam)
73 { // for parameterized volume
74 G4int idx = ((G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable()))
75 ->GetReplicaNumber(indexDepth);
76 solid = physParam->ComputeSolid(idx, physVol);
77 solid->ComputeDimensions(physParam,idx,physVol);
78 }
79 else
80 { // for ordinary volume
81 solid = physVol->GetLogicalVolume()->GetSolid();
82 }
83
84// if( solid->GetEntityType() != "G4Box" ){
85// G4Exception("G4PSFlatSurfaceCurrentScorer. - Solid type is not supported.");
86// return FALSE;
87// }
88 G4Box* boxSolid = (G4Box*)(solid);
89
90 G4int dirFlag =IsSelectedSurface(aStep,boxSolid);
91 if ( dirFlag > 0 ) {
92 if ( fDirection == fCurrent_InOut || fDirection == dirFlag ){
93 G4int index = GetIndex(aStep);
94 G4TouchableHandle theTouchable = preStep->GetTouchableHandle();
95 G4double current = 1.0;
96 if ( weighted ) current=preStep->GetWeight(); // Current (Particle Weight)
97 if ( divideByArea ){
98 G4double square = 4.*boxSolid->GetXHalfLength()*boxSolid->GetYHalfLength();
99 current = current/square; // Normalized by Area
100 }
101 EvtMap->add(index,current);
102 }
103 }
104
105 return TRUE;
106}
107
108G4int G4PSFlatSurfaceCurrent::IsSelectedSurface(G4Step* aStep, G4Box* boxSolid){
109
110 G4TouchableHandle theTouchable =
111 aStep->GetPreStepPoint()->GetTouchableHandle();
112 G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
113
114 if (aStep->GetPreStepPoint()->GetStepStatus() == fGeomBoundary ){
115 // Entering Geometry
116 G4ThreeVector stppos1= aStep->GetPreStepPoint()->GetPosition();
117 G4ThreeVector localpos1 =
118 theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos1);
119 if(std::fabs( localpos1.z() + boxSolid->GetZHalfLength())<kCarTolerance ){
120 return fCurrent_In;
121 }
122 }
123
124 if (aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary ){
125 // Exiting Geometry
126 G4ThreeVector stppos2= aStep->GetPostStepPoint()->GetPosition();
127 G4ThreeVector localpos2 =
128 theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos2);
129 if(std::fabs( localpos2.z() + boxSolid->GetZHalfLength())<kCarTolerance ){
130 return fCurrent_Out;
131 }
132 }
133
134 return -1;
135}
136
137void G4PSFlatSurfaceCurrent::Initialize(G4HCofThisEvent* HCE)
138{
139 EvtMap = new G4THitsMap<G4double>(detector->GetName(), GetName());
140 if ( HCID < 0 ) HCID = GetCollectionID(0);
141 HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap);
142}
143
144void G4PSFlatSurfaceCurrent::EndOfEvent(G4HCofThisEvent*)
145{;}
146
147void G4PSFlatSurfaceCurrent::clear(){
148 EvtMap->clear();
149}
150
151void G4PSFlatSurfaceCurrent::DrawAll()
152{;}
153
154void G4PSFlatSurfaceCurrent::PrintAll()
155{
156 G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl;
157 G4cout << " PrimitiveScorer " << GetName() <<G4endl;
158 G4cout << " Number of entries " << EvtMap->entries() << G4endl;
159 std::map<G4int,G4double*>::iterator itr = EvtMap->GetMap()->begin();
160 for(; itr != EvtMap->GetMap()->end(); itr++) {
161 G4cout << " copy no.: " << itr->first << " current : " ;
162 if ( divideByArea ) G4cout << *(itr->second)*cm*cm << " [/cm2] ";
163 else G4cout << *(itr->second) << " [track]";
164 G4cout << G4endl;
165 }
166}
167
Note: See TracBrowser for help on using the repository browser.