Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4AdjointCSManager Class Reference

#include <G4AdjointCSManager.hh>

Public Member Functions

 ~G4AdjointCSManager ()
 
G4int GetNbProcesses ()
 
std::size_t RegisterEmAdjointModel (G4VEmAdjointModel *)
 
void RegisterEmProcess (G4VEmProcess *aProcess, G4ParticleDefinition *aPartDef)
 
void RegisterEnergyLossProcess (G4VEnergyLossProcess *aProcess, G4ParticleDefinition *aPartDef)
 
void RegisterAdjointParticle (G4ParticleDefinition *aPartDef)
 
void BuildCrossSectionMatrices ()
 
void BuildTotalSigmaTables ()
 
G4double GetTotalAdjointCS (G4ParticleDefinition *aPartDef, G4double Ekin, const G4MaterialCutsCouple *aCouple)
 
G4double GetTotalForwardCS (G4ParticleDefinition *aPartDef, G4double Ekin, const G4MaterialCutsCouple *aCouple)
 
G4double GetAdjointSigma (G4double Ekin_nuc, std::size_t index_model, G4bool is_scat_proj_to_proj, const G4MaterialCutsCouple *aCouple)
 
void GetEminForTotalCS (G4ParticleDefinition *aPartDef, const G4MaterialCutsCouple *aCouple, G4double &emin_adj, G4double &emin_fwd)
 
void GetMaxFwdTotalCS (G4ParticleDefinition *aPartDef, const G4MaterialCutsCouple *aCouple, G4double &e_sigma_max, G4double &sigma_max)
 
void GetMaxAdjTotalCS (G4ParticleDefinition *aPartDef, const G4MaterialCutsCouple *aCouple, G4double &e_sigma_max, G4double &sigma_max)
 
G4double GetCrossSectionCorrection (G4ParticleDefinition *aPartDef, G4double PreStepEkin, const G4MaterialCutsCouple *aCouple, G4bool &fwd_is_used)
 
void SetFwdCrossSectionMode (G4bool aBool)
 
G4double GetContinuousWeightCorrection (G4ParticleDefinition *aPartDef, G4double PreStepEkin, G4double AfterStepEkin, const G4MaterialCutsCouple *aCouple, G4double step_length)
 
G4double GetPostStepWeightCorrection ()
 
G4double ComputeAdjointCS (G4Material *aMaterial, G4VEmAdjointModel *aModel, G4double PrimEnergy, G4double Tcut, G4bool isScatProjToProj, std::vector< G4double > &AdjointCS_for_each_element)
 
G4ElementSampleElementFromCSMatrices (G4Material *aMaterial, G4VEmAdjointModel *aModel, G4double PrimEnergy, G4double Tcut, G4bool isScatProjToProj)
 
G4double ComputeTotalAdjointCS (const G4MaterialCutsCouple *aMatCutCouple, G4ParticleDefinition *aPart, G4double PrimEnergy)
 
G4ParticleDefinitionGetAdjointParticleEquivalent (G4ParticleDefinition *theFwdPartDef)
 
G4ParticleDefinitionGetForwardParticleEquivalent (G4ParticleDefinition *theAdjPartDef)
 
void SetIon (G4ParticleDefinition *adjIon, G4ParticleDefinition *fwdIon)
 

Static Public Member Functions

static G4AdjointCSManagerGetAdjointCSManager ()
 

Friends

class G4ThreadLocalSingleton< G4AdjointCSManager >
 

Detailed Description

Definition at line 58 of file G4AdjointCSManager.hh.

Constructor & Destructor Documentation

◆ ~G4AdjointCSManager()

G4AdjointCSManager::~G4AdjointCSManager ( )

Definition at line 76 of file G4AdjointCSManager.cc.

