CMS 3D CMS Logo

BPHTrackReference.h
Go to the documentation of this file.
1 #ifndef HeavyFlavorAnalysis_RecoDecay_BPHTrackReference_h
2 #define HeavyFlavorAnalysis_RecoDecay_BPHTrackReference_h
3 
13 //----------------------
14 // Base Class Headers --
15 //----------------------
16 
17 //------------------------------------
18 // Collaborating Class Declarations --
19 //------------------------------------
27 
28 //---------------
29 // C++ Headers --
30 //---------------
31 
32 // ---------------------
33 // -- Class Interface --
34 // ---------------------
35 
37 public:
39 
45  static const reco::Track* getTrack(const reco::Candidate& rc,
61  const char* modeList = "cfhbpmnigset",
62  char* modeFlag = nullptr) {
63  if (rc.charge() == 0)
64  return nullptr;
65  const char* mptr = modeList;
66  char c;
67  if (modeFlag == nullptr)
68  modeFlag = &c;
69  char& mode = *modeFlag;
70  const reco::Track* tkp = nullptr;
71  while ((mode = *mptr++)) {
72  switch (mode) {
73  case 'c':
74  if ((tkp = getFromRC(rc)) != nullptr)
75  return tkp;
76  break;
77  case 'f':
78  if ((tkp = getFromPF(rc)) != nullptr)
79  return tkp;
80  break;
81  case 'h':
82  if ((tkp = getFromGP(rc)) != nullptr)
83  return tkp;
84  break;
85  case 'b':
86  if ((tkp = getFromBT(rc)) != nullptr)
87  return tkp;
88  break;
89  case 'p':
90  if ((tkp = getFromPC(rc)) != nullptr)
91  return tkp;
92  break;
93  case 'm':
94  if ((tkp = getMuonPF(rc)) != nullptr)
95  return tkp;
96  break;
97  case 'n':
98  if ((tkp = getMuonBT(rc)) != nullptr)
99  return tkp;
100  break;
101  case 'i':
102  if ((tkp = getMuonIT(rc)) != nullptr)
103  return tkp;
104  break;
105  case 'g':
106  if ((tkp = getMuonGT(rc)) != nullptr)
107  return tkp;
108  break;
109  case 's':
110  if ((tkp = getMuonSA(rc)) != nullptr)
111  return tkp;
112  break;
113  case 'e':
114  if ((tkp = getElecPF(rc)) != nullptr)
115  return tkp;
116  break;
117  case 't':
118  if ((tkp = getElecTC(rc)) != nullptr)
119  return tkp;
120  break;
121  }
122  }
123  return nullptr;
124  }
125 
126  static const reco::Track* getFromRC(const reco::Candidate& rc) {
127  try {
128  const reco::TrackRef& tkr = rc.get<reco::TrackRef>();
129  if (tkr.isNonnull() && tkr.isAvailable())
130  return tkr.get();
131  } catch (edm::Exception const&) {
132  }
133  return nullptr;
134  }
135  static const reco::Track* getFromPF(const reco::Candidate& rc) {
136  const reco::PFCandidate* pf = dynamic_cast<const reco::PFCandidate*>(&rc);
137  if (pf == nullptr)
138  return nullptr;
139  try {
140  const reco::TrackRef& tkr = pf->trackRef();
141  if (tkr.isNonnull() && tkr.isAvailable())
142  return tkr.get();
143  } catch (edm::Exception const&) {
144  }
145  return nullptr;
146  }
147  static const reco::Track* getFromGP(const reco::Candidate& rc) {
148  const pat::GenericParticle* gp = dynamic_cast<const pat::GenericParticle*>(&rc);
149  if (gp == nullptr)
150  return nullptr;
151  try {
152  const reco::TrackRef& tkr = gp->track();
153  if (tkr.isNonnull() && tkr.isAvailable())
154  return tkr.get();
155  } catch (edm::Exception const&) {
156  }
157  return nullptr;
158  }
159  static const reco::Track* getFromBT(const reco::Candidate& rc) {
160  try {
161  const reco::Track* trk = rc.bestTrack();
162  return trk;
163  } catch (edm::Exception const&) {
164  }
165  return nullptr;
166  }
167  static const reco::Track* getFromPC(const reco::Candidate& rc) {
168  const pat::PackedCandidate* pp = dynamic_cast<const pat::PackedCandidate*>(&rc);
169  if (pp == nullptr)
170  return nullptr;
171  try {
172  const reco::Track* trk = &pp->pseudoTrack();
173  return trk;
174  } catch (edm::Exception const&) {
175  }
176  return nullptr;
177  }
178  static const reco::Track* getMuonPF(const reco::Candidate& rc) {
179  const pat::Muon* mu = dynamic_cast<const pat::Muon*>(&rc);
180  if (mu == nullptr)
181  return nullptr;
182  return getMuonPF(mu);
183  }
184  static const reco::Track* getMuonPF(const pat::Muon* mu) {
185  try {
186  const reco::PFCandidateRef& pcr = mu->pfCandidateRef();
187  if (pcr.isNonnull() && pcr.isAvailable()) {
188  const reco::TrackRef& tkr = pcr->trackRef();
189  if (tkr.isNonnull() && tkr.isAvailable())
190  return tkr.get();
191  }
192  } catch (edm::Exception const&) {
193  }
194  return nullptr;
195  }
196  static const reco::Track* getMuonBT(const reco::Candidate& rc) {
197  const reco::Muon* mu = dynamic_cast<const reco::Muon*>(&rc);
198  if (mu == nullptr)
199  return nullptr;
200  return getMuonBT(mu);
201  }
202  static const reco::Track* getMuonBT(const reco::Muon* mu) {
203  try {
204  const reco::TrackRef& tkr = mu->muonBestTrack();
205  if (tkr.isNonnull() && tkr.isAvailable())
206  return tkr.get();
207  } catch (edm::Exception const&) {
208  }
209  return nullptr;
210  }
211  static const reco::Track* getMuonIT(const reco::Candidate& rc) {
212  const pat::Muon* mu = dynamic_cast<const pat::Muon*>(&rc);
213  if (mu == nullptr)
214  return nullptr;
215  return getMuonIT(mu);
216  }
217  static const reco::Track* getMuonIT(const pat::Muon* mu) {
218  if (!mu->isTrackerMuon())
219  return nullptr;
220  try {
221  const reco::TrackRef& mit = mu->innerTrack();
222  if (mit.isNonnull() && mit.isAvailable())
223  return mit.get();
224  } catch (edm::Exception const&) {
225  }
226  return nullptr;
227  }
228  static const reco::Track* getMuonGT(const reco::Candidate& rc) {
229  const pat::Muon* mu = dynamic_cast<const pat::Muon*>(&rc);
230  if (mu == nullptr)
231  return nullptr;
232  return getMuonGT(mu);
233  }
234  static const reco::Track* getMuonGT(const pat::Muon* mu) {
235  if (!mu->isGlobalMuon())
236  return nullptr;
237  try {
238  const reco::TrackRef& mgt = mu->globalTrack();
239  if (mgt.isNonnull() && mgt.isAvailable())
240  return mgt.get();
241  } catch (edm::Exception const&) {
242  }
243  return nullptr;
244  }
245  static const reco::Track* getMuonSA(const reco::Candidate& rc) {
246  const pat::Muon* mu = dynamic_cast<const pat::Muon*>(&rc);
247  if (mu == nullptr)
248  return nullptr;
249  return getMuonSA(mu);
250  }
251  static const reco::Track* getMuonSA(const pat::Muon* mu) {
252  if (!mu->isStandAloneMuon())
253  return nullptr;
254  try {
255  const reco::TrackRef& msa = mu->standAloneMuon();
256  if (msa.isNonnull() && msa.isAvailable())
257  return msa.get();
258  } catch (edm::Exception const&) {
259  }
260  return nullptr;
261  }
262  static const reco::Track* getElecPF(const reco::Candidate& rc) {
263  const pat::Electron* el = dynamic_cast<const pat::Electron*>(&rc);
264  if (el == nullptr)
265  return nullptr;
266  return getElecPF(el);
267  }
268  static const reco::Track* getElecPF(const pat::Electron* el) {
269  try {
270  const reco::PFCandidateRef& pcr = el->pfCandidateRef();
271  if (pcr.isNonnull() && pcr.isAvailable()) {
272  const reco::TrackRef& tkr = pcr->trackRef();
273  if (tkr.isNonnull() && tkr.isAvailable())
274  return tkr.get();
275  }
276  } catch (edm::Exception const&) {
277  }
278  return nullptr;
279  }
280  static const reco::Track* getElecTC(const reco::Candidate& rc) {
281  const pat::Electron* el = dynamic_cast<const pat::Electron*>(&rc);
282  if (el == nullptr)
283  return nullptr;
284  return getElecTC(el);
285  }
286  static const reco::Track* getElecTC(const pat::Electron* el) {
287  try {
288  // Return the ctftrack closest to the electron
289  const reco::TrackRef& tkr = el->closestCtfTrackRef();
290  if (tkr.isNonnull() && tkr.isAvailable())
291  return tkr.get();
292  } catch (edm::Exception const&) {
293  }
294  return nullptr;
295  }
296 };
297 
298 #endif
BPHTrackReference::getMuonGT
static const reco::Track * getMuonGT(const pat::Muon *mu)
Definition: BPHTrackReference.h:234
BPHTrackReference::getFromBT
static const reco::Track * getFromBT(const reco::Candidate &rc)
Definition: BPHTrackReference.h:159
PFCandidate.h
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
edm::Ref::isAvailable
bool isAvailable() const
Definition: Ref.h:537
Muon.h
GenericParticle.h
BPHTrackReference::getMuonPF
static const reco::Track * getMuonPF(const reco::Candidate &rc)
Definition: BPHTrackReference.h:178
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
edm::Ref::get
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
BPHTrackReference::getMuonSA
static const reco::Track * getMuonSA(const reco::Candidate &rc)
Definition: BPHTrackReference.h:245
reco::Candidate::get
T get() const
get a component
Definition: Candidate.h:221
pat::Electron::closestCtfTrackRef
reco::TrackRef closestCtfTrackRef() const override
override the reco::GsfElectron::closestCtfTrackRef method, to access the internal storage of the trac...
pat::Muon
Analysis-level muon class.
Definition: Muon.h:51
pat::Electron::pfCandidateRef
reco::PFCandidateRef pfCandidateRef() const
reference to the source PFCandidates; null if this has been built from a standard electron
RecoCandidate.h
BPHTrackReference::candidate
pat::PackedCandidate candidate
Definition: BPHTrackReference.h:38
reco::Muon
Definition: Muon.h:27
BPHTrackReference::getMuonIT
static const reco::Track * getMuonIT(const reco::Candidate &rc)
Definition: BPHTrackReference.h:211
edm::Ref< TrackCollection >
edm::Exception
Definition: EDMException.h:77
BPHTrackReference::getElecTC
static const reco::Track * getElecTC(const pat::Electron *el)
Definition: BPHTrackReference.h:286
BPHTrackReference::getTrack
static const reco::Track * getTrack(const reco::Candidate &rc, const char *modeList="cfhbpmnigset", char *modeFlag=nullptr)
Definition: BPHTrackReference.h:60
BPHTrackReference
Definition: BPHTrackReference.h:36
Track.h
BPHTrackReference::getMuonPF
static const reco::Track * getMuonPF(const pat::Muon *mu)
Definition: BPHTrackReference.h:184
BPHTrackReference::getMuonIT
static const reco::Track * getMuonIT(const pat::Muon *mu)
Definition: BPHTrackReference.h:217
reco::Candidate::charge
virtual int charge() const =0
electric charge
BPHTrackReference::getFromRC
static const reco::Track * getFromRC(const reco::Candidate &rc)
Definition: BPHTrackReference.h:126
reco::Track
Definition: Track.h:27
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
pat::GenericParticle
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed)
Definition: GenericParticle.h:38
BPHTrackReference::getMuonSA
static const reco::Track * getMuonSA(const pat::Muon *mu)
Definition: BPHTrackReference.h:251
pat::PackedCandidate
Definition: PackedCandidate.h:22
PackedCandidate.h
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
BPHTrackReference::getMuonGT
static const reco::Track * getMuonGT(const reco::Candidate &rc)
Definition: BPHTrackReference.h:228
BPHTrackReference::getMuonBT
static const reco::Track * getMuonBT(const reco::Muon *mu)
Definition: BPHTrackReference.h:202
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
reco::Candidate
Definition: Candidate.h:27
reco::Candidate::bestTrack
virtual const Track * bestTrack() const
Definition: Candidate.h:268
packedPFCandidateRefMixer_cfi.pf
pf
Definition: packedPFCandidateRefMixer_cfi.py:4
BPHTrackReference::getFromGP
static const reco::Track * getFromGP(const reco::Candidate &rc)
Definition: BPHTrackReference.h:147
BPHTrackReference::getElecPF
static const reco::Track * getElecPF(const reco::Candidate &rc)
Definition: BPHTrackReference.h:262
BPHTrackReference::getFromPC
static const reco::Track * getFromPC(const reco::Candidate &rc)
Definition: BPHTrackReference.h:167
Electron.h
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
BPHTrackReference::getElecPF
static const reco::Track * getElecPF(const pat::Electron *el)
Definition: BPHTrackReference.h:268
pat::Electron
Analysis-level electron class.
Definition: Electron.h:51
createTree.pp
pp
Definition: createTree.py:17
BPHTrackReference::getMuonBT
static const reco::Track * getMuonBT(const reco::Candidate &rc)
Definition: BPHTrackReference.h:196
BPHTrackReference::getElecTC
static const reco::Track * getElecTC(const reco::Candidate &rc)
Definition: BPHTrackReference.h:280
BPHTrackReference::getFromPF
static const reco::Track * getFromPF(const reco::Candidate &rc)
Definition: BPHTrackReference.h:135