CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
KDTreeLinkerTrackEcal Class Reference
Inheritance diagram for KDTreeLinkerTrackEcal:
KDTreeLinkerBase

Public Member Functions

void buildTree () override
 
void clear () override
 
void insertFieldClusterElt (reco::PFBlockElement *ecalCluster) override
 
void insertTargetElt (reco::PFBlockElement *track) override
 
 KDTreeLinkerTrackEcal (const edm::ParameterSet &conf)
 
void searchLinks () override
 
void updatePFBlockEltWithLinks () override
 
 ~KDTreeLinkerTrackEcal () override
 
- Public Member Functions inherited from KDTreeLinkerBase
const reco::PFBlockElement::TypefieldType () const
 
 KDTreeLinkerBase (const edm::ParameterSet &conf)
 
void process ()
 
void setDebug (bool isDebug)
 
void setFieldType (const reco::PFBlockElement::Type &fld)
 
void setTargetType (const reco::PFBlockElement::Type &tgt)
 
const reco::PFBlockElement::TypetargetType () const
 
virtual ~KDTreeLinkerBase ()
 

Private Attributes

BlockElt2BlockEltMap cluster2TargetLinks_
 
BlockEltSet fieldClusterSet_
 
RecHit2BlockEltMap rechit2ClusterLinks_
 
RecHitSet rechitsSet_
 
BlockEltSet targetSet_
 
KDTreeLinkerAlgo< reco::PFRecHit const * > tree_
 

Additional Inherited Members

- Static Protected Member Functions inherited from KDTreeLinkerBase
template<typename T >
static std::vector< size_t > sort_indexes (const std::vector< T > &v)
 
- Protected Attributes inherited from KDTreeLinkerBase
reco::PFBlockElement::Type _fieldType
 
reco::PFBlockElement::Type _targetType
 
float cristalPhiEtaMaxSize_ = 0.04
 
float cristalXYMaxSize_ = 3.
 
const float cutOffFrac = 1E-4
 
bool debug_ = false
 
float phiOffset_ = 0.25
 

Detailed Description

Definition at line 11 of file KDTreeLinkerTrackEcal.cc.

Constructor & Destructor Documentation

◆ KDTreeLinkerTrackEcal()

KDTreeLinkerTrackEcal::KDTreeLinkerTrackEcal ( const edm::ParameterSet conf)

Definition at line 62 of file KDTreeLinkerTrackEcal.cc.

62 : KDTreeLinkerBase(conf) {}
KDTreeLinkerBase(const edm::ParameterSet &conf)

◆ ~KDTreeLinkerTrackEcal()

KDTreeLinkerTrackEcal::~KDTreeLinkerTrackEcal ( )
override

Definition at line 64 of file KDTreeLinkerTrackEcal.cc.

References clear().

64 { clear(); }

Member Function Documentation

◆ buildTree()

void KDTreeLinkerTrackEcal::buildTree ( )
overridevirtual

Implements KDTreeLinkerBase.

Definition at line 101 of file KDTreeLinkerTrackEcal.cc.

References KDTreeLinkerAlgo< DATA, DIM >::build(), RhoEtaPhi::eta(), f, M_PI, phi, RhoEtaPhi::phi(), phimax, phimin, KDTreeLinkerBase::phiOffset_, rechitsSet_, HLT_2022v15_cff::region, and tree_.