77{
78 for (auto& p : fAdjointCSMatricesForProdToProj) {
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 : fAdjointCSMatricesForScatProjToProj) {
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 : fSigmaTableForAdjointModelScatProjToProj) {
116 p->clearAndDestroy();
117 delete p;
118 p = nullptr;
119 }
120 fSigmaTableForAdjointModelScatProjToProj.clear();
121
122 for (auto p : fSigmaTableForAdjointModelProdToProj) {
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}

Member Function Documentation

◆ BuildCrossSectionMatrices()

void G4AdjointCSManager::BuildCrossSectionMatrices ( )

Definition at line 222 of file G4AdjointCSManager.cc.

223{
224 if(fCSMatricesBuilt)
225 return;
226 // The Tcut and Tmax matrices will be computed probably just once.
227 // When Tcut changes, some PhysicsTable will be recomputed
228 // for each MaterialCutCouple but not all the matrices.
229 // The Tcut defines a lower limit in the energy of the projectile before
230 // scattering. In the Projectile to Scattered Projectile case we have
231 // E_ScatProj<E_Proj-Tcut
232 // Therefore in the adjoint case we have
233 // Eproj> E_ScatProj+Tcut
234 // This implies that when computing the adjoint CS we should integrate over
235 // Epro from E_ScatProj+Tcut to Emax
236 // In the Projectile to Secondary case Tcut plays a role only in the fact that
237 // Esecond should be greater than Tcut to have the possibility to have any
238 // adjoint process.
239 // To avoid recomputing matrices for all changes of MaterialCutCouple,
240 // we propose to compute the matrices only once for the minimum possible Tcut
241 // and then to interpolate the probability for a new Tcut (implemented in
242 // G4VAdjointEmModel)
243
244 fAdjointCSMatricesForScatProjToProj.clear();
245 fAdjointCSMatricesForProdToProj.clear();
246 const G4ElementTable* theElementTable = G4Element::GetElementTable();
247 const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
248
249 G4cout << "========== Computation of cross section matrices for adjoint "
250 "models =========="
251 << G4endl;
252 for(const auto& aModel : fAdjointModels)
253 {
254 G4cout << "Build adjoint cross section matrices for " << aModel->GetName()
255 << G4endl;
256 if(aModel->GetUseMatrix())
257 {
258 std::vector<G4AdjointCSMatrix*>* aListOfMat1 =
259 new std::vector<G4AdjointCSMatrix*>();
260 std::vector<G4AdjointCSMatrix*>* aListOfMat2 =
261 new std::vector<G4AdjointCSMatrix*>();
262 if(aModel->GetUseMatrixPerElement())
263 {
264 if(aModel->GetUseOnlyOneMatrixForAllElements())
265 {
266 std::vector<G4AdjointCSMatrix*> two_matrices =
267 BuildCrossSectionsModelAndElement(aModel, 1, 1, 80);
268 aListOfMat1->push_back(two_matrices[0]);
269 aListOfMat2->push_back(two_matrices[1]);
270 }
271 else
272 {
273 for(const auto& anElement : *theElementTable)
274 {
275 G4int Z = G4lrint(anElement->GetZ());
276 G4int A = G4lrint(anElement->GetN());
277 std::vector<G4AdjointCSMatrix*> two_matrices =
278 BuildCrossSectionsModelAndElement(aModel, Z, A, 40);
279 aListOfMat1->push_back(two_matrices[0]);
280 aListOfMat2->push_back(two_matrices[1]);
281 }
282 }
283 }
284 else
285 { // Per material case
286 for(const auto& aMaterial : *theMaterialTable)
287 {
288 std::vector<G4AdjointCSMatrix*> two_matrices =
289 BuildCrossSectionsModelAndMaterial(aModel, aMaterial, 40);
290 aListOfMat1->push_back(two_matrices[0]);
291 aListOfMat2->push_back(two_matrices[1]);
292 }
293 }
294 fAdjointCSMatricesForProdToProj.push_back(*aListOfMat1);
295 fAdjointCSMatricesForScatProjToProj.push_back(*aListOfMat2);
296 aModel->SetCSMatrices(aListOfMat1, aListOfMat2);
297 }
298 else
299 {
300 G4cout << "The model " << aModel->GetName()
301 << " does not use cross section matrices" << G4endl;
302 std::vector<G4AdjointCSMatrix*> two_empty_matrices;
303 fAdjointCSMatricesForProdToProj.push_back(two_empty_matrices);
304 fAdjointCSMatricesForScatProjToProj.push_back(two_empty_matrices);
305 }
306 }
307 G4cout << " All adjoint cross section matrices are computed!"
308 << G4endl;
309 G4cout
310 << "======================================================================"
311 << G4endl;
312
313 fCSMatricesBuilt = true;
314}
std::vector< G4Element * > G4ElementTable
std::vector< G4Material * > G4MaterialTable
int G4int
Definition: G4Types.hh:85
const G4int Z[17]
const G4double A[17]
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4ElementTable * GetElementTable()
Definition: G4Element.cc:403
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:677
int G4lrint(double ad)
Definition: templates.hh:134

Referenced by G4AdjointForcedInteractionForGamma::BuildPhysicsTable(), and G4VAdjointReverseReaction::BuildPhysicsTable().

◆ BuildTotalSigmaTables()

void G4AdjointCSManager::BuildTotalSigmaTables ( )

Definition at line 317 of file G4AdjointCSManager.cc.

318{
319 if(fSigmaTableBuilt)
320 return;
321
322 const G4ProductionCutsTable* theCoupleTable =
324
325 // Prepare the Sigma table for all AdjointEMModel, will be filled later on
326 for(std::size_t i = 0; i < fAdjointModels.size(); ++i)
327 {
328 fSigmaTableForAdjointModelScatProjToProj[i]->clearAndDestroy();
329 fSigmaTableForAdjointModelProdToProj[i]->clearAndDestroy();
330 for(std::size_t j = 0; j < theCoupleTable->GetTableSize(); ++j)
331 {
332 fSigmaTableForAdjointModelScatProjToProj[i]->push_back(
333 new G4PhysicsLogVector(fTmin, fTmax, fNbins));
334 fSigmaTableForAdjointModelProdToProj[i]->push_back(
335 new G4PhysicsLogVector(fTmin, fTmax, fNbins));
336 }
337 }
338
339 for(std::size_t i = 0; i < fAdjointParticlesInAction.size(); ++i)
340 {
341 G4ParticleDefinition* thePartDef = fAdjointParticlesInAction[i];
342 DefineCurrentParticle(thePartDef);
343 fTotalFwdSigmaTable[i]->clearAndDestroy();
344 fTotalAdjSigmaTable[i]->clearAndDestroy();
345 fEminForFwdSigmaTables[i].clear();
346 fEminForAdjSigmaTables[i].clear();
347 fEkinofFwdSigmaMax[i].clear();
348 fEkinofAdjSigmaMax[i].clear();
349
350 for(std::size_t j = 0; j < theCoupleTable->GetTableSize(); ++j)
351 {
352 const G4MaterialCutsCouple* couple =
353 theCoupleTable->GetMaterialCutsCouple((G4int)j);
354
355 // make first the total fwd CS table for FwdProcess
356 G4PhysicsVector* aVector = new G4PhysicsLogVector(fTmin, fTmax, fNbins);
357 G4bool Emin_found = false;
358 G4double sigma_max = 0.;
359 G4double e_sigma_max = 0.;
360 for(std::size_t l = 0; l < fNbins; ++l)
361 {
362 G4double totCS = 0.;
363 G4double e = aVector->Energy(l);
364 for(std::size_t k = 0; k < fForwardProcesses[i]->size(); ++k)
365 {
366 totCS += (*fForwardProcesses[i])[k]->GetCrossSection(e, couple);
367 }
368 for(std::size_t k = 0; k < fForwardLossProcesses[i]->size(); ++k)
369 {
370 if(thePartDef == fAdjIon)
371 { // e is considered already as the scaled energy
372 std::size_t mat_index = couple->GetIndex();
373 G4VEmModel* currentModel =
374 (*fForwardLossProcesses[i])[k]->SelectModelForMaterial(e,
375 mat_index);
376 G4double chargeSqRatio = currentModel->GetChargeSquareRatio(
377 fFwdIon, couple->GetMaterial(), e / fMassRatio);
378 (*fForwardLossProcesses[i])[k]->SetDynamicMassCharge(fMassRatio,
379 chargeSqRatio);
380 }
381 G4double e1 = e / fMassRatio;
382 totCS += (*fForwardLossProcesses[i])[k]->GetLambda(e1, couple);
383 }
384 aVector->PutValue(l, totCS);
385 if(totCS > sigma_max)
386 {
387 sigma_max = totCS;
388 e_sigma_max = e;
389 }
390 if(totCS > 0 && !Emin_found)
391 {
392 fEminForFwdSigmaTables[i].push_back(e);
393 Emin_found = true;
394 }
395 }
396
397 fEkinofFwdSigmaMax[i].push_back(e_sigma_max);
398
399 if(!Emin_found)
400 fEminForFwdSigmaTables[i].push_back(fTmax);
401
402 fTotalFwdSigmaTable[i]->push_back(aVector);
403
404 Emin_found = false;
405 sigma_max = 0;
406 e_sigma_max = 0.;
407 G4PhysicsVector* aVector1 = new G4PhysicsLogVector(fTmin, fTmax, fNbins);
408 for(std::size_t eindex = 0; eindex < fNbins; ++eindex)
409 {
410 G4double e = aVector1->Energy(eindex);
412 couple, thePartDef,
413 e * 0.9999999 / fMassRatio); // fMassRatio needed for ions
414 aVector1->PutValue(eindex, totCS);
415 if(totCS > sigma_max)
416 {
417 sigma_max = totCS;
418 e_sigma_max = e;
419 }
420 if(totCS > 0 && !Emin_found)
421 {
422 fEminForAdjSigmaTables[i].push_back(e);
423 Emin_found = true;
424 }
425 }
426 fEkinofAdjSigmaMax[i].push_back(e_sigma_max);
427 if(!Emin_found)
428 fEminForAdjSigmaTables[i].push_back(fTmax);
429
430 fTotalAdjSigmaTable[i]->push_back(aVector1);
431 }
432 }
433 fSigmaTableBuilt = true;
434}
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
G4double ComputeTotalAdjointCS(const G4MaterialCutsCouple *aMatCutCouple, G4ParticleDefinition *aPart, G4double PrimEnergy)
const G4Material * GetMaterial() const
void PutValue(const std::size_t index, const G4double value)
G4double Energy(const std::size_t index) const
const G4MaterialCutsCouple * GetMaterialCutsCouple(G4int i) const
std::size_t GetTableSize() const
static G4ProductionCutsTable * GetProductionCutsTable()
virtual G4double GetChargeSquareRatio(const G4ParticleDefinition *, const G4Material *, G4double kineticEnergy)
Definition: G4VEmModel.cc:325

