CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TtSemiLepSignalSelMVAComputer.cc
Go to the documentation of this file.
2 
5 
7 
12 
14  : muonsToken_(consumes<edm::View<pat::Muon> >(cfg.getParameter<edm::InputTag>("muons"))),
15  jetsToken_(consumes<std::vector<pat::Jet> >(cfg.getParameter<edm::InputTag>("jets"))),
16  METsToken_(consumes<edm::View<pat::MET> >(cfg.getParameter<edm::InputTag>("mets"))),
17  electronsToken_(consumes<edm::View<pat::Electron> >(cfg.getParameter<edm::InputTag>("elecs"))) {
18  produces<double>("DiscSel");
19 }
20 
22 
24  std::unique_ptr<double> pOutDisc(new double);
25 
26  mvaComputer.update<TtSemiLepSignalSelMVARcd>(setup, "ttSemiLepSignalSelMVA");
27 
28  // read name of the last processor in the MVA calibration
29  // (to be used as meta information)
31  setup.get<TtSemiLepSignalSelMVARcd>().get(calibContainer);
32  std::vector<PhysicsTools::Calibration::VarProcessor*> processors =
33  (calibContainer->find("ttSemiLepSignalSelMVA")).getProcessors();
34 
35  //make your preselection! This must!! be the same one as in TraintreeSaver.cc
37  evt.getByToken(METsToken_, MET_handle);
38  if (!MET_handle.isValid())
39  return;
40  const edm::View<pat::MET> MET = *MET_handle;
41 
43  evt.getByToken(jetsToken_, jet_handle);
44  if (!jet_handle.isValid())
45  return;
46  const std::vector<pat::Jet> jets = *jet_handle;
47  unsigned int nJets = 0;
48  std::vector<pat::Jet> seljets;
49  for (std::vector<pat::Jet>::const_iterator it = jets.begin(); it != jets.end(); it++) {
51  continue;
52  if (it->pt() > 30. && fabs(it->eta()) < 2.4) {
53  seljets.push_back(*it);
54  nJets++;
55  }
56  }
57 
59  evt.getByToken(muonsToken_, muon_handle);
60  if (!muon_handle.isValid())
61  return;
62  const edm::View<pat::Muon> muons = *muon_handle;
63  int nmuons = 0;
64  std::vector<pat::Muon> selMuons;
65  for (edm::View<pat::Muon>::const_iterator it = muons.begin(); it != muons.end(); it++) {
66  reco::TrackRef gltr = it->track(); // global track
67  reco::TrackRef trtr = it->innerTrack(); // tracker track
68  if (it->pt() > 30 && fabs(it->eta()) < 2.1 && (it->pt() / (it->pt() + it->trackIso() + it->caloIso())) > 0.95 &&
69  it->isGlobalMuon()) {
70  if (gltr.isNull())
71  continue; //temporary problems with dead trackrefs
72  if ((gltr->chi2() / gltr->ndof()) < 10 && trtr->numberOfValidHits() > 11) {
73  double dRmin = 9999.;
74  for (std::vector<pat::Jet>::const_iterator ajet = seljets.begin(); ajet != seljets.end(); ajet++) {
75  math::XYZTLorentzVector jet = ajet->p4();
76  math::XYZTLorentzVector muon = it->p4();
77  double tmpdR = DeltaR(muon, jet);
78  if (tmpdR < dRmin)
79  dRmin = tmpdR;
80  }
81  if (dRmin > 0.3) { //temporary problems with muon isolation
82  nmuons++;
83  selMuons.push_back(*it);
84  }
85  }
86  }
87  }
88 
89  edm::Handle<edm::View<pat::Electron> > electron_handle;
90  evt.getByToken(electronsToken_, electron_handle);
91  if (!electron_handle.isValid())
92  return;
93  const edm::View<pat::Electron> electrons = *electron_handle;
94  int nelectrons = 0;
95  for (edm::View<pat::Electron>::const_iterator it = electrons.begin(); it != electrons.end(); it++) {
96  if (it->pt() > 30 && fabs(it->eta()) < 2.4 && (it->pt() / (it->pt() + it->trackIso() + it->caloIso())) > 0.95 &&
97  it->isElectronIDAvailable("eidTight")) {
98  if (it->electronID("eidTight") == 1)
99  nelectrons++;
100  }
101  }
102 
103  double discrim;
104  // discriminator output for events which do not pass the preselection is set to -1
105  if (nmuons != 1 || nJets < 4 || nelectrons > 0)
106  discrim = -1.; //std::cout<<"nJets: "<<seljets.size()<<" numLeptons: "<<nleptons<<std::endl;}
107  else {
108  //check wheter a event was already selected (problem with duplicated events)
109  math::XYZTLorentzVector muon = selMuons.begin()->p4();
110 
111  TtSemiLepSignalSel selection(seljets, muon, MET);
112 
113  discrim = evaluateTtSemiLepSignalSel(mvaComputer, selection);
114  }
115 
116  *pOutDisc = discrim;
117 
118  evt.put(std::move(pOutDisc), "DiscSel");
119 
120  DiscSel = discrim;
121 }
122 
124 
126 
128  double dPhi = fabs(v1.Phi() - v2.Phi());
129  if (dPhi > TMath::Pi())
130  dPhi = 2 * TMath::Pi() - dPhi;
131  return dPhi;
132 }
133 
135  double dPhi = DeltaPhi(v1, v2);
136  double dR = TMath::Sqrt((v1.Eta() - v2.Eta()) * (v1.Eta() - v2.Eta()) + dPhi * dPhi);
137  return dR;
138 }
139 
140 // implement the plugins for the computer container
141 // -> register TtSemiLepSignalSelMVARcd
142 // -> define TtSemiLepSignalSelMVAFileSource
143 MVA_COMPUTER_CONTAINER_IMPLEMENT(TtSemiLepSignalSelMVA);
const double Pi
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
double DeltaPhi(const math::XYZTLorentzVector &v1, const math::XYZTLorentzVector &v2)
static bool test(uint32_t val, uint32_t mask)
Definition: Flags.h:28
edm::EDGetTokenT< edm::View< pat::Electron > > electronsToken_
selection
main part
Definition: corrVsCorr.py:100
#define MVA_COMPUTER_CONTAINER_IMPLEMENT(N)
Definition: HelperMacros.h:53
PhysicsTools::MVAComputerCache mvaComputer
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
Definition: HeavyIon.h:7
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
const_iterator begin() const
edm::EDGetTokenT< edm::View< pat::Muon > > muonsToken_
Definition: Muon.py:1
Definition: Jet.py:1
double evaluateTtSemiLepSignalSel(PhysicsTools::MVAComputerCache &mvaComputer, const TtSemiLepSignalSel &sigsel, float weight=1., const bool isSignal=false)
double DeltaR(const math::XYZTLorentzVector &v1, const math::XYZTLorentzVector &v2)
bool isValid() const
Definition: HandleBase.h:70
bool isNull() const
Checks for null.
Definition: Ref.h:235
edm::EDGetTokenT< edm::View< pat::MET > > METsToken_
bool update(const Calibration::MVAComputer *computer)
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
TtSemiLepSignalSelMVAComputer(const edm::ParameterSet &)
const_iterator end() const
void produce(edm::Event &evt, const edm::EventSetup &setup) override
def move(src, dest)
Definition: eostools.py:511