CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/RecoParticleFlow/PFClusterShapeProducer/plugins/PFClusterShapeProducer.cc

Go to the documentation of this file.
00001 #include "RecoParticleFlow/PFClusterShapeProducer/plugins/PFClusterShapeProducer.h"
00002 
00003 #include "FWCore/Framework/interface/EventSetup.h"
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 
00006 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00007 
00008 #include <sstream>
00009 
00010 using namespace edm;
00011 using namespace std;
00012 
00013 PFClusterShapeProducer::PFClusterShapeProducer(const edm::ParameterSet & ps)
00014 {
00015   shapesLabel_ = ps.getParameter<std::string>("PFClusterShapesLabel");
00016 
00017   inputTagPFClustersECAL_ 
00018     = ps.getParameter<InputTag>("PFClustersECAL");
00019   inputTagPFRecHitsECAL_ 
00020     = ps.getParameter<InputTag>("PFRecHitsECAL");
00021   
00022   csAlgo_p = new PFClusterShapeAlgo(ps.getParameter<bool>("useFractions"),
00023                                     ps.getParameter<double>("W0"));
00024 
00025   produces<reco::ClusterShapeCollection>(shapesLabel_);
00026   produces<reco::PFClusterShapeAssociationCollection>(shapesLabel_);
00027 }
00028 
00029 
00030 PFClusterShapeProducer::~PFClusterShapeProducer()
00031 {
00032   delete csAlgo_p;
00033 }
00034 
00035 
00036 void PFClusterShapeProducer::produce(edm::Event & evt, const edm::EventSetup & es)
00037 {
00038 
00039   edm::Handle<reco::PFClusterCollection> 
00040     clusterHandle = getClusterCollection(evt);
00041   edm::Handle<reco::PFRecHitCollection>
00042     rechitHandle = getRecHitCollection(evt);
00043 
00044   edm::ESHandle<CaloGeometry> geoHandle;
00045   es.get<CaloGeometryRecord>().get(geoHandle);
00046 
00047   const CaloSubdetectorGeometry * barrelGeo_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
00048   const CaloSubdetectorTopology * barrelTop_p = new EcalBarrelTopology(geoHandle);
00049   const CaloSubdetectorGeometry * endcapGeo_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
00050   const CaloSubdetectorTopology * endcapTop_p = new EcalEndcapTopology(geoHandle);
00051 
00052   std::auto_ptr<reco::ClusterShapeCollection> 
00053     csCollection_ap(csAlgo_p->makeClusterShapes(clusterHandle, rechitHandle, 
00054                                                 barrelGeo_p, barrelTop_p,
00055                                                 endcapGeo_p, endcapTop_p));
00056   
00057   edm::OrphanHandle<reco::ClusterShapeCollection> shape_h = evt.put(csCollection_ap, shapesLabel_);
00058   
00059   std::auto_ptr<reco::PFClusterShapeAssociationCollection> association_ap(new reco::PFClusterShapeAssociationCollection);
00060  
00061   for (unsigned int i = 0; i < clusterHandle->size(); i++){
00062     association_ap->insert(edm::Ref<reco::PFClusterCollection>(clusterHandle, i), 
00063                            edm::Ref<reco::ClusterShapeCollection>(shape_h, i));
00064   } 
00065   
00066   evt.put(association_ap, shapesLabel_);
00067 
00068   delete barrelTop_p;
00069   delete endcapTop_p;
00070 }
00071 
00072 
00073 edm::Handle<reco::PFClusterCollection>
00074 PFClusterShapeProducer::getClusterCollection(edm::Event & evt)
00075 {
00076   edm::Handle<reco::PFClusterCollection> handle;
00077   
00078   bool found = evt.getByLabel(inputTagPFClustersECAL_, handle);
00079   if (!found) {
00080     ostringstream err;
00081     err<<"cannot find clusters: "<<inputTagPFClustersECAL_;
00082     LogError("PFSimParticleProducer")<<err.str()<<endl;
00083     
00084     throw cms::Exception( "MissingProduct", err.str());
00085   }
00086 
00087   return handle;
00088 }
00089 
00090 
00091 
00092 edm::Handle<reco::PFRecHitCollection>
00093 PFClusterShapeProducer::getRecHitCollection(edm::Event & evt)
00094 {
00095   edm::Handle<reco::PFRecHitCollection> handle;
00096 
00097   bool found = evt.getByLabel(inputTagPFRecHitsECAL_, handle);
00098   if (!found) {
00099     ostringstream err;
00100     err<<"cannot find rechits: "<<inputTagPFRecHitsECAL_;
00101     LogError("PFSimParticleProducer")<<err.str()<<endl;
00102     
00103     throw cms::Exception( "MissingProduct", err.str());
00104   }
00105 
00106   return handle;
00107 }
00108