CMS 3D CMS Logo

ConvBremPFTrackFinder.cc
Go to the documentation of this file.
3 
13 #include "TMath.h"
15 #include "TMVA/MethodBDT.h"
17 
18 using namespace edm;
19 using namespace std;
20 using namespace reco;
21 
23  double mvaBremConvCutBarrelLowPt,
24  double mvaBremConvCutBarrelHighPt,
25  double mvaBremConvCutEndcapsLowPt,
26  double mvaBremConvCutEndcapsHighPt)
27  : builder_(builder),
28  mvaBremConvCutBarrelLowPt_(mvaBremConvCutBarrelLowPt),
29  mvaBremConvCutBarrelHighPt_(mvaBremConvCutBarrelHighPt),
30  mvaBremConvCutEndcapsLowPt_(mvaBremConvCutEndcapsLowPt),
31  mvaBremConvCutEndcapsHighPt_(mvaBremConvCutEndcapsHighPt) {}
33 
40  bool useNuclear,
41  bool useConversions,
42  bool useV0,
43  const reco::PFClusterCollection& theEClus,
44  const reco::GsfPFRecTrack& gsfpfrectk) {
45  found_ = false;
46 
47  LogDebug("ConvBremPFTrackFinder") << "runConvBremFinder:: Entering ";
48 
49  const reco::GsfTrackRef& refGsf = gsfpfrectk.gsfTrackRef();
50  float refGsfEta = refGsf->eta();
51  float refGsfPt = refGsf->pt();
52  float refGsfPhi = refGsf->phi();
53  float gsfR = sqrt(refGsf->innerPosition().x() * refGsf->innerPosition().x() +
54  refGsf->innerPosition().y() * refGsf->innerPosition().y());
55  // direction of the Gsf track
56  GlobalVector direction(refGsf->innerMomentum().x(), refGsf->innerMomentum().y(), refGsf->innerMomentum().z());
57  float refGsfPtMode = refGsf->ptMode();
58 
59  const reco::PFRecTrackRef& pfTrackRef = gsfpfrectk.kfPFRecTrackRef();
60  vector<PFBrem> primPFBrem = gsfpfrectk.PFRecBrem();
61 
62  const PFRecTrackCollection& PfRTkColl = *(thePfRecTrackCol.product());
63  reco::PFRecTrackCollection::const_iterator pft = PfRTkColl.begin();
64  reco::PFRecTrackCollection::const_iterator pftend = PfRTkColl.end();
65 
66  vector<PFRecTrackRef> AllPFRecTracks;
67  AllPFRecTracks.clear();
68  unsigned int ipft = 0;
69 
70  for (; pft != pftend; ++pft, ipft++) {
71  // do not consider the kf track already associated to the seed
72  if (pfTrackRef.isNonnull())
73  if (pfTrackRef->trackRef() == pft->trackRef())
74  continue;
75 
76  PFRecTrackRef pfRecTrRef(thePfRecTrackCol, ipft);
77  TrackRef trackRef = pfRecTrRef->trackRef();
78  reco::TrackBaseRef selTrackBaseRef(trackRef);
79 
80  LogDebug("ConvBremPFTrackFinder") << "runConvBremFinder:: pushing_back High Purity " << pft->trackRef()->pt()
81  << " eta,phi " << pft->trackRef()->eta() << ", " << pft->trackRef()->phi()
82  << " Memory Address Ref " << &*trackRef << " Memory Address BaseRef "
83  << &*selTrackBaseRef;
84  AllPFRecTracks.push_back(pfRecTrRef);
85  }
86 
87  if (useConversions) {
88  const PFConversionCollection& PfConvColl = *(pfConversions.product());
89  for (unsigned i = 0; i < PfConvColl.size(); i++) {
91 
92  unsigned int trackSize = (convRef->pfTracks()).size();
93  if (convRef->pfTracks().size() < 2)
94  continue;
95  for (unsigned iTk = 0; iTk < trackSize; iTk++) {
96  PFRecTrackRef compPFTkRef = convRef->pfTracks()[iTk];
97  reco::TrackBaseRef newTrackBaseRef(compPFTkRef->trackRef());
98  // do not consider the kf track already associated to the seed
99  if (pfTrackRef.isNonnull()) {
100  reco::TrackBaseRef primaryTrackBaseRef(pfTrackRef->trackRef());
101  if (primaryTrackBaseRef == newTrackBaseRef)
102  continue;
103  }
104  bool notFound = true;
105  for (unsigned iPF = 0; iPF < AllPFRecTracks.size(); iPF++) {
106  reco::TrackBaseRef selTrackBaseRef(AllPFRecTracks[iPF]->trackRef());
107 
108  LogDebug("ConvBremPFTrackFinder")
109  << "## Track 1 HP pt " << AllPFRecTracks[iPF]->trackRef()->pt() << " eta, phi "
110  << AllPFRecTracks[iPF]->trackRef()->eta() << ", " << AllPFRecTracks[iPF]->trackRef()->phi()
111  << " Memory Address Ref " << &(*AllPFRecTracks[iPF]->trackRef()) << " Memory Address BaseRef "
112  << &*selTrackBaseRef;
113  LogDebug("ConvBremPFTrackFinder")
114  << "** Track 2 CONV pt " << compPFTkRef->trackRef()->pt() << " eta, phi "
115  << compPFTkRef->trackRef()->eta() << ", " << compPFTkRef->trackRef()->phi() << " Memory Address Ref "
116  << &*compPFTkRef->trackRef() << " Memory Address BaseRef " << &*newTrackBaseRef;
117  //if(selTrackBaseRef == newTrackBaseRef || AllPFRecTracks[iPF]->trackRef()== compPFTkRef->trackRef()) {
118  if (AllPFRecTracks[iPF]->trackRef() == compPFTkRef->trackRef()) {
119  LogDebug("ConvBremPFTrackFinder") << " SAME BREM REF " << endl;
120  notFound = false;
121  }
122  }
123  if (notFound) {
124  LogDebug("ConvBremPFTrackFinder")
125  << "runConvBremFinder:: pushing_back Conversions " << compPFTkRef->trackRef()->pt() << " eta,phi "
126  << compPFTkRef->trackRef()->eta() << " phi " << compPFTkRef->trackRef()->phi();
127  AllPFRecTracks.push_back(compPFTkRef);
128  }
129  }
130  }
131  }
132 
133  if (useNuclear) {
134  const PFDisplacedTrackerVertexCollection& PfNuclColl = *(pfNuclears.product());
135  for (unsigned i = 0; i < PfNuclColl.size(); i++) {
136  const reco::PFDisplacedTrackerVertexRef dispacedVertexRef(pfNuclears, i);
137  unsigned int trackSize = dispacedVertexRef->pfRecTracks().size();
138  for (unsigned iTk = 0; iTk < trackSize; iTk++) {
139  reco::PFRecTrackRef newPFRecTrackRef = dispacedVertexRef->pfRecTracks()[iTk];
140  reco::TrackBaseRef newTrackBaseRef(newPFRecTrackRef->trackRef());
141  // do not consider the kf track already associated to the seed
142  if (pfTrackRef.isNonnull()) {
143  reco::TrackBaseRef primaryTrackBaseRef(pfTrackRef->trackRef());
144  if (primaryTrackBaseRef == newTrackBaseRef)
145  continue;
146  }
147  bool notFound = true;
148  for (unsigned iPF = 0; iPF < AllPFRecTracks.size(); iPF++) {
149  reco::TrackBaseRef selTrackBaseRef(AllPFRecTracks[iPF]->trackRef());
150  if (selTrackBaseRef == newTrackBaseRef)
151  notFound = false;
152  }
153  if (notFound) {
154  LogDebug("ConvBremPFTrackFinder")
155  << "runConvBremFinder:: pushing_back displaced Vertex pt " << newPFRecTrackRef->trackRef()->pt()
156  << " eta,phi " << newPFRecTrackRef->trackRef()->eta() << ", " << newPFRecTrackRef->trackRef()->phi();
157  AllPFRecTracks.push_back(newPFRecTrackRef);
158  }
159  }
160  }
161  }
162 
163  if (useV0) {
164  const PFV0Collection& PfV0Coll = *(pfV0.product());
165  for (unsigned i = 0; i < PfV0Coll.size(); i++) {
166  reco::PFV0Ref v0Ref(pfV0, i);
167  unsigned int trackSize = (v0Ref->pfTracks()).size();
168  for (unsigned iTk = 0; iTk < trackSize; iTk++) {
169  reco::PFRecTrackRef newPFRecTrackRef = (v0Ref->pfTracks())[iTk];
170  reco::TrackBaseRef newTrackBaseRef(newPFRecTrackRef->trackRef());
171  // do not consider the kf track already associated to the seed
172  if (pfTrackRef.isNonnull()) {
173  reco::TrackBaseRef primaryTrackBaseRef(pfTrackRef->trackRef());
174  if (primaryTrackBaseRef == newTrackBaseRef)
175  continue;
176  }
177  bool notFound = true;
178  for (unsigned iPF = 0; iPF < AllPFRecTracks.size(); iPF++) {
179  reco::TrackBaseRef selTrackBaseRef(AllPFRecTracks[iPF]->trackRef());
180  if (selTrackBaseRef == newTrackBaseRef)
181  notFound = false;
182  }
183  if (notFound) {
184  LogDebug("ConvBremPFTrackFinder")
185  << "runConvBremFinder:: pushing_back V0 " << newPFRecTrackRef->trackRef()->pt() << " eta,phi "
186  << newPFRecTrackRef->trackRef()->eta() << ", " << newPFRecTrackRef->trackRef()->phi();
187  AllPFRecTracks.push_back(newPFRecTrackRef);
188  }
189  }
190  }
191  }
192 
193  pfRecTrRef_vec_.clear();
194 
195  for (unsigned iPF = 0; iPF < AllPFRecTracks.size(); iPF++) {
196  double dphi = std::abs(::deltaPhi(AllPFRecTracks[iPF]->trackRef()->phi(), refGsfPhi));
197  double deta = std::abs(AllPFRecTracks[iPF]->trackRef()->eta() - refGsfEta);
198 
199  // limiting the phase space (just for saving cpu-time)
200  if (std::abs(dphi) > 1.0 || std::abs(deta) > 0.4)
201  continue;
202 
203  double minDEtaBremKF = std::numeric_limits<double>::max();
204  double minDPhiBremKF = std::numeric_limits<double>::max();
205  double minDRBremKF2 = std::numeric_limits<double>::max();
206  double minDEtaBremKFPos = std::numeric_limits<double>::max();
207  double minDPhiBremKFPos = std::numeric_limits<double>::max();
208  double minDRBremKFPos2 = std::numeric_limits<double>::max();
209  reco::TrackRef trkRef = AllPFRecTracks[iPF]->trackRef();
210 
211  double secEta = trkRef->innerMomentum().eta();
212  double secPhi = trkRef->innerMomentum().phi();
213 
214  double posEta = trkRef->innerPosition().eta();
215  double posPhi = trkRef->innerPosition().phi();
216 
217  for (unsigned ipbrem = 0; ipbrem < primPFBrem.size(); ipbrem++) {
218  if (primPFBrem[ipbrem].indTrajPoint() == 99)
219  continue;
220  const reco::PFTrajectoryPoint& atPrimECAL =
221  primPFBrem[ipbrem].extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance);
222  if (!atPrimECAL.isValid())
223  continue;
224  double bremEta = atPrimECAL.momentum().Eta();
225  double bremPhi = atPrimECAL.momentum().Phi();
226 
227  double deta = std::abs(bremEta - secEta);
228  double dphi = std::abs(::deltaPhi(bremPhi, secPhi));
229  double DR2 = deta * deta + dphi * dphi;
230 
231  double detaPos = std::abs(bremEta - posEta);
232  double dphiPos = std::abs(::deltaPhi(bremPhi, posPhi));
233  double DRPos2 = detaPos * detaPos + dphiPos * dphiPos;
234 
235  // find the closest track tangent
236  if (DR2 < minDRBremKF2) {
237  minDRBremKF2 = DR2;
238  minDEtaBremKF = deta;
239  minDPhiBremKF = std::abs(dphi);
240  }
241 
242  if (DRPos2 < minDRBremKFPos2) {
243  minDRBremKFPos2 = DRPos2;
244  minDEtaBremKFPos = detaPos;
245  minDPhiBremKFPos = std::abs(dphiPos);
246  }
247  }
248 
249  // secR
250  secR = sqrt(trkRef->innerPosition().x() * trkRef->innerPosition().x() +
251  trkRef->innerPosition().y() * trkRef->innerPosition().y());
252 
253  // apply loose selection (to be parallel) between the secondary track and brem-tangents.
254  // Moreover if the secR is internal with respect to the GSF track by two pixel layers discard it.
255  if ((minDPhiBremKF < 0.1 || minDPhiBremKFPos < 0.1) && (minDEtaBremKF < 0.02 || minDEtaBremKFPos < 0.02) &&
256  secR > (gsfR - 8)) {
257  LogDebug("ConvBremPFTrackFinder") << "runConvBremFinder:: OK Find track and BREM close "
258  << " MinDphi " << minDPhiBremKF << " MinDeta " << minDEtaBremKF;
259 
260  float MinDist = std::numeric_limits<float>::max();
261  float EE_calib = 0.;
262  PFRecTrack pfrectrack = *AllPFRecTracks[iPF];
263  // Find and ECAL associated cluster
264  for (PFClusterCollection::const_iterator clus = theEClus.begin(); clus != theEClus.end(); clus++) {
265  // Removed unusd variable, left this in case it has side effects
266  clus->position();
267  double dist = -1.;
268  PFCluster clust = *clus;
269  clust.calculatePositionREP();
271  ? LinkByRecHit::testTrackAndClusterByRecHit(pfrectrack, clust)
272  : -1.;
273 
274  if (dist > 0. && dist < MinDist) {
275  MinDist = dist;
276  EE_calib = cache->pfcalib_->energyEm(*clus, 0.0, 0.0, false);
277  }
278  }
279  if (MinDist > 0. && MinDist < 100000.) {
280  // compute all the input variables for conv brem selection
281 
282  secPout = sqrt(trkRef->outerMomentum().x() * trkRef->outerMomentum().x() +
283  trkRef->outerMomentum().y() * trkRef->outerMomentum().y() +
284  trkRef->outerMomentum().z() * trkRef->outerMomentum().z());
285 
286  secPin = sqrt(trkRef->innerMomentum().x() * trkRef->innerMomentum().x() +
287  trkRef->innerMomentum().y() * trkRef->innerMomentum().y() +
288  trkRef->innerMomentum().z() * trkRef->innerMomentum().z());
289 
290  // maybe put innter momentum pt?
291  ptRatioGsfKF = trkRef->pt() / refGsfPtMode;
292 
293  Vertex dummy;
294  const Vertex* pv = &dummy;
296  if (!primaryVertex->empty()) {
297  pv = &*primaryVertex->begin();
298  // we always use the first vertex (at the moment)
300  } else { // create a dummy PV
302  e(0, 0) = 0.0015 * 0.0015;
303  e(1, 1) = 0.0015 * 0.0015;
304  e(2, 2) = 15. * 15.;
305  Vertex::Point p(0, 0, 0);
306  dummy = Vertex(p, e, 0, 0, 0);
307  }
308 
309  TransientTrack transientTrack = builder_.build(*trkRef);
310  sTIP = IPTools::signedTransverseImpactParameter(transientTrack, direction, *pv).second.significance();
311 
312  Epout = EE_calib / secPout;
313 
314  // eta distance brem-secondary kf track
315  detaBremKF = minDEtaBremKF;
316 
317  // Number of commont hits
318  unsigned int tmpSh = 0;
319  //uint ish=0;
320  int kfhitcounter = 0;
321  for (auto const& nhit : refGsf->recHits())
322  if (nhit->isValid()) {
323  kfhitcounter = 0;
324  for (auto const& ihit : trkRef->recHits())
325  if (ihit->isValid()) {
326  // method 1
327  if (nhit->sharesInput(ihit, TrackingRecHit::all))
328  tmpSh++;
329  kfhitcounter++;
330  // method 2 to switch in case of problem with rechit collections
331  // if((ihit->geographicalId()==nhit->geographicalId())&&
332  // ((nhit->localPosition()-ihit->localPosition()).mag()<0.01)) ish++;
333  }
334  }
335 
336  nHITS1 = tmpSh;
337 
338  double mvaValue = -10;
339  double cutvalue = -10;
340 
341  float vars[6] = {secR, sTIP, nHITS1, Epout, detaBremKF, ptRatioGsfKF};
342  if (refGsfPt < 20 && std::abs(refGsfEta) < 1.479) {
343  mvaValue = cache->gbrBarrelLowPt_->GetClassifier(vars);
344  cutvalue = mvaBremConvCutBarrelLowPt_;
345  }
346  if (refGsfPt > 20 && std::abs(refGsfEta) < 1.479) {
347  mvaValue = cache->gbrBarrelHighPt_->GetClassifier(vars);
348  cutvalue = mvaBremConvCutBarrelHighPt_;
349  }
350  if (refGsfPt < 20 && std::abs(refGsfEta) > 1.479) {
351  mvaValue = cache->gbrEndcapsLowPt_->GetClassifier(vars);
352  cutvalue = mvaBremConvCutEndcapsLowPt_;
353  }
354  if (refGsfPt > 20 && std::abs(refGsfEta) > 1.479) {
355  mvaValue = cache->gbrEndcapsHighPt_->GetClassifier(vars);
356  cutvalue = mvaBremConvCutEndcapsHighPt_;
357  }
358 
359  LogDebug("ConvBremPFTrackFinder") << "Gsf track Pt, Eta " << refGsfPt << " " << refGsfEta;
360  LogDebug("ConvBremPFTrackFinder") << "Cutvalue " << cutvalue;
361 
362  if ((kfhitcounter - nHITS1) <= 3 && nHITS1 > 3)
363  mvaValue = 2; // this means duplicates tracks, very likely not physical
364 
365  LogDebug("ConvBremPFTrackFinder")
366  << " The input variables for conv brem tracks identification "
367  << " secR " << secR << " gsfR " << gsfR << " N shared hits " << nHITS1 << " sTIP " << sTIP
368  << " detaBremKF " << detaBremKF << " E/pout " << Epout << " ptRatioKFGsf " << ptRatioGsfKF
369  << " ***** MVA ***** " << mvaValue;
370 
371  if (mvaValue > cutvalue) {
372  found_ = true;
373  pfRecTrRef_vec_.push_back(AllPFRecTracks[iPF]);
374  }
375  } // end MinDIST
376  } // end selection kf - brem tangents
377  } // loop on the kf tracks
378 }
size
Write out results.
reconstructed track used as an input to particle flow
Definition: PFRecTrack.h:20
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:42
vars
Definition: DeepTauIdBase.h:60
const math::XYZTLorentzVector & momentum() const
4-momenta quadrivector
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:57
T const * product() const
Definition: Handle.h:70
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:45
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
std::vector< PFConversion > PFConversionCollection
collection of PFConversion objects
void runConvBremFinder(const edm::Handle< reco::PFRecTrackCollection > &thePfRecTrackCol, const edm::Handle< reco::VertexCollection > &primaryVertex, const edm::Handle< reco::PFDisplacedTrackerVertexCollection > &pfNuclears, const edm::Handle< reco::PFConversionCollection > &pfConversions, const edm::Handle< reco::PFV0Collection > &pfV0, const convbremhelpers::HeavyObjectCache *cache, bool useNuclear, bool useConversions, bool useV0, const reco::PFClusterCollection &theEClus, const reco::GsfPFRecTrack &gsfpfrectk)
reco::TransientTrack build(const reco::Track *p) const
bool isValid() const
is this point valid ?
void calculatePositionREP()
computes posrep_ once and for all
Definition: PFCluster.h:95
const edm::Ref< std::vector< PFRecTrack > > & kfPFRecTrackRef() const
Definition: GsfPFRecTrack.h:37
T sqrt(T t)
Definition: SSEVec.h:19
TransientTrackBuilder builder_
const std::vector< reco::PFBrem > & PFRecBrem() const
Definition: GsfPFRecTrack.h:45
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< reco::PFRecTrackRef > pfRecTrRef_vec_
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
std::vector< PFV0 > PFV0Collection
collection of PFV0 objects
Definition: PFV0Fwd.h:9
const reco::PFTrajectoryPoint & extrapolatedPoint(unsigned layerid) const
Definition: PFTrack.cc:46
static const GlobalPoint notFound(0, 0, 0)
ConvBremPFTrackFinder(const TransientTrackBuilder &builder, double mvaBremConvCutBarrelLowPt, double mvaBremConvCutBarrelHighPt, double mvaBremConvCutEndcapsLowPt, double mvaBremConvCutEndcapsHighPt)
fixed size matrix
HLT enums.
const reco::GsfTrackRef & gsfTrackRef() const
Definition: GsfPFRecTrack.h:34
def cache(function)
Definition: utilities.py:3
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
Definition: PFClusterFwd.h:9
A PFTrack holds several trajectory points, which basically contain the position and momentum of a tra...
primaryVertex
hltOfflineBeamSpot for HLTMON
static double testTrackAndClusterByRecHit(const reco::PFRecTrack &track, const reco::PFCluster &cluster, bool isBrem=false, bool debug=false)
Definition: LinkByRecHit.cc:18
std::vector< PFRecTrack > PFRecTrackCollection
collection of PFRecTrack objects
Definition: PFRecTrackFwd.h:9
std::vector< PFDisplacedTrackerVertex > PFDisplacedTrackerVertexCollection
collection of DisplacedTrackerVertexs
#define LogDebug(id)