CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SoftLepton.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SoftLepton
4 // Class: SoftLepton
5 //
13 // Original Author: fwyzard
14 // Created: Wed Oct 18 18:02:07 CEST 2006
15 // $Id: SoftLepton.cc,v 1.37 2010/08/19 23:14:52 fwyzard Exp $
16 
17 
18 #include <memory>
19 #include <string>
20 #include <utility>
21 #include <cmath>
22 
34 
35 // ROOT::Math vectors (aka math::XYZVector)
38 #include "Math/GenVector/PxPyPzM4D.h"
39 #include "Math/GenVector/VectorUtil.h"
40 #include "Math/GenVector/Boost.h"
41 
60 
65 #include "SoftLepton.h"
66 
67 enum AxisType {
68  AXIS_CALORIMETRIC = 0, // use the calorimietric jet axis
69  AXIS_CHARGED_AVERAGE = 1, // refine jet axis using charged tracks: use a pT-weighted average of (eta, phi)
70  AXIS_CHARGED_AVERAGE_NOLEPTON = 2, // as above, without the tagging lepton track
71  AXIS_CHARGED_SUM = 3, // refine jet axis using charged tracks: use the sum of tracks momentum
72  AXIS_CHARGED_SUM_NOLEPTON = 4, // as above, without the tagging lepton track
73  AXIS_CALORIMETRIC_NOLEPTON = 5 // use the calorimetric jet axis minus the lepton momentum
74 };
75 
76 using namespace std;
77 using namespace edm;
78 using namespace reco;
79 using namespace ROOT::Math::VectorUtil;
80 
84 
85 // ------------ static copy of the nominal beamspot --------------------------------------
87  reco::Vertex::Point( 0, 0, 0 ),
88  reco::Vertex::Error( ROOT::Math::SVector<double,6>( 0.0015 * 0.0015, // 0.0, 0.0
89  0.0, 0.0015 * 0.0015, // 0.0
90  0.0, 0.0, 15. * 15. ) ),
91  1, 1, 0 );
92 
93 // ------------ c'tor --------------------------------------------------------------------
95  m_jets( iConfig.getParameter<edm::InputTag>( "jets" ) ),
96  m_primaryVertex( iConfig.getParameter<edm::InputTag>( "primaryVertex" ) ),
97  m_leptons( iConfig.getParameter<edm::InputTag>( "leptons" ) ),
98  m_leptonCands( iConfig.exists("leptonCands") ? iConfig.getParameter<edm::InputTag>( "leptonCands" ) : edm::InputTag() ),
99  m_leptonId( iConfig.exists("leptonId") ? iConfig.getParameter<edm::InputTag>( "leptonId" ) : edm::InputTag() ),
100  m_transientTrackBuilder( 0 ),
101  m_refineJetAxis( iConfig.getParameter<unsigned int>( "refineJetAxis" ) ),
102  m_deltaRCut( iConfig.getParameter<double>( "leptonDeltaRCut" ) ),
103  m_chi2Cut( iConfig.getParameter<double>( "leptonChi2Cut" ) ),
104  m_muonSelection( (muon::SelectionType) iConfig.getParameter<unsigned int>( "muonSelection" ) )
105 {
106  produces<reco::SoftLeptonTagInfoCollection>();
107 }
108 
109 // ------------ d'tor --------------------------------------------------------------------
111 }
112 
113 // ------------ method called once per event during the event loop -----------------------
114 void
116 
117  // grab a TransientTrack helper from the Event Setup
119  setup.get<TransientTrackRecord>().get( "TransientTrackBuilder", builder );
120  m_transientTrackBuilder = builder.product();
121 
122  // input objects
123 
124  // input jets (and possibly tracks)
125  ProductID jets_id;
126  std::vector<edm::RefToBase<reco::Jet> > jets;
127  std::vector<reco::TrackRefVector> tracks;
128  do { {
129  // look for a JetTracksAssociationCollection
131  event.getByLabel(m_jets, h_jtas);
132  if (h_jtas.isValid()) {
133  unsigned int size = h_jtas->size();
134  jets.resize(size);
135  tracks.resize(size);
136  for (unsigned int i = 0; i < size; ++i) {
137  jets[i] = (*h_jtas)[i].first;
138  tracks[i] = (*h_jtas)[i].second;
139  }
140  break;
141  }
142  } { // else...
143  // look for a View<Jet>
145  event.getByLabel(m_jets, h_jets);
146  if (h_jets.isValid()) {
147  unsigned int size = h_jets->size();
148  jets.resize(size);
149  tracks.resize(size);
150  for (unsigned int i = 0; i < h_jets->size(); i++)
151  jets[i] = h_jets->refAt(i);
152  break;
153  }
154  } { // else...
155  throw edm::Exception(edm::errors::NotFound) << "Object " << m_jets << " of type among (\"reco::JetTracksAssociationCollection\", \"edm::View<reco::Jet>\") not found";
156  } } while (false);
157 
158  // input primary vetex
159  reco::Vertex vertex;
160  Handle<reco::VertexCollection> h_primaryVertex;
161  event.getByLabel(m_primaryVertex, h_primaryVertex);
162  if (h_primaryVertex.isValid() and not h_primaryVertex->empty())
163  vertex = h_primaryVertex->front();
164  else
165  // fall back to nominal beam spot
166  vertex = s_nominalBeamSpot;
167 
168  // input leptons (can be of different types)
170 
171  Handle< ValueMap<float> > h_leptonCands;
172  bool haveLeptonCands = !(m_leptonCands == edm::InputTag());
173  if (haveLeptonCands)
174  event.getByLabel(m_leptonCands, h_leptonCands);
175 
176  // try to access the input collection as a collection of GsfElectrons, Muons or Tracks
177 
178  unsigned int leptonId = SoftLeptonProperties::quality::leptonId;
179  do { {
180  // look for View<GsfElectron>
181  Handle<GsfElectronView> h_electrons;
182  event.getByLabel(m_leptons, h_electrons);
183 
184  if (h_electrons.isValid()) {
185  leptonId = SoftLeptonProperties::quality::egammaElectronId;
186  for (GsfElectronView::const_iterator electron = h_electrons->begin(); electron != h_electrons->end(); ++electron) {
187  LeptonIds &id = leptons[reco::TrackBaseRef(electron->gsfTrack())];
188  id[SoftLeptonProperties::quality::pfElectronId] = electron->mva();
189  if (haveLeptonCands)
190  id[SoftLeptonProperties::quality::btagElectronCands] = (*h_leptonCands)[h_electrons->refAt(electron - h_electrons->begin())];
191  }
192  break;
193  }
194  } { // else
195  // look for View<Electron>
196  // FIXME: is this obsolete?
197  Handle<ElectronView> h_electrons;
198  event.getByLabel(m_leptons, h_electrons);
199  if (h_electrons.isValid()) {
200  leptonId = SoftLeptonProperties::quality::egammaElectronId;
201  for (ElectronView::const_iterator electron = h_electrons->begin(); electron != h_electrons->end(); ++electron) {
202  LeptonIds &id = leptons[reco::TrackBaseRef(electron->track())];
203  if (haveLeptonCands)
204  id[SoftLeptonProperties::quality::btagElectronCands] = (*h_leptonCands)[h_electrons->refAt(electron - h_electrons->begin())];
205  }
206  break;
207  }
208  } { // else
209  // look for PFElectrons
210  // FIXME: is this obsolete?
212  event.getByLabel(m_leptons, h_electrons);
213  if (h_electrons.isValid()) {
214  leptonId = SoftLeptonProperties::quality::egammaElectronId;
215  for (reco::PFCandidateCollection::const_iterator electron = h_electrons->begin(); electron != h_electrons->end(); ++electron) {
216  LeptonIds *id;
217  if (electron->gsfTrackRef().isNonnull())
218  id = &leptons[reco::TrackBaseRef(electron->gsfTrackRef())];
219  else if (electron->trackRef().isNonnull())
220  id = &leptons[reco::TrackBaseRef(electron->trackRef())];
221  else
222  continue;
223  (*id)[SoftLeptonProperties::quality::pfElectronId] = electron->mva_e_pi();
224  if (haveLeptonCands)
225  (*id)[SoftLeptonProperties::quality::btagElectronCands] = (*h_leptonCands)[reco::PFCandidateRef(h_electrons, electron - h_electrons->begin())];
226  }
227  break;
228  }
229  } { // else
230  // look for View<Muon>
231  Handle<MuonView> h_muons;
232  event.getByLabel(m_leptons, h_muons);
233  if (h_muons.isValid()) {
234  for (MuonView::const_iterator muon = h_muons->begin(); muon != h_muons->end(); ++muon) {
235  // FIXME -> turn this selection into a muonCands input?
237  LeptonIds *id;
238  if (muon->globalTrack().isNonnull())
239  id = &leptons[reco::TrackBaseRef(muon->globalTrack())];
240  else if (muon->innerTrack().isNonnull())
241  id = &leptons[reco::TrackBaseRef(muon->innerTrack())];
242  else if (muon->outerTrack().isNonnull())
243  // does this makes sense ?
244  id = &leptons[reco::TrackBaseRef(muon->outerTrack())];
245  else
246  continue;
247  if (haveLeptonCands)
248  (*id)[SoftLeptonProperties::quality::btagMuonCands] = (*h_leptonCands)[h_muons->refAt(muon - h_muons->begin())];
249  }
250  }
251  break;
252  }
253  } { // else
254  // look for edm::View<Track>
256  event.getByLabel(m_leptons, h_tracks);
257  if (h_tracks.isValid()) {
258  for (unsigned int i = 0; i < h_tracks->size(); i++) {
259  LeptonIds &id = leptons[h_tracks->refAt(i)];
260  if (haveLeptonCands)
261  id[SoftLeptonProperties::quality::btagLeptonCands] = (*h_leptonCands)[h_tracks->refAt(i)];
262  }
263  break;
264  }
265  } { // else
266  throw edm::Exception(edm::errors::NotFound) << "Object " << m_leptons << " of type among (\"edm::View<reco::GsfElectron>\", \"edm::View<reco::Muon>\", \"edm::View<reco::Track>\") !found";
267  } } while (false);
268 
269  if (!(m_leptonId == edm::InputTag())) {
270  Handle< ValueMap<float> > h_leptonId;
271  event.getByLabel(m_leptonId, h_leptonId);
272 
273  for (Leptons::iterator lepton = leptons.begin(); lepton != leptons.end(); ++lepton)
274  lepton->second[leptonId] = (*h_leptonId)[lepton->first];
275  }
276 
277  // output collections
278  std::auto_ptr<reco::SoftLeptonTagInfoCollection> outputCollection( new reco::SoftLeptonTagInfoCollection() );
279  for (unsigned int i = 0; i < jets.size(); ++i) {
280  reco::SoftLeptonTagInfo result = tag( jets[i], tracks[i], leptons, vertex );
281  outputCollection->push_back( result );
282  }
283  event.put( outputCollection );
284 }
285 
286 // ---------------------------------------------------------------------------------------
290  const Leptons & leptons,
291  const reco::Vertex & primaryVertex
292 ) const {
294  info.setJetRef( jet );
295 
296  for(Leptons::const_iterator lepton = leptons.begin(); lepton != leptons.end(); ++lepton) {
297  const math::XYZVector & lepton_momentum = lepton->first->momentum();
298  if (m_chi2Cut > 0.0 && lepton->first->normalizedChi2() > m_chi2Cut)
299  continue;
300 
301  const GlobalVector jetAxis = refineJetAxis( jet, tracks, lepton->first );
302  const math::XYZVector axis( jetAxis.x(), jetAxis.y(), jetAxis.z());
303  if (DeltaR(lepton_momentum, axis) > m_deltaRCut)
304  continue;
305 
306  reco::SoftLeptonProperties properties;
307 
308  reco::TransientTrack transientTrack = m_transientTrackBuilder->build(*lepton->first);
309  properties.sip2d = IPTools::signedTransverseImpactParameter( transientTrack, jetAxis, primaryVertex ).second.significance();
310  properties.sip3d = IPTools::signedImpactParameter3D( transientTrack, jetAxis, primaryVertex ).second.significance();
311  properties.deltaR = DeltaR( lepton_momentum, axis );
312  properties.ptRel = Perp( lepton_momentum, axis );
313  properties.p0Par = boostedPPar( lepton_momentum, axis );
314  properties.etaRel = relativeEta( lepton_momentum, axis );
315  properties.ratio = lepton_momentum.R() / axis.R();
316  properties.ratioRel = lepton_momentum.Dot(axis) / axis.Mag2();
317 
318  for(LeptonIds::const_iterator iter = lepton->second.begin(); iter != lepton->second.end(); ++iter)
319  properties.setQuality(static_cast<SoftLeptonProperties::quality::Generic>(iter->first), iter->second);
320 
321  info.insert( lepton->first, properties );
322  }
323 
324  return info;
325 }
326 
327 
328 // ---------------------------------------------------------------------------------------
332  const reco::TrackBaseRef & exclude /* = reco::TrackBaseRef() */
333 ) const {
334  math::XYZVector axis = jet->momentum();
335 
338 
339  double sum_pT = 0.;
340  double sum_eta_by_pT = 0.;
341  double sum_phi_by_pT = 0.;
342 
343  double perp;
344  double phi_rel;
345  double eta_rel;
346 
347  // refine jet eta and phi with charged tracks measurements, if available
348  for (reco::TrackRefVector::const_iterator track_it = tracks.begin(); track_it != tracks.end(); ++track_it ) {
349  const reco::Track & track = **track_it;
350 
351  perp = track.pt();
352  eta_rel = (double) track.eta() - axis.eta();
353  phi_rel = (double) track.phi() - axis.phi();
354  while (phi_rel < -M_PI) phi_rel += 2*M_PI;
355  while (phi_rel > M_PI) phi_rel -= 2*M_PI;
356 
357  sum_pT += perp;
358  sum_phi_by_pT += perp * phi_rel;
359  sum_eta_by_pT += perp * eta_rel;
360  }
361 
362  // "remove" excluded track
364  const reco::Track & track = *exclude;
365 
366  perp = track.pt();
367  eta_rel = (double) track.eta() - axis.eta();
368  phi_rel = (double) track.phi() - axis.phi();
369  while (phi_rel < -M_PI) phi_rel += 2*M_PI;
370  while (phi_rel > M_PI) phi_rel -= 2*M_PI;
371 
372  sum_pT -= perp;
373  sum_phi_by_pT -= perp * phi_rel;
374  sum_eta_by_pT -= perp * eta_rel;
375  }
376 
377  if (sum_pT > 1.) // avoid the case of only the lepton-track with small rounding errors
378  axis = math::RhoEtaPhiVector( axis.rho(), axis.eta() + sum_eta_by_pT / sum_pT, axis.phi() + sum_phi_by_pT / sum_pT);
379 
380  } else if (m_refineJetAxis == AXIS_CHARGED_SUM or
382  math::XYZVector sum;
383 
384  // recalculate the jet direction as the sum of charget tracks momenta
385  for (reco::TrackRefVector::const_iterator track_it = tracks.begin(); track_it != tracks.end(); ++track_it ) {
386  const reco::Track & track = **track_it;
387  sum += track.momentum();
388  }
389 
390  // "remove" excluded track
391  if (m_refineJetAxis == AXIS_CHARGED_SUM_NOLEPTON and exclude.isNonnull()) {
392  const reco::Track & track = *exclude;
393  sum -= track.momentum();
394  }
395 
396  if (sum.R() > 1.) // avoid the case of only the lepton-track with small rounding errors
397  axis = sum;
399  axis -= exclude->momentum();
400  }
401 
402  return GlobalVector(axis.x(), axis.y(), axis.z());
403 }
404 
405 double SoftLepton::relativeEta(const math::XYZVector& vector, const math::XYZVector& axis) {
406  double mag = vector.r() * axis.r();
407  double dot = vector.Dot(axis);
408  return -log((mag - dot)/(mag + dot)) / 2;
409 }
410 
411 // compute the lepton momentum along the jet axis, in the jet rest frame
412 double SoftLepton::boostedPPar(const math::XYZVector& vector, const math::XYZVector& axis) {
413  static const double lepton_mass = 0.00; // assume a massless (ultrarelativistic) lepton
414  static const double jet_mass = 5.279; // use B±/B0 mass as the jet rest mass [PDG 2007 updates]
415  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> > lepton(vector.Dot(axis) / axis.r(), Perp(vector, axis), 0., lepton_mass);
416  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> > jet( axis.r(), 0., 0., jet_mass );
417  ROOT::Math::BoostX boost( -jet.Beta() );
418  return boost(lepton).x();
419 }
int i
Definition: DBlmapReader.cc:9
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
edm::View< reco::Muon > MuonView
Definition: SoftLepton.cc:83
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:150
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
Definition: deltaR.h:51
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:50
virtual Vector momentum() const
spatial momentum vector
reco::TransientTrack build(const reco::Track *p) const
T y() const
Definition: PV3DBase.h:62
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
std::pair< bool, Measurement1D > signedImpactParameter3D(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:71
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:139
void setJetRef(const edm::Ref< T > &jetRef)
Definition: JetTagInfo.h:25
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:249
RhoEtaPhiVectorD RhoEtaPhiVector
spatial vector with cylindrical internal representation using pseudorapidity
Definition: Vector3D.h:33
double m_chi2Cut
Definition: SoftLepton.h:103
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:244
SelectionType
Selector type.
Definition: MuonSelectors.h:19
std::vector< SoftLeptonTagInfo > SoftLeptonTagInfoCollection
void insert(const edm::RefToBase< reco::Track > &lepton, const SoftLeptonProperties &properties)
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:141
edm::RefToBase< reco::Track > TrackBaseRef
persistent reference to a Track, using views
Definition: TrackFwd.h:22
const edm::InputTag m_leptons
Definition: SoftLepton.h:93
static double relativeEta(const math::XYZVector &vector, const math::XYZVector &axis)
Definition: SoftLepton.cc:405
GlobalVector refineJetAxis(const edm::RefToBase< reco::Jet > &jet, const reco::TrackRefVector &tracks, const edm::RefToBase< reco::Track > &exclude=edm::RefToBase< reco::Track >()) const
Definition: SoftLepton.cc:329
vector< PseudoJet > jets
double pt() const
track transverse momentum
Definition: TrackBase.h:131
T z() const
Definition: PV3DBase.h:63
tuple result
Definition: query.py:137
const edm::InputTag m_primaryVertex
Definition: SoftLepton.h:92
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
AxisType
Definition: SoftLepton.cc:67
const edm::InputTag m_leptonId
Definition: SoftLepton.h:95
edm::Ref< PFCandidateCollection > PFCandidateRef
persistent reference to a PFCandidate
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:76
double m_deltaRCut
Definition: SoftLepton.h:102
const edm::InputTag m_leptonCands
Definition: SoftLepton.h:94
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
unsigned int m_refineJetAxis
Definition: SoftLepton.h:101
#define M_PI
Definition: BFit3D.cc:3
reco::SoftLeptonTagInfo tag(const edm::RefToBase< reco::Jet > &jet, const reco::TrackRefVector &tracks, const Leptons &leptons, const reco::Vertex &primaryVertex) const
Definition: SoftLepton.cc:287
tuple tracks
Definition: testEve_cfg.py:39
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
void setQuality(quality::Generic qual, float value)
const T & get() const
Definition: EventSetup.h:55
SoftLepton(const edm::ParameterSet &iConfig)
Definition: SoftLepton.cc:94
T const * product() const
Definition: ESHandle.h:62
std::map< unsigned int, float > LeptonIds
Definition: SoftLepton.h:57
edm::View< reco::GsfElectron > GsfElectronView
Definition: SoftLepton.cc:81
static const reco::Vertex s_nominalBeamSpot
Definition: SoftLepton.h:109
muon::SelectionType m_muonSelection
Definition: SoftLepton.h:106
T perp() const
Magnitude of transverse component.
T dot(const Basic3DVector &v) const
Scalar product, or &quot;dot&quot; product, with a vector of same type.
std::map< edm::RefToBase< reco::Track >, LeptonIds, TrackCompare > Leptons
Definition: SoftLepton.h:58
const edm::InputTag m_jets
Definition: SoftLepton.h:91
const TransientTrackBuilder * m_transientTrackBuilder
Definition: SoftLepton.h:98
edm::View< reco::Electron > ElectronView
Definition: SoftLepton.cc:82
virtual void produce(edm::Event &event, const edm::EventSetup &setup)
Definition: SoftLepton.cc:115
T x() const
Definition: PV3DBase.h:61
bool isNonnull() const
Checks for non-null.
Definition: RefToBase.h:279
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
tuple size
Write out results.
Global3DVector GlobalVector
Definition: GlobalVector.h:10
static double boostedPPar(const math::XYZVector &vector, const math::XYZVector &axis)
Definition: SoftLepton.cc:412