CMS 3D CMS Logo

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