Referenced by G4AdjointForcedInteractionForGamma::BuildPhysicsTable(), and G4VAdjointReverseReaction::BuildPhysicsTable().

◆ ComputeAdjointCS()

G4double G4AdjointCSManager::ComputeAdjointCS ( G4Material aMaterial,
G4VEmAdjointModel aModel,
G4double  PrimEnergy,
G4double  Tcut,
G4bool  isScatProjToProj,
std::vector< G4double > &  AdjointCS_for_each_element 
)

Definition at line 584 of file G4AdjointCSManager.cc.

587{
588 G4double EminSec = 0.;
589 G4double EmaxSec = 0.;
590
591 static G4double lastPrimaryEnergy = 0.;
592 static G4double lastTcut = 0.;
593 static G4Material* lastMaterial = nullptr;
594
595 if(isScatProjToProj)
596 {
597 EminSec = aModel->GetSecondAdjEnergyMinForScatProjToProj(PrimEnergy, Tcut);
598 EmaxSec = aModel->GetSecondAdjEnergyMaxForScatProjToProj(PrimEnergy);
599 }
600 else if(PrimEnergy > Tcut || !aModel->GetApplyCutInRange())
601 {
602 EminSec = aModel->GetSecondAdjEnergyMinForProdToProj(PrimEnergy);
603 EmaxSec = aModel->GetSecondAdjEnergyMaxForProdToProj(PrimEnergy);
604 }
605 if(EminSec >= EmaxSec)
606 return 0.;
607
608 G4bool need_to_compute = false;
609 if(aMaterial != lastMaterial || PrimEnergy != lastPrimaryEnergy ||
610 Tcut != lastTcut)
611 {
612 lastMaterial = aMaterial;
613 lastPrimaryEnergy = PrimEnergy;
614 lastTcut = Tcut;
615 fIndexOfAdjointEMModelInAction.clear();
616 fIsScatProjToProj.clear();
617 fLastAdjointCSVsModelsAndElements.clear();
618 need_to_compute = true;
619 }
620
621 std::size_t ind = 0;
622 if(!need_to_compute)
623 {
624 need_to_compute = true;
625 for(std::size_t i = 0; i < fIndexOfAdjointEMModelInAction.size(); ++i)
626 {
627 std::size_t ind1 = fIndexOfAdjointEMModelInAction[i];
628 if(aModel == fAdjointModels[ind1] &&
629 isScatProjToProj == fIsScatProjToProj[i])
630 {
631 need_to_compute = false;
632 CS_Vs_Element = fLastAdjointCSVsModelsAndElements[ind];
633 }
634 ++ind;
635 }
636 }
637
638 if(need_to_compute)
639 {
640 std::size_t ind_model = 0;
641 for(std::size_t i = 0; i < fAdjointModels.size(); ++i)
642 {
643 if(aModel == fAdjointModels[i])
644 {
645 ind_model = i;
646 break;
647 }
648 }
649 G4double Tlow = Tcut;
650 if(!fAdjointModels[ind_model]->GetApplyCutInRange())
651 Tlow = fAdjointModels[ind_model]->GetLowEnergyLimit();
652 fIndexOfAdjointEMModelInAction.push_back(ind_model);
653 fIsScatProjToProj.push_back(isScatProjToProj);
654 CS_Vs_Element.clear();
655 if(!aModel->GetUseMatrix())
656 {
657 CS_Vs_Element.push_back(aModel->AdjointCrossSection(
658 fCurrentCouple, PrimEnergy, isScatProjToProj));
659 }
660 else if(aModel->GetUseMatrixPerElement())
661 {
662 std::size_t n_el = aMaterial->GetNumberOfElements();
664 {
665 G4AdjointCSMatrix* theCSMatrix;
666 if(isScatProjToProj)
667 {
668 theCSMatrix = fAdjointCSMatricesForScatProjToProj[ind_model][0];
669 }
670 else
671 theCSMatrix = fAdjointCSMatricesForProdToProj[ind_model][0];
672 G4double CS = 0.;
673 if(PrimEnergy > Tlow)
674 CS = ComputeAdjointCS(PrimEnergy, theCSMatrix, Tlow);
675 G4double factor = 0.;
676 for(G4int i = 0; i < (G4int)n_el; ++i)
677 { // this could be computed only once
678 factor += aMaterial->GetElement(i)->GetZ() *
679 aMaterial->GetVecNbOfAtomsPerVolume()[i];
680 }
681 CS *= factor;
682 CS_Vs_Element.push_back(CS);
683 }
684 else
685 {
686 for(G4int i = 0; i < (G4int)n_el; ++i)
687 {
688 std::size_t ind_el = aMaterial->GetElement(i)->GetIndex();
689 G4AdjointCSMatrix* theCSMatrix;
690 if(isScatProjToProj)
691 {
692 theCSMatrix =
693 fAdjointCSMatricesForScatProjToProj[ind_model][ind_el];
694 }
695 else
696 theCSMatrix = fAdjointCSMatricesForProdToProj[ind_model][ind_el];
697 G4double CS = 0.;
698 if(PrimEnergy > Tlow)
699 CS = ComputeAdjointCS(PrimEnergy, theCSMatrix, Tlow);
700 CS_Vs_Element.push_back(CS *
701 (aMaterial->GetVecNbOfAtomsPerVolume()[i]));
702 }
703 }
704 }
705 else
706 {
707 std::size_t ind_mat = aMaterial->GetIndex();
708 G4AdjointCSMatrix* theCSMatrix;
709 if(isScatProjToProj)
710 {
711 theCSMatrix = fAdjointCSMatricesForScatProjToProj[ind_model][ind_mat];
712 }
713 else
714 theCSMatrix = fAdjointCSMatricesForProdToProj[ind_model][ind_mat];
715 G4double CS = 0.;
716 if(PrimEnergy > Tlow)
717 CS = ComputeAdjointCS(PrimEnergy, theCSMatrix, Tlow);
718 CS_Vs_Element.push_back(CS);
719 }
720 fLastAdjointCSVsModelsAndElements.push_back(CS_Vs_Element);
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 CS instead of the CS of an
727 // element itself
728 CS += cs_vs_el;
729 }
730 return CS;
731}
G4double ComputeAdjointCS(G4Material *aMaterial, G4VEmAdjointModel *aModel, G4double PrimEnergy, G4double Tcut, G4bool isScatProjToProj, std::vector< G4double > &AdjointCS_for_each_element)
G4double GetZ() const
Definition: G4Element.hh:131
size_t GetIndex() const
Definition: G4Element.hh:182
const G4Element * GetElement(G4int iel) const
Definition: G4Material.hh:197
size_t GetNumberOfElements() const
Definition: G4Material.hh:181
const G4double * GetVecNbOfAtomsPerVolume() const
Definition: G4Material.hh:201
size_t GetIndex() const
Definition: G4Material.hh:255
virtual G4double GetSecondAdjEnergyMaxForProdToProj(G4double primAdjEnergy)
G4bool GetUseOnlyOneMatrixForAllElements()
virtual G4double GetSecondAdjEnergyMinForScatProjToProj(G4double primAdjEnergy, G4double tcut=0.)
virtual G4double GetSecondAdjEnergyMaxForScatProjToProj(G4double primAdjEnergy)
virtual G4double AdjointCrossSection(const G4MaterialCutsCouple *aCouple, G4double primEnergy, G4bool isScatProjToProj)
virtual G4double GetSecondAdjEnergyMinForProdToProj(G4double primAdjEnergy)

