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 #include "CommonTools/Utils/interface/StringToEnumValue.h"
00014
00015
00016 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00017 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00018 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00019 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00020 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
00021 #include "DataFormats/CaloRecHit/interface/CaloID.h"
00022
00023
00024 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00025 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00026 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00027 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00028 #include "Geometry/CaloTopology/interface/EcalEndcapTopology.h"
00029 #include "Geometry/CaloTopology/interface/EcalBarrelTopology.h"
00030
00031
00032 #include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
00033
00034
00035 #include "RecoEcal/EgammaClusterProducers/interface/Multi5x5ClusterProducer.h"
00036
00037
00038 Multi5x5ClusterProducer::Multi5x5ClusterProducer(const edm::ParameterSet& ps)
00039 {
00040
00041
00042 barrelHitProducer_ = ps.getParameter<std::string>("barrelHitProducer");
00043 endcapHitProducer_ = ps.getParameter<std::string>("endcapHitProducer");
00044 barrelHitCollection_ = ps.getParameter<std::string>("barrelHitCollection");
00045 endcapHitCollection_ = ps.getParameter<std::string>("endcapHitCollection");
00046
00047
00048 doEndcap_ = ps.getParameter<bool>("doEndcap");
00049 doBarrel_ = ps.getParameter<bool>("doBarrel");
00050
00051
00052 barrelClusterCollection_ = ps.getParameter<std::string>("barrelClusterCollection");
00053 endcapClusterCollection_ = ps.getParameter<std::string>("endcapClusterCollection");
00054
00055
00056 double barrelSeedThreshold = ps.getParameter<double>("IslandBarrelSeedThr");
00057 double endcapSeedThreshold = ps.getParameter<double>("IslandEndcapSeedThr");
00058
00059 const std::vector<std::string> flagnames =
00060 ps.getParameter<std::vector<std::string> >("RecHitFlagToBeExcluded");
00061
00062 const std::vector<int> v_chstatus=
00063 StringToEnumValue<EcalRecHit::Flags>(flagnames);
00064
00065
00066 edm::ParameterSet posCalcParameters =
00067 ps.getParameter<edm::ParameterSet>("posCalcParameters");
00068 posCalculator_ = PositionCalc(posCalcParameters);
00069
00070
00071 produces< reco::BasicClusterCollection >(endcapClusterCollection_);
00072 produces< reco::BasicClusterCollection >(barrelClusterCollection_);
00073
00074 island_p = new Multi5x5ClusterAlgo(barrelSeedThreshold, endcapSeedThreshold, v_chstatus, posCalculator_);
00075
00076 nEvt_ = 0;
00077 }
00078
00079
00080 Multi5x5ClusterProducer::~Multi5x5ClusterProducer()
00081 {
00082 delete island_p;
00083 }
00084
00085
00086 void Multi5x5ClusterProducer::produce(edm::Event& evt, const edm::EventSetup& es)
00087 {
00088
00089 if (doEndcap_) {
00090 clusterizeECALPart(evt, es, endcapHitProducer_, endcapHitCollection_, endcapClusterCollection_, reco::CaloID::DET_ECAL_ENDCAP);
00091 }
00092 if (doBarrel_) {
00093 clusterizeECALPart(evt, es, barrelHitProducer_, barrelHitCollection_, barrelClusterCollection_, reco::CaloID::DET_ECAL_BARREL);
00094 }
00095
00096 nEvt_++;
00097 }
00098
00099
00100 const EcalRecHitCollection * Multi5x5ClusterProducer::getCollection(edm::Event& evt,
00101 const std::string& hitProducer_,
00102 const std::string& hitCollection_)
00103 {
00104 edm::Handle<EcalRecHitCollection> rhcHandle;
00105 evt.getByLabel(hitProducer_, hitCollection_, rhcHandle);
00106 if (!(rhcHandle.isValid()))
00107 {
00108 edm::LogError("MissingProduct") << "could not get a handle on the EcalRecHitCollection! : " ;;
00109 return 0;
00110 }
00111
00112 return rhcHandle.product();
00113 }
00114
00115
00116 void Multi5x5ClusterProducer::clusterizeECALPart(edm::Event &evt, const edm::EventSetup &es,
00117 const std::string& hitProducer,
00118 const std::string& hitCollection,
00119 const std::string& clusterCollection,
00120 const reco::CaloID::Detectors detector)
00121 {
00122
00123 const EcalRecHitCollection *hitCollection_p = getCollection(evt, hitProducer, hitCollection);
00124
00125
00126 edm::ESHandle<CaloGeometry> geoHandle;
00127 es.get<CaloGeometryRecord>().get(geoHandle);
00128
00129 const CaloSubdetectorGeometry *geometry_p;
00130 CaloSubdetectorTopology *topology_p;
00131
00132 if (detector == reco::CaloID::DET_ECAL_BARREL)
00133 {
00134 geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
00135 topology_p = new EcalBarrelTopology(geoHandle);
00136 }
00137 else
00138 {
00139 geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
00140 topology_p = new EcalEndcapTopology(geoHandle);
00141 }
00142
00143 const CaloSubdetectorGeometry *geometryES_p;
00144 geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
00145
00146
00147 reco::BasicClusterCollection clusters;
00148 clusters = island_p->makeClusters(hitCollection_p, geometry_p, topology_p, geometryES_p, detector);
00149
00150
00151 std::auto_ptr< reco::BasicClusterCollection > clusters_p(new reco::BasicClusterCollection);
00152 clusters_p->assign(clusters.begin(), clusters.end());
00153 edm::OrphanHandle<reco::BasicClusterCollection> bccHandle;
00154 if (detector == reco::CaloID::DET_ECAL_BARREL)
00155 bccHandle = evt.put(clusters_p, barrelClusterCollection_);
00156 else
00157 bccHandle = evt.put(clusters_p, endcapClusterCollection_);
00158
00159 delete topology_p;
00160 }