CMS 3D CMS Logo

Multi5x5ClusterProducer.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/Multi5x5ClusterProducer.h"
00038 
00039 
00040 Multi5x5ClusterProducer::Multi5x5ClusterProducer(const edm::ParameterSet& ps)
00041 {
00042   // The verbosity level
00043   std::string verbosityString = ps.getParameter<std::string>("VerbosityLevel");
00044   if      (verbosityString == "DEBUG")   verbosity = Multi5x5ClusterAlgo::pDEBUG;
00045   else if (verbosityString == "WARNING") verbosity = Multi5x5ClusterAlgo::pWARNING;
00046   else if (verbosityString == "INFO")    verbosity = Multi5x5ClusterAlgo::pINFO;
00047   else                                   verbosity = Multi5x5ClusterAlgo::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   // should cluster algo be run in barrel and endcap?
00056   doEndcap_ = ps.getParameter<bool>("doEndcap");
00057   doBarrel_ = ps.getParameter<bool>("doBarrel");
00058 
00059   // The names of the produced cluster collections
00060   barrelClusterCollection_  = ps.getParameter<std::string>("barrelClusterCollection");
00061   endcapClusterCollection_  = ps.getParameter<std::string>("endcapClusterCollection");
00062 
00063   // Island algorithm parameters
00064   double barrelSeedThreshold = ps.getParameter<double>("IslandBarrelSeedThr");
00065   double endcapSeedThreshold = ps.getParameter<double>("IslandEndcapSeedThr");
00066 
00067   // Parameters for the position calculation:
00068   std::map<std::string,double> providedParameters;
00069   providedParameters.insert(std::make_pair("LogWeighted",ps.getParameter<bool>("posCalc_logweight")));
00070   providedParameters.insert(std::make_pair("T0_barl",ps.getParameter<double>("posCalc_t0_barl")));
00071   providedParameters.insert(std::make_pair("T0_endc",ps.getParameter<double>("posCalc_t0_endc")));
00072   providedParameters.insert(std::make_pair("T0_endcPresh",ps.getParameter<double>("posCalc_t0_endcPresh")));
00073   providedParameters.insert(std::make_pair("W0",ps.getParameter<double>("posCalc_w0")));
00074   providedParameters.insert(std::make_pair("X0",ps.getParameter<double>("posCalc_x0")));
00075   posCalculator_ = PositionCalc(providedParameters);
00076   shapeAlgo_ = ClusterShapeAlgo(providedParameters);
00077 
00078   clustershapecollectionEB_ = ps.getParameter<std::string>("clustershapecollectionEB");
00079   clustershapecollectionEE_ = ps.getParameter<std::string>("clustershapecollectionEE");
00080 
00081   //AssociationMap
00082   barrelClusterShapeAssociation_ = ps.getParameter<std::string>("barrelShapeAssociation");
00083   endcapClusterShapeAssociation_ = ps.getParameter<std::string>("endcapShapeAssociation");
00084 
00085   // Produces a collection of barrel and a collection of endcap clusters
00086 
00087   produces< reco::ClusterShapeCollection>(clustershapecollectionEE_);
00088   produces< reco::BasicClusterCollection >(endcapClusterCollection_);
00089   produces< reco::ClusterShapeCollection>(clustershapecollectionEB_);
00090   produces< reco::BasicClusterCollection >(barrelClusterCollection_);
00091   produces< reco::BasicClusterShapeAssociationCollection >(barrelClusterShapeAssociation_);
00092   produces< reco::BasicClusterShapeAssociationCollection >(endcapClusterShapeAssociation_);
00093 
00094   island_p = new Multi5x5ClusterAlgo(barrelSeedThreshold, endcapSeedThreshold, posCalculator_,verbosity);
00095 
00096   nEvt_ = 0;
00097 }
00098 
00099 
00100 Multi5x5ClusterProducer::~Multi5x5ClusterProducer()
00101 {
00102   delete island_p;
00103 }
00104 
00105 
00106 void Multi5x5ClusterProducer::produce(edm::Event& evt, const edm::EventSetup& es)
00107 {
00108 
00109   if (doEndcap_) {
00110     clusterizeECALPart(evt, es, endcapHitProducer_, endcapHitCollection_, endcapClusterCollection_, endcapClusterShapeAssociation_, Multi5x5ClusterAlgo::endcap); 
00111   }
00112   if (doBarrel_) {
00113     clusterizeECALPart(evt, es, barrelHitProducer_, barrelHitCollection_, barrelClusterCollection_, barrelClusterShapeAssociation_, Multi5x5ClusterAlgo::barrel);
00114   }
00115 
00116   nEvt_++;
00117 }
00118 
00119 
00120 const EcalRecHitCollection * Multi5x5ClusterProducer::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("Multi5x5ClusterProducerError") << "Error! can't get the product " << hitCollection_.c_str() ;
00137       return 0;
00138     }
00139   return rhcHandle.product();
00140 }
00141 
00142 
00143 void Multi5x5ClusterProducer::clusterizeECALPart(edm::Event &evt, const edm::EventSetup &es,
00144                                                const std::string& hitProducer,
00145                                                const std::string& hitCollection,
00146                                                const std::string& clusterCollection,
00147                                                const std::string& clusterShapeAssociation,
00148                                                const Multi5x5ClusterAlgo::EcalPart& ecalPart)
00149 {
00150   // get the hit collection from the event:
00151   const EcalRecHitCollection *hitCollection_p = getCollection(evt, hitProducer, hitCollection);
00152 
00153   // get the geometry and topology from the event setup:
00154   edm::ESHandle<CaloGeometry> geoHandle;
00155   es.get<CaloGeometryRecord>().get(geoHandle);
00156 
00157   const CaloSubdetectorGeometry *geometry_p;
00158   CaloSubdetectorTopology *topology_p;
00159 
00160   std::string clustershapetag;
00161   if (ecalPart == Multi5x5ClusterAlgo::barrel) 
00162     {
00163       geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
00164       topology_p = new EcalBarrelTopology(geoHandle);
00165     }
00166   else
00167     {
00168       geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
00169       topology_p = new EcalEndcapTopology(geoHandle); 
00170    }
00171 
00172   const CaloSubdetectorGeometry *geometryES_p;
00173   geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
00174 
00175   // Run the clusterization algorithm:
00176   reco::BasicClusterCollection clusters;
00177   clusters = island_p->makeClusters(hitCollection_p, geometry_p, topology_p, geometryES_p, ecalPart);
00178 
00179   //Create associated ClusterShape objects.
00180   std::vector <reco::ClusterShape> ClusVec;
00181   for (int erg=0;erg<int(clusters.size());++erg){
00182     reco::ClusterShape TestShape = shapeAlgo_.Calculate(clusters[erg],hitCollection_p,geometry_p,topology_p);
00183     ClusVec.push_back(TestShape);
00184   }
00185 
00186   //Put clustershapes in event, but retain a Handle on them.
00187   std::auto_ptr< reco::ClusterShapeCollection> clustersshapes_p(new reco::ClusterShapeCollection);
00188   clustersshapes_p->assign(ClusVec.begin(), ClusVec.end());
00189   edm::OrphanHandle<reco::ClusterShapeCollection> clusHandle; 
00190   if (ecalPart == Multi5x5ClusterAlgo::barrel) 
00191     clusHandle= evt.put(clustersshapes_p, clustershapecollectionEB_);
00192   else
00193     clusHandle= evt.put(clustersshapes_p, clustershapecollectionEE_);
00194 
00195   // create an auto_ptr to a BasicClusterCollection, copy the barrel clusters into it and put in the Event:
00196   std::auto_ptr< reco::BasicClusterCollection > clusters_p(new reco::BasicClusterCollection);
00197   clusters_p->assign(clusters.begin(), clusters.end());
00198   edm::OrphanHandle<reco::BasicClusterCollection> bccHandle;
00199   if (ecalPart == Multi5x5ClusterAlgo::barrel) 
00200     bccHandle = evt.put(clusters_p, barrelClusterCollection_);
00201   else
00202     bccHandle = evt.put(clusters_p, endcapClusterCollection_);
00203 
00204 
00205   // BasicClusterShapeAssociationMap
00206   std::auto_ptr<reco::BasicClusterShapeAssociationCollection> shapeAssocs_p(new reco::BasicClusterShapeAssociationCollection);
00207   for (unsigned int i = 0; i < clusHandle->size(); i++){
00208     shapeAssocs_p->insert(edm::Ref<reco::BasicClusterCollection>(bccHandle,i),edm::Ref<reco::ClusterShapeCollection>(clusHandle,i));
00209   }  
00210   evt.put(shapeAssocs_p,clusterShapeAssociation);
00211 
00212   delete topology_p;
00213 }

Generated on Tue Jun 9 17:43:15 2009 for CMSSW by  doxygen 1.5.4