File indexing completed on 2024-04-06 12:22:39
0001
0002
0003
0004 #include <memory>
0005 #include <vector>
0006 #include <string>
0007
0008
0009
0010 #include "FWCore/Framework/interface/Frameworkfwd.h"
0011 #include "FWCore/Framework/interface/stream/EDFilter.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/MakerMacros.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "FWCore/Utilities/interface/InputTag.h"
0016
0017
0018 #include "DataFormats/TrackReco/interface/Track.h"
0019 #include "DataFormats/MuonReco/interface/Muon.h"
0020 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0021 #include "DataFormats/Candidate/interface/Candidate.h"
0022 #include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h"
0023 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
0024
0025 #include "MuScleFitUtils.h"
0026
0027 #include <CLHEP/Vector/LorentzVector.h>
0028
0029
0030
0031
0032 class MuScleFitGenFilter : public edm::stream::EDFilter<> {
0033 public:
0034 explicit MuScleFitGenFilter(const edm::ParameterSet&);
0035 ~MuScleFitGenFilter() override;
0036
0037 private:
0038 bool filter(edm::Event&, const edm::EventSetup&) override;
0039
0040 std::string genParticlesName_;
0041 edm::EDGetTokenT<edm::HepMCProduct> evtMCToken_;
0042 edm::EDGetTokenT<reco::GenParticleCollection> genParticlesToken_;
0043 unsigned int totalEvents_;
0044 unsigned int eventsPassingTheFilter_;
0045 };
0046
0047
0048
0049 MuScleFitGenFilter::MuScleFitGenFilter(const edm::ParameterSet& iConfig)
0050 : genParticlesName_(iConfig.getUntrackedParameter<std::string>("GenParticlesName", "genParticles")),
0051 evtMCToken_(consumes<edm::HepMCProduct>(edm::InputTag(genParticlesName_))),
0052 genParticlesToken_(mayConsume<reco::GenParticleCollection>(edm::InputTag(genParticlesName_))),
0053 totalEvents_(0),
0054 eventsPassingTheFilter_(0) {
0055 MuScleFitUtils::resfind = iConfig.getParameter<std::vector<int> >("resfind");
0056 }
0057
0058
0059
0060 MuScleFitGenFilter::~MuScleFitGenFilter() {
0061 edm::LogPrint("MuScleFitGenFilter") << "Total number of events = " << totalEvents_ << std::endl;
0062 edm::LogPrint("MuScleFitGenFilter") << "Events passing the filter = " << eventsPassingTheFilter_ << std::endl;
0063 }
0064
0065
0066
0067 bool MuScleFitGenFilter::filter(edm::Event& event, const edm::EventSetup& iSetup) {
0068 ++totalEvents_;
0069
0070 edm::Handle<edm::HepMCProduct> evtMC;
0071
0072 std::pair<lorentzVector, lorentzVector> genPair;
0073
0074 event.getByToken(evtMCToken_, evtMC);
0075 if (evtMC.isValid()) {
0076 genPair = MuScleFitUtils::findGenMuFromRes(evtMC.product());
0077 } else {
0078 edm::Handle<reco::GenParticleCollection> genParticles;
0079 event.getByToken(genParticlesToken_, genParticles);
0080 if (genParticles.isValid()) {
0081 genPair = MuScleFitUtils::findGenMuFromRes(genParticles.product());
0082 } else {
0083 edm::LogPrint("MuScleFitGenFilter") << "ERROR: no generator info found" << std::endl;
0084 return false;
0085 }
0086 }
0087 lorentzVector emptyVec(0., 0., 0., 0.);
0088 if ((genPair.first == emptyVec) || (genPair.second == emptyVec)) {
0089 return false;
0090 }
0091
0092 ++eventsPassingTheFilter_;
0093
0094 return true;
0095 }
0096
0097 #include "FWCore/Framework/interface/MakerMacros.h"
0098 DEFINE_FWK_MODULE(MuScleFitGenFilter);