Skip to content

Commit

Permalink
boosted cleaning fix for 74x
Browse files Browse the repository at this point in the history
  • Loading branch information
drankincms committed Jul 2, 2015
1 parent 2269744 commit 658e783
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 122 deletions.
Expand Up @@ -51,7 +51,7 @@ template <typename jetType> class HLTJetCollectionsForBoostedLeptonPlusJets: pub
edm::InputTag hltLeptonTag;
edm::InputTag sourceJetTag;

double minDeltaR_; //min dR for jets and leptons not to match
double minDeltaR_; //min dR to consider cleaning

// ----------member data ---------------------------
};
Expand Down
239 changes: 118 additions & 121 deletions HLTrigger/JetMET/src/HLTJetCollectionsForBoostedLeptonPlusJets.cc
Expand Up @@ -12,11 +12,11 @@
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/EgammaReco/interface/SuperCluster.h"
#include "DataFormats/Math/interface/deltaR.h"
#include "DataFormats/Math/interface/LorentzVector.h"
#include "DataFormats/JetReco/interface/PFJet.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
#include "HLTrigger/JetMET/interface/HLTJetCollectionsForBoostedLeptonPlusJets.h"
#include "HLTrigger/HLTcore/interface/defaultModuleLabel.h"
#include "CommonTools/Utils/interface/PtComparator.h"



Expand All @@ -29,10 +29,12 @@ HLTJetCollectionsForBoostedLeptonPlusJets<jetType>::HLTJetCollectionsForBoostedL
{
using namespace edm;
using namespace std;
typedef vector<RefVector<vector<jetType>,jetType,refhelper::FindUsingAdvance<vector<jetType>,jetType> > > JetCollectionVector;

typedef vector<jetType> JetCollection;

m_theLeptonToken = consumes<trigger::TriggerFilterObjectWithRefs>(hltLeptonTag);
m_theJetToken = consumes<std::vector<jetType>>(sourceJetTag);
produces<JetCollectionVector> ();
produces<JetCollection>();
}

template <typename jetType>
Expand All @@ -46,13 +48,13 @@ HLTJetCollectionsForBoostedLeptonPlusJets<jetType>::~HLTJetCollectionsForBoosted
template <typename jetType>
void
HLTJetCollectionsForBoostedLeptonPlusJets<jetType>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag> ("HltLeptonTag", edm::InputTag("triggerFilterObjectWithRefs"));
//(2)
desc.add<edm::InputTag> ("SourceJetTag", edm::InputTag("jetCollection"));
//(2)
desc.add<double> ("minDeltaR", 0.5);
descriptions.add(defaultModuleLabel<HLTJetCollectionsForBoostedLeptonPlusJets<jetType>>(), desc);
edm::ParameterSetDescription desc;
desc.add<edm::InputTag> ("HltLeptonTag", edm::InputTag("triggerFilterObjectWithRefs"));
//(2)
desc.add<edm::InputTag> ("SourceJetTag", edm::InputTag("jetCollection"));
//(2)
desc.add<double> ("minDeltaR", 0.5);
descriptions.add(defaultModuleLabel<HLTJetCollectionsForBoostedLeptonPlusJets<jetType>>(), desc);
}

