CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoEcal/EgammaClusterProducers/src/HybridClusterProducer.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/MessageLogger/interface/MessageLogger.h"
00011 #include "FWCore/Framework/interface/ESHandle.h"
00012 
00013 // Reconstruction Classes
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 
00021 // Geometry
00022 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00023 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00024 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00025 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00026 #include "Geometry/CaloTopology/interface/EcalBarrelTopology.h"
00027 #include "Geometry/CaloTopology/interface/EcalEndcapTopology.h"
00028 #include "Geometry/CaloTopology/interface/EcalPreshowerTopology.h"
00029 
00030 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h"
00031 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
00032 
00033 // Class header file
00034 #include "RecoEcal/EgammaClusterProducers/interface/HybridClusterProducer.h"
00035 #include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
00036 
00037  
00038 
00039 HybridClusterProducer::HybridClusterProducer(const edm::ParameterSet& ps)
00040 {
00041 
00042     // The debug level
00043   std::string debugString = ps.getParameter<std::string>("debugLevel");
00044   if      (debugString == "DEBUG")   debugL = HybridClusterAlgo::pDEBUG;
00045   else if (debugString == "INFO")    debugL = HybridClusterAlgo::pINFO;
00046   else                               debugL = HybridClusterAlgo::pERROR;
00047 
00048   basicclusterCollection_ = ps.getParameter<std::string>("basicclusterCollection");
00049   superclusterCollection_ = ps.getParameter<std::string>("superclusterCollection");
00050   hitproducer_ = ps.getParameter<std::string>("ecalhitproducer");
00051   hitcollection_ =ps.getParameter<std::string>("ecalhitcollection");
00052    
00053   //Setup for core tools objects. 
00054   edm::ParameterSet posCalcParameters = 
00055     ps.getParameter<edm::ParameterSet>("posCalcParameters");
00056 
00057   posCalculator_ = PositionCalc(posCalcParameters);
00058 
00059   hybrid_p = new HybridClusterAlgo(ps.getParameter<double>("HybridBarrelSeedThr"), 
00060                                    ps.getParameter<int>("step"),
00061                                    ps.getParameter<double>("ethresh"),
00062                                    ps.getParameter<double>("eseed"),
00063                                    ps.getParameter<double>("ewing"),
00064                                    ps.getParameter<std::vector<int> >("RecHitFlagToBeExcluded"),
00065                                    posCalculator_,
00066                                    debugL,
00067                                    ps.getParameter<bool>("dynamicEThresh"),
00068                                    ps.getParameter<double>("eThreshA"),
00069                                    ps.getParameter<double>("eThreshB"),
00070                                    ps.getParameter<std::vector<int> >("RecHitSeverityToBeExcluded"),
00071                                    //ps.getParameter<double>("severityRecHitThreshold"),
00072                                    //ps.getParameter<int>("severitySpikeId"),
00073                                    //ps.getParameter<double>("severitySpikeThreshold"),
00074                                    ps.getParameter<bool>("excludeFlagged")
00075                                    );
00076                                    //bremRecoveryPset,
00077 
00078   // get brem recovery parameters
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   produces< reco::BasicClusterCollection >(basicclusterCollection_);
00086   produces< reco::SuperClusterCollection >(superclusterCollection_);
00087   nEvt_ = 0;
00088 }
00089 
00090 
00091 HybridClusterProducer::~HybridClusterProducer()
00092 {
00093   delete hybrid_p;
00094 }
00095 
00096 
00097 void HybridClusterProducer::produce(edm::Event& evt, const edm::EventSetup& es)
00098 {
00099   // get the hit collection from the event:
00100   edm::Handle<EcalRecHitCollection> rhcHandle;
00101   //  evt.getByType(rhcHandle);
00102   evt.getByLabel(hitproducer_, hitcollection_, rhcHandle);
00103   if (!(rhcHandle.isValid())) 
00104     {
00105       if (debugL <= HybridClusterAlgo::pINFO)
00106         std::cout << "could not get a handle on the EcalRecHitCollection!" << std::endl;
00107       return;
00108     }
00109   const EcalRecHitCollection *hit_collection = rhcHandle.product();
00110 
00111   // get the collection geometry:
00112   edm::ESHandle<CaloGeometry> geoHandle;
00113   es.get<CaloGeometryRecord>().get(geoHandle);
00114   const CaloGeometry& geometry = *geoHandle;
00115   const CaloSubdetectorGeometry *geometry_p;
00116   std::auto_ptr<const CaloSubdetectorTopology> topology;
00117 
00118   edm::ESHandle<EcalSeverityLevelAlgo> sevLv;
00119   es.get<EcalSeverityLevelAlgoRcd>().get(sevLv);
00120 
00121   if (debugL == HybridClusterAlgo::pDEBUG)
00122     std::cout << "\n\n\n" << hitcollection_ << "\n\n" << std::endl;
00123 
00124   if(hitcollection_ == "EcalRecHitsEB") {
00125     geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
00126     topology.reset(new EcalBarrelTopology(geoHandle));
00127   } else if(hitcollection_ == "EcalRecHitsEE") {
00128     geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
00129     topology.reset(new EcalEndcapTopology(geoHandle));
00130   } else if(hitcollection_ == "EcalRecHitsPS") {
00131     geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
00132     topology.reset(new EcalPreshowerTopology (geoHandle));
00133   } else throw(std::runtime_error("\n\nHybrid Cluster Producer encountered invalied ecalhitcollection type.\n\n"));
00134     
00135   // make the Basic clusters!
00136   reco::BasicClusterCollection basicClusters;
00137   hybrid_p->makeClusters(hit_collection, geometry_p, basicClusters, sevLv.product(),false,
00138                          std::vector<EcalEtaPhiRegion>());
00139 
00140   if (debugL == HybridClusterAlgo::pDEBUG)
00141     std::cout << "Finished clustering - BasicClusterCollection returned to producer..." << std::endl;
00142 
00143   // create an auto_ptr to a BasicClusterCollection, copy the clusters into it and put in the Event:
00144   std::auto_ptr< reco::BasicClusterCollection > basicclusters_p(new reco::BasicClusterCollection);
00145   basicclusters_p->assign(basicClusters.begin(), basicClusters.end());
00146   edm::OrphanHandle<reco::BasicClusterCollection> bccHandle =  evt.put(basicclusters_p, 
00147                                                                        basicclusterCollection_);
00148   //Basic clusters now in the event.
00149   if (debugL == HybridClusterAlgo::pDEBUG)
00150     std::cout << "Basic Clusters now put into event." << std::endl;
00151   
00152   //Weird though it is, get the BasicClusters back out of the event.  We need the
00153   //edm::Ref to these guys to make our superclusters for Hybrid.
00154   //edm::Handle<reco::BasicClusterCollection> bccHandle;
00155   // evt.getByLabel("clusterproducer",basicclusterCollection_, bccHandle);
00156   if (!(bccHandle.isValid())) {
00157     if (debugL <= HybridClusterAlgo::pINFO)
00158       std::cout << "could not get a handle on the BasicClusterCollection!" << std::endl;
00159     return;
00160   }
00161   reco::BasicClusterCollection clusterCollection = *bccHandle;
00162   if (debugL == HybridClusterAlgo::pDEBUG)
00163     std::cout << "Got the BasicClusterCollection" << std::endl;
00164 
00165   reco::CaloClusterPtrVector clusterPtrVector;
00166   for (unsigned int i = 0; i < clusterCollection.size(); i++){
00167     clusterPtrVector.push_back(reco::CaloClusterPtr(bccHandle, i));
00168   }
00169 
00170   reco::SuperClusterCollection superClusters = hybrid_p->makeSuperClusters(clusterPtrVector);
00171 
00172   if (debugL == HybridClusterAlgo::pDEBUG)
00173     std::cout << "Found: " << superClusters.size() << " superclusters." << std::endl;  
00174 
00175   std::auto_ptr< reco::SuperClusterCollection > superclusters_p(new reco::SuperClusterCollection);
00176   superclusters_p->assign(superClusters.begin(), superClusters.end());
00177   
00178   evt.put(superclusters_p, superclusterCollection_);
00179 
00180   if (debugL == HybridClusterAlgo::pDEBUG)
00181     std::cout << "Hybrid Clusters (Basic/Super) added to the Event! :-)" << std::endl;
00182 
00183   nEvt_++;
00184 }
00185