CMS 3D CMS Logo

PF_PU_FirstVertexTracks.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PF_PU_AssoMap
4 // Class: PF_PU_FirstVertexTracks
5 //
10 //
11 // Original Author: Matthias Geisler
12 // Created: Wed Apr 18 14:48:37 CEST 2012
13 // $Id: PF_PU_FirstVertexTracks.cc,v 1.1 2012/11/21 09:57:30 mgeisler Exp $
14 //
15 //
17 
18 // system include files
19 #include <vector>
20 #include <string>
21 
22 // user include files
24 
29 
34 
35 //
36 // constants, enums and typedefs
37 //
38 
39 using namespace edm;
40 using namespace std;
41 using namespace reco;
42 
43 typedef vector<pair<TrackRef, int> > TrackQualityPairVector;
44 
45 //
46 // static data member definitions
47 //
48 
49 //
50 // constructors and destructor
51 //
53  //now do what ever other initialization is needed
54 
55  input_AssociationType_ = iConfig.getParameter<edm::InputTag>("AssociationType");
56 
57  token_TrackToVertexAssMap_ = mayConsume<TrackToVertexAssMap>(iConfig.getParameter<InputTag>("AssociationMap"));
58  token_VertexToTrackAssMap_ = mayConsume<VertexToTrackAssMap>(iConfig.getParameter<InputTag>("AssociationMap"));
59 
60  token_generalTracksCollection_ = consumes<TrackCollection>(iConfig.getParameter<InputTag>("TrackCollection"));
61 
62  token_VertexCollection_ = mayConsume<VertexCollection>(iConfig.getParameter<InputTag>("VertexCollection"));
63 
64  input_MinQuality_ = iConfig.getParameter<int>("MinQuality");
65 
66  //register your products
67 
68  if (input_AssociationType_.label() == "TracksToVertex") {
69  produces<TrackCollection>("T2V");
70  } else {
71  if (input_AssociationType_.label() == "VertexToTracks") {
72  produces<TrackCollection>("V2T");
73  } else {
74  if (input_AssociationType_.label() == "Both") {
75  produces<TrackCollection>("T2V");
76  produces<TrackCollection>("V2T");
77  } else {
78  std::cout << "No correct InputTag for AssociationType!" << std::endl;
79  std::cout << "Won't produce any TrackCollection!" << std::endl;
80  }
81  }
82  }
83 }
84 
85 //
86 // member functions
87 //
88 
89 // ------------ method called to produce the data ------------
91  unique_ptr<TrackCollection> t2v_firstvertextracks(new TrackCollection());
92  unique_ptr<TrackCollection> v2t_firstvertextracks(new TrackCollection());
93 
94  bool t2vassmap = false;
95  bool v2tassmap = false;
96 
97  //get the input vertex<->general track association map
100 
101  string asstype = input_AssociationType_.label();
102 
103  if ((asstype == "TracksToVertex") || (asstype == "Both")) {
104  if (iEvent.getByToken(token_TrackToVertexAssMap_, t2vAM)) {
105  t2vassmap = true;
106  }
107  }
108 
109  if ((asstype == "VertexToTracks") || (asstype == "Both")) {
110  if (iEvent.getByToken(token_VertexToTrackAssMap_, v2tAM)) {
111  v2tassmap = true;
112  }
113  }
114 
115  if (!t2vassmap && !v2tassmap) {
116  cout << "No input collection could be found" << endl;
117  return;
118  }
119 
120  //get the input track collection
121  Handle<TrackCollection> input_trckcollH;
122  iEvent.getByToken(token_generalTracksCollection_, input_trckcollH);
123 
124  if (t2vassmap) {
125  const TrackQualityPairVector trckcoll = t2vAM->begin()->val;
126 
127  //get the tracks associated to the first vertex and store them in a track collection
128  for (unsigned int trckcoll_ite = 0; trckcoll_ite < trckcoll.size(); trckcoll_ite++) {
129  float quality = trckcoll[trckcoll_ite].second;
130 
131  if (quality >= input_MinQuality_) {
132  TrackRef AMtrkref = trckcoll[trckcoll_ite].first;
133 
134  for (unsigned int index_input_trck = 0; index_input_trck < input_trckcollH->size(); index_input_trck++) {
135  TrackRef input_trackref = TrackRef(input_trckcollH, index_input_trck);
136 
137  if (trackMatch(*AMtrkref, *input_trackref)) {
138  t2v_firstvertextracks->push_back(*AMtrkref);
139  break;
140  }
141  }
142  }
143  }
144 
145  iEvent.put(std::move(t2v_firstvertextracks), "T2V");
146  }
147 
148  if (v2tassmap) {
149  //get the input vertex collection
150  Handle<VertexCollection> input_vtxcollH;
151  iEvent.getByToken(token_VertexCollection_, input_vtxcollH);
152 
153  VertexRef firstVertexRef(input_vtxcollH, 0);
154 
156 
157  for (v2t_ite = v2tAM->begin(); v2t_ite != v2tAM->end(); v2t_ite++) {
158  TrackRef AMtrkref = v2t_ite->key;
159 
160  for (unsigned int index_input_trck = 0; index_input_trck < input_trckcollH->size(); index_input_trck++) {
161  TrackRef input_trackref = TrackRef(input_trckcollH, index_input_trck);
162 
163  if (trackMatch(*AMtrkref, *input_trackref)) {
164  for (unsigned v_ite = 0; v_ite < (v2t_ite->val).size(); v_ite++) {
165  VertexRef vtxref = (v2t_ite->val)[v_ite].first;
166  float quality = (v2t_ite->val)[v_ite].second;
167 
168  if ((vtxref == firstVertexRef) && (quality >= input_MinQuality_)) {
169  v2t_firstvertextracks->push_back(*AMtrkref);
170  }
171  }
172  }
173  }
174  }
175 
176  iEvent.put(std::move(v2t_firstvertextracks), "V2T");
177  }
178 }
179 
180 bool PF_PU_FirstVertexTracks::trackMatch(const Track& track1, const Track& track2) const {
181  return ((track1).eta() == (track2).eta() && (track1).phi() == (track2).phi() && (track1).chi2() == (track2).chi2() &&
182  (track1).ndof() == (track2).ndof() && (track1).p() == (track2).p());
183 }
184 
185 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
187  //The following says we do not know what parameters are allowed so do no validation
188  // Please change this to state exactly what you do use, even if it is no parameters
190 
191  using namespace edm;
192  desc.add<InputTag>("AssociationType");
193  desc.add<InputTag>("AssociationMap");
194  desc.add<InputTag>("TrackCollection");
195  desc.add<InputTag>("VertexCollection");
196  desc.add<int>("MinQuality");
197 
198  descriptions.addDefault(desc);
199 }
200 
201 //define this as a plug-in
size
Write out results.
PF_PU_FirstVertexTracks(const edm::ParameterSet &)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
bool trackMatch(const reco::Track &, const reco::Track &) const
const_iterator end() const
last iterator over the map (read only)
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
vector< pair< TrackRef, int > > TrackQualityPairVector
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< TrackQualityPair > TrackQualityPairVector
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
const_iterator begin() const
first iterator over the map (read only)
fixed size matrix
HLT enums.
string quality
T first(std::pair< T, U > const &p)
def move(src, dest)
Definition: eostools.py:511