CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SiPixelDigisClustersFromSoA.cc
Go to the documentation of this file.
18 
19 // local include(s)
20 #include "PixelClusterizerBase.h"
22 
24 public:
26  ~SiPixelDigisClustersFromSoA() override = default;
27 
28  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
29 
30 private:
31  void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
32 
34 
36 
39 
40  const SiPixelClusterThresholds clusterThresholds_; // Cluster threshold in electrons
41 
42  const bool produceDigis_;
43  const bool storeDigis_;
44 };
45 
47  : topoToken_(esConsumes()),
48  digiGetToken_(consumes<SiPixelDigisSoA>(iConfig.getParameter<edm::InputTag>("src"))),
49  clusterPutToken_(produces<SiPixelClusterCollectionNew>()),
50  clusterThresholds_{iConfig.getParameter<int>("clusterThreshold_layer1"),
51  iConfig.getParameter<int>("clusterThreshold_otherLayers")},
52  produceDigis_(iConfig.getParameter<bool>("produceDigis")),
53  storeDigis_(iConfig.getParameter<bool>("produceDigis") & iConfig.getParameter<bool>("storeDigis")) {
54  if (produceDigis_)
55  digiPutToken_ = produces<edm::DetSetVector<PixelDigi>>();
56 }
57 
60  desc.add<edm::InputTag>("src", edm::InputTag("siPixelDigisSoA"));
61  desc.add<int>("clusterThreshold_layer1", kSiPixelClusterThresholdsDefaultPhase1.layer1);
62  desc.add<int>("clusterThreshold_otherLayers", kSiPixelClusterThresholdsDefaultPhase1.otherLayers);
63  desc.add<bool>("produceDigis", true);
64  desc.add<bool>("storeDigis", true);
65  descriptions.addWithDefaultLabel(desc);
66 }
67 
69  const auto& digis = iEvent.get(digiGetToken_);
70  const uint32_t nDigis = digis.size();
71  const auto& ttopo = iSetup.getData(topoToken_);
72 
73  std::unique_ptr<edm::DetSetVector<PixelDigi>> collection;
74  if (produceDigis_)
75  collection = std::make_unique<edm::DetSetVector<PixelDigi>>();
76  if (storeDigis_)
77  collection->reserve(gpuClustering::maxNumModules);
78  auto outputClusters = std::make_unique<SiPixelClusterCollectionNew>();
79  outputClusters->reserve(gpuClustering::maxNumModules, nDigis / 2);
80 
81  edm::DetSet<PixelDigi>* detDigis = nullptr;
82  uint32_t detId = 0;
83  for (uint32_t i = 0; i < nDigis; i++) {
84  // check for uninitialized digis
85  // this is set in RawToDigi_kernel in SiPixelRawToClusterGPUKernel.cu
86  if (digis.rawIdArr(i) == 0)
87  continue;
88  // check for noisy/dead pixels (electrons set to 0)
89  if (digis.adc(i) == 0)
90  continue;
91 
92  detId = digis.rawIdArr(i);
93  if (storeDigis_) {
94  detDigis = &collection->find_or_insert(detId);
95  if ((*detDigis).empty())
96  (*detDigis).data.reserve(64); // avoid the first relocations
97  }
98  break;
99  }
100 
101  int32_t nclus = -1;
103 #ifdef EDM_ML_DEBUG
104  auto totClustersFilled = 0;
105 #endif
106 
107  auto fillClusters = [&](uint32_t detId) {
108  if (nclus < 0)
109  return; // this in reality should never happen
111  auto layer = (DetId(detId).subdetId() == 1) ? ttopo.pxbLayer(detId) : 0;
112  auto clusterThreshold = clusterThresholds_.getThresholdForLayerOnCondition(layer == 1);
113  for (int32_t ic = 0; ic < nclus + 1; ++ic) {
114  auto const& acluster = aclusters[ic];
115  // in any case we cannot go out of sync with gpu...
116  if (acluster.charge < clusterThreshold)
117  edm::LogWarning("SiPixelDigisClustersFromSoA") << "cluster below charge Threshold "
118  << "Layer/DetId/clusId " << layer << '/' << detId << '/' << ic
119  << " size/charge " << acluster.isize << '/' << acluster.charge;
120  // sort by row (x)
121  spc.emplace_back(acluster.isize, acluster.adc, acluster.x, acluster.y, acluster.xmin, acluster.ymin, ic);
122  aclusters[ic].clear();
123 #ifdef EDM_ML_DEBUG
124  ++totClustersFilled;
125  const auto& cluster{spc.back()};
126  LogDebug("SiPixelDigisClustersFromSoA")
127  << "putting in this cluster " << ic << " " << cluster.charge() << " " << cluster.pixelADC().size();
128 #endif
129  std::push_heap(spc.begin(), spc.end(), [](SiPixelCluster const& cl1, SiPixelCluster const& cl2) {
130  return cl1.minPixelRow() < cl2.minPixelRow();
131  });
132  }
133  nclus = -1;
134  // sort by row (x)
135  std::sort_heap(spc.begin(), spc.end(), [](SiPixelCluster const& cl1, SiPixelCluster const& cl2) {
136  return cl1.minPixelRow() < cl2.minPixelRow();
137  });
138  if (spc.empty())
139  spc.abort();
140  };
141 
142  for (uint32_t i = 0; i < nDigis; i++) {
143  // check for uninitialized digis
144  if (digis.rawIdArr(i) == 0)
145  continue;
146  // check for noisy/dead pixels (electrons set to 0)
147  if (digis.adc(i) == 0)
148  continue;
149  if (digis.clus(i) > 9000)
150  continue; // not in cluster; TODO add an assert for the size
151 #ifdef EDM_ML_DEBUG
152  assert(digis.rawIdArr(i) > 109999);
153 #endif
154  if (detId != digis.rawIdArr(i)) {
155  // new module
156  fillClusters(detId);
157 #ifdef EDM_ML_DEBUG
158  assert(nclus == -1);
159 #endif
160  detId = digis.rawIdArr(i);
161  if (storeDigis_) {
162  detDigis = &collection->find_or_insert(detId);
163  if ((*detDigis).empty())
164  (*detDigis).data.reserve(64); // avoid the first relocations
165  else {
166  edm::LogWarning("SiPixelDigisClustersFromSoA")
167  << "Problem det present twice in input! " << (*detDigis).detId();
168  }
169  }
170  }
171  PixelDigi dig(digis.pdigi(i));
172  if (storeDigis_)
173  (*detDigis).data.emplace_back(dig);
174  // fill clusters
175 #ifdef EDM_ML_DEBUG
176  assert(digis.clus(i) >= 0);
178 #endif
179  nclus = std::max(digis.clus(i), nclus);
180  auto row = dig.row();
181  auto col = dig.column();
182  SiPixelCluster::PixelPos pix(row, col);
183  aclusters[digis.clus(i)].add(pix, digis.adc(i));
184  }
185 
186  // fill final clusters
187  if (detId > 0)
188  fillClusters(detId);
189 
190 #ifdef EDM_ML_DEBUG
191  LogDebug("SiPixelDigisClustersFromSoA") << "filled " << totClustersFilled << " clusters";
192 #endif
193 
194  if (produceDigis_)
195  iEvent.put(digiPutToken_, std::move(collection));
197 }
198 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
assert(be >=bs)
constexpr std::array< uint8_t, layerIndexSize > layer
constexpr int32_t getThresholdForLayerOnCondition(bool isLayer1) const noexcept
bool getData(T &iHolder) const
Definition: EventSetup.h:128
int iEvent
Definition: GenABIO.cc:224
int minPixelRow() const
edm::EDPutTokenT< edm::DetSetVector< PixelDigi > > digiPutToken_
const SiPixelClusterThresholds clusterThresholds_
def move
Definition: eostools.py:511
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
SiPixelDigisClustersFromSoA(const edm::ParameterSet &iConfig)
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:346
constexpr int32_t maxNumClustersPerModules
constexpr uint16_t maxNumModules
ParameterDescriptionBase * add(U const &iLabel, T const &value)
~SiPixelDigisClustersFromSoA() override=default
Definition: DetId.h:17
edm::EDPutTokenT< SiPixelClusterCollectionNew > clusterPutToken_
edm::EDGetTokenT< SiPixelDigisSoA > digiGetToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
constexpr SiPixelClusterThresholds kSiPixelClusterThresholdsDefaultPhase1
collection_type data
Definition: DetSet.h:80
Pixel cluster – collection of neighboring pixels above threshold.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void emplace_back(Args &&...args)
bool add(SiPixelCluster::PixelPos const &p, uint16_t const iadc)
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
Log< level::Warning, false > LogWarning
int col
Definition: cuy.py:1009
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
#define LogDebug(id)