CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/RecoEcal/EgammaClusterProducers/src/IslandClusterProducer.cc

Go to the documentation of this file.
00001 // C/C++ headers
00002 #include <iostream>
00003 #include <vector>
00004 #include <memory>
00005 
00006 // Framework
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 // Reconstruction Classes
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 // Geometry
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 // EgammaCoreTools
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 // Class header file
00037 #include "RecoEcal/EgammaClusterProducers/interface/IslandClusterProducer.h"
00038 
00039 
00040 IslandClusterProducer::IslandClusterProducer(const edm::ParameterSet& ps)
00041 {
00042   // The verbosity level
00043   std::string verbosityString = ps.getParameter<std::string>("VerbosityLevel");
00044   if      (verbosityString == "DEBUG")   verbosity = IslandClusterAlgo::pDEBUG;
00045   else if (verbosityString == "WARNING") verbosity = IslandClusterAlgo::pWARNING;
00046   else if (verbosityString == "INFO")    verbosity = IslandClusterAlgo::pINFO;
00047   else                                   verbosity = IslandClusterAlgo::pERROR;
00048 
00049   // Parameters to identify the hit collections
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 
00055   // The names of the produced cluster collections
00056   barrelClusterCollection_  = ps.getParameter<std::string>("barrelClusterCollection");
00057   endcapClusterCollection_  = ps.getParameter<std::string>("endcapClusterCollection");
00058 
00059   // Island algorithm parameters
00060   double barrelSeedThreshold = ps.getParameter<double>("IslandBarrelSeedThr");
00061   double endcapSeedThreshold = ps.getParameter<double>("IslandEndcapSeedThr");
00062 
00063   // Parameters for the position calculation:
00064    edm::ParameterSet posCalcParameters = 
00065     ps.getParameter<edm::ParameterSet>("posCalcParameters");
00066   posCalculator_ = PositionCalc(posCalcParameters);
00067   shapeAlgo_ = ClusterShapeAlgo(posCalcParameters);
00068 
00069   clustershapecollectionEB_ = ps.getParameter<std::string>("clustershapecollectionEB");
00070   clustershapecollectionEE_ = ps.getParameter<std::string>("clustershapecollectionEE");
00071 
00072   //AssociationMap
00073   barrelClusterShapeAssociation_ = ps.getParameter<std::string>("barrelShapeAssociation");
00074   endcapClusterShapeAssociation_ = ps.getParameter<std::string>("endcapShapeAssociation");
00075 
00076   // Produces a collection of barrel and a collection of endcap clusters
00077 
00078   produces< reco::ClusterShapeCollection>(clustershapecollectionEE_);
00079   produces< reco::BasicClusterCollection >(endcapClusterCollection_);
00080   produces< reco::ClusterShapeCollection>(clustershapecollectionEB_);
00081   produces< reco::BasicClusterCollection >(barrelClusterCollection_);
00082   produces< reco::BasicClusterShapeAssociationCollection >(barrelClusterShapeAssociation_);
00083   produces< reco::BasicClusterShapeAssociationCollection >(endcapClusterShapeAssociation_);
00084 
00085   island_p = new IslandClusterAlgo(barrelSeedThreshold, endcapSeedThreshold, posCalculator_,verbosity);
00086 
00087   nEvt_ = 0;
00088 }
00089 
00090 
00091 IslandClusterProducer::~IslandClusterProducer()
00092 {
00093   delete island_p;
00094 }
00095 
00096 
00097 void IslandClusterProducer::produce(edm::Event& evt, const edm::EventSetup& es)
00098 {
00099   clusterizeECALPart(evt, es, endcapHitProducer_, endcapHitCollection_, endcapClusterCollection_, endcapClusterShapeAssociation_, IslandClusterAlgo::endcap); 
00100   clusterizeECALPart(evt, es, barrelHitProducer_, barrelHitCollection_, barrelClusterCollection_, barrelClusterShapeAssociation_, IslandClusterAlgo::barrel);
00101   nEvt_++;
00102 }
00103 
00104 
00105 const EcalRecHitCollection * IslandClusterProducer::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       std::cout << "could not get a handle on the EcalRecHitCollection!" << std::endl;
00114       edm::LogError("IslandClusterProducerError") << "Error! can't get the product " << hitCollection_.c_str() ;
00115       return 0;
00116     } else {
00117     return rhcHandle.product();
00118   }
00119 }
00120 
00121 void IslandClusterProducer::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 std::string& clusterShapeAssociation,
00126                                                const IslandClusterAlgo::EcalPart& ecalPart)
00127 {
00128   // get the hit collection from the event:
00129   const EcalRecHitCollection *hitCollection_p = getCollection(evt, hitProducer, hitCollection);
00130 
00131   // get the geometry and topology from the event setup:
00132   edm::ESHandle<CaloGeometry> geoHandle;
00133   es.get<CaloGeometryRecord>().get(geoHandle);
00134 
00135   const CaloSubdetectorGeometry *geometry_p;
00136   CaloSubdetectorTopology *topology_p;
00137 
00138   std::string clustershapetag;
00139   if (ecalPart == IslandClusterAlgo::barrel) 
00140     {
00141       geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
00142       topology_p = new EcalBarrelTopology(geoHandle);
00143     }
00144   else
00145     {
00146       geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
00147       topology_p = new EcalEndcapTopology(geoHandle); 
00148    }
00149 
00150   const CaloSubdetectorGeometry *geometryES_p;
00151   geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
00152 
00153   // Run the clusterization algorithm:
00154   reco::BasicClusterCollection clusters;
00155   clusters = island_p->makeClusters(hitCollection_p, geometry_p, topology_p, geometryES_p, ecalPart);
00156 
00157   //Create associated ClusterShape objects.
00158   std::vector <reco::ClusterShape> ClusVec;
00159   for (int erg=0;erg<int(clusters.size());++erg){
00160     reco::ClusterShape TestShape = shapeAlgo_.Calculate(clusters[erg],hitCollection_p,geometry_p,topology_p);
00161     ClusVec.push_back(TestShape);
00162   }
00163 
00164   //Put clustershapes in event, but retain a Handle on them.
00165   std::auto_ptr< reco::ClusterShapeCollection> clustersshapes_p(new reco::ClusterShapeCollection);
00166   clustersshapes_p->assign(ClusVec.begin(), ClusVec.end());
00167   edm::OrphanHandle<reco::ClusterShapeCollection> clusHandle; 
00168   if (ecalPart == IslandClusterAlgo::barrel) 
00169     clusHandle= evt.put(clustersshapes_p, clustershapecollectionEB_);
00170   else
00171     clusHandle= evt.put(clustersshapes_p, clustershapecollectionEE_);
00172 
00173   // create an auto_ptr to a BasicClusterCollection, copy the barrel clusters into it and put in the Event:
00174   std::auto_ptr< reco::BasicClusterCollection > clusters_p(new reco::BasicClusterCollection);
00175   clusters_p->assign(clusters.begin(), clusters.end());
00176   edm::OrphanHandle<reco::BasicClusterCollection> bccHandle;
00177   if (ecalPart == IslandClusterAlgo::barrel) 
00178     bccHandle = evt.put(clusters_p, barrelClusterCollection_);
00179   else
00180     bccHandle = evt.put(clusters_p, endcapClusterCollection_);
00181 
00182 
00183   // BasicClusterShapeAssociationMap
00184   std::auto_ptr<reco::BasicClusterShapeAssociationCollection> shapeAssocs_p(new reco::BasicClusterShapeAssociationCollection);
00185   for (unsigned int i = 0; i < clusHandle->size(); i++){
00186     shapeAssocs_p->insert(edm::Ref<reco::BasicClusterCollection>(bccHandle,i),edm::Ref<reco::ClusterShapeCollection>(clusHandle,i));
00187   }  
00188   evt.put(shapeAssocs_p,clusterShapeAssociation);
00189 
00190   delete topology_p;
00191 }