test
CMS 3D CMS Logo

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

#include <TtSemiLepJetCombMVATrainer.h>

Inheritance diagram for TtSemiLepJetCombMVATrainer:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

 TtSemiLepJetCombMVATrainer (const edm::ParameterSet &)
 
 ~TtSemiLepJetCombMVATrainer ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (std::string const &iProcessName, std::string const &iModuleLabel, bool iPrint, std::vector< char const * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

virtual void analyze (const edm::Event &evt, const edm::EventSetup &setup)
 
virtual void beginJob ()
 
virtual void endJob ()
 
WDecay::LeptonType readLeptonType (const std::string &str)
 

Private Attributes

edm::EDGetTokenT< TtGenEventgenEvtToken_
 
edm::EDGetTokenT< std::vector
< pat::Jet > > 
jetsToken_
 
edm::EDGetTokenT< edm::View
< reco::RecoCandidate > > 
lepsToken_
 
WDecay::LeptonType leptonType_
 
edm::EDGetTokenT< std::vector
< std::vector< int > > > 
matchingToken_
 
int maxNJets_
 
edm::EDGetTokenT< std::vector
< pat::MET > > 
metsToken_
 
PhysicsTools::MVAComputerCache mvaComputer
 
unsigned int nEvents [5]
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- 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 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 25 of file TtSemiLepJetCombMVATrainer.h.

Constructor & Destructor Documentation

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

Definition at line 14 of file TtSemiLepJetCombMVATrainer.cc.

14  :
15  genEvtToken_ (consumes<TtGenEvent>(edm::InputTag("genEvt"))),
17  jetsToken_ (consumes< std::vector<pat::Jet> >(cfg.getParameter<edm::InputTag>("jets" ))),
18  metsToken_ (consumes< std::vector<pat::MET> >(cfg.getParameter<edm::InputTag>("mets" ))),
19  matchingToken_ (mayConsume< std::vector< std::vector<int> > >(cfg.getParameter<edm::InputTag>("matching"))),
20  maxNJets_ (cfg.getParameter<int> ("maxNJets")),
22 {
23 }
T getParameter(std::string const &) const
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
edm::EDGetTokenT< edm::View< reco::RecoCandidate > > lepsToken_
WDecay::LeptonType readLeptonType(const std::string &str)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< TtGenEvent > genEvtToken_
edm::EDGetTokenT< std::vector< std::vector< int > > > matchingToken_
edm::EDGetTokenT< std::vector< pat::MET > > metsToken_
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
TtSemiLepJetCombMVATrainer::~TtSemiLepJetCombMVATrainer ( )

Definition at line 25 of file TtSemiLepJetCombMVATrainer.cc.

26 {
27 }

Member Function Documentation

void TtSemiLepJetCombMVATrainer::analyze ( const edm::Event evt,
const edm::EventSetup setup 
)
privatevirtual

Implements edm::EDAnalyzer.

Definition at line 37 of file TtSemiLepJetCombMVATrainer.cc.

References PhysicsTools::Variable::ValueList::add(), PhysicsTools::MVAComputer::eval(), evaluateTtSemiLepJetComb(), TtGenEvtProducer_cfi::genEvt, genEvtToken_, edm::Event::getByToken(), i, fwrapper::jets, jetsToken_, PhysicsTools::MVATrainer::kTargetId, lepsToken_, HLT_25ns10e33_v2_cff::leptons, leptonType_, TtSemiLepEvtPartons::LightQ, TtSemiLepEvtPartons::LightQBar, matchingToken_, maxNJets_, objects.METAnalyzer::met, metsToken_, mvaComputer, nEvents, stdcomb::next_combination(), nPartons, GeneralSetup::setup(), PhysicsTools::MVAComputerCache::update(), and makeHLTPrescaleTable::values.

38 {
39  mvaComputer.update<TtSemiLepJetCombMVARcd>("trainer", setup, "ttSemiLepJetCombMVA");
40 
41  // can occur in the last iteration when the
42  // MVATrainer is about to save the result
43  if(!mvaComputer) return;
44 
45  nEvents[0]++;
46 
48  evt.getByToken(genEvtToken_, genEvt);
49 
51  evt.getByToken(lepsToken_, leptons);
52 
53  // skip events with no appropriate lepton candidate
54  if( leptons->empty() ) return;
55 
56  nEvents[1]++;
57 
58  const math::XYZTLorentzVector lepton = leptons->begin()->p4();
59 
61  evt.getByToken(metsToken_, mets);
62 
63  // skip events with empty METs vector
64  if( mets->empty() ) return;
65 
66  nEvents[2]++;
67 
68  const pat::MET *met = &(*mets)[0];
69 
71  evt.getByToken(jetsToken_, jets);
72 
73  // skip events with less jets than partons
74  unsigned int nPartons = 4;
75  if( jets->size() < nPartons ) return;
76 
77  nEvents[3]++;
78 
80  std::vector<int> matching;
81  // get jet-parton matching if signal channel
82  if(genEvt->semiLeptonicChannel() == leptonType_) {
83  evt.getByToken(matchingToken_, matchingHandle);
84  if( matchingHandle->empty() )
85  throw cms::Exception("EmptyProduct")
86  << "Empty vector from jet-parton matching. This should not happen! \n";
87  matching = *(matchingHandle->begin());
88  if(matching.size() < nPartons) return;
89  // skip events that were affected by the outlier
90  // rejection in the jet-parton matching
91  for(unsigned int i = 0; i < matching.size(); ++i) {
92  if(matching[i] == -3) continue; // -3: parton was chosen to be excluded from jet-parton matching
93  if(matching[i] < 0 || matching[i] >= (int)jets->size())
94  return;
95  }
96  }
97  // use dummy for matching if not signal channel
98  else
99  for(unsigned int i = 0; i < nPartons; i++)
100  matching.push_back( -1 );
101 
102  nEvents[4]++;
103 
104  // take into account indistinguishability of the two jets from the hadr. W decay,
105  // reduces combinatorics by a factor of 2
107  int iTemp = matching[TtSemiLepEvtPartons::LightQ];
109  matching[TtSemiLepEvtPartons::LightQBar] = iTemp;
110  }
111 
112  std::vector<int> jetIndices;
113  for(unsigned int i=0; i<jets->size(); ++i) {
114  if(maxNJets_ >= (int) nPartons && i == (unsigned int) maxNJets_) break;
115  jetIndices.push_back(i);
116  }
117 
118  std::vector<int> combi;
119  for(unsigned int i = 0; i < nPartons; ++i)
120  combi.push_back(i);
121 
122  // use a ValueList to collect all variables for the MVAComputer
124 
125  // set target variable to false like for background
126  // this is necessary when passing all combinations at once
128 
129  do {
130  // number of possible combinations from number of partons: e.g. 4! = 24
131  for(unsigned int cnt = 0; cnt < TMath::Factorial( combi.size() ); ++cnt) {
132 
133  // take into account indistinguishability of the two jets from the hadr. W decay,
134  // reduces combinatorics by a factor of 2
135  if(combi[TtSemiLepEvtPartons::LightQ] < combi[TtSemiLepEvtPartons::LightQBar]) {
136 
137  TtSemiLepJetComb jetComb(*jets, combi, lepton, *met);
138 
139  bool trueCombi = false;
140  // true combination only if signal channel
141  // and in agreement with matching
142  if(genEvt->semiLeptonicChannel()==leptonType_) {
143  trueCombi = true;
144  for(unsigned int i = 0; i < matching.size(); ++i) {
145  if(combi[i]!=matching[i] && matching[i]!=-3) {
146  trueCombi = false;
147  break;
148  }
149  }
150  }
151 
152  // feed MVA input variables for this jetComb into the ValueList
153  values.add("target", trueCombi);
154  evaluateTtSemiLepJetComb(values, jetComb);
155 
156  }
157 
158  next_permutation( combi.begin() , combi.end() );
159  }
160  }
161  while(stdcomb::next_combination( jetIndices.begin(), jetIndices.end(), combi.begin(), combi.end() ));
162 
163  // pass MVA input variables for all jet combinations in this event
164  // to the MVAComputer for training
165  mvaComputer->eval( values );
166 }
PhysicsTools::MVAComputerCache mvaComputer
Analysis-level MET class.
Definition: MET.h:43
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
int i
Definition: DBlmapReader.cc:9
static const unsigned int nPartons
edm::EDGetTokenT< edm::View< reco::RecoCandidate > > lepsToken_
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:462
static const AtomicId kTargetId
Definition: MVATrainer.h:59
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
edm::EDGetTokenT< TtGenEvent > genEvtToken_
vector< PseudoJet > jets
edm::EDGetTokenT< std::vector< std::vector< int > > > matchingToken_
Helper class that can contain an list of identifier-value pairs.
Definition: Variable.h:81
bool update(const Calibration::MVAComputer *computer)
Helper class that can contain an identifier-value pair.
Definition: Variable.h:51
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< std::vector< pat::MET > > metsToken_
bool next_combination(BidIt n_begin, BidIt n_end, BidIt r_begin, BidIt r_end)
Definition: combination.h:22
void add(AtomicId id, double value)
Definition: Variable.h:106
void TtSemiLepJetCombMVATrainer::beginJob ( void  )
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 30 of file TtSemiLepJetCombMVATrainer.cc.

