CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
InclusiveVertexFinder.h
Go to the documentation of this file.
1 #ifndef InclusiveVertexFinder_h
2 #define InclusiveVertexFinder_h
3 #include <memory>
4 
11 
15 
22 
27 
33 
37 
38 #include <type_traits>
39 
40 //#define VTXDEBUG 1
41 template <class InputContainer, class VTX>
43 public:
44  typedef std::vector<VTX> Product;
45  typedef typename InputContainer::value_type TRK;
47 
50  pdesc.add<edm::InputTag>("beamSpot", edm::InputTag("offlineBeamSpot"));
51  pdesc.add<edm::InputTag>("primaryVertices", edm::InputTag("offlinePrimaryVertices"));
53  pdesc.add<edm::InputTag>("tracks", edm::InputTag("generalTracks"));
54  pdesc.add<unsigned int>("minHits", 8);
56  pdesc.add<edm::InputTag>("tracks", edm::InputTag("particleFlow"));
57  pdesc.add<unsigned int>("minHits", 0);
58  } else {
59  pdesc.add<edm::InputTag>("tracks", edm::InputTag("generalTracks"));
60  }
61 
62  pdesc.add<double>("maximumLongitudinalImpactParameter", 0.3);
63  pdesc.add<double>("maximumTimeSignificance", 3.0);
64  pdesc.add<double>("minPt", 0.8);
65  pdesc.add<unsigned int>("maxNTracks", 30);
66  //clusterizer pset
68  clusterizer.add<double>("seedMax3DIPSignificance", 9999.0);
69  clusterizer.add<double>("seedMax3DIPValue", 9999.0);
70  clusterizer.add<double>("seedMin3DIPSignificance", 1.2);
71  clusterizer.add<double>("seedMin3DIPValue", 0.005);
72  clusterizer.add<double>("clusterMaxDistance", 0.05);
73  clusterizer.add<double>("clusterMaxSignificance", 4.5);
74  clusterizer.add<double>("distanceRatio", 20.0);
75  clusterizer.add<double>("clusterMinAngleCosine", 0.5);
76  clusterizer.add<double>("maxTimeSignificance", 3.5);
77  pdesc.add<edm::ParameterSetDescription>("clusterizer", clusterizer);
78  // vertex and fitter config
79  pdesc.add<double>("vertexMinAngleCosine", 0.95);
80  pdesc.add<double>("vertexMinDLen2DSig", 2.5);
81  pdesc.add<double>("vertexMinDLenSig", 0.5);
82  pdesc.add<double>("fitterSigmacut", 3.0);
83  pdesc.add<double>("fitterTini", 256.0);
84  pdesc.add<double>("fitterRatio", 0.25);
85  pdesc.add<bool>("useDirectVertexFitter", true);
86  pdesc.add<bool>("useVertexReco", true);
87  // vertexReco pset
89  vertexReco.add<std::string>("finder", std::string("avr"));
90  vertexReco.add<double>("primcut", 1.0);
91  vertexReco.add<double>("seccut", 3.0);
92  vertexReco.add<bool>("smoothing", true);
93  pdesc.add<edm::ParameterSetDescription>("vertexReco", vertexReco);
95  cdesc.add("inclusiveVertexFinderDefault", pdesc);
97  cdesc.add("inclusiveCandidateVertexFinderDefault", pdesc);
98  } else {
99  cdesc.addDefault(pdesc);
100  }
101  }
102 
103  void produce(edm::Event &event, const edm::EventSetup &es) override;
104 
105 private:
106  bool trackFilter(const reco::Track &track) const;
107  std::pair<std::vector<reco::TransientTrack>, GlobalPoint> nearTracks(const reco::TransientTrack &seed,
108  const std::vector<reco::TransientTrack> &tracks,
109  const reco::Vertex &primaryVertex) const;
110 
115  unsigned int minHits;
116  unsigned int maxNTracks;
117  double maxLIP;
118  double maxTimeSig;
119  double minPt;
124  double fitterTini;
125  double fitterRatio;
128  std::unique_ptr<VertexReconstructor> vtxReco;
129  std::unique_ptr<TracksClusteringFromDisplacedSeed> clusterizer;
130 };
131 template <class InputContainer, class VTX>
133  : minHits(params.getParameter<unsigned int>("minHits")),
134  maxNTracks(params.getParameter<unsigned int>("maxNTracks")),
135  maxLIP(params.getParameter<double>("maximumLongitudinalImpactParameter")),
136  maxTimeSig(params.getParameter<double>("maximumTimeSignificance")),
137  minPt(params.getParameter<double>("minPt")), //0.8
138  vertexMinAngleCosine(params.getParameter<double>("vertexMinAngleCosine")), //0.98
139  vertexMinDLen2DSig(params.getParameter<double>("vertexMinDLen2DSig")), //2.5
140  vertexMinDLenSig(params.getParameter<double>("vertexMinDLenSig")), //0.5
141  fitterSigmacut(params.getParameter<double>("fitterSigmacut")),
142  fitterTini(params.getParameter<double>("fitterTini")),
143  fitterRatio(params.getParameter<double>("fitterRatio")),
144  useVertexFitter(params.getParameter<bool>("useDirectVertexFitter")),
145  useVertexReco(params.getParameter<bool>("useVertexReco")),
146  vtxReco(new ConfigurableVertexReconstructor(params.getParameter<edm::ParameterSet>("vertexReco"))),
147  clusterizer(new TracksClusteringFromDisplacedSeed(params.getParameter<edm::ParameterSet>("clusterizer")))
148 
149 {
150  token_beamSpot = consumes<reco::BeamSpot>(params.getParameter<edm::InputTag>("beamSpot"));
151  token_primaryVertex = consumes<reco::VertexCollection>(params.getParameter<edm::InputTag>("primaryVertices"));
152  token_tracks = consumes<InputContainer>(params.getParameter<edm::InputTag>("tracks"));
154  esConsumes<TransientTrackBuilder, TransientTrackRecord>(edm::ESInputTag("", "TransientTrackBuilder"));
155  produces<Product>();
156  //produces<reco::VertexCollection>("multi");
157 }
158 template <class InputContainer, class VTX>
160  if (track.hitPattern().numberOfValidHits() < (int)minHits)
161  return false;
162  if (track.pt() < minPt)
163  return false;
164 
165  return true;
166 }
167 
168 template <class InputContainer, class VTX>
170  using namespace reco;
171 
172  VertexDistance3D vdist;
173  VertexDistanceXY vdist2d;
174  MultiVertexFitter theMultiVertexFitter;
180 
182  event.getByToken(token_beamSpot, beamSpot);
183 
185  event.getByToken(token_primaryVertex, primaryVertices);
186 
188  event.getByToken(token_tracks, tracks);
189 
190  edm::ESHandle<TransientTrackBuilder> trackBuilder = es.getHandle(token_trackBuilder);
191 
192  auto recoVertices = std::make_unique<Product>();
193  if (!primaryVertices->empty()) {
194  const reco::Vertex &pv = (*primaryVertices)[0];
195  GlobalPoint ppv(pv.position().x(), pv.position().y(), pv.position().z());
196 
197  std::vector<TransientTrack> tts;
198  //Fill transient track vector
199  for (typename InputContainer::const_iterator track = tracks->begin(); track != tracks->end(); ++track) {
200  //TransientTrack tt = trackBuilder->build(ref);
201  //TrackRef ref(tracks, track - tracks->begin());
202  TransientTrack tt(tthelpers::buildTT(tracks, trackBuilder, track - tracks->begin()));
203  if (!tt.isValid())
204  continue;
205  if (!trackFilter(tt.track()))
206  continue;
207  if (std::abs(tt.track().dz(pv.position())) > maxLIP)
208  continue;
209  if (edm::isFinite(tt.timeExt()) && pv.covariance(3, 3) > 0.) { // only apply if time available
210  auto tError = std::sqrt(std::pow(tt.dtErrorExt(), 2) + pv.covariance(3, 3));
211  auto dtSig = std::abs(tt.timeExt() - pv.t()) / tError;
212  if (dtSig > maxTimeSig)
213  continue;
214  }
215  tt.setBeamSpot(*beamSpot);
216  tts.push_back(tt);
217  }
218  std::vector<TracksClusteringFromDisplacedSeed::Cluster> clusters = clusterizer->clusters(pv, tts);
219 
220  //Create BS object from PV to feed in the AVR
222  for (unsigned int i = 0; i < 7; i++) {
223  for (unsigned int j = 0; j < 7; j++) {
224  if (i < 3 && j < 3)
225  cov(i, j) = pv.covariance(i, j);
226  else
227  cov(i, j) = 0.0;
228  }
229  }
230  BeamSpot bs(pv.position(), 0.0, 0.0, 0.0, 0.0, cov, BeamSpot::Unknown);
231 
232  int i = 0;
233 #ifdef VTXDEBUG
234 
235  std::cout << "CLUSTERS " << clusters.size() << std::endl;
236 #endif
237 
238  for (std::vector<TracksClusteringFromDisplacedSeed::Cluster>::iterator cluster = clusters.begin();
239  cluster != clusters.end();
240  ++cluster, ++i) {
241  if (cluster->tracks.size() < 2 || cluster->tracks.size() > maxNTracks)
242  continue;
243  std::vector<TransientVertex> vertices;
244  if (useVertexReco) {
245  vertices = vtxReco->vertices(cluster->tracks, bs); // attempt with config given reconstructor
246  }
247  TransientVertex singleFitVertex;
248  if (useVertexFitter) {
249  singleFitVertex = theAdaptiveFitter.vertex(cluster->tracks, cluster->seedPoint); //attempt with direct fitting
250  if (singleFitVertex.isValid())
251  vertices.push_back(singleFitVertex);
252  }
253 
254  // for each transient vertex state determine if a time can be measured and fill covariance
255  if (pv.covariance(3, 3) > 0.) {
256  for (auto &vtx : vertices) {
258  }
259  }
260 
261  for (std::vector<TransientVertex>::const_iterator v = vertices.begin(); v != vertices.end(); ++v) {
262  Measurement1D dlen = vdist.distance(pv, *v);
263  Measurement1D dlen2 = vdist2d.distance(pv, *v);
264 #ifdef VTXDEBUG
265  VTX vv(*v);
266  std::cout << "V chi2/n: " << v->normalisedChiSquared() << " ndof: " << v->degreesOfFreedom();
267  std::cout << " dlen: " << dlen.value() << " error: " << dlen.error() << " signif: " << dlen.significance();
268  std::cout << " dlen2: " << dlen2.value() << " error2: " << dlen2.error()
269  << " signif2: " << dlen2.significance();
270  std::cout << " pos: " << vv.position() << " error: " << vv.xError() << " " << vv.yError() << " " << vv.zError()
271  << std::endl;
272  std::cout << " time: " << vv.time() << " error: " << vv.tError() << std::endl;
273 #endif
275  std::vector<reco::TransientTrack> ts = v->originalTracks();
276  for (std::vector<reco::TransientTrack>::const_iterator i = ts.begin(); i != ts.end(); ++i) {
277  float w = v->trackWeight(*i);
278  if (w > 0.5)
279  dir += i->impactPointState().globalDirection();
280 #ifdef VTXDEBUG
281  std::cout << "\t[" << (*i).track().pt() << ": " << (*i).track().eta() << ", " << (*i).track().phi() << "], "
282  << w << std::endl;
283 #endif
284  }
285  GlobalPoint sv((*v).position().x(), (*v).position().y(), (*v).position().z());
286  float vscal = dir.unit().dot((sv - ppv).unit());
287  if (dlen.significance() > vertexMinDLenSig &&
288  ((vertexMinAngleCosine > 0) ? (vscal > vertexMinAngleCosine) : (vscal < vertexMinAngleCosine)) &&
289  v->normalisedChiSquared() < 10 && dlen2.significance() > vertexMinDLen2DSig) {
290  recoVertices->push_back(*v);
291 
292 #ifdef VTXDEBUG
293  std::cout << "ADDED" << std::endl;
294 #endif
295  }
296  }
297  }
298 #ifdef VTXDEBUG
299 
300  std::cout << "Final put " << recoVertices->size() << std::endl;
301 #endif
302  }
303 
304  event.put(std::move(recoVertices));
305 }
306 #endif
math::Error< dimension >::type CovarianceMatrix
Definition: BeamSpot.h:29
tuple vertexMinAngleCosine
tuple vertexMinDLenSig
const double w
Definition: UKUtility.cc:23
tuple fitterSigmacut
void setBeamSpot(const reco::BeamSpot &beamSpot)
bool isValid() const
Make the ReferenceCountingProxy method to check validity public.
tuple primaryVertices
std::pair< std::vector< reco::TransientTrack >, GlobalPoint > nearTracks(const reco::TransientTrack &seed, const std::vector< reco::TransientTrack > &tracks, const reco::Vertex &primaryVertex) const
int numberOfValidHits() const
Definition: HitPattern.h:811
double error() const
Definition: Measurement1D.h:27
double timeExt() const
auto const & tracks
cannot be loose
std::unique_ptr< VertexReconstructor > vtxReco
PreciseFloatType< T, U >::Type dot(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:99
double covariance(int i, int j) const
(i, j)-th element of error matrix, i, j = 0, ... 2
Definition: Vertex.h:148
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const override
InputContainer::value_type TRK
constexpr bool isFinite(T x)
const Point & position() const
position
Definition: Vertex.h:127
std::unique_ptr< TracksClusteringFromDisplacedSeed > clusterizer
void addDefault(ParameterSetDescription const &psetDescription)
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > token_trackBuilder
T sqrt(T t)
Definition: SSEVec.h:19
double pt() const
track transverse momentum
Definition: TrackBase.h:637
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< InputContainer > token_tracks
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool trackFilter(const reco::Track &track) const
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:622
tuple trackFilter
Definition: valSkim_cff.py:14
Vector3DBase unit() const
Definition: Vector3DBase.h:54
double significance() const
Definition: Measurement1D.h:29
void produce(edm::Event &event, const edm::EventSetup &es) override
const Track & track() const
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:504
double dtErrorExt() const
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void add(std::string const &label, ParameterSetDescription const &psetDescription)
double value() const
Definition: Measurement1D.h:25
void updateVertexTime(TransientVertex &vtx)
Definition: SVTimeHelpers.h:11
edm::EDGetTokenT< reco::BeamSpot > token_beamSpot
tuple cout
Definition: gather_cfg.py:144
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
TemplatedInclusiveVertexFinder(const edm::ParameterSet &params)
edm::EDGetTokenT< reco::VertexCollection > token_primaryVertex
tuple vertexMinDLen2DSig
reco::TransientTrack buildTT(edm::Handle< reco::TrackCollection > &tracks, edm::ESHandle< TransientTrackBuilder > &trackbuilder, unsigned int k)
Definition: TTHelpers.h:10
static void fillDescriptions(edm::ConfigurationDescriptions &cdesc)
bool isValid() const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
double t() const
t coordinate
Definition: Vertex.h:135
Basic3DVector unit() const