CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TrackMergeremb.cc
Go to the documentation of this file.
2 
3 #include <memory>
4 
6 
11 
14 
17 
20 
23 
35 
38 
41 
47 
48 // Here some overloaded functions, which are needed such that the right merger function is called for the indivudal Collections
49 template <typename T1>
51  produces<TrackCollectionemb>(instance);
52 }
53 
54 template <typename T1>
56 
57 template <typename T1>
61  std::unique_ptr<TrackCollectionemb> outTracks = std::unique_ptr<TrackCollectionemb>(new TrackCollectionemb);
62 
63  for (auto akt_collection : to_merge) {
65  iEvent.getByToken(akt_collection, track_col_in);
66 
67  size_t sedref_it = 0;
68  for (typename TrackCollectionemb::const_iterator it = track_col_in->begin(); it != track_col_in->end();
69  ++it, ++sedref_it) {
70  outTracks->push_back(typename T1::value_type(*it));
71  }
72 
73  } // end merge
74 
75  iEvent.put(std::move(outTracks), instance);
76 }
77 
78 template <>
80  produces<reco::TrackCollection>(instance).setBranchAlias(alias + "Tracks");
81  produces<reco::TrackExtraCollection>(instance).setBranchAlias(alias + "TrackExtras");
82  produces<TrackingRecHitCollection>(instance).setBranchAlias(alias + "RecHits");
83  produces<TrackToTrackMapnew>();
84 }
85 
86 template <>
89  std::unique_ptr<reco::TrackCollection> outTracks = std::make_unique<reco::TrackCollection>();
90  std::unique_ptr<reco::TrackExtraCollection> outTracks_ex = std::make_unique<reco::TrackExtraCollection>();
91  std::unique_ptr<TrackingRecHitCollection> outTracks_rh = std::make_unique<TrackingRecHitCollection>();
92  std::unique_ptr<TrackToTrackMapnew> outTracks_refs = std::make_unique<TrackToTrackMapnew>();
93 
94  auto rTrackExtras = iEvent.getRefBeforePut<reco::TrackExtraCollection>();
95  // auto rHits = iEvent.getRefBeforePut<TrackingRecHitCollection>();
96 
97  std::vector<reco::TrackRefVector> trackRefColl;
98  //std::vector<reco::TrackRef> trackRefColl;
99 
100  for (auto akt_collection : to_merge) {
102  iEvent.getByToken(akt_collection, track_col_in);
103 
104  unsigned sedref_it = 0;
105  for (reco::TrackCollection::const_iterator it = track_col_in->begin(); it != track_col_in->end();
106  ++it, ++sedref_it) {
107  outTracks->push_back(reco::Track(*it));
108  outTracks_ex->push_back(reco::TrackExtra(*it->extra()));
109  outTracks->back().setExtra(reco::TrackExtraRef(rTrackExtras, outTracks_ex->size() - 1));
110  reco::TrackRef trackRefold(track_col_in, sedref_it);
111 
112  reco::TrackRefVector trackRefColl_helpvec;
113  trackRefColl_helpvec.push_back(trackRefold);
114  trackRefColl.push_back(trackRefColl_helpvec);
115  }
116 
117  } // end merge
118 
119  edm::OrphanHandle<reco::TrackCollection> trackHandle = iEvent.put(std::move(outTracks), instance);
120  iEvent.put(std::move(outTracks_ex), instance);
121 
122  TrackToTrackMapnew::Filler filler(*outTracks_refs);
123  filler.insert(trackHandle, trackRefColl.begin(), trackRefColl.end());
124  filler.fill();
125 
126  iEvent.put(std::move(outTracks_refs));
127  iEvent.put(std::move(outTracks_rh), instance); // not implemented so far
128 }
129 
130 template <>
132  produces<reco::GsfTrackCollection>(instance).setBranchAlias(alias + "GsfTracks");
133  produces<reco::TrackExtraCollection>(instance).setBranchAlias(alias + "TrackExtras");
134  produces<reco::GsfTrackExtraCollection>(instance).setBranchAlias(alias + "GsfTrackExtras");
135  produces<TrackingRecHitCollection>(instance).setBranchAlias(alias + "RecHits");
136 }
137 
138 template <>
141  std::unique_ptr<reco::GsfTrackCollection> outTracks = std::make_unique<reco::GsfTrackCollection>();
142  std::unique_ptr<reco::TrackExtraCollection> outTracks_ex = std::make_unique<reco::TrackExtraCollection>();
143  std::unique_ptr<reco::GsfTrackExtraCollection> outTracks_exgsf = std::make_unique<reco::GsfTrackExtraCollection>();
144  std::unique_ptr<TrackingRecHitCollection> outTracks_rh = std::make_unique<TrackingRecHitCollection>();
145 
146  auto rTrackExtras = iEvent.getRefBeforePut<reco::TrackExtraCollection>();
147  auto rTrackExtras_gsf = iEvent.getRefBeforePut<reco::GsfTrackExtraCollection>();
148 
149  auto rHits = iEvent.getRefBeforePut<TrackingRecHitCollection>();
150 
151  for (auto akt_collection : to_merge) {
153  iEvent.getByToken(akt_collection, track_col_in);
154 
155  size_t sedref_it = 0;
156  for (reco::GsfTrackCollection::const_iterator it = track_col_in->begin(); it != track_col_in->end();
157  ++it, ++sedref_it) {
158  outTracks->push_back(reco::GsfTrack(*it));
159  outTracks_ex->push_back(reco::TrackExtra(*it->extra()));
160  outTracks_exgsf->push_back(reco::GsfTrackExtra(*it->gsfExtra()));
161 
162  outTracks->back().setExtra(reco::TrackExtraRef(rTrackExtras, outTracks_ex->size() - 1));
163  outTracks->back().setGsfExtra(reco::GsfTrackExtraRef(rTrackExtras_gsf, outTracks_exgsf->size() - 1));
164  }
165 
166  } // end merge
167 
168  iEvent.put(std::move(outTracks), instance);
169  iEvent.put(std::move(outTracks_ex), instance);
170  iEvent.put(std::move(outTracks_exgsf), instance);
171  iEvent.put(std::move(outTracks_rh), instance);
172 }
173 
174 template <>
176  produces<reco::MuonCollection>();
177  produces<reco::CaloMuonCollection>();
178  produces<reco::MuonTimeExtraMap>("combined");
179  produces<reco::MuonTimeExtraMap>("dt");
180  produces<reco::MuonTimeExtraMap>("csc");
181 
182  // todo make this configurable (or not )
183  produces<reco::IsoDepositMap>("tracker");
184  produces<reco::IsoDepositMap>("ecal");
185  produces<reco::IsoDepositMap>("hcal");
186  produces<reco::IsoDepositMap>("ho");
187  produces<reco::IsoDepositMap>("jets");
188 
189  produces<reco::MuonToMuonMap>();
190 }
191 
192 template <>
194  inputs_fixtrackrefs_ = consumes<TrackToTrackMapnew>(edm::InputTag("generalTracks"));
195  inputs_fixtrackcol_ = consumes<reco::TrackCollection>(edm::InputTag("generalTracks"));
196 }
197 
198 template <>
201  std::unique_ptr<reco::MuonCollection> outTracks = std::make_unique<reco::MuonCollection>();
202  std::unique_ptr<reco::CaloMuonCollection> calomu =
203  std::make_unique<reco::CaloMuonCollection>(); //not implemented so far
204 
205  edm::Handle<TrackToTrackMapnew> track_ref_map;
206  iEvent.getByToken(inputs_fixtrackrefs_, track_ref_map);
207 
209  iEvent.getByToken(inputs_fixtrackcol_, track_new_col);
210  std::map<reco::TrackRef, reco::TrackRef>
211  simple_track_to_track_map; //I didn't find a more elegant way, so just build a good old fassion std::map
212  for (unsigned abc = 0; abc < track_new_col->size(); ++abc) {
213  reco::TrackRef trackRef(track_new_col, abc);
214  simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef;
215  }
216 
217  std::vector<reco::MuonRef> muonRefColl;
218  reco::MuonRefProd outputMuonsRefProd = iEvent.getRefBeforePut<reco::MuonCollection>();
219  unsigned new_idx = 0;
220  for (auto akt_collection : to_merge) {
222  iEvent.getByToken(akt_collection, track_col_in);
223  unsigned old_idx = 0;
224  for (reco::MuonCollection::const_iterator it = track_col_in->begin(); it != track_col_in->end();
225  ++it, ++old_idx, ++new_idx) {
226  outTracks->push_back(reco::Muon(*it));
227  reco::MuonRef muRefold(track_col_in, old_idx);
228  muonRefColl.push_back(muRefold);
229  reco::MuonRef muRefnew(outputMuonsRefProd, new_idx);
230 
231  if (it->track().isNonnull()) {
232  //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;
233  outTracks->back().setTrack(simple_track_to_track_map[it->track()]);
234  }
235  }
236 
237  } // end merge
238 
239  const int nMuons = outTracks->size();
240 
241  std::vector<reco::MuonTimeExtra> dtTimeColl(nMuons);
242  std::vector<reco::MuonTimeExtra> cscTimeColl(nMuons);
243  std::vector<reco::MuonTimeExtra> combinedTimeColl(nMuons);
244  std::vector<reco::IsoDeposit> trackDepColl(nMuons);
245  std::vector<reco::IsoDeposit> ecalDepColl(nMuons);
246  std::vector<reco::IsoDeposit> hcalDepColl(nMuons);
247  std::vector<reco::IsoDeposit> hoDepColl(nMuons);
248  std::vector<reco::IsoDeposit> jetDepColl(nMuons);
249 
250  edm::OrphanHandle<reco::MuonCollection> muonHandle = iEvent.put(std::move(outTracks));
251 
252  auto fillMap = [](auto refH, auto& vec, edm::Event& ev, const std::string& cAl = "") {
254  std::unique_ptr<MapType> oMap(new MapType());
255  {
256  typename MapType::Filler filler(*oMap);
257  filler.insert(refH, vec.begin(), vec.end());
258  vec.clear();
259  filler.fill();
260  }
261  ev.put(std::move(oMap), cAl);
262  };
263 
264  fillMap(muonHandle, combinedTimeColl, iEvent, "combined");
265  fillMap(muonHandle, dtTimeColl, iEvent, "dt");
266  fillMap(muonHandle, cscTimeColl, iEvent, "csc");
267  fillMap(muonHandle, trackDepColl, iEvent, "tracker");
268  fillMap(muonHandle, ecalDepColl, iEvent, "ecal");
269  fillMap(muonHandle, hcalDepColl, iEvent, "hcal");
270  fillMap(muonHandle, hoDepColl, iEvent, "ho");
271  fillMap(muonHandle, jetDepColl, iEvent, "jets");
272  fillMap(muonHandle, muonRefColl, iEvent);
273  iEvent.put(std::move(calomu));
274 }
275 
276 template <>
278  produces<reco::PFCandidateCollection>(instance);
279  // std::cout<<"Produce PF Collection: "<<instance<<std::endl;
280 }
281 
282 template <>
284  inputs_fixtrackrefs_ = consumes<TrackToTrackMapnew>(edm::InputTag("generalTracks"));
285  inputs_fixtrackcol_ = consumes<reco::TrackCollection>(edm::InputTag("generalTracks"));
286  inputs_fixmurefs_ = consumes<reco::MuonToMuonMap>(edm::InputTag("muons1stStep"));
287  inputs_fixmucol_ = consumes<reco::MuonCollection>(edm::InputTag("muons1stStep"));
288 }
289 
290 template <>
293  std::unique_ptr<reco::PFCandidateCollection> outTracks = std::make_unique<reco::PFCandidateCollection>();
294 
295  edm::Handle<TrackToTrackMapnew> track_ref_map;
296  iEvent.getByToken(inputs_fixtrackrefs_, track_ref_map);
297 
299  iEvent.getByToken(inputs_fixtrackcol_, track_new_col);
300  std::map<reco::TrackRef, reco::TrackRef>
301  simple_track_to_track_map; //I didn't find a more elegant way, so just build a good old fassion std::map
302  for (unsigned abc = 0; abc < track_new_col->size(); ++abc) {
303  reco::TrackRef trackRef(track_new_col, abc);
304  simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef;
305  }
306 
308  iEvent.getByToken(inputs_fixmurefs_, muon_ref_map);
309 
311  iEvent.getByToken(inputs_fixmucol_, muon_new_col);
312  std::map<reco::MuonRef, reco::MuonRef>
313  simple_mu_to_mu_map; //I didn't find a more elegant way, so just build a good old fassion std::map
314  for (unsigned abc = 0; abc < muon_new_col->size(); ++abc) {
315  reco::MuonRef muRef(muon_new_col, abc);
316  simple_mu_to_mu_map[(*muon_ref_map)[muRef]] = muRef;
317  }
318 
319  for (auto akt_collection : to_merge) {
321  iEvent.getByToken(akt_collection, track_col_in);
322  for (reco::PFCandidateCollection::const_iterator it = track_col_in->begin(); it != track_col_in->end(); ++it) {
323  outTracks->push_back(reco::PFCandidate(*it));
324  //if (fabs(it->pdgId()) == 13){
325  if (it->trackRef().isNonnull() && outTracks->back().charge()) {
326  //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;
327  outTracks->back().setTrackRef(simple_track_to_track_map[it->trackRef()]);
328  }
329  if (it->muonRef().isNonnull()) {
330  //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;
331  outTracks->back().setMuonRef(simple_mu_to_mu_map[it->muonRef()]);
332  }
333  }
334  } // end merge
335 
336  iEvent.put(std::move(outTracks), instance);
337 }
338 
340 
TrackMergeremb< reco::PFCandidateCollection > PFColMerger
void willconsume(const edm::ParameterSet &iConfig)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
TrackMergeremb< reco::MuonCollection > MuonColMerger
static PFTauRenderPlugin instance
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
std::vector< GsfTrackExtra > GsfTrackExtraCollection
collection of GsfTrackExtra objects
bool ev
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:224
TrackMergeremb< reco::GsfElectronCollection > GsfElectronColMerger
def move
Definition: eostools.py:511
RefProd< PROD > getRefBeforePut()
Definition: Event.h:158
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:10
void merg_and_put(edm::Event &, std::string, std::vector< edm::EDGetTokenT< TrackCollectionemb > > &)
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
TrackMergeremb< reco::PhotonCollection > PhotonColMerger
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:67
TrackMergeremb< reco::TrackCollection > TrackColMerger