BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcGeomSvc.cxx
Go to the documentation of this file.
1#include "GaudiKernel/Algorithm.h"
2#include "GaudiKernel/Bootstrap.h"
3#include "GaudiKernel/IDataProviderSvc.h"
4#include "GaudiKernel/IIncidentListener.h"
5#include "GaudiKernel/IIncidentSvc.h"
6#include "GaudiKernel/IInterface.h"
7#include "GaudiKernel/ISvcLocator.h"
8#include "GaudiKernel/Incident.h"
9#include "GaudiKernel/Kernel.h"
10#include "GaudiKernel/MsgStream.h"
11#include "GaudiKernel/PropertyMgr.h"
12#include "GaudiKernel/SmartDataPtr.h"
13#include "GaudiKernel/StatusCode.h"
14#include <float.h>
15#include <fstream>
16
17#include "CalibData/CalibModel.h"
18#include "CalibData/Mdc/MdcAlignData.h"
19#include "EventModel/Event.h"
20#include "EventModel/EventHeader.h"
21
22#include "MdcGeomSvc.h"
23
25
26// initialize static members
27bool MdcGeomSvc::m_doSag = true;
30
31MdcGeomSvc::MdcGeomSvc( const std::string& name, ISvcLocator* svcloc )
32 : base_class( name, svcloc ) {
33 if ( getenv( "MDCGEOMSVCROOT" ) )
34 {
35 m_alignFilePath =
36 std::string( getenv( "MDCGEOMSVCROOT" ) ) + std::string( "/share/MdcAlignPar.dat" );
37 // std::cout<<" the MDC alignment file: "<<m_alignFilePath<<std::endl;
38
39 m_wirePosFilePath =
40 std::string( getenv( "MDCGEOMSVCROOT" ) ) + std::string( "/share/WirePosCalib.dat" );
41 // std::cout<<" the MDC wire position file: "<<m_wirePosFilePath<<std::endl;
42
43 m_wireTensionFilePath =
44 std::string( getenv( "MDCGEOMSVCROOT" ) ) + std::string( "/share/mdcWireTension.dat" );
45 // std::cout<<" the MDC wire tension file: "<<m_wireTensionFilePath<<std::endl;
46 }
47 else { std::cout << "A fatal error, contact wangjk..." << std::endl; }
48
49 declareProperty( "doSag", m_doSag = true );
50 declareProperty( "readAlignParDataBase", m_readAlignParDataBase = true );
51 declareProperty( "mcnoalignment", m_nomcalignment = true );
52 declareProperty( "wholeShiftX", m_wholeShiftX = 0. );
53 declareProperty( "wholeShiftY", m_wholeShiftY = 0. );
54 declareProperty( "wholeShiftZ", m_wholeShiftZ = 0. );
55 declareProperty( "wholeRotatX", m_wholeRotatX = 0. );
56 declareProperty( "wholeRotatY", m_wholeRotatY = 0. );
57 declareProperty( "wholeRotatZ", m_wholeRotatZ = 0. );
58 declareProperty( "alignFilePath", m_alignFilePath );
59 declareProperty( "wirePosFilePath", m_wirePosFilePath );
60 declareProperty( "wireTensionFilePath", m_wireTensionFilePath );
61}
62
63/*StatusCode MdcGeomSvc::queryInterface (const InterfaceID& riid, void** ppvInterface ){
64
65 if ( IID_IMdcGeomSvc.versionMatch(riid) ) {
66 *ppvInterface = static_cast<IMdcGeomSvc*> (this);
67 } else {
68 return Service::queryInterface(riid, ppvInterface) ;
69 }
70 return StatusCode::SUCCESS;
71}
72*/
74 MsgStream log( msgSvc(), name() );
75 log << MSG::INFO << name() << ": Start of run initialisation" << endmsg;
76
77 StatusCode sc = Service::initialize();
78 if ( sc.isFailure() ) return sc;
79 m_mindex = 0;
80 m_updataalign = false;
81 IIncidentSvc* incsvc;
82 sc = service( "IncidentSvc", incsvc );
83 int priority = 100;
84 if ( sc.isSuccess() ) { incsvc->addListener( this, "NewRun", priority ); }
85
86 // ReadFilePar(); // get geometry data from file SimUtil/dat/Mdc.txt
87 // Fill(); // get geometry data from Database
88
89 sc = service( "CalibDataSvc", m_pCalibDataSvc, true );
90
91 if ( !sc.isSuccess() )
92 {
93 log << MSG::ERROR << "Could not get IDataProviderSvc interface of CalibXmlCnvSvc"
94 << endmsg;
95 return sc;
96 }
97 else
98 { log << MSG::DEBUG << "Retrieved IDataProviderSvc interface of CalibXmlCnvSvc" << endmsg; }
99 ReadFilePar();
100 return StatusCode::SUCCESS;
101}
102
104 MsgStream log( msgSvc(), name() );
105 log << MSG::INFO << name() << ": End of Run" << endmsg;
106 return StatusCode::SUCCESS;
107}
108
110 for ( vector<MdcGeoLayer*>::iterator it1 = fLayers.begin(); it1 != fLayers.end(); it1++ )
111 delete *it1;
112 for ( vector<MdcGeoSuper*>::iterator it2 = fSupers.begin(); it2 != fSupers.end(); it2++ )
113 delete *it2;
114 for ( vector<MdcGeoWire*>::iterator it3 = fWires.begin(); it3 != fWires.end(); it3++ )
115 delete *it3;
116 for ( vector<MdcGeoEnd*>::iterator it4 = fEnd.begin(); it4 != fEnd.end(); it4++ )
117 delete *it4;
118 fGenerals.clear();
119 fWires.clear();
120 fLayers.clear();
121 fSupers.clear();
122 fEnd.clear();
123}
124
125void MdcGeomSvc::clean() {
126 for ( vector<MdcGeoLayer*>::iterator it1 = fLayers.begin(); it1 != fLayers.end(); it1++ )
127 delete *it1;
128 for ( vector<MdcGeoSuper*>::iterator it2 = fSupers.begin(); it2 != fSupers.end(); it2++ )
129 delete *it2;
130 for ( vector<MdcGeoWire*>::iterator it3 = fWires.begin(); it3 != fWires.end(); it3++ )
131 delete *it3;
132 for ( vector<MdcGeoEnd*>::iterator it4 = fEnd.begin(); it4 != fEnd.end(); it4++ )
133 delete *it4;
134 fGenerals.clear();
135 fWires.clear();
136 fLayers.clear();
137 fSupers.clear();
138 fEnd.clear();
139}
140
141void MdcGeomSvc::ReadFilePar() {
142 std::string geometryFilePath = getenv( "MDCSIMROOT" );
143 geometryFilePath += "/dat/Mdc.txt";
144 std::ifstream inFile( geometryFilePath.c_str() );
145
146 if ( !inFile.good() )
147 {
148 std::cout << "Error, mdc parameters file not exist" << std::endl;
149 return;
150 }
151 std::string alignFilePath;
152 std::string wirePosFilePath;
153 std::string wireTensionFilePath;
154 if ( !m_updataalign )
155 {
156 alignFilePath =
157 std::string( getenv( "MDCGEOMSVCROOT" ) ) + std::string( "/share/MdcAlignPar.dat" );
158 wirePosFilePath =
159 std::string( getenv( "MDCGEOMSVCROOT" ) ) + std::string( "/share/WirePosCalib.dat" );
160 wireTensionFilePath =
161 std::string( getenv( "MDCGEOMSVCROOT" ) ) + std::string( "/share/mdcWireTension.dat" );
162 }
163 else
164 {
165 alignFilePath = m_alignFilePath;
166 wirePosFilePath = m_wirePosFilePath;
167 wireTensionFilePath = m_wireTensionFilePath;
168 }
169 std::ifstream alignFile( alignFilePath.c_str() );
170 std::ifstream wirePosFile( wirePosFilePath.c_str() );
171 std::ifstream wireTensionFile( wireTensionFilePath.c_str() );
172
173 if ( !wirePosFile )
174 { std::cout << "Error, mdc wire position file not exist..." << std::endl; }
175
176 if ( !wireTensionFile )
177 { std::cout << "Error, mdc wire tension file not exist..." << std::endl; }
178
179 std::vector<double> wireTensionVec;
180 // cout << __FILE__ << " " << __LINE__ << " readdb = " << m_readAlignParDataBase
181 // << " update align = " << m_updataalign << endl;
182 if ( m_readAlignParDataBase && m_updataalign ) { ReadTensionDataBase( wireTensionVec ); }
183 else
184 {
185 cout << "Read wireTension from file:" << wireTensionFilePath.c_str() << endl;
186 int idd;
187 double tension;
188 for ( int ii = 0; ii < 6796; ii++ )
189 {
190 wireTensionFile >> idd >> tension;
191
192 if ( getSagFlag() ) { wireTensionVec.push_back( tension ); }
193 else
194 {
195 tension = DBL_MAX;
196 wireTensionVec.push_back( tension );
197 }
198 }
199 }
200
201 std::vector<vector<double>> wirePosVec( 6796 );
202 if ( m_readAlignParDataBase && m_updataalign ) { ReadWirePosDataBase( wirePosVec ); }
203 else
204 {
205 cout << "Read wirePosition from file:" << wirePosFilePath.c_str() << endl;
206 double dxe, dye, dze, dxw, dyw, dzw;
207 int wid;
208 std::string title;
209 getline( wirePosFile, title );
210 wirePosFile.seekg( 1, ios::cur );
211 for ( int j = 0; j < 6796; j++ )
212 {
213 wirePosFile >> wid >> dxe >> dye >> dze >> dxw >> dyw >> dzw;
214 wirePosVec[j].push_back( dxe );
215 wirePosVec[j].push_back( dye );
216 wirePosVec[j].push_back( dze );
217 wirePosVec[j].push_back( dxw );
218 wirePosVec[j].push_back( dyw );
219 wirePosVec[j].push_back( dzw );
220 /// test
221 /*
222 for(int jj=0;jj<6;jj++){
223 std::cout<<" wid: "<<wid<<" dxe: "<<wirePosVec[j][0]<<" dye: "<<wirePosVec[j][1]<<"
224 dze: "<<wirePosVec[j][2]<<" dxw: "<<wirePosVec[j][3]<<" dyw: "<<wirePosVec[j][4]<<"
225 dzw: "<<wirePosVec[j][5]<<std::endl;
226 }
227 */
228 }
229 }
230
231 double signalWireR, fieldWireR;
232 int TLayerNo, TWireNo, TSignalLayerNo, fSignalLayer[50];
233 int i, wireNo, firstWire, segmentNo, signalLayer;
234 double length, nomphi, phi, r, nomaadiv2, aadiv2, nomaa, aa, nomrotateCell, rotateCell,
235 wlength, innerR, outR, z;
236 std::string layer, name, line;
237
238 vector<int> WireNo, fSegmentNo;
239 vector<double> wLength, R, nomPhi, Phi, nomadiv2, adiv2, First, noma, a, nomebusing, ebusing,
240 nomsigma, sigma, nomdeltaz, deltaz, nomRotate, Rotate, fLength, fInnerR, fOutR, fZ;
241 vector<string> LayerName, fName;
242 vector<double> Sx, Sy, Sz, Rx, Ry, Rz;
243 double tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
244
245 /// read alignment file
246
247 if ( m_readAlignParDataBase && m_updataalign )
248 { ReadAliParDataBase( Sx, Sy, Sz, Rx, Ry, Rz ); }
249 else
250 {
251 cout << "Read alignment parameters from file:" << alignFilePath.c_str() << endl;
252 getline( alignFile, line );
253 alignFile.seekg( 1, ios::cur );
254 for ( int k = 0; k < 16; k++ )
255 {
256 alignFile >> line >> tmp1 >> tmp2 >> tmp3 >> tmp4 >> tmp5 >> tmp6;
257 // changed by luot 10.03.12
258 // if (!m_updataalign) {
259 // tmp1 = 0.0;
260 // tmp2 = 0.0;
261 // tmp3 = 0.0;
262 // tmp4 = 0.0;
263 // tmp5 = 0.0;
264 // tmp6 = 0.0;
265 // }
266 Sx.push_back( m_wholeShiftX + tmp1 );
267 Sy.push_back( m_wholeShiftY + tmp2 );
268 Sz.push_back( m_wholeShiftZ + tmp3 );
269 Rx.push_back( m_wholeRotatX + tmp4 );
270 Ry.push_back( m_wholeRotatY + tmp5 );
271 Rz.push_back( m_wholeRotatZ + tmp6 );
272 }
273 /// test the service
274 /// for(int m=0;m<16;m++) std::cout<<" Rz["<<m<<"] is: "<<Rz[m]<<std::endl;
275 }
276
277 getline( inFile, line );
278 inFile >> TLayerNo >> TWireNo >> TSignalLayerNo >> signalWireR >> fieldWireR;
279 inFile.seekg( 1, ios::cur );
280 getline( inFile, line );
281 for ( i = 0; i < TSignalLayerNo; i++ )
282 {
283 inFile >> signalLayer;
284 /// signalLayer is the index of this signalLayer in all the layers
285 fSignalLayer[i] = signalLayer - 1;
286 }
287
288 inFile.seekg( 1, ios::cur );
289 getline( inFile, line );
290 getline( inFile, line );
291
292 int i_east, i_west;
293 double delta_rotateCell;
294 /// in this loop we read the file and store them into according vectors
295 for ( i = 0; i < TLayerNo; i++ )
296 {
297 i_east = getAlignParIndexEast( i );
298 i_west = getAlignParIndexWest( i );
299
300 inFile >> layer >> wireNo >> wlength >> r >> nomphi >> firstWire >> nomrotateCell;
301 getline( inFile, line );
302
303 /// wireNo is the total wire number of this layer, including both signal
304 /// wire& field wire
305 nomaadiv2 = 2 * pi * nomrotateCell / wireNo;
306 // aadiv2=2*pi*rotateCell/wireNo+0.5*(Rz[i_west]-Rz[i_east]);
307 nomaa = 2 * r * sin( nomaadiv2 );
308 delta_rotateCell = ( Rz[i_west] - Rz[i_east] ) * wireNo / ( 4 * pi );
309 rotateCell = nomrotateCell + delta_rotateCell;
310 aadiv2 = 2 * pi * rotateCell / wireNo;
311 aa = 2 * r * sin( aadiv2 );
312
313 double shiftPhi = twopi / wireNo;
314 nomphi *= deg;
315 if ( nomphi < 0 ) nomphi += shiftPhi; // By definition, phi of first wire must >=0
316 // phi=nomphi+Rz[i_east];
317 phi = nomphi; // wulh remove Rz 12/09/18
318 LayerName.push_back( layer );
319 WireNo.push_back( wireNo );
320 wLength.push_back( wlength );
321 R.push_back( r );
322 nomPhi.push_back( nomphi );
323 Phi.push_back( phi );
324 // nomadiv2.push_back(nomaadiv2);
325 // adiv2.push_back(aadiv2);
326 First.push_back( firstWire );
327 // noma.push_back(nomaa);
328 a.push_back( aa );
329 /// CLHEP says that:
330 /// static const double radian = 1.;
331 /// static const double degree = (3.14159265358979323846/180.0)*radian
332 /// static const double deg = degree;
333
334 nomebusing.push_back( atan( nomaa / wlength ) );
335 ebusing.push_back( atan( aa / wlength ) );
336
337 // if(aa==0.0) sigma.push_back(0.0);
338 // else sigma.push_back(0.13*wlength/aa);
339 // nomdeltaz.push_back(r*(1.0-cos(nomaadiv2)));
340 // deltaz.push_back(r*(1.0-cos(aadiv2)));
341 nomRotate.push_back( nomrotateCell );
342 Rotate.push_back( rotateCell );
343 }
344
345 getline( inFile, line );
346 inFile >> segmentNo;
347 inFile.seekg( 1, ios::cur );
348 getline( inFile, line );
349 getline( inFile, line );
350
351 for ( i = 0; i < segmentNo; i++ )
352 {
353 inFile >> length >> innerR >> outR >> z >> name;
354 getline( inFile, line );
355 fLength.push_back( length );
356 fInnerR.push_back( innerR );
357 fOutR.push_back( outR );
358 fZ.push_back( z );
359 fName.push_back( name );
360 }
361
362 /// Variables used here are as follows,
363 /// MdcGeoGeneral hlh;
364 /// MdcGeoSuper* suph;
365 /// MdcGeoLayer* lh;
366 /// MdcGeoWire* wh;
367 /// MdcGeoEnd* end;
368
369 // MdcGeoGeneral include signal wire and field wire
370 MdcGeoGeneral hlh;
371 double a1, a2, a3, nomphi0, phi0, cellphi;
372 double noma1, noma2, noma3;
373 for ( i = 0; i < TLayerNo; i++ )
374 {
375 i_east = getAlignParIndexEast( i );
376 i_west = getAlignParIndexWest( i );
377 hlh.Id( i );
378 hlh.LayerName( LayerName[i] );
379 hlh.Radius( R[i] );
380 hlh.Length( wLength[i] );
381 hlh.NCell( WireNo[i] / 2 );
382 // east endcap rotates away from designed position by Phi considering misalignment,
383 // nomPhi without considering misalignment
384 hlh.Offset( Phi[i] );
385 hlh.nomOffset( nomPhi[i] );
386 hlh.Phi( Phi[i] );
387 hlh.nomPhi( nomPhi[i] );
388 hlh.First( (int)First[i] );
389 HepPoint3D offF( Sx[i_west], Sy[i_west], Sz[i_west] );
390 HepPoint3D offB( Sx[i_east], Sy[i_east], Sz[i_east] );
391 hlh.OffF( offF );
392 hlh.OffB( offB );
393 hlh.TwistF( Rz[i_west] );
394 hlh.TwistB( Rz[i_east] );
395 // west endcap rotates away from designed position by Rotate considering misalignment,
396 // nomRotate without considering misalignment
397 hlh.Shift( Rotate[i] );
398 hlh.nomShift( nomRotate[i] );
399 hlh.SxEast( Sx[i_east] );
400 hlh.SxWest( Sx[i_west] );
401 hlh.SyEast( Sy[i_east] );
402 hlh.SyWest( Sy[i_west] );
403 hlh.SzEast( Sz[i_east] );
404 hlh.SzWest( Sz[i_west] );
405
406 hlh.RxEast( Rx[i_east] );
407 hlh.RxWest( Rx[i_west] );
408 hlh.RyEast( Ry[i_east] );
409 hlh.RyWest( Ry[i_west] );
410 hlh.RzEast( Rz[i_east] );
411 hlh.RzWest( Rz[i_west] );
412 fGenerals.push_back( hlh );
413 }
414
415 MdcGeoSuper* suph;
416 for ( i = 0; i < TSignalLayerNo; i++ )
417 {
418 // MdcGeoLayer only represent signal wires
419 MdcGeoLayer* lh = new MdcGeoLayer();
420 // lh is a signalwire layer
421 int lyr = fSignalLayer[i];
422 // the value of lyr starts from 1,because the first layer of MDC is field
423 // wire
424 i_east = getAlignParIndexEast( lyr );
425 i_west = getAlignParIndexWest( lyr );
426 lh->SLayer( lyr + 1 );
427 if ( i % 4 == 0 )
428 {
429 suph = new MdcGeoSuper();
430 suph->LowerR( R[lyr - 1] );
431 if ( i == 40 ) { suph->UpperR( R[lyr + 5] ); }
432 else { suph->UpperR( R[lyr + 7] ); }
433 switch ( i / 4 )
434 {
435 case 0: suph->Type( -1 ); break;
436 case 1: suph->Type( 1 ); break;
437 case 2: suph->Type( 0 ); break;
438 case 3: suph->Type( 0 ); break;
439 case 4: suph->Type( 0 ); break;
440 case 5: suph->Type( -1 ); break;
441 case 6: suph->Type( 1 ); break;
442 case 7: suph->Type( -1 ); break;
443 case 8: suph->Type( 1 ); break;
444 case 9: suph->Type( 0 ); break;
445 case 10: suph->Type( 0 ); break;
446 default: break;
447 }
448 suph->Id( i / 4 );
449 fSupers.push_back( suph );
450 }
451 /// attention, it is 2*twopi means 4*pi
452 cellphi = 2 * twopi / WireNo[lyr];
453 /// calculate the phi angle of the sense wire of the first cell of the layer
454 phi0 = Phi[lyr] + abs( First[lyr] - 1 ) * ( cellphi / 2 );
455 nomphi0 = nomPhi[lyr] + abs( First[lyr] - 1 ) * ( cellphi / 2 );
456 lh->Id( i );
457 int wircount = 0;
458 for ( int wk = 0; wk < i; wk++ )
459 {
460 int lyrwk = fSignalLayer[wk];
461 wircount = wircount + WireNo[lyrwk] / 2;
462 };
463 /// Wirst is the the global number of the first signal wire of this layer
464 /// in all the signal wire
465 lh->Wirst( wircount );
466 lh->Slant( ebusing[lyr] );
467 lh->nomSlant( nomebusing[lyr] );
468 lh->Radius( R[lyr] );
469 lh->Length( wLength[lyr] );
470 lh->RCSiz1( R[lyr] - R[lyr - 1] );
471 lh->RCSiz2( R[lyr + 1] - R[lyr] );
472 lh->PCSiz( R[lyr] * cellphi );
473 lh->NCell( WireNo[lyr] / 2 );
474 lh->Offset( phi0 );
475 lh->Shift( Rotate[lyr] );
476 lh->nomOffset( nomphi0 );
477 lh->nomShift( nomRotate[lyr] );
478
479 vector<MdcGeoSuper*>::iterator it1 = fSupers.end() - 1;
480 lh->Sup( *it1 );
481 fLayers.push_back( lh );
482 int geo = -1;
483 if ( i < 8 ) { geo = i * 2 + 1; }
484 else if ( i < 20 ) { geo = i * 2 + 2; }
485 else if ( i < 36 ) { geo = i * 2 + 3; }
486 else { geo = i * 2 + 4; }
487 lh->Gen( geo );
488
489 for ( int j = 0; j < WireNo[lyr] / 2; j++ )
490 {
491 /// wh is signal wire
492 MdcGeoWire* wh = new MdcGeoWire();
493 const int wireId = wircount + j;
494 wh->Id( wireId );
495
496 // east end
497 noma1 = R[lyr] * cos( nomphi0 + j * cellphi );
498 noma2 = R[lyr] * sin( nomphi0 + j * cellphi );
499 noma3 = wLength[lyr] / 2; /// attention wLength[lyr] not the true length of the wire
500
501 /// caluculate aligned wire position, updated bu wulh 12/09/18
502 double sin_Ab = sin( Rx[i_east] );
503 double cos_Ab = cos( Rx[i_east] );
504 double sin_Bb = sin( Ry[i_east] );
505 double cos_Bb = cos( Ry[i_east] );
506 double sin_Rb = sin( Rz[i_east] );
507 double cos_Rb = cos( Rz[i_east] );
508 a1 = noma1 * cos_Rb * cos_Bb + noma2 * ( cos_Rb * sin_Bb * sin_Ab - sin_Rb * cos_Ab ) +
509 noma3 * ( cos_Rb * sin_Bb * cos_Ab + sin_Rb * sin_Ab );
510 a2 = noma1 * sin_Rb * cos_Bb + noma2 * ( sin_Rb * sin_Bb * sin_Ab + cos_Rb * cos_Ab ) +
511 noma3 * ( sin_Rb * sin_Bb * cos_Ab - cos_Rb * sin_Ab );
512 a3 = noma1 * ( -sin_Bb ) + noma2 * cos_Bb * sin_Ab + noma3 * cos_Bb * cos_Ab;
513
514 double xbnew = a1 + Sx[i_east] + wirePosVec[wireId][0];
515 double ybnew = a2 + Sy[i_east] + wirePosVec[wireId][1];
516 double zbnew = a3 + Sz[i_east] + wirePosVec[wireId][2];
517
518 // HepPoint3D pb(a1,a2,a3);
519 HepPoint3D pb( xbnew, ybnew, zbnew );
520 HepPoint3D nompb( noma1, noma2, noma3 );
521 HepPoint3D wireposb( wirePosVec[wireId][0], wirePosVec[wireId][1],
522 wirePosVec[wireId][2] );
523 wh->Backward( pb );
524 wh->nomBackward( nompb );
525 wh->BWirePos( wireposb );
526
527 // west end
528 noma1 = R[lyr] * cos( nomphi0 + ( j + lh->nomShift() ) * cellphi );
529 noma2 = R[lyr] * sin( nomphi0 + ( j + lh->nomShift() ) * cellphi );
530 noma3 = -wLength[lyr] / 2;
531
532 double sin_Af = sin( Rx[i_west] );
533 double cos_Af = cos( Rx[i_west] );
534 double sin_Bf = sin( Ry[i_west] );
535 double cos_Bf = cos( Ry[i_west] );
536 double sin_Rf = sin( Rz[i_west] );
537 double cos_Rf = cos( Rz[i_west] );
538 a1 = noma1 * cos_Rf * cos_Bf + noma2 * ( cos_Rf * sin_Bf * sin_Af - sin_Rf * cos_Af ) +
539 noma3 * ( cos_Rf * sin_Bf * cos_Af + sin_Rf * sin_Af );
540 a2 = noma1 * sin_Rf * cos_Bf + noma2 * ( sin_Rf * sin_Bf * sin_Af + cos_Rf * cos_Af ) +
541 noma3 * ( sin_Rf * sin_Bf * cos_Af - cos_Rf * sin_Af );
542 a3 = noma1 * ( -sin_Bf ) + noma2 * cos_Bf * sin_Af + noma3 * cos_Bf * cos_Af;
543
544 double xfnew = a1 + Sx[i_west] + wirePosVec[wireId][3];
545 double yfnew = a2 + Sy[i_west] + wirePosVec[wireId][4];
546 double zfnew = a3 + Sz[i_west] + wirePosVec[wireId][5];
547
548 // HepPoint3D pf(a1,a2,a3);
549 HepPoint3D pf( xfnew, yfnew, zfnew );
550 HepPoint3D nompf( noma1, noma2, noma3 );
551 HepPoint3D wireposf( wirePosVec[wireId][3], wirePosVec[wireId][4],
552 wirePosVec[wireId][5] );
553 wh->Forward( pf );
554 wh->nomForward( nompf );
555 wh->FWirePos( wireposf );
556
557 wh->Layer( i );
558 wh->Cell( j );
559 wh->Stat( 0 );
560 wh->Slant( ebusing[lyr] );
561 wh->nomSlant( nomebusing[lyr] );
562
563 /// set the tension and wire sag
564 wh->Tension( wireTensionVec[wireId] );
565 // std::cout<<" wh->Tension: "<< wh->Tension()<<std::endl;
566 // std::cout<<" wire sag: "<<wh->Sag(wireId)<<std::endl;
567
568 /// because of just before have fLayers.push_back(lh);
569 /// so use it2 = fLayers.end()-1 to get the MdcGeoLayer
570 /// which have just push_back into the stack
571 vector<MdcGeoLayer*>::iterator it2 = fLayers.end() - 1;
572 wh->Lyr( *it2 );
573 fWires.push_back( wh );
574 }
575 }
576
577 fMisc.OuterR( fOutR[1] );
578 fMisc.InnerR( fInnerR[2] );
579 fMisc.OuterTk( fOutR[1] - fInnerR[1] );
580 fMisc.InnerTk( fOutR[2] - fInnerR[2] );
581 fMisc.NSWire( fWires.size() );
582 fMisc.NFWire( TWireNo - fWires.size() );
583
584 fMisc.LayerNo( TLayerNo );
585 fMisc.WireNo( TWireNo );
586 fMisc.SLayerNo( TSignalLayerNo );
587 fMisc.SWireR( signalWireR );
588 fMisc.FWireR( fieldWireR );
589
590 for ( i = 0; i < segmentNo; i++ )
591 {
592 MdcGeoEnd* end = new MdcGeoEnd();
593 end->Id( i );
594 end->Length( fLength[i] );
595 end->InnerR( fInnerR[i] );
596 end->OutR( fOutR[i] );
597 end->Z( fZ[i] );
598 end->Name( fName[i] );
599 fEnd.push_back( end );
600 }
601}
602
603void MdcGeomSvc::ReadTensionDataBase( std::vector<double>& wireTensionVec ) {
604 std::string fullPath = "/Calib/MdcAlign";
605 MsgStream log( msgSvc(), name() );
606 log << MSG::INFO << "ReadTensionDataBase() wireTensionPath = " << fullPath << endmsg;
607 cout << "Read wireTension from Calibration Database!" << endl;
608
609 SmartDataPtr<CalibData::MdcAlignData> tension( m_pCalibDataSvc, fullPath );
610 if ( !tension )
611 {
612 log << MSG::ERROR << "can not get MdcAlignConst via SmartPtr" << endmsg;
613 return;
614 }
615 for ( int i = 0; i < 6796; i++ )
616 {
617 double tens = tension->gettension( i );
618 wireTensionVec.push_back( tens );
619 }
620}
621void MdcGeomSvc::ReadWirePosDataBase( std::vector<vector<double>>& wirePosVec ) {
622 std::string fullPath = "/Calib/MdcAlign";
623 MsgStream log( msgSvc(), name() );
624 log << MSG::INFO << "ReadWirePosDataBase() wirePositionPath = " << fullPath << endmsg;
625
626 cout << "Read wirePosition from Calibration Database!" << endl;
627 SmartDataPtr<CalibData::MdcAlignData> wirepos( m_pCalibDataSvc, fullPath );
628 if ( !wirepos )
629 {
630 log << MSG::ERROR << "can not get MdcAlignConst via SmartPtr" << endmsg;
631 return;
632 }
633 double dxe, dye, dze, dxw, dyw, dzw;
634 for ( int j = 0; j < 6796; j++ )
635 {
636
637 dxe = wirepos->getdxWireEast( j );
638 dye = wirepos->getdyWireEast( j );
639 dze = wirepos->getdzWireEast( j );
640 dxw = wirepos->getdxWireWest( j );
641 dyw = wirepos->getdyWireWest( j );
642 dzw = wirepos->getdzWireWest( j );
643
644 wirePosVec[j].push_back( dxe );
645 wirePosVec[j].push_back( dye );
646 wirePosVec[j].push_back( dze );
647 wirePosVec[j].push_back( dxw );
648 wirePosVec[j].push_back( dyw );
649 wirePosVec[j].push_back( dzw );
650 }
651}
652void MdcGeomSvc::ReadAliParDataBase( vector<double>& Sx, vector<double>& Sy,
653 vector<double>& Sz, vector<double>& Rx,
654 vector<double>& Ry, vector<double>& Rz ) {
655 MsgStream log( msgSvc(), name() );
656 std::string fullPath = "/Calib/MdcAlign";
657 log << MSG::INFO << "ReadAliParDataBase() alignParPath = " << fullPath << endmsg;
658 cout << "Read alignment parameters from Calibration Database!" << endl;
659
660 SmartDataPtr<CalibData::MdcAlignData> alignpar( m_pCalibDataSvc, fullPath );
661 if ( !alignpar )
662 {
663 log << MSG::ERROR << "can not get MdcAlignConst via SmartPtr" << endmsg;
664 return;
665 }
666 double tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
667 for ( int k = 0; k < 16; k++ )
668 {
669 tmp1 = alignpar->getdxEP( k );
670 tmp2 = alignpar->getdyEP( k );
671 tmp3 = alignpar->getdzEP( k );
672 tmp4 = alignpar->getrxEP( k );
673 tmp5 = alignpar->getryEP( k );
674 tmp6 = alignpar->getrzEP( k );
675
676 Sx.push_back( m_wholeShiftX + tmp1 );
677 Sy.push_back( m_wholeShiftY + tmp2 );
678 Sz.push_back( m_wholeShiftZ + tmp3 );
679 Rx.push_back( m_wholeRotatX + tmp4 );
680 Ry.push_back( m_wholeRotatY + tmp5 );
681 Rz.push_back( m_wholeRotatZ + tmp6 );
682 }
683}
684const int MdcGeomSvc::getWireSize() { return fWires.size(); }
685
686const int MdcGeomSvc::getLayerSize() { return fLayers.size(); }
687
688const int MdcGeomSvc::getSuperLayerSize() { return fSupers.size(); }
689
690const int MdcGeomSvc::getGeneralLayerSize() { return fGenerals.size(); }
691
692const int MdcGeomSvc::getSegmentNo() { return fEnd.size(); }
693
695
696const int MdcGeomSvc::getAlignParIndexEast( int lyr ) const {
697 /// the Mdc small endplate east
698 if ( ( lyr >= 0 ) && ( lyr <= 16 ) ) return 0;
699 /// the 1th ring east
700 else if ( ( lyr >= 17 ) && ( lyr <= 20 ) ) return 1;
701 /// the 2th ring east
702 else if ( ( lyr >= 21 ) && ( lyr <= 24 ) ) return 2;
703 /// the 3th ring east
704 else if ( ( lyr >= 25 ) && ( lyr <= 28 ) ) return 3;
705 /// the 4th ring east
706 else if ( ( lyr >= 29 ) && ( lyr <= 32 ) ) return 4;
707 /// the 5th ring east
708 else if ( ( lyr >= 33 ) && ( lyr <= 36 ) ) return 5;
709 /// the 6th ring east
710 else if ( ( lyr >= 37 ) && ( lyr <= 41 ) ) return 6;
711 /// the Mdc big endplate east
712 else if ( lyr >= 42 ) return 7;
713 else std::cout << " Hi, ERROR OCCUR !!!" << std::endl;
714 return -1;
715}
716
717const int MdcGeomSvc::getAlignParIndexWest( int lyr ) const {
718 /// the Mdc small endplate west
719 if ( ( lyr >= 0 ) && ( lyr <= 16 ) ) return 8;
720 /// the 1th ring west
721 else if ( ( lyr >= 17 ) && ( lyr <= 20 ) ) return 9;
722 /// the 2th ring west
723 else if ( ( lyr >= 21 ) && ( lyr <= 24 ) ) return 10;
724 /// the 3th ring west
725 else if ( ( lyr >= 25 ) && ( lyr <= 28 ) ) return 11;
726 /// the 4th ring west
727 else if ( ( lyr >= 29 ) && ( lyr <= 32 ) ) return 12;
728 /// the 5th ring west
729 else if ( ( lyr >= 33 ) && ( lyr <= 36 ) ) return 13;
730 /// the 6th ring west
731 else if ( ( lyr >= 37 ) && ( lyr <= 41 ) ) return 14;
732 /// the Mdc big endplate west
733 else if ( lyr >= 42 ) return 15;
734 else std::cout << " Hi, ERROR OCCUR !!!" << std::endl;
735 return -1;
736}
737
738/// this handle function is prepared for special use
739void MdcGeomSvc::handle( const Incident& inc ) {
740 MsgStream log( msgSvc(), name() );
741 log << MSG::DEBUG << "handle: " << inc.type() << endmsg;
742 IDataProviderSvc* m_eventSvc;
743 Gaudi::svcLocator()->service( "EventDataSvc", m_eventSvc, true );
744 SmartDataPtr<Event::EventHeader> eventHeader( m_eventSvc, "/Event/EventHeader" );
745 if ( !eventHeader ) { log << MSG::FATAL << "Could not find Event Header" << endmsg; }
746 if ( m_updataalign ) return;
747 if ( inc.type() == "NewRun" )
748 {
749 log << MSG::DEBUG << "Begin Event" << endmsg;
750 clean();
751 m_updataalign = true;
752 if ( m_nomcalignment && m_mindex == 0 )
753 {
754 int RunNo = eventHeader->runNumber();
755 if ( RunNo < 0 ) m_readAlignParDataBase = false;
756 else m_readAlignParDataBase = true;
757 m_mindex += 1;
758 cout << "m__RunNo=" << RunNo << "m_mindex=" << m_mindex << endl;
759 }
760 // std::cout<<"############"<<m_readAlignParDataBase<<std::endl;
761 ReadFilePar();
762 }
763}
764
765const MdcGeoWire* const MdcGeomSvc::Wire( unsigned id ) {
766 if ( id < fWires.size() ) return fWires[id];
767
768 return 0;
769}
770
771const MdcGeoWire* const MdcGeomSvc::Wire( unsigned lyrid, unsigned wirid ) {
772 if ( ( lyrid < fLayers.size() ) && ( (int)wirid < Layer( lyrid )->NCell() ) )
773 return fWires[Layer( lyrid )->Wirst() + wirid];
774
775 return 0;
776}
777
778const MdcGeoLayer* const MdcGeomSvc::Layer( unsigned id ) {
779 if ( id < fLayers.size() ) return fLayers[id];
780
781 return 0;
782}
783
784const MdcGeoSuper* const MdcGeomSvc::SuperLayer( unsigned id ) {
785 if ( id < fSupers.size() ) return fSupers[id];
786
787 return 0;
788}
789
790const MdcGeoGeneral* const MdcGeomSvc::GeneralLayer( unsigned id ) {
791 if ( id < fGenerals.size() ) return &fGenerals[id];
792
793 return 0;
794}
795
796const MdcGeoMisc* const MdcGeomSvc::Misc( void ) { return &fMisc; }
797
798const MdcGeoEnd* const MdcGeomSvc::End( unsigned id ) {
799 if ( id < fEnd.size() ) return fEnd[id];
800
801 return 0;
802}
803
804bool MdcGeomSvc::getSagFlag( void ) { return m_doSag; }
DECLARE_COMPONENT(BesBdkRc)
double Phi(RecMdcKalTrack *trk)
HepGeom::Point3D< double > HepPoint3D
const int wireNo
titledef title[20]
double pi
IMessageSvc * msgSvc()
static bool m_readAlignParDataBase
Definition MdcGeomSvc.h:55
MdcGeomSvc(const std::string &name, ISvcLocator *svcloc)
virtual StatusCode initialize()
virtual bool getSagFlag(void)
const MdcGeoSuper *const SuperLayer(unsigned id)
const MdcGeoWire *const Wire(unsigned id)
const MdcGeoGeneral *const GeneralLayer(unsigned id)
void handle(const Incident &inc)
this handle function is prepared for special use
const int getSuperLayerSize()
virtual StatusCode finalize()
const MdcGeoEnd *const End(unsigned id)
const MdcGeoLayer *const Layer(unsigned id)
static bool m_doSag
Definition MdcGeomSvc.h:54
const int getSegmentNo()
const int getWireSize()
const int getGeneralLayerSize()
const int getLayerSize()
const MdcGeoMisc *const Misc(void)
static bool m_nomcalignment
Definition MdcGeomSvc.h:56
complex_t R(double Q2, double M2, double G, double Mp2, double Mm2)
Definition TUtil.h:22