CMS 3D CMS Logo

PATIsolatedTrackProducer.cc
Go to the documentation of this file.
1 #include <string>
2 
10 
12 
29 
33 
39 
41 
42 namespace pat {
43 
45  public:
48 
50  ~PATIsolatedTrackProducer() override;
51 
52  void produce(edm::Event&, const edm::EventSetup&) override;
53 
54  // compute iso/miniiso
55  void getIsolation(const PolarLorentzVector& p4, const pat::PackedCandidateCollection* pc, int pc_idx,
56  pat::PFIsolation &iso, pat::PFIsolation &miniiso) const;
57 
58  bool getPFLeptonOverlap(const PolarLorentzVector& p4, const pat::PackedCandidateCollection* pc) const;
59 
60  float getPFNeutralSum(const PolarLorentzVector& p4, const pat::PackedCandidateCollection* pc, int pc_idx) const;
61 
62  void getNearestPCRef(const PolarLorentzVector& p4, const pat::PackedCandidateCollection *pc, int pc_idx, int& pc_ref_idx) const;
63 
64  float getDeDx(const reco::DeDxHitInfo *hitInfo, bool doPixel, bool doStrip) const ;
65 
67 
68  void getCaloJetEnergy(const PolarLorentzVector&, const reco::CaloJetCollection*, float&, float&) const;
69 
70  private:
86  const float pT_cut_; // only save cands with pT>pT_cut_
87  const float pT_cut_noIso_; // above this pT, don't apply any iso cut
88  const float pfIsolation_DR_; // isolation radius
89  const float pfIsolation_DZ_; // used in determining if pfcand is from PV or PU
90  const float absIso_cut_; // save if ANY of absIso, relIso, or miniRelIso pass the cuts
91  const float relIso_cut_;
92  const float miniRelIso_cut_;
93  const float caloJet_DR_; // save energy of nearest calojet within caloJet_DR_
94  const float pflepoverlap_DR_; // pf lepton overlap radius
95  const float pflepoverlap_pTmin_; // pf lepton overlap min pT (only look at PF candidates with pT>pflepoverlap_pTmin_)
96  const float pcRefNearest_DR_; // radius for nearest charged packed candidate
97  const float pcRefNearest_pTmin_; // min pT for nearest charged packed candidate
98  const float pfneutralsum_DR_; // pf lepton overlap radius
99  const bool saveDeDxHitInfo_;
101 
102  std::vector<double> miniIsoParams_;
103 
106  };
107 }
108 
110  pc_(consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
111  lt_(consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("lostTracks"))),
112  gt_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("generalTracks"))),
113  pv_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("primaryVertices"))),
114  gt2pc_(consumes<edm::Association<pat::PackedCandidateCollection> >(iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
115  gt2lt_(consumes<edm::Association<pat::PackedCandidateCollection> >(iConfig.getParameter<edm::InputTag>("lostTracks"))),
116  pc2pf_(consumes<edm::Association<reco::PFCandidateCollection> >(iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
117  caloJets_(consumes<reco::CaloJetCollection>(iConfig.getParameter<edm::InputTag>("caloJets"))),
118  gt2dedxStrip_(consumes<edm::ValueMap<reco::DeDxData> >(iConfig.getParameter<edm::InputTag>("dEdxDataStrip"))),
119  gt2dedxPixel_(consumes<edm::ValueMap<reco::DeDxData> >(iConfig.getParameter<edm::InputTag>("dEdxDataPixel"))),
120  gt2dedxHitInfo_(consumes<reco::DeDxHitInfoAss>(iConfig.getParameter<edm::InputTag>("dEdxHitInfo"))),
121  addPrescaledDeDxTracks_(iConfig.getParameter<bool>("addPrescaledDeDxTracks")),
122  gt2dedxHitInfoPrescale_(addPrescaledDeDxTracks_ ? consumes<edm::ValueMap<int>>(iConfig.getParameter<edm::InputTag>("dEdxHitInfoPrescale")) : edm::EDGetTokenT<edm::ValueMap<int>>()),
123  usePrecomputedDeDxStrip_(iConfig.getParameter<bool>("usePrecomputedDeDxStrip")),
124  usePrecomputedDeDxPixel_(iConfig.getParameter<bool>("usePrecomputedDeDxPixel")),
125  pT_cut_ (iConfig.getParameter<double>("pT_cut")),
126  pT_cut_noIso_ (iConfig.getParameter<double>("pT_cut_noIso")),
127  pfIsolation_DR_ (iConfig.getParameter<double>("pfIsolation_DR")),
128  pfIsolation_DZ_ (iConfig.getParameter<double>("pfIsolation_DZ")),
129  absIso_cut_ (iConfig.getParameter<double>("absIso_cut")),
130  relIso_cut_ (iConfig.getParameter<double>("relIso_cut")),
131  miniRelIso_cut_ (iConfig.getParameter<double>("miniRelIso_cut")),
132  caloJet_DR_ (iConfig.getParameter<double>("caloJet_DR")),
133  pflepoverlap_DR_ (iConfig.getParameter<double>("pflepoverlap_DR")),
134  pflepoverlap_pTmin_ (iConfig.getParameter<double>("pflepoverlap_pTmin")),
135  pcRefNearest_DR_ (iConfig.getParameter<double>("pcRefNearest_DR")),
136  pcRefNearest_pTmin_ (iConfig.getParameter<double>("pcRefNearest_pTmin")),
137  pfneutralsum_DR_ (iConfig.getParameter<double>("pfneutralsum_DR")),
138  saveDeDxHitInfo_(iConfig.getParameter<bool>("saveDeDxHitInfo")),
139  saveDeDxHitInfoCut_(iConfig.getParameter<std::string>("saveDeDxHitInfoCut"))
140 {
141  // TrackAssociator parameters
142  edm::ParameterSet parameters = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
143  edm::ConsumesCollector iC = consumesCollector();
144  trackAssocParameters_.loadParameters( parameters, iC );
145 
147 
148  miniIsoParams_ = iConfig.getParameter<std::vector<double> >("miniIsoParams");
149  if(miniIsoParams_.size() != 3)
150  throw cms::Exception("ParameterError") << "miniIsoParams must have exactly 3 elements.\n";
151 
152  produces< pat::IsolatedTrackCollection > ();
153 
154  if (saveDeDxHitInfo_) {
155  produces<reco::DeDxHitInfoCollection>();
156  produces<reco::DeDxHitInfoAss>();
157  }
158 }
159 
161 
163 
164  // packedPFCandidate collection
166  iEvent.getByToken( pc_, pc_h );
167  const pat::PackedCandidateCollection *pc = pc_h.product();
168 
169  // lostTracks collection
171  iEvent.getByToken( lt_, lt_h );
172  const pat::PackedCandidateCollection *lt = lt_h.product();
173 
174  // generalTracks collection
176  iEvent.getByToken( gt_, gt_h );
178 
179  // get the primary vertex
181  iEvent.getByToken( pv_, pvs );
182  const reco::Vertex & pv = (*pvs)[0];
183 
184  // generalTracks-->packedPFCandidate association
186  iEvent.getByToken(gt2pc_, gt2pc);
187 
188  // generalTracks-->lostTracks association
190  iEvent.getByToken(gt2lt_, gt2lt);
191 
192  // packedPFCandidates-->particleFlow(reco::PFCandidate) association
194  iEvent.getByToken(pc2pf_, pc2pf);
195 
197  iEvent.getByToken(caloJets_, caloJets);
198 
199  // associate generalTracks with their DeDx data (estimator for strip dE/dx)
201  iEvent.getByToken(gt2dedxStrip_, gt2dedxStrip);
202 
203  // associate generalTracks with their DeDx data (estimator for pixel dE/dx)
205  iEvent.getByToken(gt2dedxPixel_, gt2dedxPixel);
206 
207  // associate generalTracks with their DeDx hit info (used to estimate pixel dE/dx)
208  edm::Handle<reco::DeDxHitInfoAss> gt2dedxHitInfo;
209  iEvent.getByToken(gt2dedxHitInfo_, gt2dedxHitInfo);
210  edm::Handle<edm::ValueMap<int>> gt2dedxHitInfoPrescale;
212  iEvent.getByToken(gt2dedxHitInfoPrescale_, gt2dedxHitInfoPrescale);
213  }
214 
216  iSetup.get<HcalChannelQualityRcd>().get("withTopo", hcalQ_h);
217  const HcalChannelQuality *hcalQ = hcalQ_h.product();
218 
220  iSetup.get<EcalChannelStatusRcd>().get(ecalS_h);
221  const EcalChannelStatus *ecalS = ecalS_h.product();
222 
223  auto outDeDxC = std::make_unique<reco::DeDxHitInfoCollection>();
224  std::vector<int> dEdXass;
225 
226  auto outPtrP = std::make_unique<std::vector<pat::IsolatedTrack>>();
227 
228  //add general tracks
229  for(unsigned int igt=0; igt<generalTracks->size(); igt++){
230  const reco::Track &gentk = (*gt_h)[igt];
231  reco::TrackRef tkref = reco::TrackRef(gt_h, igt);
232  pat::PackedCandidateRef pcref = (*gt2pc)[tkref];
233  pat::PackedCandidateRef ltref = (*gt2lt)[tkref];
234  const pat::PackedCandidate & pfCand = *(pcref.get());
235  const pat::PackedCandidate & lostTrack = *(ltref.get());
236 
237  // Determine if this general track is associated with anything in packedPFCandidates or lostTracks
238  // Sometimes, a track gets associated w/ a neutral pfCand.
239  // In this case, ignore the pfCand and take from lostTracks
240  bool isInPackedCands = (pcref.isNonnull() && pcref.id()==pc_h.id() && pfCand.charge()!=0);
241  bool isInLostTracks = (ltref.isNonnull() && ltref.id()==lt_h.id());
242 
243  PolarLorentzVector polarP4;
245  pat::PackedCandidateRef refToCand;
246  int pdgId, charge, fromPV;
247  float dz, dxy, dzError, dxyError;
248  int pfCandInd; //to avoid counting packedPFCands in their own isolation
249  int ltCandInd; //to avoid pointing lost track to itself when looking for closest
250 
251  // get the four-momentum and charge
252  if(isInPackedCands){
253  p4 = pfCand.p4();
254  polarP4 = pfCand.polarP4();
255  charge = pfCand.charge();
256  pfCandInd = pcref.key();
257  ltCandInd = -1;
258  }else if(isInLostTracks){
259  p4 = lostTrack.p4();
260  polarP4 = lostTrack.polarP4();
261  charge = lostTrack.charge();
262  pfCandInd = -1;
263  ltCandInd = ltref.key();
264  }else{
265  double m = 0.13957018; //assume pion mass
266  double E = sqrt(m*m + gentk.p()*gentk.p());
267  p4.SetPxPyPzE(gentk.px(), gentk.py(), gentk.pz(), E);
268  polarP4.SetCoordinates(gentk.pt(), gentk.eta(), gentk.phi(), m);
269  charge = gentk.charge();
270  pfCandInd = -1;
271  ltCandInd = -1;
272  }
273 
274  int prescaled = 0;
276  const auto &dedxRef = (*gt2dedxHitInfo)[tkref];
277  if (dedxRef.isNonnull()) {
278  prescaled = (*gt2dedxHitInfoPrescale)[dedxRef];
279  }
280  }
281 
282  if(polarP4.pt() < pT_cut_ && prescaled <= 1)
283  continue;
284  if(charge == 0)
285  continue;
286 
287  // get the isolation of the track
288  pat::PFIsolation isolationDR03;
289  pat::PFIsolation miniIso;
290  getIsolation(polarP4, pc, pfCandInd, isolationDR03, miniIso);
291 
292  // isolation cut
293  if( polarP4.pt() < pT_cut_noIso_ && prescaled <= 1 &&
294  !(isolationDR03.chargedHadronIso() < absIso_cut_ ||
295  isolationDR03.chargedHadronIso()/polarP4.pt() < relIso_cut_ ||
296  miniIso.chargedHadronIso()/polarP4.pt() < miniRelIso_cut_))
297  continue;
298 
299  // get the rest after the pt/iso cuts. Saves some runtime
300  if(isInPackedCands){
301  pdgId = pfCand.pdgId();
302  dz = pfCand.dz();
303  dxy = pfCand.dxy();
304  dzError = pfCand.hasTrackDetails() ? pfCand.dzError() : gentk.dzError();
305  dxyError = pfCand.hasTrackDetails() ? pfCand.dxyError() : gentk.dxyError();
306  fromPV = pfCand.fromPV();
307  refToCand = pcref;
308  }else if(isInLostTracks){
309  pdgId = lostTrack.pdgId();
310  dz = lostTrack.dz();
311  dxy = lostTrack.dxy();
312  dzError = lostTrack.hasTrackDetails() ? lostTrack.dzError() : gentk.dzError();
313  dxyError = lostTrack.hasTrackDetails() ? lostTrack.dxyError() : gentk.dxyError();
314  fromPV = lostTrack.fromPV();
315  refToCand = ltref;
316  }else{
317  pdgId = 0;
318  dz = gentk.dz(pv.position());
319  dxy = gentk.dxy(pv.position());
320  dzError = gentk.dzError();
321  dxyError = gentk.dxyError();
322  fromPV = -1;
323  refToCand = pat::PackedCandidateRef(); //NULL reference
324  }
325 
326  float caloJetEm, caloJetHad;
327  getCaloJetEnergy(polarP4, caloJets.product(), caloJetEm, caloJetHad);
328 
329  bool pfLepOverlap = getPFLeptonOverlap(polarP4, pc);
330  float pfNeutralSum = getPFNeutralSum(polarP4, pc, pfCandInd);
331 
333  int refToNearestPF_idx=-1;
334  getNearestPCRef(polarP4, pc, pfCandInd, refToNearestPF_idx);
335  if(refToNearestPF_idx!=-1)
336  refToNearestPF = pat::PackedCandidateRef(pc_h, refToNearestPF_idx);
337 
338  pat::PackedCandidateRef refToNearestLostTrack = pat::PackedCandidateRef();
339  int refToNearestLostTrack_idx=-1;
340  getNearestPCRef(polarP4, lt, ltCandInd, refToNearestLostTrack_idx);
341  if(refToNearestLostTrack_idx!=-1)
342  refToNearestLostTrack = pat::PackedCandidateRef(lt_h, refToNearestLostTrack_idx);
343 
344  // if no dEdx info exists, just store -1
345  float dEdxPixel=-1, dEdxStrip=-1;
346  if(usePrecomputedDeDxStrip_ && gt2dedxStrip.isValid() && gt2dedxStrip->contains(tkref.id())){
347  dEdxStrip = (*gt2dedxStrip)[tkref].dEdx();
348  }else if(gt2dedxHitInfo.isValid() && gt2dedxHitInfo->contains(tkref.id())){
349  const reco::DeDxHitInfo* hitInfo = (*gt2dedxHitInfo)[tkref].get();
350  dEdxStrip = getDeDx(hitInfo, false, true);
351  }
352  if(usePrecomputedDeDxPixel_ && gt2dedxPixel.isValid() && gt2dedxPixel->contains(tkref.id())){
353  dEdxPixel = (*gt2dedxPixel)[tkref].dEdx();
354  }else if(gt2dedxHitInfo.isValid() && gt2dedxHitInfo->contains(tkref.id())){
355  const reco::DeDxHitInfo* hitInfo = (*gt2dedxHitInfo)[tkref].get();
356  dEdxPixel = getDeDx(hitInfo, true, false);
357  }
358 
359  int trackQuality = gentk.qualityMask();
360 
361  // get the associated ecal/hcal detectors
362  TrackDetMatchInfo trackDetInfo = getTrackDetMatchInfo(iEvent, iSetup, gentk);
363 
364  // fill ecal/hcal status vectors
365  std::vector<uint32_t> crossedHcalStatus;
366  for(auto const & did : trackDetInfo.crossedHcalIds){
367  crossedHcalStatus.push_back(hcalQ->getValues(did.rawId())->getValue());
368  }
369  std::vector<uint16_t> crossedEcalStatus;
370  for(auto const & did : trackDetInfo.crossedEcalIds){
371  crossedEcalStatus.push_back(ecalS->find(did.rawId())->getStatusCode());
372  }
373 
374  int deltaEta = int((trackDetInfo.trkGlobPosAtEcal.eta() - gentk.eta())/0.5 * 250);
375  int deltaPhi = int((trackDetInfo.trkGlobPosAtEcal.phi() - gentk.phi())/0.5 * 250);
376  if(deltaEta < -250) deltaEta = -250;
377  if(deltaEta > 250) deltaEta = 250;
378  if(deltaPhi < -250) deltaPhi = -250;
379  if(deltaPhi > 250) deltaPhi = 250;
380 
381  outPtrP->push_back(pat::IsolatedTrack(isolationDR03, miniIso, caloJetEm, caloJetHad, pfLepOverlap, pfNeutralSum, p4,
382  charge, pdgId, dz, dxy, dzError, dxyError,
383  gentk.hitPattern(), dEdxStrip, dEdxPixel, fromPV, trackQuality,
384  crossedEcalStatus, crossedHcalStatus,
385  deltaEta, deltaPhi, refToCand,
386  refToNearestPF, refToNearestLostTrack));
387  outPtrP->back().setStatus(prescaled);
388 
389  if (saveDeDxHitInfo_) {
390  const auto &dedxRef = (*gt2dedxHitInfo)[tkref];
391  if (saveDeDxHitInfoCut_(outPtrP->back()) && dedxRef.isNonnull()) {
392  outDeDxC->push_back( *dedxRef );
393  dEdXass.push_back(outDeDxC->size()-1);
394  } else {
395  dEdXass.push_back(-1);
396  }
397  }
398 
399  }
400 
401  // there are some number of pfcandidates with no associated track
402  // (mostly electrons, with a handful of muons)
403  // here we find these and store. Track-specific variables get some default values
404  for(unsigned int ipc=0; ipc<pc->size(); ipc++){
405  const pat::PackedCandidate& pfCand = pc->at(ipc);
407  reco::PFCandidateRef pfref = (*pc2pf)[pcref];
408 
409  // already counted if it has a track reference in the generalTracks collection
410  if(pfref.get()->trackRef().isNonnull() && pfref.get()->trackRef().id() == gt_h.id())
411  continue;
412 
413  PolarLorentzVector polarP4;
414  pat::PackedCandidateRef refToCand;
415  int pdgId, charge, fromPV;
416  float dz, dxy, dzError, dxyError;
417 
418  polarP4 = pfCand.polarP4();
419  charge = pfCand.charge();
420 
421  if(polarP4.pt() < pT_cut_)
422  continue;
423  if(charge == 0)
424  continue;
425 
426  // get the isolation of the track
427  pat::PFIsolation isolationDR03;
428  pat::PFIsolation miniIso;
429  getIsolation(polarP4, pc, ipc, isolationDR03, miniIso);
430 
431  // isolation cut
432  if( polarP4.pt() < pT_cut_noIso_ &&
433  !(isolationDR03.chargedHadronIso() < absIso_cut_ ||
434  isolationDR03.chargedHadronIso()/polarP4.pt() < relIso_cut_ ||
435  miniIso.chargedHadronIso()/polarP4.pt() < miniRelIso_cut_))
436  continue;
437 
438  pdgId = pfCand.pdgId();
439  dz = pfCand.dz();
440  dxy = pfCand.dxy();
441  if (pfCand.hasTrackDetails()){
442  dzError = pfCand.dzError();
443  dxyError = pfCand.dxyError();
444  } else {
445  dzError = 0;
446  dxyError = 0;
447  }
448  fromPV = pfCand.fromPV();
449  refToCand = pcref;
450 
451  float caloJetEm, caloJetHad;
452  getCaloJetEnergy(polarP4, caloJets.product(), caloJetEm, caloJetHad);
453 
454  bool pfLepOverlap = getPFLeptonOverlap(polarP4, pc);
455  float pfNeutralSum = getPFNeutralSum(polarP4, pc, ipc);
456 
458  int refToNearestPF_idx=-1;
459  getNearestPCRef(polarP4, pc, ipc, refToNearestPF_idx);
460  if(refToNearestPF_idx!=-1)
461  refToNearestPF = pat::PackedCandidateRef(pc_h, refToNearestPF_idx);
462 
463  pat::PackedCandidateRef refToNearestLostTrack = pat::PackedCandidateRef();
464  int refToNearestLostTrack_idx=-1;
465  getNearestPCRef(polarP4, lt, -1, refToNearestLostTrack_idx);
466  if(refToNearestLostTrack_idx!=-1)
467  refToNearestLostTrack = pat::PackedCandidateRef(lt_h, refToNearestLostTrack_idx);
468 
469  // fill with default values
471  float dEdxPixel=-1, dEdxStrip=-1;
472  int trackQuality=0;
473  std::vector<uint16_t> ecalStatus;
474  std::vector<uint32_t> hcalStatus;
475  int deltaEta=0;
476  int deltaPhi=0;
477 
478  outPtrP->push_back(pat::IsolatedTrack(isolationDR03, miniIso, caloJetEm, caloJetHad, pfLepOverlap, pfNeutralSum, pfCand.p4(),
479  charge, pdgId, dz, dxy, dzError, dxyError,
480  hp, dEdxStrip, dEdxPixel, fromPV, trackQuality,
481  ecalStatus, hcalStatus, deltaEta, deltaPhi, refToCand,
482  refToNearestPF, refToNearestLostTrack));
483 
484  dEdXass.push_back(-1); // these never have dE/dx hit info, as there's no track
485  }
486 
487  auto orphHandle = iEvent.put(std::move(outPtrP));
488  if (saveDeDxHitInfo_) {
489  auto dedxOH = iEvent.put(std::move(outDeDxC));
490  auto dedxMatch = std::make_unique<reco::DeDxHitInfoAss>(dedxOH);
492  filler.insert(orphHandle, dEdXass.begin(), dEdXass.end());
493  filler.fill();
494  iEvent.put(std::move(dedxMatch));
495  }
496 
497 }
498 
499 
501  const pat::PackedCandidateCollection *pc, int pc_idx,
502  pat::PFIsolation &iso, pat::PFIsolation &miniiso) const
503 {
504  float chiso=0, nhiso=0, phiso=0, puiso=0; // standard isolation
505  float chmiso=0, nhmiso=0, phmiso=0, pumiso=0; // mini isolation
506  float miniDR = std::max(miniIsoParams_[0], std::min(miniIsoParams_[1], miniIsoParams_[2]/p4.pt()));
507  for(pat::PackedCandidateCollection::const_iterator pf_it = pc->begin(); pf_it != pc->end(); pf_it++){
508  if(int(pf_it - pc->begin()) == pc_idx) //don't count itself
509  continue;
510  int id = std::abs(pf_it->pdgId());
511  bool fromPV = (pf_it->fromPV()>1 || fabs(pf_it->dz()) < pfIsolation_DZ_);
512  float pt = pf_it->p4().pt();
513  float dr = deltaR(p4, *pf_it);
514 
515  if(dr < pfIsolation_DR_){
516  // charged cands from PV get added to trackIso
517  if(id==211 && fromPV)
518  chiso += pt;
519  // charged cands not from PV get added to pileup iso
520  else if(id==211)
521  puiso += pt;
522  // neutral hadron iso
523  if(id==130)
524  nhiso += pt;
525  // photon iso
526  if(id==22)
527  phiso += pt;
528  }
529  // same for mini isolation
530  if(dr < miniDR){
531  if(id == 211 && fromPV)
532  chmiso += pt;
533  else if(id == 211)
534  pumiso += pt;
535  if(id == 130)
536  nhmiso += pt;
537  if(id == 22)
538  phmiso += pt;
539  }
540  }
541 
542  iso = pat::PFIsolation(chiso,nhiso,phiso,puiso);
543  miniiso = pat::PFIsolation(chmiso,nhmiso,phmiso,pumiso);
544 
545 }
546 
547 //get overlap of isolated track with a PF lepton
549 {
550  bool isOverlap = false;
551  float dr_min = pflepoverlap_DR_;
552  int id_drmin = 0;
553  for (const auto & pf : *pc) {
554  int id = std::abs(pf.pdgId());
555  int charge = std::abs(pf.charge());
556  bool fromPV = (pf.fromPV()>1 || std::abs(pf.dz()) < pfIsolation_DZ_);
557  float pt = pf.pt();
558  if(charge==0) // exclude neutral candidates
559  continue;
560  if(!(fromPV)) // exclude candidates not from PV
561  continue;
562  if(pt < pflepoverlap_pTmin_) // exclude pf candidates w/ pT below threshold
563  continue;
564 
565  float dr = deltaR(p4, pf);
566  if(dr > pflepoverlap_DR_) // exclude pf candidates far from isolated track
567  continue;
568 
569  if(dr < dr_min){
570  dr_min = dr;
571  id_drmin = id;
572  }
573 
574  }
575 
576  if(dr_min<pflepoverlap_DR_ && (id_drmin==11 || id_drmin==13))
577  isOverlap = true;
578 
579  return isOverlap;
580 }
581 
582 //get ref to nearest pf packed candidate
584 {
585  float dr_min = pcRefNearest_DR_;
586  float dr_min_pu = pcRefNearest_DR_;
587  int pc_ref_idx_pu=-1;
588  for(pat::PackedCandidateCollection::const_iterator pf_it = pc->begin(); pf_it != pc->end(); pf_it++){
589  if(int(pf_it - pc->begin()) == pc_idx) //don't count itself
590  continue;
591  int charge = std::abs(pf_it->charge());
592  bool fromPV = (pf_it->fromPV()>1 || fabs(pf_it->dz()) < pfIsolation_DZ_);
593  float pt = pf_it->p4().pt();
594  float dr = deltaR(p4, *pf_it);
595  if(charge==0) // exclude neutral candidates
596  continue;
597  if(pt < pcRefNearest_pTmin_) // exclude candidates w/ pT below threshold
598  continue;
599  if(dr > dr_min && dr > dr_min_pu) // exclude too far candidates
600  continue;
601 
602  if(fromPV){ // Priority to candidates from PV
603  if(dr < dr_min){
604  dr_min = dr;
605  pc_ref_idx = int(pf_it - pc->begin());
606  }
607  }
608  else{ // Otherwise, store candidate from non-PV if no candidate from PV found
609  if(dr < dr_min_pu){
610  dr_min_pu = dr;
611  pc_ref_idx_pu = int(pf_it - pc->begin());
612  }
613  }
614  }
615 
616  if(pc_ref_idx == -1 && pc_ref_idx_pu != -1) // If no candidate from PV was found, store candidate from non-PV (if found)
617  pc_ref_idx = pc_ref_idx_pu;
618 }
619 
620 // get PF neutral pT sum around isolated track
622 {
623  float nsum=0;
624  float nhsum=0, phsum=0;
625  for(pat::PackedCandidateCollection::const_iterator pf_it = pc->begin(); pf_it != pc->end(); pf_it++){
626  if(int(pf_it - pc->begin()) == pc_idx) //don't count itself
627  continue;
628  int id = std::abs(pf_it->pdgId());
629  float pt = pf_it->p4().pt();
630  float dr = deltaR(p4, *pf_it);
631 
632  if(dr < pfneutralsum_DR_){
633  // neutral hadron sum
634  if(id==130)
635  nhsum += pt;
636  // photon iso
637  if(id==22)
638  phsum += pt;
639  }
640  }
641 
642  nsum = nhsum + phsum;
643 
644  return nsum;
645 }
646 
647 // get the estimated DeDx in either the pixels or strips (or both)
649 {
650  if(hitInfo == nullptr){
651  return -1;
652  }
653 
654  std::vector<float> charge_vec;
655  for(unsigned int ih=0; ih<hitInfo->size(); ih++){
656 
657  bool isPixel = (hitInfo->pixelCluster(ih) != nullptr);
658  bool isStrip = (hitInfo->stripCluster(ih) != nullptr);
659 
660  if(isPixel && !doPixel) continue;
661  if(isStrip && !doStrip) continue;
662 
663  // probably shouldn't happen
664  if(!isPixel && !isStrip) continue;
665 
666  // shape selection for strips
667  if(isStrip && !DeDxTools::shapeSelection(*(hitInfo->stripCluster(ih))))
668  continue;
669 
670  float Norm=0;
671  if(isPixel)
672  Norm = 3.61e-06; //compute the normalization factor to get the energy in MeV/mm
673  if(isStrip)
674  Norm = 3.61e-06 * 265;
675 
676  //save the dE/dx in MeV/mm to a vector.
677  charge_vec.push_back(Norm*hitInfo->charge(ih)/hitInfo->pathlength(ih));
678  }
679 
680  int size = charge_vec.size();
681  float result = 0.0;
682 
683  //build the harmonic 2 dE/dx estimator
684  float expo = -2;
685  for(int i=0; i<size; i++){
686  result += pow(charge_vec[i], expo);
687  }
688  result = (size>0) ? pow(result/size, 1./expo) : 0.0;
689 
690  return result;
691 }
692 
694  const edm::EventSetup& iSetup,
695  const reco::Track& track)
696 {
698  iSetup.get<IdealMagneticFieldRecord>().get(bField);
700 
701  // can't use the associate() using reco::Track directly, since
702  // track->extra() is non-null but segfaults when trying to use it
703  return trackAssociator_.associate(iEvent, iSetup, trackAssocParameters_, &initialState);
704 }
705 
707  float &caloJetEm, float& caloJetHad) const
708 {
709  float nearestDR = 999;
710  int ind = -1;
711  for(unsigned int i=0; i<cJets->size(); i++){
712  float dR = deltaR(cJets->at(i), p4);
713  if(dR < caloJet_DR_ && dR < nearestDR){
714  nearestDR = dR;
715  ind = i;
716  }
717  }
718 
719  if(ind==-1){
720  caloJetEm = 0;
721  caloJetHad = 0;
722  }else{
723  const reco::CaloJet & cJet = cJets->at(ind);
724  caloJetEm = cJet.emEnergyInEB() + cJet.emEnergyInEE() + cJet.emEnergyInHF();
725  caloJetHad = cJet.hadEnergyInHB() + cJet.hadEnergyInHE() + cJet.hadEnergyInHF();
726  }
727 
728 }
729 
730 
virtual float dz(size_t ipv=0) const
dz with respect to the PV[ipv]
float hadEnergyInHE() const
Definition: CaloJet.h:108
size
Write out results.
double p() const
momentum vector magnitude
Definition: TrackBase.h:654
float emEnergyInEE() const
Definition: CaloJet.h:114
T getParameter(std::string const &) const
PATIsolatedTrackProducer(const edm::ParameterSet &)
const edm::EDGetTokenT< reco::TrackCollection > gt_
float dxyError() const override
uncertainty on dxy
const edm::EDGetTokenT< edm::ValueMap< reco::DeDxData > > gt2dedxStrip_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
Jets made from CaloTowers.
Definition: CaloJet.h:29
const edm::EDGetTokenT< edm::ValueMap< int > > gt2dedxHitInfoPrescale_
TrackDetectorAssociator trackAssociator_
int pdgId() const override
PDG identifier.
ProductID id() const
Definition: HandleBase.cc:15
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
double dxyError() const
error on dxy
Definition: TrackBase.h:847
float getPFNeutralSum(const PolarLorentzVector &p4, const pat::PackedCandidateCollection *pc, int pc_idx) const
float charge(size_t i) const
Definition: DeDxHitInfo.h:42
std::vector< DetId > crossedEcalIds
void useDefaultPropagator()
use the default propagator
std::vector< pat::PackedCandidate > PackedCandidateCollection
const LorentzVector & p4() const override
four-momentum Lorentz vecto r
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
float dzError() const override
uncertainty on dz
void loadParameters(const edm::ParameterSet &, edm::ConsumesCollector &)
float emEnergyInHF() const
Definition: CaloJet.h:116
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:684
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
const Item * getValues(DetId fId, bool throwOnFail=true) const
key_type key() const
Accessor for product key.
Definition: Ref.h:263
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:666
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > gt2pc_
std::vector< DetId > crossedHcalIds
const Point & position() const
position
Definition: Vertex.h:109
ProductID id() const
Accessor for product ID.
Definition: Ref.h:257
static const double deltaEta
Definition: CaloConstants.h:8
Definition: HeavyIon.h:7
const edm::EDGetTokenT< reco::DeDxHitInfoAss > gt2dedxHitInfo_
pat::IsolatedTrack::PolarLorentzVector PolarLorentzVector
void getIsolation(const PolarLorentzVector &p4, const pat::PackedCandidateCollection *pc, int pc_idx, pat::PFIsolation &iso, pat::PFIsolation &miniiso) const
int charge() const override
electric charge
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:690
edm::Association< DeDxHitInfoCollection > DeDxHitInfoAss
Definition: DeDxHitInfo.h:102
void getNearestPCRef(const PolarLorentzVector &p4, const pat::PackedCandidateCollection *pc, int pc_idx, int &pc_ref_idx) const
bool shapeSelection(const SiStripCluster &ampls)
Definition: DeDxTools.cc:10
const PVAssoc fromPV(size_t ipv=0) const
susybsm::HSCParticleRefProd hp
Definition: classes.h:27
T sqrt(T t)
Definition: SSEVec.h:18
double p4[4]
Definition: TauolaWrapper.h:92
double pt() const
track transverse momentum
Definition: TrackBase.h:660
TrackAssociatorParameters trackAssocParameters_
float emEnergyInEB() const
Definition: CaloJet.h:112
edm::Ref< pat::PackedCandidateCollection > PackedCandidateRef
int qualityMask() const
Definition: TrackBase.h:943
def pv(vc)
Definition: MetAnalyzer.py:7
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const SiPixelCluster * pixelCluster(size_t i) const
Definition: DeDxHitInfo.h:46
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:243
T min(T a, T b)
Definition: MathUtil.h:58
bool isValid() const
Definition: HandleBase.h:74
bool contains(ProductID id) const
Definition: Association.h:62
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:678
bool hasTrackDetails() const
Return true if a bestTrack can be extracted from this Candidate.
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:648
double dzError() const
error on dz
Definition: TrackBase.h:865
pat::IsolatedTrack::LorentzVector LorentzVector
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
const edm::EDGetTokenT< pat::PackedCandidateCollection > pc_
StringCutObjectSelector< pat::IsolatedTrack > saveDeDxHitInfoCut_
T const * product() const
Definition: Handle.h:74
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:485
void getCaloJetEnergy(const PolarLorentzVector &, const reco::CaloJetCollection *, float &, float &) const
const edm::EDGetTokenT< edm::Association< reco::PFCandidateCollection > > pc2pf_
const edm::EDGetTokenT< pat::PackedCandidateCollection > lt_
size_t size() const
Definition: DeDxHitInfo.h:41
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:21
void produce(edm::Event &, const edm::EventSetup &) override
const edm::EDGetTokenT< reco::VertexCollection > pv_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > gt2lt_
fixed size matrix
HLT enums.
TrackDetMatchInfo getTrackDetMatchInfo(const edm::Event &, const edm::EventSetup &, const reco::Track &)
float pathlength(size_t i) const
Definition: DeDxHitInfo.h:43
T get() const
Definition: EventSetup.h:71
float hadEnergyInHB() const
Definition: CaloJet.h:104
bool getPFLeptonOverlap(const PolarLorentzVector &p4, const pat::PackedCandidateCollection *pc) const
bool isPixel(HitType hitType)
TrackDetMatchInfo associate(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const AssociatorParameters &)
const_iterator find(uint32_t rawId) const
math::XYZPoint trkGlobPosAtEcal
Track position at different parts of the calorimeter.
const JetExtendedData & getValue(const Container &, const reco::JetBaseRef &)
get value for the association. Throw exception if no association found
int charge() const
track electric charge
Definition: TrackBase.h:606
virtual float dxy() const
dxy with respect to the PV ref
float hadEnergyInHF() const
Definition: CaloJet.h:110
float chargedHadronIso() const
Definition: PFIsolation.h:33
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:630
FreeTrajectoryState initialFreeState(const reco::Track &tk, const MagneticField *field, bool withErr=true)
T const * product() const
Definition: ESHandle.h:86
const SiStripCluster * stripCluster(size_t i) const
Definition: DeDxHitInfo.h:63
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
const PolarLorentzVector & polarP4() const override
four-momentum Lorentz vector
def move(src, dest)
Definition: eostools.py:511
const edm::EDGetTokenT< reco::CaloJetCollection > caloJets_
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:672
std::vector< CaloJet > CaloJetCollection
collection of CaloJet objects
const edm::EDGetTokenT< edm::ValueMap< reco::DeDxData > > gt2dedxPixel_
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:39
float getDeDx(const reco::DeDxHitInfo *hitInfo, bool doPixel, bool doStrip) const