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 //--- pow():
5 #include <cmath>
7 
9 public:
10  typedef unsigned int QualWordType;
11 
12 public:
13  class Packing {
14  public:
15  // Constructor: pre-computes masks and shifts from field widths
16  Packing();
17 
18  public:
19  QualWordType probX_mask;
21  float probX_units;
24  //
25  QualWordType probY_mask;
27  float probY_units;
30  //
31  QualWordType qBin_mask;
33  char qBin_width;
34  //
35  QualWordType edge_mask;
37  char edge_width;
38  //
39  QualWordType bad_mask;
40  int bad_shift;
41  char bad_width;
42  //
43  QualWordType twoROC_mask;
46  //
47  QualWordType hasFilledProb_mask;
50 
52 
53  //--- Template fit probability, in X and Y directions
54  // To pack: int raw = - log(prob)/log(prob_units)
55  // Unpack : prob = prob_units^{-raw}
56  //
57  //--- We've obsoleted probX and probY in favor of probXY and probQ as of 09/10
58  inline float probabilityX(QualWordType qualWord) const {
59  edm::LogWarning("ObsoleteVariable")
60  << "Since 39x, probabilityX and probabilityY have been replaced by probabilityXY and probabilityQ";
61  return -10;
62  }
63  inline float probabilityY(QualWordType qualWord) const {
64  edm::LogWarning("ObsoleteVariable")
65  << "Since 39x, probabilityX and probabilityY have been replaced by probabilityXY and probabilityQ";
66  return -10;
67  }
68 
69  inline float probabilityXY(QualWordType qualWord) const {
70  int raw = (qualWord >> probX_shift) & probX_mask;
71  if (raw < 0 || raw > 16383) {
72  edm::LogWarning("OutOfBounds")
73  << "Probability XY outside the bounds of the quality word. Defaulting to Prob=0. Raw = " << raw
74  << " QualityWord = " << qualWord;
75  raw = 16383;
76  }
77  float prob = (raw == 16383) ? 0 : pow(probX_units, (float)(-raw));
78  // cout << "Bits = " << raw << " --> Prob = " << prob << endl;
79  return prob;
80  }
81  inline float probabilityQ(QualWordType qualWord) const {
82  int raw = (qualWord >> probY_shift) & probY_mask;
83  if (raw < 0 || raw > 255) {
84  edm::LogWarning("OutOfBounds")
85  << "Probability Q outside the bounds of the quality word. Defaulting to Prob=0. Raw = " << raw
86  << " QualityWord = " << qualWord;
87  raw = 255;
88  }
89  float prob = (raw == 255) ? 0 : pow(probY_units, (float)(-raw));
90  // cout << "Bits = " << raw << " --> Prob = " << prob << endl;
91  return prob;
92  }
93  //
94  //--- Charge `bin' (0,1,2,3 ~ charge, qBin==4 is a new minimum charge state, qBin=5 is unphysical, qBin6,7 = unused)
95  inline int qBin(QualWordType qualWord) const {
96  int qbin = (qualWord >> qBin_shift) & qBin_mask;
97  if (qbin < 0 || qbin > 7) {
98  edm::LogWarning("OutOfBounds") << "Qbin outside the bounds of the quality word. Defaulting to Qbin=0. Qbin = "
99  << qbin << " QualityWord = " << qualWord;
100  qbin = 0;
101  }
102  return qbin;
103  }
104  //--- Quality flags (true or false):
105  //--- cluster is on the edge of the module, or straddles a dead ROC
106  inline bool isOnEdge(QualWordType qualWord) const { return (qualWord >> edge_shift) & edge_mask; }
107  //--- cluster contains bad pixels, or straddles bad column or two-column
108  inline bool hasBadPixels(QualWordType qualWord) const { return (qualWord >> bad_shift) & bad_mask; }
109  //--- the cluster spans two ROCS (and thus contains big pixels)
110  inline bool spansTwoROCs(QualWordType qualWord) const { return (qualWord >> twoROC_shift) & twoROC_mask; }
111  //--- the probability is filled
112  inline bool hasFilledProb(QualWordType qualWord) const {
113  return (qualWord >> hasFilledProb_shift) & hasFilledProb_mask;
114  }
115 
116  //------------------------------------------------------
117  //--- Setters: the inverse of the above.
118  //------------------------------------------------------
119  //
120  inline void setProbabilityXY(float prob, QualWordType& qualWord) const {
121  if (prob < 0 || prob > 1) {
122  edm::LogWarning("OutOfBounds")
123  << "Prob XY outside the bounds of the quality word. Defaulting to Prob=0. Prob = " << prob
124  << " QualityWord = " << qualWord;
125  prob = 0;
126  }
127  double draw = (prob <= 1.6E-13) ? 16383 : -log((double)prob) * probX_1_over_log_units;
128  unsigned int raw = (int)(draw + 0.5); // convert to integer, round correctly
129  // cout << "Prob = " << prob << " --> Bits = " << raw << endl;
130  qualWord |= ((raw & probX_mask) << probX_shift);
131  }
132  inline void setProbabilityQ(float prob, QualWordType& qualWord) const {
133  if (prob < 0 || prob > 1) {
134  edm::LogWarning("OutOfBounds") << "Prob Q outside the bounds of the quality word. Defaulting to Prob=0. Prob = "
135  << prob << " QualityWord = " << qualWord;
136  prob = 0;
137  }
138  double draw = (prob <= 1E-5) ? 255 : -log((double)prob) * probY_1_over_log_units;
139  unsigned int raw = (int)(draw + 0.5); // convert to integer, round correctly
140  // cout << "Prob = " << prob << " --> Bits = " << raw << endl;
141  qualWord |= ((raw & probY_mask) << probY_shift);
142  }
143 
144  inline void setQBin(int qbin, QualWordType& qualWord) const {
145  if (qbin < 0 || qbin > 7) {
146  edm::LogWarning("OutOfBounds") << "Qbin outside the bounds of the quality word. Defaulting to Qbin=0. Qbin = "
147  << qbin << " QualityWord = " << qualWord;
148  qbin = 0;
149  }
150  qualWord |= ((qbin & qBin_mask) << qBin_shift);
151  }
152 
153  inline void setIsOnEdge(bool flag, QualWordType& qualWord) const { qualWord |= ((flag & edge_mask) << edge_shift); }
154  inline void setHasBadPixels(bool flag, QualWordType& qualWord) const {
155  qualWord |= ((flag & bad_mask) << bad_shift);
156  }
157  inline void setSpansTwoROCs(bool flag, QualWordType& qualWord) const {
158  qualWord |= ((flag & twoROC_mask) << twoROC_shift);
159  }
160  inline void setHasFilledProb(bool flag, QualWordType& qualWord) const {
161  qualWord |= ((flag & hasFilledProb_mask) << hasFilledProb_shift);
162  }
163  };
164 
165 public:
166  static const Packing thePacking;
167 };
168 
169 #endif
float probabilityQ(QualWordType qualWord) const
void setProbabilityXY(float prob, QualWordType &qualWord) const
bool spansTwoROCs(QualWordType qualWord) const
static const Packing thePacking
float probabilityXY(QualWordType qualWord) const
def draw(name, histos, styles=_defaultStyles, legendLabels=[], kwargs)
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
void setIsOnEdge(bool flag, QualWordType &qualWord) const
bool isOnEdge(QualWordType qualWord) const
bool hasBadPixels(QualWordType qualWord) const
void setHasFilledProb(bool flag, QualWordType &qualWord) const
void setQBin(int qbin, QualWordType &qualWord) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
bool hasFilledProb(QualWordType qualWord) const