Belle II Software development
ExtMagFieldLimitProcess.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <simulation/kernel/ExtMagFieldLimitProcess.h>
10#include <G4TransportationManager.hh>
11#include <G4FieldManager.hh>
12#include <G4Field.hh>
13#include <G4Track.hh>
14#include <G4ForceCondition.hh>
15
16#include <framework/logging/Logger.h>
17
18using namespace std;
19using namespace Belle2;
20using namespace Belle2::Simulation;
21
23 G4VDiscreteProcess(processName),
24 m_stepLimit(kInfinity) // user may change this with a geant4 UI command
25{
26 m_field = G4TransportationManager::GetTransportationManager()->GetFieldManager()->GetDetectorField();
27 if (false) {
28 G4Track aTrack;
29 G4Step aStep;
30 G4ForceCondition* condition = nullptr;
31 GetMeanFreePath(aTrack, 0.0, condition);
32 PostStepDoIt(aTrack, aStep);
33 PostStepGetPhysicalInteractionLength(aTrack, 0.0, condition);
34 }
35
36}
37
39{
40}
41
42G4double ExtMagFieldLimitProcess::GetMeanFreePath(const G4Track&, G4double, G4ForceCondition*)
43{
44 return kInfinity;
45}
46
47
48G4double ExtMagFieldLimitProcess::PostStepGetPhysicalInteractionLength(const G4Track& aTrack, G4double, G4ForceCondition* condition)
49{
50 *condition = NotForced;
51 G4double stepLength = kInfinity;
52 if (m_field != 0) {
53 G4ThreeVector trkPosi = aTrack.GetPosition();
54 G4double pos1[3] = { trkPosi.x(), trkPosi.y(), trkPosi.z() };
55 G4double h1[3] = { 0.0, 0.0, 0.0 };
56 m_field->GetFieldValue(pos1, h1);
57 G4ThreeVector BVec(h1[0], h1[1], h1[2]);
58 G4double pmag = aTrack.GetMomentum().mag();
59 G4double BPerpMom = BVec.cross(aTrack.GetMomentum()).mag() / pmag; // LEP
60 if (BPerpMom != 0.0) {
61 stepLength = m_stepLimit * pmag / BPerpMom;
62 }
63 B2DEBUG(300, "ExtMagFieldLimitProcess::PostStepGetPhysicalInteractionLength() stepLength "
64 << stepLength << " B " << BPerpMom << " BVec " << BVec << " pmag " << pmag);
65 }
66 return stepLength;
67}
68
69G4VParticleChange* ExtMagFieldLimitProcess::PostStepDoIt(const G4Track& track, const G4Step&)
70{
71 aParticleChange.Initialize(track);
72 return &aParticleChange;
73}
74
ExtMagFieldLimitProcess(const G4String &processName="ExtMagFieldLimitProcess")
constructor
const G4Field * m_field
Stores the pointer to the magnetic field class.
G4double GetMeanFreePath(const G4Track &, G4double, G4ForceCondition *)
Returns the mean free path (always infinity!) after each step.
G4double PostStepGetPhysicalInteractionLength(const G4Track &, G4double, G4ForceCondition *)
Returns the step length after each step.
G4VParticleChange * PostStepDoIt(const G4Track &, const G4Step &)
Do nothing special after the particle has stepped.
Abstract base class for different kinds of events.
STL namespace.