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