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 <iostream>
4 #include <fstream>
5 #include <utility>
6 
8 
13 
19 
23 
25  : _verbose(cfg.getParameter<bool>("verbose")),
26  _pixelSimLinkSrc(cfg.getParameter<edm::InputTag>("pixelSimLinkSrc")),
27  _stripSimLinkSrc(cfg.getParameter<edm::InputTag>("stripSimLinkSrc")),
28  _pixelClusterSrc(cfg.getParameter<edm::InputTag>("pixelClusterSrc")),
29  _stripClusterSrc(cfg.getParameter<edm::InputTag>("stripClusterSrc")),
30  _trackingParticleSrc(cfg.getParameter<edm::InputTag>("trackingParticleSrc"))
31 {
32 
33  sipixelSimLinksToken_ = consumes<edm::DetSetVector<PixelDigiSimLink> >(cfg.getParameter<edm::InputTag>("pixelSimLinkSrc"));
34  sistripSimLinksToken_ = consumes<edm::DetSetVector<StripDigiSimLink> >(cfg.getParameter<edm::InputTag>("stripSimLinkSrc"));
35  pixelClustersToken_ = consumes<edmNew::DetSetVector<SiPixelCluster> >(cfg.getParameter<edm::InputTag>("pixelClusterSrc"));
36  stripClustersToken_ = consumes<edmNew::DetSetVector<SiStripCluster> >(cfg.getParameter<edm::InputTag>("stripClusterSrc"));
37  trackingParticleToken_ = consumes<TrackingParticleCollection>(cfg.getParameter<edm::InputTag>("trackingParticleSrc"));
38 
39  produces<ClusterTPAssociationList>();
40 }
41 
43 }
44 
46  auto clusterTPList = std::make_unique<ClusterTPAssociationList>();
47 
48  // Pixel DigiSimLink
50  // iEvent.getByLabel(_pixelSimLinkSrc, sipixelSimLinks);
51  iEvent.getByToken(sipixelSimLinksToken_,sipixelSimLinks);
52 
53  // SiStrip DigiSimLink
55  iEvent.getByToken(sistripSimLinksToken_,sistripSimLinks);
56 
57  // Pixel Cluster
59  bool foundPixelClusters = iEvent.getByToken(pixelClustersToken_,pixelClusters);
60 
61  // Strip Cluster
63  bool foundStripClusters = iEvent.getByToken(stripClustersToken_,stripClusters);
64 
65 
66  // TrackingParticle
68  iEvent.getByToken(trackingParticleToken_,TPCollectionH);
69 
70  // prepare temporary map between SimTrackId and TrackingParticle index
71  std::map<std::pair<size_t, EncodedEventId>, TrackingParticleRef> mapping;
73  itp < TPCollectionH.product()->size(); ++itp) {
74  TrackingParticleRef trackingParticle(TPCollectionH, itp);
75 
76  // SimTracks inside TrackingParticle
77  EncodedEventId eid(trackingParticle->eventId());
78  //size_t index = 0;
79  for (std::vector<SimTrack>::const_iterator itrk = trackingParticle->g4Track_begin();
80  itrk != trackingParticle->g4Track_end(); ++itrk) {
81  std::pair<uint32_t, EncodedEventId> trkid(itrk->trackId(), eid);
82  //std::cout << "creating map for id: " << trkid.first << " with tp: " << trackingParticle.key() << std::endl;
83  mapping.insert(std::make_pair(trkid, trackingParticle));
84  }
85  }
86 
87  if ( foundPixelClusters ) {
88  // Pixel Clusters
89  for (edmNew::DetSetVector<SiPixelCluster>::const_iterator iter = pixelClusters->begin();
90  iter != pixelClusters->end(); ++iter) {
91  uint32_t detid = iter->id();
92  DetId detId(detid);
93  edmNew::DetSet<SiPixelCluster> link_pixel = (*iter);
95  di != link_pixel.end(); ++di) {
96  const SiPixelCluster& cluster = (*di);
98  edmNew::makeRefTo(pixelClusters, di);
99 
100  std::set<std::pair<uint32_t, EncodedEventId> > simTkIds;
101  for (int irow = cluster.minPixelRow(); irow <= cluster.maxPixelRow(); ++irow) {
102  for (int icol = cluster.minPixelCol(); icol <= cluster.maxPixelCol(); ++icol) {
103  uint32_t channel = PixelChannelIdentifier::pixelToChannel(irow, icol);
104  std::vector<std::pair<uint32_t, EncodedEventId> > trkid(getSimTrackId<PixelDigiSimLink>(sipixelSimLinks, detId, channel));
105  if (trkid.size()==0) continue;
106  simTkIds.insert(trkid.begin(),trkid.end());
107  }
108  }
109  for (std::set<std::pair<uint32_t, EncodedEventId> >::const_iterator iset = simTkIds.begin();
110  iset != simTkIds.end(); iset++) {
111  auto ipos = mapping.find(*iset);
112  if (ipos != mapping.end()) {
113  //std::cout << "cluster in detid: " << detid << " from tp: " << ipos->second.key() << " " << iset->first << std::endl;
114  clusterTPList->push_back(std::make_pair(OmniClusterRef(c_ref), ipos->second));
115  }
116  }
117  }
118  }
119  }
120 
121  if ( foundStripClusters ) {
122  // Strip Clusters
123  for (edmNew::DetSetVector<SiStripCluster>::const_iterator iter = stripClusters->begin(false), eter = stripClusters->end(false);
124  iter != eter; ++iter) {
125  if (!(*iter).isValid()) continue;
126  uint32_t detid = iter->id();
127  DetId detId(detid);
128  edmNew::DetSet<SiStripCluster> link_strip = (*iter);
130  di != link_strip.end(); di++) {
131  const SiStripCluster& cluster = (*di);
133  edmNew::makeRefTo(stripClusters, di);
134 
135  std::set<std::pair<uint32_t, EncodedEventId> > simTkIds;
136  int first = cluster.firstStrip();
137  int last = first + cluster.amplitudes().size();
138 
139  for (int istr = first; istr < last; ++istr) {
140  std::vector<std::pair<uint32_t, EncodedEventId> > trkid(getSimTrackId<StripDigiSimLink>(sistripSimLinks, detId, istr));
141  if (trkid.size()==0) continue;
142  simTkIds.insert(trkid.begin(),trkid.end());
143  }
144  for (std::set<std::pair<uint32_t, EncodedEventId> >::const_iterator iset = simTkIds.begin();
145  iset != simTkIds.end(); iset++) {
146  auto ipos = mapping.find(*iset);
147  if (ipos != mapping.end()) {
148  //std::cout << "cluster in detid: " << detid << " from tp: " << ipos->second.key() << " " << iset->first << std::endl;
149  clusterTPList->push_back(std::make_pair(OmniClusterRef(c_ref), ipos->second));
150  }
151  }
152  }
153  }
154  }
155 
156  std::sort(clusterTPList->begin(), clusterTPList->end(), clusterTPAssociationListGreater);
157  iEvent.put(std::move(clusterTPList));
158 }
159 
160 template <typename T>
161 std::vector<std::pair<uint32_t, EncodedEventId> >
162 //std::pair<uint32_t, EncodedEventId>
164  const DetId& detId, uint32_t channel) const
165 {
166  //std::pair<uint32_t, EncodedEventId> simTrkId;
167  std::vector<std::pair<uint32_t, EncodedEventId> > simTrkId;
168  auto isearch = simLinks->find(detId);
169  if (isearch != simLinks->end()) {
170  // Loop over DigiSimLink in this det unit
171  edm::DetSet<T> link_detset = (*isearch);
172  for (typename edm::DetSet<T>::const_iterator it = link_detset.data.begin();
173  it != link_detset.data.end(); ++it) {
174  if (channel == it->channel()) {
175  simTrkId.push_back(std::make_pair(it->SimTrackId(), it->eventId()));
176  }
177  }
178  }
179  return simTrkId;
180 }
183 
T getParameter(std::string const &) const
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
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
bool clusterTPAssociationListGreater(std::pair< OmniClusterRef, TrackingParticleRef > i, std::pair< OmniClusterRef, TrackingParticleRef > j)
#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
int iEvent
Definition: GenABIO.cc:230
int minPixelRow() const
ClusterTPAssociationProducer(const edm::ParameterSet &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
def move
Definition: eostools.py:510
edm::EDGetTokenT< TrackingParticleCollection > trackingParticleToken_
Definition: DetId.h:18
T const * product() const
Definition: Handle.h:81
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > sipixelSimLinksToken_
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
virtual void produce(edm::Event &, const edm::EventSetup &)
iterator begin()
Definition: DetSetNew.h:67