101  {
102  // List of pseudo-rechits that will be used to create the KDTree
103  std::vector<KDTreeNodeInfo<reco::PFRecHit const *, 2>> eltList;
104 
105  // Filling of this list
106  for (RecHitSet::const_iterator it = rechitsSet_.begin(); it != rechitsSet_.end(); it++) {
107  const reco::PFRecHit::REPPoint &posrep = (*it)->positionREP();
108 
109  KDTreeNodeInfo<reco::PFRecHit const *, 2> rh1(*it, posrep.eta(), posrep.phi());
110  eltList.push_back(rh1);
111 
112  // Here we solve the problem of phi circular set by duplicating some rechits
113  // too close to -Pi (or to Pi) and adding (substracting) to them 2 * Pi.
114  if (rh1.dims[1] > (M_PI - phiOffset_)) {
115  float phi = rh1.dims[1] - 2 * M_PI;
116  KDTreeNodeInfo<reco::PFRecHit const *, 2> rh2(*it, float(posrep.eta()), phi);
117  eltList.push_back(rh2);
118  }
119 
120  if (rh1.dims[1] < (M_PI * -1.0 + phiOffset_)) {
121  float phi = rh1.dims[1] + 2 * M_PI;
122  KDTreeNodeInfo<reco::PFRecHit const *, 2> rh3(*it, float(posrep.eta()), phi);
123  eltList.push_back(rh3);
124  }
125  }
126 
127  // Here we define the upper/lower bounds of the 2D space (eta/phi).
128  float phimin = -1.0 * M_PI - phiOffset_;
129  float phimax = M_PI + phiOffset_;
130 
131  // etamin-etamax, phimin-phimax
132  KDTreeBox region(-3.0f, 3.0f, phimin, phimax);
133 
134  // We may now build the KDTree
135  tree_.build(eltList, region);
136 }
KDTreeLinkerAlgo< reco::PFRecHit const * > tree_
float phi() const
momentum azimuthal angle
Definition: PtEtaPhiMass.h:54
double f[11][100]
void build(std::vector< KDTreeNodeInfo< DATA, DIM > > &eltList, const KDTreeBox< DIM > &region)
#define M_PI
float eta() const
momentum pseudorapidity
Definition: PtEtaPhiMass.h:52

◆ clear()

void KDTreeLinkerTrackEcal::clear ( void  )
overridevirtual

Implements KDTreeLinkerBase.

Definition at line 263 of file KDTreeLinkerTrackEcal.cc.

References KDTreeLinkerAlgo< DATA, DIM >::clear(), cluster2TargetLinks_, fieldClusterSet_, rechit2ClusterLinks_, rechitsSet_, targetSet_, and tree_.

Referenced by ~KDTreeLinkerTrackEcal().

263  {
264  targetSet_.clear();
265  fieldClusterSet_.clear();
266 
267  rechitsSet_.clear();
268 
269  rechit2ClusterLinks_.clear();
270  cluster2TargetLinks_.clear();
271 
272  tree_.clear();
273 }
KDTreeLinkerAlgo< reco::PFRecHit const * > tree_
RecHit2BlockEltMap rechit2ClusterLinks_
BlockElt2BlockEltMap cluster2TargetLinks_

◆ insertFieldClusterElt()

void KDTreeLinkerTrackEcal::insertFieldClusterElt ( reco::PFBlockElement ecalCluster)
overridevirtual

Implements KDTreeLinkerBase.

Definition at line 72 of file KDTreeLinkerTrackEcal.cc.

References reco::PFBlockElement::clusterRef(), KDTreeLinkerBase::cutOffFrac, fieldClusterSet_, funct::fract(), HLT_2022v15_cff::fraction, edm::Ref< C, T, F >::isNull(), rechit2ClusterLinks_, and rechitsSet_.

