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:
21  float probX_units;
24  //
27  float probY_units;
30  //
33  char qBin_width;
34  //
37  char edge_width;
38  //
40  int bad_shift;
41  char bad_width;
42  //
46  //
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
SiPixelRecHitQuality::Packing::probabilityQ
float probabilityQ(QualWordType qualWord) const
Definition: SiPixelRecHitQuality.h:81
SiPixelRecHitQuality::Packing::probX_1_over_log_units
double probX_1_over_log_units
Definition: SiPixelRecHitQuality.h:22
SiPixelRecHitQuality::Packing
Definition: SiPixelRecHitQuality.h:13
MessageLogger.h
SiPixelRecHitQuality::Packing::hasFilledProb
bool hasFilledProb(QualWordType qualWord) const
Definition: SiPixelRecHitQuality.h:112
SiPixelRecHitQuality::Packing::probY_mask
QualWordType probY_mask
Definition: SiPixelRecHitQuality.h:25
SiPixelRecHitQuality::Packing::probY_width
char probY_width
Definition: SiPixelRecHitQuality.h:29
SiPixelRecHitQuality::Packing::qBin_mask
QualWordType qBin_mask
Definition: SiPixelRecHitQuality.h:31
SiPixelRecHitQuality::Packing::probY_units
float probY_units
Definition: SiPixelRecHitQuality.h:27
SiPixelRecHitQuality::Packing::probabilityY
float probabilityY(QualWordType qualWord) const
Definition: SiPixelRecHitQuality.h:63
SiPixelRecHitQuality::Packing::edge_shift
int edge_shift
Definition: SiPixelRecHitQuality.h:36
SiPixelRecHitQuality::Packing::setSpansTwoROCs
void setSpansTwoROCs(bool flag, QualWordType &qualWord) const
Definition: SiPixelRecHitQuality.h:157
ntuplePlotting.draw
def draw(name, histos, styles=_defaultStyles, legendLabels=[], **kwargs)
Definition: ntuplePlotting.py:25
SiPixelRecHitQuality::Packing::probY_1_over_log_units
double probY_1_over_log_units
Definition: SiPixelRecHitQuality.h:28
SiPixelRecHitQuality::Packing::setIsOnEdge
void setIsOnEdge(bool flag, QualWordType &qualWord) const
Definition: SiPixelRecHitQuality.h:153
SiPixelRecHitQuality::Packing::probX_width
char probX_width
Definition: SiPixelRecHitQuality.h:23
SiPixelRecHitQuality::Packing::isOnEdge
bool isOnEdge(QualWordType qualWord) const
Definition: SiPixelRecHitQuality.h:106
SiPixelRecHitQuality
Definition: SiPixelRecHitQuality.h:8
SiPixelRecHitQuality::Packing::probabilityXY
float probabilityXY(QualWordType qualWord) const
Definition: SiPixelRecHitQuality.h:69
SiPixelRecHitQuality::Packing::bad_mask
QualWordType bad_mask
Definition: SiPixelRecHitQuality.h:39
SiPixelRecHitQuality::Packing::qBin
int qBin(QualWordType qualWord) const
Definition: SiPixelRecHitQuality.h:95
SiPixelRecHitQuality::Packing::hasBadPixels
bool hasBadPixels(QualWordType qualWord) const
Definition: SiPixelRecHitQuality.h:108
SiPixelRecHitQuality::Packing::probX_mask
QualWordType probX_mask
Definition: SiPixelRecHitQuality.h:19
SiPixelRecHitQuality::Packing::spansTwoROCs
bool spansTwoROCs(QualWordType qualWord) const
Definition: SiPixelRecHitQuality.h:110
SiPixelRecHitQuality::Packing::qBin_shift
int qBin_shift
Definition: SiPixelRecHitQuality.h:32
SiPixelRecHitQuality::thePacking
static const Packing thePacking
Definition: SiPixelRecHitQuality.h:166
SiPixelRecHitQuality::QualWordType
unsigned int QualWordType
Definition: SiPixelRecHitQuality.h:10
SiPixelRecHitQuality::Packing::twoROC_shift
int twoROC_shift
Definition: SiPixelRecHitQuality.h:44
SiPixelRecHitQuality::Packing::setQBin
void setQBin(int qbin, QualWordType &qualWord) const
Definition: SiPixelRecHitQuality.h:144
SiPixelRecHitQuality::Packing::probX_shift
int probX_shift
Definition: SiPixelRecHitQuality.h:20
edm::LogWarning
Definition: MessageLogger.h:141
SiPixelRecHitQuality::Packing::setHasBadPixels
void setHasBadPixels(bool flag, QualWordType &qualWord) const
Definition: SiPixelRecHitQuality.h:154
createfilelist.int
int
Definition: createfilelist.py:10
SiPixelRecHitQuality::Packing::probabilityX
float probabilityX(QualWordType qualWord) const
Definition: SiPixelRecHitQuality.h:58
SiPixelRecHitQuality::Packing::spare_width
char spare_width
Definition: SiPixelRecHitQuality.h:51
SiPixelRecHitQuality::Packing::edge_mask
QualWordType edge_mask
Definition: SiPixelRecHitQuality.h:35
SiPixelRecHitQuality::Packing::bad_shift
int bad_shift
Definition: SiPixelRecHitQuality.h:40
SiPixelRecHitQuality::Packing::bad_width
char bad_width
Definition: SiPixelRecHitQuality.h:41
SiPixelRecHitQuality::Packing::edge_width
char edge_width
Definition: SiPixelRecHitQuality.h:37
SiPixelRecHitQuality::Packing::setProbabilityQ
void setProbabilityQ(float prob, QualWordType &qualWord) const
Definition: SiPixelRecHitQuality.h:132
SiPixelRecHitQuality::Packing::twoROC_width
char twoROC_width
Definition: SiPixelRecHitQuality.h:45
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
SiPixelRecHitQuality::Packing::setProbabilityXY
void setProbabilityXY(float prob, QualWordType &qualWord) const
Definition: SiPixelRecHitQuality.h:120
SiPixelRecHitQuality::Packing::probY_shift
int probY_shift
Definition: SiPixelRecHitQuality.h:26
SiPixelRecHitQuality::Packing::hasFilledProb_width
char hasFilledProb_width
Definition: SiPixelRecHitQuality.h:49
SiPixelRecHitQuality::Packing::probX_units
float probX_units
Definition: SiPixelRecHitQuality.h:21
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
SiPixelRecHitQuality::Packing::setHasFilledProb
void setHasFilledProb(bool flag, QualWordType &qualWord) const
Definition: SiPixelRecHitQuality.h:160
TtFullHadEvtBuilder_cfi.prob
prob
Definition: TtFullHadEvtBuilder_cfi.py:33
SiPixelRecHitQuality::Packing::hasFilledProb_mask
QualWordType hasFilledProb_mask
Definition: SiPixelRecHitQuality.h:47
SiPixelRecHitQuality::Packing::Packing
Packing()
Definition: SiPixelRecHitQuality.cc:5
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116
SiPixelRecHitQuality::Packing::hasFilledProb_shift
int hasFilledProb_shift
Definition: SiPixelRecHitQuality.h:48
SiPixelRecHitQuality::Packing::twoROC_mask
QualWordType twoROC_mask
Definition: SiPixelRecHitQuality.h:43
SiPixelRecHitQuality::Packing::qBin_width
char qBin_width
Definition: SiPixelRecHitQuality.h:33