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 
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!
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 (detIds.empty()) return;
61 
62  {
63  connections.clear();
64  connections.resize(detIds.size());
65  //connections (slow, not a big deal)
66  auto const & conns = cabling()->getDetCabling();
67  for (auto i=0U; i<detIds.size(); ++i) {
68  auto c = conns.find(detIds[i]);
69  if (c!=conns.end()) connections[i]=(*c).second;
70  }
71 
72 
73  }
74 
75 
76  { // quality
77  std::vector<uint32_t> dum; qualityHandle->getDetIds(dum);
78  assert(dum.size()<invalidI);
79  unsigned short j=0, i=0;
80  while (i<dum.size() && j<detIds.size()) {
81  if (dum[i]<detIds[j]) ++i;
82  else if (detIds[j]<dum[i]) {indices[j].qi=invalidI; ++j;}
83  else {
84  indices[j].qi=i; ++i; ++j;
85  }
86  }
87  unsigned int nn=0;
88  for(auto k=0U; k<detIds.size();++k) { if (indices[k].qi<invalidI) {++nn; assert(dum[indices[k].qi]==detIds[k]);}}
89  assert(nn<=dum.size());
90  COUT << "quality " << dum.size() << " " <<nn<< std::endl;
91  }
92  { //noise
93  std::vector<uint32_t> dum; noiseHandle->getDetIds(dum);
94  assert(dum.size()<invalidI);
95  unsigned short j=0, i=0;
96  while (i<dum.size() && j<detIds.size()) {
97  if (dum[i]<detIds[j]) ++i;
98  else if (detIds[j]<dum[i]) {indices[j].ni=invalidI; ++j;}
99  else {
100  indices[j].ni=i; ++i; ++j;
101  }
102  }
103  unsigned int nn=0;
104  for(auto k=0U; k<detIds.size();++k) { if (indices[k].ni<invalidI) {++nn; assert(dum[indices[k].ni]==detIds[k]);}}
105  assert(nn<=dum.size());
106  COUT << "noise " << dum.size() << " " <<nn<< std::endl;
107  }
108  { //gain
109  std::vector<uint32_t> dum; gainHandle->getDetIds(dum);
110  assert(dum.size()<invalidI);
111  unsigned short j=0, i=0;
112  while (i<dum.size() && j<detIds.size()) {
113  if (dum[i]<detIds[j]) ++i;
114  else if (detIds[j]<dum[i]) {indices[j].gi=invalidI; ++j;}
115  else {
116  indices[j].gi=i; ++i; ++j;
117  }
118  }
119  unsigned int nn=0;
120  for(auto k=0U; k<detIds.size();++k) { if (indices[k].gi<invalidI) {++nn; assert(dum[indices[k].gi]==detIds[k]);}}
121  assert(nn<=dum.size());
122  COUT << "gain " << dum.size() << " " <<nn<< std::endl;
123  }
124  }
125 
126 }
127 
130 findDetId(const uint32_t id) const {
131  auto b = detIds.begin();
132  auto e = detIds.end();
133  auto p = std::lower_bound(b,e,id);
134  if (p==e || id!=(*p)) {
135 #ifdef NOT_ON_MONTECARLO
136  edm::LogWarning("StripClusterizerAlgorithm")
137  <<"id " << id << " not connected. this is impossible on data "
138  << "old id " << detId << std::endl;
139 #endif
140  return Det();
141  }
142  Det det;
143  det.ind = p-detIds.begin();
144 
145  det.detId = id;
147  det.gainRange = gainHandle->getRangeByPos(indices[det.ind].gi);
149  det.quality = qualityHandle.product();
150 
151 #ifdef EDM_ML_DEBUG
152  assert(detIds[det.ind]==det.detId);
153  auto oldg = gainHandle->getRange(id);
154  assert(oldg==det.gainRange);
155  auto oldn = noiseHandle->getRange(id);
156  assert(oldn==det.noiseRange);
157  auto oldq = qualityHandle->getRange(id);
158  assert(oldq==det.qualityRange);
159 #endif
160 #ifdef EDM_ML_DEBUG
161  assert(isModuleUsable( id ));
162 #endif
163  return det;
164 }
165 
168 
171  : cms::Exception("Invalid Charge") {
172  std::stringstream s;
173  s << "Digi charge of " << digi.adc() << " ADC "
174  << "is out of range on strip " << digi.strip() << ". ";
175  this->append(s.str());
176 }
edm::ESHandle< SiStripQuality > qualityHandle
void getDetIds(std::vector< uint32_t > &DetIds_) const
void clusterize(const edm::DetSetVector< SiStripDigi > &, output_t &) const
void append(Exception const &another)
Definition: Exception.cc:203
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:44
#define COUT
const uint16_t & strip() const
Definition: SiStripDigi.h:40
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:108
SiStripDetCabling const * theCabling
int k[5][pyjets_maxn]
const std::map< uint32_t, std::vector< const FedChannelConnection * > > & getDetCabling() const
void getDetIds(std::vector< uint32_t > &DetIds_) const
bool isModuleUsable(const uint32_t &id) const
virtual void initialize(const edm::EventSetup &)
const T & get() const
Definition: EventSetup.h:58
SiStripDetCabling const * cabling() const
double b
Definition: hdecay.h:120
SiStripApvGain::Range getRangeByPos(unsigned short pos) const
Definition: SiStripGain.h:71
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
std::map< uint32_t, std::vector< int > > const & connected() const
const uint16_t & adc() const
Definition: SiStripDigi.h:41
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:70