BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
MucMark.cxx
Go to the documentation of this file.
1//------------------------------------------------------------------------------|
2// [File ]: MucMark.cxx |
3// [Brief ]: Source file of MucMark class for encapsulation |
4// [Author]: Xie Yuguang, <[email protected]> |
5// [Date ]: Oct 19, 2006 |
6//------------------------------------------------------------------------------|
7
8
9#include<iostream>
10#include<vector>
11#include<cmath>
12
14#include "MucCalibAlg/MucMark.h"
15
16using namespace std;
17
18// Constructor
19MucMark::MucMark( int part, int segment, int layer, int strip )
20{
21 m_Part = part;
22 m_Segment = segment;
23 m_Layer = layer;
24 m_Strip = strip;
25}
26
27// Destructor
29
30// Operator ==
32{
33 if( this == &other ) return true;
34
35 if( (*this).Part() == other.Part() &&
36 (*this).Segment() == other.Segment() &&
37 (*this).Layer() == other.Layer() &&
38 (*this).Strip() == other.Strip() )
39 return true;
40 else
41 return false;
42}
43
44// Set properties
45bool MucMark::SetPart( int part )
46{
47 if( part > PART_MAX || part < 0 ) {
48 cout << "part overflow:\t" << part << endl;
49 return false;
50 }
51 else {
52 m_Part = part;
53 return true;
54 }
55}
56
57bool MucMark::SetSegment( int segment )
58{
59 if( segment > ((m_Part == BRID)?B_SEG_NUM:E_SEG_NUM) || segment < 0 ) {
60 cout << "segment overflow:\t" << segment << endl;
61 return false;
62 }
63 else {
64 m_Segment = segment;
65 return true;
66 }
67}
68
69bool MucMark::SetLayer( int layer )
70{
71 if( layer > ((m_Part == BRID)?B_LAY_NUM:E_LAY_NUM) || layer < 0 ) {
72 cout << "layer overflow:\t" << layer << endl;
73 return false;
74 }
75 else {
76 m_Layer = layer;
77 return true;
78 }
79}
80
81bool MucMark::SetStrip( int strip )
82{
83 if( strip > STRIP_INBOX_MAX || strip < 0 ) {
84 cout << "strip overflow:\t" << strip << endl;
85 return false;
86 }
87 else {
88 m_Strip = strip;
89 return true;
90 }
91}
92
93// Get properties
94int MucMark::Part() { return m_Part; }
95int MucMark::Segment() { return m_Segment; }
96int MucMark::Layer() { return m_Layer; }
97int MucMark::Strip() { return m_Strip; }
98
99// Judge whether mark itself is in a Col or not
100int MucMark::IsInCol( int part, int segment, int layer, int strip, mark_col &aCol )
101{
102 for( unsigned int i=0; i<aCol.size(); i++ ) {
103 if( part == aCol[i]->Part() &&
104 segment == aCol[i]->Segment() &&
105 layer == aCol[i]->Layer() &&
106 strip == aCol[i]->Strip() )
107 return i;
108 }
109
110 return -1;
111}
112
114{
115 for( unsigned int i=0; i<aCol.size(); i++ ) {
116 if( (*this) == (*aCol[i]) ) return i;
117 }
118
119 return -1;
120}
121
122int MucMark::IsInCol( vector< mark_col > &aClusterCol )
123{
124 for( unsigned int i=0; i<aClusterCol.size(); i++ ) {
125 if( (*this).IsInCol ( aClusterCol[i] ) ) return i;
126 }
127
128 return -1;
129}
130
131// Return the number of mark itself in a Col
133{
134 int num = 0;
135
136 for( unsigned int i=0; i<aCol.size(); i++ ) {
137 if( (*this) == (*aCol[i]) ) num ++;
138 }
139
140 return num;
141}
142
143// Judge whether mark itself is in the same segment with the other
145{
146 if( (*this).Part() == other.Part() &&
147 (*this).Segment() == other.Segment() )
148 return true;
149 else
150 return false;
151}
152
153// Judge whether mark itself is in the same box with the other
155{
156 if( (*this).Part() == other.Part() &&
157 (*this).Segment() == other.Segment() &&
158 (*this).Layer() == other.Layer() )
159 return true;
160 else
161 return false;
162}
163
164// Judge whether mark itself is a neighbor with the other
166{
167 if( (*this).Part() == other.Part() &&
168 (*this).Segment() == other.Segment() &&
169 (*this).Layer() == other.Layer() &&
170 fabs( (*this).Strip() - other.Strip() ) == 1 )
171 return true;
172 else
173 return false;
174}
175
176// Judge whether mark itself is a neighbor with a multi hit
178{
179 for( unsigned int i=0; i<aCluster.size(); i++ ) {
180 if( (*this).IsNeighborWith((*aCluster[i])) )
181 return true;
182 }
183
184 return false;
185}
186
187// Return a cluster Col from a given mark Col
188vector< mark_col > MucMark::CreateClusterCol_A( mark_col &aMarkCol )
189{
190 vector< mark_col > aClusterCol;
191 mark_col checkedMarkCol;
192
193 int recordFlag = 0;
194 unsigned int circle = 0;
195
196 for( unsigned int i=0; i<aMarkCol.size(); i++ )
197 {
198 recordFlag = 0;
199 for( unsigned int j=0; j< aClusterCol.size(); j++ )
200 {
201 if( (*aMarkCol[i]).IsInCol(aClusterCol[j]) !=-1 ) {
202 recordFlag = 1;
203 break;
204 }
205 else if( (*aMarkCol[i]).IsNeighborWith(aClusterCol[j]) )
206 {
207 aClusterCol[j].push_back( aMarkCol[i] );
208 recordFlag = 1;
209 break;
210 }
211 }
212
213 if( recordFlag == 0 )
214 {
215 mark_col aCluster;
216 aCluster.push_back( aMarkCol[i] );
217 aClusterCol.push_back( aCluster );
218
219 circle =0;
220 do {
221 circle ++;
222 for( unsigned int j = i+1; j<aMarkCol.size(); j++ )
223 {
224 if( (*aMarkCol[j]).IsInCol(aClusterCol.back()) !=-1 ) continue;
225 else if( (*aMarkCol[j]).IsNeighborWith( aClusterCol.back()) )
226 aClusterCol.back().push_back( aMarkCol[j] );
227 }
228 } while( circle < aMarkCol.size()-i-1);
229 }
230 }
231
232 return aClusterCol;
233}
234
235vector< mark_col > MucMark::CreateClusterCol_B( mark_col &aMarkCol)
236{
237 vector< mark_col > aClusterCol;
238 mark_col checkedMarkCol;
239
240 unsigned int circle = 0;
241 for( unsigned int i=0; i<aMarkCol.size(); i++ )
242 {
243 if( (*aMarkCol[i]).IsInCol(checkedMarkCol) !=-1 ) continue;
244
245 mark_col aCluster;
246 aCluster.push_back( aMarkCol[i] );
247 aClusterCol.push_back( aCluster );
248 checkedMarkCol.push_back( aMarkCol[i] );
249
250 circle = 0;
251 do {
252 for( unsigned int j = i+1; j<aMarkCol.size(); j++ )
253 {
254 if( (*aMarkCol[j]).IsInCol(checkedMarkCol) != -1) continue;
255 else if( (*aMarkCol[j]).IsNeighborWith( aClusterCol.back() ) ) {
256 aClusterCol.back().push_back( aMarkCol[j] );
257 checkedMarkCol.push_back( aMarkCol[j] );
258 }
259 }
260 circle ++;
261 } while(circle < aMarkCol.size()-i-1);
262 }
263
264 return aClusterCol;
265}
266
267vector< mark_col > MucMark::CreateClusterCol_C( mark_col &aMarkCol)
268{
269 MucMark tmpMark;
270 vector< mark_col > aClusterCol;
271 mark_col copyMarkCol;
272 copyMarkCol = aMarkCol;
273
274 mark_col::iterator it1;
275 while( copyMarkCol.size() !=0 ) // while 1
276 {
277 it1 = copyMarkCol.begin();
278 mark_col aCluster;
279 aCluster.push_back( copyMarkCol[0] );
280 aClusterCol.push_back( aCluster );
281
282 copyMarkCol.erase( it1 );
283 unsigned int circle = 0;
284 unsigned int size = 0;
285 unsigned int beginsize = copyMarkCol.size();
286 while( circle < beginsize ) // while 2
287 {
288 mark_col::iterator it2;
289 size = copyMarkCol.size();
290 for( unsigned int j=0, headNum=0; j < size; j++ )
291 {
292 it2 = copyMarkCol.begin() + headNum;
293 if( (copyMarkCol[headNum])->IsNeighborWith( aClusterCol.back() ) ) {
294 aClusterCol.back().push_back( (copyMarkCol[headNum]) );
295 copyMarkCol.erase(it2);
296 }
297 else headNum ++;
298 } // end for
299
300 circle ++;
301 }; // End while 2
302
303 }; // End while 1
304
305 return aClusterCol;
306}
307
308vector< mark_col > MucMark::CreateClusterCol_D( mark_col &aMarkCol )
309{
310 vector< mark_col > aClusterCol;
311
312 bool recordFlag = false;
313 unsigned int circle = 0;
314
315 for( unsigned int i=0; i<aMarkCol.size(); i++ )
316 {
317 recordFlag = false;
318 for( int j= aClusterCol.size()-1; j>-1; j-- )
319 {
320 if( (*aMarkCol[i]).IsInCol(aClusterCol[j]) !=-1 ) {
321 recordFlag = true;
322 break;
323 }
324 else if( (*aMarkCol[i]).IsNeighborWith(aClusterCol[j]) )
325 {
326 aClusterCol[j].push_back( aMarkCol[i] );
327 recordFlag = true;
328 break;
329 }
330 }
331
332 if( recordFlag == false )
333 {
334 mark_col aCluster;
335 aCluster.push_back( aMarkCol[i] );
336 aClusterCol.push_back( aCluster );
337
338 circle =0;
339 do {
340 circle ++;
341 for( unsigned int j = i+1; j<aMarkCol.size(); j++ )
342 {
343 if( (*aMarkCol[j]).IsInCol(aClusterCol.back()) !=-1 ) continue;
344 else if( (*aMarkCol[j]).IsNeighborWith( aClusterCol.back()) )
345 aClusterCol.back().push_back( aMarkCol[j] );
346 }
347 } while( circle < aMarkCol.size()-i-1);
348 } // End if recordflag
349 } // End fist for
350
351 return aClusterCol;
352}
353
354
355vector< mark_col > MucMark::CreateClusterCol( int buildMode, mark_col &aMarkCol )
356{
357 vector< mark_col > aClusterCol;
358 switch( buildMode )
359 {
360 case 1: return CreateClusterCol_A( aMarkCol );
361 break;
362 case 2: return CreateClusterCol_B( aMarkCol );
363 break;
364 case 3: return CreateClusterCol_C( aMarkCol );
365 break;
366 case 4: return CreateClusterCol_D( aMarkCol );
367 break;
368 default: return (aClusterCol);
369 }
370}
371
372// Show mark itself
374{
375 cout << "prt: " << m_Part
376 << "\tseg: " << m_Segment
377 << "\tlay: " << m_Layer
378 << "\tstr: " << m_Strip << endl;
379}
380
381void MucMark::Print( mark_col &aMarkCol )
382{
383 for( unsigned int i=0; i< aMarkCol.size(); i++ ) aMarkCol[i]->Print();
384}
385
386void MucMark::Print( vector< mark_col > &aClusterCol )
387{
388 for( unsigned int i=0; i< aClusterCol.size(); i++ )
389 for( unsigned int j=0; j< aClusterCol[i].size(); j++ ) {
390 aClusterCol[i][j]->Print();
391 }
392}
393
394// END
395
vector< MucMark * > mark_col
Definition: MucMark.h:17
bool IsInBoxWith(MucMark &other)
Definition: MucMark.cxx:154
vector< mark_col > CreateClusterCol_A(mark_col &aMarkCol)
Definition: MucMark.cxx:188
MucMark()
Definition: MucMark.h:21
int NumInCol(mark_col &aCol)
Definition: MucMark.cxx:132
bool IsNeighborWith(MucMark &other)
Definition: MucMark.cxx:165
bool IsInSegWith(MucMark &other)
Definition: MucMark.cxx:144
vector< mark_col > CreateClusterCol_C(mark_col &aMarkCol)
Definition: MucMark.cxx:267
bool SetLayer(int layer)
Definition: MucMark.cxx:69
bool SetSegment(int segment)
Definition: MucMark.cxx:57
vector< mark_col > CreateClusterCol(int buildMode, mark_col &aMarkCol)
Definition: MucMark.cxx:355
bool operator==(MucMark &other)
Definition: MucMark.cxx:31
vector< mark_col > CreateClusterCol_D(mark_col &aMarkCol)
Definition: MucMark.cxx:308
vector< mark_col > CreateClusterCol_B(mark_col &aMarkCol)
Definition: MucMark.cxx:235
int IsInCol(int part, int segment, int layer, int strip, mark_col &aCol)
Definition: MucMark.cxx:100
bool SetStrip(int strip)
Definition: MucMark.cxx:81
bool SetPart(int part)
Definition: MucMark.cxx:45
int Part()
Definition: MucMark.cxx:94
~MucMark()
Definition: MucMark.cxx:28
int Segment()
Definition: MucMark.cxx:95
int Strip()
Definition: MucMark.cxx:97
void Print()
Definition: MucMark.cxx:373
int Layer()
Definition: MucMark.cxx:96