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 
56 };
57 
59  : sipixelSimLinksToken_(
60  consumes<edm::DetSetVector<PixelDigiSimLink> >(cfg.getParameter<edm::InputTag>("pixelSimLinkSrc"))),
61  sistripSimLinksToken_(
62  consumes<edm::DetSetVector<StripDigiSimLink> >(cfg.getParameter<edm::InputTag>("stripSimLinkSrc"))),
63  siphase2OTSimLinksToken_(
64  consumes<edm::DetSetVector<PixelDigiSimLink> >(cfg.getParameter<edm::InputTag>("phase2OTSimLinkSrc"))),
65  pixelClustersToken_(
66  consumes<edmNew::DetSetVector<SiPixelCluster> >(cfg.getParameter<edm::InputTag>("pixelClusterSrc"))),
67  stripClustersToken_(
68  consumes<edmNew::DetSetVector<SiStripCluster> >(cfg.getParameter<edm::InputTag>("stripClusterSrc"))),
69  phase2OTClustersToken_(consumes<edmNew::DetSetVector<Phase2TrackerCluster1D> >(
70  cfg.getParameter<edm::InputTag>("phase2OTClusterSrc"))),
71  trackingParticleToken_(
72  consumes<TrackingParticleCollection>(cfg.getParameter<edm::InputTag>("trackingParticleSrc"))) {
73  produces<ClusterTPAssociation>();
74 }
75 
77 
80  desc.add<edm::InputTag>("simTrackSrc", edm::InputTag("g4SimHits"));
81  desc.add<edm::InputTag>("pixelSimLinkSrc", edm::InputTag("simSiPixelDigis"));
82  desc.add<edm::InputTag>("stripSimLinkSrc", edm::InputTag("simSiStripDigis"));
83  desc.add<edm::InputTag>("phase2OTSimLinkSrc", edm::InputTag("simSiPixelDigis", "Tracker"));
84  desc.add<edm::InputTag>("pixelClusterSrc", edm::InputTag("siPixelClusters"));
85  desc.add<edm::InputTag>("stripClusterSrc", edm::InputTag("siStripClusters"));
86  desc.add<edm::InputTag>("phase2OTClusterSrc", edm::InputTag("siPhase2Clusters"));
87  desc.add<edm::InputTag>("trackingParticleSrc", edm::InputTag("mix", "MergedTrackTruth"));
88  descriptions.add("tpClusterProducerDefault", desc);
89 }
90 
92  // Pixel DigiSimLink
94  // iEvent.getByLabel(_pixelSimLinkSrc, sipixelSimLinks);
95  iEvent.getByToken(sipixelSimLinksToken_, sipixelSimLinks);
96 
97  // SiStrip DigiSimLink
99  iEvent.getByToken(sistripSimLinksToken_, sistripSimLinks);
100 
101  // Phase2 OT DigiSimLink
103  iEvent.getByToken(siphase2OTSimLinksToken_, siphase2OTSimLinks);
104 
105  // Pixel Cluster
107  bool foundPixelClusters = iEvent.getByToken(pixelClustersToken_, pixelClusters);
108 
109  // Strip Cluster
111  bool foundStripClusters = iEvent.getByToken(stripClustersToken_, stripClusters);
112 
113  // Phase2 Cluster
115  bool foundPhase2OTClusters = iEvent.getByToken(phase2OTClustersToken_, phase2OTClusters);
116 
117  // TrackingParticle
119  iEvent.getByToken(trackingParticleToken_, TPCollectionH);
120 
121  auto clusterTPList = std::make_unique<ClusterTPAssociation>(TPCollectionH);
122 
123  // prepare temporary map between SimTrackId and TrackingParticle index
124  std::map<std::pair<size_t, EncodedEventId>, TrackingParticleRef> mapping;
125  for (TrackingParticleCollection::size_type itp = 0; itp < TPCollectionH.product()->size(); ++itp) {
126  TrackingParticleRef trackingParticle(TPCollectionH, itp);
127 
128  // SimTracks inside TrackingParticle
129  EncodedEventId eid(trackingParticle->eventId());
130  //size_t index = 0;
131  for (std::vector<SimTrack>::const_iterator itrk = trackingParticle->g4Track_begin();
132  itrk != trackingParticle->g4Track_end();
133  ++itrk) {
134  std::pair<uint32_t, EncodedEventId> trkid(itrk->trackId(), eid);
135  //std::cout << "creating map for id: " << trkid.first << " with tp: " << trackingParticle.key() << std::endl;
136  mapping.insert(std::make_pair(trkid, trackingParticle));
137  }
138  }
139 
140  if (foundPixelClusters) {
141  // Pixel Clusters
142  clusterTPList->addKeyID(pixelClusters.id());
144  iter != pixelClusters->end();
145  ++iter) {
146  uint32_t detid = iter->id();
147  DetId detId(detid);
148  edmNew::DetSet<SiPixelCluster> link_pixel = (*iter);
149  for (edmNew::DetSet<SiPixelCluster>::const_iterator di = link_pixel.begin(); di != link_pixel.end(); ++di) {
150  const SiPixelCluster& cluster = (*di);
152 
153  std::set<std::pair<uint32_t, EncodedEventId> > simTkIds;
154  for (int irow = cluster.minPixelRow(); irow <= cluster.maxPixelRow(); ++irow) {
155  for (int icol = cluster.minPixelCol(); icol <= cluster.maxPixelCol(); ++icol) {
156  uint32_t channel = PixelChannelIdentifier::pixelToChannel(irow, icol);
157  std::vector<std::pair<uint32_t, EncodedEventId> > trkid(
158  getSimTrackId<PixelDigiSimLink>(sipixelSimLinks, detId, channel));
159  if (trkid.empty())
160  continue;
161  simTkIds.insert(trkid.begin(), trkid.end());
162  }
163  }
164  for (std::set<std::pair<uint32_t, EncodedEventId> >::const_iterator iset = simTkIds.begin();
165  iset != simTkIds.end();
166  iset++) {
167  auto ipos = mapping.find(*iset);
168  if (ipos != mapping.end()) {
169  //std::cout << "cluster in detid: " << detid << " from tp: " << ipos->second.key() << " " << iset->first << std::endl;
170  clusterTPList->emplace_back(OmniClusterRef(c_ref), ipos->second);
171  }
172  }
173  }
174  }
175  }
176 
177  if (foundStripClusters) {
178  // Strip Clusters
179  clusterTPList->addKeyID(stripClusters.id());
181  eter = stripClusters->end(false);
182  iter != eter;
183  ++iter) {
184  if (!(*iter).isValid())
185  continue;
186  uint32_t detid = iter->id();
187  DetId detId(detid);
188  edmNew::DetSet<SiStripCluster> link_strip = (*iter);
189  for (edmNew::DetSet<SiStripCluster>::const_iterator di = link_strip.begin(); di != link_strip.end(); di++) {
190  const SiStripCluster& cluster = (*di);
192 
193  std::set<std::pair<uint32_t, EncodedEventId> > simTkIds;
194  int first = cluster.firstStrip();
195  int last = first + cluster.amplitudes().size();
196 
197  for (int istr = first; istr < last; ++istr) {
198  std::vector<std::pair<uint32_t, EncodedEventId> > trkid(
199  getSimTrackId<StripDigiSimLink>(sistripSimLinks, detId, istr));
200  if (trkid.empty())
201  continue;
202  simTkIds.insert(trkid.begin(), trkid.end());
203  }
204  for (std::set<std::pair<uint32_t, EncodedEventId> >::const_iterator iset = simTkIds.begin();
205  iset != simTkIds.end();
206  iset++) {
207  auto ipos = mapping.find(*iset);
208  if (ipos != mapping.end()) {
209  //std::cout << "cluster in detid: " << detid << " from tp: " << ipos->second.key() << " " << iset->first << std::endl;
210  clusterTPList->emplace_back(OmniClusterRef(c_ref), ipos->second);
211  }
212  }
213  }
214  }
215  }
216 
217  if (foundPhase2OTClusters) {
218  // Phase2 Clusters
219  clusterTPList->addKeyID(phase2OTClusters.id());
220  if (phase2OTClusters.isValid()) {
222  eter = phase2OTClusters->end(false);
223  iter != eter;
224  ++iter) {
225  if (!(*iter).isValid())
226  continue;
227  uint32_t detid = iter->id();
228  DetId detId(detid);
229  edmNew::DetSet<Phase2TrackerCluster1D> link_phase2 = (*iter);
230  for (edmNew::DetSet<Phase2TrackerCluster1D>::const_iterator di = link_phase2.begin(); di != link_phase2.end();
231  di++) {
232  const Phase2TrackerCluster1D& cluster = (*di);
235 
236  std::set<std::pair<uint32_t, EncodedEventId> > simTkIds;
237 
238  for (unsigned int istr(0); istr < cluster.size(); ++istr) {
239  uint32_t channel = Phase2TrackerDigi::pixelToChannel(cluster.firstRow() + istr, cluster.column());
240  std::vector<std::pair<uint32_t, EncodedEventId> > trkid(
241  getSimTrackId<PixelDigiSimLink>(siphase2OTSimLinks, detId, channel));
242  if (trkid.empty())
243  continue;
244  simTkIds.insert(trkid.begin(), trkid.end());
245  }
246 
247  for (std::set<std::pair<uint32_t, EncodedEventId> >::const_iterator iset = simTkIds.begin();
248  iset != simTkIds.end();
249  iset++) {
250  auto ipos = mapping.find(*iset);
251  if (ipos != mapping.end()) {
252  clusterTPList->emplace_back(OmniClusterRef(c_ref), ipos->second);
253  }
254  }
255  }
256  }
257  }
258  }
259  clusterTPList->sortAndUnique();
260  iEvent.put(std::move(clusterTPList));
261 }
262 
263 template <typename T>
264 std::vector<std::pair<uint32_t, EncodedEventId> >
265 //std::pair<uint32_t, EncodedEventId>
267  const DetId& detId,
268  uint32_t channel) const {
269  //std::pair<uint32_t, EncodedEventId> simTrkId;
270  std::vector<std::pair<uint32_t, EncodedEventId> > simTrkId;
271  auto isearch = simLinks->find(detId);
272  if (isearch != simLinks->end()) {
273  // Loop over DigiSimLink in this det unit
274  edm::DetSet<T> link_detset = (*isearch);
275  for (typename edm::DetSet<T>::const_iterator it = link_detset.data.begin(); it != link_detset.data.end(); ++it) {
276  if (channel == it->channel()) {
277  simTrkId.push_back(std::make_pair(it->SimTrackId(), it->eventId()));
278  }
279  }
280  }
281  return simTrkId;
282 }
285 
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:144
Handle.h
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:58
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:145
SiPixelCluster.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
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:143
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:28
edm::Handle
Definition: AssociativeIterator.h:50
OmniClusterRef
Definition: OmniClusterRef.h:12
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:46
EncodedEventId
Definition: EncodedEventId.h:11
DetId
Definition: DetId.h:17
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:142
edmNew::DetSet
Definition: DetSetNew.h:22
ParameterSetDescription.h
EDGetToken.h
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:112
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:63
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:58
DetSetVector.h
SiStripCluster::amplitudes
SiStripCluster const & amplitudes() const
Definition: SiStripCluster.h:68
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:266
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:78
ClusterTPAssociationProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: ClusterTPAssociationProducer.cc:91
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:9
Phase2TrackerCluster1D::size
uint16_t size() const
Definition: Phase2TrackerCluster1D.h:27
ClusterTPAssociationProducer::~ClusterTPAssociationProducer
~ClusterTPAssociationProducer() override
Definition: ClusterTPAssociationProducer.cc:76
ParameterSet.h
EDProducer.h
edm::Event
Definition: Event.h:73
SiStripCluster
Definition: SiStripCluster.h:8
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