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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
|
/*! \file SiPixelInformationExtractor.cc
* \brief This class represents ...
*
* (Documentation under development)
*
*/
#include "DQM/SiPixelCommon/interface/SiPixelFolderOrganizer.h"
#include "DQM/SiPixelMonitorClient/interface/ANSIColors.h"
#include "DQM/SiPixelMonitorClient/interface/SiPixelEDAClient.h"
#include "DQM/SiPixelMonitorClient/interface/SiPixelInformationExtractor.h"
#include "DQM/SiPixelMonitorClient/interface/SiPixelUtility.h"
#include "DQMServices/Core/interface/DQMStore.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/FileInPath.h"
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/GeometrySurface/interface/Surface.h"
#include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
#include "DataFormats/SiPixelDetId/interface/PixelBarrelNameUpgrade.h"
#include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
#include "DataFormats/SiPixelDetId/interface/PixelEndcapNameUpgrade.h"
#include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
#include "CondFormats/SiPixelObjects/interface/DetectorIndex.h"
#include "CondFormats/SiPixelObjects/interface/SiPixelFrameConverter.h"
#include "Geometry/CommonTopologies/interface/PixelTopology.h"
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
#include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
#include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
#include "Rtypes.h"
#include "TAxis.h"
#include "TClass.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TImage.h"
#include "TImageDump.h"
#include "TPad.h"
#include "TPaveLabel.h"
#include "TPaveText.h"
#include "TProfile.h"
#include "TROOT.h"
#include "TRandom.h"
#include "TStopwatch.h"
#include "TString.h"
#include "TStyle.h"
#include "TSystem.h"
#include "TText.h"
#include <cmath>
#include <iostream>
#include <map>
#include <cstdlib> // for free() - Root can allocate with malloc() - sigh...
using namespace std;
using namespace edm;
//------------------------------------------------------------------------------
/*! \brief Constructor of the SiPixelInformationExtractor class.
*
*/
SiPixelInformationExtractor::SiPixelInformationExtractor(bool offlineXMLfile) : offlineXMLfile_(offlineXMLfile) {
edm::LogInfo("SiPixelInformationExtractor") << " Creating SiPixelInformationExtractor "
<< "\n";
readReference_ = false;
}
//------------------------------------------------------------------------------
/*! \brief Destructor of the SiPixelInformationExtractor class.
*
*/
SiPixelInformationExtractor::~SiPixelInformationExtractor() {
edm::LogInfo("SiPixelInformationExtractor") << " Deleting SiPixelInformationExtractor "
<< "\n";
}
//------------------------------------------------------------------------------
/*! \brief Read Configuration File
*
*/
void SiPixelInformationExtractor::readConfiguration() {}
//============================================================================================================
// -- Return type of ME
//
std::string SiPixelInformationExtractor::getMEType(MonitorElement *theMe) {
string qtype = theMe->getRootObject()->IsA()->GetName();
if (qtype.find("TH1") != string::npos) {
return "TH1";
} else if (qtype.find("TH2") != string::npos) {
return "TH2";
} else if (qtype.find("TH3") != string::npos) {
return "TH3";
}
return "TH1";
}
//------------------------------------------------------------------------------
/*! \brief (Documentation under construction).
*
* This method
*/
void SiPixelInformationExtractor::getItemList(const multimap<string, string> &req_map,
string item_name,
vector<string> &items) {
items.clear();
for (multimap<string, string>::const_iterator it = req_map.begin(); it != req_map.end(); it++) {
if (it->first == item_name) {
items.push_back(it->second);
}
}
}
//------------------------------------------------------------------------------
/*! \brief (Documentation under construction).
*
* This method
*/
bool SiPixelInformationExtractor::hasItem(multimap<string, string> &req_map, string item_name) {
multimap<string, string>::iterator pos = req_map.find(item_name);
if (pos != req_map.end())
return true;
return false;
}
//------------------------------------------------------------------------------
/*! \brief (Documentation under construction).
*
* This method
*/
std::string SiPixelInformationExtractor::getItemValue(const std::multimap<std::string, std::string> &req_map,
std::string item_name) {
std::multimap<std::string, std::string>::const_iterator pos = req_map.find(item_name);
std::string value = " ";
if (pos != req_map.end()) {
value = pos->second;
}
return value;
}
std::string SiPixelInformationExtractor::getItemValue(std::multimap<std::string, std::string> &req_map,
std::string item_name) {
std::multimap<std::string, std::string>::iterator pos = req_map.find(item_name);
std::string value = " ";
if (pos != req_map.end()) {
value = pos->second;
}
return value;
}
//
// -- Get color name from status
//
void SiPixelInformationExtractor::selectColor(string &col, int status) {
if (status == dqm::qstatus::STATUS_OK)
col = "#00ff00";
else if (status == dqm::qstatus::WARNING)
col = "#ffff00";
else if (status == dqm::qstatus::ERROR)
col = "#ff0000";
else if (status == dqm::qstatus::OTHER)
col = "#ffa500";
else
col = "#0000ff";
}
//
// -- Get Image name from ME
//
void SiPixelInformationExtractor::selectColor(string &col, vector<QReport *> &reports) {
int istat = 999;
int status = 0;
for (vector<QReport *>::const_iterator it = reports.begin(); it != reports.end(); it++) {
status = (*it)->getStatus();
if (status > istat)
istat = status;
}
selectColor(col, status);
}
//
// -- Get Image name from status
//
void SiPixelInformationExtractor::selectImage(string &name, int status) {
if (status == dqm::qstatus::STATUS_OK)
name = "images/LI_green.gif";
else if (status == dqm::qstatus::WARNING)
name = "images/LI_yellow.gif";
else if (status == dqm::qstatus::ERROR)
name = "images/LI_red.gif";
else if (status == dqm::qstatus::OTHER)
name = "images/LI_orange.gif";
else
name = "images/LI_blue.gif";
}
//
// -- Get Image name from ME
//
void SiPixelInformationExtractor::selectImage(string &name, vector<QReport *> &reports) {
int istat = 999;
int status = 0;
for (vector<QReport *>::const_iterator it = reports.begin(); it != reports.end(); it++) {
status = (*it)->getStatus();
if (status > istat)
istat = status;
}
selectImage(name, status);
}
//------------------------------------------------------------------------------
/*! \brief (Documentation under construction).
*
*/
void SiPixelInformationExtractor::computeStatus(MonitorElement *theME, double &colorValue, pair<double, double> &norm) {
double normalizationX = 1;
double normalizationY = 1;
double meanX = 0;
double meanY = 0;
colorValue = 0;
pair<double, double> normX;
pair<double, double> normY;
string theMEType = getMEType(theME);
if (theMEType.find("TH1") != string::npos) {
meanX = (double)theME->getMean();
getNormalization(theME, normX, "TH1");
normalizationX = fabs(normX.second - normX.first);
if (normalizationX == 0) {
normalizationX = 1.E-20;
}
colorValue = meanX / normalizationX;
norm.first = normX.first;
norm.second = normX.second;
}
if (theMEType.find("TH2") != string::npos) {
meanX = (double)theME->getMean(1);
meanY = (double)theME->getMean(2);
getNormalization2D(theME, normX, normY, "TH2");
normalizationX = fabs(normX.second - normX.first);
normalizationY = fabs(normY.second - normY.first);
if (normalizationX == 0) {
normalizationX = 1.E-20;
}
if (normalizationY == 0) {
normalizationY = 1.E-20;
}
double cVX = meanX / normalizationX;
double cVY = meanY / normalizationY;
colorValue = sqrt(cVX * cVX + cVY * cVY);
if (normalizationX >= normalizationY) {
norm.first = normX.first;
norm.second = normX.second;
} else {
norm.first = normY.first;
norm.second = normY.second;
}
}
return;
}
//------------------------------------------------------------------------------
/*! \brief (Documentation under construction).
*
*/
void SiPixelInformationExtractor::getNormalization(MonitorElement *theME,
pair<double, double> &norm,
std::string theMEType) {
double normLow = 0;
double normHigh = 0;
if (theMEType.find("TH1") != string::npos) {
normHigh = (double)theME->getNbinsX();
norm.first = normLow;
norm.second = normHigh;
}
}
//------------------------------------------------------------------------------
/*! \brief (Documentation under construction).
*
*/
void SiPixelInformationExtractor::getNormalization2D(MonitorElement *theME,
pair<double, double> &normX,
pair<double, double> &normY,
std::string theMEType) {
double normLow = 0;
double normHigh = 0;
if (theMEType.find("TH2") != string::npos) {
normHigh = (double)theME->getNbinsX();
normX.first = normLow;
normX.second = normHigh;
normHigh = (double)theME->getNbinsY();
normY.first = normLow;
normY.second = normHigh;
}
}
//------------------------------------------------------------------------------
/*! \brief (Documentation under construction).
*
* Given a pointer to ME returns the associated detId
*/
int SiPixelInformationExtractor::getDetId(MonitorElement *mE) {
const string &mEName = mE->getName();
int detId = 0;
if (mEName.find("_3") != string::npos) {
string detIdString = mEName.substr((mEName.find_last_of('_')) + 1, 9);
std::istringstream isst;
isst.str(detIdString);
isst >> detId;
}
return detId;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
void SiPixelInformationExtractor::bookNoisyPixels(DQMStore::IBooker &iBooker, float noiseRate_, bool Tier0Flag) {
// std::cout<<"BOOK NOISY PIXEL MEs!"<<std::endl;
iBooker.cd();
if (noiseRate_ >= 0.) {
iBooker.setCurrentFolder("Pixel/Barrel");
EventRateBarrelPixels = iBooker.book1D("barrelEventRate", "Digi event rate for all Barrel pixels", 1000, 0., 0.01);
EventRateBarrelPixels->setAxisTitle("Event Rate", 1);
EventRateBarrelPixels->setAxisTitle("Number of Pixels", 2);
iBooker.cd();
iBooker.setCurrentFolder("Pixel/Endcap");
EventRateEndcapPixels = iBooker.book1D("endcapEventRate", "Digi event rate for all Endcap pixels", 1000, 0., 0.01);
EventRateEndcapPixels->setAxisTitle("Event Rate", 1);
EventRateEndcapPixels->setAxisTitle("Number of Pixels", 2);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void SiPixelInformationExtractor::findNoisyPixels(DQMStore::IBooker &iBooker,
DQMStore::IGetter &iGetter,
bool init,
float noiseRate_,
int noiseRateDenominator_,
const SiPixelFedCablingMap *theCablingMap) {
if (init) {
endOfModules_ = false;
nevents_ = noiseRateDenominator_;
if (nevents_ == -1) {
iBooker.cd();
iGetter.cd();
iBooker.setCurrentFolder("Pixel/EventInfo");
iGetter.setCurrentFolder("Pixel/EventInfo");
nevents_ = (iGetter.get("Pixel/EventInfo/processedEvents"))->getIntValue();
}
iBooker.cd();
iGetter.cd();
myfile_.open("NoisyPixelList.txt", ios::app);
myfile_ << "Noise summary, ran over " << nevents_ << " events, threshold was set to " << noiseRate_ << std::endl;
}
string currDir = iBooker.pwd();
string dname = currDir.substr(currDir.find_last_of('/') + 1);
if (dname.find("Module_") != string::npos) {
vector<string> meVec = iGetter.getMEs();
for (vector<string>::const_iterator it = meVec.begin(); it != meVec.end(); it++) {
string full_path = currDir + "/" + (*it);
if (full_path.find("hitmap_siPixelDigis") != string::npos) {
MonitorElement *me = iGetter.get(full_path);
if (!me)
continue;
int detid = getDetId(me);
int pixcol = -1;
int pixrow = -1;
std::vector<std::pair<std::pair<int, int>, float>> noisyPixelsInModule;
TH2F *hothisto = me->getTH2F();
if (hothisto) {
for (int i = 1; i != hothisto->GetNbinsX() + 1; i++) {
for (int j = 1; j != hothisto->GetNbinsY() + 1; j++) {
float value = (hothisto->GetBinContent(i, j)) / float(nevents_);
if (me->getPathname().find("Barrel") != string::npos) {
EventRateBarrelPixels = iGetter.get("Pixel/Barrel/barrelEventRate");
if (EventRateBarrelPixels)
EventRateBarrelPixels->Fill(value);
} else if (me->getPathname().find("Endcap") != string::npos) {
EventRateEndcapPixels = iGetter.get("Pixel/Endcap/endcapEventRate");
if (EventRateEndcapPixels)
EventRateEndcapPixels->Fill(value);
}
if (value > noiseRate_) {
pixcol = i - 1;
pixrow = j - 1;
std::pair<int, int> address(pixcol, pixrow);
std::pair<std::pair<int, int>, float> PixelStats(address, value);
noisyPixelsInModule.push_back(PixelStats);
}
}
}
}
noisyDetIds_[detid] = noisyPixelsInModule;
}
}
}
vector<string> subDirVec = iGetter.getSubdirs();
for (vector<string>::const_iterator ic = subDirVec.begin(); ic != subDirVec.end(); ic++) {
if ((*ic).find("AdditionalPixelErrors") != string::npos)
continue;
iGetter.cd(*ic);
iBooker.cd(*ic);
init = false;
findNoisyPixels(iBooker, iGetter, init, noiseRate_, noiseRateDenominator_, theCablingMap);
iBooker.goUp();
iGetter.setCurrentFolder(iBooker.pwd());
}
if (iBooker.pwd().find("EventInfo") != string::npos)
endOfModules_ = true;
if (!endOfModules_)
return;
if (currDir == "Pixel/EventInfo/reportSummaryContents") {
std::vector<std::pair<sipixelobjects::DetectorIndex, double>> pixelvec;
std::map<uint32_t, int> myfedmap;
std::map<uint32_t, std::string> mynamemap;
int realfedID = -1;
int n_noisyrocs_all = 0;
int n_noisyrocs_barrel = 0;
int n_noisyrocs_endcap = 0;
int n_verynoisyrocs_all = 0;
int n_verynoisyrocs_barrel = 0;
int n_verynoisyrocs_endcap = 0;
for (int fid = 0; fid < 40; fid++) {
for (std::map<uint32_t, std::vector<std::pair<std::pair<int, int>, float>>>::const_iterator it =
noisyDetIds_.begin();
it != noisyDetIds_.end();
it++) {
uint32_t detid = (*it).first;
std::vector<std::pair<std::pair<int, int>, float>> noisyPixels = (*it).second;
// now convert into online conventions:
for (int fedid = 0; fedid <= 40; ++fedid) {
SiPixelFrameConverter converter(theCablingMap, fedid);
uint32_t newDetId = detid;
if (converter.hasDetUnit(newDetId)) {
realfedID = fedid;
break;
}
}
if (fid == realfedID) {
if (realfedID == -1)
continue;
DetId detId(detid);
uint32_t detSubId = detId.subdetId();
std::string outputname;
bool HalfModule = false;
if (detSubId == 2) { // FPIX
PixelEndcapName nameworker(detid);
outputname = nameworker.name();
} else if (detSubId == 1) { // BPIX
PixelBarrelName nameworker(detid);
outputname = nameworker.name();
HalfModule = nameworker.isHalfModule();
} else {
continue;
}
std::map<int, int> myrocmap;
myfedmap[detid] = realfedID;
mynamemap[detid] = outputname;
for (std::vector<std::pair<std::pair<int, int>, float>>::const_iterator pxl = noisyPixels.begin();
pxl != noisyPixels.end();
pxl++) {
std::pair<int, int> offlineaddress = (*pxl).first;
float Noise_frac = (*pxl).second;
int offlineColumn = offlineaddress.first;
int offlineRow = offlineaddress.second;
sipixelobjects::ElectronicIndex cabling;
SiPixelFrameConverter formatter(theCablingMap, realfedID);
sipixelobjects::DetectorIndex detector = {detid, offlineRow, offlineColumn};
formatter.toCabling(cabling, detector);
// cabling should now contain cabling.roc and cabling.dcol and
// cabling.pxid however, the coordinates now need to be converted
// from dcl,pxid to the row,col coordinates used in the calibration
// info
sipixelobjects::LocalPixel::DcolPxid loc;
loc.dcol = cabling.dcol;
loc.pxid = cabling.pxid;
sipixelobjects::LocalPixel locpixel(loc);
assert(realfedID >= 0);
assert(cabling.link >= 0);
assert(cabling.roc >= 0);
sipixelobjects::CablingPathToDetUnit path = {static_cast<unsigned int>(realfedID),
static_cast<unsigned int>(cabling.link),
static_cast<unsigned int>(cabling.roc)};
const sipixelobjects::PixelROC *theRoc = theCablingMap->findItem(path);
// END of FIX
int onlineColumn = locpixel.rocCol();
int onlineRow = locpixel.rocRow();
myrocmap[(theRoc->idInDetUnit())]++;
// ROC numbers in the barrel go from 8 to 15 instead of 0 to 7 in
// half modules. This is a fix to get the roc number, and add 8 to
// it if: it's a Barrel module AND on the minus side AND a Half
// module
int rocnumber = -1;
if ((detSubId == 1) && (outputname.find("mO") != string::npos || outputname.find("mI") != string::npos) &&
(HalfModule)) {
rocnumber = theRoc->idInDetUnit() + 8;
} else {
rocnumber = theRoc->idInDetUnit();
}
myfile_ << "NAME: " << outputname << " , DETID: " << detid << " , OFFLINE: col,row: " << offlineColumn
<< "," << offlineRow << " \t , ONLINE: roc,col,row: " << rocnumber << "," << onlineColumn << ","
<< onlineRow << " \t , fed,dcol,pixid,link: " << realfedID << "," << loc.dcol << "," << loc.pxid
<< "," << cabling.link << ", Noise fraction: " << Noise_frac << std::endl;
}
for (std::map<int, int>::const_iterator nrc = myrocmap.begin(); nrc != myrocmap.end(); nrc++) {
if ((*nrc).second > 0) {
n_noisyrocs_all++;
if (detSubId == 2) {
n_noisyrocs_endcap++;
} else if (detSubId == 1) {
n_noisyrocs_barrel++;
}
}
if ((*nrc).second > 40) {
n_verynoisyrocs_all++;
if (detSubId == 2) {
n_verynoisyrocs_endcap++;
} else if (detSubId == 1) {
n_verynoisyrocs_barrel++;
}
}
}
}
}
}
myfile_ << "There are " << n_noisyrocs_all
<< " noisy ROCs (ROCs with at least 1 noisy pixel) in the entire "
"detector. "
<< n_noisyrocs_endcap << " are in the FPIX and " << n_noisyrocs_barrel << " are in the BPIX. " << endl;
myfile_ << "There are " << n_verynoisyrocs_all
<< " highly noisy ROCs (ROCs with at least 10% of all pixels "
"passing the noise threshold) in the entire detector. "
<< n_verynoisyrocs_endcap << " are in the FPIX and " << n_verynoisyrocs_barrel << " are in the BPIX. "
<< endl;
}
myfile_.close();
return;
}
|