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