CMS 3D CMS Logo

TrackMergeremb.cc
Go to the documentation of this file.
2 
4 
9 
10 
11 
14 
17 
20 
23 
24 
36 
39 
40 
43 
44 
45 
51 
52 
53 
54 // Here some overloaded functions, which are needed such that the right merger function is called for the indivudal Collections
55 template <typename T1>
57 {
58  produces<TrackCollectionemb>(instance);
59 }
60 
61 template <typename T1>
63 {
64 
65 }
66 
67 template <typename T1>
69 {
70 
71  std::unique_ptr<TrackCollectionemb> outTracks = std::unique_ptr<TrackCollectionemb>(new TrackCollectionemb);
72 
73  for (auto akt_collection : to_merge){
74  edm::Handle<TrackCollectionemb> track_col_in;
75  iEvent.getByToken(akt_collection, track_col_in);
76 
77  size_t sedref_it = 0;
78  for (typename TrackCollectionemb::const_iterator it = track_col_in->begin(); it != track_col_in->end(); ++it, ++sedref_it) {
79  outTracks->push_back( typename T1::value_type( *it ) );
80 
81  }
82 
83  }// end merge
84 
85  iEvent.put(std::move(outTracks),instance);
86 
87 }
88 
89 template <>
91 {
92 
93  produces<reco::TrackCollection>(instance).setBranchAlias( alias + "Tracks" );
94  produces<reco::TrackExtraCollection>(instance).setBranchAlias( alias + "TrackExtras" );
95  produces<TrackingRecHitCollection>(instance).setBranchAlias( alias + "RecHits" );
96  produces<TrackToTrackMapnew>();
97 
98 }
99 
100 template <>
102 {
103 
104  std::unique_ptr<reco::TrackCollection> outTracks = std::unique_ptr<reco::TrackCollection>(new reco::TrackCollection);
105  std::unique_ptr<reco::TrackExtraCollection> outTracks_ex = std::unique_ptr<reco::TrackExtraCollection>(new reco::TrackExtraCollection());
106  std::unique_ptr<TrackingRecHitCollection> outTracks_rh = std::unique_ptr<TrackingRecHitCollection>(new TrackingRecHitCollection());
107  std::unique_ptr<TrackToTrackMapnew> outTracks_refs = std::unique_ptr<TrackToTrackMapnew>(new TrackToTrackMapnew());
108 
109  auto rTrackExtras = iEvent.getRefBeforePut<reco::TrackExtraCollection>();
110  // auto rHits = iEvent.getRefBeforePut<TrackingRecHitCollection>();
111 
112  std::vector<reco::TrackRefVector> trackRefColl;
113  //std::vector<reco::TrackRef> trackRefColl;
114 
115  for (auto akt_collection : to_merge){
117  iEvent.getByToken(akt_collection, track_col_in);
118 
119  unsigned sedref_it = 0;
120  for (reco::TrackCollection::const_iterator it = track_col_in->begin(); it != track_col_in->end(); ++it, ++sedref_it) {
121  outTracks->push_back( reco::Track( *it ) );
122  outTracks_ex->push_back( reco::TrackExtra( *it->extra() ) );
123  outTracks->back().setExtra( reco::TrackExtraRef( rTrackExtras, outTracks_ex->size() - 1) );
124  reco::TrackRef trackRefold(track_col_in, sedref_it);
125 
126  reco::TrackRefVector trackRefColl_helpvec;
127  trackRefColl_helpvec.push_back(trackRefold);
128  trackRefColl.push_back(trackRefColl_helpvec);
129  }
130 
131  }// end merge
132 
133 
134  edm::OrphanHandle<reco::TrackCollection> trackHandle = iEvent.put(std::move(outTracks),instance);
135  iEvent.put(std::move(outTracks_ex),instance);
136 
137 
138  TrackToTrackMapnew::Filler filler(*outTracks_refs);
139  filler.insert(trackHandle, trackRefColl.begin(), trackRefColl.end() );
140  filler.fill();
141 
142  iEvent.put(std::move(outTracks_refs));
143  iEvent.put(std::move(outTracks_rh),instance); // not implemented so far
144 
145 }
146 
147 
148 
149 template <>
151 {
152  produces<reco::GsfTrackCollection>(instance).setBranchAlias( alias + "GsfTracks" );
153  produces<reco::TrackExtraCollection>(instance).setBranchAlias( alias + "TrackExtras" );
154  produces<reco::GsfTrackExtraCollection>(instance).setBranchAlias( alias + "GsfTrackExtras" );
155  produces<TrackingRecHitCollection>(instance).setBranchAlias( alias + "RecHits" );
156 }
157 
158 template <>
160 {
161  std::unique_ptr<reco::GsfTrackCollection> outTracks = std::unique_ptr<reco::GsfTrackCollection>(new reco::GsfTrackCollection);
162  std::unique_ptr<reco::TrackExtraCollection> outTracks_ex = std::unique_ptr<reco::TrackExtraCollection>(new reco::TrackExtraCollection());
163  std::unique_ptr<reco::GsfTrackExtraCollection> outTracks_exgsf = std::unique_ptr<reco::GsfTrackExtraCollection>(new reco::GsfTrackExtraCollection());
164  std::unique_ptr<TrackingRecHitCollection> outTracks_rh = std::unique_ptr<TrackingRecHitCollection>(new TrackingRecHitCollection());
165 
166 
167  auto rTrackExtras = iEvent.getRefBeforePut<reco::TrackExtraCollection>();
168  auto rTrackExtras_gsf = iEvent.getRefBeforePut<reco::GsfTrackExtraCollection>();
169 
170  auto rHits = iEvent.getRefBeforePut<TrackingRecHitCollection>();
171 
172  for (auto akt_collection : to_merge){
174  iEvent.getByToken(akt_collection, track_col_in);
175 
176  size_t sedref_it = 0;
177  for (reco::GsfTrackCollection::const_iterator it = track_col_in->begin(); it != track_col_in->end(); ++it, ++sedref_it) {
178  outTracks->push_back( reco::GsfTrack( *it ) );
179  outTracks_ex->push_back( reco::TrackExtra( *it->extra() ) );
180  outTracks_exgsf->push_back( reco::GsfTrackExtra( *it->gsfExtra() ) );
181 
182  outTracks->back().setExtra( reco::TrackExtraRef( rTrackExtras, outTracks_ex->size() - 1) );
183  outTracks->back().setGsfExtra( reco::GsfTrackExtraRef( rTrackExtras_gsf, outTracks_exgsf->size() - 1) );
184  }
185 
186  }// end merge
187 
188 
189  iEvent.put(std::move(outTracks),instance);
190  iEvent.put(std::move(outTracks_ex),instance);
191  iEvent.put(std::move(outTracks_exgsf),instance);
192  iEvent.put(std::move(outTracks_rh),instance);
193 
194 }
195 
196 
197 
198 template <>
200 {
201  produces<reco::MuonCollection>();
202  produces<reco::CaloMuonCollection>();
203  produces<reco::MuonTimeExtraMap>("combined");
204  produces<reco::MuonTimeExtraMap>("dt");
205  produces<reco::MuonTimeExtraMap>("csc");
206 
207  // todo make this configurable (or not )
208  produces<reco::IsoDepositMap>("tracker");
209  produces<reco::IsoDepositMap>("ecal");
210  produces<reco::IsoDepositMap>("hcal");
211  produces<reco::IsoDepositMap>("ho");
212  produces<reco::IsoDepositMap>("jets");
213 
214  produces<reco::MuonToMuonMap>();
215 
216 
217 }
218 
219 template <>
221 {
222 
223  inputs_fixtrackrefs_ = consumes<TrackToTrackMapnew >( edm::InputTag("generalTracks") );
224  inputs_fixtrackcol_ = consumes<reco::TrackCollection >( edm::InputTag("generalTracks") );
225 
226 
227 
228 }
229 
230 
231 template <>
233 {
234  std::unique_ptr<reco::MuonCollection> outTracks = std::unique_ptr<reco::MuonCollection>(new reco::MuonCollection);
235  std::unique_ptr<reco::CaloMuonCollection> calomu = std::unique_ptr<reco::CaloMuonCollection>(new reco::CaloMuonCollection); //not implemented so far
236 
237  edm::Handle<TrackToTrackMapnew> track_ref_map;
238  iEvent.getByToken(inputs_fixtrackrefs_, track_ref_map);
239 
241  iEvent.getByToken(inputs_fixtrackcol_, track_new_col);
242  std::map<reco::TrackRef , reco::TrackRef > simple_track_to_track_map; //I didn't find a more elegant way, so just build a good old fassion std::map
243  for (unsigned abc =0; abc < track_new_col->size(); ++abc) {
244  reco::TrackRef trackRef(track_new_col, abc);
245  simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef;
246  }
247 
248  std::vector<reco::MuonRef> muonRefColl;
249  reco::MuonRefProd outputMuonsRefProd = iEvent.getRefBeforePut<reco::MuonCollection>();
250  unsigned new_idx=0;
251  for (auto akt_collection : to_merge){
252  edm::Handle<reco::MuonCollection> track_col_in;
253  iEvent.getByToken(akt_collection, track_col_in);
254  unsigned old_idx=0;
255  for (reco::MuonCollection::const_iterator it = track_col_in->begin(); it != track_col_in->end(); ++it, ++old_idx, ++new_idx) {
256  outTracks->push_back( reco::Muon( *it ) );
257  reco::MuonRef muRefold(track_col_in, old_idx);
258  muonRefColl.push_back(muRefold);
259  reco::MuonRef muRefnew(outputMuonsRefProd, new_idx);
260 
261  if (it->track().isNonnull()){
262  //std::cout<<"pfmerge tr: "<<it->trackRef().id()<< " "<< it->trackRef().key()<< " " << simple_track_to_track_map[it->trackRef()].id() << " " << simple_track_to_track_map[it->trackRef()].key() <<std::endl;
263  outTracks->back().setTrack( simple_track_to_track_map[it->track()] );
264  }
265  }
266 
267  }// end merge
268 
269  const int nMuons=outTracks->size();
270 
271  std::vector<reco::MuonTimeExtra> dtTimeColl(nMuons);
272  std::vector<reco::MuonTimeExtra> cscTimeColl(nMuons);
273  std::vector<reco::MuonTimeExtra> combinedTimeColl(nMuons);
274  std::vector<reco::IsoDeposit> trackDepColl(nMuons);
275  std::vector<reco::IsoDeposit> ecalDepColl(nMuons);
276  std::vector<reco::IsoDeposit> hcalDepColl(nMuons);
277  std::vector<reco::IsoDeposit> hoDepColl(nMuons);
278  std::vector<reco::IsoDeposit> jetDepColl(nMuons);
279 
280  edm::OrphanHandle<reco::MuonCollection> muonHandle = iEvent.put(std::move(outTracks));
281 
282  auto fillMap = [](auto refH, auto& vec, edm::Event& ev, const std::string& cAl = ""){
284  std::unique_ptr<MapType > oMap(new MapType());
285  {
286  typename MapType::Filler filler(*oMap);
287  filler.insert(refH, vec.begin(), vec.end());
288  vec.clear();
289  filler.fill();
290  }
291  ev.put(std::move(oMap), cAl);
292  };
293 
294  fillMap(muonHandle, combinedTimeColl, iEvent, "combined");
295  fillMap(muonHandle, dtTimeColl, iEvent, "dt");
296  fillMap(muonHandle, cscTimeColl, iEvent, "csc");
297  fillMap(muonHandle, trackDepColl, iEvent, "tracker");
298  fillMap(muonHandle, ecalDepColl, iEvent, "ecal");
299  fillMap(muonHandle, hcalDepColl, iEvent, "hcal");
300  fillMap(muonHandle, hoDepColl, iEvent, "ho");
301  fillMap(muonHandle, jetDepColl, iEvent, "jets");
302  fillMap(muonHandle, muonRefColl, iEvent);
303  iEvent.put(std::move(calomu));
304 
305 }
306 
307 
308 
309 template <>
311 {
312 
313  produces<reco::PFCandidateCollection>(instance);
314  // std::cout<<"Produce PF Collection: "<<instance<<std::endl;
315 
316 }
317 
318 
319 template <>
321 {
322 
323  inputs_fixtrackrefs_ = consumes<TrackToTrackMapnew >( edm::InputTag("generalTracks") );
324  inputs_fixtrackcol_ = consumes<reco::TrackCollection >( edm::InputTag("generalTracks") );
325  inputs_fixmurefs_ = consumes<reco::MuonToMuonMap >( edm::InputTag("muons1stStep") );
326  inputs_fixmucol_ = consumes<reco::MuonCollection >( edm::InputTag("muons1stStep") );
327 
328 
329 }
330 
331 
332 
333 template <>
335 {
336  std::unique_ptr<reco::PFCandidateCollection> outTracks = std::unique_ptr<reco::PFCandidateCollection>(new reco::PFCandidateCollection);
337 
338  edm::Handle<TrackToTrackMapnew> track_ref_map;
339  iEvent.getByToken(inputs_fixtrackrefs_, track_ref_map);
340 
342  iEvent.getByToken(inputs_fixtrackcol_, track_new_col);
343  std::map<reco::TrackRef , reco::TrackRef > simple_track_to_track_map; //I didn't find a more elegant way, so just build a good old fassion std::map
344  for (unsigned abc =0; abc < track_new_col->size(); ++abc) {
345  reco::TrackRef trackRef(track_new_col, abc);
346  simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef;
347  }
348 
349 
351  iEvent.getByToken(inputs_fixmurefs_, muon_ref_map);
352 
354  iEvent.getByToken(inputs_fixmucol_, muon_new_col);
355  std::map<reco::MuonRef , reco::MuonRef > simple_mu_to_mu_map; //I didn't find a more elegant way, so just build a good old fassion std::map
356  for (unsigned abc =0; abc < muon_new_col->size(); ++abc) {
357  reco::MuonRef muRef(muon_new_col, abc);
358  simple_mu_to_mu_map[(*muon_ref_map)[muRef]] = muRef;
359  }
360 
361 
362 
363  for (auto akt_collection : to_merge){
365  iEvent.getByToken(akt_collection, track_col_in);
366  for (reco::PFCandidateCollection::const_iterator it = track_col_in->begin(); it != track_col_in->end(); ++it) {
367  outTracks->push_back( reco::PFCandidate( *it ) );
368  //if (fabs(it->pdgId()) == 13){
369  if (it->trackRef().isNonnull() && outTracks->back().charge()){
370  //std::cout<<"pfmerge tr: "<<it->trackRef().id()<< " "<< it->trackRef().key()<< " " << simple_track_to_track_map[it->trackRef()].id() << " " << simple_track_to_track_map[it->trackRef()].key() <<std::endl;
371  outTracks->back().setTrackRef( simple_track_to_track_map[it->trackRef()] );
372  }
373  if (it->muonRef().isNonnull()){
374  //std::cout<<"pfmerge mu: "<<it->muonRef().id()<< " "<< it->muonRef().key()<< " " << simple_mu_to_mu_map[it->muonRef()].id() << " " << simple_mu_to_mu_map[it->muonRef()].key() <<std::endl;
375  outTracks->back().setMuonRef( simple_mu_to_mu_map[it->muonRef()] );
376  }
377 
378  }
379  }// end merge
380 
381  iEvent.put(std::move(outTracks),instance);
382 
383 }
384 
385 
387 
void willconsume(const edm::ParameterSet &iConfig)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
static PFTauRenderPlugin instance
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::vector< CaloMuon > CaloMuonCollection
collection of Muon objects
Definition: MuonFwd.h:27
std::vector< GsfTrackExtra > GsfTrackExtraCollection
collection of GsfTrackExtra objects
bool ev
TrackMergeremb< reco::PFCandidateCollection > PFColMerger
void willproduce(std::string instance, std::string alias)
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
int iEvent
Definition: GenABIO.cc:230
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h:9
TrackMergeremb< reco::PhotonCollection > PhotonColMerger
RefProd< PROD > getRefBeforePut()
Definition: Event.h:147
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:11
edm::OwnVector< TrackingRecHit > TrackingRecHitCollection
collection of TrackingRecHits
void merg_and_put(edm::Event &, std::string, std::vector< edm::EDGetTokenT< TrackCollectionemb > > &)
TrackMergeremb< reco::GsfElectronCollection > GsfElectronColMerger
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:69
TrackMergeremb< reco::MuonCollection > MuonColMerger
TrackMergeremb< reco::TrackCollection > TrackColMerger
def move(src, dest)
Definition: eostools.py:510