CMS 3D CMS Logo

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