test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackIPProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TrackIPProducer
4 // Class: TrackIPProducer
5 //
13 //
14 // Original Author: Andrea Rizzi
15 // Created: Thu Apr 6 09:56:23 CEST 2006
16 //
17 //
18 
19 // system include files
20 #include <cmath>
21 #include <memory>
22 #include <iostream>
23 #include <algorithm>
24 
25 // user include files
32 
37 
41 
50 
53 
54 
55 using namespace std;
56 using namespace reco;
57 using namespace edm;
58 using boost::bind;
59 
60 //
61 // constructors and destructor
62 //
64  m_config(iConfig)
65 {
68 
69  token_associator = consumes<reco::JetTracksAssociationCollection>(m_config.getParameter<edm::InputTag>("jetTracks"));
70  token_primaryVertex = consumes<reco::VertexCollection>(m_config.getParameter<edm::InputTag>("primaryVertex"));
71 
72  m_computeProbabilities = m_config.getParameter<bool>("computeProbabilities");
73  m_computeGhostTrack = m_config.getParameter<bool>("computeGhostTrack");
74  m_ghostTrackPriorDeltaR = m_config.getParameter<double>("ghostTrackPriorDeltaR");
75  m_cutPixelHits = m_config.getParameter<int>("minimumNumberOfPixelHits");
76  m_cutTotalHits = m_config.getParameter<int>("minimumNumberOfHits");
77  m_cutMaxTIP = m_config.getParameter<double>("maximumTransverseImpactParameter");
78  m_cutMinPt = m_config.getParameter<double>("minimumTransverseMomentum");
79  m_cutMaxChiSquared = m_config.getParameter<double>("maximumChiSquared");
80  m_cutMaxLIP = m_config.getParameter<double>("maximumLongitudinalImpactParameter");
81  m_directionWithTracks = m_config.getParameter<bool>("jetDirectionUsingTracks");
82  m_directionWithGhostTrack = m_config.getParameter<bool>("jetDirectionUsingGhostTrack");
83  m_useTrackQuality = m_config.getParameter<bool>("useTrackQuality");
84 
85  if (m_computeGhostTrack)
86  produces<reco::TrackCollection>("ghostTracks");
87  produces<reco::TrackIPTagInfoCollection>();
88 }
89 
91 {
92 }
93 
94 //
95 // member functions
96 //
97 // ------------ method called to produce the data ------------
98 void
100 {
101  // Update probability estimator if event setup is changed
103  checkEventSetup(iSetup);
104 
105  //input objects
107  iEvent.getByToken(token_associator, jetTracksAssociation);
108 
110  iEvent.getByToken(token_primaryVertex, primaryVertex);
111 
113  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
114  // m_algo.setTransientTrackBuilder(builder.product());
115 
116  // output collections
117  auto_ptr<reco::TrackIPTagInfoCollection> result(new reco::TrackIPTagInfoCollection);
118 
119  auto_ptr<reco::TrackCollection> ghostTracks;
120  TrackRefProd ghostTrackRefProd;
121  if (m_computeGhostTrack) {
122  ghostTracks.reset(new reco::TrackCollection);
123  ghostTrackRefProd = iEvent.getRefBeforePut<TrackCollection>("ghostTracks");
124  }
125 
126  // use first pv of the collection
127  Vertex dummy;
128  const Vertex *pv = &dummy;
130  if (primaryVertex->size() != 0) {
131  pv = &*primaryVertex->begin();
132  // we always use the first vertex (at the moment)
134  } else { // create a dummy PV
136  e(0, 0) = 0.0015 * 0.0015;
137  e(1, 1) = 0.0015 * 0.0015;
138  e(2, 2) = 15. * 15.;
139  Vertex::Point p(0, 0, 0);
140  dummy = Vertex(p, e, 0, 0, 0);
141  }
142 
143  int i = 0;
145  jetTracksAssociation->begin();
146  it != jetTracksAssociation->end(); it++, i++) {
147  TrackRefVector tracks = it->second;
148  math::XYZVector jetMomentum = it->first->momentum();
149 
150  if (m_directionWithTracks) {
151  jetMomentum *= 0.5;
152  for(TrackRefVector::const_iterator itTrack = tracks.begin();
153  itTrack != tracks.end(); ++itTrack)
154  if ((**itTrack).numberOfValidHits() >= m_cutTotalHits)
155  //minimal quality cuts
156  jetMomentum += (*itTrack)->momentum();
157  }
158 
160  vector<TransientTrack> transientTracks;
161 
162  for(TrackRefVector::const_iterator itTrack = tracks.begin();
163  itTrack != tracks.end(); ++itTrack) {
164  const Track & track = **itTrack;
165  TransientTrack transientTrack = builder->build(*itTrack);
166 /* cout << " pt " << track.pt() <<
167  " d0 " << fabs(track.d0()) <<
168  " #hit " << track.hitPattern().numberOfValidHits()<<
169  " ipZ " << fabs(track.dz()-pvZ)<<
170  " chi2 " << track.normalizedChi2()<<
171  " #pixel " << track.hitPattern().numberOfValidPixelHits()<< endl;
172 */
173  if (track.pt() > m_cutMinPt &&
174  track.hitPattern().numberOfValidHits() >= m_cutTotalHits && // min num tracker hits
177  std::abs(track.dxy(pv->position())) < m_cutMaxTIP &&
178  std::abs(track.dz(pv->position())) < m_cutMaxLIP) {
179  selectedTracks.push_back(*itTrack);
180  transientTracks.push_back(transientTrack);
181  }
182  }
183 
184  GlobalVector direction(jetMomentum.x(), jetMomentum.y(), jetMomentum.z());
185 
186  auto_ptr<GhostTrack> ghostTrack;
187  TrackRef ghostTrackRef;
188  if (m_computeGhostTrack) {
189  GhostTrackFitter fitter;
192  ghostTrack.reset(new GhostTrack(fitter.fit(origin, error, direction,
194  transientTracks)));
195 
196 /*
197  if (std::sqrt(jetMomentum.Perp2()) > 30) {
198  double offset = ghostTrack->prediction().lambda(origin);
199  std::cout << "------------------ jet pt " << std::sqrt(jetMomentum.Perp2()) << std::endl;
200  const std::vector<GhostTrackState> *states = &ghostTrack->states();
201  for(std::vector<GhostTrackState>::const_iterator state = states->begin();
202  state != states->end(); ++state) {
203  double dist = state->lambda() - offset;
204  double err = state->lambdaError(ghostTrack->prediction(), error);
205  double ipSig = IPTools::signedImpactParameter3D(state->track(), direction, *pv).second.significance();
206  double axisDist = state->axisDistance(ghostTrack->prediction());
207  std::cout << state->track().impactPointState().freeState()->momentum().perp()
208  << ": " << dist << "/" << err << " [" << (dist / err) << "], ipsig = " << ipSig << ", dist = " << axisDist << ", w = " << state->weight() << std::endl;
209  }
210  }
211 */
212  ghostTrackRef = TrackRef(ghostTrackRefProd, ghostTracks->size());
213  ghostTracks->push_back(*ghostTrack);
214 
216  const GhostTrackPrediction &pred = ghostTrack->prediction();
217  double lambda = pred.lambda(origin);
218  dummy = Vertex(RecoVertex::convertPos(pred.position(lambda)),
220  0, 0, 0);
221  pv = &dummy;
222  direction = pred.direction();
223  }
224  }
225 
226  vector<float> prob2D, prob3D;
227  vector<TrackIPTagInfo::TrackIPData> ipData;
228 
229  for(unsigned int ind = 0; ind < transientTracks.size(); ind++) {
230  const Track & track = *selectedTracks[ind];
231  const TransientTrack &transientTrack = transientTracks[ind];
232 
234  trackIP.ip3d = IPTools::signedImpactParameter3D(transientTrack, direction, *pv).second;
235  trackIP.ip2d = IPTools::signedTransverseImpactParameter(transientTrack, direction, *pv).second;
236 
237  TrajectoryStateOnSurface closest =
239  *pv, direction,
240  transientTrack.field());
241  if (closest.isValid())
242  trackIP.closestToJetAxis = closest.globalPosition();
243 
244  // TODO: cross check if it is the same using other methods
245  trackIP.distanceToJetAxis = IPTools::jetTrackDistance(transientTrack, direction, *pv).second;
246 
247  if (ghostTrack.get()) {
248  const std::vector<GhostTrackState> &states = ghostTrack->states();
249  std::vector<GhostTrackState>::const_iterator pos =
250  std::find_if(states.begin(), states.end(),
251  bind(equal_to<TransientTrack>(),
252  bind(&GhostTrackState::track, _1),
253  transientTrack));
254 
255  if (pos != states.end() && pos->isValid()) {
256  VertexDistance3D dist;
257  const GhostTrackPrediction &pred = ghostTrack->prediction();
258  GlobalPoint p1 = pos->tsos().globalPosition();
259  GlobalError e1 = pos->tsos().cartesianError().position();
260  GlobalPoint p2 = pred.position(pos->lambda());
261  GlobalError e2 = pred.positionError(pos->lambda());
262  trackIP.closestToGhostTrack = p1;
263  trackIP.distanceToGhostTrack = dist.distance(VertexState(p1, e1),
264  VertexState(p2, e2));
265  trackIP.ghostTrackWeight = pos->weight();
266  } else {
267  trackIP.distanceToGhostTrack = Measurement1D(-1. -1.);
268  trackIP.ghostTrackWeight = 0.;
269  }
270  } else {
271  trackIP.distanceToGhostTrack = Measurement1D(-1. -1.);
272  trackIP.ghostTrackWeight = 1.;
273  }
274 
275  ipData.push_back(trackIP);
276 
278  //probability with 3D ip
279  pair<bool,double> probability = m_probabilityEstimator->probability(m_useTrackQuality, 0,ipData.back().ip3d.significance(),track,*(it->first),*pv);
280  prob3D.push_back(probability.first ? probability.second : -1.);
281 
282  //probability with 2D ip
283  probability = m_probabilityEstimator->probability(m_useTrackQuality,1,ipData.back().ip2d.significance(),track,*(it->first),*pv);
284  prob2D.push_back(probability.first ? probability.second : -1.);
285  }
286  }
287 
288  Ref<JetTracksAssociationCollection> jtaRef(jetTracksAssociation, i);
289  result->push_back(
290  TrackIPTagInfo(ipData, prob2D, prob3D, selectedTracks,
291  jtaRef, pvRef, direction, ghostTrackRef));
292  }
293 
295  iEvent.put(ghostTracks, "ghostTracks");
296  iEvent.put(result);
297 }
298 
299 
306 
308  {
309  using namespace edm;
310  using namespace edm::eventsetup;
311 
312  const EventSetupRecord & re2D= iSetup.get<BTagTrackProbability2DRcd>();
313  const EventSetupRecord & re3D= iSetup.get<BTagTrackProbability3DRcd>();
314  unsigned long long cacheId2D= re2D.cacheIdentifier();
315  unsigned long long cacheId3D= re3D.cacheIdentifier();
316 
317  if(cacheId2D!=m_calibrationCacheId2D || cacheId3D!=m_calibrationCacheId3D ) //Calibration changed
318  {
319  //iSetup.get<BTagTrackProbabilityRcd>().get(calib);
321  iSetup.get<BTagTrackProbability2DRcd>().get(calib2DHandle);
323  iSetup.get<BTagTrackProbability3DRcd>().get(calib3DHandle);
324 
325  const TrackProbabilityCalibration * ca2D= calib2DHandle.product();
326  const TrackProbabilityCalibration * ca3D= calib3DHandle.product();
327 
329 
330  }
331  m_calibrationCacheId3D=cacheId3D;
332  m_calibrationCacheId2D=cacheId2D;
333 }
virtual Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const
reco::Vertex::Point convertPos(const GlobalPoint &p)
T getParameter(std::string const &) const
unsigned long long cacheIdentifier() const
void checkEventSetup(const edm::EventSetup &iSetup)
int i
Definition: DBlmapReader.cc:9
virtual void produce(edm::Event &, const edm::EventSetup &)
double m_ghostTrackPriorDeltaR
double m_cutMaxChiSquared
std::vector< TrackIPTagInfo > TrackIPTagInfoCollection
edm::EDGetTokenT< reco::VertexCollection > token_primaryVertex
double lambda(const GlobalPoint &point) const
transient_vector_type::const_iterator const_iterator
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
Definition: TrackBase.h:109
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
int numberOfValidHits() const
Definition: HitPattern.h:589
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:50
reco::Vertex::Error convertError(const GlobalError &ge)
Definition: ConvertError.h:8
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
std::auto_ptr< HistogramProbabilityEstimator > m_probabilityEstimator
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
std::pair< bool, Measurement1D > signedImpactParameter3D(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:71
GlobalPoint globalPosition() const
TrajectoryStateOnSurface closestApproachToJet(const TrajectoryStateOnSurface &state, const reco::Vertex &vertex, const GlobalVector &aJetDirection, const MagneticField *field)
Definition: IPTools.cc:177
const MagneticField * field() const
unsigned long long m_calibrationCacheId2D
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:249
const Point & position() const
position
Definition: Vertex.h:106
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:244
std::pair< double, Measurement1D > jetTrackDistance(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:200
GhostTrack fit(const GlobalPoint &priorPosition, const GlobalError &priorError, const GlobalVector &direction, double coneRadius, const std::vector< TransientTrack > &tracks) const
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
double pt() const
track transverse momentum
Definition: TrackBase.h:129
tuple result
Definition: query.py:137
TrackIPProducer(const edm::ParameterSet &)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:221
double p2[4]
Definition: TauolaWrapper.h:90
RefProd< PROD > getRefBeforePut()
Definition: Event.h:128
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:125
tuple tracks
Definition: testEve_cfg.py:39
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
const T & get() const
Definition: EventSetup.h:55
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:14
T const * product() const
Definition: ESHandle.h:62
Error error() const
return SMatrix
Definition: Vertex.h:129
const edm::ParameterSet & m_config
const Vector & prediction() const
bool m_directionWithGhostTrack
double p1[4]
Definition: TauolaWrapper.h:89
GlobalPoint position(double lambda=0.) const
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
int numberOfValidPixelHits() const
Definition: HitPattern.h:601
TrajectoryStateOnSurface impactPointState() const
unsigned long long m_calibrationCacheId3D
edm::EDGetTokenT< reco::JetTracksAssociationCollection > token_associator
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:119
GlobalError positionError(double lambda=0.) const
const GlobalVector direction() const