File indexing completed on 2021-11-11 03:57:27
0001
0002
0003
0004
0005
0006
0007
0008 #include <memory>
0009 #include <string>
0010 #include <iostream>
0011
0012 #include "SimTracker/TrackerHitAssociation/test/TestAssociator.h"
0013
0014
0015 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0016 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0017 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
0018 #include "Geometry/CommonDetUnit/interface/PixelGeomDetType.h"
0019 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetType.h"
0020 #include "DataFormats/DetId/interface/DetId.h"
0021 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
0022 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0023
0024
0025 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
0026 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2DCollection.h"
0027 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2DCollection.h"
0028 #include "DataFormats/TrackerRecHit2D/interface/Phase2TrackerRecHit1D.h"
0029
0030
0031 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0032 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0033
0034 using namespace std;
0035 using namespace edm;
0036
0037 void TestAssociator::analyze(const edm::Event& e, const edm::EventSetup& es) {
0038 using namespace edm;
0039 int pixelcounter = 0;
0040 int stripcounter = 0;
0041
0042 cout << " === TestAssociator " << endl;
0043
0044
0045 edm::Handle<SiStripMatchedRecHit2DCollection> rechitsmatched;
0046 edm::Handle<SiStripRecHit2DCollection> rechitsrphi;
0047 edm::Handle<SiStripRecHit2DCollection> rechitsstereo;
0048 edm::Handle<SiPixelRecHitCollection> pixelrechits;
0049 edm::Handle<Phase2TrackerRecHit1DCollectionNew> phase2rechits;
0050
0051
0052 TrackerHitAssociator associate(e, trackerHitAssociatorConfig_);
0053
0054
0055 if (doPixel_) {
0056 e.getByToken(siPixelRecHitsToken, pixelrechits);
0057 if (pixelrechits.isValid())
0058 printRechitSimhit(pixelrechits, "Pixel ", pixelcounter, associate);
0059 }
0060 if (doStrip_) {
0061 if (useOTph2_) {
0062 e.getByToken(siPhase2RecHitsToken, phase2rechits);
0063 if (phase2rechits.isValid())
0064 printRechitSimhit(phase2rechits, "Phase 2 OT ", stripcounter, associate);
0065 } else {
0066 e.getByToken(rphiRecHitToken, rechitsrphi);
0067 if (rechitsrphi.isValid())
0068 printRechitSimhit(rechitsrphi, "Strip rphi ", stripcounter, associate);
0069 e.getByToken(stereoRecHitToken, rechitsstereo);
0070 if (rechitsstereo.isValid())
0071 printRechitSimhit(rechitsstereo, "Strip stereo ", stripcounter, associate);
0072 e.getByToken(matchedRecHitToken, rechitsmatched);
0073 if (rechitsmatched.isValid())
0074 printRechitSimhit(rechitsmatched, "Strip matched", stripcounter, associate);
0075 }
0076 }
0077 if (!doPixel_ && !doStrip_)
0078 throw edm::Exception(errors::Configuration, "Strip and pixel association disabled");
0079
0080 cout << " === TestAssociator end " << endl << endl;
0081 }
0082
0083 template <typename rechitType>
0084 void TestAssociator::printRechitSimhit(const edm::Handle<edmNew::DetSetVector<rechitType>> rechitCollection,
0085 const char* rechitName,
0086 int hitCounter,
0087 TrackerHitAssociator& associate) const {
0088 std::vector<PSimHit> matched;
0089
0090 for (auto const& theDetSet : *rechitCollection) {
0091 DetId detid = theDetSet.detId();
0092 uint32_t myid = detid.rawId();
0093
0094 for (auto const& rechit : theDetSet) {
0095 int i = 0;
0096 hitCounter++;
0097 cout << hitCounter << ") " << rechitName << " RecHit subDet, DetId " << detid.subdetId() << ", " << myid
0098 << " Pos = " << rechit.localPosition() << endl;
0099 bool isPixel = false;
0100 float mindist = 999999;
0101 float dist, distx, disty;
0102 PSimHit closest;
0103
0104 matched.clear();
0105 matched = associate.associateHit(rechit);
0106 if (!matched.empty()) {
0107
0108 for (auto const& m : matched) {
0109 cout << " simtrack ID = " << m.trackId() << " Simhit Pos = " << m.localPosition()
0110 << endl;
0111
0112 if (const SiPixelRecHit* dummy = dynamic_cast<const SiPixelRecHit*>(&rechit)) {
0113 isPixel = true;
0114 dist = (rechit.localPosition() - m.localPosition()).mag();
0115 } else {
0116 isPixel = false;
0117 dist = fabs(rechit.localPosition().x() - m.localPosition().x());
0118 }
0119 if (dist < mindist) {
0120 mindist = dist;
0121 closest = m;
0122 }
0123 }
0124 cout << " Closest Simhit = " << closest.localPosition();
0125 if (isPixel) {
0126 distx = fabs(rechit.localPosition().x() - closest.localPosition().x());
0127 disty = fabs(rechit.localPosition().y() - closest.localPosition().y());
0128 cout << ", diff(x,y) = (" << distx << ", " << disty << ")";
0129 }
0130 cout << ", |diff| = " << mindist << endl;
0131 }
0132 ++i;
0133 }
0134 }
0135 }
0136
0137
0138
0139
0140
0141 TestAssociator::TestAssociator(edm::ParameterSet const& conf)
0142 : trackerHitAssociatorConfig_(conf, consumesCollector()),
0143 doPixel_(conf.getParameter<bool>("associatePixel")),
0144 doStrip_(conf.getParameter<bool>("associateStrip")),
0145 useOTph2_(conf.getParameter<bool>("usePhase2Tracker")) {
0146 matchedRecHitToken =
0147 consumes<edmNew::DetSetVector<SiStripMatchedRecHit2D>>(conf.getParameter<edm::InputTag>("matchedRecHit"));
0148 rphiRecHitToken = consumes<edmNew::DetSetVector<SiStripRecHit2D>>(conf.getParameter<edm::InputTag>("rphiRecHit"));
0149 stereoRecHitToken = consumes<edmNew::DetSetVector<SiStripRecHit2D>>(conf.getParameter<edm::InputTag>("stereoRecHit"));
0150 siPixelRecHitsToken =
0151 consumes<edmNew::DetSetVector<SiPixelRecHit>>(conf.getParameter<edm::InputTag>("siPixelRecHits"));
0152 siPhase2RecHitsToken =
0153 consumes<edmNew::DetSetVector<Phase2TrackerRecHit1D>>(conf.getParameter<edm::InputTag>("siPhase2RecHits"));
0154 }
0155
0156
0157
0158
0159
0160 TestAssociator::~TestAssociator() {}