BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Muc/MucCalib/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
13#include "MucCalib/MucIdTransform.h"
14#include "MucCalib/MucStructConst.h"
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
39 if ( part != BRID ) max = E_STR_NUM;
40 else if ( ( layer + 1 ) % 2 == 1 ) max = B_ZSTR_NUM;
41 else if ( segment == B_TOP ) max = B_TOPSTR_NUM;
42 else max = B_PHISTR_NUM;
43
44 return max;
45}
46
47// Return the id of a box according its position
48int MucIdTransform::GetBoxId( int part, int segment, int layer ) {
49 int boxId = 0;
50 for ( int i = 0; i < part; i++ ) { boxId += BOX_PER_PART[i]; }
51
52 if ( segment == 0 ) boxId += layer;
53 else boxId += ( segment * BOX_PER_SEG[part] + layer );
54
55 return boxId;
56}
57
58// Return the id of a strip according its position
59int MucIdTransform::GetStripId( int part, int segment, int layer, int strSubId ) {
60 int strId = 0;
61 int boxId = 0;
62
63 boxId = GetBoxId( part, segment, layer );
64
65 if ( part == EEID ) { strId = boxId * E_STR_NUM + strSubId; }
66 else if ( part == BRID )
67 {
68 strId = STR_PER_PART[0];
69
70 if ( segment > B_TOP ) strId += segment * B_STR_PER_SEG[0] + E_STR_NUM;
71 else strId += segment * B_STR_PER_SEG[0];
72
73 strId += ( ( 1 + layer ) / 2 ) * B_ZSTR_NUM;
74 strId += ( layer / 2 ) * ( ( segment == B_TOP ) ? B_TOPSTR_NUM : B_PHISTR_NUM );
75
76 strId += strSubId;
77 }
78 else
79 {
80 strId = STR_PER_PART[0] + STR_PER_PART[1];
81 strId += ( boxId - BOX_SUM[1] ) * E_STR_NUM + strSubId;
82 }
83
84 return strId;
85}
86
87// Get the box posistion according to histogram pointer id of the box
88bool MucIdTransform::SetBoxPos( int boxId, int* part, int* segment, int* layer ) {
89 if ( ( boxId < 0 ) || ( boxId > BOX_MAX - 1 ) )
90 {
91 *part = 0;
92 *segment = 0;
93 *layer = 0;
94 cout << "box id out range:\t" << boxId << "!" << endl;
95 return false;
96 }
97
98 // get part
99 if ( boxId < BOX_SUM[0] ) { *part = 0; }
100 else if ( boxId < BOX_SUM[1] )
101 {
102 *part = 1;
103 boxId -= BOX_SUM[0];
104 }
105 else
106 {
107 *part = 2;
108 boxId -= BOX_SUM[1];
109 }
110
111 // get segment and layer
112 if ( *part == BRID )
113 {
114 *segment = boxId / B_LAY_NUM;
115 *layer = boxId % B_LAY_NUM;
116 }
117 else
118 {
119 *segment = boxId / E_LAY_NUM;
120 *layer = boxId % E_LAY_NUM;
121 }
122
123 return true;
124}
125
126// Get the strip posistion according to histogram pointer id of the strip
127bool MucIdTransform::SetStripPos( int stripId, int* part, int* segment, int* layer,
128 int* strSubId ) {
129 if ( ( stripId < 0 ) || ( stripId > STRIP_MAX - 1 ) )
130 {
131 *part = 0;
132 *segment = 0;
133 *layer = 0;
134 *strSubId = 0;
135 cout << "strip id out range:\t" << stripId << "!" << endl;
136 return false;
137 }
138
139 // get part
140 if ( stripId < STR_SUM[0] ) { *part = 0; }
141 else if ( stripId < STR_SUM[1] )
142 {
143 *part = 1;
144 stripId -= STR_SUM[0];
145 }
146 else
147 {
148 *part = 2;
149 stripId -= STR_SUM[1];
150 }
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 if ( mode == 0 ) // position to id
205 {
206 cout << "prt: " << m_Part << "\tseg: " << m_Segment << "\tlay: " << m_Layer
207 << "\tstr: " << m_Strip << "\tid: " << m_Id << endl;
208 }
209 else // id to position
210 {
211 cout << "id: " << m_Id << "\tprt: " << m_Part << "\tseg: " << m_Segment
212 << "\tlay: " << m_Layer << "\tstr: " << m_Strip << endl;
213 }
214}
215
216// 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)
int GetBoxId(int part, int segment, int layer)
bool SetStripPos(int stripid, int *part, int *segment, int *layer, int *subid)