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