File indexing completed on 2024-04-06 12:13:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include "DataFormats/Common/interface/Handle.h"
0012 #include "DataFormats/Math/interface/LorentzVector.h"
0013 #include "FWCore/Framework/interface/Event.h"
0014 #include "FWCore/Framework/interface/Frameworkfwd.h"
0015 #include "FWCore/Framework/interface/global/EDFilter.h"
0016 #include "FWCore/Framework/interface/MakerMacros.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 #include "FWCore/Utilities/interface/EDGetToken.h"
0019 #include "FWCore/Utilities/interface/InputTag.h"
0020 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0021
0022 #include <cmath>
0023 #include <cstdlib>
0024 #include <string>
0025 #include <vector>
0026
0027 class PythiaFilterZJet : public edm::global::EDFilter<> {
0028 public:
0029 explicit PythiaFilterZJet(const edm::ParameterSet&);
0030
0031 bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0032
0033 private:
0034 const edm::EDGetTokenT<edm::HepMCProduct> token_;
0035 const double etaMuMax;
0036 const double ptZMin;
0037 const double ptZMax;
0038 };
0039
0040 PythiaFilterZJet::PythiaFilterZJet(const edm::ParameterSet& iConfig)
0041 : token_(consumes<edm::HepMCProduct>(
0042 edm::InputTag(iConfig.getUntrackedParameter("moduleLabel", std::string("generator")), "unsmeared"))),
0043 etaMuMax(iConfig.getUntrackedParameter<double>("MaxMuonEta", 2.5)),
0044 ptZMin(iConfig.getUntrackedParameter<double>("MinZPt")),
0045 ptZMax(iConfig.getUntrackedParameter<double>("MaxZPt")) {}
0046
0047 bool PythiaFilterZJet::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const {
0048 bool accepted = false;
0049 edm::Handle<edm::HepMCProduct> evt;
0050 iEvent.getByToken(token_, evt);
0051
0052 const HepMC::GenEvent* myGenEvent = evt->GetEvent();
0053
0054 if (myGenEvent->signal_process_id() == 15 || myGenEvent->signal_process_id() == 30) {
0055 std::vector<const HepMC::GenParticle*> mu;
0056
0057 for (HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin(); p != myGenEvent->particles_end();
0058 ++p) {
0059 if (std::abs((*p)->pdg_id()) == 13 && (*p)->status() == 1)
0060 mu.push_back(*p);
0061 if (mu.size() > 1)
0062 break;
0063 }
0064
0065 if (mu.size() > 1) {
0066 math::XYZTLorentzVector tot_mom(mu[0]->momentum());
0067 math::XYZTLorentzVector mom2(mu[1]->momentum());
0068 tot_mom += mom2;
0069
0070 double ptZ = tot_mom.pt();
0071 if (ptZ > ptZMin && ptZ < ptZMax && std::abs(mu[0]->momentum().eta()) < etaMuMax &&
0072 std::abs(mu[1]->momentum().eta()) < etaMuMax)
0073 accepted = true;
0074 }
0075
0076 } else {
0077
0078 return true;
0079
0080 }
0081 return accepted;
0082 }
0083
0084 DEFINE_FWK_MODULE(PythiaFilterZJet);