Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:11:13

0001 #include "DQM/SiPixelMonitorClient/interface/SiPixelEDAClient.h"
0002 
0003 // Framework
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/Framework/interface/LuminosityBlock.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "FWCore/ParameterSet/interface/FileInPath.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/ServiceRegistry/interface/Service.h"
0010 
0011 #include "DataFormats/DetId/interface/DetId.h"
0012 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0013 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0014 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0015 #include "DataFormats/GeometrySurface/interface/Surface.h"
0016 #include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
0017 #include "DataFormats/SiPixelDetId/interface/PixelBarrelNameUpgrade.h"
0018 #include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
0019 #include "DataFormats/SiPixelDetId/interface/PixelEndcapNameUpgrade.h"
0020 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0021 
0022 #include "CondFormats/SiPixelObjects/interface/DetectorIndex.h"
0023 #include "CondFormats/SiPixelObjects/interface/SiPixelFrameConverter.h"
0024 
0025 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
0026 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0027 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0028 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0029 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
0030 
0031 #include "DQMServices/Core/interface/DQMStore.h"
0032 
0033 #include "DQM/SiPixelMonitorClient/interface/SiPixelActionExecutor.h"
0034 #include "DQM/SiPixelMonitorClient/interface/SiPixelDataQuality.h"
0035 #include "DQM/SiPixelMonitorClient/interface/SiPixelInformationExtractor.h"
0036 #include "DQM/SiPixelMonitorClient/interface/SiPixelUtility.h"
0037 
0038 #include <cmath>
0039 #include <cstdio>
0040 #include <iomanip>
0041 #include <iostream>
0042 #include <sstream>
0043 #include <string>
0044 
0045 #define BUF_SIZE 256
0046 
0047 using namespace edm;
0048 using namespace std;
0049 //
0050 // -- Constructor
0051 //
0052 SiPixelEDAClient::SiPixelEDAClient(const edm::ParameterSet &ps) {
0053   // cout<<"Entering  SiPixelEDAClient::SiPixelEDAClient: "<<endl;
0054 
0055   edm::LogInfo("SiPixelEDAClient") << " Creating SiPixelEDAClient "
0056                                    << "\n";
0057 
0058   summaryFrequency_ = ps.getUntrackedParameter<int>("SummaryCreationFrequency", 20);
0059   tkMapFrequency_ = ps.getUntrackedParameter<int>("TkMapCreationFrequency", 50);
0060   staticUpdateFrequency_ = ps.getUntrackedParameter<int>("StaticUpdateFrequency", 10);
0061   actionOnLumiSec_ = ps.getUntrackedParameter<bool>("ActionOnLumiSection", false);  // client
0062   actionOnRunEnd_ = ps.getUntrackedParameter<bool>("ActionOnRunEnd", true);         // client
0063   evtOffsetForInit_ = ps.getUntrackedParameter<int>("EventOffsetForInit", 10);      // client
0064   offlineXMLfile_ = ps.getUntrackedParameter<bool>("UseOfflineXMLFile", false);     // client
0065   hiRes_ = ps.getUntrackedParameter<bool>("HighResolutionOccupancy",
0066                                           false);                                               // client
0067   noiseRate_ = ps.getUntrackedParameter<double>("NoiseRateCutValue", 0.001);                    // client
0068   noiseRateDenominator_ = ps.getUntrackedParameter<int>("NEventsForNoiseCalculation", 100000);  // client
0069   Tier0Flag_ = ps.getUntrackedParameter<bool>("Tier0Flag", false);                              // client
0070   doHitEfficiency_ = ps.getUntrackedParameter<bool>("DoHitEfficiency", true);                   // client
0071   inputSource_ = ps.getUntrackedParameter<string>("inputSource", "source");
0072   isUpgrade_ = ps.getUntrackedParameter<bool>("isUpgrade", false);  // client
0073 
0074   if (!Tier0Flag_) {
0075     string localPath = string("DQM/SiPixelMonitorClient/test/loader.html");
0076     std::ifstream fin(edm::FileInPath(localPath).fullPath().c_str(), ios::in);
0077     char buf[BUF_SIZE];
0078 
0079     if (!fin) {
0080       cerr << "Input File: loader.html"
0081            << " could not be opened!" << endl;
0082       return;
0083     }
0084 
0085     while (fin.getline(buf, BUF_SIZE, '\n')) {  // pops off the newline character
0086       html_out_ << buf;
0087     }
0088     fin.close();
0089   }
0090 
0091   firstLumi = true;
0092 
0093   // instantiate the three work horses of the client:
0094   sipixelInformationExtractor_ = new SiPixelInformationExtractor(offlineXMLfile_);
0095   sipixelActionExecutor_ = new SiPixelActionExecutor(offlineXMLfile_, Tier0Flag_);
0096   sipixelDataQuality_ = new SiPixelDataQuality(offlineXMLfile_);
0097 
0098   inputSourceToken_ = consumes<FEDRawDataCollection>(ps.getUntrackedParameter<string>("inputSource", "source"));
0099   cablingMapToken_ = esConsumes<SiPixelFedCablingMap, SiPixelFedCablingMapRcd, edm::Transition::EndLuminosityBlock>();
0100   // cout<<"...leaving  SiPixelEDAClient::SiPixelEDAClient. "<<endl;
0101 }
0102 
0103 //
0104 // -- Destructor
0105 //
0106 SiPixelEDAClient::~SiPixelEDAClient() {
0107   //  cout<<"Entering SiPixelEDAClient::~SiPixelEDAClient: "<<endl;
0108 
0109   edm::LogInfo("SiPixelEDAClient") << " Deleting SiPixelEDAClient "
0110                                    << "\n";
0111 
0112   if (sipixelInformationExtractor_) {
0113     delete sipixelInformationExtractor_;
0114     sipixelInformationExtractor_ = nullptr;
0115   }
0116   if (sipixelActionExecutor_) {
0117     delete sipixelActionExecutor_;
0118     sipixelActionExecutor_ = nullptr;
0119   }
0120   if (sipixelDataQuality_) {
0121     delete sipixelDataQuality_;
0122     sipixelDataQuality_ = nullptr;
0123   }
0124 
0125   //  cout<<"...leaving SiPixelEDAClient::~SiPixelEDAClient. "<<endl;
0126 }
0127 //
0128 // -- Begin Run
0129 //
0130 void SiPixelEDAClient::beginRun(Run const &run, edm::EventSetup const &eSetup) {
0131   edm::LogInfo("SiPixelEDAClient") << "[SiPixelEDAClient]: Begining of Run";
0132   //  cout<<"Entering SiPixelEDAClient::beginRun: "<<endl;
0133 
0134   /// cout << "-----------NEW RUN---------------" << endl;
0135 
0136   if (firstLumi) {
0137     summaryFrequency_ = -1;
0138     tkMapFrequency_ = -1;
0139     actionOnRunEnd_ = true;
0140     evtOffsetForInit_ = -1;
0141 
0142     nLumiSecs_ = 0;
0143     nEvents_ = 0;
0144     if (Tier0Flag_)
0145       nFEDs_ = 40;
0146     else
0147       nFEDs_ = 0;
0148   }
0149 
0150   //  cout<<"...leaving SiPixelEDAClient::beginRun. "<<endl;
0151 }
0152 
0153 //
0154 // -- End Luminosity Block
0155 //
0156 void SiPixelEDAClient::dqmEndLuminosityBlock(DQMStore::IBooker &iBooker,
0157                                              DQMStore::IGetter &iGetter,
0158                                              edm::LuminosityBlock const &lumiSeg,
0159                                              edm::EventSetup const &eSetup) {
0160   // cout<<"Entering SiPixelEDAClient::endLuminosityBlock: "<<endl;
0161 
0162   edm::LogInfo("SiPixelEDAClient") << "[SiPixelEDAClient]: Begin of LS transition";
0163 
0164   // Moved from beginLumi
0165   nEvents_lastLS_ = 0;
0166   nErrorsBarrel_lastLS_ = 0;
0167   nErrorsEndcap_lastLS_ = 0;
0168   MonitorElement *me = iGetter.get("Pixel/AdditionalPixelErrors/byLumiErrors");
0169   if (me) {
0170     nEvents_lastLS_ = int(me->getBinContent(0));
0171     nErrorsBarrel_lastLS_ = int(me->getBinContent(1));
0172     nErrorsEndcap_lastLS_ = int(me->getBinContent(2));
0173     me->Reset();
0174   }
0175 
0176   /// std::cout << "CREATING SUMMARY" << std::endl;
0177   sipixelActionExecutor_->createSummary(iBooker, iGetter, isUpgrade_);
0178 
0179   if (firstLumi) {
0180     iBooker.setCurrentFolder("Pixel/");
0181     iGetter.setCurrentFolder("Pixel/");
0182     // Creating Summary Histos:
0183     // std::cout << "CREATING SUMMARY" << std::endl;
0184     // sipixelActionExecutor_->createSummary(iBooker,iGetter, isUpgrade_);
0185     // Booking Deviation Histos:
0186     if (!Tier0Flag_)
0187       sipixelActionExecutor_->bookDeviations(iBooker, isUpgrade_);
0188     // Booking Efficiency Histos:
0189     if (doHitEfficiency_)
0190       sipixelActionExecutor_->bookEfficiency(iBooker, isUpgrade_);
0191     // Creating occupancy plots:
0192     sipixelActionExecutor_->bookOccupancyPlots(iBooker, iGetter, hiRes_);
0193     // Booking noisy pixel ME's:
0194     if (noiseRate_ > 0.)
0195       sipixelInformationExtractor_->bookNoisyPixels(iBooker, noiseRate_, Tier0Flag_);
0196     // Booking summary report ME's:
0197     sipixelDataQuality_->bookGlobalQualityFlag(iBooker, Tier0Flag_, nFEDs_);
0198 
0199     if (!Tier0Flag_) {
0200       MonitorElement *mefed = iGetter.get("Pixel/EventInfo/DAQContents/fedcounter");
0201       if (mefed) {
0202         for (int i = 0; i < mefed->getNbinsX(); ++i)
0203           nFEDs_ += mefed->getBinContent(i + 1);
0204       }
0205     }
0206     // copy is intentional to allow using the SiPixelFedCablingMap in dqmEndJob() where accessing EventSetup products is not allowed
0207     theCablingMap = eSetup.getData(cablingMapToken_);
0208 
0209     firstLumi = false;
0210   }
0211 
0212   edm::LogInfo("SiPixelEDAClient") << "[SiPixelEDAClient]: End of LS transition, performing the DQM client "
0213                                       "operation";
0214   //
0215   nLumiSecs_ = lumiSeg.id().luminosityBlock();
0216 
0217   /// std::cout << "NEW LUMISECTION n " << nLumiSecs_ << std::endl;
0218   // nLumiSecs_++;
0219 
0220   edm::LogInfo("SiPixelEDAClient") << "====================================================== " << endl
0221                                    << " ===> Iteration # " << nLumiSecs_ << " " << lumiSeg.luminosityBlock() << endl
0222                                    << "====================================================== " << endl;
0223 
0224   if (Tier0Flag_)
0225     sipixelActionExecutor_->normaliseAvDigiOccVsLumi(iBooker, iGetter, nLumiSecs_);
0226 
0227   bool init = true;
0228   if (actionOnLumiSec_ && nLumiSecs_ % 1 == 0) {
0229     if (doHitEfficiency_)
0230       sipixelActionExecutor_->createEfficiency(iBooker, iGetter, isUpgrade_);
0231     sipixelActionExecutor_->createOccupancy(iBooker, iGetter);
0232     iBooker.cd();
0233     iGetter.cd();
0234     sipixelDataQuality_->computeGlobalQualityFlagByLumi(
0235         iGetter, init, nFEDs_, Tier0Flag_, nEvents_lastLS_, nErrorsBarrel_lastLS_, nErrorsEndcap_lastLS_);
0236     init = true;
0237     iBooker.cd();
0238     iGetter.cd();
0239     sipixelDataQuality_->fillGlobalQualityPlot(iBooker, iGetter, init, &theCablingMap, nFEDs_, Tier0Flag_, nLumiSecs_);
0240     init = true;
0241     if (noiseRate_ >= 0.)
0242       sipixelInformationExtractor_->findNoisyPixels(
0243           iBooker, iGetter, init, noiseRate_, noiseRateDenominator_, &theCablingMap);
0244   }
0245 
0246   // cout<<"...leaving SiPixelEDAClient::endLuminosityBlock. "<<endl;
0247 }
0248 //
0249 // -- End Job
0250 //
0251 void SiPixelEDAClient::dqmEndJob(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter) {
0252   //  cout<<"In SiPixelEDAClient::endJob "<<endl;
0253   edm::LogInfo("SiPixelEDAClient") << "[SiPixelEDAClient]: endjob called!";
0254   /// cout << "[SiPixelEDAClient]: endjob called!" << endl;
0255   sipixelActionExecutor_->createSummary(iBooker, iGetter, isUpgrade_);
0256 
0257   if (actionOnRunEnd_) {
0258     // sipixelActionExecutor_->createSummary(iBooker, iGetter, isUpgrade_);
0259 
0260     if (doHitEfficiency_) {
0261       sipixelActionExecutor_->createEfficiency(iBooker, iGetter, isUpgrade_);
0262       sipixelActionExecutor_->fillEfficiencySummary(iBooker, iGetter);
0263     }
0264 
0265     sipixelActionExecutor_->createOccupancy(iBooker, iGetter);
0266 
0267     if (Tier0Flag_)
0268       sipixelActionExecutor_->normaliseAvDigiOcc(iBooker, iGetter);
0269 
0270     iBooker.cd();
0271     iGetter.cd();
0272     bool init = true;
0273     sipixelDataQuality_->computeGlobalQualityFlag(iBooker, iGetter, init, nFEDs_, Tier0Flag_);
0274     init = true;
0275     iBooker.cd();
0276     iGetter.cd();
0277 
0278     sipixelDataQuality_->fillGlobalQualityPlot(iBooker, iGetter, init, &theCablingMap, nFEDs_, Tier0Flag_, nLumiSecs_);
0279     init = true;
0280     if (noiseRate_ >= 0.)
0281       sipixelInformationExtractor_->findNoisyPixels(
0282           iBooker, iGetter, init, noiseRate_, noiseRateDenominator_, &theCablingMap);
0283   }
0284 }