Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4AdjointPrimaryGenerator class implementat << 26 // $Id: G4AdjointPrimaryGenerator.cc 81770 2014-06-05 08:31:31Z gcosmo $ 27 // 27 // 28 // Author: L. Desorgher, SpaceIT GmbH - Novemb << 28 ///////////////////////////////////////////////////////////////////////////// 29 // Contract: ESA contract 21435/08/NL/AT << 29 // Class Name: G4AdjointCrossSurfChecker 30 // Customer: ESA/ESTEC << 30 // Author: L. Desorgher 31 // ------------------------------------------- << 31 // Organisation: SpaceIT GmbH >> 32 // Contract: ESA contract 21435/08/NL/AT >> 33 // Customer: ESA/ESTEC >> 34 ///////////////////////////////////////////////////////////////////////////// 32 35 33 #include "G4AdjointPrimaryGenerator.hh" 36 #include "G4AdjointPrimaryGenerator.hh" 34 #include "G4PhysicalConstants.hh" 37 #include "G4PhysicalConstants.hh" 35 #include "G4Event.hh" 38 #include "G4Event.hh" 36 #include "G4SingleParticleSource.hh" 39 #include "G4SingleParticleSource.hh" 37 #include "G4ParticleDefinition.hh" 40 #include "G4ParticleDefinition.hh" 38 #include "G4AdjointPosOnPhysVolGenerator.hh" 41 #include "G4AdjointPosOnPhysVolGenerator.hh" 39 #include "G4Navigator.hh" 42 #include "G4Navigator.hh" 40 #include "G4TransportationManager.hh" 43 #include "G4TransportationManager.hh" 41 #include "G4VPhysicalVolume.hh" 44 #include "G4VPhysicalVolume.hh" 42 #include "G4Material.hh" 45 #include "G4Material.hh" 43 #include "Randomize.hh" 46 #include "Randomize.hh" 44 << 47 /* 45 // ------------------------------------------- << 48 #include "G4AdjointCSManager.hh" >> 49 #include "G4MaterialCutsCouple.hh" >> 50 */ >> 51 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 46 // 52 // 47 G4AdjointPrimaryGenerator::G4AdjointPrimaryGen 53 G4AdjointPrimaryGenerator::G4AdjointPrimaryGenerator() >> 54 : radius_spherical_source(0.),fLinearNavigator(0),theAccumulatedDepthVector(0) 48 { 55 { 49 center_spherical_source = G4ThreeVector(0.,0 56 center_spherical_source = G4ThreeVector(0.,0.,0.); 50 type_of_adjoint_source="Spherical"; 57 type_of_adjoint_source="Spherical"; 51 theSingleParticleSource = new G4SingleParti 58 theSingleParticleSource = new G4SingleParticleSource(); 52 59 53 theSingleParticleSource->GetEneDist()->SetEn 60 theSingleParticleSource->GetEneDist()->SetEnergyDisType("Pow"); 54 theSingleParticleSource->GetEneDist()->SetAl 61 theSingleParticleSource->GetEneDist()->SetAlpha(-1.); 55 theSingleParticleSource->GetPosDist()->SetPo 62 theSingleParticleSource->GetPosDist()->SetPosDisType("Point"); 56 theSingleParticleSource->GetAngDist()->SetAn 63 theSingleParticleSource->GetAngDist()->SetAngDistType("planar"); 57 64 58 theG4AdjointPosOnPhysVolGenerator = G4Adjoin 65 theG4AdjointPosOnPhysVolGenerator = G4AdjointPosOnPhysVolGenerator::GetInstance(); 59 } << 60 66 61 // ------------------------------------------- << 67 } >> 68 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 62 // 69 // 63 G4AdjointPrimaryGenerator::~G4AdjointPrimaryGe 70 G4AdjointPrimaryGenerator::~G4AdjointPrimaryGenerator() 64 { 71 { 65 delete theSingleParticleSource; 72 delete theSingleParticleSource; 66 } 73 } 67 << 74 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 68 // ------------------------------------------- << 69 // 75 // 70 void G4AdjointPrimaryGenerator:: << 76 void G4AdjointPrimaryGenerator::GenerateAdjointPrimaryVertex(G4Event* anEvent,G4ParticleDefinition* adj_part,G4double E1,G4double E2) 71 GenerateAdjointPrimaryVertex(G4Event* anEvent, << 72 G4double E1, G4do << 73 { 77 { 74 if (type_of_adjoint_source == "ExternalSurfa << 78 if (type_of_adjoint_source == "ExternalSurfaceOfAVolume") { 75 { << 79 76 // Generate position and direction relativ << 80 //Generate position and direction relative to the external surface of sensitive volume 77 // of sensitive volume << 81 //------------------------------------------------------------- 78 << 82 79 G4double costh_to_normal=1.; << 83 G4double costh_to_normal=1.; 80 G4ThreeVector pos =G4ThreeVector(0.,0.,0.) << 84 G4ThreeVector pos =G4ThreeVector(0.,0.,0.); 81 G4ThreeVector direction = G4ThreeVector(0. << 85 G4ThreeVector direction = G4ThreeVector(0.,0.,1.); 82 theG4AdjointPosOnPhysVolGenerator << 86 theG4AdjointPosOnPhysVolGenerator->GenerateAPositionOnTheExtSurfaceOfThePhysicalVolume(pos, direction,costh_to_normal); 83 ->GenerateAPositionOnTheExtSurfaceOfTheP << 87 if (costh_to_normal <1.e-4) costh_to_normal =1.e-4; 84 << 88 //compute now the position along the ray backward direction 85 if (costh_to_normal <1.e-4) { costh_to_no << 89 86 << 90 theSingleParticleSource->GetAngDist()->SetParticleMomentumDirection(-direction); 87 // compute now the position along the ray << 91 theSingleParticleSource->GetPosDist()->SetCentreCoords(pos); 88 // << 92 } 89 theSingleParticleSource->GetAngDist() << 93 90 ->SetParticleMomentumDirection(-directio << 94 theSingleParticleSource->GetEneDist()->SetEmin(E1); 91 theSingleParticleSource->GetPosDist()->Set << 95 theSingleParticleSource->GetEneDist()->SetEmax(E2); 92 } << 96 93 << 97 theSingleParticleSource->SetParticleDefinition(adj_part); 94 theSingleParticleSource->GetEneDist()->SetEm << 98 theSingleParticleSource->GeneratePrimaryVertex(anEvent); 95 theSingleParticleSource->GetEneDist()->SetEm << 99 96 << 100 97 theSingleParticleSource->SetParticleDefiniti << 98 theSingleParticleSource->GeneratePrimaryVert << 99 } << 100 << 101 // ------------------------------------------- << 102 // << 103 void G4AdjointPrimaryGenerator:: << 104 GenerateFwdPrimaryVertex(G4Event* anEvent,G4Pa << 105 G4double E1, G4double << 106 { << 107 if (type_of_adjoint_source == "ExternalSurfa << 108 { << 109 // Generate position and direction relativ << 110 // of sensitive volume << 111 << 112 G4double costh_to_normal=1.; << 113 G4ThreeVector pos =G4ThreeVector(0.,0.,0.) << 114 G4ThreeVector direction = G4ThreeVector(0. << 115 theG4AdjointPosOnPhysVolGenerator << 116 ->GenerateAPositionOnTheExtSurfaceOfTheP << 117 << 118 if (costh_to_normal <1.e-4) { costh_to_no << 119 theSingleParticleSource->GetAngDist() << 120 ->SetParticleMomentumDirection(direction << 121 theSingleParticleSource->GetPosDist()->Set << 122 } << 123 << 124 theSingleParticleSource->GetEneDist()->SetEm << 125 theSingleParticleSource->GetEneDist()->SetEm << 126 101 127 theSingleParticleSource->SetParticleDefiniti << 128 theSingleParticleSource->GeneratePrimaryVert << 129 } 102 } >> 103 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// >> 104 // >> 105 void G4AdjointPrimaryGenerator::GenerateFwdPrimaryVertex(G4Event* anEvent,G4ParticleDefinition* fwd_part,G4double E1,G4double E2) >> 106 { >> 107 if (type_of_adjoint_source == "ExternalSurfaceOfAVolume") { >> 108 >> 109 //Generate position and direction relative to the external surface of sensitive volume >> 110 //------------------------------------------------------------- >> 111 >> 112 G4double costh_to_normal=1.; >> 113 G4ThreeVector pos =G4ThreeVector(0.,0.,0.); >> 114 G4ThreeVector direction = G4ThreeVector(0.,0.,1.); >> 115 theG4AdjointPosOnPhysVolGenerator->GenerateAPositionOnTheExtSurfaceOfThePhysicalVolume(pos, direction,costh_to_normal); >> 116 if (costh_to_normal <1.e-4) costh_to_normal =1.e-4; >> 117 theSingleParticleSource->GetAngDist()->SetParticleMomentumDirection(direction); >> 118 theSingleParticleSource->GetPosDist()->SetCentreCoords(pos); >> 119 } 130 120 131 // ------------------------------------------- << 121 theSingleParticleSource->GetEneDist()->SetEmin(E1); >> 122 theSingleParticleSource->GetEneDist()->SetEmax(E2); >> 123 >> 124 theSingleParticleSource->SetParticleDefinition(fwd_part); >> 125 theSingleParticleSource->GeneratePrimaryVertex(anEvent); >> 126 } >> 127 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 132 // 128 // 133 void G4AdjointPrimaryGenerator:: << 129 void G4AdjointPrimaryGenerator::SetSphericalAdjointPrimarySource(G4double radius, G4ThreeVector center_pos) 134 SetSphericalAdjointPrimarySource(G4double radi << 135 { 130 { 136 radius_spherical_source = radius; 131 radius_spherical_source = radius; 137 center_spherical_source = center_pos; 132 center_spherical_source = center_pos; 138 type_of_adjoint_source = "Spherical"; << 133 type_of_adjoint_source ="Spherical"; 139 theSingleParticleSource->GetPosDist()->SetPo 134 theSingleParticleSource->GetPosDist()->SetPosDisType("Surface"); 140 theSingleParticleSource->GetPosDist()->SetPo 135 theSingleParticleSource->GetPosDist()->SetPosDisShape("Sphere"); 141 theSingleParticleSource->GetPosDist()->SetCe 136 theSingleParticleSource->GetPosDist()->SetCentreCoords(center_pos); 142 theSingleParticleSource->GetPosDist()->SetRa 137 theSingleParticleSource->GetPosDist()->SetRadius(radius); 143 theSingleParticleSource->GetAngDist()->SetAn 138 theSingleParticleSource->GetAngDist()->SetAngDistType("cos"); 144 theSingleParticleSource->GetAngDist()->SetMa 139 theSingleParticleSource->GetAngDist()->SetMaxTheta(pi); 145 theSingleParticleSource->GetAngDist()->SetMi 140 theSingleParticleSource->GetAngDist()->SetMinTheta(halfpi); 146 } 141 } 147 << 142 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 148 // ------------------------------------------- << 149 // 143 // 150 void G4AdjointPrimaryGenerator:: << 144 void G4AdjointPrimaryGenerator::SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(const G4String& volume_name) 151 SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume << 152 { 145 { 153 theG4AdjointPosOnPhysVolGenerator->DefinePhy 146 theG4AdjointPosOnPhysVolGenerator->DefinePhysicalVolume1(volume_name); 154 type_of_adjoint_source ="ExternalSurfaceOfAV 147 type_of_adjoint_source ="ExternalSurfaceOfAVolume"; 155 theSingleParticleSource->GetPosDist()->SetPo 148 theSingleParticleSource->GetPosDist()->SetPosDisType("Point"); 156 theSingleParticleSource->GetAngDist()->SetAn 149 theSingleParticleSource->GetAngDist()->SetAngDistType("planar"); 157 } 150 } 158 151 159 // ------------------------------------------- << 152 //////////////////////////////////////////////////////////////////////////////// 160 // 153 // 161 void G4AdjointPrimaryGenerator:: << 154 void G4AdjointPrimaryGenerator::ComputeAccumulatedDepthVectorAlongBackRay( 162 ComputeAccumulatedDepthVectorAlongBackRay(G4Th << 155 G4ThreeVector glob_pos, 163 G4Th << 156 G4ThreeVector direction, 164 G4do << 157 G4double, 165 { << 158 G4ParticleDefinition*) 166 if (fLinearNavigator == nullptr) << 159 { if (!fLinearNavigator) fLinearNavigator = 167 { << 160 G4TransportationManager::GetTransportationManager() 168 fLinearNavigator = G4TransportationManager << 161 ->GetNavigatorForTracking(); 169 ->GetNavigatorForTracking << 162 G4ThreeVector position = glob_pos; 170 } << 163 G4double safety=1.; 171 G4ThreeVector position = glob_pos; << 164 G4VPhysicalVolume* thePhysVolume = 172 G4double safety=1.; << 165 fLinearNavigator->LocateGlobalPointAndSetup(position); 173 G4VPhysicalVolume* thePhysVolume = << 166 G4double newStep =fLinearNavigator->ComputeStep(position,direction,1.e50, 174 fLinearNavigator->LocateGlobalPointAnd << 167 safety); 175 G4double newStep = fLinearNavigator->Compute << 168 if (theAccumulatedDepthVector) delete theAccumulatedDepthVector; 176 << 169 theAccumulatedDepthVector = new G4PhysicsOrderedFreeVector(); 177 delete theAccumulatedDepthVector; << 170 //if (theAccumulatedCSDepthVector) delete theAccumulatedCSDepthVector; 178 theAccumulatedDepthVector = new G4PhysicsFre << 171 //theAccumulatedCSDepthVector = new G4PhysicsOrderedFreeVector(); 179 << 172 180 G4double acc_depth=0.; << 173 G4double acc_depth=0.; 181 G4double acc_length=0.; << 174 G4double acc_length=0.; 182 theAccumulatedDepthVector->InsertValues(acc_ << 175 //G4double acc_cs_depth=0.; 183 << 176 //theAccumulatedCSDepthVector->InsertValues(acc_cs_depth, acc_length); 184 while (newStep > 0. && thePhysVolume != null << 177 theAccumulatedDepthVector->InsertValues(acc_length,acc_depth); 185 { << 178 186 acc_length+=newStep; << 179 while (newStep > 0. && thePhysVolume) { 187 acc_depth+=newStep*thePhysVolume->GetLogic << 180 acc_length+=newStep; 188 ->GetMater << 181 /* 189 theAccumulatedDepthVector->InsertValues(ac << 182 const G4MaterialCutsCouple* theMatCutsCouple= 190 position=position+newStep*direction; << 183 thePhysVolume->GetLogicalVolume()->GetMaterialCutsCouple(); 191 thePhysVolume = fLinearNavigator << 184 192 ->LocateGlobalPointAndSetup( << 185 193 newStep = fLinearNavigator->ComputeStep(po << 186 acc_cs_depth+=newStep*G4AdjointCSManager::GetAdjointCSManager()->GetTotalAdjointCS(aPartDef, 194 } << 187 ekin, 195 } << 188 theMatCutsCouple); >> 189 theAccumulatedCSDepthVector->InsertValues(acc_cs_depth, acc_length);*/ >> 190 >> 191 acc_depth+=newStep*thePhysVolume->GetLogicalVolume()->GetMaterial()->GetDensity(); >> 192 theAccumulatedDepthVector->InsertValues(acc_length,acc_depth); >> 193 position=position+newStep*direction; >> 194 thePhysVolume = >> 195 fLinearNavigator->LocateGlobalPointAndSetup(position,0,false); >> 196 newStep =fLinearNavigator->ComputeStep(position,direction,1.e50, >> 197 safety); >> 198 } 196 199 197 // ------------------------------------------- << 200 198 // << 201 } 199 G4double G4AdjointPrimaryGenerator:: << 202 //////////////////////////////////////////////////////////////////////////////// 200 SampleDistanceAlongBackRayAndComputeWeightCorr << 203 // 201 { << 204 G4double G4AdjointPrimaryGenerator::SampleDistanceAlongBackRayAndComputeWeightCorrection(G4double& weight_corr) 202 G4double rand = G4UniformRand(); << 205 {G4double rand = G4UniformRand(); 203 G4double distance = theAccumulatedDepthVecto << 206 G4double distance = theAccumulatedDepthVector->FindLinearEnergy(rand); 204 weight_corr=1.; << 207 /* 205 return distance; << 208 G4double acc_cs_depth=theAccumulatedCSDepthVector->GetEnergy(distance); >> 209 weight_corr=std::exp(-acc_cs_depth);*/ >> 210 weight_corr=1.; >> 211 return distance; 206 } 212 } >> 213 >> 214 >> 215 >> 216 207 217