File indexing completed on 2024-09-11 04:33:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/ESHandle.h"
0014 #include "FWCore/Framework/interface/MakerMacros.h"
0015 #include "FWCore/Framework/interface/ESWatcher.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 #include "FWCore/ServiceRegistry/interface/Service.h"
0019 #include "FWCore/Utilities/interface/InputTag.h"
0020
0021 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0022 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0023 #include "Geometry/CommonDetUnit/interface/TrackerGeomDet.h"
0024 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0025 #include "Geometry/CommonDetUnit/interface/PixelGeomDetType.h"
0026 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0027 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0028 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0029 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0030
0031 #include "DataFormats/Common/interface/Handle.h"
0032 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0033 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0034 #include "DataFormats/DetId/interface/DetId.h"
0035 #include "DataFormats/Common/interface/DetSetVector.h"
0036 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0037 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0038 #include "DataFormats/TrackerRecHit2D/interface/Phase2TrackerRecHit1D.h"
0039 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0040 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0041 #include "SimDataFormats/TrackerDigiSimLink/interface/PixelDigiSimLink.h"
0042 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
0043 #include "SimTracker/TrackerHitAssociation/interface/TrackerHitAssociator.h"
0044
0045 #include "Validation/SiTrackerPhase2V/interface/Phase2OTValidateRecHitBase.h"
0046 #include "DQM/SiTrackerPhase2/interface/TrackerPhase2DQMUtil.h"
0047
0048 class Phase2OTValidateRecHit : public Phase2OTValidateRecHitBase {
0049 public:
0050 explicit Phase2OTValidateRecHit(const edm::ParameterSet&);
0051 ~Phase2OTValidateRecHit() override;
0052 void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0053
0054 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0055
0056 private:
0057 void fillOTHistos(const edm::Event& iEvent,
0058 const TrackerHitAssociator& associateRecHit,
0059 const std::vector<edm::Handle<edm::PSimHitContainer>>& simHits,
0060 const std::map<unsigned int, SimTrack>& selectedSimTrackMap);
0061
0062 TrackerHitAssociator::Config trackerHitAssociatorConfig_;
0063 const double simtrackminpt_;
0064 const edm::EDGetTokenT<Phase2TrackerRecHit1DCollectionNew> tokenRecHitsOT_;
0065 const edm::EDGetTokenT<edm::SimTrackContainer> simTracksToken_;
0066 std::vector<edm::EDGetTokenT<edm::PSimHitContainer>> simHitTokens_;
0067 };
0068
0069
0070
0071
0072 Phase2OTValidateRecHit::Phase2OTValidateRecHit(const edm::ParameterSet& iConfig)
0073 : Phase2OTValidateRecHitBase(iConfig),
0074 trackerHitAssociatorConfig_(iConfig, consumesCollector()),
0075 simtrackminpt_(iConfig.getParameter<double>("SimTrackMinPt")),
0076 tokenRecHitsOT_(consumes<Phase2TrackerRecHit1DCollectionNew>(iConfig.getParameter<edm::InputTag>("rechitsSrc"))),
0077 simTracksToken_(consumes<edm::SimTrackContainer>(iConfig.getParameter<edm::InputTag>("simTracksSrc"))) {
0078 edm::LogInfo("Phase2OTValidateRecHit") << ">>> Construct Phase2OTValidateRecHit ";
0079 for (const auto& itag : config_.getParameter<std::vector<edm::InputTag>>("PSimHitSource"))
0080 simHitTokens_.push_back(consumes<edm::PSimHitContainer>(itag));
0081 }
0082
0083
0084
0085
0086 Phase2OTValidateRecHit::~Phase2OTValidateRecHit() {
0087
0088
0089 edm::LogInfo("Phase2OTValidateRecHit") << ">>> Destroy Phase2OTValidateRecHit ";
0090 }
0091
0092
0093
0094
0095 void Phase2OTValidateRecHit::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0096 std::vector<edm::Handle<edm::PSimHitContainer>> simHits;
0097 for (const auto& itoken : simHitTokens_) {
0098 const auto& simHitHandle = iEvent.getHandle(itoken);
0099 if (!simHitHandle.isValid())
0100 continue;
0101 simHits.emplace_back(simHitHandle);
0102 }
0103
0104 const auto& simTracks = iEvent.getHandle(simTracksToken_);
0105 std::map<unsigned int, SimTrack> selectedSimTrackMap;
0106 for (const auto& simTrackIt : *simTracks)
0107 if (simTrackIt.momentum().pt() > simtrackminpt_) {
0108 selectedSimTrackMap.insert(std::make_pair(simTrackIt.trackId(), simTrackIt));
0109 }
0110 TrackerHitAssociator associateRecHit(iEvent, trackerHitAssociatorConfig_);
0111 fillOTHistos(iEvent, associateRecHit, simHits, selectedSimTrackMap);
0112 }
0113
0114 void Phase2OTValidateRecHit::fillOTHistos(const edm::Event& iEvent,
0115 const TrackerHitAssociator& associateRecHit,
0116 const std::vector<edm::Handle<edm::PSimHitContainer>>& simHits,
0117 const std::map<unsigned int, SimTrack>& selectedSimTrackMap) {
0118
0119 const auto& rechits = iEvent.getHandle(tokenRecHitsOT_);
0120 if (!rechits.isValid())
0121 return;
0122 std::map<std::string, unsigned int> nrechitLayerMapP_primary;
0123 std::map<std::string, unsigned int> nrechitLayerMapS_primary;
0124
0125 Phase2TrackerRecHit1DCollectionNew::const_iterator DSViter;
0126 for (const auto& DSViter : *rechits) {
0127
0128 unsigned int rawid(DSViter.detId());
0129 DetId detId(rawid);
0130
0131 TrackerGeometry::ModuleType mType = tkGeom_->getDetectorType(detId);
0132 std::string key = phase2tkutil::getOTHistoId(detId.rawId(), tTopo_);
0133 if (mType == TrackerGeometry::ModuleType::Ph2PSP) {
0134 if (nrechitLayerMapP_primary.find(key) == nrechitLayerMapP_primary.end()) {
0135 nrechitLayerMapP_primary.insert(std::make_pair(key, DSViter.size()));
0136 } else {
0137 nrechitLayerMapP_primary[key] += DSViter.size();
0138 }
0139 } else if (mType == TrackerGeometry::ModuleType::Ph2PSS || mType == TrackerGeometry::ModuleType::Ph2SS) {
0140 if (nrechitLayerMapS_primary.find(key) == nrechitLayerMapS_primary.end()) {
0141 nrechitLayerMapS_primary.insert(std::make_pair(key, DSViter.size()));
0142 } else {
0143 nrechitLayerMapS_primary[key] += DSViter.size();
0144 }
0145 }
0146
0147 for (const auto& rechit : DSViter) {
0148
0149 const std::vector<SimHitIdpr>& matchedId = associateRecHit.associateHitId(rechit);
0150 const PSimHit* simhitClosest = nullptr;
0151 LocalPoint lp = rechit.localPosition();
0152 float mind = 1e4;
0153 for (const auto& simHitCol : simHits) {
0154 for (const auto& simhitIt : *simHitCol) {
0155 if (detId.rawId() != simhitIt.detUnitId())
0156 continue;
0157 for (auto& mId : matchedId) {
0158 if (simhitIt.trackId() == mId.first) {
0159 float dx = simhitIt.localPosition().x() - lp.x();
0160 float dy = simhitIt.localPosition().y() - lp.y();
0161 float dist = dx * dx + dy * dy;
0162 if (!simhitClosest || dist < mind) {
0163 mind = dist;
0164 simhitClosest = &simhitIt;
0165 }
0166 }
0167 }
0168 }
0169 }
0170 if (!simhitClosest)
0171 continue;
0172 fillOTRecHitHistos(
0173 simhitClosest, &rechit, selectedSimTrackMap, nrechitLayerMapP_primary, nrechitLayerMapS_primary);
0174
0175 }
0176 }
0177
0178
0179
0180 for (auto& lme : nrechitLayerMapP_primary) {
0181 layerMEs_[lme.first].numberRecHitsprimary_P->Fill(nrechitLayerMapP_primary[lme.first]);
0182 }
0183 for (auto& lme : nrechitLayerMapS_primary) {
0184 layerMEs_[lme.first].numberRecHitsprimary_S->Fill(nrechitLayerMapS_primary[lme.first]);
0185 }
0186 }
0187
0188 void Phase2OTValidateRecHit::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0189 edm::ParameterSetDescription desc;
0190
0191 Phase2OTValidateRecHitBase::fillPSetDescription(desc);
0192
0193
0194
0195 desc.add<edm::InputTag>("SimVertexSource", edm::InputTag("g4SimHits"));
0196 desc.add<bool>("associatePixel", false);
0197 desc.add<std::string>("TopFolderName", "TrackerPhase2OTRecHitV");
0198 desc.add<bool>("associateHitbySimTrack", true);
0199 desc.add<bool>("Verbosity", false);
0200 desc.add<bool>("associateStrip", true);
0201 desc.add<edm::InputTag>("phase2TrackerSimLinkSrc", edm::InputTag("simSiPixelDigis", "Tracker"));
0202 desc.add<bool>("associateRecoTracks", false);
0203 desc.add<edm::InputTag>("pixelSimLinkSrc", edm::InputTag("simSiPixelDigis", "Pixel"));
0204 desc.add<bool>("usePhase2Tracker", true);
0205 desc.add<edm::InputTag>("rechitsSrc", edm::InputTag("siPhase2RecHits"));
0206 desc.add<edm::InputTag>("simTracksSrc", edm::InputTag("g4SimHits"));
0207 desc.add<double>("SimTrackMinPt", 2.0);
0208 desc.add<std::vector<edm::InputTag>>("PSimHitSource",
0209 {
0210 edm::InputTag("g4SimHits:TrackerHitsTIBLowTof"),
0211 edm::InputTag("g4SimHits:TrackerHitsTIBHighTof"),
0212 edm::InputTag("g4SimHits:TrackerHitsTIDLowTof"),
0213 edm::InputTag("g4SimHits:TrackerHitsTIDHighTof"),
0214 edm::InputTag("g4SimHits:TrackerHitsTOBLowTof"),
0215 edm::InputTag("g4SimHits:TrackerHitsTOBHighTof"),
0216 edm::InputTag("g4SimHits:TrackerHitsTECLowTof"),
0217 edm::InputTag("g4SimHits:TrackerHitsTECHighTof"),
0218 edm::InputTag("g4SimHits:TrackerHitsPixelBarrelLowTof"),
0219 edm::InputTag("g4SimHits:TrackerHitsPixelBarrelHighTof"),
0220 edm::InputTag("g4SimHits:TrackerHitsPixelEndcapLowTof"),
0221 edm::InputTag("g4SimHits:TrackerHitsPixelEndcapHighTof"),
0222 });
0223
0224 desc.add<std::vector<std::string>>("ROUList",
0225 {"TrackerHitsPixelBarrelLowTof",
0226 "TrackerHitsPixelBarrelHighTof",
0227 "TrackerHitsTIBLowTof",
0228 "TrackerHitsTIBHighTof",
0229 "TrackerHitsTIDLowTof",
0230 "TrackerHitsTIDHighTof",
0231 "TrackerHitsTOBLowTof",
0232 "TrackerHitsTOBHighTof",
0233 "TrackerHitsPixelEndcapLowTof",
0234 "TrackerHitsPixelEndcapHighTof",
0235 "TrackerHitsTECLowTof",
0236 "TrackerHitsTECHighTof"});
0237
0238 descriptions.add("Phase2OTValidateRecHit", desc);
0239 }
0240
0241
0242 DEFINE_FWK_MODULE(Phase2OTValidateRecHit);