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:    Phase2OTMonitorCluster
0004 // Class:      Phase2OTMonitorCluster
0005 //
0006 /**\class Phase2OTMonitorCluster Phase2OTMonitorCluster.cc 
0007 
0008  Description: Validation plots tracker clusters. 
0009 
0010 */
0011 //
0012 // Author: Gabriel Ramirez
0013 // Date: May 23, 2020
0014 //
0015 #include <memory>
0016 #include "FWCore/Framework/interface/MakerMacros.h"
0017 #include "FWCore/Framework/interface/ESWatcher.h"
0018 #include "FWCore/Framework/interface/Frameworkfwd.h"
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/ESHandle.h"
0021 #include "FWCore/ServiceRegistry/interface/Service.h"
0022 #include "FWCore/Utilities/interface/InputTag.h"
0023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0026 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0027 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0028 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0029 #include "DataFormats/Common/interface/DetSetVector.h"
0030 #include "DataFormats/Common/interface/Handle.h"
0031 #include "DataFormats/DetId/interface/DetId.h"
0032 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
0033 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0034 #include "DataFormats/Phase2TrackerCluster/interface/Phase2TrackerCluster1D.h"
0035 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0036 // DQM Histograming
0037 #include "DQMServices/Core/interface/MonitorElement.h"
0038 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0039 #include "DQMServices/Core/interface/DQMStore.h"
0040 
0041 class Phase2OTMonitorCluster : public DQMEDAnalyzer {
0042 public:
0043   explicit Phase2OTMonitorCluster(const edm::ParameterSet&);
0044   ~Phase2OTMonitorCluster() override;
0045   void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) override;
0046   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0047   void dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) override;
0048   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0049 
0050 private:
0051   struct ClusterMEs {
0052     MonitorElement* nClusters_P = nullptr;
0053     MonitorElement* ClusterSize_P = nullptr;
0054     MonitorElement* XYGlobalPositionMap_P = nullptr;
0055     MonitorElement* XYLocalPositionMap_P = nullptr;
0056 
0057     MonitorElement* nClusters_S = nullptr;
0058     MonitorElement* ClusterSize_S = nullptr;
0059     MonitorElement* XYGlobalPositionMap_S = nullptr;
0060     MonitorElement* XYLocalPositionMap_S = nullptr;
0061   };
0062   MonitorElement* numberClusters_;
0063   MonitorElement* globalXY_P_;
0064   MonitorElement* globalRZ_P_;
0065   MonitorElement* globalXY_S_;
0066   MonitorElement* globalRZ_S_;
0067 
0068   void fillOTHistos(const edm::Event& iEvent);
0069 
0070   void bookLayerHistos(DQMStore::IBooker& ibooker, uint32_t det_it, std::string& subdir);
0071 
0072   std::map<std::string, ClusterMEs> layerMEs_;
0073 
0074   edm::ParameterSet config_;
0075   edm::EDGetTokenT<Phase2TrackerCluster1DCollectionNew> clustersToken_;
0076   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
0077   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoToken_;
0078   const TrackerGeometry* tkGeom_ = nullptr;
0079   const TrackerTopology* tTopo_ = nullptr;
0080 };
0081 #include "DQM/SiTrackerPhase2/interface/TrackerPhase2DQMUtil.h"
0082 //
0083 // constructors
0084 //
0085 Phase2OTMonitorCluster::Phase2OTMonitorCluster(const edm::ParameterSet& iConfig)
0086     : config_(iConfig),
0087       clustersToken_(consumes<Phase2TrackerCluster1DCollectionNew>(config_.getParameter<edm::InputTag>("clusterSrc"))),
0088       geomToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>()),
0089       topoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()) {
0090   edm::LogInfo("Phase2OTMonitorCluster") << ">>> Construct Phase2OTMonitorCluster ";
0091 }
0092 
0093 Phase2OTMonitorCluster::~Phase2OTMonitorCluster() {
0094   edm::LogInfo("Phase2OTMonitorCluster") << ">>> Destroy Phase2OTMonitorCluster ";
0095 }
0096 //
0097 // -- DQM Begin Run
0098 void Phase2OTMonitorCluster::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0099   tkGeom_ = &iSetup.getData(geomToken_);
0100   tTopo_ = &iSetup.getData(topoToken_);
0101 }
0102 //
0103 // -- Analyze
0104 //
0105 void Phase2OTMonitorCluster::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0106   // Getting the clusters
0107   const auto& clusterHandle = iEvent.getHandle(clustersToken_);
0108   // Number of clusters
0109   std::map<std::string, unsigned int> nClustersCounter_P;  //map of detidkey vs #cls
0110   std::map<std::string, unsigned int> nClustersCounter_S;  //map of detidkey vs #cls
0111   unsigned int nclus = 0;                                  //global counter
0112   for (const auto& DSVItr : *clusterHandle) {
0113     // Getting the id of detector unit
0114     uint32_t rawid(DSVItr.detId());
0115     DetId detId(rawid);
0116     const GeomDetUnit* geomDetUnit(tkGeom_->idToDetUnit(detId));
0117     if (!geomDetUnit)
0118       continue;
0119 
0120     std::string folderkey = phase2tkutil::getOTHistoId(detId, tTopo_);
0121 
0122     TrackerGeometry::ModuleType mType = tkGeom_->getDetectorType(detId);
0123     // initialize the nhit counters if they don't exist for this layer
0124     //the check on the detId is needed to avoid checking at the filling stage
0125     if (mType == TrackerGeometry::ModuleType::Ph2PSP) {
0126       auto counterDet = nClustersCounter_P.find(folderkey);
0127       if (counterDet == nClustersCounter_P.end())
0128         nClustersCounter_P.emplace(folderkey, DSVItr.size());
0129       else
0130         counterDet->second += DSVItr.size();
0131     } else if (mType == TrackerGeometry::ModuleType::Ph2PSS || mType == TrackerGeometry::ModuleType::Ph2SS) {
0132       auto counterDet = nClustersCounter_S.find(folderkey);
0133       if (counterDet == nClustersCounter_S.end())
0134         nClustersCounter_S.emplace(folderkey, DSVItr.size());
0135       else
0136         counterDet->second += DSVItr.size();
0137     }
0138     nclus += DSVItr.size();
0139 
0140     for (const auto& clusterItr : DSVItr) {
0141       MeasurementPoint mpCluster(clusterItr.center(), clusterItr.column() + 0.5);
0142       Local3DPoint localPosCluster = geomDetUnit->topology().localPosition(mpCluster);
0143       Global3DPoint globalPosCluster = geomDetUnit->surface().toGlobal(localPosCluster);
0144       double gx = globalPosCluster.x() * 10.;
0145       double gy = globalPosCluster.y() * 10.;
0146       double gz = globalPosCluster.z() * 10.;
0147       double gr = globalPosCluster.perp() * 10.;
0148       auto layerMEit = layerMEs_.find(folderkey);
0149       if (layerMEit == layerMEs_.end())
0150         continue;
0151       ClusterMEs& local_mes = layerMEit->second;
0152       if (mType == TrackerGeometry::ModuleType::Ph2PSP) {
0153         globalXY_P_->Fill(gx, gy);
0154         globalRZ_P_->Fill(gz, gr);
0155         local_mes.ClusterSize_P->Fill(clusterItr.size());
0156         local_mes.XYLocalPositionMap_P->Fill(localPosCluster.x(), localPosCluster.y());
0157 
0158         if (local_mes.XYGlobalPositionMap_P != nullptr)  //make this optional
0159           local_mes.XYGlobalPositionMap_P->Fill(gx, gy);
0160       } else if (mType == TrackerGeometry::ModuleType::Ph2PSS || mType == TrackerGeometry::ModuleType::Ph2SS) {
0161         globalXY_S_->Fill(gx, gy);
0162         globalRZ_S_->Fill(gz, gr);
0163         local_mes.ClusterSize_S->Fill(clusterItr.size());
0164         local_mes.XYLocalPositionMap_S->Fill(localPosCluster.x(), localPosCluster.y());
0165 
0166         if (local_mes.XYGlobalPositionMap_S != nullptr)  //make this optional
0167           local_mes.XYGlobalPositionMap_S->Fill(gx, gy);
0168       }
0169     }
0170   }
0171   for (const auto& it : nClustersCounter_P) {
0172     if (layerMEs_.find(it.first) == layerMEs_.end())
0173       continue;
0174     if (layerMEs_[it.first].nClusters_P != nullptr)  //this check should not be required though
0175       layerMEs_[it.first].nClusters_P->Fill(it.second);
0176   }
0177   for (const auto& it : nClustersCounter_S) {
0178     if (layerMEs_.find(it.first) == layerMEs_.end())
0179       continue;
0180     if (layerMEs_[it.first].nClusters_S != nullptr)  //this check should not be required though
0181       layerMEs_[it.first].nClusters_S->Fill(it.second);
0182   }
0183   numberClusters_->Fill(nclus);
0184 }
0185 
0186 //
0187 // -- Book Histograms
0188 //
0189 void Phase2OTMonitorCluster::bookHistograms(DQMStore::IBooker& ibooker,
0190                                             edm::Run const& iRun,
0191                                             edm::EventSetup const& iSetup) {
0192   std::string top_folder = config_.getParameter<std::string>("TopFolderName");
0193   ibooker.cd();
0194   ibooker.setCurrentFolder(top_folder);
0195   edm::LogInfo("Phase2OTMonitorCluster") << " Booking Histograms in: " << top_folder;
0196 
0197   numberClusters_ = phase2tkutil::book1DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalNClusters"), ibooker);
0198 
0199   globalXY_P_ = phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_P"), ibooker);
0200 
0201   globalRZ_P_ = phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionRZ_P"), ibooker);
0202 
0203   globalXY_S_ = phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_S"), ibooker);
0204 
0205   globalRZ_S_ = phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionRZ_S"), ibooker);
0206 
0207   //Now book layer wise histos
0208   edm::ESWatcher<TrackerDigiGeometryRecord> theTkDigiGeomWatcher;
0209   if (theTkDigiGeomWatcher.check(iSetup)) {
0210     for (auto const& det_u : tkGeom_->detUnits()) {
0211       //Always check TrackerNumberingBuilder before changing this part
0212       //continue if Pixel
0213       if ((det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXB ||
0214            det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXEC))
0215         continue;
0216       unsigned int detId_raw = det_u->geographicalId().rawId();
0217       edm::LogInfo("Phase2ITMonitorRecHit") << "Detid:" << detId_raw << "\tsubdet=" << det_u->subDetector()
0218                                             << "\t key=" << phase2tkutil::getITHistoId(detId_raw, tTopo_) << std::endl;
0219       bookLayerHistos(ibooker, detId_raw, top_folder);
0220     }
0221   }
0222 }
0223 
0224 //////////////////Layer Histo/////////////////////////////////
0225 void Phase2OTMonitorCluster::bookLayerHistos(DQMStore::IBooker& ibooker, uint32_t det_id, std::string& subdir) {
0226   std::string folderName = phase2tkutil::getOTHistoId(det_id, tTopo_);
0227   if (folderName.empty()) {
0228     edm::LogWarning("Phase2OTMonitorCluster") << ">>>> Invalid histo_id ";
0229     return;
0230   }
0231   if (layerMEs_.find(folderName) == layerMEs_.end()) {
0232     ibooker.cd();
0233     ibooker.setCurrentFolder(subdir + "/" + folderName);
0234     edm::LogInfo("Phase2OTMonitorCluster") << " Booking Histograms in: " << subdir + "/" + folderName;
0235     ClusterMEs local_mes;
0236     TrackerGeometry::ModuleType mType = tkGeom_->getDetectorType(det_id);
0237     if (mType == TrackerGeometry::ModuleType::Ph2PSP) {
0238       local_mes.nClusters_P =
0239           phase2tkutil::book1DFromPSet(config_.getParameter<edm::ParameterSet>("NClustersLayer_P"), ibooker);
0240       local_mes.ClusterSize_P =
0241           phase2tkutil::book1DFromPSet(config_.getParameter<edm::ParameterSet>("ClusterSize_P"), ibooker);
0242       local_mes.XYGlobalPositionMap_P =
0243           phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_perlayer_P"), ibooker);
0244       local_mes.XYLocalPositionMap_P =
0245           phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("LocalPositionXY_P"), ibooker);
0246     }
0247 
0248     local_mes.nClusters_S =
0249         phase2tkutil::book1DFromPSet(config_.getParameter<edm::ParameterSet>("NClustersLayer_S"), ibooker);
0250 
0251     local_mes.ClusterSize_S =
0252         phase2tkutil::book1DFromPSet(config_.getParameter<edm::ParameterSet>("ClusterSize_S"), ibooker);
0253 
0254     local_mes.XYGlobalPositionMap_S =
0255         phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_perlayer_S"), ibooker);
0256 
0257     local_mes.XYLocalPositionMap_S =
0258         phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("LocalPositionXY_S"), ibooker);
0259 
0260     layerMEs_.emplace(folderName, local_mes);
0261   }  //if block layerME find
0262 }
0263 
0264 void Phase2OTMonitorCluster::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0265   // rechitMonitorOT
0266   edm::ParameterSetDescription desc;
0267   {
0268     edm::ParameterSetDescription psd0;
0269     psd0.add<std::string>("name", "NumberOfClusters");
0270     psd0.add<std::string>("title", ";Number of clusters per event;");
0271     psd0.add<double>("xmin", 0.0);
0272     psd0.add<bool>("switch", true);
0273     psd0.add<double>("xmax", 350000.0);
0274     psd0.add<int>("NxBins", 150);
0275     desc.add<edm::ParameterSetDescription>("GlobalNClusters", psd0);
0276   }
0277   {
0278     edm::ParameterSetDescription psd0;
0279     psd0.add<std::string>("name", "Global_ClusterPosition_XY_P");
0280     psd0.add<std::string>("title", "Global_ClusterPosition_XY_P;x [mm];y [mm];");
0281     psd0.add<int>("NxBins", 1250);
0282     psd0.add<double>("xmin", -1250.0);
0283     psd0.add<double>("xmax", 1250.0);
0284     psd0.add<int>("NyBins", 1250);
0285     psd0.add<double>("ymin", -1250.0);
0286     psd0.add<double>("ymax", 1250.0);
0287     psd0.add<bool>("switch", true);
0288     desc.add<edm::ParameterSetDescription>("GlobalPositionXY_P", psd0);
0289   }
0290   {
0291     edm::ParameterSetDescription psd0;
0292     psd0.add<std::string>("name", "Global_ClusterPosition_XY_S");
0293     psd0.add<std::string>("title", "Global_ClusterPosition_XY_S;x [mm];y [mm];");
0294     psd0.add<int>("NxBins", 1250);
0295     psd0.add<double>("xmin", -1250.0);
0296     psd0.add<double>("xmax", 1250.0);
0297     psd0.add<int>("NyBins", 1250);
0298     psd0.add<double>("ymin", -1250.0);
0299     psd0.add<double>("ymax", 1250.0);
0300     psd0.add<bool>("switch", true);
0301     desc.add<edm::ParameterSetDescription>("GlobalPositionXY_S", psd0);
0302   }
0303 
0304   {
0305     edm::ParameterSetDescription psd0;
0306     psd0.add<std::string>("name", "Global_ClusterPosition_RZ_P");
0307     psd0.add<std::string>("title", "Global_ClusterPosition_RZ_P;z [mm];r [mm]");
0308     psd0.add<int>("NxBins", 1500);
0309     psd0.add<double>("xmin", -3000.0);
0310     psd0.add<double>("xmax", 3000.0);
0311     psd0.add<int>("NyBins", 1250);
0312     psd0.add<double>("ymin", 0.0);
0313     psd0.add<double>("ymax", 1250.0);
0314     psd0.add<bool>("switch", true);
0315     desc.add<edm::ParameterSetDescription>("GlobalPositionRZ_P", psd0);
0316   }
0317   {
0318     edm::ParameterSetDescription psd0;
0319     psd0.add<std::string>("name", "Global_ClusterPosition_RZ_S");
0320     psd0.add<std::string>("title", "Global_ClusterPosition_RZ_S;z [mm];r [mm]");
0321     psd0.add<int>("NxBins", 1500);
0322     psd0.add<double>("xmin", -3000.0);
0323     psd0.add<double>("xmax", 3000.0);
0324     psd0.add<int>("NyBins", 1250);
0325     psd0.add<double>("ymin", 0.0);
0326     psd0.add<double>("ymax", 1250.0);
0327     psd0.add<bool>("switch", true);
0328     desc.add<edm::ParameterSetDescription>("GlobalPositionRZ_S", psd0);
0329   }
0330   //Layer wise parameter
0331   {
0332     edm::ParameterSetDescription psd0;
0333     psd0.add<std::string>("name", "NumberOfClustersLayerP");
0334     psd0.add<std::string>("title", ";Number of clusters per event(macro pixel sensor);");
0335     psd0.add<double>("xmin", 0.0);
0336     psd0.add<double>("xmax", 28000.0);
0337     psd0.add<int>("NxBins", 150);
0338     psd0.add<bool>("switch", true);
0339     desc.add<edm::ParameterSetDescription>("NClustersLayer_P", psd0);
0340   }
0341   {
0342     edm::ParameterSetDescription psd0;
0343     psd0.add<std::string>("name", "NumberOfClustersLayerS");
0344     psd0.add<std::string>("title", ";Number of clusters per event(strip sensor);");
0345     psd0.add<double>("xmin", 0.0);
0346     psd0.add<double>("xmax", 28000.0);
0347     psd0.add<int>("NxBins", 150);
0348     psd0.add<bool>("switch", true);
0349     desc.add<edm::ParameterSetDescription>("NClustersLayer_S", psd0);
0350   }
0351   {
0352     edm::ParameterSetDescription psd0;
0353     psd0.add<std::string>("name", "ClusterSize_P");
0354     psd0.add<std::string>("title", ";cluster size(macro pixel sensor);");
0355     psd0.add<double>("xmin", -0.5);
0356     psd0.add<double>("xmax", 30.5);
0357     psd0.add<int>("NxBins", 31);
0358     psd0.add<bool>("switch", true);
0359     desc.add<edm::ParameterSetDescription>("ClusterSize_P", psd0);
0360   }
0361   {
0362     edm::ParameterSetDescription psd0;
0363     psd0.add<std::string>("name", "ClusterSize_S");
0364     psd0.add<std::string>("title", ";cluster size(strip sensor);");
0365     psd0.add<double>("xmin", -0.5);
0366     psd0.add<double>("xmax", 30.5);
0367     psd0.add<int>("NxBins", 31);
0368     psd0.add<bool>("switch", true);
0369     desc.add<edm::ParameterSetDescription>("ClusterSize_S", psd0);
0370   }
0371   {
0372     edm::ParameterSetDescription psd0;
0373     psd0.add<std::string>("name", "GlobalPositionXY_perlayer_P");
0374     psd0.add<std::string>("title", "GlobalClusterPositionXY_perlayer_P;x [mm];y [mm];");
0375     psd0.add<int>("NxBins", 1250);
0376     psd0.add<double>("xmin", -1250.0);
0377     psd0.add<double>("xmax", 1250.0);
0378     psd0.add<int>("NyBins", 1250);
0379     psd0.add<double>("ymin", -1250.0);
0380     psd0.add<double>("ymax", 1250.0);
0381     psd0.add<bool>("switch", false);
0382     desc.add<edm::ParameterSetDescription>("GlobalPositionXY_perlayer_P", psd0);
0383   }
0384   {
0385     edm::ParameterSetDescription psd0;
0386     psd0.add<std::string>("name", "GlobalPositionXY_perlayer_S");
0387     psd0.add<std::string>("title", "GlobalClusterPositionXY_perlayer_S;x [mm];y [mm];");
0388     psd0.add<int>("NxBins", 1250);
0389     psd0.add<double>("xmin", -1250.0);
0390     psd0.add<double>("xmax", 1250.0);
0391     psd0.add<int>("NyBins", 1250);
0392     psd0.add<double>("ymin", -1250.0);
0393     psd0.add<double>("ymax", 1250.0);
0394     psd0.add<bool>("switch", false);
0395     desc.add<edm::ParameterSetDescription>("GlobalPositionXY_perlayer_S", psd0);
0396   }
0397   {
0398     edm::ParameterSetDescription psd0;
0399     psd0.add<std::string>("name", "LocalPositionXY_P");
0400     psd0.add<std::string>("title", "LocalPositionXY_P;x ;y ;");
0401     psd0.add<int>("NxBins", 50);
0402     psd0.add<double>("xmin", -10.0);
0403     psd0.add<double>("xmax", 10.0);
0404     psd0.add<int>("NyBins", 50);
0405     psd0.add<double>("ymin", -10.0);
0406     psd0.add<double>("ymax", 10.0);
0407     psd0.add<bool>("switch", true);
0408     desc.add<edm::ParameterSetDescription>("LocalPositionXY_P", psd0);
0409   }
0410   {
0411     edm::ParameterSetDescription psd0;
0412     psd0.add<std::string>("name", "LocalPositionXY_S");
0413     psd0.add<std::string>("title", "LocalPositionXY_S;x ;y ;");
0414     psd0.add<int>("NxBins", 50);
0415     psd0.add<double>("xmin", -10.0);
0416     psd0.add<double>("xmax", 10.0);
0417     psd0.add<int>("NyBins", 50);
0418     psd0.add<double>("ymin", -10.0);
0419     psd0.add<double>("ymax", 10.0);
0420     psd0.add<bool>("switch", true);
0421     desc.add<edm::ParameterSetDescription>("LocalPositionXY_S", psd0);
0422   }
0423 
0424   desc.add<std::string>("TopFolderName", "TrackerPhase2OTCluster");
0425   desc.add<edm::InputTag>("clusterSrc", edm::InputTag("siPhase2Clusters"));
0426   descriptions.add("Phase2OTMonitorCluster", desc);
0427 }
0428 DEFINE_FWK_MODULE(Phase2OTMonitorCluster);