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.5 2010/07/23 04:35:38 taso Exp $ |
---|
28 | // GEANT4 tag $Name: $ |
---|
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 | // 2010-07-22 Introduce Unit specification. |
---|
54 | // |
---|
55 | /////////////////////////////////////////////////////////////////////////////// |
---|
56 | |
---|
57 | |
---|
58 | G4PSFlatSurfaceCurrent::G4PSFlatSurfaceCurrent(G4String name, |
---|
59 | G4int direction, G4int depth) |
---|
60 | :G4VPrimitiveScorer(name,depth),HCID(-1),fDirection(direction), |
---|
61 | weighted(true),divideByArea(true) |
---|
62 | { |
---|
63 | DefineUnitAndCategory(); |
---|
64 | SetUnit("percm2"); |
---|
65 | } |
---|
66 | |
---|
67 | G4PSFlatSurfaceCurrent::G4PSFlatSurfaceCurrent(G4String name, |
---|
68 | G4int direction, |
---|
69 | const G4String& unit, |
---|
70 | G4int depth) |
---|
71 | :G4VPrimitiveScorer(name,depth),HCID(-1),fDirection(direction), |
---|
72 | weighted(true),divideByArea(true) |
---|
73 | { |
---|
74 | DefineUnitAndCategory(); |
---|
75 | SetUnit(unit); |
---|
76 | } |
---|
77 | |
---|
78 | G4PSFlatSurfaceCurrent::~G4PSFlatSurfaceCurrent() |
---|
79 | {;} |
---|
80 | |
---|
81 | G4bool G4PSFlatSurfaceCurrent::ProcessHits(G4Step* aStep,G4TouchableHistory*) |
---|
82 | { |
---|
83 | G4StepPoint* preStep = aStep->GetPreStepPoint(); |
---|
84 | G4VPhysicalVolume* physVol = preStep->GetPhysicalVolume(); |
---|
85 | G4VPVParameterisation* physParam = physVol->GetParameterisation(); |
---|
86 | G4VSolid * solid = 0; |
---|
87 | if(physParam) |
---|
88 | { // for parameterized volume |
---|
89 | G4int idx = ((G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable())) |
---|
90 | ->GetReplicaNumber(indexDepth); |
---|
91 | solid = physParam->ComputeSolid(idx, physVol); |
---|
92 | solid->ComputeDimensions(physParam,idx,physVol); |
---|
93 | } |
---|
94 | else |
---|
95 | { // for ordinary volume |
---|
96 | solid = physVol->GetLogicalVolume()->GetSolid(); |
---|
97 | } |
---|
98 | |
---|
99 | G4Box* boxSolid = (G4Box*)(solid); |
---|
100 | |
---|
101 | G4int dirFlag =IsSelectedSurface(aStep,boxSolid); |
---|
102 | if ( dirFlag > 0 ) { |
---|
103 | if ( fDirection == fCurrent_InOut || fDirection == dirFlag ){ |
---|
104 | G4int index = GetIndex(aStep); |
---|
105 | G4TouchableHandle theTouchable = preStep->GetTouchableHandle(); |
---|
106 | G4double current = 1.0; |
---|
107 | if ( weighted ) current=preStep->GetWeight(); // Current (Particle Weight) |
---|
108 | if ( divideByArea ){ |
---|
109 | G4double square = 4.*boxSolid->GetXHalfLength()*boxSolid->GetYHalfLength(); |
---|
110 | current = current/square; // Normalized by Area |
---|
111 | } |
---|
112 | EvtMap->add(index,current); |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | return TRUE; |
---|
117 | } |
---|
118 | |
---|
119 | G4int G4PSFlatSurfaceCurrent::IsSelectedSurface(G4Step* aStep, G4Box* boxSolid){ |
---|
120 | |
---|
121 | G4TouchableHandle theTouchable = |
---|
122 | aStep->GetPreStepPoint()->GetTouchableHandle(); |
---|
123 | G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance(); |
---|
124 | |
---|
125 | if (aStep->GetPreStepPoint()->GetStepStatus() == fGeomBoundary ){ |
---|
126 | // Entering Geometry |
---|
127 | G4ThreeVector stppos1= aStep->GetPreStepPoint()->GetPosition(); |
---|
128 | G4ThreeVector localpos1 = |
---|
129 | theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos1); |
---|
130 | if(std::fabs( localpos1.z() + boxSolid->GetZHalfLength())<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() + boxSolid->GetZHalfLength())<kCarTolerance ){ |
---|
141 | return fCurrent_Out; |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | return -1; |
---|
146 | } |
---|
147 | |
---|
148 | void G4PSFlatSurfaceCurrent::Initialize(G4HCofThisEvent* HCE) |
---|
149 | { |
---|
150 | EvtMap = new G4THitsMap<G4double>(detector->GetName(), GetName()); |
---|
151 | if ( HCID < 0 ) HCID = GetCollectionID(0); |
---|
152 | HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap); |
---|
153 | } |
---|
154 | |
---|
155 | void G4PSFlatSurfaceCurrent::EndOfEvent(G4HCofThisEvent*) |
---|
156 | {;} |
---|
157 | |
---|
158 | void G4PSFlatSurfaceCurrent::clear(){ |
---|
159 | EvtMap->clear(); |
---|
160 | } |
---|
161 | |
---|
162 | void G4PSFlatSurfaceCurrent::DrawAll() |
---|
163 | {;} |
---|
164 | |
---|
165 | void G4PSFlatSurfaceCurrent::PrintAll() |
---|
166 | { |
---|
167 | G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl; |
---|
168 | G4cout << " PrimitiveScorer " << GetName() <<G4endl; |
---|
169 | G4cout << " Number of entries " << EvtMap->entries() << G4endl; |
---|
170 | std::map<G4int,G4double*>::iterator itr = EvtMap->GetMap()->begin(); |
---|
171 | for(; itr != EvtMap->GetMap()->end(); itr++) { |
---|
172 | G4cout << " copy no.: " << itr->first << " current : " ; |
---|
173 | if ( divideByArea ) { |
---|
174 | G4cout << *(itr->second)/GetUnitValue() |
---|
175 | << " ["<<GetUnit()<<"]"; |
---|
176 | }else { |
---|
177 | G4cout << *(itr->second)/GetUnitValue() << " [tracks]"; |
---|
178 | } |
---|
179 | G4cout << G4endl; |
---|
180 | } |
---|
181 | } |
---|
182 | |
---|
183 | void G4PSFlatSurfaceCurrent::SetUnit(const G4String& unit) |
---|
184 | { |
---|
185 | if ( divideByArea ) { |
---|
186 | CheckAndSetUnit(unit,"Per Unit Surface"); |
---|
187 | } else { |
---|
188 | if (unit == "" ){ |
---|
189 | unitName = unit; |
---|
190 | unitValue = 1.0; |
---|
191 | }else{ |
---|
192 | G4String msg = "Invalid unit ["+unit+"] (Current unit is [" +GetUnit()+"] )"; |
---|
193 | G4Exception(GetName(),"DetScorer0000",JustWarning,msg); |
---|
194 | } |
---|
195 | } |
---|
196 | } |
---|
197 | |
---|
198 | void G4PSFlatSurfaceCurrent::DefineUnitAndCategory(){ |
---|
199 | // Per Unit Surface |
---|
200 | new G4UnitDefinition("percentimeter2","percm2","Per Unit Surface",(1./cm2)); |
---|
201 | new G4UnitDefinition("permillimeter2","permm2","Per Unit Surface",(1./mm2)); |
---|
202 | new G4UnitDefinition("permeter2","perm2","Per Unit Surface",(1./m2)); |
---|
203 | } |
---|
204 | |
---|