ATLAS Offline Software
IndexedCrossDistancesSeedFinder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 //Author: Lianyou Shan <lianyou.shan@cern.ch>
5 /*********************************************************************
6  IndexedCrossDistancesSeedFinder.cxx - Description in header file
7 *********************************************************************/
8 
9 //#define CROSSDISTANCESSEEDFINDER_DEBUG
10 
13 #include "TrkTrack/Track.h"
14 
18 
21 #include <cmath>
22 
23 
24 namespace Trk
25 {
26 
27  IndexedCrossDistancesSeedFinder::IndexedCrossDistancesSeedFinder(const std::string& t, const std::string& n, const IInterface* p) :
28  base_class(t,n,p),
29  m_useweights(true),
30  m_trackdistcutoff(0.020),
31  m_trackdistexppower(2),
32  m_constraintcutoff(9.),
33  m_constrainttemp(9.),
34  m_maximumTracksNoCut(20),
35  m_maximumDistanceCut(3.)
36  {
37  declareProperty("useweights",m_useweights);
38  declareProperty("trackdistcutoff",m_trackdistcutoff);
39  declareProperty("trackdistexppower",m_trackdistexppower);
40  declareProperty("constrainttemp",m_constrainttemp);
41  declareProperty("constraintcutoff",m_constraintcutoff);
42  declareProperty("maximumTracksNoCut",m_maximumTracksNoCut);
43  declareProperty("maximumDistanceCut",m_maximumDistanceCut);
44  }
45 
46 
48  = default;
49 
50 
52  {
53  ATH_CHECK( m_mode3dfinder.retrieve() );
54  ATH_CHECK( m_distancefinder.retrieve() );
55  return StatusCode::SUCCESS;
56  }
57 
58 
60  IndexedCrossDistancesSeedFinder::findSeed(const std::vector<const Trk::Track*> & /*VectorTrk*/,
61  const xAOD::Vertex * /*constraint*/) const
62  {
63  ATH_MSG_ERROR ("Need to supply a primary vertex.");
64  return Amg::Vector3D(0.,0.,0.);
65  }
66 
67 
69  IndexedCrossDistancesSeedFinder::findSeed(const std::vector<const Trk::TrackParameters*> & /*perigeeList*/,
70  const xAOD::Vertex * /*constraint*/) const
71  {
72  ATH_MSG_ERROR ("Need to supply a primary vertex.");
73  return Amg::Vector3D(0.,0.,0.);
74  }
75 
76 
79  const double vy,
80  const std::vector<const Trk::TrackParameters*>& perigeeList,
81  const xAOD::Vertex* constraint) const
82  {
83  std::unique_ptr<Trk::IMode3dInfo> info;
84  return findSeed (vx, vy, info, perigeeList, constraint);
85  }
86 
87 
90  const double vy,
91  std::unique_ptr<Trk::IMode3dInfo>& info,
92  const std::vector<const Trk::TrackParameters*>& perigeeList,
93  const xAOD::Vertex* constraint) const
94  {
95  ATH_MSG_DEBUG( " Enter IndexedCrossDistancesSeedFinder " );
96 
97  bool useCutOnDistance=false;
98  if (perigeeList.size()>m_maximumTracksNoCut)
99  {
100  useCutOnDistance=true;
101  }
102 
103  //now implement the code you already had in the standalone code...
104 
105  //Calculate and cache the covariance matrix for the constraint
106  AmgSymMatrix(3) weightMatrixPositionConstraint;
107  weightMatrixPositionConstraint.setIdentity(); //very arbitrary
108  if (constraint != nullptr) {
109  weightMatrixPositionConstraint = constraint->covariancePosition().inverse();
110  }
111 
112  //Prepare the vector of points, on which the 3d mode has later to be calculated
113  std::vector<PositionAndWeight> CrossingPointsAndWeights;
114  std::vector<Amg::Vector3D> CrossingPoints;
115 
116  //Implement here SeedPointFinder algorithm, acting with the track vector....
117  const std::vector<const Trk::TrackParameters*>::const_iterator begin=perigeeList.begin();
118  const std::vector<const Trk::TrackParameters*>::const_iterator end=perigeeList.end();
119 
120  ATH_MSG_DEBUG( " Loop pairs of TrackParameters for modes " );
121 
122  std::vector< std::pair <int, int> > trkidx ;
123  int idx_i = 0 ;
124  for (std::vector<const Trk::TrackParameters*>::const_iterator i=begin;i!=end-1;++i)
125  {
126  idx_i ++ ;
127  const Trk::Perigee* MyI=dynamic_cast<const Trk::Perigee*>(*i);
128  if (MyI==nullptr) {
129  ATH_MSG_WARNING( "Neutrals not supported for seeding. Rejecting this track..." );
130  continue;
131  }
132 
133  int idx_j = idx_i ; // 1 has been added to idx_i
134  for (std::vector<const Trk::TrackParameters*>::const_iterator j=i+1;j!=end;++j++) {
135 
136  idx_j ++ ;
137  const Trk::Perigee* MyJ=dynamic_cast<const Trk::Perigee*>(*j);
138 
139  if (MyJ==nullptr) {
140  ATH_MSG_WARNING( "Neutrals not supported for seeding. Rejecting this track..." );
141  continue;
142  }
143 
144 
145  try {
146 
147  std::optional<ITrkDistanceFinder::TwoPoints> result
148  = m_distancefinder->CalculateMinimumDistance(*MyI,*MyJ);
149  if (!result) {ATH_MSG_DEBUG("Problem with distance finder: THIS POINT WILL BE SKIPPED!");
150  }
151  else
152  {
153  //Get the points which connect the minimum distance between the two tracks
154  double distance = Amg::distance (result->first, result->second);
155 #ifdef CROSSDISTANCESSEEDFINDER_DEBUG
156  ATH_MSG_DEBUG("Point 1 x: " << result->first.x() <<
157  " y: " << result->first.y() <<
158  " z: " << result->first.z() );
159  ATH_MSG_DEBUG("Point 2 x: " << result->second.x() <<
160  " y: " << result->second.y() <<
161  " z: " << result->second.z() );
162  ATH_MSG_DEBUG("distance is: " << distance );
163 #endif
164 
165  Amg::Vector3D thepoint((result->first+result->second)/2.);
166 
167  if (m_useweights)
168  {
169  PositionAndWeight thispoint(thepoint,
171 
173 
174  if (constraint!=nullptr) {
175 
176  Amg::Vector3D DeltaP(thepoint-constraint->position());
177  Amg::Vector3D DeltaPConv;
178  ATH_MSG_DEBUG("position x: " << DeltaP.x() << "position y: " << DeltaP.y() << "position z: " << DeltaP.z() );
179  DeltaPConv[0]=DeltaP.x();
180  DeltaPConv[1]=DeltaP.y();
181  DeltaPConv[2]=DeltaP.z();
182 
183 
184  double chi2=DeltaPConv.transpose()*weightMatrixPositionConstraint*DeltaPConv;
185 
186  ATH_MSG_DEBUG(" chi: " << chi2 <<
187  " beam weight " << 1./(1.+exp((chi2-m_constraintcutoff)/m_constrainttemp)) );
188 
189  thispoint.second=thispoint.second*1./(1.+exp((chi2-m_constraintcutoff)/m_constrainttemp));
190 
191  }
192 
193  if ((!useCutOnDistance || distance<m_maximumDistanceCut) && thispoint.second > 1e-10)
194  {
195  CrossingPointsAndWeights.push_back( thispoint );
196 
197  trkidx.emplace_back( idx_i - 1 , idx_j - 1 );
198 
199  ATH_MSG_VERBOSE( " crossing with track pair : " << idx_i - 1 <<" "
200  << MyI->parameters()[Trk::d0] <<" "<< idx_j - 1 <<" "
201  << MyJ->parameters()[Trk::d0] );
202 
203  }
204  }
205  else
206  {
207  const Amg::Vector3D& thispoint(thepoint);
208  if ( !useCutOnDistance || distance<m_maximumDistanceCut )
209  {
210  CrossingPoints.push_back( thispoint );
211  }
212  }
213  }
214  } catch (...) {
215  ATH_MSG_ERROR("Something wrong in distance calculation: please report..." );
216  }
217  }
218  //to be understood...
219  }
220 
221  //Now all points have been collected (N*(N-1)/2) and
222  //the mode has to be calculated
223 
224  if ( ( CrossingPoints.empty() && ! m_useweights )
225  || ( m_useweights && CrossingPointsAndWeights.empty() ) )
226  {
227  return Amg::Vector3D(0,0,0);
228  }
229 
230  ATH_MSG_DEBUG(" crossing points prepared : " << CrossingPointsAndWeights.size() );
231 
232  Amg::Vector3D myresult;
233 
234  if (m_useweights)
235  {
236  myresult=m_mode3dfinder->getMode(vx, vy, CrossingPointsAndWeights, info);
237  }
238  else
239  {
240  myresult=m_mode3dfinder->getMode(vx, vy, CrossingPoints, info);
241  }
242 
243  info->setTrkidx (std::move (trkidx));
244  ATH_MSG_DEBUG(" 3D modes found ! " );
245 
246  return myresult;
247 
248  }
249 
250 
251 std::vector<Amg::Vector3D> IndexedCrossDistancesSeedFinder::findMultiSeeds(
252  const std::vector<const Trk::Track*>& /* vectorTrk */,const xAOD::Vertex * /* constraint */) const
253 {
254 
255  //implemented to satisfy inheritance but this algorithm only supports one seed at a time
256  ATH_MSG_WARNING("Multi-seeding requested but seed finder not able to operate in that mode, returning no seeds" );
257  return std::vector<Amg::Vector3D>(0);
258 }
259 
260 std::vector<Amg::Vector3D> IndexedCrossDistancesSeedFinder::findMultiSeeds(
261  const std::vector<const Trk::TrackParameters*>& /* perigeeList */,const xAOD::Vertex * /* constraint */) const
262 {
263 
264  //implemented to satisfy inheritance but this algorithm only supports one seed at a time
265  ATH_MSG_WARNING("Multi-seeding requested but seed finder not able to operate in that mode, returning no seeds" );
266  return std::vector<Amg::Vector3D>(0);
267 
268 }
269 
270 
271 }
grepfile.info
info
Definition: grepfile.py:38
Trk::IndexedCrossDistancesSeedFinder::m_mode3dfinder
ToolHandle< IMode3dFinder > m_mode3dfinder
Definition: IndexedCrossDistancesSeedFinder.h:129
get_generator_info.result
result
Definition: get_generator_info.py:21
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
TrackParameters.h
Trk::IndexedCrossDistancesSeedFinder::m_maximumDistanceCut
double m_maximumDistanceCut
Definition: IndexedCrossDistancesSeedFinder.h:127
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
IndexedCrossDistancesSeedFinder.h
xAOD::Vertex_v1::position
const Amg::Vector3D & position() const
Returns the 3-pos.
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
ParamDefs.h
Trk::IndexedCrossDistancesSeedFinder::m_constrainttemp
float m_constrainttemp
Definition: IndexedCrossDistancesSeedFinder.h:125
Trk::IndexedCrossDistancesSeedFinder::m_distancefinder
ToolHandle< ITrkDistanceFinder > m_distancefinder
Definition: IndexedCrossDistancesSeedFinder.h:132
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
Track.h
Trk::AmgSymMatrix
AmgSymMatrix(5) &GXFTrackState
Definition: GXFTrackState.h:156
Trk::PositionAndWeight
std::pair< Amg::Vector3D, double > PositionAndWeight
Definition: SeedFinderParamDefs.h:17
GeoPrimitives.h
Trk::IndexedCrossDistancesSeedFinder::m_trackdistcutoff
float m_trackdistcutoff
Definition: IndexedCrossDistancesSeedFinder.h:122
Trk::IndexedCrossDistancesSeedFinder::~IndexedCrossDistancesSeedFinder
virtual ~IndexedCrossDistancesSeedFinder()
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:522
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::IndexedCrossDistancesSeedFinder::findMultiSeeds
virtual std::vector< Amg::Vector3D > findMultiSeeds(const std::vector< const Trk::Track * > &vectorTrk, const xAOD::Vertex *constraint=0) const override final
Finds full vector of linearization points from a vector of tracks and returns it as an Amg::Vector3D ...
Definition: IndexedCrossDistancesSeedFinder.cxx:253
EventPrimitives.h
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::IndexedCrossDistancesSeedFinder::m_trackdistexppower
int m_trackdistexppower
Definition: IndexedCrossDistancesSeedFinder.h:123
Trk::d0
@ d0
Definition: ParamDefs.h:69
SeedFinderParamDefs.h
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
GeoPrimitivesHelpers.h
Trk::IndexedCrossDistancesSeedFinder::findSeed
virtual Amg::Vector3D findSeed(const std::vector< const Trk::Track * > &vectorTrk, const xAOD::Vertex *constraint=0) const override final
Finds a linearization point out of a vector of tracks and returns it as an Amg::Vector3D object.
Definition: IndexedCrossDistancesSeedFinder.cxx:62
Trk::IndexedCrossDistancesSeedFinder::IndexedCrossDistancesSeedFinder
IndexedCrossDistancesSeedFinder(const std::string &t, const std::string &n, const IInterface *p)
Definition: IndexedCrossDistancesSeedFinder.cxx:29
Trk::IndexedCrossDistancesSeedFinder::m_constraintcutoff
float m_constraintcutoff
Definition: IndexedCrossDistancesSeedFinder.h:124
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
Trk::IndexedCrossDistancesSeedFinder::m_maximumTracksNoCut
unsigned int m_maximumTracksNoCut
Definition: IndexedCrossDistancesSeedFinder.h:126
Trk::IndexedCrossDistancesSeedFinder::m_useweights
bool m_useweights
Definition: IndexedCrossDistancesSeedFinder.h:121
Trk::IndexedCrossDistancesSeedFinder::initialize
virtual StatusCode initialize() override
Definition: IndexedCrossDistancesSeedFinder.cxx:53
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54