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/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/EcalEndcapTopology.h"
00028 #include "Geometry/CaloTopology/interface/EcalBarrelTopology.h"
00029
00030
00031 #include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
00032 #include "RecoEcal/EgammaCoreTools/interface/ClusterShapeAlgo.h"
00033 #include "DataFormats/EgammaReco/interface/ClusterShape.h"
00034 #include "DataFormats/EgammaReco/interface/ClusterShapeFwd.h"
00035
00036
00037 #include "RecoEcal/EgammaClusterProducers/interface/CosmicClusterProducer.h"
00038
00039 CosmicClusterProducer::CosmicClusterProducer(const edm::ParameterSet& ps)
00040 {
00041
00042 std::string verbosityString = ps.getParameter<std::string>("VerbosityLevel");
00043 if (verbosityString == "DEBUG") verbosity = CosmicClusterAlgo::pDEBUG;
00044 else if (verbosityString == "WARNING") verbosity = CosmicClusterAlgo::pWARNING;
00045 else if (verbosityString == "INFO") verbosity = CosmicClusterAlgo::pINFO;
00046 else verbosity = CosmicClusterAlgo::pERROR;
00047
00048
00049
00050 barrelHitProducer_ = ps.getParameter<std::string>("barrelHitProducer");
00051 endcapHitProducer_ = ps.getParameter<std::string>("endcapHitProducer");
00052 barrelHitCollection_ = ps.getParameter<std::string>("barrelHitCollection");
00053 endcapHitCollection_ = ps.getParameter<std::string>("endcapHitCollection");
00054 barrelUHitProducer_ = ps.getParameter<std::string>("barrelUnHitProducer");
00055 endcapUHitProducer_ = ps.getParameter<std::string>("endcapUnHitProducer");
00056 barrelUHitCollection_ = ps.getParameter<std::string>("barrelUnHitCollection");
00057 endcapUHitCollection_ = ps.getParameter<std::string>("endcapUnHitCollection");
00058
00059
00060 barrelClusterCollection_ = ps.getParameter<std::string>("barrelClusterCollection");
00061 endcapClusterCollection_ = ps.getParameter<std::string>("endcapClusterCollection");
00062
00063
00064 double barrelSeedThreshold = ps.getParameter<double>("BarrelSeedThr");
00065 double barrelSingleThreshold = ps.getParameter<double>("BarrelSingleThr");
00066 double barrelSecondThreshold = ps.getParameter<double>("BarrelSecondThr");
00067 double barrelSupThreshold = ps.getParameter<double>("BarrelSupThr");
00068 double endcapSeedThreshold = ps.getParameter<double>("EndcapSeedThr");
00069 double endcapSingleThreshold = ps.getParameter<double>("EndcapSingleThr");
00070 double endcapSecondThreshold = ps.getParameter<double>("EndcapSecondThr");
00071 double endcapSupThreshold = ps.getParameter<double>("EndcapSupThr");
00072
00073
00074 std::map<std::string,double> providedParameters;
00075 providedParameters.insert(std::make_pair("LogWeighted",ps.getParameter<bool>("posCalc_logweight")));
00076 providedParameters.insert(std::make_pair("T0_barl",ps.getParameter<double>("posCalc_t0_barl")));
00077 providedParameters.insert(std::make_pair("T0_endc",ps.getParameter<double>("posCalc_t0_endc")));
00078 providedParameters.insert(std::make_pair("T0_endcPresh",ps.getParameter<double>("posCalc_t0_endcPresh")));
00079 providedParameters.insert(std::make_pair("W0",ps.getParameter<double>("posCalc_w0")));
00080 providedParameters.insert(std::make_pair("X0",ps.getParameter<double>("posCalc_x0")));
00081 posCalculator_ = PositionCalc(providedParameters);
00082 shapeAlgo_ = ClusterShapeAlgo(providedParameters);
00083
00084 clustershapecollectionEB_ = ps.getParameter<std::string>("clustershapecollectionEB");
00085 clustershapecollectionEE_ = ps.getParameter<std::string>("clustershapecollectionEE");
00086
00087
00088 barrelClusterShapeAssociation_ = ps.getParameter<std::string>("barrelShapeAssociation");
00089 endcapClusterShapeAssociation_ = ps.getParameter<std::string>("endcapShapeAssociation");
00090
00091
00092
00093 produces< reco::ClusterShapeCollection>(clustershapecollectionEE_);
00094 produces< reco::BasicClusterCollection >(endcapClusterCollection_);
00095 produces< reco::ClusterShapeCollection>(clustershapecollectionEB_);
00096 produces< reco::BasicClusterCollection >(barrelClusterCollection_);
00097 produces< reco::BasicClusterShapeAssociationCollection >(barrelClusterShapeAssociation_);
00098 produces< reco::BasicClusterShapeAssociationCollection >(endcapClusterShapeAssociation_);
00099
00100 island_p = new CosmicClusterAlgo(barrelSeedThreshold, barrelSingleThreshold, barrelSecondThreshold, barrelSupThreshold, endcapSeedThreshold, endcapSingleThreshold, endcapSecondThreshold, endcapSupThreshold, posCalculator_,verbosity);
00101
00102 nEvt_ = 0;
00103 }
00104
00105
00106 CosmicClusterProducer::~CosmicClusterProducer()
00107 {
00108 delete island_p;
00109 }
00110
00111
00112 void CosmicClusterProducer::produce(edm::Event& evt, const edm::EventSetup& es)
00113 {
00114 clusterizeECALPart(evt, es, endcapHitProducer_, endcapHitCollection_, endcapUHitProducer_, endcapUHitCollection_, endcapClusterCollection_, endcapClusterShapeAssociation_, CosmicClusterAlgo::endcap);
00115 clusterizeECALPart(evt, es, barrelHitProducer_, barrelHitCollection_, barrelUHitProducer_, barrelUHitCollection_, barrelClusterCollection_, barrelClusterShapeAssociation_, CosmicClusterAlgo::barrel);
00116 nEvt_++;
00117 }
00118
00119
00120 const EcalRecHitCollection * CosmicClusterProducer::getCollection(edm::Event& evt,
00121 const std::string& hitProducer_,
00122 const std::string& hitCollection_)
00123 {
00124 edm::Handle<EcalRecHitCollection> rhcHandle;
00125 try
00126 {
00127 evt.getByLabel(hitProducer_, hitCollection_, rhcHandle);
00128 if (!(rhcHandle.isValid()))
00129 {
00130 std::cout << "could not get a handle on the EcalRecHitCollection!" << std::endl;
00131 return 0;
00132 }
00133 }
00134 catch ( cms::Exception& ex )
00135 {
00136 edm::LogError("CosmicClusterProducerError") << "Error! can't get the product " << hitCollection_.c_str() ;
00137 return 0;
00138 }
00139 return rhcHandle.product();
00140 }
00141
00142 const EcalUncalibratedRecHitCollection * CosmicClusterProducer::getUCollection(edm::Event& evt,
00143 const std::string& hitProducer_,
00144 const std::string& hitCollection_)
00145 {
00146 edm::Handle<EcalUncalibratedRecHitCollection> rhcHandle;
00147 try
00148 {
00149 evt.getByLabel(hitProducer_, hitCollection_, rhcHandle);
00150 if (!(rhcHandle.isValid()))
00151 {
00152 std::cout << "could not get a handle on the EcalUncalibratedRecHitCollection!" << std::endl;
00153 return 0;
00154 }
00155 }
00156 catch ( cms::Exception& ex )
00157 {
00158 edm::LogError("CosmicClusterProducerError") << "Error! can't get the product " << hitCollection_.c_str() ;
00159 return 0;
00160 }
00161 return rhcHandle.product();
00162 }
00163
00164
00165 void CosmicClusterProducer::clusterizeECALPart(edm::Event &evt, const edm::EventSetup &es,
00166 const std::string& hitProducer,
00167 const std::string& hitCollection,
00168 const std::string& uhitProducer,
00169 const std::string& uhitCollection,
00170 const std::string& clusterCollection,
00171 const std::string& clusterShapeAssociation,
00172 const CosmicClusterAlgo::EcalPart& ecalPart)
00173 {
00174
00175
00176 const EcalRecHitCollection *hitCollection_p = getCollection(evt, hitProducer, hitCollection);
00177 const EcalUncalibratedRecHitCollection *uhitCollection_p = getUCollection(evt, uhitProducer, uhitCollection);
00178
00179
00180 edm::ESHandle<CaloGeometry> geoHandle;
00181 es.get<CaloGeometryRecord>().get(geoHandle);
00182
00183 const CaloSubdetectorGeometry *geometry_p;
00184 CaloSubdetectorTopology *topology_p;
00185
00186 std::string clustershapetag;
00187 if (ecalPart == CosmicClusterAlgo::barrel)
00188 {
00189 geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
00190 topology_p = new EcalBarrelTopology(geoHandle);
00191 }
00192 else
00193 {
00194 geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
00195 topology_p = new EcalEndcapTopology(geoHandle);
00196 }
00197
00198 const CaloSubdetectorGeometry *geometryES_p;
00199 geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
00200
00201
00202 reco::BasicClusterCollection clusters;
00203 clusters = island_p->makeClusters(hitCollection_p, uhitCollection_p, geometry_p, topology_p, geometryES_p, ecalPart);
00204
00205
00206 std::vector <reco::ClusterShape> ClusVec;
00207
00208 for (int erg=0;erg<int(clusters.size());++erg){
00209 reco::ClusterShape TestShape = shapeAlgo_.Calculate(clusters[erg],hitCollection_p,geometry_p,topology_p);
00210 ClusVec.push_back(TestShape);
00211 }
00212
00213
00214 std::auto_ptr< reco::ClusterShapeCollection> clustersshapes_p(new reco::ClusterShapeCollection);
00215 clustersshapes_p->assign(ClusVec.begin(), ClusVec.end());
00216 edm::OrphanHandle<reco::ClusterShapeCollection> clusHandle;
00217 if (ecalPart == CosmicClusterAlgo::barrel)
00218 clusHandle= evt.put(clustersshapes_p, clustershapecollectionEB_);
00219 else
00220 clusHandle= evt.put(clustersshapes_p, clustershapecollectionEE_);
00221
00222
00223 std::auto_ptr< reco::BasicClusterCollection > clusters_p(new reco::BasicClusterCollection);
00224 clusters_p->assign(clusters.begin(), clusters.end());
00225 edm::OrphanHandle<reco::BasicClusterCollection> bccHandle;
00226
00227 if (ecalPart == CosmicClusterAlgo::barrel)
00228 bccHandle = evt.put(clusters_p, barrelClusterCollection_);
00229 else
00230 bccHandle = evt.put(clusters_p, endcapClusterCollection_);
00231
00232
00233
00234 std::auto_ptr<reco::BasicClusterShapeAssociationCollection> shapeAssocs_p(new reco::BasicClusterShapeAssociationCollection);
00235 for (unsigned int i = 0; i < clusHandle->size(); i++){
00236 shapeAssocs_p->insert(edm::Ref<reco::BasicClusterCollection>(bccHandle,i),edm::Ref<reco::ClusterShapeCollection>(clusHandle,i));
00237 }
00238 evt.put(shapeAssocs_p,clusterShapeAssociation);
00239
00240 delete topology_p;
00241 }