CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TtJetPartonMatch.h
Go to the documentation of this file.
1 #ifndef TtJetPartonMatch_h
2 #define TtJetPartonMatch_h
3 
4 #include <memory>
5 #include <vector>
6 
11 
15 
16 // ----------------------------------------------------------------------
17 // template class for:
18 //
19 // * TtFullHadJetPartonMatch
20 // * TtSemiLepJetPartonMatch
21 // * TtFullLepJetPartonMatch
22 //
23 // the class provides plugins for jet-parton matching corresponding
24 // to the JetPartonMatching class; expected input is one of the
25 // classes in:
26 //
27 // AnalysisDataFormats/TopObjects/interface/TtFullHadEvtPartons.h
28 // AnalysisDataFormats/TopObjects/interface/TtSemiLepEvtPartons.h
29 // AnalysisDataFormats/TopObjects/interface/TtFullLepEvtPartons.h
30 //
31 // output is:
32 // * a vector of vectors containing the indices of the jets in the
33 // input collection matched to the partons in the order defined in
34 // the corresponding Tt*EvtPartons class
35 // * a set of vectors with quality parameters of the matching
36 //
37 // the matching can be performed on an arbitrary number of jet
38 // combinations; per default the combination which matches best
39 // according to the quality parameters will be stored; the length
40 // of the vectors will be 1 then
41 // ----------------------------------------------------------------------
42 
43 template <typename C>
45 public:
47  explicit TtJetPartonMatch(const edm::ParameterSet&);
49  ~TtJetPartonMatch() override;
51  void produce(edm::Event&, const edm::EventSetup&) override;
52 
53 private:
56 
65  int maxNJets_;
68  int maxNComb_;
72  bool useDeltaR_;
78  double maxDist_;
81 };
82 
83 template <typename C>
85  : partons_(cfg.getParameter<std::vector<std::string> >("partonsToIgnore")),
86  genEvt_(consumes<TtGenEvent>(edm::InputTag("genEvt"))),
87  jets_(consumes<edm::View<reco::Jet> >(cfg.getParameter<edm::InputTag>("jets"))),
88  maxNJets_(cfg.getParameter<int>("maxNJets")),
89  maxNComb_(cfg.getParameter<int>("maxNComb")),
90  algorithm_(readAlgorithm(cfg.getParameter<std::string>("algorithm"))),
91  useDeltaR_(cfg.getParameter<bool>("useDeltaR")),
92  useMaxDist_(cfg.getParameter<bool>("useMaxDist")),
93  maxDist_(cfg.getParameter<double>("maxDist")),
94  verbosity_(cfg.getParameter<int>("verbosity")) {
95  // produces a vector of jet/lepton indices in the order of
96  // * TtSemiLepEvtPartons
97  // * TtFullHadEvtPartons
98  // * TtFullLepEvtPartons
99  // and vectors of the corresponding quality parameters
100  produces<std::vector<std::vector<int> > >();
101  produces<std::vector<double> >("SumPt");
102  produces<std::vector<double> >("SumDR");
103  produces<int>("NumberOfConsideredJets");
104 }
105 
106 template <typename C>
108 
109 template <typename C>
111  // will write
112  // * parton match
113  // * sumPt
114  // * sumDR
115  // to the event
116  std::unique_ptr<std::vector<std::vector<int> > > match(new std::vector<std::vector<int> >);
117  std::unique_ptr<std::vector<double> > sumPt(new std::vector<double>);
118  std::unique_ptr<std::vector<double> > sumDR(new std::vector<double>);
119  std::unique_ptr<int> pJetsConsidered(new int);
120 
121  // get TtGenEvent and jet collection from the event
123  evt.getByToken(genEvt_, genEvt);
124 
126  evt.getByToken(jets_, topJets);
127 
128  // fill vector of partons in the order of
129  // * TtFullLepEvtPartons
130  // * TtSemiLepEvtPartons
131  // * TtFullHadEvtPartons
132  std::vector<const reco::Candidate*> partons = partons_.vec(*genEvt);
133 
134  // prepare vector of jets
135  std::vector<const reco::Candidate*> jets;
136  for (unsigned int ij = 0; ij < topJets->size(); ++ij) {
137  // take all jets if maxNJets_ == -1; otherwise use
138  // maxNJets_ if maxNJets_ is big enough or use same
139  // number of jets as partons if maxNJets_ < number
140  // of partons
141  if (maxNJets_ != -1) {
142  if (maxNJets_ >= (int)partons.size()) {
143  if ((int)ij == maxNJets_)
144  break;
145  } else {
146  if (ij == partons.size())
147  break;
148  }
149  }
150  jets.push_back((const reco::Candidate*)&(*topJets)[ij]);
151  }
152  *pJetsConsidered = jets.size();
153 
154  // do the matching with specified parameters
155  JetPartonMatching jetPartonMatch(partons, jets, algorithm_, useMaxDist_, useDeltaR_, maxDist_);
156 
157  // print some info for each event
158  // if corresponding verbosity level set
159  if (verbosity_ > 0)
160  jetPartonMatch.print();
161 
162  for (unsigned int ic = 0; ic < jetPartonMatch.getNumberOfAvailableCombinations(); ++ic) {
163  if ((int)ic >= maxNComb_ && maxNComb_ >= 0)
164  break;
165  std::vector<int> matches = jetPartonMatch.getMatchesForPartons(ic);
166  partons_.expand(matches); // insert dummy indices for partons that were chosen to be ignored
167  match->push_back(matches);
168  sumPt->push_back(jetPartonMatch.getSumDeltaPt(ic));
169  sumDR->push_back(jetPartonMatch.getSumDeltaR(ic));
170  }
171  evt.put(std::move(match));
172  evt.put(std::move(sumPt), "SumPt");
173  evt.put(std::move(sumDR), "SumDR");
174  evt.put(std::move(pJetsConsidered), "NumberOfConsideredJets");
175 }
176 
177 template <typename C>
179  if (str == "totalMinDist")
181  else if (str == "minSumDist")
183  else if (str == "ptOrderedMinDist")
185  else if (str == "unambiguousOnly")
187  else
188  throw cms::Exception("Configuration") << "Chosen algorithm is not supported: " << str << "\n";
189 }
190 
191 #endif
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
tuple cfg
Definition: looper.py:296
edm::EDGetTokenT< TtGenEvent > genEvt_
TtGenEvent collection input.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
void produce(edm::Event &, const edm::EventSetup &) override
write jet parton match objects into the event
~TtJetPartonMatch() override
default destructor
unsigned int getNumberOfAvailableCombinations()
Class derived from the TopGenEvent for ttbar events.
Definition: TtGenEvent.h:18
JetPartonMatching::algorithms readAlgorithm(const std::string &str)
convert string for algorithm into corresponding enumerator type
vector< PseudoJet > jets
std::vector< int > getMatchesForPartons(const unsigned int comb=0)
def move
Definition: eostools.py:511
bool useDeltaR_
switch to choose between deltaR/deltaTheta matching
JetPartonMatching::algorithms algorithm_
choice of algorithm
constexpr char Jet[]
Definition: modules.cc:9
edm::EDGetTokenT< edm::View< reco::Jet > > jets_
jet collection input
int verbosity_
verbosity level
double getSumDeltaR(const unsigned int comb=0)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
TtJetPartonMatch(const edm::ParameterSet &)
default conructor
genEvt_(cfg.getParameter< edm::InputTag >("genEvent"))
#define str(s)
double getSumDeltaPt(const unsigned int comb=0)