00001
00002 #include "PhysicsTools/SelectorUtils/interface/WPlusJetsEventSelector.h"
00003 #include "DataFormats/Candidate/interface/ShallowCloneCandidate.h"
00004
00005 #include <iostream>
00006
00007 using namespace std;
00008
00009 WPlusJetsEventSelector::WPlusJetsEventSelector( edm::ParameterSet const & params ) :
00010 EventSelector(),
00011 muonTag_ (params.getParameter<edm::InputTag>("muonSrc") ),
00012 electronTag_ (params.getParameter<edm::InputTag>("electronSrc") ),
00013 jetTag_ (params.getParameter<edm::InputTag>("jetSrc") ),
00014 metTag_ (params.getParameter<edm::InputTag>("metSrc") ),
00015 trigTag_ (params.getParameter<edm::InputTag>("trigSrc") ),
00016 muTrig_ (params.getParameter<std::string>("muTrig")),
00017 eleTrig_ (params.getParameter<std::string>("eleTrig")),
00018 pvSelector_ (params.getParameter<edm::ParameterSet>("pvSelector") ),
00019 muonIdTight_ (params.getParameter<edm::ParameterSet>("muonIdTight") ),
00020 electronIdTight_ (params.getParameter<edm::ParameterSet>("electronIdTight") ),
00021 muonIdLoose_ (params.getParameter<edm::ParameterSet>("muonIdLoose") ),
00022 electronIdLoose_ (params.getParameter<edm::ParameterSet>("electronIdLoose") ),
00023 jetIdLoose_ (params.getParameter<edm::ParameterSet>("jetIdLoose") ),
00024 pfjetIdLoose_ (params.getParameter<edm::ParameterSet>("pfjetIdLoose") ),
00025 minJets_ (params.getParameter<int> ("minJets") ),
00026 muJetDR_ (params.getParameter<double>("muJetDR")),
00027 eleJetDR_ (params.getParameter<double>("eleJetDR")),
00028 muPlusJets_ (params.getParameter<bool>("muPlusJets") ),
00029 ePlusJets_ (params.getParameter<bool>("ePlusJets") ),
00030 muPtMin_ (params.getParameter<double>("muPtMin")),
00031 muEtaMax_ (params.getParameter<double>("muEtaMax")),
00032 eleEtMin_ (params.getParameter<double>("eleEtMin")),
00033 eleEtaMax_ (params.getParameter<double>("eleEtaMax")),
00034 muPtMinLoose_ (params.getParameter<double>("muPtMinLoose")),
00035 muEtaMaxLoose_ (params.getParameter<double>("muEtaMaxLoose")),
00036 eleEtMinLoose_ (params.getParameter<double>("eleEtMinLoose")),
00037 eleEtaMaxLoose_ (params.getParameter<double>("eleEtaMaxLoose")),
00038 jetPtMin_ (params.getParameter<double>("jetPtMin")),
00039 jetEtaMax_ (params.getParameter<double>("jetEtaMax")),
00040 jetScale_ (params.getParameter<double>("jetScale")),
00041 metMin_ (params.getParameter<double>("metMin"))
00042 {
00043
00044 push_back( "Inclusive" );
00045 push_back( "Trigger" );
00046 push_back( "PV" );
00047 push_back( ">= 1 Lepton" );
00048 push_back( "== 1 Tight Lepton" );
00049 push_back( "== 1 Tight Lepton, Mu Veto");
00050 push_back( "== 1 Lepton" );
00051 push_back( "MET Cut" );
00052 push_back( "Z Veto" );
00053 push_back( "Conversion Veto");
00054 push_back( "Cosmic Veto" );
00055 push_back( ">=1 Jets" );
00056 push_back( ">=2 Jets" );
00057 push_back( ">=3 Jets" );
00058 push_back( ">=4 Jets" );
00059 push_back( ">=5 Jets" );
00060
00061
00062
00063 set( "Inclusive" );
00064 set( "Trigger" );
00065 set( "PV" );
00066 set( ">= 1 Lepton" );
00067 set( "== 1 Tight Lepton" );
00068 set( "== 1 Tight Lepton, Mu Veto");
00069 set( "== 1 Lepton" );
00070 set( "MET Cut" );
00071 set( "Z Veto" );
00072 set( "Conversion Veto");
00073 set( "Cosmic Veto" );
00074 set( ">=1 Jets", minJets_ >= 1);
00075 set( ">=2 Jets", minJets_ >= 2);
00076 set( ">=3 Jets", minJets_ >= 3);
00077 set( ">=4 Jets", minJets_ >= 4);
00078 set( ">=5 Jets", minJets_ >= 5);
00079
00080
00081 inclusiveIndex_ = index_type(&bits_, std::string("Inclusive" ));
00082 triggerIndex_ = index_type(&bits_, std::string("Trigger" ));
00083 pvIndex_ = index_type(&bits_, std::string("PV" ));
00084 lep1Index_ = index_type(&bits_, std::string(">= 1 Lepton" ));
00085 lep2Index_ = index_type(&bits_, std::string("== 1 Tight Lepton" ));
00086 lep3Index_ = index_type(&bits_, std::string("== 1 Tight Lepton, Mu Veto"));
00087 lep4Index_ = index_type(&bits_, std::string("== 1 Lepton" ));
00088 metIndex_ = index_type(&bits_, std::string("MET Cut" ));
00089 zvetoIndex_ = index_type(&bits_, std::string("Z Veto" ));
00090 conversionIndex_ = index_type(&bits_, std::string("Conversion Veto"));
00091 cosmicIndex_ = index_type(&bits_, std::string("Cosmic Veto" ));
00092 jet1Index_ = index_type(&bits_, std::string(">=1 Jets"));
00093 jet2Index_ = index_type(&bits_, std::string(">=2 Jets"));
00094 jet3Index_ = index_type(&bits_, std::string(">=3 Jets"));
00095 jet4Index_ = index_type(&bits_, std::string(">=4 Jets"));
00096 jet5Index_ = index_type(&bits_, std::string(">=5 Jets"));
00097
00098 if ( params.exists("cutsToIgnore") )
00099 setIgnoredCuts( params.getParameter<std::vector<std::string> >("cutsToIgnore") );
00100
00101
00102 retInternal_ = getBitTemplate();
00103 }
00104
00105 bool WPlusJetsEventSelector::operator() ( edm::EventBase const & event, pat::strbitset & ret)
00106 {
00107
00108 ret.set(false);
00109
00110 selectedJets_.clear();
00111 cleanedJets_.clear();
00112 selectedMuons_.clear();
00113 selectedElectrons_.clear();
00114 looseMuons_.clear();
00115 looseElectrons_.clear();
00116 selectedMETs_.clear();
00117
00118
00119 passCut( ret, inclusiveIndex_);
00120
00121
00122 bool passTrig = false;
00123 if (!ignoreCut(triggerIndex_) ) {
00124
00125
00126 edm::Handle<pat::TriggerEvent> triggerEvent;
00127 event.getByLabel(trigTag_, triggerEvent);
00128
00129 pat::TriggerEvent const * trig = &*triggerEvent;
00130
00131 if ( trig->wasRun() && trig->wasAccept() ) {
00132
00133 pat::TriggerPath const * muPath = trig->path(muTrig_);
00134
00135 pat::TriggerPath const * elePath = trig->path(eleTrig_);
00136
00137 if ( muPlusJets_ && muPath != 0 && muPath->wasAccept() ) {
00138 passTrig = true;
00139 }
00140
00141 if ( ePlusJets_ && elePath != 0 && elePath->wasAccept() ) {
00142 passTrig = true;
00143 }
00144 }
00145 }
00146
00147
00148
00149
00150 if ( ignoreCut(triggerIndex_) ||
00151 passTrig ) {
00152 passCut(ret, triggerIndex_);
00153
00154
00155 bool passPV = false;
00156
00157 passPV = pvSelector_( event );
00158 if ( ignoreCut(pvIndex_) || passPV ) {
00159 passCut(ret, pvIndex_);
00160
00161 edm::Handle< vector< pat::Electron > > electronHandle;
00162 event.getByLabel (electronTag_, electronHandle);
00163
00164 edm::Handle< vector< pat::Muon > > muonHandle;
00165 event.getByLabel (muonTag_, muonHandle);
00166
00167 edm::Handle< vector< pat::Jet > > jetHandle;
00168
00169 edm::Handle< edm::OwnVector<reco::Candidate> > jetClonesHandle ;
00170
00171 edm::Handle< vector< pat::MET > > metHandle;
00172 event.getByLabel (metTag_, metHandle);
00173
00174 int nElectrons = 0;
00175 for ( std::vector<pat::Electron>::const_iterator electronBegin = electronHandle->begin(),
00176 electronEnd = electronHandle->end(), ielectron = electronBegin;
00177 ielectron != electronEnd; ++ielectron ) {
00178 ++nElectrons;
00179
00180 if ( ielectron->et() > eleEtMin_ && fabs(ielectron->eta()) < eleEtaMax_ &&
00181 electronIdTight_(*ielectron) &&
00182 ielectron->electronID( "eidRobustTight" ) > 0 ) {
00183 selectedElectrons_.push_back( reco::ShallowClonePtrCandidate( edm::Ptr<pat::Electron>( electronHandle, ielectron - electronBegin ) ) );
00184 } else {
00185
00186 if ( ielectron->et() > eleEtMinLoose_ && fabs(ielectron->eta()) < eleEtaMaxLoose_ &&
00187 electronIdLoose_(*ielectron) ) {
00188 looseElectrons_.push_back( reco::ShallowClonePtrCandidate( edm::Ptr<pat::Electron>( electronHandle, ielectron - electronBegin ) ) );
00189 }
00190 }
00191 }
00192
00193
00194 for ( std::vector<pat::Muon>::const_iterator muonBegin = muonHandle->begin(),
00195 muonEnd = muonHandle->end(), imuon = muonBegin;
00196 imuon != muonEnd; ++imuon ) {
00197 if ( !imuon->isGlobalMuon() ) continue;
00198
00199
00200 bool passTight = muonIdTight_(*imuon,event) && imuon->isTrackerMuon() ;
00201 if ( imuon->pt() > muPtMin_ && fabs(imuon->eta()) < muEtaMax_ &&
00202 passTight ) {
00203
00204 selectedMuons_.push_back( reco::ShallowClonePtrCandidate( edm::Ptr<pat::Muon>( muonHandle, imuon - muonBegin ) ) );
00205 } else {
00206
00207 if ( imuon->pt() > muPtMinLoose_ && fabs(imuon->eta()) < muEtaMaxLoose_ &&
00208 muonIdLoose_(*imuon,event) ) {
00209 looseMuons_.push_back( reco::ShallowClonePtrCandidate( edm::Ptr<pat::Muon>( muonHandle, imuon - muonBegin ) ) );
00210 }
00211 }
00212 }
00213
00214
00215 met_ = reco::ShallowClonePtrCandidate( edm::Ptr<pat::MET>( metHandle, 0),
00216 metHandle->at(0).charge(),
00217 metHandle->at(0).p4() );
00218
00219
00220
00221 event.getByLabel (jetTag_, jetHandle);
00222 pat::strbitset ret1 = jetIdLoose_.getBitTemplate();
00223 pat::strbitset ret2 = pfjetIdLoose_.getBitTemplate();
00224 for ( std::vector<pat::Jet>::const_iterator jetBegin = jetHandle->begin(),
00225 jetEnd = jetHandle->end(), ijet = jetBegin;
00226 ijet != jetEnd; ++ijet ) {
00227 reco::ShallowClonePtrCandidate scaledJet ( reco::ShallowClonePtrCandidate( edm::Ptr<pat::Jet>( jetHandle, ijet - jetBegin ),
00228 ijet->charge(),
00229 ijet->p4() * jetScale_ ) );
00230 bool passJetID = false;
00231 if ( ijet->isCaloJet() || ijet->isJPTJet() ) passJetID = jetIdLoose_(*ijet, ret1);
00232 else passJetID = pfjetIdLoose_(*ijet, ret2);
00233 if ( scaledJet.pt() > jetPtMin_ && fabs(scaledJet.eta()) < jetEtaMax_ && passJetID ) {
00234 selectedJets_.push_back( scaledJet );
00235
00236 if ( muPlusJets_ ) {
00237
00238
00239 bool indeltaR = false;
00240 for( std::vector<reco::ShallowClonePtrCandidate>::const_iterator muonBegin = selectedMuons_.begin(),
00241 muonEnd = selectedMuons_.end(), imuon = muonBegin;
00242 imuon != muonEnd; ++imuon ) {
00243 if( reco::deltaR( imuon->eta(), imuon->phi(), scaledJet.eta(), scaledJet.phi() ) < muJetDR_ )
00244 { indeltaR = true; }
00245 }
00246 if( !indeltaR ) {
00247 cleanedJets_.push_back( scaledJet );
00248 }
00249 }
00250 else {
00251
00252 bool indeltaR = false;
00253 for( std::vector<reco::ShallowClonePtrCandidate>::const_iterator electronBegin = selectedElectrons_.begin(),
00254 electronEnd = selectedElectrons_.end(), ielectron = electronBegin;
00255 ielectron != electronEnd; ++ielectron ) {
00256 if( reco::deltaR( ielectron->eta(), ielectron->phi(), scaledJet.eta(), scaledJet.phi() ) < eleJetDR_ )
00257 { indeltaR = true; }
00258 }
00259 if( !indeltaR ) {
00260 cleanedJets_.push_back( scaledJet );
00261 }
00262 }
00263 }
00264 }
00265
00266
00267
00268 int nleptons = 0;
00269 if ( muPlusJets_ )
00270 nleptons += selectedMuons_.size();
00271
00272 if ( ePlusJets_ )
00273 nleptons += selectedElectrons_.size();
00274
00275 if ( ignoreCut(lep1Index_) ||
00276 ( nleptons > 0 ) ){
00277 passCut( ret, lep1Index_);
00278
00279 if ( ignoreCut(lep2Index_) ||
00280 ( nleptons == 1 ) ){
00281 passCut( ret, lep2Index_);
00282
00283 bool oneMuon =
00284 ( selectedMuons_.size() == 1 &&
00285 looseMuons_.size() + selectedElectrons_.size() + looseElectrons_.size() == 0
00286 );
00287 bool oneElectron =
00288 ( selectedElectrons_.size() == 1 &&
00289 selectedMuons_.size() == 0
00290 );
00291
00292 bool oneMuonMuVeto =
00293 ( selectedMuons_.size() == 1 &&
00294 looseMuons_.size() == 0
00295 );
00296
00297
00298 if ( ignoreCut(lep3Index_) ||
00299 ePlusJets_ ||
00300 (muPlusJets_ && oneMuonMuVeto)
00301 ) {
00302 passCut(ret, lep3Index_);
00303
00304 if ( ignoreCut(lep4Index_) ||
00305 ( (muPlusJets_ && oneMuon) ^ (ePlusJets_ && oneElectron ) )
00306 ) {
00307 passCut(ret, lep4Index_);
00308
00309 bool metCut = met_.pt() > metMin_;
00310 if ( ignoreCut(metIndex_) ||
00311 metCut ) {
00312 passCut( ret, metIndex_ );
00313
00314
00315 bool zVeto = true;
00316 if ( selectedMuons_.size() == 2 ) {
00317 }
00318 if ( selectedElectrons_.size() == 2 ) {
00319 }
00320 if ( ignoreCut(zvetoIndex_) ||
00321 zVeto ){
00322 passCut(ret, zvetoIndex_);
00323
00324
00325 bool conversionVeto = true;
00326 if ( ignoreCut(conversionIndex_) ||
00327 conversionVeto ) {
00328 passCut(ret,conversionIndex_);
00329
00330
00331
00332 bool cosmicVeto = true;
00333 if ( ignoreCut(cosmicIndex_) ||
00334 cosmicVeto ) {
00335 passCut(ret,cosmicIndex_);
00336
00337 if ( ignoreCut(jet1Index_) ||
00338 static_cast<int>(cleanedJets_.size()) >= 1 ){
00339 passCut(ret,jet1Index_);
00340 }
00341
00342 if ( ignoreCut(jet2Index_) ||
00343 static_cast<int>(cleanedJets_.size()) >= 2 ){
00344 passCut(ret,jet2Index_);
00345 }
00346
00347 if ( ignoreCut(jet3Index_) ||
00348 static_cast<int>(cleanedJets_.size()) >= 3 ){
00349 passCut(ret,jet3Index_);
00350 }
00351
00352 if ( ignoreCut(jet4Index_) ||
00353 static_cast<int>(cleanedJets_.size()) >= 4 ){
00354 passCut(ret,jet4Index_);
00355 }
00356
00357 if ( ignoreCut(jet5Index_) ||
00358 static_cast<int>(cleanedJets_.size()) >= 5 ){
00359 passCut(ret,jet5Index_);
00360 }
00361
00362
00363
00364 }
00365
00366 }
00367
00368 }
00369
00370 }
00371
00372 }
00373
00374 }
00375
00376 }
00377
00378 }
00379
00380 }
00381
00382 }
00383
00384
00385 setIgnored(ret);
00386
00387 return (bool)ret;
00388 }