CMS 3D CMS Logo

LHEPtFilter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: LHEPtFilter
4 // Class: LHEPtFilter
5 //
6 /*
7 
8  Description: Filter to select events with pT in a given range.
9  (Based on LHEGenericFilter)
10 
11 
12 */
13 //
14 
15 // system include files
16 #include <memory>
17 #include <iostream>
18 #include <set>
19 
20 // user include files
21 #include "Math/Vector4D.h"
22 #include "Math/Vector4Dfwd.h"
23 
26 
29 
32 
33 //
34 // class declaration
35 //
36 
38 public:
39  explicit LHEPtFilter(const edm::ParameterSet&);
40  ~LHEPtFilter() override;
41 
42  bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
43 
44 private:
45  // ----------member data ---------------------------
46 
48  std::vector<int> pdgIdVec_;
49  std::set<int> pdgIds_; // Set of PDG Ids to include
50  double ptMin_; // number of particles required to pass filter
51  double ptMax_; // number of particles required to pass filter
52 };
53 
54 using namespace edm;
55 using namespace std;
56 
58  : pdgIdVec_(iConfig.getParameter<std::vector<int>>("selectedPdgIds")),
59  ptMin_(iConfig.getParameter<double>("ptMin")),
60  ptMax_(iConfig.getParameter<double>("ptMax")) {
61  //here do whatever other initialization is needed
62  src_ = consumes<LHEEventProduct>(iConfig.getParameter<edm::InputTag>("src"));
63  pdgIds_ = std::set<int>(pdgIdVec_.begin(), pdgIdVec_.end());
64 }
65 
67  // do anything here that needs to be done at destruction time
68  // (e.g. close files, deallocate resources etc.)
69 }
70 
71 // ------------ method called to skim the data ------------
74  iEvent.getByToken(src_, EvtHandle);
75 
76  std::vector<lhef::HEPEUP::FiveVector> lheParticles = EvtHandle->hepeup().PUP;
77  std::vector<ROOT::Math::PxPyPzEVector> cands;
78 
79  for (unsigned int i = 0; i < lheParticles.size(); ++i) {
80  if (EvtHandle->hepeup().ISTUP[i] != 1) { // keep only outgoing particles
81  continue;
82  }
83  int pdgId = EvtHandle->hepeup().IDUP[i];
84  if (pdgIds_.count(pdgId)) {
85  cands.push_back(
86  ROOT::Math::PxPyPzEVector(lheParticles[i][0], lheParticles[i][1], lheParticles[i][2], lheParticles[i][3]));
87  }
88  }
89  double vpt_ = -1;
90  if (!cands.empty()) {
91  ROOT::Math::PxPyPzEVector tot = cands.at(0);
92  for (unsigned icand = 1; icand < cands.size(); ++icand) {
93  tot += cands.at(icand);
94  }
95  vpt_ = tot.pt();
96  }
97  if ((ptMax_ < 0. || vpt_ <= ptMax_) && vpt_ > ptMin_) {
98  return true;
99  } else {
100  return false;
101  }
102 }
103 
104 //define this as a plug-in
T getParameter(std::string const &) const
~LHEPtFilter() override
Definition: LHEPtFilter.cc:66
const lhef::HEPEUP & hepeup() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
LHEPtFilter(const edm::ParameterSet &)
Definition: LHEPtFilter.cc:57
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< FiveVector > PUP
Definition: LesHouches.h:261
std::set< int > pdgIds_
Definition: LHEPtFilter.cc:49
double ptMax_
Definition: LHEPtFilter.cc:51
std::vector< int > ISTUP
Definition: LesHouches.h:243
std::vector< int > IDUP
Definition: LesHouches.h:238
double ptMin_
Definition: LHEPtFilter.cc:50
HLT enums.
edm::EDGetTokenT< LHEEventProduct > src_
Definition: LHEPtFilter.cc:47
bool filter(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: LHEPtFilter.cc:72
std::vector< int > pdgIdVec_
Definition: LHEPtFilter.cc:48