CMS 3D CMS Logo

SiStripQualityStatistics.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripQualityStatistics
4 // Class: SiStripQualityStatistics
5 //
13 //
14 // Original Author: Domenico GIORDANO
15 // Created: Wed Oct 3 12:11:10 CEST 2007
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
35 
36 class SiStripFedCabling;
37 
39 public:
41  ~SiStripQualityStatistics() override = default;
42 
43  void endRun(edm::Run const&, edm::EventSetup const&) override;
45 
46  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
47 
48 private:
49  void updateAndSave(const SiStripQuality* siStripQuality);
51 
55  const bool saveTkHistoMap_;
56  //Global Info
57  int NTkBadComponent[4]; //k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
58  int NBadComponent[4][19][4];
59  //legend: NBadComponent[i][j][k]= SubSystem i, layer/disk/wheel j, BadModule/Fiber/Apv k
60  // i: 0=TIB, 1=TID, 2=TOB, 3=TEC
61  // k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
62  std::stringstream ssV[4][19];
63 
66  std::unique_ptr<TkHistoMap> tkhisto;
69  std::unique_ptr<TrackerTopology> tTopo_;
71 };
72 
74  : TkMapFileName_(iConfig.getUntrackedParameter<std::string>("TkMapFileName", "")),
75  saveTkHistoMap_(iConfig.getUntrackedParameter<bool>("SaveTkHistoMap", true)),
76  tkMap(nullptr),
77  tkMapFullIOVs(nullptr),
78  tTopoToken_(esConsumes<edm::Transition::EndRun>()),
79  tkDetMapToken_(esConsumes<edm::Transition::EndRun>()),
80  withFedErrHelper_{iConfig, consumesCollector(), true} {
82  iConfig.getUntrackedParameter<edm::FileInPath>("file", edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile))
83  .fullPath());
84 
85  tkMapFullIOVs = new TrackerMap("BadComponents");
86  tkhisto = nullptr;
87 }
88 
91  desc.addUntracked<std::string>("TkMapFileName", "");
92  desc.addUntracked<bool>("SaveTkHistoMap", true);
95  descriptions.add("siStripQualityStatistics", desc);
96 }
97 
101  }
103  if (!filename.empty()) {
104  tkMapFullIOVs->save(false, 0, 0, filename);
105  filename.erase(filename.begin() + filename.find('.'), filename.end());
106  tkMapFullIOVs->print(false, 0, 0, filename);
107 
108  if (saveTkHistoMap_) {
109  tkhisto->save(filename + ".root");
110  tkhisto->saveAsCanvas(filename + "_Canvas.root", "E");
111  }
112  }
113 }
114 
116  tTopo_ = std::make_unique<TrackerTopology>(iSetup.getData(tTopoToken_));
117  if ((!tkhisto) && (!TkMapFileName_.empty())) {
118  //here the baseline (the value of the empty,not assigned bins) is put to -1 (default is zero)
119  tkhisto = std::make_unique<TkHistoMap>(&iSetup.getData(tkDetMapToken_), "BadComp", "BadComp", -1.);
120  }
121 
123  run_ = run.id();
125  }
126 }
127 
129  for (int i = 0; i < 4; ++i) {
130  NTkBadComponent[i] = 0;
131  for (int j = 0; j < 19; ++j) {
132  ssV[i][j].str("");
133  for (int k = 0; k < 4; ++k)
134  NBadComponent[i][j][k] = 0;
135  }
136  }
137 
138  if (tkMap)
139  delete tkMap;
140  tkMap = new TrackerMap("BadComponents");
141 
142  std::stringstream ss;
143  std::vector<uint32_t> detids = detInfo_.getAllDetIds();
144  std::vector<uint32_t>::const_iterator idet = detids.begin();
145  for (; idet != detids.end(); ++idet) {
146  ss << "detid " << (*idet) << " IsModuleUsable " << siStripQuality->IsModuleUsable((*idet)) << "\n";
147  if (siStripQuality->IsModuleUsable((*idet)))
148  tkMap->fillc(*idet, 0x00ff00);
149  }
150  LogDebug("SiStripQualityStatistics") << ss.str() << std::endl;
151 
152  std::vector<SiStripQuality::BadComponent> BC = siStripQuality->getBadComponentList();
153 
154  for (size_t i = 0; i < BC.size(); ++i) {
155  //&&&&&&&&&&&&&
156  //Full Tk
157  //&&&&&&&&&&&&&
158 
159  if (BC[i].BadModule)
160  NTkBadComponent[0]++;
161  if (BC[i].BadFibers)
162  NTkBadComponent[1] += ((BC[i].BadFibers >> 2) & 0x1) + ((BC[i].BadFibers >> 1) & 0x1) + ((BC[i].BadFibers) & 0x1);
163  if (BC[i].BadApvs)
164  NTkBadComponent[2] += ((BC[i].BadApvs >> 5) & 0x1) + ((BC[i].BadApvs >> 4) & 0x1) + ((BC[i].BadApvs >> 3) & 0x1) +
165  ((BC[i].BadApvs >> 2) & 0x1) + ((BC[i].BadApvs >> 1) & 0x1) + ((BC[i].BadApvs) & 0x1);
166 
167  //&&&&&&&&&&&&&&&&&
168  //Single SubSystem
169  //&&&&&&&&&&&&&&&&&
170  int component;
171  DetId detectorId = DetId(BC[i].detid);
172  int subDet = detectorId.subdetId();
173  if (subDet == StripSubdetector::TIB) {
174  //&&&&&&&&&&&&&&&&&
175  //TIB
176  //&&&&&&&&&&&&&&&&&
177 
178  component = tTopo_->tibLayer(BC[i].detid);
179  SetBadComponents(0, component, BC[i]);
180 
181  } else if (subDet == StripSubdetector::TID) {
182  //&&&&&&&&&&&&&&&&&
183  //TID
184  //&&&&&&&&&&&&&&&&&
185 
186  component = tTopo_->tidSide(BC[i].detid) == 2 ? tTopo_->tidWheel(BC[i].detid) : tTopo_->tidWheel(BC[i].detid) + 3;
187  SetBadComponents(1, component, BC[i]);
188 
189  } else if (subDet == StripSubdetector::TOB) {
190  //&&&&&&&&&&&&&&&&&
191  //TOB
192  //&&&&&&&&&&&&&&&&&
193 
194  component = tTopo_->tobLayer(BC[i].detid);
195  SetBadComponents(2, component, BC[i]);
196 
197  } else if (subDet == StripSubdetector::TEC) {
198  //&&&&&&&&&&&&&&&&&
199  //TEC
200  //&&&&&&&&&&&&&&&&&
201 
202  component = tTopo_->tecSide(BC[i].detid) == 2 ? tTopo_->tecWheel(BC[i].detid) : tTopo_->tecWheel(BC[i].detid) + 9;
203  SetBadComponents(3, component, BC[i]);
204  }
205  }
206 
207  //&&&&&&&&&&&&&&&&&&
208  // Single Strip Info
209  //&&&&&&&&&&&&&&&&&&
210  float percentage = 0;
211 
212  SiStripQuality::RegistryIterator rbegin = siStripQuality->getRegistryVectorBegin();
214 
215  for (SiStripBadStrip::RegistryIterator rp = rbegin; rp != rend; ++rp) {
216  uint32_t detid = rp->detid;
217 
218  int subdet = -999;
219  int component = -999;
220  DetId detectorId = DetId(detid);
221  int subDet = detectorId.subdetId();
222  if (subDet == StripSubdetector::TIB) {
223  subdet = 0;
224  component = tTopo_->tibLayer(detid);
225  } else if (subDet == StripSubdetector::TID) {
226  subdet = 1;
227  component = tTopo_->tidSide(detid) == 2 ? tTopo_->tidWheel(detid) : tTopo_->tidWheel(detid) + 3;
228  } else if (subDet == StripSubdetector::TOB) {
229  subdet = 2;
230  component = tTopo_->tobLayer(detid);
231  } else if (subDet == StripSubdetector::TEC) {
232  subdet = 3;
233  component = tTopo_->tecSide(detid) == 2 ? tTopo_->tecWheel(detid) : tTopo_->tecWheel(detid) + 9;
234  }
235 
236  SiStripQuality::Range sqrange = SiStripQuality::Range(siStripQuality->getDataVectorBegin() + rp->ibegin,
237  siStripQuality->getDataVectorBegin() + rp->iend);
238 
239  percentage = 0;
240  for (int it = 0; it < sqrange.second - sqrange.first; it++) {
241  unsigned int range = siStripQuality->decode(*(sqrange.first + it)).range;
242  NTkBadComponent[3] += range;
243  NBadComponent[subdet][0][3] += range;
244  NBadComponent[subdet][component][3] += range;
245  percentage += range;
246  }
247  if (percentage != 0)
248  percentage /= 128. * detInfo_.getNumberOfApvsAndStripLength(detid).first;
249  if (percentage > 1)
250  edm::LogError("SiStripQualityStatistics") << "PROBLEM detid " << detid << " value " << percentage << std::endl;
251 
252  //------- Global Statistics on percentage of bad components along the IOVs ------//
253  tkMapFullIOVs->fill(detid, percentage);
254  if (tkhisto != nullptr)
255  tkhisto->fill(detid, percentage);
256  }
257 
258  //&&&&&&&&&&&&&&&&&&
259  // printout
260  //&&&&&&&&&&&&&&&&&&
261 
262  ss.str("");
263  ss << "\n-----------------\nNew IOV starting from run " << run_.run() << "\n-----------------\n";
264  ss << "\n-----------------\nGlobal Info\n-----------------";
265  ss << "\nBadComponent \t Modules \tFibers "
266  "\tApvs\tStrips\n----------------------------------------------------------------";
267  ss << "\nTracker:\t\t" << NTkBadComponent[0] << "\t" << NTkBadComponent[1] << "\t" << NTkBadComponent[2] << "\t"
268  << NTkBadComponent[3];
269  ss << "\n";
270  ss << "\nTIB:\t\t\t" << NBadComponent[0][0][0] << "\t" << NBadComponent[0][0][1] << "\t" << NBadComponent[0][0][2]
271  << "\t" << NBadComponent[0][0][3];
272  ss << "\nTID:\t\t\t" << NBadComponent[1][0][0] << "\t" << NBadComponent[1][0][1] << "\t" << NBadComponent[1][0][2]
273  << "\t" << NBadComponent[1][0][3];
274  ss << "\nTOB:\t\t\t" << NBadComponent[2][0][0] << "\t" << NBadComponent[2][0][1] << "\t" << NBadComponent[2][0][2]
275  << "\t" << NBadComponent[2][0][3];
276  ss << "\nTEC:\t\t\t" << NBadComponent[3][0][0] << "\t" << NBadComponent[3][0][1] << "\t" << NBadComponent[3][0][2]
277  << "\t" << NBadComponent[3][0][3];
278  ss << "\n";
279 
280  for (int i = 1; i < 5; ++i)
281  ss << "\nTIB Layer " << i << " :\t\t" << NBadComponent[0][i][0] << "\t" << NBadComponent[0][i][1] << "\t"
282  << NBadComponent[0][i][2] << "\t" << NBadComponent[0][i][3];
283  ss << "\n";
284  for (int i = 1; i < 4; ++i)
285  ss << "\nTID+ Disk " << i << " :\t\t" << NBadComponent[1][i][0] << "\t" << NBadComponent[1][i][1] << "\t"
286  << NBadComponent[1][i][2] << "\t" << NBadComponent[1][i][3];
287  for (int i = 4; i < 7; ++i)
288  ss << "\nTID- Disk " << i - 3 << " :\t\t" << NBadComponent[1][i][0] << "\t" << NBadComponent[1][i][1] << "\t"
289  << NBadComponent[1][i][2] << "\t" << NBadComponent[1][i][3];
290  ss << "\n";
291  for (int i = 1; i < 7; ++i)
292  ss << "\nTOB Layer " << i << " :\t\t" << NBadComponent[2][i][0] << "\t" << NBadComponent[2][i][1] << "\t"
293  << NBadComponent[2][i][2] << "\t" << NBadComponent[2][i][3];
294  ss << "\n";
295  for (int i = 1; i < 10; ++i)
296  ss << "\nTEC+ Disk " << i << " :\t\t" << NBadComponent[3][i][0] << "\t" << NBadComponent[3][i][1] << "\t"
297  << NBadComponent[3][i][2] << "\t" << NBadComponent[3][i][3];
298  for (int i = 10; i < 19; ++i)
299  ss << "\nTEC- Disk " << i - 9 << " :\t\t" << NBadComponent[3][i][0] << "\t" << NBadComponent[3][i][1] << "\t"
300  << NBadComponent[3][i][2] << "\t" << NBadComponent[3][i][3];
301  ss << "\n";
302 
303  ss << "\n----------------------------------------------------------------\n\t\t Detid \tModules Fibers "
304  "Apvs\n----------------------------------------------------------------";
305  for (int i = 1; i < 5; ++i)
306  ss << "\nTIB Layer " << i << " :" << ssV[0][i].str();
307  ss << "\n";
308  for (int i = 1; i < 4; ++i)
309  ss << "\nTID+ Disk " << i << " :" << ssV[1][i].str();
310  for (int i = 4; i < 7; ++i)
311  ss << "\nTID- Disk " << i - 3 << " :" << ssV[1][i].str();
312  ss << "\n";
313  for (int i = 1; i < 7; ++i)
314  ss << "\nTOB Layer " << i << " :" << ssV[2][i].str();
315  ss << "\n";
316  for (int i = 1; i < 10; ++i)
317  ss << "\nTEC+ Disk " << i << " :" << ssV[3][i].str();
318  for (int i = 10; i < 19; ++i)
319  ss << "\nTEC- Disk " << i - 9 << " :" << ssV[3][i].str();
320 
321  edm::LogInfo("SiStripQualityStatistics") << ss.str() << std::endl;
322 
324  std::stringstream sRun;
325  sRun.str("");
326  sRun << "_Run_" << std::setw(6) << std::setfill('0') << run_.run() << std::setw(0);
327 
328  if (!filename.empty()) {
329  filename.insert(filename.find('.'), sRun.str());
330  tkMap->save(true, 0, 0, filename);
331  filename.erase(filename.begin() + filename.find('.'), filename.end());
332  tkMap->print(true, 0, 0, filename);
333  }
334 }
335 
337  int napv = detInfo_.getNumberOfApvsAndStripLength(BC.detid).first;
338 
339  ssV[i][component] << "\n\t\t " << BC.detid << " \t " << BC.BadModule << " \t " << ((BC.BadFibers) & 0x1) << " ";
340  if (napv == 4)
341  ssV[i][component] << "x " << ((BC.BadFibers >> 1) & 0x1);
342 
343  if (napv == 6)
344  ssV[i][component] << ((BC.BadFibers >> 1) & 0x1) << " " << ((BC.BadFibers >> 2) & 0x1);
345  ssV[i][component] << " \t " << ((BC.BadApvs) & 0x1) << " " << ((BC.BadApvs >> 1) & 0x1) << " ";
346  if (napv == 4)
347  ssV[i][component] << "x x " << ((BC.BadApvs >> 2) & 0x1) << " " << ((BC.BadApvs >> 3) & 0x1);
348  if (napv == 6)
349  ssV[i][component] << ((BC.BadApvs >> 2) & 0x1) << " " << ((BC.BadApvs >> 3) & 0x1) << " "
350  << ((BC.BadApvs >> 4) & 0x1) << " " << ((BC.BadApvs >> 5) & 0x1) << " ";
351 
352  if (BC.BadApvs) {
353  NBadComponent[i][0][2] += ((BC.BadApvs >> 5) & 0x1) + ((BC.BadApvs >> 4) & 0x1) + ((BC.BadApvs >> 3) & 0x1) +
354  ((BC.BadApvs >> 2) & 0x1) + ((BC.BadApvs >> 1) & 0x1) + ((BC.BadApvs) & 0x1);
355  NBadComponent[i][component][2] += ((BC.BadApvs >> 5) & 0x1) + ((BC.BadApvs >> 4) & 0x1) +
356  ((BC.BadApvs >> 3) & 0x1) + ((BC.BadApvs >> 2) & 0x1) +
357  ((BC.BadApvs >> 1) & 0x1) + ((BC.BadApvs) & 0x1);
358  tkMap->fillc(BC.detid, 0xff0000);
359  }
360  if (BC.BadFibers) {
361  NBadComponent[i][0][1] += ((BC.BadFibers >> 2) & 0x1) + ((BC.BadFibers >> 1) & 0x1) + ((BC.BadFibers) & 0x1);
362  NBadComponent[i][component][1] +=
363  ((BC.BadFibers >> 2) & 0x1) + ((BC.BadFibers >> 1) & 0x1) + ((BC.BadFibers) & 0x1);
364  tkMap->fillc(BC.detid, 0x0000ff);
365  }
366  if (BC.BadModule) {
367  NBadComponent[i][0][0]++;
368  NBadComponent[i][component][0]++;
369  tkMap->fillc(BC.detid, 0x0);
370  }
371 }
372 
unsigned short range
static constexpr auto TEC
ContainerIterator getDataVectorBegin() const
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
void SetBadComponents(int, int, SiStripQuality::BadComponent &)
std::string fullPath() const
Definition: FileInPath.cc:161
void updateAndSave(const SiStripQuality *siStripQuality)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Registry::const_iterator RegistryIterator
Log< level::Error, false > LogError
const std::vector< BadComponent > & getBadComponentList() const
const edm::ESGetToken< TkDetMap, TrackerTopologyRcd > tkDetMapToken_
~SiStripQualityStatistics() override=default
std::unique_ptr< TrackerTopology > tTopo_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
void save(bool print_total=true, float minval=0., float maxval=0., std::string s="svgmap.svg", int width=1500, int height=800)
Definition: TrackerMap.cc:811
Transition
Definition: Transition.h:12
RegistryIterator getRegistryVectorEnd() const
void endRun(edm::Run const &, edm::EventSetup const &) override
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
SiStripDetInfo read(std::string filePath)
bool getData(T &iHolder) const
Definition: EventSetup.h:122
static constexpr auto TOB
void fillc(int idmod, int RGBcode)
Definition: TrackerMap.h:135
std::stringstream ssV[4][19]
Log< level::Info, false > LogInfo
const edm::ESGetToken< SiStripQuality, SiStripQualityRcd > & qualityToken() const
Definition: DetId.h:17
static constexpr auto TIB
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
const std::pair< unsigned short, double > getNumberOfApvsAndStripLength(uint32_t detId) const
std::unique_ptr< TkHistoMap > tkhisto
const SiStripQuality & getMergedQuality(dqm::harvesting::DQMStore::IGetter &getter)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
SiStripQualityWithFromFedErrorsHelper withFedErrHelper_
HLT enums.
std::pair< ContainerIterator, ContainerIterator > Range
void print(bool print_total=true, float minval=0., float maxval=0., std::string s="svgmap")
Definition: TrackerMap.cc:2943
data decode(const unsigned int &value) const
static constexpr char const *const kDefaultFile
static void fillDescription(edm::ParameterSetDescription &desc)
SiStripQualityStatistics(const edm::ParameterSet &)
#define str(s)
bool IsModuleUsable(uint32_t detid) const
static constexpr auto TID
const std::vector< uint32_t > & getAllDetIds() const noexcept
RegistryIterator getRegistryVectorBegin() const
void fill(int layer, int ring, int nmod, float x)
Definition: TrackerMap.cc:3289
RunNumber_t run() const
Definition: RunID.h:36
Definition: Run.h:45
#define LogDebug(id)