| 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.8 2010/07/23 04:35:38 taso Exp $
|
|---|
| 28 | // GEANT4 tag $Name: $
|
|---|
| 29 | //
|
|---|
| 30 | // // G4PSCylinderSurfaceFlux
|
|---|
| 31 | #include "G4PSCylinderSurfaceFlux.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 Surface Flux.
|
|---|
| 42 | // Current version assumes only for G4Tubs shape, and the surface
|
|---|
| 43 | // is fixed on inner plane of the tube.
|
|---|
| 44 | //
|
|---|
| 45 | // Surface is defined at the innner surface of the tube.
|
|---|
| 46 | // Direction R R+dR
|
|---|
| 47 | // 0 IN || OUT ->|<- |
|
|---|
| 48 | // 1 IN ->| |
|
|---|
| 49 | // 2 OUT |<- |
|
|---|
| 50 | //
|
|---|
| 51 | // Created: 2007-03-29 Tsukasa ASO
|
|---|
| 52 | // 2010-07-22 Introduce Unit specification.
|
|---|
| 53 | // 2010-07-22 Add weighted and divideByArea options
|
|---|
| 54 | ///////////////////////////////////////////////////////////////////////////////
|
|---|
| 55 |
|
|---|
| 56 | G4PSCylinderSurfaceFlux::G4PSCylinderSurfaceFlux(G4String name,
|
|---|
| 57 | G4int direction, G4int depth)
|
|---|
| 58 | :G4VPrimitiveScorer(name,depth),HCID(-1),fDirection(direction),
|
|---|
| 59 | weighted(true),divideByArea(true)
|
|---|
| 60 | {
|
|---|
| 61 | DefineUnitAndCategory();
|
|---|
| 62 | SetUnit("percm2");
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | G4PSCylinderSurfaceFlux::G4PSCylinderSurfaceFlux(G4String name,
|
|---|
| 66 | G4int direction,
|
|---|
| 67 | const G4String& unit,
|
|---|
| 68 | G4int depth)
|
|---|
| 69 | :G4VPrimitiveScorer(name,depth),HCID(-1),fDirection(direction)
|
|---|
| 70 | {
|
|---|
| 71 | DefineUnitAndCategory();
|
|---|
| 72 | SetUnit(unit);
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | G4PSCylinderSurfaceFlux::~G4PSCylinderSurfaceFlux()
|
|---|
| 76 | {;}
|
|---|
| 77 |
|
|---|
| 78 | G4bool G4PSCylinderSurfaceFlux::ProcessHits(G4Step* aStep,G4TouchableHistory*)
|
|---|
| 79 | {
|
|---|
| 80 | G4StepPoint* preStep = aStep->GetPreStepPoint();
|
|---|
| 81 | G4StepPoint* postStep = aStep->GetPreStepPoint();
|
|---|
| 82 |
|
|---|
| 83 | G4VPhysicalVolume* physVol = preStep->GetPhysicalVolume();
|
|---|
| 84 | G4VPVParameterisation* physParam = physVol->GetParameterisation();
|
|---|
| 85 | G4VSolid * solid = 0;
|
|---|
| 86 | if(physParam)
|
|---|
| 87 | { // for parameterized volume
|
|---|
| 88 | G4int idx = ((G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable()))
|
|---|
| 89 | ->GetReplicaNumber(indexDepth);
|
|---|
| 90 | solid = physParam->ComputeSolid(idx, physVol);
|
|---|
| 91 | solid->ComputeDimensions(physParam,idx,physVol);
|
|---|
| 92 | }
|
|---|
| 93 | else
|
|---|
| 94 | { // for ordinary volume
|
|---|
| 95 | solid = physVol->GetLogicalVolume()->GetSolid();
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | G4Tubs* tubsSolid = (G4Tubs*)(solid);
|
|---|
| 99 |
|
|---|
| 100 | G4int dirFlag =IsSelectedSurface(aStep,tubsSolid);
|
|---|
| 101 |
|
|---|
| 102 | if ( dirFlag > 0 ){
|
|---|
| 103 | if (fDirection == fFlux_InOut || dirFlag == fDirection ){
|
|---|
| 104 |
|
|---|
| 105 | G4StepPoint* thisStep=0;
|
|---|
| 106 | if ( dirFlag == fFlux_In ){
|
|---|
| 107 | thisStep = preStep;
|
|---|
| 108 | }else if ( dirFlag == fFlux_Out ){
|
|---|
| 109 | thisStep = postStep;
|
|---|
| 110 | }else{
|
|---|
| 111 | return FALSE;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | G4TouchableHandle theTouchable = thisStep->GetTouchableHandle();
|
|---|
| 115 | G4ThreeVector pdirection = thisStep->GetMomentumDirection();
|
|---|
| 116 | G4ThreeVector localdir =
|
|---|
| 117 | theTouchable->GetHistory()->GetTopTransform().TransformAxis(pdirection);
|
|---|
| 118 | G4ThreeVector position = thisStep->GetPosition();
|
|---|
| 119 | G4ThreeVector localpos =
|
|---|
| 120 | theTouchable->GetHistory()->GetTopTransform().TransformAxis(position);
|
|---|
| 121 | G4double angleFactor = (localdir.x()*localpos.x()+localdir.y()*localpos.y())
|
|---|
| 122 | /std::sqrt(localdir.x()*localdir.x()
|
|---|
| 123 | +localdir.y()*localdir.y()+localdir.z()*localdir.z())
|
|---|
| 124 | /std::sqrt(localpos.x()*localpos.x()+localpos.y()*localpos.y());
|
|---|
| 125 |
|
|---|
| 126 | if ( angleFactor < 0 ) angleFactor *= -1.;
|
|---|
| 127 | G4double square = 2.*tubsSolid->GetZHalfLength()
|
|---|
| 128 | *tubsSolid->GetInnerRadius()* tubsSolid->GetDeltaPhiAngle()/radian;
|
|---|
| 129 |
|
|---|
| 130 | G4double flux = 1.0;
|
|---|
| 131 | if ( weighted ) flux *=preStep->GetWeight();
|
|---|
| 132 | // Current (Particle Weight)
|
|---|
| 133 |
|
|---|
| 134 | flux = flux/angleFactor;
|
|---|
| 135 | if ( divideByArea ) flux /= square;
|
|---|
| 136 | //Flux with angle.
|
|---|
| 137 | G4int index = GetIndex(aStep);
|
|---|
| 138 | EvtMap->add(index,flux);
|
|---|
| 139 | return TRUE;
|
|---|
| 140 | }else{
|
|---|
| 141 | return FALSE;
|
|---|
| 142 | }
|
|---|
| 143 | }else{
|
|---|
| 144 | return FALSE;
|
|---|
| 145 | }
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | G4int G4PSCylinderSurfaceFlux::IsSelectedSurface(G4Step* aStep, G4Tubs* tubsSolid){
|
|---|
| 149 |
|
|---|
| 150 | G4TouchableHandle theTouchable =
|
|---|
| 151 | aStep->GetPreStepPoint()->GetTouchableHandle();
|
|---|
| 152 | G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
|
|---|
| 153 |
|
|---|
| 154 | if (aStep->GetPreStepPoint()->GetStepStatus() == fGeomBoundary ){
|
|---|
| 155 | // Entering Geometry
|
|---|
| 156 | G4ThreeVector stppos1= aStep->GetPreStepPoint()->GetPosition();
|
|---|
| 157 | G4ThreeVector localpos1 =
|
|---|
| 158 | theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos1);
|
|---|
| 159 | if ( std::fabs(localpos1.z()) > tubsSolid->GetZHalfLength() ) return -1;
|
|---|
| 160 | //if(std::fabs( localpos1.x()*localpos1.x()+localpos1.y()*localpos1.y()
|
|---|
| 161 | // - (tubsSolid->GetInnerRadius()*tubsSolid->GetInnerRadius()))
|
|---|
| 162 | // <kCarTolerance ){
|
|---|
| 163 | G4double localR2 = localpos1.x()*localpos1.x()+localpos1.y()*localpos1.y();
|
|---|
| 164 | G4double InsideRadius = tubsSolid->GetInnerRadius();
|
|---|
| 165 | if (localR2 > (InsideRadius-kCarTolerance)*(InsideRadius-kCarTolerance)
|
|---|
| 166 | &&localR2 < (InsideRadius+kCarTolerance)*(InsideRadius+kCarTolerance)){
|
|---|
| 167 | return fFlux_In;
|
|---|
| 168 | }
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | if (aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary ){
|
|---|
| 172 | // Exiting Geometry
|
|---|
| 173 | G4ThreeVector stppos2= aStep->GetPostStepPoint()->GetPosition();
|
|---|
| 174 | G4ThreeVector localpos2 =
|
|---|
| 175 | theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos2);
|
|---|
| 176 | if ( std::fabs(localpos2.z()) > tubsSolid->GetZHalfLength() ) return -1;
|
|---|
| 177 | //if(std::fabs( localpos2.x()*localpos2.x()+localpos2.y()*localpos2.y()
|
|---|
| 178 | // - (tubsSolid->GetInnerRadius()*tubsSolid->GetInnerRadius()))
|
|---|
| 179 | // <kCarTolerance ){
|
|---|
| 180 | G4double localR2 = localpos2.x()*localpos2.x()+localpos2.y()*localpos2.y();
|
|---|
| 181 | G4double InsideRadius = tubsSolid->GetInnerRadius();
|
|---|
| 182 | if (localR2 > (InsideRadius-kCarTolerance)*(InsideRadius-kCarTolerance)
|
|---|
| 183 | &&localR2 < (InsideRadius+kCarTolerance)*(InsideRadius+kCarTolerance)){
|
|---|
| 184 | return fFlux_Out;
|
|---|
| 185 | }
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | return -1;
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | void G4PSCylinderSurfaceFlux::Initialize(G4HCofThisEvent* HCE)
|
|---|
| 192 | {
|
|---|
| 193 | EvtMap = new G4THitsMap<G4double>(GetMultiFunctionalDetector()->GetName(),
|
|---|
| 194 | GetName());
|
|---|
| 195 | if ( HCID < 0 ) HCID = GetCollectionID(0);
|
|---|
| 196 | HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap);
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | void G4PSCylinderSurfaceFlux::EndOfEvent(G4HCofThisEvent*)
|
|---|
| 200 | {;}
|
|---|
| 201 |
|
|---|
| 202 | void G4PSCylinderSurfaceFlux::clear(){
|
|---|
| 203 | EvtMap->clear();
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | void G4PSCylinderSurfaceFlux::DrawAll()
|
|---|
| 207 | {;}
|
|---|
| 208 |
|
|---|
| 209 | void G4PSCylinderSurfaceFlux::PrintAll()
|
|---|
| 210 | {
|
|---|
| 211 | G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl;
|
|---|
| 212 | G4cout << " PrimitiveScorer" << GetName() <<G4endl;
|
|---|
| 213 | G4cout << " Number of entries " << EvtMap->entries() << G4endl;
|
|---|
| 214 | std::map<G4int,G4double*>::iterator itr = EvtMap->GetMap()->begin();
|
|---|
| 215 | for(; itr != EvtMap->GetMap()->end(); itr++) {
|
|---|
| 216 | G4cout << " copy no.: " << itr->first
|
|---|
| 217 | << " flux : " << *(itr->second)/GetUnitValue()
|
|---|
| 218 | << " ["<<GetUnit()<<"]"
|
|---|
| 219 | << G4endl;
|
|---|
| 220 | }
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | void G4PSCylinderSurfaceFlux::SetUnit(const G4String& unit)
|
|---|
| 224 | {
|
|---|
| 225 | if ( divideByArea ) {
|
|---|
| 226 | CheckAndSetUnit(unit,"Per Unit Surface");
|
|---|
| 227 | } else {
|
|---|
| 228 | if (unit == "" ){
|
|---|
| 229 | unitName = unit;
|
|---|
| 230 | unitValue = 1.0;
|
|---|
| 231 | }else{
|
|---|
| 232 | G4String msg = "Invalid unit ["+unit+"] (Current unit is [" +GetUnit()+"] )";
|
|---|
| 233 | G4Exception(GetName(),"DetScorer0000",JustWarning,msg);
|
|---|
| 234 | }
|
|---|
| 235 | }
|
|---|
| 236 | }
|
|---|
| 237 |
|
|---|
| 238 | void G4PSCylinderSurfaceFlux::DefineUnitAndCategory(){
|
|---|
| 239 | // Per Unit Surface
|
|---|
| 240 | new G4UnitDefinition("percentimeter2","percm2","Per Unit Surface",(1./cm2));
|
|---|
| 241 | new G4UnitDefinition("permillimeter2","permm2","Per Unit Surface",(1./mm2));
|
|---|
| 242 | new G4UnitDefinition("permeter2","perm2","Per Unit Surface",(1./m2));
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|