CMS 3D CMS Logo

TrackAndVertexUnpacker.cc
Go to the documentation of this file.
1 
12 
13 //#include "DataFormats/Common/interface/ValueMap.h"
14 //#include "DataFormats/Common/interface/View.h"
15 //#include "DataFormats/PatCandidates/interface/Vertexing.h"
16 
21 
22 //#include "PhysicsTools/PatAlgos/interface/VertexingHelper.h"
23 
24 namespace pat {
25 
27  public:
28  explicit PATTrackAndVertexUnpacker(const edm::ParameterSet& iConfig);
29  ~PATTrackAndVertexUnpacker() override;
30 
31  void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
32 
33  private:
34  typedef std::vector<edm::InputTag> VInputTag;
35  // configurables
41  };
42 
43 } // namespace pat
44 
46 
47 PATTrackAndVertexUnpacker::PATTrackAndVertexUnpacker(const edm::ParameterSet& iConfig)
48  : Cands_(consumes<std::vector<pat::PackedCandidate>>(iConfig.getParameter<edm::InputTag>("packedCandidates"))),
49  PVs_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("slimmedVertices"))),
51  iConfig.getParameter<edm::InputTag>("slimmedSecondaryVertices"))),
52  AdditionalTracks_(
53  consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("additionalTracks"))) {
54  produces<reco::TrackCollection>();
55  produces<reco::VertexCollection>();
56  produces<reco::VertexCollection>("secondary");
57 }
58 
60 
62  using namespace edm;
63  using namespace std;
64  using namespace reco;
66  iEvent.getByToken(Cands_, cands);
68  iEvent.getByToken(PVs_, pvs);
70  iEvent.getByToken(SVs_, svs);
72  iEvent.getByToken(AdditionalTracks_, addTracks);
73 
74  auto outTks = std::make_unique<std::vector<reco::Track>>();
75  std::map<unsigned int, std::vector<unsigned int>> asso;
76  std::map<unsigned int, unsigned int> trackKeys;
77  unsigned int j = 0;
78  for (unsigned int i = 0; i < cands->size(); i++) {
79  const pat::PackedCandidate& c = (*cands)[i];
80  if (c.hasTrackDetails() && c.charge() != 0 && c.numberOfHits() > 0) {
81  outTks->push_back(c.pseudoTrack());
82  for (size_t ipv = 0; ipv < pvs->size(); ++ipv) {
83  if (c.fromPV(ipv) == pat::PackedCandidate::PVUsedInFit)
84  asso[ipv].push_back(j);
85  }
86  trackKeys[i] = j;
87  j++;
88  }
89  }
90 
91  int offsetAdd = j;
92  for (unsigned int i = 0; i < addTracks->size(); i++) {
93  if ((*addTracks)[i].hasTrackDetails()) {
94  outTks->push_back((*addTracks)[i].pseudoTrack());
95  for (size_t ipv = 0; ipv < pvs->size(); ++ipv) {
96  if ((*addTracks)[i].fromPV(ipv) == pat::PackedCandidate::PVUsedInFit)
97  asso[ipv].push_back(j);
98  }
99  j++;
100  }
101  }
102 
104 
105  auto outPv = std::make_unique<std::vector<reco::Vertex>>();
106 
107  for (size_t ipv = 0; ipv < pvs->size(); ++ipv) {
108  reco::Vertex pv = (*pvs)[ipv];
109  for (unsigned int i = 0; i < asso[ipv].size(); i++) {
110  TrackRef r(oh, asso[ipv][i]);
111  TrackBaseRef rr(r);
112  pv.add(rr);
113  }
114  outPv->push_back(pv);
115  }
116  iEvent.put(std::move(outPv));
117 
118  auto outSv = std::make_unique<std::vector<reco::Vertex>>();
119  for (size_t i = 0; i < svs->size(); i++) {
120  const reco::VertexCompositePtrCandidate& sv = (*svs)[i];
121  outSv->push_back(reco::Vertex(sv.vertex(), sv.vertexCovariance(), sv.vertexChi2(), sv.vertexNdof(), 0));
122  for (size_t j = 0; j < sv.numberOfDaughters(); j++) {
123  TrackRef r;
124  if (sv.daughterPtr(j).id() == cands.id()) {
125  // use trackKeys because cand->track has gaps from neutral
126  r = TrackRef(oh, trackKeys[sv.daughterPtr(j).key()]);
127  } else {
128  // use directly the key because addTracks is only charged
129  r = TrackRef(oh, offsetAdd + sv.daughterPtr(j).key());
130  }
131  TrackBaseRef rr(r);
132  outSv->back().add(rr);
133  }
134  }
135 
136  iEvent.put(std::move(outSv), "secondary");
137 }
138 
140 
edm::StreamID
Definition: StreamID.h:30
mps_fire.i
i
Definition: mps_fire.py:355
edm::EDGetTokenT
Definition: EDGetToken.h:33
findQualityFiles.rr
string rr
Definition: findQualityFiles.py:185
edm
HLT enums.
Definition: AlignableModifier.h:19
reco::VertexCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
pat::PATTrackAndVertexUnpacker::PATTrackAndVertexUnpacker
PATTrackAndVertexUnpacker(const edm::ParameterSet &iConfig)
Definition: TrackAndVertexUnpacker.cc:47
pat::PATTrackAndVertexUnpacker::~PATTrackAndVertexUnpacker
~PATTrackAndVertexUnpacker() override
Definition: TrackAndVertexUnpacker.cc:59
pat::PATTrackAndVertexUnpacker::produce
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
Definition: TrackAndVertexUnpacker.cc:61
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
pat::PATTrackAndVertexUnpacker::AdditionalTracks_
const edm::EDGetTokenT< std::vector< pat::PackedCandidate > > AdditionalTracks_
Definition: TrackAndVertexUnpacker.cc:39
reco::VertexCompositePtrCandidate
Definition: VertexCompositePtrCandidate.h:16
edm::Ref< TrackCollection >
pat::PackedCandidate::PVUsedInFit
Definition: PackedCandidate.h:703
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
pfDeepBoostedJetPreprocessParams_cfi.sv
sv
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:226
VertexCompositePtrCandidate.h
edm::global::EDProducer
Definition: EDProducer.h:32
reco::TrackRef
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
Vertex.h
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
pat::PackedCandidate
Definition: PackedCandidate.h:22
PackedCandidate.h
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
FSQDQM_cfi.pvs
pvs
Definition: FSQDQM_cfi.py:12
InputTag.h
pat::PackedCandidateCollection
std::vector< pat::PackedCandidate > PackedCandidateCollection
Definition: PackedCandidate.h:1130
alignCSCRings.r
r
Definition: alignCSCRings.py:93
VertexFwd.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::OrphanHandle
Definition: EDProductfwd.h:39
pat::PATTrackAndVertexUnpacker::PVs_
const edm::EDGetTokenT< reco::VertexCollection > PVs_
Definition: TrackAndVertexUnpacker.cc:37
pat::PATTrackAndVertexUnpacker::VInputTag
std::vector< edm::InputTag > VInputTag
Definition: TrackAndVertexUnpacker.cc:34
HLT_2018_cff.cands
cands
Definition: HLT_2018_cff.py:13762
edm::RefToBase< reco::Track >
ParameterSet.h
EDProducer.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
pat::PATTrackAndVertexUnpacker
Definition: TrackAndVertexUnpacker.cc:26
reco::Vertex
Definition: Vertex.h:35
pat::PATTrackAndVertexUnpacker::SVs_
const edm::EDGetTokenT< reco::VertexCompositePtrCandidateCollection > SVs_
Definition: TrackAndVertexUnpacker.cc:38
reco::VertexCompositePtrCandidateCollection
std::vector< VertexCompositePtrCandidate > VertexCompositePtrCandidateCollection
collection of Candidate objects
Definition: VertexCompositePtrCandidateFwd.h:19
pat::PATTrackAndVertexUnpacker::Cands_
const edm::EDGetTokenT< std::vector< pat::PackedCandidate > > Cands_
Definition: TrackAndVertexUnpacker.cc:36