CMS 3D CMS Logo

OniaVtxReProducer.cc
Go to the documentation of this file.
10 
12 {
13  const edm::Provenance *prov = handle.provenance();
14  if (prov == 0) 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 is_primary_available = true;
31  if (is_primary_available) prov = parent_prov;
32  else throw cms::Exception("Configuration") << "Vertices to re-produce don't come from a PrimaryVertexProducer \n";
33 
34  configure(psetFromProvenance);
35 
36  // Now we also dig out the ProcessName used for the reco::Tracks and reco::Vertices
37  std::vector<edm::BranchID> parents = prov->productProvenance()->parentage().parents();
38  bool foundTracks = false;
39  bool foundBeamSpot = false;
40  for (std::vector<edm::BranchID>::const_iterator it = parents.begin(), ed = parents.end(); it != ed; ++it) {
41  edm::Provenance parprov = iEvent.getProvenance(*it);
42  if (parprov.friendlyClassName() == "recoTracks") {
43  tracksTag_ = edm::InputTag(parprov.moduleLabel(), parprov.productInstanceName(), parprov.processName());
44  foundTracks = true;
45  if (parprov.moduleLabel() != "generalTracks") foundTracks = false; // this is necessary since we are asking for that in onia2mumu
46  } else if (parprov.friendlyClassName() == "recoBeamSpot") {
47  beamSpotTag_ = edm::InputTag(parprov.moduleLabel(), parprov.productInstanceName(), parprov.processName());
48  foundBeamSpot = true;
49  if (parprov.moduleLabel() != "offlineBeamSpot") foundBeamSpot = false; // this is necessary since we are asking for that in onia2mumu
50  }
51  }
52  if (!foundTracks || !foundBeamSpot) {
53  //edm::LogWarning("OniaVtxReProducer_MissingParentage") <<
54  throw cms::Exception("Configuration") <<
55  "Can't find correct parentage info for vertex collection inputs: " << (foundTracks ? "" : "generalTracks ") << (foundBeamSpot ? "" : "offlineBeamSpot") << "\n";
56  }
57 
58 }
59 
60 void
62 {
63  config_ = iConfig;
64  tracksTag_ = iConfig.getParameter<edm::InputTag>("TrackLabel");
65  beamSpotTag_ = iConfig.getParameter<edm::InputTag>("beamSpotLabel");
66  algo_.reset(new PrimaryVertexProducerAlgorithm(iConfig));
67 }
68 
69 std::vector<TransientVertex>
71  const reco::BeamSpot &bs,
72  const edm::EventSetup &iSetup) const
73 {
75  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",theB);
76 
77  std::vector<reco::TransientTrack> t_tks; t_tks.reserve(tracks.size());
78  for (reco::TrackCollection::const_iterator it = tracks.begin(), ed = tracks.end(); it != ed; ++it) {
79  t_tks.push_back((*theB).build(*it));
80  t_tks.back().setBeamSpot(bs);
81  }
82 
83  return algo_->vertices(t_tks, bs,"AdaptiveVertexFitter");
84 }
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:31
std::unique_ptr< PrimaryVertexProducerAlgorithm > algo_
std::string const & processName() const
Definition: Provenance.h:52
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:230
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:54
const T & get() const
Definition: EventSetup.h:56
std::string const & moduleLabel() const
Definition: Provenance.h:50
edm::ParameterSet config_
edm::InputTag tracksTag_
Parentage const & parentage() const
edm::InputTag beamSpotTag_
std::string const & productInstanceName() const
Definition: Provenance.h:53
Provenance getProvenance(BranchID const &theID) const
Definition: Event.cc:81
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11
Provenance const * provenance() const
Definition: HandleBase.h:83