CMS 3D CMS Logo

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