CMS 3D CMS Logo

Geant4ePropagator.h
Go to the documentation of this file.
1 #ifndef TrackPropagation_Geant4ePropagator_h
2 #define TrackPropagation_Geant4ePropagator_h
3 
4 #include <memory>
5 
6 // CMS includes
7 // - Propagator
9 
10 // - Geant4e
11 #include "G4ErrorPropagatorData.hh"
12 #include "G4ErrorPropagatorManager.hh"
13 #include "G4ErrorSurfaceTarget.hh"
14 
20 class Geant4ePropagator : public Propagator {
21 public:
28  Geant4ePropagator(const MagneticField *field = nullptr,
31  double plimit = 1.0);
32 
33  ~Geant4ePropagator() override;
34 
42  std::pair<TrajectoryStateOnSurface, double> propagateWithPath(const FreeTrajectoryState &,
43  const Plane &) const override;
44 
45  std::pair<TrajectoryStateOnSurface, double> propagateWithPath(const FreeTrajectoryState &,
46  const Cylinder &) const override;
47 
48  std::pair<TrajectoryStateOnSurface, double> propagateWithPath(const TrajectoryStateOnSurface &,
49  const Plane &) const override;
50 
51  std::pair<TrajectoryStateOnSurface, double> propagateWithPath(const TrajectoryStateOnSurface &,
52  const Cylinder &) const override;
53 
54  Geant4ePropagator *clone() const override { return new Geant4ePropagator(*this); }
55 
56  const MagneticField *magneticField() const override { return theField; }
57 
58 private:
59  typedef std::pair<TrajectoryStateOnSurface, double> TsosPP;
60  typedef std::pair<bool, std::shared_ptr<G4ErrorTarget>> ErrorTargetPair;
61 
62  // Magnetic field
64 
65  // Name of the particle whose properties will be used in the propagation
67 
68  // The Geant4e manager. Does the real propagation
69  G4ErrorPropagatorManager *theG4eManager;
70  G4ErrorPropagatorData *theG4eData;
71  double plimit_;
72 
73  // Transform a CMS Reco detector surface into a Geant4 Target for the error
74  // propagation
75  template <class SurfaceType>
76  ErrorTargetPair transformToG4SurfaceTarget(const SurfaceType &pDest, bool moveTargetToEndOfSurface) const;
77 
78  // generates the Geant4 name for a particle from the
79  // string stored in theParticleName ( set via constructor )
80  // and the particle charge.
81  // 'mu' as a basis for muon becomes 'mu+' or 'mu-', depening on the charge
82  // This method only supports neutral and +/- 1e charges so far
83  //
84  // returns the generated string
86 
87  // flexible method which performs the actual propagation either for a plane or
88  // cylinder surface type
89  //
90  // returns TSOS after the propagation and the path length
91  template <class SurfaceType>
92  std::pair<TrajectoryStateOnSurface, double> propagateGeneric(const FreeTrajectoryState &ftsStart,
93  const SurfaceType &pDest) const;
94 
95  // saves the Geant4 propagation direction (Forward or Backward) in the
96  // provided variable reference mode and returns true if the propagation
97  // direction could be set
98  template <class SurfaceType>
99  bool configurePropagation(G4ErrorMode &mode,
100  SurfaceType const &pDest,
101  GlobalPoint const &cmsInitPos,
102  GlobalVector const &cmsInitMom) const;
103 
104  // special case to determine the propagation direction if the CMS propagation
105  // direction 'anyDirection' was set. This method is called by
106  // configurePropagation and provides specific implementations for Plane and
107  // Cylinder classes
108  template <class SurfaceType>
109  bool configureAnyPropagation(G4ErrorMode &mode,
110  SurfaceType const &pDest,
111  GlobalPoint const &cmsInitPos,
112  GlobalVector const &cmsInitMom) const;
113 
114  // Ensure Geant4 Error propagation is initialized, if not done so, yet
115  // if the forceInit parameter is set to true, the initialization is performed,
116  // even if already done before.
117  // This can be necessary, when Geant4 needs to read in a new MagneticField
118  // object, which changed during lumi section crossing
119  void ensureGeant4eIsInitilized(bool forceInit) const;
120 
121  // returns the name of the SurfaceType. Mostly for debug outputs
122  template <class SurfaceType>
123  std::string getSurfaceType(SurfaceType const &surface) const;
124 
125  void debugReportPlaneSetup(GlobalPoint const &posPlane,
126  HepGeom::Point3D<double> const &surfPos,
127  GlobalVector const &normalPlane,
128  HepGeom::Normal3D<double> const &surfNorm,
129  const Plane &pDest) const;
130 
131  template <class SurfaceType>
132  void debugReportTrackState(std::string const &currentContext,
133  GlobalPoint const &cmsInitPos,
134  CLHEP::Hep3Vector const &g4InitPos,
135  GlobalVector const &cmsInitMom,
136  CLHEP::Hep3Vector const &g4InitMom,
137  const SurfaceType &pDest) const;
138 };
139 
140 #endif
std::pair< TrajectoryStateOnSurface, double > TsosPP
void debugReportTrackState(std::string const &currentContext, GlobalPoint const &cmsInitPos, CLHEP::Hep3Vector const &g4InitPos, GlobalVector const &cmsInitMom, CLHEP::Hep3Vector const &g4InitMom, const SurfaceType &pDest) const
std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Plane &) const override
Geant4ePropagator * clone() const override
std::string theParticleName
PropagationDirection
const MagneticField * theField
Definition: Plane.h:16
G4ErrorPropagatorManager * theG4eManager
void ensureGeant4eIsInitilized(bool forceInit) const
G4ErrorPropagatorData * theG4eData
std::pair< bool, std::shared_ptr< G4ErrorTarget > > ErrorTargetPair
void debugReportPlaneSetup(GlobalPoint const &posPlane, HepGeom::Point3D< double > const &surfPos, GlobalVector const &normalPlane, HepGeom::Normal3D< double > const &surfNorm, const Plane &pDest) const
const MagneticField * magneticField() const override
bool configureAnyPropagation(G4ErrorMode &mode, SurfaceType const &pDest, GlobalPoint const &cmsInitPos, GlobalVector const &cmsInitMom) const
~Geant4ePropagator() override
std::string getSurfaceType(SurfaceType const &surface) const
std::string generateParticleName(int charge) const
bool configurePropagation(G4ErrorMode &mode, SurfaceType const &pDest, GlobalPoint const &cmsInitPos, GlobalVector const &cmsInitMom) const
ErrorTargetPair transformToG4SurfaceTarget(const SurfaceType &pDest, bool moveTargetToEndOfSurface) const
Geant4ePropagator(const MagneticField *field=nullptr, std::string particleName="mu", PropagationDirection dir=alongMomentum, double plimit=1.0)
std::pair< TrajectoryStateOnSurface, double > propagateGeneric(const FreeTrajectoryState &ftsStart, const SurfaceType &pDest) const