Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:42

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   /** The methods propagateWithPath() are identical to the corresponding
0036    *  methods propagate() in what concerns the resulting
0037    *  TrajectoryStateOnSurface, but they provide in addition the
0038    *  exact path length along the trajectory.
0039    *  All of these method calls are internally mapped to
0040    */
0041 
0042   std::pair<TrajectoryStateOnSurface, double> propagateWithPath(const FreeTrajectoryState &,
0043                                                                 const Plane &) const override;
0044 
0045   std::pair<TrajectoryStateOnSurface, double> propagateWithPath(const FreeTrajectoryState &,
0046                                                                 const Cylinder &) const override;
0047 
0048   std::pair<TrajectoryStateOnSurface, double> propagateWithPath(const TrajectoryStateOnSurface &,
0049                                                                 const Plane &) const override;
0050 
0051   std::pair<TrajectoryStateOnSurface, double> propagateWithPath(const TrajectoryStateOnSurface &,
0052                                                                 const Cylinder &) const override;
0053 
0054   Geant4ePropagator *clone() const override { return new Geant4ePropagator(*this); }
0055 
0056   const MagneticField *magneticField() const override { return theField; }
0057 
0058 private:
0059   typedef std::pair<TrajectoryStateOnSurface, double> TsosPP;
0060   typedef std::pair<bool, std::shared_ptr<G4ErrorTarget>> ErrorTargetPair;
0061 
0062   // Magnetic field
0063   const MagneticField *theField;
0064 
0065   // Name of the particle whose properties will be used in the propagation
0066   std::string theParticleName;
0067 
0068   // The Geant4e manager. Does the real propagation
0069   G4ErrorPropagatorManager *theG4eManager;
0070   G4ErrorPropagatorData *theG4eData;
0071   double plimit_;
0072 
0073   // Transform a CMS Reco detector surface into a Geant4 Target for the error
0074   // propagation
0075   template <class SurfaceType>
0076   ErrorTargetPair transformToG4SurfaceTarget(const SurfaceType &pDest, bool moveTargetToEndOfSurface) const;
0077 
0078   // generates the Geant4 name for a particle from the
0079   // string stored in theParticleName ( set via constructor )
0080   // and the particle charge.
0081   // 'mu' as a basis for muon becomes 'mu+' or 'mu-', depening on the charge
0082   // This method only supports neutral and +/- 1e charges so far
0083   //
0084   // returns the generated string
0085   std::string generateParticleName(int charge) const;
0086 
0087   // flexible method which performs the actual propagation either for a plane or
0088   // cylinder surface type
0089   //
0090   // returns TSOS after the propagation and the path length
0091   template <class SurfaceType>
0092   std::pair<TrajectoryStateOnSurface, double> propagateGeneric(const FreeTrajectoryState &ftsStart,
0093                                                                const SurfaceType &pDest) const;
0094 
0095   // saves the Geant4 propagation direction (Forward or Backward) in the
0096   // provided variable reference mode and returns true if the propagation
0097   // direction could be set
0098   template <class SurfaceType>
0099   bool configurePropagation(G4ErrorMode &mode,
0100                             SurfaceType const &pDest,
0101                             GlobalPoint const &cmsInitPos,
0102                             GlobalVector const &cmsInitMom) const;
0103 
0104   // special case to determine the propagation direction if the CMS propagation
0105   // direction 'anyDirection' was set. This method is called by
0106   // configurePropagation and provides specific implementations for Plane and
0107   // Cylinder classes
0108   template <class SurfaceType>
0109   bool configureAnyPropagation(G4ErrorMode &mode,
0110                                SurfaceType const &pDest,
0111                                GlobalPoint const &cmsInitPos,
0112                                GlobalVector const &cmsInitMom) const;
0113 
0114   // Ensure Geant4 Error propagation is initialized, if not done so, yet
0115   // if the forceInit parameter is set to true, the initialization is performed,
0116   // even if already done before.
0117   // This can be necessary, when Geant4 needs to read in a new MagneticField
0118   // object, which changed during lumi section crossing
0119   void ensureGeant4eIsInitilized(bool forceInit) const;
0120 
0121   // returns the name of the SurfaceType. Mostly for debug outputs
0122   template <class SurfaceType>
0123   std::string getSurfaceType(SurfaceType const &surface) const;
0124 
0125   void debugReportPlaneSetup(GlobalPoint const &posPlane,
0126                              HepGeom::Point3D<double> const &surfPos,
0127                              GlobalVector const &normalPlane,
0128                              HepGeom::Normal3D<double> const &surfNorm,
0129                              const Plane &pDest) const;
0130 
0131   template <class SurfaceType>
0132   void debugReportTrackState(std::string const &currentContext,
0133                              GlobalPoint const &cmsInitPos,
0134                              CLHEP::Hep3Vector const &g4InitPos,
0135                              GlobalVector const &cmsInitMom,
0136                              CLHEP::Hep3Vector const &g4InitMom,
0137                              const SurfaceType &pDest) const;
0138 };
0139 
0140 #endif