BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
Muc/MucGeoCreateAlg/MucGeoCreateAlg-00-03-00/src/MucIdTransform.cxx
Go to the documentation of this file.
1//------------------------------------------------------------------------------|
2// [File ]: MucIdTransform.cxx |
3// [Brief ]: Source file of MucIdTransform class for encapsulation |
4// [Author]: Xie Yuguang, <[email protected]> |
5// [Date ]: Oct 19, 2006 |
6//------------------------------------------------------------------------------|
7
8#include<iostream>
9#include<cmath>
10
11using namespace std;
12
15
16// Constructor
18{
19 m_Id = 0;
20 m_Part = 0;
21 m_Segment = 0;
22 m_Layer = 0;
23 m_Strip = 0;
24}
25
26// Destructor
28
29// Get properties
30int MucIdTransform::GetId() { return m_Id; }
31int MucIdTransform::GetPart() { return m_Part; }
32int MucIdTransform::GetSegment() { return m_Segment; }
33int MucIdTransform::GetLayer() { return m_Layer; }
34int MucIdTransform::GetStrip() { return m_Strip; }
35
36// Return the maximum strip in a box
37int MucIdTransform::GetStripMax( int part, int segment, int layer )
38{
39 int max = 0;
40 if( part != BRID ) max = E_STR_NUM;
41 else if( (layer+1)%2 == 1 ) max = B_ZSTR_NUM;
42 else if( segment == B_TOP ) max = B_TOPSTR_NUM;
43 else max = B_PHISTR_NUM;
44 return max;
45}
46
47// Return the id of a box according its position
48int MucIdTransform::GetBoxId( int part, int segment, int layer )
49{
50 int boxId = 0;
51 for(int i=0; i<part; i++) {
52 boxId += BOX_PER_PART[i];
53 }
54
55 if( segment == 0 ) boxId += layer;
56 else boxId += ( segment * BOX_PER_SEG[part] + layer );
57
58 return boxId;
59}
60
61// Return the id of a strip according its position
62int MucIdTransform::GetStripId( int part, int segment, int layer, int strSubId )
63{
64 int strId = 0;
65 int boxId = 0;
66
67 boxId = GetBoxId( part, segment, layer );
68
69 if( part == EEID ) strId = boxId*E_STR_NUM + strSubId;
70 else if( part == BRID )
71 {
72 strId = STR_PER_PART[0];
73
74 if( segment > B_TOP )
75 strId += segment * B_STR_PER_SEG[0] + E_STR_NUM;
76 else
77 strId += segment * B_STR_PER_SEG[0];
78
79 strId += ((1+layer)/2) * B_ZSTR_NUM;
80 strId += (layer/2) * ( (segment == B_TOP)?B_TOPSTR_NUM:B_PHISTR_NUM );
81
82 strId += strSubId;
83 }
84 else {
85 strId = STR_PER_PART[0] + STR_PER_PART[1];
86 strId += (boxId - BOX_SUM[1])*E_STR_NUM + strSubId;
87 }
88
89 return strId;
90}
91
92// Get the box posistion according to histogram pointer id of the box
93bool MucIdTransform::SetBoxPos( int boxId, int* part, int* segment, int* layer )
94{
95 if( (boxId < 0) || (boxId > BOX_MAX-1) )
96 {
97 *part = 0;
98 *segment = 0;
99 *layer = 0;
100 cout << "box id out range:\t" << boxId << "!" << endl;
101 return false;
102 }
103
104 // get part
105 if( boxId < BOX_SUM[0] ) { *part = 0; }
106 else if( boxId < BOX_SUM[1] ) { *part = 1; boxId -= BOX_SUM[0]; }
107 else { *part = 2; boxId -= BOX_SUM[1]; }
108
109 // get segment and layer
110 if( *part == BRID ) {
111 *segment = boxId / B_LAY_NUM;
112 *layer = boxId % B_LAY_NUM;
113 }
114 else {
115 *segment = boxId / E_LAY_NUM;
116 *layer = boxId % E_LAY_NUM;
117 }
118
119 return true;
120}
121
122// Get the strip posistion according to histogram pointer id of the strip
123bool MucIdTransform::SetStripPos( int stripId, int *part, int *segment, int *layer, int *strSubId )
124{
125 if( (stripId < 0) || (stripId > STRIP_MAX-1) )
126 {
127 *part = 0;
128 *segment = 0;
129 *layer = 0;
130 *strSubId = 0;
131 cout << "strip id out range:\t" << stripId << "!" << endl;
132 return false;
133 }
134
135 // get part
136 if( stripId < STR_SUM[0] ) { *part = 0; }
137 else if ( stripId < STR_SUM[1] ) { *part = 1; stripId -= STR_SUM[0]; }
138 else { *part = 2; stripId -= STR_SUM[1]; }
139
140 // get segment and layer
141 if( *part == BRID )
142 {
143 int temp = 0;
144 if ( stripId >= 2*B_STR_PER_SEG[0] && stripId < 2*B_STR_PER_SEG[0] + B_STR_PER_SEG[1] )
145 {
146 // get segment
147 *segment = B_TOP;
148
149 stripId -= 2*B_STR_PER_SEG[0];
150 temp = stripId % ( B_ZSTR_NUM + B_TOPSTR_NUM );
151
152 // get layer
153 if( temp < B_ZSTR_NUM ) *layer = 2*( stripId / ( B_ZSTR_NUM + B_TOPSTR_NUM ) );
154 else *layer = 2*( stripId / ( B_ZSTR_NUM + B_TOPSTR_NUM ) ) + 1;
155
156 // get strip
157 if( temp < B_ZSTR_NUM ) *strSubId = temp;
158 else *strSubId = temp - B_ZSTR_NUM;
159 } // top segment
160 else
161 {
162 if (stripId >= 2*B_STR_PER_SEG[0] + B_STR_PER_SEG[1] ) stripId -= E_STR_NUM;
163
164 // get segment
165 *segment = stripId / B_STR_PER_SEG[0];
166
167 stripId %= B_STR_PER_SEG[0];
168 temp = stripId % ( B_ZSTR_NUM + B_PHISTR_NUM );
169
170 // get layer
171 if( temp < B_ZSTR_NUM ) *layer = 2*( stripId / ( B_ZSTR_NUM + B_PHISTR_NUM ) );
172 else *layer = 2*( stripId / ( B_ZSTR_NUM + B_PHISTR_NUM ) ) + 1;
173
174 // get strip
175 if( temp < B_ZSTR_NUM ) *strSubId = temp;
176 else *strSubId = temp - B_ZSTR_NUM;
177 }
178 } // barrel
179 else
180 {
181 *strSubId = stripId % E_STR_NUM;
182 *layer = ( stripId / E_STR_NUM ) % E_LAY_NUM ;
183 *segment = ( stripId / E_STR_NUM ) / E_LAY_NUM ;
184 }
185
186 return true;
187}
188
189// Show transform results
190void MucIdTransform::Print( int mode )
191{
192 if( mode == 0 ) // position to id
193 {
194 cout << "prt: " << m_Part
195 << "\tseg: " << m_Segment
196 << "\tlay: " << m_Layer
197 << "\tstr: " << m_Strip
198 << "\tid: " << m_Id << endl;
199 }
200 else // id to position
201 {
202 cout << "id: " << m_Id
203 << "\tprt: " << m_Part
204 << "\tseg: " << m_Segment
205 << "\tlay: " << m_Layer
206 << "\tstr: " << m_Strip << endl;
207 }
208}
209
210//END
211
int GetStripId(int part, int segment, int layer, int subid)
bool SetBoxPos(int boxid, int *part, int *segment, int *layer)
int GetStripMax(int part, int segment, int layer)
bool SetStripPos(int stripid, int *part, int *segment, int *layer, int *subid)