CMS 3D CMS Logo

SeedGeneratorFromProtoTracksEDProducer.cc
Go to the documentation of this file.
2 
5 
10 
18 
23 
24 
26 #include <vector>
27 
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 
48  psd0.add<std::string>("ComponentName",std::string("SeedFromConsecutiveHitsCreator"));
49  psd0.add<std::string>("propagator",std::string("PropagatorWithMaterial"));
50  psd0.add<double>("SeedMomentumForBOFF",5.0);
51  psd0.add<double>("OriginTransverseErrorMultiplier",1.0);
52  psd0.add<double>("MinOneOverPtError",1.0);
53  psd0.add<std::string>("magneticField",std::string(""));
54  psd0.add<std::string>("TTRHBuilder",std::string("WithTrackAngle"));
55  psd0.add<bool>("forceKinematicWithRegionDirection",false);
56  desc.add<edm::ParameterSetDescription>("SeedCreatorPSet",psd0);
57 
58  descriptions.add("SeedGeneratorFromProtoTracksEDProducer", desc);
59 }
60 
61 
63  : theConfig(cfg)
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  , builderName ( cfg.getParameter<std::string>("TTRHBuilder") )
69  , usePV_ ( cfg.getParameter<bool>( "usePV" ) )
70  , theInputCollectionTag ( consumes<reco::TrackCollection> (cfg.getParameter<InputTag>("InputCollection")) )
71  , theInputVertexCollectionTag ( consumes<reco::VertexCollection>(cfg.getParameter<InputTag>("InputVertexCollection")) )
72 {
73  produces<TrajectorySeedCollection>();
74 
75 
76 
77 }
78 
79 
81 {
82  auto result = std::make_unique<TrajectorySeedCollection>();
85 
86  const TrackCollection &protos = *(trks.product());
87 
89  bool foundVertices = ev.getByToken(theInputVertexCollectionTag, vertices);
90  //const reco::VertexCollection & vertices = *(h_vertices.product());
91 
95  for (TrackCollection::const_iterator it=protos.begin(); it!= protos.end(); ++it) {
96  const Track & proto = (*it);
97  GlobalPoint vtx(proto.vertex().x(), proto.vertex().y(), proto.vertex().z());
98 
99  // check the compatibility with a primary vertex
100  bool keepTrack = false;
101  if ( (!foundVertices) || vertices->empty() ) {
102  if (useEventsWithNoVertex) keepTrack = true;
103  }
104  else if (usePV_){
105 
106  GlobalPoint aPV(vertices->begin()->position().x(),vertices->begin()->position().y(),vertices->begin()->position().z());
107  double distR2 = sqr(vtx.x()-aPV.x()) +sqr(vtx.y()-aPV.y());
108  double distZ = fabs(vtx.z()-aPV.z());
109  if ( distR2 < sqr(originRadius) && distZ < originHalfLength ) {
110  keepTrack = true;
111  }
112  }
113  else {
114  for (reco::VertexCollection::const_iterator iv=vertices->begin(); iv!= vertices->end(); ++iv) {
115  GlobalPoint aPV(iv->position().x(),iv->position().y(),iv->position().z());
116  double distR2 = sqr(vtx.x()-aPV.x()) +sqr(vtx.y()-aPV.y());
117  double distZ = fabs(vtx.z()-aPV.z());
118  if ( distR2 < sqr(originRadius) && distZ < originHalfLength ) {
119  keepTrack = true;
120  break;
121  }
122  }
123  }
124  if (!keepTrack) continue;
125 
126  if ( useProtoTrackKinematics ) {
127  SeedFromProtoTrack seedFromProtoTrack( proto, es);
128  if (seedFromProtoTrack.isValid()) (*result).push_back( seedFromProtoTrack.trajectorySeed() );
129  } else {
131  es.get<TransientRecHitRecord>().get(builderName,ttrhbESH);
132  std::vector<Hit> hits;
133  for (unsigned int iHit = 0, nHits = proto.recHitsSize(); iHit < nHits; ++iHit) {
134  TrackingRecHitRef refHit = proto.recHit(iHit);
135  if(refHit->isValid()) hits.push_back((Hit)&(*refHit));
136  }
137  sort(hits.begin(), hits.end(), HitLessByRadius());
138 
139  if (hits.size() > 1) {
140  double mom_perp = sqrt(proto.momentum().x()*proto.momentum().x()+proto.momentum().y()*proto.momentum().y());
141  GlobalTrackingRegion region(mom_perp, vtx, 0.2, 0.2);
142 
143  edm::ParameterSet seedCreatorPSet = theConfig.getParameter<edm::ParameterSet>("SeedCreatorPSet");
144  SeedFromConsecutiveHitsCreator seedCreator(seedCreatorPSet);
145  seedCreator.init(region, es, nullptr);
146  seedCreator.makeSeed(*result, SeedingHitSet(hits[0], hits[1], hits.size() >2 ? hits[2] : SeedingHitSet::nullPtr() ));
147  }
148  }
149  }
150 
151  ev.put(std::move(result));
152 }
153 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
Definition: Track.h:119
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
bool ev
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:675
const edm::EDGetTokenT< reco::TrackCollection > theInputCollectionTag
TrajectorySeed trajectorySeed() const
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead ...
Definition: TrackBase.h:687
BaseTrackerRecHit const * ConstRecHitPointer
Definition: SeedingHitSet.h:11
T sqrt(T t)
Definition: SSEVec.h:18
static ConstRecHitPointer nullPtr()
Definition: SeedingHitSet.h:13
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
const T & get() const
Definition: EventSetup.h:55
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
fixed size matrix
HLT enums.
TrackingRecHitRef recHit(size_t i) const
Get i-th hit on the track.
Definition: Track.h:114
long double T
def move(src, dest)
Definition: eostools.py:510