Skip to content

Commit

Permalink
Merge pull request cms-sw#24 from tstreble/NanoAOD_BPH_dEdX
Browse files Browse the repository at this point in the history
dEdX variables
  • Loading branch information
tstreble authored Sep 13, 2018
2 parents 0906961 + e00bef2 commit c46e48c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
58 changes: 43 additions & 15 deletions PhysicsTools/NanoAOD/plugins/PFCandProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

#include "DataFormats/PatCandidates/interface/PackedCandidate.h"
#include "DataFormats/PatCandidates/interface/CompositeCandidate.h"
#include "DataFormats/PatCandidates/interface/IsolatedTrack.h"
#include "DataFormats/BeamSpot/interface/BeamSpot.h"
#include "DataFormats/Common/interface/RefToPtr.h"

#include "TrackingTools/Records/interface/TransientTrackRecord.h"
#include "TrackingTools/TransientTrack/interface/TransientTrack.h"
Expand Down Expand Up @@ -44,12 +46,14 @@ class PFCandProducer : public edm::EDProducer {

edm::EDGetTokenT<reco::BeamSpot> beamSpotSrc_;
edm::EDGetTokenT<edm::View<pat::PackedCandidate>> PFCandSrc_;
edm::EDGetTokenT<edm::View<pat::IsolatedTrack>> IsoTrackSrc_;

};

PFCandProducer::PFCandProducer(const edm::ParameterSet &iConfig):
beamSpotSrc_( consumes<reco::BeamSpot> ( iConfig.getParameter<edm::InputTag>( "beamSpot" ) ) ),
PFCandSrc_( consumes<edm::View<pat::PackedCandidate>> ( iConfig.getParameter<edm::InputTag>( "PFCandCollection" ) ) )
PFCandSrc_( consumes<edm::View<pat::PackedCandidate>> ( iConfig.getParameter<edm::InputTag>( "PFCandCollection" ) ) ),
IsoTrackSrc_( consumes<edm::View<pat::IsolatedTrack>> ( iConfig.getParameter<edm::InputTag>( "IsoTrackCollection" ) ) )
{
produces<pat::CompositeCandidateCollection>();
}
Expand All @@ -65,7 +69,7 @@ void PFCandProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
iEvent.getByToken(beamSpotSrc_, beamSpotHandle);

if ( ! beamSpotHandle.isValid() ) {
edm::LogError("BToKpipiProducer") << "No beam spot available from EventSetup" ;
edm::LogError("PFCandProducer") << "No beam spot available from EventSetup" ;
}

reco::BeamSpot beamSpot = *beamSpotHandle;
Expand All @@ -75,33 +79,57 @@ void PFCandProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
iEvent.getByToken(PFCandSrc_, pfCandHandle);

unsigned int pfCandNumber = pfCandHandle->size();

edm::Handle<edm::View<pat::IsolatedTrack>> isoTrackHandle;

iEvent.getByToken(IsoTrackSrc_, isoTrackHandle);

unsigned int isoTrackNumber = isoTrackHandle->size();

// Output collection
std::unique_ptr<pat::CompositeCandidateCollection> result( new pat::CompositeCandidateCollection );

for (unsigned int i = 0; i < pfCandNumber; ++i) {

const pat::PackedCandidate & pfCand = (*pfCandHandle)[i];
auto pfCandPtr = edm::Ptr<pat::PackedCandidate>(pfCandHandle,i);

double DCABS = -1.;
double DCABSErr = -1.;
double DCABS = -1.;
double DCABSErr = -1.;

if(pfCand.hasTrackDetails()) {
if(pfCand.hasTrackDetails()) {

pair<double,double> DCA = computeDCA(pfCand,
bFieldHandle,
beamSpot);
pair<double,double> DCA = computeDCA(pfCand,
bFieldHandle,
beamSpot);

DCABS = DCA.first;
DCABSErr = DCA.second;
DCABS = DCA.first;
DCABSErr = DCA.second;

}

double dEdXStrip = -1.;
double dEdXPixel = -1.;

for (unsigned int j = 0; j < isoTrackNumber; ++j) {

const pat::IsolatedTrack & isoTrack = (*isoTrackHandle)[j];
auto pfCand_fromTrack_Ptr = edm::refToPtr(isoTrack.packedCandRef());

if(isoTrack.packedCandRef().isNonnull() && pfCand_fromTrack_Ptr==pfCandPtr){
dEdXStrip = isoTrack.dEdxStrip();
dEdXPixel = isoTrack.dEdxPixel();
}

}
}

pat::CompositeCandidate pfCandNew;
pfCandNew.addDaughter( pfCand );
pfCandNew.addUserFloat("DCASig", DCABS/DCABSErr);
pat::CompositeCandidate pfCandNew;
pfCandNew.addDaughter( pfCand );
pfCandNew.addUserFloat("DCASig", DCABS/DCABSErr);
pfCandNew.addUserFloat("dEdXStrip", dEdXStrip);
pfCandNew.addUserFloat("dEdXPixel", dEdXPixel);

result->push_back(pfCandNew);
result->push_back(pfCandNew);

}

Expand Down
5 changes: 4 additions & 1 deletion PhysicsTools/NanoAOD/python/PFCands_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

PFCand=cms.EDProducer("PFCandProducer",
beamSpot=cms.InputTag("offlineBeamSpot"),
PFCandCollection=cms.InputTag("packedPFCandidates")
PFCandCollection=cms.InputTag("packedPFCandidates"),
IsoTrackCollection=cms.InputTag("isolatedTracks")
)


Expand All @@ -20,6 +21,8 @@
mass = Var("daughter(0).mass()",float,doc="mass"),
pdgId = Var("daughter(0).pdgId()",int,doc="PF pdgID"),
DCASig=Var("userFloat('DCASig')", float,doc="significance of xy-distance of closest approach PFCand-beamspot"),
dEdXStrip=Var("userFloat('dEdXStrip')", float,doc="dE/dX from strips of associated isolated track"),
dEdXPixel=Var("userFloat('dEdXPixel')", float,doc="dE/dX from pixels of associated isolated track"),
dz = Var("daughter(0).dz()",float,doc="dz (with sign) wrt first PV, in cm",precision=10),
dxy = Var("daughter(0).dxy()",float,doc="dxy (with sign) wrt first PV, in cm",precision=10),
),
Expand Down

0 comments on commit c46e48c

Please sign in to comment.