[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 | // |
---|
[1012] | 27 | // $Id: G4PSFlatSurfaceFlux.cc,v 1.2 2008/12/29 00:17:14 asaim Exp $ |
---|
[1228] | 28 | // GEANT4 tag $Name: geant4-09-03 $ |
---|
[814] | 29 | // |
---|
| 30 | // G4PSFlatSurfaceFlux |
---|
| 31 | #include "G4PSFlatSurfaceFlux.hh" |
---|
| 32 | #include "G4StepStatus.hh" |
---|
| 33 | #include "G4Track.hh" |
---|
[1012] | 34 | #include "G4VSolid.hh" |
---|
| 35 | #include "G4VPhysicalVolume.hh" |
---|
| 36 | #include "G4VPVParameterisation.hh" |
---|
[814] | 37 | #include "G4UnitsTable.hh" |
---|
| 38 | #include "G4GeometryTolerance.hh" |
---|
| 39 | //////////////////////////////////////////////////////////////////////////////// |
---|
| 40 | // (Description) |
---|
| 41 | // This is a primitive scorer class for scoring Surface Flux. |
---|
| 42 | // Current version assumes only for G4Box shape, and the surface |
---|
| 43 | // is fixed on -Z plane. |
---|
| 44 | // |
---|
| 45 | // Surface is defined at the -Z surface. |
---|
| 46 | // Direction -Z +Z |
---|
| 47 | // 0 IN || OUT ->|<- | |
---|
| 48 | // 1 IN ->| | |
---|
| 49 | // 2 OUT |<- | |
---|
| 50 | // |
---|
| 51 | // Created: 2005-11-14 Tsukasa ASO, Akinori Kimura. |
---|
| 52 | // |
---|
| 53 | // 18-Nov-2005 T.Aso, To use always positive value for anglefactor. |
---|
| 54 | // 29-Mar-2007 T.Aso, Bug fix for momentum direction at outgoing flux. |
---|
| 55 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 56 | |
---|
| 57 | G4PSFlatSurfaceFlux::G4PSFlatSurfaceFlux(G4String name, |
---|
| 58 | G4int direction, G4int depth) |
---|
| 59 | :G4VPrimitiveScorer(name,depth),HCID(-1),fDirection(direction) |
---|
| 60 | {;} |
---|
| 61 | |
---|
| 62 | G4PSFlatSurfaceFlux::~G4PSFlatSurfaceFlux() |
---|
| 63 | {;} |
---|
| 64 | |
---|
| 65 | G4bool G4PSFlatSurfaceFlux::ProcessHits(G4Step* aStep,G4TouchableHistory*) |
---|
| 66 | { |
---|
| 67 | G4StepPoint* preStep = aStep->GetPreStepPoint(); |
---|
[1012] | 68 | G4VPhysicalVolume* physVol = preStep->GetPhysicalVolume(); |
---|
| 69 | G4VPVParameterisation* physParam = physVol->GetParameterisation(); |
---|
| 70 | G4VSolid * solid = 0; |
---|
| 71 | if(physParam) |
---|
| 72 | { // for parameterized volume |
---|
| 73 | G4int idx = ((G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable())) |
---|
| 74 | ->GetReplicaNumber(indexDepth); |
---|
| 75 | solid = physParam->ComputeSolid(idx, physVol); |
---|
| 76 | solid->ComputeDimensions(physParam,idx,physVol); |
---|
[814] | 77 | } |
---|
[1012] | 78 | else |
---|
| 79 | { // for ordinary volume |
---|
| 80 | solid = physVol->GetLogicalVolume()->GetSolid(); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | // if( solid->GetEntityType() != "G4Box" ){ |
---|
| 84 | // G4Exception("G4PSFlatSurfaceFluxScorer. - Solid type is not supported."); |
---|
| 85 | // return FALSE; |
---|
| 86 | // } |
---|
[814] | 87 | G4Box* boxSolid = (G4Box*)(solid); |
---|
| 88 | |
---|
| 89 | G4int dirFlag =IsSelectedSurface(aStep,boxSolid); |
---|
| 90 | if ( dirFlag > 0 ) { |
---|
| 91 | if ( fDirection == fFlux_InOut || fDirection == dirFlag ){ |
---|
| 92 | |
---|
| 93 | G4StepPoint* thisStep=0; |
---|
| 94 | if ( dirFlag == fFlux_In ){ |
---|
| 95 | thisStep = preStep; |
---|
| 96 | }else if ( dirFlag == fFlux_Out ){ |
---|
| 97 | thisStep = aStep->GetPostStepPoint(); |
---|
| 98 | }else{ |
---|
| 99 | return FALSE; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | G4TouchableHandle theTouchable = thisStep->GetTouchableHandle(); |
---|
| 103 | G4ThreeVector pdirection = thisStep->GetMomentumDirection(); |
---|
| 104 | G4ThreeVector localdir = |
---|
| 105 | theTouchable->GetHistory()->GetTopTransform().TransformAxis(pdirection); |
---|
| 106 | // |
---|
| 107 | G4double angleFactor = localdir.z(); |
---|
| 108 | if ( angleFactor < 0 ) angleFactor *= -1.; |
---|
| 109 | G4double flux = preStep->GetWeight(); // Current (Particle Weight) |
---|
| 110 | // |
---|
| 111 | G4double square = 4.*boxSolid->GetXHalfLength()*boxSolid->GetYHalfLength(); |
---|
| 112 | // |
---|
| 113 | flux = flux/angleFactor/square; // Flux with angle. |
---|
| 114 | // |
---|
| 115 | G4int index = GetIndex(aStep); |
---|
| 116 | EvtMap->add(index,flux); |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | #ifdef debug |
---|
| 120 | G4cout << " PASSED vol " |
---|
| 121 | << index << " trk "<<trkid<<" len " << fFlatSurfaceFlux<<G4endl; |
---|
| 122 | #endif |
---|
| 123 | |
---|
| 124 | return TRUE; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | G4int G4PSFlatSurfaceFlux::IsSelectedSurface(G4Step* aStep, G4Box* boxSolid){ |
---|
| 128 | |
---|
| 129 | G4TouchableHandle theTouchable = |
---|
| 130 | aStep->GetPreStepPoint()->GetTouchableHandle(); |
---|
| 131 | G4double kCarTolerance=G4GeometryTolerance::GetInstance()->GetSurfaceTolerance(); |
---|
| 132 | |
---|
| 133 | if (aStep->GetPreStepPoint()->GetStepStatus() == fGeomBoundary ){ |
---|
| 134 | // Entering Geometry |
---|
| 135 | G4ThreeVector stppos1= aStep->GetPreStepPoint()->GetPosition(); |
---|
| 136 | G4ThreeVector localpos1 = |
---|
| 137 | theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos1); |
---|
| 138 | if(std::fabs( localpos1.z() + boxSolid->GetZHalfLength())<kCarTolerance ){ |
---|
| 139 | return fFlux_In; |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | if (aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary ){ |
---|
| 144 | // Exiting Geometry |
---|
| 145 | G4ThreeVector stppos2= aStep->GetPostStepPoint()->GetPosition(); |
---|
| 146 | G4ThreeVector localpos2 = |
---|
| 147 | theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos2); |
---|
| 148 | if(std::fabs( localpos2.z() + boxSolid->GetZHalfLength())<kCarTolerance ){ |
---|
| 149 | return fFlux_Out; |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | return -1; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | void G4PSFlatSurfaceFlux::Initialize(G4HCofThisEvent* HCE) |
---|
| 157 | { |
---|
| 158 | EvtMap = new G4THitsMap<G4double>(GetMultiFunctionalDetector()->GetName(), |
---|
| 159 | GetName()); |
---|
| 160 | if ( HCID < 0 ) HCID = GetCollectionID(0); |
---|
| 161 | HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap); |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | void G4PSFlatSurfaceFlux::EndOfEvent(G4HCofThisEvent*) |
---|
| 165 | {;} |
---|
| 166 | |
---|
| 167 | void G4PSFlatSurfaceFlux::clear(){ |
---|
| 168 | EvtMap->clear(); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | void G4PSFlatSurfaceFlux::DrawAll() |
---|
| 172 | {;} |
---|
| 173 | |
---|
| 174 | void G4PSFlatSurfaceFlux::PrintAll() |
---|
| 175 | { |
---|
| 176 | G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl; |
---|
| 177 | G4cout << " PrimitiveScorer" << GetName() <<G4endl; |
---|
| 178 | G4cout << " Number of entries " << EvtMap->entries() << G4endl; |
---|
| 179 | std::map<G4int,G4double*>::iterator itr = EvtMap->GetMap()->begin(); |
---|
| 180 | for(; itr != EvtMap->GetMap()->end(); itr++) { |
---|
| 181 | G4cout << " copy no.: " << itr->first |
---|
| 182 | << " flux : " << *(itr->second)*cm*cm << " [cm^-2]" |
---|
| 183 | << G4endl; |
---|
| 184 | } |
---|
| 185 | } |
---|
| 186 | |
---|