12 #include "GaudiKernel/EventContext.h"
13 #include "GaudiKernel/SystemOfUnits.h"
23 inline double takenearest(
const double of,
const double to) {
30 safeAtan2(
const double y,
const double x)
35 return std::atan2(
y,
x);
50 safeAcos(
const double x)
64 oppositeangle(
const double angle)
69 square(
const double tosquare)
79 setphipoca(
const double phi)
84 goFromPhipocaToPhi(
const double phipoca)
86 return phipoca +
M_PI / 2.;
90 getRadiusOfCurvature(
const Trk::Perigee& myPerigee,
const double Bzfield)
97 const double RadiusOfCurvature,
101 myPerigee.parameters()[
Trk::d0] *
cos(phipoca) -
102 RadiusOfCurvature *
cos(phipoca),
104 myPerigee.parameters()[
Trk::d0] *
sin(phipoca) -
105 RadiusOfCurvature *
sin(phipoca),
107 myPerigee.parameters()[
Trk::z0] +
145 m_solveAmbiguityUsingZ(true)
148 declareInterface<Trk2dDistanceSeeder>(
this);
158 return StatusCode::SUCCESS;
164 return StatusCode::SUCCESS;
176 fieldCondObj->getInitializedCache (fieldCache);
187 double abs1 = getRadiusOfCurvature(mytracks.
getFirstPerigee(), bfield1);
190 const double sgnr1 = abs1>0 ? 1. : -1.;
191 const double sgnr2 = abs2>0 ? 1. : -1.;
194 const std::pair<Amg::Vector3D,Amg::Vector3D> centersofcurv
198 #ifdef TRK2DDISTANCESEEDER_DEBUG
199 ATH_MSG_DEBUG(
" Center of track number 1: " << centersofcurv.first <<
" center of track 2 " << centersofcurv.second );
202 const double distance2d = dist2d(centersofcurv.first,centersofcurv.second);
204 abs1 = std::abs(abs1);
205 abs2 = std::abs(abs2);
208 #ifdef TRK2DDISTANCESEEDER_DEBUG
210 ATH_MSG_DEBUG(
"phitanpoca1: " << phitanpoca1 <<
" phitanpoca2: " << phitanpoca2 );
223 if (distance2d > (abs1+abs2)) {
225 #ifdef TRK2DDISTANCESEEDER_DEBUG
229 phi1 = safeAtan2(centersofcurv.second.y()-centersofcurv.first.y(),
230 centersofcurv.second.x()-centersofcurv.first.x());
235 phi2=oppositeangle(phi1);
239 phi1=oppositeangle(phi1);
243 phi1=takenearest(phi1,phitanpoca1);
244 phi2=takenearest(phi2,phitanpoca2);
251 if (fabs(abs2-abs1)>=distance2d) {
253 #ifdef TRK2DDISTANCESEEDER_DEBUG
260 #ifdef TRK2DDISTANCESEEDER_DEBUG
263 phi1 = safeAtan2(centersofcurv.second.y()-centersofcurv.first.y(),
264 centersofcurv.second.x()-centersofcurv.first.x());
269 #ifdef TRK2DDISTANCESEEDER_DEBUG
274 phi1 = safeAtan2(-(centersofcurv.second.y()-centersofcurv.first.y()),
275 -(centersofcurv.second.x()-centersofcurv.first.x()));
281 phi2=oppositeangle(phi2);
285 phi1=oppositeangle(phi1);
288 phi1=takenearest(setphipoca(phi1),setphipoca(phitanpoca1));
289 phi2=takenearest(setphipoca(phi2),setphipoca(phitanpoca2));
290 phi1poca = setphipoca(phi1);
291 phi2poca = setphipoca(phi2);
296 const double projection2=(square(abs1)-square(abs2)-square(distance2d))/2./distance2d;
297 const double cosinus2=projection2/sgnr2/abs2;
300 #ifdef TRK2DDISTANCESEEDER_DEBUG
301 const double projection1=(square(abs2)-square(abs1)-square(distance2d))/2./distance2d;
302 const double cosinus1=projection1/sgnr1/abs1;
303 ATH_MSG_DEBUG(
"projection1: " << projection1 <<
" cosinus1 " << cosinus1
304 <<
"projection2: " << projection2 <<
" cosinus2 " << cosinus2 );
307 const double phibase2 =
308 safeAtan2(centersofcurv.second.y() - centersofcurv.first.y(),
309 centersofcurv.second.x() - centersofcurv.first.x());
311 const double addtophi2=
314 #ifdef TRK2DDISTANCESEEDER_DEBUG
315 ATH_MSG_DEBUG(
" phibase2 is : " << phibase2 <<
" add to phi " << addtophi2 );
318 const std::pair<double,double> possiblephiontrack2(phibase2+addtophi2,phibase2-addtophi2);
320 #ifdef TRK2DDISTANCESEEDER_DEBUG
321 ATH_MSG_DEBUG(
"the two phis are: " << possiblephiontrack2.first <<
" and " << possiblephiontrack2.second );
324 const std::pair<double,double>
325 possiblecosphitrack1((centersofcurv.second.x()-centersofcurv.first.x()
326 +sgnr2*abs2*
std::cos(possiblephiontrack2.first))/sgnr1/abs1,
327 (centersofcurv.second.x()-centersofcurv.first.x()
328 +sgnr2*abs2*
std::cos(possiblephiontrack2.second))/sgnr1/abs1);
330 const std::pair<double,double>
331 possiblesigntrack1(sgnr1*(centersofcurv.second.y()-centersofcurv.first.y()
332 +sgnr2*abs2*
std::sin(possiblephiontrack2.first))>0?1.:-1.,
333 sgnr1*(centersofcurv.second.y()-centersofcurv.first.y()
334 +sgnr2*abs2*
std::sin(possiblephiontrack2.second))>0?1.:-1.);
336 const std::pair<double,double>
337 possiblephiontrack1(possiblesigntrack1.first*safeAcos(possiblecosphitrack1.first),
338 possiblesigntrack1.second*safeAcos(possiblecosphitrack1.second));
341 const std::pair<PointOnTrack,PointOnTrack>
343 takenearest(setphipoca(possiblephiontrack1.first),
344 setphipoca(phitanpoca1))),
346 takenearest(setphipoca(possiblephiontrack1.second),
347 setphipoca(phitanpoca1))));
349 const std::pair<PointOnTrack,PointOnTrack>
351 takenearest(setphipoca(possiblephiontrack2.first),
352 setphipoca(phitanpoca2))),
354 takenearest(setphipoca(possiblephiontrack2.second),
355 setphipoca(phitanpoca2))));
358 const std::pair<Amg::Vector3D,Amg::Vector3D>
359 possiblepoints1(getSeedPoint(possiblepointsontrack1.first.getPerigee(),centersofcurv.first,
360 abs1*sgnr1,possiblepointsontrack1.first.getPhiPoint()),
361 getSeedPoint(possiblepointsontrack1.second.getPerigee(),centersofcurv.first,
362 abs1*sgnr1,possiblepointsontrack1.second.getPhiPoint()));
364 const std::pair<Amg::Vector3D,Amg::Vector3D>
365 possiblepoints2(getSeedPoint(possiblepointsontrack2.first.getPerigee(),centersofcurv.second,
366 abs2*sgnr2,possiblepointsontrack2.first.getPhiPoint()),
367 getSeedPoint(possiblepointsontrack2.second.getPerigee(),centersofcurv.second,
368 abs2*sgnr2,possiblepointsontrack2.second.getPhiPoint()));
371 #ifdef TRK2DDISTANCESEEDER_DEBUG
372 ATH_MSG_DEBUG(
"Point 1a: x " << possiblepoints1.first.x() <<
" y " << possiblepoints1.first.y() );
373 ATH_MSG_DEBUG(
"Point 2a: x " << possiblepoints2.first.x() <<
" y " << possiblepoints2.first.y() );
374 ATH_MSG_DEBUG(
"Point 1b: x " << possiblepoints1.second.x() <<
" y " << possiblepoints1.second.y() );
375 ATH_MSG_DEBUG(
"Point 2b: x " << possiblepoints2.second.x() <<
" y " << possiblepoints2.second.y() );
376 ATH_MSG_DEBUG(
"Distance between 1a and 2a:" << fabs(possiblepoints1.first.z()-possiblepoints2.first.z()) <<
377 "Distance between 1a and 2a:" << fabs(possiblepoints1.second.z()-possiblepoints2.second.z()) );
384 if (fabs(possiblepoints1.first.z()-possiblepoints2.first.z())<
385 fabs(possiblepoints1.second.z()-possiblepoints2.second.z()))
387 phi1poca = possiblepointsontrack1.first.getPhiPoint();
388 phi2poca = possiblepointsontrack2.first.getPhiPoint();
390 phi1poca = possiblepointsontrack1.second.getPhiPoint();
391 phi2poca = possiblepointsontrack2.second.getPhiPoint();
396 if (sqrt(possiblepoints1.first.x()*possiblepoints1.first.x()+possiblepoints1.first.y()*possiblepoints1.first.y())<
397 sqrt(possiblepoints2.first.x()*possiblepoints2.first.x()+possiblepoints2.first.y()*possiblepoints2.first.y()))
399 phi1poca = possiblepointsontrack1.first.getPhiPoint();
400 phi2poca = possiblepointsontrack2.first.getPhiPoint();
402 phi1poca = possiblepointsontrack1.second.getPhiPoint();
403 phi2poca = possiblepointsontrack2.second.getPhiPoint();
406 phi1=goFromPhipocaToPhi(phi1poca);
407 phi2=goFromPhipocaToPhi(phi2poca);
412 *twopoints =
TwoPoints (getSeedPoint(centersofcurv.first,
413 abs1*sgnr1,setphipoca(phi1)),
414 getSeedPoint(centersofcurv.second,
415 abs2*sgnr2,setphipoca(phi2)));
425 double magnFieldVect[3];
427 posXYZ[0] =
p.associatedSurface().center().x();
428 posXYZ[1] =
p.associatedSurface().center().y();
429 posXYZ[2] =
p.associatedSurface().center().z();
431 cache.
getField(posXYZ,magnFieldVect);
432 const double bfield = magnFieldVect[2]*299.792;
433 if (bfield==0. || std::isnan(bfield)) {
434 ATH_MSG_DEBUG(
"Could not find a magnetic field different from zero: very very strange" );
437 ATH_MSG_DEBUG(
"Magnetic field projection of z axis in the perigee position is: " << bfield <<
" GeV/mm " );