CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/RecoEcal/EgammaClusterProducers/src/CosmicClusterProducer.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/CosmicClusterProducer.h"
00038 
00039 CosmicClusterProducer::CosmicClusterProducer(const edm::ParameterSet& ps)
00040 {
00041   // The verbosity level
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   // 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   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   // 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>("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   // Parameters for the position calculation:
00074   edm::ParameterSet posCalcParameters = 
00075     ps.getParameter<edm::ParameterSet>("posCalcParameters");
00076 
00077   posCalculator_ = PositionCalc(posCalcParameters);
00078   shapeAlgo_ = ClusterShapeAlgo(posCalcParameters);
00079 
00080   clustershapecollectionEB_ = ps.getParameter<std::string>("clustershapecollectionEB");
00081   clustershapecollectionEE_ = ps.getParameter<std::string>("clustershapecollectionEE");
00082 
00083   //AssociationMap
00084   barrelClusterShapeAssociation_ = ps.getParameter<std::string>("barrelShapeAssociation");
00085   endcapClusterShapeAssociation_ = ps.getParameter<std::string>("endcapShapeAssociation");
00086 
00087   // Produces a collection of barrel and a collection of endcap clusters
00088 
00089   produces< reco::ClusterShapeCollection>(clustershapecollectionEE_);
00090   produces< reco::BasicClusterCollection >(endcapClusterCollection_);
00091   produces< reco::ClusterShapeCollection>(clustershapecollectionEB_);
00092   produces< reco::BasicClusterCollection >(barrelClusterCollection_);
00093   produces< reco::BasicClusterShapeAssociationCollection >(barrelClusterShapeAssociation_);
00094   produces< reco::BasicClusterShapeAssociationCollection >(endcapClusterShapeAssociation_);
00095 
00096   island_p = new CosmicClusterAlgo(barrelSeedThreshold, barrelSingleThreshold, barrelSecondThreshold, barrelSupThreshold, endcapSeedThreshold, endcapSingleThreshold, endcapSecondThreshold, endcapSupThreshold, posCalculator_,verbosity);
00097 
00098   nEvt_ = 0;
00099 }
00100 
00101 
00102 CosmicClusterProducer::~CosmicClusterProducer()
00103 {
00104   delete island_p;
00105 }
00106  
00107 
00108 void CosmicClusterProducer::produce(edm::Event& evt, const edm::EventSetup& es)
00109 {
00110   clusterizeECALPart(evt, es, endcapHitProducer_, endcapHitCollection_, endcapUHitProducer_, endcapUHitCollection_, endcapClusterCollection_, endcapClusterShapeAssociation_, CosmicClusterAlgo::endcap); 
00111   clusterizeECALPart(evt, es, barrelHitProducer_, barrelHitCollection_, barrelUHitProducer_, barrelUHitCollection_, barrelClusterCollection_, barrelClusterShapeAssociation_, CosmicClusterAlgo::barrel);
00112   nEvt_++;
00113 }
00114 
00115 
00116 const EcalRecHitCollection * CosmicClusterProducer::getCollection(edm::Event& evt,
00117                                                                   const std::string& hitProducer_,
00118                                                                   const std::string& hitCollection_)
00119 {
00120   edm::Handle<EcalRecHitCollection> rhcHandle;
00121   try
00122     {
00123       evt.getByLabel(hitProducer_, hitCollection_, rhcHandle);
00124       if (!(rhcHandle.isValid())) 
00125         {
00126           std::cout << "could not get a handle on the EcalRecHitCollection!" << std::endl;
00127           return 0;
00128         }
00129     }
00130   catch ( cms::Exception& ex ) 
00131     {
00132       edm::LogError("CosmicClusterProducerError") << "Error! can't get the product " << hitCollection_.c_str() ;
00133       return 0;
00134     }
00135   return rhcHandle.product();
00136 }
00137 
00138 const EcalUncalibratedRecHitCollection * CosmicClusterProducer::getUCollection(edm::Event& evt,
00139                                                                   const std::string& hitProducer_,
00140                                                                   const std::string& hitCollection_)
00141 {
00142   edm::Handle<EcalUncalibratedRecHitCollection> rhcHandle;
00143   try
00144     {
00145       evt.getByLabel(hitProducer_, hitCollection_, rhcHandle);
00146       if (!(rhcHandle.isValid())) 
00147         {
00148           std::cout << "could not get a handle on the EcalUncalibratedRecHitCollection!" << std::endl;
00149           return 0;
00150         }
00151     }
00152   catch ( cms::Exception& ex ) 
00153     {
00154       edm::LogError("CosmicClusterProducerError") << "Error! can't get the product " << hitCollection_.c_str() ;
00155       return 0;
00156     }
00157   return rhcHandle.product();
00158 }
00159 
00160 
00161 void CosmicClusterProducer::clusterizeECALPart(edm::Event &evt, const edm::EventSetup &es,
00162                                                const std::string& hitProducer,
00163                                                const std::string& hitCollection,
00164                                                                                            const std::string& uhitProducer,
00165                                                const std::string& uhitCollection,
00166                                                const std::string& clusterCollection,
00167                                                const std::string& clusterShapeAssociation,
00168                                                const CosmicClusterAlgo::EcalPart& ecalPart)
00169 {
00170   // get the hit collection from the event:
00171 
00172   const EcalRecHitCollection *hitCollection_p = getCollection(evt, hitProducer, hitCollection);
00173   const EcalUncalibratedRecHitCollection *uhitCollection_p = getUCollection(evt, uhitProducer, uhitCollection);
00174 
00175   // get the geometry and topology from the event setup:
00176   edm::ESHandle<CaloGeometry> geoHandle;
00177   es.get<CaloGeometryRecord>().get(geoHandle);
00178 
00179   const CaloSubdetectorGeometry *geometry_p;
00180   CaloSubdetectorTopology *topology_p;
00181 
00182   std::string clustershapetag;
00183   if (ecalPart == CosmicClusterAlgo::barrel) 
00184     {
00185       geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
00186       topology_p = new EcalBarrelTopology(geoHandle);
00187     }
00188   else
00189     {
00190       geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
00191       topology_p = new EcalEndcapTopology(geoHandle); 
00192    }
00193 
00194   const CaloSubdetectorGeometry *geometryES_p;
00195   geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower); 
00196   
00197   // Run the clusterization algorithm:
00198   reco::BasicClusterCollection clusters;
00199   clusters = island_p->makeClusters(hitCollection_p, uhitCollection_p, geometry_p, topology_p, geometryES_p,  ecalPart);
00200   
00201   //Create associated ClusterShape objects.
00202   std::vector <reco::ClusterShape> ClusVec;
00203  
00204   for (int erg=0;erg<int(clusters.size());++erg){
00205     reco::ClusterShape TestShape = shapeAlgo_.Calculate(clusters[erg],hitCollection_p,geometry_p,topology_p);
00206     ClusVec.push_back(TestShape);
00207   }
00208   
00209   //Put clustershapes in event, but retain a Handle on them.
00210   std::auto_ptr< reco::ClusterShapeCollection> clustersshapes_p(new reco::ClusterShapeCollection);
00211   clustersshapes_p->assign(ClusVec.begin(), ClusVec.end());
00212   edm::OrphanHandle<reco::ClusterShapeCollection> clusHandle; 
00213   if (ecalPart == CosmicClusterAlgo::barrel) 
00214     clusHandle= evt.put(clustersshapes_p, clustershapecollectionEB_);
00215   else
00216     clusHandle= evt.put(clustersshapes_p, clustershapecollectionEE_);
00217   
00218   // create an auto_ptr to a BasicClusterCollection, copy the barrel clusters into it and put in the Event:
00219   std::auto_ptr< reco::BasicClusterCollection > clusters_p(new reco::BasicClusterCollection);
00220   clusters_p->assign(clusters.begin(), clusters.end());
00221   edm::OrphanHandle<reco::BasicClusterCollection> bccHandle;
00222   
00223   if (ecalPart == CosmicClusterAlgo::barrel) 
00224     bccHandle = evt.put(clusters_p, barrelClusterCollection_);
00225   else
00226     bccHandle = evt.put(clusters_p, endcapClusterCollection_);
00227 
00228   
00229   // BasicClusterShapeAssociationMap 
00230   std::auto_ptr<reco::BasicClusterShapeAssociationCollection> shapeAssocs_p(new reco::BasicClusterShapeAssociationCollection);
00231   for (unsigned int i = 0; i < clusHandle->size(); i++){
00232     shapeAssocs_p->insert(edm::Ref<reco::BasicClusterCollection>(bccHandle,i),edm::Ref<reco::ClusterShapeCollection>(clusHandle,i));
00233   }  
00234   evt.put(shapeAssocs_p,clusterShapeAssociation);
00235   
00236   delete topology_p;
00237 }