CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/SUSYBSMAnalysis/HSCP/src/HSCParticleSelector.cc

Go to the documentation of this file.
00001 #include <memory>
00002 #include "FWCore/Framework/interface/Frameworkfwd.h"
00003 #include "FWCore/Framework/interface/MakerMacros.h"
00004 #include "FWCore/Framework/interface/EDFilter.h"
00005 
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "DataFormats/Common/interface/Handle.h"
00008 #include "DataFormats/Common/interface/View.h"
00009 
00010 #include "AnalysisDataFormats/SUSYBSMObjects/interface/HSCParticle.h"
00011 #include "SUSYBSMAnalysis/HSCP/interface/CandidateSelector.h"
00012 
00013 //
00014 // class declaration
00015 //
00016 class HSCParticleSelector : public edm::EDFilter {
00017    public:
00018       explicit HSCParticleSelector(const edm::ParameterSet&);
00019       ~HSCParticleSelector();
00020 
00021    private:
00022       virtual void beginJob() ;
00023       virtual bool filter(edm::Event&, const edm::EventSetup&);
00024       virtual void endJob() ;
00025 
00026       edm::InputTag sourceTag_;
00027 
00028       bool                            Filter_;
00029       std::vector<CandidateSelector*> Selectors;
00030 };
00031 
00032 
00034 HSCParticleSelector::HSCParticleSelector(const edm::ParameterSet& iConfig)
00035 {
00036    // What is being produced
00037    produces<susybsm::HSCParticleCollection >();
00038 
00039    // Input products
00040    sourceTag_     = iConfig.getParameter<edm::InputTag> ("source");
00041    Filter_        = iConfig.getParameter<bool>          ("filter");
00042 
00043    // Load all the selections
00044    std::vector<edm::ParameterSet> SelectionParameters = iConfig.getParameter<std::vector<edm::ParameterSet> >("SelectionParameters");
00045    for(unsigned int i=0;i<SelectionParameters.size();i++){
00046       Selectors.push_back(new CandidateSelector(SelectionParameters[i]) );
00047    }
00048 } 
00049 
00051 HSCParticleSelector::~HSCParticleSelector(){
00052 }
00053 
00055 void HSCParticleSelector::beginJob() {
00056 }
00057 
00059 void HSCParticleSelector::endJob(){
00060 }
00061 
00063 bool HSCParticleSelector::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00064 {
00065       // Source Collection
00066       edm::Handle<susybsm::HSCParticleCollection > SourceHandle;
00067       if (!iEvent.getByLabel(sourceTag_, SourceHandle)) {
00068             edm::LogError("") << ">>> HSCParticleCollection does not exist !!!";
00069             return false;
00070       }
00071       susybsm::HSCParticleCollection Source = *SourceHandle.product();
00072 
00073 
00074       // Output Collection
00075       susybsm::HSCParticleCollection* output = new susybsm::HSCParticleCollection;
00076       std::auto_ptr<susybsm::HSCParticleCollection> result(output);
00077 
00078       // cleanup the collection based on the input selection
00079       for(susybsm::HSCParticleCollection::iterator hscpcandidate = Source.begin(); hscpcandidate < Source.end(); ++hscpcandidate){
00080          bool decision = false;
00081          for(unsigned int i=0;i<Selectors.size();i++){decision |= Selectors[i]->isSelected(*hscpcandidate);}
00082          if(decision){
00083             susybsm::HSCParticle* newhscp = new susybsm::HSCParticle(*hscpcandidate);
00084             output->push_back(*newhscp);
00085          }
00086       }
00087 
00088       bool filterResult = !Filter_ || (Filter_ && output->size()>=1);
00089 
00090       iEvent.put(result);
00091 
00092       return filterResult;
00093 }
00094 
00095 DEFINE_FWK_MODULE(HSCParticleSelector);
00096 
00097 
00098 
00099