CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoEcal/EgammaClusterProducers/src/ReducedESRecHitCollectionProducer.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/Event.h"
00002 #include "FWCore/Framework/interface/EventSetup.h"
00003 #include "FWCore/Framework/interface/ESHandle.h"
00004 #include "FWCore/Utilities/interface/Exception.h"
00005 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00006 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00007 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00008 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00009 #include "Geometry/EcalAlgo/interface/EcalPreshowerGeometry.h"
00010 #include "Geometry/CaloTopology/interface/EcalPreshowerTopology.h"
00011 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00012 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00013 #include "RecoCaloTools/Navigation/interface/EcalPreshowerNavigator.h"
00014 #include "RecoEcal/EgammaClusterProducers/interface/ReducedESRecHitCollectionProducer.h"
00015 #include "DataFormats/DetId/interface/DetIdCollection.h"
00016 
00017 ReducedESRecHitCollectionProducer::ReducedESRecHitCollectionProducer(const edm::ParameterSet& ps):
00018   geometry_p(0),
00019   topology_p(0)
00020 {
00021 
00022  scEtThresh_          = ps.getParameter<double>("scEtThreshold");
00023 
00024  InputRecHitES_       = ps.getParameter<edm::InputTag>("EcalRecHitCollectionES");
00025  InputSpuerClusterEE_ = ps.getParameter<edm::InputTag>("EndcapSuperClusterCollection"); 
00026 
00027  OutputLabelES_       = ps.getParameter<std::string>("OutputLabel_ES");
00028  
00029  interestingDetIdCollections_         = ps.getParameter<std::vector< edm::InputTag> >("interestingDetIds");
00030  
00031  produces< EcalRecHitCollection > (OutputLabelES_);
00032  
00033 }
00034 
00035 ReducedESRecHitCollectionProducer::~ReducedESRecHitCollectionProducer() {
00036   if (topology_p) delete topology_p;
00037 }
00038 
00039 void ReducedESRecHitCollectionProducer::beginRun (edm::Run &, const edm::EventSetup&iSetup){
00040   ESHandle<CaloGeometry> geoHandle;
00041   iSetup.get<CaloGeometryRecord>().get(geoHandle);
00042   const CaloSubdetectorGeometry *geometry = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
00043   geometry_p = dynamic_cast<const EcalPreshowerGeometry *>(geometry);
00044   if (!geometry_p){
00045     edm::LogError("WrongGeometry")<<
00046       "could not cast the subdet geometry to preshower geometry";
00047   }
00048   
00049   if (geometry) topology_p = new EcalPreshowerTopology(geoHandle);
00050   
00051 }
00052 
00053 void ReducedESRecHitCollectionProducer::produce(edm::Event & e, const edm::EventSetup& iSetup){
00054 
00055 
00056   edm::Handle<ESRecHitCollection> ESRecHits_;
00057   e.getByLabel(InputRecHitES_, ESRecHits_);
00058   
00059   std::auto_ptr<EcalRecHitCollection> output(new EcalRecHitCollection);
00060 
00061   edm::Handle<reco::SuperClusterCollection> pEndcapSuperClusters;
00062   e.getByLabel(InputSpuerClusterEE_, pEndcapSuperClusters);
00063   {
00064     const reco::SuperClusterCollection* eeSuperClusters = pEndcapSuperClusters.product();
00065     
00066     for (reco::SuperClusterCollection::const_iterator isc = eeSuperClusters->begin(); isc != eeSuperClusters->end(); ++isc) {
00067 
00068       if (isc->energy() < scEtThresh_) continue;
00069       if (fabs(isc->eta()) < 1.65 || fabs(isc->eta()) > 2.6) continue;
00070       //cout<<"SC energy : "<<isc->energy()<<" "<<isc->eta()<<endl;
00071 
00072       //Int_t nBC = 0;
00073       reco::CaloCluster_iterator ibc = isc->clustersBegin();
00074       for ( ; ibc != isc->clustersEnd(); ++ibc ) {  
00075 
00076         //cout<<"BC : "<<nBC<<endl;
00077 
00078         const GlobalPoint point((*ibc)->x(),(*ibc)->y(),(*ibc)->z());
00079 
00080         ESDetId esId1 = geometry_p->getClosestCellInPlane(point, 1);
00081         ESDetId esId2 = geometry_p->getClosestCellInPlane(point, 2);
00082         
00083         collectIds(esId1, esId2, 0);
00084         collectIds(esId1, esId2, 1);
00085         collectIds(esId1, esId2, -1);
00086 
00087         //nBC++;
00088       }
00089       
00090     }
00091     
00092   }
00093 
00094 
00095   edm::Handle<DetIdCollection > detId;
00096   for( unsigned int t = 0; t < interestingDetIdCollections_.size(); ++t )
00097     {
00098       e.getByLabel(interestingDetIdCollections_[t],detId);
00099       if (!detId.isValid()){
00100         edm::LogError("MissingInput")<<"the collection of interesting detIds:"<<interestingDetIdCollections_[t]<<" is not found.";
00101         continue;
00102       }
00103       collectedIds_.insert(detId->begin(),detId->end());
00104     }
00105 
00106 
00107   output->reserve( collectedIds_.size());
00108   EcalRecHitCollection::const_iterator it;
00109   for (it = ESRecHits_->begin(); it != ESRecHits_->end(); ++it) {
00110     if (it->recoFlag()==1 || it->recoFlag()==14 || (it->recoFlag()<=10 && it->recoFlag()>=5)) continue;
00111     if (collectedIds_.find(it->id())!=collectedIds_.end()){
00112       output->push_back(*it);
00113     }
00114   }
00115   collectedIds_.clear();
00116 
00117   e.put(output, OutputLabelES_);
00118 
00119 }
00120 
00121 void ReducedESRecHitCollectionProducer::collectIds(const ESDetId esDetId1, const ESDetId esDetId2, const int & row) {
00122 
00123   //cout<<row<<endl;
00124   
00125   map<DetId,const EcalRecHit*>::iterator it;
00126   map<DetId, int>::iterator itu;
00127   ESDetId next;
00128   ESDetId strip1;
00129   ESDetId strip2;
00130 
00131   strip1 = esDetId1;
00132   strip2 = esDetId2;
00133 
00134   EcalPreshowerNavigator theESNav1(strip1, topology_p);
00135   theESNav1.setHome(strip1);
00136   
00137   EcalPreshowerNavigator theESNav2(strip2, topology_p);
00138   theESNav2.setHome(strip2);
00139 
00140   if (row == 1) {
00141     if (strip1 != ESDetId(0)) strip1 = theESNav1.north();
00142     if (strip2 != ESDetId(0)) strip2 = theESNav2.east();
00143   } else if (row == -1) {
00144     if (strip1 != ESDetId(0)) strip1 = theESNav1.south();
00145     if (strip2 != ESDetId(0)) strip2 = theESNav2.west();
00146   }
00147 
00148   // Plane 1 
00149   if (strip1 == ESDetId(0)) {
00150   } else {
00151     collectedIds_.insert(strip1);
00152     //cout<<"center : "<<strip1<<endl;
00153     // east road 
00154     for (int i=0; i<15; ++i) {
00155       next = theESNav1.east();
00156       //cout<<"east : "<<i<<" "<<next<<endl;
00157       if (next != ESDetId(0)) {
00158         collectedIds_.insert(next);
00159       } else {
00160         break;
00161       }
00162     }
00163 
00164     // west road 
00165     theESNav1.setHome(strip1);
00166     theESNav1.home();
00167     for (int i=0; i<15; ++i) {
00168       next = theESNav1.west();
00169       //cout<<"west : "<<i<<" "<<next<<endl;
00170       if (next != ESDetId(0)) {
00171         collectedIds_.insert(next);
00172       } else {
00173         break;
00174       }
00175     }
00176 
00177   }
00178 
00179   if (strip2 == ESDetId(0)) {
00180   } else {
00181     collectedIds_.insert(strip2);
00182     //cout<<"center : "<<strip2<<endl;
00183     // north road 
00184     for (int i=0; i<15; ++i) {
00185       next = theESNav2.north();
00186       //cout<<"north : "<<i<<" "<<next<<endl;
00187       if (next != ESDetId(0)) {
00188         collectedIds_.insert(next);
00189       } else {
00190         break;
00191       } 
00192     }
00193 
00194     // south road 
00195     theESNav2.setHome(strip2);
00196     theESNav2.home();
00197     for (int i=0; i<15; ++i) {
00198       next = theESNav2.south();
00199       //cout<<"south : "<<i<<" "<<next<<endl;
00200       if (next != ESDetId(0)) {
00201         collectedIds_.insert(next);
00202       } else {
00203         break;
00204       }
00205     }
00206   }
00207 }
00208 
00209