CMS 3D CMS Logo

SiPixelBadModuleReader.cc
Go to the documentation of this file.
1 // system include files
2 #include <cmath>
3 #include <cstdio>
4 #include <fstream>
5 #include <iomanip>
6 #include <iostream>
7 #include <string>
8 #include <sys/time.h>
9 
10 // user include files
37 
38 // ROOT includes
39 #include "TCanvas.h"
40 #include "TStyle.h"
41 #include "TROOT.h"
42 #include "TFile.h"
43 #include "TTree.h"
44 #include "TBranch.h"
45 #include "TH2F.h"
46 
47 class SiPixelBadModuleReader : public edm::one::EDAnalyzer<edm::one::SharedResources> {
48 public:
49  explicit SiPixelBadModuleReader(const edm::ParameterSet &);
50  ~SiPixelBadModuleReader() override;
51 
52  void analyze(const edm::Event &, const edm::EventSetup &) override;
53 
54 private:
60 
61  const uint32_t printdebug_;
63 
71 };
72 
74  : badModuleToken(esConsumes()),
75  badModuleFromDBToken(esConsumes()),
76  siPixelFedCablingToken(esConsumes()),
77  tkGeomToken(esConsumes()),
78  tkTopoToken(esConsumes()),
79  printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug", 1)),
80  whichRcd(iConfig.getUntrackedParameter<std::string>("RcdName")) {
81  usesResource(TFileService::kSharedResource);
82 }
83 // txtFileName_(iConfig.getUntrackedParameter<std::string>("OutputFile","BadModuleSummary.txt")){}
84 
86 
88  const SiPixelQuality *SiPixelBadModule_ = nullptr;
89  if (whichRcd == "SiPixelQualityRcd") {
90  SiPixelBadModule_ = &iSetup.getData(badModuleToken);
91  } else if (whichRcd == "SiPixelQualityFromDbRcd") {
92  SiPixelBadModule_ = &iSetup.getData(badModuleFromDBToken);
93  } else {
94  throw cms::Exception("LogicalError") << "SiPixelBadModuleReader::analyze, unsupported RcdName value " << whichRcd
95  << ".\n Please check the configuration." << std::endl;
96  }
97 
99  edm::LogInfo("SiPixelBadModuleReader") << "[SiPixelBadModuleReader::analyze] End Reading SiPixelBadModule"
100  << std::endl;
101 
102  const TrackerGeometry *geom = &iSetup.getData(tkGeomToken);
103  const TrackerTopology &ttopo = iSetup.getData(tkTopoToken);
104 
107  fs->make<TH2F>("dead_modules_BPIX_lay1", "Dead modules in BPIX Layer 1", 112, -28., 28., 100, -3.2, 3.2);
109  fs->make<TH2F>("dead_modules_BPIX_lay2", "Dead modules in BPIX Layer 2", 112, -28., 28., 100, -3.2, 3.2);
111  fs->make<TH2F>("dead_modules_BPIX_lay3", "Dead modules in BPIX Layer 3", 112, -28., 28., 100, -3.2, 3.2);
113  fs->make<TH2F>("dead_modules_minusZ_disk1", "Dead modules in FPIX minus Z disk 1", 80, -18., 18., 80, -18., 18.);
115  fs->make<TH2F>("dead_modules_minusZ_disk2", "Dead modules in FPIX minus Z disk 2", 80, -18., 18., 80, -18., 18.);
117  fs->make<TH2F>("dead_modules_plusZ_disk1", "Dead modules in FPIX plus Z disk 1", 80, -18., 18., 80, -18., 18.);
119  fs->make<TH2F>("dead_modules_plusZ_disk2", "Dead modules in BPIX plus Z disk 2", 80, -18, 18., 80, -18., 18.);
120 
121  gStyle->SetPalette(1);
122 
123  std::vector<SiPixelQuality::disabledModuleType> disabledModules = SiPixelBadModule_->getBadComponentList();
124 
125  if (printdebug_) {
126  std::ofstream debugout("BadModuleDebug.txt");
127  debugout << "Values stored in DB, in human readable form: " << std::endl;
128  for (size_t id = 0; id < disabledModules.size(); id++) {
129  SiPixelQuality::disabledModuleType badmodule = disabledModules[id];
130 
132  // errortype "whole" = int 0 in DB //
133  // errortype "tbmA" = int 1 in DB //
134  // errortype "tbmB" = int 2 in DB //
136 
137  std::string errorstring;
138 
139  if (badmodule.errorType == 0)
140  errorstring = "whole";
141  else if (badmodule.errorType == 1)
142  errorstring = "tbmA";
143  else if (badmodule.errorType == 2)
144  errorstring = "tbmB";
145  else if (badmodule.errorType == 3)
146  errorstring = "none";
147 
148  debugout << " " << std::endl;
149  debugout << " " << std::endl; //to make the reading easier
150  debugout << "DetID: " << badmodule.DetID << " and this has an error type of '" << errorstring << "'" << std::endl;
151  debugout << "The bad ROCs are: " << std::endl;
152  for (unsigned short n = 0; n < 16; n++) {
153  unsigned short mask = 1 << n; // 1 << n = 2^{n} using bitwise shift
154  if (badmodule.BadRocs & mask)
155  debugout << n << ", ";
156  }
157  debugout << std::endl;
158  debugout << ttopo.print(badmodule.DetID) << std::endl;
159  const auto &plane = geom->idToDet(badmodule.DetID)->surface();
160  debugout << "phiSpan " << plane.phiSpan().first << "," << plane.phiSpan().second << std::endl;
161  debugout << "rSpan " << plane.rSpan().first << "," << plane.rSpan().second << std::endl;
162  debugout << "zSpan " << plane.zSpan().first << "," << plane.zSpan().second << std::endl;
163  debugout << " " << std::endl;
164  debugout << " " << std::endl; //to make the reading easier
165  }
166  }
167 
168  int nmodules = 0;
169  int nbadmodules = 0;
170  int npartialbad = 0;
171  for (TrackerGeometry::DetContainer::const_iterator it = geom->dets().begin(); it != geom->dets().end(); it++) {
172  if (dynamic_cast<PixelGeomDetUnit const *>((*it)) != nullptr) {
173  DetId detId = (*it)->geographicalId();
174  uint32_t id = detId();
175  nmodules++;
176 
177  const GeomDetUnit *geoUnit = geom->idToDetUnit(detId);
178  const PixelGeomDetUnit *pixDet = dynamic_cast<const PixelGeomDetUnit *>(geoUnit);
179  float detR = pixDet->surface().position().perp();
180  float detZ = pixDet->surface().position().z();
181  float detPhi = pixDet->surface().position().phi();
182  // float detEta = -1.*log(tan(atan2(detR,detZ)/2.));
183  float detX = detR * cos(detPhi);
184  float detY = detR * sin(detPhi);
185 
186  //Histograms in "colz": those with 2 hits are totally fine. Those with 1 are dead. Done this way to visualize where ROCs are
187  //fill histograms for ALL modules
188  if (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel) &&
189  PixelBarrelName(detId).layerName() == 1) {
190  _TH2F_dead_modules_BPIX_lay1->Fill(detZ, detPhi);
191  _TH2F_dead_modules_BPIX_lay1->SetOption("colz");
192  }
193 
194  if (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel) &&
195  PixelBarrelName(detId).layerName() == 2) {
196  _TH2F_dead_modules_BPIX_lay2->Fill(detZ, detPhi);
197  _TH2F_dead_modules_BPIX_lay2->SetOption("colz");
198  }
199 
200  if (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel) &&
201  PixelBarrelName(detId).layerName() == 3) {
202  _TH2F_dead_modules_BPIX_lay3->Fill(detZ, detPhi);
203  _TH2F_dead_modules_BPIX_lay3->SetOption("colz");
204  }
205  if (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap) &&
206  PixelEndcapName(detId).diskName() == 1 &&
208  PixelEndcapName(detId).halfCylinder() == 1)) { //mI = 2, mO = 1
209  _TH2F_dead_modules_FPIX_minusZ_disk1->Fill(detX, detY);
210  _TH2F_dead_modules_FPIX_minusZ_disk1->SetOption("colz");
211  }
212 
213  if (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap) &&
214  PixelEndcapName(detId).diskName() == 2 &&
216  PixelEndcapName(detId).halfCylinder() == 1)) { //mI = 2, mO = 1
217  _TH2F_dead_modules_FPIX_minusZ_disk2->Fill(detX, detY);
218  _TH2F_dead_modules_FPIX_minusZ_disk2->SetOption("colz");
219  }
220 
221  if (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap) &&
222  PixelEndcapName(detId).diskName() == 1 &&
224  PixelEndcapName(detId).halfCylinder() == 4)) { //p0 = 3, pI = 4
225  _TH2F_dead_modules_FPIX_plusZ_disk1->Fill(detX, detY);
226  _TH2F_dead_modules_FPIX_plusZ_disk1->SetOption("colz");
227  }
228 
229  if (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap) &&
230  PixelEndcapName(detId).diskName() == 2 &&
232  PixelEndcapName(detId).halfCylinder() == 4)) { //p0 = 3, pI = 4
233  _TH2F_dead_modules_FPIX_plusZ_disk2->Fill(detX, detY);
234  _TH2F_dead_modules_FPIX_plusZ_disk2->SetOption("colz");
235  }
236 
237  //fill histograms for when all ROCs are OK
238  if (SiPixelBadModule_->IsModuleBad(id) == false && SiPixelBadModule_->getBadRocs(id) == 0) {
239  if (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel) &&
240  PixelBarrelName(detId).layerName() == 1) {
241  _TH2F_dead_modules_BPIX_lay1->Fill(detZ, detPhi);
242  _TH2F_dead_modules_BPIX_lay1->SetOption("colz");
243  }
244 
245  if (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel) &&
246  PixelBarrelName(detId).layerName() == 2) {
247  _TH2F_dead_modules_BPIX_lay2->Fill(detZ, detPhi);
248  _TH2F_dead_modules_BPIX_lay2->SetOption("colz");
249  }
250 
251  if (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel) &&
252  PixelBarrelName(detId).layerName() == 3) {
253  _TH2F_dead_modules_BPIX_lay3->Fill(detZ, detPhi);
254  _TH2F_dead_modules_BPIX_lay3->SetOption("colz");
255  }
256  if (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap) &&
257  PixelEndcapName(detId).diskName() == 1 &&
259  PixelEndcapName(detId).halfCylinder() == 1)) { //mI = 2, mO = 1
260  _TH2F_dead_modules_FPIX_minusZ_disk1->Fill(detX, detY);
261  _TH2F_dead_modules_FPIX_minusZ_disk1->SetOption("colz");
262  }
263 
264  if (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap) &&
265  PixelEndcapName(detId).diskName() == 2 &&
267  PixelEndcapName(detId).halfCylinder() == 1)) { //mI = 2, mO = 1
268  _TH2F_dead_modules_FPIX_minusZ_disk2->Fill(detX, detY);
269  _TH2F_dead_modules_FPIX_minusZ_disk2->SetOption("colz");
270  }
271 
272  if (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap) &&
273  PixelEndcapName(detId).diskName() == 1 &&
275  PixelEndcapName(detId).halfCylinder() == 4)) { //p0 = 3, pI = 4
276  _TH2F_dead_modules_FPIX_plusZ_disk1->Fill(detX, detY);
277  _TH2F_dead_modules_FPIX_plusZ_disk1->SetOption("colz");
278  }
279 
280  if (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap) &&
281  PixelEndcapName(detId).diskName() == 2 &&
283  PixelEndcapName(detId).halfCylinder() == 4)) { //p0 = 3, pI = 4
284  _TH2F_dead_modules_FPIX_plusZ_disk2->Fill(detX, detY);
285  _TH2F_dead_modules_FPIX_plusZ_disk2->SetOption("colz");
286  }
287  }
288 
289  //count number of completely dead modules
290  if (SiPixelBadModule_->IsModuleBad(id) == true) {
291  nbadmodules++;
292  }
293 
294  //count number of partially dead modules
295  if (SiPixelBadModule_->IsModuleBad(id) == false && SiPixelBadModule_->getBadRocs(id) != 0) {
296  npartialbad++;
297  }
298  }
299  }
300 
301  std::ofstream txtout("BadModuleSummary.txt");
302  txtout << "The total number of modules is: " << nmodules << std::endl;
303  txtout << "The total number of completely dead modules is: " << nbadmodules << std::endl;
304  txtout << "The total number of partially dead modules is: " << npartialbad << std::endl;
305 }
static const std::string kSharedResource
Definition: TFileService.h:76
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T perp() const
Definition: PV3DBase.h:69
~SiPixelBadModuleReader() override
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
T z() const
Definition: PV3DBase.h:61
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
std::string print(DetId detid) const
const edm::ESGetToken< SiPixelQuality, SiPixelQualityFromDbRcd > badModuleFromDBToken
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
const edm::ESGetToken< SiPixelFedCablingMap, SiPixelFedCablingMapRcd > siPixelFedCablingToken
bool IsModuleBad(const uint32_t &detid) const
const edm::ESGetToken< SiPixelQuality, SiPixelQualityRcd > badModuleToken
constexpr uint32_t mask
Definition: gpuClustering.h:26
void analyze(const edm::Event &, const edm::EventSetup &) override
const std::vector< disabledModuleType > getBadComponentList() const
int diskName() const
disk id
HalfCylinder halfCylinder() const
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
Log< level::Info, false > LogInfo
Definition: DetId.h:17
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tkTopoToken
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
const PositionType & position() const
int layerName() const
layer id
short getBadRocs(const uint32_t &detid) const
SiPixelBadModuleReader(const edm::ParameterSet &)