Skip to content

Commit

Permalink
Merge pull request #13256 from alberto-sanchez/onia2mumu-80x
Browse files Browse the repository at this point in the history
Onia2mumu fixing muonless PV option
  • Loading branch information
davidlange6 committed Feb 15, 2016
2 parents 83a2662 + d063eea commit 89debf0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
2 changes: 2 additions & 0 deletions HeavyFlavorAnalysis/Onia2MuMu/interface/Onia2MuMuPAT.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class Onia2MuMuPAT : public edm::EDProducer {
edm::EDGetTokenT<edm::View<pat::Muon>> muons_;
edm::EDGetTokenT<reco::BeamSpot> thebeamspot_;
edm::EDGetTokenT<reco::VertexCollection> thePVs_;
edm::EDGetTokenT<reco::TrackCollection> revtxtrks_;
edm::EDGetTokenT<reco::BeamSpot> revtxbs_;
StringCutObjectSelector<pat::Muon> higherPuritySelection_;
StringCutObjectSelector<pat::Muon> lowerPuritySelection_;
StringCutObjectSelector<reco::Candidate, true> dimuonSelection_;
Expand Down
5 changes: 3 additions & 2 deletions HeavyFlavorAnalysis/Onia2MuMu/src/Onia2MuMuPAT.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Onia2MuMuPAT::Onia2MuMuPAT(const edm::ParameterSet& iConfig):
resolveAmbiguity_(iConfig.getParameter<bool>("resolvePileUpAmbiguity")),
addMCTruth_(iConfig.getParameter<bool>("addMCTruth"))
{
revtxtrks_ = consumes<reco::TrackCollection>((edm::InputTag)"generalTracks"); //if that is not true, we will raise an exception
revtxbs_ = consumes<reco::BeamSpot>((edm::InputTag)"offlineBeamSpot");
produces<pat::CompositeCandidateCollection>();
}

Expand Down Expand Up @@ -181,13 +183,11 @@ Onia2MuMuPAT::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
if( addMuonlessPrimaryVertex_ && thePrimaryV.tracksSize()>2) {
// Primary vertex matched to the dimuon, now refit it removing the two muons
OniaVtxReProducer revertex(priVtxs, iEvent);
edm::EDGetTokenT<reco::TrackCollection> revtxtrks_ = consumes<reco::TrackCollection>(revertex.inputTracks());
edm::Handle<reco::TrackCollection> pvtracks;
iEvent.getByToken(revtxtrks_, pvtracks);
if( !pvtracks.isValid()) { std::cout << "pvtracks NOT valid " << std::endl; }
else {
edm::Handle<reco::BeamSpot> pvbeamspot;
edm::EDGetTokenT<reco::BeamSpot> revtxbs_ = consumes<reco::BeamSpot>(revertex.inputBeamSpot());
iEvent.getByToken(revtxbs_, pvbeamspot);
if (pvbeamspot.id() != theBeamSpot.id()) edm::LogWarning("Inconsistency") << "The BeamSpot used for PV reco is not the same used in this analyzer.";
// I need to go back to the reco::Muon object, as the TrackRef in the pat::Muon can be an embedded ref.
Expand Down Expand Up @@ -324,6 +324,7 @@ Onia2MuMuPAT::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
myCand.addUserFloat("cosAlpha",-100);
myCand.addUserFloat("ppdlBS",-100);
myCand.addUserFloat("ppdlErrBS",-100);
myCand.addUserFloat("DCA", -1 );
if (addCommonVertex_) {
myCand.addUserData("commonVertex",Vertex());
}
Expand Down
36 changes: 23 additions & 13 deletions HeavyFlavorAnalysis/Onia2MuMu/src/OniaVtxReProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,24 @@ OniaVtxReProducer::OniaVtxReProducer(const edm::Handle<reco::VertexCollection> &
{
const edm::Provenance *prov = handle.provenance();
if (prov == 0) throw cms::Exception("CorruptData") << "Vertex handle doesn't have provenance.";
// edm::ParameterSetID psid = prov->psetID();

// edm::pset::Registry *psregistry = edm::pset::Registry::instance();
edm::ParameterSet psetFromProvenance = edm::parameterSet(*prov);
// if (!psregistry->getMapped(psid, psetFromProvenance))
// throw cms::Exception("CorruptData") << "Vertex handle parameter set ID id = " << psid;

if (edm::moduleName(*prov) != "RecoChargedRefCandidatePrimaryVertexSorter" )
//if (edm::moduleName(*prov) != "PrimaryVertexProducer")
throw cms::Exception("Configuration") << "Vertices to re-produce don't come from a PrimaryVertexProducer, but from a "
<< edm::moduleName(*prov) <<".\n";
bool is_primary_available = false;
const edm::Provenance *parent_prov = prov;
if (edm::moduleName(*prov) != "PrimaryVertexProducer") {
std::vector<edm::BranchID> parents = prov->productProvenance()->parentage().parents();
for (std::vector<edm::BranchID>::const_iterator it = parents.begin(), ed = parents.end(); it != ed; ++it) {
edm::Provenance parprov = iEvent.getProvenance(*it);
if (parprov.friendlyClassName() == "recoVertexs") { // for AOD actually this the parent we should look for
parent_prov = &parprov;
psetFromProvenance = edm::parameterSet(parprov);
is_primary_available = true;
break;
}
}
} else is_primary_available = true;
if (is_primary_available) prov = parent_prov;
else throw cms::Exception("Configuration") << "Vertices to re-produce don't come from a PrimaryVertexProducer \n";

configure(psetFromProvenance);

Expand All @@ -35,16 +42,19 @@ OniaVtxReProducer::OniaVtxReProducer(const edm::Handle<reco::VertexCollection> &
if (parprov.friendlyClassName() == "recoTracks") {
tracksTag_ = edm::InputTag(parprov.moduleLabel(), parprov.productInstanceName(), parprov.processName());
foundTracks = true;
if (parprov.moduleLabel() != "generalTracks") foundTracks = false; // this is necessary since we are asking for that in onia2mumu
} else if (parprov.friendlyClassName() == "recoBeamSpot") {
beamSpotTag_ = edm::InputTag(parprov.moduleLabel(), parprov.productInstanceName(), parprov.processName());
foundBeamSpot = true;
if (parprov.moduleLabel() != "offlineBeamSpot") foundBeamSpot = false; // this is necessary since we are asking for that in onia2mumu
}
}
if (!foundTracks || !foundBeamSpot) {
edm::LogWarning("OniaVtxReProducer_MissingParentage") <<
"Can't find parentage info for vertex collection inputs: " <<
(foundTracks ? "" : "tracks ") << (foundBeamSpot ? "" : "beamSpot") << "\n";
//edm::LogWarning("OniaVtxReProducer_MissingParentage") <<
throw cms::Exception("Configuration") <<
"Can't find correct parentage info for vertex collection inputs: " << (foundTracks ? "" : "generalTracks ") << (foundBeamSpot ? "" : "offlineBeamSpot") << "\n";
}

}

void
Expand All @@ -70,5 +80,5 @@ OniaVtxReProducer::makeVertices(const reco::TrackCollection &tracks,
t_tks.back().setBeamSpot(bs);
}

return algo_->vertices(t_tks, bs,"KalmanVertexFitter");
return algo_->vertices(t_tks, bs,"AdaptiveVertexFitter");
}

0 comments on commit 89debf0

Please sign in to comment.