CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/PhysicsTools/PatUtils/src/LeptonVertexSignificance.cc

Go to the documentation of this file.
00001 //
00002 // $Id: LeptonVertexSignificance.cc,v 1.3 2010/10/15 22:44:33 wmtan Exp $
00003 //
00004 
00005 #include "PhysicsTools/PatUtils/interface/LeptonVertexSignificance.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "FWCore/Utilities/interface/Exception.h"
00008 #include "FWCore/Framework/interface/ESHandle.h"
00009 #include "DataFormats/Common/interface/Handle.h"
00010 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
00011 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
00012 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00013 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
00014 #include "DataFormats/VertexReco/interface/Vertex.h"
00015 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00016 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h" 
00017 #include "FWCore/Framework/interface/EventSetup.h"
00018 #include "FWCore/Framework/interface/Event.h"
00019 #include "DataFormats/PatCandidates/interface/Electron.h"
00020 #include "DataFormats/PatCandidates/interface/Muon.h"
00021 
00022 using namespace pat;
00023 
00024 // constructor
00025 LeptonVertexSignificance::LeptonVertexSignificance(const edm::EventSetup & iSetup) {
00026   // instantiate the transient-track builder
00027   edm::ESHandle<TransientTrackBuilder> builder;
00028   iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
00029   theTrackBuilder_ = new TransientTrackBuilder(*builder.product());
00030 }
00031 
00032 // destructor
00033 LeptonVertexSignificance::~LeptonVertexSignificance() {
00034   delete theTrackBuilder_;
00035 }
00036 
00037 // calculate the TrackIsoPt for the lepton object
00038 float LeptonVertexSignificance::calculate(const Electron & theElectron, const edm::Event & iEvent) {
00039   return this->calculate(*theElectron.gsfTrack(), iEvent);
00040 }
00041 
00042 float LeptonVertexSignificance::calculate(const Muon & theMuon, const edm::Event & iEvent) {
00043   return this->calculate(*theMuon.track(), iEvent);
00044 }
00045 
00046 // calculate the TrackIsoPt for the lepton's track
00047 float LeptonVertexSignificance::calculate(const reco::Track & theTrack, const edm::Event & iEvent) {
00048   // FIXME: think more about how to handle events without vertices
00049   // lepton LR calculation should have nothing to do with event selection
00050   edm::Handle<reco::VertexCollection> vertexHandle;
00051   iEvent.getByLabel("offlinePrimaryVerticesFromCTFTracks", vertexHandle);
00052   if (vertexHandle.product()->size() == 0) return 0;
00053   reco::Vertex theVertex = vertexHandle.product()->front();
00054   // calculate the track-vertex association significance
00055   reco::TransientTrack theTrTrack = theTrackBuilder_->build(&theTrack);
00056   GlobalPoint theVertexPoint(theVertex.position().x(), theVertex.position().y(), theVertex.position().z());
00057   FreeTrajectoryState theLeptonNearVertex = theTrTrack.trajectoryStateClosestToPoint(theVertexPoint).theState();
00058   return fabs(theVertex.position().z() - theLeptonNearVertex.position().z())
00059     / sqrt(std::pow(theVertex.zError(), 2) + theLeptonNearVertex.cartesianError().position().czz());
00060 }
00061