Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-25 22:37:43

0001 // -*- C++ -*-
0002 //bookLayer
0003 // Package:    Phase2ITMonitorCluster
0004 // Class:      Phase2ITMonitorCluster
0005 //
0006 /**\class Phase2ITMonitorCluster Phase2ITMonitorCluster.cc 
0007 
0008  Description: DQM plots tracker clusters. 
0009 
0010 */
0011 //
0012 // Author: Gabriel Ramirez
0013 // Date: May 23, 2020
0014 #include <memory>
0015 #include "FWCore/Framework/interface/MakerMacros.h"
0016 #include "FWCore/Framework/interface/ESWatcher.h"
0017 #include "FWCore/Framework/interface/Frameworkfwd.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0021 #include "FWCore/Framework/interface/Event.h"
0022 #include "FWCore/Framework/interface/ESHandle.h"
0023 #include "FWCore/ServiceRegistry/interface/Service.h"
0024 #include "FWCore/Utilities/interface/InputTag.h"
0025 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0026 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0027 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0028 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0029 #include "DataFormats/Common/interface/DetSetVector.h"
0030 #include "DataFormats/Common/interface/Handle.h"
0031 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0032 #include "DataFormats/DetId/interface/DetId.h"
0033 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
0034 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0035 // DQM Histograming
0036 #include "DQMServices/Core/interface/MonitorElement.h"
0037 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0038 #include "DQMServices/Core/interface/DQMStore.h"
0039 
0040 class Phase2ITMonitorCluster : public DQMEDAnalyzer {
0041 public:
0042   explicit Phase2ITMonitorCluster(const edm::ParameterSet&);
0043   ~Phase2ITMonitorCluster() override;
0044   void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) override;
0045   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0046   void dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) override;
0047   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0048 
0049 private:
0050   struct ClusterMEs {
0051     MonitorElement* nClusters = nullptr;
0052     MonitorElement* ClusterSize = nullptr;
0053     MonitorElement* ClusterSizeX = nullptr;
0054     MonitorElement* ClusterSizeY = nullptr;
0055     MonitorElement* ClusterCharge = nullptr;
0056     MonitorElement* XYGlobalPositionMapPixel = nullptr;
0057     MonitorElement* XYLocalPositionMapPixel = nullptr;
0058   };
0059 
0060   MonitorElement* numberClusters_;
0061   MonitorElement* globalXY_barrel_;
0062   MonitorElement* globalXY_endcap_;
0063   MonitorElement* globalRZ_barrel_;
0064   MonitorElement* globalRZ_endcap_;
0065 
0066   void bookLayerHistos(DQMStore::IBooker& ibooker, uint32_t det_it, std::string& subdir);
0067 
0068   std::map<std::string, ClusterMEs> layerMEs_;
0069   edm::ParameterSet config_;
0070   edm::EDGetTokenT<edmNew::DetSetVector<SiPixelCluster>> itPixelClusterToken_;
0071   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
0072   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoToken_;
0073   const TrackerGeometry* tkGeom_ = nullptr;
0074   const TrackerTopology* tTopo_ = nullptr;
0075 };
0076 #include "DQM/SiTrackerPhase2/interface/TrackerPhase2DQMUtil.h"
0077 //
0078 // constructors
0079 //
0080 Phase2ITMonitorCluster::Phase2ITMonitorCluster(const edm::ParameterSet& iConfig)
0081     : config_(iConfig),
0082       itPixelClusterToken_(consumes<edmNew::DetSetVector<SiPixelCluster>>(
0083           config_.getParameter<edm::InputTag>("InnerPixelClusterSource"))),
0084       geomToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>()),
0085       topoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()) {
0086   edm::LogInfo("Phase2ITMonitorCluster") << ">>> Construct Phase2ITMonitorCluster ";
0087 }
0088 
0089 Phase2ITMonitorCluster::~Phase2ITMonitorCluster() {
0090   edm::LogInfo("Phase2ITMonitorCluster") << ">>> Destroy Phase2ITMonitorCluster ";
0091 }
0092 //
0093 // -- DQM Begin Run
0094 void Phase2ITMonitorCluster::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0095   tkGeom_ = &iSetup.getData(geomToken_);
0096   tTopo_ = &iSetup.getData(topoToken_);
0097 }
0098 
0099 //
0100 // -- Analyze
0101 //
0102 void Phase2ITMonitorCluster::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0103   // Getting the clusters
0104   const auto& itPixelClusterHandle = iEvent.getHandle(itPixelClusterToken_);
0105   // Number of clusters
0106   std::map<std::string, unsigned int> nClsmap;
0107   unsigned int nclusGlobal = 0;
0108   for (const auto& DSVItr : *itPixelClusterHandle) {
0109     uint32_t rawid(DSVItr.detId());
0110     DetId detId(rawid);
0111     const GeomDet* geomDet = tkGeom_->idToDet(detId);
0112     if (!geomDet)
0113       continue;
0114     const GeomDetUnit* geomDetUnit(tkGeom_->idToDetUnit(detId));
0115     if (!geomDetUnit)
0116       continue;
0117     nclusGlobal += DSVItr.size();
0118     std::string folderkey = phase2tkutil::getITHistoId(detId, tTopo_);
0119     // initialize the nhit counters if they don't exist for this layer
0120     auto counterDet = nClsmap.find(folderkey);
0121     if (counterDet == nClsmap.end()) {
0122       nClsmap.emplace(folderkey, DSVItr.size());
0123     } else
0124       counterDet->second += DSVItr.size();
0125     for (const auto& clusterItr : DSVItr) {
0126       MeasurementPoint mpCluster(clusterItr.x(), clusterItr.y());
0127       Local3DPoint localPosCluster = geomDetUnit->topology().localPosition(mpCluster);
0128       Global3DPoint globalPosCluster = geomDetUnit->surface().toGlobal(localPosCluster);
0129       double gx = globalPosCluster.x() * 10.;
0130       double gy = globalPosCluster.y() * 10.;
0131       double gz = globalPosCluster.z() * 10.;
0132       double gr = globalPosCluster.perp() * 10.;
0133 
0134       // cluster size
0135       if (geomDetUnit->subDetector() == GeomDetEnumerators::SubDetector::P2PXB) {
0136         globalXY_barrel_->Fill(gx, gy);
0137         globalRZ_barrel_->Fill(gz, gr);
0138       } else if (geomDetUnit->subDetector() == GeomDetEnumerators::SubDetector::P2PXEC) {
0139         globalXY_endcap_->Fill(gx, gy);
0140         globalRZ_endcap_->Fill(gz, gr);
0141       }
0142       auto local_mesIT = layerMEs_.find(folderkey);
0143       if (local_mesIT == layerMEs_.end())
0144         continue;
0145       ClusterMEs& local_mes = local_mesIT->second;
0146       if (local_mes.XYGlobalPositionMapPixel)  //make this optional
0147         local_mes.XYGlobalPositionMapPixel->Fill(globalPosCluster.z(), globalPosCluster.perp());
0148       local_mes.XYLocalPositionMapPixel->Fill(localPosCluster.x(), localPosCluster.y());
0149       local_mes.ClusterSize->Fill(clusterItr.size());
0150       local_mes.ClusterSizeX->Fill(clusterItr.sizeX());
0151       local_mes.ClusterSizeY->Fill(clusterItr.sizeY());
0152       local_mes.ClusterCharge->Fill(clusterItr.charge());
0153     }
0154   }
0155 
0156   for (const auto& it : nClsmap) {
0157     if (layerMEs_.find(it.first) == layerMEs_.end())
0158       continue;
0159     layerMEs_[it.first].nClusters->Fill(it.second);
0160   }
0161   numberClusters_->Fill(nclusGlobal);  //global histo of #clusters
0162 }
0163 
0164 //
0165 // -- Book Histograms
0166 //
0167 void Phase2ITMonitorCluster::bookHistograms(DQMStore::IBooker& ibooker,
0168                                             edm::Run const& iRun,
0169                                             edm::EventSetup const& iSetup) {
0170   std::string top_folder = config_.getParameter<std::string>("TopFolderName");
0171   std::stringstream folder_name;
0172 
0173   ibooker.cd();
0174   folder_name << top_folder << "/";
0175   ibooker.setCurrentFolder(folder_name.str());
0176 
0177   edm::LogInfo("Phase2ITMonitorCluster") << " Booking Histograms in: " << folder_name.str();
0178 
0179   numberClusters_ = phase2tkutil::book1DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalNClusters"), ibooker);
0180 
0181   globalXY_barrel_ =
0182       phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_PXB"), ibooker);
0183 
0184   globalRZ_barrel_ =
0185       phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionRZ_PXB"), ibooker);
0186 
0187   globalXY_endcap_ =
0188       phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_PXEC"), ibooker);
0189 
0190   globalRZ_endcap_ =
0191       phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionRZ_PXEC"), ibooker);
0192 
0193   //Now book layer wise histos
0194   edm::ESWatcher<TrackerDigiGeometryRecord> theTkDigiGeomWatcher;
0195   if (theTkDigiGeomWatcher.check(iSetup)) {
0196     for (auto const& det_u : tkGeom_->detUnits()) {
0197       //Always check TrackerNumberingBuilder before changing this part
0198       if (!(det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXB ||
0199             det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXEC))
0200         continue;
0201       unsigned int detId_raw = det_u->geographicalId().rawId();
0202       edm::LogInfo("Phase2ITMonitorRecHit") << "Detid:" << detId_raw << "\tsubdet=" << det_u->subDetector()
0203                                             << "\t key=" << phase2tkutil::getITHistoId(detId_raw, tTopo_) << std::endl;
0204       bookLayerHistos(ibooker, detId_raw, top_folder);
0205     }
0206   }
0207 }
0208 
0209 //////////////////Layer Histo/////////////////////////////////
0210 void Phase2ITMonitorCluster::bookLayerHistos(DQMStore::IBooker& ibooker, uint32_t det_id, std::string& subdir) {
0211   std::string folderName = phase2tkutil::getITHistoId(det_id, tTopo_);
0212   if (folderName.empty())
0213     return;
0214 
0215   std::map<std::string, ClusterMEs>::iterator pos = layerMEs_.find(folderName);
0216 
0217   if (pos == layerMEs_.end()) {
0218     ibooker.cd();
0219     ibooker.setCurrentFolder(subdir + "/" + folderName);
0220 
0221     edm::LogInfo("Phase2ITMonitorCluster") << " Booking Histograms in: " << subdir + "/" + folderName;
0222 
0223     ClusterMEs local_mes;
0224 
0225     local_mes.nClusters =
0226         phase2tkutil::book1DFromPSet(config_.getParameter<edm::ParameterSet>("NClustersLayer"), ibooker);
0227 
0228     local_mes.ClusterSize =
0229         phase2tkutil::book1DFromPSet(config_.getParameter<edm::ParameterSet>("ClusterSize"), ibooker);
0230 
0231     local_mes.ClusterSizeX =
0232         phase2tkutil::book1DFromPSet(config_.getParameter<edm::ParameterSet>("ClusterSizeX"), ibooker);
0233 
0234     local_mes.ClusterSizeY =
0235         phase2tkutil::book1DFromPSet(config_.getParameter<edm::ParameterSet>("ClusterSizeY"), ibooker);
0236 
0237     local_mes.ClusterCharge =
0238         phase2tkutil::book1DFromPSet(config_.getParameter<edm::ParameterSet>("ClusterCharge"), ibooker);
0239 
0240     local_mes.XYLocalPositionMapPixel =
0241         phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("LocalPositionXY"), ibooker);
0242 
0243     local_mes.XYGlobalPositionMapPixel =
0244         phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_perlayer"), ibooker);
0245 
0246     layerMEs_.emplace(folderName, local_mes);
0247   }
0248 }
0249 
0250 void Phase2ITMonitorCluster::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0251   // clusterITMonitor
0252   edm::ParameterSetDescription desc;
0253   //Global Histos
0254   {
0255     edm::ParameterSetDescription psd0;
0256     psd0.add<std::string>("name", "NumberOfClusters");
0257     psd0.add<std::string>("title", "NumberClusters;Number of Clusters;");
0258     psd0.add<double>("xmin", 0.0);
0259     psd0.add<bool>("switch", true);
0260     psd0.add<double>("xmax", 300000.0);
0261     psd0.add<int>("NxBins", 150);
0262     desc.add<edm::ParameterSetDescription>("GlobalNClusters", psd0);
0263   }
0264   {
0265     edm::ParameterSetDescription psd0;
0266     psd0.add<std::string>("name", "Global_Position_RZ_IT_barrel");
0267     psd0.add<std::string>("title", "Global_Position_RZ_IT_barrel;z [mm];r [mm]");
0268     psd0.add<double>("ymax", 300.0);
0269     psd0.add<int>("NxBins", 1500);
0270     psd0.add<int>("NyBins", 300);
0271     psd0.add<bool>("switch", true);
0272     psd0.add<double>("xmax", 3000.0);
0273     psd0.add<double>("xmin", -3000.0);
0274     psd0.add<double>("ymin", 0.0);
0275     desc.add<edm::ParameterSetDescription>("GlobalPositionRZ_PXB", psd0);
0276   }
0277   {
0278     edm::ParameterSetDescription psd0;
0279     psd0.add<std::string>("name", "Global_Position_XY_IT_barrel");
0280     psd0.add<std::string>("title", "Global_Position_XY_IT_barrel;x [mm];y [mm];");
0281     psd0.add<double>("ymax", 300.0);
0282     psd0.add<int>("NxBins", 600);
0283     psd0.add<int>("NyBins", 600);
0284     psd0.add<bool>("switch", true);
0285     psd0.add<double>("xmax", 300.0);
0286     psd0.add<double>("xmin", -300.0);
0287     psd0.add<double>("ymin", -300.0);
0288     desc.add<edm::ParameterSetDescription>("GlobalPositionXY_PXB", psd0);
0289   }
0290   {
0291     edm::ParameterSetDescription psd0;
0292     psd0.add<std::string>("name", "Global_Position_RZ_IT_endcap");
0293     psd0.add<std::string>("title", "Global_Position_RZ_IT_endcap;z [mm];r [mm]");
0294     psd0.add<double>("ymax", 300.0);
0295     psd0.add<int>("NxBins", 1500);
0296     psd0.add<int>("NyBins", 300);
0297     psd0.add<bool>("switch", true);
0298     psd0.add<double>("xmax", 3000.0);
0299     psd0.add<double>("xmin", -3000.0);
0300     psd0.add<double>("ymin", 0.0);
0301     desc.add<edm::ParameterSetDescription>("GlobalPositionRZ_PXEC", psd0);
0302   }
0303   {
0304     edm::ParameterSetDescription psd0;
0305     psd0.add<std::string>("name", "Global_Position_XY_IT_endcap");
0306     psd0.add<std::string>("title", "Global_Position_XY_IT_endcap; x [mm]; y [mm]");
0307     psd0.add<double>("ymax", 300.0);
0308     psd0.add<int>("NxBins", 600);
0309     psd0.add<int>("NyBins", 600);
0310     psd0.add<bool>("switch", true);
0311     psd0.add<double>("xmax", 300.0);
0312     psd0.add<double>("xmin", -300.0);
0313     psd0.add<double>("ymin", -300.0);
0314     desc.add<edm::ParameterSetDescription>("GlobalPositionXY_PXEC", psd0);
0315   }
0316   //Local histos
0317   //Per layer/ring histos
0318   {
0319     edm::ParameterSetDescription psd0;
0320     psd0.add<std::string>("name", "NumberOfClustersLayer");
0321     psd0.add<std::string>("title", "NumberOfClutsers;Number of Clusters;");
0322     psd0.add<double>("xmin", 0.0);
0323     psd0.add<bool>("switch", true);
0324     psd0.add<double>("xmax", 20000.0);
0325     psd0.add<int>("NxBins", 150);
0326     desc.add<edm::ParameterSetDescription>("NClustersLayer", psd0);
0327   }
0328   {
0329     edm::ParameterSetDescription psd0;
0330     psd0.add<std::string>("name", "ClusterCharge");
0331     psd0.add<std::string>("title", ";Cluster charge;");
0332     psd0.add<double>("xmin", 0.);
0333     psd0.add<bool>("switch", true);
0334     psd0.add<double>("xmax", 100000.);
0335     psd0.add<int>("NxBins", 100);
0336     desc.add<edm::ParameterSetDescription>("ClusterCharge", psd0);
0337   }
0338   {
0339     edm::ParameterSetDescription psd0;
0340     psd0.add<std::string>("name", "ClusterSize");
0341     psd0.add<std::string>("title", ";Cluster size;");
0342     psd0.add<double>("xmin", -0.5);
0343     psd0.add<double>("xmax", 30.5);
0344     psd0.add<int>("NxBins", 31);
0345     psd0.add<bool>("switch", true);
0346     desc.add<edm::ParameterSetDescription>("ClusterSize", psd0);
0347   }
0348   {
0349     edm::ParameterSetDescription psd0;
0350     psd0.add<std::string>("name", "ClusterSizeY");
0351     psd0.add<std::string>("title", ";Cluster sizeY;");
0352     psd0.add<double>("xmin", -0.5);
0353     psd0.add<bool>("switch", true);
0354     psd0.add<double>("xmax", 30.5);
0355     psd0.add<int>("NxBins", 31);
0356     desc.add<edm::ParameterSetDescription>("ClusterSizeY", psd0);
0357   }
0358   {
0359     edm::ParameterSetDescription psd0;
0360     psd0.add<std::string>("name", "ClusterSizeX");
0361     psd0.add<std::string>("title", ";Cluster sizeX;");
0362     psd0.add<double>("xmin", -0.5);
0363     psd0.add<bool>("switch", true);
0364     psd0.add<double>("xmax", 30.5);
0365     psd0.add<int>("NxBins", 31);
0366     desc.add<edm::ParameterSetDescription>("ClusterSizeX", psd0);
0367   }
0368   {
0369     edm::ParameterSetDescription psd0;
0370     psd0.add<std::string>("name", "Local_ClusterPosition_XY");
0371     psd0.add<std::string>("title", "Local_ClusterPosition_XY; x; y");
0372     psd0.add<double>("ymax", 0.0);
0373     psd0.add<int>("NxBins", 500);
0374     psd0.add<int>("NyBins", 500);
0375     psd0.add<bool>("switch", true);
0376     psd0.add<double>("xmax", 0.0);
0377     psd0.add<double>("xmin", 0.0);
0378     psd0.add<double>("ymin", 0.0);
0379     desc.add<edm::ParameterSetDescription>("LocalPositionXY", psd0);
0380   }
0381   {
0382     edm::ParameterSetDescription psd0;
0383     psd0.add<std::string>("name", "GlobalPositionXY_perlayer");
0384     psd0.add<std::string>("title", "GlobalClusterPositionXY_perlayer;x [mm];y [mm];");
0385     psd0.add<double>("ymax", 300.0);
0386     psd0.add<int>("NxBins", 600);
0387     psd0.add<int>("NyBins", 600);
0388     psd0.add<bool>("switch", false);
0389     psd0.add<double>("xmax", 300.0);
0390     psd0.add<double>("xmin", -300.0);
0391     psd0.add<double>("ymin", -300.0);
0392     desc.add<edm::ParameterSetDescription>("GlobalPositionXY_perlayer", psd0);
0393   }
0394 
0395   desc.add<std::string>("TopFolderName", "TrackerPhase2ITCluster");
0396   desc.add<edm::InputTag>("InnerPixelClusterSource", edm::InputTag("siPixelClusters"));
0397   descriptions.add("Phase2ITMonitorCluster", desc);
0398 }
0399 
0400 DEFINE_FWK_MODULE(Phase2ITMonitorCluster);