CMS 3D CMS Logo

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