CMS 3D CMS Logo

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   if      (debugString == "DEBUG")   debugL_pi0 = EndcapPiZeroDiscriminatorAlgo::pDEBUG;
00058   else if (debugString == "INFO")    debugL_pi0 = EndcapPiZeroDiscriminatorAlgo::pINFO;
00059   else                               debugL_pi0 = EndcapPiZeroDiscriminatorAlgo::pERROR;
00060 
00061   string tmpPath = ps.getUntrackedParameter<string>("pathToWeightFiles","RecoEcal/EgammaClusterProducers/data/");
00062   
00063   presh_pi0_algo = new EndcapPiZeroDiscriminatorAlgo(preshStripECut, preshNst, tmpPath.c_str(), debugL_pi0); 
00064 
00065   if ( debugL_pi0 == EndcapPiZeroDiscriminatorAlgo::pDEBUG ) 
00066                   cout << "PreshowerClusterShapeProducer:presh_pi0_algo class instantiated " << endl; 
00067   
00068   nEvt_ = 0;
00069 
00070 }
00071 
00072 
00073 PreshowerClusterShapeProducer::~PreshowerClusterShapeProducer() {
00074    delete presh_pi0_algo;
00075 }
00076 
00077 
00078 void PreshowerClusterShapeProducer::produce(Event& evt, const EventSetup& es) {
00079 
00080   ostringstream ostr; // use this stream for all messages in produce
00081 
00082   if ( debugL_pi0 <= EndcapPiZeroDiscriminatorAlgo::pDEBUG )
00083        cout << "\n .......  Event " << evt.id() << " with Number = " <<  nEvt_+1
00084             << " is analyzing ....... " << endl << endl;
00085 
00086   Handle< EcalRecHitCollection >   pRecHits;
00087   Handle< SuperClusterCollection > pSuperClusters;
00088 
00089   // get the ECAL -> Preshower geometry and topology:
00090   ESHandle<CaloGeometry> geoHandle;
00091   es.get<CaloGeometryRecord>().get(geoHandle);
00092   const CaloSubdetectorGeometry *geometry = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
00093   const CaloSubdetectorGeometry *& geometry_p = geometry;
00094 
00095 
00096   // create an auto_ptr to a PreshowerClusterShapeCollection
00097   std::auto_ptr< reco::PreshowerClusterShapeCollection > ps_cl_for_pi0_disc_x(new reco::PreshowerClusterShapeCollection);
00098   std::auto_ptr< reco::PreshowerClusterShapeCollection > ps_cl_for_pi0_disc_y(new reco::PreshowerClusterShapeCollection);
00099 
00100 
00101   CaloSubdetectorTopology* topology_p=0;
00102   if (geometry)
00103       topology_p = new EcalPreshowerTopology(geoHandle);
00104 
00105   
00106   // fetch the Preshower product (RecHits)
00107   evt.getByLabel( preshHitProducer_, pRecHits);
00108   // pointer to the object in the product
00109   const EcalRecHitCollection* rechits = pRecHits.product(); 
00110   
00111   if ( debugL_pi0 == EndcapPiZeroDiscriminatorAlgo::pDEBUG ) 
00112     cout << "PreshowerClusterShapeProducer: ### Total # of preshower RecHits: "
00113          << rechits->size() << endl;
00114   
00115   //  if ( rechits->size() <= 0 ) return;
00116   
00117   // make the map of Preshower rechits:
00118   map<DetId, EcalRecHit> rechits_map;
00119   EcalRecHitCollection::const_iterator it;
00120   for (it = rechits->begin(); it != rechits->end(); it++) {
00121      rechits_map.insert(make_pair(it->id(), *it));
00122   }
00123   if ( debugL_pi0 <= EndcapPiZeroDiscriminatorAlgo::pDEBUG ) cout
00124     << "PreshowerClusterShapeProducer: ### Preshower RecHits_map of size "
00125                                 << rechits_map.size() <<" was created!" << endl; 
00126   
00127   reco::PreshowerClusterShapeCollection ps_cl_x, ps_cl_y;
00128 
00129   //make cycle over Photon Collection
00130   int SC_index  = 0;
00131 //  Handle<PhotonCollection> correctedPhotonHandle; 
00132 //  evt.getByLabel(photonCorrCollectionProducer_, correctedPhotonCollection_ , correctedPhotonHandle);
00133 //  const PhotonCollection corrPhoCollection = *(correctedPhotonHandle.product());
00134 //  cout << " Photon Collection size : " << corrPhoCollection.size() << endl;
00135 
00136   evt.getByLabel(endcapSClusterProducer_, pSuperClusters);
00137   const reco::SuperClusterCollection* SClusts = pSuperClusters.product();
00138   if ( debugL_pi0 <= EndcapPiZeroDiscriminatorAlgo::pDEBUG ) cout <<"### Total # Endcap Superclusters: " << SClusts->size() << endl;
00139   SuperClusterCollection::const_iterator it_s;
00140   for ( it_s=SClusts->begin();  it_s!=SClusts->end(); it_s++ ) {
00141 
00142       SuperClusterRef it_super(reco::SuperClusterRef(pSuperClusters,SC_index));
00143       
00144       float SC_Et   = it_super->energy()*sin(2*atan(exp(-it_super->eta())));
00145       float SC_eta  = it_super->eta();
00146       float SC_phi  = it_super->phi();
00147 
00148       if ( debugL_pi0 <= EndcapPiZeroDiscriminatorAlgo::pDEBUG ) {
00149         cout << "PreshowerClusterShapeProducer: superCl_E = " << it_super->energy()
00150                   << " superCl_Et = " << SC_Et
00151                   << " superCl_Eta = " << SC_eta
00152                   << " superCl_Phi = " << SC_phi << endl;
00153       }                    
00154       
00155       if(fabs(SC_eta) >= 1.65 && fabs(SC_eta) <= 2.5) 
00156         {  //  Use Preshower region only
00157           if (geometry)
00158             {
00159               const GlobalPoint pointSC(it_super->x(),it_super->y(),it_super->z()); // get the centroid of the SC
00160               if ( debugL_pi0 <= EndcapPiZeroDiscriminatorAlgo::pDEBUG ) cout << "SC centroind = " << pointSC << endl;
00161               
00162               // Get the Preshower 2-planes RecHit vectors associated with the given SC
00163               
00164               DetId tmp_stripX = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(pointSC, 1);
00165               DetId tmp_stripY = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(pointSC, 2);
00166               ESDetId stripX = (tmp_stripX == DetId(0)) ? ESDetId(0) : ESDetId(tmp_stripX);
00167               ESDetId stripY = (tmp_stripY == DetId(0)) ? ESDetId(0) : ESDetId(tmp_stripY);
00168               
00169               vector<float> vout_stripE1 = presh_pi0_algo->findPreshVector(stripX, &rechits_map, topology_p);
00170               vector<float> vout_stripE2 = presh_pi0_algo->findPreshVector(stripY, &rechits_map, topology_p);
00171               
00172               if ( debugL_pi0 <= EndcapPiZeroDiscriminatorAlgo::pDEBUG ) {
00173                 cout  << "PreshowerClusterShapeProducer : ES Energy vector associated to the given SC = " ;
00174                 for(int k1=0;k1<11;k1++) {
00175                   cout  << vout_stripE1[k1] << " " ;
00176                 }
00177                 for(int k1=0;k1<11;k1++) {
00178                   cout  << vout_stripE2[k1] << " " ;
00179                 }           
00180                 cout  << endl;
00181               } 
00182               
00183               reco::PreshowerClusterShape ps1 = reco::PreshowerClusterShape(vout_stripE1,1);
00184               ps1.setSCRef(it_super);
00185               ps_cl_x.push_back(ps1);
00186               
00187               reco::PreshowerClusterShape ps2 = reco::PreshowerClusterShape(vout_stripE2,2);
00188               ps2.setSCRef(it_super);
00189               ps_cl_y.push_back(ps2);
00190               
00191             }
00192           SC_index++;
00193         } // end of cycle over Endcap SC       
00194   } 
00195   // put collection of PreshowerClusterShape in the Event:
00196   ps_cl_for_pi0_disc_x->assign(ps_cl_x.begin(), ps_cl_x.end());
00197   ps_cl_for_pi0_disc_y->assign(ps_cl_y.begin(), ps_cl_y.end());
00198   
00199   evt.put(ps_cl_for_pi0_disc_x, PreshowerClusterShapeCollectionX_);
00200   evt.put(ps_cl_for_pi0_disc_y, PreshowerClusterShapeCollectionY_);  
00201   
00202   if ( debugL_pi0 <= EndcapPiZeroDiscriminatorAlgo::pDEBUG ) cout << "PreshowerClusterShapeCollection added to the event" << endl;
00203 
00204   if (topology_p)
00205     delete topology_p;
00206 
00207   nEvt_++;
00208 
00209   LogDebug("PiZeroDiscriminatorDebug") << ostr.str();
00210 }

Generated on Tue Jun 9 17:43:15 2009 for CMSSW by  doxygen 1.5.4