test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ClusterTPAssociationProducer.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <vector>
3 #include <utility>
4 
13 
22 
29 
31 {
32 public:
33  typedef std::vector<OmniClusterRef> OmniClusterCollection;
34 
37 
38  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
39 
40 private:
41  virtual void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
42 
43  template <typename T>
44  std::vector<std::pair<uint32_t, EncodedEventId> >
45  getSimTrackId(const edm::Handle<edm::DetSetVector<T> >& simLinks, const DetId& detId, uint32_t channel) const;
46 
52 };
53 
55  : sipixelSimLinksToken_(consumes<edm::DetSetVector<PixelDigiSimLink> >(cfg.getParameter<edm::InputTag>("pixelSimLinkSrc"))),
56  sistripSimLinksToken_(consumes<edm::DetSetVector<StripDigiSimLink> >(cfg.getParameter<edm::InputTag>("stripSimLinkSrc"))),
57  pixelClustersToken_(consumes<edmNew::DetSetVector<SiPixelCluster> >(cfg.getParameter<edm::InputTag>("pixelClusterSrc"))),
58  stripClustersToken_(consumes<edmNew::DetSetVector<SiStripCluster> >(cfg.getParameter<edm::InputTag>("stripClusterSrc"))),
59  trackingParticleToken_(consumes<TrackingParticleCollection>(cfg.getParameter<edm::InputTag>("trackingParticleSrc")))
60 {
61  produces<ClusterTPAssociation>();
62 }
63 
65 }
66 
69  desc.add<edm::InputTag>("simTrackSrc", edm::InputTag("g4SimHits"));
70  desc.add<edm::InputTag>("pixelSimLinkSrc", edm::InputTag("simSiPixelDigis"));
71  desc.add<edm::InputTag>("stripSimLinkSrc", edm::InputTag("simSiStripDigis"));
72  desc.add<edm::InputTag>("pixelClusterSrc", edm::InputTag("siPixelClusters"));
73  desc.add<edm::InputTag>("stripClusterSrc", edm::InputTag("siStripClusters"));
74  desc.add<edm::InputTag>("trackingParticleSrc", edm::InputTag("mix", "MergedTrackTruth"));
75  descriptions.add("tpClusterProducer", desc);
76 }
77 
79  // Pixel DigiSimLink
81  // iEvent.getByLabel(_pixelSimLinkSrc, sipixelSimLinks);
82  iEvent.getByToken(sipixelSimLinksToken_,sipixelSimLinks);
83 
84  // SiStrip DigiSimLink
86  iEvent.getByToken(sistripSimLinksToken_,sistripSimLinks);
87 
88  // Pixel Cluster
90  bool foundPixelClusters = iEvent.getByToken(pixelClustersToken_,pixelClusters);
91 
92  // Strip Cluster
94  bool foundStripClusters = iEvent.getByToken(stripClustersToken_,stripClusters);
95 
96 
97  // TrackingParticle
99  iEvent.getByToken(trackingParticleToken_,TPCollectionH);
100 
101  auto clusterTPList = std::make_unique<ClusterTPAssociation>(TPCollectionH);
102 
103  // prepare temporary map between SimTrackId and TrackingParticle index
104  std::map<std::pair<size_t, EncodedEventId>, TrackingParticleRef> mapping;
106  itp < TPCollectionH.product()->size(); ++itp) {
107  TrackingParticleRef trackingParticle(TPCollectionH, itp);
108 
109  // SimTracks inside TrackingParticle
110  EncodedEventId eid(trackingParticle->eventId());
111  //size_t index = 0;
112  for (std::vector<SimTrack>::const_iterator itrk = trackingParticle->g4Track_begin();
113  itrk != trackingParticle->g4Track_end(); ++itrk) {
114  std::pair<uint32_t, EncodedEventId> trkid(itrk->trackId(), eid);
115  //std::cout << "creating map for id: " << trkid.first << " with tp: " << trackingParticle.key() << std::endl;
116  mapping.insert(std::make_pair(trkid, trackingParticle));
117  }
118  }
119 
120  if ( foundPixelClusters ) {
121  // Pixel Clusters
122  for (edmNew::DetSetVector<SiPixelCluster>::const_iterator iter = pixelClusters->begin();
123  iter != pixelClusters->end(); ++iter) {
124  uint32_t detid = iter->id();
125  DetId detId(detid);
126  edmNew::DetSet<SiPixelCluster> link_pixel = (*iter);
128  di != link_pixel.end(); ++di) {
129  const SiPixelCluster& cluster = (*di);
131  edmNew::makeRefTo(pixelClusters, di);
132 
133  std::set<std::pair<uint32_t, EncodedEventId> > simTkIds;
134  for (int irow = cluster.minPixelRow(); irow <= cluster.maxPixelRow(); ++irow) {
135  for (int icol = cluster.minPixelCol(); icol <= cluster.maxPixelCol(); ++icol) {
136  uint32_t channel = PixelChannelIdentifier::pixelToChannel(irow, icol);
137  std::vector<std::pair<uint32_t, EncodedEventId> > trkid(getSimTrackId<PixelDigiSimLink>(sipixelSimLinks, detId, channel));
138  if (trkid.size()==0) continue;
139  simTkIds.insert(trkid.begin(),trkid.end());
140  }
141  }
142  for (std::set<std::pair<uint32_t, EncodedEventId> >::const_iterator iset = simTkIds.begin();
143  iset != simTkIds.end(); iset++) {
144  auto ipos = mapping.find(*iset);
145  if (ipos != mapping.end()) {
146  //std::cout << "cluster in detid: " << detid << " from tp: " << ipos->second.key() << " " << iset->first << std::endl;
147  clusterTPList->emplace_back(OmniClusterRef(c_ref), ipos->second);
148  }
149  }
150  }
151  }
152  }
153 
154  if ( foundStripClusters ) {
155  // Strip Clusters
156  for (edmNew::DetSetVector<SiStripCluster>::const_iterator iter = stripClusters->begin(false), eter = stripClusters->end(false);
157  iter != eter; ++iter) {
158  if (!(*iter).isValid()) continue;
159  uint32_t detid = iter->id();
160  DetId detId(detid);
161  edmNew::DetSet<SiStripCluster> link_strip = (*iter);
163  di != link_strip.end(); di++) {
164  const SiStripCluster& cluster = (*di);
166  edmNew::makeRefTo(stripClusters, di);
167 
168  std::set<std::pair<uint32_t, EncodedEventId> > simTkIds;
169  int first = cluster.firstStrip();
170  int last = first + cluster.amplitudes().size();
171 
172  for (int istr = first; istr < last; ++istr) {
173  std::vector<std::pair<uint32_t, EncodedEventId> > trkid(getSimTrackId<StripDigiSimLink>(sistripSimLinks, detId, istr));
174  if (trkid.size()==0) continue;
175  simTkIds.insert(trkid.begin(),trkid.end());
176  }
177  for (std::set<std::pair<uint32_t, EncodedEventId> >::const_iterator iset = simTkIds.begin();
178  iset != simTkIds.end(); iset++) {
179  auto ipos = mapping.find(*iset);
180  if (ipos != mapping.end()) {
181  //std::cout << "cluster in detid: " << detid << " from tp: " << ipos->second.key() << " " << iset->first << std::endl;
182  clusterTPList->emplace_back(OmniClusterRef(c_ref), ipos->second);
183  }
184  }
185  }
186  }
187  }
188 
189  clusterTPList->sort();
190  iEvent.put(std::move(clusterTPList));
191 }
192 
193 template <typename T>
194 std::vector<std::pair<uint32_t, EncodedEventId> >
195 //std::pair<uint32_t, EncodedEventId>
197  const DetId& detId, uint32_t channel) const
198 {
199  //std::pair<uint32_t, EncodedEventId> simTrkId;
200  std::vector<std::pair<uint32_t, EncodedEventId> > simTrkId;
201  auto isearch = simLinks->find(detId);
202  if (isearch != simLinks->end()) {
203  // Loop over DigiSimLink in this det unit
204  edm::DetSet<T> link_detset = (*isearch);
205  for (typename edm::DetSet<T>::const_iterator it = link_detset.data.begin();
206  it != link_detset.data.end(); ++it) {
207  if (channel == it->channel()) {
208  simTrkId.push_back(std::make_pair(it->SimTrackId(), it->eventId()));
209  }
210  }
211  }
212  return simTrkId;
213 }
216 
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
void push_back(const T &t)
Definition: DetSet.h:68
tuple cfg
Definition: looper.py:293
std::vector< TrackingParticle > TrackingParticleCollection
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
uint16_t firstStrip() const
data_type const * const_iterator
Definition: DetSetNew.h:30
uint16_t size_type
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > pixelClustersToken_
edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > stripClustersToken_
int maxPixelRow() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:230
int minPixelRow() const
virtual void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
ClusterTPAssociationProducer(const edm::ParameterSet &)
std::vector< OmniClusterRef > OmniClusterCollection
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
def move
Definition: eostools.py:510
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::EDGetTokenT< TrackingParticleCollection > trackingParticleToken_
Definition: DetId.h:18
T const * product() const
Definition: Handle.h:81
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > sipixelSimLinksToken_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
int maxPixelCol() const
collection_type data
Definition: DetSet.h:78
Pixel cluster – collection of neighboring pixels above threshold.
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
iterator begin()
Definition: DetSetNew.h:67