Go to the documentation of this file.00001
00002 #include <vector>
00003 #include <memory>
00004
00005
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
00018 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00019 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00020 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00021 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00022 #include "DataFormats/EgammaReco/interface/PreshowerClusterFwd.h"
00023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00024 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00025 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00026 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00027 #include "Geometry/CaloGeometry/interface/TruncatedPyramid.h"
00028 #include "Geometry/EcalAlgo/interface/EcalPreshowerGeometry.h"
00029 #include "Geometry/CaloTopology/interface/EcalPreshowerTopology.h"
00030 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00031 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00032 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00033 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00034 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00035 #include "DataFormats/EcalDetId/interface/ESDetId.h"
00036 #include "CondFormats/DataRecord/interface/ESGainRcd.h"
00037 #include "CondFormats/DataRecord/interface/ESMIPToGeVConstantRcd.h"
00038 #include "CondFormats/DataRecord/interface/ESEEIntercalibConstantsRcd.h"
00039 #include "CondFormats/DataRecord/interface/ESMissingEnergyCalibrationRcd.h"
00040 #include "CondFormats/DataRecord/interface/ESChannelStatusRcd.h"
00041 #include <fstream>
00042
00043 #include "RecoEcal/EgammaClusterProducers/interface/PreshowerClusterProducer.h"
00044
00045 using namespace edm;
00046 using namespace std;
00047
00048 PreshowerClusterProducer::PreshowerClusterProducer(const edm::ParameterSet& ps) {
00049
00050
00051 preshHitProducer_ = ps.getParameter<edm::InputTag>("preshRecHitProducer");
00052
00053
00054 endcapSClusterProducer_ = ps.getParameter<edm::InputTag>("endcapSClusterProducer");
00055
00056
00057 preshClusterCollectionX_ = ps.getParameter<std::string>("preshClusterCollectionX");
00058 preshClusterCollectionY_ = ps.getParameter<std::string>("preshClusterCollectionY");
00059 preshNclust_ = ps.getParameter<int>("preshNclust");
00060
00061 etThresh_ = ps.getParameter<double>("etThresh");
00062
00063 assocSClusterCollection_ = ps.getParameter<std::string>("assocSClusterCollection");
00064
00065 produces< reco::PreshowerClusterCollection >(preshClusterCollectionX_);
00066 produces< reco::PreshowerClusterCollection >(preshClusterCollectionY_);
00067 produces< reco::SuperClusterCollection >(assocSClusterCollection_);
00068
00069 float preshStripECut = ps.getParameter<double>("preshStripEnergyCut");
00070 int preshSeededNst = ps.getParameter<int>("preshSeededNstrip");
00071 preshClustECut = ps.getParameter<double>("preshClusterEnergyCut");
00072
00073 presh_algo = new PreshowerClusterAlgo(preshStripECut,preshClustECut,preshSeededNst);
00074
00075 nEvt_ = 0;
00076 }
00077
00078
00079 PreshowerClusterProducer::~PreshowerClusterProducer() {
00080 delete presh_algo;
00081 }
00082
00083 void PreshowerClusterProducer::produce(edm::Event& evt, const edm::EventSetup& es) {
00084
00085 edm::Handle< EcalRecHitCollection > pRecHits;
00086 edm::Handle< reco::SuperClusterCollection > pSuperClusters;
00087
00088
00089 edm::ESHandle<CaloGeometry> geoHandle;
00090 es.get<CaloGeometryRecord>().get(geoHandle);
00091
00092
00093 set(es);
00094 const ESChannelStatus *channelStatus = esChannelStatus_.product();
00095
00096 const CaloSubdetectorGeometry *geometry = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
00097 const CaloSubdetectorGeometry *& geometry_p = geometry;
00098
00099
00100 std::auto_ptr< reco::PreshowerClusterCollection > clusters_p1(new reco::PreshowerClusterCollection);
00101 std::auto_ptr< reco::PreshowerClusterCollection > clusters_p2(new reco::PreshowerClusterCollection);
00102
00103 std::auto_ptr< reco::SuperClusterCollection > superclusters_p(new reco::SuperClusterCollection);
00104
00105 CaloSubdetectorTopology * topology_p=0;
00106 if (geometry)
00107 topology_p = new EcalPreshowerTopology(geoHandle);
00108
00109
00110 evt.getByLabel(endcapSClusterProducer_, pSuperClusters);
00111 const reco::SuperClusterCollection* SClusts = pSuperClusters.product();
00112
00113
00114 evt.getByLabel( preshHitProducer_, pRecHits);
00115
00116 const EcalRecHitCollection* rechits = pRecHits.product();
00117
00118 LogTrace("EcalClusters") << "PreshowerClusterProducerInfo: ### Total # of preshower RecHits: "<< rechits->size();
00119
00120
00121 std::map<DetId, EcalRecHit> rechits_map;
00122 EcalRecHitCollection::const_iterator it;
00123 for (it = rechits->begin(); it != rechits->end(); it++) {
00124
00125 if (it->recoFlag()==1 || it->recoFlag()==14 || (it->recoFlag()<=10 && it->recoFlag()>=5)) continue;
00126
00127 rechits_map.insert(std::make_pair(it->id(), *it));
00128 }
00129
00130 std::set<DetId> used_strips;
00131 used_strips.clear();
00132 LogTrace("EcalClusters") << "PreshowerClusterProducerInfo: ### rechits_map of size " << rechits_map.size() <<" was created!";
00133
00134
00135 reco::PreshowerClusterCollection clusters1, clusters2;
00136 reco::SuperClusterCollection new_SC;
00137
00138
00139 reco::SuperClusterCollection::const_iterator it_super;
00140 int isc = 0;
00141 for (it_super=SClusts->begin(); it_super!=SClusts->end(); ++it_super) {
00142
00143 float e1 = 0;
00144 float e2 = 0;
00145 float deltaE = 0;
00146
00147 reco::CaloClusterPtrVector new_BC;
00148 ++isc;
00149 LogTrace("EcalClusters")<< " superE = " << it_super->energy() << " superETA = " << it_super->eta() << " superPHI = " << it_super->phi() ;
00150
00151 int nBC = 0;
00152 int condP1 = 1;
00153 int condP2 = 1;
00154 reco::CaloCluster_iterator bc_iter = it_super->clustersBegin();
00155 for ( ; bc_iter !=it_super->clustersEnd(); ++bc_iter ) {
00156 if (geometry) {
00157
00158
00159 double X = (*bc_iter)->x();
00160 double Y = (*bc_iter)->y();
00161 double Z = (*bc_iter)->z();
00162 const GlobalPoint point(X,Y,Z);
00163
00164 DetId tmp1 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, 1);
00165 DetId tmp2 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, 2);
00166 ESDetId strip1 = (tmp1 == DetId(0)) ? ESDetId(0) : ESDetId(tmp1);
00167 ESDetId strip2 = (tmp2 == DetId(0)) ? ESDetId(0) : ESDetId(tmp2);
00168
00169 if (nBC == 0) {
00170 if (strip1 != ESDetId(0) && strip2 != ESDetId(0)) {
00171 ESChannelStatusMap::const_iterator status_p1 = channelStatus->getMap().find(strip1);
00172 ESChannelStatusMap::const_iterator status_p2 = channelStatus->getMap().find(strip2);
00173 if (status_p1->getStatusCode() == 1) condP1 = 0;
00174 if (status_p2->getStatusCode() == 1) condP2 = 0;
00175 } else if (strip1 == ESDetId(0))
00176 condP1 = 0;
00177 else if (strip2 == ESDetId(0))
00178 condP2 = 0;
00179 }
00180
00181
00182 for (int i=0; i<preshNclust_; i++) {
00183 reco::PreshowerCluster cl1 = presh_algo->makeOneCluster(strip1,&used_strips,&rechits_map,geometry_p,topology_p);
00184 cl1.setBCRef(*bc_iter);
00185 if (cl1.energy() > preshClustECut) {
00186 clusters1.push_back(cl1);
00187 e1 += cl1.energy();
00188 }
00189 reco::PreshowerCluster cl2 = presh_algo->makeOneCluster(strip2,&used_strips,&rechits_map,geometry_p,topology_p);
00190 cl2.setBCRef(*bc_iter);
00191
00192 if ( cl2.energy() > preshClustECut) {
00193 clusters2.push_back(cl2);
00194 e2 += cl2.energy();
00195 }
00196 }
00197 }
00198
00199 new_BC.push_back(*bc_iter);
00200 nBC++;
00201 }
00202
00203 LogTrace("EcalClusters") << " For SC #" << isc-1 << ", containing "
00204 << it_super->clustersSize()
00205 << " basic clusters, PreshowerClusterAlgo made "
00206 << clusters1.size() << " in X plane and "
00207 << clusters2.size()
00208 << " in Y plane " << " preshower clusters " ;
00209
00210
00211 if(e1+e2 > 1.0e-10) {
00212
00213 e1 = e1 / mip_;
00214 e2 = e2 / mip_;
00215
00216 if (condP1 == 1 && condP2 == 1) {
00217 deltaE = gamma0_*(e1 + alpha0_*e2);
00218 } else if (condP1 == 1 && condP2 == 0) {
00219 deltaE = gamma1_*(e1 + alpha1_*e2);
00220 } else if (condP1 == 0 && condP2 == 1) {
00221 deltaE = gamma2_*(e1 + alpha2_*e2);
00222 } else if (condP1 == 0 && condP2 == 0) {
00223 deltaE = gamma3_*(e1 + alpha3_*e2);
00224 }
00225 }
00226
00227
00228 float E = it_super->energy() + deltaE;
00229
00230 LogTrace("EcalClusters") << " Creating corrected SC ";
00231
00232 reco::SuperCluster sc(E, it_super->position(), it_super->seed(), new_BC, deltaE);
00233 if (condP1 == 1 && condP2 == 1) sc.setPreshowerPlanesStatus(0);
00234 else if (condP1 == 1 && condP2 == 0) sc.setPreshowerPlanesStatus(1);
00235 else if (condP1 == 0 && condP2 == 1) sc.setPreshowerPlanesStatus(2);
00236 else if (condP1 == 0 && condP2 == 0) sc.setPreshowerPlanesStatus(3);
00237
00238 if (sc.energy()*sin(sc.position().theta())>etThresh_)
00239 new_SC.push_back(sc);
00240 LogTrace("EcalClusters") << " SuperClusters energies: new E = " << sc.energy() << " vs. old E =" << it_super->energy();
00241
00242 }
00243
00244
00245 clusters_p1->assign(clusters1.begin(), clusters1.end());
00246 clusters_p2->assign(clusters2.begin(), clusters2.end());
00247
00248 evt.put( clusters_p1, preshClusterCollectionX_ );
00249 evt.put( clusters_p2, preshClusterCollectionY_ );
00250 LogTrace("EcalClusters") << "Preshower clusters added to the event" ;
00251
00252
00253 superclusters_p->assign(new_SC.begin(), new_SC.end());
00254 evt.put(superclusters_p, assocSClusterCollection_);
00255 LogTrace("EcalClusters") << "Corrected SClusters added to the event" ;
00256
00257 if (topology_p)
00258 delete topology_p;
00259
00260 nEvt_++;
00261
00262 }
00263
00264 void PreshowerClusterProducer::set(const edm::EventSetup& es) {
00265
00266 es.get<ESGainRcd>().get(esgain_);
00267 const ESGain *gain = esgain_.product();
00268
00269 double ESGain = gain->getESGain();
00270
00271 es.get<ESMIPToGeVConstantRcd>().get(esMIPToGeV_);
00272 const ESMIPToGeVConstant *mipToGeV = esMIPToGeV_.product();
00273
00274 mip_ = (ESGain == 1) ? mipToGeV->getESValueLow() : mipToGeV->getESValueHigh();
00275
00276 es.get<ESChannelStatusRcd>().get(esChannelStatus_);
00277
00278 es.get<ESEEIntercalibConstantsRcd>().get(esEEInterCalib_);
00279 const ESEEIntercalibConstants *esEEInterCalib = esEEInterCalib_.product();
00280
00281
00282 gamma0_ = (ESGain == 1) ? esEEInterCalib->getGammaLow0() : esEEInterCalib->getGammaHigh0();
00283 alpha0_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow0() : esEEInterCalib->getAlphaHigh0();
00284
00285
00286 gamma1_ = (ESGain == 1) ? esEEInterCalib->getGammaLow1() : esEEInterCalib->getGammaHigh1();
00287 alpha1_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow1() : esEEInterCalib->getAlphaHigh1();
00288
00289
00290 gamma2_ = (ESGain == 1) ? esEEInterCalib->getGammaLow2() : esEEInterCalib->getGammaHigh2();
00291 alpha2_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow2() : esEEInterCalib->getAlphaHigh2();
00292
00293
00294 gamma3_ = (ESGain == 1) ? esEEInterCalib->getGammaLow3() : esEEInterCalib->getGammaHigh3();
00295 alpha3_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow3() : esEEInterCalib->getAlphaHigh3();
00296
00297 es.get<ESMissingEnergyCalibrationRcd>().get(esMissingECalib_);
00298 const ESMissingEnergyCalibration * esMissingECalib = esMissingECalib_.product();
00299
00300
00301 aEta_[0] = esMissingECalib->getConstAEta0();
00302 bEta_[0] = esMissingECalib->getConstBEta0();
00303
00304
00305 aEta_[1] = esMissingECalib->getConstAEta1();
00306 bEta_[1] = esMissingECalib->getConstBEta1();
00307
00308
00309 aEta_[2] = esMissingECalib->getConstAEta2();
00310 bEta_[2] = esMissingECalib->getConstBEta2();
00311
00312
00313 aEta_[3] = esMissingECalib->getConstAEta3();
00314 bEta_[3] = esMissingECalib->getConstBEta3();
00315
00316 }