CMS 3D CMS Logo

OniaVtxReProducer.cc
Go to the documentation of this file.
1 #include <memory>
2 
9 
11  const edm::Provenance *prov = handle.provenance();
12  if (prov == nullptr)
13  throw cms::Exception("CorruptData") << "Vertex handle doesn't have provenance.";
14  edm::ParameterSet psetFromProvenance = edm::parameterSet(*prov, iEvent.processHistory());
15 
16  bool is_primary_available = false;
17  const edm::Provenance *parent_prov = prov;
18  if (edm::moduleName(*prov, iEvent.processHistory()) != "PrimaryVertexProducer") {
19  std::vector<edm::BranchID> parents = prov->productProvenance()->parentage().parents();
20  for (std::vector<edm::BranchID>::const_iterator it = parents.begin(), ed = parents.end(); it != ed; ++it) {
21  edm::Provenance parprov = iEvent.getProvenance(*it);
22  if (parprov.friendlyClassName() == "recoVertexs") { // for AOD actually this the parent we should look for
23  parent_prov = &parprov;
24  psetFromProvenance = edm::parameterSet(parprov, iEvent.processHistory());
25  is_primary_available = true;
26  break;
27  }
28  }
29  } else
30  is_primary_available = true;
31  if (is_primary_available)
32  prov = parent_prov;
33  else
34  throw cms::Exception("Configuration") << "Vertices to re-produce don't come from a PrimaryVertexProducer \n";
35 
36  configure(psetFromProvenance);
37 
38  // Now we also dig out the ProcessName used for the reco::Tracks and reco::Vertices
39  std::vector<edm::BranchID> parents = prov->productProvenance()->parentage().parents();
40  bool foundTracks = false;
41  bool foundBeamSpot = false;
42  for (std::vector<edm::BranchID>::const_iterator it = parents.begin(), ed = parents.end(); it != ed; ++it) {
43  edm::Provenance parprov = iEvent.getProvenance(*it);
44  if (parprov.friendlyClassName() == "recoTracks") {
45  tracksTag_ = edm::InputTag(parprov.moduleLabel(), parprov.productInstanceName(), parprov.processName());
46  foundTracks = true;
47  if (parprov.moduleLabel() != "generalTracks")
48  foundTracks = false; // this is necessary since we are asking for that in onia2mumu
49  } else if (parprov.friendlyClassName() == "recoBeamSpot") {
50  beamSpotTag_ = edm::InputTag(parprov.moduleLabel(), parprov.productInstanceName(), parprov.processName());
51  foundBeamSpot = true;
52  if (parprov.moduleLabel() != "offlineBeamSpot")
53  foundBeamSpot = false; // this is necessary since we are asking for that in onia2mumu
54  }
55  }
56  if (!foundTracks || !foundBeamSpot) {
57  //edm::LogWarning("OniaVtxReProducer_MissingParentage") <<
58  throw cms::Exception("Configuration")
59  << "Can't find correct parentage info for vertex collection inputs: " << (foundTracks ? "" : "generalTracks ")
60  << (foundBeamSpot ? "" : "offlineBeamSpot") << "\n";
61  }
62 }
63 
65  config_ = iConfig;
66  tracksTag_ = iConfig.getParameter<edm::InputTag>("TrackLabel");
67  beamSpotTag_ = iConfig.getParameter<edm::InputTag>("beamSpotLabel");
68  algo_ = std::make_unique<PrimaryVertexProducerAlgorithm>(iConfig);
69 }
70 
71 std::vector<TransientVertex> OniaVtxReProducer::makeVertices(const reco::TrackCollection &tracks,
72  const reco::BeamSpot &bs,
73  const TransientTrackBuilder &theB) const {
74  std::vector<reco::TransientTrack> t_tks;
75  t_tks.reserve(tracks.size());
76  for (reco::TrackCollection::const_iterator it = tracks.begin(), ed = tracks.end(); it != ed; ++it) {
77  t_tks.push_back(theB.build(*it));
78  t_tks.back().setBeamSpot(bs);
79  }
80 
81  return algo_->vertices(t_tks, bs, "AdaptiveVertexFitter");
82 }
edm::Provenance::moduleLabel
std::string const & moduleLabel() const
Definition: Provenance.h:55
edm::Parentage::parents
std::vector< BranchID > const & parents() const
Definition: Parentage.h:44
OniaVtxReProducer::algo_
std::unique_ptr< PrimaryVertexProducerAlgorithm > algo_
Definition: OniaVtxReProducer.h:43
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
MessageLogger.h
patZpeak.handle
handle
Definition: patZpeak.py:23
OniaVtxReProducer::OniaVtxReProducer
OniaVtxReProducer(const edm::Handle< reco::VertexCollection > &configFromOriginalVertexCollection, const edm::Event &iEvent)
This is the real constructor to be used.
Definition: OniaVtxReProducer.cc:10
OniaVtxReProducer::beamSpotTag_
edm::InputTag beamSpotTag_
Definition: OniaVtxReProducer.h:42
edm::Provenance::productProvenance
ProductProvenance const * productProvenance() const
Definition: Provenance.cc:24
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
TransientTrack.h
edm::Handle< reco::VertexCollection >
OniaVtxReProducer::makeVertices
std::vector< TransientVertex > makeVertices(const reco::TrackCollection &tracks, const reco::BeamSpot &bs, const TransientTrackBuilder &theB) const
Make the vertices.
Definition: OniaVtxReProducer.cc:71
OniaVtxReProducer::configure
void configure(const edm::ParameterSet &iConfig)
Definition: OniaVtxReProducer.cc:64
cms::cuda::bs
bs
Definition: HistoContainer.h:127
edm::Provenance::processName
std::string const & processName() const
Definition: Provenance.h:57
ProductProvenance.h
reco::BeamSpot
Definition: BeamSpot.h:21
OniaVtxReProducer.h
edm::Provenance::productInstanceName
std::string const & productInstanceName() const
Definition: Provenance.h:58
OniaVtxReProducer::config_
edm::ParameterSet config_
Definition: OniaVtxReProducer.h:40
edm::ParameterSet
Definition: ParameterSet.h:47
iEvent
int iEvent
Definition: GenABIO.cc:224
OniaVtxReProducer::tracksTag_
edm::InputTag tracksTag_
Definition: OniaVtxReProducer.h:41
TransientTrackBuilder
Definition: TransientTrackBuilder.h:16
Registry.h
edm::Provenance::friendlyClassName
std::string const & friendlyClassName() const
Definition: Provenance.h:59
Exception
Definition: hltDiff.cc:246
edm::parameterSet
ParameterSet const & parameterSet(Provenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
Provenance.h
edm::ProductProvenance::parentage
Parentage const & parentage() const
Definition: ProductProvenance.cc:39
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
TransientTrackBuilder::build
reco::TransientTrack build(const reco::Track *p) const
Definition: TransientTrackBuilder.cc:20
edm::moduleName
std::string moduleName(Provenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:27
parents
TPRegexp parents
Definition: eve_filter.cc:21
edm::Provenance
Definition: Provenance.h:34
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14