CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/RecoLocalCalo/HcalRecProducers/src/HcalHitSelection.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    HcalHitSelection
00004 // Class:      HcalHitSelection
00005 // 
00013 //
00014 // Original Author:  Jean-Roch Vlimant,40 3-A28,+41227671209,
00015 //         Created:  Thu Nov  4 22:17:56 CET 2010
00016 // $Id: HcalHitSelection.cc,v 1.4 2011/03/24 19:41:28 vlimant Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDProducer.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 
00033 #include "FWCore/Framework/interface/ESHandle.h"
00034 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00035 #include "DataFormats/DetId/interface/DetIdCollection.h"
00036 
00037 #include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
00038 #include "CondFormats/DataRecord/interface/HcalChannelQualityRcd.h"
00039 
00040 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputer.h"
00041 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputerRcd.h"
00042 
00043 //
00044 // class declaration
00045 //
00046 
00047 class HcalHitSelection : public edm::EDProducer {
00048    public:
00049       explicit HcalHitSelection(const edm::ParameterSet&);
00050       ~HcalHitSelection();
00051 
00052    private:
00053       virtual void beginJob() ;
00054       virtual void produce(edm::Event&, const edm::EventSetup&);
00055       virtual void endJob() ;
00056   
00057   edm::InputTag hbheTag,hoTag,hfTag;
00058   int hoSeverityLevel;
00059   std::vector<edm::InputTag> interestingDetIdCollections;
00060   
00061   //hcal severity ES
00062   edm::ESHandle<HcalChannelQuality> theHcalChStatus;
00063   edm::ESHandle<HcalSeverityLevelComputer> theHcalSevLvlComputer;
00064   std::set<DetId> toBeKept;
00065   template <typename CollectionType> void skim( const edm::Handle<CollectionType> & input, std::auto_ptr<CollectionType> & output,int severityThreshold=0);
00066   
00067       // ----------member data ---------------------------
00068 };
00069 
00070 template <class CollectionType> void HcalHitSelection::skim( const edm::Handle<CollectionType> & input, std::auto_ptr<CollectionType> & output,int severityThreshold){
00071   output->reserve(input->size());
00072   typename CollectionType::const_iterator begin=input->begin();
00073   typename CollectionType::const_iterator end=input->end();
00074   typename CollectionType::const_iterator hit=begin;
00075 
00076   for (;hit!=end;++hit){
00077     //    edm::LogError("HcalHitSelection")<<"the hit pointer is"<<&(*hit);
00078     const DetId & id = hit->detid();
00079     const uint32_t & recHitFlag = hit->flags();
00080     //    edm::LogError("HcalHitSelection")<<"the hit id and flag are "<<id.rawId()<<" "<<recHitFlag;
00081         
00082     const uint32_t & dbStatusFlag = theHcalChStatus->getValues(id)->getValue();
00083     int severityLevel = theHcalSevLvlComputer->getSeverityLevel(id, recHitFlag, dbStatusFlag); 
00084     //anything that is not "good" goes in
00085     if (severityLevel>severityThreshold){
00086       output->push_back(*hit);
00087     }else{
00088       //chek on the detid list
00089       if (toBeKept.find(id)!=toBeKept.end())
00090         output->push_back(*hit);
00091     }
00092   }
00093 }
00094 
00095 //
00096 // constants, enums and typedefs
00097 //
00098 
00099 
00100 //
00101 // static data member definitions
00102 //
00103 
00104 //
00105 // constructors and destructor
00106 //
00107 HcalHitSelection::HcalHitSelection(const edm::ParameterSet& iConfig)
00108 {
00109   hbheTag=iConfig.getParameter<edm::InputTag>("hbheTag");
00110   hfTag=iConfig.getParameter<edm::InputTag>("hfTag");
00111   hoTag=iConfig.getParameter<edm::InputTag>("hoTag");
00112 
00113   interestingDetIdCollections = iConfig.getParameter< std::vector<edm::InputTag> >("interestingDetIds");
00114 
00115   hoSeverityLevel=iConfig.getParameter<int>("hoSeverityLevel");
00116 
00117   produces<HBHERecHitCollection>(hbheTag.label());
00118   produces<HFRecHitCollection>(hfTag.label());
00119   produces<HORecHitCollection>(hoTag.label());
00120   
00121 }
00122 
00123 
00124 HcalHitSelection::~HcalHitSelection()
00125 {
00126  
00127    // do anything here that needs to be done at desctruction time
00128    // (e.g. close files, deallocate resources etc.)
00129 
00130 }
00131 
00132 
00133 //
00134 // member functions
00135 //
00136 
00137 // ------------ method called to produce the data  ------------
00138 void
00139 HcalHitSelection::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00140 {
00141   iSetup.get<HcalChannelQualityRcd>().get(theHcalChStatus);
00142   iSetup.get<HcalSeverityLevelComputerRcd>().get(theHcalSevLvlComputer);
00143 
00144   edm::Handle<HBHERecHitCollection> hbhe;
00145   edm::Handle<HFRecHitCollection> hf;
00146   edm::Handle<HORecHitCollection> ho;
00147 
00148   iEvent.getByLabel(hbheTag,hbhe);
00149   iEvent.getByLabel(hfTag,hf);
00150   iEvent.getByLabel(hoTag,ho);
00151 
00152   toBeKept.clear();
00153   edm::Handle<DetIdCollection > detId;
00154   for( unsigned int t = 0; t < interestingDetIdCollections.size(); ++t )
00155     {
00156       iEvent.getByLabel(interestingDetIdCollections[t],detId);
00157       if (!detId.isValid()){
00158         edm::LogError("MissingInput")<<"the collection of interesting detIds:"<<interestingDetIdCollections[t]<<" is not found.";
00159         continue;
00160       }
00161       toBeKept.insert(detId->begin(),detId->end());
00162     }
00163 
00164   std::auto_ptr<HBHERecHitCollection> hbhe_out(new HBHERecHitCollection());
00165   skim(hbhe,hbhe_out);
00166   iEvent.put(hbhe_out,hbheTag.label());
00167 
00168   std::auto_ptr<HFRecHitCollection> hf_out(new HFRecHitCollection());
00169   skim(hf,hf_out);
00170   iEvent.put(hf_out,hfTag.label());
00171 
00172   std::auto_ptr<HORecHitCollection> ho_out(new HORecHitCollection());
00173   skim(ho,ho_out,hoSeverityLevel);
00174   iEvent.put(ho_out,hoTag.label());
00175   
00176 }
00177 
00178 // ------------ method called once each job just before starting event loop  ------------
00179 void 
00180 HcalHitSelection::beginJob()
00181 {
00182 }
00183 
00184 // ------------ method called once each job just after ending the event loop  ------------
00185 void 
00186 HcalHitSelection::endJob() {
00187 }
00188 
00189 //define this as a plug-in
00190 DEFINE_FWK_MODULE(HcalHitSelection);