CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SiPixelRecHitQuality.h
Go to the documentation of this file.
1 #ifndef DataFormats_SiPixelRecHitQuality_h
2 #define DataFormats_SiPixelRecHitQuality_h 1
3 
4 #include <cmath>
5 
7 public:
8  typedef unsigned int QualWordType;
9 
10 public:
11  class Packing {
12  public:
13  // Constructor: pre-computes masks and shifts from field widths
14  Packing();
15 
16  public:
19  float probX_units;
22  //
25  float probY_units;
28  //
31  char qBin_width;
32  //
35  char edge_width;
36  //
38  int bad_shift;
39  char bad_width;
40  //
44  //
48 
50 
51  //--- Template fit probability, in X and Y directions
52  // To pack: int raw = - log(prob)/log(prob_units)
53  // Unpack : prob = prob_units^{-raw}
54  //
55  //--- We've obsoleted probX and probY in favor of probXY and probQ as of 09/10
56  inline float probabilityX(QualWordType qualWord) const {
58  return -10;
59  }
60  inline float probabilityY(QualWordType qualWord) const {
62  return -10;
63  }
64 
65  inline float probabilityXY(QualWordType qualWord) const {
66  int raw = (qualWord >> probX_shift) & probX_mask;
67  if (raw < 0 || raw > 16383) {
68  warningOutOfBoundRaw("XY", raw, qualWord);
69  raw = 16383;
70  }
71  float prob = (raw == 16383) ? 0 : pow(probX_units, (float)(-raw));
72  // cout << "Bits = " << raw << " --> Prob = " << prob << endl;
73  return prob;
74  }
75  inline float probabilityQ(QualWordType qualWord) const {
76  int raw = (qualWord >> probY_shift) & probY_mask;
77  if (raw < 0 || raw > 255) {
78  warningOutOfBoundRaw("Q", raw, qualWord);
79  raw = 255;
80  }
81  float prob = (raw == 255) ? 0 : pow(probY_units, (float)(-raw));
82  // cout << "Bits = " << raw << " --> Prob = " << prob << endl;
83  return prob;
84  }
85  //
86  //--- Charge `bin' (0,1,2,3 ~ charge, qBin==4 is a new minimum charge state, qBin=5 is unphysical, qBin6,7 = unused)
87  inline int qBin(QualWordType qualWord) const {
88  int qbin = (qualWord >> qBin_shift) & qBin_mask;
89  if (qbin < 0 || qbin > 7) {
90  warningOutOfBoundQbin(qbin, qualWord);
91  qbin = 0;
92  }
93  return qbin;
94  }
95  //--- Quality flags (true or false):
96  //--- cluster is on the edge of the module, or straddles a dead ROC
97  inline bool isOnEdge(QualWordType qualWord) const { return (qualWord >> edge_shift) & edge_mask; }
98  //--- cluster contains bad pixels, or straddles bad column or two-column
99  inline bool hasBadPixels(QualWordType qualWord) const { return (qualWord >> bad_shift) & bad_mask; }
100  //--- the cluster spans two ROCS (and thus contains big pixels)
101  inline bool spansTwoROCs(QualWordType qualWord) const { return (qualWord >> twoROC_shift) & twoROC_mask; }
102  //--- the probability is filled
103  inline bool hasFilledProb(QualWordType qualWord) const {
104  return (qualWord >> hasFilledProb_shift) & hasFilledProb_mask;
105  }
106 
107  //------------------------------------------------------
108  //--- Setters: the inverse of the above.
109  //------------------------------------------------------
110  //
111  inline void setProbabilityXY(float prob, QualWordType& qualWord) const {
112  if (prob > 1.0f && prob <= 1.0f + std::numeric_limits<float>::epsilon()) {
113  prob = 1;
114  } else if (prob < 0.0f || prob > 1.0f + std::numeric_limits<float>::epsilon()) {
115  warningOutOfBoundProb("XY", prob, qualWord);
116  prob = 0;
117  }
118  double draw = (prob <= 1.6E-13) ? 16383 : -log((double)prob) * probX_1_over_log_units;
119  unsigned int raw = (int)(draw + 0.5); // convert to integer, round correctly
120  // cout << "Prob = " << prob << " --> Bits = " << raw << endl;
121  qualWord |= ((raw & probX_mask) << probX_shift);
122  }
123  inline void setProbabilityQ(float prob, QualWordType& qualWord) const {
124  if (prob > 1.0f && prob <= 1.0f + std::numeric_limits<float>::epsilon()) {
125  prob = 1;
126  } else if (prob < 0.0f || prob > 1.0f + std::numeric_limits<float>::epsilon()) {
127  warningOutOfBoundProb("Q", prob, qualWord);
128  prob = 0;
129  }
130  double draw = (prob <= 1E-5) ? 255 : -log((double)prob) * probY_1_over_log_units;
131  unsigned int raw = (int)(draw + 0.5); // convert to integer, round correctly
132  // cout << "Prob = " << prob << " --> Bits = " << raw << endl;
133  qualWord |= ((raw & probY_mask) << probY_shift);
134  }
135 
136  inline void setQBin(int qbin, QualWordType& qualWord) const {
137  if (qbin < 0 || qbin > 7) {
138  warningOutOfBoundQbin(qbin, qualWord);
139  qbin = 0;
140  }
141  qualWord |= ((qbin & qBin_mask) << qBin_shift);
142  }
143 
144  inline void setIsOnEdge(bool flag, QualWordType& qualWord) const { qualWord |= ((flag & edge_mask) << edge_shift); }
145  inline void setHasBadPixels(bool flag, QualWordType& qualWord) const {
146  qualWord |= ((flag & bad_mask) << bad_shift);
147  }
148  inline void setSpansTwoROCs(bool flag, QualWordType& qualWord) const {
149  qualWord |= ((flag & twoROC_mask) << twoROC_shift);
150  }
151  inline void setHasFilledProb(bool flag, QualWordType& qualWord) const {
152  qualWord |= ((flag & hasFilledProb_mask) << hasFilledProb_shift);
153  }
154  };
155 
156 public:
157  static const Packing thePacking;
158 
159 private:
160  static void warningObsolete();
161  static void warningOutOfBoundQbin(int, QualWordType const&);
162  static void warningOutOfBoundProb(const char* iVariable, float, QualWordType const&);
163  static void warningOutOfBoundRaw(const char* iVariable, int iRaw, QualWordType const&);
164 };
165 
166 #endif
float probabilityQ(QualWordType qualWord) const
void setProbabilityXY(float prob, QualWordType &qualWord) const
bool spansTwoROCs(QualWordType qualWord) const
static const Packing thePacking
static std::vector< std::string > checklist log
float probabilityXY(QualWordType qualWord) const
void setHasBadPixels(bool flag, QualWordType &qualWord) const
void setProbabilityQ(float prob, QualWordType &qualWord) const
float probabilityY(QualWordType qualWord) const
int qBin(QualWordType qualWord) const
void setSpansTwoROCs(bool flag, QualWordType &qualWord) const
float probabilityX(QualWordType qualWord) const
static void warningOutOfBoundRaw(const char *iVariable, int iRaw, QualWordType const &)
void setIsOnEdge(bool flag, QualWordType &qualWord) const
bool isOnEdge(QualWordType qualWord) const
static void warningOutOfBoundQbin(int, QualWordType const &)
bool hasBadPixels(QualWordType qualWord) const
void setHasFilledProb(bool flag, QualWordType &qualWord) const
static void warningOutOfBoundProb(const char *iVariable, float, QualWordType const &)
void setQBin(int qbin, QualWordType &qualWord) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
bool hasFilledProb(QualWordType qualWord) const