CMS 3D CMS Logo

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