CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/RecoEgamma/EgammaElectronProducers/plugins/SiStripElectronProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     EgammaElectronProducers
00004 // Class  :     SiStripElectronProducer
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  
00010 //         Created:  Fri May 26 16:11:30 EDT 2006
00011 // $Id: SiStripElectronProducer.cc,v 1.2 2007/08/28 01:42:29 ratnik Exp $
00012 //
00013 
00014 // system include files
00015 #include <memory>
00016 #include <sstream>
00017 
00018 // user include files
00019 #include "DataFormats/EgammaCandidates/interface/SiStripElectronFwd.h"
00020 #include "SiStripElectronProducer.h"
00021 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
00022 #include "DataFormats/RoadSearchCloud/interface/RoadSearchCloudCollection.h"
00023 #include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
00024 
00025 #include "FWCore/Framework/interface/Event.h"
00026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00028 
00029 #include "DataFormats/Common/interface/Handle.h"
00030 #include "FWCore/Framework/interface/ESHandle.h"
00031 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00032 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2DCollection.h"
00033 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2DCollection.h"
00034 #include "MagneticField/Engine/interface/MagneticField.h"
00035 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" 
00036 
00037 //
00038 // constants, enums and typedefs
00039 //
00040 
00041 //
00042 // static data member definitions
00043 //
00044 
00045 //
00046 // constructors and destructor
00047 //
00048 SiStripElectronProducer::SiStripElectronProducer(const edm::ParameterSet& iConfig)
00049 {
00050    // register your products
00051    siStripElectronsLabel_ = iConfig.getParameter<std::string>("siStripElectronsLabel");
00052    trackCandidatesLabel_ = iConfig.getParameter<std::string>("trackCandidatesLabel");
00053    produces<reco::SiStripElectronCollection>(siStripElectronsLabel_);
00054    produces<TrackCandidateCollection>(trackCandidatesLabel_);
00055 
00056    // get parameters
00057    siHitProducer_ = iConfig.getParameter<std::string>("siHitProducer");
00058    siRphiHitCollection_ = iConfig.getParameter<std::string>("siRphiHitCollection");
00059    siStereoHitCollection_ = iConfig.getParameter<std::string>("siStereoHitCollection");
00060    siMatchedHitCollection_ = iConfig.getParameter<std::string>("siMatchedHitCollection");
00061 
00062    superClusterProducer_ = iConfig.getParameter<std::string>("superClusterProducer");
00063    superClusterCollection_ = iConfig.getParameter<std::string>("superClusterCollection");
00064    
00065    algo_p = new SiStripElectronAlgo(
00066       iConfig.getParameter<int32_t>("maxHitsOnDetId"),
00067       iConfig.getParameter<double>("originUncertainty"),
00068       iConfig.getParameter<double>("phiBandWidth"),      // this is in radians
00069       iConfig.getParameter<double>("maxNormResid"),
00070       iConfig.getParameter<int32_t>("minHits"),
00071       iConfig.getParameter<double>("maxReducedChi2"));
00072 
00073    LogDebug("") << " Welcome to SiStripElectronProducer " ;
00074 
00075 }
00076 
00077 
00078 // SiStripElectronProducer::SiStripElectronProducer(const SiStripElectronProducer& rhs)
00079 // {
00080 //    // do actual copying here;
00081 // }
00082 
00083 SiStripElectronProducer::~SiStripElectronProducer()
00084 {
00085    // do anything here that needs to be done at desctruction time
00086    // (e.g. close files, deallocate resources etc.)
00087    delete algo_p;
00088 }
00089 
00090 //
00091 // assignment operators
00092 //
00093 // const SiStripElectronProducer& SiStripElectronProducer::operator=(const SiStripElectronProducer& rhs)
00094 // {
00095 //   //An exception safe implementation is
00096 //   SiStripElectronProducer temp(rhs);
00097 //   swap(rhs);
00098 //
00099 //   return *this;
00100 // }
00101 
00102 //
00103 // member functions
00104 //
00105 
00106 // ------------ method called to produce the data  ------------
00107 void
00108 SiStripElectronProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00109 {
00110    // Extract data from the event
00111    edm::ESHandle<TrackerGeometry> trackerHandle;
00112    iSetup.get<TrackerDigiGeometryRecord>().get(trackerHandle);
00113 
00114    edm::Handle<SiStripRecHit2DCollection> rphiHitsHandle;
00115    iEvent.getByLabel(siHitProducer_, siRphiHitCollection_, rphiHitsHandle);
00116 
00117    edm::Handle<SiStripRecHit2DCollection> stereoHitsHandle;
00118    iEvent.getByLabel(siHitProducer_, siStereoHitCollection_, stereoHitsHandle);
00119 
00120    edm::Handle<SiStripMatchedRecHit2DCollection> matchedHitsHandle;
00121    iEvent.getByLabel(siHitProducer_, siMatchedHitCollection_, matchedHitsHandle);
00122 
00123    edm::ESHandle<MagneticField> magneticFieldHandle;
00124    iSetup.get<IdealMagneticFieldRecord>().get(magneticFieldHandle);
00125 
00126    edm::Handle<reco::SuperClusterCollection> superClusterHandle;
00127    iEvent.getByLabel(superClusterProducer_, superClusterCollection_, superClusterHandle);
00128 
00129    // Set up SiStripElectronAlgo for this event
00130    algo_p->prepareEvent(trackerHandle, rphiHitsHandle, stereoHitsHandle, matchedHitsHandle, magneticFieldHandle);
00131 
00132    // Prepare the output electron candidates and clouds to be filled
00133    std::auto_ptr<reco::SiStripElectronCollection> electronOut(new reco::SiStripElectronCollection);
00134    std::auto_ptr<TrackCandidateCollection> trackCandidateOut(new TrackCandidateCollection);
00135 
00136    // counter for electron candidates
00137    int siStripElectCands = 0 ;
00138 
00139    std::ostringstream str;
00140 
00141 
00142    // Loop over clusters
00143    str << "Starting loop over superclusters."<< "\n" << std::endl;
00144    for (unsigned int i = 0;  i < superClusterHandle.product()->size();  i++) {
00145       const reco::SuperCluster* sc = &(*reco::SuperClusterRef(superClusterHandle, i));
00146       double energy = sc->energy();
00147 
00148       if (algo_p->findElectron(*electronOut, *trackCandidateOut, reco::SuperClusterRef(superClusterHandle, i))) {
00149         str << "Supercluster energy: " << energy << ", FOUND an electron." << "\n" << std::endl;
00150          ++siStripElectCands ;
00151       }
00152       else {
00153          str << "Supercluster energy: " << energy << ", DID NOT FIND an electron."<< "\n" << std::endl;
00154       }
00155    }
00156    str << "Ending loop over superclusters." << "\n" << std::endl;
00157    
00158    str << " Found " << siStripElectCands 
00159                     << " SiStripElectron Candidates before track fit " 
00160                     << "\n" << std::endl ;
00161 
00162    LogDebug("SiStripElectronProducer") << str.str();
00163 
00164    // Put the electron candidates and the tracking trajectories into the event
00165    iEvent.put(electronOut, siStripElectronsLabel_);
00166    iEvent.put(trackCandidateOut, trackCandidatesLabel_);
00167 }
00168 
00169 //
00170 // const member functions
00171 //
00172 
00173 //
00174 // static member functions
00175 //