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 bool reassignSeedCrysToClusterItSeeds=false;
00075 if(ps.exists("reassignSeedCrysToClusterItSeeds")) reassignSeedCrysToClusterItSeeds = ps.getParameter<bool>("reassignSeedCrysToClusterItSeeds");
00076
00077
00078
00079 island_p = new Multi5x5ClusterAlgo(barrelSeedThreshold, endcapSeedThreshold, v_chstatus, posCalculator_,reassignSeedCrysToClusterItSeeds);
00080
00081 nEvt_ = 0;
00082 }
00083
00084
00085 Multi5x5ClusterProducer::~Multi5x5ClusterProducer()
00086 {
00087 delete island_p;
00088 }
00089
00090
00091 void Multi5x5ClusterProducer::produce(edm::Event& evt, const edm::EventSetup& es)
00092 {
00093
00094 if (doEndcap_) {
00095 clusterizeECALPart(evt, es, endcapHitProducer_, endcapHitCollection_, endcapClusterCollection_, reco::CaloID::DET_ECAL_ENDCAP);
00096 }
00097 if (doBarrel_) {
00098 clusterizeECALPart(evt, es, barrelHitProducer_, barrelHitCollection_, barrelClusterCollection_, reco::CaloID::DET_ECAL_BARREL);
00099 }
00100
00101 nEvt_++;
00102 }
00103
00104
00105 const EcalRecHitCollection * Multi5x5ClusterProducer::getCollection(edm::Event& evt,
00106 const std::string& hitProducer_,
00107 const std::string& hitCollection_)
00108 {
00109 edm::Handle<EcalRecHitCollection> rhcHandle;
00110 evt.getByLabel(hitProducer_, hitCollection_, rhcHandle);
00111 if (!(rhcHandle.isValid()))
00112 {
00113 edm::LogError("MissingProduct") << "could not get a handle on the EcalRecHitCollection! : " ;;
00114 return 0;
00115 }
00116
00117 return rhcHandle.product();
00118 }
00119
00120
00121 void Multi5x5ClusterProducer::clusterizeECALPart(edm::Event &evt, const edm::EventSetup &es,
00122 const std::string& hitProducer,
00123 const std::string& hitCollection,
00124 const std::string& clusterCollection,
00125 const reco::CaloID::Detectors detector)
00126 {
00127
00128 const EcalRecHitCollection *hitCollection_p = getCollection(evt, hitProducer, hitCollection);
00129
00130
00131 edm::ESHandle<CaloGeometry> geoHandle;
00132 es.get<CaloGeometryRecord>().get(geoHandle);
00133
00134 const CaloSubdetectorGeometry *geometry_p;
00135 CaloSubdetectorTopology *topology_p;
00136
00137 if (detector == reco::CaloID::DET_ECAL_BARREL)
00138 {
00139 geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
00140 topology_p = new EcalBarrelTopology(geoHandle);
00141 }
00142 else
00143 {
00144 geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
00145 topology_p = new EcalEndcapTopology(geoHandle);
00146 }
00147
00148 const CaloSubdetectorGeometry *geometryES_p;
00149 geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
00150
00151
00152 reco::BasicClusterCollection clusters;
00153 clusters = island_p->makeClusters(hitCollection_p, geometry_p, topology_p, geometryES_p, detector);
00154
00155
00156 std::auto_ptr< reco::BasicClusterCollection > clusters_p(new reco::BasicClusterCollection);
00157 clusters_p->assign(clusters.begin(), clusters.end());
00158 edm::OrphanHandle<reco::BasicClusterCollection> bccHandle;
00159 if (detector == reco::CaloID::DET_ECAL_BARREL)
00160 bccHandle = evt.put(clusters_p, barrelClusterCollection_);
00161 else
00162 bccHandle = evt.put(clusters_p, endcapClusterCollection_);
00163
00164 delete topology_p;
00165 }