BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
Muc/MucGeoCreateAlg/MucGeoCreateAlg-00-01-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 {
76 strId = boxId*E_STR_NUM + strSubId;
77 }
78 else if( part == BRID )
79 {
80 strId = STR_PER_PART[0];
81
82 if( segment > B_TOP )
83 strId += segment * B_STR_PER_SEG[0] + E_STR_NUM;
84 else
85 strId += segment * B_STR_PER_SEG[0];
86
87 strId += ((1+layer)/2) * B_ZSTR_NUM;
88 strId += (layer/2) * ( (segment == B_TOP)?B_TOPSTR_NUM:B_PHISTR_NUM );
89
90 strId += strSubId;
91 }
92 else
93 {
94 strId = STR_PER_PART[0] + STR_PER_PART[1];
95 strId += (boxId - BOX_SUM[1])*E_STR_NUM + strSubId;
96 }
97
98 return strId;
99}
100
101// Get the box posistion according to histogram pointer id of the box
102bool MucIdTransform::SetBoxPos( int boxId, int* part, int* segment, int* layer )
103{
104
105 if( (boxId < 0) || (boxId > BOX_MAX-1) )
106 {
107 *part = 0;
108 *segment = 0;
109 *layer = 0;
110 cout << "box id out range:\t" << boxId << "!" << endl;
111 return false;
112 }
113
114 // get part
115 if( boxId < BOX_SUM[0] ) { *part = 0; }
116 else if( boxId < BOX_SUM[1] ) { *part = 1; boxId -= BOX_SUM[0]; }
117 else { *part = 2; boxId -= BOX_SUM[1]; }
118
119 // get segment and layer
120 if( *part == BRID )
121 {
122 *segment = boxId / B_LAY_NUM;
123 *layer = boxId % B_LAY_NUM;
124 }
125 else
126 {
127 *segment = boxId / E_LAY_NUM;
128 *layer = boxId % E_LAY_NUM;
129 }
130
131 return true;
132}
133
134// Get the strip posistion according to histogram pointer id of the strip
135bool MucIdTransform::SetStripPos( int stripId, int *part, int *segment, int *layer, int *strSubId )
136{
137 if( (stripId < 0) || (stripId > STRIP_MAX-1) )
138 {
139 *part = 0;
140 *segment = 0;
141 *layer = 0;
142 *strSubId = 0;
143 cout << "strip id out range:\t" << stripId << "!" << endl;
144 return false;
145 }
146
147 // get part
148 if( stripId < STR_SUM[0] ) { *part = 0; }
149 else if ( stripId < STR_SUM[1] ) { *part = 1; stripId -= STR_SUM[0]; }
150 else { *part = 2; stripId -= STR_SUM[1]; }
151
152 // get segment and layer
153 if( *part == BRID )
154 {
155 int temp = 0;
156 if ( stripId >= 2*B_STR_PER_SEG[0] && stripId < 2*B_STR_PER_SEG[0] + B_STR_PER_SEG[1] )
157 {
158 // get segment
159 *segment = B_TOP;
160
161 stripId -= 2*B_STR_PER_SEG[0];
162 temp = stripId % ( B_ZSTR_NUM + B_TOPSTR_NUM );
163
164 // get layer
165 if( temp < B_ZSTR_NUM ) *layer = 2*( stripId / ( B_ZSTR_NUM + B_TOPSTR_NUM ) );
166 else *layer = 2*( stripId / ( B_ZSTR_NUM + B_TOPSTR_NUM ) ) + 1;
167
168 // get strip
169 if( temp < B_ZSTR_NUM ) *strSubId = temp;
170 else *strSubId = temp - B_ZSTR_NUM;
171
172 } // top segment
173 else
174 {
175 if (stripId >= 2*B_STR_PER_SEG[0] + B_STR_PER_SEG[1] ) stripId -= E_STR_NUM;
176
177 // get segment
178 *segment = stripId / B_STR_PER_SEG[0];
179
180 stripId %= B_STR_PER_SEG[0];
181 temp = stripId % ( B_ZSTR_NUM + B_PHISTR_NUM );
182
183 // get layer
184 if( temp < B_ZSTR_NUM ) *layer = 2*( stripId / ( B_ZSTR_NUM + B_PHISTR_NUM ) );
185 else *layer = 2*( stripId / ( B_ZSTR_NUM + B_PHISTR_NUM ) ) + 1;
186
187 // get strip
188 if( temp < B_ZSTR_NUM ) *strSubId = temp;
189 else *strSubId = temp - B_ZSTR_NUM;
190 }
191 } // barrel
192 else
193 {
194 *strSubId = stripId % E_STR_NUM;
195 *layer = ( stripId / E_STR_NUM ) % E_LAY_NUM ;
196 *segment = ( stripId / E_STR_NUM ) / E_LAY_NUM ;
197 }
198
199 return true;
200}
201
202// Show transform results
203void MucIdTransform::Print( int mode )
204{
205 if( mode == 0 ) // position to id
206 {
207 cout << "prt: " << m_Part
208 << "\tseg: " << m_Segment
209 << "\tlay: " << m_Layer
210 << "\tstr: " << m_Strip
211 << "\tid: " << m_Id << endl;
212 }
213 else // id to position
214 {
215 cout << "id: " << m_Id
216 << "\tprt: " << m_Part
217 << "\tseg: " << m_Segment
218 << "\tlay: " << m_Layer
219 << "\tstr: " << m_Strip << endl;
220 }
221}
222
223//END
224
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)