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
39 
42 
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
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);
PhysicsTools::MVAComputer::eval
double eval(Iterator_t first, Iterator_t last) const
evaluate variables given by a range of iterators given by first and last
mps_fire.i
i
Definition: mps_fire.py:428
TtSemiLepJetCombMVAComputer::lepsToken_
edm::EDGetTokenT< edm::View< reco::RecoCandidate > > lepsToken_
Definition: TtSemiLepJetCombMVAComputer.h:31
TtSemiLepEvtPartons::LightQBar
Definition: TtSemiLepEvtPartons.h:25
TtSemiLepJetCombMVAComputer::jetsToken_
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
Definition: TtSemiLepJetCombMVAComputer.h:32
sistrip::View
View
Definition: ConstantsForView.h:26
HLT_FULL_cff.leptons
leptons
Definition: HLT_FULL_cff.py:26294
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
L1TrackObjectNtupleMaker_cfg.pOut
pOut
Definition: L1TrackObjectNtupleMaker_cfg.py:172
TtSemiLepJetCombMVAComputer::endJob
void endJob() override
Definition: TtSemiLepJetCombMVAComputer.cc:125
TtSemiLepJetCombMVARcd
Definition: TtSemiLepJetCombMVAComputer.h:18
singleTopDQM_cfi.jets
jets
Definition: singleTopDQM_cfi.py:42
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
singleTopDQM_cfi.mets
mets
Definition: singleTopDQM_cfi.py:43
edm::Handle
Definition: AssociativeIterator.h:50
PhysicsTools::Variable::ValueList
Helper class that can contain an list of identifier-value pairs.
Definition: Variable.h:77
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
TtSemiLepJetCombMVAComputer::mvaComputer
PhysicsTools::MVAComputerCache mvaComputer
Definition: TtSemiLepJetCombMVAComputer.h:38
BTaggingMonitor_cfi.met
met
Definition: BTaggingMonitor_cfi.py:84
Jet
Definition: Jet.py:1
TtSemiLepJetComb
Common calculator class to keep multivariate analysis variables for jet combinations in semi-leptonic...
Definition: TtSemiLepJetComb.h:48
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
edm::ESHandle
Definition: DTSurvey.h:22
evaluateTtSemiLepJetComb
void evaluateTtSemiLepJetComb(PhysicsTools::Variable::ValueList &values, const TtSemiLepJetComb &jetComb)
Definition: TtSemiLepJetCombEval.h:13
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
edm::ParameterSet
Definition: ParameterSet.h:47
TtSemiLepJetCombMVAComputer::metsToken_
edm::EDGetTokenT< std::vector< pat::MET > > metsToken_
Definition: TtSemiLepJetCombMVAComputer.h:33
nPartons
static const unsigned int nPartons
Definition: TtFullHadKinFitProducer.cc:3
TtSemiLepEvtPartons::LightQ
Definition: TtSemiLepEvtPartons.h:25
createfilelist.int
int
Definition: createfilelist.py:10
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
pat::MET
Analysis-level MET class.
Definition: MET.h:40
edm::EventSetup
Definition: EventSetup.h:58
pat
Definition: HeavyIon.h:7
get
#define get
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
looper.cfg
cfg
Definition: looper.py:296
TtSemiLepJetCombMVAComputer::produce
void produce(edm::Event &evt, const edm::EventSetup &setup) override
Definition: TtSemiLepJetCombMVAComputer.cc:19
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
stdcomb::next_combination
bool next_combination(BidIt n_begin, BidIt n_end, BidIt r_begin, BidIt r_end)
Definition: combination.h:19
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
PhysicsTools::MVAComputerCache::update
bool update(const Calibration::MVAComputer *computer)
Definition: MVAComputerCache.cc:15
TtSemiLepJetCombMVAComputer::~TtSemiLepJetCombMVAComputer
~TtSemiLepJetCombMVAComputer() override
Definition: TtSemiLepJetCombMVAComputer.cc:17
MET
MVA_COMPUTER_CONTAINER_IMPLEMENT
#define MVA_COMPUTER_CONTAINER_IMPLEMENT(N)
Definition: HelperMacros.h:53
TtSemiLepJetCombMVAComputer::beginJob
void beginJob() override
Definition: TtSemiLepJetCombMVAComputer.cc:123
TtSemiLepJetCombMVAComputer::maxNComb_
int maxNComb_
Definition: TtSemiLepJetCombMVAComputer.h:36
TtSemiLepJetCombMVAComputer::maxNJets_
int maxNJets_
Definition: TtSemiLepJetCombMVAComputer.h:35
edm::Event
Definition: Event.h:73
TtSemiLepJetCombMVAComputer.h
combination.h
TtSemiLepJetCombMVAComputer::TtSemiLepJetCombMVAComputer
TtSemiLepJetCombMVAComputer(const edm::ParameterSet &)
Definition: TtSemiLepJetCombMVAComputer.cc:5