Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-04 02:02:31

0001 // -*- C++ -*-
0002 //
0003 // Package:    Phase2TrackerMonitorDigi
0004 // Class:      Phase2TrackerMonitorDigi
0005 //
0006 /**\class Phase2TrackerMonitorDigi Phase2TrackerMonitorDigi.cc 
0007 
0008  Description: It generates various histograms of digi properties. Manual switching is enabled for each histogram. Seperate Histograms are there for P type and S type sensors of the outer Tracker   
0009 
0010 */
0011 //
0012 // Author: Suchandra Dutta, Gourab Saha, Suvankar Roy Chowdhury, Subir Sarkar
0013 // Date: January 29, 2016
0014 // Date: November 8, 2019 (Modified for adding in phase2 DQM Offline)
0015 //
0016 // system include files
0017 
0018 #include <memory>
0019 
0020 #include "DQM/SiTrackerPhase2/plugins/Phase2TrackerMonitorDigi.h"
0021 
0022 #include "FWCore/Framework/interface/MakerMacros.h"
0023 #include "DataFormats/Common/interface/Handle.h"
0024 
0025 #include "FWCore/ServiceRegistry/interface/Service.h"
0026 #include "FWCore/Utilities/interface/InputTag.h"
0027 #include "FWCore/Framework/interface/ESWatcher.h"
0028 
0029 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0030 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0031 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0032 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0033 #include "Geometry/CommonDetUnit/interface/PixelGeomDetType.h"
0034 
0035 #include "DataFormats/Phase2TrackerDigi/interface/Phase2TrackerDigi.h"
0036 #include "DataFormats/SiPixelDigi/interface/PixelDigi.h"
0037 #include "DataFormats/SiPixelDigi/interface/PixelDigiCollection.h"
0038 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0039 
0040 // DQM Histograming
0041 #include "DQMServices/Core/interface/MonitorElement.h"
0042 #include "DQM/SiTrackerPhase2/interface/TrackerPhase2DQMUtil.h"
0043 
0044 using Phase2TrackerGeomDetUnit = PixelGeomDetUnit;
0045 //
0046 // constructors
0047 //
0048 Phase2TrackerMonitorDigi::Phase2TrackerMonitorDigi(const edm::ParameterSet& iConfig)
0049     : config_(iConfig),
0050       pixelFlag_(config_.getParameter<bool>("PixelPlotFillingFlag")),
0051       clsFlag_(config_.getParameter<bool>("StandAloneClusteriserFlag")),
0052       geomType_(config_.getParameter<std::string>("GeometryType")),
0053       otDigiSrc_(config_.getParameter<edm::InputTag>("OuterTrackerDigiSource")),
0054       itPixelDigiSrc_(config_.getParameter<edm::InputTag>("InnerPixelDigiSource")),
0055       otDigiToken_(consumes<edm::DetSetVector<Phase2TrackerDigi>>(otDigiSrc_)),
0056       itPixelDigiToken_(consumes<edm::DetSetVector<PixelDigi>>(itPixelDigiSrc_)),
0057       geomToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>()),
0058       topoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()) {
0059   edm::LogInfo("Phase2TrackerMonitorDigi") << ">>> Construct Phase2TrackerMonitorDigi ";
0060 }
0061 
0062 //
0063 // destructor
0064 //
0065 Phase2TrackerMonitorDigi::~Phase2TrackerMonitorDigi() {
0066   // do anything here that needs to be done at desctruction time
0067   // (e.g. close files, deallocate resources etc.)
0068   edm::LogInfo("Phase2TrackerMonitorDigi") << ">>> Destroy Phase2TrackerMonitorDigi ";
0069 }
0070 
0071 void Phase2TrackerMonitorDigi::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0072   tkGeom_ = &iSetup.getData(geomToken_);
0073   tTopo_ = &iSetup.getData(topoToken_);
0074 }
0075 
0076 // -- Analyze
0077 //
0078 void Phase2TrackerMonitorDigi::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0079   using namespace edm;
0080 
0081   // Get digis
0082   const auto& pixDigiHandle = iEvent.getHandle(itPixelDigiToken_);
0083   const auto& otDigiHandle = iEvent.getHandle(otDigiToken_);
0084 
0085   // Tracker Topology
0086   edm::ESWatcher<TrackerDigiGeometryRecord> theTkDigiGeomWatcher;
0087   if (theTkDigiGeomWatcher.check(iSetup)) {
0088     if (pixelFlag_)
0089       fillITPixelDigiHistos(pixDigiHandle);
0090     else
0091       fillOTDigiHistos(otDigiHandle);
0092   }
0093 }
0094 void Phase2TrackerMonitorDigi::fillITPixelDigiHistos(const edm::Handle<edm::DetSetVector<PixelDigi>> handle) {
0095   const edm::DetSetVector<PixelDigi>* digis = handle.product();
0096 
0097   for (typename edm::DetSetVector<PixelDigi>::const_iterator DSViter = digis->begin(); DSViter != digis->end();
0098        DSViter++) {
0099     unsigned int rawid = DSViter->id;
0100     edm::LogInfo("Phase2TrackerMonitorDigi") << " Det Id = " << rawid;
0101 
0102     int layer = tTopo_->getITPixelLayerNumber(rawid);
0103 
0104     if (layer < 0)
0105       continue;
0106     const DetId detId(rawid);
0107 
0108     std::string key = getHistoId(rawid, pixelFlag_);
0109     std::map<std::string, DigiMEs>::iterator pos = layerMEs.find(key);
0110 
0111     if (pos == layerMEs.end())
0112       continue;
0113 
0114     if (DetId(detId).det() != DetId::Detector::Tracker)
0115       continue;
0116 
0117     const GeomDetUnit* gDetUnit = tkGeom_->idToDetUnit(detId);
0118     const GeomDet* geomDet = tkGeom_->idToDet(detId);
0119 
0120     const Phase2TrackerGeomDetUnit* tkDetUnit = dynamic_cast<const Phase2TrackerGeomDetUnit*>(gDetUnit);
0121     int nRows = tkDetUnit->specificTopology().nrows();
0122     int nColumns = tkDetUnit->specificTopology().ncolumns();
0123     if (nRows * nColumns == 0)
0124       continue;
0125 
0126     DigiMEs& local_mes = pos->second;
0127 
0128     local_mes.nHitDetsPerLayer++;
0129 
0130     int nDigi = 0;
0131     int row_last = -1;
0132     int col_last = -1;
0133     std::vector<Ph2DigiCluster> digiClusters;
0134     for (typename edm::DetSet<PixelDigi>::const_iterator di = DSViter->begin(); di != DSViter->end(); di++) {
0135       int col = di->column();  // column
0136       int row = di->row();     // row
0137       int adc = di->adc();     // digi charge
0138       if (geomDet) {
0139         MeasurementPoint mp(row + 0.5, col + 0.5);
0140         GlobalPoint pdPos = geomDet->surface().toGlobal(gDetUnit->topology().localPosition(mp));
0141         if (XYPositionMap)
0142           XYPositionMap->Fill(pdPos.x() * 10., pdPos.y() * 10.);
0143         if (RZPositionMap)
0144           RZPositionMap->Fill(pdPos.z() * 10., std::hypot(pdPos.x(), pdPos.y()) * 10.);
0145       }
0146       nDigi++;
0147       edm::LogInfo("Phase2TrackerMonitorDigi") << "  column " << col << " row " << row << std::dec << std::endl;
0148       if (local_mes.ChargeXYMap)
0149         local_mes.ChargeXYMap->Fill(col, row, adc);
0150       if (local_mes.PositionOfDigisP)
0151         local_mes.PositionOfDigisP->Fill(row + 1, col + 1);
0152       if (local_mes.ChargeOfDigis)
0153         local_mes.ChargeOfDigis->Fill(adc);
0154       if (clsFlag_) {
0155         if (row_last == -1 || abs(row - row_last) != 1 || col != col_last) {
0156           Ph2DigiCluster dClus;
0157           dClus.position = row + 1;
0158           dClus.column = col;
0159           dClus.width = 1;
0160           dClus.charge = 255;
0161           digiClusters.push_back(dClus);
0162         } else {
0163           int pos = digiClusters.back().position + row + 1;
0164           int width = digiClusters.back().width + 1;
0165           pos /= width;
0166 
0167           digiClusters.back().position = pos;
0168           digiClusters.back().width += 1;
0169         }
0170         edm::LogInfo("Phase2TrackerMonitorDigi") << " row " << row << " col " << col << " row_last " << row_last
0171                                                  << " col_last " << col_last << " width " << digiClusters.back().width;
0172         row_last = row;
0173         col_last = col;
0174       }
0175     }
0176     if (local_mes.NumberOfDigisPerDet)
0177       local_mes.NumberOfDigisPerDet->Fill(nDigi);
0178     if (clsFlag_)
0179       fillDigiClusters(local_mes, digiClusters);
0180     local_mes.nDigiPerLayer += nDigi;
0181     float occupancy = 1.0;
0182     if (nRows * nColumns > 0)
0183       occupancy = nDigi * 1.0 / (nRows * nColumns);
0184     if (geomDet) {
0185       GlobalPoint gp = geomDet->surface().toGlobal(
0186           gDetUnit->topology().localPosition(MeasurementPoint(nRows / 2.0, nColumns / 2.0)));
0187       if (XYOccupancyMap)
0188         XYOccupancyMap->Fill(gp.x() * 10., gp.y() * 10, occupancy);
0189       if (RZOccupancyMap)
0190         RZOccupancyMap->Fill(gp.z() * 10., std::hypot(gp.x(), gp.y()) * 10., occupancy);
0191       if (local_mes.EtaOccupancyProfP)
0192         local_mes.EtaOccupancyProfP->Fill(gp.eta(), occupancy);
0193     }
0194 
0195     if (local_mes.DigiOccupancyP)
0196       local_mes.DigiOccupancyP->Fill(occupancy);
0197   }
0198   // Fill histograms after loop over digis are complete
0199   for (auto& ilayer : layerMEs) {
0200     DigiMEs& local_mes = ilayer.second;
0201     if (local_mes.TotalNumberOfDigisPerLayer)
0202       local_mes.TotalNumberOfDigisPerLayer->Fill(local_mes.nDigiPerLayer);
0203     if (local_mes.NumberOfHitDetectorsPerLayer)
0204       local_mes.NumberOfHitDetectorsPerLayer->Fill(local_mes.nHitDetsPerLayer);
0205     local_mes.nDigiPerLayer = 0;
0206     local_mes.nHitDetsPerLayer = 0;
0207   }
0208 }
0209 void Phase2TrackerMonitorDigi::fillOTDigiHistos(const edm::Handle<edm::DetSetVector<Phase2TrackerDigi>> handle) {
0210   const edm::DetSetVector<Phase2TrackerDigi>* digis = handle.product();
0211 
0212   for (typename edm::DetSetVector<Phase2TrackerDigi>::const_iterator DSViter = digis->begin(); DSViter != digis->end();
0213        DSViter++) {
0214     unsigned int rawid = DSViter->id;
0215     DetId detId(rawid);
0216     edm::LogInfo("Phase2TrackerMonitorDigi") << " Det Id = " << rawid;
0217     int layer = tTopo_->getOTLayerNumber(rawid);
0218     if (layer < 0)
0219       continue;
0220     std::string key = getHistoId(rawid, pixelFlag_);
0221     std::map<std::string, DigiMEs>::iterator pos = layerMEs.find(key);
0222     if (pos == layerMEs.end())
0223       continue;
0224     DigiMEs& local_mes = pos->second;
0225 
0226     local_mes.nHitDetsPerLayer++;
0227     if (DetId(detId).det() != DetId::Detector::Tracker)
0228       continue;
0229 
0230     const GeomDetUnit* gDetUnit = tkGeom_->idToDetUnit(detId);
0231     const GeomDet* geomDet = tkGeom_->idToDet(detId);
0232 
0233     const Phase2TrackerGeomDetUnit* tkDetUnit = dynamic_cast<const Phase2TrackerGeomDetUnit*>(gDetUnit);
0234     int nRows = tkDetUnit->specificTopology().nrows();
0235     int nColumns = tkDetUnit->specificTopology().ncolumns();
0236     if (nRows * nColumns == 0)
0237       continue;
0238 
0239     int nDigi = 0;
0240     int row_last = -1;
0241     int col_last = -1;
0242     float frac_ot = 0.;
0243     std::vector<Ph2DigiCluster> digiClusters;
0244     for (typename edm::DetSet<Phase2TrackerDigi>::const_iterator di = DSViter->begin(); di != DSViter->end(); di++) {
0245       int col = di->column();  // column
0246       int row = di->row();     // row
0247       const DetId detId(rawid);
0248 
0249       if (geomDet) {
0250         MeasurementPoint mp(row + 0.5, col + 0.5);
0251         GlobalPoint pdPos = geomDet->surface().toGlobal(gDetUnit->topology().localPosition(mp));
0252         if (XYPositionMap)
0253           XYPositionMap->Fill(pdPos.x() * 10., pdPos.y() * 10.);
0254         if (RZPositionMap)
0255           RZPositionMap->Fill(pdPos.z() * 10., std::hypot(pdPos.x(), pdPos.y()) * 10.);
0256       }
0257       nDigi++;
0258       if (di->overThreshold())
0259         frac_ot++;
0260       edm::LogInfo("Phase2TrackerMonitorDigi") << "  column " << col << " row " << row << std::dec << std::endl;
0261       if (nColumns > 2 && local_mes.PositionOfDigisP)
0262         local_mes.PositionOfDigisP->Fill(row + 1, col + 1);
0263       if (nColumns <= 2 && local_mes.PositionOfDigisS)
0264         local_mes.PositionOfDigisS->Fill(row + 1, col + 1);
0265 
0266       if (clsFlag_) {
0267         if (row_last == -1 || abs(row - row_last) != 1 || col != col_last) {
0268           Ph2DigiCluster dClus;
0269           dClus.position = row + 1;
0270           dClus.column = col;
0271           dClus.width = 1;
0272           dClus.charge = 255;
0273           digiClusters.push_back(dClus);
0274         } else {
0275           int pos = digiClusters.back().position + row + 1;
0276           int width = digiClusters.back().width + 1;
0277           pos /= width;
0278 
0279           digiClusters.back().position = pos;
0280           digiClusters.back().width += 1;
0281         }
0282         row_last = row;
0283         col_last = col;
0284         edm::LogInfo("Phase2TrackerMonitorDigi") << " row " << row << " col " << col << " row_last " << row_last
0285                                                  << " col_last " << col_last << " width " << digiClusters.back().width;
0286       }
0287     }
0288     if (local_mes.NumberOfDigisPerDet)
0289       local_mes.NumberOfDigisPerDet->Fill(nDigi);
0290     if (clsFlag_)
0291       fillDigiClusters(local_mes, digiClusters);
0292     local_mes.nDigiPerLayer += nDigi;
0293     if (nDigi)
0294       frac_ot /= nDigi;
0295     if (local_mes.FractionOfOvTBits && nColumns <= 2)
0296       local_mes.FractionOfOvTBits->Fill(frac_ot);
0297 
0298     float occupancy = 1.0;
0299     if (nRows * nColumns > 0)
0300       occupancy = nDigi * 1.0 / (nRows * nColumns);
0301     if (geomDet) {
0302       GlobalPoint gp = geomDet->surface().toGlobal(gDetUnit->topology().localPosition(MeasurementPoint(0.0, 0.0)));
0303       if (XYOccupancyMap)
0304         XYOccupancyMap->Fill(gp.x() * 10., gp.y() * 10., occupancy);
0305       if (RZOccupancyMap)
0306         RZOccupancyMap->Fill(gp.z() * 10., std::hypot(gp.x(), gp.y()) * 10., occupancy);
0307       if (nColumns > 2) {
0308         if (local_mes.DigiOccupancyP)
0309           local_mes.DigiOccupancyP->Fill(occupancy);
0310         if (local_mes.EtaOccupancyProfP)
0311           local_mes.EtaOccupancyProfP->Fill(gp.eta(), occupancy);
0312       } else {
0313         if (local_mes.DigiOccupancyS)
0314           local_mes.DigiOccupancyS->Fill(occupancy);
0315         if (local_mes.EtaOccupancyProfS)
0316           local_mes.EtaOccupancyProfS->Fill(gp.eta(), occupancy);
0317         if (local_mes.FractionOfOvTBitsVsEta)
0318           local_mes.FractionOfOvTBitsVsEta->Fill(gp.eta(), frac_ot);
0319       }
0320     }
0321   }
0322   // Fill histograms after loop over digis are complete
0323   for (auto& ilayer : layerMEs) {
0324     DigiMEs& local_mes = ilayer.second;
0325     if (local_mes.TotalNumberOfDigisPerLayer)
0326       local_mes.TotalNumberOfDigisPerLayer->Fill(local_mes.nDigiPerLayer);
0327     if (local_mes.NumberOfHitDetectorsPerLayer)
0328       local_mes.NumberOfHitDetectorsPerLayer->Fill(local_mes.nHitDetsPerLayer);
0329     local_mes.nDigiPerLayer = 0;
0330     local_mes.nHitDetsPerLayer = 0;
0331   }
0332 }
0333 //
0334 // -- Book Histograms
0335 //
0336 void Phase2TrackerMonitorDigi::bookHistograms(DQMStore::IBooker& ibooker,
0337                                               edm::Run const& iRun,
0338                                               edm::EventSetup const& iSetup) {
0339   std::string top_folder = config_.getParameter<std::string>("TopFolderName");
0340   edm::ESWatcher<TrackerDigiGeometryRecord> theTkDigiGeomWatcher;
0341 
0342   if (theTkDigiGeomWatcher.check(iSetup)) {
0343     for (auto const& det_u : tkGeom_->detUnits()) {
0344       unsigned int detId_raw = det_u->geographicalId().rawId();
0345       bookLayerHistos(ibooker, detId_raw);
0346     }
0347   }
0348   ibooker.cd();
0349   std::stringstream folder_name;
0350   folder_name << top_folder << "/"
0351               << "DigiMonitor";
0352   ibooker.setCurrentFolder(folder_name.str());
0353 
0354   edm::ParameterSet Parameters = config_.getParameter<edm::ParameterSet>("XYPositionMapH");
0355   edm::ParameterSet ParametersOcc = config_.getParameter<edm::ParameterSet>("DigiOccupancyPH");
0356   if (Parameters.getParameter<bool>("switch"))
0357     XYPositionMap = ibooker.book2D("DigiXPosVsYPos",
0358                                    "DigiXPosVsYPos",
0359                                    Parameters.getParameter<int32_t>("Nxbins"),
0360                                    Parameters.getParameter<double>("xmin"),
0361                                    Parameters.getParameter<double>("xmax"),
0362                                    Parameters.getParameter<int32_t>("Nybins"),
0363                                    Parameters.getParameter<double>("ymin"),
0364                                    Parameters.getParameter<double>("ymax"));
0365   else
0366     XYPositionMap = nullptr;
0367 
0368   if (Parameters.getParameter<bool>("switch") && ParametersOcc.getParameter<bool>("switch"))
0369     XYOccupancyMap = ibooker.bookProfile2D("OccupancyInXY",
0370                                            "OccupancyInXY",
0371                                            Parameters.getParameter<int32_t>("Nxbins"),
0372                                            Parameters.getParameter<double>("xmin"),
0373                                            Parameters.getParameter<double>("xmax"),
0374                                            Parameters.getParameter<int32_t>("Nybins"),
0375                                            Parameters.getParameter<double>("ymin"),
0376                                            Parameters.getParameter<double>("ymax"),
0377                                            ParametersOcc.getParameter<double>("xmin"),
0378                                            ParametersOcc.getParameter<double>("xmax"));
0379   else
0380     XYOccupancyMap = nullptr;
0381 
0382   Parameters = config_.getParameter<edm::ParameterSet>("RZPositionMapH");
0383   if (Parameters.getParameter<bool>("switch"))
0384     RZPositionMap = ibooker.book2D("DigiRPosVsZPos",
0385                                    "DigiRPosVsZPos",
0386                                    Parameters.getParameter<int32_t>("Nxbins"),
0387                                    Parameters.getParameter<double>("xmin"),
0388                                    Parameters.getParameter<double>("xmax"),
0389                                    Parameters.getParameter<int32_t>("Nybins"),
0390                                    Parameters.getParameter<double>("ymin"),
0391                                    Parameters.getParameter<double>("ymax"));
0392   else
0393     RZPositionMap = nullptr;
0394 
0395   if (Parameters.getParameter<bool>("switch") && ParametersOcc.getParameter<bool>("switch"))
0396     RZOccupancyMap = ibooker.bookProfile2D("OccupancyInRZ",
0397                                            "OccupancyInRZ",
0398                                            Parameters.getParameter<int32_t>("Nxbins"),
0399                                            Parameters.getParameter<double>("xmin"),
0400                                            Parameters.getParameter<double>("xmax"),
0401                                            Parameters.getParameter<int32_t>("Nybins"),
0402                                            Parameters.getParameter<double>("ymin"),
0403                                            Parameters.getParameter<double>("ymax"),
0404                                            ParametersOcc.getParameter<double>("xmin"),
0405                                            ParametersOcc.getParameter<double>("xmax"));
0406   else
0407     RZOccupancyMap = nullptr;
0408 }
0409 //
0410 // -- Book Layer Histograms
0411 //
0412 void Phase2TrackerMonitorDigi::bookLayerHistos(DQMStore::IBooker& ibooker, unsigned int det_id) {
0413   int layer;
0414   if (pixelFlag_)
0415     layer = tTopo_->getITPixelLayerNumber(det_id);
0416   else
0417     layer = tTopo_->getOTLayerNumber(det_id);
0418 
0419   if (layer < 0)
0420     return;
0421   std::string key = getHistoId(det_id, pixelFlag_);
0422   std::map<std::string, DigiMEs>::iterator pos = layerMEs.find(key);
0423 
0424   if (pos == layerMEs.end()) {
0425     std::string top_folder = config_.getParameter<std::string>("TopFolderName");
0426     std::stringstream folder_name;
0427 
0428     //For endCap: P-type sensors are present only upto ring 10 for discs 1&2 (TEDD-1) and upto ring 7 for discs 3,4&5 (TEDD-2)
0429     bool isPStypeModForTEDD_1 =
0430         (!pixelFlag_ && layer > 100 && tTopo_->tidWheel(det_id) < 3 && tTopo_->tidRing(det_id) <= 10) ? true : false;
0431     bool isPStypeModForTEDD_2 =
0432         (!pixelFlag_ && layer > 100 && tTopo_->tidWheel(det_id) >= 3 && tTopo_->tidRing(det_id) <= 7) ? true : false;
0433 
0434     bool isPtypeSensor =
0435         (pixelFlag_ || (layer < 4 || (layer > 6 && (isPStypeModForTEDD_1 || isPStypeModForTEDD_2)))) ? true : false;
0436 
0437     ibooker.cd();
0438     ibooker.setCurrentFolder(top_folder + "/DigiMonitor/" + key);
0439     edm::LogInfo("Phase2TrackerMonitorDigi") << " Booking Histograms in : " << key;
0440 
0441     std::ostringstream HistoName;
0442     DigiMEs local_mes;
0443 
0444     local_mes.nDigiPerLayer = 0;
0445     local_mes.nHitDetsPerLayer = 0;
0446 
0447     edm::ParameterSet Parameters = config_.getParameter<edm::ParameterSet>("NumberOfDigisPerDetH");
0448     edm::ParameterSet EtaParameters = config_.getParameter<edm::ParameterSet>("EtaH");
0449     HistoName.str("");
0450     HistoName << "NumberOfDigisPerDet";
0451     if (Parameters.getParameter<bool>("switch"))
0452       local_mes.NumberOfDigisPerDet = ibooker.book1D(HistoName.str(),
0453                                                      HistoName.str(),
0454                                                      Parameters.getParameter<int32_t>("Nbins"),
0455                                                      Parameters.getParameter<double>("xmin"),
0456                                                      Parameters.getParameter<double>("xmax"));
0457     else
0458       local_mes.NumberOfDigisPerDet = nullptr;
0459 
0460     Parameters = config_.getParameter<edm::ParameterSet>("TotalNumberOfDigisPerLayerH");
0461     HistoName.str("");
0462     HistoName << "TotalNumberOfDigisPerLayer";
0463     if (Parameters.getParameter<bool>("switch"))
0464       local_mes.TotalNumberOfDigisPerLayer = ibooker.book1D(HistoName.str(),
0465                                                             HistoName.str(),
0466                                                             Parameters.getParameter<int32_t>("Nbins"),
0467                                                             Parameters.getParameter<double>("xmin"),
0468                                                             Parameters.getParameter<double>("xmax"));
0469     else
0470       local_mes.TotalNumberOfDigisPerLayer = nullptr;
0471 
0472     Parameters = config_.getParameter<edm::ParameterSet>("NumberOfHitDetsPerLayerH");
0473     HistoName.str("");
0474     HistoName << "NumberOfHitDetectorsPerLayer";
0475     if (Parameters.getParameter<bool>("switch"))
0476       local_mes.NumberOfHitDetectorsPerLayer = ibooker.book1D(HistoName.str(),
0477                                                               HistoName.str(),
0478                                                               Parameters.getParameter<int32_t>("Nbins"),
0479                                                               Parameters.getParameter<double>("xmin"),
0480                                                               Parameters.getParameter<double>("xmax"));
0481     else
0482       local_mes.NumberOfHitDetectorsPerLayer = nullptr;
0483 
0484     // Plots only for the inner pixel
0485     if (pixelFlag_) {
0486       Parameters = config_.getParameter<edm::ParameterSet>("ChargeXYMapH");
0487       HistoName.str("");
0488       HistoName << "ChargeXYMap";
0489       if (Parameters.getParameter<bool>("switch"))
0490         local_mes.ChargeXYMap = ibooker.book2D(HistoName.str(),
0491                                                HistoName.str(),
0492                                                Parameters.getParameter<int32_t>("Nxbins"),
0493                                                Parameters.getParameter<double>("xmin"),
0494                                                Parameters.getParameter<double>("xmax"),
0495                                                Parameters.getParameter<int32_t>("Nybins"),
0496                                                Parameters.getParameter<double>("ymin"),
0497                                                Parameters.getParameter<double>("ymax"));
0498       else
0499         local_mes.ChargeXYMap = nullptr;
0500 
0501       Parameters = config_.getParameter<edm::ParameterSet>("DigiChargeH");
0502       HistoName.str("");
0503       HistoName << "ChargeOfDigis";
0504       if (Parameters.getParameter<bool>("switch"))
0505         local_mes.ChargeOfDigis = ibooker.book1D(HistoName.str(),
0506                                                  HistoName.str(),
0507                                                  Parameters.getParameter<int32_t>("Nbins"),
0508                                                  Parameters.getParameter<double>("xmin"),
0509                                                  Parameters.getParameter<double>("xmax"));
0510       else
0511         local_mes.ChargeOfDigis = nullptr;
0512 
0513       // For standalone clusteriser
0514       if (clsFlag_) {
0515         edm::ParameterSet WidthParameters = config_.getParameter<edm::ParameterSet>("ClusterWidthH");
0516         HistoName.str("");
0517         HistoName << "ChargeOfDigisVsWidth";
0518         if (Parameters.getParameter<bool>("switch") && WidthParameters.getParameter<bool>("switch"))
0519           local_mes.ChargeOfDigisVsWidth = ibooker.book2D(HistoName.str(),
0520                                                           HistoName.str(),
0521                                                           Parameters.getParameter<int32_t>("Nbins"),
0522                                                           Parameters.getParameter<double>("xmin"),
0523                                                           Parameters.getParameter<double>("xmax"),
0524                                                           WidthParameters.getParameter<int32_t>("Nbins"),
0525                                                           WidthParameters.getParameter<double>("xmin"),
0526                                                           WidthParameters.getParameter<double>("xmax"));
0527         else
0528           local_mes.ChargeOfDigisVsWidth = nullptr;
0529       }
0530     }
0531     // For outer tracker modules (S-type histograms)
0532     else {
0533       Parameters = config_.getParameter<edm::ParameterSet>("DigiOccupancySH");
0534       HistoName.str("");
0535       HistoName << "DigiOccupancyS";
0536       if (Parameters.getParameter<bool>("switch"))
0537         local_mes.DigiOccupancyS = ibooker.book1D(HistoName.str(),
0538                                                   HistoName.str(),
0539                                                   Parameters.getParameter<int32_t>("Nbins"),
0540                                                   Parameters.getParameter<double>("xmin"),
0541                                                   Parameters.getParameter<double>("xmax"));
0542       else
0543         local_mes.DigiOccupancyS = nullptr;
0544 
0545       HistoName.str("");
0546       HistoName << "DigiOccupancyVsEtaS";
0547       if (Parameters.getParameter<bool>("switch") && EtaParameters.getParameter<bool>("switch"))
0548         local_mes.EtaOccupancyProfS = ibooker.bookProfile(HistoName.str(),
0549                                                           HistoName.str(),
0550                                                           EtaParameters.getParameter<int32_t>("Nbins"),
0551                                                           EtaParameters.getParameter<double>("xmin"),
0552                                                           EtaParameters.getParameter<double>("xmax"),
0553                                                           Parameters.getParameter<double>("xmin"),
0554                                                           Parameters.getParameter<double>("xmax"),
0555                                                           "");
0556       else
0557         local_mes.EtaOccupancyProfS = nullptr;
0558 
0559       Parameters = config_.getParameter<edm::ParameterSet>("PositionOfDigisSH");
0560       HistoName.str("");
0561       HistoName << "PositionOfDigisS";
0562       if (Parameters.getParameter<bool>("switch"))
0563         local_mes.PositionOfDigisS = ibooker.book2D(HistoName.str(),
0564                                                     HistoName.str(),
0565                                                     Parameters.getParameter<int32_t>("Nxbins"),
0566                                                     Parameters.getParameter<double>("xmin"),
0567                                                     Parameters.getParameter<double>("xmax"),
0568                                                     Parameters.getParameter<int32_t>("Nybins"),
0569                                                     Parameters.getParameter<double>("ymin"),
0570                                                     Parameters.getParameter<double>("ymax"));
0571       else
0572         local_mes.PositionOfDigisS = nullptr;
0573 
0574       // For standalone clusteriser
0575       if (clsFlag_) {
0576         Parameters = config_.getParameter<edm::ParameterSet>("ClusterPositionSH");
0577         HistoName.str("");
0578         HistoName << "ClusterPositionS";
0579         if (Parameters.getParameter<bool>("switch"))
0580           local_mes.ClusterPositionS = ibooker.book2D(HistoName.str(),
0581                                                       HistoName.str(),
0582                                                       Parameters.getParameter<int32_t>("Nxbins"),
0583                                                       Parameters.getParameter<double>("xmin"),
0584                                                       Parameters.getParameter<double>("xmax"),
0585                                                       Parameters.getParameter<int32_t>("Nybins"),
0586                                                       Parameters.getParameter<double>("ymin"),
0587                                                       Parameters.getParameter<double>("ymax"));
0588         else
0589           local_mes.ClusterPositionS = nullptr;
0590       }
0591       // Only for the S-type sensor of PS module
0592       // FracOfOverThresholdBits is only available for S-type sensor of PS module
0593       if (isPStypeModForTEDD_1 || isPStypeModForTEDD_2) {
0594         HistoName.str("");
0595         HistoName << "FractionOfOverThresholdDigis";
0596         local_mes.FractionOfOvTBits = ibooker.book1D(HistoName.str(), HistoName.str(), 11, -0.05, 1.05);
0597 
0598         Parameters = config_.getParameter<edm::ParameterSet>("NumberOfDigisPerDetH");
0599         HistoName.str("");
0600         HistoName << "FractionOfOverThresholdDigisVaEta";
0601         if (Parameters.getParameter<bool>("switch") && EtaParameters.getParameter<bool>("switch"))
0602           local_mes.FractionOfOvTBitsVsEta = ibooker.bookProfile(HistoName.str(),
0603                                                                  HistoName.str(),
0604                                                                  EtaParameters.getParameter<int32_t>("Nbins"),
0605                                                                  EtaParameters.getParameter<double>("xmin"),
0606                                                                  EtaParameters.getParameter<double>("xmax"),
0607                                                                  Parameters.getParameter<double>("xmin"),
0608                                                                  Parameters.getParameter<double>("xmax"),
0609                                                                  "");
0610         else
0611           local_mes.FractionOfOvTBitsVsEta = nullptr;
0612       }
0613     }
0614 
0615     // Plots for P-type sensor (Pixel or P-side of PS module)
0616     if (isPtypeSensor) {
0617       Parameters = config_.getParameter<edm::ParameterSet>("DigiOccupancyPH");
0618       HistoName.str("");
0619       HistoName << "DigiOccupancyP";
0620       if (Parameters.getParameter<bool>("switch"))
0621         local_mes.DigiOccupancyP = ibooker.book1D(HistoName.str(),
0622                                                   HistoName.str(),
0623                                                   Parameters.getParameter<int32_t>("Nbins"),
0624                                                   Parameters.getParameter<double>("xmin"),
0625                                                   Parameters.getParameter<double>("xmax"));
0626       else
0627         local_mes.DigiOccupancyP = nullptr;
0628 
0629       HistoName.str("");
0630       HistoName << "DigiOccupancyVsEtaP";
0631       if (Parameters.getParameter<bool>("switch") && EtaParameters.getParameter<bool>("switch"))
0632         local_mes.EtaOccupancyProfP = ibooker.bookProfile(HistoName.str(),
0633                                                           HistoName.str(),
0634                                                           EtaParameters.getParameter<int32_t>("Nbins"),
0635                                                           EtaParameters.getParameter<double>("xmin"),
0636                                                           EtaParameters.getParameter<double>("xmax"),
0637                                                           Parameters.getParameter<double>("xmin"),
0638                                                           Parameters.getParameter<double>("xmax"),
0639                                                           "");
0640       else
0641         local_mes.EtaOccupancyProfP = nullptr;
0642 
0643       Parameters = config_.getParameter<edm::ParameterSet>("PositionOfDigisPH");
0644       HistoName.str("");
0645       HistoName << "PositionOfDigisP";
0646       if (Parameters.getParameter<bool>("switch"))
0647         local_mes.PositionOfDigisP = ibooker.book2D(HistoName.str(),
0648                                                     HistoName.str(),
0649                                                     Parameters.getParameter<int32_t>("Nxbins"),
0650                                                     Parameters.getParameter<double>("xmin"),
0651                                                     Parameters.getParameter<double>("xmax"),
0652                                                     Parameters.getParameter<int32_t>("Nybins"),
0653                                                     Parameters.getParameter<double>("ymin"),
0654                                                     Parameters.getParameter<double>("ymax"));
0655       else
0656         local_mes.PositionOfDigisP = nullptr;
0657 
0658       if (clsFlag_) {
0659         Parameters = config_.getParameter<edm::ParameterSet>("ClusterPositionPH");
0660         HistoName.str("");
0661         HistoName << "ClusterPositionP";
0662         if (Parameters.getParameter<bool>("switch"))
0663           local_mes.ClusterPositionP = ibooker.book2D(HistoName.str(),
0664                                                       HistoName.str(),
0665                                                       Parameters.getParameter<int32_t>("Nxbins"),
0666                                                       Parameters.getParameter<double>("xmin"),
0667                                                       Parameters.getParameter<double>("xmax"),
0668                                                       Parameters.getParameter<int32_t>("Nybins"),
0669                                                       Parameters.getParameter<double>("ymin"),
0670                                                       Parameters.getParameter<double>("ymax"));
0671         else
0672           local_mes.ClusterPositionP = nullptr;
0673       }
0674     }
0675 
0676     // Plots for Standalone clusters (Can be switched on from configs)
0677     if (clsFlag_) {
0678       Parameters = config_.getParameter<edm::ParameterSet>("NumberOfClustersPerDetH");
0679       HistoName.str("");
0680       HistoName << "NumberOfClustersPerDet";
0681       if (Parameters.getParameter<bool>("switch"))
0682         local_mes.NumberOfClustersPerDet = ibooker.book1D(HistoName.str(),
0683                                                           HistoName.str(),
0684                                                           Parameters.getParameter<int32_t>("Nbins"),
0685                                                           Parameters.getParameter<double>("xmin"),
0686                                                           Parameters.getParameter<double>("xmax"));
0687       else
0688         local_mes.NumberOfClustersPerDet = nullptr;
0689 
0690       Parameters = config_.getParameter<edm::ParameterSet>("ClusterWidthH");
0691       HistoName.str("");
0692       HistoName << "ClusterWidth";
0693       if (Parameters.getParameter<bool>("switch"))
0694         local_mes.ClusterWidth = ibooker.book1D(HistoName.str(),
0695                                                 HistoName.str(),
0696                                                 Parameters.getParameter<int32_t>("Nbins"),
0697                                                 Parameters.getParameter<double>("xmin"),
0698                                                 Parameters.getParameter<double>("xmax"));
0699       else
0700         local_mes.ClusterWidth = nullptr;
0701     }
0702 
0703     layerMEs.insert(std::make_pair(key, local_mes));
0704   }
0705 }
0706 
0707 std::string Phase2TrackerMonitorDigi::getHistoId(uint32_t det_id, bool flag) {
0708   if (flag)
0709     return phase2tkutil::getITHistoId(det_id, tTopo_);
0710   else
0711     return phase2tkutil::getOTHistoId(det_id, tTopo_);
0712 }
0713 
0714 void Phase2TrackerMonitorDigi::fillDigiClusters(DigiMEs& mes, std::vector<Ph2DigiCluster>& digi_clusters) {
0715   int nclus = digi_clusters.size();
0716   if (mes.NumberOfClustersPerDet)
0717     mes.NumberOfClustersPerDet->Fill(nclus);
0718   for (auto& iclus : digi_clusters) {
0719     if (mes.ClusterWidth)
0720       mes.ClusterWidth->Fill(iclus.width);
0721     if (pixelFlag_ && mes.ChargeOfDigisVsWidth)
0722       mes.ChargeOfDigisVsWidth->Fill(iclus.charge, iclus.width);
0723     if (mes.ClusterPositionP)
0724       mes.ClusterPositionP->Fill(iclus.position, iclus.column + 1);
0725     if (!pixelFlag_ && mes.ClusterPositionS && iclus.column <= 2)
0726       mes.ClusterPositionS->Fill(iclus.position, iclus.column + 1);
0727   }
0728 }
0729 //define this as a plug-in
0730 DEFINE_FWK_MODULE(Phase2TrackerMonitorDigi);