Go to the documentation of this file.00001
00002 #include <iostream>
00003 #include <vector>
00004 #include <memory>
00005
00006
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
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
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
00031 #include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
00032
00033
00034 #include "RecoEcal/EgammaClusterProducers/interface/Multi5x5ClusterProducer.h"
00035
00036
00037 Multi5x5ClusterProducer::Multi5x5ClusterProducer(const edm::ParameterSet& ps)
00038 {
00039
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
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
00053 doEndcap_ = ps.getParameter<bool>("doEndcap");
00054 doBarrel_ = ps.getParameter<bool>("doBarrel");
00055
00056
00057 barrelClusterCollection_ = ps.getParameter<std::string>("barrelClusterCollection");
00058 endcapClusterCollection_ = ps.getParameter<std::string>("endcapClusterCollection");
00059
00060
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
00067 edm::ParameterSet posCalcParameters =
00068 ps.getParameter<edm::ParameterSet>("posCalcParameters");
00069 posCalculator_ = PositionCalc(posCalcParameters);
00070
00071
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
00131 const EcalRecHitCollection *hitCollection_p = getCollection(evt, hitProducer, hitCollection);
00132
00133
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
00155 reco::BasicClusterCollection clusters;
00156 clusters = island_p->makeClusters(hitCollection_p, geometry_p, topology_p, geometryES_p, detector);
00157
00158
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 }