DetPack

PTrajectoryStateOnDet

Pack

Packing

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
#ifndef PTrajectoryStateOnDet_H
#define PTrajectoryStateOnDet_H

#include "DataFormats/TrajectoryState/interface/LocalTrajectoryParameters.h"
#include <cassert>
/** Persistent version of a TrajectoryStateOnSurface.
 *  Stores local trajectory parameters and errors and
 *  the id of the Det defining the surface.
 */
class PTrajectoryStateOnDet {
public:
  // little endian...
  struct Packing {
    unsigned int rest : 30;
    unsigned char ss : 2;
  };
  struct DetPack {
    unsigned int loc : 25;
    unsigned char sub : 3;
    unsigned char det : 4;
  };

private:
  // we assume that id cannot be calo! (i.e. det<4)
  static const unsigned int idMask = 0x3fffffff;
  union Pack {
    Pack() {}
    Pack(unsigned int pack) : packed(pack) {}
    Pack(unsigned int id, int surfaceSide) : packed(id) {
      bytes.ss = surfaceSide;
      assert(surfaceSide < 3);
      assert((id >> 28) < 4);
    }
    int side() const { return bytes.ss; }
    unsigned int id() const { return packed & idMask; }
    unsigned int packed;
    Packing bytes;
    DetPack det;
  };

public:
  PTrajectoryStateOnDet() {}

  PTrajectoryStateOnDet(const LocalTrajectoryParameters& param, float ipt, unsigned int id, int surfaceSide)
      : theLocalParameters(param), thePt(ipt) {
    Pack p(id, surfaceSide);
    thePack = p.packed;
    theLocalErrors[0] = -99999.e10;
  }

  PTrajectoryStateOnDet(
      const LocalTrajectoryParameters& param, float ipt, float errmatrix[15], unsigned int id, int surfaceSide)
      : theLocalParameters(param), thePt(ipt) {
    Pack p(id, surfaceSide);
    thePack = p.packed;
    for (int i = 0; i < 15; i++)
      theLocalErrors[i] = errmatrix[i];
  }

  const LocalTrajectoryParameters& parameters() const { return theLocalParameters; }
  float pt() const { return thePt; }
  bool hasError() const { return theLocalErrors[0] > -1.e10; }
  float& error(int i) { return theLocalErrors[i]; }
  float error(int i) const { return theLocalErrors[i]; }
  unsigned int detId() const { return thePack & idMask; }
  int surfaceSide() const {
    Pack p(thePack);
    return p.side();
  }

private:
  LocalTrajectoryParameters theLocalParameters;
  float theLocalErrors[15] = {};
  float thePt = 0;
  unsigned int thePack = 0;
};

#endif