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

Last change on this file since 1202 was 1012, checked in by garnier, 15 years ago

update

File size: 6.6 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.2 2008/12/28 21:10:51 asaim Exp $
28// GEANT4 tag $Name: geant4-09-02-ref-02 $
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  if ( dirFlag > 0 ) {
90    if ( fDirection == fCurrent_InOut || fDirection == dirFlag ){
91      G4TouchableHandle theTouchable = preStep->GetTouchableHandle();
92      //
93      G4double current = 1.0;
94      if ( weighted ) current = preStep->GetWeight(); // Current (Particle Weight)
95      //
96      if ( divideByArea ){
97        G4double square = 2.*tubsSolid->GetZHalfLength()
98          *tubsSolid->GetInnerRadius()* tubsSolid->GetDeltaPhiAngle()/radian;
99        current = current/square;  // Current normalized by Area
100      }
101
102      G4int index = GetIndex(aStep);
103      EvtMap->add(index,current);
104    }
105
106  }
107
108  return TRUE;
109}
110
111G4int G4PSCylinderSurfaceCurrent::IsSelectedSurface(G4Step* aStep, G4Tubs* tubsSolid){
112
113  G4TouchableHandle theTouchable = 
114    aStep->GetPreStepPoint()->GetTouchableHandle();
115  G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance(); 
116
117  if (aStep->GetPreStepPoint()->GetStepStatus() == fGeomBoundary ){
118    // Entering Geometry
119    G4ThreeVector stppos1= aStep->GetPreStepPoint()->GetPosition();
120    G4ThreeVector localpos1 = 
121      theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos1);
122    if ( std::fabs(localpos1.z()) > tubsSolid->GetZHalfLength() ) return -1;
123    if(std::fabs( (localpos1.x()*localpos1.x()+localpos1.y()*localpos1.y())
124                  -(tubsSolid->GetInnerRadius()*tubsSolid->GetInnerRadius()) )
125       < kCarTolerance ){
126      return fCurrent_In;
127    }
128  }
129
130  if (aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary ){
131    // Exiting Geometry
132    G4ThreeVector stppos2= aStep->GetPostStepPoint()->GetPosition();
133    G4ThreeVector localpos2 = 
134      theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos2);
135    if ( std::fabs(localpos2.z()) > tubsSolid->GetZHalfLength() ) return -1;
136    if(std::fabs( (localpos2.x()*localpos2.x()+localpos2.y()*localpos2.y()) 
137                  - (tubsSolid->GetInnerRadius()*tubsSolid->GetInnerRadius()) )
138       <kCarTolerance ){
139      return fCurrent_Out;
140    }
141  }
142
143  return -1;
144}
145
146void G4PSCylinderSurfaceCurrent::Initialize(G4HCofThisEvent* HCE)
147{
148  EvtMap = new G4THitsMap<G4double>(detector->GetName(), GetName());
149  if ( HCID < 0 ) HCID = GetCollectionID(0);
150  HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap);
151}
152
153void G4PSCylinderSurfaceCurrent::EndOfEvent(G4HCofThisEvent*)
154{;}
155
156void G4PSCylinderSurfaceCurrent::clear(){
157  EvtMap->clear();
158}
159
160void G4PSCylinderSurfaceCurrent::DrawAll()
161{;}
162
163void G4PSCylinderSurfaceCurrent::PrintAll()
164{
165  G4cout << " MultiFunctionalDet  " << detector->GetName() << G4endl;
166  G4cout << " PrimitiveScorer " << GetName() <<G4endl; 
167  G4cout << " Number of entries " << EvtMap->entries() << G4endl;
168  std::map<G4int,G4double*>::iterator itr = EvtMap->GetMap()->begin();
169  for(; itr != EvtMap->GetMap()->end(); itr++) {
170    G4cout << "  copy no.: " << itr->first
171           << "  current  : " ;
172    if ( divideByArea ) G4cout << *(itr->second)*cm*cm << " [/cm2]";
173    else G4cout << *(itr->second) << " [track]";
174    G4cout << G4endl;
175  }
176}
177
Note: See TracBrowser for help on using the repository browser.