2
2
3
3
// user include files
4
4
#include " CommonTools/Utils/interface/StringCutObjectSelector.h"
5
- #include " DataFormats/Candidate/interface/VertexCompositePtrCandidate.h"
6
5
#include " DataFormats/Common/interface/ValueMap.h"
7
6
#include " DataFormats/NanoAOD/interface/FlatTable.h"
8
7
#include " DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
@@ -37,6 +36,7 @@ class HLTVertexTableProducer : public edm::stream::EDProducer<> {
37
36
const edm::EDGetTokenT<edm::ValueMap<float >> pvsScore_;
38
37
const StringCutObjectSelector<reco::Vertex> goodPvCut_;
39
38
const std::string goodPvCutString_;
39
+ const bool usePF_;
40
40
const std::string pvName_;
41
41
const double dlenMin_, dlenSigMin_;
42
42
};
@@ -52,11 +52,11 @@ HLTVertexTableProducer::HLTVertexTableProducer(const edm::ParameterSet& params)
52
52
pvsScore_(consumes<edm::ValueMap<float >>(params.getParameter<edm::InputTag>(" pvSrc" ))),
53
53
goodPvCut_(params.getParameter<std::string>(" goodPvCut" ), true),
54
54
goodPvCutString_(params.getParameter<std::string>(" goodPvCut" )),
55
+ usePF_(params.getParameter<bool >(" usePF" )),
55
56
pvName_(params.getParameter<std::string>(" pvName" )),
56
57
dlenMin_(params.getParameter<double >(" dlenMin" )),
57
58
dlenSigMin_(params.getParameter<double >(" dlenSigMin" )) {
58
59
produces<nanoaod::FlatTable>(" PV" );
59
- produces<edm::PtrVector<reco::VertexCompositePtrCandidate>>();
60
60
}
61
61
62
62
//
@@ -69,6 +69,7 @@ void HLTVertexTableProducer::produce(edm::Event& iEvent, const edm::EventSetup&
69
69
70
70
// vertex collection
71
71
auto pvsIn = iEvent.getHandle (pvs_);
72
+ auto pvScoreIn = iEvent.getHandle (pvsScore_);
72
73
const size_t nPVs = pvsIn.isValid () ? (*pvsIn).size () : 0 ;
73
74
74
75
static constexpr float default_value = std::numeric_limits<float >::quiet_NaN ();
@@ -90,7 +91,6 @@ void HLTVertexTableProducer::produce(edm::Event& iEvent, const edm::EventSetup&
90
91
91
92
if (pvsIn.isValid () || !(this ->skipNonExistingSrc_ )) {
92
93
const auto & pvs = *pvsIn;
93
- const auto & pvsScoreProd = iEvent.get (pvsScore_);
94
94
95
95
auto pfcIn = iEvent.getHandle (pfc_);
96
96
const bool isPfcValid = pfcIn.isValid ();
@@ -109,40 +109,55 @@ void HLTVertexTableProducer::produce(edm::Event& iEvent, const edm::EventSetup&
109
109
v_zError[i] = pv.zError ();
110
110
v_nTracks[i] = pv.nTracks ();
111
111
v_is_good[i] = goodPvCut_ (pv);
112
- v_pv_score[i] = pvsScoreProd.get (pvsIn.id (), i);
113
112
114
- float sumpt2 = 0 .f , sumpx = 0 .f , sumpy = 0 .f ;
113
+ if (pvScoreIn.isValid () || !(this ->skipNonExistingSrc_ )) {
114
+ const auto & pvsScoreProd = *pvScoreIn;
115
+ v_pv_score[i] = pvsScoreProd.get (pvsIn.id (), i);
116
+ }
115
117
116
- if (isPfcValid || !(this ->skipNonExistingSrc_ )) {
117
- for (const auto & obj : *pfcIn) {
118
- if (obj.charge () == 0 || !obj.trackRef ().isNonnull ())
119
- continue ;
118
+ float sumpt2 = 0 .f , sumpx = 0 .f , sumpy = 0 .f ;
120
119
121
- const auto dz = std::abs (obj.trackRef ()->dz (pos));
122
- if (dz >= 0.2 )
123
- continue ;
120
+ if (usePF_) {
121
+ if (isPfcValid || !(this ->skipNonExistingSrc_ )) {
122
+ for (const auto & obj : *pfcIn) {
123
+ if (obj.charge () == 0 || !obj.trackRef ().isNonnull ())
124
+ continue ;
124
125
125
- bool isClosest = true ;
126
- for (size_t j = 0 ; j < nPVs; ++j) {
127
- if (j == i)
126
+ const auto dz = std::abs (obj.trackRef ()->dz (pos));
127
+ if (dz >= 0.2 )
128
128
continue ;
129
- const auto dz_j = std::abs (obj.trackRef ()->dz (pvs[j].position ()));
130
- if (dz_j < dz) {
131
- isClosest = false ;
132
- break ;
129
+
130
+ bool isClosest = true ;
131
+ for (size_t j = 0 ; j < nPVs; ++j) {
132
+ if (j == i)
133
+ continue ;
134
+ const auto dz_j = std::abs (obj.trackRef ()->dz (pvs[j].position ()));
135
+ if (dz_j < dz) {
136
+ isClosest = false ;
137
+ break ;
138
+ }
133
139
}
134
- }
135
140
136
- if (isClosest) {
137
- const float pt = obj.pt ();
138
- sumpt2 += pt * pt;
139
- sumpx += obj.px ();
140
- sumpy += obj.py ();
141
+ if (isClosest) {
142
+ const float pt = obj.pt ();
143
+ sumpt2 += pt * pt;
144
+ sumpx += obj.px ();
145
+ sumpy += obj.py ();
146
+ }
141
147
}
148
+ } else {
149
+ edm::LogWarning (" HLTVertexTableProducer" )
150
+ << " Invalid handle for " << pvName_ << " in PF candidate input collection" ;
142
151
}
143
152
} else {
144
- edm::LogWarning (" HLTVertexTableProducer" )
145
- << " Invalid handle for " << pvName_ << " in PF candidate input collection" ;
153
+ // Loop over tracks used in PV fit
154
+ for (auto t = pv.tracks_begin (); t != pv.tracks_end (); ++t) {
155
+ const auto & trk = **t; // trk is a reco::TrackBase
156
+ const float pt = trk.pt ();
157
+ sumpt2 += pt * pt;
158
+ sumpx += trk.px ();
159
+ sumpy += trk.py ();
160
+ }
146
161
}
147
162
v_pv_sumpt2[i] = sumpt2;
148
163
v_pv_sumpx[i] = sumpx;
@@ -186,6 +201,8 @@ void HLTVertexTableProducer::fillDescriptions(edm::ConfigurationDescriptions& de
186
201
desc.add <std::string>(" pvName" )->setComment (" name of the flat table ouput" );
187
202
desc.add <edm::InputTag>(" pvSrc" )->setComment (
188
203
" std::vector<reco::Vertex> and ValueMap<float> primary vertex input collections" );
204
+ desc.add <bool >(" usePF" , true )
205
+ ->setComment (" if true, use PF candidate-based association; if false, use only tracks used in PV fit" );
189
206
desc.add <edm::InputTag>(" pfSrc" )->setComment (" reco::PFCandidateCollection PF candidates input collections" );
190
207
desc.add <std::string>(" goodPvCut" )->setComment (" selection on the primary vertex" );
191
208
desc.add <double >(" dlenMin" )->setComment (" minimum value of dl to select secondary vertex" );
0 commit comments