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 // $Id: G4AdjointCSManager.cc,v 1.6 2010-11-11 11:51:56 ldesorgh Exp $ >> 27 // GEANT4 tag $Name: not supported by cvs2svn $ 26 // 28 // 27 << 28 #include "G4AdjointCSManager.hh" 29 #include "G4AdjointCSManager.hh" 29 << 30 #include "G4AdjointCSMatrix.hh" 30 #include "G4AdjointCSMatrix.hh" 31 #include "G4AdjointElectron.hh" << 32 #include "G4AdjointGamma.hh" << 33 #include "G4AdjointInterpolator.hh" 31 #include "G4AdjointInterpolator.hh" 34 #include "G4AdjointProton.hh" << 32 #include "G4AdjointCSMatrix.hh" 35 #include "G4Electron.hh" << 33 #include "G4VEmAdjointModel.hh" 36 #include "G4Element.hh" << 37 #include "G4ElementTable.hh" 34 #include "G4ElementTable.hh" 38 #include "G4Gamma.hh" << 35 #include "G4Element.hh" 39 #include "G4ParticleDefinition.hh" 36 #include "G4ParticleDefinition.hh" 40 #include "G4PhysicalConstants.hh" << 37 #include "G4Element.hh" 41 #include "G4PhysicsLogVector.hh" << 42 #include "G4PhysicsTable.hh" << 43 #include "G4ProductionCutsTable.hh" << 44 #include "G4Proton.hh" << 45 #include "G4SystemOfUnits.hh" << 46 #include "G4VEmAdjointModel.hh" << 47 #include "G4VEmProcess.hh" 38 #include "G4VEmProcess.hh" 48 #include "G4VEnergyLossProcess.hh" 39 #include "G4VEnergyLossProcess.hh" >> 40 #include "G4PhysicsTable.hh" >> 41 #include "G4PhysicsLogVector.hh" >> 42 #include "G4PhysicsTableHelper.hh" >> 43 #include "G4Electron.hh" >> 44 #include "G4Gamma.hh" >> 45 #include "G4Proton.hh" >> 46 #include "G4AdjointElectron.hh" >> 47 #include "G4AdjointGamma.hh" >> 48 #include "G4AdjointProton.hh" >> 49 #include "G4ProductionCutsTable.hh" >> 50 #include "G4ProductionCutsTable.hh" >> 51 #include <fstream> >> 52 #include <iomanip> 49 53 50 G4ThreadLocal G4AdjointCSManager* G4AdjointCSM << 51 << 52 constexpr G4double G4AdjointCSManager::fTmin; << 53 constexpr G4double G4AdjointCSManager::fTmax; << 54 constexpr G4int G4AdjointCSManager::fNbins; << 55 54 >> 55 G4AdjointCSManager* G4AdjointCSManager::theInstance = 0; 56 ////////////////////////////////////////////// 56 /////////////////////////////////////////////////////// >> 57 // 57 G4AdjointCSManager* G4AdjointCSManager::GetAdj 58 G4AdjointCSManager* G4AdjointCSManager::GetAdjointCSManager() 58 { << 59 { if(theInstance == 0) { 59 if(fInstance == nullptr) << 60 static G4AdjointCSManager ins; 60 { << 61 theInstance = &ins; 61 static G4ThreadLocalSingleton<G4AdjointCSM << 62 fInstance = inst.Instance(); << 63 } 62 } 64 return fInstance; << 63 return theInstance; 65 } 64 } 66 65 67 ////////////////////////////////////////////// 66 /////////////////////////////////////////////////////// >> 67 // 68 G4AdjointCSManager::G4AdjointCSManager() 68 G4AdjointCSManager::G4AdjointCSManager() 69 { << 69 { CrossSectionMatrixesAreBuilt=false; >> 70 TotalSigmaTableAreBuilt=false; >> 71 theTotalForwardSigmaTableVector.clear(); >> 72 theTotalAdjointSigmaTableVector.clear(); >> 73 listOfForwardEmProcess.clear(); >> 74 listOfForwardEnergyLossProcess.clear(); >> 75 theListOfAdjointParticlesInAction.clear(); >> 76 EminForFwdSigmaTables.clear(); >> 77 EminForAdjSigmaTables.clear(); >> 78 EkinofFwdSigmaMax.clear(); >> 79 EkinofAdjSigmaMax.clear(); >> 80 listSigmaTableForAdjointModelScatProjToProj.clear(); >> 81 listSigmaTableForAdjointModelProdToProj.clear(); >> 82 Tmin=0.1*keV; >> 83 Tmax=100.*TeV; >> 84 nbins=320; //probably this should be decrease, that was choosen to avoid error in the CS value closed to CS jump.(For example at Tcut) >> 85 70 RegisterAdjointParticle(G4AdjointElectron::A 86 RegisterAdjointParticle(G4AdjointElectron::AdjointElectron()); 71 RegisterAdjointParticle(G4AdjointGamma::Adjo 87 RegisterAdjointParticle(G4AdjointGamma::AdjointGamma()); 72 RegisterAdjointParticle(G4AdjointProton::Adj 88 RegisterAdjointParticle(G4AdjointProton::AdjointProton()); >> 89 >> 90 verbose = 1; >> 91 >> 92 lastPartDefForCS =0; >> 93 LastEkinForCS =0; >> 94 LastCSCorrectionFactor =1.; >> 95 >> 96 forward_CS_mode = true; >> 97 >> 98 currentParticleDef = 0; >> 99 >> 100 theAdjIon = 0; >> 101 theFwdIon = 0; >> 102 >> 103 73 } 104 } 74 << 75 ////////////////////////////////////////////// 105 /////////////////////////////////////////////////////// >> 106 // 76 G4AdjointCSManager::~G4AdjointCSManager() 107 G4AdjointCSManager::~G4AdjointCSManager() 77 { << 108 {; 78 for (auto& p : fAdjointCSMatricesForProdToPr << 79 for (auto p1 : p) { << 80 if (p1) { << 81 delete p1; << 82 p1 = nullptr; << 83 } << 84 } << 85 p.clear(); << 86 } << 87 fAdjointCSMatricesForProdToProj.clear(); << 88 << 89 for (auto& p : fAdjointCSMatricesForScatProj << 90 for (auto p1 : p) { << 91 if (p1) { << 92 delete p1; << 93 p1 = nullptr; << 94 } << 95 } << 96 p.clear(); << 97 } << 98 fAdjointCSMatricesForScatProjToProj.clear(); << 99 << 100 for (auto p : fAdjointModels) { << 101 if (p) { << 102 delete p; << 103 p = nullptr; << 104 } << 105 } << 106 fAdjointModels.clear(); << 107 << 108 for (auto p : fTotalAdjSigmaTable) { << 109 p->clearAndDestroy(); << 110 delete p; << 111 p = nullptr; << 112 } << 113 fTotalAdjSigmaTable.clear(); << 114 << 115 for (auto p : fSigmaTableForAdjointModelScat << 116 p->clearAndDestroy(); << 117 delete p; << 118 p = nullptr; << 119 } << 120 fSigmaTableForAdjointModelScatProjToProj.cle << 121 << 122 for (auto p : fSigmaTableForAdjointModelProd << 123 p->clearAndDestroy(); << 124 delete p; << 125 p = nullptr; << 126 } << 127 fSigmaTableForAdjointModelProdToProj.clear() << 128 << 129 for (auto p : fTotalFwdSigmaTable) { << 130 p->clearAndDestroy(); << 131 delete p; << 132 p = nullptr; << 133 } << 134 fTotalFwdSigmaTable.clear(); << 135 << 136 for (auto p : fForwardProcesses) { << 137 delete p; << 138 p = nullptr; << 139 } << 140 fForwardProcesses.clear(); << 141 << 142 for (auto p : fForwardLossProcesses) { << 143 delete p; << 144 p = nullptr; << 145 } << 146 fForwardLossProcesses.clear(); << 147 } 109 } 148 << 149 ////////////////////////////////////////////// 110 /////////////////////////////////////////////////////// 150 std::size_t G4AdjointCSManager::RegisterEmAdjo << 111 // 151 { << 112 size_t G4AdjointCSManager::RegisterEmAdjointModel(G4VEmAdjointModel* aModel) 152 fAdjointModels.push_back(aModel); << 113 {listOfAdjointEMModel.push_back(aModel); 153 fSigmaTableForAdjointModelScatProjToProj.pus << 114 listSigmaTableForAdjointModelScatProjToProj.push_back(new G4PhysicsTable); 154 fSigmaTableForAdjointModelProdToProj.push_ba << 115 listSigmaTableForAdjointModelProdToProj.push_back(new G4PhysicsTable); 155 return fAdjointModels.size() - 1; << 116 return listOfAdjointEMModel.size() -1; >> 117 156 } 118 } 157 << 158 ////////////////////////////////////////////// 119 /////////////////////////////////////////////////////// 159 void G4AdjointCSManager::RegisterEmProcess(G4V << 120 // 160 G4P << 121 void G4AdjointCSManager::RegisterEmProcess(G4VEmProcess* aProcess, G4ParticleDefinition* aFwdPartDef) 161 { << 122 { 162 G4ParticleDefinition* anAdjPartDef = << 123 G4ParticleDefinition* anAdjPartDef = GetAdjointParticleEquivalent(aFwdPartDef); 163 GetAdjointParticleEquivalent(aFwdPartDef); << 124 if (anAdjPartDef && aProcess){ 164 if(anAdjPartDef && aProcess) << 125 RegisterAdjointParticle(anAdjPartDef); 165 { << 126 G4int index=-1; 166 RegisterAdjointParticle(anAdjPartDef); << 127 167 << 128 for (size_t i=0;i<theListOfAdjointParticlesInAction.size();i++){ 168 for(std::size_t i = 0; i < fAdjointParticl << 129 if (anAdjPartDef->GetParticleName() == theListOfAdjointParticlesInAction[i]->GetParticleName()) index=i; 169 { << 130 } 170 if(anAdjPartDef->GetParticleName() == << 131 listOfForwardEmProcess[index]->push_back(aProcess); 171 fAdjointParticlesInAction[i]->GetPart << 172 fForwardProcesses[i]->push_back(aProce << 173 } << 174 } 132 } 175 } 133 } 176 << 177 ////////////////////////////////////////////// 134 /////////////////////////////////////////////////////// 178 void G4AdjointCSManager::RegisterEnergyLossPro << 135 // 179 G4VEnergyLossProcess* aProcess, G4ParticleDe << 136 void G4AdjointCSManager::RegisterEnergyLossProcess(G4VEnergyLossProcess* aProcess, G4ParticleDefinition* aFwdPartDef) 180 { 137 { 181 G4ParticleDefinition* anAdjPartDef = << 138 G4ParticleDefinition* anAdjPartDef = GetAdjointParticleEquivalent(aFwdPartDef); 182 GetAdjointParticleEquivalent(aFwdPartDef); << 139 if (anAdjPartDef && aProcess){ 183 if(anAdjPartDef && aProcess) << 140 RegisterAdjointParticle(anAdjPartDef); 184 { << 141 G4int index=-1; 185 RegisterAdjointParticle(anAdjPartDef); << 142 for (size_t i=0;i<theListOfAdjointParticlesInAction.size();i++){ 186 for(std::size_t i = 0; i < fAdjointParticl << 143 if (anAdjPartDef->GetParticleName() == theListOfAdjointParticlesInAction[i]->GetParticleName()) index=i; 187 { << 144 } 188 if(anAdjPartDef->GetParticleName() == << 145 listOfForwardEnergyLossProcess[index]->push_back(aProcess); 189 fAdjointParticlesInAction[i]->GetPart << 146 } 190 fForwardLossProc << 191 << 192 } << 193 } << 194 } 147 } 195 << 196 ////////////////////////////////////////////// 148 /////////////////////////////////////////////////////// >> 149 // 197 void G4AdjointCSManager::RegisterAdjointPartic 150 void G4AdjointCSManager::RegisterAdjointParticle(G4ParticleDefinition* aPartDef) 198 { << 151 { G4int index=-1; 199 G4bool found = false; << 152 for (size_t i=0;i<theListOfAdjointParticlesInAction.size();i++){ 200 for(auto p : fAdjointParticlesInAction) << 153 if (aPartDef->GetParticleName() == theListOfAdjointParticlesInAction[i]->GetParticleName()) index=i; 201 { << 154 } 202 if(p->GetParticleName() == aPartDef->GetPa << 155 203 { << 156 if (index ==-1){ 204 found = true; << 157 listOfForwardEnergyLossProcess.push_back(new std::vector<G4VEnergyLossProcess*>()); 205 } << 158 theTotalForwardSigmaTableVector.push_back(new G4PhysicsTable); 206 } << 159 theTotalAdjointSigmaTableVector.push_back(new G4PhysicsTable); 207 if(!found) << 160 listOfForwardEmProcess.push_back(new std::vector<G4VEmProcess*>()); 208 { << 161 theListOfAdjointParticlesInAction.push_back(aPartDef); 209 fForwardLossProcesses.push_back(new std::v << 162 EminForFwdSigmaTables.push_back(std::vector<G4double> ()); 210 fTotalFwdSigmaTable.push_back(new G4Physic << 163 EminForAdjSigmaTables.push_back(std::vector<G4double> ()); 211 fTotalAdjSigmaTable.push_back(new G4Physic << 164 EkinofFwdSigmaMax.push_back(std::vector<G4double> ()); 212 fForwardProcesses.push_back(new std::vecto << 165 EkinofAdjSigmaMax.push_back(std::vector<G4double> ()); 213 fAdjointParticlesInAction.push_back(aPartD << 166 214 fEminForFwdSigmaTables.push_back(std::vect << 167 } 215 fEminForAdjSigmaTables.push_back(std::vect << 216 fEkinofFwdSigmaMax.push_back(std::vector<G << 217 fEkinofAdjSigmaMax.push_back(std::vector<G << 218 } << 219 } 168 } 220 << 221 ////////////////////////////////////////////// 169 /////////////////////////////////////////////////////// >> 170 // 222 void G4AdjointCSManager::BuildCrossSectionMatr 171 void G4AdjointCSManager::BuildCrossSectionMatrices() 223 { << 172 { 224 if(fCSMatricesBuilt) << 173 if (CrossSectionMatrixesAreBuilt) return; 225 return; << 174 //Tcut, Tmax 226 // The Tcut and Tmax matrices will be comput << 175 //The matrices will be computed probably just once 227 // When Tcut changes, some PhysicsTable will << 176 //When Tcut will change some PhysicsTable will be recomputed 228 // for each MaterialCutCouple but not all th << 177 // for each MaterialCutCouple but not all the matrices 229 // The Tcut defines a lower limit in the ene << 178 //The Tcut defines a lower limit in the energy of the Projectile before the scattering 230 // scattering. In the Projectile to Scattere << 179 //In the Projectile to Scattered Projectile case we have 231 // E_ScatProj<E_Proj-Tcut << 180 // E_ScatProj<E_Proj-Tcut 232 // Therefore in the adjoint case we have << 181 //Therefore in the adjoint case we have 233 // Eproj> E_ScatProj+Tcut << 182 // Eproj> E_ScatProj+Tcut 234 // This implies that when computing the adjo << 183 //This implies that when computing the adjoint CS we should integrate over Epro 235 // Epro from E_ScatProj+Tcut to Emax << 184 // from E_ScatProj+Tcut to Emax 236 // In the Projectile to Secondary case Tcut << 185 //In the Projectile to Secondary case Tcut plays a role only in the fact that 237 // Esecond should be greater than Tcut to ha << 186 // Esecond should be greater than Tcut to have the possibility to have any adjoint 238 // adjoint process. << 187 //process 239 // To avoid recomputing matrices for all cha << 188 //To avoid to recompute the matrices for all changes of MaterialCutCouple 240 // we propose to compute the matrices only o << 189 //We propose to compute the matrices only once for the minimum possible Tcut and then 241 // and then to interpolate the probability f << 190 //to interpolate the probability for a new Tcut (implemented in G4VAdjointEmModel) 242 // G4VAdjointEmModel) << 191 243 << 192 244 fAdjointCSMatricesForScatProjToProj.clear(); << 193 theAdjointCSMatricesForScatProjToProj.clear(); 245 fAdjointCSMatricesForProdToProj.clear(); << 194 theAdjointCSMatricesForProdToProj.clear(); 246 const G4ElementTable* theElementTable = G4 << 195 const G4ElementTable* theElementTable = G4Element::GetElementTable(); 247 const G4MaterialTable* theMaterialTable = G4 << 196 const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable(); 248 << 197 249 G4cout << "========== Computation of cross s << 198 G4cout<<"========== Computation of cross section matrices for adjoint models =========="<<G4endl; 250 "models ==========" << 199 for (size_t i=0; i<listOfAdjointEMModel.size();i++){ 251 << G4endl; << 200 G4VEmAdjointModel* aModel =listOfAdjointEMModel[i]; 252 for(const auto& aModel : fAdjointModels) << 201 G4cout<<"Build adjoint cross section matrices for "<<aModel->GetName()<<G4endl; 253 { << 202 if (aModel->GetUseMatrix()){ 254 G4cout << "Build adjoint cross section mat << 203 std::vector<G4AdjointCSMatrix*>* aListOfMat1 = new std::vector<G4AdjointCSMatrix*>(); 255 << G4endl; << 204 std::vector<G4AdjointCSMatrix*>* aListOfMat2 = new std::vector<G4AdjointCSMatrix*>(); 256 if(aModel->GetUseMatrix()) << 205 aListOfMat1->clear(); 257 { << 206 aListOfMat2->clear(); 258 std::vector<G4AdjointCSMatrix*>* aListOf << 207 if (aModel->GetUseMatrixPerElement()){ 259 new std::vector<G4AdjointCSMatrix*>(); << 208 if (aModel->GetUseOnlyOneMatrixForAllElements()){ 260 std::vector<G4AdjointCSMatrix*>* aListOf << 209 std::vector<G4AdjointCSMatrix*> 261 new std::vector<G4AdjointCSMatrix*>(); << 210 two_matrices=BuildCrossSectionsMatricesForAGivenModelAndElement(aModel,1, 1, 80); 262 if(aModel->GetUseMatrixPerElement()) << 211 aListOfMat1->push_back(two_matrices[0]); 263 { << 212 aListOfMat2->push_back(two_matrices[1]); 264 if(aModel->GetUseOnlyOneMatrixForAllEl << 213 } 265 { << 214 else { 266 std::vector<G4AdjointCSMatrix*> two_ << 215 for (size_t j=0; j<theElementTable->size();j++){ 267 BuildCrossSectionsModelAndElement( << 216 G4Element* anElement=(*theElementTable)[j]; 268 aListOfMat1->push_back(two_matrices[ << 217 G4int Z = int(anElement->GetZ()); 269 aListOfMat2->push_back(two_matrices[ << 218 G4int A = int(anElement->GetA()); 270 } << 219 std::vector<G4AdjointCSMatrix*> 271 else << 220 two_matrices=BuildCrossSectionsMatricesForAGivenModelAndElement(aModel,Z, A, 40); 272 { << 221 aListOfMat1->push_back(two_matrices[0]); 273 for(const auto& anElement : *theElem << 222 aListOfMat2->push_back(two_matrices[1]); 274 { << 223 } 275 G4int Z = G4lrint(anElement->GetZ( << 224 } 276 G4int A = G4lrint(anElement->GetN( << 225 } 277 std::vector<G4AdjointCSMatrix*> tw << 226 else { //Per material case 278 BuildCrossSectionsModelAndElemen << 227 for (size_t j=0; j<theMaterialTable->size();j++){ 279 aListOfMat1->push_back(two_matrice << 228 G4Material* aMaterial=(*theMaterialTable)[j]; 280 aListOfMat2->push_back(two_matrice << 229 std::vector<G4AdjointCSMatrix*> 281 } << 230 two_matrices=BuildCrossSectionsMatricesForAGivenModelAndMaterial(aModel,aMaterial, 40); 282 } << 231 aListOfMat1->push_back(two_matrices[0]); 283 } << 232 aListOfMat2->push_back(two_matrices[1]); 284 else << 233 } 285 { // Per material case << 234 286 for(const auto& aMaterial : *theMateri << 235 } 287 { << 236 theAdjointCSMatricesForProdToProj.push_back(*aListOfMat1); 288 std::vector<G4AdjointCSMatrix*> two_ << 237 theAdjointCSMatricesForScatProjToProj.push_back(*aListOfMat2); 289 BuildCrossSectionsModelAndMaterial << 238 aModel->SetCSMatrices(aListOfMat1, aListOfMat2); 290 aListOfMat1->push_back(two_matrices[ << 239 } 291 aListOfMat2->push_back(two_matrices[ << 240 else { G4cout<<"The model "<<aModel->GetName()<<" does not use cross section matrices"<<G4endl; 292 } << 241 std::vector<G4AdjointCSMatrix*> two_empty_matrices; 293 } << 242 theAdjointCSMatricesForProdToProj.push_back(two_empty_matrices); 294 fAdjointCSMatricesForProdToProj.push_bac << 243 theAdjointCSMatricesForScatProjToProj.push_back(two_empty_matrices); 295 fAdjointCSMatricesForScatProjToProj.push << 244 296 aModel->SetCSMatrices(aListOfMat1, aList << 245 } 297 } << 246 } 298 else << 247 G4cout<<" All adjoint cross section matrices are computed!"<<G4endl; 299 { << 248 G4cout<<"======================================================================"<<G4endl; 300 G4cout << "The model " << aModel->GetNam << 249 301 << " does not use cross section m << 250 CrossSectionMatrixesAreBuilt = true; 302 std::vector<G4AdjointCSMatrix*> two_empt << 251 303 fAdjointCSMatricesForProdToProj.push_bac << 304 fAdjointCSMatricesForScatProjToProj.push << 305 } << 306 } << 307 G4cout << " All adjoint cross s << 308 << G4endl; << 309 G4cout << 310 << "====================================== << 311 << G4endl; << 312 252 313 fCSMatricesBuilt = true; << 314 } 253 } 315 254 >> 255 316 ////////////////////////////////////////////// 256 /////////////////////////////////////////////////////// >> 257 // 317 void G4AdjointCSManager::BuildTotalSigmaTables 258 void G4AdjointCSManager::BuildTotalSigmaTables() 318 { << 259 { if (TotalSigmaTableAreBuilt) return; 319 if(fSigmaTableBuilt) << 320 return; << 321 << 322 const G4ProductionCutsTable* theCoupleTable << 323 G4ProductionCutsTable::GetProductionCutsTa << 324 260 325 // Prepare the Sigma table for all AdjointEM << 261 326 for(std::size_t i = 0; i < fAdjointModels.si << 262 const G4ProductionCutsTable* theCoupleTable= G4ProductionCutsTable::GetProductionCutsTable(); 327 { << 263 328 fSigmaTableForAdjointModelScatProjToProj[i << 264 329 fSigmaTableForAdjointModelProdToProj[i]->c << 265 //Prepare the Sigma table for all AdjointEMModel, will be filled later on 330 for(std::size_t j = 0; j < theCoupleTable- << 266 for (size_t i=0; i<listOfAdjointEMModel.size();i++){ 331 { << 267 listSigmaTableForAdjointModelScatProjToProj[i]->clearAndDestroy(); 332 fSigmaTableForAdjointModelScatProjToProj << 268 listSigmaTableForAdjointModelProdToProj[i]->clearAndDestroy(); 333 new G4PhysicsLogVector(fTmin, fTmax, f << 269 for (size_t j=0;j<theCoupleTable->GetTableSize();j++){ 334 fSigmaTableForAdjointModelProdToProj[i]- << 270 listSigmaTableForAdjointModelScatProjToProj[i]->push_back(new G4PhysicsLogVector(Tmin, Tmax, nbins)); 335 new G4PhysicsLogVector(fTmin, fTmax, f << 271 listSigmaTableForAdjointModelProdToProj[i]->push_back(new G4PhysicsLogVector(Tmin, Tmax, nbins)); 336 } << 272 } 337 } << 273 } 338 << 274 339 for(std::size_t i = 0; i < fAdjointParticles << 275 340 { << 276 341 G4ParticleDefinition* thePartDef = fAdjoin << 277 for (size_t i=0;i<theListOfAdjointParticlesInAction.size();i++){ 342 DefineCurrentParticle(thePartDef); << 278 G4ParticleDefinition* thePartDef = theListOfAdjointParticlesInAction[i]; 343 fTotalFwdSigmaTable[i]->clearAndDestroy(); << 279 DefineCurrentParticle(thePartDef); 344 fTotalAdjSigmaTable[i]->clearAndDestroy(); << 280 theTotalForwardSigmaTableVector[i]->clearAndDestroy(); 345 fEminForFwdSigmaTables[i].clear(); << 281 theTotalAdjointSigmaTableVector[i]->clearAndDestroy(); 346 fEminForAdjSigmaTables[i].clear(); << 282 EminForFwdSigmaTables[i].clear(); 347 fEkinofFwdSigmaMax[i].clear(); << 283 EminForAdjSigmaTables[i].clear(); 348 fEkinofAdjSigmaMax[i].clear(); << 284 EkinofFwdSigmaMax[i].clear(); 349 << 285 EkinofAdjSigmaMax[i].clear(); 350 for(std::size_t j = 0; j < theCoupleTable- << 286 //G4cout<<thePartDef->GetParticleName(); 351 { << 287 352 const G4MaterialCutsCouple* couple = << 288 for (size_t j=0;j<theCoupleTable->GetTableSize();j++){ 353 theCoupleTable->GetMaterialCutsCouple( << 289 const G4MaterialCutsCouple* couple = theCoupleTable->GetMaterialCutsCouple(j); 354 << 290 355 // make first the total fwd CS table for << 291 /* 356 G4PhysicsVector* aVector = new G4Physics << 292 G4String file_name1=couple->GetMaterial()->GetName()+"_"+thePartDef->GetParticleName()+"_adj_totCS.txt"; 357 G4bool Emin_found = false; << 293 G4String file_name2=couple->GetMaterial()->GetName()+"_"+thePartDef->GetParticleName()+"_fwd_totCS.txt"; 358 G4double sigma_max = 0.; << 294 359 G4double e_sigma_max = 0.; << 295 std::fstream FileOutputAdjCS(file_name1, std::ios::out); 360 for(std::size_t l = 0; l < fNbins; ++l) << 296 std::fstream FileOutputFwdCS(file_name2, std::ios::out); 361 { << 297 362 G4double totCS = 0.; << 298 363 G4double e = aVector->Energy(l); << 299 364 for(std::size_t k = 0; k < fForwardPro << 300 FileOutputAdjCS<<std::setiosflags(std::ios::scientific); 365 { << 301 FileOutputAdjCS<<std::setprecision(6); 366 totCS += (*fForwardProcesses[i])[k]- << 302 FileOutputFwdCS<<std::setiosflags(std::ios::scientific); 367 } << 303 FileOutputFwdCS<<std::setprecision(6); 368 for(std::size_t k = 0; k < fForwardLos << 304 */ 369 { << 305 370 if(thePartDef == fAdjIon) << 306 371 { // e is considered already as the << 307 //make first the total fwd CS table for FwdProcess 372 std::size_t mat_index = couple->Ge << 308 G4PhysicsVector* aVector = new G4PhysicsLogVector(Tmin, Tmax, nbins); 373 G4VEmModel* currentModel = << 309 G4bool Emin_found=false; 374 (*fForwardLossProcesses[i])[k]-> << 310 G4double sigma_max =0.; 375 << 311 G4double e_sigma_max =0.; 376 G4double chargeSqRatio = currentMo << 312 for(size_t l=0; l<aVector->GetVectorLength(); l++) { 377 fFwdIon, couple->GetMaterial(), << 313 G4double totCS=0.; 378 (*fForwardLossProcesses[i])[k]->Se << 314 G4double e=aVector->GetLowEdgeEnergy(l); 379 << 315 for (size_t k=0; k<listOfForwardEmProcess[i]->size(); k++){ 380 } << 316 totCS+=(*listOfForwardEmProcess[i])[k]->GetLambda(e, couple); 381 G4double e1 = e / fMassRatio; << 317 } 382 totCS += (*fForwardLossProcesses[i]) << 318 for (size_t k=0; k<listOfForwardEnergyLossProcess[i]->size(); k++){ 383 } << 319 if (thePartDef == theAdjIon) { // e is considered already as the scaled energy 384 aVector->PutValue(l, totCS); << 320 size_t mat_index = couple->GetIndex(); 385 if(totCS > sigma_max) << 321 G4VEmModel* currentModel = (*listOfForwardEnergyLossProcess[i])[k]->SelectModelForMaterial(e,mat_index); 386 { << 322 G4double chargeSqRatio = currentModel->GetChargeSquareRatio(theFwdIon,couple->GetMaterial(),e/massRatio); 387 sigma_max = totCS; << 323 (*listOfForwardEnergyLossProcess[i])[k]->SetDynamicMassCharge(massRatio,chargeSqRatio); 388 e_sigma_max = e; << 324 } 389 } << 325 G4double e1=e/massRatio; 390 if(totCS > 0 && !Emin_found) << 326 totCS+=(*listOfForwardEnergyLossProcess[i])[k]->GetLambda(e1, couple); 391 { << 327 } 392 fEminForFwdSigmaTables[i].push_back( << 328 aVector->PutValue(l,totCS); 393 Emin_found = true; << 329 if (totCS>sigma_max){ 394 } << 330 sigma_max=totCS; 395 } << 331 e_sigma_max = e; 396 << 332 397 fEkinofFwdSigmaMax[i].push_back(e_sigma_ << 333 } 398 << 334 //FileOutputFwdCS<<e<<'\t'<<totCS<<G4endl; 399 if(!Emin_found) << 335 400 fEminForFwdSigmaTables[i].push_back(fT << 336 if (totCS>0 && !Emin_found) { 401 << 337 EminForFwdSigmaTables[i].push_back(e); 402 fTotalFwdSigmaTable[i]->push_back(aVecto << 338 Emin_found=true; 403 << 339 } 404 Emin_found = false; << 340 405 sigma_max = 0; << 341 406 e_sigma_max = 0.; << 342 } 407 G4PhysicsVector* aVector1 = new G4Physic << 343 //FileOutputFwdCS.close(); 408 for(std::size_t eindex = 0; eindex < fNb << 344 409 { << 345 EkinofFwdSigmaMax[i].push_back(e_sigma_max); 410 G4double e = aVector1->Energy(eind << 346 411 G4double totCS = ComputeTotalAdjointCS << 347 412 couple, thePartDef, << 348 if(!Emin_found) EminForFwdSigmaTables[i].push_back(Tmax); 413 e * 0.9999999 / fMassRatio); // fMa << 349 414 aVector1->PutValue(eindex, totCS); << 350 theTotalForwardSigmaTableVector[i]->push_back(aVector); 415 if(totCS > sigma_max) << 351 416 { << 352 417 sigma_max = totCS; << 353 Emin_found=false; 418 e_sigma_max = e; << 354 sigma_max=0; 419 } << 355 e_sigma_max =0.; 420 if(totCS > 0 && !Emin_found) << 356 G4PhysicsVector* aVector1 = new G4PhysicsLogVector(Tmin, Tmax, nbins); 421 { << 357 for(eindex=0; eindex<aVector->GetVectorLength(); eindex++) { 422 fEminForAdjSigmaTables[i].push_back( << 358 G4double e=aVector->GetLowEdgeEnergy(eindex); 423 Emin_found = true; << 359 G4double totCS =ComputeTotalAdjointCS(couple,thePartDef,e*0.9999999/massRatio); //massRatio needed for ions 424 } << 360 aVector1->PutValue(eindex,totCS); 425 } << 361 if (totCS>sigma_max){ 426 fEkinofAdjSigmaMax[i].push_back(e_sigma_ << 362 sigma_max=totCS; 427 if(!Emin_found) << 363 e_sigma_max = e; 428 fEminForAdjSigmaTables[i].push_back(fT << 364 429 << 365 } 430 fTotalAdjSigmaTable[i]->push_back(aVecto << 366 //FileOutputAdjCS<<e<<'\t'<<totCS<<G4endl; 431 } << 367 if (totCS>0 && !Emin_found) { >> 368 EminForAdjSigmaTables[i].push_back(e); >> 369 Emin_found=true; >> 370 } >> 371 >> 372 } >> 373 //FileOutputAdjCS.close(); >> 374 EkinofAdjSigmaMax[i].push_back(e_sigma_max); >> 375 if(!Emin_found) EminForAdjSigmaTables[i].push_back(Tmax); >> 376 >> 377 theTotalAdjointSigmaTableVector[i]->push_back(aVector1); >> 378 >> 379 } 432 } 380 } 433 fSigmaTableBuilt = true; << 381 TotalSigmaTableAreBuilt =true; 434 } << 382 435 << 436 ////////////////////////////////////////////// << 437 G4double G4AdjointCSManager::GetTotalAdjointCS << 438 G4ParticleDefinition* aPartDef, G4double Eki << 439 const G4MaterialCutsCouple* aCouple) << 440 { << 441 DefineCurrentMaterial(aCouple); << 442 DefineCurrentParticle(aPartDef); << 443 return (((*fTotalAdjSigmaTable[fCurrentParti << 444 ->Value(Ekin * fMassRatio)); << 445 } 383 } 446 << 447 ////////////////////////////////////////////// 384 /////////////////////////////////////////////////////// 448 G4double G4AdjointCSManager::GetTotalForwardCS << 385 // 449 G4ParticleDefinition* aPartDef, G4double Eki << 386 G4double G4AdjointCSManager::GetTotalAdjointCS(G4ParticleDefinition* aPartDef, G4double Ekin, 450 const G4MaterialCutsCouple* aCouple) << 387 const G4MaterialCutsCouple* aCouple) 451 { << 388 { DefineCurrentMaterial(aCouple); 452 DefineCurrentMaterial(aCouple); << 389 DefineCurrentParticle(aPartDef); >> 390 G4bool b; >> 391 return (((*theTotalAdjointSigmaTableVector[currentParticleIndex])[currentMatIndex])->GetValue(Ekin*massRatio, b)); >> 392 >> 393 >> 394 >> 395 } >> 396 /////////////////////////////////////////////////////// >> 397 // >> 398 G4double G4AdjointCSManager::GetTotalForwardCS(G4ParticleDefinition* aPartDef, G4double Ekin, >> 399 const G4MaterialCutsCouple* aCouple) >> 400 { DefineCurrentMaterial(aCouple); 453 DefineCurrentParticle(aPartDef); 401 DefineCurrentParticle(aPartDef); 454 return (((*fTotalFwdSigmaTable[fCurrentParti << 402 G4bool b; 455 ->Value(Ekin * fMassRatio)); << 403 return (((*theTotalForwardSigmaTableVector[currentParticleIndex])[currentMatIndex])->GetValue(Ekin*massRatio, b)); >> 404 >> 405 456 } 406 } 457 << 458 ////////////////////////////////////////////// 407 /////////////////////////////////////////////////////// 459 G4double G4AdjointCSManager::GetAdjointSigma( << 408 // 460 G4double Ekin_nuc, std::size_t index_model, << 409 G4double G4AdjointCSManager::GetAdjointSigma(G4double Ekin_nuc, size_t index_model,G4bool is_scat_proj_to_proj, 461 const G4MaterialCutsCouple* aCouple) << 410 const G4MaterialCutsCouple* aCouple) 462 { << 411 { DefineCurrentMaterial(aCouple); 463 DefineCurrentMaterial(aCouple); << 412 G4bool b; 464 if(is_scat_proj_to_proj) << 413 if (is_scat_proj_to_proj) return (((*listSigmaTableForAdjointModelScatProjToProj[index_model])[currentMatIndex])->GetValue(Ekin_nuc, b)); 465 return (((*fSigmaTableForAdjointModelScatP << 414 else return (((*listSigmaTableForAdjointModelProdToProj[index_model])[currentMatIndex])->GetValue(Ekin_nuc, b)); 466 [fCurrentMatIndex])->Value(Ekin << 415 } 467 else << 468 return ( << 469 ((*fSigmaTableForAdjointModelProdToProj[ << 470 ->Value(Ekin_nuc)); << 471 } << 472 << 473 ////////////////////////////////////////////// 416 /////////////////////////////////////////////////////// >> 417 // 474 void G4AdjointCSManager::GetEminForTotalCS(G4P 418 void G4AdjointCSManager::GetEminForTotalCS(G4ParticleDefinition* aPartDef, 475 con << 419 const G4MaterialCutsCouple* aCouple, G4double& emin_adj, G4double& emin_fwd) 476 G4d << 420 { DefineCurrentMaterial(aCouple); 477 G4d << 478 { << 479 DefineCurrentMaterial(aCouple); << 480 DefineCurrentParticle(aPartDef); 421 DefineCurrentParticle(aPartDef); 481 emin_adj = fEminForAdjSigmaTables[fCurrentPa << 422 emin_adj = EminForAdjSigmaTables[currentParticleIndex][currentMatIndex]/massRatio; 482 fMassRatio; << 423 emin_fwd = EminForFwdSigmaTables[currentParticleIndex][currentMatIndex]/massRatio; 483 emin_fwd = fEminForFwdSigmaTables[fCurrentPa << 424 484 fMassRatio; << 425 >> 426 485 } 427 } 486 << 487 ////////////////////////////////////////////// 428 /////////////////////////////////////////////////////// >> 429 // 488 void G4AdjointCSManager::GetMaxFwdTotalCS(G4Pa 430 void G4AdjointCSManager::GetMaxFwdTotalCS(G4ParticleDefinition* aPartDef, 489 cons << 431 const G4MaterialCutsCouple* aCouple, G4double& e_sigma_max, G4double& sigma_max) 490 G4do << 432 { DefineCurrentMaterial(aCouple); 491 G4do << 492 { << 493 DefineCurrentMaterial(aCouple); << 494 DefineCurrentParticle(aPartDef); 433 DefineCurrentParticle(aPartDef); 495 e_sigma_max = fEkinofFwdSigmaMax[fCurrentPar << 434 e_sigma_max = EkinofFwdSigmaMax[currentParticleIndex][currentMatIndex]; 496 sigma_max = ((*fTotalFwdSigmaTable[fCurrentP << 435 G4bool b; 497 ->Value(e_sigma_max); << 436 sigma_max =((*theTotalForwardSigmaTableVector[currentParticleIndex])[currentMatIndex])->GetValue(e_sigma_max, b); 498 e_sigma_max /= fMassRatio; << 437 e_sigma_max/=massRatio; >> 438 >> 439 499 } 440 } 500 << 501 ////////////////////////////////////////////// 441 /////////////////////////////////////////////////////// >> 442 // 502 void G4AdjointCSManager::GetMaxAdjTotalCS(G4Pa 443 void G4AdjointCSManager::GetMaxAdjTotalCS(G4ParticleDefinition* aPartDef, 503 cons << 444 const G4MaterialCutsCouple* aCouple, G4double& e_sigma_max, G4double& sigma_max) 504 G4do << 445 { DefineCurrentMaterial(aCouple); 505 G4do << 506 { << 507 DefineCurrentMaterial(aCouple); << 508 DefineCurrentParticle(aPartDef); 446 DefineCurrentParticle(aPartDef); 509 e_sigma_max = fEkinofAdjSigmaMax[fCurrentPar << 447 e_sigma_max = EkinofAdjSigmaMax[currentParticleIndex][currentMatIndex]; 510 sigma_max = ((*fTotalAdjSigmaTable[fCurrentP << 448 G4bool b; 511 ->Value(e_sigma_max); << 449 sigma_max =((*theTotalAdjointSigmaTableVector[currentParticleIndex])[currentMatIndex])->GetValue(e_sigma_max, b); 512 e_sigma_max /= fMassRatio; << 450 e_sigma_max/=massRatio; 513 } << 451 514 << 452 515 ////////////////////////////////////////////// << 453 } 516 G4double G4AdjointCSManager::GetCrossSectionCo << 454 /////////////////////////////////////////////////////// 517 G4ParticleDefinition* aPartDef, G4double Pre << 455 // 518 const G4MaterialCutsCouple* aCouple, G4bool& << 456 G4double G4AdjointCSManager::GetCrossSectionCorrection(G4ParticleDefinition* aPartDef,G4double PreStepEkin,const G4MaterialCutsCouple* aCouple, G4bool& fwd_is_used, 519 { << 457 G4double& fwd_TotCS) 520 static G4double lastEkin = 0.; << 458 { G4double corr_fac = 1.; 521 static G4ParticleDefinition* lastPartDef; << 459 if (forward_CS_mode) { 522 << 460 fwd_TotCS=PrefwdCS; 523 G4double corr_fac = 1.; << 461 if (LastEkinForCS != PreStepEkin || aPartDef != lastPartDefForCS || aCouple!=currentCouple) { 524 if(fForwardCSMode && aPartDef) << 462 DefineCurrentMaterial(aCouple); 525 { << 463 PreadjCS = GetTotalAdjointCS(aPartDef, PreStepEkin,aCouple); 526 if(lastEkin != PreStepEkin || aPartDef != << 464 PrefwdCS = GetTotalForwardCS(aPartDef, PreStepEkin,aCouple); 527 aCouple != fCurrentCouple) << 465 LastEkinForCS = PreStepEkin; 528 { << 466 lastPartDefForCS = aPartDef; 529 DefineCurrentMaterial(aCouple); << 467 if (PrefwdCS >0. && PreadjCS >0.) { 530 G4double preadjCS = GetTotalAdjointCS(aP << 468 forward_CS_is_used = true; 531 G4double prefwdCS = GetTotalForwardCS(aP << 469 LastCSCorrectionFactor = PrefwdCS/PreadjCS; 532 lastEkin = PreStepEkin; << 470 } 533 lastPartDef = aPartDef; << 471 else { 534 if(prefwdCS > 0. && preadjCS > 0.) << 472 forward_CS_is_used = false; 535 { << 473 LastCSCorrectionFactor = 1.; 536 fForwardCSUsed = true; << 474 537 fLastCSCorrectionFactor = prefwdCS / p << 475 } 538 } << 476 539 else << 477 } 540 { << 478 corr_fac =LastCSCorrectionFactor; 541 fForwardCSUsed = false; << 479 542 fLastCSCorrectionFactor = 1.; << 480 543 } << 481 544 } << 482 } 545 corr_fac = fLastCSCorrectionFactor; << 483 else { 546 } << 484 forward_CS_is_used = false; 547 else << 485 LastCSCorrectionFactor = 1.; 548 { << 486 } 549 fForwardCSUsed = false; << 487 fwd_TotCS=PrefwdCS; 550 fLastCSCorrectionFactor = 1.; << 488 fwd_is_used = forward_CS_is_used; 551 } << 489 return corr_fac; 552 fwd_is_used = fForwardCSUsed; << 490 } 553 return corr_fac; << 491 /////////////////////////////////////////////////////// 554 } << 492 // 555 << 493 G4double G4AdjointCSManager::GetContinuousWeightCorrection(G4ParticleDefinition* aPartDef, G4double PreStepEkin,G4double AfterStepEkin, 556 ////////////////////////////////////////////// << 494 const G4MaterialCutsCouple* aCouple, G4double step_length) 557 G4double G4AdjointCSManager::GetContinuousWeig << 495 { G4double corr_fac = 1.; 558 G4ParticleDefinition* aPartDef, G4double Pre << 496 //return corr_fac; 559 const G4MaterialCutsCouple* aCouple, G4doubl << 497 //G4double after_adjCS = GetTotalAdjointCS(aPartDef, AfterStepEkin,aCouple); 560 { << 498 G4double after_fwdCS = GetTotalForwardCS(aPartDef, AfterStepEkin,aCouple); 561 G4double corr_fac = 1.; << 499 G4double pre_adjCS = GetTotalAdjointCS(aPartDef, PreStepEkin,aCouple); 562 G4double after_fwdCS = GetTotalForwardCS(aPa << 500 if (!forward_CS_is_used || pre_adjCS ==0. || after_fwdCS==0.) { 563 G4double pre_adjCS = GetTotalAdjointCS(aPa << 501 forward_CS_is_used=false; 564 if(!fForwardCSUsed || pre_adjCS == 0. || aft << 502 G4double pre_fwdCS = GetTotalForwardCS(aPartDef, PreStepEkin,aCouple); 565 { << 503 corr_fac *=std::exp((pre_adjCS-pre_fwdCS)*step_length); 566 G4double pre_fwdCS = GetTotalForwardCS(aPa << 504 LastCSCorrectionFactor = 1.; 567 corr_fac *= std::exp((pre_adjCS - pre_fwdC << 505 } 568 fLastCSCorrectionFactor = 1.; << 506 else { 569 } << 507 LastCSCorrectionFactor = after_fwdCS/pre_adjCS; 570 else << 508 } 571 { << 509 572 fLastCSCorrectionFactor = after_fwdCS / pr << 573 } << 574 return corr_fac; << 575 } << 576 510 >> 511 >> 512 return corr_fac; >> 513 } 577 ////////////////////////////////////////////// 514 /////////////////////////////////////////////////////// 578 G4double G4AdjointCSManager::GetPostStepWeight << 515 // 579 { << 516 G4double G4AdjointCSManager::GetPostStepWeightCorrection( ) 580 return 1. / fLastCSCorrectionFactor; << 517 {//return 1.; 581 } << 518 return 1./LastCSCorrectionFactor; 582 << 519 >> 520 } 583 ////////////////////////////////////////////// 521 /////////////////////////////////////////////////////// 584 G4double G4AdjointCSManager::ComputeAdjointCS( << 522 // 585 G4Material* aMaterial, G4VEmAdjointModel* aM << 523 G4double G4AdjointCSManager::ComputeAdjointCS(G4Material* aMaterial, 586 G4double Tcut, G4bool isScatProjToProj, std: << 524 G4VEmAdjointModel* aModel, 587 { << 525 G4double PrimEnergy, 588 G4double EminSec = 0.; << 526 G4double Tcut, 589 G4double EmaxSec = 0.; << 527 G4bool IsScatProjToProjCase, 590 << 528 std::vector<G4double>& CS_Vs_Element) 591 static G4double lastPrimaryEnergy = 0.; << 529 { 592 static G4double lastTcut = 0.; << 530 593 static G4Material* lastMaterial = nullptr; << 531 G4double EminSec=0; 594 << 532 G4double EmaxSec=0; 595 if(isScatProjToProj) << 533 596 { << 534 if (IsScatProjToProjCase){ 597 EminSec = aModel->GetSecondAdjEnergyMinFor << 535 EminSec= aModel->GetSecondAdjEnergyMinForScatProjToProjCase(PrimEnergy,Tcut); 598 EmaxSec = aModel->GetSecondAdjEnergyMaxFor << 536 EmaxSec= aModel->GetSecondAdjEnergyMaxForScatProjToProjCase(PrimEnergy); 599 } << 537 } 600 else if(PrimEnergy > Tcut || !aModel->GetApp << 538 else if (PrimEnergy > Tcut || !aModel->GetApplyCutInRange()) { 601 { << 539 EminSec= aModel->GetSecondAdjEnergyMinForProdToProjCase(PrimEnergy); 602 EminSec = aModel->GetSecondAdjEnergyMinFor << 540 EmaxSec= aModel->GetSecondAdjEnergyMaxForProdToProjCase(PrimEnergy); 603 EmaxSec = aModel->GetSecondAdjEnergyMaxFor << 541 } 604 } << 542 if (EminSec >= EmaxSec) return 0.; 605 if(EminSec >= EmaxSec) << 543 606 return 0.; << 544 607 << 545 G4bool need_to_compute=false; 608 G4bool need_to_compute = false; << 546 if ( aMaterial!= lastMaterial || PrimEnergy != lastPrimaryEnergy || Tcut != lastTcut){ 609 if(aMaterial != lastMaterial || PrimEnergy ! << 547 lastMaterial =aMaterial; 610 Tcut != lastTcut) << 548 lastPrimaryEnergy = PrimEnergy; 611 { << 549 lastTcut=Tcut; 612 lastMaterial = aMaterial; << 550 listOfIndexOfAdjointEMModelInAction.clear(); 613 lastPrimaryEnergy = PrimEnergy; << 551 listOfIsScatProjToProjCase.clear(); 614 lastTcut = Tcut; << 552 lastAdjointCSVsModelsAndElements.clear(); 615 fIndexOfAdjointEMModelInAction.clear(); << 553 need_to_compute=true; 616 fIsScatProjToProj.clear(); << 554 617 fLastAdjointCSVsModelsAndElements.clear(); << 555 } 618 need_to_compute = true; << 556 size_t ind=0; 619 } << 557 if (!need_to_compute){ 620 << 558 need_to_compute=true; 621 std::size_t ind = 0; << 559 for (size_t i=0;i<listOfIndexOfAdjointEMModelInAction.size();i++){ 622 if(!need_to_compute) << 560 size_t ind1=listOfIndexOfAdjointEMModelInAction[i]; 623 { << 561 if (aModel == listOfAdjointEMModel[ind1] && IsScatProjToProjCase == listOfIsScatProjToProjCase[i]){ 624 need_to_compute = true; << 562 need_to_compute=false; 625 for(std::size_t i = 0; i < fIndexOfAdjoint << 563 CS_Vs_Element = lastAdjointCSVsModelsAndElements[ind]; 626 { << 564 } 627 std::size_t ind1 = fIndexOfAdjointEMMode << 565 ind++; 628 if(aModel == fAdjointModels[ind1] && << 566 } 629 isScatProjToProj == fIsScatProjToProj << 567 } 630 { << 568 631 need_to_compute = false; << 569 if (need_to_compute){ 632 CS_Vs_Element = fLastAdjointCSVsMode << 570 size_t ind_model=0; 633 } << 571 for (size_t i=0;i<listOfAdjointEMModel.size();i++){ 634 ++ind; << 572 if (aModel == listOfAdjointEMModel[i]){ 635 } << 573 ind_model=i; 636 } << 574 break; 637 << 575 } 638 if(need_to_compute) << 576 } 639 { << 577 G4double Tlow=Tcut; 640 std::size_t ind_model = 0; << 578 if (!listOfAdjointEMModel[ind_model]->GetApplyCutInRange()) Tlow =listOfAdjointEMModel[ind_model]->GetLowEnergyLimit(); 641 for(std::size_t i = 0; i < fAdjointModels. << 579 listOfIndexOfAdjointEMModelInAction.push_back(ind_model); 642 { << 580 listOfIsScatProjToProjCase.push_back(IsScatProjToProjCase); 643 if(aModel == fAdjointModels[i]) << 581 CS_Vs_Element.clear(); 644 { << 582 if (!aModel->GetUseMatrix()){ 645 ind_model = i; << 583 CS_Vs_Element.push_back(aModel->AdjointCrossSection(currentCouple,PrimEnergy,IsScatProjToProjCase)); 646 break; << 584 647 } << 585 648 } << 586 } 649 G4double Tlow = Tcut; << 587 else if (aModel->GetUseMatrixPerElement()){ 650 if(!fAdjointModels[ind_model]->GetApplyCut << 588 size_t n_el = aMaterial->GetNumberOfElements(); 651 Tlow = fAdjointModels[ind_model]->GetLow << 589 if (aModel->GetUseOnlyOneMatrixForAllElements()){ 652 fIndexOfAdjointEMModelInAction.push_back(i << 590 G4AdjointCSMatrix* theCSMatrix; 653 fIsScatProjToProj.push_back(isScatProjToPr << 591 if (IsScatProjToProjCase){ 654 CS_Vs_Element.clear(); << 592 theCSMatrix=theAdjointCSMatricesForScatProjToProj[ind_model][0]; 655 if(!aModel->GetUseMatrix()) << 593 } 656 { << 594 else theCSMatrix=theAdjointCSMatricesForProdToProj[ind_model][0]; 657 CS_Vs_Element.push_back(aModel->AdjointC << 595 G4double CS =0.; 658 fCurrentCouple, PrimEnergy, isScatProj << 596 if (PrimEnergy > Tlow) 659 } << 597 CS = ComputeAdjointCS(PrimEnergy,theCSMatrix,Tlow); 660 else if(aModel->GetUseMatrixPerElement()) << 598 G4double factor=0.; 661 { << 599 for (size_t i=0;i<n_el;i++){ //this could be computed only once 662 std::size_t n_el = aMaterial->GetNumberO << 600 //size_t ind_el = aMaterial->GetElement(i)->GetIndex(); 663 if(aModel->GetUseOnlyOneMatrixForAllElem << 601 factor+=aMaterial->GetElement(i)->GetZ()*aMaterial->GetVecNbOfAtomsPerVolume()[i]; 664 { << 602 } 665 G4AdjointCSMatrix* theCSMatrix; << 603 CS *=factor; 666 if(isScatProjToProj) << 604 CS_Vs_Element.push_back(CS); 667 { << 605 668 theCSMatrix = fAdjointCSMatricesForS << 606 } 669 } << 607 else { 670 else << 608 for (size_t i=0;i<n_el;i++){ 671 theCSMatrix = fAdjointCSMatricesForP << 609 size_t ind_el = aMaterial->GetElement(i)->GetIndex(); 672 G4double CS = 0.; << 610 //G4cout<<aMaterial->GetName()<<G4endl; 673 if(PrimEnergy > Tlow) << 611 G4AdjointCSMatrix* theCSMatrix; 674 CS = ComputeAdjointCS(PrimEnergy, th << 612 if (IsScatProjToProjCase){ 675 G4double factor = 0.; << 613 theCSMatrix=theAdjointCSMatricesForScatProjToProj[ind_model][ind_el]; 676 for(G4int i = 0; i < (G4int)n_el; ++i) << 614 } 677 { // this could be computed only once << 615 else theCSMatrix=theAdjointCSMatricesForProdToProj[ind_model][ind_el]; 678 factor += aMaterial->GetElement(i)-> << 616 G4double CS =0.; 679 aMaterial->GetVecNbOfAtoms << 617 if (PrimEnergy > Tlow) 680 } << 618 CS = ComputeAdjointCS(PrimEnergy,theCSMatrix,Tlow); 681 CS *= factor; << 619 //G4cout<<CS<<G4endl; 682 CS_Vs_Element.push_back(CS); << 620 CS_Vs_Element.push_back(CS*(aMaterial->GetVecNbOfAtomsPerVolume()[i])); 683 } << 621 } 684 else << 622 } 685 { << 623 686 for(G4int i = 0; i < (G4int)n_el; ++i) << 624 } 687 { << 625 else { 688 std::size_t ind_el = aMaterial->GetE << 626 size_t ind_mat = aMaterial->GetIndex(); 689 G4AdjointCSMatrix* theCSMatrix; << 627 G4AdjointCSMatrix* theCSMatrix; 690 if(isScatProjToProj) << 628 if (IsScatProjToProjCase){ 691 { << 629 theCSMatrix=theAdjointCSMatricesForScatProjToProj[ind_model][ind_mat]; 692 theCSMatrix = << 630 } 693 fAdjointCSMatricesForScatProjToP << 631 else theCSMatrix=theAdjointCSMatricesForProdToProj[ind_model][ind_mat]; 694 } << 632 G4double CS =0.; 695 else << 633 if (PrimEnergy > Tlow) 696 theCSMatrix = fAdjointCSMatricesFo << 634 CS = ComputeAdjointCS(PrimEnergy,theCSMatrix,Tlow); 697 G4double CS = 0.; << 635 CS_Vs_Element.push_back(CS); 698 if(PrimEnergy > Tlow) << 636 699 CS = ComputeAdjointCS(PrimEnergy, << 637 700 CS_Vs_Element.push_back(CS * << 638 } 701 (aMaterial-> << 639 lastAdjointCSVsModelsAndElements.push_back(CS_Vs_Element); 702 } << 640 703 } << 641 } 704 } << 642 705 else << 643 706 { << 644 G4double CS=0; 707 std::size_t ind_mat = aMaterial->GetInde << 645 for (size_t i=0;i<CS_Vs_Element.size();i++){ 708 G4AdjointCSMatrix* theCSMatrix; << 646 CS+=CS_Vs_Element[i]; //We could put the progressive sum of the CS instead of the CS of an element itself 709 if(isScatProjToProj) << 647 710 { << 711 theCSMatrix = fAdjointCSMatricesForSca << 712 } << 713 else << 714 theCSMatrix = fAdjointCSMatricesForPro << 715 G4double CS = 0.; << 716 if(PrimEnergy > Tlow) << 717 CS = ComputeAdjointCS(PrimEnergy, theC << 718 CS_Vs_Element.push_back(CS); << 719 } << 720 fLastAdjointCSVsModelsAndElements.push_bac << 721 } << 722 << 723 G4double CS = 0.; << 724 for(const auto& cs_vs_el : CS_Vs_Element) << 725 { << 726 // We could put the progressive sum of the << 727 // element itself << 728 CS += cs_vs_el; << 729 } 648 } 730 return CS; 649 return CS; 731 } << 650 } 732 << 733 ////////////////////////////////////////////// 651 /////////////////////////////////////////////////////// 734 G4Element* G4AdjointCSManager::SampleElementFr << 652 // 735 G4Material* aMaterial, G4VEmAdjointModel* aM << 653 G4Element* G4AdjointCSManager::SampleElementFromCSMatrices(G4Material* aMaterial, 736 G4double Tcut, G4bool isScatProjToProj) << 654 G4VEmAdjointModel* aModel, 737 { << 655 G4double PrimEnergy, 738 std::vector<G4double> CS_Vs_Element; << 656 G4double Tcut, 739 G4double CS = ComputeAdjointCS(aMaterial, << 657 G4bool IsScatProjToProjCase) 740 isScatProjToP << 658 { std::vector<G4double> CS_Vs_Element; 741 G4double SumCS = 0.; << 659 G4double CS = ComputeAdjointCS(aMaterial,aModel,PrimEnergy,Tcut,IsScatProjToProjCase,CS_Vs_Element); 742 std::size_t ind = 0; << 660 G4double rand_var= G4UniformRand(); 743 for(std::size_t i = 0; i < CS_Vs_Element.siz << 661 G4double SumCS=0.; 744 { << 662 size_t ind=0; 745 SumCS += CS_Vs_Element[i]; << 663 for (size_t i=0;i<CS_Vs_Element.size();i++){ 746 if(G4UniformRand() <= SumCS / CS) << 664 SumCS+=CS_Vs_Element[i]; 747 { << 665 if (rand_var<=SumCS/CS){ 748 ind = i; << 666 ind=i; 749 break; << 667 break; 750 } << 668 } 751 } 669 } 752 << 670 753 return const_cast<G4Element*>(aMaterial->Get << 671 return const_cast<G4Element*>(aMaterial->GetElement(ind)); 754 } << 672 755 << 673 >> 674 >> 675 } 756 ////////////////////////////////////////////// 676 /////////////////////////////////////////////////////// 757 G4double G4AdjointCSManager::ComputeTotalAdjoi << 677 // 758 const G4MaterialCutsCouple* aCouple, G4Parti << 678 G4double G4AdjointCSManager::ComputeTotalAdjointCS(const G4MaterialCutsCouple* aCouple, 759 G4double Ekin) << 679 G4ParticleDefinition* aPartDef, 760 { << 680 G4double Ekin) 761 G4double TotalCS = 0.; << 681 { 762 << 682 G4double TotalCS=0.; 763 DefineCurrentMaterial(aCouple); << 683 764 << 684 DefineCurrentMaterial(aCouple); 765 std::vector<G4double> CS_Vs_Element; << 685 766 G4double CS; << 686 767 G4VEmAdjointModel* adjModel = nullptr; << 687 std::vector<G4double> CS_Vs_Element; 768 for(std::size_t i = 0; i < fAdjointModels.si << 688 G4double CS; 769 { << 689 for (size_t i=0; i<listOfAdjointEMModel.size();i++){ 770 G4double Tlow = 0.; << 690 771 adjModel = fAdjointModels[i]; << 691 G4double Tlow=0; 772 if(!adjModel->GetApplyCutInRange()) << 692 if (!listOfAdjointEMModel[i]->GetApplyCutInRange()) Tlow =listOfAdjointEMModel[i]->GetLowEnergyLimit(); 773 Tlow = adjModel->GetLowEnergyLimit(); << 693 else { 774 else << 694 G4ParticleDefinition* theDirSecondPartDef = 775 { << 695 GetForwardParticleEquivalent(listOfAdjointEMModel[i]->GetAdjointEquivalentOfDirectSecondaryParticleDefinition()); 776 G4ParticleDefinition* theDirSecondPartDe << 696 size_t idx=56; 777 adjModel->GetAdjointEquivalentOfDirect << 697 if (theDirSecondPartDef->GetParticleName() == "gamma") idx = 0; 778 std::size_t idx = 56; << 698 else if (theDirSecondPartDef->GetParticleName() == "e-") idx = 1; 779 if(theDirSecondPartDef->GetParticleName( << 699 else if (theDirSecondPartDef->GetParticleName() == "e+") idx = 2; 780 idx = 0; << 700 if (idx <56) { 781 else if(theDirSecondPartDef->GetParticle << 701 const std::vector<G4double>* aVec = G4ProductionCutsTable::GetProductionCutsTable()->GetEnergyCutsVector(idx); 782 idx = 1; << 702 Tlow =(*aVec)[aCouple->GetIndex()]; 783 else if(theDirSecondPartDef->GetParticle << 703 } 784 idx = 2; << 704 785 if(idx < 56) << 705 786 { << 706 } 787 const std::vector<G4double>* aVec = << 707 if ( Ekin<=listOfAdjointEMModel[i]->GetHighEnergyLimit() && Ekin>=listOfAdjointEMModel[i]->GetLowEnergyLimit()){ 788 G4ProductionCutsTable::GetProduction << 708 if (aPartDef == listOfAdjointEMModel[i]->GetAdjointEquivalentOfDirectPrimaryParticleDefinition()){ 789 idx); << 709 CS=ComputeAdjointCS(currentMaterial, 790 Tlow = (*aVec)[aCouple->GetIndex()]; << 710 listOfAdjointEMModel[i], 791 } << 711 Ekin, Tlow,true,CS_Vs_Element); 792 } << 712 TotalCS += CS; 793 if(Ekin <= adjModel->GetHighEnergyLimit() << 713 (*listSigmaTableForAdjointModelScatProjToProj[i])[currentMatIndex]->PutValue(eindex,CS); 794 Ekin >= adjModel->GetLowEnergyLimit()) << 714 } 795 { << 715 if (aPartDef == listOfAdjointEMModel[i]->GetAdjointEquivalentOfDirectSecondaryParticleDefinition()){ 796 if(aPartDef == << 716 CS = ComputeAdjointCS(currentMaterial, 797 adjModel->GetAdjointEquivalentOfDirec << 717 listOfAdjointEMModel[i], 798 { << 718 Ekin, Tlow,false, CS_Vs_Element); 799 CS = ComputeAdjointCS(fCurrentMaterial << 719 TotalCS += CS; 800 CS_Vs_Element); << 720 (*listSigmaTableForAdjointModelProdToProj[i])[currentMatIndex]->PutValue(eindex,CS); 801 TotalCS += CS; << 721 } 802 (*fSigmaTableForAdjointModelScatProjTo << 722 803 ->PutValue(fNbins, CS); << 723 } 804 } << 724 else { 805 if(aPartDef == << 725 (*listSigmaTableForAdjointModelScatProjToProj[i])[currentMatIndex]->PutValue(eindex,0.); 806 adjModel->GetAdjointEquivalentOfDirec << 726 (*listSigmaTableForAdjointModelProdToProj[i])[currentMatIndex]->PutValue(eindex,0.); 807 { << 727 808 CS = ComputeAdjointCS(fCurrentMaterial << 728 } 809 CS_Vs_Element); << 729 } 810 TotalCS += CS; << 730 return TotalCS; 811 (*fSigmaTableForAdjointModelProdToProj << 731 812 fNbins, CS); << 732 813 } << 733 } 814 } << 815 else << 816 { << 817 (*fSigmaTableForAdjointModelScatProjToPr << 818 ->PutValue(fNbins, 0.); << 819 (*fSigmaTableForAdjointModelProdToProj[i << 820 fNbins, 0.); << 821 } << 822 } << 823 return TotalCS; << 824 } << 825 << 826 ////////////////////////////////////////////// 734 /////////////////////////////////////////////////////// >> 735 // 827 std::vector<G4AdjointCSMatrix*> 736 std::vector<G4AdjointCSMatrix*> 828 G4AdjointCSManager::BuildCrossSectionsModelAnd << 737 G4AdjointCSManager::BuildCrossSectionsMatricesForAGivenModelAndElement(G4VEmAdjointModel* aModel,G4int Z,G4int A, 829 << 738 G4int nbin_pro_decade) 830 << 739 { 831 { << 740 G4AdjointCSMatrix* theCSMatForProdToProjBackwardScattering = new G4AdjointCSMatrix(false); 832 G4AdjointCSMatrix* theCSMatForProdToProjBack << 741 G4AdjointCSMatrix* theCSMatForScatProjToProjBackwardScattering = new G4AdjointCSMatrix(true); 833 new G4AdjointCSMatrix(false); << 742 834 G4AdjointCSMatrix* theCSMatForScatProjToProj << 743 835 new G4AdjointCSMatrix(true); << 744 //make the vector of primary energy of the adjoint particle, could try to make this just once ? 836 << 745 837 // make the vector of primary energy of the << 746 G4double EkinMin =aModel->GetLowEnergyLimit(); 838 G4double EkinMin = aModel->GetLowEner << 747 G4double EkinMaxForScat =aModel->GetHighEnergyLimit()*0.999; 839 G4double EkinMaxForScat = aModel->GetHighEne << 748 G4double EkinMaxForProd =aModel->GetHighEnergyLimit()*0.999; 840 G4double EkinMaxForProd = aModel->GetHighEne << 749 if (aModel->GetSecondPartOfSameType() )EkinMaxForProd =EkinMaxForProd/2.; 841 if(aModel->GetSecondPartOfSameType()) << 750 842 EkinMaxForProd = EkinMaxForProd / 2.; << 751 843 << 752 //Product to projectile backward scattering 844 // Product to projectile backward scattering << 753 //----------------------------------------- 845 G4double dE = std::pow(10., 1. / nbin_pro_de << 754 G4double fE=std::pow(10.,1./nbin_pro_decade); 846 G4double E2 = << 755 G4double E2=std::pow(10.,double( int(std::log10(EkinMin)*nbin_pro_decade)+1)/nbin_pro_decade)/fE; 847 std::pow(10., double(int(std::log10(EkinMi << 756 G4double E1=EkinMin; 848 nbin_pro_decade) / dE; << 757 while (E1 <EkinMaxForProd){ 849 G4double E1 = EkinMin; << 758 E1=std::max(EkinMin,E2); 850 // Loop checking, 07-Aug-2015, Vladimir Ivan << 759 E1=std::min(EkinMaxForProd,E1); 851 while(E1 < EkinMaxForProd) << 760 std::vector< std::vector< double>* > aMat= aModel->ComputeAdjointCrossSectionVectorPerAtomForSecond(E1,Z,A,nbin_pro_decade); 852 { << 761 if (aMat.size()>=2) { 853 E1 = std::max(EkinMin, E2); << 762 std::vector< double>* log_ESecVec=aMat[0]; 854 E1 = std::min(EkinMaxForProd, E1); << 763 std::vector< double>* log_CSVec=aMat[1]; 855 std::vector<std::vector<double>*> aMat = << 764 G4double log_adjointCS=log_CSVec->back(); 856 aModel->ComputeAdjointCrossSectionVector << 765 //normalise CSVec such that it becomes a probability vector 857 << 766 for (size_t j=0;j<log_CSVec->size();j++) { 858 if(aMat.size() >= 2) << 767 if (j==0) (*log_CSVec)[j] = 0.; 859 { << 768 else (*log_CSVec)[j]=std::log(1.-std::exp((*log_CSVec)[j]-log_adjointCS) +1e-50); 860 std::vector<double>* log_ESecVec = aMat[ << 769 } 861 std::vector<double>* log_CSVec = aMat[ << 770 (*log_CSVec)[log_CSVec->size()-1]=(*log_CSVec)[log_CSVec->size()-2]-std::log(1000.); 862 G4double log_adjointCS = log_C << 771 theCSMatForProdToProjBackwardScattering->AddData(std::log(E1),log_adjointCS,log_ESecVec,log_CSVec,0); 863 // normalise CSVec such that it becomes << 772 } 864 for(std::size_t j = 0; j < log_CSVec->si << 773 E1=E2; 865 { << 774 E2*=fE; 866 if(j == 0) << 775 } 867 (*log_CSVec)[j] = 0.; << 776 868 else << 777 //Scattered projectile to projectile backward scattering 869 (*log_CSVec)[j] = << 778 //----------------------------------------- 870 std::log(1. - std::exp((*log_CSVec << 779 871 } << 780 E2=std::pow(10.,double( int(std::log10(EkinMin)*nbin_pro_decade)+1)/nbin_pro_decade)/fE; 872 (*log_CSVec)[log_CSVec->size() - 1] = << 781 E1=EkinMin; 873 (*log_CSVec)[log_CSVec->size() - 2] - << 782 while (E1 <EkinMaxForScat){ 874 theCSMatForProdToProjBackwardScattering- << 783 E1=std::max(EkinMin,E2); 875 std::log(E1), log_adjointCS, log_ESecV << 784 E1=std::min(EkinMaxForScat,E1); 876 } << 785 std::vector< std::vector< double>* > aMat= aModel->ComputeAdjointCrossSectionVectorPerAtomForScatProj(E1,Z,A,nbin_pro_decade); 877 E1 = E2; << 786 if (aMat.size()>=2) { 878 E2 *= dE; << 787 std::vector< double>* log_ESecVec=aMat[0]; 879 } << 788 std::vector< double>* log_CSVec=aMat[1]; 880 << 789 G4double log_adjointCS=log_CSVec->back(); 881 // Scattered projectile to projectile backwa << 790 //normalise CSVec such that it becomes a probability vector 882 E2 = std::pow(10., G4double(int(std::log10(E << 791 for (size_t j=0;j<log_CSVec->size();j++) { 883 nbin_pro_decade) / dE; << 792 if (j==0) (*log_CSVec)[j] = 0.; 884 E1 = EkinMin; << 793 else (*log_CSVec)[j]=std::log(1.-std::exp((*log_CSVec)[j]-log_adjointCS)+1e-50); 885 // Loop checking, 07-Aug-2015, Vladimir Ivan << 794 } 886 while(E1 < EkinMaxForScat) << 795 (*log_CSVec)[log_CSVec->size()-1]=(*log_CSVec)[log_CSVec->size()-2]-std::log(1000.); 887 { << 796 theCSMatForScatProjToProjBackwardScattering->AddData(std::log(E1),log_adjointCS,log_ESecVec,log_CSVec,0); 888 E1 = std::max(EkinMin, E2); << 797 } 889 E1 = std::min(EkinMaxForScat, E1); << 798 E1=E2; 890 std::vector<std::vector<G4double>*> aMat = << 799 E2*=fE; 891 aModel->ComputeAdjointCrossSectionVector << 800 } 892 E1, Z, A, nbin_pro_decade); << 801 893 if(aMat.size() >= 2) << 802 894 { << 895 std::vector<G4double>* log_ESecVec = aMa << 896 std::vector<G4double>* log_CSVec = aMa << 897 G4double log_adjointCS = log << 898 // normalise CSVec such that it becomes << 899 for(std::size_t j = 0; j < log_CSVec->si << 900 { << 901 if(j == 0) << 902 (*log_CSVec)[j] = 0.; << 903 else << 904 (*log_CSVec)[j] = << 905 std::log(1. - std::exp((*log_CSVec << 906 } << 907 (*log_CSVec)[log_CSVec->size() - 1] = << 908 (*log_CSVec)[log_CSVec->size() - 2] - << 909 theCSMatForScatProjToProjBackwardScatter << 910 std::log(E1), log_adjointCS, log_ESecV << 911 } << 912 E1 = E2; << 913 E2 *= dE; << 914 } << 915 << 916 std::vector<G4AdjointCSMatrix*> res; 803 std::vector<G4AdjointCSMatrix*> res; >> 804 res.clear(); 917 res.push_back(theCSMatForProdToProjBackwardS 805 res.push_back(theCSMatForProdToProjBackwardScattering); 918 res.push_back(theCSMatForScatProjToProjBackw 806 res.push_back(theCSMatForScatProjToProjBackwardScattering); >> 807 919 808 >> 809 /* >> 810 G4String file_name; >> 811 std::stringstream astream; >> 812 G4String str_Z; >> 813 astream<<Z; >> 814 astream>>str_Z; >> 815 theCSMatForProdToProjBackwardScattering->Write(aModel->GetName()+G4String("_CSMat_Z")+str_Z+"_ProdToProj.txt"); >> 816 theCSMatForScatProjToProjBackwardScattering->Write(aModel->GetName()+G4String("_CSMat_Z")+str_Z+"_ScatProjToProj.txt"); >> 817 >> 818 */ >> 819 >> 820 920 return res; 821 return res; >> 822 >> 823 921 } 824 } 922 << 923 ////////////////////////////////////////////// 825 /////////////////////////////////////////////////////// >> 826 // 924 std::vector<G4AdjointCSMatrix*> 827 std::vector<G4AdjointCSMatrix*> 925 G4AdjointCSManager::BuildCrossSectionsModelAnd << 828 G4AdjointCSManager::BuildCrossSectionsMatricesForAGivenModelAndMaterial(G4VEmAdjointModel* aModel, 926 G4VEmAdjointModel* aModel, G4Material* aMate << 829 G4Material* aMaterial, 927 { << 830 G4int nbin_pro_decade) 928 G4AdjointCSMatrix* theCSMatForProdToProjBack << 831 { 929 new G4AdjointCSMatrix(false); << 832 G4AdjointCSMatrix* theCSMatForProdToProjBackwardScattering = new G4AdjointCSMatrix(false); 930 G4AdjointCSMatrix* theCSMatForScatProjToProj << 833 G4AdjointCSMatrix* theCSMatForScatProjToProjBackwardScattering = new G4AdjointCSMatrix(true); 931 new G4AdjointCSMatrix(true); << 834 932 << 835 933 G4double EkinMin = aModel->GetLowEner << 836 //make the vector of primary energy of the adjoint particle, could try to make this just once ? 934 G4double EkinMaxForScat = aModel->GetHighEne << 837 935 G4double EkinMaxForProd = aModel->GetHighEne << 838 G4double EkinMin =aModel->GetLowEnergyLimit(); 936 if(aModel->GetSecondPartOfSameType()) << 839 G4double EkinMaxForScat =aModel->GetHighEnergyLimit()*0.999; 937 EkinMaxForProd /= 2.; << 840 G4double EkinMaxForProd =aModel->GetHighEnergyLimit()*0.999; 938 << 841 if (aModel->GetSecondPartOfSameType() )EkinMaxForProd =EkinMaxForProd/2.; 939 // Product to projectile backward scattering << 842 940 G4double dE = std::pow(10., 1. / nbin_pro_de << 843 941 G4double E2 = << 844 942 std::pow(10., double(int(std::log10(EkinMi << 845 943 nbin_pro_decade) / dE; << 846 944 G4double E1 = EkinMin; << 847 945 // Loop checking, 07-Aug-2015, Vladimir Ivan << 848 946 while(E1 < EkinMaxForProd) << 849 //Product to projectile backward scattering 947 { << 850 //----------------------------------------- 948 E1 = std::max(EkinMin, E2); << 851 G4double fE=std::pow(10.,1./nbin_pro_decade); 949 E1 = std::min(EkinMaxForProd, E1); << 852 G4double E2=std::pow(10.,double( int(std::log10(EkinMin)*nbin_pro_decade)+1)/nbin_pro_decade)/fE; 950 std::vector<std::vector<G4double>*> aMat = << 853 G4double E1=EkinMin; 951 aModel->ComputeAdjointCrossSectionVector << 854 while (E1 <EkinMaxForProd){ 952 aMaterial, E1, nbin_pro_decade); << 855 E1=std::max(EkinMin,E2); 953 if(aMat.size() >= 2) << 856 E1=std::min(EkinMaxForProd,E1); 954 { << 857 std::vector< std::vector< double>* > aMat= aModel->ComputeAdjointCrossSectionVectorPerVolumeForSecond(aMaterial,E1,nbin_pro_decade); 955 std::vector<G4double>* log_ESecVec = aMa << 858 if (aMat.size()>=2) { 956 std::vector<G4double>* log_CSVec = aMa << 859 std::vector< double>* log_ESecVec=aMat[0]; 957 G4double log_adjointCS = log << 860 std::vector< double>* log_CSVec=aMat[1]; 958 << 861 G4double log_adjointCS=log_CSVec->back(); 959 // normalise CSVec such that it becomes << 862 960 for(std::size_t j = 0; j < log_CSVec->si << 863 //normalise CSVec such that it becomes a probability vector 961 { << 864 for (size_t j=0;j<log_CSVec->size();j++) { 962 if(j == 0) << 865 //G4cout<<"CSMan1 "<<(*log_CSVec)[j]<<G4endl; 963 (*log_CSVec)[j] = 0.; << 866 if (j==0) (*log_CSVec)[j] = 0.; 964 else << 867 else (*log_CSVec)[j]=std::log(1.-std::exp((*log_CSVec)[j]-log_adjointCS)); 965 (*log_CSVec)[j] = << 868 //G4cout<<"CSMan2 "<<(*log_CSVec)[j]<<G4endl; 966 std::log(1. - std::exp((*log_CSVec << 869 } 967 } << 870 (*log_CSVec)[log_CSVec->size()-1]=(*log_CSVec)[log_CSVec->size()-2]-std::log(1000.); 968 (*log_CSVec)[log_CSVec->size() - 1] = << 871 theCSMatForProdToProjBackwardScattering->AddData(std::log(E1),log_adjointCS,log_ESecVec,log_CSVec,0); 969 (*log_CSVec)[log_CSVec->size() - 2] - << 872 } 970 theCSMatForProdToProjBackwardScattering- << 873 971 std::log(E1), log_adjointCS, log_ESecV << 874 972 } << 875 973 << 876 E1=E2; 974 E1 = E2; << 877 E2*=fE; 975 E2 *= dE; << 878 } 976 } << 879 977 << 880 //Scattered projectile to projectile backward scattering 978 // Scattered projectile to projectile backwa << 881 //----------------------------------------- 979 E2 = << 882 980 std::pow(10., G4double(G4int(std::log10(Ek << 883 E2=std::pow(10.,double( int(std::log10(EkinMin)*nbin_pro_decade)+1)/nbin_pro_decade)/fE; 981 nbin_pro_decade) / << 884 E1=EkinMin; 982 dE; << 885 while (E1 <EkinMaxForScat){ 983 E1 = EkinMin; << 886 E1=std::max(EkinMin,E2); 984 while(E1 < EkinMaxForScat) << 887 E1=std::min(EkinMaxForScat,E1); 985 { << 888 std::vector< std::vector< double>* > aMat= aModel->ComputeAdjointCrossSectionVectorPerVolumeForScatProj(aMaterial,E1,nbin_pro_decade); 986 E1 = std::max(EkinMin, E2); << 889 if (aMat.size()>=2) { 987 E1 = std::min(EkinMaxForScat, E1); << 890 std::vector< double>* log_ESecVec=aMat[0]; 988 std::vector<std::vector<G4double>*> aMat = << 891 std::vector< double>* log_CSVec=aMat[1]; 989 aModel->ComputeAdjointCrossSectionVector << 892 G4double log_adjointCS=log_CSVec->back(); 990 aMaterial, E1, nbin_pro_decade); << 893 991 if(aMat.size() >= 2) << 894 for (size_t j=0;j<log_CSVec->size();j++) { 992 { << 895 //G4cout<<"CSMan1 "<<(*log_CSVec)[j]<<G4endl; 993 std::vector<G4double>* log_ESecVec = aMa << 896 if (j==0) (*log_CSVec)[j] = 0.; 994 std::vector<G4double>* log_CSVec = aMa << 897 else (*log_CSVec)[j]=std::log(1.-std::exp((*log_CSVec)[j]-log_adjointCS)); 995 G4double log_adjointCS = log << 898 //G4cout<<"CSMan2 "<<(*log_CSVec)[j]<<G4endl;if (theAdjPartDef->GetParticleName() == "adj_gamma") return G4Gamma::Gamma(); 996 << 899 997 for(std::size_t j = 0; j < log_CSVec->si << 900 } 998 { << 901 (*log_CSVec)[log_CSVec->size()-1]=(*log_CSVec)[log_CSVec->size()-2]-std::log(1000.); 999 if(j == 0) << 902 1000 (*log_CSVec)[j] = 0.; << 903 theCSMatForScatProjToProjBackwardScattering->AddData(std::log(E1),log_adjointCS,log_ESecVec,log_CSVec,0); 1001 else << 904 } 1002 (*log_CSVec)[j] = << 905 E1=E2; 1003 std::log(1. - std::exp((*log_CSVe << 906 E2*=fE; 1004 } << 907 } 1005 (*log_CSVec)[log_CSVec->size() - 1] = << 908 1006 (*log_CSVec)[log_CSVec->size() - 2] - << 909 1007 << 910 1008 theCSMatForScatProjToProjBackwardScatte << 911 1009 std::log(E1), log_adjointCS, log_ESec << 912 1010 } << 913 1011 E1 = E2; << 914 1012 E2 *= dE; << 1013 } << 1014 << 1015 std::vector<G4AdjointCSMatrix*> res; 915 std::vector<G4AdjointCSMatrix*> res; >> 916 res.clear(); >> 917 1016 res.push_back(theCSMatForProdToProjBackward 918 res.push_back(theCSMatForProdToProjBackwardScattering); 1017 res.push_back(theCSMatForScatProjToProjBack << 919 res.push_back(theCSMatForScatProjToProjBackwardScattering); >> 920 >> 921 /* >> 922 theCSMatForProdToProjBackwardScattering->Write(aModel->GetName()+"_CSMat_"+aMaterial->GetName()+"_ProdToProj.txt"); >> 923 theCSMatForScatProjToProjBackwardScattering->Write(aModel->GetName()+"_CSMat_"+aMaterial->GetName()+"_ScatProjToProj.txt"); >> 924 */ >> 925 1018 926 1019 return res; 927 return res; >> 928 >> 929 1020 } 930 } 1021 931 1022 ///////////////////////////////////////////// 932 /////////////////////////////////////////////////////// 1023 G4ParticleDefinition* G4AdjointCSManager::Get << 933 // 1024 G4ParticleDefinition* theFwdPartDef) << 934 G4ParticleDefinition* G4AdjointCSManager::GetAdjointParticleEquivalent(G4ParticleDefinition* theFwdPartDef) 1025 { 935 { 1026 if(theFwdPartDef->GetParticleName() == "e-" << 936 if (theFwdPartDef->GetParticleName() == "e-") return G4AdjointElectron::AdjointElectron(); 1027 return G4AdjointElectron::AdjointElectron << 937 else if (theFwdPartDef->GetParticleName() == "gamma") return G4AdjointGamma::AdjointGamma(); 1028 else if(theFwdPartDef->GetParticleName() == << 938 else if (theFwdPartDef->GetParticleName() == "proton") return G4AdjointProton::AdjointProton(); 1029 return G4AdjointGamma::AdjointGamma(); << 939 else if (theFwdPartDef ==theFwdIon) return theAdjIon; 1030 else if(theFwdPartDef->GetParticleName() == << 940 1031 return G4AdjointProton::AdjointProton(); << 941 return 0; 1032 else if(theFwdPartDef == fFwdIon) << 1033 return fAdjIon; << 1034 return nullptr; << 1035 } 942 } 1036 << 1037 ///////////////////////////////////////////// 943 /////////////////////////////////////////////////////// 1038 G4ParticleDefinition* G4AdjointCSManager::Get << 944 // 1039 G4ParticleDefinition* theAdjPartDef) << 945 G4ParticleDefinition* G4AdjointCSManager::GetForwardParticleEquivalent(G4ParticleDefinition* theAdjPartDef) 1040 { 946 { 1041 if(theAdjPartDef->GetParticleName() == "adj << 947 if (theAdjPartDef->GetParticleName() == "adj_e-") return G4Electron::Electron(); 1042 return G4Electron::Electron(); << 948 else if (theAdjPartDef->GetParticleName() == "adj_gamma") return G4Gamma::Gamma(); 1043 else if(theAdjPartDef->GetParticleName() == << 949 else if (theAdjPartDef->GetParticleName() == "adj_proton") return G4Proton::Proton(); 1044 return G4Gamma::Gamma(); << 950 else if (theAdjPartDef == theAdjIon) return theFwdIon; 1045 else if(theAdjPartDef->GetParticleName() == << 951 return 0; 1046 return G4Proton::Proton(); << 1047 else if(theAdjPartDef == fAdjIon) << 1048 return fFwdIon; << 1049 return nullptr; << 1050 } 952 } 1051 << 1052 ///////////////////////////////////////////// 953 /////////////////////////////////////////////////////// 1053 void G4AdjointCSManager::DefineCurrentMateria << 954 // 1054 const G4MaterialCutsCouple* couple) << 955 void G4AdjointCSManager::DefineCurrentMaterial(const G4MaterialCutsCouple* couple) 1055 { 956 { 1056 if(couple != fCurrentCouple) << 957 if(couple != currentCouple) { 1057 { << 958 currentCouple = const_cast<G4MaterialCutsCouple*> (couple); 1058 fCurrentCouple = const_cast<G4Ma << 959 currentMaterial = const_cast<G4Material*> (couple->GetMaterial()); 1059 fCurrentMaterial = const_cast<G4Ma << 960 currentMatIndex = couple->GetIndex(); 1060 fCurrentMatIndex = couple->GetInde << 961 lastPartDefForCS =0; 1061 fLastCSCorrectionFactor = 1.; << 962 LastEkinForCS =0; 1062 } << 963 LastCSCorrectionFactor =1.; >> 964 } 1063 } 965 } 1064 966 1065 ///////////////////////////////////////////// 967 /////////////////////////////////////////////////////// 1066 void G4AdjointCSManager::DefineCurrentParticl << 968 // 1067 const G4ParticleDefinition* aPartDef) << 969 void G4AdjointCSManager::DefineCurrentParticle(const G4ParticleDefinition* aPartDef) 1068 { 970 { 1069 << 971 if(aPartDef != currentParticleDef) { 1070 if(aPartDef != fCurrentParticleDef) << 972 1071 { << 973 currentParticleDef= const_cast< G4ParticleDefinition* > (aPartDef); 1072 fCurrentParticleDef = const_cast<G4Partic << 974 massRatio=1; 1073 fMassRatio = 1.; << 975 if (aPartDef == theAdjIon) massRatio = proton_mass_c2/aPartDef->GetPDGMass(); 1074 if(aPartDef == fAdjIon) << 976 currentParticleIndex=1000000; 1075 fMassRatio = proton_mass_c2 / aPartDef- << 977 for (size_t i=0;i<theListOfAdjointParticlesInAction.size();i++){ 1076 fCurrentParticleIndex = 1000000; << 978 if (aPartDef == theListOfAdjointParticlesInAction[i]) currentParticleIndex=i; 1077 for(std::size_t i = 0; i < fAdjointPartic << 979 } 1078 { << 980 1079 if(aPartDef == fAdjointParticlesInActio << 981 } 1080 fCurrentParticleIndex = i; << 1081 } << 1082 } << 1083 } 982 } 1084 983 1085 ///////////////////////////////////////////// << 1086 G4double G4AdjointCSManager::ComputeAdjointCS << 1087 G4double aPrimEnergy, G4AdjointCSMatrix* an << 1088 { << 1089 std::vector<double>* theLogPrimEnergyVector << 1090 anAdjointCSMatrix->GetLogPrimEnergyVector << 1091 if(theLogPrimEnergyVector->empty()) << 1092 { << 1093 G4cout << "No data are contained in the g << 1094 return 0.; << 1095 } << 1096 G4double log_Tcut = std::log(Tcut); << 1097 G4double log_E = std::log(aPrimEnergy); << 1098 << 1099 if(aPrimEnergy <= Tcut || log_E > theLogPri << 1100 return 0.; << 1101 984 1102 G4AdjointInterpolator* theInterpolator = G4 << 1103 985 1104 std::size_t ind = << 986 ///////////////////////////////////////////////////////////////////////////////////////////////// 1105 theInterpolator->FindPositionForLogVector << 987 // 1106 G4double aLogPrimEnergy1, aLogPrimEnergy2; << 988 G4double G4AdjointCSManager::ComputeAdjointCS(G4double aPrimEnergy,G4AdjointCSMatrix* 1107 G4double aLogCS1, aLogCS2; << 989 anAdjointCSMatrix,G4double Tcut) 1108 G4double log01, log02; << 990 { 1109 std::vector<G4double>* aLogSecondEnergyVect << 991 std::vector< double> *theLogPrimEnergyVector = anAdjointCSMatrix->GetLogPrimEnergyVector(); 1110 std::vector<G4double>* aLogSecondEnergyVect << 992 if (theLogPrimEnergyVector->size() ==0){ 1111 std::vector<G4double>* aLogProbVector1 << 993 G4cout<<"No data are contained in the given AdjointCSMatrix!"<<G4endl; 1112 std::vector<G4double>* aLogProbVector2 << 994 G4cout<<"The s"<<G4endl; 1113 std::vector<std::size_t>* aLogProbVectorInd << 995 return 0.; 1114 std::vector<std::size_t>* aLogProbVectorInd << 996 1115 << 1116 anAdjointCSMatrix->GetData((G4int)ind, aLog << 1117 aLogSecondEnergy << 1118 aLogProbVectorIn << 1119 anAdjointCSMatrix->GetData(G4int(ind + 1), << 1120 aLogSecondEnergy << 1121 aLogProbVectorIn << 1122 if (! (aLogProbVector1 && aLogProbVector2 & << 1123 aLogSecondEnergyVector1 && aLogS << 1124 return 0.; << 1125 } 997 } >> 998 G4double log_Tcut = std::log(Tcut); >> 999 G4double log_E =std::log(aPrimEnergy); >> 1000 >> 1001 if (aPrimEnergy <= Tcut || log_E > theLogPrimEnergyVector->back()) return 0.; >> 1002 >> 1003 1126 1004 1127 if(anAdjointCSMatrix->IsScatProjToProj()) << 1005 G4AdjointInterpolator* theInterpolator=G4AdjointInterpolator::GetInstance(); 1128 { // case where the Tcut plays a role << 1006 1129 G4double log_minimum_prob1, log_minimum_p << 1007 size_t ind =theInterpolator->FindPositionForLogVector(log_E,*theLogPrimEnergyVector); 1130 log_minimum_prob1 = theInterpolator->Inte << 1008 G4double aLogPrimEnergy1,aLogPrimEnergy2; 1131 log_Tcut, *aLogSecondEnergyVector1, *aL << 1009 G4double aLogCS1,aLogCS2; 1132 log_minimum_prob2 = theInterpolator->Inte << 1010 G4double log01,log02; 1133 log_Tcut, *aLogSecondEnergyVector2, *aL << 1011 std::vector< double>* aLogSecondEnergyVector1 =0; 1134 aLogCS1 += log_minimum_prob1; << 1012 std::vector< double>* aLogSecondEnergyVector2 =0; 1135 aLogCS2 += log_minimum_prob2; << 1013 std::vector< double>* aLogProbVector1=0; >> 1014 std::vector< double>* aLogProbVector2=0; >> 1015 std::vector< size_t>* aLogProbVectorIndex1=0; >> 1016 std::vector< size_t>* aLogProbVectorIndex2=0; >> 1017 >> 1018 >> 1019 anAdjointCSMatrix->GetData(ind, aLogPrimEnergy1,aLogCS1,log01, aLogSecondEnergyVector1,aLogProbVector1,aLogProbVectorIndex1); >> 1020 anAdjointCSMatrix->GetData(ind+1, aLogPrimEnergy2,aLogCS2,log02, aLogSecondEnergyVector2,aLogProbVector2,aLogProbVectorIndex2); >> 1021 if (anAdjointCSMatrix->IsScatProjToProjCase()){ //case where the Tcut plays a role >> 1022 G4double log_minimum_prob1, log_minimum_prob2; >> 1023 log_minimum_prob1=theInterpolator->InterpolateForLogVector(log_Tcut,*aLogSecondEnergyVector1,*aLogProbVector1); >> 1024 log_minimum_prob2=theInterpolator->InterpolateForLogVector(log_Tcut,*aLogSecondEnergyVector2,*aLogProbVector2); >> 1025 aLogCS1+= log_minimum_prob1; >> 1026 aLogCS2+= log_minimum_prob2; 1136 } 1027 } 1137 << 1028 1138 G4double log_adjointCS = theInterpolator->L << 1029 G4double log_adjointCS = theInterpolator->LinearInterpolation(log_E,aLogPrimEnergy1,aLogPrimEnergy2,aLogCS1,aLogCS2); 1139 log_E, aLogPrimEnergy1, aLogPrimEnergy2, << 1030 return std::exp(log_adjointCS); 1140 return std::exp(log_adjointCS); << 1031 1141 } << 1032 >> 1033 } 1142 1034