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