CMS 3D CMS Logo

BTagSkimLeptonJet.cc
Go to the documentation of this file.
1 
9 #include <cmath>
10 
14 
18 
19 //#include "DataFormats/EgammaCandidates/interface/PixelMatchGsfElectron.h"
20 //#include "DataFormats/EgammaCandidates/interface/PixelMatchGsfElectronFwd.h"
23 
25 
26 #include "TVector3.h"
27 #include "Math/GenVector/VectorUtil.h"
28 #include "Math/GenVector/PxPyPzE4D.h"
29 
30 using namespace edm;
31 using namespace std;
32 using namespace reco;
33 
34 
36  nEvents_(0), nAccepted_(0)
37 {
38  CaloJetInput_ = iConfig.getParameter<InputTag>( "CaloJet" );
39  MinCaloJetPt_ = iConfig.getParameter<double>( "MinimumCaloJetPt" );
40  MaxCaloJetEta_ = iConfig.getParameter<double>( "MaximumCaloJetEta" );
41 
42  LeptonType_ = iConfig.getParameter<std::string>("LeptonType");
43  if ( LeptonType_ != "electron" && LeptonType_ != "muon" )
44  edm::LogError( "BTagSkimLeptonJet" )
45  << "unknown lepton type !!";
46  LeptonInput_ = iConfig.getParameter<InputTag>( "Lepton" );
47  MinLeptonPt_ = iConfig.getParameter<double>( "MinimumLeptonPt" );
48  MaxLeptonEta_ = iConfig.getParameter<double>( "MaximumLeptonEta" );
49  //MinNLepton_ = iConfig.getParameter<int>( "MinimumNLepton" );
50 
51  MaxDeltaR_ = iConfig.getParameter<double>( "MaximumDeltaR" );
52 
53  MinPtRel_ = iConfig.getParameter<double>("MinimumPtRel" );
54 
55  MinNLeptonJet_ = iConfig.getParameter<int>( "MinimumNLeptonJet" );
56  if ( MinNLeptonJet_ < 1 )
57  edm::LogError( "BTagSkimLeptonJet" )
58  << "MinimunNCaloJet < 1 !!";
59 }
60 
61 /*------------------------------------------------------------------------*/
62 
64 {}
65 
66 /*------------------------------------------------------------------------*/
67 
69  const edm::EventSetup& iSetup )
70 {
71  nEvents_++;
72 
73  Handle<CaloJetCollection> CaloJetsHandle;
74  //try {
75  iEvent.getByLabel( CaloJetInput_, CaloJetsHandle );
76  //}
77  //catch ( cms::Exception& ex ) {
78  //edm::LogError( "BTagSkimLeptonJet" )
79  // << "Unable to get CaloJet collection "
80  // << CaloJetInput_.label();
81  //return false;
82  //}
83  if ( CaloJetsHandle->empty() ) return false;
84  CaloJetCollection TheCaloJets = *CaloJetsHandle;
85  std::stable_sort( TheCaloJets.begin(), TheCaloJets.end(), PtSorter() );
86 
87  //int nLepton = 0;
88 
89  Handle<MuonCollection> MuonHandle;
90  MuonCollection TheMuons;
91  if (LeptonType_ == "muon") {
92  //try{
93  iEvent.getByLabel( LeptonInput_, MuonHandle );
94  // }
95  // catch ( cms::Exception& ex ) {
96  //edm::LogError( "BTagSkimLeptonJet" )
97  // << "Unable to get muon collection "
98  // << LeptonInput_.label();
99  //return false;
100  //}
101  TheMuons = *MuonHandle;
102  std::stable_sort( TheMuons.begin(), TheMuons.end(), PtSorter() );
103  }
104 
105  Handle<GsfElectronCollection> ElectronHandle;
106  GsfElectronCollection TheElectrons;
107  if (LeptonType_ == "electron") {
108  //try{
109  iEvent.getByLabel( LeptonInput_, ElectronHandle );
110  // }
111  // catch ( cms::Exception& ex ) {
112  // edm::LogError( "BTagSkimLeptonJet" )
113  // << "Unable to get electron collection "
114  // << LeptonInput_.label();
115  // return false;
116  // }
117  TheElectrons = *ElectronHandle;
118  std::stable_sort( TheElectrons.begin(), TheElectrons.end(), PtSorter() );
119  }
120 
121  // Jet cuts
122  int nJet = 0;
123  for ( CaloJetCollection::const_iterator ajet = TheCaloJets.begin(); ajet != TheCaloJets.end(); ++ajet ) {
124 
125  if ( (fabs(ajet->eta()) < MaxCaloJetEta_) && (ajet->pt() > MinCaloJetPt_) ) {
126 
127  if (LeptonType_ == "muon" ) {
128  for ( MuonCollection::const_iterator amuon = TheMuons.begin(); amuon != TheMuons.end(); ++amuon ) {
129  // select good muon
130  if ( (amuon->pt() > MinLeptonPt_) && (fabs(amuon->eta()) < MaxLeptonEta_) ) {
131 
132  double deltar = ROOT::Math::VectorUtil::DeltaR(ajet->p4().Vect(),
133  amuon->momentum() );
134 
135  TVector3 jetvec(ajet->p4().Vect().X(),
136  ajet->p4().Vect().Y(),
137  ajet->p4().Vect().Z() );
138  TVector3 muvec( amuon->momentum().X(),
139  amuon->momentum().Y(),
140  amuon->momentum().Z() );
141  jetvec += muvec;
142  double ptrel = muvec.Perp(jetvec);
143 
144  if ( ( deltar < MaxDeltaR_ ) && (ptrel > MinPtRel_) ) nJet++;
145  if ( nJet >= MinNLeptonJet_ ) break;
146  }
147  }
148  }
149 
150  if (LeptonType_ == "electron") {
151  for ( GsfElectronCollection::const_iterator anelectron = TheElectrons.begin(); anelectron != TheElectrons.end(); anelectron++ ) {
152  if ( (anelectron->pt() > MinLeptonPt_) && (fabs(anelectron->eta()) < MaxLeptonEta_ ) ) {
153 
154  double deltar = ROOT::Math::VectorUtil::DeltaR(ajet->p4().Vect(),
155  anelectron->momentum() );
156 
157  TVector3 jetvec(ajet->p4().Vect().X(),
158  ajet->p4().Vect().Y(),
159  ajet->p4().Vect().Z() );
160  TVector3 evec( anelectron->momentum().X(),
161  anelectron->momentum().Y(),
162  anelectron->momentum().Z() );
163  jetvec += evec;
164  double ptrel = evec.Perp(jetvec);
165 
166  if ( ( deltar < MaxDeltaR_ ) && (ptrel > MinPtRel_) ) nJet++;
167  if ( nJet >= MinNLeptonJet_ ) break;
168  }
169  }
170  }
171 
172  }// close jet selection
173  }
174 
175  if ( nJet < MinNLeptonJet_ ) return false;
176 
177  nAccepted_++;
178 
179  return true;
180 }
181 
182 /*------------------------------------------------------------------------*/
183 
185 {
186  edm::LogVerbatim( "BTagSkimLeptonJet" )
187  << "=============================================================================\n"
188  << " Events read: " << nEvents_
189  << "\n Events accepted by (" << LeptonType_ << ") BTagSkimLeptonJet: " << nAccepted_
190  << "\n Efficiency: " << (double)(nAccepted_)/(double)(nEvents_)
191  << "\n==========================================================================="
192  << endl;
193 }
194 
195 //define this as a plug-in
T getParameter(std::string const &) const
~BTagSkimLeptonJet() override
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::string LeptonType_
BTagSkimLeptonJet(const edm::ParameterSet &)
void endJob() override
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
edm::InputTag LeptonInput_
Definition: deltar.py:1
unsigned int nAccepted_
fixed size matrix
HLT enums.
bool filter(edm::Event &, const edm::EventSetup &) override
edm::InputTag CaloJetInput_
unsigned int nEvents_
std::vector< CaloJet > CaloJetCollection
collection of CaloJet objects