CMS 3D CMS Logo

TrackMergeremb.cc
Go to the documentation of this file.
2 
4 
9 
12 
15 
18 
21 
33 
36 
39 
45 
46 // Here some overloaded functions, which are needed such that the right merger function is called for the indivudal Collections
47 template <typename T1>
49  produces<TrackCollectionemb>(instance);
50 }
51 
52 template <typename T1>
54 
55 template <typename T1>
58  std::vector<edm::EDGetTokenT<TrackCollectionemb> >& to_merge) {
59  std::unique_ptr<TrackCollectionemb> outTracks = std::unique_ptr<TrackCollectionemb>(new TrackCollectionemb);
60 
61  for (auto akt_collection : to_merge) {
63  iEvent.getByToken(akt_collection, track_col_in);
64 
65  size_t sedref_it = 0;
66  for (typename TrackCollectionemb::const_iterator it = track_col_in->begin(); it != track_col_in->end();
67  ++it, ++sedref_it) {
68  outTracks->push_back(typename T1::value_type(*it));
69  }
70 
71  } // end merge
72 
73  iEvent.put(std::move(outTracks), instance);
74 }
75 
76 template <>
78  produces<reco::TrackCollection>(instance).setBranchAlias(alias + "Tracks");
79  produces<reco::TrackExtraCollection>(instance).setBranchAlias(alias + "TrackExtras");
80  produces<TrackingRecHitCollection>(instance).setBranchAlias(alias + "RecHits");
81  produces<TrackToTrackMapnew>();
82 }
83 
84 template <>
87  std::unique_ptr<reco::TrackCollection> outTracks = std::unique_ptr<reco::TrackCollection>(new reco::TrackCollection);
88  std::unique_ptr<reco::TrackExtraCollection> outTracks_ex =
89  std::unique_ptr<reco::TrackExtraCollection>(new reco::TrackExtraCollection());
90  std::unique_ptr<TrackingRecHitCollection> outTracks_rh =
91  std::unique_ptr<TrackingRecHitCollection>(new TrackingRecHitCollection());
92  std::unique_ptr<TrackToTrackMapnew> outTracks_refs = std::unique_ptr<TrackToTrackMapnew>(new 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 =
142  std::unique_ptr<reco::GsfTrackCollection>(new reco::GsfTrackCollection);
143  std::unique_ptr<reco::TrackExtraCollection> outTracks_ex =
144  std::unique_ptr<reco::TrackExtraCollection>(new reco::TrackExtraCollection());
145  std::unique_ptr<reco::GsfTrackExtraCollection> outTracks_exgsf =
146  std::unique_ptr<reco::GsfTrackExtraCollection>(new reco::GsfTrackExtraCollection());
147  std::unique_ptr<TrackingRecHitCollection> outTracks_rh =
148  std::unique_ptr<TrackingRecHitCollection>(new TrackingRecHitCollection());
149 
150  auto rTrackExtras = iEvent.getRefBeforePut<reco::TrackExtraCollection>();
151  auto rTrackExtras_gsf = iEvent.getRefBeforePut<reco::GsfTrackExtraCollection>();
152 
153  auto rHits = iEvent.getRefBeforePut<TrackingRecHitCollection>();
154 
155  for (auto akt_collection : to_merge) {
157  iEvent.getByToken(akt_collection, track_col_in);
158 
159  size_t sedref_it = 0;
160  for (reco::GsfTrackCollection::const_iterator it = track_col_in->begin(); it != track_col_in->end();
161  ++it, ++sedref_it) {
162  outTracks->push_back(reco::GsfTrack(*it));
163  outTracks_ex->push_back(reco::TrackExtra(*it->extra()));
164  outTracks_exgsf->push_back(reco::GsfTrackExtra(*it->gsfExtra()));
165 
166  outTracks->back().setExtra(reco::TrackExtraRef(rTrackExtras, outTracks_ex->size() - 1));
167  outTracks->back().setGsfExtra(reco::GsfTrackExtraRef(rTrackExtras_gsf, outTracks_exgsf->size() - 1));
168  }
169 
170  } // end merge
171 
172  iEvent.put(std::move(outTracks), instance);
173  iEvent.put(std::move(outTracks_ex), instance);
174  iEvent.put(std::move(outTracks_exgsf), instance);
175  iEvent.put(std::move(outTracks_rh), instance);
176 }
177 
178 template <>
180  produces<reco::MuonCollection>();
181  produces<reco::CaloMuonCollection>();
182  produces<reco::MuonTimeExtraMap>("combined");
183  produces<reco::MuonTimeExtraMap>("dt");
184  produces<reco::MuonTimeExtraMap>("csc");
185 
186  // todo make this configurable (or not )
187  produces<reco::IsoDepositMap>("tracker");
188  produces<reco::IsoDepositMap>("ecal");
189  produces<reco::IsoDepositMap>("hcal");
190  produces<reco::IsoDepositMap>("ho");
191  produces<reco::IsoDepositMap>("jets");
192 
193  produces<reco::MuonToMuonMap>();
194 }
195 
196 template <>
198  inputs_fixtrackrefs_ = consumes<TrackToTrackMapnew>(edm::InputTag("generalTracks"));
199  inputs_fixtrackcol_ = consumes<reco::TrackCollection>(edm::InputTag("generalTracks"));
200 }
201 
202 template <>
205  std::unique_ptr<reco::MuonCollection> outTracks = std::unique_ptr<reco::MuonCollection>(new reco::MuonCollection);
206  std::unique_ptr<reco::CaloMuonCollection> calomu =
207  std::unique_ptr<reco::CaloMuonCollection>(new reco::CaloMuonCollection); //not implemented so far
208 
209  edm::Handle<TrackToTrackMapnew> track_ref_map;
210  iEvent.getByToken(inputs_fixtrackrefs_, track_ref_map);
211 
213  iEvent.getByToken(inputs_fixtrackcol_, track_new_col);
214  std::map<reco::TrackRef, reco::TrackRef>
215  simple_track_to_track_map; //I didn't find a more elegant way, so just build a good old fassion std::map
216  for (unsigned abc = 0; abc < track_new_col->size(); ++abc) {
217  reco::TrackRef trackRef(track_new_col, abc);
218  simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef;
219  }
220 
221  std::vector<reco::MuonRef> muonRefColl;
222  reco::MuonRefProd outputMuonsRefProd = iEvent.getRefBeforePut<reco::MuonCollection>();
223  unsigned new_idx = 0;
224  for (auto akt_collection : to_merge) {
226  iEvent.getByToken(akt_collection, track_col_in);
227  unsigned old_idx = 0;
228  for (reco::MuonCollection::const_iterator it = track_col_in->begin(); it != track_col_in->end();
229  ++it, ++old_idx, ++new_idx) {
230  outTracks->push_back(reco::Muon(*it));
231  reco::MuonRef muRefold(track_col_in, old_idx);
232  muonRefColl.push_back(muRefold);
233  reco::MuonRef muRefnew(outputMuonsRefProd, new_idx);
234 
235  if (it->track().isNonnull()) {
236  //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;
237  outTracks->back().setTrack(simple_track_to_track_map[it->track()]);
238  }
239  }
240 
241  } // end merge
242 
243  const int nMuons = outTracks->size();
244 
245  std::vector<reco::MuonTimeExtra> dtTimeColl(nMuons);
246  std::vector<reco::MuonTimeExtra> cscTimeColl(nMuons);
247  std::vector<reco::MuonTimeExtra> combinedTimeColl(nMuons);
248  std::vector<reco::IsoDeposit> trackDepColl(nMuons);
249  std::vector<reco::IsoDeposit> ecalDepColl(nMuons);
250  std::vector<reco::IsoDeposit> hcalDepColl(nMuons);
251  std::vector<reco::IsoDeposit> hoDepColl(nMuons);
252  std::vector<reco::IsoDeposit> jetDepColl(nMuons);
253 
254  edm::OrphanHandle<reco::MuonCollection> muonHandle = iEvent.put(std::move(outTracks));
255 
256  auto fillMap = [](auto refH, auto& vec, edm::Event& ev, const std::string& cAl = "") {
257  typedef edm::ValueMap<typename std::decay<decltype(vec)>::type::value_type> MapType;
258  std::unique_ptr<MapType> oMap(new MapType());
259  {
260  typename MapType::Filler filler(*oMap);
261  filler.insert(refH, vec.begin(), vec.end());
262  vec.clear();
263  filler.fill();
264  }
265  ev.put(std::move(oMap), cAl);
266  };
267 
268  fillMap(muonHandle, combinedTimeColl, iEvent, "combined");
269  fillMap(muonHandle, dtTimeColl, iEvent, "dt");
270  fillMap(muonHandle, cscTimeColl, iEvent, "csc");
271  fillMap(muonHandle, trackDepColl, iEvent, "tracker");
272  fillMap(muonHandle, ecalDepColl, iEvent, "ecal");
273  fillMap(muonHandle, hcalDepColl, iEvent, "hcal");
274  fillMap(muonHandle, hoDepColl, iEvent, "ho");
275  fillMap(muonHandle, jetDepColl, iEvent, "jets");
276  fillMap(muonHandle, muonRefColl, iEvent);
277  iEvent.put(std::move(calomu));
278 }
279 
280 template <>
282  produces<reco::PFCandidateCollection>(instance);
283  // std::cout<<"Produce PF Collection: "<<instance<<std::endl;
284 }
285 
286 template <>
288  inputs_fixtrackrefs_ = consumes<TrackToTrackMapnew>(edm::InputTag("generalTracks"));
289  inputs_fixtrackcol_ = consumes<reco::TrackCollection>(edm::InputTag("generalTracks"));
290  inputs_fixmurefs_ = consumes<reco::MuonToMuonMap>(edm::InputTag("muons1stStep"));
291  inputs_fixmucol_ = consumes<reco::MuonCollection>(edm::InputTag("muons1stStep"));
292 }
293 
294 template <>
297  std::unique_ptr<reco::PFCandidateCollection> outTracks =
298  std::unique_ptr<reco::PFCandidateCollection>(new reco::PFCandidateCollection);
299 
300  edm::Handle<TrackToTrackMapnew> track_ref_map;
301  iEvent.getByToken(inputs_fixtrackrefs_, track_ref_map);
302 
304  iEvent.getByToken(inputs_fixtrackcol_, track_new_col);
305  std::map<reco::TrackRef, reco::TrackRef>
306  simple_track_to_track_map; //I didn't find a more elegant way, so just build a good old fassion std::map
307  for (unsigned abc = 0; abc < track_new_col->size(); ++abc) {
308  reco::TrackRef trackRef(track_new_col, abc);
309  simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef;
310  }
311 
313  iEvent.getByToken(inputs_fixmurefs_, muon_ref_map);
314 
316  iEvent.getByToken(inputs_fixmucol_, muon_new_col);
317  std::map<reco::MuonRef, reco::MuonRef>
318  simple_mu_to_mu_map; //I didn't find a more elegant way, so just build a good old fassion std::map
319  for (unsigned abc = 0; abc < muon_new_col->size(); ++abc) {
320  reco::MuonRef muRef(muon_new_col, abc);
321  simple_mu_to_mu_map[(*muon_ref_map)[muRef]] = muRef;
322  }
323 
324  for (auto akt_collection : to_merge) {
326  iEvent.getByToken(akt_collection, track_col_in);
327  for (reco::PFCandidateCollection::const_iterator it = track_col_in->begin(); it != track_col_in->end(); ++it) {
328  outTracks->push_back(reco::PFCandidate(*it));
329  //if (fabs(it->pdgId()) == 13){
330  if (it->trackRef().isNonnull() && outTracks->back().charge()) {
331  //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;
332  outTracks->back().setTrackRef(simple_track_to_track_map[it->trackRef()]);
333  }
334  if (it->muonRef().isNonnull()) {
335  //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;
336  outTracks->back().setMuonRef(simple_mu_to_mu_map[it->muonRef()]);
337  }
338  }
339  } // end merge
340 
341  iEvent.put(std::move(outTracks), instance);
342 }
343 
345 
edm::RefProd< MuonCollection >
TrackExtra.h
Muon.h
GsfTrackExtra.h
TrackColMerger
TrackMergeremb< reco::TrackCollection > TrackColMerger
Definition: TrackMergeremb.cc:40
TrackMergeremb::willconsume
void willconsume(const edm::ParameterSet &iConfig)
Definition: TrackMergeremb.cc:53
PFCandidate.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
reco::GsfTrackExtraCollection
std::vector< GsfTrackExtra > GsfTrackExtraCollection
collection of GsfTrackExtra objects
Definition: GsfTrackExtraFwd.h:9
PhotonFwd.h
edm::RefVector< TrackCollection >
edm::Handle
Definition: AssociativeIterator.h:50
reco::Muon
Definition: Muon.h:27
edm::Ref< TrackExtraCollection >
PFColMerger
TrackMergeremb< reco::PFCandidateCollection > PFColMerger
Definition: TrackMergeremb.cc:44
reco::TrackExtra
Definition: TrackExtra.h:26
reco::GsfTrack
Definition: GsfTrack.h:12
MakerMacros.h
MuonTimeExtraMap.h
Photon.h
ConversionTrack.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
jets_cff.nMuons
nMuons
Definition: jets_cff.py:209
MuonFwd.h
reco::MuonCollection
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
MuonTimeExtra.h
MuonCocktails.h
reco::CaloMuonCollection
std::vector< CaloMuon > CaloMuonCollection
collection of Muon objects
Definition: MuonFwd.h:27
reco::Track
Definition: Track.h:27
reco::TrackExtraCollection
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:10
MuonColMerger
TrackMergeremb< reco::MuonCollection > MuonColMerger
Definition: TrackMergeremb.cc:41
ConversionTrackFwd.h
IsoDeposit.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TrackMergeremb::willproduce
void willproduce(std::string instance, std::string alias)
Definition: TrackMergeremb.cc:48
CaloMuon.h
edm::ParameterSet
Definition: ParameterSet.h:36
MuonTime.h
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
GsfTrackExtraFwd.h
iEvent
int iEvent
Definition: GenABIO.cc:224
GsfTrack.h
GsfElectronColMerger
TrackMergeremb< reco::GsfElectronCollection > GsfElectronColMerger
Definition: TrackMergeremb.cc:42
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
TrackMergeremb.h
MuonQuality.h
edm::RefVector::push_back
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67
PFRecTrack.h
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
ValueMap.h
TrackMergeremb
Definition: TrackMergeremb.h:34
MuonTimingFiller.h
PA_ZEESkim_cff.decay
decay
Definition: PA_ZEESkim_cff.py:26
reco::GsfTrackCollection
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h:9
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::OrphanHandle< reco::TrackCollection >
GsfTrackFwd.h
edm::ValueMap
Definition: ValueMap.h:107
SiStripOfflineCRack_cfg.alias
alias
Definition: SiStripOfflineCRack_cfg.py:129
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
TrackMergeremb::TrackCollectionemb
T1 TrackCollectionemb
Definition: TrackMergeremb.h:42
TrackingRecHitCollection
edm::OwnVector< TrackingRecHit > TrackingRecHitCollection
collection of TrackingRecHits
Definition: TrackingRecHitFwd.h:10
reco::PFCandidateCollection
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
Definition: PFCandidateFwd.h:12
PFRecTrackFwd.h
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
reco::GsfTrackExtra
Definition: GsfTrackExtra.h:16
IsoDepositFwd.h
edm::helper::Filler
Definition: ValueMap.h:22
PhotonColMerger
TrackMergeremb< reco::PhotonCollection > PhotonColMerger
Definition: TrackMergeremb.cc:43
edm::Event
Definition: Event.h:73
MapType
MapType
Definition: SiPixelTemplateDBObject_PayloadInspector.cc:51
edm::InputTag
Definition: InputTag.h:15
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
TrackMergeremb::merg_and_put
void merg_and_put(edm::Event &, std::string, std::vector< edm::EDGetTokenT< TrackCollectionemb > > &)
Definition: TrackMergeremb.cc:56
PFCandidateFwd.h
edm::OwnVector< TrackingRecHit >