Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:43

0001 #ifndef PSimHit_H
0002 #define PSimHit_H
0003 
0004 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
0005 #include "DataFormats/GeometryVector/interface/LocalVector.h"
0006 #include "SimDataFormats/EncodedEventId/interface/EncodedEventId.h"
0007 
0008 class TrackingSlaveSD;  // for friend declaration only
0009 
0010 /** 
0011  * Persistent-capable SimHit.
0012  * Suitable for tracking detectors.
0013  */
0014 
0015 class PSimHit {
0016 public:
0017   static constexpr unsigned int k_tidOffset = 200000000;
0018 
0019   PSimHit() : theDetUnitId(0) {}
0020 
0021   PSimHit(const Local3DPoint& entry,
0022           const Local3DPoint& exit,
0023           float pabs,
0024           float tof,
0025           float eloss,
0026           int particleType,
0027           unsigned int detId,
0028           unsigned int trackId,
0029           float theta,
0030           float phi,
0031           unsigned short processType = 0)
0032       : theEntryPoint(entry),
0033         theSegment(exit - entry),
0034         thePabs(pabs),
0035         theEnergyLoss(eloss),
0036         theThetaAtEntry(theta),
0037         thePhiAtEntry(phi),
0038         theTof(tof),
0039         theParticleType(particleType),
0040         theProcessType(processType),
0041         theDetUnitId(detId),
0042         theTrackId(trackId) {}
0043 
0044   /// Entry point in the local Det frame
0045   Local3DPoint entryPoint() const { return theEntryPoint; }
0046 
0047   /// Exit point in the local Det frame
0048   Local3DPoint exitPoint() const { return theEntryPoint + theSegment; }
0049 
0050   /** Local position in the Det frame.
0051    *  Normally it is on the detection surface, but this is not
0052    *  checked. It is computed as the middle point between entry and exit.
0053    */
0054   Local3DPoint localPosition() const { return theEntryPoint + 0.5 * theSegment; }
0055 
0056   /// The momentum of the track that produced the hit, at entry point.
0057   LocalVector momentumAtEntry() const { return LocalVector(thetaAtEntry(), phiAtEntry(), pabs()); }
0058 
0059   /// Obsolete. Same as momentumAtEntry().unit(), for backward compatibility.
0060   LocalVector localDirection() const { return LocalVector(thetaAtEntry(), phiAtEntry(), 1.f); }
0061 
0062   /// fast and more accurate access to momentumAtEntry().theta()
0063   Geom::Theta<float> thetaAtEntry() const { return Geom::Theta<float>(theThetaAtEntry); }
0064 
0065   /// fast and more accurate access to momentumAtEntry().phi()
0066   Geom::Phi<float> phiAtEntry() const { return Geom::Phi<float>(thePhiAtEntry); }
0067 
0068   /// fast and more accurate access to momentumAtEntry().mag()
0069   float pabs() const { return thePabs; }
0070 
0071   /** Time of flight in nanoseconds from the primary interaction
0072    *  to the entry point. Always positive in a PSimHit,
0073    *  but may become negative in a SimHit due to bunch assignment.
0074    */
0075   float timeOfFlight() const { return tof(); }
0076 
0077   /// deprecated name for timeOfFlight()
0078   float tof() const { return theTof; }
0079 
0080   /// The energy deposit in the PSimHit, in ???.
0081   float energyLoss() const { return theEnergyLoss; }
0082 
0083   /** The particle type of the track that produced this hit,
0084    *  in standard PDG code. 
0085    *  NB: This differs from ORCA5 and earlier, where the code was Geant3.
0086    *  The particle type of the hit may differ from the particle type of
0087    *  the SimTrack with id trackId(). This happends if the hit was created
0088    *  by a secondary track (e.g. a delta ray) originating from the 
0089    *  trackId() and not existing as a separate SimTrack.
0090    */
0091   int particleType() const { return theParticleType; }
0092 
0093   /** The DetUnit identifier, to be interpreted in the context of the
0094    *  detector system that produced the hit. E.g. in the Tracker
0095    *  this is index used with DetUnitNumbering<TrackerSimHitTag>.
0096    *  Currently the context is not deducible from the PSimHit and
0097    *  must be known when the PSimHit is created/accessed.
0098    */
0099   unsigned int detUnitId() const { return theDetUnitId; }
0100 
0101   /** The SimTrack ID of the "mother" track. This may be the actual
0102    *  charged track that produced the hit, or a "mother" of this
0103    *  track, in case the track that produced the hit was not
0104    *  saved as a SimTrack.
0105    *  This ID must be interpreted in the context of the SimEvent
0106    *  to which the PSimHit belongs.
0107    */
0108   unsigned int trackId() const { return theTrackId; }
0109 
0110   /** In case te SimTrack ID is incremented by the k_tidOffset for hit category definition, this
0111    * methods returns the original theTrackId value directly.
0112    */
0113   unsigned int originalTrackId() const { return theTrackId % k_tidOffset; }
0114 
0115   unsigned int offsetTrackId() const { return theTrackId / k_tidOffset; }
0116 
0117   static unsigned int addTrackIdOffset(unsigned int tId, unsigned int offset) { return offset * k_tidOffset + tId; }
0118 
0119   EncodedEventId eventId() const { return theEventId; }
0120 
0121   void setEventId(EncodedEventId e) { theEventId = e; }
0122 
0123   /** The ID of the physics process that created the track that produced 
0124    *  the hit. This is useful for identifying hits from secondary interactions,
0125    *  especially in the case when the track that produced the hit was not saved 
0126    *  as a SimTrack.
0127    *  The meaning of the ID is defined outside of the PSimHit; The only 
0128    *  value with special significance is zero (for "undefined"), so zero should
0129    *  not be the ID of any process.
0130    */
0131   unsigned short processType() const { return theProcessType; }
0132 
0133   void setTof(float tof) { theTof = tof; }
0134 
0135 protected:
0136   // properties
0137   Local3DPoint theEntryPoint;  // position at entry
0138   Local3DVector theSegment;    // exitPos - entryPos
0139   float thePabs;               // momentum
0140   float theEnergyLoss;         // Energy loss
0141   float theThetaAtEntry;
0142   float thePhiAtEntry;
0143 
0144   float theTof;  // Time Of Flight
0145   int theParticleType;
0146   unsigned short theProcessType;  // ID of the process which created the track
0147                                   // which created the PSimHit
0148 
0149   // association
0150   unsigned int theDetUnitId;
0151   unsigned int theTrackId;
0152   EncodedEventId theEventId;
0153 
0154   friend class TrackingSlaveSD;
0155 };
0156 
0157 std::ostream& operator<<(std::ostream& o, const PSimHit& hit);
0158 
0159 #endif  // PSimHit_H