test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackResiduals.cc
Go to the documentation of this file.
1 #include <math.h>
4 #include <cstdio>
5 #include <cstring>
6 
8 
9 using namespace reco;
10 
11 TrackResiduals::TrackResiduals () : residualType(X_Y_RESIDUALS)
12 {
13  memset(residuals_, 0, sizeof(residuals_));
14 }
15 
17 {
18  memset(residuals_, 0, sizeof(residuals_));
19 }
20 
22 {
24 }
25 
26 void TrackResiduals::setResidualXY (int idx, double residualX, double residualY)
27 {
28  assert(residualType == X_Y_RESIDUALS);
29  if (idx>=numResiduals) {
30  edm::LogWarning("TrackResiduals")<<" setting residual over the array size.";
31  return;}
32  residuals_[idx] = (pack_residual(residualX) << 4) | pack_residual(residualY);
33 }
34 
35 double TrackResiduals::residualX (int i) const
36 {
37  switch (residualType) {
38  case X_Y_RESIDUALS:
39  return unpack_residual(residuals_[i] >> 4);
40  case X_Y_PULLS:
41  return unpack_pull(residuals_[i] >> 4);
42  default:
43  assert(0);
44  }
45  return 0;
46 }
47 
48 double TrackResiduals::residualY (int i) const
49 {
50  switch (residualType) {
51  case X_Y_RESIDUALS:
52  return unpack_residual(residuals_[i] & 0x0f);
53  case X_Y_PULLS:
54  return unpack_pull(residuals_[i] & 0x0f);
55  default:
56  assert(0);
57  }
58  return 0;
59 }
60 
61 static int index_to_hitpattern (int i_hitpattern, const HitPattern &h)
62 {
63  int i_residuals = 0;
64  assert(i_hitpattern < h.numberOfHits());
65  if (!h.validHitFilter(h.getHitPattern(i_hitpattern)))
66  // asking for residual of invalid hit...
67  return -999;
68  for (int i = 0; i <= i_hitpattern; i++) {
69  if (h.validHitFilter(h.getHitPattern(i)))
70  i_residuals++;
71  }
72  assert(i_residuals > 0);
73  return i_residuals - 1;
74 }
75 
76 double TrackResiduals::residualX (int i, const HitPattern &h) const
77 {
78  int idx = index_to_hitpattern(i, h);
79  if (idx == -999)
80  return -999;
81  return residualX(idx);
82 }
83 
84 double TrackResiduals::residualY (int i, const HitPattern &h) const
85 {
86  int idx = index_to_hitpattern(i, h);
87  if (idx == -999)
88  return -999;
89  return residualY(idx);
90 }
91 
92 void TrackResiduals::setPullXY (int idx, double pullX, double pullY)
93 {
94  assert(residualType == X_Y_PULLS);
95  if (idx>=numResiduals) {
96  edm::LogWarning("TrackResiduals")<<" setting pulls over the array size.";
97  return;}
98 
99  residuals_[idx] = (pack_pull(pullX) << 4) | pack_pull(pullY);
100 }
101 
102 static const double pull_char_to_double[8][2] = {
103  { 0, 0.5 },
104  { 0.5, 1 },
105  { 1, 1.5 },
106  { 1.5, 2 },
107  { 2, 2.5 },
108  { 2.5, 3.5 },
109  { 3.5, 4.5 },
110  { 4.5, 5.5 },
111 };
112 
113 double TrackResiduals::unpack_pull (unsigned char pull)
114 {
115  int sgn = 1 - 2 * ((pull & 0x08) >> 3);
116  unsigned char mag = pull & 0x07;
117  return sgn *
119 }
120 
121 unsigned char TrackResiduals::pack_pull (double pull)
122 {
123  unsigned char sgn = (pull < 0) * 0x08; // 1xxx is -abs(0xxx)
124  int mag = -1;
125  while (++mag < 8 && pull_char_to_double[mag][1] < fabs(pull));
126  return sgn + mag;
127 }
128 
129 
130 double TrackResiduals::unpack_residual (unsigned char pull)
131 {
132  int sgn = 1 - 2 * ((pull & 0x08) >> 3);
133  unsigned char mag = pull & 0x07;
134  return sgn *
136 }
137 
138 unsigned char TrackResiduals::pack_residual (double pull)
139 {
140  unsigned char sgn = (pull < 0) * 0x08; // 1xxx is -abs(0xxx)
141  int mag = -1;
142  while (++mag < 8 && pull_char_to_double[mag][1] < fabs(pull));
143  return sgn + mag;
144 }
145 
146 void TrackResiduals::print (std::ostream &stream) const
147 {
148  stream << "TrackResiduals" << std::endl;
149  std::ios_base::fmtflags flags = stream.flags();
150  stream.setf ( std::ios_base::hex, std::ios_base::basefield );
151  stream.setf ( std::ios_base::showbase );
152  for (int i = 0; i < numResiduals; i++) {
153  unsigned char residual = residuals_[i];
154  printf("0x%x\n", residual);
155 // stream << residual << std::endl;
156  }
157  stream.flags(flags);
158 }
159 
160 void TrackResiduals::print (const HitPattern &h, std::ostream &stream) const
161 {
162  stream << "TrackResiduals" << std::endl;
163  for (int i = 0; i < h.numberOfHits(); i++) {
164  stream << (h.validHitFilter(h.getHitPattern(i)) ?
165  "valid hit: " : "invalid hit: ") <<
166  "( " << residualX(i, h) << " , " << residualY(i, h) << " )" <<
167  std::endl;
168  }
169 }
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
float sgn(float val)
Definition: FWPFMaths.cc:9
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
double residualY(int i, const HitPattern &) const
void setPullXY(int idx, double pullX, double pullY)
static double unpack_residual(unsigned char)
static int index_to_hitpattern(int i_hitpattern, const HitPattern &h)
static const double pull_char_to_double[8][2]
void setResidualType(enum ResidualType)
int numberOfHits() const
Definition: HitPattern.cc:211
unsigned char residuals_[numResiduals]
residuals, bitpacked two hits to a char
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
static bool validHitFilter(uint32_t pattern)
Definition: HitPattern.h:564
double residualX(int i, const HitPattern &) const
static unsigned char pack_residual(double)
void print(std::ostream &stream=std::cout) const
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
void setResidualXY(int idx, double residualX, double residualY)
uint32_t getHitPattern(int position) const
Definition: HitPattern.cc:142
static double unpack_pull(unsigned char)
static unsigned char pack_pull(double)