CMS 3D CMS Logo

CollectionMerger.cc
Go to the documentation of this file.
3 
6 
9 
12 
15 
17 
21 
27 
31 
34 
36 
38 
41 
44 
47 
55 
59 
60 template <typename T1, typename T2>
62  std::vector<edm::InputTag> inCollections = iConfig.getParameter<std::vector<edm::InputTag>>("mergCollections");
63  for (auto const &inCollection : inCollections) {
64  inputs_[inCollection.instance()].push_back(consumes<MergeCollection>(inCollection));
65  }
66  willconsume(iConfig);
67  for (const auto &toproduce : inputs_) {
68  std::string alias(iConfig.getParameter<std::string>("@module_label"));
69  willproduce(toproduce.first, alias);
70  }
71 }
72 
73 template <typename T1, typename T2>
75  // nothing to be done yet...
76 }
77 
78 template <typename T1, typename T2>
80  for (auto input_ : inputs_) {
81  std::unique_ptr<MergeCollection> output(new MergeCollection());
82  std::vector<edm::Handle<MergeCollection>> inputCollections;
83  inputCollections.resize(input_.second.size());
84  for (unsigned id = 0; id < input_.second.size(); id++) {
85  iEvent.getByToken(input_.second[id], inputCollections[id]);
86  }
87  fill_output_obj(iEvent, output, inputCollections);
88  iEvent.put(std::move(output), input_.first);
89  }
90 }
91 
92 template <typename T1, typename T2>
94 
95 template <typename T1, typename T2>
97  produces<MergeCollection>(instance);
98 }
99 
100 // -------- Here Tracker Merger -----------
101 template <typename T1, typename T2>
102 void CollectionMerger<T1, T2>::fill_output_obj_tracker(std::unique_ptr<MergeCollection> &output,
103  std::vector<edm::Handle<MergeCollection>> &inputCollections,
104  bool print_pixel) {
105  std::map<uint32_t, std::vector<BaseHit>> output_map;
106  // First merge the collections with the help of the output map
107  for (auto const &inputCollection : inputCollections) {
108  for (typename MergeCollection::const_iterator clustSet = inputCollection->begin();
109  clustSet != inputCollection->end();
110  ++clustSet) {
111  DetId detIdObject(clustSet->detId());
112  for (typename edmNew::DetSet<BaseHit>::const_iterator clustIt = clustSet->begin(); clustIt != clustSet->end();
113  ++clustIt) {
114  output_map[detIdObject.rawId()].push_back(*clustIt);
115  }
116  }
117  }
118  // Now save it into the standard CMSSW format, with the standard Filler
119  for (typename std::map<uint32_t, std::vector<BaseHit>>::const_iterator outHits = output_map.begin();
120  outHits != output_map.end();
121  ++outHits) {
122  DetId detIdObject(outHits->first);
123  typename MergeCollection::FastFiller spc(*output, detIdObject);
124  for (const auto &Hit : outHits->second) {
125  spc.push_back(Hit);
126  }
127  }
128 }
129 
130 template <typename T1, typename T2>
131 void CollectionMerger<T1, T2>::fill_output_obj_calo(std::unique_ptr<MergeCollection> &output,
132  std::vector<edm::Handle<MergeCollection>> &inputCollections) {
133  std::map<uint32_t, BaseHit> output_map;
134  // First merge the two collections again
135  for (auto const &inputCollection : inputCollections) {
136  for (typename MergeCollection::const_iterator recHit = inputCollection->begin(); recHit != inputCollection->end();
137  ++recHit) {
138  DetId detIdObject(recHit->detid().rawId());
139  T2 *akt_calo_obj = &output_map[detIdObject.rawId()];
140  float new_energy = akt_calo_obj->energy() + recHit->energy();
141  T2 newRecHit(*recHit);
142  newRecHit.setEnergy(new_energy);
143  *akt_calo_obj = newRecHit;
144  }
145  }
146  // Now save it into the standard CMSSW format
147  for (typename std::map<uint32_t, BaseHit>::const_iterator outHits = output_map.begin(); outHits != output_map.end();
148  ++outHits) {
149  output->push_back(outHits->second);
150  }
151  output->sort(); // Do a sort for this collection
152 }
153 
154 // -------- Here Muon Chamber Merger -----------
155 template <typename T1, typename T2>
157  std::unique_ptr<MergeCollection> &output, std::vector<edm::Handle<MergeCollection>> &inputCollections) {
158  std::map<uint32_t, std::vector<BaseHit>> output_map;
159  // First merge the collections with the help of the output map
160  for (auto const &inputCollection : inputCollections) {
161  for (typename MergeCollection::const_iterator recHit = inputCollection->begin(); recHit != inputCollection->end();
162  ++recHit) {
163  DetId detIdObject(recHit->geographicalId());
164  output_map[detIdObject].push_back(*recHit);
165  }
166  }
167  // Now save it into the standard CMSSW format, with the standard Filler
168  for (typename std::map<uint32_t, std::vector<BaseHit>>::const_iterator outHits = output_map.begin();
169  outHits != output_map.end();
170  ++outHits) {
171  output->put((typename T1::id_iterator::value_type)outHits->first,
172  outHits->second.begin(),
173  outHits->second.end()); // The DTLayerId misses the automatic type cast
174  }
175 }
176 
177 // -------- Here Electron Seed Merger -----------
178 // TODO: move seed merger to TrackMerger class
179 template <>
181  const edm::ParameterSet &iConfig) {
182  // track refs for trackerdriven seeds
183  inputs_fixtrackrefs_ = consumes<TrackToTrackMapnew>(edm::InputTag("generalTracks"));
184  inputs_fixtrackcol_ = consumes<reco::TrackCollection>(edm::InputTag("generalTracks"));
185 
186  // sc refs for ecaldriven seeds
187  inputs_scEB_ = consumes<reco::SuperClusterCollection>(
188  edm::InputTag("particleFlowSuperClusterECAL:particleFlowSuperClusterECALBarrel"));
189  inputs_scEE_ = consumes<reco::SuperClusterCollection>(
190  edm::InputTag("particleFlowSuperClusterECAL:particleFlowSuperClusterECALEndcapWithPreshower"));
191 }
192 
193 template <>
195  std::string alias) {
196  produces<MergeCollection>(instance);
197 }
198 
199 template <typename T1, typename T2>
201  std::unique_ptr<MergeCollection> &output,
202  std::vector<edm::Handle<MergeCollection>> &inputCollections) {
203  // track to track map for trackerdriven seed fix
204  edm::Handle<TrackToTrackMapnew> track_ref_map;
205  iEvent.getByToken(inputs_fixtrackrefs_, track_ref_map);
206 
208  iEvent.getByToken(inputs_fixtrackcol_, track_new_col);
209  std::map<reco::TrackRef, reco::TrackRef> simple_track_to_track_map;
210  for (unsigned abc = 0; abc < track_new_col->size(); ++abc) {
211  reco::TrackRef trackRef(track_new_col, abc);
212  simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef;
213  }
214 
215  // ECAL barrel supercluster collection
217  iEvent.getByToken(inputs_scEB_, scEB);
218  auto bScEB = scEB->cbegin();
219  auto eScEB = scEB->cend();
220 
221  // ECAL endcap supercluster collection
223  iEvent.getByToken(inputs_scEE_, scEE);
224  auto bScEE = scEE->cbegin();
225  auto eScEE = scEE->cend();
226 
227  // First merge the two collections again
228  for (auto const &inputCollection : inputCollections) {
229  for (typename MergeCollection::const_iterator seed = inputCollection->begin(); seed != inputCollection->end();
230  ++seed) {
231  T2 newSeed(*seed);
232 
233  // fix reference to supercluster if seed is ecal driven
234  if (seed->isEcalDriven()) {
235  const reco::ElectronSeed::CaloClusterRef &seedCcRef(seed->caloCluster());
236  if (seedCcRef.isNonnull()) {
237  // find corresponding supercluster in ECAL barrel and endcap
238  float dx, dy, dz, dr;
241  for (auto sc = bScEB; sc != eScEB; ++sc) {
242  const reco::SuperClusterRef &scRef(reco::SuperClusterRef(scEB, std::distance(bScEB, sc)));
243  dx = fabs(scRef->x() - seedCcRef->x());
244  dy = fabs(scRef->y() - seedCcRef->y());
245  dz = fabs(scRef->z() - seedCcRef->z());
246  dr = sqrt(dx * dx + dy * dy + dz * dz);
247  if (dr < drMin) {
248  drMin = dr;
249  ccRefMin = reco::ElectronSeed::CaloClusterRef(scRef);
250  }
251  }
252  for (auto sc = bScEE; sc != eScEE; ++sc) {
253  const reco::SuperClusterRef &scRef(reco::SuperClusterRef(scEE, std::distance(bScEE, sc)));
254  dx = fabs(scRef->x() - seedCcRef->x());
255  dy = fabs(scRef->y() - seedCcRef->y());
256  dz = fabs(scRef->z() - seedCcRef->z());
257  dr = sqrt(dx * dx + dy * dy + dz * dz);
258  if (dr < drMin) {
259  drMin = dr;
260  ccRefMin = reco::ElectronSeed::CaloClusterRef(scRef);
261  }
262  }
263  // set new calocluster if new ref was found
264  if (drMin < 10.0) {
265  newSeed.setCaloCluster(ccRefMin);
266  }
267  }
268  }
269  if (seed->isTrackerDriven()) {
270  const reco::ElectronSeed::CtfTrackRef &ctfTrackRef(seed->ctfTrack());
271  if (ctfTrackRef.isNonnull()) {
272  newSeed.setCtfTrack(simple_track_to_track_map[ctfTrackRef]);
273  }
274  }
275  output->push_back(newSeed);
276  }
277  }
278 }
279 
280 // Here some overloaded functions, which are needed such that the right merger function is called for the indivudal Collections
281 template <typename T1, typename T2>
283  std::unique_ptr<MergeCollection> &output,
284  std::vector<edm::Handle<MergeCollection>> &inputCollections) {
285  assert(0);
286 }
287 
288 // Start with the Tracker collections
289 template <>
292  std::unique_ptr<MergeCollection> &output,
293  std::vector<edm::Handle<MergeCollection>> &inputCollections) {
294  fill_output_obj_tracker(output, inputCollections, true);
295 }
296 
297 template <>
300  std::unique_ptr<MergeCollection> &output,
301  std::vector<edm::Handle<MergeCollection>> &inputCollections) {
302  fill_output_obj_tracker(output, inputCollections);
303 }
304 
305 template <>
308  std::unique_ptr<MergeCollection> &output,
309  std::vector<edm::Handle<MergeCollection>> &inputCollections) {
310  fill_output_obj_calo(output, inputCollections);
311 }
312 
313 template <>
316  std::unique_ptr<MergeCollection> &output,
317  std::vector<edm::Handle<MergeCollection>> &inputCollections) {
318  fill_output_obj_calo(output, inputCollections);
319 }
320 
321 template <>
324  std::unique_ptr<MergeCollection> &output,
325  std::vector<edm::Handle<MergeCollection>> &inputCollections) {
326  fill_output_obj_calo(output, inputCollections);
327 }
328 
329 template <>
332  std::unique_ptr<MergeCollection> &output,
333  std::vector<edm::Handle<MergeCollection>> &inputCollections) {
334  fill_output_obj_calo(output, inputCollections);
335 }
336 
337 template <>
340  std::unique_ptr<MergeCollection> &output,
341  std::vector<edm::Handle<MergeCollection>> &inputCollections) {
342  fill_output_obj_calo(output, inputCollections);
343 }
344 
345 template <>
348  std::unique_ptr<MergeCollection> &output,
349  std::vector<edm::Handle<MergeCollection>> &inputCollections) {
350  fill_output_obj_muonchamber(output, inputCollections);
351 }
352 
353 template <>
356  std::unique_ptr<MergeCollection> &output,
357  std::vector<edm::Handle<MergeCollection>> &inputCollections) {
358  fill_output_obj_muonchamber(output, inputCollections);
359 }
360 
361 template <>
364  std::unique_ptr<MergeCollection> &output,
365  std::vector<edm::Handle<MergeCollection>> &inputCollections) {
366  fill_output_obj_muonchamber(output, inputCollections);
367 }
368 
369 template <>
372  std::unique_ptr<MergeCollection> &output,
373  std::vector<edm::Handle<MergeCollection>> &inputCollections) {
374  fill_output_obj_seed(iEvent, output, inputCollections);
375 }
376 
379 
382 
388 
CollectionMerger< edm::SortedCollection< HORecHit >, HORecHit > HORecHitColMerger
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
~CollectionMerger() override
void fill_output_obj_muonchamber(std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection >> &inputCollections)
CollectionMerger< std::vector< reco::ElectronSeed >, reco::ElectronSeed > EcalDrivenElectronSeedColMerger
static PFTauRenderPlugin instance
void fill_output_obj_calo(std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection >> &inputCollections)
data_type const * const_iterator
Definition: DetSetNew.h:31
void willproduce(std::string instance, std::string alias)
assert(be >=bs)
int iEvent
Definition: GenABIO.cc:224
T sqrt(T t)
Definition: SSEVec.h:23
const double infinity
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
CollectionMerger< edmNew::DetSetVector< SiPixelCluster >, SiPixelCluster > PixelColMerger
void fill_output_obj(edm::Event &, std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection >> &inputCollections)
void produce(edm::Event &, const edm::EventSetup &) override
Definition: DetId.h:17
CollectionMerger< edm::SortedCollection< ZDCRecHit >, ZDCRecHit > ZDCRecHitColMerger
edm::RefToBase< CaloCluster > CaloClusterRef
Definition: ElectronSeed.h:68
void fill_output_obj_seed(edm::Event &, std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection >> &inputCollections)
void willconsume(const edm::ParameterSet &iConfig)
Pixel cluster – collection of neighboring pixels above threshold.
void fill_output_obj_tracker(std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection >> &inputCollections, bool print_pixel=false)
CollectionMerger< std::vector< reco::ElectronSeed >, reco::ElectronSeed > ElectronSeedColMerger
CollectionMerger< edmNew::DetSetVector< SiStripCluster >, SiStripCluster > StripColMerger
CollectionMerger< edm::RangeMap< DTLayerId, edm::OwnVector< DTRecHit1DPair > >, DTRecHit1DPair > DTRecHitColMerger
Definition: output.py:1
CollectionMerger< edm::RangeMap< CSCDetId, edm::OwnVector< CSCRecHit2D > >, CSCRecHit2D > CSCRecHitColMerger
CollectionMerger< edm::SortedCollection< HFRecHit >, HFRecHit > HFRecHitColMerger
CollectionMerger(const edm::ParameterSet &)
CollectionMerger< edm::RangeMap< RPCDetId, edm::OwnVector< RPCRecHit > >, RPCRecHit > RPCRecHitColMerger
CollectionMerger< edm::SortedCollection< HBHERecHit >, HBHERecHit > HBHERecHitColMerger
def move(src, dest)
Definition: eostools.py:511
CollectionMerger< edm::SortedCollection< EcalRecHit >, EcalRecHit > EcalRecHitColMerger