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/MessageLogger/interface/MessageLogger.h"
00011 #include "FWCore/Framework/interface/ESHandle.h"
00012
00013
00014 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00015 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00016 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00017 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00018 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00019 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
00020 #include "DataFormats/EgammaReco/interface/BasicClusterShapeAssociation.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/EcalBarrelTopology.h"
00028 #include "Geometry/CaloTopology/interface/EcalEndcapTopology.h"
00029 #include "Geometry/CaloTopology/interface/EcalPreshowerTopology.h"
00030
00031
00032 #include "RecoEcal/EgammaClusterProducers/interface/HybridClusterProducer.h"
00033 #include "RecoEcal/EgammaCoreTools/interface/ClusterShapeAlgo.h"
00034 #include "DataFormats/EgammaReco/interface/ClusterShape.h"
00035 #include "DataFormats/EgammaReco/interface/ClusterShapeFwd.h"
00036 #include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
00037
00038
00039
00040 HybridClusterProducer::HybridClusterProducer(const edm::ParameterSet& ps)
00041 {
00042
00043
00044 std::string debugString = ps.getParameter<std::string>("debugLevel");
00045 if (debugString == "DEBUG") debugL = HybridClusterAlgo::pDEBUG;
00046 else if (debugString == "INFO") debugL = HybridClusterAlgo::pINFO;
00047 else debugL = HybridClusterAlgo::pERROR;
00048
00049 basicclusterCollection_ = ps.getParameter<std::string>("basicclusterCollection");
00050 superclusterCollection_ = ps.getParameter<std::string>("superclusterCollection");
00051 hitproducer_ = ps.getParameter<std::string>("ecalhitproducer");
00052 hitcollection_ =ps.getParameter<std::string>("ecalhitcollection");
00053
00054
00055 std::map<std::string,double> providedParameters;
00056 providedParameters.insert(std::make_pair("LogWeighted",ps.getParameter<bool>("posCalc_logweight")));
00057 providedParameters.insert(std::make_pair("T0_barl",ps.getParameter<double>("posCalc_t0")));
00058 providedParameters.insert(std::make_pair("W0",ps.getParameter<double>("posCalc_w0")));
00059 providedParameters.insert(std::make_pair("X0",ps.getParameter<double>("posCalc_x0")));
00060
00061 posCalculator_ = PositionCalc(providedParameters);
00062 shapeAlgo_ = ClusterShapeAlgo(providedParameters);
00063
00064 hybrid_p = new HybridClusterAlgo(ps.getParameter<double>("HybridBarrelSeedThr"),
00065 ps.getParameter<int>("step"),
00066 ps.getParameter<double>("eseed"),
00067 ps.getParameter<double>("ewing"),
00068 ps.getParameter<double>("ethresh"),
00069 posCalculator_,
00070
00071 ps.getParameter<bool>("dynamicEThresh"),
00072 ps.getParameter<double>("eThreshA"),
00073 ps.getParameter<double>("eThreshB"),
00074
00075 debugL);
00076
00077
00078
00079 bool dynamicPhiRoad = ps.getParameter<bool>("dynamicPhiRoad");
00080 if (dynamicPhiRoad) {
00081 edm::ParameterSet bremRecoveryPset = ps.getParameter<edm::ParameterSet>("bremRecoveryPset");
00082 hybrid_p->setDynamicPhiRoad(bremRecoveryPset);
00083 }
00084
00085
00086 clustershapecollection_ = ps.getParameter<std::string>("clustershapecollection");
00087 clusterShapeAssociation_ = ps.getParameter<std::string>("shapeAssociation");
00088
00089 produces< reco::ClusterShapeCollection>(clustershapecollection_);
00090 produces< reco::BasicClusterCollection >(basicclusterCollection_);
00091 produces< reco::SuperClusterCollection >(superclusterCollection_);
00092 produces< reco::BasicClusterShapeAssociationCollection >(clusterShapeAssociation_);
00093 nEvt_ = 0;
00094 }
00095
00096
00097 HybridClusterProducer::~HybridClusterProducer()
00098 {
00099 delete hybrid_p;
00100 }
00101
00102
00103 void HybridClusterProducer::produce(edm::Event& evt, const edm::EventSetup& es)
00104 {
00105
00106 edm::Handle<EcalRecHitCollection> rhcHandle;
00107
00108 evt.getByLabel(hitproducer_, hitcollection_, rhcHandle);
00109 if (!(rhcHandle.isValid()))
00110 {
00111 if (debugL <= HybridClusterAlgo::pINFO)
00112 std::cout << "could not get a handle on the EcalRecHitCollection!" << std::endl;
00113 return;
00114 }
00115 const EcalRecHitCollection *hit_collection = rhcHandle.product();
00116
00117
00118 edm::ESHandle<CaloGeometry> geoHandle;
00119 es.get<CaloGeometryRecord>().get(geoHandle);
00120 const CaloGeometry& geometry = *geoHandle;
00121 const CaloSubdetectorGeometry *geometry_p;
00122 std::auto_ptr<const CaloSubdetectorTopology> topology;
00123
00124 if (debugL == HybridClusterAlgo::pDEBUG)
00125 std::cout << "\n\n\n" << hitcollection_ << "\n\n" << std::endl;
00126
00127 if(hitcollection_ == "EcalRecHitsEB") {
00128 geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
00129 topology.reset(new EcalBarrelTopology(geoHandle));
00130 } else if(hitcollection_ == "EcalRecHitsEE") {
00131 geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
00132 topology.reset(new EcalEndcapTopology(geoHandle));
00133 } else if(hitcollection_ == "EcalRecHitsPS") {
00134 geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
00135 topology.reset(new EcalPreshowerTopology (geoHandle));
00136 } else throw(std::runtime_error("\n\nHybrid Cluster Producer encountered invalied ecalhitcollection type.\n\n"));
00137
00138
00139 reco::BasicClusterCollection basicClusters;
00140 hybrid_p->makeClusters(hit_collection, geometry_p, basicClusters);
00141 if (debugL == HybridClusterAlgo::pDEBUG)
00142 std::cout << "Finished clustering - BasicClusterCollection returned to producer..." << std::endl;
00143
00144 std::vector <reco::ClusterShape> ClusVec;
00145 for (int erg=0;erg<int(basicClusters.size());++erg){
00146 reco::ClusterShape TestShape = shapeAlgo_.Calculate(basicClusters[erg],hit_collection,geometry_p,topology.get());
00147 ClusVec.push_back(TestShape);
00148 }
00149 std::auto_ptr< reco::ClusterShapeCollection> clustersshapes_p(new reco::ClusterShapeCollection);
00150 clustersshapes_p->assign(ClusVec.begin(), ClusVec.end());
00151 edm::OrphanHandle<reco::ClusterShapeCollection> clusHandle = evt.put(clustersshapes_p,
00152 clustershapecollection_);
00153
00154
00155 std::auto_ptr< reco::BasicClusterCollection > basicclusters_p(new reco::BasicClusterCollection);
00156 basicclusters_p->assign(basicClusters.begin(), basicClusters.end());
00157 edm::OrphanHandle<reco::BasicClusterCollection> bccHandle = evt.put(basicclusters_p,
00158 basicclusterCollection_);
00159
00160 if (debugL == HybridClusterAlgo::pDEBUG)
00161 std::cout << "Basic Clusters now put into event." << std::endl;
00162
00163
00164
00165
00166
00167 if (!(bccHandle.isValid())) {
00168 if (debugL <= HybridClusterAlgo::pINFO)
00169 std::cout << "could not get a handle on the BasicClusterCollection!" << std::endl;
00170 return;
00171 }
00172 reco::BasicClusterCollection clusterCollection = *bccHandle;
00173 if (debugL == HybridClusterAlgo::pDEBUG)
00174 std::cout << "Got the BasicClusterCollection" << std::endl;
00175
00176 reco::BasicClusterRefVector clusterRefVector;
00177 for (unsigned int i = 0; i < clusterCollection.size(); i++){
00178 clusterRefVector.push_back(reco::BasicClusterRef(bccHandle, i));
00179 }
00180
00181 reco::SuperClusterCollection superClusters = hybrid_p->makeSuperClusters(clusterRefVector);
00182
00183 if (debugL == HybridClusterAlgo::pDEBUG)
00184 std::cout << "Found: " << superClusters.size() << " superclusters." << std::endl;
00185
00186 std::auto_ptr< reco::SuperClusterCollection > superclusters_p(new reco::SuperClusterCollection);
00187 superclusters_p->assign(superClusters.begin(), superClusters.end());
00188
00189 evt.put(superclusters_p, superclusterCollection_);
00190
00191
00192 std::auto_ptr<reco::BasicClusterShapeAssociationCollection> shapeAssocs_p(new reco::BasicClusterShapeAssociationCollection);
00193 for (unsigned int i = 0; i < clusterCollection.size(); i++){
00194 shapeAssocs_p->insert(edm::Ref<reco::BasicClusterCollection>(bccHandle,i),edm::Ref<reco::ClusterShapeCollection>(clusHandle,i));
00195 }
00196
00197 evt.put(shapeAssocs_p,clusterShapeAssociation_);
00198
00199 if (debugL == HybridClusterAlgo::pDEBUG)
00200 std::cout << "Hybrid Clusters (Basic/Super) added to the Event! :-)" << std::endl;
00201
00202 nEvt_++;
00203 }
00204