Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:28:53

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