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"
17#include "GaudiKernel/ISvcLocator.h"
18#include "GaudiKernel/IDataProviderSvc.h"
19#include "GaudiKernel/Bootstrap.h"
31 if(getenv(
"MDCGEOMSVCROOT")){
32 m_alignFilePath = std::string(getenv(
"MDCGEOMSVCROOT"))+std::string(
"/share/MdcAlignPar.dat");
35 m_wirePosFilePath = std::string(getenv(
"MDCGEOMSVCROOT"))+std::string(
"/share/WirePosCalib.dat");
38 m_wireTensionFilePath = std::string(getenv(
"MDCGEOMSVCROOT"))+std::string(
"/share/mdcWireTension.dat");
43 std::cout<<
"A fatal error, contact wangjk..."<<std::endl;
46 declareProperty(
"doSag",
m_doSag =
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);
73 MsgStream log(messageService(), name());
74 log << MSG::INFO << name() <<
": Start of run initialisation" << endreq;
76 StatusCode sc = Service::initialize();
77 if ( sc.isFailure() )
return sc;
79 m_updataalign =
false;
81 sc = service(
"IncidentSvc", incsvc);
84 incsvc -> addListener(
this,
"NewRun", priority);
90 sc = service(
"CalibDataSvc", m_pCalibDataSvc,
true);
92 if ( !sc.isSuccess() ) {
94 <<
"Could not get IDataProviderSvc interface of CalibXmlCnvSvc"
99 <<
"Retrieved IDataProviderSvc interface of CalibXmlCnvSvc"
103 return StatusCode::SUCCESS;
107 MsgStream log(messageService(), name());
108 log << MSG::INFO << name() <<
": End of Run" << endreq;
109 return StatusCode::SUCCESS;
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;
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;
137void MdcGeomSvc::ReadFilePar(){
138 std::string geometryFilePath = getenv(
"MDCSIMROOT");
139 geometryFilePath +=
"/dat/Mdc.txt";
140 std::ifstream inFile(geometryFilePath.c_str() );
143 std::cout<<
"Error, mdc parameters file not exist"<<std::endl;
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");
154 alignFilePath = m_alignFilePath;
155 wirePosFilePath = m_wirePosFilePath;
156 wireTensionFilePath = m_wireTensionFilePath;
158 std::ifstream alignFile(alignFilePath.c_str());
159 std::ifstream wirePosFile(wirePosFilePath.c_str());
160 std::ifstream wireTensionFile(wireTensionFilePath.c_str());
163 std::cout<<
"Error, mdc wire position file not exist..."<<std::endl;
166 if(!wireTensionFile){
167 std::cout<<
"Error, mdc wire tension file not exist..."<<std::endl;
170 std::vector<double> wireTensionVec;
174 ReadTensionDataBase(wireTensionVec);
176 cout <<
"Read wireTension from file:" << wireTensionFilePath.c_str() << endl;
179 for(
int ii=0; ii<6796; ii++){
180 wireTensionFile>>idd>>tension;
183 wireTensionVec.push_back(tension);
187 wireTensionVec.push_back(tension);
192 std::vector<vector<double> > wirePosVec(6796);
194 ReadWirePosDataBase(wirePosVec);
196 cout <<
"Read wirePosition from file:" << wirePosFilePath.c_str() << endl;
197 double dxe,dye,dze,dxw,dyw,dzw;
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);
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;
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;
237 ReadAliParDataBase(Sx, Sy, Sz, Rx, Ry, Rz);
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;
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);
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++){
271 fSignalLayer[i]=signalLayer-1;
274 inFile.seekg(1,ios::cur);
275 getline(inFile, line);
276 getline(inFile, line);
279 double delta_rotateCell;
281 for( i=0; i<TLayerNo; i++){
282 i_east=getAlignParIndexEast(i);
283 i_west=getAlignParIndexWest(i);
285 inFile>>layer>>
wireNo>>wlength>>r>>nomphi>>firstWire>>nomrotateCell;
286 getline(inFile, line);
290 nomaadiv2=2*
pi*nomrotateCell/
wireNo;
292 nomaa=2*r*
sin(nomaadiv2);
293 delta_rotateCell=(Rz[i_west]-Rz[i_east])*
wireNo/(4*
pi);
294 rotateCell=nomrotateCell+delta_rotateCell;
298 double shiftPhi=twopi/
wireNo;
300 if(nomphi<0) nomphi += shiftPhi;
303 LayerName.push_back(layer);
305 wLength.push_back(wlength);
307 nomPhi.push_back(nomphi);
311 First.push_back(firstWire);
319 nomebusing.push_back(atan(nomaa/wlength));
320 ebusing.push_back(atan(aa/wlength));
326 nomRotate.push_back(nomrotateCell);
327 Rotate.push_back(rotateCell);
330 getline(inFile, line);
332 inFile.seekg(1,ios::cur);
333 getline(inFile, line);
334 getline(inFile, line);
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);
343 fName.push_back(name);
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);
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]);
380 hlh.
Shift(Rotate[i]);
395 fGenerals.push_back(hlh);
399 for(i=0;i<TSignalLayerNo;i++){
403 int lyr=fSignalLayer[i];
406 i_east=getAlignParIndexEast(lyr);
407 i_west=getAlignParIndexWest(lyr);
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;
433 fSupers.push_back(suph);
436 cellphi=2*twopi/
WireNo[lyr];
438 phi0=
Phi[lyr]+
abs(First[lyr]-1)*(cellphi/2);
439 nomphi0=nomPhi[lyr]+
abs(First[lyr]-1)*(cellphi/2);
442 for(
int wk=0; wk<i; wk++){
443 int lyrwk=fSignalLayer[wk];
444 wircount=wircount +
WireNo[lyrwk]/2;
449 lh->
Slant(ebusing[lyr]);
453 lh->
RCSiz1(R[lyr]-R[lyr-1]);
454 lh->
RCSiz2(R[lyr+1]-R[lyr]);
455 lh->
PCSiz(R[lyr]*cellphi);
458 lh->
Shift(Rotate[lyr]);
462 vector<MdcGeoSuper*>::iterator it1 = fSupers.end()-1;
464 fLayers.push_back(lh);
477 for(
int j=0;j<
WireNo[lyr]/2;j++){
480 const int wireId = wircount+j;
484 noma1 =
R[lyr]*
cos(nomphi0+j*cellphi);
485 noma2 =
R[lyr]*
sin(nomphi0+j*cellphi);
486 noma3 = wLength[lyr]/2;
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;
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];
508 HepPoint3D wireposb(wirePosVec[wireId][0],wirePosVec[wireId][1],wirePosVec[wireId][2]);
516 noma3 = -wLength[lyr]/2;
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;
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];
538 HepPoint3D wireposf(wirePosVec[wireId][3],wirePosVec[wireId][4],wirePosVec[wireId][5]);
546 wh->
Slant(ebusing[lyr]);
550 wh->
Tension(wireTensionVec[wireId]);
557 vector<MdcGeoLayer*>::iterator it2 = fLayers.end()-1;
559 fWires.push_back(wh);
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());
573 fMisc.
SWireR(signalWireR);
576 for(i=0;i<segmentNo;i++){
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;
594 SmartDataPtr<CalibData::MdcAlignData> tension(m_pCalibDataSvc, fullPath);
596 log << MSG::ERROR <<
"can not get MdcAlignConst via SmartPtr"
600 for(
int i=0;i<6796;i++){
601 double tens = tension->gettension(i);
602 wireTensionVec.push_back(tens);
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;
610 cout <<
"Read wirePosition from Calibration Database!" << endl;
611 SmartDataPtr<CalibData::MdcAlignData> wirepos(m_pCalibDataSvc, fullPath);
613 log << MSG::ERROR <<
"can not get MdcAlignConst via SmartPtr"
617 double dxe,dye,dze,dxw,dyw,dzw;
618 for(
int j=0; j<6796; j++){
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);
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);
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;
643 SmartDataPtr<CalibData::MdcAlignData> alignpar(m_pCalibDataSvc, fullPath);
645 log << MSG::ERROR <<
"can not get MdcAlignConst via SmartPtr"
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);
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);
669 return fWires.size();
674 return fLayers.size();
679 return fSupers.size();
684 return fGenerals.size();
694const int MdcGeomSvc::getAlignParIndexEast(
int lyr)
const{
696 if((lyr>=0) && (lyr<=16))
return 0;
698 else if((lyr>=17) && (lyr<=20))
return 1;
700 else if((lyr>=21) && (lyr<=24))
return 2;
702 else if((lyr>=25) && (lyr<=28))
return 3;
704 else if((lyr>=29) && (lyr<=32))
return 4;
706 else if((lyr>=33) && (lyr<=36))
return 5;
708 else if((lyr>=37) && (lyr<=41))
return 6;
710 else if(lyr>=42)
return 7;
711 else std::cout<<
" Hi, ERROR OCCUR !!!"<<std::endl;
716const int MdcGeomSvc::getAlignParIndexWest(
int lyr)
const{
718 if((lyr>=0) && (lyr<=16))
return 8;
720 else if((lyr>=17) && (lyr<=20))
return 9;
722 else if((lyr>=21) && (lyr<=24))
return 10;
724 else if((lyr>=25) && (lyr<=28))
return 11;
726 else if((lyr>=29) && (lyr<=32))
return 12;
728 else if((lyr>=33) && (lyr<=36))
return 13;
730 else if((lyr>=37) && (lyr<=41))
return 14;
732 else if(lyr>=42)
return 15;
733 else std::cout<<
" Hi, ERROR OCCUR !!!"<<std::endl;
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");
746 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
748 if (m_updataalign)
return;
749 if (inc.type() ==
"NewRun" ){
750 log << MSG::DEBUG <<
"Begin Event" << endreq;
752 m_updataalign =
true;
754 int RunNo=eventHeader->runNumber();
758 cout<<
"m__RunNo="<<RunNo<<
"m_mindex="<<m_mindex<<endl;
767 if (
id < fWires.size())
775 if ((lyrid <fLayers.size()) && ((
int) wirid <
Layer(lyrid)->NCell()))
783 if (
id < fLayers.size())
791 if (
id < fSupers.size())
799 if (
id < fGenerals.size())
800 return & fGenerals[id];
812 if (
id < fEnd.size())
double sin(const BesAngle a)
double cos(const BesAngle a)
double Phi(RecMdcKalTrack *trk)
double Length(void) const
double InnerR(void) const
double Length(void) const
double nomShift(void) const
double TwistB(void) const
double SzWest(void) const
HepPoint3D OffB(void) const
double nomPhi(void) const
double RxEast(void) const
double SxEast(void) const
double TwistF(void) const
double Offset(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
double SzEast(void) const
double RzWest(void) const
double RzEast(void) const
double SyEast(void) const
double RyEast(void) const
double Radius(void) const
double Radius(void) const
double RCSiz2(void) const
double Length(void) const
MdcGeoSuper * Sup(void) const
double nomShift(void) const
double nomSlant(void) const
double RCSiz1(void) const
double Offset(void) const
double nomOffset(void) const
double FWireR(void) const
double OuterTk(void) const
double InnerR(void) const
double OuterR(void) const
double SWireR(void) const
double InnerTk(void) const
double LowerR(void) const
double UpperR(void) const
HepPoint3D FWirePos(void) const
HepPoint3D BWirePos(void) const
MdcGeoLayer * Lyr(void) const
HepPoint3D nomForward(void) const
HepPoint3D Forward(void) const
HepPoint3D nomBackward(void) const
HepPoint3D Backward(void) const
double Tension(void) const
double nomSlant(void) const
static bool m_readAlignParDataBase
MdcGeomSvc(const std::string &name, ISvcLocator *svcloc)
virtual StatusCode initialize()
static 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)
const int getGeneralLayerSize()
const MdcGeoMisc *const Misc(void)
static bool m_nomcalignment
complex_t R(double Q2, double M2, double G, double Mp2, double Mm2)