CMS 3D CMS Logo

SeedGeneratorFromProtoTracksEDProducer.cc
Go to the documentation of this file.
2 
5 
10 
16 
21 
22 #include <vector>
23 
24 using namespace edm;
25 using namespace reco;
26 
27 template <class T>
28 T sqr(T t) {
29  return t * t;
30 }
32 
34  bool operator()(const Hit& h1, const Hit& h2) { return h1->globalPosition().perp2() < h2->globalPosition().perp2(); }
35 };
36 
39  desc.add<InputTag>("InputCollection", InputTag("pixelTracks"));
40  desc.add<InputTag>("InputVertexCollection", InputTag(""));
41  desc.add<double>("originHalfLength", 1E9);
42  desc.add<double>("originRadius", 1E9);
43  desc.add<bool>("useProtoTrackKinematics", false);
44  desc.add<bool>("useEventsWithNoVertex", true);
45  desc.add<std::string>("TTRHBuilder", "TTRHBuilderWithoutAngle4PixelTriplets");
46  desc.add<bool>("usePV", false);
47  desc.add<bool>("includeFourthHit", false);
48 
50  psd0.add<std::string>("ComponentName", std::string("SeedFromConsecutiveHitsCreator"));
51  psd0.add<std::string>("propagator", std::string("PropagatorWithMaterial"));
52  psd0.add<double>("SeedMomentumForBOFF", 5.0);
53  psd0.add<double>("OriginTransverseErrorMultiplier", 1.0);
54  psd0.add<double>("MinOneOverPtError", 1.0);
55  psd0.add<std::string>("magneticField", std::string(""));
56  psd0.add<std::string>("TTRHBuilder", std::string("WithTrackAngle"));
57  psd0.add<bool>("forceKinematicWithRegionDirection", false);
58  desc.add<edm::ParameterSetDescription>("SeedCreatorPSet", psd0);
59 
60  descriptions.add("SeedGeneratorFromProtoTracksEDProducer", desc);
61 }
62 
64  : originHalfLength(cfg.getParameter<double>("originHalfLength")),
65  originRadius(cfg.getParameter<double>("originRadius")),
66  useProtoTrackKinematics(cfg.getParameter<bool>("useProtoTrackKinematics")),
67  useEventsWithNoVertex(cfg.getParameter<bool>("useEventsWithNoVertex")),
68  usePV_(cfg.getParameter<bool>("usePV")),
69  includeFourthHit_(cfg.getParameter<bool>("includeFourthHit")),
70  theInputCollectionTag(consumes<reco::TrackCollection>(cfg.getParameter<InputTag>("InputCollection"))),
71  theInputVertexCollectionTag(
72  consumes<reco::VertexCollection>(cfg.getParameter<InputTag>("InputVertexCollection"))),
73  seedCreator_(cfg.getParameter<edm::ParameterSet>("SeedCreatorPSet"), consumesCollector()),
74  config_(consumesCollector()) {
75  produces<TrajectorySeedCollection>();
76 }
77 
79  auto result = std::make_unique<TrajectorySeedCollection>();
81  ev.getByToken(theInputCollectionTag, trks);
82 
83  const TrackCollection& protos = *(trks.product());
84 
86  bool foundVertices = ev.getByToken(theInputVertexCollectionTag, vertices);
87  //const reco::VertexCollection & vertices = *(h_vertices.product());
88 
92  for (TrackCollection::const_iterator it = protos.begin(); it != protos.end(); ++it) {
93  const Track& proto = (*it);
94  GlobalPoint vtx(proto.vertex().x(), proto.vertex().y(), proto.vertex().z());
95 
96  // check the compatibility with a primary vertex
97  bool keepTrack = false;
98  if ((!foundVertices) || vertices->empty()) {
100  keepTrack = true;
101  } else if (usePV_) {
102  GlobalPoint aPV(
103  vertices->begin()->position().x(), vertices->begin()->position().y(), vertices->begin()->position().z());
104  double distR2 = sqr(vtx.x() - aPV.x()) + sqr(vtx.y() - aPV.y());
105  double distZ = fabs(vtx.z() - aPV.z());
106  if (distR2 < sqr(originRadius) && distZ < originHalfLength) {
107  keepTrack = true;
108  }
109  } else {
110  for (reco::VertexCollection::const_iterator iv = vertices->begin(); iv != vertices->end(); ++iv) {
111  GlobalPoint aPV(iv->position().x(), iv->position().y(), iv->position().z());
112  double distR2 = sqr(vtx.x() - aPV.x()) + sqr(vtx.y() - aPV.y());
113  double distZ = fabs(vtx.z() - aPV.z());
114  if (distR2 < sqr(originRadius) && distZ < originHalfLength) {
115  keepTrack = true;
116  break;
117  }
118  }
119  }
120  if (!keepTrack)
121  continue;
122 
124  SeedFromProtoTrack seedFromProtoTrack(config_, proto, es);
125  if (seedFromProtoTrack.isValid())
126  (*result).push_back(seedFromProtoTrack.trajectorySeed());
127  } else {
128  std::vector<Hit> hits;
129  for (unsigned int iHit = 0, nHits = proto.recHitsSize(); iHit < nHits; ++iHit) {
130  TrackingRecHitRef refHit = proto.recHit(iHit);
131  if (refHit->isValid())
132  hits.push_back((Hit) & (*refHit));
133  }
134  sort(hits.begin(), hits.end(), HitLessByRadius());
135 
136  if (hits.size() > 1) {
137  double mom_perp =
138  sqrt(proto.momentum().x() * proto.momentum().x() + proto.momentum().y() * proto.momentum().y());
139  GlobalTrackingRegion region(mom_perp, vtx, 0.2, 0.2);
140 
141  seedCreator_.init(region, es, nullptr);
142  if (hits.size() > 3 and not includeFourthHit_)
143  seedCreator_.makeSeed(*result, {hits[0], hits[1], hits[2]});
144  else
145  seedCreator_.makeSeed(*result, hits);
146  }
147  }
148  }
149 
150  ev.put(std::move(result));
151 }
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
Definition: Track.h:97
int32_t *__restrict__ iv
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
TrajectorySeed trajectorySeed() const
const edm::EDGetTokenT< reco::TrackCollection > theInputCollectionTag
bool operator()(const Hit &h1, const Hit &h2)
BaseTrackerRecHit const * ConstRecHitPointer
Definition: SeedingHitSet.h:14
T sqrt(T t)
Definition: SSEVec.h:19
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead ...
Definition: TrackBase.h:676
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const edm::EDGetTokenT< reco::VertexCollection > theInputVertexCollectionTag
SeedingHitSet::ConstRecHitPointer Hit
void produce(edm::Event &ev, const edm::EventSetup &es) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:664
TrackingRecHitRef recHit(size_t i) const
Get i-th hit on the track.
Definition: Track.h:94
fixed size matrix
HLT enums.
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
long double T
def move(src, dest)
Definition: eostools.py:511