72  {
73  const reco::PFClusterRef &clusterref = ecalCluster->clusterRef();
74 
75  // This test is more or less done in PFBlockAlgo.h. In others cases, it should be switch on.
76  // if (!((clusterref->layer() == PFLayer::ECAL_ENDCAP) ||
77  // (clusterref->layer() == PFLayer::ECAL_BARREL)))
78  // return;
79 
80  const std::vector<reco::PFRecHitFraction> &fraction = clusterref->recHitFractions();
81 
82  // We create a list of ecalCluster
83  fieldClusterSet_.insert(ecalCluster);
84  for (size_t rhit = 0; rhit < fraction.size(); ++rhit) {
85  const reco::PFRecHitRef &rh = fraction[rhit].recHitRef();
86  double fract = fraction[rhit].fraction();
87 
88  if ((rh.isNull()) || (fract < cutOffFrac))
89  continue;
90 
91  const reco::PFRecHit &rechit = *rh;
92 
93  // We save the links rechit to EcalClusters
94  rechit2ClusterLinks_[&rechit].insert(ecalCluster);
95 
96  // We create a liste of rechits
97  rechitsSet_.insert(&rechit);
98  }
99 }
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
Definition: PFRecHit.h:31
virtual const PFClusterRef & clusterRef() const
const Fraction< n, m >::type & fract()
Definition: Fraction.h:36
bool isNull() const
Checks for null.
Definition: Ref.h:235
const float cutOffFrac
RecHit2BlockEltMap rechit2ClusterLinks_

◆ insertTargetElt()

void KDTreeLinkerTrackEcal::insertTargetElt ( reco::PFBlockElement track)
overridevirtual

Implements KDTreeLinkerBase.

Definition at line 66 of file KDTreeLinkerTrackEcal.cc.

References reco::PFTrajectoryPoint::ECALShowerMax, targetSet_, and HLT_2022v15_cff::track.

66  {
67  if (track->trackRefPF()->extrapolatedPoint(reco::PFTrajectoryPoint::ECALShowerMax).isValid()) {
68  targetSet_.insert(track);
69  }
70 }

◆ searchLinks()

void KDTreeLinkerTrackEcal::searchLinks ( )
overridevirtual

Implements KDTreeLinkerBase.

Definition at line 138 of file KDTreeLinkerTrackEcal.cc.

References reco::PFTrajectoryPoint::ClosestApproach, cluster2TargetLinks_, KDTreeLinkerBase::cristalPhiEtaMaxSize_, PFLayer::ECAL_BARREL, reco::PFTrajectoryPoint::ECALShowerMax, PVValHelper::eta, reco::PFTrajectoryPoint::isValid(), M_PI, SiStripPI::min, reco::PFTrajectoryPoint::momentum(), phi, reco::PFTrajectoryPoint::position(), reco::PFTrajectoryPoint::positionREP(), FastTimerService_cff::range, rpcPointValidation_cfi::recHit, rechit2ClusterLinks_, FastTrackerRecHitMaskProducer_cfi::recHits, runTheMatrix::ret, KDTreeLinkerAlgo< DATA, DIM >::search(), mathSSE::sqrt(), targetSet_, listHistos::trackPt, tree_, x, and y.

