CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/HLTrigger/JetMET/src/HLTJetCollectionsForElePlusJets.cc

Go to the documentation of this file.
00001 #include "HLTrigger/JetMET/interface/HLTJetCollectionsForElePlusJets.h"
00002 
00003 #include "FWCore/Framework/interface/MakerMacros.h"
00004 
00005 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
00006 #include "DataFormats/EgammaCandidates/interface/Electron.h"
00007 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00008 #include "DataFormats/JetReco/interface/PFJetCollection.h"
00009 
00010 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00011 
00012 #include "DataFormats/Common/interface/Handle.h"
00013 
00014 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00015 
00016 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00017 #include "TVector3.h"
00018 
00019 #include <string>
00020 #include <vector>
00021 #include <typeinfo>
00022 
00023 template<typename T>
00024 HLTJetCollectionsForElePlusJets<T>::HLTJetCollectionsForElePlusJets(const edm::ParameterSet& iConfig):
00025   hltElectronTag(iConfig.getParameter< edm::InputTag > ("HltElectronTag")),
00026   sourceJetTag(iConfig.getParameter< edm::InputTag > ("SourceJetTag")),
00027   //minJetPt_(iConfig.getParameter<double> ("MinJetPt")),
00028   //maxAbsJetEta_(iConfig.getParameter<double> ("MaxAbsJetEta")),
00029   //minNJets_(iConfig.getParameter<unsigned int> ("MinNJets")),
00030   minDeltaR_(iConfig.getParameter< double > ("minDeltaR"))
00031   //Only for VBF
00032   //minSoftJetPt_(iConfig.getParameter< double > ("MinSoftJetPt")),
00033   //minDeltaEta_(iConfig.getParameter< double > ("MinDeltaEta"))
00034 {
00035   typedef std::vector<edm::RefVector<std::vector<T>,T,edm::refhelper::FindUsingAdvance<std::vector<T>,T> > > TCollectionVector;
00036   produces<TCollectionVector> ();
00037 }
00038 
00039 
00040 template<typename T>
00041 HLTJetCollectionsForElePlusJets<T>::~HLTJetCollectionsForElePlusJets()
00042 {
00043    // do anything here that needs to be done at desctruction time
00044    // (e.g. close files, deallocate resources etc.)
00045 
00046 }
00047 
00048 template<typename T>
00049 void HLTJetCollectionsForElePlusJets<T>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00050     edm::ParameterSetDescription desc;
00051     desc.add<edm::InputTag> ("HltElectronTag", edm::InputTag("triggerFilterObjectWithRefs"));
00052     desc.add<edm::InputTag> ("SourceJetTag", edm::InputTag("jetCollection"));
00053    // desc.add<double> ("MinJetPt", 30.);
00054    // desc.add<double> ("MaxAbsJetEta", 2.6);
00055    // desc.add<unsigned int> ("MinNJets", 1);
00056     desc.add<double> ("minDeltaR", 0.5);
00057     //Only for VBF
00058    // desc.add<double> ("MinSoftJetPt", 25.);
00059     //desc.add<double> ("MinDeltaEta", -1.);
00060     descriptions.add(std::string("hlt")+std::string(typeid(HLTJetCollectionsForElePlusJets<T>).name()),desc);
00061 }
00062 
00063 //
00064 // member functions
00065 //
00066 
00067 
00068 // ------------ method called to produce the data  ------------
00069 template <typename T>
00070 void
00071 HLTJetCollectionsForElePlusJets<T>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00072 {
00073   using namespace edm;
00074   using namespace std;
00075 
00076   typedef vector<T> TCollection;
00077   typedef Ref<TCollection> TRef;
00078 
00079   typedef edm::RefVector<TCollection> TRefVector;
00080 
00081   typedef std::vector<edm::RefVector<std::vector<T>,T,edm::refhelper::FindUsingAdvance<std::vector<T>,T> > > TCollectionVector;
00082   
00083   edm::Handle<trigger::TriggerFilterObjectWithRefs> PrevFilterOutput;
00084   iEvent.getByLabel(hltElectronTag,PrevFilterOutput);
00085  
00086   //its easier on the if statement flow if I try everything at once, shouldnt add to timing
00087   std::vector<edm::Ref<reco::RecoEcalCandidateCollection> > clusCands;
00088   PrevFilterOutput->getObjects(trigger::TriggerCluster,clusCands);
00089 
00090   std::vector<edm::Ref<reco::ElectronCollection> > eleCands;
00091   PrevFilterOutput->getObjects(trigger::TriggerElectron,eleCands);
00092   
00093   //prepare the collection of 3-D vector for electron momenta
00094   std::vector<TVector3> ElePs;
00095 
00096   if(!clusCands.empty()){ //try trigger cluster
00097     for(size_t candNr=0;candNr<clusCands.size();candNr++){
00098       TVector3 positionVector(
00099                   clusCands[candNr]->superCluster()->position().x(),
00100                   clusCands[candNr]->superCluster()->position().y(),
00101                   clusCands[candNr]->superCluster()->position().z());
00102       ElePs.push_back(positionVector);
00103     }
00104   }else if(!eleCands.empty()){ // try trigger electrons
00105     for(size_t candNr=0;candNr<eleCands.size();candNr++){
00106       TVector3 positionVector(
00107                   eleCands[candNr]->superCluster()->position().x(),
00108                   eleCands[candNr]->superCluster()->position().y(),
00109                   eleCands[candNr]->superCluster()->position().z());
00110       ElePs.push_back(positionVector);
00111     }
00112   }
00113   
00114   edm::Handle<TCollection> theJetCollectionHandle;
00115   iEvent.getByLabel(sourceJetTag, theJetCollectionHandle);
00116   //const TCollection* theJetCollection = theJetCollectionHandle.product();
00117   
00118   const TCollection & theJetCollection = *theJetCollectionHandle;
00119   
00120   //std::auto_ptr< TCollection >  theFilteredJetCollection(new TCollection);
00121   
00122   std::auto_ptr < TCollectionVector > allSelections(new TCollectionVector());
00123   
00124  //bool foundSolution(false);
00125 
00126     for (unsigned int i = 0; i < ElePs.size(); i++) {
00127 
00128        // bool VBFJetPair = false;
00129         //std::vector<int> store_jet;
00130         TRefVector refVector;
00131 
00132         for (unsigned int j = 0; j < theJetCollection.size(); j++) {
00133             TVector3 JetP(theJetCollection[j].px(), theJetCollection[j].py(), theJetCollection[j].pz());
00134             double DR = ElePs[i].DeltaR(JetP);
00135 
00136             if (DR > minDeltaR_)
00137         refVector.push_back(TRef(theJetCollectionHandle, j));
00138         }
00139     allSelections->push_back(refVector);
00140     }
00141 
00142     //iEvent.put(theFilteredJetCollection);
00143     iEvent.put(allSelections);
00144   
00145   return;
00146   
00147 }