Go to the documentation of this file.00001 #include "SeedGeneratorFromProtoTracksEDProducer.h"
00002
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "DataFormats/Common/interface/Handle.h"
00005
00006 #include "DataFormats/TrackReco/interface/Track.h"
00007 #include "DataFormats/VertexReco/interface/Vertex.h"
00008 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
00009
00010 #include "RecoTracker/TkSeedGenerator/interface/SeedFromProtoTrack.h"
00011 #include "RecoTracker/TkSeedingLayers/interface/SeedingHitSet.h"
00012 #include "SeedFromConsecutiveHitsCreator.h"
00013 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
00014 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
00015 #include "RecoTracker/TkTrackingRegions/interface/GlobalTrackingRegion.h"
00016 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
00017
00018 #include "FWCore/Framework/interface/EventSetup.h"
00019 #include "FWCore/Framework/interface/ESHandle.h"
00020
00021
00022 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00023 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00025 #include <vector>
00026 #include <cassert>
00027 using namespace edm;
00028 using namespace reco;
00029
00030 template <class T> T sqr( T t) {return t*t;}
00031 typedef TransientTrackingRecHit::ConstRecHitPointer Hit;
00032
00033 struct HitLessByRadius { bool operator() (const Hit& h1, const Hit & h2) { return h1->globalPosition().perp2() < h2->globalPosition().perp2(); } };
00034
00035 SeedGeneratorFromProtoTracksEDProducer::SeedGeneratorFromProtoTracksEDProducer(const ParameterSet& cfg)
00036 : theConfig(cfg),
00037 theInputCollectionTag(cfg.getParameter<InputTag>("InputCollection")),
00038 theInputVertexCollectionTag(cfg.getParameter<InputTag>("InputVertexCollection")),
00039 originHalfLength(cfg.getParameter<double>("originHalfLength")),
00040 originRadius(cfg.getParameter<double>("originRadius")),
00041 useProtoTrackKinematics(cfg.getParameter<bool>("useProtoTrackKinematics")),
00042 useEventsWithNoVertex(cfg.getParameter<bool>("useEventsWithNoVertex")),
00043 builderName(cfg.getParameter<std::string>("TTRHBuilder"))
00044
00045 {
00046 produces<TrajectorySeedCollection>();
00047 }
00048
00049 void SeedGeneratorFromProtoTracksEDProducer::produce(edm::Event& ev, const edm::EventSetup& es)
00050 {
00051 std::auto_ptr<TrajectorySeedCollection> result(new TrajectorySeedCollection());
00052 Handle<reco::TrackCollection> trks;
00053 ev.getByLabel(theInputCollectionTag, trks);
00054
00055 const TrackCollection &protos = *(trks.product());
00056
00057 edm::Handle<reco::VertexCollection> vertices;
00058 bool foundVertices = ev.getByLabel(theInputVertexCollectionTag, vertices);
00059
00060
00064 for (TrackCollection::const_iterator it=protos.begin(); it!= protos.end(); ++it) {
00065 const Track & proto = (*it);
00066 GlobalPoint vtx(proto.vertex().x(), proto.vertex().y(), proto.vertex().z());
00067
00068
00069 bool keepTrack = false;
00070 if ( !foundVertices ) {
00071 if (useEventsWithNoVertex) keepTrack = true;
00072 } else {
00073 for (reco::VertexCollection::const_iterator iv=vertices->begin(); iv!= vertices->end(); ++iv) {
00074 GlobalPoint aPV(iv->position().x(),iv->position().y(),iv->position().z());
00075 double distR2 = sqr(vtx.x()-aPV.x()) +sqr(vtx.y()-aPV.y());
00076 double distZ = fabs(vtx.z()-aPV.z());
00077 if ( distR2 < sqr(originRadius) && distZ < originHalfLength ) {
00078 keepTrack = true;
00079 break;
00080 }
00081 }
00082 }
00083 if (!keepTrack) continue;
00084
00085 if ( useProtoTrackKinematics ) {
00086 SeedFromProtoTrack seedFromProtoTrack( proto, es);
00087 if (seedFromProtoTrack.isValid()) (*result).push_back( seedFromProtoTrack.trajectorySeed() );
00088 } else {
00089 edm::ESHandle<TransientTrackingRecHitBuilder> ttrhbESH;
00090 es.get<TransientRecHitRecord>().get(builderName,ttrhbESH);
00091 std::vector<Hit> hits;
00092 for (unsigned int iHit = 0, nHits = proto.recHitsSize(); iHit < nHits; ++iHit) {
00093 TrackingRecHitRef refHit = proto.recHit(iHit);
00094 if(refHit->isValid()) hits.push_back(ttrhbESH->build( &(*refHit) ));
00095 }
00096 sort(hits.begin(), hits.end(), HitLessByRadius());
00097 assert(hits.size()<4);
00098 if (hits.size() > 1) {
00099 double mom_perp = sqrt(proto.momentum().x()*proto.momentum().x()+proto.momentum().y()*proto.momentum().y());
00100 GlobalTrackingRegion region(mom_perp, vtx, 0.2, 0.2);
00101 SeedFromConsecutiveHitsCreator seedCreator;
00102 seedCreator.init(region, es, 0);
00103 seedCreator.makeSeed(*result, SeedingHitSet(hits[0], hits[1], hits.size() >2 ? hits[2] : SeedingHitSet::nullPtr() ));
00104 }
00105 }
00106 }
00107
00108 ev.put(result);
00109 }
00110