CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
TtSemiLepJetCombMVAComputer Class Reference

#include <TtSemiLepJetCombMVAComputer.h>

Inheritance diagram for TtSemiLepJetCombMVAComputer:
edm::stream::EDProducer<>

Public Member Functions

 TtSemiLepJetCombMVAComputer (const edm::ParameterSet &)
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Private Member Functions

void produce (edm::Event &evt, const edm::EventSetup &setup) override
 

Private Attributes

edm::EDGetTokenT< std::vector
< pat::Jet > > 
jetsToken_
 
edm::EDGetTokenT< edm::View
< reco::RecoCandidate > > 
lepsToken_
 
const int maxNComb_
 
const int maxNJets_
 
edm::EDGetTokenT< std::vector
< pat::MET > > 
metsToken_
 
PhysicsTools::MVAComputerCache mvaComputer
 
edm::ESGetToken
< PhysicsTools::Calibration::MVAComputerContainer,
TtSemiLepJetCombMVARcd
mvaToken_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T...>
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T...>
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Definition at line 21 of file TtSemiLepJetCombMVAComputer.h.

Constructor & Destructor Documentation

TtSemiLepJetCombMVAComputer::TtSemiLepJetCombMVAComputer ( const edm::ParameterSet cfg)
explicit

Definition at line 5 of file TtSemiLepJetCombMVAComputer.cc.

8  jetsToken_(consumes<std::vector<pat::Jet>>(cfg.getParameter<edm::InputTag>("jets"))),
9  metsToken_(consumes<std::vector<pat::MET>>(cfg.getParameter<edm::InputTag>("mets"))),
10  maxNJets_(cfg.getParameter<int>("maxNJets")),
11  maxNComb_(cfg.getParameter<int>("maxNComb")) {
12  produces<std::vector<std::vector<int>>>();
13  produces<std::vector<double>>("Discriminators");
14  produces<std::string>("Method");
15  produces<int>("NumberOfConsideredJets");
16 }
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
edm::EDGetTokenT< std::vector< pat::MET > > metsToken_
edm::ESGetToken< PhysicsTools::Calibration::MVAComputerContainer, TtSemiLepJetCombMVARcd > mvaToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< edm::View< reco::RecoCandidate > > lepsToken_
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283

Member Function Documentation

void TtSemiLepJetCombMVAComputer::produce ( edm::Event evt,
const edm::EventSetup setup 
)
overrideprivate

Definition at line 18 of file TtSemiLepJetCombMVAComputer.cc.

References PhysicsTools::MVAComputer::eval(), evaluateTtSemiLepJetComb(), edm::Event::getByToken(), edm::EventSetup::getData(), mps_fire::i, fwrapper::jets, jetsToken_, lepsToken_, HLT_FULL_cff::leptons, TtSemiLepEvtPartons::LightQ, TtSemiLepEvtPartons::LightQBar, maxNComb_, maxNJets_, objects.METAnalyzer::met, metsToken_, eostools::move(), mvaComputer, mvaToken_, stdcomb::next_combination(), nPartons, edm::Event::put(), AlCaHLTBitMon_QueryRunRegistry::string, PhysicsTools::MVAComputerCache::update(), makeHLTPrescaleTable::values, and trackerHitRTTI::vector.

