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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /event/src/G4AdjointPrimaryGenerator.cc (Version 11.3.0) and /event/src/G4AdjointPrimaryGenerator.cc (Version 10.6)


  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 << 
 27 //                                                 26 //
 28 // Author: L. Desorgher, SpaceIT GmbH - Novemb <<  27 /////////////////////////////////////////////////////////////////////////////
 29 // Contract: ESA contract 21435/08/NL/AT       <<  28 //      Class Name: G4AdjointCrossSurfChecker
 30 // Customer: ESA/ESTEC                         <<  29 //  Author:         L. Desorgher
 31 // ------------------------------------------- <<  30 //  Organisation:   SpaceIT GmbH
                                                   >>  31 //  Contract: ESA contract 21435/08/NL/AT
                                                   >>  32 //  Customer:       ESA/ESTEC
                                                   >>  33 /////////////////////////////////////////////////////////////////////////////
 32                                                    34 
 33 #include "G4AdjointPrimaryGenerator.hh"            35 #include "G4AdjointPrimaryGenerator.hh"
 34 #include "G4PhysicalConstants.hh"                  36 #include "G4PhysicalConstants.hh"
 35 #include "G4Event.hh"                              37 #include "G4Event.hh"
 36 #include "G4SingleParticleSource.hh"               38 #include "G4SingleParticleSource.hh"
 37 #include "G4ParticleDefinition.hh"                 39 #include "G4ParticleDefinition.hh"
 38 #include "G4AdjointPosOnPhysVolGenerator.hh"       40 #include "G4AdjointPosOnPhysVolGenerator.hh" 
 39 #include "G4Navigator.hh"                          41 #include "G4Navigator.hh"
 40 #include "G4TransportationManager.hh"              42 #include "G4TransportationManager.hh"
 41 #include "G4VPhysicalVolume.hh"                    43 #include "G4VPhysicalVolume.hh"
 42 #include "G4Material.hh"                           44 #include "G4Material.hh"
 43 #include "Randomize.hh"                            45 #include "Randomize.hh"
 44                                                <<  46 /*
 45 // ------------------------------------------- <<  47 #include "G4AdjointCSManager.hh"
                                                   >>  48 #include "G4MaterialCutsCouple.hh"
                                                   >>  49 */
                                                   >>  50 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 46 //                                                 51 //
 47 G4AdjointPrimaryGenerator::G4AdjointPrimaryGen     52 G4AdjointPrimaryGenerator::G4AdjointPrimaryGenerator()
                                                   >>  53   : radius_spherical_source(0.),fLinearNavigator(0),theAccumulatedDepthVector(0)
 48 {                                                  54 {
 49   center_spherical_source = G4ThreeVector(0.,0     55   center_spherical_source = G4ThreeVector(0.,0.,0.);
 50   type_of_adjoint_source="Spherical";              56   type_of_adjoint_source="Spherical";
 51   theSingleParticleSource  = new G4SingleParti     57   theSingleParticleSource  = new G4SingleParticleSource();
 52                                                    58  
 53   theSingleParticleSource->GetEneDist()->SetEn     59   theSingleParticleSource->GetEneDist()->SetEnergyDisType("Pow");
 54   theSingleParticleSource->GetEneDist()->SetAl     60   theSingleParticleSource->GetEneDist()->SetAlpha(-1.);
 55   theSingleParticleSource->GetPosDist()->SetPo     61   theSingleParticleSource->GetPosDist()->SetPosDisType("Point");
 56   theSingleParticleSource->GetAngDist()->SetAn     62   theSingleParticleSource->GetAngDist()->SetAngDistType("planar");
 57                                                    63 
 58   theG4AdjointPosOnPhysVolGenerator = G4Adjoin     64   theG4AdjointPosOnPhysVolGenerator = G4AdjointPosOnPhysVolGenerator::GetInstance();
 59 }                                              << 
 60                                                    65 
 61 // ------------------------------------------- <<  66 }
                                                   >>  67 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 62 //                                                 68 //
 63 G4AdjointPrimaryGenerator::~G4AdjointPrimaryGe     69 G4AdjointPrimaryGenerator::~G4AdjointPrimaryGenerator()
 64 {                                                  70 {
 65   delete theSingleParticleSource;                  71   delete theSingleParticleSource;
 66 }                                                  72 }
 67                                                <<  73 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 68 // ------------------------------------------- << 
 69 //                                                 74 //
 70 void G4AdjointPrimaryGenerator::               <<  75 void G4AdjointPrimaryGenerator::GenerateAdjointPrimaryVertex(G4Event* anEvent,G4ParticleDefinition* adj_part,G4double E1,G4double E2)
 71 GenerateAdjointPrimaryVertex(G4Event* anEvent, << 
 72                              G4double E1, G4do << 
 73 {                                                  76 {
 74   if (type_of_adjoint_source == "ExternalSurfa <<  77    if (type_of_adjoint_source == "ExternalSurfaceOfAVolume") {
 75   {                                            <<  78     
 76     // Generate position and direction relativ <<  79   //Generate position and direction relative to the external surface of sensitive volume
 77     // of sensitive volume                     <<  80     //-------------------------------------------------------------
 78                                                <<  81 
 79     G4double costh_to_normal=1.;               <<  82   G4double costh_to_normal=1.;
 80     G4ThreeVector pos =G4ThreeVector(0.,0.,0.) <<  83   G4ThreeVector pos =G4ThreeVector(0.,0.,0.);
 81     G4ThreeVector direction = G4ThreeVector(0. <<  84   G4ThreeVector direction = G4ThreeVector(0.,0.,1.);
 82     theG4AdjointPosOnPhysVolGenerator          <<  85     theG4AdjointPosOnPhysVolGenerator->GenerateAPositionOnTheExtSurfaceOfThePhysicalVolume(pos, direction,costh_to_normal);
 83       ->GenerateAPositionOnTheExtSurfaceOfTheP <<  86     if (costh_to_normal <1.e-4) costh_to_normal =1.e-4;
 84                                                <<  87     //compute now the position along the ray backward direction
 85     if (costh_to_normal <1.e-4)  { costh_to_no <<  88 
 86                                                <<  89     theSingleParticleSource->GetAngDist()->SetParticleMomentumDirection(-direction);
 87     // compute now the position along the ray  <<  90     theSingleParticleSource->GetPosDist()->SetCentreCoords(pos);
 88     //                                         <<  91    }  
 89     theSingleParticleSource->GetAngDist()      <<  92 
 90       ->SetParticleMomentumDirection(-directio <<  93    theSingleParticleSource->GetEneDist()->SetEmin(E1); 
 91     theSingleParticleSource->GetPosDist()->Set <<  94    theSingleParticleSource->GetEneDist()->SetEmax(E2);  
 92   }                                            <<  95   
 93                                                <<  96    theSingleParticleSource->SetParticleDefinition(adj_part);
 94   theSingleParticleSource->GetEneDist()->SetEm <<  97    theSingleParticleSource->GeneratePrimaryVertex(anEvent);
 95   theSingleParticleSource->GetEneDist()->SetEm <<  98 
 96                                                <<  99 
 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                                                   100 
127   theSingleParticleSource->SetParticleDefiniti << 
128   theSingleParticleSource->GeneratePrimaryVert << 
129 }                                                 101 }
                                                   >> 102 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                   >> 103 //
                                                   >> 104 void G4AdjointPrimaryGenerator::GenerateFwdPrimaryVertex(G4Event* anEvent,G4ParticleDefinition* fwd_part,G4double E1,G4double E2)
                                                   >> 105 {
                                                   >> 106    if (type_of_adjoint_source == "ExternalSurfaceOfAVolume") {
                                                   >> 107 
                                                   >> 108   //Generate position and direction relative to the external surface of sensitive volume
                                                   >> 109     //-------------------------------------------------------------
                                                   >> 110 
                                                   >> 111     G4double costh_to_normal=1.;
                                                   >> 112   G4ThreeVector pos =G4ThreeVector(0.,0.,0.);
                                                   >> 113   G4ThreeVector direction = G4ThreeVector(0.,0.,1.);
                                                   >> 114     theG4AdjointPosOnPhysVolGenerator->GenerateAPositionOnTheExtSurfaceOfThePhysicalVolume(pos, direction,costh_to_normal);
                                                   >> 115     if (costh_to_normal <1.e-4) costh_to_normal =1.e-4;
                                                   >> 116     theSingleParticleSource->GetAngDist()->SetParticleMomentumDirection(direction);
                                                   >> 117     theSingleParticleSource->GetPosDist()->SetCentreCoords(pos);
                                                   >> 118    }
130                                                   119 
131 // ------------------------------------------- << 120    theSingleParticleSource->GetEneDist()->SetEmin(E1);
                                                   >> 121    theSingleParticleSource->GetEneDist()->SetEmax(E2);
                                                   >> 122 
                                                   >> 123    theSingleParticleSource->SetParticleDefinition(fwd_part);
                                                   >> 124    theSingleParticleSource->GeneratePrimaryVertex(anEvent);
                                                   >> 125 }
                                                   >> 126 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
132 //                                                127 //
133 void G4AdjointPrimaryGenerator::               << 128 void G4AdjointPrimaryGenerator::SetSphericalAdjointPrimarySource(G4double radius, G4ThreeVector center_pos)
134 SetSphericalAdjointPrimarySource(G4double radi << 
135 {                                                 129 { 
136   radius_spherical_source = radius;               130   radius_spherical_source = radius;
137   center_spherical_source = center_pos;           131   center_spherical_source = center_pos;
138   type_of_adjoint_source = "Spherical";        << 132   type_of_adjoint_source ="Spherical"; 
139   theSingleParticleSource->GetPosDist()->SetPo    133   theSingleParticleSource->GetPosDist()->SetPosDisType("Surface");
140   theSingleParticleSource->GetPosDist()->SetPo    134   theSingleParticleSource->GetPosDist()->SetPosDisShape("Sphere");
141   theSingleParticleSource->GetPosDist()->SetCe    135   theSingleParticleSource->GetPosDist()->SetCentreCoords(center_pos);
142   theSingleParticleSource->GetPosDist()->SetRa    136   theSingleParticleSource->GetPosDist()->SetRadius(radius);
143   theSingleParticleSource->GetAngDist()->SetAn    137   theSingleParticleSource->GetAngDist()->SetAngDistType("cos");
144   theSingleParticleSource->GetAngDist()->SetMa    138   theSingleParticleSource->GetAngDist()->SetMaxTheta(pi);
145   theSingleParticleSource->GetAngDist()->SetMi    139   theSingleParticleSource->GetAngDist()->SetMinTheta(halfpi);
146 }                                                 140 }
147                                                << 141 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
148 // ------------------------------------------- << 
149 //                                                142 //
150 void G4AdjointPrimaryGenerator::               << 143 void G4AdjointPrimaryGenerator::SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(const G4String& volume_name)
151 SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume << 
152 {                                                 144 {
153   theG4AdjointPosOnPhysVolGenerator->DefinePhy    145   theG4AdjointPosOnPhysVolGenerator->DefinePhysicalVolume1(volume_name);
154   type_of_adjoint_source ="ExternalSurfaceOfAV    146   type_of_adjoint_source ="ExternalSurfaceOfAVolume";
155   theSingleParticleSource->GetPosDist()->SetPo    147   theSingleParticleSource->GetPosDist()->SetPosDisType("Point");
156   theSingleParticleSource->GetAngDist()->SetAn    148   theSingleParticleSource->GetAngDist()->SetAngDistType("planar"); 
157 }                                                 149 }
158                                                   150 
159 // ------------------------------------------- << 151 ////////////////////////////////////////////////////////////////////////////////
160 //                                                152 //
161 void G4AdjointPrimaryGenerator::               << 153 void G4AdjointPrimaryGenerator::ComputeAccumulatedDepthVectorAlongBackRay(
162 ComputeAccumulatedDepthVectorAlongBackRay(G4Th << 154                                                  G4ThreeVector glob_pos,
163                                           G4Th << 155                                                  G4ThreeVector direction,
164                                           G4do << 156                                                  G4double,
165 {                                              << 157                                                  G4ParticleDefinition*)
166   if (fLinearNavigator == nullptr)             << 158 { if (!fLinearNavigator) fLinearNavigator =
167   {                                            << 159        G4TransportationManager::GetTransportationManager()
168     fLinearNavigator = G4TransportationManager << 160                                             ->GetNavigatorForTracking();
169                      ->GetNavigatorForTracking << 161  G4ThreeVector position = glob_pos;
170   }                                            << 162  G4double safety=1.;
171   G4ThreeVector position = glob_pos;           << 163  G4VPhysicalVolume* thePhysVolume =
172   G4double safety=1.;                          << 164        fLinearNavigator->LocateGlobalPointAndSetup(position);
173   G4VPhysicalVolume* thePhysVolume =           << 165  G4double newStep =fLinearNavigator->ComputeStep(position,direction,1.e50,
174         fLinearNavigator->LocateGlobalPointAnd << 166                   safety);
175   G4double newStep = fLinearNavigator->Compute << 167  if (theAccumulatedDepthVector) delete theAccumulatedDepthVector;
176                                                << 168  theAccumulatedDepthVector = new G4PhysicsOrderedFreeVector();
177   delete theAccumulatedDepthVector;            << 169  //if (theAccumulatedCSDepthVector) delete theAccumulatedCSDepthVector;
178   theAccumulatedDepthVector = new G4PhysicsFre << 170  //theAccumulatedCSDepthVector = new G4PhysicsOrderedFreeVector();
179                                                << 171 
180   G4double acc_depth=0.;                       << 172  G4double acc_depth=0.;
181   G4double acc_length=0.;                      << 173  G4double acc_length=0.;
182   theAccumulatedDepthVector->InsertValues(acc_ << 174  //G4double acc_cs_depth=0.;
183                                                << 175  //theAccumulatedCSDepthVector->InsertValues(acc_cs_depth, acc_length);
184   while (newStep > 0. && thePhysVolume != null << 176  theAccumulatedDepthVector->InsertValues(acc_length,acc_depth);
185   {                                            << 177 
186     acc_length+=newStep;                       << 178  while (newStep > 0. && thePhysVolume) {
187     acc_depth+=newStep*thePhysVolume->GetLogic << 179    acc_length+=newStep;
188                                     ->GetMater << 180    /*
189     theAccumulatedDepthVector->InsertValues(ac << 181    const G4MaterialCutsCouple* theMatCutsCouple=
190     position=position+newStep*direction;       << 182             thePhysVolume->GetLogicalVolume()->GetMaterialCutsCouple();
191     thePhysVolume = fLinearNavigator           << 183 
192                   ->LocateGlobalPointAndSetup( << 184 
193     newStep = fLinearNavigator->ComputeStep(po << 185    acc_cs_depth+=newStep*G4AdjointCSManager::GetAdjointCSManager()->GetTotalAdjointCS(aPartDef,
194   }                                            << 186                                                              ekin,
195 }                                              << 187                                                         theMatCutsCouple);
                                                   >> 188    theAccumulatedCSDepthVector->InsertValues(acc_cs_depth, acc_length);*/
                                                   >> 189 
                                                   >> 190    acc_depth+=newStep*thePhysVolume->GetLogicalVolume()->GetMaterial()->GetDensity();
                                                   >> 191    theAccumulatedDepthVector->InsertValues(acc_length,acc_depth);
                                                   >> 192    position=position+newStep*direction;
                                                   >> 193    thePhysVolume =
                                                   >> 194           fLinearNavigator->LocateGlobalPointAndSetup(position,0,false);
                                                   >> 195    newStep =fLinearNavigator->ComputeStep(position,direction,1.e50,
                                                   >> 196                      safety);
                                                   >> 197  }
196                                                   198 
197 // ------------------------------------------- << 199 
198 //                                             << 200 }
199 G4double G4AdjointPrimaryGenerator::           << 201 ////////////////////////////////////////////////////////////////////////////////
200 SampleDistanceAlongBackRayAndComputeWeightCorr << 202 //
201 {                                              << 203 G4double G4AdjointPrimaryGenerator::SampleDistanceAlongBackRayAndComputeWeightCorrection(G4double& weight_corr)
202   G4double rand = G4UniformRand();             << 204 {G4double rand = G4UniformRand();
203   G4double distance = theAccumulatedDepthVecto << 205  G4double distance = theAccumulatedDepthVector->FindLinearEnergy(rand);
204   weight_corr=1.;                              << 206  /*
205   return distance;                             << 207  G4double acc_cs_depth=theAccumulatedCSDepthVector->GetEnergy(distance);
                                                   >> 208  weight_corr=std::exp(-acc_cs_depth);*/
                                                   >> 209  weight_corr=1.;
                                                   >> 210  return distance;
206 }                                                 211 }
                                                   >> 212 
                                                   >> 213 
                                                   >> 214 
                                                   >> 215 
207                                                   216