File indexing completed on 2024-04-06 12:31:25
0001 #ifndef TtJetPartonMatch_h
0002 #define TtJetPartonMatch_h
0003
0004 #include <memory>
0005 #include <vector>
0006
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/global/EDProducer.h"
0009 #include "FWCore/Framework/interface/Frameworkfwd.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011
0012 #include "DataFormats/JetReco/interface/Jet.h"
0013 #include "AnalysisDataFormats/TopObjects/interface/TtGenEvent.h"
0014 #include "TopQuarkAnalysis/TopTools/interface/JetPartonMatching.h"
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 template <typename C>
0044 class TtJetPartonMatch : public edm::global::EDProducer<> {
0045 public:
0046
0047 explicit TtJetPartonMatch(const edm::ParameterSet&);
0048
0049 void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0050
0051 private:
0052
0053 JetPartonMatching::algorithms readAlgorithm(const std::string& str) const;
0054
0055
0056 C partons_;
0057
0058 edm::EDGetTokenT<TtGenEvent> genEvt_;
0059
0060 edm::EDGetTokenT<edm::View<reco::Jet>> jets_;
0061
0062
0063 int maxNJets_;
0064
0065
0066 int maxNComb_;
0067
0068 JetPartonMatching::algorithms algorithm_;
0069
0070 bool useDeltaR_;
0071
0072
0073 bool useMaxDist_;
0074
0075
0076 double maxDist_;
0077
0078 int verbosity_;
0079 };
0080
0081 template <typename C>
0082 TtJetPartonMatch<C>::TtJetPartonMatch(const edm::ParameterSet& cfg)
0083 : partons_(cfg.getParameter<std::vector<std::string>>("partonsToIgnore")),
0084 genEvt_(consumes<TtGenEvent>(edm::InputTag("genEvt"))),
0085 jets_(consumes<edm::View<reco::Jet>>(cfg.getParameter<edm::InputTag>("jets"))),
0086 maxNJets_(cfg.getParameter<int>("maxNJets")),
0087 maxNComb_(cfg.getParameter<int>("maxNComb")),
0088 algorithm_(readAlgorithm(cfg.getParameter<std::string>("algorithm"))),
0089 useDeltaR_(cfg.getParameter<bool>("useDeltaR")),
0090 useMaxDist_(cfg.getParameter<bool>("useMaxDist")),
0091 maxDist_(cfg.getParameter<double>("maxDist")),
0092 verbosity_(cfg.getParameter<int>("verbosity")) {
0093
0094
0095
0096
0097
0098 produces<std::vector<std::vector<int>>>();
0099 produces<std::vector<double>>("SumPt");
0100 produces<std::vector<double>>("SumDR");
0101 produces<int>("NumberOfConsideredJets");
0102 }
0103
0104 template <typename C>
0105 void TtJetPartonMatch<C>::produce(edm::StreamID, edm::Event& evt, const edm::EventSetup& setup) const {
0106
0107
0108
0109
0110
0111 auto match = std::make_unique<std::vector<std::vector<int>>>();
0112 auto sumPt = std::make_unique<std::vector<double>>();
0113 auto sumDR = std::make_unique<std::vector<double>>();
0114 std::unique_ptr<int> pJetsConsidered(new int);
0115
0116
0117 const TtGenEvent& genEvt = evt.get(genEvt_);
0118
0119 const edm::View<reco::Jet>& topJets = evt.get(jets_);
0120
0121
0122
0123
0124
0125 std::vector<const reco::Candidate*> partons = partons_.vec(genEvt);
0126
0127
0128 std::vector<const reco::Candidate*> jets;
0129 for (unsigned int ij = 0; ij < topJets.size(); ++ij) {
0130
0131
0132
0133
0134 if (maxNJets_ != -1) {
0135 if (maxNJets_ >= (int)partons.size()) {
0136 if ((int)ij == maxNJets_)
0137 break;
0138 } else {
0139 if (ij == partons.size())
0140 break;
0141 }
0142 }
0143 jets.push_back(&topJets[ij]);
0144 }
0145 *pJetsConsidered = jets.size();
0146
0147
0148 JetPartonMatching jetPartonMatch(partons, jets, algorithm_, useMaxDist_, useDeltaR_, maxDist_);
0149
0150
0151
0152 if (verbosity_ > 0)
0153 jetPartonMatch.print();
0154
0155 for (unsigned int ic = 0; ic < jetPartonMatch.getNumberOfAvailableCombinations(); ++ic) {
0156 if ((int)ic >= maxNComb_ && maxNComb_ >= 0)
0157 break;
0158 std::vector<int> matches = jetPartonMatch.getMatchesForPartons(ic);
0159 partons_.expand(matches);
0160 match->push_back(matches);
0161 sumPt->push_back(jetPartonMatch.getSumDeltaPt(ic));
0162 sumDR->push_back(jetPartonMatch.getSumDeltaR(ic));
0163 }
0164 evt.put(std::move(match));
0165 evt.put(std::move(sumPt), "SumPt");
0166 evt.put(std::move(sumDR), "SumDR");
0167 evt.put(std::move(pJetsConsidered), "NumberOfConsideredJets");
0168 }
0169
0170 template <typename C>
0171 JetPartonMatching::algorithms TtJetPartonMatch<C>::readAlgorithm(const std::string& str) const {
0172 if (str == "totalMinDist")
0173 return JetPartonMatching::totalMinDist;
0174 else if (str == "minSumDist")
0175 return JetPartonMatching::minSumDist;
0176 else if (str == "ptOrderedMinDist")
0177 return JetPartonMatching::ptOrderedMinDist;
0178 else if (str == "unambiguousOnly")
0179 return JetPartonMatching::unambiguousOnly;
0180 else
0181 throw cms::Exception("Configuration") << "Chosen algorithm is not supported: " << str << "\n";
0182 }
0183
0184 #endif