Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:31:54

0001 #ifndef TrackPropagation_Geant4ePropagator_h
0002 #define TrackPropagation_Geant4ePropagator_h
0003 
0004 #include <memory>
0005 
0006 // CMS includes
0007 // - Propagator
0008 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
0009 
0010 // - Geant4e
0011 #include "G4ErrorPropagatorData.hh"
0012 #include "G4ErrorPropagatorManager.hh"
0013 #include "G4ErrorSurfaceTarget.hh"
0014 
0015 /** Propagator based on the Geant4e package. Uses the Propagator class
0016  *  in the TrackingTools/GeomPropagators package to define the interface.
0017  *  See that class for more details.
0018  */
0019 
0020 class Geant4ePropagator : public Propagator {
0021 public:
0022   /** Constructor. Takes as arguments:
0023    *  * The magnetic field
0024    *  * The particle name whose properties will be used in the propagation.
0025    * Without the charge, i.e. "mu", "pi", ...
0026    *  * The propagation direction. It may be: alongMomentum, oppositeToMomentum
0027    */
0028   Geant4ePropagator(const MagneticField *field = nullptr,
0029                     std::string particleName = "mu",
0030                     PropagationDirection dir = alongMomentum,
0031                     double plimit = 1.0);
0032 
0033   ~Geant4ePropagator() override;
0034 
0035   /** Propagate from a free state (e.g. position and momentum in
0036    *  in global cartesian coordinates) to a surface.
0037    */
0038   /*
0039           virtual TrajectoryStateOnSurface
0040           propagate(const FreeTrajectoryState& ftsStart, const Plane& pDest)
0041      const override;
0042 
0043           virtual TrajectoryStateOnSurface
0044           propagate(const FreeTrajectoryState& ftsStart, const Cylinder& cDest)
0045      const override;
0046   */
0047   /** Propagate from a state on surface (e.g. position and momentum in
0048    *  in global cartesian coordinates associated with a layer) to a surface.
0049    */
0050   /*
0051           virtual TrajectoryStateOnSurface
0052           propagate(const TrajectoryStateOnSurface& tsos, const Plane& plane)
0053      const override;
0054 
0055           virtual TrajectoryStateOnSurface
0056           propagate(const TrajectoryStateOnSurface& tsos, const Cylinder& cyl)
0057      const override;
0058   */
0059   /** The methods propagateWithPath() are identical to the corresponding
0060    *  methods propagate() in what concerns the resulting
0061    *  TrajectoryStateOnSurface, but they provide in addition the
0062    *  exact path length along the trajectory.
0063    *  All of these method calls are internally mapped to
0064    */
0065 
0066   std::pair<TrajectoryStateOnSurface, double> propagateWithPath(const FreeTrajectoryState &,
0067                                                                 const Plane &) const override;
0068 
0069   std::pair<TrajectoryStateOnSurface, double> propagateWithPath(const FreeTrajectoryState &,
0070                                                                 const Cylinder &) const override;
0071 
0072   std::pair<TrajectoryStateOnSurface, double> propagateWithPath(const TrajectoryStateOnSurface &,
0073                                                                 const Plane &) const override;
0074 
0075   std::pair<TrajectoryStateOnSurface, double> propagateWithPath(const TrajectoryStateOnSurface &,
0076                                                                 const Cylinder &) const override;
0077 
0078   Geant4ePropagator *clone() const override { return new Geant4ePropagator(*this); }
0079 
0080   const MagneticField *magneticField() const override { return theField; }
0081 
0082 private:
0083   typedef std::pair<TrajectoryStateOnSurface, double> TsosPP;
0084   typedef std::pair<bool, std::shared_ptr<G4ErrorTarget>> ErrorTargetPair;
0085 
0086   // Magnetic field
0087   const MagneticField *theField;
0088 
0089   // Name of the particle whose properties will be used in the propagation
0090   std::string theParticleName;
0091 
0092   // The Geant4e manager. Does the real propagation
0093   G4ErrorPropagatorManager *theG4eManager;
0094   G4ErrorPropagatorData *theG4eData;
0095   double plimit_;
0096 
0097   // Transform a CMS Reco detector surface into a Geant4 Target for the error
0098   // propagation
0099   template <class SurfaceType>
0100   ErrorTargetPair transformToG4SurfaceTarget(const SurfaceType &pDest, bool moveTargetToEndOfSurface) const;
0101 
0102   // generates the Geant4 name for a particle from the
0103   // string stored in theParticleName ( set via constructor )
0104   // and the particle charge.
0105   // 'mu' as a basis for muon becomes 'mu+' or 'mu-', depening on the charge
0106   // This method only supports neutral and +/- 1e charges so far
0107   //
0108   // returns the generated string
0109   std::string generateParticleName(int charge) const;
0110 
0111   // flexible method which performs the actual propagation either for a plane or
0112   // cylinder surface type
0113   //
0114   // returns TSOS after the propagation and the path length
0115   template <class SurfaceType>
0116   std::pair<TrajectoryStateOnSurface, double> propagateGeneric(const FreeTrajectoryState &ftsStart,
0117                                                                const SurfaceType &pDest) const;
0118 
0119   // saves the Geant4 propagation direction (Forward or Backward) in the
0120   // provided variable reference mode and returns true if the propagation
0121   // direction could be set
0122   template <class SurfaceType>
0123   bool configurePropagation(G4ErrorMode &mode,
0124                             SurfaceType const &pDest,
0125                             GlobalPoint const &cmsInitPos,
0126                             GlobalVector const &cmsInitMom) const;
0127 
0128   // special case to determine the propagation direction if the CMS propagation
0129   // direction 'anyDirection' was set. This method is called by
0130   // configurePropagation and provides specific implementations for Plane and
0131   // Cylinder classes
0132   template <class SurfaceType>
0133   bool configureAnyPropagation(G4ErrorMode &mode,
0134                                SurfaceType const &pDest,
0135                                GlobalPoint const &cmsInitPos,
0136                                GlobalVector const &cmsInitMom) const;
0137 
0138   // Ensure Geant4 Error propagation is initialized, if not done so, yet
0139   // if the forceInit parameter is set to true, the initialization is performed,
0140   // even if already done before.
0141   // This can be necessary, when Geant4 needs to read in a new MagneticField
0142   // object, which changed during lumi section crossing
0143   void ensureGeant4eIsInitilized(bool forceInit) const;
0144 
0145   // returns the name of the SurfaceType. Mostly for debug outputs
0146   template <class SurfaceType>
0147   std::string getSurfaceType(SurfaceType const &surface) const;
0148 
0149   void debugReportPlaneSetup(GlobalPoint const &posPlane,
0150                              HepGeom::Point3D<double> const &surfPos,
0151                              GlobalVector const &normalPlane,
0152                              HepGeom::Normal3D<double> const &surfNorm,
0153                              const Plane &pDest) const;
0154 
0155   template <class SurfaceType>
0156   void debugReportTrackState(std::string const &currentContext,
0157                              GlobalPoint const &cmsInitPos,
0158                              CLHEP::Hep3Vector const &g4InitPos,
0159                              GlobalVector const &cmsInitMom,
0160                              CLHEP::Hep3Vector const &g4InitMom,
0161                              const SurfaceType &pDest) const;
0162 };
0163 
0164 #endif