CMS 3D CMS Logo

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 == -1.0f) {
127  // default prob in absence of Q probability computation is -1 --> set to 0
128  prob = 0;
129  } else if (prob < 0.0f || prob > 1.0f + std::numeric_limits<float>::epsilon()) {
130  warningOutOfBoundProb("Q", prob, qualWord);
131  prob = 0;
132  }
133  double draw = (prob <= 1E-5) ? 255 : -log((double)prob) * probY_1_over_log_units;
134  unsigned int raw = (int)(draw + 0.5); // convert to integer, round correctly
135  // cout << "Prob = " << prob << " --> Bits = " << raw << endl;
136  qualWord |= ((raw & probY_mask) << probY_shift);
137  }
138 
139  inline void setQBin(int qbin, QualWordType& qualWord) const {
140  if (qbin < 0 || qbin > 7) {
141  warningOutOfBoundQbin(qbin, qualWord);
142  qbin = 0;
143  }
144  qualWord |= ((qbin & qBin_mask) << qBin_shift);
145  }
146 
147  inline void setIsOnEdge(bool flag, QualWordType& qualWord) const { qualWord |= ((flag & edge_mask) << edge_shift); }
148  inline void setHasBadPixels(bool flag, QualWordType& qualWord) const {
149  qualWord |= ((flag & bad_mask) << bad_shift);
150  }
151  inline void setSpansTwoROCs(bool flag, QualWordType& qualWord) const {
152  qualWord |= ((flag & twoROC_mask) << twoROC_shift);
153  }
154  inline void setHasFilledProb(bool flag, QualWordType& qualWord) const {
155  qualWord |= ((flag & hasFilledProb_mask) << hasFilledProb_shift);
156  }
157  };
158 
159 public:
160  static const Packing thePacking;
161 
162 private:
163  static void warningObsolete();
164  static void warningOutOfBoundQbin(int, QualWordType const&);
165  static void warningOutOfBoundProb(const char* iVariable, float, QualWordType const&);
166  static void warningOutOfBoundRaw(const char* iVariable, int iRaw, QualWordType const&);
167 };
168 
169 #endif
static const Packing thePacking
float probabilityY(QualWordType qualWord) const
bool hasFilledProb(QualWordType qualWord) const
float probabilityXY(QualWordType qualWord) const
void setHasBadPixels(bool flag, QualWordType &qualWord) const
constexpr int pow(int x)
Definition: conifer.h:24
bool spansTwoROCs(QualWordType qualWord) const
bool hasBadPixels(QualWordType qualWord) const
void setSpansTwoROCs(bool flag, QualWordType &qualWord) const
float probabilityQ(QualWordType qualWord) const
def draw(name, histos, styles=_defaultStyles, legendLabels=[], kwargs)
void setIsOnEdge(bool flag, QualWordType &qualWord) const
int qBin(QualWordType qualWord) const
void setHasFilledProb(bool flag, QualWordType &qualWord) const
void setQBin(int qbin, QualWordType &qualWord) const
double f[11][100]
bool isOnEdge(QualWordType qualWord) const
static void warningOutOfBoundRaw(const char *iVariable, int iRaw, QualWordType const &)
void setProbabilityQ(float prob, QualWordType &qualWord) const
float probabilityX(QualWordType qualWord) const
static void warningOutOfBoundQbin(int, QualWordType const &)
static void warningOutOfBoundProb(const char *iVariable, float, QualWordType const &)
void setProbabilityXY(float prob, QualWordType &qualWord) const