CMS 3D CMS Logo

PATVertexSlimmer.cc
Go to the documentation of this file.
1 #include <string>
2 #include <memory>
3 
4 // user include files
9 
15 
16 namespace pat {
18  public:
19  explicit PATVertexSlimmer(const edm::ParameterSet&);
20  ~PATVertexSlimmer() override;
21 
22  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
23 
24  private:
27  const bool rekeyScores_;
28  };
29 } // namespace pat
30 
32  : src_(consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("src"))),
33  score_(mayConsume<edm::ValueMap<float>>(
34  iConfig.existsAs<edm::InputTag>("score") ? iConfig.getParameter<edm::InputTag>("score") : edm::InputTag())),
35  rekeyScores_(iConfig.existsAs<edm::InputTag>("score")) {
36  produces<std::vector<reco::Vertex>>();
37  if (rekeyScores_)
38  produces<edm::ValueMap<float>>();
39 }
40 
42 
45  iEvent.getByToken(src_, vertices);
46  auto outPtr = std::make_unique<std::vector<reco::Vertex>>();
47 
48  outPtr->reserve(vertices->size());
49  for (unsigned int i = 0, n = vertices->size(); i < n; ++i) {
50  const reco::Vertex& v = (*vertices)[i];
51  auto co = v.covariance4D();
52  if (i > 0) {
53  for (size_t j = 0; j < 4; j++) {
54  for (size_t k = j; k < 4; k++) {
55  co(j, k) = MiniFloatConverter::reduceMantissaToNbits<10>(co(j, k));
56  }
57  }
58  }
59  outPtr->push_back(reco::Vertex(v.position(), co, v.t(), v.chi2(), v.ndof(), 0));
60  }
61 
62  auto oh = iEvent.put(std::move(outPtr));
63  if (rekeyScores_) {
65  iEvent.getByToken(score_, scores);
66  auto vertexScoreOutput = std::make_unique<edm::ValueMap<float>>();
67  edm::ValueMap<float>::const_iterator idIt = scores->begin();
68  for (; idIt != scores->end(); idIt++) {
69  if (idIt.id() == vertices.id())
70  break;
71  }
72  // std::find_if(scores->begin(), scores->end(), [vertices] (const edm::ValueMap<float>::const_iterator& s) { return s.id() == vertices.id(); } );
73  edm::ValueMap<float>::Filler vertexScoreFiller(*vertexScoreOutput);
74  vertexScoreFiller.insert(oh, idIt.begin(), idIt.end());
75  vertexScoreFiller.fill();
76  iEvent.put(std::move(vertexScoreOutput));
77  }
78 }
79 
PATVertexSlimmer(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
const edm::EDGetTokenT< std::vector< reco::Vertex > > src_
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
__host__ __device__ VT * co
Definition: prefixScan.h:47
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< edm::ValueMap< float > > score_
fixed size matrix
HLT enums.
def move(src, dest)
Definition: eostools.py:511