CMS 3D CMS Logo

AlignmentTracksFromVertexSelector.cc
Go to the documentation of this file.
2 
5 
8 
11 
12 // vertices
15 
16 // constructor ----------------------------------------------------------------
19  : ttbESToken_(
20  iC.esConsumes<TransientTrackBuilder, TransientTrackRecord>(edm::ESInputTag("", "TransientTrackBuilder"))),
21  vertexToken_(iC.consumes<reco::VertexCollection>(cfg.getParameter<edm::InputTag>("vertices"))),
22  diLeptonToken_(iC.consumes<reco::TrackCollection>(cfg.getParameter<edm::InputTag>("leptonTracks"))),
23  useClosestVertex_(cfg.getParameter<bool>("useClosestVertexToDilepton")),
24  vertexIndex_(cfg.getParameter<unsigned int>("vertexIndex")) {}
25 
26 // destructor -----------------------------------------------------------------
28 
29 // compute the closest vertex to di-lepton ------------------------------------
32  const edm::EventSetup& setup) const {
33  reco::Vertex* defaultVtx = nullptr;
34 
35  // fill the transient track collection with the lepton tracks
36  const TransientTrackBuilder* theB = &setup.getData(ttbESToken_);
37  std::vector<reco::TransientTrack> tks;
38  for (const auto& track : leptonTracks) {
39  reco::TransientTrack trajectory = theB->build(track);
40  tks.push_back(trajectory);
41  }
42 
43  // compute the secondary vertex
44  TransientVertex aTransVtx;
45  KalmanVertexFitter kalman(true);
46  aTransVtx = kalman.vertex(tks);
47 
48  if (!aTransVtx.isValid())
49  return defaultVtx;
50 
51  // find the closest vertex to the secondary vertex in 3D
52  VertexDistance3D vertTool3D;
53  float minD = 9999.;
54  int closestVtxIndex = 0;
55  int counter = 0;
56  for (const auto& vtx : *vertices) {
57  double dist3D = vertTool3D.distance(aTransVtx, vtx).value();
58  if (dist3D < minD) {
59  minD = dist3D;
60  closestVtxIndex = counter;
61  }
62  counter++;
63  }
64  if ((*vertices).at(closestVtxIndex).isValid()) {
65  return &(vertices->at(closestVtxIndex));
66  } else {
67  return defaultVtx;
68  }
69 }
70 
71 // do selection ---------------------------------------------------------------
73  const edm::Handle<reco::TrackCollection>& tc, const edm::Event& evt, const edm::EventSetup& setup) const {
74  Tracks result;
75 
76  std::vector<unsigned int> thePVkeys;
77 
78  // get collection of reconstructed vertices from event
80 
81  // get collection of the di-lepton traxks
82  const auto& leptonTracks = evt.get(diLeptonToken_);
83 
84  // fill the vector of keys
85  if (vertexHandle.isValid()) {
86  const reco::VertexCollection* vertices = vertexHandle.product();
87  const reco::Vertex* theVtx = nullptr;
88 
89  if (useClosestVertex_) {
90  theVtx = findClosestVertex(leptonTracks, vertices, setup);
91  } else {
92  if ((*vertices).at(vertexIndex_).isValid()) {
93  theVtx = &(vertices->at(vertexIndex_));
94  }
95  }
96 
97  if (theVtx) {
98  for (auto tv = theVtx->tracks_begin(); tv != theVtx->tracks_end(); tv++) {
99  if (tv->isNonnull()) {
100  const reco::TrackRef trackRef = tv->castTo<reco::TrackRef>();
101  thePVkeys.push_back(trackRef.key());
102  }
103  }
104  }
105  }
106 
107  std::sort(thePVkeys.begin(), thePVkeys.end());
108 
109  LogDebug("AlignmentTrackFromVertexSelector")
110  << "after collecting the PV keys: thePVkeys.size()" << thePVkeys.size() << std::endl;
111  for (const auto& key : thePVkeys) {
112  LogDebug("AlignmentTrackFromVertexSelector") << key << ", ";
113  }
114  LogDebug("AlignmentTrackFromVertexSelector") << std::endl;
115 
116  if (tc.isValid()) {
117  int indx(0);
118  // put the track in the collection is it was used for the vertex
119  for (reco::TrackCollection::const_iterator tk = tc->begin(); tk != tc->end(); ++tk, ++indx) {
120  reco::TrackRef trackRef = reco::TrackRef(tc, indx);
121  if (std::find(thePVkeys.begin(), thePVkeys.end(), trackRef.key()) != thePVkeys.end()) {
122  LogDebug("AlignmentTrackFromVertexSelector") << "track index: " << indx << "filling result vector" << std::endl;
123  result.push_back(&(*tk));
124  } // if a valid key is found
125  } // end loop over tracks
126  } // if the handle is valid
127  return result;
128 }
counter
Definition: counter.py:1
KalmanVertexFitter::vertex
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const override
Definition: KalmanVertexFitter.h:49
AlignmentTrackFromVertexSelector::findClosestVertex
const reco::Vertex * findClosestVertex(const reco::TrackCollection &leptonTracks, const reco::VertexCollection *vertices, const edm::EventSetup &setup) const
Definition: AlignmentTracksFromVertexSelector.cc:30
electrons_cff.bool
bool
Definition: electrons_cff.py:366
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11724
MessageLogger.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
KalmanVertexFitter.h
AlignmentTrackFromVertexSelector::useClosestVertex_
bool useClosestVertex_
Definition: AlignmentTracksFromVertexSelector.h:45
ESInputTag
TransientVertex::isValid
bool isValid() const
Definition: TransientVertex.h:195
edm
HLT enums.
Definition: AlignableModifier.h:19
AlignmentTrackFromVertexSelector::diLeptonToken_
edm::EDGetTokenT< reco::TrackCollection > diLeptonToken_
Definition: AlignmentTracksFromVertexSelector.h:44
Measurement1D::value
double value() const
Definition: Measurement1D.h:25
reco::VertexCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
VertexDistance3D::distance
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
Definition: VertexDistance3D.cc:17
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
VertexDistance3D.h
reco::Vertex::tracks_end
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.h:110
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
AlignmentTrackFromVertexSelector::Tracks
std::vector< const reco::Track * > Tracks
Definition: AlignmentTracksFromVertexSelector.h:23
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::Handle< reco::TrackCollection >
AlignmentTrackFromVertexSelector::~AlignmentTrackFromVertexSelector
~AlignmentTrackFromVertexSelector()
destructor
Definition: AlignmentTracksFromVertexSelector.cc:27
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
AlignmentTracksFromVertexSelector_cfi.vertices
vertices
Definition: AlignmentTracksFromVertexSelector_cfi.py:5
AlignmentTrackFromVertexSelector::vertexToken_
edm::EDGetTokenT< reco::VertexCollection > vertexToken_
Definition: AlignmentTracksFromVertexSelector.h:43
edm::Ref< TrackCollection >
Track.h
VertexDistanceXY.h
TransientTrackRecord
Definition: TransientTrackRecord.h:11
VertexDistance3D
Definition: VertexDistance3D.h:13
reco::TrackRef
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
reco::Vertex::tracks_begin
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.h:108
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
AlignmentTrackFromVertexSelector::select
Tracks select(const edm::Handle< reco::TrackCollection > &tc, const edm::Event &evt, const edm::EventSetup &setup) const
select tracks
Definition: AlignmentTracksFromVertexSelector.cc:72
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
createfilelist.int
int
Definition: createfilelist.py:10
TransientTrackBuilder
Definition: TransientTrackBuilder.h:16
counter
static std::atomic< unsigned int > counter
Definition: SharedResourceNames.cc:18
TransientVertex
Definition: TransientVertex.h:18
edm::EventSetup
Definition: EventSetup.h:58
looper.cfg
cfg
Definition: looper.py:296
AlignmentTrackFromVertexSelector::AlignmentTrackFromVertexSelector
AlignmentTrackFromVertexSelector(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
constructor
Definition: AlignmentTracksFromVertexSelector.cc:17
AlignmentTrackFromVertexSelector::vertexIndex_
unsigned int vertexIndex_
Definition: AlignmentTracksFromVertexSelector.h:46
AlignmentTracksFromVertexSelector.h
TransientVertex.h
reco::TransientTrack
Definition: TransientTrack.h:19
extraflags_cff.vtx
vtx
Definition: extraflags_cff.py:19
l1t::VertexCollection
std::vector< Vertex > VertexCollection
Definition: Vertex.h:12
edm::Ref::key
key_type key() const
Accessor for product key.
Definition: Ref.h:250
TransientTrackBuilder::build
reco::TransientTrack build(const reco::Track *p) const
Definition: TransientTrackBuilder.cc:20
AlignmentTrackFromVertexSelector::ttbESToken_
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > ttbESToken_
Definition: AlignmentTracksFromVertexSelector.h:42
mps_fire.result
result
Definition: mps_fire.py:311
ParameterSet.h
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
crabWrapper.key
key
Definition: crabWrapper.py:19
edm::Event::get
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:346
edm::Event::getHandle
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:563
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
reco::Vertex
Definition: Vertex.h:35
KalmanVertexFitter
Definition: KalmanVertexFitter.h:22