CMS 3D CMS Logo

AlignmentTracksFromVertexCompositeCandidateSelector.cc
Go to the documentation of this file.
2 
5 
8 
9 // constructor ----------------------------------------------------------------
12  : vccToken_(iC.consumes<reco::VertexCompositeCandidateCollection>(
13  cfg.getParameter<edm::InputTag>("vertexCompositeCandidates"))) {}
14 
15 // destructor -----------------------------------------------------------------
17 
18 // do selection ---------------------------------------------------------------
20  const edm::Handle<reco::TrackCollection>& tc, const edm::Event& evt, const edm::EventSetup& setup) const {
21  Tracks result;
22 
23  std::vector<unsigned int> theV0keys;
24 
26  evt.getByToken(vccToken_, vccHandle);
27 
28  if (vccHandle.isValid()) {
29  // Loop over VertexCompositeCandidates and associate tracks
30  for (const auto& vcc : *vccHandle) {
31  for (size_t i = 0; i < vcc.numberOfDaughters(); ++i) {
32  LogDebug("AlignmentTrackFromVertexCompositeCandidateSelector") << "daughter: " << i << std::endl;
33  const reco::Candidate* daughter = vcc.daughter(i);
34  const reco::RecoChargedCandidate* chargedDaughter = dynamic_cast<const reco::RecoChargedCandidate*>(daughter);
35  if (chargedDaughter) {
36  LogDebug("AlignmentTrackFromVertexCompositeCandidateSelector") << "charged daughter: " << i << std::endl;
37  const reco::TrackRef trackRef = chargedDaughter->track();
38  if (trackRef.isNonnull()) {
39  LogDebug("AlignmentTrackFromVertexCompositeCandidateSelector")
40  << "charged daughter has non-null trackref: " << i << std::endl;
41  theV0keys.push_back(trackRef.key());
42  }
43  }
44  }
45  }
46  } else {
47  edm::LogError("AlignmentTrackFromVertexCompositeCandidateSelector")
48  << "Error >> Failed to get VertexCompositeCandidateCollection";
49  }
50 
51  LogDebug("AlignmentTrackFromVertexCompositeCandidateSelector")
52  << "collection will have size: " << theV0keys.size() << std::endl;
53 
54  if (tc.isValid()) {
55  int indx(0);
56  // put the track in the collection is it was used for the vertex
57  for (reco::TrackCollection::const_iterator tk = tc->begin(); tk != tc->end(); ++tk, ++indx) {
58  reco::TrackRef trackRef = reco::TrackRef(tc, indx);
59  if (std::find(theV0keys.begin(), theV0keys.end(), trackRef.key()) != theV0keys.end()) {
60  LogDebug("AlignmentTrackFromVertexSelector") << "track index: " << indx << "filling result vector" << std::endl;
61  result.push_back(&(*tk));
62  } // if a valid key is found
63  } // end loop over tracks
64  } // if the handle is valid
65 
66  LogDebug("AlignmentTrackFromVertexCompositeCandidateSelector")
67  << "collection will have size: " << result.size() << std::endl;
68 
69  return result;
70 }
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
std::vector< VertexCompositeCandidate > VertexCompositeCandidateCollection
collection of Candidate objects
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
Log< level::Error, false > LogError
Tracks select(const edm::Handle< reco::TrackCollection > &tc, const edm::Event &evt, const edm::EventSetup &setup) const
select tracks
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
key_type key() const
Accessor for product key.
Definition: Ref.h:250
reco::TrackRef track() const override
reference to a track
AlignmentTrackFromVertexCompositeCandidateSelector(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
constructor
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
bool isValid() const
Definition: HandleBase.h:70
fixed size matrix
HLT enums.
const edm::EDGetTokenT< reco::VertexCompositeCandidateCollection > vccToken_
#define LogDebug(id)