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