CMS 3D CMS Logo

ClusterTPAssociationProducer.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <vector>
3 #include <utility>
4 
13 
23 
31 
33 public:
34  typedef std::vector<OmniClusterRef> OmniClusterCollection;
35 
38 
39  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
40 
41 private:
42  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
43 
44  template <typename T>
45  std::vector<std::pair<uint32_t, EncodedEventId> > getSimTrackId(const edm::Handle<edm::DetSetVector<T> >& simLinks,
46  const DetId& detId,
47  uint32_t channel) const;
48 
57 };
58 
60  : sipixelSimLinksToken_(
61  consumes<edm::DetSetVector<PixelDigiSimLink> >(cfg.getParameter<edm::InputTag>("pixelSimLinkSrc"))),
62  sistripSimLinksToken_(
63  consumes<edm::DetSetVector<StripDigiSimLink> >(cfg.getParameter<edm::InputTag>("stripSimLinkSrc"))),
64  siphase2OTSimLinksToken_(
65  consumes<edm::DetSetVector<PixelDigiSimLink> >(cfg.getParameter<edm::InputTag>("phase2OTSimLinkSrc"))),
66  pixelClustersToken_(
67  consumes<edmNew::DetSetVector<SiPixelCluster> >(cfg.getParameter<edm::InputTag>("pixelClusterSrc"))),
68  stripClustersToken_(
69  consumes<edmNew::DetSetVector<SiStripCluster> >(cfg.getParameter<edm::InputTag>("stripClusterSrc"))),
70  phase2OTClustersToken_(consumes<edmNew::DetSetVector<Phase2TrackerCluster1D> >(
71  cfg.getParameter<edm::InputTag>("phase2OTClusterSrc"))),
72  trackingParticleToken_(
73  consumes<TrackingParticleCollection>(cfg.getParameter<edm::InputTag>("trackingParticleSrc"))),
74  throwOnMissingCollections_(cfg.getParameter<bool>("throwOnMissingCollections")) {
75  produces<ClusterTPAssociation>();
76 }
77 
79 
82  desc.add<edm::InputTag>("simTrackSrc", edm::InputTag("g4SimHits"));
83  desc.add<edm::InputTag>("pixelSimLinkSrc", edm::InputTag("simSiPixelDigis"));
84  desc.add<edm::InputTag>("stripSimLinkSrc", edm::InputTag("simSiStripDigis"));
85  desc.add<edm::InputTag>("phase2OTSimLinkSrc", edm::InputTag("simSiPixelDigis", "Tracker"));
86  desc.add<edm::InputTag>("pixelClusterSrc", edm::InputTag("siPixelClusters"));
87  desc.add<edm::InputTag>("stripClusterSrc", edm::InputTag("siStripClusters"));
88  desc.add<edm::InputTag>("phase2OTClusterSrc", edm::InputTag("siPhase2Clusters"));
89  desc.add<edm::InputTag>("trackingParticleSrc", edm::InputTag("mix", "MergedTrackTruth"));
90  desc.add<bool>("throwOnMissingCollections", true);
91  descriptions.add("tpClusterProducerDefault", desc);
92 }
93 
95  // Pixel Cluster
97  bool foundPixelClusters = iEvent.getByToken(pixelClustersToken_, pixelClusters);
98 
99  // Strip Cluster
101  bool foundStripClusters = iEvent.getByToken(stripClustersToken_, stripClusters);
102 
103  // Phase2 Cluster
105  bool foundPhase2OTClusters = iEvent.getByToken(phase2OTClustersToken_, phase2OTClusters);
106 
107  // Pixel DigiSimLink
109  // iEvent.getByLabel(_pixelSimLinkSrc, sipixelSimLinks);
110  auto pixelSimLinksFound = iEvent.getByToken(sipixelSimLinksToken_, sipixelSimLinks);
111  if (not throwOnMissingCollections_ and foundPixelClusters and not pixelSimLinksFound) {
112  auto clusterTPList = std::make_unique<ClusterTPAssociation>();
113  iEvent.put(std::move(clusterTPList));
114  return;
115  }
116 
117  // SiStrip DigiSimLink
119  auto stripSimLinksFound = iEvent.getByToken(sistripSimLinksToken_, sistripSimLinks);
120  if (not throwOnMissingCollections_ and foundStripClusters and not stripSimLinksFound) {
121  auto clusterTPList = std::make_unique<ClusterTPAssociation>();
122  iEvent.put(std::move(clusterTPList));
123  return;
124  }
125 
126  // Phase2 OT DigiSimLink
128  auto phase2OTSimLinksFound = iEvent.getByToken(siphase2OTSimLinksToken_, siphase2OTSimLinks);
129  if (not throwOnMissingCollections_ and foundPhase2OTClusters and not phase2OTSimLinksFound) {
130  auto clusterTPList = std::make_unique<ClusterTPAssociation>();
131  iEvent.put(std::move(clusterTPList));
132  return;
133  }
134 
135  // TrackingParticle
137  auto tpFound = iEvent.getByToken(trackingParticleToken_, TPCollectionH);
138  if (not throwOnMissingCollections_ and not tpFound) {
139  auto clusterTPList = std::make_unique<ClusterTPAssociation>();
140  iEvent.put(std::move(clusterTPList));
141  return;
142  }
143 
144  auto clusterTPList = std::make_unique<ClusterTPAssociation>(TPCollectionH);
145 
146  // prepare temporary map between SimTrackId and TrackingParticle index
147  std::map<std::pair<size_t, EncodedEventId>, TrackingParticleRef> mapping;
148  for (TrackingParticleCollection::size_type itp = 0; itp < TPCollectionH.product()->size(); ++itp) {
149  TrackingParticleRef trackingParticle(TPCollectionH, itp);
150 
151  // SimTracks inside TrackingParticle
152  EncodedEventId eid(trackingParticle->eventId());
153  //size_t index = 0;
154  for (std::vector<SimTrack>::const_iterator itrk = trackingParticle->g4Track_begin();
155  itrk != trackingParticle->g4Track_end();
156  ++itrk) {
157  std::pair<uint32_t, EncodedEventId> trkid(itrk->trackId(), eid);
158  //std::cout << "creating map for id: " << trkid.first << " with tp: " << trackingParticle.key() << std::endl;
159  mapping.insert(std::make_pair(trkid, trackingParticle));
160  }
161  }
162 
163  if (foundPixelClusters) {
164  // Pixel Clusters
165  clusterTPList->addKeyID(pixelClusters.id());
167  iter != pixelClusters->end();
168  ++iter) {
169  uint32_t detid = iter->id();
170  DetId detId(detid);
171  edmNew::DetSet<SiPixelCluster> link_pixel = (*iter);
172  for (edmNew::DetSet<SiPixelCluster>::const_iterator di = link_pixel.begin(); di != link_pixel.end(); ++di) {
173  const SiPixelCluster& cluster = (*di);
175 
176  std::set<std::pair<uint32_t, EncodedEventId> > simTkIds;
177  for (int irow = cluster.minPixelRow(); irow <= cluster.maxPixelRow(); ++irow) {
178  for (int icol = cluster.minPixelCol(); icol <= cluster.maxPixelCol(); ++icol) {
179  uint32_t channel = PixelChannelIdentifier::pixelToChannel(irow, icol);
180  std::vector<std::pair<uint32_t, EncodedEventId> > trkid(
181  getSimTrackId<PixelDigiSimLink>(sipixelSimLinks, detId, channel));
182  if (trkid.empty())
183  continue;
184  simTkIds.insert(trkid.begin(), trkid.end());
185  }
186  }
187  for (std::set<std::pair<uint32_t, EncodedEventId> >::const_iterator iset = simTkIds.begin();
188  iset != simTkIds.end();
189  iset++) {
190  auto ipos = mapping.find(*iset);
191  if (ipos != mapping.end()) {
192  //std::cout << "cluster in detid: " << detid << " from tp: " << ipos->second.key() << " " << iset->first << std::endl;
193  clusterTPList->emplace_back(OmniClusterRef(c_ref), ipos->second);
194  }
195  }
196  }
197  }
198  }
199 
200  if (foundStripClusters) {
201  // Strip Clusters
202  clusterTPList->addKeyID(stripClusters.id());
204  eter = stripClusters->end(false);
205  iter != eter;
206  ++iter) {
207  if (!(*iter).isValid())
208  continue;
209  uint32_t detid = iter->id();
210  DetId detId(detid);
211  edmNew::DetSet<SiStripCluster> link_strip = (*iter);
212  for (edmNew::DetSet<SiStripCluster>::const_iterator di = link_strip.begin(); di != link_strip.end(); di++) {
213  const SiStripCluster& cluster = (*di);
215 
216  std::set<std::pair<uint32_t, EncodedEventId> > simTkIds;
217  int first = cluster.firstStrip();
218  int last = first + cluster.amplitudes().size();
219 
220  for (int istr = first; istr < last; ++istr) {
221  std::vector<std::pair<uint32_t, EncodedEventId> > trkid(
222  getSimTrackId<StripDigiSimLink>(sistripSimLinks, detId, istr));
223  if (trkid.empty())
224  continue;
225  simTkIds.insert(trkid.begin(), trkid.end());
226  }
227  for (std::set<std::pair<uint32_t, EncodedEventId> >::const_iterator iset = simTkIds.begin();
228  iset != simTkIds.end();
229  iset++) {
230  auto ipos = mapping.find(*iset);
231  if (ipos != mapping.end()) {
232  //std::cout << "cluster in detid: " << detid << " from tp: " << ipos->second.key() << " " << iset->first << std::endl;
233  clusterTPList->emplace_back(OmniClusterRef(c_ref), ipos->second);
234  }
235  }
236  }
237  }
238  }
239 
240  if (foundPhase2OTClusters) {
241  // Phase2 Clusters
242  clusterTPList->addKeyID(phase2OTClusters.id());
243  if (phase2OTClusters.isValid()) {
245  eter = phase2OTClusters->end(false);
246  iter != eter;
247  ++iter) {
248  if (!(*iter).isValid())
249  continue;
250  uint32_t detid = iter->id();
251  DetId detId(detid);
252  edmNew::DetSet<Phase2TrackerCluster1D> link_phase2 = (*iter);
253  for (edmNew::DetSet<Phase2TrackerCluster1D>::const_iterator di = link_phase2.begin(); di != link_phase2.end();
254  di++) {
255  const Phase2TrackerCluster1D& cluster = (*di);
258 
259  std::set<std::pair<uint32_t, EncodedEventId> > simTkIds;
260 
261  for (unsigned int istr(0); istr < cluster.size(); ++istr) {
262  uint32_t channel = Phase2TrackerDigi::pixelToChannel(cluster.firstRow() + istr, cluster.column());
263  std::vector<std::pair<uint32_t, EncodedEventId> > trkid(
264  getSimTrackId<PixelDigiSimLink>(siphase2OTSimLinks, detId, channel));
265  if (trkid.empty())
266  continue;
267  simTkIds.insert(trkid.begin(), trkid.end());
268  }
269 
270  for (std::set<std::pair<uint32_t, EncodedEventId> >::const_iterator iset = simTkIds.begin();
271  iset != simTkIds.end();
272  iset++) {
273  auto ipos = mapping.find(*iset);
274  if (ipos != mapping.end()) {
275  clusterTPList->emplace_back(OmniClusterRef(c_ref), ipos->second);
276  }
277  }
278  }
279  }
280  }
281  }
282  clusterTPList->sortAndUnique();
283  iEvent.put(std::move(clusterTPList));
284 }
285 
286 template <typename T>
287 std::vector<std::pair<uint32_t, EncodedEventId> >
288 //std::pair<uint32_t, EncodedEventId>
290  const DetId& detId,
291  uint32_t channel) const {
292  //std::pair<uint32_t, EncodedEventId> simTrkId;
293  std::vector<std::pair<uint32_t, EncodedEventId> > simTrkId;
294  auto isearch = simLinks->find(detId);
295  if (isearch != simLinks->end()) {
296  // Loop over DigiSimLink in this det unit
297  edm::DetSet<T> link_detset = (*isearch);
298  for (typename edm::DetSet<T>::const_iterator it = link_detset.data.begin(); it != link_detset.data.end(); ++it) {
299  if (channel == it->channel()) {
300  simTrkId.push_back(std::make_pair(it->SimTrackId(), it->eventId()));
301  }
302  }
303  }
304  return simTrkId;
305 }
308 
ConfigurationDescriptions.h
ClusterTPAssociationProducer::stripClustersToken_
edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > stripClustersToken_
Definition: ClusterTPAssociationProducer.cc:53
edm::DetSet::push_back
void push_back(const T &t)
Definition: DetSet.h:66
edm::DetSetVector
Definition: DetSetVector.h:61
edm::StreamID
Definition: StreamID.h:30
SiPixelCluster::minPixelCol
int minPixelCol() const
Definition: SiPixelCluster.h:140
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:393
LumiMonitor_cff.pixelClusters
pixelClusters
Definition: LumiMonitor_cff.py:10
edm::Handle::product
T const * product() const
Definition: Handle.h:70
ClusterTPAssociationProducer::ClusterTPAssociationProducer
ClusterTPAssociationProducer(const edm::ParameterSet &)
Definition: ClusterTPAssociationProducer.cc:59
Phase2TrackerCluster1D
Definition: Phase2TrackerCluster1D.h:10
Phase2TrackerCluster1D::column
unsigned int column() const
Definition: Phase2TrackerCluster1D.h:26
edm::DetSet
Definition: DetSet.h:23
ClusterTPAssociationProducer::trackingParticleToken_
edm::EDGetTokenT< TrackingParticleCollection > trackingParticleToken_
Definition: ClusterTPAssociationProducer.cc:55
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
SiPixelCluster::maxPixelCol
int maxPixelCol() const
Definition: SiPixelCluster.h:141
SiPixelCluster.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edmNew::makeRefTo
edm::Ref< typename HandleT::element_type, typename HandleT::element_type::value_type::value_type > makeRefTo(const HandleT &iHandle, typename HandleT::element_type::value_type::const_iterator itIter)
Definition: DetSetVectorNew.h:689
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edmNew::DetSetVector::const_iterator
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetSetVectorNew.h:197
Phase2TrackerCluster1D::firstRow
unsigned int firstRow() const
Definition: Phase2TrackerCluster1D.h:24
SiPixelCluster::maxPixelRow
int maxPixelRow() const
Definition: SiPixelCluster.h:139
PixelChannelIdentifier.h
ClusterTPAssociationProducer::sipixelSimLinksToken_
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > sipixelSimLinksToken_
Definition: ClusterTPAssociationProducer.cc:49
ClusterTPAssociationProducer
Definition: ClusterTPAssociationProducer.cc:32
SiPixelCluster
Pixel cluster – collection of neighboring pixels above threshold.
Definition: SiPixelCluster.h:27
edm::Handle
Definition: AssociativeIterator.h:50
OmniClusterRef
Definition: OmniClusterRef.h:12
dqmdumpme.first
first
Definition: dqmdumpme.py:55
HLTEgPhaseIITestSequence_cff.phase2OTClusters
phase2OTClusters
Definition: HLTEgPhaseIITestSequence_cff.py:722
edmNew
Definition: DetSet2RangeMap.h:11
edm::Ref< TrackingParticleCollection >
Phase2TrackerDigi::pixelToChannel
static PackedDigiType pixelToChannel(unsigned int row, unsigned int col)
Definition: Phase2TrackerDigi.h:43
SiStripCluster::firstStrip
uint16_t firstStrip() const
Definition: SiStripCluster.h:47
EncodedEventId
Definition: EncodedEventId.h:11
DetId
Definition: DetId.h:17
ClusterTPAssociationProducer::throwOnMissingCollections_
bool throwOnMissingCollections_
Definition: ClusterTPAssociationProducer.cc:56
edmNew::DetSet::end
iterator end()
Definition: DetSetNew.h:56
MakerMacros.h
dqmdumpme.last
last
Definition: dqmdumpme.py:56
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
PixelChannelIdentifier::pixelToChannel
static int pixelToChannel(int row, int col)
Definition: PixelChannelIdentifier.h:65
SiPixelCluster::minPixelRow
int minPixelRow() const
Definition: SiPixelCluster.h:138
edmNew::DetSet
Definition: DetSetNew.h:22
ParameterSetDescription.h
EDGetToken.h
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
HLT_FULL_cff.stripClusters
stripClusters
Definition: HLT_FULL_cff.py:10014
Phase2TrackerDigi.h
edm::ParameterSet
Definition: ParameterSet.h:47
SiStripCluster.h
Event.h
ClusterTPAssociationProducer::sistripSimLinksToken_
edm::EDGetTokenT< edm::DetSetVector< StripDigiSimLink > > sistripSimLinksToken_
Definition: ClusterTPAssociationProducer.cc:50
ModuleDef.h
SiStripCluster::size
uint8_t size() const
Definition: SiStripCluster.h:64
iEvent
int iEvent
Definition: GenABIO.cc:224
runTauDisplay.eid
eid
Definition: runTauDisplay.py:298
edmNew::DetSet::begin
iterator begin()
Definition: DetSetNew.h:54
edm::EventSetup
Definition: EventSetup.h:57
DetSetVector.h
SiStripCluster::amplitudes
SiStripCluster const & amplitudes() const
Definition: SiStripCluster.h:69
OmniClusterRef.h
ClusterTPAssociationProducer::getSimTrackId
std::vector< std::pair< uint32_t, EncodedEventId > > getSimTrackId(const edm::Handle< edm::DetSetVector< T > > &simLinks, const DetId &detId, uint32_t channel) const
Definition: ClusterTPAssociationProducer.cc:289
InputTag.h
looper.cfg
cfg
Definition: looper.py:297
ClusterTPAssociationProducer::phase2OTClustersToken_
edm::EDGetTokenT< edmNew::DetSetVector< Phase2TrackerCluster1D > > phase2OTClustersToken_
Definition: ClusterTPAssociationProducer.cc:54
TrackingParticle.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
ClusterTPAssociationProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: ClusterTPAssociationProducer.cc:80
ClusterTPAssociationProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: ClusterTPAssociationProducer.cc:94
TrackingParticleFwd.h
DetId.h
Frameworkfwd.h
ClusterTPAssociationProducer::pixelClustersToken_
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > pixelClustersToken_
Definition: ClusterTPAssociationProducer.cc:52
ClusterTPAssociationProducer::OmniClusterCollection
std::vector< OmniClusterRef > OmniClusterCollection
Definition: ClusterTPAssociationProducer.cc:34
Phase2TrackerCluster1D.h
edm::DetSet::data
collection_type data
Definition: DetSet.h:80
TrackingParticleCollection
std::vector< TrackingParticle > TrackingParticleCollection
Definition: TrackingParticleFwd.h:8
Phase2TrackerCluster1D::size
uint16_t size() const
Definition: Phase2TrackerCluster1D.h:27
ClusterTPAssociationProducer::~ClusterTPAssociationProducer
~ClusterTPAssociationProducer() override
Definition: ClusterTPAssociationProducer.cc:78
ParameterSet.h
EDProducer.h
edm::Event
Definition: Event.h:73
SiStripCluster
Definition: SiStripCluster.h:9
taus_updatedMVAIds_cff.mapping
mapping
Definition: taus_updatedMVAIds_cff.py:29
SimTrackContainer.h
DetSetVectorNew.h
edm::InputTag
Definition: InputTag.h:15
ClusterTPAssociation.h
edmNew::DetSet::const_iterator
const data_type * const_iterator
Definition: DetSetNew.h:31
edm::DetSet::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSet.h:31
ClusterTPAssociationProducer::siphase2OTSimLinksToken_
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > siphase2OTSimLinksToken_
Definition: ClusterTPAssociationProducer.cc:51