CMS 3D CMS Logo

SiPixelRecHitSoAFromLegacy.cc
Go to the documentation of this file.
1 #include <cuda_runtime.h>
2 
26 
27 #include "gpuPixelRecHits.h"
28 
30 public:
31  explicit SiPixelRecHitSoAFromLegacy(const edm::ParameterSet& iConfig);
32  ~SiPixelRecHitSoAFromLegacy() override = default;
33 
34  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
35 
36  using HitModuleStart = std::array<uint32_t, gpuClustering::maxNumModules + 1>;
38 
39 private:
40  void produce(edm::StreamID streamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
41 
48  const bool convert2Legacy_;
49 };
50 
52  : geomToken_(esConsumes()),
53  cpeToken_(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("CPE")))),
54  bsGetToken_{consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot"))},
55  clusterToken_{consumes<SiPixelClusterCollectionNew>(iConfig.getParameter<edm::InputTag>("src"))},
56  tokenHit_{produces<TrackingRecHit2DCPU>()},
57  tokenModuleStart_{produces<HMSstorage>()},
58  convert2Legacy_(iConfig.getParameter<bool>("convertToLegacy")) {
59  if (convert2Legacy_)
60  produces<SiPixelRecHitCollectionNew>();
61 }
62 
65 
66  desc.add<edm::InputTag>("beamSpot", edm::InputTag("offlineBeamSpot"));
67  desc.add<edm::InputTag>("src", edm::InputTag("siPixelClustersPreSplitting"));
68  desc.add<std::string>("CPE", "PixelCPEFast");
69  desc.add<bool>("convertToLegacy", false);
70  descriptions.addWithDefaultLabel(desc);
71 }
72 
74  const TrackerGeometry* geom_ = &es.getData(geomToken_);
75  PixelCPEFast const* fcpe = dynamic_cast<const PixelCPEFast*>(&es.getData(cpeToken_));
76  if (not fcpe) {
77  throw cms::Exception("Configuration") << "SiPixelRecHitSoAFromLegacy can only use a CPE of type PixelCPEFast";
78  }
79  auto const& cpeView = fcpe->getCPUProduct();
80 
81  const reco::BeamSpot& bs = iEvent.get(bsGetToken_);
82 
83  BeamSpotPOD bsHost;
84  bsHost.x = bs.x0();
85  bsHost.y = bs.y0();
86  bsHost.z = bs.z0();
87 
89  iEvent.getByToken(clusterToken_, hclusters);
90  auto const& input = *hclusters;
91 
92  // allocate a buffer for the indices of the clusters
93  auto hmsp = std::make_unique<uint32_t[]>(gpuClustering::maxNumModules + 1);
94  // hitsModuleStart is a non-owning pointer to the buffer
95  auto hitsModuleStart = hmsp.get();
96  // wrap the buffer in a HostProduct
97  auto hms = std::make_unique<HMSstorage>(std::move(hmsp));
98  // move the HostProduct to the Event, without reallocating the buffer or affecting hitsModuleStart
100 
101  // legacy output
102  auto legacyOutput = std::make_unique<SiPixelRecHitCollectionNew>();
103 
104  // storage
105  std::vector<uint16_t> xx;
106  std::vector<uint16_t> yy;
107  std::vector<uint16_t> adc;
108  std::vector<uint16_t> moduleInd;
109  std::vector<int32_t> clus;
110 
111  std::vector<edm::Ref<edmNew::DetSetVector<SiPixelCluster>, SiPixelCluster>> clusterRef;
112 
113  constexpr uint32_t maxHitsInModule = gpuClustering::maxHitsInModule();
114 
115  HitModuleStart moduleStart_; // index of the first pixel of each module
116  HitModuleStart clusInModule_;
117  memset(&clusInModule_, 0, sizeof(HitModuleStart)); // needed??
118  assert(gpuClustering::maxNumModules + 1 == clusInModule_.size());
119  assert(0 == clusInModule_[gpuClustering::maxNumModules]);
120  uint32_t moduleId_;
121  moduleStart_[1] = 0; // we run sequentially....
122 
124  moduleStart_.data(), clusInModule_.data(), &moduleId_, hitsModuleStart};
125 
126  // fill cluster arrays
127  int numberOfClusters = 0;
128  for (auto const& dsv : input) {
129  unsigned int detid = dsv.detId();
130  DetId detIdObject(detid);
131  const GeomDetUnit* genericDet = geom_->idToDetUnit(detIdObject);
132  auto gind = genericDet->index();
134  auto const nclus = dsv.size();
135  clusInModule_[gind] = nclus;
136  numberOfClusters += nclus;
137  }
138  hitsModuleStart[0] = 0;
139  for (int i = 1, n = clusInModule_.size(); i < n; ++i)
140  hitsModuleStart[i] = hitsModuleStart[i - 1] + clusInModule_[i - 1];
141  assert(numberOfClusters == int(hitsModuleStart[gpuClustering::maxNumModules]));
142 
143  // output SoA
144  auto output = std::make_unique<TrackingRecHit2DCPU>(numberOfClusters, &cpeView, hitsModuleStart, nullptr);
145 
146  if (0 == numberOfClusters) {
147  iEvent.put(std::move(output));
148  if (convert2Legacy_)
149  iEvent.put(std::move(legacyOutput));
150  return;
151  }
152 
153  if (convert2Legacy_)
154  legacyOutput->reserve(gpuClustering::maxNumModules, numberOfClusters);
155 
156  int numberOfDetUnits = 0;
157  int numberOfHits = 0;
158  for (auto const& dsv : input) {
159  numberOfDetUnits++;
160  unsigned int detid = dsv.detId();
161  DetId detIdObject(detid);
162  const GeomDetUnit* genericDet = geom_->idToDetUnit(detIdObject);
163  auto const gind = genericDet->index();
165  const PixelGeomDetUnit* pixDet = dynamic_cast<const PixelGeomDetUnit*>(genericDet);
166  assert(pixDet);
167  auto const nclus = dsv.size();
168  assert(clusInModule_[gind] == nclus);
169  if (0 == nclus)
170  continue; // is this really possible?
171 
172  auto const fc = hitsModuleStart[gind];
173  auto const lc = hitsModuleStart[gind + 1];
174  assert(lc > fc);
175  LogDebug("SiPixelRecHitSoAFromLegacy") << "in det " << gind << ": conv " << nclus << " hits from " << dsv.size()
176  << " legacy clusters" << ' ' << fc << ',' << lc;
177  assert((lc - fc) == nclus);
178  if (nclus > maxHitsInModule)
179  printf(
180  "WARNING: too many clusters %d in Module %d. Only first %d Hits converted\n", nclus, gind, maxHitsInModule);
181 
182  // fill digis
183  xx.clear();
184  yy.clear();
185  adc.clear();
186  moduleInd.clear();
187  clus.clear();
188  clusterRef.clear();
189  moduleId_ = gind;
190  uint32_t ic = 0;
191  uint32_t ndigi = 0;
192  for (auto const& clust : dsv) {
193  assert(clust.size() > 0);
194  for (int i = 0, nd = clust.size(); i < nd; ++i) {
195  auto px = clust.pixel(i);
196  xx.push_back(px.x);
197  yy.push_back(px.y);
198  adc.push_back(px.adc);
199  moduleInd.push_back(gind);
200  clus.push_back(ic);
201  ++ndigi;
202  }
203  assert(clust.originalId() == ic); // make sure hits and clus are in sync
204  if (convert2Legacy_)
205  clusterRef.emplace_back(edmNew::makeRefTo(hclusters, &clust));
206  ic++;
207  }
208  assert(nclus == ic);
209  assert(clus.size() == ndigi);
210  numberOfHits += nclus;
211  // filled creates view
212  SiPixelDigisCUDA::DeviceConstView digiView{xx.data(), yy.data(), adc.data(), moduleInd.data(), clus.data()};
213  assert(digiView.adc(0) != 0);
214  // we run on blockId.x==0
215  gpuPixelRecHits::getHits(&cpeView, &bsHost, &digiView, ndigi, &clusterView, output->view());
216  for (auto h = fc; h < lc; ++h)
217  if (h - fc < maxHitsInModule)
218  assert(gind == output->view()->detectorIndex(h));
219  else
220  assert(gpuClustering::invalidModuleId == output->view()->detectorIndex(h));
221  if (convert2Legacy_) {
222  SiPixelRecHitCollectionNew::FastFiller recHitsOnDetUnit(*legacyOutput, detid);
223  for (auto h = fc; h < lc; ++h) {
224  auto ih = h - fc;
225  if (ih >= maxHitsInModule)
226  break;
227  assert(ih < clusterRef.size());
228  LocalPoint lp(output->view()->xLocal(h), output->view()->yLocal(h));
229  LocalError le(output->view()->xerrLocal(h), 0, output->view()->yerrLocal(h));
231  SiPixelRecHit hit(lp, le, rqw, *genericDet, clusterRef[ih]);
232  recHitsOnDetUnit.push_back(hit);
233  }
234  }
235  }
236  assert(numberOfHits == numberOfClusters);
237 
238  // fill data structure to support CA
239  for (auto i = 0U; i < phase1PixelTopology::numberOfLayers + 1; ++i) {
240  output->hitsLayerStart()[i] = hitsModuleStart[cpeView.layerGeometry().layerStart[i]];
241  }
242  cms::cuda::fillManyFromVector(output->phiBinner(),
244  output->iphi(),
245  output->hitsLayerStart(),
246  numberOfHits,
247  256,
248  nullptr);
249 
250  LogDebug("SiPixelRecHitSoAFromLegacy") << "created HitSoa for " << numberOfClusters << " clusters in "
251  << numberOfDetUnits << " Dets";
252  iEvent.put(std::move(output));
253  if (convert2Legacy_)
254  iEvent.put(std::move(legacyOutput));
255 }
256 
ConfigurationDescriptions.h
edm::StreamID
Definition: StreamID.h:30
Handle.h
mps_fire.i
i
Definition: mps_fire.py:428
gpuClustering::maxHitsInModule
constexpr uint32_t maxHitsInModule()
Definition: gpuClusteringConstants.h:27
input
static const std::string input
Definition: EdmProvDump.cc:48
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
SiPixelRecHitSoAFromLegacy::~SiPixelRecHitSoAFromLegacy
~SiPixelRecHitSoAFromLegacy() override=default
TrackerGeometry.h
GeomDet
Definition: GeomDet.h:27
ESInputTag
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
phase1PixelTopology::numberOfLayers
constexpr uint32_t numberOfLayers
Definition: phase1PixelTopology.h:25
edm::EDGetTokenT< reco::BeamSpot >
edm
HLT enums.
Definition: AlignableModifier.h:19
gpuClustering::adc
uint16_t *__restrict__ uint16_t const *__restrict__ adc
Definition: gpuClusterChargeCut.h:20
edm::EDPutTokenT
Definition: EDPutToken.h:33
h
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: L1TUtmAlgorithmRcd.h:4
TrackingRecHit2DHeterogeneous.h
SiPixelDigisCUDA::DeviceConstView
Definition: SiPixelDigisCUDA.h:50
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
SiPixelRecHitSoAFromLegacy::clusterToken_
const edm::EDGetTokenT< SiPixelClusterCollectionNew > clusterToken_
Definition: SiPixelRecHitSoAFromLegacy.cc:45
cms::cuda::assert
assert(be >=bs)
PixelCPEBase.h
HostProduct.h
BeamSpotPOD::z
float z
Definition: BeamSpotPOD.h:12
GeomDet::index
int index() const
Definition: GeomDet.h:83
SiPixelCluster
Pixel cluster – collection of neighboring pixels above threshold.
Definition: SiPixelCluster.h:28
PixelCPEFast.h
edmNew::DetSetVector::FastFiller::push_back
void push_back(data_type const &d)
Definition: DetSetVectorNew.h:274
SiPixelClustersCUDA.h
edm::Handle
Definition: AssociativeIterator.h:50
SiPixelRecHitSoAFromLegacy::cpeToken_
const edm::ESGetToken< PixelClusterParameterEstimator, TkPixelCPERecord > cpeToken_
Definition: SiPixelRecHitSoAFromLegacy.cc:43
SiPixelRecHitSoAFromLegacy::SiPixelRecHitSoAFromLegacy
SiPixelRecHitSoAFromLegacy(const edm::ParameterSet &iConfig)
Definition: SiPixelRecHitSoAFromLegacy.cc:51
SiPixelRecHit
Our base class.
Definition: SiPixelRecHit.h:23
SiPixelRecHitSoAFromLegacy::HitModuleStart
std::array< uint32_t, gpuClustering::maxNumModules+1 > HitModuleStart
Definition: SiPixelRecHitSoAFromLegacy.cc:36
TrackerGeometry::idToDetUnit
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: TrackerGeometry.cc:183
BeamSpotPOD::y
float y
Definition: BeamSpotPOD.h:12
DetId
Definition: DetId.h:17
MakerMacros.h
cms::cuda::bs
bs
Definition: HistoContainer.h:127
h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BeamSpot.h
SiPixelRecHitSoAFromLegacy::convert2Legacy_
const bool convert2Legacy_
Definition: SiPixelRecHitSoAFromLegacy.cc:48
SiPixelRecHitQuality::QualWordType
unsigned int QualWordType
Definition: SiPixelRecHitQuality.h:9
PixelGeomDetUnit
Definition: PixelGeomDetUnit.h:15
PixelCPEFast
Definition: PixelCPEFast.h:15
reco::BeamSpot
Definition: BeamSpot.h:21
benchmark_cfg.fc
fc
Definition: benchmark_cfg.py:15
SiPixelRecHitSoAFromLegacy
Definition: SiPixelRecHitSoAFromLegacy.cc:29
gpuPixelRecHits.h
Point3DBase< float, LocalTag >
ParameterSetDescription.h
gpuClustering::maxNumModules
constexpr uint16_t maxNumModules
Definition: gpuClusteringConstants.h:29
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiPixelClustersCUDA::DeviceConstView
Definition: SiPixelClustersCUDA.h:35
TrackerDigiGeometryRecord.h
SiPixelRecHitCollection.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
HostProduct
Definition: HostProduct.h:8
Event.h
geometryCSVtoXML.yy
yy
Definition: geometryCSVtoXML.py:19
SiPixelRecHitSoAFromLegacy::tokenHit_
const edm::EDPutTokenT< TrackingRecHit2DCPU > tokenHit_
Definition: SiPixelRecHitSoAFromLegacy.cc:46
gpuClustering::invalidModuleId
constexpr uint16_t invalidModuleId
Definition: gpuClusteringConstants.h:32
LocalError
Definition: LocalError.h:12
BeamSpotCUDA.h
iEvent
int iEvent
Definition: GenABIO.cc:224
BeamSpotPOD::x
float x
Definition: BeamSpotPOD.h:12
edm::EventSetup
Definition: EventSetup.h:58
SiPixelDigisCUDA.h
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord >
InputTag.h
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
multPhiCorr_741_25nsDY_cfi.px
px
Definition: multPhiCorr_741_25nsDY_cfi.py:10
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
BeamSpotPOD
Definition: BeamSpotPOD.h:11
SiPixelRecHitSoAFromLegacy::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: SiPixelRecHitSoAFromLegacy.cc:63
Exception
Definition: hltDiff.cc:245
SiPixelRecHitSoAFromLegacy::bsGetToken_
const edm::EDGetTokenT< reco::BeamSpot > bsGetToken_
Definition: SiPixelRecHitSoAFromLegacy.cc:44
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
SiPixelRecHitSoAFromLegacy::produce
void produce(edm::StreamID streamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
Definition: SiPixelRecHitSoAFromLegacy.cc:73
TkPixelCPERecord.h
edmNew::DetSetVector::FastFiller
Definition: DetSetVectorNew.h:202
ParameterSet.h
EDProducer.h
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
DetSetVectorNew.h
edm::InputTag
Definition: InputTag.h:15
geometryCSVtoXML.xx
xx
Definition: geometryCSVtoXML.py:19
hit
Definition: SiStripHitEffFromCalibTree.cc:88
SiPixelRecHitSoAFromLegacy::tokenModuleStart_
const edm::EDPutTokenT< HMSstorage > tokenModuleStart_
Definition: SiPixelRecHitSoAFromLegacy.cc:47
edm::ConfigurationDescriptions::addWithDefaultLabel
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:87
SiPixelRecHitSoAFromLegacy::geomToken_
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
Definition: SiPixelRecHitSoAFromLegacy.cc:42
TrackerGeometry
Definition: TrackerGeometry.h:14