CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
26  uint32_t n_cache_id = es.get<SiStripNoisesRcd>().cacheIdentifier();
27  uint32_t g_cache_id = es.get<SiStripGainRcd>().cacheIdentifier();
28  uint32_t q_cache_id = es.get<SiStripQualityRcd>().cacheIdentifier();
29 
30  bool mod=false;
31  if(g_cache_id != gain_cache_id) {
32  es.get<SiStripGainRcd>().get( gainHandle );
33  gain_cache_id = g_cache_id;
34  mod=true;
35  }
36  if(n_cache_id != noise_cache_id) {
37  es.get<SiStripNoisesRcd>().get( noiseHandle );
38  noise_cache_id = n_cache_id;
39  mod=true;
40  }
41  if(q_cache_id != quality_cache_id) {
43  quality_cache_id = q_cache_id;
44  mod=true;
45  }
46 
47  if (mod) {
48  // redo indexing!
49  theCabling = qualityHandle->cabling();
50  assert(theCabling);
51  auto const & conn = cabling()->connected();
52  COUT << "cabling " << conn.size() << std::endl;
53  detIds.clear();
54  detIds.reserve(conn.size());
55  for (auto const & c : conn) { if (!isModuleBad(c.first)) detIds.push_back(c.first);}
56  indices.clear();
57  indices.resize(detIds.size());
58  COUT << "good detIds " << detIds.size() << std::endl;
59 
60  if (0==detIds.size()) {
61  ind=0; detId=0; return;
62  }
63 
64  {
65  connections.clear();
66  connections.resize(detIds.size());
67  //connections (slow, not a big deal)
68  auto const & conns = cabling()->getDetCabling();
69  for (auto i=0U; i<detIds.size(); ++i) {
70  auto c = conns.find(detIds[i]);
71  if (c!=conns.end()) connections[i]=(*c).second;
72  }
73 
74 
75  }
76 
77 
78  { // quality
79  std::vector<uint32_t> dum; qualityHandle->getDetIds(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]) ++i;
84  else if (detIds[j]<dum[i]) {indices[j].qi=invalidI; ++j;}
85  else {
86  indices[j].qi=i; ++i; ++j;
87  }
88  }
89  unsigned int nn=0;
90  for(auto k=0U; k<detIds.size();++k) { if (indices[k].qi<invalidI) {++nn; assert(dum[indices[k].qi]==detIds[k]);}}
91  assert(nn<=dum.size());
92  COUT << "quality " << dum.size() << " " <<nn<< std::endl;
93  }
94  { //noise
95  std::vector<uint32_t> dum; noiseHandle->getDetIds(dum);
96  assert(dum.size()<invalidI);
97  unsigned short j=0, i=0;
98  while (i<dum.size() && j<detIds.size()) {
99  if (dum[i]<detIds[j]) ++i;
100  else if (detIds[j]<dum[i]) {indices[j].ni=invalidI; ++j;}
101  else {
102  indices[j].ni=i; ++i; ++j;
103  }
104  }
105  unsigned int nn=0;
106  for(auto k=0U; k<detIds.size();++k) { if (indices[k].ni<invalidI) {++nn; assert(dum[indices[k].ni]==detIds[k]);}}
107  assert(nn<=dum.size());
108  COUT << "noise " << dum.size() << " " <<nn<< std::endl;
109  }
110  { //gain
111  std::vector<uint32_t> dum; gainHandle->getDetIds(dum);
112  assert(dum.size()<invalidI);
113  unsigned short j=0, i=0;
114  while (i<dum.size() && j<detIds.size()) {
115  if (dum[i]<detIds[j]) ++i;
116  else if (detIds[j]<dum[i]) {indices[j].gi=invalidI; ++j;}
117  else {
118  indices[j].gi=i; ++i; ++j;
119  }
120  }
121  unsigned int nn=0;
122  for(auto k=0U; k<detIds.size();++k) { if (indices[k].gi<invalidI) {++nn; assert(dum[indices[k].gi]==detIds[k]);}}
123  assert(nn<=dum.size());
124  COUT << "gain " << dum.size() << " " <<nn<< std::endl;
125  }
126  }
127 
128  if (0==detIds.size()) {
129  ind=0; detId=0; return;
130  }
131 
132  // initalize first det
133  ind = 0;
134  detId = detIds[ind];
135 
136  noiseRange = noiseHandle->getRangeByPos(indices[ind].ni);
137  gainRange = gainHandle->getRangeByPos(indices[ind].gi);
138  qualityRange = qualityHandle->getRangeByPos(indices[ind].qi);
139 
140 }
141 
142 
144 setDetId(const uint32_t id) {
145  if (id==detId) return true; // rare....
146  /*
147  // priority to sequential scan
148  if (id==detIds[ind+1]) {
149  ++ind;
150  } else if unlikely( (id>detId) & (id<detIds[ind+1]) ) {
151 // edm::LogWarning("StripClusterizerAlgorithm")
152 // <<"id " << id << " not connected. this is impossible on data "
153 // << "old id " << detId << std::endl;
154  return false;
155  } else{
156  */
157  auto b = detIds.begin();
158  auto e = detIds.end();
159  // if (id>detId) b+=ind;
160  // else e=b+ind;
161  auto p = std::lower_bound(b,e,id);
162  if (p==e || id!=(*p)) {
163 #ifdef NOT_ON_MONTECARLO
164  edm::LogWarning("StripClusterizerAlgorithm")
165  <<"id " << id << " not connected. this is impossible on data "
166  << "old id " << detId << std::endl;
167 #endif
168  return false;
169  }
170  ind = p-detIds.begin();
171 // }
172 
173  detId = id;
174  noiseRange = noiseHandle->getRangeByPos(indices[ind].ni);
175  gainRange = gainHandle->getRangeByPos(indices[ind].gi);
176  qualityRange = qualityHandle->getRangeByPos(indices[ind].qi);
177 
178 #ifdef EDM_ML_DEBUG
179  assert(detIds[ind]==detId);
180  auto oldg = gainHandle->getRange(id);
181  assert(oldg==gainRange);
182  auto oldn = noiseHandle->getRange(id);
183  assert(oldn==noiseRange);
184  auto oldq = qualityHandle->getRange(id);
185  assert(oldq==qualityRange);
186 #endif
187 
188  return true;
189 }
190 
193 
196  : cms::Exception("Invalid Charge") {
197  std::stringstream s;
198  s << "Digi charge of " << digi.adc() << " ADC "
199  << "is out of range on strip " << digi.strip() << ". ";
200  this->append(s.str());
201 }
int i
Definition: DBlmapReader.cc:9
edm::ESHandle< SiStripQuality > qualityHandle
void clusterize_(const T &input, output_t &output)
void append(Exception const &another)
Definition: Exception.cc:203
edm::ESHandle< SiStripGain > gainHandle
SiStripQuality::Range qualityRange
bool isModuleBad(const uint32_t &id) const
edm::ESHandle< SiStripNoises > noiseHandle
static std::string const input
Definition: EdmProvDump.cc:44
#define COUT
const uint16_t & strip() const
Definition: SiStripDigi.h:40
std::vector< std::vector< const FedChannelConnection * > > connections
int j
Definition: DBlmapReader.cc:9
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
SiStripDetCabling const * theCabling
int k[5][pyjets_maxn]
const std::map< uint32_t, std::vector< const FedChannelConnection * > > & getDetCabling() const
virtual void initialize(const edm::EventSetup &)
const T & get() const
Definition: EventSetup.h:55
SiStripDetCabling const * cabling() const
void clusterize(const edm::DetSetVector< SiStripDigi > &, output_t &)
double b
Definition: hdecay.h:120
std::map< uint32_t, std::vector< int > > const & connected() const
std::vector< uint32_t > detIds
const uint16_t & adc() const
Definition: SiStripDigi.h:41
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
tuple conn
Definition: results_mgr.py:53