CMS 3D CMS Logo

SiPixelDigiMorphing.cc
Go to the documentation of this file.
12 
13 #include <bitset>
14 #include <iterator>
15 
17 public:
18  explicit SiPixelDigiMorphing(const edm::ParameterSet& conf);
19  ~SiPixelDigiMorphing() override = default;
20 
21  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
22  void produce(edm::Event& e, const edm::EventSetup& c) override;
23 
24 private:
27 
28  const int32_t nrows_;
29  const int32_t ncols_;
30  const int32_t nrocs_; // in Phase 1, this is ROCs, but could be any subset of a pixel row
31  const int32_t iters_;
32  const uint32_t fakeAdc_;
33 
34  int32_t ncols_r_; // number of columns per ROC
35  int32_t ksize_; // kernel size
36 
37  std::vector<uint64_t> kernel1_;
38  std::vector<uint64_t> kernel2_;
40 
42 
43  void morph(uint64_t* const imap, uint64_t* omap, uint64_t* const kernel, MorphOption op) const;
44 };
45 
47  : tPixelDigi_(consumes(conf.getParameter<edm::InputTag>("src"))),
48  tPutPixelDigi_(produces<edm::DetSetVector<PixelDigi>>()),
49  nrows_(conf.getParameter<int32_t>("nrows")),
50  ncols_(conf.getParameter<int32_t>("ncols")),
51  nrocs_(conf.getParameter<int32_t>("nrocs")),
52  iters_(conf.getParameter<int32_t>("iters")),
53  fakeAdc_(conf.getParameter<uint32_t>("fakeAdc")) {
54  if (ncols_ % nrocs_ == 0) {
56  } else {
57  throw cms::Exception("Configuration") << "[SiPixelDigiMorphing]:"
58  << " number of columns not divisible with"
59  << " number of ROCs\n";
60  }
61 
62  if (ncols_r_ + 2 * iters_ <= int(sizeof(uint64_t) * 8)) {
63  ksize_ = 2 * iters_ + 1;
64  } else {
65  throw cms::Exception("Configuration") << "[SiPixelDigiMorphing]:"
66  << " too many columns per ROC"
67  << " or too many iterations set\n"
68  << " Ncol/Nrocs+2*iters should not be"
69  << " more than " << sizeof(uint64_t) * 8 << "\n";
70  }
71 
72  std::vector<int32_t> k1(conf.getParameter<std::vector<int32_t>>("kernel1"));
73  std::vector<int32_t> k2(conf.getParameter<std::vector<int32_t>>("kernel2"));
74 
75  kernel1_.resize(ksize_, 0);
76  kernel2_.resize(ksize_, 0);
77  mask_ = 0;
78  int w = (ncols_r_ + 2 * iters_) / ksize_ + ((ncols_r_ + 2 * iters_) % ksize_ != 0);
79  for (int j = 0; j < w; j++) {
80  for (int ii = 0; ii < ksize_; ii++) {
81  kernel1_[ii] <<= ksize_;
82  kernel1_[ii] |= k1[ii];
83  kernel2_[ii] <<= ksize_;
84  kernel2_[ii] |= k2[ii];
85  }
86  mask_ <<= ksize_;
87  mask_ |= 1;
88  }
89  mask_ <<= iters_;
90 }
91 
94 
95  desc.add<edm::InputTag>("src", edm::InputTag("siPixelDigis"));
96  desc.add<int32_t>("nrows", 160);
97  desc.add<int32_t>("ncols", 416);
98  desc.add<int32_t>("nrocs", 8);
99  desc.add<int32_t>("iters", 1);
100  desc.add<std::vector<int32_t>>("kernel1", {7, 7, 7});
101  desc.add<std::vector<int32_t>>("kernel2", {2, 7, 2});
102  desc.add<uint32_t>("fakeAdc", 100);
103 
104  descriptions.addWithDefaultLabel(desc);
105 }
106 
108  auto const& inputDigi = e.get(tPixelDigi_);
109 
110  auto outputDigis = std::make_unique<edm::DetSetVector<PixelDigi>>();
111 
112  const int rocSize = nrows_ + 2 * iters_;
113  const int arrSize = nrocs_ * rocSize;
114 
115  uint64_t imap[arrSize];
116  uint64_t map1[arrSize];
117  uint64_t map2[arrSize];
118 
119  for (auto const& ds : inputDigi) {
120  auto rawId = ds.detId();
121  edm::DetSet<PixelDigi>* detDigis = nullptr;
122  detDigis = &(outputDigis->find_or_insert(rawId));
123 
124  memset(imap, 0, arrSize * sizeof(uint64_t));
125  for (auto const& di : ds) {
126  int r = int(di.column()) / ncols_r_;
127  int c = int(di.column()) % ncols_r_;
128  imap[r * rocSize + di.row() + iters_] |= uint64_t(1) << (c + iters_);
129  if (r > 0 && c < iters_) {
130  imap[(r - 1) * rocSize + di.row() + iters_] |= uint64_t(1) << (c + ncols_r_ + iters_);
131  } else if (++r < nrocs_ && c >= ncols_r_ - iters_) {
132  imap[r * rocSize + di.row() + iters_] |= uint64_t(1) << (c - ncols_r_ + iters_);
133  }
134  (*detDigis).data.emplace_back(di.row(), di.column(), di.adc(), 0);
135  }
136 
137  std::memcpy(map1, imap, arrSize * sizeof(uint64_t));
138  memset(map2, 0, arrSize * sizeof(uint64_t));
139 
140  morph(map1, map2, kernel1_.data(), kDilate);
141  morph(map2, map1, kernel2_.data(), kErode);
142 
143  uint64_t* i = imap + iters_;
144  uint64_t* o = map1 + iters_;
145  for (int roc = 0; roc < nrocs_; roc++, i += 2 * iters_, o += 2 * iters_) {
146  for (int row = 0; row < nrows_; row++, i++, o++) {
147  if (*o == 0)
148  continue;
149  *o >>= iters_;
150  *i >>= iters_;
151  for (int col = 0; col < ncols_r_; col++, (*i) >>= 1, (*o) >>= 1) {
152  if (*o == 0)
153  break;
154  if (((*i) & uint64_t(1)) == 1)
155  continue;
156  if (((*o) & uint64_t(1)) == 1) {
157  (*detDigis).data.emplace_back(row, roc * ncols_r_ + col, fakeAdc_, 1);
158  }
159  }
160  }
161  }
162  }
163  e.put(tPutPixelDigi_, std::move(outputDigis));
164 }
165 
166 void SiPixelDigiMorphing::morph(uint64_t* const imap, uint64_t* omap, uint64_t* const kernel, MorphOption op) const {
167  uint64_t* i[ksize_]; // i(nput)
168  uint64_t* o = omap + iters_; // o(output)
169  unsigned char valid = 0;
170  unsigned char const validMask = (1 << ksize_) - 1;
171  uint64_t m[ksize_]; // m(ask)
172 
173  for (int ii = 0; ii < ksize_; ii++) {
174  i[ii] = imap + ii;
175  valid = (valid << 1) | (*i[ii] != 0);
176  m[ii] = mask_ << ii;
177  }
178 
179  for (int roc = 0; roc < nrocs_; roc++, o += 2 * iters_) {
180  for (int row = 0; row < nrows_; row++, o++) {
181  if ((valid & validMask) != 0) {
182  for (int jj = 0; jj < ksize_; jj++) {
183  for (int ii = 0; ii < ksize_; ii++) {
184  uint64_t v = (*i[ii]) & (kernel[ii] << jj); // v(ector)
185  if (op == kErode)
186  v ^= (kernel[ii] << jj);
187  uint64_t vv = v; // vv(vector bit - shifted and contracted)
188  for (int b = 1; b < ksize_; b++)
189  vv |= (v >> b);
190  *o |= ((vv << iters_) & m[jj]);
191  }
192  if (op == kErode)
193  *o ^= m[jj];
194  }
195  }
196  for (int ii = 0; ii < ksize_; ii++)
197  i[ii]++;
198  valid = (valid << 1) | (*i[ksize_ - 1] != 0);
199  }
200  for (int ii = 0; ii < ksize_; ii++) {
201  i[ii] += 2 * iters_;
202  valid = (valid << 1) | (*i[ii] != 0);
203  }
204  }
205 }
206 
ConfigurationDescriptions.h
SiPixelDigiMorphing::tPutPixelDigi_
edm::EDPutTokenT< edm::DetSetVector< PixelDigi > > tPutPixelDigi_
Definition: SiPixelDigiMorphing.cc:26
SiPixelDigiMorphing::ncols_r_
int32_t ncols_r_
Definition: SiPixelDigiMorphing.cc:34
SiPixelDigiMorphing::~SiPixelDigiMorphing
~SiPixelDigiMorphing() override=default
mps_fire.i
i
Definition: mps_fire.py:428
SiPixelDigiMorphing::ncols_
const int32_t ncols_
Definition: SiPixelDigiMorphing.cc:29
SiPixelDigiMorphing::morph
void morph(uint64_t *const imap, uint64_t *omap, uint64_t *const kernel, MorphOption op) const
Definition: SiPixelDigiMorphing.cc:166
MessageLogger.h
SiPixelDigiMorphing::ksize_
int32_t ksize_
Definition: SiPixelDigiMorphing.cc:35
edm::DetSet
Definition: DetSet.h:23
edm::EDGetTokenT
Definition: EDGetToken.h:33
SiPixelDigiMorphing::kernel2_
std::vector< uint64_t > kernel2_
Definition: SiPixelDigiMorphing.cc:38
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::EDPutTokenT
Definition: EDPutToken.h:33
cuy.col
col
Definition: cuy.py:1009
SiPixelDigiMorphing::kDilate
Definition: SiPixelDigiMorphing.cc:41
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
PixelDigi
Definition: PixelDigi.h:14
EDProducer.h
PixelDigi.h
SiPixelDigiMorphing::fakeAdc_
const uint32_t fakeAdc_
Definition: SiPixelDigiMorphing.cc:32
findQualityFiles.v
v
Definition: findQualityFiles.py:179
SiPixelDigiMorphing::kErode
Definition: SiPixelDigiMorphing.cc:41
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:42
MakerMacros.h
SiPixelDigiMorphing::kernel1_
std::vector< uint64_t > kernel1_
Definition: SiPixelDigiMorphing.cc:37
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
SiPixelDigiMorphing::iters_
const int32_t iters_
Definition: SiPixelDigiMorphing.cc:31
w
const double w
Definition: UKUtility.cc:23
SiPixelDigiMorphing
Definition: SiPixelDigiMorphing.cc:16
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:78
b
double b
Definition: hdecay.h:118
SiPixelDigiMorphing::tPixelDigi_
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > tPixelDigi_
Definition: SiPixelDigiMorphing.cc:25
SiPixelDigiMorphing::nrocs_
const int32_t nrocs_
Definition: SiPixelDigiMorphing.cc:30
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
edm::ParameterSet
Definition: ParameterSet.h:47
SiPixelDigiMorphing::produce
void produce(edm::Event &e, const edm::EventSetup &c) override
Definition: SiPixelDigiMorphing.cc:107
ModuleDef.h
createfilelist.int
int
Definition: createfilelist.py:10
edm::stream::EDProducer
Definition: EDProducer.h:36
edm::EventSetup
Definition: EventSetup.h:58
DetSetVector.h
alignCSCRings.r
r
Definition: alignCSCRings.py:93
SiPixelDigiMorphing::mask_
uint64_t mask_
Definition: SiPixelDigiMorphing.cc:39
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
DetId.h
Frameworkfwd.h
Exception
Definition: hltDiff.cc:245
findQualityFiles.jj
string jj
Definition: findQualityFiles.py:188
PixelMapPlotter.roc
roc
Definition: PixelMapPlotter.py:498
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
SiPixelDigiMorphing::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: SiPixelDigiMorphing.cc:92
SiPixelDigiMorphing::nrows_
const int32_t nrows_
Definition: SiPixelDigiMorphing.cc:28
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
RunInfoPI::valid
Definition: RunInfoPayloadInspectoHelper.h:16
ParameterSet.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
DetSetVectorNew.h
cuy.ii
ii
Definition: cuy.py:589
edm::InputTag
Definition: InputTag.h:15
SiPixelDigiMorphing::MorphOption
MorphOption
Definition: SiPixelDigiMorphing.cc:41
edm::ConfigurationDescriptions::addWithDefaultLabel
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:87
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
SiPixelDigiMorphing::SiPixelDigiMorphing
SiPixelDigiMorphing(const edm::ParameterSet &conf)
Definition: SiPixelDigiMorphing.cc:46