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