File indexing completed on 2024-04-06 12:15:33
0001 #include <memory>
0002
0003 #include "DataFormats/Provenance/interface/ProductProvenance.h"
0004 #include "FWCore/Common/interface/Provenance.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/ParameterSet/interface/Registry.h"
0007 #include "HeavyFlavorAnalysis/Onia2MuMu/interface/OniaVtxReProducer.h"
0008 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
0009
0010 OniaVtxReProducer::OniaVtxReProducer(const edm::Handle<reco::VertexCollection> &handle, const edm::Event &iEvent) {
0011 const edm::Provenance *prov = handle.provenance();
0012 if (prov == nullptr)
0013 throw cms::Exception("CorruptData") << "Vertex handle doesn't have provenance.";
0014 edm::ParameterSet psetFromProvenance = edm::parameterSet(prov->stable(), iEvent.processHistory());
0015
0016 bool is_primary_available = false;
0017 const edm::Provenance *parent_prov = prov;
0018 if (edm::moduleName(prov->stable(), iEvent.processHistory()) != "PrimaryVertexProducer") {
0019 std::vector<edm::BranchID> parents = prov->productProvenance()->parentage().parents();
0020 for (std::vector<edm::BranchID>::const_iterator it = parents.begin(), ed = parents.end(); it != ed; ++it) {
0021 edm::Provenance parprov = iEvent.getProvenance(*it);
0022 if (parprov.friendlyClassName() == "recoVertexs") {
0023 parent_prov = &parprov;
0024 psetFromProvenance = edm::parameterSet(parprov.stable(), iEvent.processHistory());
0025 is_primary_available = true;
0026 break;
0027 }
0028 }
0029 } else
0030 is_primary_available = true;
0031 if (is_primary_available)
0032 prov = parent_prov;
0033 else
0034 throw cms::Exception("Configuration") << "Vertices to re-produce don't come from a PrimaryVertexProducer \n";
0035
0036 configure(psetFromProvenance);
0037
0038
0039 std::vector<edm::BranchID> parents = prov->productProvenance()->parentage().parents();
0040 bool foundTracks = false;
0041 bool foundBeamSpot = false;
0042 for (std::vector<edm::BranchID>::const_iterator it = parents.begin(), ed = parents.end(); it != ed; ++it) {
0043 const edm::Provenance &parprov = iEvent.getProvenance(*it);
0044 if (parprov.friendlyClassName() == "recoTracks") {
0045 tracksTag_ = edm::InputTag(parprov.moduleLabel(), parprov.productInstanceName(), parprov.processName());
0046 foundTracks = true;
0047 if (parprov.moduleLabel() != "generalTracks")
0048 foundTracks = false;
0049 } else if (parprov.friendlyClassName() == "recoBeamSpot") {
0050 beamSpotTag_ = edm::InputTag(parprov.moduleLabel(), parprov.productInstanceName(), parprov.processName());
0051 foundBeamSpot = true;
0052 if (parprov.moduleLabel() != "offlineBeamSpot")
0053 foundBeamSpot = false;
0054 }
0055 }
0056 if (!foundTracks || !foundBeamSpot) {
0057
0058 throw cms::Exception("Configuration")
0059 << "Can't find correct parentage info for vertex collection inputs: " << (foundTracks ? "" : "generalTracks ")
0060 << (foundBeamSpot ? "" : "offlineBeamSpot") << "\n";
0061 }
0062 }
0063
0064 void OniaVtxReProducer::configure(const edm::ParameterSet &iConfig) {
0065 config_ = iConfig;
0066 tracksTag_ = iConfig.getParameter<edm::InputTag>("TrackLabel");
0067 beamSpotTag_ = iConfig.getParameter<edm::InputTag>("beamSpotLabel");
0068 algo_ = std::make_unique<PrimaryVertexProducerAlgorithm>(iConfig);
0069 }
0070
0071 std::vector<TransientVertex> OniaVtxReProducer::makeVertices(const reco::TrackCollection &tracks,
0072 const reco::BeamSpot &bs,
0073 const TransientTrackBuilder &theB) const {
0074 std::vector<reco::TransientTrack> t_tks;
0075 t_tks.reserve(tracks.size());
0076 for (reco::TrackCollection::const_iterator it = tracks.begin(), ed = tracks.end(); it != ed; ++it) {
0077 t_tks.push_back(theB.build(*it));
0078 t_tks.back().setBeamSpot(bs);
0079 }
0080
0081 return algo_->vertices(t_tks, bs, "AdaptiveVertexFitter");
0082 }