ATLAS Offline Software
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
16 #include "AtlasHepMC/GenParticle.h"
18 
19 
20 InDet::PRD_TruthTrajectorySelectorID::PRD_TruthTrajectorySelectorID(const std::string& t, const std::string& n, const IInterface* p) :
21 AthAlgTool(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 
42 ThreePointCircle::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 
52 {
53  delete m_translation;
54 }
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.);
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 }
ThreePointCircle::m_phi0
double m_phi0
Definition: PRD_TruthTrajectorySelectorID.h:49
AtlasDetectorID::is_pixel
bool is_pixel(Identifier id) const
Definition: AtlasDetectorID.h:760
TRTCalib_Extractor.det
det
Definition: TRTCalib_Extractor.py:36
AtlasDetectorID::is_sct
bool is_sct(Identifier id) const
Definition: AtlasDetectorID.h:770
PixelCluster.h
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:75
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
ThreePointCircle::ThreePointCircle
ThreePointCircle(const std::vector< Amg::Vector3D > &vecPoints)
The constructor from three points.
Definition: PRD_TruthTrajectorySelectorID.cxx:42
ThreePointCircle::d0
double d0() const
Definition: PRD_TruthTrajectorySelectorID.h:55
PRD_TruthTrajectorySelectorID.h
Trk::PRD_TruthTrajectory::genParticle
HepMC::ConstGenParticlePtr genParticle
Definition: PRD_TruthTrajectory.h:31
ThreePointCircle::m_z0
double m_z0
Definition: PRD_TruthTrajectorySelectorID.h:49
AtlasDetectorID::is_trt
bool is_trt(Identifier id) const
Definition: AtlasDetectorID.h:782
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
InDet::PRD_TruthTrajectorySelectorID::PRD_TruthTrajectorySelectorID
PRD_TruthTrajectorySelectorID(const std::string &t, const std::string &n, const IInterface *p)
Definition: PRD_TruthTrajectorySelectorID.cxx:20
x
#define x
SCT_Cluster.h
GenParticle.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
PlotCalibFromCool.cx
cx
Definition: PlotCalibFromCool.py:666
AtlasDetectorID.h
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
ThreePointCircle::m_eta
double m_eta
Definition: PRD_TruthTrajectorySelectorID.h:49
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ThreePointCircle::m_pt
double m_pt
Definition: PRD_TruthTrajectorySelectorID.h:49
HepMC::is_simulation_particle
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...
Definition: MagicNumbers.h:355
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
fitman.bx
bx
Definition: fitman.py:410
ThreePointCircle::m_d0
double m_d0
Definition: PRD_TruthTrajectorySelectorID.h:49
fitman.by
by
Definition: fitman.py:411
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
InDet::SCT_Cluster
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/SCT_Cluster.h:34
ThreePointCircle::m_translation
Amg::Translation3D * m_translation
Definition: PRD_TruthTrajectorySelectorID.h:47
TRT_DriftCircle.h
Trk::PRD_TruthTrajectory
Definition: PRD_TruthTrajectory.h:27
ThreePointCircle::m_radius
double m_radius
Definition: PRD_TruthTrajectorySelectorID.h:50
MagicNumbers.h
ThreePointCircle
Definition: PRD_TruthTrajectorySelectorID.h:16
InDet::PRD_TruthTrajectorySelectorID::pass
virtual bool pass(const Trk::PRD_TruthTrajectory &) const
Interface method from IPRD_TruthTrajectorySelector.
Definition: PRD_TruthTrajectorySelectorID.cxx:134
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
ThreePointCircle::m_center
Amg::Vector2D m_center
Definition: PRD_TruthTrajectorySelectorID.h:51
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
InDet::PixelCluster
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/PixelCluster.h:49
makeTRTBarrelCans.dy
tuple dy
Definition: makeTRTBarrelCans.py:21
InDet::SiCluster::globalPosition
const Amg::Vector3D & globalPosition() const
return global position reference
y
#define y
PlotCalibFromCool.cy
cy
Definition: PlotCalibFromCool.py:667
makeTRTBarrelCans.dx
tuple dx
Definition: makeTRTBarrelCans.py:20
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
calibdata.cd
cd
Definition: calibdata.py:51
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
AthAlgTool
Definition: AthAlgTool.h:26
InDet::PRD_TruthTrajectorySelectorID::finalize
StatusCode finalize()
Definition: PRD_TruthTrajectorySelectorID.cxx:37
TRTCalib_cfilter.p3
p3
Definition: TRTCalib_cfilter.py:132
InDet::PRD_TruthTrajectorySelectorID::m_atlasId
const AtlasDetectorID * m_atlasId
ID pixel helper.
Definition: PRD_TruthTrajectorySelectorID.h:96
Trk::PRD_TruthTrajectory::prds
std::vector< const Trk::PrepRawData * > prds
public members
Definition: PRD_TruthTrajectory.h:30
InDet::PRD_TruthTrajectorySelectorID::initialize
StatusCode initialize()
Definition: PRD_TruthTrajectorySelectorID.cxx:26
ThreePointCircle::constructCircle
void constructCircle(const Amg::Vector3D &, const Amg::Vector3D &, const Amg::Vector3D &)
Definition: PRD_TruthTrajectorySelectorID.cxx:56
ThreePointCircle::~ThreePointCircle
~ThreePointCircle()
Destructor.
Definition: PRD_TruthTrajectorySelectorID.cxx:51