Geant4  10.02.p01
GB01BOptrChangeCrossSection.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
29 
30 #include "G4ParticleDefinition.hh"
31 #include "G4ParticleTable.hh"
32 #include "G4VProcess.hh"
33 
34 #include "Randomize.hh"
35 
37 
39  G4String name)
40  : G4VBiasingOperator(name),
41  fSetup(true)
42 {
44 
45  if ( fParticleToBias == 0 )
46  {
48  ed << "Particle `" << particleName << "' not found !" << G4endl;
49  G4Exception("GB01BOptrChangeCrossSection(...)",
50  "exGB01.01",
52  ed);
53  }
54 }
55 
57 {
58  for ( std::map< const G4BiasingProcessInterface*, G4BOptnChangeCrossSection* >::iterator
59  it = fChangeCrossSectionOperations.begin() ;
60  it != fChangeCrossSectionOperations.end() ;
61  it++ ) delete (*it).second;
62 }
63 
64 
66 {
67  // --------------
68  // -- Setup stage:
69  // ---------------
70  // -- Start by collecting processes under biasing, create needed biasing
71  // -- operations and associate these operations to the processes:
72  if ( fSetup )
73  {
74  const G4ProcessManager* processManager = fParticleToBias->GetProcessManager();
75  const G4BiasingProcessSharedData* sharedData =
77  if ( sharedData ) // -- sharedData tested, as is can happen a user attaches an operator to a
78  // -- volume but without defined BiasingProcessInterface processes.
79  {
80  for ( size_t i = 0 ; i < (sharedData->GetPhysicsBiasingProcessInterfaces()).size(); i++ )
81  {
82  const G4BiasingProcessInterface* wrapperProcess =
83  (sharedData->GetPhysicsBiasingProcessInterfaces())[i];
84  G4String operationName = "XSchange-" +
85  wrapperProcess->GetWrappedProcess()->GetProcessName();
86  fChangeCrossSectionOperations[wrapperProcess] =
87  new G4BOptnChangeCrossSection(operationName);
88  }
89  }
90  fSetup = false;
91  }
92 }
93 
94 
98  callingProcess)
99 {
100 
101  // -----------------------------------------------------
102  // -- Check if current particle type is the one to bias:
103  // -----------------------------------------------------
104  if ( track->GetDefinition() != fParticleToBias ) return 0;
105 
106 
107  // ---------------------------------------------------------------------
108  // -- select and setup the biasing operation for current callingProcess:
109  // ---------------------------------------------------------------------
110  // -- Check if the analog cross-section well defined : for example, the conversion
111  // -- process for a gamma below e+e- creation threshold has an DBL_MAX interaction
112  // -- length. Nothing is done in this case (ie, let analog process to deal with the case)
113  G4double analogInteractionLength =
114  callingProcess->GetWrappedProcess()->GetCurrentInteractionLength();
115  if ( analogInteractionLength > DBL_MAX/10. ) return 0;
116 
117  // -- Analog cross-section is well-defined:
118  G4double analogXS = 1./analogInteractionLength;
119 
120  // -- Choose a constant cross-section bias. But at this level, this factor can be made
121  // -- direction dependent, like in the exponential transform MCNP case, or it
122  // -- can be chosen differently, depending on the process, etc.
123  G4double XStransformation = 2.0 ;
124 
125  // -- fetch the operation associated to this callingProcess:
126  G4BOptnChangeCrossSection* operation = fChangeCrossSectionOperations[callingProcess];
127  // -- get the operation that was proposed to the process in the previous step:
128  G4VBiasingOperation* previousOperation = callingProcess->GetPreviousOccurenceBiasingOperation();
129 
130  // -- now setup the operation to be returned to the process: this
131  // -- consists in setting the biased cross-section, and in asking
132  // -- the operation to sample its exponential interaction law.
133  // -- To do this, to first order, the two lines:
134  // operation->SetBiasedCrossSection( XStransformation * analogXS );
135  // operation->Sample();
136  // -- are correct and sufficient.
137  // -- But, to avoid having to shoot a random number each time, we sample
138  // -- only on the first time the operation is proposed, or if the interaction
139  // -- occured. If the interaction did not occur for the process in the previous,
140  // -- we update the number of interaction length instead of resampling.
141  if ( previousOperation == 0 )
142  {
143  operation->SetBiasedCrossSection( XStransformation * analogXS );
144  operation->Sample();
145  }
146  else
147  {
148  if ( previousOperation != operation )
149  {
150  // -- should not happen !
152  ed << " Logic problem in operation handling !" << G4endl;
153  G4Exception("GB01BOptrChangeCrossSection::ProposeOccurenceBiasingOperation(...)",
154  "exGB01.02",
155  JustWarning,
156  ed);
157  return 0;
158  }
159  if ( operation->GetInteractionOccured() )
160  {
161  operation->SetBiasedCrossSection( XStransformation * analogXS );
162  operation->Sample();
163  }
164  else
165  {
166  // -- update the 'interaction length' and underneath 'number of interaction lengths'
167  // -- for past step (this takes into accout the previous step cross-section value)
168  operation->UpdateForStep( callingProcess->GetPreviousStepSize() );
169  // -- update the cross-section value:
170  operation->SetBiasedCrossSection( XStransformation * analogXS );
171  // -- forces recomputation of the 'interaction length' taking into account above
172  // -- new cross-section value [tricky : to be improved]
173  operation->UpdateForStep( 0.0 );
174  }
175  }
176 
177  return operation;
178 
179 }
180 
181 
185  G4VBiasingOperation* occurenceOperationApplied,
186  G4double,
188  const G4VParticleChange* )
189 {
190  G4BOptnChangeCrossSection* operation = fChangeCrossSectionOperations[callingProcess];
191  if ( operation == occurenceOperationApplied ) operation->SetInteractionOccured();
192 }
193 
G4ParticleDefinition * GetDefinition() const
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4String name
Definition: TRTMaterials.hh:40
const std::vector< const G4BiasingProcessInterface * > & GetPhysicsBiasingProcessInterfaces() const
GB01BOptrChangeCrossSection(G4String particleToBias, G4String name="ChangeXS")
G4ProcessManager * GetProcessManager() const
G4BiasingAppliedCase
G4VProcess * GetWrappedProcess() const
virtual void OperationApplied(const G4BiasingProcessInterface *callingProcess, G4BiasingAppliedCase biasingCase, G4VBiasingOperation *occurenceOperationApplied, G4double weightForOccurenceInteraction, G4VBiasingOperation *finalStateOperationApplied, const G4VParticleChange *particleChangeProduced)
G4double GetCurrentInteractionLength() const
Definition: G4VProcess.hh:462
const G4ParticleDefinition * fParticleToBias
virtual G4VBiasingOperation * ProposeOccurenceBiasingOperation(const G4Track *track, const G4BiasingProcessInterface *callingProcess)
const G4String & GetProcessName() const
Definition: G4VProcess.hh:408
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4ParticleTable * GetParticleTable()
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
#define DBL_MAX
Definition: templates.hh:83
void UpdateForStep(G4double stepLength)
std::map< const G4BiasingProcessInterface *, G4BOptnChangeCrossSection * > fChangeCrossSectionOperations
G4VBiasingOperation * GetPreviousOccurenceBiasingOperation() const
const G4BiasingProcessSharedData * GetSharedData() const