CMS 3D CMS Logo

SiPixelRecHitConverter.cc
Go to the documentation of this file.
1 
12 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 
42 //--- Base class for CPEs:
43 
45 
46 //--- Geometry + DataFormats
51 
52 //--- Framework
57 
64 
65 // Geometry
68 
69 // Data Formats
73 
74 // STL
75 #include <vector>
76 #include <memory>
77 #include <string>
78 #include <iostream>
79 
80 // MessageLogger
82 
84 
85 // Make heterogeneous framework happy
88 
89 using namespace std;
90 
91 namespace cms {
92 
94  public:
95  //--- Constructor, virtual destructor (just in case)
96  explicit SiPixelRecHitConverter(const edm::ParameterSet& conf);
97  ~SiPixelRecHitConverter() override;
98 
99  //--- Factory method to make CPE's depending on the ParameterSet
100  //--- Not sure if we need to make more than one CPE to run concurrently
101  //--- on different parts of the detector (e.g., one for the barrel and the
102  //--- one for the forward). The way the CPE's are written now, it's
103  //--- likely we can use one (and they will switch internally), or
104  //--- make two of the same but configure them differently. We need a more
105  //--- realistic use case...
106 
107  //--- The top-level event method.
108  void produce(edm::Event& e, const edm::EventSetup& c) override;
109 
110  //--- Execute the position estimator algorithm(s).
111  void run(edm::Event& e,
114  TrackerGeometry const& geom);
115 
116  private:
118 
119  // TO DO: maybe allow a map of pointers?
121  PixelCPEBase const* cpe_ = nullptr; // What we got (for now, one ptr to base class)
128  bool m_newCont; // save also in emdNew::DetSetVector
129  };
130 
131  //---------------------------------------------------------------------------
133  //---------------------------------------------------------------------------
134  SiPixelRecHitConverter::SiPixelRecHitConverter(edm::ParameterSet const& conf)
135  : src_(conf.getParameter<edm::InputTag>("src")),
136  tPixelCluster_(consumes<edmNew::DetSetVector<SiPixelCluster>>(src_)),
137  tPut_(produces<SiPixelRecHitCollection>()),
138  tHost_(produces<HMSstorage>()),
141  edm::ESInputTag("", conf.getParameter<std::string>("CPE")))) {}
142 
143  // Destructor
145 
146  //---------------------------------------------------------------------------
148  //---------------------------------------------------------------------------
150  // Step A.1: get input data
152  e.getByToken(tPixelCluster_, input);
153 
154  // Step A.2: get event setup
155  auto const& geom = es.getData(tTrackerGeom_);
156 
157  // Step B: create empty output collection
159 
160  // Step B*: create CPE
161  cpe_ = dynamic_cast<const PixelCPEBase*>(&es.getData(tCPE_));
162 
163  // Step C: Iterate over DetIds and invoke the strip CPE algorithm
164  // on each DetUnit
165 
166  run(e, input, output, geom);
167 
168  output.shrink_to_fit();
169  e.emplace(tPut_, std::move(output));
170  }
171 
172  //---------------------------------------------------------------------------
176  //---------------------------------------------------------------------------
180  TrackerGeometry const& geom) {
181  if (!cpe_) {
182  edm::LogError("SiPixelRecHitConverter") << " at least one CPE is not ready -- can't run!";
183  // TO DO: throw an exception here? The user may want to know...
184  assert(0);
185  return; // clusterizer is invalid, bail out
186  }
187 
188  int numberOfDetUnits = 0;
189  int numberOfClusters = 0;
190 
191  const edmNew::DetSetVector<SiPixelCluster>& input = *inputhandle;
192 
193  // allocate a buffer for the indices of the clusters
194  auto hmsp = std::make_unique<uint32_t[]>(gpuClustering::maxNumModules + 1);
195  // hitsModuleStart is a non-owning pointer to the buffer
196  auto hitsModuleStart = hmsp.get();
197  // fill cluster arrays
198  std::array<uint32_t, gpuClustering::maxNumModules + 1> clusInModule{};
199  for (auto const& dsv : input) {
200  unsigned int detid = dsv.detId();
201  DetId detIdObject(detid);
202  const GeomDetUnit* genericDet = geom.idToDetUnit(detIdObject);
203  auto gind = genericDet->index();
204  // FIXME to be changed to support Phase2
205  if (gind >= int(gpuClustering::maxNumModules))
206  continue;
207  auto const nclus = dsv.size();
208  assert(nclus > 0);
209  clusInModule[gind] = nclus;
210  numberOfClusters += nclus;
211  }
212  hitsModuleStart[0] = 0;
213  assert(clusInModule.size() > gpuClustering::maxNumModules);
214  for (int i = 1, n = clusInModule.size(); i < n; ++i)
215  hitsModuleStart[i] = hitsModuleStart[i - 1] + clusInModule[i - 1];
216  assert(numberOfClusters == int(hitsModuleStart[gpuClustering::maxNumModules]));
217 
218  // wrap the buffer in a HostProduct, and move it to the Event, without reallocating the buffer or affecting hitsModuleStart
219  iEvent.emplace(tHost_, std::move(hmsp));
220 
221  numberOfClusters = 0;
222  for (auto const& dsv : input) {
223  numberOfDetUnits++;
224  unsigned int detid = dsv.detId();
225  DetId detIdObject(detid);
226  const GeomDetUnit* genericDet = geom.idToDetUnit(detIdObject);
227  const PixelGeomDetUnit* pixDet = dynamic_cast<const PixelGeomDetUnit*>(genericDet);
228  assert(pixDet);
229  SiPixelRecHitCollectionNew::FastFiller recHitsOnDetUnit(output, detid);
230 
231  edmNew::DetSet<SiPixelCluster>::const_iterator clustIt = dsv.begin(), clustEnd = dsv.end();
232 
233  for (; clustIt != clustEnd; clustIt++) {
234  numberOfClusters++;
235  std::tuple<LocalPoint, LocalError, SiPixelRecHitQuality::QualWordType> tuple =
236  cpe_->getParameters(*clustIt, *genericDet);
237  LocalPoint lp(std::get<0>(tuple));
238  LocalError le(std::get<1>(tuple));
239  SiPixelRecHitQuality::QualWordType rqw(std::get<2>(tuple));
240  // Create a persistent edm::Ref to the cluster
242  edmNew::makeRefTo(inputhandle, clustIt);
243  // Make a RecHit and add it to the DetSet
244  // old : recHitsOnDetUnit.push_back( new SiPixelRecHit( lp, le, detIdObject, &*clustIt) );
245  SiPixelRecHit hit(lp, le, rqw, *genericDet, cluster);
246  //
247  // Now save it =================
248  recHitsOnDetUnit.push_back(hit);
249  // =============================
250 
251  // std::cout << "SiPixelRecHitConverterVI " << numberOfClusters << ' '<< lp << " " << le << std::endl;
252  } // <-- End loop on Clusters
253 
254  // LogDebug("SiPixelRecHitConverter")
255  //std::cout << "SiPixelRecHitConverterVI "
256  // << " Found " << recHitsOnDetUnit.size() << " RecHits on " << detid //;
257  // << std::endl;
258 
259  } // <-- End loop on DetUnits
260 
261  // LogDebug ("SiPixelRecHitConverter")
262  // std::cout << "SiPixelRecHitConverterVI "
263  // << cpeName_ << " converted " << numberOfClusters
264  // << " SiPixelClusters into SiPixelRecHits, in "
265  // << numberOfDetUnits << " DetUnits." //;
266  // << std::endl;
267  }
268 } // end of namespace cms
269 
271 
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > const tPixelCluster_
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 push_back(data_type const &d)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::EDPutTokenT< HMSstorage > const tHost_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
int index() const
Definition: GeomDet.h:83
data_type const * const_iterator
Definition: DetSetNew.h:31
Log< level::Error, false > LogError
assert(be >=bs)
edm::ESGetToken< PixelClusterParameterEstimator, TkPixelCPERecord > const tCPE_
static std::string const input
Definition: EdmProvDump.cc:47
int iEvent
Definition: GenABIO.cc:224
ReturnType getParameters(const SiPixelCluster &cl, const GeomDetUnit &det) const override
Definition: PixelCPEBase.h:133
edm::EDPutTokenT< SiPixelRecHitCollection > const tPut_
constexpr uint16_t maxNumModules
bool getData(T &iHolder) const
Definition: EventSetup.h:122
void produce(edm::Event &e, const edm::EventSetup &c) override
The "Event" entrypoint: gets called by framework for every event.
Namespace of DDCMS conversion namespace.
Definition: DetId.h:17
Pixel cluster – collection of neighboring pixels above threshold.
HLT enums.
void run(edm::Event &e, edm::Handle< edmNew::DetSetVector< SiPixelCluster >> inputhandle, SiPixelRecHitCollectionNew &output, TrackerGeometry const &geom)
PixelCPEBase const * cpe_
const PixelClusterParameterEstimator * cpe_; // what we got (for now, one ptr to base class) ...
def move(src, dest)
Definition: eostools.py:511
Our base class.
Definition: SiPixelRecHit.h:23
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > const tTrackerGeom_