CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
46  public:
47 
49  explicit TtJetPartonMatch(const edm::ParameterSet&);
53  virtual void produce(edm::Event&, const edm::EventSetup&);
54 
55  private:
56 
58  JetPartonMatching::algorithms readAlgorithm(const std::string& str);
59 
66  int maxNJets_;
69  int maxNComb_;
73  bool useDeltaR_;
79  double maxDist_;
82 };
83 
84 template<typename C>
86  partons_ (cfg.getParameter<std::vector<std::string> >("partonsToIgnore")),
87  jets_ (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 {
96  // produces a vector of jet/lepton indices in the order of
97  // * TtSemiLepEvtPartons
98  // * TtFullHadEvtPartons
99  // * TtFullLepEvtPartons
100  // and vectors of the corresponding quality parameters
101  produces< std::vector<std::vector<int> > >();
102  produces< std::vector<double> >("SumPt");
103  produces< std::vector<double> >("SumDR");
104 }
105 
106 template<typename C>
108 {
109 }
110 
111 template<typename C>
112 void
114 {
116  evt.getByLabel("genEvt", genEvt);
117 
119  evt.getByLabel(jets_, topJets);
120 
121  // fill vector of partons in the order of
122  // * TtFullLepEvtPartons
123  // * TtSemiLepEvtPartons
124  // * TtFullHadEvtPartons
125  std::vector<const reco::Candidate*> partons = partons_.vec(*genEvt);
126 
127  // prepare vector of jets
128  std::vector<const reco::Candidate*> jets;
129  for(unsigned int ij=0; ij<topJets->size(); ++ij) {
130  // take all jets if maxNJets_ == -1; otherwise use
131  // maxNJets_ if maxNJets_ is big enough or use same
132  // number of jets as partons if maxNJets_ < number
133  // of partons
134  if(maxNJets_!=-1) {
135  if(maxNJets_>=(int)partons.size()) {
136  if((int)ij==maxNJets_) break;
137  }
138  else {
139  if(ij==partons.size()) break;
140  }
141  }
142  jets.push_back( (const reco::Candidate*) &(*topJets)[ij] );
143  }
144 
145  // do the matching with specified parameters
146  JetPartonMatching jetPartonMatch(partons, jets, algorithm_, useMaxDist_, useDeltaR_, maxDist_);
147 
148  // print some info for each event
149  // if corresponding verbosity level set
150  if(verbosity_>0)
151  jetPartonMatch.print();
152 
153  // write
154  // * parton match
155  // * sumPt
156  // * sumDR
157  // to the event
158  std::auto_ptr< std::vector<std::vector<int> > > match(new std::vector<std::vector<int> >);
159  std::auto_ptr< std::vector<double> > sumPt(new std::vector<double>);
160  std::auto_ptr< std::vector<double> > sumDR(new std::vector<double>);
161 
162  for(unsigned int ic=0; ic<jetPartonMatch.getNumberOfAvailableCombinations(); ++ic) {
163  if((int)ic>=maxNComb_ && maxNComb_>=0) break;
164  std::vector<int> matches = jetPartonMatch.getMatchesForPartons(ic);
165  partons_.expand(matches); // insert dummy indices for partons that were chosen to be ignored
166  match->push_back( matches );
167  sumPt->push_back( jetPartonMatch.getSumDeltaPt(ic) );
168  sumDR->push_back( jetPartonMatch.getSumDeltaR (ic) );
169  }
170  evt.put(match);
171  evt.put(sumPt, "SumPt");
172  evt.put(sumDR, "SumDR");
173 }
174 
175 template<typename C>
177 TtJetPartonMatch<C>::readAlgorithm(const std::string& str)
178 {
179  if (str == "totalMinDist" ) return JetPartonMatching::totalMinDist;
180  else if(str == "minSumDist" ) return JetPartonMatching::minSumDist;
181  else if(str == "ptOrderedMinDist") return JetPartonMatching::ptOrderedMinDist;
182  else if(str == "unambiguousOnly" ) return JetPartonMatching::unambiguousOnly;
183  else throw cms::Exception("Configuration")
184  << "Chosen algorithm is not supported: " << str << "\n";
185 }
186 
187 #endif
edm::InputTag jets_
jet collection input
unsigned int getNumberOfAvailableCombinations()
JetPartonMatching::algorithms readAlgorithm(const std::string &str)
convert string for algorithm into corresponding enumerator type
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
std::vector< int > getMatchesForPartons(const unsigned int comb=0)
bool useDeltaR_
switch to choose between deltaR/deltaTheta matching
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
JetPartonMatching::algorithms algorithm_
choice of algorithm
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:6
TtJetPartonMatch(const edm::ParameterSet &)
default conructor
~TtJetPartonMatch()
default destructor
double getSumDeltaPt(const unsigned int comb=0)
virtual void produce(edm::Event &, const edm::EventSetup &)
write jet parton match objects into the event