References i, and nEvents.

31 {
32  for(unsigned int i = 0; i < 5; i++)
33  nEvents[i] = 0;
34 }
int i
Definition: DBlmapReader.cc:9
void TtSemiLepJetCombMVATrainer::endJob ( void  )
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 169 of file TtSemiLepJetCombMVATrainer.cc.

References dqm-mbProfile::log, and nEvents.

170 {
171  edm::LogInfo log("TtSemiLepJetCombMVATrainer");
172  log << "Number of events... \n"
173  << "...passed to the trainer : " << std::setw(7) << nEvents[0] << "\n"
174  << "...rejected since no lepton candidate : " << std::setw(7) << nEvents[0]-nEvents[1] << "\n"
175  << "...rejected since no MET object : " << std::setw(7) << nEvents[1]-nEvents[2] << "\n"
176  << "...rejected since not enough jets : " << std::setw(7) << nEvents[2]-nEvents[3] << "\n"
177  << "...rejected due to bad jet-parton matching : " << std::setw(7) << nEvents[3]-nEvents[4] << "\n"
178  << "...accepted for training : " << std::setw(7) << nEvents[4] << "\n";
179 }
WDecay::LeptonType TtSemiLepJetCombMVATrainer::readLeptonType ( const std::string &  str)
private

Definition at line 182 of file TtSemiLepJetCombMVATrainer.cc.

