File indexing completed on 2024-04-06 12:13:39
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include "DataFormats/Common/interface/Handle.h"
0020 #include "FWCore/Framework/interface/Frameworkfwd.h"
0021 #include "FWCore/Framework/interface/global/EDFilter.h"
0022 #include "FWCore/Framework/interface/Event.h"
0023 #include "FWCore/Framework/interface/MakerMacros.h"
0024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0026 #include "FWCore/Utilities/interface/EDGetToken.h"
0027 #include "FWCore/Utilities/interface/InputTag.h"
0028 #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
0029
0030 #include <cmath>
0031 #include <cstdlib>
0032 #include <string>
0033 #include <vector>
0034
0035
0036
0037
0038
0039 class LHEGenericFilter : public edm::global::EDFilter<> {
0040 public:
0041 explicit LHEGenericFilter(const edm::ParameterSet&);
0042
0043 private:
0044 bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0045
0046
0047
0048 const edm::EDGetTokenT<LHEEventProduct> src_;
0049 const int numRequired_;
0050 const std::vector<int> particleID_;
0051 enum Logic { LT, GT, EQ, NE };
0052 Logic whichlogic;
0053 };
0054
0055 using namespace std;
0056
0057 LHEGenericFilter::LHEGenericFilter(const edm::ParameterSet& iConfig)
0058 : src_(consumes<LHEEventProduct>(iConfig.getParameter<edm::InputTag>("src"))),
0059 numRequired_(iConfig.getParameter<int>("NumRequired")),
0060 particleID_(iConfig.getParameter<std::vector<int> >("ParticleID")) {
0061
0062
0063
0064
0065 std::string acceptLogic = iConfig.getParameter<std::string>("AcceptLogic");
0066 if (acceptLogic == "LT")
0067 whichlogic = LT;
0068 else if (acceptLogic == "GT")
0069 whichlogic = GT;
0070 else if (acceptLogic == "EQ")
0071 whichlogic = EQ;
0072 else if (acceptLogic == "NE")
0073 whichlogic = NE;
0074 else {
0075 edm::LogError("cat_A") << "wrong input for AcceptLogic string";
0076
0077 whichlogic = LT;
0078 }
0079 }
0080
0081
0082 bool LHEGenericFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const {
0083 edm::Handle<LHEEventProduct> EvtHandle;
0084 iEvent.getByToken(src_, EvtHandle);
0085
0086 int nFound = 0;
0087
0088 for (int i = 0; i < EvtHandle->hepeup().NUP; ++i) {
0089 if (EvtHandle->hepeup().ISTUP[i] != 1) {
0090 continue;
0091 }
0092 for (unsigned int j = 0; j < particleID_.size(); ++j) {
0093 if (particleID_[j] == 0 || abs(particleID_[j]) == abs(EvtHandle->hepeup().IDUP[i])) {
0094 nFound++;
0095 break;
0096 }
0097 }
0098
0099 }
0100
0101
0102 if ((whichlogic == LT && nFound < numRequired_) || (whichlogic == GT && nFound > numRequired_) ||
0103 (whichlogic == EQ && nFound == numRequired_) || (whichlogic == NE && nFound != numRequired_)) {
0104 return true;
0105 } else {
0106 return false;
0107 }
0108 }
0109
0110
0111 DEFINE_FWK_MODULE(LHEGenericFilter);