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}
28
32
33G4double ExtMagFieldLimitProcess::GetMeanFreePath(const G4Track&, G4double, G4ForceCondition*)
34{
35 return kInfinity;
36}
37
38
39G4double ExtMagFieldLimitProcess::PostStepGetPhysicalInteractionLength(const G4Track& aTrack, G4double, G4ForceCondition* condition)
40{
41 *condition = NotForced;
42 G4double stepLength = kInfinity;
43 if (m_field != 0) {
44 G4ThreeVector trkPosi = aTrack.GetPosition();
45 G4double pos1[3] = { trkPosi.x(), trkPosi.y(), trkPosi.z() };
46 G4double h1[3] = { 0.0, 0.0, 0.0 };
47 m_field->GetFieldValue(pos1, h1);
48 G4ThreeVector BVec(h1[0], h1[1], h1[2]);
49 G4double pmag = aTrack.GetMomentum().mag();
50 G4double BPerpMom = BVec.cross(aTrack.GetMomentum()).mag() / pmag; // LEP
51 if (BPerpMom != 0.0) {
52 stepLength = m_stepLimit * pmag / BPerpMom;
53 }
54 B2DEBUG(300, "ExtMagFieldLimitProcess::PostStepGetPhysicalInteractionLength() stepLength "
55 << stepLength << " B " << BPerpMom << " BVec " << BVec << " pmag " << pmag);
56 }
57 return stepLength;
58}
59
60G4VParticleChange* ExtMagFieldLimitProcess::PostStepDoIt(const G4Track& track, const G4Step&)
61{
62 aParticleChange.Initialize(track);
63 return &aParticleChange;
64}
65
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.