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 
9 
17 
20 
21 
25 #include <vector>
26 #include <cassert>
27 using namespace edm;
28 using namespace reco;
29 
30 template <class T> T sqr( T t) {return t*t;}
32 
33 struct HitLessByRadius { bool operator() (const Hit& h1, const Hit & h2) { return h1->globalPosition().perp2() < h2->globalPosition().perp2(); } };
34 
36  : theConfig(cfg),
37  theInputCollectionTag(cfg.getParameter<InputTag>("InputCollection")),
38  theInputVertexCollectionTag(cfg.getParameter<InputTag>("InputVertexCollection")),
39  originHalfLength(cfg.getParameter<double>("originHalfLength")),
40  originRadius(cfg.getParameter<double>("originRadius")),
41  useProtoTrackKinematics(cfg.getParameter<bool>("useProtoTrackKinematics")),
42  useEventsWithNoVertex(cfg.getParameter<bool>("useEventsWithNoVertex")),
43  builderName(cfg.getParameter<std::string>("TTRHBuilder"))
44 
45 {
46  produces<TrajectorySeedCollection>();
47 }
48 
50 {
51  std::auto_ptr<TrajectorySeedCollection> result(new TrajectorySeedCollection());
54 
55  const TrackCollection &protos = *(trks.product());
56 
58  bool foundVertices = ev.getByLabel(theInputVertexCollectionTag, vertices);
59  //const reco::VertexCollection & vertices = *(h_vertices.product());
60 
61  for (TrackCollection::const_iterator it=protos.begin(); it!= protos.end(); ++it) {
62  const Track & proto = (*it);
63  GlobalPoint vtx(proto.vertex().x(), proto.vertex().y(), proto.vertex().z());
64 
65  // check the compatibility with a primary vertex
66  bool keepTrack = false;
67  if ( !foundVertices ) {
68  if (useEventsWithNoVertex) keepTrack = true;
69  } else {
70  for (reco::VertexCollection::const_iterator iv=vertices->begin(); iv!= vertices->end(); ++iv) {
71  GlobalPoint aPV(iv->position().x(),iv->position().y(),iv->position().z());
72  double distR2 = sqr(vtx.x()-aPV.x()) +sqr(vtx.y()-aPV.y());
73  double distZ = fabs(vtx.z()-aPV.z());
74  if ( distR2 < sqr(originRadius) && distZ < originHalfLength ) {
75  keepTrack = true;
76  break;
77  }
78  }
79  }
80  if (!keepTrack) continue;
81 
83  SeedFromProtoTrack seedFromProtoTrack( proto, es);
84  if (seedFromProtoTrack.isValid()) (*result).push_back( seedFromProtoTrack.trajectorySeed() );
85  } else {
87  es.get<TransientRecHitRecord>().get(builderName,ttrhbESH);
88  std::vector<Hit> hits;
89  for (unsigned int iHit = 0, nHits = proto.recHitsSize(); iHit < nHits; ++iHit) {
90  TrackingRecHitRef refHit = proto.recHit(iHit);
91  if(refHit->isValid()) hits.push_back(ttrhbESH->build( &(*refHit) ));
92  }
93  sort(hits.begin(), hits.end(), HitLessByRadius());
94  assert(hits.size()<4);
95  if (hits.size() > 1) {
96  double mom_perp = sqrt(proto.momentum().x()*proto.momentum().x()+proto.momentum().y()*proto.momentum().y());
97  GlobalTrackingRegion region(mom_perp, vtx, 0.2, 0.2);
98  SeedFromConsecutiveHitsCreator().trajectorySeed(*result, SeedingHitSet(hits[0], hits[1], hits.size() >2 ? hits[2] : SeedingHitSet::nullPtr() ), region, es, 0);
99  }
100  }
101  }
102 
103  ev.put(result);
104 }
105 
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:150
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
Definition: Track.h:69
virtual void produce(edm::Event &ev, const edm::EventSetup &es)
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
TrajectorySeed trajectorySeed() const
std::vector< TrajectorySeed > TrajectorySeedCollection
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
T sqrt(T t)
Definition: SSEVec.h:46
static ConstRecHitPointer nullPtr()
Definition: SeedingHitSet.h:11
tuple result
Definition: query.py:137
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead ...
Definition: TrackBase.h:156
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: Handle.h:74
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
TransientTrackingRecHit::ConstRecHitPointer Hit
long double T