References Exception, WDecay::kElec, WDecay::kMuon, and WDecay::kTau.

183 {
184  if (str == "kElec") return WDecay::kElec;
185  else if(str == "kMuon") return WDecay::kMuon;
186  else if(str == "kTau" ) return WDecay::kTau;
187  else throw cms::Exception("Configuration")
188  << "Chosen leptonType is not supported: " << str << "\n";
189 }

Member Data Documentation

edm::EDGetTokenT<TtGenEvent> TtSemiLepJetCombMVATrainer::genEvtToken_
private

Definition at line 40 of file TtSemiLepJetCombMVATrainer.h.

Referenced by analyze().

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

Definition at line 42 of file TtSemiLepJetCombMVATrainer.h.

Referenced by analyze().

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

Definition at line 41 of file TtSemiLepJetCombMVATrainer.h.

Referenced by analyze().

WDecay::LeptonType TtSemiLepJetCombMVATrainer::leptonType_
private

Definition at line 48 of file TtSemiLepJetCombMVATrainer.h.

Referenced by analyze().

edm::EDGetTokenT< std::vector< std::vector<int> > > TtSemiLepJetCombMVATrainer::matchingToken_
private

Definition at line 44 of file TtSemiLepJetCombMVATrainer.h.

Referenced by analyze().

int TtSemiLepJetCombMVATrainer::maxNJets_
private

Definition at line 46 of file TtSemiLepJetCombMVATrainer.h.

Referenced by analyze().

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

Definition at line 43 of file TtSemiLepJetCombMVATrainer.h.

Referenced by analyze().

PhysicsTools::MVAComputerCache TtSemiLepJetCombMVATrainer::mvaComputer
private

Definition at line 50 of file TtSemiLepJetCombMVATrainer.h.

Referenced by analyze().

unsigned int TtSemiLepJetCombMVATrainer::nEvents[5]
private

Definition at line 52 of file TtSemiLepJetCombMVATrainer.h.

Referenced by analyze(), beginJob(), and endJob().