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 //
47 // static data member definitions
48 //
49 
50 //
51 // constructors and destructor
52 //
54 {
55  //now do what ever other initialization is needed
56 
57  input_AssociationType_ = iConfig.getParameter<edm::InputTag>("AssociationType");
58 
59  token_TrackToVertexAssMap_ = mayConsume<TrackToVertexAssMap>(iConfig.getParameter<InputTag>("AssociationMap"));
60  token_VertexToTrackAssMap_ = mayConsume<VertexToTrackAssMap>(iConfig.getParameter<InputTag>("AssociationMap"));
61 
62  token_generalTracksCollection_ = consumes<TrackCollection>(iConfig.getParameter<InputTag>("TrackCollection"));
63 
64  token_VertexCollection_ = mayConsume<VertexCollection>(iConfig.getParameter<InputTag>("VertexCollection"));
65 
66  input_MinQuality_ = iConfig.getParameter<int>("MinQuality");
67 
68  //register your products
69 
70  if ( input_AssociationType_.label() == "TracksToVertex" ) {
71  produces<TrackCollection>("T2V");
72  } else {
73  if ( input_AssociationType_.label() == "VertexToTracks" ) {
74  produces<TrackCollection>("V2T");
75  } else {
76  if ( input_AssociationType_.label() == "Both" ) {
77  produces<TrackCollection>("T2V");
78  produces<TrackCollection>("V2T");
79  } else {
80  std::cout << "No correct InputTag for AssociationType!" << std::endl;
81  std::cout << "Won't produce any TrackCollection!" << std::endl;
82  }
83  }
84  }
85 
86 }
87 
88 
90 {
91 
92  // do anything here that needs to be done at desctruction time
93  // (e.g. close files, deallocate resources etc.)
94 
95 }
96 
97 
98 //
99 // member functions
100 //
101 
102 // ------------ method called to produce the data ------------
103 void
105 {
106 
107  unique_ptr<TrackCollection> t2v_firstvertextracks(new TrackCollection() );
108  unique_ptr<TrackCollection> v2t_firstvertextracks(new TrackCollection() );
109 
110  bool t2vassmap = false;
111  bool v2tassmap = false;
112 
113  //get the input vertex<->general track association map
116 
117  string asstype = input_AssociationType_.label();
118 
119  if ( ( asstype == "TracksToVertex" ) || ( asstype == "Both" ) ) {
120  if ( iEvent.getByToken(token_TrackToVertexAssMap_, t2vAM ) ) {
121  t2vassmap = true;
122  }
123  }
124 
125  if ( ( asstype == "VertexToTracks" ) || ( asstype == "Both" ) ) {
126  if ( iEvent.getByToken(token_VertexToTrackAssMap_, v2tAM ) ) {
127  v2tassmap = true;
128  }
129  }
130 
131  if ( !t2vassmap && !v2tassmap ) {
132  cout << "No input collection could be found" << endl;
133  return;
134  }
135 
136  //get the input track collection
137  Handle<TrackCollection> input_trckcollH;
138  iEvent.getByToken(token_generalTracksCollection_,input_trckcollH);
139 
140  if ( t2vassmap ){
141 
142  const TrackQualityPairVector trckcoll = t2vAM->begin()->val;
143 
144  //get the tracks associated to the first vertex and store them in a track collection
145  for (unsigned int trckcoll_ite = 0; trckcoll_ite < trckcoll.size(); trckcoll_ite++){
146 
147  float quality = trckcoll[trckcoll_ite].second;
148 
149  if ( quality>=input_MinQuality_ ) {
150 
151  TrackRef AMtrkref = trckcoll[trckcoll_ite].first;
152 
153  for(unsigned int index_input_trck=0; index_input_trck<input_trckcollH->size(); index_input_trck++){
154 
155  TrackRef input_trackref = TrackRef(input_trckcollH,index_input_trck);
156 
157  if( TrackMatch(*AMtrkref,*input_trackref) ){
158 
159  t2v_firstvertextracks->push_back(*AMtrkref);
160  break;
161 
162  }
163 
164  }
165 
166  }
167 
168  }
169 
170  iEvent.put(std::move(t2v_firstvertextracks), "T2V" );
171 
172  }
173 
174  if ( v2tassmap ) {
175 
176  //get the input vertex collection
177  Handle<VertexCollection> input_vtxcollH;
178  iEvent.getByToken(token_VertexCollection_,input_vtxcollH);
179 
180  VertexRef firstVertexRef(input_vtxcollH,0);
181 
183 
184  for(v2t_ite=v2tAM->begin(); v2t_ite!=v2tAM->end(); v2t_ite++){
185 
186  TrackRef AMtrkref = v2t_ite->key;
187 
188  for(unsigned int index_input_trck=0; index_input_trck<input_trckcollH->size(); index_input_trck++){
189 
190  TrackRef input_trackref = TrackRef(input_trckcollH,index_input_trck);
191 
192  if(TrackMatch(*AMtrkref,*input_trackref)){
193 
194  for(unsigned v_ite = 0; v_ite<(v2t_ite->val).size(); v_ite++){
195 
196  VertexRef vtxref = (v2t_ite->val)[v_ite].first;
197  float quality = (v2t_ite->val)[v_ite].second;
198 
199  if ( (vtxref==firstVertexRef) && (quality>=input_MinQuality_) ){
200  v2t_firstvertextracks->push_back(*AMtrkref);
201  }
202 
203  }
204 
205  }
206 
207  }
208 
209  }
210 
211  iEvent.put(std::move(v2t_firstvertextracks), "V2T" );
212 
213  }
214 
215 }
216 
217 bool
218 PF_PU_FirstVertexTracks::TrackMatch(const Track& track1,const Track& track2)
219 {
220 
221  return (
222  (track1).eta() == (track2).eta() &&
223  (track1).phi() == (track2).phi() &&
224  (track1).chi2() == (track2).chi2() &&
225  (track1).ndof() == (track2).ndof() &&
226  (track1).p() == (track2).p()
227  );
228 
229 }
230 
231 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
232 void
234  //The following says we do not know what parameters are allowed so do no validation
235  // Please change this to state exactly what you do use, even if it is no parameters
237  desc.setUnknown();
238  descriptions.addDefault(desc);
239 }
240 
241 //define this as a plug-in
size
Write out results.
PF_PU_FirstVertexTracks(const edm::ParameterSet &)
T getParameter(std::string const &) const
std::vector< TrackQualityPair > TrackQualityPairVector
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
const_iterator end() const
last iterator over the map (read only)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
void produce(edm::Event &, const edm::EventSetup &) override
vector< pair< TrackRef, int > > TrackQualityPairVector
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
fixed size matrix
HLT enums.
const_iterator begin() const
first iterator over the map (read only)
T first(std::pair< T, U > const &p)
def move(src, dest)
Definition: eostools.py:510
virtual bool TrackMatch(const reco::Track &, const reco::Track &)