CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/RecoEcal/EgammaClusterProducers/src/Multi5x5SuperClusterProducer.cc

Go to the documentation of this file.
00001 // C/C++ headers
00002 #include <iostream>
00003 #include <vector>
00004 #include <memory>
00005 #include <sstream>
00006 
00007 // Framework
00008 #include "FWCore/Framework/interface/Event.h"
00009 #include "FWCore/Framework/interface/EventSetup.h"
00010 #include "DataFormats/Common/interface/Handle.h"
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 #include "FWCore/Utilities/interface/Exception.h"
00013 
00014 // Reconstruction Classes
00015 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00016 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
00017 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00018 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00019 
00020 // Class header file
00021 #include "RecoEcal/EgammaClusterProducers/interface/Multi5x5SuperClusterProducer.h"
00022 
00023 
00024 Multi5x5SuperClusterProducer::Multi5x5SuperClusterProducer(const edm::ParameterSet& ps)
00025 {
00026 
00027   endcapClusterProducer_ = ps.getParameter<std::string>("endcapClusterProducer");
00028   barrelClusterProducer_ = ps.getParameter<std::string>("barrelClusterProducer");
00029 
00030   endcapClusterCollection_ = ps.getParameter<std::string>("endcapClusterCollection");
00031   barrelClusterCollection_ = ps.getParameter<std::string>("barrelClusterCollection");
00032 
00033   endcapSuperclusterCollection_ = ps.getParameter<std::string>("endcapSuperclusterCollection");
00034   barrelSuperclusterCollection_ = ps.getParameter<std::string>("barrelSuperclusterCollection");
00035 
00036   doBarrel_ = ps.getParameter<bool>("doBarrel");
00037   doEndcaps_ = ps.getParameter<bool>("doEndcaps");
00038 
00039   barrelEtaSearchRoad_ = ps.getParameter<double>("barrelEtaSearchRoad");
00040   barrelPhiSearchRoad_ = ps.getParameter<double>("barrelPhiSearchRoad");
00041   endcapEtaSearchRoad_ = ps.getParameter<double>("endcapEtaSearchRoad");
00042   endcapPhiSearchRoad_ = ps.getParameter<double>("endcapPhiSearchRoad");
00043   seedTransverseEnergyThreshold_ = ps.getParameter<double>("seedTransverseEnergyThreshold");
00044 
00045   const edm::ParameterSet bremRecoveryPset = ps.getParameter<edm::ParameterSet>("bremRecoveryPset");
00046   bool dynamicPhiRoad = ps.getParameter<bool>("dynamicPhiRoad");
00047 
00048   bremAlgo_p = new Multi5x5BremRecoveryClusterAlgo(bremRecoveryPset, barrelEtaSearchRoad_, barrelPhiSearchRoad_, 
00049                                          endcapEtaSearchRoad_, endcapPhiSearchRoad_, 
00050                                          dynamicPhiRoad, seedTransverseEnergyThreshold_);
00051 
00052   produces< reco::SuperClusterCollection >(endcapSuperclusterCollection_);
00053   produces< reco::SuperClusterCollection >(barrelSuperclusterCollection_);
00054 
00055   totalE = 0;
00056   noSuperClusters = 0;
00057   nEvt_ = 0;
00058 }
00059 
00060 
00061 Multi5x5SuperClusterProducer::~Multi5x5SuperClusterProducer()
00062 {
00063   delete bremAlgo_p;
00064 }
00065 
00066 void
00067 Multi5x5SuperClusterProducer::endJob() {
00068   double averEnergy = 0.;
00069   std::ostringstream str;
00070   str << "Multi5x5SuperClusterProducer::endJob()\n"
00071       << "  total # reconstructed super clusters: " << noSuperClusters << "\n"
00072       << "  total energy of all clusters: " << totalE << "\n";
00073   if(noSuperClusters>0) { 
00074     averEnergy = totalE / noSuperClusters;
00075     str << "  average SuperCluster energy = " << averEnergy << "\n";
00076   }
00077   edm::LogInfo("Multi5x5SuperClusterProducerInfo") << str.str() << "\n";
00078 
00079 }
00080 
00081 
00082 void Multi5x5SuperClusterProducer::produce(edm::Event& evt, const edm::EventSetup& es)
00083 {
00084   if(doEndcaps_)
00085     produceSuperclustersForECALPart(evt, endcapClusterProducer_, endcapClusterCollection_, endcapSuperclusterCollection_);
00086 
00087   if(doBarrel_)
00088     produceSuperclustersForECALPart(evt, barrelClusterProducer_, barrelClusterCollection_, barrelSuperclusterCollection_);
00089 
00090   nEvt_++;
00091 }
00092 
00093 
00094 void Multi5x5SuperClusterProducer::produceSuperclustersForECALPart(edm::Event& evt, 
00095                                                            std::string clusterProducer, 
00096                                                            std::string clusterCollection,
00097                                                            std::string superclusterCollection)
00098 {
00099   // get the cluster collection out and turn it to a BasicClusterRefVector:
00100   reco::CaloClusterPtrVector *clusterPtrVector_p = new reco::CaloClusterPtrVector;
00101   getClusterPtrVector(evt, clusterProducer, clusterCollection, clusterPtrVector_p);
00102 
00103   // run the brem recovery and get the SC collection
00104   std::auto_ptr<reco::SuperClusterCollection> 
00105     superclusters_ap(new reco::SuperClusterCollection(bremAlgo_p->makeSuperClusters(*clusterPtrVector_p)));
00106 
00107   // count the total energy and the number of superclusters
00108   reco::SuperClusterCollection::iterator it;
00109   for (it = superclusters_ap->begin(); it != superclusters_ap->end(); it++)
00110     {
00111       totalE += it->energy();
00112       noSuperClusters++;
00113     }
00114 
00115   // put the SC collection in the event
00116   evt.put(superclusters_ap, superclusterCollection);
00117 
00118   delete clusterPtrVector_p;
00119 }
00120 
00121 
00122 void Multi5x5SuperClusterProducer::getClusterPtrVector(edm::Event& evt, std::string clusterProducer_, std::string clusterCollection_, reco::CaloClusterPtrVector *clusterPtrVector_p)
00123 {  
00124   edm::Handle<reco::BasicClusterCollection> bccHandle;
00125   try
00126     {
00127       evt.getByLabel(clusterProducer_, clusterCollection_, bccHandle);
00128       if (!(bccHandle.isValid()))
00129         {
00130           edm::LogError("Multi5x5SuperClusterProducerError") << "could not get a handle on the BasicCluster Collection!";
00131           clusterPtrVector_p = 0;
00132         }
00133     } 
00134   catch ( cms::Exception& ex )
00135     {
00136       edm::LogError("Multi5x5SuperClusterProducerError") << "Error! can't get the product " << clusterCollection_.c_str(); 
00137       clusterPtrVector_p = 0;
00138     }
00139 
00140   const reco::BasicClusterCollection *clusterCollection_p = bccHandle.product();
00141   for (unsigned int i = 0; i < clusterCollection_p->size(); i++)
00142     {
00143       clusterPtrVector_p->push_back(reco::CaloClusterPtr(bccHandle, i));
00144     }
00145 }