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 {
34 public:
35  typedef std::vector<OmniClusterRef> OmniClusterCollection;
36 
39 
40  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
41 
42 private:
43  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
44 
45  template <typename T>
46  std::vector<std::pair<uint32_t, EncodedEventId> >
47  getSimTrackId(const edm::Handle<edm::DetSetVector<T> >& simLinks, const DetId& detId, uint32_t channel) const;
48 
56 };
57 
59  : sipixelSimLinksToken_(consumes<edm::DetSetVector<PixelDigiSimLink> >(cfg.getParameter<edm::InputTag>("pixelSimLinkSrc"))),
60  sistripSimLinksToken_(consumes<edm::DetSetVector<StripDigiSimLink> >(cfg.getParameter<edm::InputTag>("stripSimLinkSrc"))),
61  siphase2OTSimLinksToken_(consumes<edm::DetSetVector<PixelDigiSimLink> >(cfg.getParameter<edm::InputTag>("phase2OTSimLinkSrc"))),
62  pixelClustersToken_(consumes<edmNew::DetSetVector<SiPixelCluster> >(cfg.getParameter<edm::InputTag>("pixelClusterSrc"))),
63  stripClustersToken_(consumes<edmNew::DetSetVector<SiStripCluster> >(cfg.getParameter<edm::InputTag>("stripClusterSrc"))),
64  phase2OTClustersToken_(consumes<edmNew::DetSetVector<Phase2TrackerCluster1D> >(cfg.getParameter<edm::InputTag>("phase2OTClusterSrc"))),
65  trackingParticleToken_(consumes<TrackingParticleCollection>(cfg.getParameter<edm::InputTag>("trackingParticleSrc")))
66 {
67  produces<ClusterTPAssociation>();
68 }
69 
71 }
72 
75  desc.add<edm::InputTag>("simTrackSrc", edm::InputTag("g4SimHits"));
76  desc.add<edm::InputTag>("pixelSimLinkSrc", edm::InputTag("simSiPixelDigis"));
77  desc.add<edm::InputTag>("stripSimLinkSrc", edm::InputTag("simSiStripDigis"));
78  desc.add<edm::InputTag>("phase2OTSimLinkSrc", edm::InputTag("simSiPixelDigis","Tracker"));
79  desc.add<edm::InputTag>("pixelClusterSrc", edm::InputTag("siPixelClusters"));
80  desc.add<edm::InputTag>("stripClusterSrc", edm::InputTag("siStripClusters"));
81  desc.add<edm::InputTag>("phase2OTClusterSrc", edm::InputTag("siPhase2Clusters"));
82  desc.add<edm::InputTag>("trackingParticleSrc", edm::InputTag("mix", "MergedTrackTruth"));
83  descriptions.add("tpClusterProducerDefault", desc);
84 }
85 
87  // Pixel DigiSimLink
89  // iEvent.getByLabel(_pixelSimLinkSrc, sipixelSimLinks);
90  iEvent.getByToken(sipixelSimLinksToken_,sipixelSimLinks);
91 
92  // SiStrip DigiSimLink
94  iEvent.getByToken(sistripSimLinksToken_,sistripSimLinks);
95 
96  // Phase2 OT DigiSimLink
98  iEvent.getByToken(siphase2OTSimLinksToken_, siphase2OTSimLinks);
99 
100  // Pixel Cluster
102  bool foundPixelClusters = iEvent.getByToken(pixelClustersToken_,pixelClusters);
103 
104  // Strip Cluster
106  bool foundStripClusters = iEvent.getByToken(stripClustersToken_,stripClusters);
107 
108  // Phase2 Cluster
110  bool foundPhase2OTClusters = iEvent.getByToken(phase2OTClustersToken_, phase2OTClusters);
111 
112  // TrackingParticle
114  iEvent.getByToken(trackingParticleToken_,TPCollectionH);
115 
116  auto clusterTPList = std::make_unique<ClusterTPAssociation>(TPCollectionH);
117 
118  // prepare temporary map between SimTrackId and TrackingParticle index
119  std::map<std::pair<size_t, EncodedEventId>, TrackingParticleRef> mapping;
121  itp < TPCollectionH.product()->size(); ++itp) {
122  TrackingParticleRef trackingParticle(TPCollectionH, itp);
123 
124  // SimTracks inside TrackingParticle
125  EncodedEventId eid(trackingParticle->eventId());
126  //size_t index = 0;
127  for (std::vector<SimTrack>::const_iterator itrk = trackingParticle->g4Track_begin();
128  itrk != trackingParticle->g4Track_end(); ++itrk) {
129  std::pair<uint32_t, EncodedEventId> trkid(itrk->trackId(), eid);
130  //std::cout << "creating map for id: " << trkid.first << " with tp: " << trackingParticle.key() << std::endl;
131  mapping.insert(std::make_pair(trkid, trackingParticle));
132  }
133  }
134 
135  if ( foundPixelClusters ) {
136  // Pixel Clusters
137  clusterTPList->addKeyID(pixelClusters.id());
138  for (edmNew::DetSetVector<SiPixelCluster>::const_iterator iter = pixelClusters->begin();
139  iter != pixelClusters->end(); ++iter) {
140  uint32_t detid = iter->id();
141  DetId detId(detid);
142  edmNew::DetSet<SiPixelCluster> link_pixel = (*iter);
144  di != link_pixel.end(); ++di) {
145  const SiPixelCluster& cluster = (*di);
147  edmNew::makeRefTo(pixelClusters, di);
148 
149  std::set<std::pair<uint32_t, EncodedEventId> > simTkIds;
150  for (int irow = cluster.minPixelRow(); irow <= cluster.maxPixelRow(); ++irow) {
151  for (int icol = cluster.minPixelCol(); icol <= cluster.maxPixelCol(); ++icol) {
152  uint32_t channel = PixelChannelIdentifier::pixelToChannel(irow, icol);
153  std::vector<std::pair<uint32_t, EncodedEventId> > trkid(getSimTrackId<PixelDigiSimLink>(sipixelSimLinks, detId, channel));
154  if (trkid.empty()) continue;
155  simTkIds.insert(trkid.begin(),trkid.end());
156  }
157  }
158  for (std::set<std::pair<uint32_t, EncodedEventId> >::const_iterator iset = simTkIds.begin();
159  iset != simTkIds.end(); iset++) {
160  auto ipos = mapping.find(*iset);
161  if (ipos != mapping.end()) {
162  //std::cout << "cluster in detid: " << detid << " from tp: " << ipos->second.key() << " " << iset->first << std::endl;
163  clusterTPList->emplace_back(OmniClusterRef(c_ref), ipos->second);
164  }
165  }
166  }
167  }
168  }
169 
170  if ( foundStripClusters ) {
171  // Strip Clusters
172  clusterTPList->addKeyID(stripClusters.id());
173  for (edmNew::DetSetVector<SiStripCluster>::const_iterator iter = stripClusters->begin(false), eter = stripClusters->end(false);
174  iter != eter; ++iter) {
175  if (!(*iter).isValid()) continue;
176  uint32_t detid = iter->id();
177  DetId detId(detid);
178  edmNew::DetSet<SiStripCluster> link_strip = (*iter);
180  di != link_strip.end(); di++) {
181  const SiStripCluster& cluster = (*di);
183  edmNew::makeRefTo(stripClusters, di);
184 
185  std::set<std::pair<uint32_t, EncodedEventId> > simTkIds;
186  int first = cluster.firstStrip();
187  int last = first + cluster.amplitudes().size();
188 
189  for (int istr = first; istr < last; ++istr) {
190  std::vector<std::pair<uint32_t, EncodedEventId> > trkid(getSimTrackId<StripDigiSimLink>(sistripSimLinks, detId, istr));
191  if (trkid.empty()) continue;
192  simTkIds.insert(trkid.begin(),trkid.end());
193  }
194  for (std::set<std::pair<uint32_t, EncodedEventId> >::const_iterator iset = simTkIds.begin();
195  iset != simTkIds.end(); iset++) {
196  auto ipos = mapping.find(*iset);
197  if (ipos != mapping.end()) {
198  //std::cout << "cluster in detid: " << detid << " from tp: " << ipos->second.key() << " " << iset->first << std::endl;
199  clusterTPList->emplace_back(OmniClusterRef(c_ref), ipos->second);
200  }
201  }
202  }
203  }
204  }
205 
206  if ( foundPhase2OTClusters ) {
207  // Phase2 Clusters
208  clusterTPList->addKeyID(phase2OTClusters.id());
209  if(phase2OTClusters.isValid()){
210  for (edmNew::DetSetVector<Phase2TrackerCluster1D>::const_iterator iter = phase2OTClusters->begin(false), eter = phase2OTClusters->end(false);
211  iter != eter; ++iter) {
212  if (!(*iter).isValid()) continue;
213  uint32_t detid = iter->id();
214  DetId detId(detid);
215  edmNew::DetSet<Phase2TrackerCluster1D> link_phase2 = (*iter);
217  di != link_phase2.end(); di++) {
218  const Phase2TrackerCluster1D& cluster = (*di);
220  edmNew::makeRefTo(phase2OTClusters, di);
221 
222  std::set<std::pair<uint32_t, EncodedEventId> > simTkIds;
223 
224  for (unsigned int istr(0); istr < cluster.size(); ++istr) {
225  uint32_t channel = Phase2TrackerDigi::pixelToChannel(cluster.firstRow() + istr, cluster.column());
226  std::vector<std::pair<uint32_t, EncodedEventId> > trkid(getSimTrackId<PixelDigiSimLink>(siphase2OTSimLinks, detId, channel));
227  if (trkid.empty()) continue;
228  simTkIds.insert(trkid.begin(),trkid.end());
229  }
230 
231  for (std::set<std::pair<uint32_t, EncodedEventId> >::const_iterator iset = simTkIds.begin();
232  iset != simTkIds.end(); iset++) {
233  auto ipos = mapping.find(*iset);
234  if (ipos != mapping.end()) {
235  clusterTPList->emplace_back(OmniClusterRef(c_ref), ipos->second);
236  }
237  }
238  }
239  }
240  }
241 
242  }
243  clusterTPList->sortAndUnique();
244  iEvent.put(std::move(clusterTPList));
245 }
246 
247 template <typename T>
248 std::vector<std::pair<uint32_t, EncodedEventId> >
249 //std::pair<uint32_t, EncodedEventId>
251  const DetId& detId, uint32_t channel) const
252 {
253  //std::pair<uint32_t, EncodedEventId> simTrkId;
254  std::vector<std::pair<uint32_t, EncodedEventId> > simTrkId;
255  auto isearch = simLinks->find(detId);
256  if (isearch != simLinks->end()) {
257  // Loop over DigiSimLink in this det unit
258  edm::DetSet<T> link_detset = (*isearch);
259  for (typename edm::DetSet<T>::const_iterator it = link_detset.data.begin();
260  it != link_detset.data.end(); ++it) {
261  if (channel == it->channel()) {
262  simTrkId.push_back(std::make_pair(it->SimTrackId(), it->eventId()));
263  }
264  }
265  }
266  return simTrkId;
267 }
270 
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
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)
int minPixelCol() const
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
void push_back(const T &t)
Definition: DetSet.h:68
std::vector< TrackingParticle > TrackingParticleCollection
ProductID id() const
Definition: HandleBase.cc:15
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
edm::EDGetTokenT< edmNew::DetSetVector< Phase2TrackerCluster1D > > phase2OTClustersToken_
uint16_t firstStrip() const
data_type const * const_iterator
Definition: DetSetNew.h:30
uint16_t size_type
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > siphase2OTSimLinksToken_
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > pixelClustersToken_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > stripClustersToken_
int maxPixelRow() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
unsigned int firstRow() const
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
int minPixelRow() const
ClusterTPAssociationProducer(const edm::ParameterSet &)
std::vector< OmniClusterRef > OmniClusterCollection
unsigned int column() const
static PackedDigiType pixelToChannel(unsigned int row, unsigned int col)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
edm::EDGetTokenT< TrackingParticleCollection > trackingParticleToken_
Definition: DetId.h:18
T const * product() const
Definition: Handle.h:74
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > sipixelSimLinksToken_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
int maxPixelCol() const
collection_type data
Definition: DetSet.h:80
Pixel cluster – collection of neighboring pixels above threshold.
HLT enums.
iterator end()
Definition: DetSetNew.h:70
static int pixelToChannel(int row, int col)
std::vector< std::pair< uint32_t, EncodedEventId > > getSimTrackId(const edm::Handle< edm::DetSetVector< T > > &simLinks, const DetId &detId, uint32_t channel) const
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
edm::EDGetTokenT< edm::DetSetVector< StripDigiSimLink > > sistripSimLinksToken_
const std::vector< uint8_t > & amplitudes() const
def move(src, dest)
Definition: eostools.py:511
iterator begin()
Definition: DetSetNew.h:67