CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SiStripBadAPVAlgorithmFromClusterOccupancy.cc
Go to the documentation of this file.
2 
10 
12  const TrackerTopology* theTopo)
13  : lowoccupancy_(0),
14  highoccupancy_(100),
15  absolutelow_(0),
16  numberiterations_(2),
17  Nevents_(0),
18  occupancy_(0),
19  OutFileName_("Occupancy.root"),
20  UseInputDB_(iConfig.getUntrackedParameter<bool>("UseInputDB", false)),
21  tTopo(theTopo) {
23 }
24 
26  LogTrace("SiStripBadAPVAlgorithmFromClusterOccupancy")
27  << "[SiStripBadAPVAlgorithmFromClusterOccupancy::~SiStripBadAPVAlgorithmFromClusterOccupancy] " << std::endl;
28 }
29 
31  HistoMap& DM,
32  const SiStripQuality* inSiStripQuality) {
33  LogTrace("SiStripBadAPVAlgorithmFromClusterOccupancy")
34  << "[SiStripBadAPVAlgorithmFromClusterOccupancy::extractBadAPVs] " << std::endl;
35 
36  if (WriteOutputFile_ == true) {
37  f = new TFile(OutFileName_.c_str(), "RECREATE");
38  f->cd();
39 
40  apvtree = new TTree("moduleOccupancy", "tree");
41 
42  apvtree->Branch("DetRawId", &detrawid, "DetRawId/I");
43  apvtree->Branch("SubDetId", &subdetid, "SubDetId/I");
44  apvtree->Branch("Layer_Ring", &layer_ring, "Layer_Ring/I");
45  apvtree->Branch("Disc", &disc, "Disc/I");
46  apvtree->Branch("IsBack", &isback, "IsBack/I");
47  apvtree->Branch("IsExternalString", &isexternalstring, "IsExternalString/I");
48  apvtree->Branch("IsZMinusSide", &iszminusside, "IsZMinusSide/I");
49  apvtree->Branch("RodStringPetal", &rodstringpetal, "RodStringPetal/I");
50  apvtree->Branch("IsStereo", &isstereo, "IsStereo/I");
51  apvtree->Branch("ModuleNumber", &module_number, "ModuleNumber/I");
52  apvtree->Branch("NumberOfStrips", &number_strips, "NumberOfStrips/I");
53  apvtree->Branch("APVGlobalPositionX", &global_position_x, "APVGlobalPositionX/F");
54  apvtree->Branch("APVGlobalPositionY", &global_position_y, "APVGlobalPositionY/F");
55  apvtree->Branch("APVGlobalPositionZ", &global_position_z, "APVGlobalPositionZ/F");
56  apvtree->Branch("APVNumber", &apv_number, "APVNumber/I");
57  apvtree->Branch("APVAbsoluteOccupancy", &apvAbsoluteOccupancy, "apvAbsoluteOccupancy/D");
58  apvtree->Branch("APVMedianOccupancy", &apvMedianOccupancy, "apvMedianOccupancy/D");
59  }
60 
61  HistoMap::iterator it = DM.begin();
62  HistoMap::iterator itEnd = DM.end();
63  std::vector<unsigned int> badStripList;
64  uint32_t detid;
65  for (; it != itEnd; ++it) {
66  Apv APV;
67 
68  for (int apv = 0; apv < 6; apv++) {
69  APV.apvMedian[apv] = 0;
70  APV.apvabsoluteOccupancy[apv] = 0;
71 
72  for (int strip = 0; strip < 128; strip++) {
73  stripOccupancy[apv][strip] = 0;
74  stripWeight[apv][strip] = 0;
75  }
76  }
77 
78  pHisto phisto;
79  phisto._th1f = it->second.get();
80  phisto._NEntries = (int)phisto._th1f->GetEntries();
81  phisto._NBins = phisto._th1f->GetNbinsX();
82 
83  number_strips = (int)phisto._NBins;
84  number_apvs = number_strips / 128;
85  APV.numberApvs = number_apvs;
86 
87  for (int apv = 0; apv < number_apvs; apv++) {
88  for (int strip = 0; strip < 128; strip++) {
89  stripOccupancy[apv][strip] =
90  phisto._th1f->GetBinContent((apv * 128) + strip + 1); // Remember: Bin=0 is underflow bin!
91  stripWeight[apv][strip] = 1;
92  APV.apvabsoluteOccupancy[apv] +=
93  phisto._th1f->GetBinContent((apv * 128) + strip + 1); // Remember: Bin=0 is underflow bin!
94  }
95  }
96 
97  for (int apv = 0; apv < number_apvs; apv++) {
98  APV.apvMedian[apv] = TMath::Median(128, stripOccupancy[apv], stripWeight[apv]);
99  }
100 
101  detid = it->first;
102  DetId detectorId = DetId(detid);
103 
104  if (edm::isDebugEnabled())
105  LogTrace("SiStripBadAPV") << "Analyzing detid " << detid << std::endl;
106 
107  detrawid = detid;
108  APV.detrawId = detrawid;
109  subdetid = detectorId.subdetId();
110  switch (detectorId.subdetId()) {
113  disc = -1;
115  isback = -1;
117  isexternalstring = 1;
118  else
119  isexternalstring = 0;
121  iszminusside = 1;
122  else
123  iszminusside = 0;
127 
128  if (layer_ring == 1)
129  medianValues_TIB_Layer1.push_back(APV);
130  else if (layer_ring == 2)
131  medianValues_TIB_Layer2.push_back(APV);
132  else if (layer_ring == 3)
133  medianValues_TIB_Layer3.push_back(APV);
134  else if (layer_ring == 4)
135  medianValues_TIB_Layer4.push_back(APV);
136  break;
137 
143  isback = 1;
144  else
145  isback = 0;
147  iszminusside = 1;
148  else
149  iszminusside = 0;
150  isexternalstring = -1;
151  rodstringpetal = -1;
154 
155  if (iszminusside == 0) {
156  if (disc == 1)
157  medianValues_TIDPlus_Disc1.push_back(APV);
158  else if (disc == 2)
159  medianValues_TIDPlus_Disc2.push_back(APV);
160  else if (disc == 3)
161  medianValues_TIDPlus_Disc3.push_back(APV);
162  } else if (iszminusside == 1) {
163  if (disc == 1)
164  medianValues_TIDMinus_Disc1.push_back(APV);
165  else if (disc == 2)
166  medianValues_TIDMinus_Disc2.push_back(APV);
167  else if (disc == 3)
168  medianValues_TIDMinus_Disc3.push_back(APV);
169  }
170  break;
171 
174  disc = -1;
176  isback = -1;
178  iszminusside = 1;
179  else
180  iszminusside = 0;
181  isexternalstring = -1;
185 
186  if (layer_ring == 1)
187  medianValues_TOB_Layer1.push_back(APV);
188  else if (layer_ring == 2)
189  medianValues_TOB_Layer2.push_back(APV);
190  else if (layer_ring == 3)
191  medianValues_TOB_Layer3.push_back(APV);
192  else if (layer_ring == 4)
193  medianValues_TOB_Layer4.push_back(APV);
194  else if (layer_ring == 5)
195  medianValues_TOB_Layer5.push_back(APV);
196  else if (layer_ring == 6)
197  medianValues_TOB_Layer6.push_back(APV);
198  break;
199 
205  isback = 1;
206  else
207  isback = 0;
209  iszminusside = 1;
210  else
211  iszminusside = 0;
212  isexternalstring = -1;
216 
217  if (iszminusside == 0) {
218  if (disc == 1)
219  medianValues_TECPlus_Disc1.push_back(APV);
220  else if (disc == 2)
221  medianValues_TECPlus_Disc2.push_back(APV);
222  else if (disc == 3)
223  medianValues_TECPlus_Disc3.push_back(APV);
224  else if (disc == 4)
225  medianValues_TECPlus_Disc4.push_back(APV);
226  else if (disc == 5)
227  medianValues_TECPlus_Disc5.push_back(APV);
228  else if (disc == 6)
229  medianValues_TECPlus_Disc6.push_back(APV);
230  else if (disc == 7)
231  medianValues_TECPlus_Disc7.push_back(APV);
232  else if (disc == 8)
233  medianValues_TECPlus_Disc8.push_back(APV);
234  else if (disc == 9)
235  medianValues_TECPlus_Disc9.push_back(APV);
236  } else if (iszminusside == 1) {
237  if (disc == 1)
238  medianValues_TECMinus_Disc1.push_back(APV);
239  else if (disc == 2)
240  medianValues_TECMinus_Disc2.push_back(APV);
241  else if (disc == 3)
242  medianValues_TECMinus_Disc3.push_back(APV);
243  else if (disc == 4)
244  medianValues_TECMinus_Disc4.push_back(APV);
245  else if (disc == 5)
246  medianValues_TECMinus_Disc5.push_back(APV);
247  else if (disc == 6)
248  medianValues_TECMinus_Disc6.push_back(APV);
249  else if (disc == 7)
250  medianValues_TECMinus_Disc7.push_back(APV);
251  else if (disc == 8)
252  medianValues_TECMinus_Disc8.push_back(APV);
253  else if (disc == 9)
254  medianValues_TECMinus_Disc9.push_back(APV);
255  }
256  break;
257 
258  default:
259  std::cout << "### Detector does not belong to TIB, TID, TOB or TEC !? ###" << std::endl;
260  std::cout << "### DetRawId: " << detrawid << " ###" << std::endl;
261  }
262 
263  const StripGeomDetUnit* theStripDet = dynamic_cast<const StripGeomDetUnit*>((TkGeom->idToDet(detectorId)));
264  const StripTopology* theStripTopol = dynamic_cast<const StripTopology*>(&(theStripDet->specificTopology()));
265 
266  for (int apv = 0; apv < number_apvs; apv++) {
267  apv_number = apv + 1;
268  apvMedianOccupancy = APV.apvMedian[apv];
270 
271  LocalPoint pos_strip_local = theStripTopol->localPosition((apv * 128));
272  GlobalPoint pos_strip_global = (TkGeom->idToDet(detectorId))->surface().toGlobal(pos_strip_local);
273 
274  global_position_x = pos_strip_global.x();
275  global_position_y = pos_strip_global.y();
276  global_position_z = pos_strip_global.z();
277 
278  if (WriteOutputFile_ == true)
279  apvtree->Fill();
280  }
281 
282  } // end loop on modules
283 
284  // Calculate Mean and RMS for each Layer
289 
296 
303 
313 
323 
324  pQuality = siStripQuality;
325  badStripList.clear();
326 
327  // Analyze the APV Occupancy for hot APVs
328  AnalyzeOccupancy(siStripQuality, medianValues_TIB_Layer1, MeanAndRms_TIB_Layer1, badStripList, inSiStripQuality);
329  AnalyzeOccupancy(siStripQuality, medianValues_TIB_Layer2, MeanAndRms_TIB_Layer2, badStripList, inSiStripQuality);
330  AnalyzeOccupancy(siStripQuality, medianValues_TIB_Layer3, MeanAndRms_TIB_Layer3, badStripList, inSiStripQuality);
331  AnalyzeOccupancy(siStripQuality, medianValues_TIB_Layer4, MeanAndRms_TIB_Layer4, badStripList, inSiStripQuality);
332 
333  AnalyzeOccupancy(siStripQuality, medianValues_TOB_Layer1, MeanAndRms_TOB_Layer1, badStripList, inSiStripQuality);
334  AnalyzeOccupancy(siStripQuality, medianValues_TOB_Layer2, MeanAndRms_TOB_Layer2, badStripList, inSiStripQuality);
335  AnalyzeOccupancy(siStripQuality, medianValues_TOB_Layer3, MeanAndRms_TOB_Layer3, badStripList, inSiStripQuality);
336  AnalyzeOccupancy(siStripQuality, medianValues_TOB_Layer4, MeanAndRms_TOB_Layer4, badStripList, inSiStripQuality);
337  AnalyzeOccupancy(siStripQuality, medianValues_TOB_Layer5, MeanAndRms_TOB_Layer5, badStripList, inSiStripQuality);
338  AnalyzeOccupancy(siStripQuality, medianValues_TOB_Layer6, MeanAndRms_TOB_Layer6, badStripList, inSiStripQuality);
339 
341  siStripQuality, medianValues_TIDPlus_Disc1, MeanAndRms_TIDPlus_Disc1, badStripList, inSiStripQuality);
343  siStripQuality, medianValues_TIDPlus_Disc2, MeanAndRms_TIDPlus_Disc2, badStripList, inSiStripQuality);
345  siStripQuality, medianValues_TIDPlus_Disc3, MeanAndRms_TIDPlus_Disc3, badStripList, inSiStripQuality);
347  siStripQuality, medianValues_TIDMinus_Disc1, MeanAndRms_TIDMinus_Disc1, badStripList, inSiStripQuality);
349  siStripQuality, medianValues_TIDMinus_Disc2, MeanAndRms_TIDMinus_Disc2, badStripList, inSiStripQuality);
351  siStripQuality, medianValues_TIDMinus_Disc3, MeanAndRms_TIDMinus_Disc3, badStripList, inSiStripQuality);
352 
354  siStripQuality, medianValues_TECPlus_Disc1, MeanAndRms_TECPlus_Disc1, badStripList, inSiStripQuality);
356  siStripQuality, medianValues_TECPlus_Disc2, MeanAndRms_TECPlus_Disc2, badStripList, inSiStripQuality);
358  siStripQuality, medianValues_TECPlus_Disc3, MeanAndRms_TECPlus_Disc3, badStripList, inSiStripQuality);
360  siStripQuality, medianValues_TECPlus_Disc4, MeanAndRms_TECPlus_Disc4, badStripList, inSiStripQuality);
362  siStripQuality, medianValues_TECPlus_Disc5, MeanAndRms_TECPlus_Disc5, badStripList, inSiStripQuality);
364  siStripQuality, medianValues_TECPlus_Disc6, MeanAndRms_TECPlus_Disc6, badStripList, inSiStripQuality);
366  siStripQuality, medianValues_TECPlus_Disc7, MeanAndRms_TECPlus_Disc7, badStripList, inSiStripQuality);
368  siStripQuality, medianValues_TECPlus_Disc8, MeanAndRms_TECPlus_Disc8, badStripList, inSiStripQuality);
370  siStripQuality, medianValues_TECPlus_Disc9, MeanAndRms_TECPlus_Disc9, badStripList, inSiStripQuality);
371 
373  siStripQuality, medianValues_TECMinus_Disc1, MeanAndRms_TECMinus_Disc1, badStripList, inSiStripQuality);
375  siStripQuality, medianValues_TECMinus_Disc2, MeanAndRms_TECMinus_Disc2, badStripList, inSiStripQuality);
377  siStripQuality, medianValues_TECMinus_Disc3, MeanAndRms_TECMinus_Disc3, badStripList, inSiStripQuality);
379  siStripQuality, medianValues_TECMinus_Disc4, MeanAndRms_TECMinus_Disc4, badStripList, inSiStripQuality);
381  siStripQuality, medianValues_TECMinus_Disc5, MeanAndRms_TECMinus_Disc5, badStripList, inSiStripQuality);
383  siStripQuality, medianValues_TECMinus_Disc6, MeanAndRms_TECMinus_Disc6, badStripList, inSiStripQuality);
385  siStripQuality, medianValues_TECMinus_Disc7, MeanAndRms_TECMinus_Disc7, badStripList, inSiStripQuality);
387  siStripQuality, medianValues_TECMinus_Disc8, MeanAndRms_TECMinus_Disc8, badStripList, inSiStripQuality);
389  siStripQuality, medianValues_TECMinus_Disc9, MeanAndRms_TECMinus_Disc9, badStripList, inSiStripQuality);
390 
391  siStripQuality->fillBadComponents();
392 
393  if (WriteOutputFile_ == true) {
394  f->cd();
395  apvtree->Write();
396  f->Close();
397  }
398 
399  LogTrace("SiStripBadAPV") << ss.str() << std::endl;
400 }
401 
403  std::pair<double, double>* MeanRMS,
404  int number_iterations) {
405  Double_t tot[7], tot2[7];
406  Double_t n[7];
407 
408  Double_t Mean[7] = {0};
409  Double_t Rms[7] = {1000, 1000, 1000, 1000, 1000, 1000, 1000};
410 
411  int Moduleposition;
412 
413  for (int i = 0; i < number_iterations; i++) {
414  for (int j = 0; j < 7; j++) {
415  n[j] = 0;
416  tot[j] = 0;
417  tot2[j] = 0;
418  }
419 
420  for (uint32_t it = 0; it < a.size(); it++) {
421  Moduleposition = (a[it].modulePosition) - 1;
422 
423  for (int apv = 0; apv < a[it].numberApvs; apv++) {
424  if (i > 0) {
425  if (a[it].apvMedian[apv] < (Mean[Moduleposition] - 3 * Rms[Moduleposition]) ||
426  (a[it].apvMedian[apv] > (Mean[Moduleposition] + 5 * Rms[Moduleposition]))) {
427  continue;
428  }
429  }
430  tot[Moduleposition] += a[it].apvMedian[apv];
431  tot2[Moduleposition] += (a[it].apvMedian[apv]) * (a[it].apvMedian[apv]);
432  n[Moduleposition]++;
433  }
434  }
435 
436  for (int j = 0; j < 7; j++) {
437  if (n[j] != 0) {
438  Mean[j] = tot[j] / n[j];
439  Rms[j] = TMath::Sqrt(TMath::Abs(tot2[j] / n[j] - Mean[j] * Mean[j]));
440  }
441  }
442  }
443 
444  for (int j = 0; j < 7; j++) {
445  MeanRMS[j] = std::make_pair(Mean[j], Rms[j]);
446  }
447 }
448 
450  std::vector<Apv>& medianValues,
451  std::pair<double, double>* MeanAndRms,
452  std::vector<unsigned int>& BadStripList,
453  const SiStripQuality* InSiStripQuality) {
454  int Moduleposition;
455  uint32_t Detid;
456 
457  for (uint32_t it = 0; it < medianValues.size(); it++) {
458  Moduleposition = (medianValues[it].modulePosition) - 1;
459  Detid = medianValues[it].detrawId;
460 
461  for (int apv = 0; apv < medianValues[it].numberApvs; apv++) {
462  if (UseInputDB_) {
463  if (InSiStripQuality->IsApvBad(Detid, apv)) {
464  continue; //if the apv is already flagged as bad, continue.
465  }
466  }
467  if (medianValues[it].apvMedian[apv] > minNevents_) {
468  if ((medianValues[it].apvMedian[apv] >
469  (MeanAndRms[Moduleposition].first + highoccupancy_ * MeanAndRms[Moduleposition].second)) &&
470  (medianValues[it].apvMedian[apv] > absolutelow_))
471  BadStripList.push_back(pQuality->encode((apv * 128), 128, 0));
472  } else if (medianValues[it].apvMedian[apv] <
473  (MeanAndRms[Moduleposition].first - lowoccupancy_ * MeanAndRms[Moduleposition].second) &&
474  (MeanAndRms[Moduleposition].first > 2 || medianValues[it].apvabsoluteOccupancy[apv] == 0)) {
475  BadStripList.push_back(pQuality->encode((apv * 128), 128, 0));
476  std::cout << "Dead APV! DetId: " << medianValues[it].detrawId << ", APV number: " << apv + 1
477  << ", APVMedian: " << medianValues[it].apvMedian[apv]
478  << ", Mean: " << MeanAndRms[Moduleposition].first << ", RMS: " << MeanAndRms[Moduleposition].second
479  << ", LowThreshold: " << lowoccupancy_ << ", Mean-Low*RMS: "
480  << (MeanAndRms[Moduleposition].first - lowoccupancy_ * MeanAndRms[Moduleposition].second)
481  << std::endl;
482  }
483  }
484  if (BadStripList.begin() != BadStripList.end()) {
485  quality->compact(Detid, BadStripList);
486  SiStripQuality::Range range(BadStripList.begin(), BadStripList.end());
487  quality->put(Detid, range);
488  }
489  BadStripList.clear();
490  }
491 }
492 
bool IsApvBad(const uint32_t &detid, const short &apvNb) const
bool isDebugEnabled()
static constexpr auto TEC
unsigned int tibLayer(const DetId &id) const
unsigned int tibString(const DetId &id) const
unsigned int tidRing(const DetId &id) const
bool tobIsStereo(const DetId &id) const
uint32_t const *__restrict__ Quality * quality
void CalculateMeanAndRMS(const std::vector< Apv > &, std::pair< double, double > *, int)
unsigned int tecRing(const DetId &id) const
ring id
SiStripBadAPVAlgorithmFromClusterOccupancy(const edm::ParameterSet &, const TrackerTopology *)
T y() const
Definition: PV3DBase.h:60
unsigned int tidWheel(const DetId &id) const
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
bool tecIsZMinusSide(const DetId &id) const
#define LogTrace(id)
bool tidIsStereo(const DetId &id) const
const uint16_t range(const Frame &aFrame)
bool tidIsZMinusSide(const DetId &id) const
static const char occupancy_[]
U second(std::pair< T, U > const &p)
bool tecIsStereo(const DetId &id) const
bool tibIsExternalString(const DetId &id) const
bool tibIsZMinusSide(const DetId &id) const
void extractBadAPVs(SiStripQuality *, HistoMap &, const SiStripQuality *)
unsigned int tidModule(const DetId &id) const
bool tidIsBackRing(const DetId &id) const
T z() const
Definition: PV3DBase.h:61
void compact(unsigned int &, std::vector< unsigned int > &)
T Abs(T a)
Definition: MathUtil.h:49
bool tobIsZMinusSide(const DetId &id) const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
void AnalyzeOccupancy(SiStripQuality *, std::vector< Apv > &, std::pair< double, double > *, std::vector< unsigned int > &, const SiStripQuality *)
static constexpr auto TOB
void fillBadComponents()
const TrackerGeomDet * idToDet(DetId) const override
unsigned int tibModule(const DetId &id) const
unsigned int tecModule(const DetId &id) const
for(Iditer=Id.begin();Iditer!=Id.end();Iditer++)
bool tecIsBackPetal(const DetId &id) const
Definition: DetId.h:17
static constexpr auto TIB
bool tibIsStereo(const DetId &id) const
unsigned int tobModule(const DetId &id) const
double a
Definition: hdecay.h:119
std::pair< ContainerIterator, ContainerIterator > Range
virtual LocalPoint localPosition(float strip) const =0
unsigned int tecPetalNumber(const DetId &id) const
tuple cout
Definition: gather_cfg.py:144
unsigned int tobRod(const DetId &id) const
bool put(const uint32_t &detID, const InputVector &vect)
T x() const
Definition: PV3DBase.h:59
unsigned int tecWheel(const DetId &id) const
static constexpr auto TID
unsigned int encode(const unsigned short &first, const unsigned short &NconsecutiveBadStrips, const unsigned short &flag=0)
unsigned int tobLayer(const DetId &id) const