CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/RecoEcal/EgammaClusterProducers/src/ExampleClusterProducer.cc

Go to the documentation of this file.
00001 #include "RecoEcal/EgammaClusterProducers/interface/ExampleClusterProducer.h"
00002 #include "RecoEcal/EgammaClusterAlgos/interface/ExampleClusterAlgo.h"
00003 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00004 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00005 
00006 #include "DataFormats/Common/interface/Handle.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include "FWCore/Utilities/interface/Exception.h"
00009 
00010 #include <vector>
00011 
00012 ExampleClusterProducer::ExampleClusterProducer(const edm::ParameterSet& ps) {
00013 
00014 
00015   // use onfiguration file to setup input/output collection names
00016   nMaxPrintout_ = ps.getUntrackedParameter<int>("nMaxPrintout",1);
00017 
00018   hitProducer_   = ps.getParameter<std::string>("hitProducer");
00019   hitCollection_ = ps.getParameter<std::string>("hitCollection");
00020   clusterCollection_ = ps.getParameter<std::string>("clusterCollection");
00021 
00022 
00023   // configure your algorithm via ParameterSet
00024   double energyCut = ps.getUntrackedParameter<double>("energyCut",0.);
00025   int nXtalCut     = ps.getUntrackedParameter<int>("nXtalCut",-1);
00026 
00027   algo_ = new ExampleClusterAlgo(energyCut,nXtalCut);
00028 
00029 }
00030 
00031 ExampleClusterProducer::~ExampleClusterProducer() {
00032  delete algo_;
00033 }
00034 
00035 
00036 void
00037 ExampleClusterProducer::produce(edm::Event& evt, const edm::EventSetup& es) {
00038 
00039   using namespace edm;
00040 
00041   // handle to the product
00042   Handle< EcalRecHitCollection > pRecHits;
00043 
00044   // fetch the product
00045   evt.getByLabel( hitProducer_, hitCollection_, pRecHits);
00046   if (!pRecHits.isValid()) {
00047     edm::LogError("ExampleClusterProducerError") << "Error! can't get the product " << hitCollection_.c_str() ;
00048   }
00049 
00050   // pointer to the object in the product
00051   const EcalRecHitCollection* rechits = pRecHits.product();
00052   edm::LogInfo("ExampleClusterProducerInfo") << "total #  calibrated rechits: " << rechits->size() ;
00053 
00054   // output collection of basic clusters
00055   // reco::BasicClusterCollection defined in BasicClusterFwd.h
00056 
00057   // make the clusters by passing rechits to the agorithm
00058   std::auto_ptr< reco::BasicClusterCollection >  
00059     clusters(  new reco::BasicClusterCollection(algo_->makeClusters( *rechits )) );
00060 
00061   // put the product in the event
00062   evt.put( clusters, clusterCollection_ );
00063 }