ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GB05BOptrSplitAndKillByCrossSection.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GB05BOptrSplitAndKillByCrossSection.cc
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 //
26 //
29 
33 
34 #include "G4ParticleDefinition.hh"
35 #include "G4ParticleTable.hh"
36 #include "G4VProcess.hh"
37 
38 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
39 
42  G4String name)
43  : G4VBiasingOperator(name),
44  fSetup(true)
45 {
47 
48  if ( fParticleToBias == 0 )
49  {
51  ed << "Particle `" << particleName << "' not found !" << G4endl;
52  G4Exception("GB05BOptrSplitAndKillByCrossSection(...)",
53  "exGB05.01",
55  ed);
56  }
57 
59  new GB05BOptnSplitAndKillByCrossSection("splitterFor_"+particleName);
60 
61 }
62 
63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
64 
66 {
68 }
69 
70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
71 
73 {
74  // ---------------
75  // -- Setup stage:
76  // ---------------
77  // -- Start by collecting the pointer of the physics processes
78  // -- considered for the splitting by cross-sections. Doing so,
79  // -- this also verifies that these physics processes are each
80  // -- under control of a G4BiasingProcessInterface wrapper.
81  if ( fSetup )
82  {
83  const G4ProcessManager* processManager = fParticleToBias->GetProcessManager();
84  const G4BiasingProcessSharedData* sharedData =
86  if ( sharedData )
87  {
88  for ( size_t i = 0 ; i < fProcessesToEquipoise.size() ; i++ )
89  {
90  G4bool processFound(false);
91  for ( size_t j = 0 ;
92  j < (sharedData->GetPhysicsBiasingProcessInterfaces()).size();
93  j++ )
94  {
95  const G4BiasingProcessInterface* wrapperProcess =
96  (sharedData->GetPhysicsBiasingProcessInterfaces())[j];
97  if ( fProcessesToEquipoise[i] ==
98  wrapperProcess->GetWrappedProcess()->GetProcessName() )
99  {
100  fProcesses.push_back( wrapperProcess->GetWrappedProcess() );
101  processFound = true;
102  break;
103  }
104  }
105  if ( !processFound )
106  {
107  G4String particleName = "(unknown)";
108  if ( fParticleToBias != nullptr )
109  {
110  particleName = fParticleToBias->GetParticleName();
111  }
113  ed << "Process `" << fProcessesToEquipoise[i]
114  << "' not found for particle `" << particleName << "'"
115  << G4endl;
116  G4Exception("GB05BOptrSplitAndKillByCrossSection::StartRun(...)",
117  "exGB05.02",
118  JustWarning,
119  ed);
120  }
121  }
122  }
123  fSetup = false;
124  }
125 
126  if ( fProcessesToEquipoise.size() == 0 || fProcesses.size() == 0 )
127  {
129  ed << "No processes to counterbalance for defined or found ! "
130  << "Biasing will do nothing."
131  << G4endl;
132  G4Exception("GB05BOptrSplitAndKillByCrossSection::StartRun(...)",
133  "exGB05.03",
134  JustWarning,
135  ed);
136  }
137 
138 }
139 
140 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
141 
145  const G4BiasingProcessInterface* /*callingProcess*/)
146 {
147 
148  // -----------------------------------------------------
149  // -- Check if current particle type is the one to bias:
150  // -----------------------------------------------------
151  if ( track->GetDefinition() != fParticleToBias ) return 0;
152 
153  // --------------------------------------------------------------------
154  // -- Compute the total cross-section for the physics processes
155  // -- considered.
156  // -- These physics processes have been updated to the current track
157  // -- state by their related wrapper G4BiasingProcessInterface objects,
158  // -- the cross-sections/mean free pathes are hence usable.
159  // --------------------------------------------------------------------
160  G4double totalCrossSection(0.0);
161  for ( size_t i = 0 ; i < fProcesses.size() ; i++ )
162  {
163  G4double interactionLength = fProcesses[i]->GetCurrentInteractionLength();
164  if ( interactionLength < DBL_MAX/10. )
165  totalCrossSection += 1./interactionLength;
166  }
167  if ( totalCrossSection < DBL_MIN ) return 0;
168 
169  G4double totalInteractionLength = 1./totalCrossSection;
170 
171  // ---------------------------------------------------------------------
172  // -- Passes the updated "absorption" cross-section (interaction length)
173  // -- to the biasing operation, and returns this operation:
174  // ---------------------------------------------------------------------
175  fSplitAndKillByCrossSection->SetInteractionLength( totalInteractionLength );
176 
178 
179 }
180 
183 {
184  fProcessesToEquipoise.push_back( processName );
185 }