CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/DPGAnalysis/Skims/src/BeamSplash.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:   BeamSplash
00004 // Class:     BeamSPlash
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/BeamSplash.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 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00030 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00031 
00032 using namespace edm;
00033 using namespace std;
00034 
00035 BeamSplash::BeamSplash(const edm::ParameterSet& iConfig)
00036 {
00037   EBRecHitCollection_ = iConfig.getParameter<edm::InputTag>("ebrechitcollection");
00038   EERecHitCollection_ = iConfig.getParameter<edm::InputTag>("eerechitcollection");
00039   HBHERecHitCollection_ = iConfig.getParameter<edm::InputTag>("hbherechitcollection");
00040 
00041   EnergyCutTot = iConfig.getUntrackedParameter<double>("energycuttot");
00042   EnergyCutEcal = iConfig.getUntrackedParameter<double>("energycutecal");
00043   EnergyCutHcal = iConfig.getUntrackedParameter<double>("energycuthcal");
00044   applyfilter = iConfig.getUntrackedParameter<bool>("applyfilter",true);
00045 }
00046 
00047 BeamSplash::~BeamSplash()
00048 {
00049 }
00050 
00051 bool BeamSplash::filter( edm::Event& iEvent, const edm::EventSetup& iSetup)
00052 {
00053   bool accepted = false;
00054 
00055   bool acceptedtot = false;
00056   bool acceptedEcal = false;
00057   bool acceptedHcal = false;
00058 
00059   int ievt = iEvent.id().event();
00060   int irun = iEvent.id().run();
00061   int ils = iEvent.luminosityBlock();
00062   int ibx = iEvent.bunchCrossing();
00063 
00064   double totene=0;
00065   double ecalene=0;
00066   double hcalene=0;
00067 
00068 
00069   Handle< EBRecHitCollection > pEBRecHits;
00070   Handle< EERecHitCollection > pEERecHits;
00071   Handle< HBHERecHitCollection > pHBHERecHits;
00072  
00073   const EBRecHitCollection*  EBRecHits = 0;
00074   const EERecHitCollection*  EERecHits = 0; 
00075   const HBHERecHitCollection*  HBHERecHits = 0; 
00076   
00077   if ( EBRecHitCollection_.label() != "" && EBRecHitCollection_.instance() != "" ) 
00078     {
00079       iEvent.getByLabel( EBRecHitCollection_, pEBRecHits);
00080       if ( pEBRecHits.isValid() ) 
00081         {
00082           EBRecHits = pEBRecHits.product(); // get a ptr to the product
00083         } 
00084       else 
00085         {
00086           edm::LogError("EcalRecHitError") << "Error! can't get the product " << EBRecHitCollection_.label() ;
00087         }
00088     }
00089 
00090   if ( EERecHitCollection_.label() != "" && EERecHitCollection_.instance() != "" ) 
00091     {
00092       iEvent.getByLabel( EERecHitCollection_, pEERecHits);
00093       
00094       if ( pEERecHits.isValid() ) 
00095         {
00096           EERecHits = pEERecHits.product(); // get a ptr to the product
00097         } 
00098       else 
00099         {
00100           edm::LogError("EcalRecHitError") << "Error! can't get the product " << EERecHitCollection_.label() ;
00101       }
00102     }
00103 
00104   if ( HBHERecHitCollection_.label() != "" )
00105     {
00106       iEvent.getByLabel( HBHERecHitCollection_, pHBHERecHits);
00107       
00108       if ( pHBHERecHits.isValid() ) 
00109         {
00110           HBHERecHits = pHBHERecHits.product(); // get a ptr to the product
00111         } 
00112       else 
00113         {
00114           edm::LogError("HcalRecHitError") << "Error! can't get the product " << HBHERecHitCollection_.label() ;
00115       }
00116     }
00117 
00118   // now sum over them
00119   if (EBRecHits) 
00120     {
00121       for(EBRecHitCollection::const_iterator it  = EBRecHits->begin(); it != EBRecHits->end(); ++it) 
00122         {
00123           totene+=it->energy();
00124           ecalene+=it->energy();
00125         }
00126     }
00127   if (EERecHits) 
00128     {
00129       for(EERecHitCollection::const_iterator it  = EERecHits->begin(); it != EERecHits->end(); ++it) 
00130         {
00131           totene+=it->energy();
00132           ecalene+=it->energy();
00133         }
00134     }
00135   if (HBHERecHits) 
00136     {
00137       for(HBHERecHitCollection::const_iterator it  = HBHERecHits->begin(); it != HBHERecHits->end(); ++it) 
00138         {
00139           totene+=it->energy();
00140           hcalene+=it->energy();
00141         }
00142     }
00143 
00144   if(totene>EnergyCutTot) acceptedtot=true;
00145   if(ecalene>EnergyCutEcal) acceptedEcal=true;
00146   if(hcalene>EnergyCutHcal) acceptedHcal=true;
00147 
00148   accepted = acceptedtot|acceptedEcal|acceptedHcal;
00149   
00150   
00151   if (accepted)
00152         {
00153     edm::LogVerbatim("BeamSplash") << "!!!!!!!BeamSplash!!!!!!!: run:" << irun << " event:" << ievt << " ls:"<< ils << " bx= " << ibx  <<" totene=" << totene << " ecalene=" << ecalene << " hcalene=" << hcalene ; 
00154     std::cout << "!!!!!!!BeamSplash!!!!!!!: run:" << irun << " event:" << ievt << " ls:"<< ils << " bx= " << ibx  <<" totene=" <<totene << " ecalene=" << ecalene << " hcalene=" << hcalene << std::endl; 
00155  } 
00156 
00157   if (applyfilter)
00158     return accepted;
00159   else
00160     return true;
00161 
00162 }
00163 
00164 //define this as a plug-in
00165 DEFINE_FWK_MODULE(BeamSplash);