Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-03-13 02:31:38

0001 // -*- C++ -*-
0002 //
0003 // Package:    SiPixelMonitorRawData
0004 // Class:      SiPixelRawDataErrorSource
0005 //
0006 /**\class
0007 
0008  Description:
0009  Produces histograms for error information generated at the raw2digi stage for
0010  the pixel tracker.
0011 
0012  Implementation:
0013  Takes a DetSetVector<SiPixelRawDataError> as input, and uses it to populate  a
0014  folder hierarchy (organized by detId) with histograms containing information
0015  about the errors.  Uses SiPixelRawDataErrorModule class to book and fill
0016  individual folders. Note that this source is different than other DQM sources
0017  in the creation of an unphysical detId folder (detId=0xffffffff) to hold
0018  information about errors for which there is no detId available (except the
0019  dummy detId given to it at raw2digi).
0020 
0021 */
0022 //
0023 // Original Author:  Andrew York
0024 //
0025 #include "DQM/SiPixelMonitorRawData/interface/SiPixelRawDataErrorSource.h"
0026 // Framework
0027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0028 #include "FWCore/ServiceRegistry/interface/Service.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030 // DQM Framework
0031 #include "DQM/SiPixelCommon/interface/SiPixelFolderOrganizer.h"
0032 #include "DQM/SiPixelCommon/interface/SiPixelHistogramId.h"
0033 #include "DQMServices/Core/interface/DQMStore.h"
0034 
0035 // Geometry
0036 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
0037 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0038 // DataFormats
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   // do anything here that needs to be done at desctruction time
0076   // (e.g. close files, deallocate resources etc.)
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   // Build map
0091   buildStructure(iSetup);
0092 }
0093 
0094 void SiPixelRawDataErrorSource::bookHistograms(DQMStore::IBooker &iBooker,
0095                                                edm::Run const &,
0096                                                edm::EventSetup const &iSetup) {
0097   // Book Monitoring Elements
0098   bookMEs(iBooker);
0099 }
0100 
0101 //------------------------------------------------------------------
0102 // Method called for every event
0103 //------------------------------------------------------------------
0104 void SiPixelRawDataErrorSource::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0105   eventNo++;
0106   // check feds in readout
0107   if (eventNo == 1) {
0108     // check if any Pixel FED is in readout:
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   // get input data
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     // cout<<"NErrors: "<<nEventBPIXModuleErrors<<"
0144     // "<<nEventFPIXModuleErrors<<endl;
0145     nErrors = nErrors + numberOfModuleErrors;
0146     // if(nErrors>0) cout<<"MODULES: nErrors: "<<nErrors<<endl;
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;  // (*struct_iter2).first >= 0, since
0152                                                                       // (*struct_iter2).first is unsigned
0153     if ((*struct_iter2).first >= 32 && (*struct_iter2).first <= 39)
0154       nEventFPIXFEDErrors = nEventFPIXFEDErrors + numberOfFEDErrors;
0155     // cout<<"NFEDErrors: "<<nEventBPIXFEDErrors<<"
0156     // "<<nEventFPIXFEDErrors<<endl;
0157     nErrors = nErrors + numberOfFEDErrors;
0158     // if(nErrors>0) cout<<"FEDS: nErrors: "<<nErrors<<endl;
0159   }
0160   if (byLumiErrors) {
0161     byLumiErrors->setBinContent(0, eventNo);
0162     // cout<<"NErrors: "<<nEventBPIXModuleErrors<<" "<<nEventFPIXModuleErrors<<"
0163     // "<<nEventBPIXFEDErrors<<" "<<nEventFPIXFEDErrors<<endl;
0164     if (nEventBPIXModuleErrors + nEventBPIXFEDErrors > 0)
0165       byLumiErrors->Fill(0, 1.);
0166     if (nEventFPIXModuleErrors + nEventFPIXFEDErrors > 0)
0167       byLumiErrors->Fill(1, 1.);
0168     // cout<<"histo: "<<byLumiErrors->getBinContent(0)<<"
0169     // "<<byLumiErrors->getBinContent(1)<<"
0170     // "<<byLumiErrors->getBinContent(2)<<endl;
0171   }
0172 
0173   // Rate of errors per lumi section:
0174   if (errorRate)
0175     errorRate->Fill(lumiSection, nErrors);
0176 
0177   // slow down...
0178   if (slowDown)
0179     usleep(100000);
0180 }
0181 
0182 //------------------------------------------------------------------
0183 // Build data structure
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   // LogVerbatim ("PixelDQM") << " *** I have " << pDD->detTypes().size() <<"
0194   // types"<<std::endl;
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     // check if it is a detUnit
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     // check if it is a detUnit
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     // std::cout<<"Adding FED module: "<<fedId<<std::endl;
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 // Book MEs
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     /// Create folder tree and book histograms
0273 
0274     if (modOn) {
0275       if (!theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 0, isUpgrade)) {
0276         // std::cout<<"PIB! not booking histograms for non-PIB
0277         // modules!"<<std::endl;
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   }  // for loop
0297 
0298   for (struct_iter2 = theFEDStructure.begin(); struct_iter2 != theFEDStructure.end(); struct_iter2++) {
0299     /// Create folder tree for errors without detId and book histograms
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   // Booking FED histograms
0307   std::string hid;
0308   // Get collection name and instantiate Histo Id builder
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     // Types of errors
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     // Number of errors
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     // Type of FIFO full (errorType = 28).  FIFO 1 is 1-5 (where fullType =
0325     // channel of FIFO 1), fullType = 6 signifies FIFO 2 nearly full, 7
0326     // signifies trigger FIFO nearly full, 8 indicates an unexpected result
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     // For error type 30, the type of problem encoded in the TBM trailer
0331     // 0 = stack full, 1 = Pre-cal issued, 2 = clear trigger counter, 3 = sync
0332     // trigger, 4 = sync trigger error, 5 = reset ROC, 6 = reset TBM, 7 = no
0333     // token bit pass
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     // For error type 30, the type of problem encoded in the TBM error trailer 0
0338     // = none 1 = data stream too long, 2 = FSM errors, 3 = invalid # of ROCs, 4
0339     // = multiple
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     // For error type 31, the event number of the TBM header with the error
0344     hid = theHistogramId->setHistoId("EvtNbr", id);
0345     meEvtNbr_[id] = iBooker.book1D(hid, "Event number", 1, 0, 1);
0346     // For errorType = 34, datastream size according to error word
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   // Add the booked histograms to the histogram map for booking
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   // cout<<"...leaving SiPixelRawDataErrorSource::bookMEs now! "<<endl;
0375 }
0376 
0377 DEFINE_FWK_MODULE(SiPixelRawDataErrorSource);