Skip to content

Commit

Permalink
works now
Browse files Browse the repository at this point in the history
  • Loading branch information
lgray committed Oct 10, 2016
1 parent 4717543 commit 4067e4b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class VertexAssociatorByPositionAndTracksProducer: public edm::global::EDProduce
const double absZ_;
const double sigmaZ_;
const double maxRecoZ_;
const double absT_;
const double sigmaT_;
const double maxRecoT_;
const double sharedTrackFraction_;

edm::EDGetTokenT<reco::RecoToSimCollection> trackRecoToSimAssociationToken_;
Expand All @@ -37,6 +40,9 @@ VertexAssociatorByPositionAndTracksProducer::VertexAssociatorByPositionAndTracks
absZ_(config.getParameter<double>("absZ")),
sigmaZ_(config.getParameter<double>("sigmaZ")),
maxRecoZ_(config.getParameter<double>("maxRecoZ")),
absT_(config.getParameter<double>("absT")),
sigmaT_(config.getParameter<double>("sigmaT")),
maxRecoT_(config.getParameter<double>("maxRecoT")),
sharedTrackFraction_(config.getParameter<double>("sharedTrackFraction")),
trackRecoToSimAssociationToken_(consumes<reco::RecoToSimCollection>(config.getParameter<edm::InputTag>("trackAssociation"))),
trackSimToRecoAssociationToken_(consumes<reco::SimToRecoCollection>(config.getParameter<edm::InputTag>("trackAssociation")))
Expand All @@ -53,6 +59,9 @@ void VertexAssociatorByPositionAndTracksProducer::fillDescriptions(edm::Configur
desc.add<double>("absZ", 0.1);
desc.add<double>("sigmaZ", 3.0);
desc.add<double>("maxRecoZ", 1000.0);
desc.add<double>("absT", -1.0);
desc.add<double>("sigmaT", -1.0);
desc.add<double>("maxRecoT", -1.0);
desc.add<double>("sharedTrackFraction", -1.0);

// Track-TrackingParticle association
Expand All @@ -68,13 +77,27 @@ void VertexAssociatorByPositionAndTracksProducer::produce(edm::StreamID, edm::Ev
edm::Handle<reco::SimToRecoCollection > simtorecoCollectionH;
iEvent.getByToken(trackSimToRecoAssociationToken_, simtorecoCollectionH);

auto impl = std::make_unique<VertexAssociatorByPositionAndTracks>(&(iEvent.productGetter()),
absZ_,
sigmaZ_,
maxRecoZ_,
sharedTrackFraction_,
recotosimCollectionH.product(),
simtorecoCollectionH.product());
std::unique_ptr<VertexAssociatorByPositionAndTracks> impl;
if( sigmaT_ < 0.0 ) {
impl = std::make_unique<VertexAssociatorByPositionAndTracks>(&(iEvent.productGetter()),
absZ_,
sigmaZ_,
maxRecoZ_,
sharedTrackFraction_,
recotosimCollectionH.product(),
simtorecoCollectionH.product());
} else {
impl = std::make_unique<VertexAssociatorByPositionAndTracks>(&(iEvent.productGetter()),
absZ_,
sigmaZ_,
maxRecoZ_,
absT_,
sigmaT_,
maxRecoT_,
sharedTrackFraction_,
recotosimCollectionH.product(),
simtorecoCollectionH.product());
}

auto toPut = std::make_unique<reco::VertexToTrackingVertexAssociator>(std::move(impl));
iEvent.put(std::move(toPut));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "SimTracker/VertexAssociation/interface/VertexAssociatorByPositionAndTracks.h"
#include "SimTracker/VertexAssociation/interface/calculateVertexSharedTracks.h"
#include "CLHEP/Units/GlobalSystemOfUnits.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"

Expand Down Expand Up @@ -81,12 +82,21 @@ reco::VertexRecoToSimCollection VertexAssociatorByPositionAndTracks::associateRe

LogTrace("VertexAssociation") << " Considering TrackingVertex at Z " << simVertex.position().z();

// recoVertex.t() == 0. is a special value
// need to change this to std::numeric_limits<double>::max() or something more clear
const bool useTiming = ( absT_ != std::numeric_limits<double>::max() && recoVertex.t() != 0. );
if( useTiming ) {
LogTrace("VertexAssociation") << " and T " << recoVertex.t()*CLHEP::second << std::endl;
}

const double tdiff = std::abs(recoVertex.t() - simVertex.position().t()*CLHEP::second);
const double zdiff = std::abs(recoVertex.z() - simVertex.position().z());
if(zdiff < absZ_ && zdiff / recoVertex.zError() < sigmaZ_) {
if( zdiff < absZ_ && zdiff / recoVertex.zError() < sigmaZ_ &&
( !useTiming || ( tdiff < absT_ && tdiff / recoVertex.tError() < sigmaT_ ) ) ) {
auto sharedTracks = calculateVertexSharedTracks(recoVertex, simVertex, *trackRecoToSimAssociation_);
auto fraction = double(sharedTracks)/recoVertex.tracksSize();
if(sharedTrackFraction_ < 0 || fraction > sharedTrackFraction_) {
LogTrace("VertexAssociation") << " Matched with significance " << zdiff/recoVertex.zError()
LogTrace("VertexAssociation") << " Matched with significance " << zdiff/recoVertex.zError() << " " << tdiff/recoVertex.tError()
<< " shared tracks " << sharedTracks << " reco Tracks " << recoVertex.tracksSize() << " TrackingParticles " << simVertex.nDaughterTracks();

ret.insert(reco::VertexBaseRef(vCH, iReco), std::make_pair(TrackingVertexRef(tVCH, iSim), sharedTracks));
Expand Down Expand Up @@ -136,13 +146,19 @@ reco::VertexSimToRecoCollection VertexAssociatorByPositionAndTracks::associateSi
continue;

LogTrace("VertexAssociation") << " Considering reco::Vertex at Z " << recoVertex.z();
const bool useTiming = ( absT_ != std::numeric_limits<double>::max() && recoVertex.t() != 0. );
if( useTiming ) {
LogTrace("VertexAssociation") << " and T " << recoVertex.t()*CLHEP::second << std::endl;
}

const double tdiff = std::abs(recoVertex.t() - simVertex.position().t()*CLHEP::second);
const double zdiff = std::abs(recoVertex.z() - simVertex.position().z());
if(zdiff < absZ_ && zdiff / recoVertex.zError() < sigmaZ_) {
if( zdiff < absZ_ && zdiff / recoVertex.zError() < sigmaZ_ &&
( !useTiming || ( tdiff < absT_ && tdiff / recoVertex.tError() < sigmaT_ ) ) ) {
auto sharedTracks = calculateVertexSharedTracks(simVertex, recoVertex, *trackSimToRecoAssociation_);
auto fraction = double(sharedTracks)/recoVertex.tracksSize();
if(sharedTrackFraction_ < 0 || fraction > sharedTrackFraction_) {
LogTrace("VertexAssociation") << " Matched with significance " << zdiff/recoVertex.zError()
LogTrace("VertexAssociation") << " Matched with significance " << zdiff/recoVertex.zError() << " " << tdiff/recoVertex.tError()
<< " shared tracks " << sharedTracks << " reco Tracks " << recoVertex.tracksSize() << " TrackingParticles " << simVertex.nDaughterTracks();

ret.insert(TrackingVertexRef(tVCH, iSim), std::make_pair(reco::VertexBaseRef(vCH, iReco), sharedTracks));
Expand Down

0 comments on commit 4067e4b

Please sign in to comment.