CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
31 
39 
40 //
41 // constants, enums and typedefs
42 //
43 
44 using namespace edm;
45 using namespace std;
46 using namespace reco;
47 
50 
51 typedef vector<pair<TrackRef, int> > TrackQualityPairVector;
52 
53 
54 //
55 // static data member definitions
56 //
57 
58 //
59 // constructors and destructor
60 //
62 {
63 
64  //now do what ever other initialization is needed
65 
66  input_AssociationType_ = iConfig.getParameter<edm::InputTag>("AssociationType");
67 
68  input_AssociationMap_ = iConfig.getParameter<InputTag>("AssociationMap");
69 
70  input_generalTracksCollection_ = iConfig.getParameter<InputTag>("TrackCollection");
71 
72  input_VertexCollection_ = iConfig.getParameter<InputTag>("VertexCollection");
73 
74  input_MinQuality_ = iConfig.getParameter<int>("MinQuality");
75 
76  //register your products
77 
78  if ( input_AssociationType_.label() == "TracksToVertex" ) {
79  produces<TrackCollection>("T2V");
80  } else {
81  if ( input_AssociationType_.label() == "VertexToTracks" ) {
82  produces<TrackCollection>("V2T");
83  } else {
84  if ( input_AssociationType_.label() == "Both" ) {
85  produces<TrackCollection>("T2V");
86  produces<TrackCollection>("V2T");
87  } else {
88  edm::LogWarning("FirstVertexTracks") << "No correct InputTag for AssociationType!" << std::endl
89  << "Won't produce any TrackCollection!" << std::endl;
90  }
91  }
92  }
93 
94 }
95 
96 
98 {
99 
100  // do anything here that needs to be done at desctruction time
101  // (e.g. close files, deallocate resources etc.)
102 
103 }
104 
105 
106 //
107 // member functions
108 //
109 
110 // ------------ method called to produce the data ------------
111 void
113 {
114 
115  auto_ptr<TrackCollection> t2v_firstvertextracks(new TrackCollection() );
116  auto_ptr<TrackCollection> v2t_firstvertextracks(new TrackCollection() );
117 
118  bool t2vassmap = false;
119  bool v2tassmap = false;
120 
121  //get the input vertex<->general track association map
124 
125  string asstype = input_AssociationType_.label();
126 
127  if ( ( asstype == "TracksToVertex" ) || ( asstype == "Both" ) ) {
128  if ( iEvent.getByLabel(input_AssociationMap_, t2vAM ) ) {
129  t2vassmap = true;
130  }
131  }
132 
133  if ( ( asstype == "VertexToTracks" ) || ( asstype == "Both" ) ) {
134  if ( iEvent.getByLabel(input_AssociationMap_, v2tAM ) ) {
135  v2tassmap = true;
136  }
137  }
138 
139  if ( !t2vassmap && !v2tassmap ) {
140  edm::LogWarning("FirstVertexTracks") << "No input collection could be found" << endl;
141  return;
142  }
143 
144  //get the input track collection
145  Handle<TrackCollection> input_trckcollH;
146  iEvent.getByLabel(input_generalTracksCollection_,input_trckcollH);
147 
148  if ( t2vassmap ) {
149 
150  const TrackQualityPairVector trckcoll = t2vAM->begin()->val;
151 
152  //get the tracks associated to the first vertex and store them in a track collection
153  for ( unsigned int trckcoll_ite = 0; trckcoll_ite < trckcoll.size(); trckcoll_ite++ ) {
154 
155  float quality = trckcoll[trckcoll_ite].second;
156 
157  if ( quality>=input_MinQuality_ ) {
158 
159  TrackRef AMtrkref = trckcoll[trckcoll_ite].first;
160 
161  for ( unsigned int index_input_trck=0; index_input_trck<input_trckcollH->size(); index_input_trck++ ) {
162 
163  TrackRef input_trackref = TrackRef(input_trckcollH,index_input_trck);
164 
165  if( TrackMatch(*AMtrkref,*input_trackref) ){
166 
167  t2v_firstvertextracks->push_back(*AMtrkref);
168  break;
169 
170  }
171 
172  }
173 
174  }
175 
176  }
177 
178  iEvent.put( t2v_firstvertextracks, "T2V" );
179 
180  }
181 
182  if ( v2tassmap ) {
183 
184  //get the input vertex collection
185  Handle<VertexCollection> input_vtxcollH;
186  iEvent.getByLabel(input_VertexCollection_,input_vtxcollH);
187 
188  VertexRef firstVertexRef(input_vtxcollH,0);
189 
191 
192  for ( v2t_ite=v2tAM->begin(); v2t_ite!=v2tAM->end(); v2t_ite++ ) {
193 
194  TrackRef AMtrkref = v2t_ite->key;
195 
196  for ( unsigned int index_input_trck=0; index_input_trck<input_trckcollH->size(); index_input_trck++ ) {
197 
198  TrackRef input_trackref = TrackRef(input_trckcollH,index_input_trck);
199 
200  if( TrackMatch(*AMtrkref,*input_trackref) ){
201 
202  for(unsigned v_ite = 0; v_ite<(v2t_ite->val).size(); v_ite++){
203 
204  VertexRef vtxref = (v2t_ite->val)[v_ite].first;
205  float quality = (v2t_ite->val)[v_ite].second;
206 
207  if ( ( vtxref==firstVertexRef ) && ( quality>=input_MinQuality_ ) ){
208  v2t_firstvertextracks->push_back(*AMtrkref);
209  }
210 
211  }
212 
213  }
214 
215  }
216 
217  }
218 
219  iEvent.put( v2t_firstvertextracks, "V2T" );
220 
221  }
222 
223 }
224 
225 bool
226 PF_PU_FirstVertexTracks::TrackMatch(const Track& track1, const Track& track2)
227 {
228 
229  return (
230  ( track1.eta() == track2.eta() ) &&
231  ( track1.phi() == track2.phi() ) &&
232  ( track1.chi2() == track2.chi2() ) &&
233  ( track1.ndof() == track2.ndof() ) &&
234  ( track1.p() == track2.p() )
235  );
236 
237 }
238 
239 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
240 void
242  //The following says we do not know what parameters are allowed so do no validation
243  // Please change this to state exactly what you do use, even if it is no parameters
245  desc.setUnknown();
246  descriptions.addDefault(desc);
247 }
248 
249 //define this as a plug-in
double p() const
momentum vector magnitude
Definition: TrackBase.h:127
PF_PU_FirstVertexTracks(const edm::ParameterSet &)
T getParameter(std::string const &) const
std::vector< TrackQualityPair > TrackQualityPairVector
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:137
DEFINE_FWK_MODULE(HiMixingModule)
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:243
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:139
void addDefault(ParameterSetDescription const &psetDescription)
double chi2() const
chi-squared of the fit
Definition: TrackBase.h:105
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
double ndof() const
number of degrees of freedom of the fit
Definition: TrackBase.h:107
edm::AssociationMap< edm::OneToManyWithQuality< reco::VertexCollection, reco::TrackCollection, int > > TrackToVertexAssMap
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
virtual void produce(edm::Event &, const edm::EventSetup &)
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:14
T first(std::pair< T, U > const &p)
tuple size
Write out results.
edm::AssociationMap< edm::OneToManyWithQuality< reco::TrackCollection, reco::VertexCollection, int > > VertexToTrackAssMap
virtual bool TrackMatch(const reco::Track &, const reco::Track &)