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