Belle II Software  release-05-02-19
ExtMagFieldLimitProcess.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2011 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Leo Piilonen *
7  * Derived from: G4ErrorMagFieldLimitProcess.cc *
8  * *
9  * This software is provided "as is" without any warranty. *
10  **************************************************************************/
11 
12 #include <simulation/kernel/ExtMagFieldLimitProcess.h>
13 #include <G4TransportationManager.hh>
14 #include <G4FieldManager.hh>
15 #include <G4Field.hh>
16 #include <G4Track.hh>
17 #include <G4ForceCondition.hh>
18 
19 #include <framework/logging/Logger.h>
20 
21 using namespace std;
22 using namespace Belle2;
23 using namespace Belle2::Simulation;
24 
25 ExtMagFieldLimitProcess::ExtMagFieldLimitProcess(const G4String& processName) :
26  G4VDiscreteProcess(processName),
27  m_stepLimit(kInfinity) // user may change this with a geant4 UI command
28 {
29  m_field = G4TransportationManager::GetTransportationManager()->GetFieldManager()->GetDetectorField();
30  if (false) {
31  G4Track aTrack;
32  G4Step aStep;
33  G4ForceCondition* condition = nullptr;
34  GetMeanFreePath(aTrack, 0.0, condition);
35  PostStepDoIt(aTrack, aStep);
36  PostStepGetPhysicalInteractionLength(aTrack, 0.0, condition);
37  }
38 
39 }
40 
42 {
43 }
44 
45 G4double ExtMagFieldLimitProcess::GetMeanFreePath(const G4Track&, G4double, G4ForceCondition*)
46 {
47  return kInfinity;
48 }
49 
50 
51 G4double ExtMagFieldLimitProcess::PostStepGetPhysicalInteractionLength(const G4Track& aTrack, G4double, G4ForceCondition* condition)
52 {
53  /* cppcheck-suppress ctunullpointer */
54  *condition = NotForced;
55  G4double stepLength = kInfinity;
56  if (m_field != 0) {
57  G4ThreeVector trkPosi = aTrack.GetPosition();
58  G4double pos1[3] = { trkPosi.x(), trkPosi.y(), trkPosi.z() };
59  G4double h1[3] = { 0.0, 0.0, 0.0 };
60  m_field->GetFieldValue(pos1, h1);
61  G4ThreeVector BVec(h1[0], h1[1], h1[2]);
62  G4double pmag = aTrack.GetMomentum().mag();
63  G4double BPerpMom = BVec.cross(aTrack.GetMomentum()).mag() / pmag; // LEP
64  if (BPerpMom != 0.0) {
65  stepLength = m_stepLimit * pmag / BPerpMom;
66  }
67  B2DEBUG(300, "ExtMagFieldLimitProcess::PostStepGetPhysicalInteractionLength() stepLength "
68  << stepLength << " B " << BPerpMom << " BVec " << BVec << " pmag " << pmag);
69  }
70  return stepLength;
71 }
72 
73 G4VParticleChange* ExtMagFieldLimitProcess::PostStepDoIt(const G4Track& track, const G4Step&)
74 {
75  aParticleChange.Initialize(track);
76  return &aParticleChange;
77 }
78 
Belle2::Simulation::ExtMagFieldLimitProcess::m_stepLimit
G4double m_stepLimit
Stores the step limit.
Definition: ExtMagFieldLimitProcess.h:60
Belle2::Simulation::ExtMagFieldLimitProcess::PostStepDoIt
G4VParticleChange * PostStepDoIt(const G4Track &, const G4Step &)
Do nothing special after the particle has stepped.
Definition: ExtMagFieldLimitProcess.cc:73
Belle2::Simulation::ExtMagFieldLimitProcess::~ExtMagFieldLimitProcess
~ExtMagFieldLimitProcess()
destructor
Definition: ExtMagFieldLimitProcess.cc:41
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::Simulation::ExtMagFieldLimitProcess::GetMeanFreePath
G4double GetMeanFreePath(const G4Track &, G4double, G4ForceCondition *)
Returns the mean free path (always infinity!) after each step.
Definition: ExtMagFieldLimitProcess.cc:45
Belle2::Simulation::ExtMagFieldLimitProcess::m_field
const G4Field * m_field
Stores the pointer to the magnetic field class.
Definition: ExtMagFieldLimitProcess.h:57
Belle2::Simulation::ExtMagFieldLimitProcess::PostStepGetPhysicalInteractionLength
G4double PostStepGetPhysicalInteractionLength(const G4Track &, G4double, G4ForceCondition *)
Returns the step length after each step.
Definition: ExtMagFieldLimitProcess.cc:51