File indexing completed on 2024-04-06 12:28:54
0001 #include "SeedGeneratorFromProtoTracksEDProducer.h"
0002
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "DataFormats/Common/interface/Handle.h"
0005
0006 #include "FWCore/Utilities/interface/InputTag.h"
0007 #include "DataFormats/TrackReco/interface/Track.h"
0008 #include "DataFormats/VertexReco/interface/Vertex.h"
0009 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
0010
0011 #include "RecoTracker/TkSeedingLayers/interface/SeedingHitSet.h"
0012 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
0013 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
0014 #include "RecoTracker/TkTrackingRegions/interface/GlobalTrackingRegion.h"
0015 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
0016
0017 #include "FWCore/Framework/interface/ConsumesCollector.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0020 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0021
0022 #include <vector>
0023
0024 using namespace edm;
0025 using namespace reco;
0026
0027 template <class T>
0028 T sqr(T t) {
0029 return t * t;
0030 }
0031 typedef SeedingHitSet::ConstRecHitPointer Hit;
0032
0033 struct HitLessByRadius {
0034 bool operator()(const Hit& h1, const Hit& h2) { return h1->globalPosition().perp2() < h2->globalPosition().perp2(); }
0035 };
0036
0037 void SeedGeneratorFromProtoTracksEDProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0038 edm::ParameterSetDescription desc;
0039 desc.add<InputTag>("InputCollection", InputTag("pixelTracks"));
0040 desc.add<InputTag>("InputVertexCollection", InputTag(""));
0041 desc.add<double>("originHalfLength", 1E9);
0042 desc.add<double>("originRadius", 1E9);
0043 desc.add<bool>("useProtoTrackKinematics", false);
0044 desc.add<bool>("useEventsWithNoVertex", true);
0045 desc.add<std::string>("TTRHBuilder", "TTRHBuilderWithoutAngle4PixelTriplets");
0046 desc.add<bool>("usePV", false);
0047 desc.add<bool>("includeFourthHit", false);
0048 desc.add<bool>("produceComplement", false);
0049
0050 edm::ParameterSetDescription psd0;
0051 psd0.add<std::string>("ComponentName", std::string("SeedFromConsecutiveHitsCreator"));
0052 psd0.add<std::string>("propagator", std::string("PropagatorWithMaterial"));
0053 psd0.add<double>("SeedMomentumForBOFF", 5.0);
0054 psd0.add<double>("OriginTransverseErrorMultiplier", 1.0);
0055 psd0.add<double>("MinOneOverPtError", 1.0);
0056 psd0.add<std::string>("magneticField", std::string(""));
0057 psd0.add<std::string>("TTRHBuilder", std::string("WithTrackAngle"));
0058 psd0.add<bool>("forceKinematicWithRegionDirection", false);
0059 desc.add<edm::ParameterSetDescription>("SeedCreatorPSet", psd0);
0060
0061 descriptions.add("SeedGeneratorFromProtoTracksEDProducer", desc);
0062 }
0063
0064 SeedGeneratorFromProtoTracksEDProducer::SeedGeneratorFromProtoTracksEDProducer(const ParameterSet& cfg)
0065 : originHalfLength(cfg.getParameter<double>("originHalfLength")),
0066 originRadius(cfg.getParameter<double>("originRadius")),
0067 useProtoTrackKinematics(cfg.getParameter<bool>("useProtoTrackKinematics")),
0068 useEventsWithNoVertex(cfg.getParameter<bool>("useEventsWithNoVertex")),
0069 usePV_(cfg.getParameter<bool>("usePV")),
0070 includeFourthHit_(cfg.getParameter<bool>("includeFourthHit")),
0071 produceComplement_(cfg.getParameter<bool>("produceComplement")),
0072 theInputCollectionTag(consumes<reco::TrackCollection>(cfg.getParameter<InputTag>("InputCollection"))),
0073 theInputVertexCollectionTag(
0074 consumes<reco::VertexCollection>(cfg.getParameter<InputTag>("InputVertexCollection"))),
0075 seedCreator_(cfg.getParameter<edm::ParameterSet>("SeedCreatorPSet"), consumesCollector()),
0076 config_(consumesCollector()) {
0077 produces<TrajectorySeedCollection>();
0078 if (produceComplement_) {
0079 produces<reco::TrackCollection>();
0080 }
0081 }
0082
0083 void SeedGeneratorFromProtoTracksEDProducer::produce(edm::Event& ev, const edm::EventSetup& es) {
0084 auto result = std::make_unique<TrajectorySeedCollection>();
0085 auto leftTracks = std::make_unique<reco::TrackCollection>();
0086 Handle<reco::TrackCollection> trks;
0087 ev.getByToken(theInputCollectionTag, trks);
0088
0089 const TrackCollection& protos = *(trks.product());
0090
0091 edm::Handle<reco::VertexCollection> vertices;
0092 bool foundVertices = ev.getByToken(theInputVertexCollectionTag, vertices);
0093
0094
0095
0096
0097
0098 for (TrackCollection::const_iterator it = protos.begin(); it != protos.end(); ++it) {
0099 const Track& proto = (*it);
0100 GlobalPoint vtx(proto.vertex().x(), proto.vertex().y(), proto.vertex().z());
0101
0102
0103 bool keepTrack = false;
0104 if ((!foundVertices) || vertices->empty()) {
0105 if (useEventsWithNoVertex)
0106 keepTrack = true;
0107 } else if (usePV_) {
0108 GlobalPoint aPV(
0109 vertices->begin()->position().x(), vertices->begin()->position().y(), vertices->begin()->position().z());
0110 double distR2 = sqr(vtx.x() - aPV.x()) + sqr(vtx.y() - aPV.y());
0111 double distZ = fabs(vtx.z() - aPV.z());
0112 if (distR2 < sqr(originRadius) && distZ < originHalfLength) {
0113 keepTrack = true;
0114 }
0115 } else {
0116 for (reco::VertexCollection::const_iterator iv = vertices->begin(); iv != vertices->end(); ++iv) {
0117 GlobalPoint aPV(iv->position().x(), iv->position().y(), iv->position().z());
0118 double distR2 = sqr(vtx.x() - aPV.x()) + sqr(vtx.y() - aPV.y());
0119 double distZ = fabs(vtx.z() - aPV.z());
0120 if (distR2 < sqr(originRadius) && distZ < originHalfLength) {
0121 keepTrack = true;
0122 break;
0123 }
0124 }
0125 }
0126 if (produceComplement_ and !keepTrack)
0127 (*leftTracks).push_back(proto);
0128 if (!keepTrack)
0129 continue;
0130
0131 if (useProtoTrackKinematics) {
0132 SeedFromProtoTrack seedFromProtoTrack(config_, proto, es);
0133 if (seedFromProtoTrack.isValid())
0134 (*result).push_back(seedFromProtoTrack.trajectorySeed());
0135 } else {
0136 std::vector<Hit> hits;
0137 for (unsigned int iHit = 0, nHits = proto.recHitsSize(); iHit < nHits; ++iHit) {
0138 TrackingRecHitRef refHit = proto.recHit(iHit);
0139 if (refHit->isValid())
0140 hits.push_back((Hit) & (*refHit));
0141 }
0142 sort(hits.begin(), hits.end(), HitLessByRadius());
0143
0144 if (hits.size() > 1) {
0145 double mom_perp =
0146 sqrt(proto.momentum().x() * proto.momentum().x() + proto.momentum().y() * proto.momentum().y());
0147 GlobalTrackingRegion region(mom_perp, vtx, 0.2, 0.2);
0148
0149 seedCreator_.init(region, es, nullptr);
0150 if (hits.size() > 3 and not includeFourthHit_)
0151 seedCreator_.makeSeed(*result, {hits[0], hits[1], hits[2]});
0152 else
0153 seedCreator_.makeSeed(*result, hits);
0154 }
0155 }
0156 }
0157
0158 ev.put(std::move(result));
0159 if (produceComplement_)
0160 ev.put(std::move(leftTracks));
0161 }