Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef PTrajectoryStateOnDet_H
0002 #define PTrajectoryStateOnDet_H
0003 
0004 #include "DataFormats/TrajectoryState/interface/LocalTrajectoryParameters.h"
0005 #include <cassert>
0006 /** Persistent version of a TrajectoryStateOnSurface.
0007  *  Stores local trajectory parameters and errors and
0008  *  the id of the Det defining the surface.
0009  */
0010 class PTrajectoryStateOnDet {
0011 public:
0012   // little endian...
0013   struct Packing {
0014     unsigned int rest : 30;
0015     unsigned char ss : 2;
0016   };
0017   struct DetPack {
0018     unsigned int loc : 25;
0019     unsigned char sub : 3;
0020     unsigned char det : 4;
0021   };
0022 
0023 private:
0024   // we assume that id cannot be calo! (i.e. det<4)
0025   static const unsigned int idMask = 0x3fffffff;
0026   union Pack {
0027     Pack() {}
0028     Pack(unsigned int pack) : packed(pack) {}
0029     Pack(unsigned int id, int surfaceSide) : packed(id) {
0030       bytes.ss = surfaceSide;
0031       assert(surfaceSide < 3);
0032       assert((id >> 28) < 4);
0033     }
0034     int side() const { return bytes.ss; }
0035     unsigned int id() const { return packed & idMask; }
0036     unsigned int packed;
0037     Packing bytes;
0038     DetPack det;
0039   };
0040 
0041 public:
0042   PTrajectoryStateOnDet() {}
0043 
0044   PTrajectoryStateOnDet(const LocalTrajectoryParameters& param, float ipt, unsigned int id, int surfaceSide)
0045       : theLocalParameters(param), thePt(ipt) {
0046     Pack p(id, surfaceSide);
0047     thePack = p.packed;
0048     theLocalErrors[0] = -99999.e10;
0049   }
0050 
0051   PTrajectoryStateOnDet(
0052       const LocalTrajectoryParameters& param, float ipt, float errmatrix[15], unsigned int id, int surfaceSide)
0053       : theLocalParameters(param), thePt(ipt) {
0054     Pack p(id, surfaceSide);
0055     thePack = p.packed;
0056     for (int i = 0; i < 15; i++)
0057       theLocalErrors[i] = errmatrix[i];
0058   }
0059 
0060   const LocalTrajectoryParameters& parameters() const { return theLocalParameters; }
0061   float pt() const { return thePt; }
0062   bool hasError() const { return theLocalErrors[0] > -1.e10; }
0063   float& error(int i) { return theLocalErrors[i]; }
0064   float error(int i) const { return theLocalErrors[i]; }
0065   unsigned int detId() const { return thePack & idMask; }
0066   int surfaceSide() const {
0067     Pack p(thePack);
0068     return p.side();
0069   }
0070 
0071 private:
0072   LocalTrajectoryParameters theLocalParameters;
0073   float theLocalErrors[15] = {};
0074   float thePt = 0;
0075   unsigned int thePack = 0;
0076 };
0077 
0078 #endif