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  produces<int >("NumberOfConsideredJets");
20 }
21 
23 {
24 }
25 
26 void
28 {
29  std::auto_ptr<std::vector<std::vector<int> > > pOut (new std::vector<std::vector<int> >);
30  std::auto_ptr<std::vector<double> > pOutDisc(new std::vector<double>);
31  std::auto_ptr<std::string > pOutMeth(new std::string);
32  std::auto_ptr<int > pJetsConsidered(new int);
33 
34  mvaComputer.update<TtSemiLepJetCombMVARcd>(setup, "ttSemiLepJetCombMVA");
35 
36  // read name of the processor that provides the MVA discriminator
37  // (to be used as meta information)
39  setup.get<TtSemiLepJetCombMVARcd>().get( calibContainer );
40  std::vector<PhysicsTools::Calibration::VarProcessor*> processors
41  = (calibContainer->find("ttSemiLepJetCombMVA")).getProcessors();
42  *pOutMeth = ( processors[ processors.size()-3 ] )->getInstanceName();
43  evt.put(pOutMeth, "Method");
44 
45  // get lepton, jets and mets
47  evt.getByLabel(leps_, leptons);
48 
50  evt.getByLabel(jets_, jets);
51 
53  evt.getByLabel(mets_, mets);
54 
55  const unsigned int nPartons = 4;
56 
57  // skip events with no appropriate lepton candidate,
58  // empty METs vector or less jets than partons
59  if( leptons->empty() || mets->empty() || jets->size() < nPartons ) {
60  std::vector<int> invalidCombi;
61  for(unsigned int i = 0; i < nPartons; ++i)
62  invalidCombi.push_back( -1 );
63  pOut->push_back( invalidCombi );
64  evt.put(pOut);
65  pOutDisc->push_back( 0. );
66  evt.put(pOutDisc, "Discriminators");
67  *pJetsConsidered = jets->size();
68  evt.put(pJetsConsidered, "NumberOfConsideredJets");
69  return;
70  }
71 
72  const math::XYZTLorentzVector lepton = leptons->begin()->p4();
73 
74  const pat::MET *met = &(*mets)[0];
75 
76  // analyze jet combinations
77  std::vector<int> jetIndices;
78  for(unsigned int i=0; i<jets->size(); ++i){
79  if(maxNJets_ >= (int) nPartons && maxNJets_ == (int) i) {
80  *pJetsConsidered = i;
81  break;
82  }
83  jetIndices.push_back(i);
84  }
85 
86  std::vector<int> combi;
87  for(unsigned int i=0; i<nPartons; ++i)
88  combi.push_back(i);
89 
90  typedef std::pair<double, std::vector<int> > discCombPair;
91  std::list<discCombPair> discCombList;
92 
93  do{
94  for(int cnt = 0; cnt < TMath::Factorial( combi.size() ); ++cnt){
95  // take into account indistinguishability of the two jets from the hadr. W decay,
96  // reduces combinatorics by a factor of 2
98 
99  TtSemiLepJetComb jetComb(*jets, combi, lepton, *met);
100 
101  // feed MVA input variables into a ValueList
103  evaluateTtSemiLepJetComb(values, jetComb);
104 
105  // get discriminator from the MVAComputer
106  double discrim = mvaComputer->eval( values );
107 
108  discCombList.push_back( std::make_pair(discrim, combi) );
109 
110  }
111  next_permutation( combi.begin() , combi.end() );
112  }
113  }
114  while(stdcomb::next_combination( jetIndices.begin(), jetIndices.end(), combi.begin(), combi.end() ));
115 
116  // sort results w.r.t. discriminator values
117  discCombList.sort();
118 
119  // write result into the event
120  // (starting with the JetComb having the highest discriminator value -> reverse iterator)
121  unsigned int iDiscComb = 0;
122  typedef std::list<discCombPair>::reverse_iterator discCombIterator;
123  for(discCombIterator discCombPair = discCombList.rbegin(); discCombPair != discCombList.rend(); ++discCombPair) {
124  if(maxNComb_ >= 1 && iDiscComb == (unsigned int) maxNComb_) break;
125  pOut ->push_back( discCombPair->second );
126  pOutDisc->push_back( discCombPair->first );
127  iDiscComb++;
128  }
129  evt.put(pOut);
130  evt.put(pOutDisc, "Discriminators");
131  evt.put(pJetsConsidered, "NumberOfConsideredJets");
132 }
133 
134 void
136 {
137 }
138 
139 void
141 {
142 }
143 
144 // implement the plugins for the computer container
145 // -> register TtSemiLepJetCombMVARcd
146 // -> define TtSemiLepJetCombMVAFileSource
147 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:94
vector< PseudoJet > jets
PhysicsTools::MVAComputerCache mvaComputer
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
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
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")