CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoEcal/EgammaClusterProducers/src/PreshowerClusterShapeProducer.cc

Go to the documentation of this file.
00001 // system include files
00002 #include <vector>
00003 #include <memory>
00004 
00005 // user include files
00006 #include "FWCore/Framework/interface/Frameworkfwd.h"
00007 #include "FWCore/Framework/interface/EDAnalyzer.h"
00008 
00009 #include "FWCore/Framework/interface/Event.h"
00010 #include "FWCore/Framework/interface/EventSetup.h"
00011 #include "DataFormats/Common/interface/Handle.h"
00012 #include "FWCore/Framework/interface/ESHandle.h"
00013 #include "FWCore/Framework/interface/MakerMacros.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 #include "FWCore/Utilities/interface/Exception.h"
00016 
00017 // Reconstruction Classes
00018 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00019 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00020 
00021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00022 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00023 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00024 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00025 #include "Geometry/CaloGeometry/interface/TruncatedPyramid.h"
00026 #include "Geometry/EcalAlgo/interface/EcalPreshowerGeometry.h"
00027 #include "Geometry/CaloTopology/interface/EcalPreshowerTopology.h"
00028 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00029 #include "DataFormats/EcalDetId/interface/ESDetId.h"
00030 #include <fstream>
00031 #include <sstream>
00032 
00033 #include "RecoEcal/EgammaClusterProducers/interface/PreshowerClusterShapeProducer.h"
00034 
00035 using namespace std;
00036 using namespace reco;
00037 using namespace edm;
00039 
00040 PreshowerClusterShapeProducer::PreshowerClusterShapeProducer(const ParameterSet& ps) {
00041   // use configuration file to setup input/output collection names
00042   // Parameters to identify the hit collections
00043   preshHitProducer_   = ps.getParameter<edm::InputTag>("preshRecHitProducer");
00044   endcapSClusterProducer_   = ps.getParameter<edm::InputTag>("endcapSClusterProducer");
00045 
00046   PreshowerClusterShapeCollectionX_ = ps.getParameter<string>("PreshowerClusterShapeCollectionX");
00047   PreshowerClusterShapeCollectionY_ = ps.getParameter<string>("PreshowerClusterShapeCollectionY");
00048 
00049   produces< reco::PreshowerClusterShapeCollection >(PreshowerClusterShapeCollectionX_);
00050   produces< reco::PreshowerClusterShapeCollection >(PreshowerClusterShapeCollectionY_);
00051   
00052   float preshStripECut = ps.getParameter<double>("preshStripEnergyCut");
00053   int preshNst = ps.getParameter<int>("preshPi0Nstrip");
00054   
00055   string debugString = ps.getParameter<string>("debugLevel");
00056 
00057 
00058   string tmpPath = ps.getUntrackedParameter<string>("pathToWeightFiles","RecoEcal/EgammaClusterProducers/data/");
00059   
00060   presh_pi0_algo = new EndcapPiZeroDiscriminatorAlgo(preshStripECut, preshNst, tmpPath.c_str()); 
00061 
00062   LogTrace("EcalClusters") << "PreshowerClusterShapeProducer:presh_pi0_algo class instantiated " ;
00063   
00064   
00065   nEvt_ = 0;
00066 
00067 }
00068 
00069 
00070 PreshowerClusterShapeProducer::~PreshowerClusterShapeProducer() {
00071    delete presh_pi0_algo;
00072 }
00073 
00074 
00075 void PreshowerClusterShapeProducer::produce(Event& evt, const EventSetup& es) {
00076 
00077   ostringstream ostr; // use this stream for all messages in produce
00078 
00079   LogTrace("EcalClusters") << "\n .......  Event " << evt.id() << " with Number = " <<  nEvt_+1 << " is analyzing ....... " ;
00080 
00081 
00082   Handle< EcalRecHitCollection >   pRecHits;
00083   Handle< SuperClusterCollection > pSuperClusters;
00084 
00085   // get the ECAL -> Preshower geometry and topology:
00086   ESHandle<CaloGeometry> geoHandle;
00087   es.get<CaloGeometryRecord>().get(geoHandle);
00088   const CaloSubdetectorGeometry *geometry = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
00089   const CaloSubdetectorGeometry *& geometry_p = geometry;
00090 
00091 
00092   // create an auto_ptr to a PreshowerClusterShapeCollection
00093   std::auto_ptr< reco::PreshowerClusterShapeCollection > ps_cl_for_pi0_disc_x(new reco::PreshowerClusterShapeCollection);
00094   std::auto_ptr< reco::PreshowerClusterShapeCollection > ps_cl_for_pi0_disc_y(new reco::PreshowerClusterShapeCollection);
00095 
00096 
00097   CaloSubdetectorTopology* topology_p=0;
00098   if (geometry)
00099       topology_p = new EcalPreshowerTopology(geoHandle);
00100 
00101   
00102   // fetch the Preshower product (RecHits)
00103   evt.getByLabel( preshHitProducer_, pRecHits);
00104   // pointer to the object in the product
00105   const EcalRecHitCollection* rechits = pRecHits.product(); 
00106   
00107   LogTrace("EcalClusters") << "PreshowerClusterShapeProducer: ### Total # of preshower RecHits: " << rechits->size() ;
00108   
00109   //  if ( rechits->size() <= 0 ) return;
00110   
00111   // make the map of Preshower rechits:
00112   map<DetId, EcalRecHit> rechits_map;
00113   EcalRecHitCollection::const_iterator it;
00114   for (it = rechits->begin(); it != rechits->end(); it++) {
00115      rechits_map.insert(make_pair(it->id(), *it));
00116   }
00117   
00118   LogTrace("EcalClusters") << "PreshowerClusterShapeProducer: ### Preshower RecHits_map of size " << rechits_map.size() <<" was created!" ;
00119   
00120   reco::PreshowerClusterShapeCollection ps_cl_x, ps_cl_y;
00121 
00122   //make cycle over Photon Collection
00123   int SC_index  = 0;
00124 //  Handle<PhotonCollection> correctedPhotonHandle; 
00125 //  evt.getByLabel(photonCorrCollectionProducer_, correctedPhotonCollection_ , correctedPhotonHandle);
00126 //  const PhotonCollection corrPhoCollection = *(correctedPhotonHandle.product());
00127 //  cout << " Photon Collection size : " << corrPhoCollection.size() << endl;
00128 
00129   evt.getByLabel(endcapSClusterProducer_, pSuperClusters);
00130   const reco::SuperClusterCollection* SClusts = pSuperClusters.product();
00131   LogTrace("EcalClusters") << "### Total # Endcap Superclusters: " << SClusts->size() ;
00132 
00133   SuperClusterCollection::const_iterator it_s;
00134   for ( it_s=SClusts->begin();  it_s!=SClusts->end(); it_s++ ) {
00135 
00136       SuperClusterRef it_super(reco::SuperClusterRef(pSuperClusters,SC_index));
00137       
00138       float SC_Et   = it_super->energy()*sin(2*atan(exp(-it_super->eta())));
00139       float SC_eta  = it_super->eta();
00140       float SC_phi  = it_super->phi();
00141 
00142       LogTrace("EcalClusters") << "PreshowerClusterShapeProducer: superCl_E = " << it_super->energy() << " superCl_Et = " << SC_Et << " superCl_Eta = " << SC_eta << " superCl_Phi = " << SC_phi ;
00143 
00144       
00145       if(fabs(SC_eta) >= 1.65 && fabs(SC_eta) <= 2.5) 
00146         {  //  Use Preshower region only
00147           if (geometry)
00148             {
00149               const GlobalPoint pointSC(it_super->x(),it_super->y(),it_super->z()); // get the centroid of the SC
00150               LogTrace("EcalClusters") << "SC centroind = " << pointSC ;
00151               
00152               // Get the Preshower 2-planes RecHit vectors associated with the given SC
00153               
00154               DetId tmp_stripX = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(pointSC, 1);
00155               DetId tmp_stripY = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(pointSC, 2);
00156               ESDetId stripX = (tmp_stripX == DetId(0)) ? ESDetId(0) : ESDetId(tmp_stripX);
00157               ESDetId stripY = (tmp_stripY == DetId(0)) ? ESDetId(0) : ESDetId(tmp_stripY);
00158               
00159               vector<float> vout_stripE1 = presh_pi0_algo->findPreshVector(stripX, &rechits_map, topology_p);
00160               vector<float> vout_stripE2 = presh_pi0_algo->findPreshVector(stripY, &rechits_map, topology_p);
00161               
00162               LogTrace("EcalClusters") << "PreshowerClusterShapeProducer : ES Energy vector associated to the given SC = " ;
00163               for(int k1=0;k1<11;k1++) {
00164                 LogTrace("EcalClusters") << vout_stripE1[k1] << " " ;
00165               }
00166               
00167               for(int k1=0;k1<11;k1++) {
00168                 LogTrace("EcalClusters")  << vout_stripE2[k1] << " " ;
00169               } 
00170               
00171               reco::PreshowerClusterShape ps1 = reco::PreshowerClusterShape(vout_stripE1,1);
00172               ps1.setSCRef(it_super);
00173               ps_cl_x.push_back(ps1);
00174               
00175               reco::PreshowerClusterShape ps2 = reco::PreshowerClusterShape(vout_stripE2,2);
00176               ps2.setSCRef(it_super);
00177               ps_cl_y.push_back(ps2);
00178               
00179             }
00180           SC_index++;
00181         } // end of cycle over Endcap SC       
00182   } 
00183   // put collection of PreshowerClusterShape in the Event:
00184   ps_cl_for_pi0_disc_x->assign(ps_cl_x.begin(), ps_cl_x.end());
00185   ps_cl_for_pi0_disc_y->assign(ps_cl_y.begin(), ps_cl_y.end());
00186   
00187   evt.put(ps_cl_for_pi0_disc_x, PreshowerClusterShapeCollectionX_);
00188   evt.put(ps_cl_for_pi0_disc_y, PreshowerClusterShapeCollectionY_);  
00189   LogTrace("EcalClusters") << "PreshowerClusterShapeCollection added to the event" ;
00190   
00191   if (topology_p)
00192     delete topology_p;
00193 
00194   nEvt_++;
00195 
00196   LogDebug("PiZeroDiscriminatorDebug") << ostr.str();
00197 }