Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-26 04:12:42

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 
0049   edm::ParameterSetDescription psd0;
0050   psd0.add<std::string>("ComponentName", std::string("SeedFromConsecutiveHitsCreator"));
0051   psd0.add<std::string>("propagator", std::string("PropagatorWithMaterial"));
0052   psd0.add<double>("SeedMomentumForBOFF", 5.0);
0053   psd0.add<double>("OriginTransverseErrorMultiplier", 1.0);
0054   psd0.add<double>("MinOneOverPtError", 1.0);
0055   psd0.add<std::string>("magneticField", std::string(""));
0056   psd0.add<std::string>("TTRHBuilder", std::string("WithTrackAngle"));
0057   psd0.add<bool>("forceKinematicWithRegionDirection", false);
0058   desc.add<edm::ParameterSetDescription>("SeedCreatorPSet", psd0);
0059 
0060   descriptions.add("SeedGeneratorFromProtoTracksEDProducer", desc);
0061 }
0062 
0063 SeedGeneratorFromProtoTracksEDProducer::SeedGeneratorFromProtoTracksEDProducer(const ParameterSet& cfg)
0064     : originHalfLength(cfg.getParameter<double>("originHalfLength")),
0065       originRadius(cfg.getParameter<double>("originRadius")),
0066       useProtoTrackKinematics(cfg.getParameter<bool>("useProtoTrackKinematics")),
0067       useEventsWithNoVertex(cfg.getParameter<bool>("useEventsWithNoVertex")),
0068       usePV_(cfg.getParameter<bool>("usePV")),
0069       includeFourthHit_(cfg.getParameter<bool>("includeFourthHit")),
0070       theInputCollectionTag(consumes<reco::TrackCollection>(cfg.getParameter<InputTag>("InputCollection"))),
0071       theInputVertexCollectionTag(
0072           consumes<reco::VertexCollection>(cfg.getParameter<InputTag>("InputVertexCollection"))),
0073       seedCreator_(cfg.getParameter<edm::ParameterSet>("SeedCreatorPSet"), consumesCollector()),
0074       config_(consumesCollector()) {
0075   produces<TrajectorySeedCollection>();
0076 }
0077 
0078 void SeedGeneratorFromProtoTracksEDProducer::produce(edm::Event& ev, const edm::EventSetup& es) {
0079   auto result = std::make_unique<TrajectorySeedCollection>();
0080   Handle<reco::TrackCollection> trks;
0081   ev.getByToken(theInputCollectionTag, trks);
0082 
0083   const TrackCollection& protos = *(trks.product());
0084 
0085   edm::Handle<reco::VertexCollection> vertices;
0086   bool foundVertices = ev.getByToken(theInputVertexCollectionTag, vertices);
0087   //const reco::VertexCollection & vertices = *(h_vertices.product());
0088 
0089   ///
0090   /// need optimization: all es stuff should go out of the loop
0091   ///
0092   for (TrackCollection::const_iterator it = protos.begin(); it != protos.end(); ++it) {
0093     const Track& proto = (*it);
0094     GlobalPoint vtx(proto.vertex().x(), proto.vertex().y(), proto.vertex().z());
0095 
0096     // check the compatibility with a primary vertex
0097     bool keepTrack = false;
0098     if ((!foundVertices) || vertices->empty()) {
0099       if (useEventsWithNoVertex)
0100         keepTrack = true;
0101     } else if (usePV_) {
0102       GlobalPoint aPV(
0103           vertices->begin()->position().x(), vertices->begin()->position().y(), vertices->begin()->position().z());
0104       double distR2 = sqr(vtx.x() - aPV.x()) + sqr(vtx.y() - aPV.y());
0105       double distZ = fabs(vtx.z() - aPV.z());
0106       if (distR2 < sqr(originRadius) && distZ < originHalfLength) {
0107         keepTrack = true;
0108       }
0109     } else {
0110       for (reco::VertexCollection::const_iterator iv = vertices->begin(); iv != vertices->end(); ++iv) {
0111         GlobalPoint aPV(iv->position().x(), iv->position().y(), iv->position().z());
0112         double distR2 = sqr(vtx.x() - aPV.x()) + sqr(vtx.y() - aPV.y());
0113         double distZ = fabs(vtx.z() - aPV.z());
0114         if (distR2 < sqr(originRadius) && distZ < originHalfLength) {
0115           keepTrack = true;
0116           break;
0117         }
0118       }
0119     }
0120     if (!keepTrack)
0121       continue;
0122 
0123     if (useProtoTrackKinematics) {
0124       SeedFromProtoTrack seedFromProtoTrack(config_, proto, es);
0125       if (seedFromProtoTrack.isValid())
0126         (*result).push_back(seedFromProtoTrack.trajectorySeed());
0127     } else {
0128       std::vector<Hit> hits;
0129       for (unsigned int iHit = 0, nHits = proto.recHitsSize(); iHit < nHits; ++iHit) {
0130         TrackingRecHitRef refHit = proto.recHit(iHit);
0131         if (refHit->isValid())
0132           hits.push_back((Hit) & (*refHit));
0133       }
0134       sort(hits.begin(), hits.end(), HitLessByRadius());
0135 
0136       if (hits.size() > 1) {
0137         double mom_perp =
0138             sqrt(proto.momentum().x() * proto.momentum().x() + proto.momentum().y() * proto.momentum().y());
0139         GlobalTrackingRegion region(mom_perp, vtx, 0.2, 0.2);
0140 
0141         seedCreator_.init(region, es, nullptr);
0142         if (hits.size() > 3 and not includeFourthHit_)
0143           seedCreator_.makeSeed(*result, {hits[0], hits[1], hits[2]});
0144         else
0145           seedCreator_.makeSeed(*result, hits);
0146       }
0147     }
0148   }
0149 
0150   ev.put(std::move(result));
0151 }