1#include "GaudiKernel/Algorithm.h"
2#include "MdcGeomSvc/MdcGeomSvc.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);
58 declareProperty(
"useCGEM",m_useCgem =
true);
65 if ( IID_IMdcGeomSvc.versionMatch(riid) ) {
68 return Service::queryInterface(riid, ppvInterface) ;
70 return StatusCode::SUCCESS;
74 MsgStream log(messageService(), name());
75 log << MSG::INFO << name() <<
": Start of run initialisation" << endreq;
77 StatusCode sc = Service::initialize();
78 if ( sc.isFailure() )
return sc;
80 m_updataalign =
false;
82 sc = service(
"IncidentSvc", incsvc);
85 incsvc -> addListener(
this,
"NewRun", priority);
91 sc = service(
"CalibDataSvc", m_pCalibDataSvc,
true);
93 if ( !sc.isSuccess() ) {
95 <<
"Could not get IDataProviderSvc interface of CalibXmlCnvSvc"
100 <<
"Retrieved IDataProviderSvc interface of CalibXmlCnvSvc"
104 return StatusCode::SUCCESS;
108 MsgStream log(messageService(), name());
109 log << MSG::INFO << name() <<
": End of Run" << endreq;
110 return StatusCode::SUCCESS;
114 for(vector<MdcGeoLayer*>::iterator it1 = fLayers.begin(); it1 != fLayers.end(); it1++)
delete *it1;
115 for(vector<MdcGeoSuper*>::iterator it2 = fSupers.begin(); it2 != fSupers.end(); it2++)
delete *it2;
116 for(vector<MdcGeoWire*>::iterator it3 = fWires.begin(); it3 != fWires.end(); it3++)
delete *it3;
117 for(vector<MdcGeoEnd*>::iterator it4 = fEnd.begin(); it4 != fEnd.end(); it4++)
delete *it4;
125void MdcGeomSvc::clean(){
126 for(vector<MdcGeoLayer*>::iterator it1 = fLayers.begin(); it1 != fLayers.end(); it1++)
delete *it1;
127 for(vector<MdcGeoSuper*>::iterator it2 = fSupers.begin(); it2 != fSupers.end(); it2++)
delete *it2;
128 for(vector<MdcGeoWire*>::iterator it3 = fWires.begin(); it3 != fWires.end(); it3++)
delete *it3;
129 for(vector<MdcGeoEnd*>::iterator it4 = fEnd.begin(); it4 != fEnd.end(); it4++)
delete *it4;
138void MdcGeomSvc::ReadFilePar(){
139 std::string geometryFilePath = getenv(
"MDCSIMROOT");
140 if(m_useCgem) geometryFilePath +=
"/dat/Mdc_cgem.txt";
141 else geometryFilePath +=
"/dat/Mdc.txt";
142 std::ifstream inFile(geometryFilePath.c_str() );
145 std::cout<<
"Error, mdc parameters file not exist"<<std::endl;
148 std::string alignFilePath;
149 std::string wirePosFilePath;
150 std::string wireTensionFilePath;
151 if (!m_updataalign) {
152 alignFilePath = std::string(getenv(
"MDCGEOMSVCROOT"))+std::string(
"/share/MdcAlignPar.dat");
153 wirePosFilePath = std::string(getenv(
"MDCGEOMSVCROOT"))+std::string(
"/share/WirePosCalib.dat");
154 wireTensionFilePath = std::string(getenv(
"MDCGEOMSVCROOT"))+std::string(
"/share/mdcWireTension.dat");
156 alignFilePath = m_alignFilePath;
157 wirePosFilePath = m_wirePosFilePath;
158 wireTensionFilePath = m_wireTensionFilePath;
160 std::ifstream alignFile(alignFilePath.c_str());
161 std::ifstream wirePosFile(wirePosFilePath.c_str());
162 std::ifstream wireTensionFile(wireTensionFilePath.c_str());
165 std::cout<<
"Error, mdc wire position file not exist..."<<std::endl;
168 if(!wireTensionFile){
169 std::cout<<
"Error, mdc wire tension file not exist..."<<std::endl;
172 std::vector<double> wireTensionVec;
176 ReadTensionDataBase(wireTensionVec);
178 cout <<
"Read wireTension from file:" << wireTensionFilePath.c_str() << endl;
181 for(
int ii=0; ii<6796; ii++){
182 wireTensionFile>>idd>>tension;
185 wireTensionVec.push_back(tension);
189 wireTensionVec.push_back(tension);
194 std::vector<vector<double> > wirePosVec(6796);
196 ReadWirePosDataBase(wirePosVec);
198 cout <<
"Read wirePosition from file:" << wirePosFilePath.c_str() << endl;
199 double dxe,dye,dze,dxw,dyw,dzw;
202 getline(wirePosFile, title);
203 wirePosFile.seekg(1,ios::cur);
204 for(
int j=0; j<6796; j++){
205 wirePosFile>>wid>>dxe>>dye>>dze>>dxw>>dyw>>dzw;
206 wirePosVec[j].push_back(dxe);
207 wirePosVec[j].push_back(dye);
208 wirePosVec[j].push_back(dze);
209 wirePosVec[j].push_back(dxw);
210 wirePosVec[j].push_back(dyw);
211 wirePosVec[j].push_back(dzw);
221 double signalWireR, fieldWireR;
222 int TLayerNo, TWireNo,TSignalLayerNo,fSignalLayer[50];
223 int i,
wireNo, firstWire,segmentNo,signalLayer;
224 double length, nomphi, phi, r,nomaadiv2, aadiv2,
225 nomaa, aa, nomrotateCell, rotateCell, wlength, innerR, outR, z;
226 std::string layer, name, line;
228 vector<int> WireNo, fSegmentNo;
229 vector<double> wLength,
R, nomPhi,
Phi,nomadiv2, adiv2,
First,
230 noma, a, nomebusing, ebusing, nomsigma, sigma, nomdeltaz, deltaz,
231 nomRotate, Rotate, fLength, fInnerR, fOutR, fZ;
232 vector<string> LayerName, fName;
233 vector<double> Sx,Sy,Sz,Rx,Ry,Rz;
234 double tmp1,tmp2,tmp3,tmp4,tmp5,tmp6;
239 ReadAliParDataBase(Sx, Sy, Sz, Rx, Ry, Rz);
241 cout <<
"Read alignment parameters from file:" << alignFilePath.c_str() << endl;
242 getline(alignFile, line);
243 alignFile.seekg(1,ios::cur);
244 for(
int k=0;k<16;k++){
245 alignFile>>line>>tmp1>>tmp2>>tmp3>>tmp4>>tmp5>>tmp6;
255 Sx.push_back(m_wholeShiftX+tmp1);
256 Sy.push_back(m_wholeShiftY+tmp2);
257 Sz.push_back(m_wholeShiftZ+tmp3);
258 Rx.push_back(m_wholeRotatX+tmp4);
259 Ry.push_back(m_wholeRotatY+tmp5);
260 Rz.push_back(m_wholeRotatZ+tmp6);
266 getline(inFile, line);
267 inFile>>TLayerNo>>TWireNo>>TSignalLayerNo>>signalWireR>>fieldWireR;
268 inFile.seekg(1,ios::cur);
269 getline(inFile, line);
270 for( i=0; i<TSignalLayerNo; i++){
273 fSignalLayer[i]=signalLayer-1;
276 inFile.seekg(1,ios::cur);
277 getline(inFile, line);
278 getline(inFile, line);
281 double delta_rotateCell;
283 for( i=0; i<TLayerNo; i++){
284 i_east=getAlignParIndexEast(i);
285 i_west=getAlignParIndexWest(i);
287 inFile>>layer>>
wireNo>>wlength>>r>>nomphi>>firstWire>>nomrotateCell;
288 getline(inFile, line);
292 nomaadiv2=2*
pi*nomrotateCell/
wireNo;
294 nomaa=2*r*
sin(nomaadiv2);
295 delta_rotateCell=(Rz[i_west]-Rz[i_east])*
wireNo/(4*
pi);
296 rotateCell=nomrotateCell+delta_rotateCell;
300 double shiftPhi=twopi/
wireNo;
302 if(nomphi<0) nomphi += shiftPhi;
303 phi=nomphi+Rz[i_east];
304 LayerName.push_back(layer);
306 wLength.push_back(wlength);
308 nomPhi.push_back(nomphi);
312 First.push_back(firstWire);
320 nomebusing.push_back(atan(nomaa/wlength));
321 ebusing.push_back(atan(aa/wlength));
327 nomRotate.push_back(nomrotateCell);
328 Rotate.push_back(rotateCell);
331 getline(inFile, line);
333 inFile.seekg(1,ios::cur);
334 getline(inFile, line);
335 getline(inFile, line);
337 for(i=0; i<segmentNo; i++){
338 inFile>>
length>>innerR>>outR>>z>>name;
339 getline(inFile,line);
340 fLength.push_back(
length);
341 fInnerR.push_back(innerR);
342 fOutR.push_back(outR);
344 fName.push_back(name);
356 double a1,a2,a3,nomphi0,phi0,cellphi;
357 double noma1,noma2,noma3;
358 for(i=0;i<TLayerNo;i++){
359 i_east=getAlignParIndexEast(i);
360 i_west=getAlignParIndexWest(i);
365 hlh.
NCell(WireNo[i]/2);
372 hlh.
First((
int)First[i]);
373 HepPoint3D offF(Sx[i_west],Sy[i_west],Sz[i_west]);
374 HepPoint3D offB(Sx[i_east],Sy[i_east],Sz[i_east]);
381 hlh.
Shift(Rotate[i]);
396 fGenerals.push_back(hlh);
400 for(i=0;i<TSignalLayerNo;i++){
404 int lyr=fSignalLayer[i];
407 i_east=getAlignParIndexEast(lyr);
408 i_west=getAlignParIndexWest(lyr);
420 case 0: suph->
Type(-1);
break;
421 case 1: suph->
Type( 1);
break;
422 case 2: suph->
Type( 0);
break;
423 case 3: suph->
Type( 0);
break;
424 case 4: suph->
Type( 0);
break;
425 case 5: suph->
Type(-1);
break;
426 case 6: suph->
Type( 1);
break;
427 case 7: suph->
Type(-1);
break;
428 case 8: suph->
Type( 1);
break;
429 case 9: suph->
Type( 0);
break;
430 case 10: suph->
Type(0);
break;
434 fSupers.push_back(suph);
437 cellphi=2*twopi/WireNo[lyr];
439 phi0=
Phi[lyr]+
abs(First[lyr]-1)*(cellphi/2);
440 nomphi0=nomPhi[lyr]+
abs(First[lyr]-1)*(cellphi/2);
443 for(
int wk=0; wk<i; wk++){
444 int lyrwk=fSignalLayer[wk];
445 wircount=wircount + WireNo[lyrwk]/2;
450 lh->
Slant(ebusing[lyr]);
454 lh->
RCSiz1(R[lyr]-R[lyr-1]);
455 lh->
RCSiz2(R[lyr+1]-R[lyr]);
456 lh->
PCSiz(R[lyr]*cellphi);
457 lh->
NCell(WireNo[lyr]/2);
459 lh->
Shift(Rotate[lyr]);
463 vector<MdcGeoSuper*>::iterator it1 = fSupers.end()-1;
465 fLayers.push_back(lh);
478 for(
int j=0;j<WireNo[lyr]/2;j++){
481 const int wireId = wircount+j;
485 a1 =
R[lyr]*
cos(phi0+j*cellphi)+Sx[i_east]+wirePosVec[wireId][0];
486 a2 =
R[lyr]*
sin(phi0+j*cellphi)+Sy[i_east]+wirePosVec[wireId][1];
487 a3 = wLength[lyr]/2+wirePosVec[wireId][2]+Sz[i_east];
491 double yb = a2 *
cos(Rx[i_east]) + a3 *
sin(Rx[i_east]);
492 double zb = a3 *
cos(Rx[i_east]) - a2 *
sin(Rx[i_east]);
495 double xbnew = xb *
cos(Ry[i_east]) - zb *
sin(Ry[i_east]);
497 double zbnew = xb *
sin(Ry[i_east]) + zb *
cos(Ry[i_east]);
499 noma1 =
R[lyr]*
cos(nomphi0+j*cellphi);
500 noma2 =
R[lyr]*
sin(nomphi0+j*cellphi);
502 noma3 = wLength[lyr]/2;
506 HepPoint3D wireposb(wirePosVec[wireId][0],wirePosVec[wireId][1],wirePosVec[wireId][2]);
516 a1 =
R[lyr]*
cos(phi0+(j+lh->
Shift())*cellphi)+Sx[i_west]+wirePosVec[wireId][3];
517 a2 =
R[lyr]*
sin(phi0+(j+lh->
Shift())*cellphi)+Sy[i_west]+wirePosVec[wireId][4];
519 a3 = -wLength[lyr]/2+wirePosVec[wireId][5]+Sz[i_west];
522 double yf = a2 *
cos(Rx[i_west]) + a3 *
sin(Rx[i_west]);
523 double zf = a3 *
cos(Rx[i_west]) - a2 *
sin(Rx[i_west]);
526 double xfnew = xf *
cos(Ry[i_west]) - zf *
sin(Ry[i_west]);
528 double zfnew = xf *
sin(Ry[i_west]) + zf *
cos(Ry[i_west]);
532 noma3 = -wLength[lyr]/2;
536 HepPoint3D wireposf(wirePosVec[wireId][3],wirePosVec[wireId][4],wirePosVec[wireId][5]);
550 wh->
Slant(ebusing[lyr]);
554 wh->
Tension(wireTensionVec[wireId]);
561 vector<MdcGeoLayer*>::iterator it2 = fLayers.end()-1;
563 fWires.push_back(wh);
569 fMisc.
OuterTk(fOutR[1]-fInnerR[1]);
570 fMisc.
InnerTk(fOutR[2]-fInnerR[2]);
571 fMisc.
NSWire(fWires.size());
572 fMisc.
NFWire(TWireNo-fWires.size());
577 fMisc.
SWireR(signalWireR);
580 for(i=0;i<segmentNo;i++){
592void MdcGeomSvc::ReadTensionDataBase(std::vector<double> & wireTensionVec){
593 std::string fullPath =
"/Calib/MdcAlign";
594 MsgStream log(messageService(), name());
595 log << MSG::INFO<<
"ReadTensionDataBase() wireTensionPath = "<<fullPath<< endreq;
596 cout <<
"Read wireTension from Calibration Database!" << endl;
598 SmartDataPtr<CalibData::MdcAlignData> tension(m_pCalibDataSvc, fullPath);
600 log << MSG::ERROR <<
"can not get MdcAlignConst via SmartPtr"
604 for(
int i=0;i<6796;i++){
605 double tens = tension->gettension(i);
606 wireTensionVec.push_back(tens);
609void MdcGeomSvc::ReadWirePosDataBase(std::vector<vector<double> > & wirePosVec){
610 std::string fullPath =
"/Calib/MdcAlign";
611 MsgStream log(messageService(), name());
612 log << MSG::INFO<<
"ReadWirePosDataBase() wirePositionPath = "<<fullPath<< endreq;
614 cout <<
"Read wirePosition from Calibration Database!" << endl;
615 SmartDataPtr<CalibData::MdcAlignData> wirepos(m_pCalibDataSvc, fullPath);
617 log << MSG::ERROR <<
"can not get MdcAlignConst via SmartPtr"
621 double dxe,dye,dze,dxw,dyw,dzw;
622 for(
int j=0; j<6796; j++){
624 dxe = wirepos->getdxWireEast(j);
625 dye = wirepos->getdyWireEast(j);
626 dze = wirepos->getdzWireEast(j);
627 dxw = wirepos->getdxWireWest(j);
628 dyw = wirepos->getdyWireWest(j);
629 dzw = wirepos->getdzWireWest(j);
631 wirePosVec[j].push_back(dxe);
632 wirePosVec[j].push_back(dye);
633 wirePosVec[j].push_back(dze);
634 wirePosVec[j].push_back(dxw);
635 wirePosVec[j].push_back(dyw);
636 wirePosVec[j].push_back(dzw);
640void MdcGeomSvc::ReadAliParDataBase(vector<double>& Sx, vector<double>& Sy, vector<double>& Sz,
641 vector<double>& Rx, vector<double>& Ry, vector<double>& Rz){
642 MsgStream log(messageService(), name());
643 std::string fullPath =
"/Calib/MdcAlign";
644 log << MSG::INFO<<
"ReadAliParDataBase() alignParPath = "<<fullPath<< endreq;
645 cout <<
"Read alignment parameters from Calibration Database!" << endl;
647 SmartDataPtr<CalibData::MdcAlignData> alignpar(m_pCalibDataSvc, fullPath);
649 log << MSG::ERROR <<
"can not get MdcAlignConst via SmartPtr"
653 double tmp1,tmp2,tmp3,tmp4,tmp5,tmp6;
654 for(
int k=0;k<16;k++){
655 tmp1 = alignpar->getdxEP(k);
656 tmp2 = alignpar->getdyEP(k);
657 tmp3 = alignpar->getdzEP(k);
658 tmp4 = alignpar->getrxEP(k);
659 tmp5 = alignpar->getryEP(k);
660 tmp6 = alignpar->getrzEP(k);
662 Sx.push_back(m_wholeShiftX+tmp1);
663 Sy.push_back(m_wholeShiftY+tmp2);
664 Sz.push_back(m_wholeShiftZ+tmp3);
665 Rx.push_back(m_wholeRotatX+tmp4);
666 Ry.push_back(m_wholeRotatY+tmp5);
667 Rz.push_back(m_wholeRotatZ+tmp6);
673 return fWires.size();
678 return fLayers.size();
683 return fSupers.size();
688 return fGenerals.size();
698const int MdcGeomSvc::getAlignParIndexEast(
int lyr)
const{
700 if((lyr>=0) && (lyr<=16))
return 0;
702 else if((lyr>=17) && (lyr<=20))
return 1;
704 else if((lyr>=21) && (lyr<=24))
return 2;
706 else if((lyr>=25) && (lyr<=28))
return 3;
708 else if((lyr>=29) && (lyr<=32))
return 4;
710 else if((lyr>=33) && (lyr<=36))
return 5;
712 else if((lyr>=37) && (lyr<=41))
return 6;
714 else if(lyr>=42)
return 7;
715 else std::cout<<
" Hi, ERROR OCCUR !!!"<<std::endl;
720const int MdcGeomSvc::getAlignParIndexWest(
int lyr)
const{
722 if((lyr>=0) && (lyr<=16))
return 8;
724 else if((lyr>=17) && (lyr<=20))
return 9;
726 else if((lyr>=21) && (lyr<=24))
return 10;
728 else if((lyr>=25) && (lyr<=28))
return 11;
730 else if((lyr>=29) && (lyr<=32))
return 12;
732 else if((lyr>=33) && (lyr<=36))
return 13;
734 else if((lyr>=37) && (lyr<=41))
return 14;
736 else if(lyr>=42)
return 15;
737 else std::cout<<
" Hi, ERROR OCCUR !!!"<<std::endl;
744 MsgStream log( messageService(), name() );
745 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
746 IDataProviderSvc* m_eventSvc;
747 Gaudi::svcLocator()->service(
"EventDataSvc", m_eventSvc,
true);
748 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,
"/Event/EventHeader");
750 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
752 if (m_updataalign)
return;
753 if (inc.type() ==
"NewRun" ){
754 log << MSG::DEBUG <<
"Begin Event" << endreq;
756 m_updataalign =
true;
758 int RunNo=eventHeader->runNumber();
762 cout<<
"m__RunNo="<<RunNo<<
"m_mindex="<<m_mindex<<endl;
771 if (
id < fWires.size())
779 if ((lyrid <fLayers.size()) && ((
int) wirid <
Layer(lyrid)->NCell()))
787 if (
id < fLayers.size())
795 if (
id < fSupers.size())
803 if (
id < fGenerals.size())
804 return & fGenerals[id];
816 if (
id < fEnd.size())
double sin(const BesAngle a)
double cos(const BesAngle a)
double Phi(RecMdcKalTrack *trk)
double abs(const EvtComplex &c)
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()
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
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)