CMS 3D CMS Logo

TtSemiLepJetCombMVAComputer.cc
Go to the documentation of this file.
2 
4 
6  : lepsToken_(consumes<edm::View<reco::RecoCandidate>>(cfg.getParameter<edm::InputTag>("leps"))),
7  jetsToken_(consumes<std::vector<pat::Jet>>(cfg.getParameter<edm::InputTag>("jets"))),
8  metsToken_(consumes<std::vector<pat::MET>>(cfg.getParameter<edm::InputTag>("mets"))),
9  maxNJets_(cfg.getParameter<int>("maxNJets")),
10  maxNComb_(cfg.getParameter<int>("maxNComb")) {
11  produces<std::vector<std::vector<int>>>();
12  produces<std::vector<double>>("Discriminators");
13  produces<std::string>("Method");
14  produces<int>("NumberOfConsideredJets");
15 }
16 
18 
20  std::unique_ptr<std::vector<std::vector<int>>> pOut(new std::vector<std::vector<int>>);
21  std::unique_ptr<std::vector<double>> pOutDisc(new std::vector<double>);
22  std::unique_ptr<std::string> pOutMeth(new std::string);
23  std::unique_ptr<int> pJetsConsidered(new int);
24 
25  mvaComputer.update<TtSemiLepJetCombMVARcd>(setup, "ttSemiLepJetCombMVA");
26 
27  // read name of the processor that provides the MVA discriminator
28  // (to be used as meta information)
30  setup.get<TtSemiLepJetCombMVARcd>().get(calibContainer);
31  std::vector<PhysicsTools::Calibration::VarProcessor*> processors =
32  (calibContainer->find("ttSemiLepJetCombMVA")).getProcessors();
33  *pOutMeth = (processors[processors.size() - 3])->getInstanceName();
34  evt.put(std::move(pOutMeth), "Method");
35 
36  // get lepton, jets and mets
38  evt.getByToken(lepsToken_, leptons);
39 
41  evt.getByToken(jetsToken_, jets);
42 
44  evt.getByToken(metsToken_, mets);
45 
46  const unsigned int nPartons = 4;
47 
48  // skip events with no appropriate lepton candidate,
49  // empty METs vector or less jets than partons
50  if (leptons->empty() || mets->empty() || jets->size() < nPartons) {
51  std::vector<int> invalidCombi;
52  for (unsigned int i = 0; i < nPartons; ++i)
53  invalidCombi.push_back(-1);
54  pOut->push_back(invalidCombi);
55  evt.put(std::move(pOut));
56  pOutDisc->push_back(0.);
57  evt.put(std::move(pOutDisc), "Discriminators");
58  *pJetsConsidered = jets->size();
59  evt.put(std::move(pJetsConsidered), "NumberOfConsideredJets");
60  return;
61  }
62 
63  const math::XYZTLorentzVector lepton = leptons->begin()->p4();
64 
65  const pat::MET* met = &(*mets)[0];
66 
67  // analyze jet combinations
68  std::vector<int> jetIndices;
69  for (unsigned int i = 0; i < jets->size(); ++i) {
70  if (maxNJets_ >= (int)nPartons && maxNJets_ == (int)i) {
71  *pJetsConsidered = i;
72  break;
73  }
74  jetIndices.push_back(i);
75  }
76 
77  std::vector<int> combi;
78  for (unsigned int i = 0; i < nPartons; ++i)
79  combi.push_back(i);
80 
81  typedef std::pair<double, std::vector<int>> discCombPair;
82  std::list<discCombPair> discCombList;
83 
84  do {
85  for (int cnt = 0; cnt < TMath::Factorial(combi.size()); ++cnt) {
86  // take into account indistinguishability of the two jets from the hadr. W decay,
87  // reduces combinatorics by a factor of 2
89  TtSemiLepJetComb jetComb(*jets, combi, lepton, *met);
90 
91  // feed MVA input variables into a ValueList
93  evaluateTtSemiLepJetComb(values, jetComb);
94 
95  // get discriminator from the MVAComputer
96  double discrim = mvaComputer->eval(values);
97 
98  discCombList.push_back(std::make_pair(discrim, combi));
99  }
100  next_permutation(combi.begin(), combi.end());
101  }
102  } while (stdcomb::next_combination(jetIndices.begin(), jetIndices.end(), combi.begin(), combi.end()));
103 
104  // sort results w.r.t. discriminator values
105  discCombList.sort();
106 
107  // write result into the event
108  // (starting with the JetComb having the highest discriminator value -> reverse iterator)
109  unsigned int iDiscComb = 0;
110  typedef std::list<discCombPair>::reverse_iterator discCombIterator;
111  for (discCombIterator discCombPair = discCombList.rbegin(); discCombPair != discCombList.rend(); ++discCombPair) {
112  if (maxNComb_ >= 1 && iDiscComb == (unsigned int)maxNComb_)
113  break;
114  pOut->push_back(discCombPair->second);
115  pOutDisc->push_back(discCombPair->first);
116  iDiscComb++;
117  }
118  evt.put(std::move(pOut));
119  evt.put(std::move(pOutDisc), "Discriminators");
120  evt.put(std::move(pJetsConsidered), "NumberOfConsideredJets");
121 }
122 
124 
126 
127 // implement the plugins for the computer container
128 // -> register TtSemiLepJetCombMVARcd
129 // -> define TtSemiLepJetCombMVAFileSource
130 MVA_COMPUTER_CONTAINER_IMPLEMENT(TtSemiLepJetCombMVA);
Analysis-level MET class.
Definition: MET.h:40
static const unsigned int nPartons
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
double eval(Iterator_t first, Iterator_t last) const
evaluate variables given by a range of iterators given by first and last
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
#define MVA_COMPUTER_CONTAINER_IMPLEMENT(N)
Definition: HelperMacros.h:53
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
edm::EDGetTokenT< std::vector< pat::MET > > metsToken_
Definition: HeavyIon.h:7
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
Definition: Jet.py:1
PhysicsTools::MVAComputerCache mvaComputer
void produce(edm::Event &evt, const edm::EventSetup &setup) override
Helper class that can contain an list of identifier-value pairs.
Definition: Variable.h:77
bool update(const Calibration::MVAComputer *computer)
void evaluateTtSemiLepJetComb(PhysicsTools::Variable::ValueList &values, const TtSemiLepJetComb &jetComb)
TtSemiLepJetCombMVAComputer(const edm::ParameterSet &)
fixed size matrix
HLT enums.
Common calculator class to keep multivariate analysis variables for jet combinations in semi-leptonic...
edm::EDGetTokenT< edm::View< reco::RecoCandidate > > lepsToken_
bool next_combination(BidIt n_begin, BidIt n_end, BidIt r_begin, BidIt r_end)
Definition: combination.h:19
def move(src, dest)
Definition: eostools.py:511