138  {
139  // Most of the code has been taken from LinkByRecHit.cc
140 
141  // We iterate over the tracks.
142  for (BlockEltSet::iterator it = targetSet_.begin(); it != targetSet_.end(); it++) {
143  reco::PFRecTrackRef trackref = (*it)->trackRefPF();
144 
145  const reco::PFTrajectoryPoint &atECAL = trackref->extrapolatedPoint(reco::PFTrajectoryPoint::ECALShowerMax);
146 
147  // The track didn't reach ecal
148  if (!atECAL.isValid())
149  continue;
150 
151  const reco::PFTrajectoryPoint &atVertex = trackref->extrapolatedPoint(reco::PFTrajectoryPoint::ClosestApproach);
152 
153  double trackPt = sqrt(atVertex.momentum().Vect().Perp2());
154  float tracketa = atECAL.positionREP().eta();
155  float trackphi = atECAL.positionREP().phi();
156  double trackx = atECAL.position().X();
157  double tracky = atECAL.position().Y();
158  double trackz = atECAL.position().Z();
159 
160  // Estimate the maximal envelope in phi/eta that will be used to find rechit candidates.
161  // Same envelope for cap et barrel rechits.
162  float range = cristalPhiEtaMaxSize_ * (2.0 + 1.0 / std::min(1., trackPt / 2.));
163 
164  // We search for all candidate recHits, ie all recHits contained in the maximal size envelope.
165  std::vector<reco::PFRecHit const *> recHits;
166  KDTreeBox trackBox(tracketa - range, tracketa + range, trackphi - range, trackphi + range);
167  tree_.search(trackBox, recHits);
168 
169  // Here we check all rechit candidates using the non-approximated method.
170  for (auto const &recHit : recHits) {
171  const auto &cornersxyz = recHit->getCornersXYZ();
172  const auto &posxyz = recHit->position();
173  const auto &rhrep = recHit->positionREP();
174  const auto &corners = recHit->getCornersREP();
175 
176  double rhsizeeta = fabs(corners[3].eta() - corners[1].eta());
177  double rhsizephi = fabs(corners[3].phi() - corners[1].phi());
178  if (rhsizephi > M_PI)
179  rhsizephi = 2. * M_PI - rhsizephi;
180 
181  double deta = fabs(rhrep.eta() - tracketa);
182  double dphi = fabs(rhrep.phi() - trackphi);
183  if (dphi > M_PI)
184  dphi = 2. * M_PI - dphi;
185 
186  // Find all clusters associated to given rechit
187  RecHit2BlockEltMap::iterator ret = rechit2ClusterLinks_.find(recHit);
188 
189  for (BlockEltSet::const_iterator clusterIt = ret->second.begin(); clusterIt != ret->second.end(); clusterIt++) {
190  reco::PFClusterRef clusterref = (*clusterIt)->clusterRef();
191  double clusterz = clusterref->position().z();
192  int fracsNbr = clusterref->recHitFractions().size();
193 
194  if (clusterref->layer() == PFLayer::ECAL_BARREL) { // BARREL
195  // Check if the track is in the barrel
196  if (fabs(trackz) > 300.)
197  continue;
198 
199  double _rhsizeeta = rhsizeeta * (2.00 + 1.0 / (fracsNbr * std::min(1., trackPt / 2.)));
200  double _rhsizephi = rhsizephi * (2.00 + 1.0 / (fracsNbr * std::min(1., trackPt / 2.)));
201 
202  // Check if the track and the cluster are linked
203  if (deta < (_rhsizeeta / 2.) && dphi < (_rhsizephi / 2.))
204  cluster2TargetLinks_[*clusterIt].insert(*it);
205 
206  } else { // ENDCAP
207 
208  // Check if the track is in the cap
209  if (fabs(trackz) < 300.)
210  continue;
211  if (trackz * clusterz < 0.)
212  continue;
213 
214  double x[5];
215  double y[5];
216  for (unsigned jc = 0; jc < 4; ++jc) {
217  auto cornerposxyz = cornersxyz[jc];
218  x[3 - jc] = cornerposxyz.x() +
219  (cornerposxyz.x() - posxyz.x()) * (1.00 + 0.50 / fracsNbr / std::min(1., trackPt / 2.));
220  y[3 - jc] = cornerposxyz.y() +
221  (cornerposxyz.y() - posxyz.y()) * (1.00 + 0.50 / fracsNbr / std::min(1., trackPt / 2.));
222  }
223 
224  x[4] = x[0];
225  y[4] = y[0];
226 
227  bool isinside = TMath::IsInside(trackx, tracky, 5, x, y);
228 
229  // Check if the track and the cluster are linked
230  if (isinside)
231  cluster2TargetLinks_[*clusterIt].insert(*it);
232  }
233  }
234  }
235  }
236 }
const REPPoint & positionREP() const
trajectory position in (rho, eta, phi) base
void search(const KDTreeBox< DIM > &searchBox, std::vector< DATA > &resRecHitList)
KDTreeLinkerAlgo< reco::PFRecHit const * > tree_
ret
prodAgent to be discontinued
const math::XYZTLorentzVector & momentum() const
4-momenta quadrivector
bool isValid() const
is this point valid ?
Point of closest approach from beam axis (initial point in the case of PFSimParticle) ...
T sqrt(T t)
Definition: SSEVec.h:19
#define M_PI
const math::XYZPoint & position() const
cartesian position (x, y, z)
RecHit2BlockEltMap rechit2ClusterLinks_
A PFTrack holds several trajectory points, which basically contain the position and momentum of a tra...
BlockElt2BlockEltMap cluster2TargetLinks_

