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