CMS 3D CMS Logo

SiPixelRecHitFromSoAAlpaka.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <vector>
3 
23 
24 template <typename TrackerTraits>
27  using hindex_type = typename TrackerTraits::hindex_type;
28  using HMSstorage = typename std::vector<hindex_type>;
29 
30 public:
31  explicit SiPixelRecHitFromSoAAlpaka(const edm::ParameterSet& iConfig);
32  ~SiPixelRecHitFromSoAAlpaka() override = default;
33 
34  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
35 
36  // Data has been implicitly copied from Device to Host by the framework
38 
39 private:
40  void produce(edm::StreamID streamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
41 
47 };
48 
49 template <typename TrackerTraits>
51  : geomToken_(esConsumes()),
52  hitsToken_(consumes(iConfig.getParameter<edm::InputTag>("pixelRecHitSrc"))),
53  clusterToken_(consumes(iConfig.getParameter<edm::InputTag>("src"))),
54  rechitsPutToken_(produces()),
55  hostPutToken_(produces()) {}
56 
57 template <typename TrackerTraits>
60  desc.add<edm::InputTag>("pixelRecHitSrc", edm::InputTag("siPixelRecHitsPreSplittingAlpaka"));
61  desc.add<edm::InputTag>("src", edm::InputTag("siPixelClustersPreSplitting"));
62  descriptions.addWithDefaultLabel(desc);
63 }
64 
65 template <typename TrackerTraits>
68  const edm::EventSetup& iSetup) const {
69  auto const& hits = iEvent.get(hitsToken_);
70  auto nHits = hits.view().metadata().size();
71  LogDebug("SiPixelRecHitFromSoAAlpaka") << "converting " << nHits << " Hits";
72 
73  // allocate a buffer for the indices of the clusters
75 
77  output.reserve(nMaxModules, nHits);
78 
79  HMSstorage hmsp(nMaxModules + 1);
80 
81  if (0 == nHits) {
82  hmsp.clear();
83  iEvent.emplace(rechitsPutToken_, std::move(output));
84  iEvent.emplace(hostPutToken_, std::move(hmsp));
85  return;
86  }
87 
88  // fill content of HMSstorage product, and put it into the Event
89  for (unsigned int idx = 0; idx < hmsp.size(); ++idx) {
90  hmsp[idx] = hits.view().hitsModuleStart()[idx];
91  }
92  iEvent.emplace(hostPutToken_, std::move(hmsp));
93 
94  auto xl = hits.view().xLocal();
95  auto yl = hits.view().yLocal();
96  auto xe = hits.view().xerrLocal();
97  auto ye = hits.view().yerrLocal();
98 
99  TrackerGeometry const& geom = iSetup.getData(geomToken_);
100 
101  auto const hclusters = iEvent.getHandle(clusterToken_);
102 
104 
105  int numberOfDetUnits = 0;
106  int numberOfClusters = 0;
107  for (auto const& dsv : *hclusters) {
108  numberOfDetUnits++;
109  unsigned int detid = dsv.detId();
110  DetId detIdObject(detid);
111  const GeomDetUnit* genericDet = geom.idToDetUnit(detIdObject);
112  auto gind = genericDet->index();
113  const PixelGeomDetUnit* pixDet = dynamic_cast<const PixelGeomDetUnit*>(genericDet);
114  assert(pixDet);
115  SiPixelRecHitCollection::FastFiller recHitsOnDetUnit(output, detid);
116  auto fc = hits.view().hitsModuleStart()[gind];
117  auto lc = hits.view().hitsModuleStart()[gind + 1];
118  auto nhits = lc - fc;
119 
120  assert(lc > fc);
121  LogDebug("SiPixelRecHitFromSoAAlpaka") << "in det " << gind << ": conv " << nhits << " hits from " << dsv.size()
122  << " legacy clusters" << ' ' << fc << ',' << lc << "\n";
123  if (nhits > maxHitsInModule)
124  edm::LogWarning("SiPixelRecHitFromSoAAlpaka")
125  .format("Too many clusters {} in module {}. Only the first {} hits will be converted",
126  nhits,
127  gind,
129 
131 
132  LogDebug("SiPixelRecHitFromSoAAlpaka") << "in det " << gind << "conv " << nhits << " hits from " << dsv.size()
133  << " legacy clusters" << ' ' << lc << ',' << fc;
134 
135  if (0 == nhits)
136  continue;
137  auto jnd = [&](int k) { return fc + k; };
138  assert(nhits <= dsv.size());
139  if (nhits != dsv.size()) {
140  edm::LogWarning("GPUHits2CPU") << "nhits!= nclus " << nhits << ' ' << dsv.size();
141  }
142  for (auto const& clust : dsv) {
143  assert(clust.originalId() >= 0);
144  assert(clust.originalId() < dsv.size());
145  if (clust.originalId() >= nhits)
146  continue;
147  auto ij = jnd(clust.originalId());
148  LocalPoint lp(xl[ij], yl[ij]);
149  LocalError le(xe[ij], 0, ye[ij]);
151 
152  numberOfClusters++;
153 
154  /* cpu version.... (for reference)
155  std::tuple<LocalPoint, LocalError, SiPixelRecHitQuality::QualWordType> tuple = cpe_->getParameters( clust, *genericDet );
156  LocalPoint lp( std::get<0>(tuple) );
157  LocalError le( std::get<1>(tuple) );
158  SiPixelRecHitQuality::QualWordType rqw( std::get<2>(tuple) );
159  */
160 
161  // Create a persistent edm::Ref to the cluster
163  // Make a RecHit and add it to the DetSet
164  recHitsOnDetUnit.emplace_back(lp, le, rqw, *genericDet, cluster);
165  // =============================
166 
167  LogDebug("SiPixelRecHitFromSoAAlpaka") << "cluster " << numberOfClusters << " at " << lp << ' ' << le;
168 
169  } // <-- End loop on Clusters
170 
171  // LogDebug("SiPixelRecHitGPU")
172  LogDebug("SiPixelRecHitFromSoAAlpaka") << "found " << recHitsOnDetUnit.size() << " RecHits on " << detid;
173 
174  } // <-- End loop on DetUnits
175 
176  LogDebug("SiPixelRecHitFromSoAAlpaka") << "found " << numberOfDetUnits << " dets, " << numberOfClusters
177  << " clusters";
178 
179  iEvent.emplace(rechitsPutToken_, std::move(output));
180 }
181 
185 
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)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
constexpr int nMaxModules
void produce(edm::StreamID streamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
std::array< hindex_type, TrackerTraits::numberOfModules+1 > HitModuleStartArray
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const edm::EDGetTokenT< SiPixelClusterCollectionNew > clusterToken_
int index() const
Definition: GeomDet.h:83
typename std::vector< hindex_type > HMSstorage
const edm::EDPutTokenT< HMSstorage > hostPutToken_
assert(be >=bs)
constexpr uint16_t numberOfModules
~SiPixelRecHitFromSoAAlpaka() override=default
int iEvent
Definition: GenABIO.cc:224
const edm::EDPutTokenT< SiPixelRecHitCollection > rechitsPutToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
Definition: DetId.h:17
SiPixelRecHitFromSoAAlpaka(const edm::ParameterSet &iConfig)
typename TrackingRecHitSoA< TrackerTraits >::HitModuleStartArray HitModuleStartArray
typename TrackerTraits::hindex_type hindex_type
Pixel cluster – collection of neighboring pixels above threshold.
HLT enums.
void emplace_back(Args &&... args)
Definition: output.py:1
Log< level::Warning, false > LogWarning
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
const edm::EDGetTokenT< HitsOnHost > hitsToken_
def move(src, dest)
Definition: eostools.py:511
constexpr uint32_t maxHitsInModule()
#define LogDebug(id)