CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoEcal/EgammaClusterProducers/src/Multi5x5ClusterProducer.cc

Go to the documentation of this file.
00001 // C/C++ headers
00002 #include <iostream>
00003 #include <vector>
00004 #include <memory>
00005 
00006 // Framework
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "FWCore/Framework/interface/EventSetup.h"
00009 #include "DataFormats/Common/interface/Handle.h"
00010 #include "FWCore/Framework/interface/ESHandle.h"
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 #include "FWCore/Utilities/interface/Exception.h"
00013 
00014 // Reconstruction Classes
00015 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00016 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00017 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00018 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00019 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
00020 #include "DataFormats/CaloRecHit/interface/CaloID.h"
00021 
00022 // Geometry
00023 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00024 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00025 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00026 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00027 #include "Geometry/CaloTopology/interface/EcalEndcapTopology.h"
00028 #include "Geometry/CaloTopology/interface/EcalBarrelTopology.h"
00029 
00030 // EgammaCoreTools
00031 #include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
00032 
00033 // Class header file
00034 #include "RecoEcal/EgammaClusterProducers/interface/Multi5x5ClusterProducer.h"
00035 
00036 
00037 Multi5x5ClusterProducer::Multi5x5ClusterProducer(const edm::ParameterSet& ps)
00038 {
00039   // The verbosity level
00040   std::string verbosityString = ps.getParameter<std::string>("VerbosityLevel");
00041   if      (verbosityString == "DEBUG")   verbosity = Multi5x5ClusterAlgo::pDEBUG;
00042   else if (verbosityString == "WARNING") verbosity = Multi5x5ClusterAlgo::pWARNING;
00043   else if (verbosityString == "INFO")    verbosity = Multi5x5ClusterAlgo::pINFO;
00044   else                                   verbosity = Multi5x5ClusterAlgo::pERROR;
00045 
00046   // Parameters to identify the hit collections
00047   barrelHitProducer_   = ps.getParameter<std::string>("barrelHitProducer");
00048   endcapHitProducer_   = ps.getParameter<std::string>("endcapHitProducer");
00049   barrelHitCollection_ = ps.getParameter<std::string>("barrelHitCollection");
00050   endcapHitCollection_ = ps.getParameter<std::string>("endcapHitCollection");
00051 
00052   // should cluster algo be run in barrel and endcap?
00053   doEndcap_ = ps.getParameter<bool>("doEndcap");
00054   doBarrel_ = ps.getParameter<bool>("doBarrel");
00055 
00056   // The names of the produced cluster collections
00057   barrelClusterCollection_  = ps.getParameter<std::string>("barrelClusterCollection");
00058   endcapClusterCollection_  = ps.getParameter<std::string>("endcapClusterCollection");
00059 
00060   // Island algorithm parameters
00061   double barrelSeedThreshold = ps.getParameter<double>("IslandBarrelSeedThr");
00062   double endcapSeedThreshold = ps.getParameter<double>("IslandEndcapSeedThr");
00063 
00064   std::vector<int> v_chstatus = ps.getParameter<std::vector<int> >("RecHitFlagToBeExcluded");
00065 
00066   // Parameters for the position calculation:
00067   edm::ParameterSet posCalcParameters = 
00068     ps.getParameter<edm::ParameterSet>("posCalcParameters");
00069   posCalculator_ = PositionCalc(posCalcParameters);
00070 
00071   // Produces a collection of barrel and a collection of endcap clusters
00072   produces< reco::BasicClusterCollection >(endcapClusterCollection_);
00073   produces< reco::BasicClusterCollection >(barrelClusterCollection_);
00074 
00075   island_p = new Multi5x5ClusterAlgo(barrelSeedThreshold, endcapSeedThreshold,  v_chstatus, posCalculator_,verbosity);
00076 
00077   nEvt_ = 0;
00078 }
00079 
00080 
00081 Multi5x5ClusterProducer::~Multi5x5ClusterProducer()
00082 {
00083   delete island_p;
00084 }
00085 
00086 
00087 void Multi5x5ClusterProducer::produce(edm::Event& evt, const edm::EventSetup& es)
00088 {
00089 
00090   if (doEndcap_) {
00091     clusterizeECALPart(evt, es, endcapHitProducer_, endcapHitCollection_, endcapClusterCollection_, reco::CaloID::DET_ECAL_ENDCAP); 
00092   }
00093   if (doBarrel_) {
00094     clusterizeECALPart(evt, es, barrelHitProducer_, barrelHitCollection_, barrelClusterCollection_, reco::CaloID::DET_ECAL_BARREL);
00095   }
00096 
00097   nEvt_++;
00098 }
00099 
00100 
00101 const EcalRecHitCollection * Multi5x5ClusterProducer::getCollection(edm::Event& evt,
00102                                                                   const std::string& hitProducer_,
00103                                                                   const std::string& hitCollection_)
00104 {
00105   edm::Handle<EcalRecHitCollection> rhcHandle;
00106   try
00107     {
00108       evt.getByLabel(hitProducer_, hitCollection_, rhcHandle);
00109       if (!(rhcHandle.isValid())) 
00110         {
00111           std::cout << "could not get a handle on the EcalRecHitCollection!" << std::endl;
00112           return 0;
00113         }
00114     }
00115   catch ( cms::Exception& ex ) 
00116     {
00117       edm::LogError("Multi5x5ClusterProducerError") << "Error! can't get the product " << hitCollection_.c_str() ;
00118       return 0;
00119     }
00120   return rhcHandle.product();
00121 }
00122 
00123 
00124 void Multi5x5ClusterProducer::clusterizeECALPart(edm::Event &evt, const edm::EventSetup &es,
00125                                                const std::string& hitProducer,
00126                                                const std::string& hitCollection,
00127                                                const std::string& clusterCollection,
00128                                                const reco::CaloID::Detectors detector)
00129 {
00130   // get the hit collection from the event:
00131   const EcalRecHitCollection *hitCollection_p = getCollection(evt, hitProducer, hitCollection);
00132 
00133   // get the geometry and topology from the event setup:
00134   edm::ESHandle<CaloGeometry> geoHandle;
00135   es.get<CaloGeometryRecord>().get(geoHandle);
00136 
00137   const CaloSubdetectorGeometry *geometry_p;
00138   CaloSubdetectorTopology *topology_p;
00139 
00140   if (detector == reco::CaloID::DET_ECAL_BARREL) 
00141     {
00142       geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
00143       topology_p = new EcalBarrelTopology(geoHandle);
00144     }
00145   else
00146     {
00147       geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
00148       topology_p = new EcalEndcapTopology(geoHandle); 
00149    }
00150 
00151   const CaloSubdetectorGeometry *geometryES_p;
00152   geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
00153 
00154   // Run the clusterization algorithm:
00155   reco::BasicClusterCollection clusters;
00156   clusters = island_p->makeClusters(hitCollection_p, geometry_p, topology_p, geometryES_p, detector);
00157 
00158   // create an auto_ptr to a BasicClusterCollection, copy the barrel clusters into it and put in the Event:
00159   std::auto_ptr< reco::BasicClusterCollection > clusters_p(new reco::BasicClusterCollection);
00160   clusters_p->assign(clusters.begin(), clusters.end());
00161   edm::OrphanHandle<reco::BasicClusterCollection> bccHandle;
00162   if (detector == reco::CaloID::DET_ECAL_BARREL) 
00163     bccHandle = evt.put(clusters_p, barrelClusterCollection_);
00164   else
00165     bccHandle = evt.put(clusters_p, endcapClusterCollection_);
00166 
00167   delete topology_p;
00168 }