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>
6 
8 public:
9  typedef unsigned int QualWordType;
10 
11 public:
12  class Packing {
13  public:
14  // Constructor: pre-computes masks and shifts from field widths
15  Packing();
16 
17  public:
20  float probX_units;
23  //
26  float probY_units;
29  //
32  char qBin_width;
33  //
36  char edge_width;
37  //
39  int bad_shift;
40  char bad_width;
41  //
45  //
49 
51 
52  //--- Template fit probability, in X and Y directions
53  // To pack: int raw = - log(prob)/log(prob_units)
54  // Unpack : prob = prob_units^{-raw}
55  //
56  //--- We've obsoleted probX and probY in favor of probXY and probQ as of 09/10
57  inline float probabilityX(QualWordType qualWord) const {
59  return -10;
60  }
61  inline float probabilityY(QualWordType qualWord) const {
63  return -10;
64  }
65 
66  inline float probabilityXY(QualWordType qualWord) const {
67  int raw = (qualWord >> probX_shift) & probX_mask;
68  if (raw < 0 || raw > 16383) {
69  warningOutOfBoundRaw("XY", raw, qualWord);
70  raw = 16383;
71  }
72  float prob = (raw == 16383) ? 0 : pow(probX_units, (float)(-raw));
73  // cout << "Bits = " << raw << " --> Prob = " << prob << endl;
74  return prob;
75  }
76  inline float probabilityQ(QualWordType qualWord) const {
77  int raw = (qualWord >> probY_shift) & probY_mask;
78  if (raw < 0 || raw > 255) {
79  warningOutOfBoundRaw("Q", raw, qualWord);
80  raw = 255;
81  }
82  float prob = (raw == 255) ? 0 : pow(probY_units, (float)(-raw));
83  // cout << "Bits = " << raw << " --> Prob = " << prob << endl;
84  return prob;
85  }
86  //
87  //--- Charge `bin' (0,1,2,3 ~ charge, qBin==4 is a new minimum charge state, qBin=5 is unphysical, qBin6,7 = unused)
88  inline int qBin(QualWordType qualWord) const {
89  int qbin = (qualWord >> qBin_shift) & qBin_mask;
90  if (qbin < 0 || qbin > 7) {
91  warningOutOfBoundQbin(qbin, qualWord);
92  qbin = 0;
93  }
94  return qbin;
95  }
96  //--- Quality flags (true or false):
97  //--- cluster is on the edge of the module, or straddles a dead ROC
98  inline bool isOnEdge(QualWordType qualWord) const { return (qualWord >> edge_shift) & edge_mask; }
99  //--- cluster contains bad pixels, or straddles bad column or two-column
100  inline bool hasBadPixels(QualWordType qualWord) const { return (qualWord >> bad_shift) & bad_mask; }
101  //--- the cluster spans two ROCS (and thus contains big pixels)
102  inline bool spansTwoROCs(QualWordType qualWord) const { return (qualWord >> twoROC_shift) & twoROC_mask; }
103  //--- the probability is filled
104  inline bool hasFilledProb(QualWordType qualWord) const {
105  return (qualWord >> hasFilledProb_shift) & hasFilledProb_mask;
106  }
107 
108  //------------------------------------------------------
109  //--- Setters: the inverse of the above.
110  //------------------------------------------------------
111  //
112  inline void setProbabilityXY(float prob, QualWordType& qualWord) const {
113  if (prob < 0 || prob > 1) {
114  warningOutOfBoundProb("XY", prob, qualWord);
115  prob = 0;
116  }
117  double draw = (prob <= 1.6E-13) ? 16383 : -log((double)prob) * probX_1_over_log_units;
118  unsigned int raw = (int)(draw + 0.5); // convert to integer, round correctly
119  // cout << "Prob = " << prob << " --> Bits = " << raw << endl;
120  qualWord |= ((raw & probX_mask) << probX_shift);
121  }
122  inline void setProbabilityQ(float prob, QualWordType& qualWord) const {
123  if (prob < 0 || prob > 1) {
124  warningOutOfBoundProb("Q", prob, qualWord);
125  prob = 0;
126  }
127  double draw = (prob <= 1E-5) ? 255 : -log((double)prob) * probY_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 & probY_mask) << probY_shift);
131  }
132 
133  inline void setQBin(int qbin, QualWordType& qualWord) const {
134  if (qbin < 0 || qbin > 7) {
135  warningOutOfBoundQbin(qbin, qualWord);
136  qbin = 0;
137  }
138  qualWord |= ((qbin & qBin_mask) << qBin_shift);
139  }
140 
141  inline void setIsOnEdge(bool flag, QualWordType& qualWord) const { qualWord |= ((flag & edge_mask) << edge_shift); }
142  inline void setHasBadPixels(bool flag, QualWordType& qualWord) const {
143  qualWord |= ((flag & bad_mask) << bad_shift);
144  }
145  inline void setSpansTwoROCs(bool flag, QualWordType& qualWord) const {
146  qualWord |= ((flag & twoROC_mask) << twoROC_shift);
147  }
148  inline void setHasFilledProb(bool flag, QualWordType& qualWord) const {
149  qualWord |= ((flag & hasFilledProb_mask) << hasFilledProb_shift);
150  }
151  };
152 
153 public:
154  static const Packing thePacking;
155 
156 private:
157  static void warningObsolete();
158  static void warningOutOfBoundQbin(int, QualWordType const&);
159  static void warningOutOfBoundProb(const char* iVariable, float, QualWordType const&);
160  static void warningOutOfBoundRaw(const char* iVariable, int iRaw, QualWordType const&);
161 };
162 
163 #endif
SiPixelRecHitQuality::Packing::probabilityQ
float probabilityQ(QualWordType qualWord) const
Definition: SiPixelRecHitQuality.h:76
SiPixelRecHitQuality::Packing::probX_1_over_log_units
double probX_1_over_log_units
Definition: SiPixelRecHitQuality.h:21
SiPixelRecHitQuality::Packing
Definition: SiPixelRecHitQuality.h:12
SiPixelRecHitQuality::Packing::hasFilledProb
bool hasFilledProb(QualWordType qualWord) const
Definition: SiPixelRecHitQuality.h:104
SiPixelRecHitQuality::Packing::probY_mask
QualWordType probY_mask
Definition: SiPixelRecHitQuality.h:24
SiPixelRecHitQuality::Packing::probY_width
char probY_width
Definition: SiPixelRecHitQuality.h:28
SiPixelRecHitQuality::Packing::qBin_mask
QualWordType qBin_mask
Definition: SiPixelRecHitQuality.h:30
SiPixelRecHitQuality::Packing::probY_units
float probY_units
Definition: SiPixelRecHitQuality.h:26
SiPixelRecHitQuality::Packing::probabilityY
float probabilityY(QualWordType qualWord) const
Definition: SiPixelRecHitQuality.h:61
SiPixelRecHitQuality::Packing::edge_shift
int edge_shift
Definition: SiPixelRecHitQuality.h:35
SiPixelRecHitQuality::Packing::setSpansTwoROCs
void setSpansTwoROCs(bool flag, QualWordType &qualWord) const
Definition: SiPixelRecHitQuality.h:145
SiPixelRecHitQuality::warningOutOfBoundQbin
static void warningOutOfBoundQbin(int, QualWordType const &)
Definition: SiPixelRecHitQuality.cc:61
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:27
SiPixelRecHitQuality::Packing::setIsOnEdge
void setIsOnEdge(bool flag, QualWordType &qualWord) const
Definition: SiPixelRecHitQuality.h:141
SiPixelRecHitQuality::Packing::probX_width
char probX_width
Definition: SiPixelRecHitQuality.h:22
SiPixelRecHitQuality::Packing::isOnEdge
bool isOnEdge(QualWordType qualWord) const
Definition: SiPixelRecHitQuality.h:98
SiPixelRecHitQuality
Definition: SiPixelRecHitQuality.h:7
SiPixelRecHitQuality::Packing::probabilityXY
float probabilityXY(QualWordType qualWord) const
Definition: SiPixelRecHitQuality.h:66
SiPixelRecHitQuality::Packing::bad_mask
QualWordType bad_mask
Definition: SiPixelRecHitQuality.h:38
SiPixelRecHitQuality::Packing::qBin
int qBin(QualWordType qualWord) const
Definition: SiPixelRecHitQuality.h:88
SiPixelRecHitQuality::Packing::hasBadPixels
bool hasBadPixels(QualWordType qualWord) const
Definition: SiPixelRecHitQuality.h:100
SiPixelRecHitQuality::Packing::probX_mask
QualWordType probX_mask
Definition: SiPixelRecHitQuality.h:18
SiPixelRecHitQuality::Packing::spansTwoROCs
bool spansTwoROCs(QualWordType qualWord) const
Definition: SiPixelRecHitQuality.h:102
SiPixelRecHitQuality::Packing::qBin_shift
int qBin_shift
Definition: SiPixelRecHitQuality.h:31
SiPixelRecHitQuality::thePacking
static const Packing thePacking
Definition: SiPixelRecHitQuality.h:154
SiPixelRecHitQuality::QualWordType
unsigned int QualWordType
Definition: SiPixelRecHitQuality.h:9
SiPixelRecHitQuality::Packing::twoROC_shift
int twoROC_shift
Definition: SiPixelRecHitQuality.h:43
SiPixelRecHitQuality::warningOutOfBoundProb
static void warningOutOfBoundProb(const char *iVariable, float, QualWordType const &)
Definition: SiPixelRecHitQuality.cc:66
SiPixelRecHitQuality::warningOutOfBoundRaw
static void warningOutOfBoundRaw(const char *iVariable, int iRaw, QualWordType const &)
Definition: SiPixelRecHitQuality.cc:72
SiPixelRecHitQuality::Packing::setQBin
void setQBin(int qbin, QualWordType &qualWord) const
Definition: SiPixelRecHitQuality.h:133
SiPixelRecHitQuality::Packing::probX_shift
int probX_shift
Definition: SiPixelRecHitQuality.h:19
SiPixelRecHitQuality::Packing::setHasBadPixels
void setHasBadPixels(bool flag, QualWordType &qualWord) const
Definition: SiPixelRecHitQuality.h:142
createfilelist.int
int
Definition: createfilelist.py:10
SiPixelRecHitQuality::Packing::probabilityX
float probabilityX(QualWordType qualWord) const
Definition: SiPixelRecHitQuality.h:57
SiPixelRecHitQuality::Packing::spare_width
char spare_width
Definition: SiPixelRecHitQuality.h:50
SiPixelRecHitQuality::Packing::edge_mask
QualWordType edge_mask
Definition: SiPixelRecHitQuality.h:34
SiPixelRecHitQuality::Packing::bad_shift
int bad_shift
Definition: SiPixelRecHitQuality.h:39
SiPixelRecHitQuality::Packing::bad_width
char bad_width
Definition: SiPixelRecHitQuality.h:40
SiPixelRecHitQuality::Packing::edge_width
char edge_width
Definition: SiPixelRecHitQuality.h:36
SiPixelRecHitQuality::Packing::setProbabilityQ
void setProbabilityQ(float prob, QualWordType &qualWord) const
Definition: SiPixelRecHitQuality.h:122
SiPixelRecHitQuality::Packing::twoROC_width
char twoROC_width
Definition: SiPixelRecHitQuality.h:44
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
SiPixelRecHitQuality::Packing::setProbabilityXY
void setProbabilityXY(float prob, QualWordType &qualWord) const
Definition: SiPixelRecHitQuality.h:112
SiPixelRecHitQuality::Packing::probY_shift
int probY_shift
Definition: SiPixelRecHitQuality.h:25
SiPixelRecHitQuality::Packing::hasFilledProb_width
char hasFilledProb_width
Definition: SiPixelRecHitQuality.h:48
SiPixelRecHitQuality::Packing::probX_units
float probX_units
Definition: SiPixelRecHitQuality.h:20
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
SiPixelRecHitQuality::Packing::setHasFilledProb
void setHasFilledProb(bool flag, QualWordType &qualWord) const
Definition: SiPixelRecHitQuality.h:148
TtFullHadEvtBuilder_cfi.prob
prob
Definition: TtFullHadEvtBuilder_cfi.py:33
SiPixelRecHitQuality::warningObsolete
static void warningObsolete()
Definition: SiPixelRecHitQuality.cc:56
SiPixelRecHitQuality::Packing::hasFilledProb_mask
QualWordType hasFilledProb_mask
Definition: SiPixelRecHitQuality.h:46
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:47
SiPixelRecHitQuality::Packing::twoROC_mask
QualWordType twoROC_mask
Definition: SiPixelRecHitQuality.h:42
SiPixelRecHitQuality::Packing::qBin_width
char qBin_width
Definition: SiPixelRecHitQuality.h:32