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