CMS 3D CMS Logo

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