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