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 ////////////////////////////////////////////// << 26 // $Id: G4AdjointCSManager.hh 93569 2015-10-26 14:53:21Z gcosmo $ 27 // Class: G4AdjointCSManager << 28 // Author: L. Desorgher << 29 // Organisation: SpaceIT GmbH << 30 // 27 // 31 // Class is responsible for the management of << 28 ///////////////////////////////////////////////////////////////////////////////// 32 // matrices, and for the computation of the to << 29 // Class: G4AdjointCSManager 33 // sections. Total adjoint and forward cross s << 30 // Author: L. Desorgher 34 // weight of a particle after a tracking step << 31 // Organisation: SpaceIT GmbH 35 // reverse reaction. It is also used to sample << 32 // Contract: ESA contract 21435/08/NL/AT 36 // given adjoint cross section matrix. << 33 // Customer: ESA/ESTEC >> 34 ///////////////////////////////////////////////////////////////////////////////// >> 35 // >> 36 // CHANGE HISTORY >> 37 // -------------- >> 38 // ChangeHistory: >> 39 // 1st April 2007 creation by L. Desorgher >> 40 // >> 41 // September-October 2009. Implementation of the mode where the adjoint cross sections are scaled such that the total used adjoint cross sections is in >> 42 // most of the cases equal to the total forward cross section. L.Desorgher >> 43 // >> 44 //------------------------------------------------------------- >> 45 // Documentation: >> 46 // Is responsible for the management of all adjoint cross sections matrices, and for the computation of the total forward and adjoint cross sections. >> 47 // Total adjoint and forward cross sections are needed to correct the weight of a particle after a tracking step or after the occurence of a reverse reaction. >> 48 // It is also used to sample an adjoint secondary from a given adjoint cross section matrix. 37 // 49 // 38 ////////////////////////////////////////////// << 39 << 40 #ifndef G4AdjointCSManager_h 50 #ifndef G4AdjointCSManager_h 41 #define G4AdjointCSManager_h 1 51 #define G4AdjointCSManager_h 1 42 52 43 #include "globals.hh" << 53 #include"globals.hh" 44 #include "G4AdjointCSMatrix.hh" << 54 #include<vector> >> 55 #include"G4AdjointCSMatrix.hh" 45 #include "G4ThreadLocalSingleton.hh" 56 #include "G4ThreadLocalSingleton.hh" 46 57 47 #include <vector> << 58 class G4VEmAdjointModel; 48 << 49 class G4Element; << 50 class G4Material; << 51 class G4MaterialCutsCouple; 59 class G4MaterialCutsCouple; >> 60 class G4Material; 52 class G4ParticleDefinition; 61 class G4ParticleDefinition; 53 class G4PhysicsTable; << 62 class G4Element; 54 class G4VEmProcess; 63 class G4VEmProcess; 55 class G4VEmAdjointModel; << 56 class G4VEnergyLossProcess; 64 class G4VEnergyLossProcess; >> 65 class G4PhysicsTable; 57 66 >> 67 //////////////////////////////////////////////////////////////////////////////// >> 68 // 58 class G4AdjointCSManager 69 class G4AdjointCSManager 59 { 70 { 60 friend class G4ThreadLocalSingleton<G4Adjoin << 61 << 62 public: << 63 ~G4AdjointCSManager(); << 64 static G4AdjointCSManager* GetAdjointCSManag << 65 << 66 G4int GetNbProcesses(); << 67 << 68 // Registration of the different models and << 69 << 70 std::size_t RegisterEmAdjointModel(G4VEmAdjo << 71 << 72 void RegisterEmProcess(G4VEmProcess* aProces << 73 G4ParticleDefinition* << 74 << 75 void RegisterEnergyLossProcess(G4VEnergyLoss << 76 G4ParticleDef << 77 << 78 void RegisterAdjointParticle(G4ParticleDefin << 79 << 80 // Building of the CS Matrices and Total For << 81 void BuildCrossSectionMatrices(); << 82 << 83 void BuildTotalSigmaTables(); << 84 << 85 // Get TotalCrossSections form Total Lambda << 86 // correction and scaling of the << 87 G4double GetTotalAdjointCS(G4ParticleDefinit << 88 const G4MaterialC << 89 << 90 G4double GetTotalForwardCS(G4ParticleDefinit << 91 const G4MaterialC << 92 << 93 G4double GetAdjointSigma(G4double Ekin_nuc, << 94 G4bool is_scat_proj << 95 const G4MaterialCut << 96 << 97 void GetEminForTotalCS(G4ParticleDefinition* << 98 const G4MaterialCutsC << 99 G4double& emin_adj, G << 100 << 101 void GetMaxFwdTotalCS(G4ParticleDefinition* << 102 const G4MaterialCutsCo << 103 G4double& e_sigma_max, << 104 << 105 void GetMaxAdjTotalCS(G4ParticleDefinition* << 106 const G4MaterialCutsCo << 107 G4double& e_sigma_max, << 108 71 109 // CrossSection Correction 1 or FwdCS/AdjCS << 72 friend class G4ThreadLocalSingleton<G4AdjointCSManager>; 110 // forward_CS_is_used and forward_CS_mode << 73 111 G4double GetCrossSectionCorrection(G4Particl << 74 public: 112 G4double << 75 ~G4AdjointCSManager(); 113 const G4M << 76 static G4AdjointCSManager* GetAdjointCSManager(); 114 G4bool& f << 77 115 << 78 public: 116 // Cross section mode << 79 G4int GetNbProcesses(); 117 inline void SetFwdCrossSectionMode(G4bool aB << 80 118 << 81 //Registration of the different models and processes 119 // Weight correction << 82 120 G4double GetContinuousWeightCorrection(G4Par << 83 size_t RegisterEmAdjointModel(G4VEmAdjointModel*); 121 G4dou << 84 122 G4dou << 85 void RegisterEmProcess(G4VEmProcess* aProcess, G4ParticleDefinition* aPartDef); 123 const << 86 124 G4dou << 87 void RegisterEnergyLossProcess(G4VEnergyLossProcess* aProcess, G4ParticleDefinition* aPartDef); 125 << 88 126 G4double GetPostStepWeightCorrection(); << 89 void RegisterAdjointParticle(G4ParticleDefinition* aPartDef); 127 << 90 128 // called by the adjoint model to get the CS << 91 //Building of the CS Matrices and Total Forward and Adjoint LambdaTables 129 G4double ComputeAdjointCS(G4Material* aMater << 92 //---------------------------------------------------------------------- 130 G4double PrimEnerg << 93 131 G4bool isScatProjT << 94 void BuildCrossSectionMatrices(); 132 std::vector<G4doub << 95 void BuildTotalSigmaTables(); 133 << 96 134 // called by the adjoint model to sample sec << 97 135 G4Element* SampleElementFromCSMatrices(G4Mat << 98 //Get TotalCrossSections form Total Lambda Tables, Needed for Weight correction and scaling of the 136 G4VEm << 99 //------------------------------------------------- 137 G4dou << 100 G4double GetTotalAdjointCS(G4ParticleDefinition* aPartDef, G4double Ekin, 138 G4boo << 101 const G4MaterialCutsCouple* aCouple); 139 << 102 G4double GetTotalForwardCS(G4ParticleDefinition* aPartDef, G4double Ekin, 140 // Total Adjoint CS is computed at initialis << 103 const G4MaterialCutsCouple* aCouple); 141 G4double ComputeTotalAdjointCS(const G4Mater << 104 142 G4ParticleDef << 105 G4double GetAdjointSigma(G4double Ekin_nuc, size_t index_model,G4bool is_scat_proj_to_proj, 143 G4double Prim << 106 const G4MaterialCutsCouple* aCouple); 144 << 107 145 G4ParticleDefinition* GetAdjointParticleEqui << 108 void GetEminForTotalCS(G4ParticleDefinition* aPartDef, 146 G4ParticleDefinition* theFwdPartDef); << 109 const G4MaterialCutsCouple* aCouple, G4double& emin_adj, G4double& emin_fwd); 147 << 110 void GetMaxFwdTotalCS(G4ParticleDefinition* aPartDef, 148 G4ParticleDefinition* GetForwardParticleEqui << 111 const G4MaterialCutsCouple* aCouple, G4double& e_sigma_max, G4double& sigma_max); 149 G4ParticleDefinition* theAdjPartDef); << 112 void GetMaxAdjTotalCS(G4ParticleDefinition* aPartDef, 150 << 113 const G4MaterialCutsCouple* aCouple, G4double& e_sigma_max, G4double& sigma_max); 151 // inline << 114 152 inline void SetIon(G4ParticleDefinition* adj << 115 153 { << 116 154 fAdjIon = adjIon; << 117 //CrossSection Correction 1 or FwdCS/AdjCS following the G4boolean value of forward_CS_is_used and forward_CS_mode 155 fFwdIon = fwdIon; << 118 //------------------------------------------------- 156 } << 119 G4double GetCrossSectionCorrection(G4ParticleDefinition* aPartDef,G4double PreStepEkin,const G4MaterialCutsCouple* aCouple, G4bool& fwd_is_used, G4double& fwd_TotCS); 157 << 120 158 private: << 121 159 G4AdjointCSManager(); << 122 //Cross section mode 160 << 123 //------------------ 161 void DefineCurrentMaterial(const G4MaterialC << 124 inline void SetFwdCrossSectionMode(G4bool aBool){forward_CS_mode=aBool;} 162 << 125 163 void DefineCurrentParticle(const G4ParticleD << 126 164 << 127 //Weight correction 165 G4double ComputeAdjointCS(G4double aPrimEner << 128 //------------------ 166 G4AdjointCSMatrix* << 129 167 G4double Tcut); << 130 G4double GetContinuousWeightCorrection(G4ParticleDefinition* aPartDef, G4double PreStepEkin,G4double AfterStepEkin, 168 << 131 const G4MaterialCutsCouple* aCouple, G4double step_length); 169 std::vector<G4AdjointCSMatrix*> BuildCrossSe << 132 G4double GetPostStepWeightCorrection(); 170 G4VEmAdjointModel* aModel, G4int Z, G4int << 133 171 << 134 172 std::vector<G4AdjointCSMatrix*> BuildCrossSe << 135 173 G4VEmAdjointModel* aModel, G4Material* aMa << 136 174 << 137 //Method Called by the adjoint model to get there CS, if not precised otherwise 175 static constexpr G4double fTmin = 0.1 * CLHE << 138 //------------------------------- 176 static constexpr G4double fTmax = 100. * CLH << 139 177 // fNbins chosen to avoid error << 140 G4double ComputeAdjointCS(G4Material* aMaterial, 178 // in the CS value close to CS jump. (For ex << 141 G4VEmAdjointModel* aModel, 179 static constexpr G4int fNbins = 320; << 142 G4double PrimEnergy, 180 << 143 G4double Tcut, 181 static G4ThreadLocal G4AdjointCSManager* fIn << 144 G4bool IsScatProjToProjCase, 182 << 145 std::vector<G4double>& 183 // only one ion can be considered by simulat << 146 AdjointCS_for_each_element); 184 G4ParticleDefinition* fAdjIon = nullptr; << 147 185 G4ParticleDefinition* fFwdIon = nullptr; << 148 //Method Called by the adjoint model to sample the secondary energy form the CS matrix 186 << 149 //-------------------------------------------------------------------------------- 187 G4MaterialCutsCouple* fCurrentCouple = nullp << 150 G4Element* SampleElementFromCSMatrices(G4Material* aMaterial, 188 G4Material* fCurrentMaterial = nullp << 151 G4VEmAdjointModel* aModel, 189 << 152 G4double PrimEnergy, 190 // x dim is for G4VAdjointEM*, y dim is for << 153 G4double Tcut, 191 std::vector<std::vector<G4AdjointCSMatrix*>> << 154 G4bool IsScatProjToProjCase); 192 fAdjointCSMatricesForScatProjToProj; << 155 193 << 156 194 std::vector<std::vector<G4AdjointCSMatrix*>> << 157 //Total Adjoint CS is computed at initialisation phase 195 << 158 //----------------------------------------------------- 196 std::vector<G4VEmAdjointModel*> fAdjointMode << 159 G4double ComputeTotalAdjointCS(const G4MaterialCutsCouple* aMatCutCouple,G4ParticleDefinition* aPart,G4double PrimEnergy); 197 << 160 198 std::vector<std::size_t> fIndexOfAdjointEMMo << 161 199 std::vector<G4bool> fIsScatProjToProj; << 162 200 std::vector<std::vector<G4double>> fLastAdjo << 163 201 << 164 G4ParticleDefinition* GetAdjointParticleEquivalent(G4ParticleDefinition* theFwdPartDef); 202 // total adjoint and total forward cross sec << 165 G4ParticleDefinition* GetForwardParticleEquivalent(G4ParticleDefinition* theAdjPartDef); 203 // and in function of adjoint particle type << 166 204 std::vector<G4PhysicsTable*> fTotalFwdSigmaT << 167 //inline 205 std::vector<G4PhysicsTable*> fTotalAdjSigmaT << 168 inline void SetTmin(G4double aVal){Tmin=aVal;} 206 << 169 inline void SetTmax(G4double aVal){Tmax=aVal;} 207 // Sigma table for each G4VAdjointEMModel << 170 inline void SetNbins(G4int aInt){nbins=aInt;} 208 std::vector<G4PhysicsTable*> fSigmaTableForA << 171 inline void SetIon(G4ParticleDefinition* adjIon, 209 std::vector<G4PhysicsTable*> fSigmaTableForA << 172 G4ParticleDefinition* fwdIon) {theAdjIon=adjIon; theFwdIon =fwdIon;} 210 << 173 211 std::vector<std::vector<G4double>> fEminForF << 174 212 std::vector<std::vector<G4double>> fEminForA << 175 private: 213 std::vector<std::vector<G4double>> fEkinofFw << 176 static G4ThreadLocal G4AdjointCSManager* theInstance; 214 std::vector<std::vector<G4double>> fEkinofAd << 177 std::vector< std::vector<G4AdjointCSMatrix*> > theAdjointCSMatricesForScatProjToProj; //x dim is for G4VAdjointEM*, y dim is for elements 215 << 178 std::vector< std::vector<G4AdjointCSMatrix*> > theAdjointCSMatricesForProdToProj; 216 // list of forward G4VEmProcess and of G4VEn << 179 std::vector< G4VEmAdjointModel*> listOfAdjointEMModel; 217 // adjoint particle << 180 218 std::vector<std::vector<G4VEmProcess*>*> fFo << 181 std::vector<G4AdjointCSMatrix*> 219 std::vector<std::vector<G4VEnergyLossProcess << 182 BuildCrossSectionsMatricesForAGivenModelAndElement(G4VEmAdjointModel* aModel, 220 << 183 G4int Z, 221 // list of adjoint particles considered << 184 G4int A, 222 std::vector<G4ParticleDefinition*> fAdjointP << 185 G4int nbin_pro_decade); 223 << 186 224 G4double fMassRatio = 1.; // i << 187 std::vector<G4AdjointCSMatrix*> 225 G4double fLastCSCorrectionFactor = 1.; << 188 BuildCrossSectionsMatricesForAGivenModelAndMaterial(G4VEmAdjointModel* aModel, 226 << 189 G4Material* aMaterial, 227 G4ParticleDefinition* fCurrentParticleDef = << 190 G4int nbin_pro_decade); 228 std::size_t fCurrentParticleIndex = 0; << 191 229 std::size_t fCurrentMatIndex = 0; << 192 >> 193 G4Material* lastMaterial; >> 194 G4double lastPrimaryEnergy; >> 195 G4double lastTcut; >> 196 std::vector< size_t> listOfIndexOfAdjointEMModelInAction; >> 197 std::vector< G4bool> listOfIsScatProjToProjCase; >> 198 std::vector< std::vector<G4double> > lastAdjointCSVsModelsAndElements; >> 199 G4bool CrossSectionMatrixesAreBuilt; >> 200 size_t currentParticleIndex; >> 201 G4ParticleDefinition* currentParticleDef; >> 202 >> 203 //total adjoint and total forward cross section table in function of material and in function of adjoint particle type >> 204 //-------------------------------------------------------------------------------------------------------------------- >> 205 std::vector<G4PhysicsTable*> theTotalForwardSigmaTableVector; >> 206 std::vector<G4PhysicsTable*> theTotalAdjointSigmaTableVector; >> 207 std::vector< std::vector<G4double> > EminForFwdSigmaTables; >> 208 std::vector< std::vector<G4double> > EminForAdjSigmaTables; >> 209 std::vector< std::vector<G4double> > EkinofFwdSigmaMax; >> 210 std::vector< std::vector<G4double> > EkinofAdjSigmaMax; >> 211 G4bool TotalSigmaTableAreBuilt; >> 212 >> 213 //Sigma tavle for each G4VAdjointEMModel >> 214 std::vector<G4PhysicsTable*> listSigmaTableForAdjointModelScatProjToProj; >> 215 std::vector<G4PhysicsTable*> listSigmaTableForAdjointModelProdToProj; >> 216 >> 217 //list of forward G4VEMLossProcess and of G4VEMProcess for the different adjoint particle >> 218 //-------------------------------------------------------------- >> 219 std::vector< std::vector<G4VEmProcess*>* > listOfForwardEmProcess; >> 220 std::vector< std::vector<G4VEnergyLossProcess*>* > listOfForwardEnergyLossProcess; >> 221 >> 222 //list of adjoint particles considered >> 223 //-------------------------------------------------------------- >> 224 std::vector< G4ParticleDefinition*> theListOfAdjointParticlesInAction; >> 225 >> 226 G4double Tmin,Tmax; >> 227 G4int nbins; >> 228 >> 229 //Current material >> 230 //---------------- >> 231 G4MaterialCutsCouple* currentCouple; >> 232 G4Material* currentMaterial; >> 233 size_t currentMatIndex; >> 234 >> 235 G4int verbose; >> 236 >> 237 //Two CS mode are possible :forward_CS_mode = false the Adjoint CS are used as it is implying a AlongStep Weight Correction. >> 238 // :forward_CS_mode = true the Adjoint CS are scaled to have the total adjoint CS eual to the fwd one implying a PostStep Weight Correction. >> 239 // For energy range where the total FwdCS or the total adjoint CS are null, the scaling is not possble and >> 240 // forward_CS_is_used is set to false >> 241 //-------------------------------------------- >> 242 G4bool forward_CS_is_used; >> 243 G4bool forward_CS_mode; >> 244 >> 245 //Adj and Fwd CS values for re-use >> 246 //------------------------ >> 247 >> 248 G4double PreadjCS,PostadjCS; >> 249 G4double PrefwdCS,PostfwdCS; >> 250 G4double LastEkinForCS; >> 251 G4double LastCSCorrectionFactor; >> 252 G4ParticleDefinition* lastPartDefForCS; >> 253 >> 254 //Ion >> 255 //---------------- >> 256 G4ParticleDefinition* theAdjIon; //at the moment Only one ion can be considered by simulation >> 257 G4ParticleDefinition* theFwdIon; >> 258 G4double massRatio; >> 259 >> 260 private: >> 261 G4AdjointCSManager(); >> 262 void DefineCurrentMaterial(const G4MaterialCutsCouple* couple); >> 263 void DefineCurrentParticle(const G4ParticleDefinition* aPartDef); >> 264 G4double ComputeAdjointCS(G4double aPrimEnergy, G4AdjointCSMatrix* anAdjointCSMatrix, G4double Tcut); >> 265 size_t eindex; 230 266 231 G4bool fCSMatricesBuilt = false; << 232 G4bool fSigmaTableBuilt = false; << 233 G4bool fForwardCSUsed = true; << 234 G4bool fForwardCSMode = true; << 235 // Two CS mode are possible: << 236 // 1) fForwardCSMode = false, the Adjoint CS << 237 // an AlongStep Weight Correction. << 238 // 2) fForwardCSMode = true, the Adjoint CS << 239 // adjoint CS equal to the fwd one implyi << 240 // For energies where the total Fwd CS or th << 241 // the scaling is not possible and fForwardC << 242 }; 267 }; 243 #endif 268 #endif 244 269