CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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,
29  std::string particleName = "mu",
31  double plimit = 1.0);
32 
33  ~Geant4ePropagator() override;
34 
38  /*
39  virtual TrajectoryStateOnSurface
40  propagate(const FreeTrajectoryState& ftsStart, const Plane& pDest)
41  const override;
42 
43  virtual TrajectoryStateOnSurface
44  propagate(const FreeTrajectoryState& ftsStart, const Cylinder& cDest)
45  const override;
46  */
50  /*
51  virtual TrajectoryStateOnSurface
52  propagate(const TrajectoryStateOnSurface& tsos, const Plane& plane)
53  const override;
54 
55  virtual TrajectoryStateOnSurface
56  propagate(const TrajectoryStateOnSurface& tsos, const Cylinder& cyl)
57  const override;
58  */
66  std::pair<TrajectoryStateOnSurface, double> propagateWithPath(const FreeTrajectoryState &,
67  const Plane &) const override;
68 
69  std::pair<TrajectoryStateOnSurface, double> propagateWithPath(const FreeTrajectoryState &,
70  const Cylinder &) const override;
71 
72  std::pair<TrajectoryStateOnSurface, double> propagateWithPath(const TrajectoryStateOnSurface &,
73  const Plane &) const override;
74 
75  std::pair<TrajectoryStateOnSurface, double> propagateWithPath(const TrajectoryStateOnSurface &,
76  const Cylinder &) const override;
77 
78  Geant4ePropagator *clone() const override { return new Geant4ePropagator(*this); }
79 
80  const MagneticField *magneticField() const override { return theField; }
81 
82 private:
83  typedef std::pair<TrajectoryStateOnSurface, double> TsosPP;
84  typedef std::pair<bool, std::shared_ptr<G4ErrorTarget>> ErrorTargetPair;
85 
86  // Magnetic field
88 
89  // Name of the particle whose properties will be used in the propagation
91 
92  // The Geant4e manager. Does the real propagation
93  G4ErrorPropagatorManager *theG4eManager;
94  G4ErrorPropagatorData *theG4eData;
95  double plimit_;
96 
97  // Transform a CMS Reco detector surface into a Geant4 Target for the error
98  // propagation
99  template <class SurfaceType>
100  ErrorTargetPair transformToG4SurfaceTarget(const SurfaceType &pDest, bool moveTargetToEndOfSurface) const;
101 
102  // generates the Geant4 name for a particle from the
103  // string stored in theParticleName ( set via constructor )
104  // and the particle charge.
105  // 'mu' as a basis for muon becomes 'mu+' or 'mu-', depening on the charge
106  // This method only supports neutral and +/- 1e charges so far
107  //
108  // returns the generated string
110 
111  // flexible method which performs the actual propagation either for a plane or
112  // cylinder surface type
113  //
114  // returns TSOS after the propagation and the path length
115  template <class SurfaceType>
116  std::pair<TrajectoryStateOnSurface, double> propagateGeneric(const FreeTrajectoryState &ftsStart,
117  const SurfaceType &pDest) const;
118 
119  // saves the Geant4 propagation direction (Forward or Backward) in the
120  // provided variable reference mode and returns true if the propagation
121  // direction could be set
122  template <class SurfaceType>
123  bool configurePropagation(G4ErrorMode &mode,
124  SurfaceType const &pDest,
125  GlobalPoint const &cmsInitPos,
126  GlobalVector const &cmsInitMom) const;
127 
128  // special case to determine the propagation direction if the CMS propagation
129  // direction 'anyDirection' was set. This method is called by
130  // configurePropagation and provides specific implementations for Plane and
131  // Cylinder classes
132  template <class SurfaceType>
133  bool configureAnyPropagation(G4ErrorMode &mode,
134  SurfaceType const &pDest,
135  GlobalPoint const &cmsInitPos,
136  GlobalVector const &cmsInitMom) const;
137 
138  // Ensure Geant4 Error propagation is initialized, if not done so, yet
139  // if the forceInit parameter is set to true, the initialization is performed,
140  // even if already done before.
141  // This can be necessary, when Geant4 needs to read in a new MagneticField
142  // object, which changed during lumi section crossing
143  void ensureGeant4eIsInitilized(bool forceInit) const;
144 
145  // returns the name of the SurfaceType. Mostly for debug outputs
146  template <class SurfaceType>
147  std::string getSurfaceType(SurfaceType const &surface) const;
148 
149  void debugReportPlaneSetup(GlobalPoint const &posPlane,
150  HepGeom::Point3D<double> const &surfPos,
151  GlobalVector const &normalPlane,
152  HepGeom::Normal3D<double> const &surfNorm,
153  const Plane &pDest) const;
154 
155  template <class SurfaceType>
156  void debugReportTrackState(std::string const &currentContext,
157  GlobalPoint const &cmsInitPos,
158  CLHEP::Hep3Vector const &g4InitPos,
159  GlobalVector const &cmsInitMom,
160  CLHEP::Hep3Vector const &g4InitMom,
161  const SurfaceType &pDest) const;
162 };
163 
164 #endif
std::pair< TrajectoryStateOnSurface, double > TsosPP
void debugReportPlaneSetup(GlobalPoint const &posPlane, HepGeom::Point3D< double > const &surfPos, GlobalVector const &normalPlane, HepGeom::Normal3D< double > const &surfNorm, const Plane &pDest) const
std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Plane &) const override
Geant4ePropagator * clone() const override
std::string theParticleName
bool configurePropagation(G4ErrorMode &mode, SurfaceType const &pDest, GlobalPoint const &cmsInitPos, GlobalVector const &cmsInitMom) const
PropagationDirection
const MagneticField * theField
Definition: Plane.h:16
G4ErrorPropagatorManager * theG4eManager
G4ErrorPropagatorData * theG4eData
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< bool, std::shared_ptr< G4ErrorTarget > > ErrorTargetPair
const MagneticField * magneticField() const override
std::pair< TrajectoryStateOnSurface, double > propagateGeneric(const FreeTrajectoryState &ftsStart, const SurfaceType &pDest) const
~Geant4ePropagator() override
ErrorTargetPair transformToG4SurfaceTarget(const SurfaceType &pDest, bool moveTargetToEndOfSurface) const
std::string getSurfaceType(SurfaceType const &surface) const
bool configureAnyPropagation(G4ErrorMode &mode, SurfaceType const &pDest, GlobalPoint const &cmsInitPos, GlobalVector const &cmsInitMom) const
std::string generateParticleName(int charge) const
Geant4ePropagator(const MagneticField *field=nullptr, std::string particleName="mu", PropagationDirection dir=alongMomentum, double plimit=1.0)
void ensureGeant4eIsInitilized(bool forceInit) const