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