Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-18 02:12:45

0001 // Package:    Phase2ITValidateTrackingRecHit
0002 // Class:      Phase2ITValidateTrackingRecHit
0003 //
0004 /**\class Phase2ITValidateTrackingRecHit Phase2ITValidateTrackingRecHit.cc 
0005  Description:  Plugin for Phase2 TrackingRecHit 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 "DataFormats/TrackReco/interface/Track.h"
0033 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0034 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0035 #include "Geometry/CommonDetUnit/interface/TrackerGeomDet.h"
0036 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0037 #include "Geometry/CommonDetUnit/interface/PixelGeomDetType.h"
0038 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0039 //--- for SimHit association
0040 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
0041 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0042 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0043 #include "SimTracker/TrackerHitAssociation/interface/TrackerHitAssociator.h"
0044 //DQM
0045 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0046 #include "DQMServices/Core/interface/DQMStore.h"
0047 #include "DQMServices/Core/interface/MonitorElement.h"
0048 // base class
0049 #include "Validation/SiTrackerPhase2V/interface/Phase2ITValidateRecHitBase.h"
0050 #include "DQM/SiTrackerPhase2/interface/TrackerPhase2DQMUtil.h"
0051 
0052 class Phase2ITValidateTrackingRecHit : public Phase2ITValidateRecHitBase {
0053 public:
0054   explicit Phase2ITValidateTrackingRecHit(const edm::ParameterSet&);
0055   ~Phase2ITValidateTrackingRecHit() override;
0056   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0057   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0058 
0059 private:
0060   void fillITHistos(const edm::Event& iEvent,
0061                     const TrackerHitAssociator& associateRecHit,
0062                     const std::vector<edm::Handle<edm::PSimHitContainer>>& simHits,
0063                     const std::map<unsigned int, SimTrack>& selectedSimTrackMap);
0064   edm::ParameterSet config_;
0065   TrackerHitAssociator::Config trackerHitAssociatorConfig_;
0066   const double simtrackminpt_;
0067   const edm::EDGetTokenT<reco::TrackCollection> tokenTracks_;
0068   const edm::EDGetTokenT<edm::SimTrackContainer> simTracksToken_;
0069   std::vector<edm::EDGetTokenT<edm::PSimHitContainer>> simHitTokens_;
0070 };
0071 
0072 Phase2ITValidateTrackingRecHit::Phase2ITValidateTrackingRecHit(const edm::ParameterSet& iConfig)
0073     : Phase2ITValidateRecHitBase(iConfig),
0074       config_(iConfig),
0075       trackerHitAssociatorConfig_(iConfig, consumesCollector()),
0076       simtrackminpt_(iConfig.getParameter<double>("SimTrackMinPt")),
0077       tokenTracks_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracksSrc"))),
0078       simTracksToken_(consumes<edm::SimTrackContainer>(iConfig.getParameter<edm::InputTag>("simTracksSrc"))) {
0079   edm::LogInfo("Phase2ITValidateRecHit") << ">>> Construct Phase2ITValidateRecHit ";
0080   for (const auto& itName : config_.getParameter<std::vector<std::string>>("ROUList")) {
0081     simHitTokens_.push_back(consumes<std::vector<PSimHit>>(edm::InputTag("g4SimHits", itName)));
0082   }
0083 }
0084 //
0085 Phase2ITValidateTrackingRecHit::~Phase2ITValidateTrackingRecHit() {
0086   edm::LogInfo("Phase2ITValidateTrackingRecHit") << ">>> Destroy Phase2ITValidateTrackingRecHit ";
0087 }
0088 
0089 void Phase2ITValidateTrackingRecHit::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0090   std::vector<edm::Handle<edm::PSimHitContainer>> simHits;
0091   for (const auto& itoken : simHitTokens_) {
0092     const auto& simHitHandle = iEvent.getHandle(itoken);
0093     if (!simHitHandle.isValid())
0094       continue;
0095     simHits.emplace_back(simHitHandle);
0096   }
0097   // Get the SimTracks and push them in a map of id, SimTrack
0098   const auto& simTracks = iEvent.getHandle(simTracksToken_);
0099 
0100   std::map<unsigned int, SimTrack> selectedSimTrackMap;
0101   for (const auto& simTrackIt : *simTracks) {
0102     if (simTrackIt.momentum().pt() > simtrackminpt_) {
0103       selectedSimTrackMap.emplace(simTrackIt.trackId(), simTrackIt);
0104     }
0105   }
0106   TrackerHitAssociator associateRecHit(iEvent, trackerHitAssociatorConfig_);
0107   fillITHistos(iEvent, associateRecHit, simHits, selectedSimTrackMap);
0108 }
0109 
0110 void Phase2ITValidateTrackingRecHit::fillITHistos(const edm::Event& iEvent,
0111                                                   const TrackerHitAssociator& associateRecHit,
0112                                                   const std::vector<edm::Handle<edm::PSimHitContainer>>& simHits,
0113                                                   const std::map<unsigned int, SimTrack>& selectedSimTrackMap) {
0114   const auto& tracks = iEvent.getHandle(tokenTracks_);
0115   if (!tracks.isValid())
0116     return;
0117 
0118   std::map<std::string, unsigned int> nrechitLayerMap_primary;
0119 
0120   // loop over tracks
0121   for (const auto& track : *tracks) {
0122     // loop over hits
0123     for (auto const& hit : track.recHits()) {
0124       if (!hit->isValid())
0125         continue;
0126 
0127       auto id = hit->geographicalId();
0128       // check that we are in the pixel
0129       auto subdetid = (id.subdetId());
0130       if (!(subdetid == PixelSubdetector::PixelBarrel) && !(subdetid == PixelSubdetector::PixelEndcap))
0131         continue;
0132 
0133       const GeomDetUnit* geomDetunit(tkGeom_->idToDetUnit(id));
0134       if (!geomDetunit)
0135         continue;
0136       // determine the detector we are in
0137       std::string key = phase2tkutil::getITHistoId(id.rawId(), tTopo_);
0138       if (nrechitLayerMap_primary.find(key) == nrechitLayerMap_primary.end()) {
0139         nrechitLayerMap_primary.emplace(key, 1);
0140       } else {
0141         nrechitLayerMap_primary[key] += 1;
0142       }
0143 
0144       const SiPixelRecHit* rechit = dynamic_cast<const SiPixelRecHit*>(hit);
0145       if (!rechit)
0146         continue;
0147 
0148       const std::vector<SimHitIdpr>& matchedId = associateRecHit.associateHitId(*rechit);
0149       const PSimHit* simhitClosest = nullptr;
0150       float minx = 10000;
0151       LocalPoint lp = rechit->localPosition();
0152       for (const auto& simHitCol : simHits) {
0153         for (const auto& simhitIt : *simHitCol) {
0154           if (id.rawId() != simhitIt.detUnitId())
0155             continue;
0156           for (const auto& mId : matchedId) {
0157             if (simhitIt.trackId() == mId.first) {
0158               if (!simhitClosest || std::abs(simhitIt.localPosition().x() - lp.x()) < minx) {
0159                 minx = std::abs(simhitIt.localPosition().x() - lp.x());
0160                 simhitClosest = &simhitIt;
0161               }
0162             }
0163           }
0164         }  //end loop over PSimhitcontainers
0165       }    //end loop over simHits
0166 
0167       if (!simhitClosest)
0168         continue;
0169 
0170       // call the base class method to fill the plots
0171       fillRechitHistos(simhitClosest, rechit, selectedSimTrackMap, nrechitLayerMap_primary);
0172 
0173     }  // loop over tracking rechits
0174   }    // loop over tracks
0175 
0176   //fill nRecHit counter per layer
0177   for (const auto& lme : nrechitLayerMap_primary) {
0178     layerMEs_[lme.first].numberRecHitsprimary->Fill(nrechitLayerMap_primary[lme.first]);
0179   }
0180 }
0181 
0182 void Phase2ITValidateTrackingRecHit::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0183   // rechitValidIT
0184   edm::ParameterSetDescription desc;
0185 
0186   // call the base fillPsetDescription for the plots bookings
0187   Phase2ITValidateRecHitBase::fillPSetDescription(desc);
0188 
0189   //to be used in TrackerHitAssociator
0190   desc.add<bool>("associatePixel", true);
0191   desc.add<bool>("associateStrip", false);
0192   desc.add<bool>("usePhase2Tracker", true);
0193   desc.add<bool>("associateRecoTracks", false);
0194   desc.add<bool>("associateHitbySimTrack", true);
0195   desc.add<edm::InputTag>("pixelSimLinkSrc", edm::InputTag("simSiPixelDigis", "Pixel"));
0196   desc.add<std::vector<std::string>>("ROUList",
0197                                      {
0198                                          "TrackerHitsPixelBarrelLowTof",
0199                                          "TrackerHitsPixelBarrelHighTof",
0200                                          "TrackerHitsPixelEndcapLowTof",
0201                                          "TrackerHitsPixelEndcapHighTof",
0202                                      });
0203   //
0204   desc.add<edm::InputTag>("simTracksSrc", edm::InputTag("g4SimHits"));
0205   desc.add<edm::InputTag>("SimVertexSource", edm::InputTag("g4SimHits"));
0206   desc.add<double>("SimTrackMinPt", 2.0);
0207   desc.add<edm::InputTag>("tracksSrc", edm::InputTag("generalTracks"));
0208   desc.add<std::string>("TopFolderName", "TrackerPhase2ITTrackingRecHitV");
0209   desc.add<bool>("Verbosity", false);
0210   descriptions.add("Phase2ITValidateTrackingRecHit", desc);
0211 }
0212 //define this as a plug-in
0213 DEFINE_FWK_MODULE(Phase2ITValidateTrackingRecHit);