CMS 3D CMS Logo

StripClusterizerAlgorithm.cc
Go to the documentation of this file.
2 
11 
12 // #define VIDEBUG
13 
14 #ifdef VIDEBUG
15 #define COUT std::cout
16 #else
17 #define COUT LogDebug("StripClusterizerAlgorithm")
18 #endif
19 
20 #include <string>
21 #include <algorithm>
22 #include <cassert>
23 
25  uint32_t n_cache_id = es.get<SiStripNoisesRcd>().cacheIdentifier();
26  uint32_t g_cache_id = es.get<SiStripGainRcd>().cacheIdentifier();
27  uint32_t q_cache_id = es.get<SiStripQualityRcd>().cacheIdentifier();
28 
29  bool mod = false;
30  if (g_cache_id != gain_cache_id) {
31  es.get<SiStripGainRcd>().get(gainHandle);
32  gain_cache_id = g_cache_id;
33  mod = true;
34  }
35  if (n_cache_id != noise_cache_id) {
36  es.get<SiStripNoisesRcd>().get(noiseHandle);
37  noise_cache_id = n_cache_id;
38  mod = true;
39  }
40  if (q_cache_id != quality_cache_id) {
42  quality_cache_id = q_cache_id;
43  mod = true;
44  }
45 
46  if (mod) {
47  // redo indexing!
49  assert(theCabling);
50  auto const& conn = cabling()->connected();
51  COUT << "cabling " << conn.size() << std::endl;
52  detIds.clear();
53  detIds.reserve(conn.size());
54  for (auto const& c : conn) {
55  if (!isModuleBad(c.first))
56  detIds.push_back(c.first);
57  }
58  indices.clear();
59  indices.resize(detIds.size());
60  COUT << "good detIds " << detIds.size() << std::endl;
61 
62  if (detIds.empty())
63  return;
64 
65  {
66  connections.clear();
67  connections.resize(detIds.size());
68  //connections (slow, not a big deal)
69  auto const& conns = cabling()->getDetCabling();
70  for (auto i = 0U; i < detIds.size(); ++i) {
71  auto c = conns.find(detIds[i]);
72  if (c != conns.end())
73  connections[i] = (*c).second;
74  }
75  }
76 
77  { // quality
78  std::vector<uint32_t> dum;
80  assert(dum.size() < invalidI);
81  unsigned short j = 0, i = 0;
82  while (i < dum.size() && j < detIds.size()) {
83  if (dum[i] < detIds[j])
84  ++i;
85  else if (detIds[j] < dum[i]) {
86  indices[j].qi = invalidI;
87  ++j;
88  } else {
89  indices[j].qi = i;
90  ++i;
91  ++j;
92  }
93  }
94  unsigned int nn = 0;
95  for (auto k = 0U; k < detIds.size(); ++k) {
96  if (indices[k].qi < invalidI) {
97  ++nn;
98  assert(dum[indices[k].qi] == detIds[k]);
99  }
100  }
101  assert(nn <= dum.size());
102  COUT << "quality " << dum.size() << " " << nn << std::endl;
103  }
104  { //noise
105  std::vector<uint32_t> dum;
106  noiseHandle->getDetIds(dum);
107  assert(dum.size() < invalidI);
108  unsigned short j = 0, i = 0;
109  while (i < dum.size() && j < detIds.size()) {
110  if (dum[i] < detIds[j])
111  ++i;
112  else if (detIds[j] < dum[i]) {
113  indices[j].ni = invalidI;
114  ++j;
115  } else {
116  indices[j].ni = i;
117  ++i;
118  ++j;
119  }
120  }
121  unsigned int nn = 0;
122  for (auto k = 0U; k < detIds.size(); ++k) {
123  if (indices[k].ni < invalidI) {
124  ++nn;
125  assert(dum[indices[k].ni] == detIds[k]);
126  }
127  }
128  assert(nn <= dum.size());
129  COUT << "noise " << dum.size() << " " << nn << std::endl;
130  }
131  { //gain
132  std::vector<uint32_t> dum;
133  gainHandle->getDetIds(dum);
134  assert(dum.size() < invalidI);
135  unsigned short j = 0, i = 0;
136  while (i < dum.size() && j < detIds.size()) {
137  if (dum[i] < detIds[j])
138  ++i;
139  else if (detIds[j] < dum[i]) {
140  indices[j].gi = invalidI;
141  ++j;
142  } else {
143  indices[j].gi = i;
144  ++i;
145  ++j;
146  }
147  }
148  unsigned int nn = 0;
149  for (auto k = 0U; k < detIds.size(); ++k) {
150  if (indices[k].gi < invalidI) {
151  ++nn;
152  assert(dum[indices[k].gi] == detIds[k]);
153  }
154  }
155  assert(nn <= dum.size());
156  COUT << "gain " << dum.size() << " " << nn << std::endl;
157  }
158  }
159 }
160 
162  auto b = detIds.begin();
163  auto e = detIds.end();
164  auto p = std::lower_bound(b, e, id);
165  if (p == e || id != (*p)) {
166 #ifdef NOT_ON_MONTECARLO
167  edm::LogWarning("StripClusterizerAlgorithm") << "id " << id << " not connected. this is impossible on data "
168  << "old id " << detId << std::endl;
169 #endif
170  return Det();
171  }
172  Det det;
173  det.ind = p - detIds.begin();
174 
175  det.detId = id;
177  det.gainRange = gainHandle->getRangeByPos(indices[det.ind].gi);
179  det.quality = qualityHandle.product();
180 
181 #ifdef EDM_ML_DEBUG
182  assert(detIds[det.ind] == det.detId);
183  auto oldg = gainHandle->getRange(id);
184  assert(oldg == det.gainRange);
185  auto oldn = noiseHandle->getRange(id);
186  assert(oldn == det.noiseRange);
187  auto oldq = qualityHandle->getRange(id);
188  assert(oldq == det.qualityRange);
189 #endif
190 #ifdef EDM_ML_DEBUG
191  assert(isModuleUsable(id));
192 #endif
193  return det;
194 }
195 
197  clusterize_(input, output);
198 }
200  clusterize_(input, output);
201 }
202 
204  : cms::Exception("Invalid Charge") {
205  std::stringstream s;
206  s << "Digi charge of " << digi.adc() << " ADC "
207  << "is out of range on strip " << digi.strip() << ". ";
208  this->append(s.str());
209 }
edm::ESHandle< SiStripQuality > qualityHandle
void getDetIds(std::vector< uint32_t > &DetIds_) const
const std::map< uint32_t, std::vector< const FedChannelConnection * > > & getDetCabling() const
std::map< uint32_t, std::vector< int > > const & connected() const
void clusterize(const edm::DetSetVector< SiStripDigi > &, output_t &) const
void append(Exception const &another)
Definition: Exception.cc:153
edm::ESHandle< SiStripGain > gainHandle
Range getRangeByPos(unsigned short pos) const
bool isModuleBad(const uint32_t &id) const
GeometricSearchDet Det
Definition: DetBelowR.h:8
edm::ESHandle< SiStripNoises > noiseHandle
static std::string const input
Definition: EdmProvDump.cc:48
#define COUT
const uint16_t & strip() const
Definition: SiStripDigi.h:33
std::vector< std::vector< const FedChannelConnection * > > connections
void clusterize_(const T &input, output_t &output) const
SiStripDetCabling const * cabling() const
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
void getDetIds(std::vector< uint32_t > &DetIds_) const
ATTENTION: we assume the detIds are the same as those from the first gain.
Definition: SiStripGain.cc:102
SiStripDetCabling const * theCabling
Namespace of DDCMS conversion namespace.
void getDetIds(std::vector< uint32_t > &DetIds_) const
bool isModuleUsable(const uint32_t &id) const
virtual void initialize(const edm::EventSetup &)
SiStripDetCabling const * cabling() const
double b
Definition: hdecay.h:118
SiStripApvGain::Range getRangeByPos(unsigned short pos) const
Definition: SiStripGain.h:72
const Range getRange(const uint32_t detID) const
Det findDetId(const uint32_t) const
Range getRangeByPos(unsigned short pos) const
const Range getRange(const uint32_t detID) const
T get() const
Definition: EventSetup.h:73
const uint16_t & adc() const
Definition: SiStripDigi.h:34
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
T const * product() const
Definition: ESHandle.h:86
const SiStripApvGain::Range getRange(uint32_t detID) const
Definition: SiStripGain.h:71