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