Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-11 04:33:34

0001 // Package:    Phase2ITValidateRecHit
0002 // Class:      Phase2ITValidateRecHit
0003 //
0004 /**\class Phase2ITValidateRecHit Phase2ITValidateRecHit.cc 
0005  Description:  Plugin for Phase2 RecHit validation
0006 */
0007 //
0008 // Author: Shubhi Parolia, Suvankar Roy Chowdhury
0009 // Date: June 2020
0010 //
0011 // system include files
0012 #include <memory>
0013 #include <map>
0014 #include <vector>
0015 #include <algorithm>
0016 #include "FWCore/MessageLogger/interface/MessageLogger.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/MakerMacros.h"
0021 #include "FWCore/Framework/interface/ESHandle.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 #include "FWCore/ServiceRegistry/interface/Service.h"
0024 #include "FWCore/Utilities/interface/InputTag.h"
0025 #include "DataFormats/Common/interface/Handle.h"
0026 #include "DataFormats/Common/interface/DetSetVector.h"
0027 #include "DataFormats/DetId/interface/DetId.h"
0028 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0029 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
0030 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0031 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0032 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0033 #include "Geometry/CommonDetUnit/interface/TrackerGeomDet.h"
0034 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0035 #include "Geometry/CommonDetUnit/interface/PixelGeomDetType.h"
0036 //--- for SimHit association
0037 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
0038 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0039 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0040 #include "SimTracker/TrackerHitAssociation/interface/TrackerHitAssociator.h"
0041 //DQM
0042 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0043 #include "DQMServices/Core/interface/DQMStore.h"
0044 #include "DQMServices/Core/interface/MonitorElement.h"
0045 // base class
0046 #include "Validation/SiTrackerPhase2V/interface/Phase2ITValidateRecHitBase.h"
0047 #include "DQM/SiTrackerPhase2/interface/TrackerPhase2DQMUtil.h"
0048 
0049 class Phase2ITValidateRecHit : public Phase2ITValidateRecHitBase {
0050 public:
0051   explicit Phase2ITValidateRecHit(const edm::ParameterSet&);
0052   ~Phase2ITValidateRecHit() override;
0053   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0054 
0055   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0056 
0057 private:
0058   void fillITHistos(const edm::Event& iEvent,
0059                     const TrackerHitAssociator& associateRecHit,
0060                     const std::vector<edm::Handle<edm::PSimHitContainer>>& simHits,
0061                     const std::map<unsigned int, SimTrack>& selectedSimTrackMap);
0062 
0063   edm::ParameterSet config_;
0064   TrackerHitAssociator::Config trackerHitAssociatorConfig_;
0065   const double simtrackminpt_;
0066   const edm::EDGetTokenT<SiPixelRecHitCollection> tokenRecHitsIT_;
0067   const edm::EDGetTokenT<edm::SimTrackContainer> simTracksToken_;
0068   std::vector<edm::EDGetTokenT<edm::PSimHitContainer>> simHitTokens_;
0069 };
0070 
0071 Phase2ITValidateRecHit::Phase2ITValidateRecHit(const edm::ParameterSet& iConfig)
0072     : Phase2ITValidateRecHitBase(iConfig),
0073       config_(iConfig),
0074       trackerHitAssociatorConfig_(iConfig, consumesCollector()),
0075       simtrackminpt_(iConfig.getParameter<double>("SimTrackMinPt")),
0076       tokenRecHitsIT_(consumes<SiPixelRecHitCollection>(iConfig.getParameter<edm::InputTag>("rechitsSrc"))),
0077       simTracksToken_(consumes<edm::SimTrackContainer>(iConfig.getParameter<edm::InputTag>("simTracksSrc"))) {
0078   edm::LogInfo("Phase2ITValidateRecHit") << ">>> Construct Phase2ITValidateRecHit ";
0079   for (const auto& itName : config_.getParameter<std::vector<std::string>>("ROUList")) {
0080     simHitTokens_.push_back(consumes<std::vector<PSimHit>>(edm::InputTag("g4SimHits", itName)));
0081   }
0082 }
0083 //
0084 Phase2ITValidateRecHit::~Phase2ITValidateRecHit() {
0085   edm::LogInfo("Phase2ITValidateRecHit") << ">>> Destroy Phase2ITValidateRecHit ";
0086 }
0087 
0088 void Phase2ITValidateRecHit::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0089   std::vector<edm::Handle<edm::PSimHitContainer>> simHits;
0090   for (const auto& itoken : simHitTokens_) {
0091     const auto& simHitHandle = iEvent.getHandle(itoken);
0092     if (!simHitHandle.isValid())
0093       continue;
0094     simHits.emplace_back(simHitHandle);
0095   }
0096   // Get the SimTracks and push them in a map of id, SimTrack
0097   const auto& simTracks = iEvent.getHandle(simTracksToken_);
0098 
0099   std::map<unsigned int, SimTrack> selectedSimTrackMap;
0100   for (const auto& simTrackIt : *simTracks) {
0101     if (simTrackIt.momentum().pt() > simtrackminpt_) {
0102       selectedSimTrackMap.emplace(simTrackIt.trackId(), simTrackIt);
0103     }
0104   }
0105   TrackerHitAssociator associateRecHit(iEvent, trackerHitAssociatorConfig_);
0106   fillITHistos(iEvent, associateRecHit, simHits, selectedSimTrackMap);
0107 }
0108 
0109 void Phase2ITValidateRecHit::fillITHistos(const edm::Event& iEvent,
0110                                           const TrackerHitAssociator& associateRecHit,
0111                                           const std::vector<edm::Handle<edm::PSimHitContainer>>& simHits,
0112                                           const std::map<unsigned int, SimTrack>& selectedSimTrackMap) {
0113   // Get the RecHits
0114   const auto& rechits = iEvent.getHandle(tokenRecHitsIT_);
0115   if (!rechits.isValid())
0116     return;
0117   std::map<std::string, unsigned int> nrechitLayerMap_primary;
0118   // Loop over modules
0119   for (const auto& DSViter : *rechits) {
0120     // Get the detector unit's id
0121     unsigned int rawid(DSViter.detId());
0122     DetId detId(rawid);
0123     // determine the detector we are in
0124     std::string key = phase2tkutil::getITHistoId(detId.rawId(), tTopo_);
0125     if (nrechitLayerMap_primary.find(key) == nrechitLayerMap_primary.end()) {
0126       nrechitLayerMap_primary.emplace(key, DSViter.size());
0127     } else {
0128       nrechitLayerMap_primary[key] += DSViter.size();
0129     }
0130     //loop over rechits for a single detId
0131     for (const auto& rechit : DSViter) {
0132       //GetSimHits
0133       const std::vector<SimHitIdpr>& matchedId = associateRecHit.associateHitId(rechit);
0134       const PSimHit* simhitClosest = nullptr;
0135       float minx = 10000;
0136       LocalPoint lp = rechit.localPosition();
0137       for (const auto& simHitCol : simHits) {
0138         for (const auto& simhitIt : *simHitCol) {
0139           if (detId.rawId() != simhitIt.detUnitId())
0140             continue;
0141           for (const auto& mId : matchedId) {
0142             if (simhitIt.trackId() == mId.first) {
0143               if (!simhitClosest || abs(simhitIt.localPosition().x() - lp.x()) < minx) {
0144                 minx = std::abs(simhitIt.localPosition().x() - lp.x());
0145                 simhitClosest = &simhitIt;
0146               }
0147             }
0148           }
0149         }  //end loop over PSimhitcontainers
0150       }  //end loop over simHits
0151       if (!simhitClosest)
0152         continue;
0153 
0154       // call the base class method to fill the plots
0155       fillRechitHistos(simhitClosest, &rechit, selectedSimTrackMap, nrechitLayerMap_primary);
0156 
0157     }  //end loop over rechits of a detId
0158   }  //End loop over DetSetVector
0159 
0160   //fill nRecHit counter per layer
0161   for (const auto& lme : nrechitLayerMap_primary) {
0162     layerMEs_[lme.first].numberRecHitsprimary->Fill(nrechitLayerMap_primary[lme.first]);
0163   }
0164 }
0165 
0166 void Phase2ITValidateRecHit::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0167   // rechitValidIT
0168   edm::ParameterSetDescription desc;
0169 
0170   // call the base fillPsetDescription for the plots bookings
0171   Phase2ITValidateRecHitBase::fillPSetDescription(desc);
0172 
0173   //to be used in TrackerHitAssociator
0174   desc.add<bool>("associatePixel", true);
0175   desc.add<bool>("associateStrip", false);
0176   desc.add<bool>("usePhase2Tracker", true);
0177   desc.add<bool>("associateRecoTracks", false);
0178   desc.add<bool>("associateHitbySimTrack", true);
0179   desc.add<edm::InputTag>("pixelSimLinkSrc", edm::InputTag("simSiPixelDigis", "Pixel"));
0180   desc.add<std::vector<std::string>>("ROUList",
0181                                      {
0182                                          "TrackerHitsPixelBarrelLowTof",
0183                                          "TrackerHitsPixelBarrelHighTof",
0184                                          "TrackerHitsPixelEndcapLowTof",
0185                                          "TrackerHitsPixelEndcapHighTof",
0186                                      });
0187   //
0188   desc.add<edm::InputTag>("simTracksSrc", edm::InputTag("g4SimHits"));
0189   desc.add<edm::InputTag>("SimVertexSource", edm::InputTag("g4SimHits"));
0190   desc.add<double>("SimTrackMinPt", 2.0);
0191   desc.add<edm::InputTag>("rechitsSrc", edm::InputTag("siPixelRecHits"));
0192   desc.add<std::string>("TopFolderName", "TrackerPhase2ITRecHitV");
0193   desc.add<bool>("Verbosity", false);
0194   descriptions.add("Phase2ITValidateRecHit", desc);
0195 }
0196 //define this as a plug-in
0197 DEFINE_FWK_MODULE(Phase2ITValidateRecHit);