Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    SiPixelMonitorCluster
0004 // Class:      SiPixelClusterSource
0005 //
0006 /**\class
0007 
0008  Description: Pixel DQM source for Clusters
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Vincenzo Chiochia & Andrew York
0015 //         Created:
0016 //
0017 //
0018 // Updated by: Lukas Wehrli
0019 // for pixel offline DQM
0020 #include "DQM/SiPixelMonitorCluster/interface/SiPixelClusterSource.h"
0021 // Framework
0022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0023 #include "FWCore/ServiceRegistry/interface/Service.h"
0024 #include "FWCore/Framework/interface/MakerMacros.h"
0025 // DQM Framework
0026 #include "DQM/SiPixelCommon/interface/SiPixelFolderOrganizer.h"
0027 #include "DQMServices/Core/interface/DQMStore.h"
0028 // Geometry
0029 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
0030 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0031 // DataFormats
0032 #include "DataFormats/DetId/interface/DetId.h"
0033 #include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
0034 #include "DataFormats/SiPixelDetId/interface/PixelBarrelNameUpgrade.h"
0035 #include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
0036 #include "DataFormats/SiPixelDetId/interface/PixelEndcapNameUpgrade.h"
0037 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0038 //
0039 #include <cstdlib>
0040 #include <string>
0041 
0042 using namespace std;
0043 using namespace edm;
0044 
0045 SiPixelClusterSource::SiPixelClusterSource(const edm::ParameterSet &iConfig)
0046     : conf_(iConfig),
0047       src_(conf_.getParameter<edm::InputTag>("src")),
0048       digisrc_(conf_.getParameter<edm::InputTag>("digisrc")),
0049       saveFile(conf_.getUntrackedParameter<bool>("saveFile", false)),
0050       isPIB(conf_.getUntrackedParameter<bool>("isPIB", false)),
0051       slowDown(conf_.getUntrackedParameter<bool>("slowDown", false)),
0052       modOn(conf_.getUntrackedParameter<bool>("modOn", true)),
0053       twoDimOn(conf_.getUntrackedParameter<bool>("twoDimOn", true)),
0054       reducedSet(conf_.getUntrackedParameter<bool>("reducedSet", false)),
0055       ladOn(conf_.getUntrackedParameter<bool>("ladOn", false)),
0056       layOn(conf_.getUntrackedParameter<bool>("layOn", false)),
0057       phiOn(conf_.getUntrackedParameter<bool>("phiOn", false)),
0058       ringOn(conf_.getUntrackedParameter<bool>("ringOn", false)),
0059       bladeOn(conf_.getUntrackedParameter<bool>("bladeOn", false)),
0060       diskOn(conf_.getUntrackedParameter<bool>("diskOn", false)),
0061       smileyOn(conf_.getUntrackedParameter<bool>("smileyOn", false)),
0062       bigEventSize(conf_.getUntrackedParameter<int>("bigEventSize", 100)),
0063       isUpgrade(conf_.getUntrackedParameter<bool>("isUpgrade", false)),
0064       noOfLayers(0),
0065       noOfDisks(0) {
0066   LogInfo("PixelDQM") << "SiPixelClusterSource::SiPixelClusterSource: Got DQM BackEnd interface" << endl;
0067 
0068   // set Token(-s)
0069   srcToken_ = consumes<edmNew::DetSetVector<SiPixelCluster>>(conf_.getParameter<edm::InputTag>("src"));
0070   digisrcToken_ = consumes<edm::DetSetVector<PixelDigi>>(conf_.getParameter<edm::InputTag>("digisrc"));
0071 
0072   trackerTopoToken_ = esConsumes<TrackerTopology, TrackerTopologyRcd>();
0073   trackerGeomToken_ = esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>();
0074   trackerTopoTokenBeginRun_ = esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>();
0075   trackerGeomTokenBeginRun_ = esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>();
0076 
0077   firstRun = true;
0078   topFolderName_ = conf_.getParameter<std::string>("TopFolderName");
0079 }
0080 
0081 SiPixelClusterSource::~SiPixelClusterSource() {
0082   // do anything here that needs to be done at desctruction time
0083   // (e.g. close files, deallocate resources etc.)
0084   LogInfo("PixelDQM") << "SiPixelClusterSource::~SiPixelClusterSource: Destructor" << endl;
0085 
0086   std::map<uint32_t, SiPixelClusterModule *>::iterator struct_iter;
0087   for (struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++) {
0088     delete struct_iter->second;
0089     struct_iter->second = nullptr;
0090   }
0091 }
0092 
0093 void SiPixelClusterSource::dqmBeginRun(const edm::Run &r, const edm::EventSetup &iSetup) {
0094   LogInfo("PixelDQM") << " SiPixelClusterSource::beginJob - Initialisation ... " << std::endl;
0095   LogInfo("PixelDQM") << "Mod/Lad/Lay/Phi " << modOn << "/" << ladOn << "/" << layOn << "/" << phiOn << std::endl;
0096   LogInfo("PixelDQM") << "Blade/Disk/Ring" << bladeOn << "/" << diskOn << "/" << ringOn << std::endl;
0097   LogInfo("PixelDQM") << "2DIM IS " << twoDimOn << "\n";
0098   LogInfo("PixelDQM") << "Smiley (Cluster sizeY vs. Cluster eta) is " << smileyOn << "\n";
0099 
0100   if (firstRun) {
0101     eventNo = 0;
0102     lumSec = 0;
0103     nLumiSecs = 0;
0104     nBigEvents = 0;
0105     // Build map
0106     buildStructure(iSetup);
0107 
0108     firstRun = false;
0109   }
0110 }
0111 
0112 void SiPixelClusterSource::bookHistograms(DQMStore::IBooker &iBooker, edm::Run const &, const edm::EventSetup &iSetup) {
0113   bookMEs(iBooker, iSetup);
0114   // Book occupancy maps in global coordinates for all clusters:
0115   iBooker.setCurrentFolder(topFolderName_ + "/Clusters/OffTrack");
0116   // bpix
0117   std::stringstream ss1, ss2;
0118   for (int i = 1; i <= noOfLayers; i++) {
0119     ss1.str(std::string());
0120     ss1 << "position_siPixelClusters_Layer_" << i;
0121     ss2.str(std::string());
0122     ss2 << "Clusters Layer" << i << ";Global Z (cm);Global #phi";
0123     meClPosLayer.push_back(iBooker.book2D(ss1.str(), ss2.str(), 200, -30., 30., 128, -3.2, 3.2));
0124   }
0125   for (int i = 1; i <= noOfDisks; i++) {
0126     ss1.str(std::string());
0127     ss1 << "position_siPixelClusters_pz_Disk_" << i;
0128     ss2.str(std::string());
0129     ss2 << "Clusters +Z Disk" << i << ";Global X (cm);Global Y (cm)";
0130     meClPosDiskpz.push_back(iBooker.book2D(ss1.str(), ss2.str(), 80, -20., 20., 80, -20., 20.));
0131     ss1.str(std::string());
0132     ss1 << "position_siPixelClusters_mz_Disk_" << i;
0133     ss2.str(std::string());
0134     ss2 << "Clusters -Z Disk" << i << ";Global X (cm);Global Y (cm)";
0135     meClPosDiskmz.push_back(iBooker.book2D(ss1.str(), ss2.str(), 80, -20., 20., 80, -20., 20.));
0136   }
0137 
0138   // Book trend cluster plots for barrel and endcap. Lumisections for offline
0139   // and second for online - taken from strips
0140   iBooker.setCurrentFolder(topFolderName_ + "/Barrel");
0141   ss1.str(std::string());
0142   ss1 << "totalNumberOfClustersProfile_siPixelClusters_Barrel";
0143   ss2.str(std::string());
0144   ss2 << "Total number of barrel clusters profile;Lumisection;";
0145   meClusBarrelProf = iBooker.bookProfile(ss1.str(), ss2.str(), 2400, 0., 150, 0, 0, "");
0146   meClusBarrelProf->getTH1()->SetCanExtend(TH1::kAllAxes);
0147 
0148   iBooker.setCurrentFolder(topFolderName_ + "/Endcap");
0149 
0150   ss1.str(std::string());
0151   ss1 << "totalNumberOfClustersProfile_siPixelClusters_FPIX+";
0152   ss2.str(std::string());
0153   ss2 << "Total number of FPIX+ clusters profile;Lumisection;";
0154   meClusFpixPProf = iBooker.bookProfile(ss1.str(), ss2.str(), 2400, 0., 150, 0, 0, "");
0155   meClusFpixPProf->getTH1()->SetCanExtend(TH1::kAllAxes);
0156 
0157   ss1.str(std::string());
0158   ss1 << "totalNumberOfClustersProfile_siPixelClusters_FPIX-";
0159   ss2.str(std::string());
0160   ss2 << "Total number of FPIX- clusters profile;Lumisection;";
0161   meClusFpixMProf = iBooker.bookProfile(ss1.str(), ss2.str(), 2400, 0., 150, 0, 0, "");
0162   meClusFpixMProf->getTH1()->SetCanExtend(TH1::kAllAxes);
0163 
0164   iBooker.setCurrentFolder(topFolderName_ + "/Barrel");
0165   for (int i = 1; i <= noOfLayers; i++) {
0166     int ybins = -1;
0167     float ymin = 0.;
0168     float ymax = 0.;
0169     if (i == 1) {
0170       ybins = 42;
0171       ymin = -10.5;
0172       ymax = 10.5;
0173     }
0174     if (i == 2) {
0175       ybins = 66;
0176       ymin = -16.5;
0177       ymax = 16.5;
0178     }
0179     if (i == 3) {
0180       ybins = 90;
0181       ymin = -22.5;
0182       ymax = 22.5;
0183     }
0184     if (i == 4) {
0185       ybins = 130;
0186       ymin = -32.5;
0187       ymax = 32.5;
0188     }
0189     ss1.str(std::string());
0190     ss1 << "pix_bar Occ_roc_online_" + digisrc_.label() + "_layer_" << i;
0191     ss2.str(std::string());
0192     ss2 << "Pixel Barrel Occupancy, ROC level (Online): Layer " << i;
0193     meZeroRocBPIX.push_back(iBooker.book2D(ss1.str(), ss2.str(), 72, -4.5, 4.5, ybins, ymin, ymax));
0194     meZeroRocBPIX.at(i - 1)->setAxisTitle("ROC / Module", 1);
0195     meZeroRocBPIX.at(i - 1)->setAxisTitle("ROC / Ladder", 2);
0196   }
0197 
0198   iBooker.setCurrentFolder(topFolderName_ + "/Endcap");
0199   meZeroRocFPIX = iBooker.book2D(
0200       "ROC_endcap_occupancy", "Pixel Endcap Occupancy, ROC level (Online)", 72, -4.5, 4.5, 288, -12.5, 12.5);
0201   meZeroRocFPIX->setBinLabel(1, "Disk-2 Pnl2", 1);
0202   meZeroRocFPIX->setBinLabel(9, "Disk-2 Pnl1", 1);
0203   meZeroRocFPIX->setBinLabel(19, "Disk-1 Pnl2", 1);
0204   meZeroRocFPIX->setBinLabel(27, "Disk-1 Pnl1", 1);
0205   meZeroRocFPIX->setBinLabel(41, "Disk+1 Pnl1", 1);
0206   meZeroRocFPIX->setBinLabel(49, "Disk+1 Pnl2", 1);
0207   meZeroRocFPIX->setBinLabel(59, "Disk+2 Pnl1", 1);
0208   meZeroRocFPIX->setBinLabel(67, "Disk+2 Pnl2", 1);
0209   meZeroRocFPIX->setAxisTitle("Blades in Inner (>0) / Outer(<) Halves", 2);
0210   meZeroRocFPIX->setAxisTitle("ROC occupancy", 3);
0211 }
0212 
0213 //------------------------------------------------------------------
0214 // Method called for every event
0215 //------------------------------------------------------------------
0216 void SiPixelClusterSource::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0217   eventNo++;
0218 
0219   if (meClPosLayer.at(0) && meClPosLayer.at(0)->getEntries() > 150000) {
0220     for (int i = 0; i < noOfLayers; i++) {
0221       meClPosLayer.at(i)->Reset();
0222     }
0223     for (int i = 0; i < noOfDisks; i++) {
0224       meClPosDiskpz.at(i)->Reset();
0225       meClPosDiskmz.at(i)->Reset();
0226     }
0227   }
0228 
0229   // get input data
0230   edm::Handle<edmNew::DetSetVector<SiPixelCluster>> input;
0231   iEvent.getByToken(srcToken_, input);
0232   auto const &clustColl = *(input.product());
0233 
0234   edm::ESHandle<TrackerGeometry> pDD = iSetup.getHandle(trackerGeomToken_);
0235   const TrackerGeometry *tracker = &(*pDD);
0236 
0237   edm::Handle<edm::DetSetVector<PixelDigi>> digiinput;
0238   iEvent.getByToken(digisrcToken_, digiinput);
0239   const edm::DetSetVector<PixelDigi> diginp = *(digiinput.product());
0240 
0241   edm::ESHandle<TrackerTopology> tTopoHandle = iSetup.getHandle(trackerTopoToken_);
0242   const TrackerTopology *pTT = tTopoHandle.product();
0243 
0244   int lumiSection = (int)iEvent.luminosityBlock();
0245   int nEventFpixClusters = 0;
0246 
0247   int nEventsBarrel = 0;
0248   int nEventsFPIXm = 0;
0249   int nEventsFPIXp = 0;
0250 
0251   std::map<uint32_t, SiPixelClusterModule *>::iterator struct_iter;
0252   for (struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++) {
0253     int numberOfFpixClusters = (*struct_iter)
0254                                    .second->fill(*input,
0255                                                  pTT,
0256                                                  tracker,
0257                                                  &nEventsBarrel,
0258                                                  &nEventsFPIXp,
0259                                                  &nEventsFPIXm,
0260                                                  meClPosLayer,
0261                                                  meClPosDiskpz,
0262                                                  meClPosDiskmz,
0263                                                  modOn,
0264                                                  ladOn,
0265                                                  layOn,
0266                                                  phiOn,
0267                                                  bladeOn,
0268                                                  diskOn,
0269                                                  ringOn,
0270                                                  twoDimOn,
0271                                                  reducedSet,
0272                                                  smileyOn,
0273                                                  isUpgrade);
0274     nEventFpixClusters = nEventFpixClusters + numberOfFpixClusters;
0275   }
0276 
0277   if (nEventFpixClusters > bigEventSize) {
0278     if (bigFpixClusterEventRate) {
0279       bigFpixClusterEventRate->Fill(lumiSection, 1. / 23.);
0280     }
0281   }
0282 
0283   float trendVar = iEvent.orbitNumber() / 262144.0;  // lumisection : seconds - matches strip trend plot
0284 
0285   meClusBarrelProf->Fill(trendVar, nEventsBarrel);
0286   meClusFpixPProf->Fill(trendVar, nEventsFPIXp);
0287   meClusFpixMProf->Fill(trendVar, nEventsFPIXm);
0288 
0289   // std::cout<<"nEventFpixClusters: "<<nEventFpixClusters<<" , nLumiSecs:
0290   // "<<nLumiSecs<<" , nBigEvents: "<<nBigEvents<<std::endl;
0291 
0292   for (TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++) {
0293     DetId detId = (*it)->geographicalId();
0294 
0295     // fill barrel
0296     if (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
0297       getrococcupancy(detId, diginp, pTT, meZeroRocBPIX);
0298     }
0299 
0300     // fill endcap
0301     if (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) {
0302       getrococcupancye(detId, clustColl, pTT, pDD, meZeroRocFPIX);
0303     }
0304   }
0305 
0306   // slow down...
0307   if (slowDown)
0308     usleep(10000);
0309 }
0310 
0311 //------------------------------------------------------------------
0312 // Build data structure
0313 //------------------------------------------------------------------
0314 void SiPixelClusterSource::buildStructure(const edm::EventSetup &iSetup) {
0315   LogInfo("PixelDQM") << " SiPixelClusterSource::buildStructure";
0316   edm::ESHandle<TrackerGeometry> pDD = iSetup.getHandle(trackerGeomTokenBeginRun_);
0317 
0318   edm::ESHandle<TrackerTopology> tTopoHandle = iSetup.getHandle(trackerTopoTokenBeginRun_);
0319   const TrackerTopology *pTT = tTopoHandle.product();
0320 
0321   LogVerbatim("PixelDQM") << " *** Geometry node for TrackerGeom is  " << &(*pDD) << std::endl;
0322   LogVerbatim("PixelDQM") << " *** I have " << pDD->dets().size() << " detectors" << std::endl;
0323   LogVerbatim("PixelDQM") << " *** I have " << pDD->detTypes().size() << " types" << std::endl;
0324 
0325   for (TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++) {
0326     if (dynamic_cast<PixelGeomDetUnit const *>((*it)) != nullptr) {
0327       DetId detId = (*it)->geographicalId();
0328       const GeomDetUnit *geoUnit = pDD->idToDetUnit(detId);
0329       const PixelGeomDetUnit *pixDet = dynamic_cast<const PixelGeomDetUnit *>(geoUnit);
0330       int nrows = (pixDet->specificTopology()).nrows();
0331       int ncols = (pixDet->specificTopology()).ncolumns();
0332 
0333       if ((detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) ||
0334           (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap))) {
0335         uint32_t id = detId();
0336         if (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
0337           if (isPIB)
0338             continue;
0339           LogDebug("PixelDQM") << " ---> Adding Barrel Module " << detId.rawId() << endl;
0340           int layer = PixelBarrelName(DetId(id), pTT, isUpgrade).layerName();
0341           if (layer > noOfLayers)
0342             noOfLayers = layer;
0343           SiPixelClusterModule *theModule = new SiPixelClusterModule(id, ncols, nrows);
0344           thePixelStructure.insert(pair<uint32_t, SiPixelClusterModule *>(id, theModule));
0345         } else if (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) {
0346           LogDebug("PixelDQM") << " ---> Adding Endcap Module " << detId.rawId() << endl;
0347           int disk = PixelEndcapName(DetId(id), pTT, isUpgrade).diskName();
0348           if (disk > noOfDisks)
0349             noOfDisks = disk;
0350           SiPixelClusterModule *theModule = new SiPixelClusterModule(id, ncols, nrows);
0351           thePixelStructure.insert(pair<uint32_t, SiPixelClusterModule *>(id, theModule));
0352         }
0353       }
0354     }
0355   }
0356   LogInfo("PixelDQM") << " *** Pixel Structure Size " << thePixelStructure.size() << endl;
0357 }
0358 //------------------------------------------------------------------
0359 // Book MEs
0360 //------------------------------------------------------------------
0361 void SiPixelClusterSource::bookMEs(DQMStore::IBooker &iBooker, const edm::EventSetup &iSetup) {
0362   // Get DQM interface
0363   iBooker.setCurrentFolder(topFolderName_);
0364   char title[256];
0365   snprintf(title,
0366            256,
0367            "Rate of events with >%i FPIX clusters;LumiSection;Rate of large "
0368            "FPIX events per LS [Hz]",
0369            bigEventSize);
0370   bigFpixClusterEventRate = iBooker.book1D("bigFpixClusterEventRate", title, 5000, 0., 5000.);
0371 
0372   std::map<uint32_t, SiPixelClusterModule *>::iterator struct_iter;
0373 
0374   SiPixelFolderOrganizer theSiPixelFolder(false);
0375 
0376   edm::ESHandle<TrackerTopology> tTopoHandle = iSetup.getHandle(trackerTopoTokenBeginRun_);
0377   const TrackerTopology *pTT = tTopoHandle.product();
0378 
0379   for (struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++) {
0380     /// Create folder tree and book histograms
0381     if (modOn) {
0382       if (theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 0, isUpgrade)) {
0383         (*struct_iter).second->book(conf_, pTT, iBooker, 0, twoDimOn, reducedSet, isUpgrade);
0384       } else {
0385         if (!isPIB)
0386           throw cms::Exception("LogicError") << "[SiPixelClusterSource::bookMEs] Creation of DQM folder "
0387                                                 "failed";
0388       }
0389     }
0390     if (ladOn) {
0391       if (theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 1, isUpgrade)) {
0392         (*struct_iter).second->book(conf_, pTT, iBooker, 1, twoDimOn, reducedSet, isUpgrade);
0393       } else {
0394         LogDebug("PixelDQM") << "PROBLEM WITH LADDER-FOLDER\n";
0395       }
0396     }
0397     if (layOn) {
0398       if (theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 2, isUpgrade)) {
0399         (*struct_iter).second->book(conf_, pTT, iBooker, 2, twoDimOn, reducedSet, isUpgrade);
0400       } else {
0401         LogDebug("PixelDQM") << "PROBLEM WITH LAYER-FOLDER\n";
0402       }
0403     }
0404     if (phiOn) {
0405       if (theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 3, isUpgrade)) {
0406         (*struct_iter).second->book(conf_, pTT, iBooker, 3, twoDimOn, reducedSet, isUpgrade);
0407       } else {
0408         LogDebug("PixelDQM") << "PROBLEM WITH PHI-FOLDER\n";
0409       }
0410     }
0411     if (bladeOn) {
0412       if (theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 4, isUpgrade)) {
0413         (*struct_iter).second->book(conf_, pTT, iBooker, 4, twoDimOn, reducedSet, isUpgrade);
0414       } else {
0415         LogDebug("PixelDQM") << "PROBLEM WITH BLADE-FOLDER\n";
0416       }
0417     }
0418     if (diskOn) {
0419       if (theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 5, isUpgrade)) {
0420         (*struct_iter).second->book(conf_, pTT, iBooker, 5, twoDimOn, reducedSet, isUpgrade);
0421       } else {
0422         LogDebug("PixelDQM") << "PROBLEM WITH DISK-FOLDER\n";
0423       }
0424     }
0425     if (ringOn) {
0426       if (theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 6, isUpgrade)) {
0427         (*struct_iter).second->book(conf_, pTT, iBooker, 6, twoDimOn, reducedSet, isUpgrade);
0428       } else {
0429         LogDebug("PixelDQM") << "PROBLEM WITH RING-FOLDER\n";
0430       }
0431     }
0432     if (smileyOn) {
0433       if (theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 7, isUpgrade)) {
0434         (*struct_iter).second->book(conf_, pTT, iBooker, 7, twoDimOn, reducedSet, isUpgrade);
0435       } else {
0436         LogDebug("PixelDQM") << "PROBLEM WITH BARREL-FOLDER\n";
0437       }
0438     }
0439   }
0440 }
0441 
0442 void SiPixelClusterSource::getrococcupancy(DetId detId,
0443                                            const edm::DetSetVector<PixelDigi> &diginp,
0444                                            const TrackerTopology *const tTopo,
0445                                            std::vector<MonitorElement *> const &meinput) {
0446   edm::DetSetVector<PixelDigi>::const_iterator ipxsearch = diginp.find(detId);
0447   if (ipxsearch != diginp.end()) {
0448     // Look at digis now
0449     edm::DetSet<PixelDigi>::const_iterator pxdi;
0450     for (pxdi = ipxsearch->begin(); pxdi != ipxsearch->end(); pxdi++) {
0451       bool isHalfModule = PixelBarrelName(DetId(detId), tTopo, isUpgrade).isHalfModule();
0452       int DBlayer = PixelBarrelName(DetId(detId), tTopo, isUpgrade).layerName();
0453       int DBmodule = PixelBarrelName(DetId(detId), tTopo, isUpgrade).moduleName();
0454       int DBladder = PixelBarrelName(DetId(detId), tTopo, isUpgrade).ladderName();
0455       int DBshell = PixelBarrelName(DetId(detId), tTopo, isUpgrade).shell();
0456 
0457       // add sign to the modules
0458       if (DBshell == 1 || DBshell == 2) {
0459         DBmodule = -DBmodule;
0460       }
0461       if (DBshell == 1 || DBshell == 3) {
0462         DBladder = -DBladder;
0463       }
0464 
0465       int col = pxdi->column();
0466       int row = pxdi->row();
0467 
0468       float modsign = (float)DBmodule / (abs((float)DBmodule));
0469       float ladsign = (float)DBladder / (abs((float)DBladder));
0470       float rocx = ((float)col / (52. * 8.)) * modsign + ((float)DBmodule - (modsign) * 0.5);
0471       float rocy = ((float)row / (80. * 2.)) * ladsign + ((float)DBladder - (ladsign) * 0.5);
0472 
0473       // do the flip where need
0474       bool flip = false;
0475       if ((DBladder % 2 == 0) && (!isHalfModule)) {
0476         flip = true;
0477       }
0478       if ((flip) && (DBladder > 0)) {
0479         if ((((float)DBladder - (ladsign) * 0.5) <= rocy) && (rocy < (float)DBladder)) {
0480           rocy = rocy + ladsign * 0.5;
0481         } else if ((((float)DBladder) <= rocy) && (rocy < ((float)DBladder + (ladsign) * 0.5))) {
0482           rocy = rocy - ladsign * 0.5;
0483         }
0484       }
0485 
0486       // tweak border effect for negative modules/ladders
0487       if (modsign < 0) {
0488         rocx = rocx - 0.0001;
0489       }
0490       if (ladsign < 0) {
0491         rocy = rocy - 0.0001;
0492       } else {
0493         rocy = rocy + 0.0001;
0494       }
0495       if (abs(DBladder) == 1) {
0496         rocy = rocy + ladsign * 0.5;
0497       }  // take care of the half module
0498       meinput[DBlayer - 1]->Fill(rocx, rocy);
0499     }  // end of looping over pxdi
0500   }
0501 }
0502 
0503 void SiPixelClusterSource::getrococcupancye(DetId detId,
0504                                             const edmNew::DetSetVector<SiPixelCluster> &clustColl,
0505                                             const TrackerTopology *const pTT,
0506                                             edm::ESHandle<TrackerGeometry> pDD,
0507                                             MonitorElement *meinput) {
0508   edmNew::DetSetVector<SiPixelCluster>::const_iterator ipxsearch = clustColl.find(detId);
0509   if (ipxsearch != clustColl.end()) {
0510     // Look at clusters now
0511     edmNew::DetSet<SiPixelCluster>::const_iterator pxclust;
0512     for (pxclust = ipxsearch->begin(); pxclust != ipxsearch->end(); pxclust++) {
0513       const GeomDetUnit *geoUnit = pDD->idToDetUnit(detId);
0514       const PixelGeomDetUnit *pixDet = dynamic_cast<const PixelGeomDetUnit *>(geoUnit);
0515       const PixelTopology *topol = &(pixDet->specificTopology());
0516       LocalPoint clustlp = topol->localPosition(MeasurementPoint(pxclust->x(), pxclust->y()));
0517       GlobalPoint clustgp = geoUnit->surface().toGlobal(clustlp);
0518 
0519       float xclust = pxclust->x();
0520       float yclust = pxclust->y();
0521       float z = clustgp.z();
0522 
0523       int pxfside = PixelEndcapName(detId, pTT, isUpgrade).halfCylinder();
0524       int pxfpanel = PixelEndcapName(detId, pTT, isUpgrade).pannelName();
0525       int pxfmodule = PixelEndcapName(detId, pTT, isUpgrade).plaquetteName();
0526       int pxfdisk = PixelEndcapName(detId, pTT, isUpgrade).diskName();
0527       int pxfblade = PixelEndcapName(detId, pTT, isUpgrade).bladeName();
0528 
0529       if ((pxfside == 1) || (pxfside == 3)) {
0530         pxfblade = -1. * pxfblade;
0531       }
0532 
0533       if (z < 0.) {
0534         pxfdisk = -1. * pxfdisk;
0535       }
0536 
0537       int clu_sdpx = ((pxfdisk > 0) ? 1 : -1) * (2 * (abs(pxfdisk) - 1) + pxfpanel);
0538       int binselx = (pxfpanel == 1 && (pxfmodule == 1 || pxfmodule == 4))
0539                         ? (pxfmodule == 1)
0540                         : ((pxfpanel == 1 && xclust < 80.0) || (pxfpanel == 2 && xclust >= 80.0));
0541       int nperpan = 2 * pxfmodule + pxfpanel - 1 + binselx;
0542       int clu_roc_binx =
0543           ((pxfdisk > 0) ? nperpan : 9 - nperpan) + (clu_sdpx + 4) * 8 - 2 * ((abs(pxfdisk) == 1) ? pxfdisk : 0);
0544 
0545       int clu_roc_biny = -99.;
0546       int nrocly = pxfmodule + pxfpanel;
0547       for (int i = 0; i < nrocly; i++) {
0548         int j = (pxfdisk < 0) ? i : nrocly - 1 - i;
0549         if (yclust >= (j * 52.0) && yclust < ((j + 1) * 52.0))
0550           clu_roc_biny = 6 - nrocly + 2 * i + ((pxfblade > 0) ? pxfblade - 1 : pxfblade + 12) * 12 + 1;
0551       }
0552       if (pxfblade > 0) {
0553         clu_roc_biny = clu_roc_biny + 144;
0554       }
0555 
0556       meinput->setBinContent(clu_roc_binx, clu_roc_biny, meinput->getBinContent(clu_roc_binx, clu_roc_biny) + 1);
0557       meinput->setBinContent(
0558           clu_roc_binx, clu_roc_biny + 1, meinput->getBinContent(clu_roc_binx, clu_roc_biny + 1) + 1);
0559     }
0560   }
0561 }
0562 
0563 // define this as a plug-in
0564 DEFINE_FWK_MODULE(SiPixelClusterSource);