[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: G4PSCylinderSurfaceFlux.cc,v 1.1 2007/08/14 21:23:51 taso Exp $ |
---|
| 28 | // // GEANT4 tag $Name: $ |
---|
| 29 | // // |
---|
| 30 | // // G4PSCylinderSurfaceFlux |
---|
| 31 | #include "G4PSCylinderSurfaceFlux.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 G4Tubs shape, and the surface |
---|
| 40 | // is fixed on inner plane of the tube. |
---|
| 41 | // |
---|
| 42 | // Surface is defined at the innner surface of the tube. |
---|
| 43 | // Direction R R+dR |
---|
| 44 | // 0 IN || OUT ->|<- | |
---|
| 45 | // 1 IN ->| | |
---|
| 46 | // 2 OUT |<- | |
---|
| 47 | // |
---|
| 48 | // Created: 2007-03-29 Tsukasa ASO |
---|
| 49 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 50 | |
---|
| 51 | G4PSCylinderSurfaceFlux::G4PSCylinderSurfaceFlux(G4String name, |
---|
| 52 | G4int direction, G4int depth) |
---|
| 53 | :G4VPrimitiveScorer(name,depth),HCID(-1),fDirection(direction) |
---|
| 54 | {;} |
---|
| 55 | |
---|
| 56 | G4PSCylinderSurfaceFlux::~G4PSCylinderSurfaceFlux() |
---|
| 57 | {;} |
---|
| 58 | |
---|
| 59 | G4bool G4PSCylinderSurfaceFlux::ProcessHits(G4Step* aStep,G4TouchableHistory*) |
---|
| 60 | { |
---|
| 61 | G4StepPoint* preStep = aStep->GetPreStepPoint(); |
---|
| 62 | G4StepPoint* postStep = aStep->GetPreStepPoint(); |
---|
| 63 | G4VSolid * solid = |
---|
| 64 | preStep->GetPhysicalVolume()->GetLogicalVolume()->GetSolid(); |
---|
| 65 | if( solid->GetEntityType() != "G4Tubs" ){ |
---|
| 66 | G4Exception("G4PSCylinderSurfaceFluxScorer. - Solid type is not supported."); |
---|
| 67 | return FALSE; |
---|
| 68 | } |
---|
| 69 | G4Tubs* tubsSolid = (G4Tubs*)(solid); |
---|
| 70 | |
---|
| 71 | G4int dirFlag =IsSelectedSurface(aStep,tubsSolid); |
---|
| 72 | |
---|
| 73 | if ( dirFlag > 0 ){ |
---|
| 74 | if (fDirection == fFlux_InOut || dirFlag == fDirection ){ |
---|
| 75 | |
---|
| 76 | G4StepPoint* thisStep=0; |
---|
| 77 | if ( dirFlag == fFlux_In ){ |
---|
| 78 | thisStep = preStep; |
---|
| 79 | }else if ( dirFlag == fFlux_Out ){ |
---|
| 80 | thisStep = postStep; |
---|
| 81 | }else{ |
---|
| 82 | return FALSE; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | G4TouchableHandle theTouchable = thisStep->GetTouchableHandle(); |
---|
| 86 | G4ThreeVector pdirection = thisStep->GetMomentumDirection(); |
---|
| 87 | G4ThreeVector localdir = |
---|
| 88 | theTouchable->GetHistory()->GetTopTransform().TransformAxis(pdirection); |
---|
| 89 | G4ThreeVector position = thisStep->GetPosition(); |
---|
| 90 | G4ThreeVector localpos = |
---|
| 91 | theTouchable->GetHistory()->GetTopTransform().TransformAxis(position); |
---|
| 92 | G4double angleFactor = (localdir.x()*localpos.x()+localdir.y()*localpos.y()) |
---|
| 93 | /std::sqrt(localdir.x()*localdir.x() |
---|
| 94 | +localdir.y()*localdir.y()+localdir.z()*localdir.z()) |
---|
| 95 | /std::sqrt(localpos.x()*localpos.x()+localpos.y()*localpos.y()); |
---|
| 96 | |
---|
| 97 | if ( angleFactor < 0 ) angleFactor *= -1.; |
---|
| 98 | G4double square = 2.*tubsSolid->GetZHalfLength() |
---|
| 99 | *tubsSolid->GetInnerRadius()* tubsSolid->GetDeltaPhiAngle()/radian; |
---|
| 100 | |
---|
| 101 | G4double flux = preStep->GetWeight(); |
---|
| 102 | // Current (Particle Weight) |
---|
| 103 | |
---|
| 104 | flux = flux/angleFactor/square; |
---|
| 105 | //Flux with angle. |
---|
| 106 | G4int index = GetIndex(aStep); |
---|
| 107 | EvtMap->add(index,flux); |
---|
| 108 | return TRUE; |
---|
| 109 | }else{ |
---|
| 110 | return FALSE; |
---|
| 111 | } |
---|
| 112 | }else{ |
---|
| 113 | return FALSE; |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | G4int G4PSCylinderSurfaceFlux::IsSelectedSurface(G4Step* aStep, G4Tubs* tubsSolid){ |
---|
| 118 | |
---|
| 119 | G4TouchableHandle theTouchable = |
---|
| 120 | aStep->GetPreStepPoint()->GetTouchableHandle(); |
---|
| 121 | G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance(); |
---|
| 122 | |
---|
| 123 | if (aStep->GetPreStepPoint()->GetStepStatus() == fGeomBoundary ){ |
---|
| 124 | // Entering Geometry |
---|
| 125 | G4ThreeVector stppos1= aStep->GetPreStepPoint()->GetPosition(); |
---|
| 126 | G4ThreeVector localpos1 = |
---|
| 127 | theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos1); |
---|
| 128 | if ( std::fabs(localpos1.z()) > tubsSolid->GetZHalfLength() ) return -1; |
---|
| 129 | if(std::fabs( localpos1.x()*localpos1.x()+localpos1.y()*localpos1.y() ) |
---|
| 130 | - (tubsSolid->GetInnerRadius()*tubsSolid->GetInnerRadius())<kCarTolerance ){ |
---|
| 131 | return fFlux_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()) > tubsSolid->GetZHalfLength() ) return -1; |
---|
| 141 | if(std::fabs( localpos2.x()*localpos2.x()+localpos2.y()*localpos2.y() ) |
---|
| 142 | - (tubsSolid->GetInnerRadius()*tubsSolid->GetInnerRadius())<kCarTolerance ){ |
---|
| 143 | return fFlux_Out; |
---|
| 144 | } |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | return -1; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | void G4PSCylinderSurfaceFlux::Initialize(G4HCofThisEvent* HCE) |
---|
| 151 | { |
---|
| 152 | EvtMap = new G4THitsMap<G4double>(GetMultiFunctionalDetector()->GetName(), |
---|
| 153 | GetName()); |
---|
| 154 | if ( HCID < 0 ) HCID = GetCollectionID(0); |
---|
| 155 | HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap); |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | void G4PSCylinderSurfaceFlux::EndOfEvent(G4HCofThisEvent*) |
---|
| 159 | {;} |
---|
| 160 | |
---|
| 161 | void G4PSCylinderSurfaceFlux::clear(){ |
---|
| 162 | EvtMap->clear(); |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | void G4PSCylinderSurfaceFlux::DrawAll() |
---|
| 166 | {;} |
---|
| 167 | |
---|
| 168 | void G4PSCylinderSurfaceFlux::PrintAll() |
---|
| 169 | { |
---|
| 170 | G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl; |
---|
| 171 | G4cout << " PrimitiveScorer" << GetName() <<G4endl; |
---|
| 172 | G4cout << " Number of entries " << EvtMap->entries() << G4endl; |
---|
| 173 | std::map<G4int,G4double*>::iterator itr = EvtMap->GetMap()->begin(); |
---|
| 174 | for(; itr != EvtMap->GetMap()->end(); itr++) { |
---|
| 175 | G4cout << " copy no.: " << itr->first |
---|
| 176 | << " flux : " << *(itr->second)*cm*cm << " [cm^-2]" |
---|
| 177 | << G4endl; |
---|
| 178 | } |
---|
| 179 | } |
---|
| 180 | |
---|