CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ClusterShape.cc
Go to the documentation of this file.
3 
6 
8 
9 #include <vector>
10 #include <fstream>
11 
12 using namespace std;
13 
14 /*****************************************************************************/
16 {
17 }
18 
19 /*****************************************************************************/
21 {
22 }
23 
24 /*****************************************************************************/
25 int ClusterShape::getDirection(int low,int hig, int olow,int ohig)
26 {
27  if(hig == ohig && low == olow) return 0;
28  if(hig >= ohig && low >= olow) return 1;
29  if(hig <= ohig && low <= olow) return -1;
30 
31  return -2;
32 }
33 
34 /*****************************************************************************/
35 bool ClusterShape::processColumn(pair<int,int> pos, bool inTheLoop)
36 {
37  if(x[1] > -1)
38  { // Process previous column
39  if(low < y[0] || x[1] == x[0]) y[0] = low;
40  if(hig > y[1] || x[1] == x[0]) y[1] = hig;
41 
42  if(x[1] > x[0])
43  { // Determine direction
44  int dir = getDirection(low,hig, olow,ohig);
45 
46  // no direction
47  if(dir == -2) return false;
48 
49  if(x[1] > x[0]+1)
50  { // Check if direction changes
51  if(odir*dir == -1)
52  { odir = -2; return false; }
53  }
54 
55  if(x[1] <= x[0]+1 || odir == 0)
56  odir = dir;
57 
58  }
59 
60  olow = low; ohig = hig;
61  }
62  else
63  { // Very first column, initialize
64  x[0] = pos.first;
65  }
66 
67  // Open new column
68  if(inTheLoop)
69  {
70  x[1] = pos.first;
71  low = pos.second;
72  hig = pos.second;
73  }
74 
75  return(true);
76 }
77 
78 /*****************************************************************************/
79 struct lessPixel : public binary_function<SiPixelCluster::Pixel,
80  SiPixelCluster::Pixel,bool>
81 {
83  const SiPixelCluster::Pixel& b) const
84  {
85  // slightly faster by avoiding branches
86  return (a.x < b.x) | ((a.x == b.x) & (a.y < b.y));
87  }
88 };
89 
90 /*****************************************************************************/
92  (const PixelGeomDetUnit& pixelDet,
93  const SiPixelRecHit& recHit, ClusterData& data)
94 {
95  determineShape(pixelDet, *(recHit.cluster()), data);
96 }
97 
99  (const PixelGeomDetUnit& pixelDet,
100  const SiPixelCluster& cluster, ClusterData& data)
101 {
102  // Topology
103  const PixelTopology * theTopology = (&(pixelDet.specificTopology()));
104 
105  // Initialize
106  data.isStraight = true;
107  data.isComplete = true;
108 
109  x[0] = -1; x[1] = -1;
110  y[0] = -1; y[1] = -1;
111  olow = -2; ohig = -2; odir = 0;
112  low = 0; hig = 0;
113 
114  pair<int,int> pos;
115 
116  // Get sorted pixels
117  size_t npixels = cluster.pixelADC().size();
118  pixels_.reserve(npixels);
119  for(size_t i=0; i<npixels; ++i) {
120  pixels_.push_back(cluster.pixel(i));
121  }
122  sort(pixels_.begin(),pixels_.end(),lessPixel());
123 
124  // Look at all the pixels
125  for(const auto& pixel: pixels_)
126  {
127  // Position
128  pos.first = (int)pixel.x;
129  pos.second = (int)pixel.y;
130 
131  // Check if at the edge or big
132  if(theTopology->isItEdgePixelInX(pos.first) ||
133  theTopology->isItEdgePixelInY(pos.second))
134  { data.isComplete = false; } // break; }
135 
136  // Check if straight
137  if(pos.first > x[1])
138  { // column ready
139  if(processColumn(pos, true) == false)
140  { data.isStraight = false; } // break; }
141  }
142  else
143  { // increasing column
144  if(pos.second > hig+1) // at least a pixel is missing
145  { data.isStraight = false; } // break; }
146 
147  hig = pos.second;
148  }
149  }
150  pixels_.clear();
151 
152  // Check if straight, process last column
153  if(processColumn(pos, false) == false)
154  data.isStraight = false;
155 
156  // Treat clusters with big pixel(s) inside
157  const int minPixelRow = cluster.minPixelRow();
158  const int maxPixelRow = cluster.maxPixelRow();
159  for(int ix = minPixelRow + 1;
160  ix < maxPixelRow; ix++)
161  x[1] += theTopology->isItBigPixelInX(ix);
162 
163  const int minPixelCol = cluster.minPixelCol();
164  const int maxPixelCol = cluster.maxPixelCol();
165  for(int iy = minPixelCol + 1;
166  iy < maxPixelCol; iy++)
167  y[1] += theTopology->isItBigPixelInY(iy);
168 
169  // Treat clusters with bix pixel(s) outside, FIXME FIXME
170  unsigned int px = 0;
171  px += theTopology->isItBigPixelInX(minPixelRow);
172  px += theTopology->isItBigPixelInX(maxPixelRow);
173 
174  unsigned int py = 0;
175  py += theTopology->isItBigPixelInY(minPixelCol);
176  py += theTopology->isItBigPixelInY(maxPixelCol);
177 
178  data.hasBigPixelsOnlyInside = (px <= 0 && py <= 0);
179 
180  //if( (px > 0 || py > 0) && odir == 0)
181  if( !data.hasBigPixelsOnlyInside && odir == 0)
182  {
183  // if outside and don't know the direction FIXME?
184  data.isComplete = false;
185  }
186  // else
187  { // FIXME do it
188  assert((px+1)*(py+1) <= data.size.capacity());
189  const int pre_dx = x[1] - x[0];
190  const int pre_dy = y[1] - y[0];
191  for(unsigned int ax = 0; ax <= px; ax++)
192  for(unsigned int ay = 0; ay <= py; ay++)
193  {
194  int dx = pre_dx + ax;
195  int dy = pre_dy + ay;
196  if(odir != 0) dy *= odir;
197 
198  pair<int,int> s(dx,dy);
199  data.size.push_back_unchecked(s);
200  }
201  }
202 }
int i
Definition: DBlmapReader.cc:9
int minPixelCol() const
assert(m_qm.get())
void determineShape(const PixelGeomDetUnit &pixelDet, const SiPixelRecHit &recHit, ClusterData &data)
Definition: ClusterShape.cc:92
bool isComplete
Definition: ClusterData.h:12
int maxPixelRow() const
T x() const
Cartesian x coordinate.
virtual bool isItEdgePixelInX(int ixbin) const =0
int minPixelRow() const
bool processColumn(std::pair< int, int > pos, bool inTheLoop)
Definition: ClusterShape.cc:35
bool operator()(const SiPixelCluster::Pixel &a, const SiPixelCluster::Pixel &b) const
Definition: ClusterShape.cc:82
const std::vector< uint16_t > & pixelADC() const
virtual bool isItBigPixelInX(const int ixbin) const =0
ClusterRef cluster() const
Definition: SiPixelRecHit.h:49
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
bool hasBigPixelsOnlyInside
Definition: ClusterData.h:12
double b
Definition: hdecay.h:120
int maxPixelCol() const
Pixel cluster – collection of neighboring pixels above threshold.
virtual bool isItEdgePixelInY(int iybin) const =0
Pixel pixel(int i) const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
int getDirection(int low, int hig, int olow, int ohig)
Definition: ClusterShape.cc:25
void push_back_unchecked(const T &value)
Definition: VecArray.h:85
double a
Definition: hdecay.h:121
ArrayType size
Definition: ClusterData.h:11
dbl *** dir
Definition: mlp_gen.cc:35
static constexpr size_type capacity() noexcept
Definition: VecArray.h:71
bool isStraight
Definition: ClusterData.h:12
Our base class.
Definition: SiPixelRecHit.h:23
virtual bool isItBigPixelInY(const int iybin) const =0