CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
TtSemiLepJetCombMVAComputer Class Reference

#include <TtSemiLepJetCombMVAComputer.h>

Inheritance diagram for TtSemiLepJetCombMVAComputer:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 TtSemiLepJetCombMVAComputer (const edm::ParameterSet &)
 
 ~TtSemiLepJetCombMVAComputer () override
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducer () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void beginJob () override
 
void endJob () override
 
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_
 
int maxNComb_
 
int maxNJets_
 
edm::EDGetTokenT< std::vector< pat::MET > > metsToken_
 
PhysicsTools::MVAComputerCache mvaComputer
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::ProducerBase
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

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.

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 }
T getParameter(std::string const &) const
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
edm::EDGetTokenT< std::vector< pat::MET > > metsToken_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< edm::View< reco::RecoCandidate > > lepsToken_
TtSemiLepJetCombMVAComputer::~TtSemiLepJetCombMVAComputer ( )
override

Definition at line 17 of file TtSemiLepJetCombMVAComputer.cc.

17 {}

Member Function Documentation

void TtSemiLepJetCombMVAComputer::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 123 of file TtSemiLepJetCombMVAComputer.cc.

123 {}
void TtSemiLepJetCombMVAComputer::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 125 of file TtSemiLepJetCombMVAComputer.cc.

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

Definition at line 19 of file TtSemiLepJetCombMVAComputer.cc.

References PhysicsTools::MVAComputer::eval(), evaluateTtSemiLepJetComb(), edm::eventsetup::EventSetupRecordImplementation< T >::get(), edm::Event::getByToken(), mps_fire::i, createfilelist::int, singleTopDQM_cfi::jets, jetsToken_, lepsToken_, HLT_2018_cff::leptons, TtSemiLepEvtPartons::LightQ, TtSemiLepEvtPartons::LightQBar, maxNComb_, maxNJets_, BTaggingMonitor_cfi::met, singleTopDQM_cfi::mets, metsToken_, eostools::move(), mvaComputer, stdcomb::next_combination(), nPartons, edm::Event::put(), singleTopDQM_cfi::setup, AlCaHLTBitMon_QueryRunRegistry::string, PhysicsTools::MVAComputerCache::update(), and contentValuesCheck::values.

19  {
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 }
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
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
edm::EDGetTokenT< std::vector< pat::MET > > metsToken_
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
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
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

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

Definition at line 32 of file TtSemiLepJetCombMVAComputer.h.

Referenced by produce().

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

Definition at line 31 of file TtSemiLepJetCombMVAComputer.h.

Referenced by produce().

int TtSemiLepJetCombMVAComputer::maxNComb_
private

Definition at line 36 of file TtSemiLepJetCombMVAComputer.h.

Referenced by produce().

int TtSemiLepJetCombMVAComputer::maxNJets_
private

Definition at line 35 of file TtSemiLepJetCombMVAComputer.h.

Referenced by produce().

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

Definition at line 33 of file TtSemiLepJetCombMVAComputer.h.

Referenced by produce().

PhysicsTools::MVAComputerCache TtSemiLepJetCombMVAComputer::mvaComputer
private

Definition at line 38 of file TtSemiLepJetCombMVAComputer.h.

Referenced by produce().