//
Expand All @@ -71,142 +73,137 @@ HLTJetCollectionsForBoostedLeptonPlusJets<jetType>::produce(edm::Event& iEvent,
//(3)
using namespace reco;
//(3)

typedef vector<RefVector<vector<jetType>,jetType,refhelper::FindUsingAdvance<vector<jetType>,jetType> > > JetCollectionVector;
typedef vector<jetType> JetCollection;
typedef edm::RefVector<JetCollection> JetRefVector;
typedef edm::Ref<JetCollection> JetRef;
//(4)
typedef math::XYZTLorentzVector LorentzVector;
//(4)

Handle<trigger::TriggerFilterObjectWithRefs> PrevFilterOutput;
iEvent.getByToken(m_theLeptonToken,PrevFilterOutput);

//its easier on the if statement flow if I try everything at once, shouldnt add to timing
// Electrons can be stored as objects of types TriggerCluster, TriggerElectron, or TriggerPhoton
vector<Ref<reco::RecoEcalCandidateCollection> > clusCands;
PrevFilterOutput->getObjects(trigger::TriggerCluster,clusCands);
vector<reco::RecoChargedCandidateRef> muonCands;
PrevFilterOutput->getObjects(trigger::TriggerMuon,muonCands);

vector<Ref<reco::ElectronCollection> > eleCands;
PrevFilterOutput->getObjects(trigger::TriggerElectron,eleCands);

trigger::VRphoton photonCands;
PrevFilterOutput->getObjects(trigger::TriggerPhoton, photonCands);

vector<reco::RecoChargedCandidateRef> muonCands;
PrevFilterOutput->getObjects(trigger::TriggerMuon,muonCands);
vector<Ref<reco::RecoEcalCandidateCollection> > clusCands;
PrevFilterOutput->getObjects(trigger::TriggerCluster,clusCands);

Handle<JetCollection> theJetCollectionHandle;
iEvent.getByToken(m_theJetToken, theJetCollectionHandle);

const JetCollection & theJetCollection = *theJetCollectionHandle;
typename JetCollection::const_iterator jet;

auto_ptr < JetCollectionVector > allSelections(new JetCollectionVector());

if(!clusCands.empty()){ // try trigger clusters
for(size_t candNr=0;candNr<clusCands.size();candNr++){
JetRefVector refVector;
for (unsigned int j = 0; j < theJetCollection.size(); j++) {
if (deltaR(clusCands[candNr]->superCluster()->position(),theJetCollection[j]) > minDeltaR_) refVector.push_back(JetRef(theJetCollectionHandle, j));
else{
unsigned int w =0 ;
std::vector<reco::PFCandidatePtr> pfConstituents = theJetCollection[j].getPFConstituents();
for(std::vector<reco::PFCandidatePtr>::const_iterator i_candidate = pfConstituents.begin(); i_candidate != pfConstituents.end(); ++i_candidate){
TVector3 ClusP(clusCands[candNr]->p4().Px(),clusCands[candNr]->p4().Py(), clusCands[candNr]->p4().Pz());
TVector3 PFJetConstP((*i_candidate)->px(),(*i_candidate)->py(),(*i_candidate)->pz());
double deltaRPFConste = ClusP.DeltaR(PFJetConstP);
if(deltaRPFConste < 0.001 && w==0){
const_cast<LorentzVector&>(theJetCollection[j].p4()) = theJetCollection[j].p4() - clusCands[candNr]->p4();
w ++;
} //if
auto_ptr < JetCollection > allSelections(new JetCollection);

std::vector<size_t> usedCands;

std::cout<<"----------------NEW EVENT----------------\n";
if(!muonCands.empty()){ // muons
for (jet = theJetCollectionHandle->begin(); jet != theJetCollectionHandle->end(); jet++) {
//const jetType* referenceJet = &*jet;
jetType cleanedJet = *jet; //copy original jet
if (cleanedJet.pt()>30) std::cout<<"Jet: pt = "<<cleanedJet.pt()<<" eta = "<<cleanedJet.eta()<<" eta = "<<cleanedJet.phi()<<std::endl;
for(size_t candNr=0;candNr<muonCands.size();candNr++){
if (std::find(usedCands.begin(),usedCands.end(),candNr)!=usedCands.end()) continue;
std::cout<<"Muon: pt = "<<muonCands[candNr]->pt()<<" eta = "<<muonCands[candNr]->eta()<<" eta = "<<muonCands[candNr]->phi()<<std::endl;
if (deltaR((*muonCands[candNr]),cleanedJet) <= minDeltaR_) {
std::vector<edm::Ptr<reco::PFCandidate> > pfConstituents = cleanedJet.getPFConstituents();
for(std::vector<edm::Ptr<reco::PFCandidate> >::const_iterator i_candidate = pfConstituents.begin(); i_candidate != pfConstituents.end(); ++i_candidate){
if (deltaR((*muonCands[candNr]),(**i_candidate))<0.001) {
std::cout<<"CLEANED"<<std::endl;
cleanedJet.setP4( cleanedJet.p4() - muonCands[candNr]->p4());
usedCands.push_back(candNr);
break;
}//if constituent matched
}//for constituents
refVector.push_back(JetRef(theJetCollectionHandle, j));
}//else
}
allSelections->push_back(refVector);
}
}

if(!eleCands.empty()){ // try electrons
for(size_t candNr=0;candNr<eleCands.size();candNr++){
JetRefVector refVector;
for (unsigned int j = 0; j < theJetCollection.size(); j++) {
if (deltaR(eleCands[candNr]->superCluster()->position(),theJetCollection[j]) > minDeltaR_) refVector.push_back(JetRef(theJetCollectionHandle, j));
else{
unsigned int w =0 ;
std::vector<reco::PFCandidatePtr> pfConstituents = theJetCollection[j].getPFConstituents();
for(std::vector<reco::PFCandidatePtr>::const_iterator i_candidate = pfConstituents.begin(); i_candidate != pfConstituents.end(); ++i_candidate){
TVector3 ElectronP(eleCands[candNr]->p4().Px(),eleCands[candNr]->p4().Py(), eleCands[candNr]->p4().Pz());
TVector3 PFJetConstP((*i_candidate)->px(),(*i_candidate)->py(),(*i_candidate)->pz());
double deltaRPFConste = ElectronP.DeltaR(PFJetConstP);
if(deltaRPFConste < 0.001 && w==0){
const_cast<LorentzVector&>(theJetCollection[j].p4()) = theJetCollection[j].p4() - eleCands[candNr]->p4();
w ++;
} //if
}//if dR<min
}//for cands
allSelections->push_back(cleanedJet);
}//for jets
}//if cands

if(!eleCands.empty()){ // electrons
for (jet = theJetCollectionHandle->begin(); jet != theJetCollectionHandle->end(); jet++) {
//const jetType* referenceJet = &*jet;
jetType cleanedJet = *jet; //copy original jet
if (cleanedJet.pt()>30) std::cout<<"Jet: pt = "<<cleanedJet.pt()<<" eta = "<<cleanedJet.eta()<<" eta = "<<cleanedJet.phi()<<std::endl;
for(size_t candNr=0;candNr<eleCands.size();candNr++){
if (std::find(usedCands.begin(),usedCands.end(),candNr)!=usedCands.end()) continue;
std::cout<<"Electron: pt = "<<eleCands[candNr]->pt()<<" eta = "<<eleCands[candNr]->eta()<<" eta = "<<eleCands[candNr]->phi()<<std::endl;
if (deltaR((*eleCands[candNr]),cleanedJet) <= minDeltaR_) {
std::vector<edm::Ptr<reco::PFCandidate> > pfConstituents = cleanedJet.getPFConstituents();
for(std::vector<edm::Ptr<reco::PFCandidate> >::const_iterator i_candidate = pfConstituents.begin(); i_candidate != pfConstituents.end(); ++i_candidate){
if (deltaR((*eleCands[candNr]),(**i_candidate))<0.001) {
std::cout<<"CLEANED"<<std::endl;
cleanedJet.setP4( cleanedJet.p4() - eleCands[candNr]->p4());
usedCands.push_back(candNr);
break;
}//if constituent matched
}//for constituents
refVector.push_back(JetRef(theJetCollectionHandle, j));
}//else
}//for jet collection

allSelections->push_back(refVector);
}
}

if(!photonCands.empty()){ // try photons
for(size_t candNr=0;candNr<photonCands.size();candNr++){
JetRefVector refVector;
for (unsigned int j = 0; j < theJetCollection.size(); j++) {
if (deltaR(photonCands[candNr]->superCluster()->position(),theJetCollection[j]) > minDeltaR_) refVector.push_back(JetRef(theJetCollectionHandle, j));
else{
unsigned int w =0 ;
std::vector<reco::PFCandidatePtr> pfConstituents = theJetCollection[j].getPFConstituents();
for(std::vector<reco::PFCandidatePtr>::const_iterator i_candidate = pfConstituents.begin(); i_candidate != pfConstituents.end(); ++i_candidate){
TVector3 PhotonP(photonCands[candNr]->p4().Px(),photonCands[candNr]->p4().Py(), photonCands[candNr]->p4().Pz());
TVector3 PFJetConstP((*i_candidate)->px(),(*i_candidate)->py(),(*i_candidate)->pz());
double deltaRPFConste = PhotonP.DeltaR(PFJetConstP);
if(deltaRPFConste < 0.001 && w==0){
const_cast<LorentzVector&>(theJetCollection[j].p4()) = theJetCollection[j].p4() - photonCands[candNr]->p4();
w ++;
} //if
}//if dR<min
}//for cands
allSelections->push_back(cleanedJet);
}//for jets
}//if cands

if(!photonCands.empty()){ // photons
for (jet = theJetCollectionHandle->begin(); jet != theJetCollectionHandle->end(); jet++) {
//const jetType* referenceJet = &*jet;
jetType cleanedJet = *jet; //copy original jet
if (cleanedJet.pt()>30) std::cout<<"Jet: pt = "<<cleanedJet.pt()<<" eta = "<<cleanedJet.eta()<<" eta = "<<cleanedJet.phi()<<std::endl;
for(size_t candNr=0;candNr<photonCands.size();candNr++){
if (std::find(usedCands.begin(),usedCands.end(),candNr)!=usedCands.end()) continue;
std::cout<<"Photon: pt = "<<photonCands[candNr]->pt()<<" eta = "<<photonCands[candNr]->eta()<<" eta = "<<photonCands[candNr]->phi()<<std::endl;
if (deltaR((*photonCands[candNr]),cleanedJet) <= minDeltaR_) {
std::vector<edm::Ptr<reco::PFCandidate> > pfConstituents = cleanedJet.getPFConstituents();
for(std::vector<edm::Ptr<reco::PFCandidate> >::const_iterator i_candidate = pfConstituents.begin(); i_candidate != pfConstituents.end(); ++i_candidate){
if (deltaR((*photonCands[candNr]),(**i_candidate))<0.001) {
std::cout<<"CLEANED"<<std::endl;
cleanedJet.setP4( cleanedJet.p4() - photonCands[candNr]->p4());
usedCands.push_back(candNr);
break;
}//if constituent matched
}//for constituents
refVector.push_back(JetRef(theJetCollectionHandle, j));
}//else
}//for jet collection
allSelections->push_back(refVector);
}
}

if(!muonCands.empty()){ // muons
for(size_t candNr=0;candNr<muonCands.size();candNr++){
JetRefVector refVector;
for (unsigned int j = 0; j < theJetCollection.size(); j++) {
if (deltaR(muonCands[candNr]->p4(),theJetCollection[j]) > minDeltaR_) refVector.push_back(JetRef(theJetCollectionHandle, j));
else{
unsigned int w =0 ;
std::vector<reco::PFCandidatePtr> pfConstituents = theJetCollection[j].getPFConstituents();
for(std::vector<reco::PFCandidatePtr>::const_iterator i_candidate = pfConstituents.begin(); i_candidate != pfConstituents.end(); ++i_candidate){
TVector3 MuP(muonCands[candNr]->p4().Px(),muonCands[candNr]->p4().Py(), muonCands[candNr]->p4().Pz());
TVector3 PFJetConstP((*i_candidate)->px(),(*i_candidate)->py(),(*i_candidate)->pz());
double deltaRPFConste = MuP.DeltaR(PFJetConstP);
if(deltaRPFConste < 0.001 && w==0){
const_cast<LorentzVector&>(theJetCollection[j].p4()) = theJetCollection[j].p4() - muonCands[candNr]->p4();
w ++;
} //if
}//if dR<min
}//for cands
allSelections->push_back(cleanedJet);
}//for jets
}//if cands

if(!clusCands.empty()){ // trigger clusters
for (jet = theJetCollectionHandle->begin(); jet != theJetCollectionHandle->end(); jet++) {
//const jetType* referenceJet = &*jet;
jetType cleanedJet = *jet; //copy original jet
if (cleanedJet.pt()>30) std::cout<<"Jet: pt = "<<cleanedJet.pt()<<" eta = "<<cleanedJet.eta()<<" eta = "<<cleanedJet.phi()<<std::endl;
for(size_t candNr=0;candNr<clusCands.size();candNr++){
if (std::find(usedCands.begin(),usedCands.end(),candNr)!=usedCands.end()) continue;
std::cout<<"Cluster: pt = "<<clusCands[candNr]->pt()<<" eta = "<<clusCands[candNr]->eta()<<" eta = "<<clusCands[candNr]->phi()<<std::endl;
if (deltaR((*clusCands[candNr]),cleanedJet) <= minDeltaR_) {
std::vector<edm::Ptr<reco::PFCandidate> > pfConstituents = cleanedJet.getPFConstituents();
for(std::vector<edm::Ptr<reco::PFCandidate> >::const_iterator i_candidate = pfConstituents.begin(); i_candidate != pfConstituents.end(); ++i_candidate){
if (deltaR((*clusCands[candNr]),(**i_candidate))<0.001) {
std::cout<<"CLEANED"<<std::endl;
cleanedJet.setP4( cleanedJet.p4() - clusCands[candNr]->p4());
usedCands.push_back(candNr);
break;
}//if constituent matched
}//for constituents
refVector.push_back(JetRef(theJetCollectionHandle, j));
}//else
}
allSelections->push_back(refVector);
}
}




iEvent.put(allSelections);
}//if dR<min
}//for cands
allSelections->push_back(cleanedJet);
}//for jets
}//if cands

NumericSafeGreaterByPt<jetType> compJets;
// reorder cleaned jets
std::sort (allSelections->begin(), allSelections->end(), compJets);
iEvent.put(allSelections);

return;

}

0 comments on commit 658e783

Please sign in to comment.