CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SeedGeneratorFromProtoTracksEDProducer.cc
Go to the documentation of this file.
2 
5 
10 
18 
23 
24 
26 #include <vector>
27 #include <cassert>
28 using namespace edm;
29 using namespace reco;
30 
31 template <class T> T sqr( T t) {return t*t;}
33 
34 struct HitLessByRadius { bool operator() (const Hit& h1, const Hit & h2) { return h1->globalPosition().perp2() < h2->globalPosition().perp2(); } };
35 
38  desc.add<InputTag>("InputCollection", InputTag("pixelTracks"));
39  desc.add<InputTag>("InputVertexCollection", InputTag(""));
40  desc.add<double>("originHalfLength", 1E9);
41  desc.add<double>("originRadius", 1E9);
42  desc.add<bool>("useProtoTrackKinematics", false);
43  desc.add<bool>("useEventsWithNoVertex", true);
44  desc.add<std::string>("TTRHBuilder", "TTRHBuilderWithoutAngle4PixelTriplets");
45  desc.add<bool>("usePV", false);
46  descriptions.add("SeedGeneratorFromProtoTracksEDProducer", desc);
47 }
48 
49 
51 
52 {
53  produces<TrajectorySeedCollection>();
54  theInputCollectionTag = consumes<reco::TrackCollection>(cfg.getParameter<InputTag>("InputCollection"));
55  theInputVertexCollectionTag = consumes<reco::VertexCollection>(cfg.getParameter<InputTag>("InputVertexCollection"));
56  originHalfLength = cfg.getParameter<double>("originHalfLength");
57  originRadius = cfg.getParameter<double>("originRadius");
58  useProtoTrackKinematics = cfg.getParameter<bool>("useProtoTrackKinematics");
59  useEventsWithNoVertex = cfg.getParameter<bool>("useEventsWithNoVertex");
60  builderName = cfg.getParameter<std::string>("TTRHBuilder");
61  usePV_ = cfg.getParameter<bool>( "usePV" );
62 }
63 
64 
66 {
67  std::auto_ptr<TrajectorySeedCollection> result(new TrajectorySeedCollection());
70 
71  const TrackCollection &protos = *(trks.product());
72 
74  bool foundVertices = ev.getByToken(theInputVertexCollectionTag, vertices);
75  //const reco::VertexCollection & vertices = *(h_vertices.product());
76 
80  for (TrackCollection::const_iterator it=protos.begin(); it!= protos.end(); ++it) {
81  const Track & proto = (*it);
82  GlobalPoint vtx(proto.vertex().x(), proto.vertex().y(), proto.vertex().z());
83 
84  // check the compatibility with a primary vertex
85  bool keepTrack = false;
86  if ( (!foundVertices) || vertices->empty() ) {
87  if (useEventsWithNoVertex) keepTrack = true;
88  }
89  else if (usePV_){
90 
91  GlobalPoint aPV(vertices->begin()->position().x(),vertices->begin()->position().y(),vertices->begin()->position().z());
92  double distR2 = sqr(vtx.x()-aPV.x()) +sqr(vtx.y()-aPV.y());
93  double distZ = fabs(vtx.z()-aPV.z());
94  if ( distR2 < sqr(originRadius) && distZ < originHalfLength ) {
95  keepTrack = true;
96  }
97  }
98  else {
99  for (reco::VertexCollection::const_iterator iv=vertices->begin(); iv!= vertices->end(); ++iv) {
100  GlobalPoint aPV(iv->position().x(),iv->position().y(),iv->position().z());
101  double distR2 = sqr(vtx.x()-aPV.x()) +sqr(vtx.y()-aPV.y());
102  double distZ = fabs(vtx.z()-aPV.z());
103  if ( distR2 < sqr(originRadius) && distZ < originHalfLength ) {
104  keepTrack = true;
105  break;
106  }
107  }
108  }
109  if (!keepTrack) continue;
110 
111  if ( useProtoTrackKinematics ) {
112  SeedFromProtoTrack seedFromProtoTrack( proto, es);
113  if (seedFromProtoTrack.isValid()) (*result).push_back( seedFromProtoTrack.trajectorySeed() );
114  } else {
116  es.get<TransientRecHitRecord>().get(builderName,ttrhbESH);
117  std::vector<Hit> hits;
118  for (unsigned int iHit = 0, nHits = proto.recHitsSize(); iHit < nHits; ++iHit) {
119  TrackingRecHitRef refHit = proto.recHit(iHit);
120  if(refHit->isValid()) hits.push_back((Hit)&(*refHit));
121  }
122  sort(hits.begin(), hits.end(), HitLessByRadius());
123  assert(hits.size()<4);
124  if (hits.size() > 1) {
125  double mom_perp = sqrt(proto.momentum().x()*proto.momentum().x()+proto.momentum().y()*proto.momentum().y());
126  GlobalTrackingRegion region(mom_perp, vtx, 0.2, 0.2);
127  SeedFromConsecutiveHitsCreator seedCreator;
128  seedCreator.init(region, es, 0);
129  seedCreator.makeSeed(*result, SeedingHitSet(hits[0], hits[1], hits.size() >2 ? hits[2] : SeedingHitSet::nullPtr() ));
130  }
131  }
132  }
133 
134  ev.put(result);
135 }
136 
T getParameter(std::string const &) const
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:148
edm::EDGetTokenT< reco::VertexCollection > theInputVertexCollectionTag
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
Definition: Track.h:69
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
edm::EDGetTokenT< reco::TrackCollection > theInputCollectionTag
TrajectorySeed trajectorySeed() const
BaseTrackerRecHit const * ConstRecHitPointer
Definition: SeedingHitSet.h:11
std::vector< TrajectorySeed > TrajectorySeedCollection
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
T sqrt(T t)
Definition: SSEVec.h:48
virtual void init(const TrackingRegion &region, const edm::EventSetup &es, const SeedComparitor *filter) GCC11_FINAL
static ConstRecHitPointer nullPtr()
Definition: SeedingHitSet.h:13
tuple result
Definition: query.py:137
ParameterDescriptionBase * add(U const &iLabel, T const &value)
SeedingHitSet::ConstRecHitPointer Hit
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead ...
Definition: TrackBase.h:154
virtual void produce(edm::Event &ev, const edm::EventSetup &es) override
const T & get() const
Definition: EventSetup.h:55
void add(std::string const &label, ParameterSetDescription const &psetDescription)
T const * product() const
Definition: Handle.h:81
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Square< F >::type sqr(const F &f)
Definition: Square.h:13
TrackingRecHitRef recHit(size_t i) const
Get i-th hit on the track.
Definition: Track.h:67
virtual void makeSeed(TrajectorySeedCollection &seedCollection, const SeedingHitSet &hits) GCC11_FINAL
long double T