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