BOSS 7.0.2
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcAlignAlg/MdcAlignAlg-00-01-04/share/distAlign/src/MdcCosGeom.cpp
Go to the documentation of this file.
1#include "include/MdcCosGeom.h"
2
3#include <iostream>
4#include <fstream>
5#include <iomanip>
6#include <cmath>
7#include <cstdlib>
8
9using namespace std;
10
11MdcCosGeom::MdcCosGeom(std::string fwireconf, std::string falign):
12 m_fwconf(fwireconf), m_falign(falign)
13{
14 // constructor
15 int ilay;
16 int icell;
17 for(ilay=0; ilay<LAYERNMAX; ilay++){
18 for(icell=0; icell<CELLNMAX; icell++){
19 m_wiretable[ilay][icell] = -1;
20 }
21 }
22
23 for(int i=0; i<12; i++){
24 m_iTXf = 0;
25 m_iTXb = 8;
26 m_iTYf = 16;
27 m_iTYb = 24;
28 m_iTZf = 32;
29 m_iTZb = 40;
30
31 m_iRXf = 48;
32 m_iRXb = 56;
33 m_iRYf = 64;
34 m_iRYb = 72;
35 m_iRZf = 80;
36 m_iRZb = 88;
37 }
38
39 m_rot = 0.0;
40
41 int ipream;
42 for(ilay=0; ilay<LAYERNMAX; ilay++){
43 for(ipream=0; ipream<100; ipream++){
44 m_fan[ilay][ipream] = -999;
45 }
46 }
47
48 cout << "INFO: MdcCosGeom created." << endl;
49}
50
52 // destructor
53 int i;
54 for(i=0; i<WIRENMAX; i++){
55 delete m_pwire[i];
56 }
57 for(i=0; i<LAYERNMAX; i++){
58 delete m_player[i];
59 }
60
61 cout << "INFO: MdcCosGeom has been destructed." << endl;
62}
63
64bool MdcCosGeom::initialize(double rot){
65 m_rot = rot * PI / 180.0;
66 if( ! initWire() ){
67 cout << "ERROR: Intialize wire failed !!!" << endl;
68 return false;
69 }
70 return true;
71}
72
74 int iwire = 0;
75 int ilay;
76 int icell;
77 int ampid;
78 int channel;
79 int iFan;
80
81 char wirelabel[100];
82 char wiretag[100];
83
84 int ncell;
85 int first;
86 double radius;
87 double twist;
88 double length;
89 double offset;
90 string strtmp;
91
92 double aglstart;
93 double angleforwini;
94 double angleforw;
95 double angleback;
96
97 int layertype;
98
99 double xf;
100 double yf;
101 double zf;
102 double xb;
103 double yb;
104 double zb;
105
106 double slant;
107
108 double tension[] = {15, 15, 15, 16, 16, 17, 17, 18, 14, 14,
109 19, 19, 24, 24, 31, 31, 37, 37, 45, 45,
110 46, 47, 47, 47, 47, 48, 48, 48, 48, 49,
111 49, 49, 49, 50, 50, 50, 51, 51, 51, 52,
112 52, 52, 52};
113
114 int iEle; // index of the element for alignment
115 int iPar[12]; // index of alignment paramter
116
117 if( ! initAlign() ){
118 return false;
119 }
120
121 if( ! initPream() ){
122 return false;
123 }
124
125 ifstream fin( m_fwconf.c_str() );
126 if( ! fin.is_open() ){
127 cout << "ERROR: can not open file " << m_fwconf << endl;
128 return false;
129 }
130
131 for(ilay=0; ilay<LAYERNMAX; ilay++){
132 fin >> strtmp >> radius >> ncell >> twist
133 >> offset >> length >> first;
134
135 length -= 4.0; // wulh test on 2007-05-08
136 ncell /= 2;
137
138 if( fabs(twist) > 0.1 ){
139 offset = 0.0;
140 }
141
142 aglstart = (PI / ncell) * first + (offset * PI / 180.0);
143 if( aglstart < -0.000001 ){
144 aglstart += 2.0 * PI / ncell;
145 }
146
147 if( twist < -0.1 ){
148 layertype = 1;
149 } else if( twist > 0.1 ){
150 layertype = 2;
151 } else{
152 layertype = 0;
153 }
154
155 slant = atan( sin(PI * twist / ncell)
156 * radius * 2.0 / length );
157
158 m_player[ilay] = new MdcCosLayer;
159 m_player[ilay] -> setLayerType( layertype );
160 m_player[ilay] -> setNcell( ncell );
161 m_player[ilay] -> setLayerRad( radius );
162 m_player[ilay] -> setLength( length );
163 m_player[ilay] -> setTwistCell( twist );
164 m_player[ilay] -> setSlant( slant );
165
166 if( ilay < INNERNMAX ) m_player[ilay] -> setFgInner( true );
167 else m_player[ilay] -> setFgInner( false );
168
169 // set the index of the element for alignment
170 if( ilay < 8 ){
171 iEle = 0;
172 } else if( ilay < 10 ){
173 iEle = 1;
174 } else if( ilay < 12 ){
175 iEle = 2;
176 } else if( ilay < 14 ){
177 iEle = 3;
178 } else if( ilay < 16 ){
179 iEle = 4;
180 } else if( ilay < 18 ){
181 iEle = 5;
182 } else if( ilay < 20 ){
183 iEle = 6;
184 } else{
185 iEle = 7;
186 }
187
188 iPar[0] = iEle + m_iTXf; // TXf
189 iPar[1] = iEle + m_iTXb; // TXb
190 iPar[2] = iEle + m_iTYf; // TYf
191 iPar[3] = iEle + m_iTYb; // TYb
192 iPar[4] = iEle + m_iTZf; // TZf
193 iPar[5] = iEle + m_iTZb; // TZb
194 iPar[6] = iEle + m_iRXf; // RXf
195 iPar[7] = iEle + m_iRXb; // RXb
196 iPar[8] = iEle + m_iRYf; // RYf
197 iPar[9] = iEle + m_iRYb; // RTb
198 iPar[10] = iEle + m_iRZf; // RZf
199 iPar[11] = iEle + m_iRZb; // RZb
200
201 m_player[ilay] -> setAlignParId(iPar);
202
203 for(icell=0; icell<ncell; icell++){
204 m_wiretable[ilay][icell] = iwire;
205 angleforwini = (double)icell * 2.0 * PI / ncell + aglstart;
206
207 // forward endpoint
208 angleforw = angleforwini + m_alignPar[iEle+m_iRZf];
209 angleforw += m_rot;
210
211 xf = radius * cos( angleforw );
212 yf = radius * sin( angleforw );
213 zf = 0.5 * length;
214
215 xf += m_alignPar[iEle+m_iTXf];
216 yf += m_alignPar[iEle+m_iTYf];
217 zf += m_alignPar[iEle+m_iTZf];
218
219 // backward endpoint
220 angleback = angleforwini + twist * 2.0 * PI / ncell;
221 angleback += m_alignPar[iEle+m_iRZb];
222 angleback += m_rot;
223
224 xb = radius * cos( angleback );
225 yb = radius * sin( angleback );
226 zb = -0.5 * length;
227
228 xb += m_alignPar[iEle+m_iTXb];
229 yb += m_alignPar[iEle+m_iTYb];
230 zb += m_alignPar[iEle+m_iTZb];
231
232 ampid = icell / 8;
233 channel = icell - 8 * ampid;
234 sprintf(wirelabel, "%02dS%02d-%d", ilay+1, ampid+1, channel+1);
235 sprintf(wiretag, "%02d_%02d_%04d_%02d",
236 ilay, icell, iwire, ampid+1);
237
238 m_pwire[iwire] = new MdcCosWire;
239
240 m_pwire[iwire] -> setLayerPtr(m_player[ilay]);
241
242 m_pwire[iwire] -> setWireId( iwire );
243 m_pwire[iwire] -> setLayerId( ilay );
244 m_pwire[iwire] -> setCellId( icell );
245 m_pwire[iwire] -> setPreAmpId( ampid+1 );
246 m_pwire[iwire] -> setChannel( channel );
247
248 // set fanID
249 iFan = m_fan[ilay][ampid];
250// m_pwire[iwire] -> setFanId( abs(iFan) - 1 );
251 m_pwire[iwire] -> setFanId( abs(iFan) ); // begin from 1
252 if(iFan > 0) m_pwire[iwire] -> setEndId( 1 );
253 else m_pwire[iwire] -> setEndId( -1 );
254
255 m_pwire[iwire] -> setWireLabel( wirelabel );
256 m_pwire[iwire] -> setWireTag( wiretag );
257
258 m_pwire[iwire] -> setXf( xf );
259 m_pwire[iwire] -> setYf( yf );
260 m_pwire[iwire] -> setZf( zf );
261
262 m_pwire[iwire] -> setXb( xb );
263 m_pwire[iwire] -> setYb( yb );
264 m_pwire[iwire] -> setZb( zb );
265
266 if( angleforw < 0 ) angleforw += 2.0 * PI;
267 m_pwire[iwire] -> setPhiForward( angleforw );
268
269 m_pwire[iwire] -> setTension( tension[ilay] );
270
271 iwire++;
272 }
273 }
274 fin.close();
275 cout << "INFO: Number of wires: " << iwire << endl;
276 m_nWire = iwire;
277 m_nLayer = LAYERNMAX;
278
279 return true;
280}
281
282bool MdcCosGeom::initAlign(){
283 ifstream falign( m_falign.c_str() );
284 if( ! falign.is_open() ){
285 cout << "ERROR: can not open alignment data file "
286 << m_falign << endl;
287 return false;
288 }
289
290 cout << "INFO: Alignment data file is " << m_falign << endl;
291
292 int i;
293 string str;
294 getline(falign, str);
295
296 for(i=0; i<8; i++){
297 falign >> str >> m_alignPar[i+m_iTXf] >> m_alignPar[i+m_iTYf]
298 >> m_alignPar[i+m_iTZf] >> m_alignPar[i+m_iRXf]
299 >> m_alignPar[i+m_iRYf] >> m_alignPar[i+m_iRZf];
300
301 // mrad -> rad
302 m_alignPar[i+m_iRXf] *= 0.001;
303 m_alignPar[i+m_iRYf] *= 0.001;
304 m_alignPar[i+m_iRZf] *= 0.001;
305 }
306
307 for(i=0; i<8; i++){
308 falign >> str >> m_alignPar[i+m_iTXb] >> m_alignPar[i+m_iTYb]
309 >> m_alignPar[i+m_iTZb] >> m_alignPar[i+m_iRXb]
310 >> m_alignPar[i+m_iRYb] >> m_alignPar[i+m_iRZb];
311
312 // mrad -> rad
313 m_alignPar[i+m_iRXb] *= 0.001;
314 m_alignPar[i+m_iRYb] *= 0.001;
315 m_alignPar[i+m_iRZb] *= 0.001;
316 }
317
318 falign.close();
319
320 return true;
321}
322
324 int i;
325 int k;
326 int iEnd;
327 char fname[100];
328
329 int lay;
330 int ipream;
331
332 for(k=0; k<2; k++){
333 for(i=0; i<8; i++){
334 if(0 == k){
335 sprintf(fname, "pream/east%d.dat", i+1);
336 iEnd = 1;
337 } else{
338 sprintf(fname, "pream/west%d.dat", i+1);
339 iEnd = -1;
340 }
341
342 ifstream fin(fname);
343 while(fin >> lay){
344 fin >> ipream;
345 m_fan[lay-1][ipream-1] = (i+1) * iEnd;
346 }
347 fin.close();
348 fin.clear();
349 }
350 }
351 return true;
352}
353
355 return true;
356}
357
358void MdcCosGeom::check(string fchk) const {
359 ofstream fout( fchk.c_str() );
360 for(int iwire=0; iwire<6796; iwire++){
361 fout << setw(4) << iwire;
362 fout << setw(6) << getWire(iwire) -> getWireId();
363 fout << setw(4) << getWire(iwire) -> getLayerId();
364 fout << setw(5) << getWire(iwire) -> getCellId();
365 fout << setw(15) << getWire(iwire) -> getXb();
366 fout << setw(15) << getWire(iwire) -> getYb();
367 fout << setw(7) << getWire(iwire) -> getZb();
368 fout << setw(15) << getWire(iwire) -> getXf();
369 fout << setw(15) << getWire(iwire) -> getYf();
370 fout << setw(7) << getWire(iwire) -> getZf();
371 fout << endl;
372 }
373 fout.close();
374
375 cout << fchk << " has been created for check." << endl;
376}
377
378const MdcCosWire* MdcCosGeom::getWire(int ilay, int icell) const {
379 assert( ilay < LAYERNMAX );
380 assert( icell < getLayer(ilay)->getNcell() );
381
382 int iwire = m_wiretable[ilay][icell];
383
384 return m_pwire[iwire];
385}
386
387const void MdcCosGeom::getAlignPar(double alignPar[]) const {
388 for(int i=0; i<96; i++){
389 alignPar[i] = m_alignPar[i];
390 }
391
392 for(int k=0; k<8; k++){
393 alignPar[k+m_iRXf] *= 1000.0;
394 alignPar[k+m_iRYf] *= 1000.0;
395 alignPar[k+m_iRZf] *= 1000.0;
396 }
397}
double sin(const BesAngle a)
double cos(const BesAngle a)
const double PI
Definition: PipiJpsi.cxx:55
void check(std::string fchk) const
MdcCosGeom(std::string fwireconf, std::string fAlign)