Referenced by G4VEmAdjointModel::AdjointCrossSection(), ComputeAdjointCS(), ComputeTotalAdjointCS(), and SampleElementFromCSMatrices().

◆ ComputeTotalAdjointCS()

G4double G4AdjointCSManager::ComputeTotalAdjointCS ( const G4MaterialCutsCouple aMatCutCouple,
G4ParticleDefinition aPart,
G4double  PrimEnergy 
)

Definition at line 757 of file G4AdjointCSManager.cc.

760{
761 G4double TotalCS = 0.;
762
763 DefineCurrentMaterial(aCouple);
764
765 std::vector<G4double> CS_Vs_Element;
766 G4double CS;
767 G4VEmAdjointModel* adjModel = nullptr;
768 for(std::size_t i = 0; i < fAdjointModels.size(); ++i)
769 {
770 G4double Tlow = 0.;
771 adjModel = fAdjointModels[i];
772 if(!adjModel->GetApplyCutInRange())
773 Tlow = adjModel->GetLowEnergyLimit();
774 else
775 {
778 std::size_t idx = 56;
779 if(theDirSecondPartDef->GetParticleName() == "gamma")
780 idx = 0;
781 else if(theDirSecondPartDef->GetParticleName() == "e-")
782 idx = 1;
783 else if(theDirSecondPartDef->GetParticleName() == "e+")
784 idx = 2;
785 if(idx < 56)
786 {
787 const std::vector<G4double>* aVec =
789 idx);
790 Tlow = (*aVec)[aCouple->GetIndex()];
791 }
792 }
793 if(Ekin <= adjModel->GetHighEnergyLimit() &&
794 Ekin >= adjModel->GetLowEnergyLimit())
795 {
796 if(aPartDef ==
798 {
799 CS = ComputeAdjointCS(fCurrentMaterial, adjModel, Ekin, Tlow, true,
800 CS_Vs_Element);
801 TotalCS += CS;
802 (*fSigmaTableForAdjointModelScatProjToProj[i])[fCurrentMatIndex]
803 ->PutValue(fNbins, CS);
804 }
805 if(aPartDef ==
807 {
808 CS = ComputeAdjointCS(fCurrentMaterial, adjModel, Ekin, Tlow, false,
809 CS_Vs_Element);
810 TotalCS += CS;
811 (*fSigmaTableForAdjointModelProdToProj[i])[fCurrentMatIndex]->PutValue(
812 fNbins, CS);
813 }
814 }
815 else
816 {
817 (*fSigmaTableForAdjointModelScatProjToProj[i])[fCurrentMatIndex]
818 ->PutValue(fNbins, 0.);
819 (*fSigmaTableForAdjointModelProdToProj[i])[fCurrentMatIndex]->PutValue(
820 fNbins, 0.);
821 }
822 }
823 return TotalCS;
824}
G4ParticleDefinition * GetForwardParticleEquivalent(G4ParticleDefinition *theAdjPartDef)
const G4String & GetParticleName() const
const std::vector< G4double > * GetEnergyCutsVector(std::size_t pcIdx) const
G4ParticleDefinition * GetAdjointEquivalentOfDirectPrimaryParticleDefinition()
G4double GetLowEnergyLimit()
G4ParticleDefinition * GetAdjointEquivalentOfDirectSecondaryParticleDefinition()

Referenced by BuildTotalSigmaTables().

◆ GetAdjointCSManager()

◆ GetAdjointParticleEquivalent()

G4ParticleDefinition * G4AdjointCSManager::GetAdjointParticleEquivalent ( G4ParticleDefinition theFwdPartDef)

Definition at line 1023 of file G4AdjointCSManager.cc.

1025{
1026 if(theFwdPartDef->GetParticleName() == "e-")
1028 else if(theFwdPartDef->GetParticleName() == "gamma")
1030 else if(theFwdPartDef->GetParticleName() == "proton")
1032 else if(theFwdPartDef == fFwdIon)
1033 return fAdjIon;
1034 return nullptr;
1035}
static G4AdjointElectron * AdjointElectron()
static G4AdjointGamma * AdjointGamma()
static G4AdjointProton * AdjointProton()

Referenced by RegisterEmProcess(), and RegisterEnergyLossProcess().

◆ GetAdjointSigma()

G4double G4AdjointCSManager::GetAdjointSigma ( G4double  Ekin_nuc,
std::size_t  index_model,
G4bool  is_scat_proj_to_proj,
const G4MaterialCutsCouple aCouple 
)

Definition at line 459 of file G4AdjointCSManager.cc.

462{
463 DefineCurrentMaterial(aCouple);
464 if(is_scat_proj_to_proj)
465 return (((*fSigmaTableForAdjointModelScatProjToProj[index_model])
466 [fCurrentMatIndex])->Value(Ekin_nuc));
467 else
468 return (
469 ((*fSigmaTableForAdjointModelProdToProj[index_model])[fCurrentMatIndex])
470 ->Value(Ekin_nuc));
471}

◆ GetContinuousWeightCorrection()

G4double G4AdjointCSManager::GetContinuousWeightCorrection ( G4ParticleDefinition aPartDef,
G4double  PreStepEkin,
G4double  AfterStepEkin,
const G4MaterialCutsCouple aCouple,
G4double  step_length 
)

Definition at line 557 of file G4AdjointCSManager.cc.

560{
561 G4double corr_fac = 1.;
562 G4double after_fwdCS = GetTotalForwardCS(aPartDef, AfterStepEkin, aCouple);
563 G4double pre_adjCS = GetTotalAdjointCS(aPartDef, PreStepEkin, aCouple);
564 if(!fForwardCSUsed || pre_adjCS == 0. || after_fwdCS == 0.)
565 {
566 G4double pre_fwdCS = GetTotalForwardCS(aPartDef, PreStepEkin, aCouple);
567 corr_fac *= std::exp((pre_adjCS - pre_fwdCS) * step_length);
568 fLastCSCorrectionFactor = 1.;
569 }
570 else
571 {
572 fLastCSCorrectionFactor = after_fwdCS / pre_adjCS;
573 }
574 return corr_fac;
575}
G4double GetTotalForwardCS(G4ParticleDefinition *aPartDef, G4double Ekin, const G4MaterialCutsCouple *aCouple)
G4double GetTotalAdjointCS(G4ParticleDefinition *aPartDef, G4double Ekin, const G4MaterialCutsCouple *aCouple)

Referenced by G4AdjointAlongStepWeightCorrection::AlongStepDoIt().

◆ GetCrossSectionCorrection()

G4double G4AdjointCSManager::GetCrossSectionCorrection ( G4ParticleDefinition aPartDef,
G4double  PreStepEkin,
const G4MaterialCutsCouple aCouple,
G4bool fwd_is_used 
)

Definition at line 516 of file G4AdjointCSManager.cc.

519{
520 static G4double lastEkin = 0.;
521 static G4ParticleDefinition* lastPartDef;
522
523 G4double corr_fac = 1.;
524 if(fForwardCSMode && aPartDef)
525 {
526 if(lastEkin != PreStepEkin || aPartDef != lastPartDef ||
527 aCouple != fCurrentCouple)
528 {
529 DefineCurrentMaterial(aCouple);
530 G4double preadjCS = GetTotalAdjointCS(aPartDef, PreStepEkin, aCouple);
531 G4double prefwdCS = GetTotalForwardCS(aPartDef, PreStepEkin, aCouple);
532 lastEkin = PreStepEkin;
533 lastPartDef = aPartDef;
534 if(prefwdCS > 0. && preadjCS > 0.)
535 {
536 fForwardCSUsed = true;
537 fLastCSCorrectionFactor = prefwdCS / preadjCS;
538 }
539 else
540 {
541 fForwardCSUsed = false;
542 fLastCSCorrectionFactor = 1.;
543 }
544 }
545 corr_fac = fLastCSCorrectionFactor;
546 }
547 else
548 {
549 fForwardCSUsed = false;
550 fLastCSCorrectionFactor = 1.;
551 }
552 fwd_is_used = fForwardCSUsed;
553 return corr_fac;
554}

Referenced by G4VAdjointReverseReaction::GetMeanFreePath().

◆ GetEminForTotalCS()

void G4AdjointCSManager::GetEminForTotalCS ( G4ParticleDefinition aPartDef,
const G4MaterialCutsCouple aCouple,
G4double emin_adj,
G4double emin_fwd 
)

Definition at line 474 of file G4AdjointCSManager.cc.

478{
479 DefineCurrentMaterial(aCouple);
480 DefineCurrentParticle(aPartDef);
481 emin_adj = fEminForAdjSigmaTables[fCurrentParticleIndex][fCurrentMatIndex] /
482 fMassRatio;
483 emin_fwd = fEminForFwdSigmaTables[fCurrentParticleIndex][fCurrentMatIndex] /
484 fMassRatio;
485}

◆ GetForwardParticleEquivalent()

G4ParticleDefinition * G4AdjointCSManager::GetForwardParticleEquivalent ( G4ParticleDefinition theAdjPartDef)

Definition at line 1038 of file G4AdjointCSManager.cc.

1040{
1041 if(theAdjPartDef->GetParticleName() == "adj_e-")
1042 return G4Electron::Electron();
1043 else if(theAdjPartDef->GetParticleName() == "adj_gamma")
1044 return G4Gamma::Gamma();
1045 else if(theAdjPartDef->GetParticleName() == "adj_proton")
1046 return G4Proton::Proton();
1047 else if(theAdjPartDef == fAdjIon)
1048 return fFwdIon;
1049 return nullptr;
1050}
static G4Electron * Electron()
Definition: G4Electron.cc:93
static G4Gamma * Gamma()
Definition: G4Gamma.cc:85
static G4Proton * Proton()
Definition: G4Proton.cc:92

Referenced by ComputeTotalAdjointCS().

◆ GetMaxAdjTotalCS()

void G4AdjointCSManager::GetMaxAdjTotalCS ( G4ParticleDefinition aPartDef,
const G4MaterialCutsCouple aCouple,
G4double e_sigma_max,
G4double sigma_max 
)

Definition at line 502 of file G4AdjointCSManager.cc.

506{
507 DefineCurrentMaterial(aCouple);
508 DefineCurrentParticle(aPartDef);
509 e_sigma_max = fEkinofAdjSigmaMax[fCurrentParticleIndex][fCurrentMatIndex];
510 sigma_max = ((*fTotalAdjSigmaTable[fCurrentParticleIndex])[fCurrentMatIndex])
511 ->Value(e_sigma_max);
512 e_sigma_max /= fMassRatio;
513}

◆ GetMaxFwdTotalCS()

void G4AdjointCSManager::GetMaxFwdTotalCS ( G4ParticleDefinition aPartDef,
const G4MaterialCutsCouple aCouple,
G4double e_sigma_max,
G4double sigma_max 
)

Definition at line 488 of file G4AdjointCSManager.cc.

492{
493 DefineCurrentMaterial(aCouple);
494 DefineCurrentParticle(aPartDef);
495 e_sigma_max = fEkinofFwdSigmaMax[fCurrentParticleIndex][fCurrentMatIndex];
496 sigma_max = ((*fTotalFwdSigmaTable[fCurrentParticleIndex])[fCurrentMatIndex])
497 ->Value(e_sigma_max);
498 e_sigma_max /= fMassRatio;
499}

◆ GetNbProcesses()

G4int G4AdjointCSManager::GetNbProcesses ( )

◆ GetPostStepWeightCorrection()

◆ GetTotalAdjointCS()

G4double G4AdjointCSManager::GetTotalAdjointCS ( G4ParticleDefinition aPartDef,
G4double  Ekin,
const G4MaterialCutsCouple aCouple 
)

Definition at line 437 of file G4AdjointCSManager.cc.

440{
441 DefineCurrentMaterial(aCouple);
442 DefineCurrentParticle(aPartDef);
443 return (((*fTotalAdjSigmaTable[fCurrentParticleIndex])[fCurrentMatIndex])
444 ->Value(Ekin * fMassRatio));
445}

Referenced by G4AdjointForcedInteractionForGamma::AlongStepDoIt(), GetContinuousWeightCorrection(), GetCrossSectionCorrection(), and G4AdjointForcedInteractionForGamma::PostStepGetPhysicalInteractionLength().

◆ GetTotalForwardCS()

G4double G4AdjointCSManager::GetTotalForwardCS ( G4ParticleDefinition aPartDef,
G4double  Ekin,
const G4MaterialCutsCouple aCouple 
)

Definition at line 448 of file G4AdjointCSManager.cc.

451{
452 DefineCurrentMaterial(aCouple);
453 DefineCurrentParticle(aPartDef);
454 return (((*fTotalFwdSigmaTable[fCurrentParticleIndex])[fCurrentMatIndex])
455 ->Value(Ekin * fMassRatio));
456}

Referenced by G4AdjointForcedInteractionForGamma::AlongStepDoIt(), GetContinuousWeightCorrection(), and GetCrossSectionCorrection().

◆ RegisterAdjointParticle()

void G4AdjointCSManager::RegisterAdjointParticle ( G4ParticleDefinition aPartDef)

Definition at line 197 of file G4AdjointCSManager.cc.

198{
199 G4bool found = false;
200 for(auto p : fAdjointParticlesInAction)
201 {
202 if(p->GetParticleName() == aPartDef->GetParticleName())
203 {
204 found = true;
205 }
206 }
207 if(!found)
208 {
209 fForwardLossProcesses.push_back(new std::vector<G4VEnergyLossProcess*>());
210 fTotalFwdSigmaTable.push_back(new G4PhysicsTable);
211 fTotalAdjSigmaTable.push_back(new G4PhysicsTable);
212 fForwardProcesses.push_back(new std::vector<G4VEmProcess*>());
213 fAdjointParticlesInAction.push_back(aPartDef);
214 fEminForFwdSigmaTables.push_back(std::vector<G4double>());
215 fEminForAdjSigmaTables.push_back(std::vector<G4double>());
216 fEkinofFwdSigmaMax.push_back(std::vector<G4double>());
217 fEkinofAdjSigmaMax.push_back(std::vector<G4double>());
218 }
219}

Referenced by RegisterEmProcess(), and RegisterEnergyLossProcess().

◆ RegisterEmAdjointModel()

std::size_t G4AdjointCSManager::RegisterEmAdjointModel ( G4VEmAdjointModel aModel)

Definition at line 150 of file G4AdjointCSManager.cc.

151{
152 fAdjointModels.push_back(aModel);
153 fSigmaTableForAdjointModelScatProjToProj.push_back(new G4PhysicsTable);
154 fSigmaTableForAdjointModelProdToProj.push_back(new G4PhysicsTable);
155 return fAdjointModels.size() - 1;
156}

Referenced by G4VEmAdjointModel::G4VEmAdjointModel().

◆ RegisterEmProcess()

void G4AdjointCSManager::RegisterEmProcess ( G4VEmProcess aProcess,
G4ParticleDefinition aPartDef 
)

Definition at line 159 of file G4AdjointCSManager.cc.

161{
162 G4ParticleDefinition* anAdjPartDef =
163 GetAdjointParticleEquivalent(aFwdPartDef);
164 if(anAdjPartDef && aProcess)
165 {
166 RegisterAdjointParticle(anAdjPartDef);
167
168 for(std::size_t i = 0; i < fAdjointParticlesInAction.size(); ++i)
169 {
170 if(anAdjPartDef->GetParticleName() ==
171 fAdjointParticlesInAction[i]->GetParticleName())
172 fForwardProcesses[i]->push_back(aProcess);
173 }
174 }
175}
void RegisterAdjointParticle(G4ParticleDefinition *aPartDef)
G4ParticleDefinition * GetAdjointParticleEquivalent(G4ParticleDefinition *theFwdPartDef)

◆ RegisterEnergyLossProcess()

void G4AdjointCSManager::RegisterEnergyLossProcess ( G4VEnergyLossProcess aProcess,
G4ParticleDefinition aPartDef 
)

Definition at line 178 of file G4AdjointCSManager.cc.

180{
181 G4ParticleDefinition* anAdjPartDef =
182 GetAdjointParticleEquivalent(aFwdPartDef);
183 if(anAdjPartDef && aProcess)
184 {
185 RegisterAdjointParticle(anAdjPartDef);
186 for(std::size_t i = 0; i < fAdjointParticlesInAction.size(); ++i)
187 {
188 if(anAdjPartDef->GetParticleName() ==
189 fAdjointParticlesInAction[i]->GetParticleName())
190 fForwardLossProcesses[i]->push_back(aProcess);
191
192 }
193 }
194}

◆ SampleElementFromCSMatrices()

G4Element * G4AdjointCSManager::SampleElementFromCSMatrices ( G4Material aMaterial,
G4VEmAdjointModel aModel,
G4double  PrimEnergy,
G4double  Tcut,
G4bool  isScatProjToProj 
)

Definition at line 734 of file G4AdjointCSManager.cc.

737{
738 std::vector<G4double> CS_Vs_Element;
739 G4double CS = ComputeAdjointCS(aMaterial, aModel, PrimEnergy, Tcut,
740 isScatProjToProj, CS_Vs_Element);
741 G4double SumCS = 0.;
742 std::size_t ind = 0;
743 for(std::size_t i = 0; i < CS_Vs_Element.size(); ++i)
744 {
745 SumCS += CS_Vs_Element[i];
746 if(G4UniformRand() <= SumCS / CS)
747 {
748 ind = i;
749 break;
750 }
751 }
752
753 return const_cast<G4Element*>(aMaterial->GetElement((G4int)ind));
754}
#define G4UniformRand()
Definition: Randomize.hh:52

◆ SetFwdCrossSectionMode()

void G4AdjointCSManager::SetFwdCrossSectionMode ( G4bool  aBool)
inline

Definition at line 117 of file G4AdjointCSManager.hh.

117{ fForwardCSMode = aBool; }

◆ SetIon()

void G4AdjointCSManager::SetIon ( G4ParticleDefinition adjIon,
G4ParticleDefinition fwdIon 
)
inline

Definition at line 152 of file G4AdjointCSManager.hh.

153 {
154 fAdjIon = adjIon;
155 fFwdIon = fwdIon;
156 }

Friends And Related Function Documentation

◆ G4ThreadLocalSingleton< G4AdjointCSManager >

Definition at line 1 of file G4AdjointCSManager.hh.


The documentation for this class was generated from the following files: