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 
64  for (TrackCollection::const_iterator it=protos.begin(); it!= protos.end(); ++it) {
65  const Track & proto = (*it);
66  GlobalPoint vtx(proto.vertex().x(), proto.vertex().y(), proto.vertex().z());
67 
68  // check the compatibility with a primary vertex
69  bool keepTrack = false;
70  if ( !foundVertices ) {
71  if (useEventsWithNoVertex) keepTrack = true;
72  } else {
73  for (reco::VertexCollection::const_iterator iv=vertices->begin(); iv!= vertices->end(); ++iv) {
74  GlobalPoint aPV(iv->position().x(),iv->position().y(),iv->position().z());
75  double distR2 = sqr(vtx.x()-aPV.x()) +sqr(vtx.y()-aPV.y());
76  double distZ = fabs(vtx.z()-aPV.z());
77  if ( distR2 < sqr(originRadius) && distZ < originHalfLength ) {
78  keepTrack = true;
79  break;
80  }
81  }
82  }
83  if (!keepTrack) continue;
84 
86  SeedFromProtoTrack seedFromProtoTrack( proto, es);
87  if (seedFromProtoTrack.isValid()) (*result).push_back( seedFromProtoTrack.trajectorySeed() );
88  } else {
90  es.get<TransientRecHitRecord>().get(builderName,ttrhbESH);
91  std::vector<Hit> hits;
92  for (unsigned int iHit = 0, nHits = proto.recHitsSize(); iHit < nHits; ++iHit) {
93  TrackingRecHitRef refHit = proto.recHit(iHit);
94  if(refHit->isValid()) hits.push_back(ttrhbESH->build( &(*refHit) ));
95  }
96  sort(hits.begin(), hits.end(), HitLessByRadius());
97  assert(hits.size()<4);
98  if (hits.size() > 1) {
99  double mom_perp = sqrt(proto.momentum().x()*proto.momentum().x()+proto.momentum().y()*proto.momentum().y());
100  GlobalTrackingRegion region(mom_perp, vtx, 0.2, 0.2);
101  SeedFromConsecutiveHitsCreator seedCreator;
102  seedCreator.init(region, es, 0);
103  seedCreator.makeSeed(*result, SeedingHitSet(hits[0], hits[1], hits.size() >2 ? hits[2] : SeedingHitSet::nullPtr() ));
104  }
105  }
106  }
107 
108  ev.put(result);
109 }
110 
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
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:94
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:11
tuple result
Definition: query.py:137
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead ...
Definition: TrackBase.h:156
virtual void produce(edm::Event &ev, const edm::EventSetup &es) override
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
virtual void makeSeed(TrajectorySeedCollection &seedCollection, const SeedingHitSet &hits) GCC11_FINAL
TransientTrackingRecHit::ConstRecHitPointer Hit
long double T