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"
32 if(getenv(
"MDCGEOMSVCROOT")){
33 m_alignFilePath = std::string(getenv(
"MDCGEOMSVCROOT"))+std::string(
"/share/MdcAlignPar.dat");
36 m_wirePosFilePath = std::string(getenv(
"MDCGEOMSVCROOT"))+std::string(
"/share/WirePosCalib.dat");
39 m_wireTensionFilePath = std::string(getenv(
"MDCGEOMSVCROOT"))+std::string(
"/share/mdcWireTension.dat");
44 std::cout<<
"A fatal error, contact wangjk..."<<std::endl;
47 declareProperty(
"doSag", m_doSag =
true);
48 declareProperty(
"readAlignParDataBase", m_readAlignParDataBase =
true);
49 declareProperty(
"mcnoalignment",m_nomcalignment=
true);
50 declareProperty(
"wholeShiftX",m_wholeShiftX = 0.);
51 declareProperty(
"wholeShiftY",m_wholeShiftY = 0.);
52 declareProperty(
"wholeShiftZ",m_wholeShiftZ = 0.);
53 declareProperty(
"wholeRotatX",m_wholeRotatX = 0.);
54 declareProperty(
"wholeRotatY",m_wholeRotatY = 0.);
55 declareProperty(
"wholeRotatZ",m_wholeRotatZ = 0.);
56 declareProperty(
"alignFilePath",m_alignFilePath);
57 declareProperty(
"wirePosFilePath",m_wirePosFilePath);
58 declareProperty(
"wireTensionFilePath",m_wireTensionFilePath);
59 declareProperty(
"useCGEM",m_useCgem =
true);
60 declareProperty(
"NeighborRange",m_NeighborRange = 1.);
61 declareProperty(
"testAdjacentIntersection",m_conf_testAdjacentIntersection =
false);
68 if ( IID_IMdcGeomSvc.versionMatch(riid) ) {
71 return Service::queryInterface(riid, ppvInterface) ;
73 return StatusCode::SUCCESS;
77 MsgStream log(messageService(), name());
78 log << MSG::INFO << name() <<
": Start of run initialisation" << endreq;
80 StatusCode sc = Service::initialize();
81 if ( sc.isFailure() )
return sc;
83 m_updataalign =
false;
85 sc = service(
"IncidentSvc", incsvc);
88 incsvc -> addListener(
this,
"NewRun", priority);
94 sc = service(
"CalibDataSvc", m_pCalibDataSvc,
true);
96 if ( !sc.isSuccess() ) {
98 <<
"Could not get IDataProviderSvc interface of CalibXmlCnvSvc"
103 <<
"Retrieved IDataProviderSvc interface of CalibXmlCnvSvc"
108 return StatusCode::SUCCESS;
112 if (m_conf_testAdjacentIntersection)\
113 testAdjacentIntersection();
114 MsgStream log(messageService(), name());
115 log << MSG::INFO << name() <<
": End of Run" << endreq;
116 return StatusCode::SUCCESS;
120 for(vector<MdcGeoLayer*>::iterator it1 = fLayers.begin(); it1 != fLayers.end(); it1++)
delete *it1;
121 for(vector<MdcGeoSuper*>::iterator it2 = fSupers.begin(); it2 != fSupers.end(); it2++)
delete *it2;
122 for(vector<MdcGeoWire*>::iterator it3 = fWires.begin(); it3 != fWires.end(); it3++)
delete *it3;
123 for(vector<MdcGeoEnd*>::iterator it4 = fEnd.begin(); it4 != fEnd.end(); it4++)
delete *it4;
131void MdcGeomSvc::clean(){
132 for(vector<MdcGeoLayer*>::iterator it1 = fLayers.begin(); it1 != fLayers.end(); it1++)
delete *it1;
133 for(vector<MdcGeoSuper*>::iterator it2 = fSupers.begin(); it2 != fSupers.end(); it2++)
delete *it2;
134 for(vector<MdcGeoWire*>::iterator it3 = fWires.begin(); it3 != fWires.end(); it3++)
delete *it3;
135 for(vector<MdcGeoEnd*>::iterator it4 = fEnd.begin(); it4 != fEnd.end(); it4++)
delete *it4;
144void MdcGeomSvc::ReadFilePar(){
145 std::string geometryFilePath = getenv(
"MDCSIMROOT");
146 if(m_useCgem) geometryFilePath +=
"/dat/Mdc_cgem.txt";
147 else geometryFilePath +=
"/dat/Mdc.txt";
148 std::ifstream inFile(geometryFilePath.c_str() );
151 std::cout<<
"Error, mdc parameters file not exist"<<std::endl;
154 std::string alignFilePath;
155 std::string wirePosFilePath;
156 std::string wireTensionFilePath;
157 if (!m_updataalign) {
158 alignFilePath = std::string(getenv(
"MDCGEOMSVCROOT"))+std::string(
"/share/MdcAlignPar.dat");
159 wirePosFilePath = std::string(getenv(
"MDCGEOMSVCROOT"))+std::string(
"/share/WirePosCalib.dat");
160 wireTensionFilePath = std::string(getenv(
"MDCGEOMSVCROOT"))+std::string(
"/share/mdcWireTension.dat");
162 alignFilePath = m_alignFilePath;
163 wirePosFilePath = m_wirePosFilePath;
164 wireTensionFilePath = m_wireTensionFilePath;
166 std::ifstream alignFile(alignFilePath.c_str());
167 std::ifstream wirePosFile(wirePosFilePath.c_str());
168 std::ifstream wireTensionFile(wireTensionFilePath.c_str());
171 std::cout<<
"Error, mdc wire position file not exist..."<<std::endl;
174 if(!wireTensionFile){
175 std::cout<<
"Error, mdc wire tension file not exist..."<<std::endl;
178 std::vector<double> wireTensionVec;
182 ReadTensionDataBase(wireTensionVec);
184 cout <<
"Read wireTension from file:" << wireTensionFilePath.c_str() << endl;
187 for(
int ii=0; ii<6796; ii++){
188 wireTensionFile>>idd>>tension;
191 wireTensionVec.push_back(tension);
195 wireTensionVec.push_back(tension);
200 std::vector<vector<double> > wirePosVec(6796);
202 ReadWirePosDataBase(wirePosVec);
204 cout <<
"Read wirePosition from file:" << wirePosFilePath.c_str() << endl;
205 double dxe,dye,dze,dxw,dyw,dzw;
208 getline(wirePosFile, title);
209 wirePosFile.seekg(1,ios::cur);
210 for(
int j=0; j<6796; j++){
211 wirePosFile>>wid>>dxe>>dye>>dze>>dxw>>dyw>>dzw;
212 wirePosVec[j].push_back(dxe);
213 wirePosVec[j].push_back(dye);
214 wirePosVec[j].push_back(dze);
215 wirePosVec[j].push_back(dxw);
216 wirePosVec[j].push_back(dyw);
217 wirePosVec[j].push_back(dzw);
227 double signalWireR, fieldWireR;
228 int TLayerNo, TWireNo,TSignalLayerNo,fSignalLayer[50];
229 int i,
wireNo, firstWire,segmentNo,signalLayer;
230 double length, nomphi, phi, r,nomaadiv2, aadiv2,
231 nomaa, aa, nomrotateCell, rotateCell, wlength, innerR, outR, z;
232 std::string layer, name, line;
234 vector<int> WireNo, fSegmentNo;
235 vector<double> wLength,
R, nomPhi,
Phi,nomadiv2, adiv2,
First,
236 noma, a, nomebusing, ebusing, nomsigma, sigma, nomdeltaz, deltaz,
237 nomRotate, Rotate, fLength, fInnerR, fOutR, fZ;
238 vector<string> LayerName, fName;
239 vector<double> Sx,Sy,Sz,Rx,Ry,Rz;
240 double tmp1,tmp2,tmp3,tmp4,tmp5,tmp6;
245 ReadAliParDataBase(Sx, Sy, Sz, Rx, Ry, Rz);
247 cout <<
"Read alignment parameters from file:" << alignFilePath.c_str() << endl;
248 getline(alignFile, line);
249 alignFile.seekg(1,ios::cur);
250 for(
int k=0;k<16;k++){
251 alignFile>>line>>tmp1>>tmp2>>tmp3>>tmp4>>tmp5>>tmp6;
261 Sx.push_back(m_wholeShiftX+tmp1);
262 Sy.push_back(m_wholeShiftY+tmp2);
263 Sz.push_back(m_wholeShiftZ+tmp3);
264 Rx.push_back(m_wholeRotatX+tmp4);
265 Ry.push_back(m_wholeRotatY+tmp5);
266 Rz.push_back(m_wholeRotatZ+tmp6);
272 getline(inFile, line);
273 inFile>>TLayerNo>>TWireNo>>TSignalLayerNo>>signalWireR>>fieldWireR;
274 inFile.seekg(1,ios::cur);
275 getline(inFile, line);
276 for( i=0; i<TSignalLayerNo; i++){
279 fSignalLayer[i]=signalLayer-1;
282 inFile.seekg(1,ios::cur);
283 getline(inFile, line);
284 getline(inFile, line);
287 double delta_rotateCell;
289 for( i=0; i<TLayerNo; i++){
290 i_east=getAlignParIndexEast(i);
291 i_west=getAlignParIndexWest(i);
293 inFile>>layer>>
wireNo>>wlength>>r>>nomphi>>firstWire>>nomrotateCell;
294 getline(inFile, line);
298 nomaadiv2=2*
pi*nomrotateCell/
wireNo;
300 nomaa=2*r*
sin(nomaadiv2);
301 delta_rotateCell=(Rz[i_west]-Rz[i_east])*
wireNo/(4*
pi);
302 rotateCell=nomrotateCell+delta_rotateCell;
306 double shiftPhi=twopi/
wireNo;
308 if(nomphi<0) nomphi += shiftPhi;
309 phi=nomphi+Rz[i_east];
310 LayerName.push_back(layer);
312 wLength.push_back(wlength);
314 nomPhi.push_back(nomphi);
318 First.push_back(firstWire);
326 nomebusing.push_back(atan(nomaa/wlength));
327 ebusing.push_back(atan(aa/wlength));
333 nomRotate.push_back(nomrotateCell);
334 Rotate.push_back(rotateCell);
337 getline(inFile, line);
339 inFile.seekg(1,ios::cur);
340 getline(inFile, line);
341 getline(inFile, line);
343 for(i=0; i<segmentNo; i++){
344 inFile>>
length>>innerR>>outR>>z>>name;
345 getline(inFile,line);
346 fLength.push_back(
length);
347 fInnerR.push_back(innerR);
348 fOutR.push_back(outR);
350 fName.push_back(name);
362 double a1,a2,a3,nomphi0,phi0,cellphi;
363 double noma1,noma2,noma3;
364 for(i=0;i<TLayerNo;i++){
365 i_east=getAlignParIndexEast(i);
366 i_west=getAlignParIndexWest(i);
371 hlh.
NCell(WireNo[i]/2);
378 hlh.
First((
int)First[i]);
379 HepPoint3D offF(Sx[i_west],Sy[i_west],Sz[i_west]);
380 HepPoint3D offB(Sx[i_east],Sy[i_east],Sz[i_east]);
387 hlh.
Shift(Rotate[i]);
402 fGenerals.push_back(hlh);
406 for(i=0;i<TSignalLayerNo;i++){
410 int lyr=fSignalLayer[i];
413 i_east=getAlignParIndexEast(lyr);
414 i_west=getAlignParIndexWest(lyr);
426 case 0: suph->
Type(-1);
break;
427 case 1: suph->
Type( 1);
break;
428 case 2: suph->
Type( 0);
break;
429 case 3: suph->
Type( 0);
break;
430 case 4: suph->
Type( 0);
break;
431 case 5: suph->
Type(-1);
break;
432 case 6: suph->
Type( 1);
break;
433 case 7: suph->
Type(-1);
break;
434 case 8: suph->
Type( 1);
break;
435 case 9: suph->
Type( 0);
break;
436 case 10: suph->
Type(0);
break;
440 fSupers.push_back(suph);
443 cellphi=2*twopi/WireNo[lyr];
445 phi0=
Phi[lyr]+
abs(First[lyr]-1)*(cellphi/2);
446 nomphi0=nomPhi[lyr]+
abs(First[lyr]-1)*(cellphi/2);
449 for(
int wk=0; wk<i; wk++){
450 int lyrwk=fSignalLayer[wk];
451 wircount=wircount + WireNo[lyrwk]/2;
456 lh->
Slant(ebusing[lyr]);
460 lh->
RCSiz1(R[lyr]-R[lyr-1]);
461 lh->
RCSiz2(R[lyr+1]-R[lyr]);
462 lh->
PCSiz(R[lyr]*cellphi);
463 lh->
NCell(WireNo[lyr]/2);
465 lh->
Shift(Rotate[lyr]);
469 vector<MdcGeoSuper*>::iterator it1 = fSupers.end()-1;
471 fLayers.push_back(lh);
484 for(
int j=0;j<WireNo[lyr]/2;j++){
487 const int wireId = wircount+j;
491 a1 =
R[lyr]*
cos(phi0+j*cellphi)+Sx[i_east]+wirePosVec[wireId][0];
492 a2 =
R[lyr]*
sin(phi0+j*cellphi)+Sy[i_east]+wirePosVec[wireId][1];
493 a3 = wLength[lyr]/2+wirePosVec[wireId][2]+Sz[i_east];
497 double yb = a2 *
cos(Rx[i_east]) + a3 *
sin(Rx[i_east]);
498 double zb = a3 *
cos(Rx[i_east]) - a2 *
sin(Rx[i_east]);
501 double xbnew = xb *
cos(Ry[i_east]) - zb *
sin(Ry[i_east]);
503 double zbnew = xb *
sin(Ry[i_east]) + zb *
cos(Ry[i_east]);
505 noma1 =
R[lyr]*
cos(nomphi0+j*cellphi);
506 noma2 =
R[lyr]*
sin(nomphi0+j*cellphi);
508 noma3 = wLength[lyr]/2;
512 HepPoint3D wireposb(wirePosVec[wireId][0],wirePosVec[wireId][1],wirePosVec[wireId][2]);
522 a1 =
R[lyr]*
cos(phi0+(j+lh->
Shift())*cellphi)+Sx[i_west]+wirePosVec[wireId][3];
523 a2 =
R[lyr]*
sin(phi0+(j+lh->
Shift())*cellphi)+Sy[i_west]+wirePosVec[wireId][4];
525 a3 = -wLength[lyr]/2+wirePosVec[wireId][5]+Sz[i_west];
528 double yf = a2 *
cos(Rx[i_west]) + a3 *
sin(Rx[i_west]);
529 double zf = a3 *
cos(Rx[i_west]) - a2 *
sin(Rx[i_west]);
532 double xfnew = xf *
cos(Ry[i_west]) - zf *
sin(Ry[i_west]);
534 double zfnew = xf *
sin(Ry[i_west]) + zf *
cos(Ry[i_west]);
538 noma3 = -wLength[lyr]/2;
542 HepPoint3D wireposf(wirePosVec[wireId][3],wirePosVec[wireId][4],wirePosVec[wireId][5]);
556 wh->
Slant(ebusing[lyr]);
560 wh->
Tension(wireTensionVec[wireId]);
567 vector<MdcGeoLayer*>::iterator it2 = fLayers.end()-1;
569 fWires.push_back(wh);
575 fMisc.
OuterTk(fOutR[1]-fInnerR[1]);
576 fMisc.
InnerTk(fOutR[2]-fInnerR[2]);
577 fMisc.
NSWire(fWires.size());
578 fMisc.
NFWire(TWireNo-fWires.size());
583 fMisc.
SWireR(signalWireR);
586 for(i=0;i<segmentNo;i++){
598void MdcGeomSvc::ReadTensionDataBase(std::vector<double> & wireTensionVec){
599 std::string fullPath =
"/Calib/MdcAlign";
600 MsgStream log(messageService(), name());
601 log << MSG::INFO<<
"ReadTensionDataBase() wireTensionPath = "<<fullPath<< endreq;
602 cout <<
"Read wireTension from Calibration Database!" << endl;
604 SmartDataPtr<CalibData::MdcAlignData> tension(m_pCalibDataSvc, fullPath);
606 log << MSG::ERROR <<
"can not get MdcAlignConst via SmartPtr"
610 for(
int i=0;i<6796;i++){
611 double tens = tension->gettension(i);
612 wireTensionVec.push_back(tens);
615void MdcGeomSvc::ReadWirePosDataBase(std::vector<vector<double> > & wirePosVec){
616 std::string fullPath =
"/Calib/MdcAlign";
617 MsgStream log(messageService(), name());
618 log << MSG::INFO<<
"ReadWirePosDataBase() wirePositionPath = "<<fullPath<< endreq;
620 cout <<
"Read wirePosition from Calibration Database!" << endl;
621 SmartDataPtr<CalibData::MdcAlignData> wirepos(m_pCalibDataSvc, fullPath);
623 log << MSG::ERROR <<
"can not get MdcAlignConst via SmartPtr"
627 double dxe,dye,dze,dxw,dyw,dzw;
628 for(
int j=0; j<6796; j++){
630 dxe = wirepos->getdxWireEast(j);
631 dye = wirepos->getdyWireEast(j);
632 dze = wirepos->getdzWireEast(j);
633 dxw = wirepos->getdxWireWest(j);
634 dyw = wirepos->getdyWireWest(j);
635 dzw = wirepos->getdzWireWest(j);
637 wirePosVec[j].push_back(dxe);
638 wirePosVec[j].push_back(dye);
639 wirePosVec[j].push_back(dze);
640 wirePosVec[j].push_back(dxw);
641 wirePosVec[j].push_back(dyw);
642 wirePosVec[j].push_back(dzw);
646void MdcGeomSvc::ReadAliParDataBase(vector<double>& Sx, vector<double>& Sy, vector<double>& Sz,
647 vector<double>& Rx, vector<double>& Ry, vector<double>& Rz){
648 MsgStream log(messageService(), name());
649 std::string fullPath =
"/Calib/MdcAlign";
650 log << MSG::INFO<<
"ReadAliParDataBase() alignParPath = "<<fullPath<< endreq;
651 cout <<
"Read alignment parameters from Calibration Database!" << endl;
653 SmartDataPtr<CalibData::MdcAlignData> alignpar(m_pCalibDataSvc, fullPath);
655 log << MSG::ERROR <<
"can not get MdcAlignConst via SmartPtr"
659 double tmp1,tmp2,tmp3,tmp4,tmp5,tmp6;
660 for(
int k=0;k<16;k++){
661 tmp1 = alignpar->getdxEP(k);
662 tmp2 = alignpar->getdyEP(k);
663 tmp3 = alignpar->getdzEP(k);
664 tmp4 = alignpar->getrxEP(k);
665 tmp5 = alignpar->getryEP(k);
666 tmp6 = alignpar->getrzEP(k);
668 Sx.push_back(m_wholeShiftX+tmp1);
669 Sy.push_back(m_wholeShiftY+tmp2);
670 Sz.push_back(m_wholeShiftZ+tmp3);
671 Rx.push_back(m_wholeRotatX+tmp4);
672 Ry.push_back(m_wholeRotatY+tmp5);
673 Rz.push_back(m_wholeRotatZ+tmp6);
679 return fWires.size();
684 return fLayers.size();
689 return fSupers.size();
694 return fGenerals.size();
704const int MdcGeomSvc::getAlignParIndexEast(
int lyr)
const{
706 if((lyr>=0) && (lyr<=16))
return 0;
708 else if((lyr>=17) && (lyr<=20))
return 1;
710 else if((lyr>=21) && (lyr<=24))
return 2;
712 else if((lyr>=25) && (lyr<=28))
return 3;
714 else if((lyr>=29) && (lyr<=32))
return 4;
716 else if((lyr>=33) && (lyr<=36))
return 5;
718 else if((lyr>=37) && (lyr<=41))
return 6;
720 else if(lyr>=42)
return 7;
721 else std::cout<<
" Hi, ERROR OCCUR !!!"<<std::endl;
726const int MdcGeomSvc::getAlignParIndexWest(
int lyr)
const{
728 if((lyr>=0) && (lyr<=16))
return 8;
730 else if((lyr>=17) && (lyr<=20))
return 9;
732 else if((lyr>=21) && (lyr<=24))
return 10;
734 else if((lyr>=25) && (lyr<=28))
return 11;
736 else if((lyr>=29) && (lyr<=32))
return 12;
738 else if((lyr>=33) && (lyr<=36))
return 13;
740 else if((lyr>=37) && (lyr<=41))
return 14;
742 else if(lyr>=42)
return 15;
743 else std::cout<<
" Hi, ERROR OCCUR !!!"<<std::endl;
750 MsgStream log( messageService(), name() );
751 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
752 IDataProviderSvc* m_eventSvc;
753 Gaudi::svcLocator()->service(
"EventDataSvc", m_eventSvc,
true);
754 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,
"/Event/EventHeader");
756 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
758 if (m_updataalign)
return;
759 if (inc.type() ==
"NewRun" ){
760 log << MSG::DEBUG <<
"Begin Event" << endreq;
762 m_updataalign =
true;
764 int RunNo=eventHeader->runNumber();
768 cout<<
"m__RunNo="<<RunNo<<
"m_mindex="<<m_mindex<<endl;
778 if (
id < fWires.size())
786 if ((lyrid <fLayers.size()) && ((
int) wirid <
Layer(lyrid)->NCell()))
794 if (
id < fLayers.size())
802 if (
id < fSupers.size())
810 if (
id < fGenerals.size())
811 return & fGenerals[id];
823 if (
id < fEnd.size())
835void MdcGeomSvc::AddWireNeighbors(){
836 std::vector<double> BackwardPhi;
837 std::vector<double> ForwardPhi;
838 std::vector<double> Center_r;
839 std::vector<double> Cho;
842 for(
unsigned k = 0;k<fWires.size();k++) {
843 WireK = fWires.at(k);
844 if(layerID!=WireK->
Layer()){
847 layerID=WireK->
Layer();
865 BackwardPhi.push_back(
phi1);
866 ForwardPhi.push_back(
phi2);
869 for(
unsigned k = 0;k<fWires.size();k++) {
873 double phiBmax,phiBmin,phiFmax,phiFmin;
875 double Bphi,Fphi,BphiN,FphiN;
877 Bphi = BackwardPhi.at(k);
878 Fphi = ForwardPhi.at(k);
879 WireK = fWires.at(k);
880 if(k==0||fWires.at(k-1)->Layer()!=WireK->
Layer()){
883 WireK->MdcGeoWire::AddWireNeighbor(fWires.at(wireID),wireID,neiborType);
886 WireK->MdcGeoWire::AddWireNeighbor(fWires.at(wireID),wireID,neiborType);
888 else if(k==6795||fWires.at(k+1)->Layer()!=WireK->
Layer()){
891 WireK->MdcGeoWire::AddWireNeighbor(fWires.at(wireID),wireID,neiborType);
894 WireK->MdcGeoWire::AddWireNeighbor(fWires.at(wireID),wireID,neiborType);
899 WireK->MdcGeoWire::AddWireNeighbor(fWires.at(wireID),wireID,neiborType);
902 WireK->MdcGeoWire::AddWireNeighbor(fWires.at(wireID),wireID,neiborType);
904 for(
int n=k-1;
n>=0&&(WireK->
Layer()-fWires.at(
n)->Layer())<2;
n--){
906 WireN = fWires.at(
n);
907 BphiN = BackwardPhi.at(
n);
908 FphiN = ForwardPhi.at(
n);
910 layer1 = WireK->
Layer();
912 nPhi = atan(Cho.at(layer1)/Center_r.at(layer1))-atan((WireN->
Forward().z()/WireK->
Forward().z())*Cho.at(layer1)/Center_r.at(layer1));
913 if((Bphi>Fphi&&(Bphi-Fphi)<
M_PI)||(Fphi-Bphi)>
M_PI){
914 phiBmax = CalculatePhi(Bphi+dPhi-
nPhi);
915 phiBmin = CalculatePhi(Bphi-dPhi-
nPhi);
916 phiFmax = CalculatePhi(Fphi+dPhi+
nPhi);
917 phiFmin = CalculatePhi(Fphi-dPhi+
nPhi);
920 phiBmax = CalculatePhi(Bphi+dPhi+
nPhi);
921 phiBmin = CalculatePhi(Bphi-dPhi+
nPhi);
922 phiFmax = CalculatePhi(Fphi+dPhi-
nPhi);
923 phiFmin = CalculatePhi(Fphi-dPhi-
nPhi);
927 if(((BphiN>phiBmin&&BphiN<phiBmin+
M_PI/2.)||BphiN<phiBmin-3*
M_PI/2.)&&((FphiN<phiFmax&&FphiN>phiFmax-
M_PI/2.)||FphiN>phiFmax+3*
M_PI/2.)){
928 WireK->MdcGeoWire::AddWireNeighbor(WireN,wireID,neiborType);
931 if(((FphiN>phiFmin&&FphiN<phiFmin+
M_PI/2.)||FphiN<phiFmin-3*
M_PI/2.)&&((BphiN<phiBmax&&BphiN>phiBmax-
M_PI/2.)||BphiN>phiBmax+3*
M_PI/2.)){
932 if(flag==0) WireK->MdcGeoWire::AddWireNeighbor(WireN,wireID,neiborType);
936 for(
int n=k+1;
n<6796&&(fWires.at(
n)->
Layer()-WireK->
Layer())<2;
n++){
938 WireN = fWires.at(
n);
939 BphiN = BackwardPhi.at(
n);
940 FphiN = ForwardPhi.at(
n);
942 layer1 = WireN->
Layer();
944 nPhi = atan(Cho.at(layer1)/Center_r.at(layer1))-atan((WireK->
Forward().z()/WireN->
Forward().z())*Cho.at(layer1)/Center_r.at(layer1));
945 if((BphiN>FphiN&&(BphiN-FphiN)<
M_PI)||(FphiN-BphiN)>
M_PI){
946 phiBmax = CalculatePhi(BphiN+dPhi-
nPhi);
947 phiBmin = CalculatePhi(BphiN-dPhi-
nPhi);
948 phiFmax = CalculatePhi(FphiN+dPhi+
nPhi);
949 phiFmin = CalculatePhi(FphiN-dPhi+
nPhi);
952 phiBmax = CalculatePhi(BphiN+dPhi+
nPhi);
953 phiBmin = CalculatePhi(BphiN-dPhi+
nPhi);
954 phiFmax = CalculatePhi(FphiN+dPhi-
nPhi);
955 phiFmin = CalculatePhi(FphiN-dPhi-
nPhi);
959 if(((Bphi>phiBmin&&Bphi<phiBmin+
M_PI/2.)||Bphi<phiBmin-3*
M_PI/2.)&&((Fphi<phiFmax&&Fphi>phiFmax-
M_PI/2.)||Fphi>phiFmax+3*
M_PI/2.)){
960 WireK->MdcGeoWire::AddWireNeighbor(WireN,wireID,neiborType);
963 if(((Fphi>phiFmin&&Fphi<phiFmin+
M_PI/2.)||Fphi<phiFmin-3*
M_PI/2.)&&((Bphi<phiBmax&&Bphi>phiBmax-
M_PI/2.)||Bphi>phiBmax+3*
M_PI/2.)){
964 if(flag==0) WireK->MdcGeoWire::AddWireNeighbor(WireN,wireID,neiborType);
972void MdcGeomSvc::RenewWireNeighbors(
double range){
973 m_NeighborRange = range;
974 for(
unsigned k = 0;k<fWires.size();k++) {
975 fWires.at(k)->ClearNeighbors();
977 MdcGeomSvc::AddWireNeighbors();
980 const double MdcGeomSvc::CalculatePhi(
double phi)
const{
981 if(0<phi&&phi<2*
M_PI){
1006 B1 += dB *(A1.z()-B1.z());
1010 double deltaZ=-deltaDir.dot(deltaPoint)/deltaDir.mag2();
1011 return A1 + deltaZ* dA;
1018 return A1 + dA*( (targetZ - A1.z()) / dA.z() );
1021static double interpolate(
double A1,
double Za1,
double A2,
double Za2,
double targetZ){
1025 return A1 + dA*( (targetZ - Za1) / dz );
1029static double squared(
double x){
return x*
x;}
1046 vector<HepPoint3D> ret;
1055 double maxZAllowed=(
1059 double minZAllowed=(
1066 directionR.setMag(1);
1074 double typicalWidthA=(wireAl->
Forward() - wireA->
Forward()).mag();
1075 double typicalWidthB=(wireB1->
Forward() - wireB->
Forward()).mag();
1084 double widthAtSurfaceA=typicalWidthA;
1085 double widthAtSurfaceB=typicalWidthB;
1091 double surfaceA=directionR.dot((A1+A2)/2);
1092 double surfaceB=directionR.dot((B1+B2)/2);
1094 double surfaceDiff=(surfaceB-surfaceA);
1104 direction1m.setZ(0);
1107 direction2m.setZ(0);
1108 if (direction2m.mag2() > direction1m.mag()) direction1m = direction2m;
1110 direction1m.setMag(1);
1113 HepPoint3D directionA=(A2-A1);directionA/=directionA.z();
1114 HepPoint3D directionB=(B2-B1);directionB/=directionB.z();
1115 HepPoint3D deltaA=direction1m*(widthAtSurfaceA/2);
1116 HepPoint3D deltaB=direction1m*(widthAtSurfaceB/2);
1118 if ((directionA-directionB).mag2()<= 0.01*0.01){
1120 if (direction1m.mag2()>squared(widthAtSurfaceA+widthAtSurfaceB)/4) {
1125 ret.push_back(B1m-deltaB);
1126 ret.push_back(A1m+deltaA);
1127 ret.push_back(A2m+deltaA);
1128 ret.push_back(B2m-deltaB);
1133 HepPoint3D Ptop=getIntersection(A1m+deltaA,directionA,B1m-deltaB,directionB);
1134 HepPoint3D Prht=getIntersection(A1m+deltaA,directionA,B1m+deltaB,directionB);
1135 HepPoint3D Plft=getIntersection(A1m-deltaA,directionA,B1m-deltaB,directionB);
1136 HepPoint3D Pbot=getIntersection(A1m-deltaA,directionA,B1m+deltaB,directionB);
1138 if (Ptop.z() < Pbot.z()) std::swap(Ptop,Pbot);
1140 HepPoint3D Pmtp=Prht.z()>Plft.z()? Prht: Plft;
1141 HepPoint3D Pmbt=Prht.z()>Plft.z()? Plft: Prht;
1144 int PointsAtMaxZCount=0;
1146 int PointsAtMinZCount=0;
1148 int PointsLeftGoodCount=1;
1150 int PointsRightGoodCount=1;
1153 if (Ptop.z()<=maxZAllowed){
1154 PointsAtMaxZ[0]=Ptop;
1155 PointsAtMaxZCount=1;
1156 }
else if (Ptop.z()>maxZAllowed && maxZAllowed>=Pmtp.z() ){
1157 PointsAtMaxZ[0]=interpolate(Ptop,Plft,maxZAllowed);
1158 PointsAtMaxZ[1]=interpolate(Ptop,Prht,maxZAllowed);
1159 PointsAtMaxZCount=2;
1160 }
else if (Pmtp.z()>maxZAllowed && maxZAllowed>= Pmbt.z() ){
1161 PointsAtMaxZ[0]=interpolate(Ptop,Pmbt,maxZAllowed);
1162 PointsAtMaxZ[1]=interpolate(Pmtp,Pbot,maxZAllowed);
1163 PointsAtMaxZCount=2;
1165 std::swap(PointsAtMaxZ[0],PointsAtMaxZ[1]);
1166 PointsLeftGoodCount=0;
1168 PointsRightGoodCount=0;
1172 }
else if (Pmbt.z()>maxZAllowed && maxZAllowed>= Pbot.z() ){
1173 PointsAtMaxZ[0]=interpolate(Pbot,Plft,maxZAllowed);
1174 PointsAtMaxZ[1]=interpolate(Pbot,Prht,maxZAllowed);
1175 PointsAtMaxZCount=2;
1176 PointsLeftGoodCount=PointsRightGoodCount=0;
1181 if ( minZAllowed <=Pbot.z() ){
1182 PointsAtMinZ[0]=Pbot;
1183 PointsAtMinZCount=1;
1184 }
else if (Pbot.z() < minZAllowed && minZAllowed <=Pmbt.z()){
1185 PointsAtMinZ[0]=interpolate(Pbot,Plft,minZAllowed);
1186 PointsAtMinZ[1]=interpolate(Pbot,Prht,minZAllowed);
1187 PointsAtMinZCount=2;
1188 }
else if (Pmbt.z() < minZAllowed && minZAllowed <=Pmtp.z()){
1189 PointsAtMinZ[0]=interpolate(Ptop,Pmbt,minZAllowed);
1190 PointsAtMinZ[1]=interpolate(Pmtp,Pbot,minZAllowed);
1191 PointsAtMinZCount=2;
1193 std::swap(PointsAtMaxZ[0],PointsAtMaxZ[1]);
1194 PointsRightGoodCount=0;
1196 PointsLeftGoodCount=0;
1198 }
else if (Pmtp.z() < minZAllowed && minZAllowed <=Ptop.z()){
1199 PointsAtMinZ[0]=interpolate(Ptop,Plft,minZAllowed);
1200 PointsAtMinZ[1]=interpolate(Ptop,Prht,minZAllowed);
1201 PointsAtMinZCount=2;
1202 PointsRightGoodCount=PointsLeftGoodCount=0;
1208 for (
int i=0;i<PointsAtMaxZCount;i++){
1209 ret.push_back(PointsAtMaxZ[i]);
1211 for (
int i=0;i<PointsRightGoodCount;i++){
1212 ret.push_back(PointsRightGood[i]);
1214 for (
int i=PointsAtMinZCount-1;i>=0;i--){
1215 ret.push_back(PointsAtMinZ[i]);
1217 for (
int i=0;i<PointsLeftGoodCount;i++){
1218 ret.push_back(PointsLeftGood[i]);
1231static bool circularPhiExtend(
double&
phi1,
double&
phi2){
1235 if (phiU-phiL<
M_PI){
1254 double phiA1=A1.getPhi();
1255 double phiA2=A2.getPhi();
1256 double phiB1=B1.getPhi();
1257 double phiB2=B2.getPhi();
1258 circularPhiExtend(phiA1, phiA2);
1259 circularPhiExtend(phiB1, phiB2);
1260 double dPhiA=phiA2-phiA1;
1261 double dZA=A2.z()-A1.z();
1262 double phiAatB1=phiA1+(B1.z()-A1.z())/dZA*dPhiA;
1263 double dPhiB=phiB2-phiB1;
1264 double dZB=B2.z()-B1.z();
1267 double z=B1.z()+(phiAatB1-phiB1)/(dPhiB/dZB-dPhiA/dZA);
1278 if (bounds.empty())
return ret;
1279 double z=(bounds[2]+bounds[3])/2;
1301 if (vertexs.size()==0)
return ret;
1314 double phiL,phiU, zL,zU;
1317 for (
size_t i=0;i<vertexs.size()-1;i++){
1347 phiL=vertex.getPhi();
1348 phiU=vertex.getPhi();
1353 zL=std::min(zL,vertex.z());
1354 zU=std::max(zU,vertex.z());
1355 phiL=std::min(phiL,vertex.getPhi());
1356 phiU=std::max(phiU,vertex.getPhi());
1361 if (phiU >=
M_PI *1.5 && phiL <=
M_PI *.5) {
1363 double phi2=vertex.getPhi();
1366 for (
size_t i=1;i<vertexs.size();i++){
1368 double phi2=vertex.getPhi();
1370 phiL=std::min(phiL,
phi2);
1371 phiU=std::max(phiU,
phi2);
1375 ret.push_back(phiL);
1376 ret.push_back(phiU);
1385 clock_t time0=clock();
1386 ofstream fileout(
"testAdjacentIntersection.csv");
1387 MsgStream log(messageService(), name());
1388 log << MSG::WARNING<<__PRETTY_FUNCTION__<<endreq;
1389 const char * comma=
", ";
1390 const char * endll=
"\n";
1391 fileout <<
"# A_layer" << comma
1392 <<
"A_wireID" << comma
1393 <<
"A_WirePhi(0)" << comma
1396 <<
"A_Forward_phi" << comma
1397 <<
"A_Backward_phi" << comma
1398 <<
"B_layer" << comma
1399 <<
"B_wireID" << comma
1400 <<
"B_WirePhi(0)" << comma
1401 <<
"B_Forward_phi" << comma
1402 <<
"B_Backward_phi" << comma
1404 <<
"phiL,phiU, zL,zU" << comma
1406 <<
"wireA.x0, wireA.y0"<<comma
1407 <<
"wireB.x0, wireB.y0"<<comma
1409 <<
"line.a,line.b,line.c,line.x0, line.y0, line.z0, line.Angle2d, line.angle3d, line.cosAngleR"<< comma
1410 <<
"line.a,line.b,line.c,line.x0, line.y0, line.z0, line.Angle2d, line.angle3d, line.cosAngleR"<< comma
1411 <<
"line.a,line.b,line.c,line.x0, line.y0, line.z0, line.Angle2d, line.angle3d, line.cosAngleR"<< comma
1412 <<
"line.a,line.b,line.c,line.x0, line.y0, line.z0, line.Angle2d, line.angle3d, line.cosAngleR"<< comma
1414 <<
"xa1,ya1,za1" << comma
1415 <<
"xa2,ya2,za2" << comma
1416 <<
"xb1,yb1,zb1" << comma
1417 <<
"xb2,yb2,zb2" << comma
1418 <<
"x1,y1,z1" << comma
1419 <<
"x2,y2,z2" << comma
1420 <<
"x3,y3,z3" << comma
1421 <<
"x4,y4,z4" << endll;
1423 fileout <<
"# xn yn zn are coordinates of vertex" << endll;
1424 fileout <<
"# layer: ";
1425 for (
unsigned i=0;i<43;++i){
1428 fileout <<
"# layerRadius: ";
1429 for (
unsigned i=0;i<43;++i){
1433 fileout <<
"# distToNextLayerRadius: ";
1434 for (
unsigned i=0;i<42;++i){
1439 for (
size_t _wire_index=0;_wire_index<fWires.size();++_wire_index){
1443 for (
size_t _neighbor_index=0;_neighbor_index<cross_neighbors.size();_neighbor_index++){
1444 const MdcGeoWire * neighbor=cross_neighbors[_neighbor_index];
1449 fileout << wire->
Layer() << comma
1450 << wire->
Id() << comma
1454 << wire->
Forward().getPhi() << comma
1455 << wire->
Backward().getPhi() << comma
1457 << neighbor->
Layer() << comma
1458 << neighbor->
Id() << comma
1459 << neighbor->
WirePhi(0) << comma
1460 << neighbor->
Forward().getPhi() << comma
1461 << neighbor->
Backward().getPhi() << comma;
1465 if (bound.empty()) {
1466 for (
size_t i = 0; i < 4; ++i) fileout << 0. << comma;
1468 for (
size_t i = 0; i < bound.size(); i++){
1469 fileout << bound.at(i) << comma;
1475 if (!psblines.empty())Z0=psblines[0].z0;
1478 << wire ->
GetX(Z0)<<comma
1479 << wire ->
GetY(Z0)<<comma
1480 << neighbor->
GetX(Z0) << comma
1481 << neighbor->
GetY(Z0) << comma;
1484 for (
size_t i = 0; i < psblines.size(); ++i)
1486 <<psblines[i].a << comma
1487 <<psblines[i].b << comma
1488 <<psblines[i].c << comma
1489 <<psblines[i].x0 << comma
1490 <<psblines[i].y0 << comma
1491 <<psblines[i].z0 << comma
1492 <<psblines[i].angle2D << comma
1493 <<psblines[i].angle3D << comma
1494 <<psblines[i].angleWithR() << comma;
1495 for (
size_t i = psblines.size(); i < 4; ++i)
1496 for (
size_t ii = 0; ii < 9; ii++)
1497 fileout<<
'0'<<comma;
1503 fileout << vertex.x() << comma << vertex.y() << comma << vertex.z() <<comma;
1505 fileout << vertex.x() << comma << vertex.y() << comma << vertex.z() <<comma;
1507 fileout << vertex.x() << comma << vertex.y() << comma << vertex.z() <<comma;
1509 fileout << vertex.x() << comma << vertex.y() << comma << vertex.z();
1513 for (
size_t i = 0; i < shape.size(); i++){
1515 fileout <<comma<< vertex.x() << comma << vertex.y() << comma << vertex.z();
1523 clock_t time1=clock();
1524 cout<<
"test_Adj_Complete, time="<<(time1-time0)*1000./CLOCKS_PER_SEC<<
"ms"<<endl;
1540 void tangents (CLHEP::Hep2Vector c,
double r1,
double r2, vector<MdcGeomSvc::AdjCandiTgtLine2D> & ans) {
1542 double z = squared(c.x()) + squared(c.y());
1543 double d = z - squared(r);
1544 if (d < -
EPS)
return;
1547 l.
a = (c.x() * r + c.y() * d) / z;
1548 l.
b = (c.y() * r - c.x() * d) / z;
1562 vector<MdcGeomSvc::AdjCandiTgtLine2D>
tangents (CLHEP::Hep2Vector a, CLHEP::Hep2Vector b,
double ra,
double rb) {
1563 vector<MdcGeomSvc::AdjCandiTgtLine2D> ans;
1564 for (
int i=-1; i<=1; i+=2)
1565 for (
int j=-1; j<=1; j+=2)
1567 for (
size_t i=0; i<ans.size(); ++i)
1568 ans[i].c -= ans[i].a * a.x() + ans[i].b * a.y();
1598 HepPoint3D directionABSurface=directionA.cross(directionB);
1599 if (directionABSurface.dot(A1)<0)
1600 directionABSurface=-directionABSurface;
1601 HepPoint3D directionABSurface2D=directionABSurface;
1602 directionABSurface2D.setZ(0);
1614 CLHEP::Hep2Vector pA(wireA->
GetX(expectedZ),wireA->
GetY(expectedZ));
1615 CLHEP::Hep2Vector pB(wireB->
GetX(expectedZ),wireB->
GetY(expectedZ));
1617 CLHEP::Hep2Vector pMid=(pA+pB)/2;
1623 for (
size_t i=0; i<ret.size(); i++) {
1639 double x=(b*b*x0 - a*b*y0 - a*c);
1640 double y=(-a*b*x0 + a*a*y0 - b*c);
1644 ret[i].z0=expectedZ;
1647 directionLine = -directionLine;
1648 HepPoint3D directionLineRotate90(-directionLine.y(),directionLine.x(),0);
1657 ret[i].angle2D=directionLineRotate90.angle(directionABSurface);
1658 ret[i].angle3D=directionLineRotate90.angle(directionABSurface2D);
1691 if (bound.size()==4)expectedZ=(bound[3]+bound[2])/2;
1693 vector<MdcGeomSvc::AdjCandiTgtLine2D> ret;
double sin(const BesAngle a)
double cos(const BesAngle a)
double Phi(RecMdcKalTrack *trk)
double abs(const EvtComplex &c)
HepGeom::Point3D< double > HepPoint3D
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
double GetX(const double z) const
double GetY(const double z) const
HepPoint3D BWirePos(void) const
vector< MdcGeoWire * > GetNeighborType4(void) const
double WirePhi(double z) const
MdcGeoLayer * Lyr(void) const
HepPoint3D nomForward(void) const
HepPoint3D Forward(void) const
int GetNeighborIDType1(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)
vector< AdjCandiTgtLine2D > getAdjacentCandidateWithDriftCircle(const MdcGeoWire *wireA, const MdcGeoWire *wireB, double driftA, double driftB)
give the lines that is tangent to both drift circles at the approximate z that the wires cross....
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)
HepPoint3D getAdjacentIntersectionPointFast(const MdcGeoWire *wireA, const MdcGeoWire *wireB)
find the z where points on wireA, wireB has same phi. point is given as avg(A(z),B(z))
void handle(const Incident &inc)
this handle function is prepared for special use
HepPoint3D getAdjacentIntersectionPointSlower(const MdcGeoWire *wireA, const MdcGeoWire *wireB)
const int getSuperLayerSize()
vector< double > getAdjacentIntersectionBounds(const MdcGeoWire *wireA, const MdcGeoWire *wireB)
get bounding box in \varphi and z of touching shape of 2 adjacent layer wires.
virtual StatusCode finalize()
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
const MdcGeoEnd *const End(unsigned id)
const MdcGeoLayer *const Layer(unsigned id)
vector< HepPoint3D > getAdjacentIntersectionShape(const MdcGeoWire *wireA, const MdcGeoWire *wireB)
get touching shape of 2 adjacent layer wires. return vertexs of intersection shape if the wires' se...
const int getGeneralLayerSize()
void testAdjacentIntersection()
const MdcGeoMisc *const Misc(void)
static bool m_nomcalignment
void tangents(CLHEP::Hep2Vector c, double r1, double r2, vector< MdcGeomSvc::AdjCandiTgtLine2D > &ans)
find tangent. should have returned optional<line>, but ok..
complex_t R(double Q2, double M2, double G, double Mp2, double Mm2)
forms a line in x-y space, ax + by + c = 0
static const double INFTY