Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:51:35

0001 #ifndef _TRACKER_LOCALTRAJECTORYPARAMETERS_H_
0002 #define _TRACKER_LOCALTRAJECTORYPARAMETERS_H_
0003 
0004 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
0005 #include "DataFormats/GeometryVector/interface/LocalVector.h"
0006 #include "DataFormats/TrajectoryState/interface/TrackCharge.h"
0007 #include "DataFormats/Math/interface/AlgebraicROOTObjects.h"
0008 
0009 #include <cmath>
0010 
0011 /** Class providing access to a set of relevant parameters of a trajectory
0012  *  in a local, Cartesian frame. The set consists of the following parameters: <BR> <BR>
0013  *  
0014  *  q/p : charged particles: charge (plus or minus one) divided by magnitude of momentum <BR>
0015  *        neutral particles: inverse magnitude of momentum <BR>
0016  *  dxdz : direction tangent in local xz-plane <BR>
0017  *  dydz : direction tangent in local yz-plane <BR>
0018  *  x : local x-coordinate <BR>
0019  *  y : local y-coordinate <BR> <BR>
0020  *
0021  *  In addition, the sign of local p_z is needed to fully define the direction of the track
0022  *  in this local frame.
0023  */
0024 
0025 class LocalTrajectoryParameters {
0026 public:
0027   // construct
0028 
0029   LocalTrajectoryParameters() {}
0030 
0031   /** Constructor from vector of parameters.
0032    *
0033    *  Expects a vector of parameters as defined above, plus the sign of p_z.
0034    *  For charged particles the charge will be determined by the sign of
0035    *  the first element. For neutral particles the last argument should be false, 
0036    *  in which case the charge of the first element will be neglected.
0037    */
0038   LocalTrajectoryParameters(const AlgebraicVector5& v, float aPzSign, bool charged = true) {
0039     theQbp = v[0];
0040     theDxdz = v[1];
0041     theDydz = v[2];
0042     theX = v[3];
0043     theY = v[4];
0044     thePzSign = aPzSign;
0045     if (charged)
0046       theCharge = theQbp > 0 ? 1 : -1;
0047     else
0048       theCharge = 0;
0049   }
0050 
0051   /** Constructor from individual parameters.
0052    *
0053    *  Expects parameters as defined above, plus the sign of p_z.
0054    *  For charged particles the charge will be determined by the sign of
0055    *  the first argument. For neutral particles the last argument should be false, 
0056    *  in which case the charge of the first argument will be neglected.
0057    */
0058   LocalTrajectoryParameters(float aQbp, float aDxdz, float aDydz, float aX, float aY, float aPzSign, bool charged = true)
0059       : theDxdz(aDxdz), theDydz(aDydz), theX(aX), theY(aY), thePzSign(aPzSign > 0 ? 1 : -1) {
0060     if (charged) {
0061       theQbp = aQbp;
0062       theCharge = theQbp > 0 ? 1 : -1;
0063     } else {
0064       theQbp = aQbp;
0065       theCharge = 0;
0066     }
0067   }
0068 
0069   /// Constructor from local position, momentum and charge.
0070   LocalTrajectoryParameters(const LocalPoint& pos, const LocalVector& p, TrackCharge charge)
0071       : theQbp(charge / p.mag()),
0072         theDxdz(p.x() / p.z()),
0073         theDydz(p.y() / p.z()),
0074         theX(pos.x()),
0075         theY(pos.y()),
0076         thePzSign(p.z() > 0. ? 1 : -1),
0077         theCharge(charge) {
0078     if (charge == 0)
0079       theQbp = 1.f / p.mag();
0080   }
0081 
0082   // access
0083 
0084   /// Local x and y position coordinates.
0085   LocalPoint position() const { return LocalPoint(theX, theY); }
0086 
0087   /// Momentum vector in the local frame.
0088   LocalVector momentum() const {
0089     float op = std::abs(theQbp);
0090     if (op < 1.e-9f)
0091       op = 1.e-9f;
0092     float pz = float(thePzSign) / (op * std::sqrt(1.f + theDxdz * theDxdz + theDydz * theDydz));
0093     float px = pz * theDxdz;
0094     float py = pz * theDydz;
0095     return LocalVector(px, py, pz);
0096   }
0097 
0098   /// Momentum vector unit in the local frame.
0099   LocalVector direction() const {
0100     float dz = float(thePzSign) / std::sqrt(1.f + theDxdz * theDxdz + theDydz * theDydz);
0101     float dx = dz * theDxdz;
0102     float dy = dz * theDydz;
0103     return LocalVector(dx, dy, dz);
0104   }
0105 
0106   /// Momentum vector unit in the local frame.
0107   LocalVector directionNotNormalized() const { return LocalVector(theDxdz, theDydz, 1.f); }
0108 
0109   /// Charge (-1, 0 or 1)
0110   TrackCharge charge() const { return theCharge; }
0111 
0112   /// Signed inverse momentum q/p (zero for neutrals).
0113   float signedInverseMomentum() const { return charge() == 0 ? 0.f : theQbp; }
0114 
0115   /** Vector of parameters with signed inverse momentum.
0116    *
0117    *  Vector of parameters as defined above, with the
0118    *  first element = q/p .
0119    */
0120   AlgebraicVector5 vector() const {
0121     AlgebraicVector5 v;
0122     v[0] = signedInverseMomentum();
0123     v[1] = theDxdz;
0124     v[2] = theDydz;
0125     v[3] = theX;
0126     v[4] = theY;
0127     return v;
0128   }
0129 
0130   /** Vector of parameters in internal representation.
0131    *
0132    *  Vector of parameters as defined above, with the first
0133    *  element = q/p for charged and = 1/p for neutral.
0134    */
0135   AlgebraicVector5 mixedFormatVector() const {
0136     AlgebraicVector5 v;
0137     v[0] = theQbp;  // signed in case of charged particles, 1/p for neutrals
0138     v[1] = theDxdz;
0139     v[2] = theDydz;
0140     v[3] = theX;
0141     v[4] = theY;
0142     return v;
0143   }
0144 
0145   /// Sign of the z-component of the momentum in the local frame.
0146   float pzSign() const { return thePzSign; }
0147 
0148   /// Update of momentum by a scalar dP.
0149   bool updateP(float dP) {
0150     float p = 1.f / std::abs(theQbp);
0151     if ((p += dP) <= 0.f)
0152       return false;
0153     float newQbp = theQbp > 0. ? 1.f / p : -1.f / p;
0154     theQbp = newQbp;
0155     return true;
0156   }
0157 
0158   float qbp() const { return theQbp; }
0159   float dxdz() const { return theDxdz; }
0160   float dydz() const { return theDydz; }
0161   float absdz() const { return 1.f / std::sqrt(1.f + theDxdz * theDxdz + theDydz * theDydz); }
0162 
0163 private:
0164   float theQbp;   ///< q/p (charged) or 1/p (neutral)
0165   float theDxdz;  ///< tangent of direction in local x vs. z
0166   float theDydz;  ///< tangent of direction in local y vs. z
0167   float theX;     ///< local x position
0168   float theY;     ///< local y position
0169 
0170   short thePzSign;  ///< sign of local pz
0171 
0172   short theCharge;  ///< charge
0173 };
0174 
0175 #endif