ATLAS Offline Software
Loading...
Searching...
No Matches
PRD_TruthTrajectorySelectorID.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6// PRD_TruthTrajectorySelectorID.cxx, (c) ATLAS Detector software
8
13// DetectorDescription
15// HepMC
18
19
20InDet::PRD_TruthTrajectorySelectorID::PRD_TruthTrajectorySelectorID(const std::string& t, const std::string& n, const IInterface* p) :
21AthAlgTool(t,n,p)
22{
23 declareInterface<Trk::IPRD_TruthTrajectorySelector>(this);
24}
25
27 ATH_MSG_VERBOSE("Initializing ...");
28 StatusCode sc = detStore()->retrieve(m_atlasId, "AtlasID");
29 if (sc.isFailure()) {
30 msg(MSG::ERROR) << "Could not get AtlasID helper !" << endmsg;
31 return StatusCode::FAILURE;
32 }
33 return StatusCode::SUCCESS;
34
35}
36
38 ATH_MSG_VERBOSE("Finalizing ...");
39 return StatusCode::SUCCESS;
40}
41
42ThreePointCircle::ThreePointCircle(const std::vector<Amg::Vector3D>& posVec) :
43 m_translation(nullptr), m_d0(0.), m_z0(0.), m_phi0(0.), m_eta(0.), m_pt(0.)
44{
45 if (posVec.size() <3)
46 std::cout << "[WARNING] not enough points" << std::endl;
47 else
48 constructCircle(posVec[0],posVec[1],posVec[2]);
49}
50
55
57 const Amg::Vector3D& p2,
58 const Amg::Vector3D& p3) {
59
60 // get the (x/y) coordinates of all points
61 double translationX = m_translation ? -(m_translation->translation()).x() : 0.;
62 double translationY = m_translation ? -(m_translation->translation()).y() : 0.;
63
64 double bx = p1.x()+translationX;
65 double by = p1.y()+translationY;
66 double cx = p2.x()+translationX;
67 double cy = p2.y()+translationY;
68 double dx = p3.x()+translationX;
69 double dy = p3.y()+translationY;
70
71 double temp = cx*cx+cy*cy;
72
73 // prepare the matrix for the linear equation
74 double bc = (bx*bx + by*by - temp)/2.0;
75 double cd = (temp - dx*dx - dy*dy)/2.0;
76 double det = (bx-cx)*(cy-dy)-(cx-dx)*(by-cy);
77 //if (std::abs(det) < 1.0e-6) {
78 //std::cout << "[WARNING] Determinant is close to 0 " << std::endl;
79 //}
80
81 // invert the determinant
82 det = 1./det;
83
84 // x / y coordinate of the center
85 double cRx= (bc*(cy-dy)-cd*(by-cy))*det;
86 double cRy = ((bx-cx)*cd-(cx-dx)*bc)*det;
87
88 // get the center, radius and momentum
89 m_center = Amg::Vector2D(cRx,cRy);
90 m_radius = sqrt((cRx-bx)*(cRx-bx)+(cRy-by)*(cRy-by));
91 m_pt = m_radius*(0.3*2.);
92
93 // transverse parameters
94 m_d0 = std::sqrt(cRx*cRx+cRy*cRy)-m_radius;
95
96 // longitudinal parameters
97 double theta = 1./3*(p1.theta() + p2.theta() + p3.theta());
98 double r1 = p1.perp();
99 double z1 = p1.z();
100 double deltaz = r1/tan(theta);
101 m_z0 = z1 - deltaz;
102 // eta
103 m_eta = 1./3*(p1.eta() + p2.eta() + p3.eta());
104
105 // get the point of closest approach
106 Amg::Vector2D poca = -m_d0*m_center.unit();
107
108 // find the closest measurement
109 Amg::Vector2D closestMeasurement = p1.perp() < p2.perp() ?
110 Amg::Vector2D(p1.x(),p1.y()) : Amg::Vector2D(p2.x(),p2.y());
111 if (p3.perp() < p1.perp()) closestMeasurement = Amg::Vector2D(p3.x(),p3.y());
112
113 // phi0 is the most difficult one, two solution possible
114 Amg::Vector2D directionOne(-cRy,cRx);
115 Amg::Vector2D directionTwo(cRy,-cRx);
116
117 // build difference vector closest measurement, poca
118 Amg::Vector2D toFirstMeas(closestMeasurement-poca);
119
120 // check with scalar product
121 m_phi0 = directionOne.dot(toFirstMeas) > 0. ? directionOne.phi() : directionTwo.phi();
122
123 // now sign d0
124 Amg::Vector3D pocaDir(poca.x(),poca.y(),0.);
125 Amg::Vector3D momDir(std::cos(m_phi0),std::sin(m_phi0),0.);
126 double signD0 = pocaDir.cross(momDir).z() > 0. ? 1. : -1.;
127 m_d0 = signD0 * std::abs(m_d0);
128
129 // update the center for the translation
130 m_center += Amg::Vector2D(translationX,translationY);
131
132}
133
135
136 std::vector<Amg::Vector3D> pos;
137 std::vector<const Trk::PrepRawData* >::const_iterator prdIter = prdvec.prds.begin();
138 std::vector<const Trk::PrepRawData* >::const_iterator prdIterE = prdvec.prds.end();
139
140 // look for 3 globalPositions for ThreePointCircle approximation
141 for ( int i = 0; i < 3 && prdIter != prdIterE; ++ prdIter ){
142 if( m_atlasId->is_pixel((*prdIter)->identify()) ){
143 const InDet::PixelCluster* pixclus=dynamic_cast<const InDet::PixelCluster*>(*prdIter);
144 if (pixclus) {
145 if(!pos.empty() && (pos.back()-pixclus->globalPosition()).squaredNorm() < 9)
146 continue;
147 pos.push_back (pixclus->globalPosition());
148 }
149 }
150 else if( m_atlasId->is_sct((*prdIter)->identify()) ){
151 const InDet::SCT_Cluster* sctclus=dynamic_cast<const InDet::SCT_Cluster*>(*prdIter);
152 if (sctclus) {
153 if(!pos.empty() && (pos.back()-sctclus->globalPosition()).squaredNorm() < 9)
154 continue;
155 pos.push_back (sctclus->globalPosition());
156 }
157 }
158 else if( m_atlasId->is_trt((*prdIter)->identify()) ){
159 continue;
160 }
161 i++;
162 }
163
164 // only take trajectory if enough hits
165 if( pos.size() != 3 ) return false;
166
167 ThreePointCircle circle(pos);
168 // trajectory only selected when within cuts
169 if( ( std::abs(circle.d0()) <= 15 && !HepMC::is_simulation_particle(prdvec.genParticle) )) return true;
170
171 return false;
172}
Scalar theta() const
theta method
#define endmsg
#define ATH_MSG_VERBOSE(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
static Double_t sc
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
MsgStream & msg() const
virtual bool pass(const Trk::PRD_TruthTrajectory &) const
Interface method from IPRD_TruthTrajectorySelector.
PRD_TruthTrajectorySelectorID(const std::string &t, const std::string &n, const IInterface *p)
const AtlasDetectorID * m_atlasId
ID pixel helper.
const Amg::Vector3D & globalPosition() const
return global position reference
Amg::Translation3D * m_translation
ThreePointCircle(const std::vector< Amg::Vector3D > &vecPoints)
The constructor from three points.
void constructCircle(const Amg::Vector3D &, const Amg::Vector3D &, const Amg::Vector3D &)
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
simple definitiion of a PRD_TruhtTrajectory
std::vector< const Trk::PrepRawData * > prds
public members
HepMC::ConstGenParticlePtr genParticle