diff --git a/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py b/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py index 498963e8e4740..e9118bbbedc07 100644 --- a/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py +++ b/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py @@ -148,6 +148,7 @@ 'keep recoCentrality_hiCentrality_*_*', 'keep int_centralityBin_*_*', 'keep recoHFFilterInfo_hiHFfilters_*_*', + 'keep *_offlineSlimmedPrimaryVerticesRecovery_*_*', 'keep *_hiEvtPlane_*_*', 'keep *_hiEvtPlaneFlat_*_*' ] diff --git a/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py b/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py index 6fe16e0dce688..8921858d017ea 100644 --- a/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py +++ b/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py @@ -84,6 +84,11 @@ from Configuration.ProcessModifiers.run2_miniAOD_pp_on_AA_103X_cff import run2_miniAOD_pp_on_AA_103X run2_miniAOD_pp_on_AA_103X.toReplaceWith(slimmingTask,cms.Task(primaryVertexAssociationCleaned,slimmingTask.copy())) +from RecoHI.HiTracking.miniAODVertexRecovery_cff import offlinePrimaryVerticesRecovery, offlineSlimmedPrimaryVerticesRecovery +pp_on_AA_2018.toReplaceWith( + slimmingTask, + cms.Task(slimmingTask.copy(), offlinePrimaryVerticesRecovery, offlineSlimmedPrimaryVerticesRecovery)) + from Configuration.Eras.Modifier_phase2_timing_cff import phase2_timing _phase2_timing_slimmingTask = cms.Task(slimmingTask.copy(), offlineSlimmedPrimaryVertices4D) diff --git a/RecoHI/HiTracking/python/miniAODVertexRecovery_cff.py b/RecoHI/HiTracking/python/miniAODVertexRecovery_cff.py new file mode 100644 index 0000000000000..e32f951a04722 --- /dev/null +++ b/RecoHI/HiTracking/python/miniAODVertexRecovery_cff.py @@ -0,0 +1,34 @@ +import FWCore.ParameterSet.Config as cms + +from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import offlinePrimaryVertices + +offlinePrimaryVerticesRecovery = offlinePrimaryVertices.clone( + + isRecoveryIteration = True, + recoveryVtxCollection = "offlinePrimaryVertices", + + TkFilterParameters = dict( + maxNormalizedChi2 = 999.0, + minPixelLayersWithHits= 0, + minSiliconLayersWithHits = 0, + maxD0Significance = 999.0, + minPt = 0.0, + maxEta = 999.0, + trackQuality = "any" + ), + + TkClusParameters = dict( + algorithm = "gap", + TkGapClusParameters = cms.PSet( + zSeparation = cms.double(1.0) + ) + ), + + vertexCollections = [offlinePrimaryVertices.vertexCollections[0].clone()] +) + +from PhysicsTools.PatAlgos.slimming.offlineSlimmedPrimaryVertices_cfi import offlineSlimmedPrimaryVertices +offlineSlimmedPrimaryVerticesRecovery = offlineSlimmedPrimaryVertices.clone( + src = "offlinePrimaryVerticesRecovery", + score = None +) diff --git a/RecoVertex/PrimaryVertexProducer/interface/PrimaryVertexProducer.h b/RecoVertex/PrimaryVertexProducer/interface/PrimaryVertexProducer.h index 16df19b2f0754..4405178d579da 100644 --- a/RecoVertex/PrimaryVertexProducer/interface/PrimaryVertexProducer.h +++ b/RecoVertex/PrimaryVertexProducer/interface/PrimaryVertexProducer.h @@ -82,6 +82,9 @@ class PrimaryVertexProducer : public edm::stream::EDProducer<> { edm::ParameterSet theConfig; bool fVerbose; + bool fRecoveryIteration; + edm::EDGetTokenT recoveryVtxToken; + edm::EDGetTokenT bsToken; edm::EDGetTokenT trkToken; edm::EDGetTokenT > trkTimesToken; diff --git a/RecoVertex/PrimaryVertexProducer/plugins/PrimaryVertexProducer.cc b/RecoVertex/PrimaryVertexProducer/plugins/PrimaryVertexProducer.cc index dcd042d5408bf..abdb054a95f8c 100644 --- a/RecoVertex/PrimaryVertexProducer/plugins/PrimaryVertexProducer.cc +++ b/RecoVertex/PrimaryVertexProducer/plugins/PrimaryVertexProducer.cc @@ -115,6 +115,19 @@ PrimaryVertexProducer::PrimaryVertexProducer(const edm::ParameterSet& conf) : th algorithms.push_back(algorithm); produces(algorithm.label); } + + //check if this is a recovery iteration + fRecoveryIteration = conf.getParameter("isRecoveryIteration"); + if (fRecoveryIteration) { + if (algorithms.empty()) { + throw VertexException("PrimaryVertexProducerAlgorithm: No algorithm specified. "); + } else if (algorithms.size() > 1) { + throw VertexException( + "PrimaryVertexProducerAlgorithm: Running in Recovery mode and more than one algorithm specified. Please " + "only one algorithm."); + } + recoveryVtxToken = consumes(conf.getParameter("recoveryVtxCollection")); + } } PrimaryVertexProducer::~PrimaryVertexProducer() { @@ -149,6 +162,22 @@ void PrimaryVertexProducer::produce(edm::Event& iEvent, const edm::EventSetup& i edm::LogError("UnusableBeamSpot") << "Beamspot with invalid errors " << beamVertexState.error().matrix(); } + //if this is a recovery iteration, check if we already have a valid PV + if (fRecoveryIteration) { + auto const& oldVertices = iEvent.get(recoveryVtxToken); + //look for the first valid (not-BeamSpot) vertex + for (auto const& old : oldVertices) { + if (!(old.isFake())) { + //found a valid vertex, write the first one to the collection and return + //otherwise continue with regular vertexing procedure + auto result = std::make_unique(); + result->push_back(old); + iEvent.put(std::move(result), algorithms.begin()->label); + return; + } + } + } + // get RECO tracks from the event // `tks` can be used as a ptr to a reco::TrackCollection edm::Handle tks; @@ -414,6 +443,8 @@ void PrimaryVertexProducer::fillDescriptions(edm::ConfigurationDescriptions& des psd0.add("algorithm", "DA_vect"); desc.add("TkClusParameters", psd0); } + desc.add("isRecoveryIteration", false); + desc.add("recoveryVtxCollection", {""}); descriptions.add("primaryVertexProducer", desc); } diff --git a/RecoVertex/PrimaryVertexProducer/python/OfflinePrimaryVertices_cfi.py b/RecoVertex/PrimaryVertexProducer/python/OfflinePrimaryVertices_cfi.py index 418ebf4205376..2a5b1e5104b4f 100644 --- a/RecoVertex/PrimaryVertexProducer/python/OfflinePrimaryVertices_cfi.py +++ b/RecoVertex/PrimaryVertexProducer/python/OfflinePrimaryVertices_cfi.py @@ -40,8 +40,10 @@ maxDistanceToBeam = cms.double(1.0), ) ] - ) - + ), + + isRecoveryIteration = cms.bool(False), + recoveryVtxCollection = cms.InputTag("") )