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