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