CMS 3D CMS Logo

SoftPFMuonTagInfoProducer.cc
Go to the documentation of this file.
1 // * Author: Alberto Zucchetta
2 // * Mail: a.zucchetta@cern.ch
3 // * January 16, 2015
4 
18 // Muons
24 
26 
27 // Transient Track and IP
33 #include <cmath>
34 
36  jetToken = consumes<edm::View<reco::Jet> >(conf.getParameter<edm::InputTag>("jets"));
37  muonToken = consumes<edm::View<reco::Muon> >(conf.getParameter<edm::InputTag>("muons"));
38  vertexToken = consumes<reco::VertexCollection>(conf.getParameter<edm::InputTag>("primaryVertex"));
39  pTcut = conf.getParameter<double>("muonPt");
40  SIPsigcut = conf.getParameter<double>("muonSIPsig");
41  IPsigcut = conf.getParameter<double>("filterIpsig");
42  ratio1cut = conf.getParameter<double>("filterRatio1");
43  ratio2cut = conf.getParameter<double>("filterRatio2");
44  useFilter = conf.getParameter<bool>("filterPromptMuons");
45  produces<reco::CandSoftLeptonTagInfoCollection>();
46 }
47 
49 
51  // Declare produced collection
52  auto theMuonTagInfo = std::make_unique<reco::CandSoftLeptonTagInfoCollection>();
53 
54  // Declare and open Jet collection
55  edm::Handle<edm::View<reco::Jet> > theJetCollection;
56  iEvent.getByToken(jetToken, theJetCollection);
57 
58  // Declare Muon collection
59  edm::Handle<edm::View<reco::Muon> > theMuonCollection;
60  iEvent.getByToken(muonToken, theMuonCollection);
61 
62  // Declare and open Vertex collection
63  edm::Handle<reco::VertexCollection> theVertexCollection;
64  iEvent.getByToken(vertexToken, theVertexCollection);
65  if(!theVertexCollection.isValid() || theVertexCollection->empty()) return;
66  const reco::Vertex* vertex=&theVertexCollection->front();
67 
68  // Biult TransientTrackBuilder
70  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", theTrackBuilder);
71  const TransientTrackBuilder* transientTrackBuilder=theTrackBuilder.product();
72 
73  // Loop on jets
74  for(unsigned int ij=0, nj=theJetCollection->size(); ij<nj; ij++) {
75  edm::RefToBase<reco::Jet> jetRef = theJetCollection->refAt(ij);
76  // Build TagInfo object
78  tagInfo.setJetRef(jetRef);
79  // Loop on jet daughters
80  for(unsigned int id=0, nd=jetRef->numberOfDaughters(); id<nd; ++id) {
81  edm::Ptr<reco::Candidate> lepPtr = jetRef->daughterPtr(id);
82  if(std::abs(lepPtr->pdgId())!=13) continue;
83 
84  const reco::Muon* muon(nullptr);
85  // Step 1: try to access the muon from reco::PFCandidate
86  const reco::PFCandidate* pfcand=dynamic_cast<const reco::PFCandidate*>(lepPtr.get());
87  if(pfcand) {
88  muon=pfcand->muonRef().get();
89  }
90  // If not PFCandidate is available, find a match looping on the muon collection
91  else {
92  for(unsigned int im=0, nm=theMuonCollection->size(); im<nm; ++im) { // --- Begin loop on muons
93  const reco::Muon* recomuon=&theMuonCollection->at(im);
94  const pat::Muon* patmuon=dynamic_cast<const pat::Muon*>(recomuon);
95  // Step 2: try a match between reco::Candidate
96  if(patmuon) {
97  if(patmuon->originalObjectRef()==lepPtr) {
98  muon=theMuonCollection->refAt(im).get();
99  break;
100  }
101  }
102  // Step 3: try a match with dR and dpT if pat::Muon casting fails
103  else {
104  if(reco::deltaR(*recomuon, *lepPtr)<0.01 && std::abs(recomuon->pt()-lepPtr->pt())/lepPtr->pt()<0.1) {
105  muon=theMuonCollection->refAt(im).get();
106  break;
107  }
108  }
109  } // --- End loop on muons
110  }
111  if(!muon || !muon::isLooseMuon(*muon) || muon->pt()<pTcut) continue;
112  reco::TrackRef trkRef( muon->innerTrack() );
113  reco::TrackBaseRef trkBaseRef( trkRef );
114  // Build Transient Track
115  reco::TransientTrack transientTrack=transientTrackBuilder->build(trkRef);
116  // Define jet and muon vectors
117  reco::Candidate::Vector jetvect(jetRef->p4().Vect()), muonvect(muon->p4().Vect());
118  // Calculate variables
119  reco::SoftLeptonProperties properties;
120  Measurement1D ip2d = IPTools::signedTransverseImpactParameter(transientTrack, GlobalVector(jetRef->px(), jetRef->py(), jetRef->pz()), *vertex).second;
121  Measurement1D ip3d = IPTools::signedImpactParameter3D(transientTrack, GlobalVector(jetRef->px(), jetRef->py(), jetRef->pz()), *vertex).second;
122  properties.sip2dsig = ip2d.significance();
123  properties.sip3dsig = ip3d.significance();
124  properties.sip2d = ip2d.value();
125  properties.sip3d = ip3d.value();
126  properties.deltaR = reco::deltaR(*jetRef, *muon);
127  properties.ptRel = ( (jetvect-muonvect).Cross(muonvect) ).R() / jetvect.R(); // | (Pj-Pu) X Pu | / | Pj |
128  float mag = muonvect.R()*jetvect.R();
129  float dot = muon->p4().Dot(jetRef->p4());
130  properties.etaRel = -log((mag - dot)/(mag + dot)) / 2.;
131  properties.ratio = muon->pt() / jetRef->pt();
132  properties.ratioRel = muon->p4().Dot(jetRef->p4()) / jetvect.Mag2();
133  properties.p0Par = boostedPPar(muon->momentum(), jetRef->momentum());
134  properties.charge = muon->charge();
135 
136  if(std::abs(properties.sip3dsig)>SIPsigcut) continue;
137 
138  // Filter leptons from W, Z decays
139  if(useFilter && ((std::abs(properties.sip3dsig)<IPsigcut && properties.ratio>ratio1cut) || properties.ratio>ratio2cut)) continue;
140 
141  // Insert lepton properties
142  tagInfo.insert(lepPtr, properties);
143 
144  } // --- End loop on daughters
145 
146  // Fill the TagInfo collection
147  theMuonTagInfo->push_back(tagInfo);
148  } // --- End loop on jets
149 
150  // Put the TagInfo collection in the event
151  iEvent.put(std::move(theMuonTagInfo));
152 }
153 
154 
155 // compute the lepton momentum along the jet axis, in the jet rest frame
157  static const double lepton_mass = 0.00; // assume a massless (ultrarelativistic) lepton
158  static const double jet_mass = 5.279; // use B±/B0 mass as the jet rest mass [PDG 2007 updates]
159  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> > lepton(vector.Dot(axis) / axis.r(), ROOT::Math::VectorUtil::Perp(vector, axis), 0., lepton_mass);
160  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> > jet( axis.r(), 0., 0., jet_mass );
161  ROOT::Math::BoostX boost( -jet.Beta() );
162  return boost(lepton).x();
163 }
164 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
math::XYZVector Vector
point in the space
Definition: Candidate.h:43
Definition: CLHEP.h:16
virtual TrackRef innerTrack() const
Definition: Muon.h:48
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:159
double px() const final
x coordinate of momentum vector
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:50
reco::TransientTrack build(const reco::Track *p) const
std::pair< bool, Measurement1D > signedImpactParameter3D(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:71
double pt() const final
transverse momentum
int charge() const final
electric charge
Definition: LeafCandidate.h:91
void produce(edm::Event &, const edm::EventSetup &) override
void setJetRef(const edm::Ref< T > &jetRef)
Definition: JetTagInfo.h:25
bool isLooseMuon(const reco::Muon &)
size_t numberOfDaughters() const override
number of daughters
Vector momentum() const final
spatial momentum vector
int iEvent
Definition: GenABIO.cc:224
double pz() const final
z coordinate of momentum vector
virtual int pdgId() const =0
PDG identifier.
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< edm::View< reco::Jet > > jetToken
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:243
const edm::Ptr< reco::Candidate > & originalObjectRef() const
reference to original object. Returns a null reference if not available
Definition: PATObject.h:500
bool isValid() const
Definition: HandleBase.h:74
virtual float boostedPPar(const math::XYZVector &, const math::XYZVector &)
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:459
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
void insert(const REF &lepton, const SoftLeptonProperties &properties)
double significance() const
Definition: Measurement1D.h:29
virtual double pt() const =0
transverse momentum
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
virtual CandidatePtr daughterPtr(size_type i) const
reference to daughter at given position
double py() const final
y coordinate of momentum vector
double value() const
Definition: Measurement1D.h:25
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
edm::EDGetTokenT< reco::VertexCollection > vertexToken
T dot(const Basic3DVector &v) const
Scalar product, or "dot" product, with a vector of same type.
SoftPFMuonTagInfoProducer(const edm::ParameterSet &conf)
T get() const
Definition: EventSetup.h:71
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken
T const * product() const
Definition: ESHandle.h:86
Analysis-level muon class.
Definition: Muon.h:51
def move(src, dest)
Definition: eostools.py:511
Global3DVector GlobalVector
Definition: GlobalVector.h:10