source: trunk/source/digits_hits/scorer/src/G4PSFlatSurfaceFlux.cc @ 814

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

import all except CVS

File size: 6.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: G4PSFlatSurfaceFlux.cc,v 1.1 2007/07/11 01:31:02 asaim Exp $
28// GEANT4 tag $Name:  $
29//
30// G4PSFlatSurfaceFlux
31#include "G4PSFlatSurfaceFlux.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 Surface Flux.
39//  Current version assumes only for G4Box shape, and the surface
40//  is fixed on -Z plane.
41//
42// Surface is defined at the -Z surface.
43// Direction                  -Z   +Z
44//   0  IN || OUT            ->|<-  |
45//   1  IN                   ->|    |
46//   2  OUT                    |<-  |
47//
48// Created: 2005-11-14  Tsukasa ASO, Akinori Kimura.
49//
50// 18-Nov-2005  T.Aso,  To use always positive value for anglefactor.
51// 29-Mar-2007  T.Aso,  Bug fix for momentum direction at outgoing flux.
52///////////////////////////////////////////////////////////////////////////////
53
54G4PSFlatSurfaceFlux::G4PSFlatSurfaceFlux(G4String name, 
55                                         G4int direction, G4int depth)
56  :G4VPrimitiveScorer(name,depth),HCID(-1),fDirection(direction)
57{;}
58
59G4PSFlatSurfaceFlux::~G4PSFlatSurfaceFlux()
60{;}
61
62G4bool G4PSFlatSurfaceFlux::ProcessHits(G4Step* aStep,G4TouchableHistory*)
63{
64  G4StepPoint* preStep = aStep->GetPreStepPoint();
65  G4VSolid * solid = 
66    preStep->GetPhysicalVolume()->GetLogicalVolume()->GetSolid();
67  if( solid->GetEntityType() != "G4Box" ){
68    G4Exception("G4PSFlatSurfaceFluxScorer. - Solid type is not supported.");
69    return FALSE;
70  }
71  G4Box* boxSolid = (G4Box*)(solid);
72
73  G4int dirFlag =IsSelectedSurface(aStep,boxSolid);
74  if ( dirFlag > 0 ) {
75    if ( fDirection == fFlux_InOut || fDirection == dirFlag ){
76
77      G4StepPoint* thisStep=0;
78      if ( dirFlag == fFlux_In ){
79        thisStep = preStep;
80      }else if ( dirFlag == fFlux_Out ){
81        thisStep = aStep->GetPostStepPoint();
82      }else{
83        return FALSE;
84      }
85
86      G4TouchableHandle theTouchable = thisStep->GetTouchableHandle();
87      G4ThreeVector pdirection = thisStep->GetMomentumDirection();
88      G4ThreeVector localdir  = 
89        theTouchable->GetHistory()->GetTopTransform().TransformAxis(pdirection);
90      //
91      G4double angleFactor = localdir.z();
92      if ( angleFactor < 0 ) angleFactor *= -1.;
93      G4double flux = preStep->GetWeight(); // Current (Particle Weight)
94      //
95      G4double square = 4.*boxSolid->GetXHalfLength()*boxSolid->GetYHalfLength();
96      //
97      flux = flux/angleFactor/square;  // Flux with angle.
98      //
99      G4int index = GetIndex(aStep);
100      EvtMap->add(index,flux);
101    }
102  }
103#ifdef debug
104    G4cout << " PASSED vol " 
105           << index << " trk "<<trkid<<" len " << fFlatSurfaceFlux<<G4endl;
106#endif
107
108  return TRUE;
109}
110
111G4int G4PSFlatSurfaceFlux::IsSelectedSurface(G4Step* aStep, G4Box* boxSolid){
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() + boxSolid->GetZHalfLength())<kCarTolerance ){
123      return fFlux_In;
124    }
125  }
126
127  if (aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary ){
128    // Exiting Geometry
129    G4ThreeVector stppos2= aStep->GetPostStepPoint()->GetPosition();
130    G4ThreeVector localpos2 = 
131      theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos2);
132    if(std::fabs( localpos2.z() + boxSolid->GetZHalfLength())<kCarTolerance ){
133      return fFlux_Out;
134    }
135  }
136
137  return -1;
138}
139
140void G4PSFlatSurfaceFlux::Initialize(G4HCofThisEvent* HCE)
141{
142  EvtMap = new G4THitsMap<G4double>(GetMultiFunctionalDetector()->GetName(),
143                                    GetName());
144  if ( HCID < 0 ) HCID = GetCollectionID(0);
145  HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap);
146}
147
148void G4PSFlatSurfaceFlux::EndOfEvent(G4HCofThisEvent*)
149{;}
150
151void G4PSFlatSurfaceFlux::clear(){
152  EvtMap->clear();
153}
154
155void G4PSFlatSurfaceFlux::DrawAll()
156{;}
157
158void G4PSFlatSurfaceFlux::PrintAll()
159{
160  G4cout << " MultiFunctionalDet  " << detector->GetName() << G4endl;
161  G4cout << " PrimitiveScorer" << GetName() <<G4endl; 
162  G4cout << " Number of entries " << EvtMap->entries() << G4endl;
163  std::map<G4int,G4double*>::iterator itr = EvtMap->GetMap()->begin();
164  for(; itr != EvtMap->GetMap()->end(); itr++) {
165    G4cout << "  copy no.: " << itr->first
166           << "  flux  : " << *(itr->second)*cm*cm << " [cm^-2]"
167           << G4endl;
168  }
169}
170
Note: See TracBrowser for help on using the repository browser.