CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/ElectroWeakAnalysis/ZEE/src/aod2patFilterZee.cc

Go to the documentation of this file.
00001 #ifndef aod2patFilterZee_H
00002 #define aod2patFilterZee_H
00003 
00004 /******************************************************************************
00005  *
00006  * Implementation Notes:
00007  *
00008  *   this is a filter that creates pat::Electrons without the need of
00009  *   running the PAT sequence
00010  *
00011  *   it is meant to be an interface of Wenu and Zee CandidateFilters
00012  *   for the October 2009 exercise
00013  *   it does make sense to implement the trigger requirement here
00014  *   but it will not be implemented in order to keep compatibolity with the
00015  *   old code
00016  *
00017  *
00018  * contact:
00019  * Nikolaos.Rompotis@Cern.ch
00020  *
00021  * Nikolaos Rompotis
00022  * Imperial College London
00023  *
00024  * 21 Sept 2009
00025  *
00026  *****************************************************************************/
00027 
00028 
00029 
00030 // system include files
00031 #include <memory>
00032 
00033 // user include files
00034 #include "FWCore/Framework/interface/Frameworkfwd.h"
00035 #include "FWCore/Framework/interface/EDFilter.h"
00036 
00037 #include "FWCore/Framework/interface/Event.h"
00038 #include "FWCore/Framework/interface/MakerMacros.h"
00039 
00040 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00041 //
00042 #include <vector>
00043 #include <iostream>
00044 #include "FWCore/Utilities/interface/InputTag.h"
00045 #include "DataFormats/PatCandidates/interface/Electron.h"
00046 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00047 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
00048 #include "DataFormats/Common/interface/TriggerResults.h"
00049 #include "DataFormats/METReco/interface/METCollection.h"
00050 #include "DataFormats/METReco/interface/CaloMETCollection.h"
00051 //
00052 #include "TString.h"
00053 #include "TMath.h"
00054 #include "DataFormats/PatCandidates/interface/MET.h"
00055 
00056 
00057 class aod2patFilterZee : public edm::EDFilter {
00058    public:
00059       explicit aod2patFilterZee(const edm::ParameterSet&);
00060       ~aod2patFilterZee();
00061 
00062    private:
00063       virtual void beginJob();
00064       virtual bool filter(edm::Event&, const edm::EventSetup&);
00065       virtual void endJob() ;
00066   //bool isInFiducial(double eta);
00067       
00068       // ----------member data ---------------------------
00069   //double ETCut_;
00070   //double METCut_;
00071   //double ETCut2ndEle_;
00072   //edm::InputTag triggerCollectionTag_;
00073   //edm::InputTag triggerEventTag_;
00074   //std::string hltpath_;
00075   //edm::InputTag hltpathFilter_;
00076   edm::InputTag electronCollectionTag_;
00077   edm::InputTag metCollectionTag_;
00078 
00079   //double BarrelMaxEta_;
00080   //double EndCapMaxEta_;
00081   //double EndCapMinEta_;
00082   //bool electronMatched2HLT_;
00083   //double electronMatched2HLT_DR_;
00084   //bool vetoSecondElectronEvents_;
00085 };
00086 #endif
00087 
00088 
00089 aod2patFilterZee::aod2patFilterZee(const edm::ParameterSet& iConfig)
00090 {
00091 
00092   electronCollectionTag_=iConfig.getUntrackedParameter<edm::InputTag>
00093     ("electronCollectionTag");
00094   metCollectionTag_=iConfig.getUntrackedParameter<edm::InputTag>
00095     ("metCollectionTag");
00096 
00097 
00098   produces< pat::ElectronCollection > 
00099     ("patElectrons").setBranchAlias("patElectrons");
00100 
00101   produces< pat::METCollection>("patCaloMets").setBranchAlias("patCaloMets");
00102   //produces< pat::METCollection>("patPfMets").setBranchAlias("patPfMets");
00103   //produces< pat::METCollection>("patTcMets").setBranchAlias("patTcMets");
00104   //produces< pat::METCollection>("patT1cMets").setBranchAlias("patT1cMets");
00105 
00106 }
00107 
00108 aod2patFilterZee::~aod2patFilterZee()
00109 {
00110  
00111    // do anything here that needs to be done at desctruction time
00112    // (e.g. close files, deallocate resources etc.)
00113 
00114 }
00115 
00116 
00117 bool
00118 aod2patFilterZee::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00119 {
00120   using namespace edm;
00121   using namespace std;
00122   using namespace pat;
00123   // *************************************************************************
00124   // ELECTRONS
00125   // *************************************************************************
00126   edm::Handle<reco::GsfElectronCollection> gsfElectrons;
00127   iEvent.getByLabel(electronCollectionTag_, gsfElectrons);
00128   if (!gsfElectrons.isValid()) {
00129     std::cout <<"aod2patFilterZee: Could not get electron collection with label: "
00130               <<electronCollectionTag_ << std::endl;
00131     return false;
00132   }
00133   const reco::GsfElectronCollection *pElecs = gsfElectrons.product();
00134   // calculate your electrons
00135   auto_ptr<pat::ElectronCollection> patElectrons(new pat::ElectronCollection);
00136   for (reco::GsfElectronCollection::const_iterator elec = pElecs->begin();
00137        elec != pElecs->end(); ++elec) {
00138     reco::GsfElectron mygsfelec = *elec;
00139     pat::Electron myElectron(mygsfelec);
00140     // now set the isolations from the Gsf electron
00141     myElectron.setTrackIso(elec->dr03TkSumPt());
00142     myElectron.setEcalIso(elec->dr04EcalRecHitSumEt());
00143     myElectron.setHcalIso(elec->dr04HcalTowerSumEt());
00144 
00145     patElectrons->push_back(myElectron);
00146   }
00147   // *************************************************************************
00148   // METs
00149   // *************************************************************************
00150   edm::Handle<reco::CaloMETCollection> calomets;
00151   iEvent.getByLabel(metCollectionTag_, calomets);
00152   if (! calomets.isValid()) {
00153     std::cout << "aod2patFilterZee: Could not get met collection with label: "
00154               << metCollectionTag_ << std::endl;
00155     return false;
00156   }
00157   const  reco::CaloMETCollection *mycalomets =  calomets.product();
00158   auto_ptr<pat::METCollection> patCaloMets(new pat::METCollection);
00159   for (reco::CaloMETCollection::const_iterator met = mycalomets->begin();
00160        met != mycalomets->end(); ++ met ) {
00161     pat::MET mymet(*met);
00162     patCaloMets->push_back(mymet);
00163   }
00164 
00165   //
00166   // put everything in the event
00167   //
00168   iEvent.put( patElectrons, "patElectrons");
00169   iEvent.put( patCaloMets, "patCaloMets");
00170   //
00171 
00172   return true;
00173 
00174 }
00175 
00176 // ------------ method called once each job just before starting event loop  -
00177 void 
00178 aod2patFilterZee::beginJob() {
00179 }
00180 
00181 // ------------ method called once each job just after ending the event loop  -
00182 void 
00183 aod2patFilterZee::endJob() {
00184 }
00185 
00186 
00187 //define this as a plug-in
00188 DEFINE_FWK_MODULE(aod2patFilterZee);