CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DPGAnalysis/Skims/src/ECALActivity.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:   ECALActivity
00004 // Class:     ECALActivity
00005 //
00006 //
00007 // Original Author:  Luca Malgeri
00008 
00009 #include <memory>
00010 #include <vector>
00011 #include <map>
00012 #include <set>
00013 
00014 // user include files
00015 #include "DPGAnalysis/Skims/interface/ECALActivity.h"
00016 
00017 #include "FWCore/Utilities/interface/InputTag.h"
00018 #include "FWCore/Framework/interface/Frameworkfwd.h"
00019 #include "FWCore/Framework/interface/EDFilter.h"
00020 #include "FWCore/Framework/interface/Event.h"
00021 #include "FWCore/Framework/interface/MakerMacros.h"
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 #include "FWCore/Framework/interface/ESHandle.h"
00024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00025 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00026 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00027 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00028 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00029 
00030 using namespace edm;
00031 using namespace std;
00032 
00033 ECALActivity::ECALActivity(const edm::ParameterSet& iConfig)
00034 {
00035   EBRecHitCollection_ = iConfig.getParameter<edm::InputTag>("ebrechitcollection");
00036   EERecHitCollection_ = iConfig.getParameter<edm::InputTag>("ebrechitcollection");
00037 
00038   EBnum=iConfig.getUntrackedParameter<int>("EBnum");
00039   EBthresh=iConfig.getUntrackedParameter<double>("EBthresh");
00040   EEnum=iConfig.getUntrackedParameter<int>("EEnum");
00041   EEthresh=iConfig.getUntrackedParameter<double>("EEthresh");
00042   ETOTnum=iConfig.getUntrackedParameter<int>("ETOTnum");
00043   ETOTthresh=iConfig.getUntrackedParameter<double>("ETOTthresh");
00044   applyfilter = iConfig.getUntrackedParameter<bool>("applyfilter",true);
00045 }
00046 
00047 ECALActivity::~ECALActivity()
00048 {
00049 }
00050 
00051 bool ECALActivity::filter( edm::Event& iEvent, const edm::EventSetup& iSetup)
00052 {
00053   bool accepted = false;
00054   bool eb= false;
00055   bool ee= false;
00056   bool etot= false;
00057 
00058   //int ievt = iEvent.id().event();
00059   //int irun = iEvent.id().run();
00060   //int ils = iEvent.luminosityBlock();
00061 
00062   int  ebabovethresh=0;
00063   int  eeabovethresh=0;
00064   int  etotabovethresh=0;
00065 
00066 
00067   Handle< EBRecHitCollection > pEBRecHits;
00068   Handle< EERecHitCollection > pEERecHits;
00069  
00070   const EBRecHitCollection*  EBRecHits = 0;
00071   const EERecHitCollection*  EERecHits = 0; 
00072   
00073   if ( EBRecHitCollection_.label() != "" && EBRecHitCollection_.instance() != "" ) 
00074     {
00075       iEvent.getByLabel( EBRecHitCollection_, pEBRecHits);
00076       if ( pEBRecHits.isValid() ) 
00077         {
00078           EBRecHits = pEBRecHits.product(); // get a ptr to the product
00079         } 
00080       else 
00081         {
00082           edm::LogError("EcalRecHitError") << "Error! can't get the product " << EBRecHitCollection_.label() ;
00083         }
00084     }
00085 
00086   if ( EERecHitCollection_.label() != "" && EERecHitCollection_.instance() != "" ) 
00087     {
00088       iEvent.getByLabel( EERecHitCollection_, pEERecHits);
00089       
00090       if ( pEERecHits.isValid() ) 
00091         {
00092           EERecHits = pEERecHits.product(); // get a ptr to the product
00093         } 
00094       else 
00095         {
00096           edm::LogError("EcalRecHitError") << "Error! can't get the product " << EERecHitCollection_.label() ;
00097       }
00098     }
00099 
00100 
00101   // now loop over them
00102   if (EBRecHits) 
00103     {
00104       for(EBRecHitCollection::const_iterator it  = EBRecHits->begin(); it != EBRecHits->end(); ++it) 
00105         {
00106           if (it->energy()>EBthresh) ebabovethresh++;
00107           if (it->energy()>ETOTthresh) etotabovethresh++;
00108         }
00109     }
00110   if (EERecHits) 
00111     {
00112       for(EERecHitCollection::const_iterator it  = EERecHits->begin(); it != EERecHits->end(); ++it) 
00113         {
00114           if (it->energy()>EEthresh) eeabovethresh++;
00115           if (it->energy()>ETOTthresh) etotabovethresh++;
00116         }
00117     }
00118 
00119   if(ebabovethresh>=EBnum) eb=true;
00120   if(eeabovethresh>=EEnum) ee=true;
00121   if(etotabovethresh>=ETOTnum) etot=true;
00122 
00123   accepted = eb|ee|etot;
00124   
00125   if (applyfilter)
00126     return accepted;
00127   else
00128     return true;
00129 
00130 }
00131 
00132 //define this as a plug-in
00133 DEFINE_FWK_MODULE(ECALActivity);