Skip to content

Commit f715847

Browse files
authoredNov 8, 2021
Merge pull request #35938 from JanFSchulte/LeptonMassLHEFilter122X
Add invariant mass filter for generic objects in LHE events
2 parents 155a430 + 91fb6d9 commit f715847

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// system include files
2+
#include <memory>
3+
#include <iostream>
4+
5+
// user include files
6+
#include "FWCore/Framework/interface/Frameworkfwd.h"
7+
#include "FWCore/Framework/interface/global/EDFilter.h"
8+
9+
#include "FWCore/Framework/interface/Event.h"
10+
#include "FWCore/Framework/interface/MakerMacros.h"
11+
#include "FWCore/PluginManager/interface/ModuleDef.h"
12+
13+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
14+
#include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
15+
16+
using namespace edm;
17+
using namespace std;
18+
19+
//
20+
// class declaration
21+
//
22+
23+
class LHEGenericMassFilter : public edm::global::EDFilter<> {
24+
public:
25+
explicit LHEGenericMassFilter(const edm::ParameterSet&);
26+
~LHEGenericMassFilter() override;
27+
28+
private:
29+
bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
30+
void endJob() override;
31+
32+
// ----------member data ---------------------------
33+
34+
const edm::EDGetTokenT<LHEEventProduct> src_;
35+
const int numRequired_; // number of particles required to pass filter
36+
const std::vector<int> particleID_; // vector of particle IDs to look for
37+
const double minMass_;
38+
const double maxMass_;
39+
};
40+
41+
LHEGenericMassFilter::LHEGenericMassFilter(const edm::ParameterSet& iConfig)
42+
: src_(consumes<LHEEventProduct>(iConfig.getParameter<edm::InputTag>("src"))),
43+
numRequired_(iConfig.getParameter<int>("NumRequired")),
44+
particleID_(iConfig.getParameter<std::vector<int> >("ParticleID")),
45+
minMass_(iConfig.getParameter<double>("MinMass")),
46+
maxMass_(iConfig.getParameter<double>("MaxMass")) {}
47+
48+
LHEGenericMassFilter::~LHEGenericMassFilter() {
49+
// do anything here that needs to be done at destruction time
50+
// (e.g. close files, deallocate resources etc.)
51+
}
52+
53+
// ------------ method called to skim the data ------------
54+
bool LHEGenericMassFilter::filter(edm::StreamID iID, edm::Event& iEvent, edm::EventSetup const& iSetup) const {
55+
edm::Handle<LHEEventProduct> EvtHandle;
56+
iEvent.getByToken(src_, EvtHandle);
57+
58+
int nFound = 0;
59+
60+
double Px = 0.;
61+
double Py = 0.;
62+
double Pz = 0.;
63+
double E = 0.;
64+
65+
for (int i = 0; i < EvtHandle->hepeup().NUP; ++i) {
66+
if (EvtHandle->hepeup().ISTUP[i] != 1) { // keep only outgoing particles
67+
continue;
68+
}
69+
for (unsigned int j = 0; j < particleID_.size(); ++j) {
70+
if (abs(particleID_[j]) == abs(EvtHandle->hepeup().IDUP[i])) {
71+
nFound++;
72+
Px = Px + EvtHandle->hepeup().PUP[i][0];
73+
Py = Py + EvtHandle->hepeup().PUP[i][1];
74+
Pz = Pz + EvtHandle->hepeup().PUP[i][2];
75+
E = E + EvtHandle->hepeup().PUP[i][3];
76+
77+
break; // only match a given particle once!
78+
}
79+
} // loop over targets
80+
81+
} // loop over particles
82+
83+
// event accept/reject logic
84+
if (nFound == numRequired_) {
85+
double Mass = std::sqrt(E * E - (Px * Px + Py * Py + Pz * Pz));
86+
if (Mass > minMass_ && Mass < maxMass_) {
87+
return true;
88+
}
89+
}
90+
return false;
91+
}
92+
93+
// ------------ method called once each job just after ending the event loop ------------
94+
void LHEGenericMassFilter::endJob() {}
95+
96+
//define this as a plug-in
97+
DEFINE_FWK_MODULE(LHEGenericMassFilter);

0 commit comments

Comments
 (0)
Please sign in to comment.