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

Diff markup

Differences between /processes/biasing/generic/src/G4BOptnForceCommonTruncatedExp.cc (Version 11.3.0) and /processes/biasing/generic/src/G4BOptnForceCommonTruncatedExp.cc (Version 11.0.p1)


  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 // G4BOptnForceCommonTruncatedExp              << 
 27 // ------------------------------------------- << 
 28 #include "G4BOptnForceCommonTruncatedExp.hh"       26 #include "G4BOptnForceCommonTruncatedExp.hh"
 29 #include "G4ILawCommonTruncatedExp.hh"             27 #include "G4ILawCommonTruncatedExp.hh"
 30 #include "G4ILawForceFreeFlight.hh"                28 #include "G4ILawForceFreeFlight.hh"
 31 #include "G4TransportationManager.hh"              29 #include "G4TransportationManager.hh"
 32                                                    30 
 33 #include "Randomize.hh"                            31 #include "Randomize.hh"
 34 #include "G4BiasingProcessInterface.hh"            32 #include "G4BiasingProcessInterface.hh"
 35                                                    33 
 36 G4BOptnForceCommonTruncatedExp::               <<  34 G4BOptnForceCommonTruncatedExp::G4BOptnForceCommonTruncatedExp(G4String name)
 37 G4BOptnForceCommonTruncatedExp(const G4String& <<  35   : G4VBiasingOperation(name),
 38   : G4VBiasingOperation(name)                  <<  36     fNumberOfSharing(0),
                                                   >>  37     fProcessToApply(nullptr),
                                                   >>  38     fInteractionOccured(false),
                                                   >>  39     fMaximumDistance(-1.0)
 39 {                                                  40 {
 40   fCommonTruncatedExpLaw = new G4ILawCommonTru     41   fCommonTruncatedExpLaw = new G4ILawCommonTruncatedExp("ExpLawForOperation"+name);
 41   fForceFreeFlightLaw    = new G4ILawForceFree     42   fForceFreeFlightLaw    = new G4ILawForceFreeFlight   ("FFFLawForOperation"+name);
                                                   >>  43   
                                                   >>  44   fTotalCrossSection = 0.0;
 42 }                                                  45 }
 43                                                    46 
 44 G4BOptnForceCommonTruncatedExp::~G4BOptnForceC     47 G4BOptnForceCommonTruncatedExp::~G4BOptnForceCommonTruncatedExp()
 45 {                                                  48 {
 46   delete fCommonTruncatedExpLaw;               <<  49   if ( fCommonTruncatedExpLaw ) delete fCommonTruncatedExpLaw;
 47   delete fForceFreeFlightLaw;                  <<  50   if ( fForceFreeFlightLaw )    delete fForceFreeFlightLaw;
 48 }                                                  51 }
 49                                                    52 
 50 const G4VBiasingInteractionLaw* G4BOptnForceCo     53 const G4VBiasingInteractionLaw* G4BOptnForceCommonTruncatedExp::
 51 ProvideOccurenceBiasingInteractionLaw( const G <<  54 ProvideOccurenceBiasingInteractionLaw( const G4BiasingProcessInterface*       callingProcess, 
 52                                        G4Force <<  55                G4ForceCondition&                proposeForceCondition )
 53 {                                                  56 {
 54   if ( callingProcess->GetWrappedProcess() ==      57   if ( callingProcess->GetWrappedProcess() == fProcessToApply )
 55   {                                            <<  58     {
 56     proposeForceCondition = Forced;            <<  59       proposeForceCondition =                 Forced;
 57     return fCommonTruncatedExpLaw;             <<  60       return                  fCommonTruncatedExpLaw;
 58   }                                            <<  61     }
 59   else                                             62   else
 60   {                                            <<  63     {
 61     proposeForceCondition = Forced;            <<  64       proposeForceCondition =                 Forced;
 62     return fForceFreeFlightLaw;                <<  65       return                     fForceFreeFlightLaw;
 63   }                                            <<  66     }
 64 }                                                  67 }
 65                                                    68 
 66 G4GPILSelection G4BOptnForceCommonTruncatedExp <<  69 
 67 ProposeGPILSelection( const G4GPILSelection )  <<  70 G4GPILSelection   G4BOptnForceCommonTruncatedExp::ProposeGPILSelection( const G4GPILSelection )
 68 {                                                  71 {
 69   return NotCandidateForSelection;                 72   return NotCandidateForSelection;
 70 }                                                  73 }
 71                                                    74 
 72 G4VParticleChange* G4BOptnForceCommonTruncated <<  75 
 73 ApplyFinalStateBiasing( const G4BiasingProcess <<  76 G4VParticleChange* G4BOptnForceCommonTruncatedExp::ApplyFinalStateBiasing( const G4BiasingProcessInterface* callingProcess,
 74                         const G4Track* track,  <<  77                      const G4Track*                   track,
 75                         const G4Step* step,    <<  78                      const G4Step*                    step,
 76                               G4bool& forceFin <<  79                      G4bool&                          forceFinalState )
 77 {                                                  80 {
 78   if ( callingProcess->GetWrappedProcess() !=      81   if ( callingProcess->GetWrappedProcess() != fProcessToApply )
 79   {                                            <<  82     {
 80     forceFinalState = true;                    <<  83       forceFinalState = true;
 81     fDummyParticleChange.Initialize( *track ); <<  84       fDummyParticleChange.Initialize( *track );
 82     return &fDummyParticleChange;              <<  85       return &fDummyParticleChange; 
 83   }                                            <<  86     }
 84   if ( fInteractionOccured )                       87   if ( fInteractionOccured )
 85   {                                            <<  88     {
 86     forceFinalState = true;                    <<  89       forceFinalState = true;
 87     fDummyParticleChange.Initialize( *track ); <<  90       fDummyParticleChange.Initialize( *track );
 88     return &fDummyParticleChange;              <<  91       return &fDummyParticleChange;
 89   }                                            <<  92     }
 90                                                    93   
 91   // -- checks if process won the GPIL race:       94   // -- checks if process won the GPIL race:
 92   G4double processGPIL = callingProcess->GetPo <<  95   G4double processGPIL = callingProcess->GetPostStepGPIL() < callingProcess->GetAlongStepGPIL() ?
 93                        < callingProcess->GetAl <<  96     callingProcess->GetPostStepGPIL() : callingProcess->GetAlongStepGPIL() ;
 94                        ? callingProcess->GetPo << 
 95                        : callingProcess->GetAl << 
 96   if ( processGPIL <= step->GetStepLength() )      97   if ( processGPIL <= step->GetStepLength() )
 97   {                                            <<  98     {
 98     // -- if process won, wrapped process prod <<  99       // -- if process won, wrapped process produces the final state.
 99     // -- In this case, the weight for occurre << 100       // -- In this case, the weight for occurrence biasing is applied
100     // -- by the callingProcess, at exit of pr << 101       // -- by the callingProcess, at exit of present method. This is
101     // -- selected by "forceFinalState = false << 102       // -- selected by "forceFinalState = false":
102     forceFinalState     = false;               << 103       forceFinalState     = false;
103     fInteractionOccured = true;                << 104       fInteractionOccured = true;
104     return callingProcess->GetWrappedProcess() << 105       return callingProcess->GetWrappedProcess()->PostStepDoIt( *track, *step );
105   }                                            << 106     }
106   else                                            107   else
107   {                                            << 108     {
108     forceFinalState = true;                    << 109       forceFinalState = true;
109     fDummyParticleChange.Initialize( *track ); << 110       fDummyParticleChange.Initialize( *track );
110     return &fDummyParticleChange;              << 111       return &fDummyParticleChange; 
111   }                                            << 112     }
112 }                                                 113 }
113                                                   114 
114 void G4BOptnForceCommonTruncatedExp::          << 115 
115 AddCrossSection( const G4VProcess* process, G4 << 116 void G4BOptnForceCommonTruncatedExp::AddCrossSection( const G4VProcess* process, G4double crossSection )
116 {                                                 117 {
117   fTotalCrossSection      += crossSection;        118   fTotalCrossSection      += crossSection;
118   fCrossSections[process]  = crossSection;        119   fCrossSections[process]  = crossSection;
119   fNumberOfSharing         = fCrossSections.si    120   fNumberOfSharing         = fCrossSections.size();
120 }                                                 121 }
121                                                   122 
                                                   >> 123 
122 void G4BOptnForceCommonTruncatedExp::Initializ    124 void G4BOptnForceCommonTruncatedExp::Initialize( const G4Track* track )
123 {                                                 125 {
124   fCrossSections.clear();                         126   fCrossSections.clear();
125   fTotalCrossSection  = 0.0;                      127   fTotalCrossSection  = 0.0;
126   fNumberOfSharing    = 0;                        128   fNumberOfSharing    = 0;
127   fProcessToApply     = 0;                        129   fProcessToApply     = 0;
128   fInteractionOccured = false;                    130   fInteractionOccured = false;
129   fInitialMomentum    = track->GetMomentum();     131   fInitialMomentum    = track->GetMomentum();
130                                                   132 
131   G4VSolid* currentSolid = track->GetVolume()-    133   G4VSolid* currentSolid = track->GetVolume()->GetLogicalVolume()->GetSolid();
132   G4ThreeVector  localPosition = (G4Transporta    134   G4ThreeVector  localPosition = (G4TransportationManager::GetTransportationManager()->
133                                   GetNavigator << 135           GetNavigatorForTracking()->
134                                   GetGlobalToL << 136           GetGlobalToLocalTransform()).TransformPoint(track->GetPosition());
135   G4ThreeVector localDirection = (G4Transporta    137   G4ThreeVector localDirection = (G4TransportationManager::GetTransportationManager()->
136                                   GetNavigator << 138           GetNavigatorForTracking()->
137                                   GetGlobalToL << 139           GetGlobalToLocalTransform()).TransformAxis(track->GetMomentumDirection());
138   fMaximumDistance = currentSolid->DistanceToO    140   fMaximumDistance = currentSolid->DistanceToOut(localPosition, localDirection);
139   if ( fMaximumDistance <= DBL_MIN ) { fMaximu << 141   if ( fMaximumDistance <= DBL_MIN )  fMaximumDistance = 0.0;
140   fCommonTruncatedExpLaw->SetMaximumDistance(     142   fCommonTruncatedExpLaw->SetMaximumDistance( fMaximumDistance );
141 }                                                 143 }
142                                                   144 
                                                   >> 145 
143 void G4BOptnForceCommonTruncatedExp::UpdateFor    146 void G4BOptnForceCommonTruncatedExp::UpdateForStep( const G4Step* step )
144 {                                                 147 {
145   fCrossSections.clear();                         148   fCrossSections.clear();
146   fTotalCrossSection  = 0.0;                      149   fTotalCrossSection  = 0.0;
147   fNumberOfSharing    = 0;                        150   fNumberOfSharing    = 0;
148   fProcessToApply     = 0;                        151   fProcessToApply     = 0;
149                                                   152   
150   fCommonTruncatedExpLaw->UpdateForStep( step-    153   fCommonTruncatedExpLaw->UpdateForStep( step->GetStepLength() );
151   fMaximumDistance = fCommonTruncatedExpLaw->G    154   fMaximumDistance = fCommonTruncatedExpLaw->GetMaximumDistance();
152 }                                                 155 }
153                                                   156 
                                                   >> 157 
154 void G4BOptnForceCommonTruncatedExp::Sample()     158 void G4BOptnForceCommonTruncatedExp::Sample()
155 {                                                 159 {
156   fCommonTruncatedExpLaw->SetForceCrossSection    160   fCommonTruncatedExpLaw->SetForceCrossSection( fTotalCrossSection );
157   fCommonTruncatedExpLaw->Sample();               161   fCommonTruncatedExpLaw->Sample();
158   ChooseProcessToApply();                         162   ChooseProcessToApply();
159   fCommonTruncatedExpLaw->SetSelectedProcessXS    163   fCommonTruncatedExpLaw->SetSelectedProcessXSfraction(fCrossSections[fProcessToApply] / fTotalCrossSection);
160 }                                                 164 }
161                                                   165 
                                                   >> 166 
162 void G4BOptnForceCommonTruncatedExp::ChoosePro    167 void G4BOptnForceCommonTruncatedExp::ChooseProcessToApply()
163 {                                                 168 {
164   G4double sigmaRand   = G4UniformRand() * fTo    169   G4double sigmaRand   = G4UniformRand() * fTotalCrossSection;
165   G4double sigmaSelect = 0.0;                     170   G4double sigmaSelect = 0.0;
166   for ( auto it = fCrossSections.cbegin(); it  << 171   for ( std::map< const G4VProcess*, G4double>::const_iterator it = fCrossSections.begin();
167   {                                            << 172   it != fCrossSections.end();
168     sigmaSelect += (*it).second;               << 173   it++)
169     if ( sigmaRand <= sigmaSelect )            << 
170     {                                             174     {
171       fProcessToApply = (*it).first;           << 175       sigmaSelect += (*it).second;
172       break;                                   << 176       if ( sigmaRand <= sigmaSelect )
                                                   >> 177   {
                                                   >> 178     fProcessToApply = (*it).first;
                                                   >> 179     break;
                                                   >> 180   }
173     }                                             181     }
174   }                                            << 
175 }                                                 182 }
176                                                   183