18  {
19  std::unique_ptr<std::vector<std::vector<int>>> pOut(new std::vector<std::vector<int>>);
20  std::unique_ptr<std::vector<double>> pOutDisc(new std::vector<double>);
21  std::unique_ptr<std::string> pOutMeth(new std::string);
22  std::unique_ptr<int> pJetsConsidered(new int);
23 
24  const auto& calibContainer = setup.getData(mvaToken_);
25  mvaComputer.update(&calibContainer, "ttSemiLepJetCombMVA");
26 
27  // read name of the processor that provides the MVA discriminator
28  // (to be used as meta information)
29  std::vector<const PhysicsTools::Calibration::VarProcessor*> processors =
30  (calibContainer.find("ttSemiLepJetCombMVA")).getProcessors();
31  *pOutMeth = (processors[processors.size() - 3])->getInstanceName();
32  evt.put(std::move(pOutMeth), "Method");
33 
34  // get lepton, jets and mets
36  evt.getByToken(lepsToken_, leptons);
37 
39  evt.getByToken(jetsToken_, jets);
40 
42  evt.getByToken(metsToken_, mets);
43 
44  const unsigned int nPartons = 4;
45 
46  // skip events with no appropriate lepton candidate,
47  // empty METs vector or less jets than partons
48  if (leptons->empty() || mets->empty() || jets->size() < nPartons) {
49  std::vector<int> invalidCombi;
50  for (unsigned int i = 0; i < nPartons; ++i)
51  invalidCombi.push_back(-1);
52  pOut->push_back(invalidCombi);
53  evt.put(std::move(pOut));
54  pOutDisc->push_back(0.);
55  evt.put(std::move(pOutDisc), "Discriminators");
56  *pJetsConsidered = jets->size();
57  evt.put(std::move(pJetsConsidered), "NumberOfConsideredJets");
58  return;
59  }
60 
61  const math::XYZTLorentzVector lepton = leptons->begin()->p4();
62 
63  const pat::MET* met = &(*mets)[0];
64 
65  // analyze jet combinations
66  std::vector<int> jetIndices;
67  for (unsigned int i = 0; i < jets->size(); ++i) {
68  if (maxNJets_ >= (int)nPartons && maxNJets_ == (int)i) {
69  *pJetsConsidered = i;
70  break;
71  }
72  jetIndices.push_back(i);
73  }
74 
75  std::vector<int> combi;
76  for (unsigned int i = 0; i < nPartons; ++i)
77  combi.push_back(i);
78 
79  typedef std::pair<double, std::vector<int>> discCombPair;
80  std::list<discCombPair> discCombList;
81 
82  do {
83  for (int cnt = 0; cnt < TMath::Factorial(combi.size()); ++cnt) {
84  // take into account indistinguishability of the two jets from the hadr. W decay,
85  // reduces combinatorics by a factor of 2
87  TtSemiLepJetComb jetComb(*jets, combi, lepton, *met);
88 
89  // feed MVA input variables into a ValueList
91  evaluateTtSemiLepJetComb(values, jetComb);
92 
93  // get discriminator from the MVAComputer
94  double discrim = mvaComputer->eval(values);
95 
96  discCombList.push_back(std::make_pair(discrim, combi));
97  }
98  next_permutation(combi.begin(), combi.end());
99  }
100  } while (stdcomb::next_combination(jetIndices.begin(), jetIndices.end(), combi.begin(), combi.end()));
101 
102  // sort results w.r.t. discriminator values
103  discCombList.sort();
104 
105  // write result into the event
106  // (starting with the JetComb having the highest discriminator value -> reverse iterator)
107  unsigned int iDiscComb = 0;
108  typedef std::list<discCombPair>::reverse_iterator discCombIterator;
109  for (discCombIterator discCombPair = discCombList.rbegin(); discCombPair != discCombList.rend(); ++discCombPair) {
110  if (maxNComb_ >= 1 && iDiscComb == (unsigned int)maxNComb_)
111  break;
112  pOut->push_back(discCombPair->second);
113  pOutDisc->push_back(discCombPair->first);
114  iDiscComb++;
115  }
116  evt.put(std::move(pOut));
117  evt.put(std::move(pOutDisc), "Discriminators");
118  evt.put(std::move(pJetsConsidered), "NumberOfConsideredJets");
119 }
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:133
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:539
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
edm::EDGetTokenT< std::vector< pat::MET > > metsToken_
bool getData(T &iHolder) const
Definition: EventSetup.h:122
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
edm::ESGetToken< PhysicsTools::Calibration::MVAComputerContainer, TtSemiLepJetCombMVARcd > mvaToken_
vector< PseudoJet > jets
def move
Definition: eostools.py:511
PhysicsTools::MVAComputerCache mvaComputer
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)
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

Member Data Documentation

edm::EDGetTokenT<std::vector<pat::Jet> > TtSemiLepJetCombMVAComputer::jetsToken_
private

Definition at line 30 of file TtSemiLepJetCombMVAComputer.h.

Referenced by produce().

edm::EDGetTokenT<edm::View<reco::RecoCandidate> > TtSemiLepJetCombMVAComputer::lepsToken_
private

Definition at line 29 of file TtSemiLepJetCombMVAComputer.h.

Referenced by produce().

const int TtSemiLepJetCombMVAComputer::maxNComb_
private

Definition at line 34 of file TtSemiLepJetCombMVAComputer.h.

Referenced by produce().

const int TtSemiLepJetCombMVAComputer::maxNJets_
private

Definition at line 33 of file TtSemiLepJetCombMVAComputer.h.

Referenced by produce().

edm::EDGetTokenT<std::vector<pat::MET> > TtSemiLepJetCombMVAComputer::metsToken_
private

Definition at line 31 of file TtSemiLepJetCombMVAComputer.h.

Referenced by produce().

PhysicsTools::MVAComputerCache TtSemiLepJetCombMVAComputer::mvaComputer
private

Definition at line 36 of file TtSemiLepJetCombMVAComputer.h.

Referenced by produce().

Definition at line 28 of file TtSemiLepJetCombMVAComputer.h.

Referenced by produce().