◆ updatePFBlockEltWithLinks()

void KDTreeLinkerTrackEcal::updatePFBlockEltWithLinks ( )
overridevirtual

Implements KDTreeLinkerBase.

Definition at line 238 of file KDTreeLinkerTrackEcal.cc.

References KDTreeLinkerBase::_fieldType, KDTreeLinkerBase::_targetType, cluster2TargetLinks_, and reco::PFMultiLinksTC::linkedPFObjects.

238  {
239  //TODO YG : Check if cluster positionREP() is valid ?
240 
241  // Here we save in each ECAL cluster the list of phi/eta values of linked tracks.
242  for (BlockElt2BlockEltMap::iterator it = cluster2TargetLinks_.begin(); it != cluster2TargetLinks_.end(); ++it) {
243  const auto &ecalElt = it->first;
244  const auto &trackEltSet = it->second;
245  reco::PFMultiLinksTC multitracks(true);
246 
247  for (const auto &trackElt : trackEltSet) {
248  const reco::PFRecTrackRef &trackref = trackElt->trackRefPF();
249 
250  reco::PFMultilink multiLink(trackref);
251  multitracks.linkedPFObjects.push_back(multiLink);
252 
253  // We set the multilinks flag of the track (for links to ECAL) to true. It will allow us to
254  // use it in an optimized way in prefilter
255  trackElt->setIsValidMultilinks(true, _fieldType);
256  }
257 
258  // We set multilinks of the ECAL element (for links to tracks)
259  ecalElt->setMultilinks(multitracks, _targetType);
260  }
261 }
reco::PFBlockElement::Type _fieldType
reco::PFBlockElement::Type _targetType
BlockElt2BlockEltMap cluster2TargetLinks_

Member Data Documentation

◆ cluster2TargetLinks_

BlockElt2BlockEltMap KDTreeLinkerTrackEcal::cluster2TargetLinks_
private

Definition at line 49 of file KDTreeLinkerTrackEcal.cc.

Referenced by clear(), searchLinks(), and updatePFBlockEltWithLinks().

◆ fieldClusterSet_

BlockEltSet KDTreeLinkerTrackEcal::fieldClusterSet_
private

Definition at line 43 of file KDTreeLinkerTrackEcal.cc.

Referenced by clear(), and insertFieldClusterElt().

◆ rechit2ClusterLinks_

RecHit2BlockEltMap KDTreeLinkerTrackEcal::rechit2ClusterLinks_
private

Definition at line 52 of file KDTreeLinkerTrackEcal.cc.

Referenced by clear(), insertFieldClusterElt(), and searchLinks().

◆ rechitsSet_

RecHitSet KDTreeLinkerTrackEcal::rechitsSet_
private

Definition at line 46 of file KDTreeLinkerTrackEcal.cc.

Referenced by buildTree(), clear(), and insertFieldClusterElt().

◆ targetSet_

BlockEltSet KDTreeLinkerTrackEcal::targetSet_
private

Definition at line 42 of file KDTreeLinkerTrackEcal.cc.

Referenced by clear(), insertTargetElt(), and searchLinks().

◆ tree_

KDTreeLinkerAlgo<reco::PFRecHit const *> KDTreeLinkerTrackEcal::tree_
private

Definition at line 55 of file KDTreeLinkerTrackEcal.cc.

Referenced by buildTree(), clear(), and searchLinks().