CMS 3D CMS Logo

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 /*****************************************************************************/
80  (const PixelGeomDetUnit& pixelDet,
82 {
83  determineShape(pixelDet, *(recHit.cluster()), data);
84 }
85 
87  (const PixelGeomDetUnit& pixelDet,
88  const SiPixelCluster& cluster, ClusterData& data)
89 {
90  // Topology
91  const PixelTopology * theTopology = (&(pixelDet.specificTopology()));
92 
93  // Initialize
94  data.isStraight = true;
95  data.isComplete = true;
96 
97  x[0] = -1; x[1] = -1;
98  y[0] = -1; y[1] = -1;
99  olow = -2; ohig = -2; odir = 0;
100  low = 0; hig = 0;
101 
102  pair<int,int> pos;
103 
104  // Get sorted pixels
105  size_t npixels = cluster.pixelADC().size();
106  pixels_.reserve(npixels);
107  for(size_t i=0; i<npixels; ++i) {
108  pixels_.push_back(cluster.pixel(i));
109  }
110  sort(pixels_.begin(),pixels_.end(),[](auto const& a, auto const& b){
111  // slightly faster by avoiding branches
112  return (a.x < b.x) | ((a.x == b.x) & (a.y < b.y));
113  });
114 
115  // Look at all the pixels
116  for(const auto& pixel: pixels_)
117  {
118  // Position
119  pos.first = (int)pixel.x;
120  pos.second = (int)pixel.y;
121 
122  // Check if at the edge or big
123  if(theTopology->isItEdgePixelInX(pos.first) ||
124  theTopology->isItEdgePixelInY(pos.second))
125  { data.isComplete = false; } // break; }
126 
127  // Check if straight
128  if(pos.first > x[1])
129  { // column ready
130  if(processColumn(pos, true) == false)
131  { data.isStraight = false; } // break; }
132  }
133  else
134  { // increasing column
135  if(pos.second > hig+1) // at least a pixel is missing
136  { data.isStraight = false; } // break; }
137 
138  hig = pos.second;
139  }
140  }
141  pixels_.clear();
142 
143  // Check if straight, process last column
144  if(processColumn(pos, false) == false)
145  data.isStraight = false;
146 
147  // Treat clusters with big pixel(s) inside
148  const int minPixelRow = cluster.minPixelRow();
149  const int maxPixelRow = cluster.maxPixelRow();
150  for(int ix = minPixelRow + 1;
151  ix < maxPixelRow; ix++)
152  x[1] += theTopology->isItBigPixelInX(ix);
153 
154  const int minPixelCol = cluster.minPixelCol();
155  const int maxPixelCol = cluster.maxPixelCol();
156  for(int iy = minPixelCol + 1;
157  iy < maxPixelCol; iy++)
158  y[1] += theTopology->isItBigPixelInY(iy);
159 
160  // Treat clusters with bix pixel(s) outside, FIXME FIXME
161  unsigned int px = 0;
162  px += theTopology->isItBigPixelInX(minPixelRow);
163  px += theTopology->isItBigPixelInX(maxPixelRow);
164 
165  unsigned int py = 0;
166  py += theTopology->isItBigPixelInY(minPixelCol);
167  py += theTopology->isItBigPixelInY(maxPixelCol);
168 
169  data.hasBigPixelsOnlyInside = (px <= 0 && py <= 0);
170 
171  //if( (px > 0 || py > 0) && odir == 0)
172  if( !data.hasBigPixelsOnlyInside && odir == 0)
173  {
174  // if outside and don't know the direction FIXME?
175  data.isComplete = false;
176  }
177  // else
178  { // FIXME do it
179  assert((px+1)*(py+1) <= data.size.capacity());
180  const int pre_dx = x[1] - x[0];
181  const int pre_dy = y[1] - y[0];
182  for(unsigned int ax = 0; ax <= px; ax++)
183  for(unsigned int ay = 0; ay <= py; ay++)
184  {
185  int dx = pre_dx + ax;
186  int dy = pre_dy + ay;
187  if(odir != 0) dy *= odir;
188 
189  pair<int,int> s(dx,dy);
190  data.size.push_back_unchecked(s);
191  }
192  }
193 }
int minPixelCol() const
virtual bool isItEdgePixelInX(int ixbin) const =0
void determineShape(const PixelGeomDetUnit &pixelDet, const SiPixelRecHit &recHit, ClusterData &data)
Definition: ClusterShape.cc:80
virtual bool isItEdgePixelInY(int iybin) const =0
virtual bool isItBigPixelInX(int ixbin) const =0
bool isComplete
Definition: ClusterData.h:12
int maxPixelRow() const
int minPixelRow() const
bool processColumn(std::pair< int, int > pos, bool inTheLoop)
Definition: ClusterShape.cc:35
virtual bool isItBigPixelInY(int iybin) const =0
const std::vector< uint16_t > & pixelADC() const
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.
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:83
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