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 //------------------------------------
19 // Collaborating Class Declarations --
20 //------------------------------------
28 
29 //---------------
30 // C++ Headers --
31 //---------------
32 #include <iostream>
33 
34 // ---------------------
35 // -- Class Interface --
36 // ---------------------
37 
39 
40  public:
41 
43 
47 
51 
54  static const reco::Track* getTrack( const reco::Candidate& rc,
69  const char* modeList = "cfhbpmnigse",
70  char* modeFlag = nullptr ) {
71  if ( rc.charge() == 0 ) return nullptr;
72  const char* mptr = modeList;
73  char c;
74  if ( modeFlag == nullptr ) modeFlag = &c;
75  char& mode = *modeFlag;
76  const reco::Track* tkp = nullptr;
77  while ( ( mode = *mptr++ ) ) {
78  switch ( mode ) {
79  case 'c': if ( ( tkp = getFromRC( rc ) ) != nullptr ) return tkp; break;
80  case 'f': if ( ( tkp = getFromPF( rc ) ) != nullptr ) return tkp; break;
81  case 'h': if ( ( tkp = getFromGP( rc ) ) != nullptr ) return tkp; break;
82  case 'b': if ( ( tkp = getFromBT( rc ) ) != nullptr ) return tkp; break;
83  case 'p': if ( ( tkp = getFromPC( rc ) ) != nullptr ) return tkp; break;
84  case 'm': if ( ( tkp = getMuonPF( rc ) ) != nullptr ) return tkp; break;
85  case 'n': if ( ( tkp = getMuonBT( rc ) ) != nullptr ) return tkp; break;
86  case 'i': if ( ( tkp = getMuonIT( rc ) ) != nullptr ) return tkp; break;
87  case 'g': if ( ( tkp = getMuonGT( rc ) ) != nullptr ) return tkp; break;
88  case 's': if ( ( tkp = getMuonSA( rc ) ) != nullptr ) return tkp; break;
89  case 'e': if ( ( tkp = getElecPF( rc ) ) != nullptr ) return tkp; break;
90  }
91  }
92  return nullptr;
93  }
94 
95  static const reco::Track* getFromRC( const reco::Candidate& rc ) {
96 // std::cout << "getFromRC" << std::endl;
97  try {
98  const reco::TrackRef& tkr = rc.get<reco::TrackRef>();
99  if ( tkr.isNonnull() && tkr.isAvailable() ) return tkr.get();
100  }
101  catch ( edm::Exception e ) {
102  }
103  return nullptr;
104  }
105  static const reco::Track* getFromPF( const reco::Candidate& rc ) {
106 // std::cout << "getFromPF" << std::endl;
107  const reco::PFCandidate* pf =
108  dynamic_cast<const reco::PFCandidate*>( &rc );
109  if ( pf == nullptr ) return nullptr;
110  try {
111  const reco::TrackRef& tkr = pf->trackRef();
112  if ( tkr.isNonnull() && tkr.isAvailable() ) return tkr.get();
113  }
114  catch ( edm::Exception e ) {
115  }
116  return nullptr;
117  }
118  static const reco::Track* getFromGP( const reco::Candidate& rc ) {
119 // std::cout << "getFromGC" << std::endl;
120  const pat::GenericParticle* gp =
121  dynamic_cast<const pat::GenericParticle*>( &rc );
122  if ( gp == nullptr ) return nullptr;
123  try {
124  const reco::TrackRef& tkr = gp->track();
125  if ( tkr.isNonnull() && tkr.isAvailable() ) return tkr.get();
126  }
127  catch ( edm::Exception e ) {
128  }
129  return nullptr;
130  }
131  static const reco::Track* getFromBT( const reco::Candidate& rc ) {
132 // std::cout << "getFromBT" << std::endl;
133  try {
134  const reco::Track* trk = rc.bestTrack();
135  return trk;
136  }
137  catch ( edm::Exception e ) {
138  }
139  return nullptr;
140  }
141  static const reco::Track* getFromPC( const reco::Candidate& rc ) {
142 // std::cout << "getFromPC" << std::endl;
143  const pat::PackedCandidate* pp =
144  dynamic_cast<const pat::PackedCandidate*>( &rc );
145  if ( pp == nullptr ) return nullptr;
146  try {
147  const reco::Track* trk = &pp->pseudoTrack();
148  return trk;
149  }
150  catch ( edm::Exception e ) {
151  }
152  return nullptr;
153  }
154  static const reco::Track* getMuonPF( const reco::Candidate& rc ) {
155 // std::cout << "getMuonPF" << std::endl;
156  const pat::Muon* mu = dynamic_cast<const pat::Muon*>( &rc );
157  if ( mu == nullptr ) return nullptr;
158  return getMuonPF( mu );
159  }
160  static const reco::Track* getMuonPF( const pat::Muon* mu ) {
161  try {
162  const reco::PFCandidateRef& pcr = mu->pfCandidateRef();
163  if ( pcr.isNonnull() && pcr.isAvailable() ) {
164  const reco::TrackRef& tkr = pcr->trackRef();
165  if ( tkr.isNonnull() && tkr.isAvailable() ) return tkr.get();
166  }
167  }
168  catch ( edm::Exception e ) {
169  }
170  return nullptr;
171  }
172  static const reco::Track* getMuonBT( const reco::Candidate& rc ) {
173 // std::cout << "getMuonBT" << std::endl;
174  const reco::Muon* mu = dynamic_cast<const reco::Muon*>( &rc );
175  if ( mu == nullptr ) return nullptr;
176  return getMuonBT( mu );
177  }
178  static const reco::Track* getMuonBT( const reco::Muon* mu ) {
179  try {
180  const reco::TrackRef& tkr = mu->muonBestTrack();
181  if ( tkr.isNonnull() && tkr.isAvailable() ) return tkr.get();
182  }
183  catch ( edm::Exception e ) {
184  }
185  return nullptr;
186  }
187  static const reco::Track* getMuonIT( const reco::Candidate& rc ) {
188 // std::cout << "getMuonIT" << std::endl;
189  const pat::Muon* mu = dynamic_cast<const pat::Muon*>( &rc );
190  if ( mu == nullptr ) return nullptr;
191  return getMuonIT( mu );
192  }
193  static const reco::Track* getMuonIT( const pat::Muon* mu ) {
194  if ( !mu->isTrackerMuon() ) return nullptr;
195  try {
196  const reco::TrackRef& mit = mu->innerTrack();
197  if ( mit.isNonnull() && mit.isAvailable() ) return mit.get();
198  }
199  catch ( edm::Exception e ) {
200  }
201  return nullptr;
202  }
203  static const reco::Track* getMuonGT( const reco::Candidate& rc ) {
204 // std::cout << "getMuonGT" << std::endl;
205  const pat::Muon* mu = dynamic_cast<const pat::Muon*>( &rc );
206  if ( mu == nullptr ) return nullptr;
207  return getMuonGT( mu );
208  }
209  static const reco::Track* getMuonGT( const pat::Muon* mu ) {
210  if ( !mu->isGlobalMuon() ) return nullptr;
211  try {
212  const reco::TrackRef& mgt = mu->globalTrack();
213  if ( mgt.isNonnull() && mgt.isAvailable() ) return mgt.get();
214  }
215  catch ( edm::Exception e ) {
216  }
217  return nullptr;
218  }
219  static const reco::Track* getMuonSA( const reco::Candidate& rc ) {
220 // std::cout << "getMuonGT" << std::endl;
221  const pat::Muon* mu = dynamic_cast<const pat::Muon*>( &rc );
222  if ( mu == nullptr ) return nullptr;
223  return getMuonSA( mu );
224  }
225  static const reco::Track* getMuonSA( const pat::Muon* mu ) {
226  if ( !mu->isStandAloneMuon() ) return nullptr;
227  try {
228  const reco::TrackRef& msa = mu->standAloneMuon();
229  if ( msa.isNonnull() && msa.isAvailable() ) return msa.get();
230  }
231  catch ( edm::Exception e ) {
232  }
233  return nullptr;
234  }
235  static const reco::Track* getElecPF( const reco::Candidate& rc ) {
236 // std::cout << "getElecPF" << std::endl;
237  const pat::Electron* el = dynamic_cast<const pat::Electron*>( &rc );
238  if ( el == nullptr ) return nullptr;
239  return getElecPF( el );
240  }
241  static const reco::Track* getElecPF( const pat::Electron* el ) {
242  try {
243  const reco::PFCandidateRef& pcr = el->pfCandidateRef();
244  if ( pcr.isNonnull() && pcr.isAvailable() ) {
245  const reco::TrackRef& tkr = pcr->trackRef();
246  if ( tkr.isNonnull() && tkr.isAvailable() ) return tkr.get();
247  }
248  }
249  catch ( edm::Exception e ) {
250  }
251  return nullptr;
252  }
253 
254  private:
255 
256  // private copy and assigment constructors
259 
260 };
261 
262 
263 #endif
264 
static const reco::Track * getMuonPF(const reco::Candidate &rc)
bool isAvailable() const
Definition: Ref.h:577
static const reco::Track * getFromPF(const reco::Candidate &rc)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
static const reco::Track * getMuonSA(const reco::Candidate &rc)
bool isStandAloneMuon() const override
Definition: Muon.h:278
static const reco::Track * getMuonGT(const pat::Muon *mu)
virtual const Track * bestTrack() const
Definition: Candidate.h:247
static const reco::Track * getMuonIT(const pat::Muon *mu)
#define nullptr
pat::PackedCandidate candidate
bool isTrackerMuon() const override
Definition: Muon.h:277
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:442
static const reco::Track * getFromRC(const reco::Candidate &rc)
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed) ...
virtual TrackRef muonBestTrack() const
Definition: Muon.h:63
reco::TrackRef innerTrack() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:73
static const reco::Track * getMuonPF(const pat::Muon *mu)
reco::PFCandidateRef pfCandidateRef() const
reference to the source PFCandidates; null if this has been built from a standard electron ...
static const reco::Track * getTrack(const reco::Candidate &rc, const char *modeList="cfhbpmnigse", char *modeFlag=0)
static const reco::Track * getMuonIT(const reco::Candidate &rc)
bool isGlobalMuon() const override
Definition: Muon.h:276
static const reco::Track * getMuonGT(const reco::Candidate &rc)
reco::PFCandidateRef pfCandidateRef() const
static const reco::Track * getMuonSA(const pat::Muon *mu)
virtual const reco::Track & pseudoTrack() const
Return reference to a pseudo track made with candidate kinematics, parameterized error for eta...
const int mu
Definition: Constants.h:22
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:245
reco::TrackRef track() const override
reco::TrackRef globalTrack() const override
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon) ...
Definition: Muon.h:81
reco::TrackRef standAloneMuon() const override
reference to Track reconstructed in the muon detector only (reimplemented from reco::Muon) ...
static const reco::Track * getMuonBT(const reco::Muon *mu)
Analysis-level electron class.
Definition: Electron.h:52
static const reco::Track * getElecPF(const reco::Candidate &rc)
virtual int charge() const =0
electric charge
BPHTrackReference & operator=(const BPHTrackReference &x)
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
T get() const
get a component
Definition: Candidate.h:217
static const reco::Track * getFromPC(const reco::Candidate &rc)
static const reco::Track * getElecPF(const pat::Electron *el)
Analysis-level muon class.
Definition: Muon.h:50
static const reco::Track * getFromGP(const reco::Candidate &rc)
static const reco::Track * getMuonBT(const reco::Candidate &rc)
static const reco::Track * getFromBT(const reco::Candidate &rc)