Geant4  10.01.p03
G4BiasingHelper.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 //
26 #include "G4BiasingHelper.hh"
27 
28 #include "G4ProcessManager.hh"
30 
32  G4String physicsProcessToBias,
33  G4String wrappedName)
34 {
35  G4VProcess* physicsProcess(0);
36 
37  G4ProcessVector* vprocess = pmanager->GetProcessList();
38  for (G4int ip = 0 ; ip < vprocess->size() ; ip++)
39  {
40  if ( (*vprocess)[ip]->GetProcessName() == physicsProcessToBias )
41  {
42  physicsProcess = (*vprocess)[ip];
43  break;
44  }
45  }
46 
47  // -- process not found, return "false" to tell about failure
48  if ( physicsProcess == 0 ) return false;
49 
50  // -- process is not a physics one, return "false" to tell about failure
51  G4int processType = physicsProcess->GetProcessType();
52  if ( ( processType != 2 ) && // EM
53  ( processType != 3 ) && // Optical
54  ( processType != 4 ) && // Hadronic
55  ( processType != 6 ) ) // Decay
56  return false;
57 
58  // -- prevent wrapper of wrapper...
59  if ( dynamic_cast< G4BiasingProcessInterface* >( physicsProcess ) ) return false;
60 
61  // -- remember process indeces:
62  G4int atRestIndex = pmanager->GetProcessOrdering(physicsProcess, idxAtRest );
63  G4int alongStepIndex = pmanager->GetProcessOrdering(physicsProcess, idxAlongStep);
64  G4int postStepIndex = pmanager->GetProcessOrdering(physicsProcess, idxPostStep );
65 
66  // -- now remove the physic process, that will be replaced by a wrapped version:
67  G4VProcess* removed = pmanager->RemoveProcess(physicsProcess);
68  if ( removed != physicsProcess )
69  {
71  ed << "Internal inconsistency in processes handling. Please report !" << G4endl;
72  G4Exception("G4BiasingHelper::ActivatePhysicsBiasing(...)",
73  "BIAS.GEN.01",
75  ed);
76  }
77 
78  G4BiasingProcessInterface* biasingWrapper = new G4BiasingProcessInterface( physicsProcess,
79  atRestIndex != ordInActive,
80  alongStepIndex != ordInActive,
81  postStepIndex != ordInActive,
82  wrappedName);
83 
84  if ( alongStepIndex == -1 ) alongStepIndex = ordDefault;
85 
86  pmanager->AddProcess( biasingWrapper,
87  atRestIndex,
88  alongStepIndex,
89  postStepIndex);
90 
91  return true;
92 }
93 
95  G4String nonPhysicsProcessName )
96 {
97  G4BiasingProcessInterface* biasingNonPhys(0);
98  if ( nonPhysicsProcessName == "" ) biasingNonPhys = new G4BiasingProcessInterface();
99  else biasingNonPhys = new G4BiasingProcessInterface(nonPhysicsProcessName );
100  pmanager->AddProcess( biasingNonPhys,
101  ordInActive,
102  ordInActive,
103  ordDefault);
104 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4int GetProcessOrdering(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt)
G4ProcessType GetProcessType() const
Definition: G4VProcess.hh:414
static void ActivateNonPhysicsBiasing(G4ProcessManager *pmanager, G4String nonPhysicsProcessName="")
int G4int
Definition: G4Types.hh:78
bool G4bool
Definition: G4Types.hh:79
G4int AddProcess(G4VProcess *aProcess, G4int ordAtRestDoIt=ordInActive, G4int ordAlongSteptDoIt=ordInActive, G4int ordPostStepDoIt=ordInActive)
static G4bool ActivatePhysicsBiasing(G4ProcessManager *pmanager, G4String physicsProcessToBias, G4String wrappedName="")
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4int size() const
#define G4endl
Definition: G4ios.hh:61
G4VProcess * RemoveProcess(G4VProcess *aProcess)
G4ProcessVector * GetProcessList() const