File indexing completed on 2025-03-13 02:31:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 #include "DQM/SiPixelMonitorRawData/interface/SiPixelRawDataErrorSource.h"
0026
0027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0028 #include "FWCore/ServiceRegistry/interface/Service.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030
0031 #include "DQM/SiPixelCommon/interface/SiPixelFolderOrganizer.h"
0032 #include "DQM/SiPixelCommon/interface/SiPixelHistogramId.h"
0033 #include "DQMServices/Core/interface/DQMStore.h"
0034
0035
0036 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
0037 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0038
0039 #include "DataFormats/DetId/interface/DetId.h"
0040 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0041 #include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
0042 #include "DataFormats/SiPixelDetId/interface/PixelBarrelNameUpgrade.h"
0043 #include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
0044 #include "DataFormats/SiPixelDetId/interface/PixelEndcapNameUpgrade.h"
0045 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0046
0047 #include <cstdlib>
0048 #include <string>
0049
0050 using namespace std;
0051 using namespace edm;
0052
0053 SiPixelRawDataErrorSource::SiPixelRawDataErrorSource(const edm::ParameterSet &iConfig)
0054 : conf_(iConfig),
0055 src_(consumes<DetSetVector<SiPixelRawDataError>>(conf_.getParameter<edm::InputTag>("src"))),
0056 saveFile(conf_.getUntrackedParameter<bool>("saveFile", false)),
0057 isPIB(conf_.getUntrackedParameter<bool>("isPIB", false)),
0058 slowDown(conf_.getUntrackedParameter<bool>("slowDown", false)),
0059 reducedSet(conf_.getUntrackedParameter<bool>("reducedSet", false)),
0060 modOn(conf_.getUntrackedParameter<bool>("modOn", true)),
0061 ladOn(conf_.getUntrackedParameter<bool>("ladOn", false)),
0062 bladeOn(conf_.getUntrackedParameter<bool>("bladeOn", false)),
0063 isUpgrade(conf_.getUntrackedParameter<bool>("isUpgrade", false)) {
0064 firstRun = true;
0065 LogInfo("PixelDQM") << "SiPixelRawDataErrorSource::SiPixelRawDataErrorSource:"
0066 " Got DQM BackEnd interface"
0067 << endl;
0068 topFolderName_ = conf_.getParameter<std::string>("TopFolderName");
0069 inputSourceToken_ = consumes<FEDRawDataCollection>(conf_.getUntrackedParameter<string>("inputSource", "source"));
0070 trackerTopoTokenBeginRun_ = esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>();
0071 trackerGeomTokenBeginRun_ = esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>();
0072 }
0073
0074 SiPixelRawDataErrorSource::~SiPixelRawDataErrorSource() {
0075
0076
0077 LogInfo("PixelDQM") << "SiPixelRawDataErrorSource::~SiPixelRawDataErrorSource: Destructor" << endl;
0078 }
0079
0080 void SiPixelRawDataErrorSource::dqmBeginRun(const edm::Run &r, const edm::EventSetup &iSetup) {
0081 LogInfo("PixelDQM") << " SiPixelRawDataErrorSource::beginRun - Initialisation ... " << std::endl;
0082 LogInfo("PixelDQM") << "Mod/Lad/Blade " << modOn << "/" << ladOn << "/" << bladeOn << std::endl;
0083
0084 if (firstRun) {
0085 eventNo = 0;
0086
0087 firstRun = false;
0088 }
0089
0090
0091 buildStructure(iSetup);
0092 }
0093
0094 void SiPixelRawDataErrorSource::bookHistograms(DQMStore::IBooker &iBooker,
0095 edm::Run const &,
0096 edm::EventSetup const &iSetup) {
0097
0098 bookMEs(iBooker);
0099 }
0100
0101
0102
0103
0104 void SiPixelRawDataErrorSource::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0105 eventNo++;
0106
0107 if (eventNo == 1) {
0108
0109 edm::Handle<FEDRawDataCollection> rawDataHandle;
0110 iEvent.getByToken(inputSourceToken_, rawDataHandle);
0111 if (!rawDataHandle.isValid()) {
0112 edm::LogInfo("SiPixelRawDataErrorSource") << "inputsource is empty";
0113 } else {
0114 const FEDRawDataCollection &rawDataCollection = *rawDataHandle;
0115 for (int i = 0; i != 40; i++) {
0116 if (rawDataCollection.FEDData(i).size() && rawDataCollection.FEDData(i).data())
0117 fedcounter->setBinContent(i + 1, 1);
0118 }
0119 }
0120 }
0121
0122 edm::Handle<DetSetVector<SiPixelRawDataError>> input;
0123 iEvent.getByToken(src_, input);
0124 if (!input.isValid())
0125 return;
0126
0127 int lumiSection = (int)iEvent.luminosityBlock();
0128
0129 int nEventBPIXModuleErrors = 0;
0130 int nEventFPIXModuleErrors = 0;
0131 int nEventBPIXFEDErrors = 0;
0132 int nEventFPIXFEDErrors = 0;
0133 int nErrors = 0;
0134
0135 std::map<uint32_t, SiPixelRawDataErrorModule *>::iterator struct_iter;
0136 std::map<uint32_t, SiPixelRawDataErrorModule *>::iterator struct_iter2;
0137 for (struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++) {
0138 int numberOfModuleErrors = (*struct_iter).second->fill(*input, &meMapFEDs_, modOn, ladOn, bladeOn);
0139 if (DetId((*struct_iter).first).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel))
0140 nEventBPIXModuleErrors = nEventBPIXModuleErrors + numberOfModuleErrors;
0141 if (DetId((*struct_iter).first).subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap))
0142 nEventFPIXModuleErrors = nEventFPIXModuleErrors + numberOfModuleErrors;
0143
0144
0145 nErrors = nErrors + numberOfModuleErrors;
0146
0147 }
0148 for (struct_iter2 = theFEDStructure.begin(); struct_iter2 != theFEDStructure.end(); struct_iter2++) {
0149 int numberOfFEDErrors = (*struct_iter2).second->fillFED(*input, &meMapFEDs_);
0150 if ((*struct_iter2).first <= 31)
0151 nEventBPIXFEDErrors = nEventBPIXFEDErrors + numberOfFEDErrors;
0152
0153 if ((*struct_iter2).first >= 32 && (*struct_iter2).first <= 39)
0154 nEventFPIXFEDErrors = nEventFPIXFEDErrors + numberOfFEDErrors;
0155
0156
0157 nErrors = nErrors + numberOfFEDErrors;
0158
0159 }
0160 if (byLumiErrors) {
0161 byLumiErrors->setBinContent(0, eventNo);
0162
0163
0164 if (nEventBPIXModuleErrors + nEventBPIXFEDErrors > 0)
0165 byLumiErrors->Fill(0, 1.);
0166 if (nEventFPIXModuleErrors + nEventFPIXFEDErrors > 0)
0167 byLumiErrors->Fill(1, 1.);
0168
0169
0170
0171 }
0172
0173
0174 if (errorRate)
0175 errorRate->Fill(lumiSection, nErrors);
0176
0177
0178 if (slowDown)
0179 usleep(100000);
0180 }
0181
0182
0183
0184
0185 void SiPixelRawDataErrorSource::buildStructure(const edm::EventSetup &iSetup) {
0186 LogInfo("PixelDQM") << " SiPixelRawDataErrorSource::buildStructure";
0187
0188 edm::ESHandle<TrackerGeometry> pDD = iSetup.getHandle(trackerGeomTokenBeginRun_);
0189
0190 LogVerbatim("PixelDQM") << " *** Geometry node for TrackerGeom is " << &(*pDD) << std::endl;
0191 LogVerbatim("PixelDQM") << " *** I have " << pDD->detsPXB().size() << " barrel pixel detectors" << std::endl;
0192 LogVerbatim("PixelDQM") << " *** I have " << pDD->detsPXF().size() << " endcap pixel detectors" << std::endl;
0193
0194
0195
0196 for (TrackerGeometry::DetContainer::const_iterator it = pDD->detsPXB().begin(); it != pDD->detsPXB().end(); it++) {
0197 const GeomDetUnit *geoUnit = dynamic_cast<const GeomDetUnit *>(*it);
0198
0199 if (geoUnit == nullptr) {
0200 LogError("PixelDQM") << "Pixel GeomDet is not a GeomDetUnit!" << std::endl;
0201 continue;
0202 }
0203 const PixelGeomDetUnit *pixDet = dynamic_cast<const PixelGeomDetUnit *>(geoUnit);
0204 int nrows = (pixDet->specificTopology()).nrows();
0205 int ncols = (pixDet->specificTopology()).ncolumns();
0206
0207 if (isPIB)
0208 continue;
0209 DetId detId = (*it)->geographicalId();
0210 LogDebug("PixelDQM") << " ---> Adding Barrel Module " << detId.rawId() << endl;
0211 uint32_t id = detId();
0212 SiPixelRawDataErrorModule *theModule = new SiPixelRawDataErrorModule(id, ncols, nrows);
0213 thePixelStructure.insert(pair<uint32_t, SiPixelRawDataErrorModule *>(id, theModule));
0214 }
0215
0216 for (TrackerGeometry::DetContainer::const_iterator it = pDD->detsPXF().begin(); it != pDD->detsPXF().end(); it++) {
0217 const GeomDetUnit *geoUnit = dynamic_cast<const GeomDetUnit *>(*it);
0218
0219 if (geoUnit == nullptr)
0220 LogError("PixelDQM") << "Pixel GeomDet is not a GeomDetUnit!" << std::endl;
0221 const PixelGeomDetUnit *pixDet = dynamic_cast<const PixelGeomDetUnit *>(geoUnit);
0222 int nrows = (pixDet->specificTopology()).nrows();
0223 int ncols = (pixDet->specificTopology()).ncolumns();
0224
0225 DetId detId = (*it)->geographicalId();
0226 LogDebug("PixelDQM") << " ---> Adding Endcap Module " << detId.rawId() << endl;
0227 uint32_t id = detId();
0228 SiPixelRawDataErrorModule *theModule = new SiPixelRawDataErrorModule(id, ncols, nrows);
0229 thePixelStructure.insert(pair<uint32_t, SiPixelRawDataErrorModule *>(id, theModule));
0230 }
0231
0232 LogDebug("PixelDQM") << " ---> Adding Module for Additional Errors " << endl;
0233 pair<int, int> fedIds(FEDNumbering::MINSiPixelFEDID, FEDNumbering::MAXSiPixelFEDID);
0234
0235 fedIds.first = 0;
0236 fedIds.second = 39;
0237
0238 for (int fedId = fedIds.first; fedId <= fedIds.second; fedId++) {
0239
0240 uint32_t id = static_cast<uint32_t>(fedId);
0241 SiPixelRawDataErrorModule *theModule = new SiPixelRawDataErrorModule(id);
0242 theFEDStructure.insert(pair<uint32_t, SiPixelRawDataErrorModule *>(id, theModule));
0243 }
0244
0245 LogInfo("PixelDQM") << " *** Pixel Structure Size " << thePixelStructure.size() << endl;
0246 }
0247
0248
0249
0250 void SiPixelRawDataErrorSource::bookMEs(DQMStore::IBooker &iBooker) {
0251 iBooker.setCurrentFolder(topFolderName_ + "/EventInfo/DAQContents");
0252 char title0[80];
0253 sprintf(title0, "FED isPresent;FED ID;isPresent");
0254 fedcounter = iBooker.book1D("fedcounter", title0, 40, -0.5, 39.5);
0255 iBooker.setCurrentFolder(topFolderName_ + "/AdditionalPixelErrors");
0256 char title[80];
0257 sprintf(title, "By-LumiSection Error counters");
0258 {
0259 auto scope = DQMStore::IBooker::UseLumiScope(iBooker);
0260 byLumiErrors = iBooker.book1D("byLumiErrors", title, 2, 0., 2.);
0261 }
0262 char title1[80];
0263 sprintf(title1, "Errors per LumiSection;LumiSection;NErrors");
0264 errorRate = iBooker.book1D("errorRate", title1, 5000, 0., 5000.);
0265
0266 std::map<uint32_t, SiPixelRawDataErrorModule *>::iterator struct_iter;
0267 std::map<uint32_t, SiPixelRawDataErrorModule *>::iterator struct_iter2;
0268
0269 SiPixelFolderOrganizer theSiPixelFolder(false);
0270
0271 for (struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++) {
0272
0273
0274 if (modOn) {
0275 if (!theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 0, isUpgrade)) {
0276
0277
0278 if (!isPIB)
0279 throw cms::Exception("LogicError") << "[SiPixelRawDataErrorSource::bookMEs] Creation of DQM folder "
0280 "failed";
0281 }
0282 }
0283
0284 if (ladOn) {
0285 if (!theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 1, isUpgrade)) {
0286 LogDebug("PixelDQM") << "PROBLEM WITH LADDER-FOLDER\n";
0287 }
0288 }
0289
0290 if (bladeOn) {
0291 if (!theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 4, isUpgrade)) {
0292 LogDebug("PixelDQM") << "PROBLEM WITH BLADE-FOLDER\n";
0293 }
0294 }
0295
0296 }
0297
0298 for (struct_iter2 = theFEDStructure.begin(); struct_iter2 != theFEDStructure.end(); struct_iter2++) {
0299
0300 if (!theSiPixelFolder.setFedFolder(iBooker, (*struct_iter2).first)) {
0301 throw cms::Exception("LogicError") << "[SiPixelRawDataErrorSource::bookMEs] Creation of DQM folder "
0302 "failed";
0303 }
0304 }
0305
0306
0307 std::string hid;
0308
0309 edm::InputTag src = conf_.getParameter<edm::InputTag>("src");
0310 SiPixelHistogramId *theHistogramId = new SiPixelHistogramId(src.label());
0311
0312 for (uint32_t id = 0; id < 40; id++) {
0313 char temp[50];
0314 sprintf(temp, (topFolderName_ + "/AdditionalPixelErrors/FED_%d").c_str(), id);
0315 iBooker.cd(temp);
0316
0317 hid = theHistogramId->setHistoId("errorType", id);
0318 meErrorType_[id] = iBooker.book1D(hid, "Type of errors", 15, 24.5, 39.5);
0319 meErrorType_[id]->setAxisTitle("Type of errors", 1);
0320
0321 hid = theHistogramId->setHistoId("NErrors", id);
0322 meNErrors_[id] = iBooker.book1D(hid, "Number of errors", 36, 0., 36.);
0323 meNErrors_[id]->setAxisTitle("Number of errors", 1);
0324
0325
0326
0327 hid = theHistogramId->setHistoId("fullType", id);
0328 meFullType_[id] = iBooker.book1D(hid, "Type of FIFO full", 7, 0.5, 7.5);
0329 meFullType_[id]->setAxisTitle("FIFO type", 1);
0330
0331
0332
0333
0334 hid = theHistogramId->setHistoId("TBMMessage", id);
0335 meTBMMessage_[id] = iBooker.book1D(hid, "TBM trailer message", 8, -0.5, 7.5);
0336 meTBMMessage_[id]->setAxisTitle("TBM message", 1);
0337
0338
0339
0340 hid = theHistogramId->setHistoId("TBMType", id);
0341 meTBMType_[id] = iBooker.book1D(hid, "Type of TBM trailer", 5, -0.5, 4.5);
0342 meTBMType_[id]->setAxisTitle("TBM Type", 1);
0343
0344 hid = theHistogramId->setHistoId("EvtNbr", id);
0345 meEvtNbr_[id] = iBooker.book1D(hid, "Event number", 1, 0, 1);
0346
0347 hid = theHistogramId->setHistoId("evtSize", id);
0348 meEvtSize_[id] = iBooker.book1D(hid, "Event size", 1, 0, 1);
0349
0350 hid = theHistogramId->setHistoId("FedChNErr", id);
0351 meFedChNErr_[id] = iBooker.book1D(hid, "Number of errors per FED channel", 37, 0, 37);
0352 meFedChNErr_[id]->setAxisTitle("FED channel", 1);
0353
0354 hid = theHistogramId->setHistoId("FedChLErr", id);
0355 meFedChLErr_[id] = iBooker.book1D(hid, "Last error per FED channel", 37, 0, 37);
0356 meFedChLErr_[id]->setAxisTitle("FED channel", 1);
0357
0358 hid = theHistogramId->setHistoId("FedETypeNErr", id);
0359 meFedETypeNErr_[id] = iBooker.book1D(hid, "Number of errors per type", 21, 0, 21);
0360 meFedETypeNErr_[id]->setAxisTitle("Error type", 1);
0361 }
0362
0363 meMapFEDs_["meErrorType_"] = meErrorType_;
0364 meMapFEDs_["meNErrors_"] = meNErrors_;
0365 meMapFEDs_["meFullType_"] = meFullType_;
0366 meMapFEDs_["meTBMMessage_"] = meTBMMessage_;
0367 meMapFEDs_["meTBMType_"] = meTBMType_;
0368 meMapFEDs_["meEvtNbr_"] = meEvtNbr_;
0369 meMapFEDs_["meEvtSize_"] = meEvtSize_;
0370 meMapFEDs_["meFedChNErr_"] = meFedChNErr_;
0371 meMapFEDs_["meFedChLErr_"] = meFedChLErr_;
0372 meMapFEDs_["meFedETypeNErr_"] = meFedETypeNErr_;
0373
0374
0375 }
0376
0377 DEFINE_FWK_MODULE(SiPixelRawDataErrorSource);