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 
11 
16 
17 
19  muons_ (cfg.getParameter<edm::InputTag>("muons")),
20  jets_ (cfg.getParameter<edm::InputTag>("jets")),
21  METs_ (cfg.getParameter<edm::InputTag>("mets")),
22  electrons_ (cfg.getParameter<edm::InputTag>("elecs"))
23 {
24  produces< double >("DiscSel");
25 }
26 
27 
28 
30 {
31 }
32 
33 void
35 {
36  std::auto_ptr< double > pOutDisc (new double);
37 
38  mvaComputer.update<TtSemiLepSignalSelMVARcd>(setup, "ttSemiLepSignalSelMVA");
39 
40  // read name of the last processor in the MVA calibration
41  // (to be used as meta information)
43  setup.get<TtSemiLepSignalSelMVARcd>().get( calibContainer );
44  std::vector<PhysicsTools::Calibration::VarProcessor*> processors
45  = (calibContainer->find("ttSemiLepSignalSelMVA")).getProcessors();
46 
47  //make your preselection! This must!! be the same one as in TraintreeSaver.cc
49  evt.getByLabel(METs_,MET_handle);
50  if(!MET_handle.isValid()) return;
51  const edm::View<pat::MET> MET = *MET_handle;
52 
54  evt.getByLabel(jets_, jet_handle);
55  if(!jet_handle.isValid()) return;
56  const std::vector<pat::Jet> jets = *jet_handle;
57  unsigned int nJets = 0;
58  std::vector<pat::Jet> seljets;
59  for(std::vector<pat::Jet>::const_iterator it = jets.begin(); it != jets.end(); it++) {
61  if(it->pt()>30. && fabs(it->eta())<2.4) {
62  seljets.push_back(*it);
63  nJets++;
64  }
65  }
66 
67  edm::Handle< edm::View<pat::Muon> > muon_handle;
68  evt.getByLabel(muons_, muon_handle);
69  if(!muon_handle.isValid()) return;
70  const edm::View<pat::Muon> muons = *muon_handle;
71  int nmuons = 0;
72  std::vector<pat::Muon> selMuons;
73  for(edm::View<pat::Muon>::const_iterator it = muons.begin(); it!=muons.end(); it++) {
74  reco::TrackRef gltr = it->track(); // global track
75  reco::TrackRef trtr = it->innerTrack(); // tracker track
76  if(it->pt()>30 && fabs(it->eta())<2.1 && (it->pt()/(it->pt()+it->trackIso()+it->caloIso()))>0.95 && it->isGlobalMuon()){
77  if(gltr.isNull()) continue; //temporary problems with dead trackrefs
78  if((gltr->chi2()/gltr->ndof())<10 && trtr->numberOfValidHits()>11) {
79  double dRmin = 9999.;
80  for(std::vector<pat::Jet>::const_iterator ajet = seljets.begin(); ajet != seljets.end(); ajet++) {
81  math::XYZTLorentzVector jet = ajet->p4();
82  math::XYZTLorentzVector muon = it->p4();
83  double tmpdR = DeltaR(muon,jet);
84  if(tmpdR<dRmin) dRmin = tmpdR;
85  }
86  if(dRmin>0.3) { //temporary problems with muon isolation
87  nmuons++;
88  selMuons.push_back(*it);
89  }
90  }
91  }
92  }
93 
94  edm::Handle< edm::View<pat::Electron> > electron_handle;
95  evt.getByLabel(electrons_, electron_handle);
96  if(!electron_handle.isValid()) return;
97  const edm::View<pat::Electron> electrons = *electron_handle;
98  int nelectrons = 0;
99  for(edm::View<pat::Electron>::const_iterator it = electrons.begin(); it!=electrons.end(); it++) {
100  if(it->pt()>30 && fabs(it->eta())<2.4 && (it->pt()/(it->pt()+it->trackIso()+it->caloIso()))>0.95 && it->isElectronIDAvailable("eidTight"))
101  {
102  if(it->electronID("eidTight")==1) nelectrons++;
103  }
104  }
105 
106 
107  double discrim;
108  // discriminator output for events which do not pass the preselection is set to -1
109  if( nmuons!=1 ||
110  nJets < 4 ||
111  nelectrons > 0 ) discrim = -1.; //std::cout<<"nJets: "<<seljets.size()<<" numLeptons: "<<nleptons<<std::endl;}
112  else {
113  //check wheter a event was already selected (problem with duplicated events)
114  math::XYZTLorentzVector muon = selMuons.begin()->p4();
115 
116  TtSemiLepSignalSel selection(seljets,muon,MET);
117 
118  discrim = evaluateTtSemiLepSignalSel(mvaComputer, selection);
119  }
120 
121  *pOutDisc = discrim;
122 
123  evt.put(pOutDisc, "DiscSel");
124 
125  DiscSel = discrim;
126 
127 }
128 
129 void
131 {
132 }
133 
134 void
136 {
137 }
138 
140 {
141  double dPhi = fabs(v1.Phi() - v2.Phi());
142  if (dPhi > TMath::Pi()) dPhi = 2*TMath::Pi() - dPhi;
143  return dPhi;
144 }
145 
147 {
148  double dPhi = DeltaPhi(v1,v2);
149  double dR = TMath::Sqrt((v1.Eta()-v2.Eta())*(v1.Eta()-v2.Eta())+dPhi*dPhi);
150  return dR;
151 }
152 
153 // implement the plugins for the computer container
154 // -> register TtSemiLepSignalSelMVARcd
155 // -> define TtSemiLepSignalSelMVAFileSource
156 MVA_COMPUTER_CONTAINER_IMPLEMENT(TtSemiLepSignalSelMVA);
const double Pi
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
double evaluateTtSemiLepSignalSel(PhysicsTools::MVAComputerCache &mvaComputer, const TtSemiLepSignalSel &sigsel, float weight=1., const bool training=false, const bool isSignal=false)
double DeltaPhi(const math::XYZTLorentzVector &v1, const math::XYZTLorentzVector &v2)
static bool test(uint32_t val, uint32_t mask)
Definition: Flags.h:30
selection
main part
Definition: corrVsCorr.py:98
PhysicsTools::MVAComputerCache mvaComputer
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
bool isNull() const
Checks for null.
Definition: Ref.h:247
double dPhi(double phi1, double phi2)
Definition: JetUtil.h:30
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
vector< PseudoJet > jets
double DeltaR(const math::XYZTLorentzVector &v1, const math::XYZTLorentzVector &v2)
virtual void produce(edm::Event &evt, const edm::EventSetup &setup)
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
bool update(const Calibration::MVAComputer *computer)
#define MVA_COMPUTER_CONTAINER_IMPLEMENT(N)
Definition: HelperMacros.h:46
tuple muons
Definition: patZpeak.py:38
TtSemiLepSignalSelMVAComputer(const edm::ParameterSet &)
const_iterator begin() const
const_iterator end() const
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")