CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoHI/HiEgammaAlgos/plugins/HiEgammaSCCorrectionMaker.cc

Go to the documentation of this file.
00001 #include "RecoHI/HiEgammaAlgos/plugins/HiEgammaSCCorrectionMaker.h"
00002 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00003 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00004 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00005 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00006 
00007 #include "FWCore/PluginManager/interface/ModuleDef.h"
00008 #include "FWCore/Framework/interface/MakerMacros.h"
00009 
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 #include "FWCore/Utilities/interface/Exception.h"
00012 #include "DataFormats/Common/interface/Handle.h"
00013 
00014 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00015 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00016 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00017 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00018 #include "Geometry/CaloTopology/interface/EcalBarrelTopology.h"
00019 #include "Geometry/CaloTopology/interface/EcalEndcapTopology.h"
00020 #include "Geometry/CaloTopology/interface/EcalPreshowerTopology.h"
00021 #include "Geometry/CaloTopology/interface/CaloTopology.h"
00022 #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"
00023 
00024 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionBaseClass.h" 
00025 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionFactory.h" 
00026 
00027 
00028 #include <string>
00029 
00030 HiEgammaSCCorrectionMaker::HiEgammaSCCorrectionMaker(const edm::ParameterSet& ps)
00031 {
00032  
00033   // The verbosity level
00034   std::string debugString = ps.getParameter<std::string>("VerbosityLevel");
00035   if      (debugString == "DEBUG")   verbosity_ = HiEgammaSCEnergyCorrectionAlgo::pDEBUG;
00036   else if (debugString == "INFO")    verbosity_ = HiEgammaSCEnergyCorrectionAlgo::pINFO;
00037   else                               verbosity_ = HiEgammaSCEnergyCorrectionAlgo::pERROR;
00038 
00039   // the input producers
00040   rHInputProducer_ = ps.getParameter<edm::InputTag>("recHitProducer");
00041   sCInputProducer_ = ps.getParameter<edm::InputTag>("rawSuperClusterProducer");
00042   std::string sCAlgo_str = ps.getParameter<std::string>("superClusterAlgo");
00043 
00044   // determine which BasicCluster algo we are correcting for
00045   //And obtain forrection parameters form cfg file
00046   edm::ParameterSet fCorrPset;
00047   if (sCAlgo_str=="Hybrid") {
00048     sCAlgo_= reco::CaloCluster::hybrid;
00049     fCorrPset = ps.getParameter<edm::ParameterSet>("hyb_fCorrPset"); 
00050   } else if (sCAlgo_str=="Island") {
00051     sCAlgo_= reco::CaloCluster::island;
00052     fCorrPset = ps.getParameter<edm::ParameterSet>("isl_fCorrPset");
00053   } else if (sCAlgo_str=="DynamicHybrid") {
00054     sCAlgo_ = reco::CaloCluster::dynamicHybrid;
00055     fCorrPset = ps.getParameter<edm::ParameterSet>("dyn_fCorrPset"); 
00056   } else if (sCAlgo_str=="Multi5x5") {
00057     sCAlgo_ = reco::CaloCluster::multi5x5;
00058     fCorrPset = ps.getParameter<edm::ParameterSet>("fix_fCorrPset");
00059   } else {
00060     edm::LogError("HiEgammaSCCorrectionMakerError") 
00061       << "Error! SuperClusterAlgo in config file must be Hybrid or Island: " 
00062       << sCAlgo_str << "  Using Hybrid by default";
00063     sCAlgo_=reco::CaloCluster::hybrid;
00064   }
00065   
00066   // set correction algo parameters
00067   applyEnergyCorrection_ = ps.getParameter<bool>("applyEnergyCorrection");
00068   sigmaElectronicNoise_ =  ps.getParameter<double>("sigmaElectronicNoise");
00069 
00070   etThresh_ =  ps.getParameter<double>("etThresh");
00071 
00072   // set the producer parameters
00073   outputCollection_ = ps.getParameter<std::string>("corectedSuperClusterCollection");
00074   produces<reco::SuperClusterCollection>(outputCollection_);
00075 
00076   // instanciate the correction algo object
00077   energyCorrector_ = new HiEgammaSCEnergyCorrectionAlgo(sigmaElectronicNoise_, sCAlgo_, fCorrPset, verbosity_);
00078   
00079 
00080   // energy correction class
00081   if (applyEnergyCorrection_ )
00082     EnergyCorrection_ = EcalClusterFunctionFactory::get()->create("EcalClusterEnergyCorrection", ps);
00083 }
00084 
00085 HiEgammaSCCorrectionMaker::~HiEgammaSCCorrectionMaker()
00086 {
00087   delete energyCorrector_;
00088 }
00089 
00090 void
00091 HiEgammaSCCorrectionMaker::produce(edm::Event& evt, const edm::EventSetup& es)
00092 {
00093   using namespace edm;
00094 
00095   // initialize energy correction class
00096   if(applyEnergyCorrection_) 
00097     EnergyCorrection_->init(es);
00098 
00099   // get the collection geometry:
00100   edm::ESHandle<CaloGeometry> geoHandle;
00101   es.get<CaloGeometryRecord>().get(geoHandle);
00102   const CaloGeometry& geometry = *geoHandle;
00103   const CaloSubdetectorGeometry *geometry_p;
00104 
00105   edm::ESHandle<CaloTopology> pTopology;
00106   es.get<CaloTopologyRecord>().get(theCaloTopo_);
00107   const CaloTopology *topology = theCaloTopo_.product();
00108 
00109   std::string rHInputCollection = rHInputProducer_.instance();
00110   if(rHInputCollection == "EcalRecHitsEB") {
00111     geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
00112   } else if(rHInputCollection == "EcalRecHitsEE") {
00113     geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
00114   } else if(rHInputCollection == "EcalRecHitsPS") {
00115     geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
00116   } else {
00117           std::string str = "\n\nSCCorrectionMaker encountered invalied ecalhitcollection type: " + rHInputCollection + ".\n\n";
00118           throw(std::runtime_error( str.c_str() ));
00119   }
00120   
00121   // Get raw SuperClusters from the event    
00122   Handle<reco::SuperClusterCollection> pRawSuperClusters;
00123   try { 
00124     evt.getByLabel(sCInputProducer_, pRawSuperClusters);
00125   } catch ( cms::Exception& ex ) {
00126     edm::LogError("HiEgammaSCCorrectionMakerError") 
00127       << "Error! can't get the rawSuperClusters " 
00128       << sCInputProducer_.label() ;
00129   }    
00130   
00131   // Get the RecHits from the event
00132   Handle<EcalRecHitCollection> pRecHits;
00133   try { 
00134     evt.getByLabel(rHInputProducer_, pRecHits);
00135   } catch ( cms::Exception& ex ) {
00136     edm::LogError("HiEgammaSCCorrectionMakerError") 
00137       << "Error! can't get the RecHits " 
00138       << rHInputProducer_.label();
00139   }    
00140   
00141   // Create a pointer to the RecHits and raw SuperClusters
00142   const EcalRecHitCollection *hitCollection = pRecHits.product();
00143   const reco::SuperClusterCollection *rawClusters = pRawSuperClusters.product();
00144    
00145   // Define a collection of corrected SuperClusters to put back into the event
00146   std::auto_ptr<reco::SuperClusterCollection> corrClusters(new reco::SuperClusterCollection);
00147   
00148   //  Loop over raw clusters and make corrected ones
00149   reco::SuperClusterCollection::const_iterator aClus;
00150   for(aClus = rawClusters->begin(); aClus != rawClusters->end(); aClus++)
00151   {
00152      reco::SuperCluster newClus;
00153      if(applyEnergyCorrection_) 
00154         newClus = energyCorrector_->applyCorrection(*aClus, *hitCollection, sCAlgo_, geometry_p, topology, EnergyCorrection_);
00155      else
00156         newClus=*aClus;
00157 
00158      if(newClus.energy()*sin(newClus.position().theta())>etThresh_) {
00159         corrClusters->push_back(newClus);
00160      }
00161   }
00162   // Put collection of corrected SuperClusters into the event
00163   evt.put(corrClusters, outputCollection_);   
00164 }
00165 
00166 DEFINE_FWK_MODULE(HiEgammaSCCorrectionMaker);