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 <fstream>
00040
00041 #include "RecoEcal/EgammaClusterProducers/interface/PreshowerClusterProducer.h"
00042
00043
00044 using namespace edm;
00045 using namespace std;
00046
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
00074 std::string debugString = ps.getParameter<std::string>("debugLevel");
00075 if (debugString == "DEBUG") debugL = PreshowerClusterAlgo::pDEBUG;
00076 else if (debugString == "INFO") debugL = PreshowerClusterAlgo::pINFO;
00077 else debugL = PreshowerClusterAlgo::pERROR;
00078
00079 presh_algo = new PreshowerClusterAlgo(preshStripECut,preshClustECut,preshSeededNst,debugL);
00080
00081 nEvt_ = 0;
00082
00083 }
00084
00085
00086 PreshowerClusterProducer::~PreshowerClusterProducer() {
00087 delete presh_algo;
00088 }
00089
00090
00091 void PreshowerClusterProducer::produce(edm::Event& evt, const edm::EventSetup& es) {
00092
00093 edm::Handle< EcalRecHitCollection > pRecHits;
00094 edm::Handle< reco::SuperClusterCollection > pSuperClusters;
00095
00096
00097 edm::ESHandle<CaloGeometry> geoHandle;
00098 es.get<CaloGeometryRecord>().get(geoHandle);
00099
00100
00101 set(es);
00102
00103 const CaloSubdetectorGeometry *geometry = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
00104 const CaloSubdetectorGeometry *& geometry_p = geometry;
00105
00106
00107 std::auto_ptr< reco::PreshowerClusterCollection > clusters_p1(new reco::PreshowerClusterCollection);
00108 std::auto_ptr< reco::PreshowerClusterCollection > clusters_p2(new reco::PreshowerClusterCollection);
00109
00110 std::auto_ptr< reco::SuperClusterCollection > superclusters_p(new reco::SuperClusterCollection);
00111
00112 CaloSubdetectorTopology * topology_p=0;
00113 if (geometry)
00114 topology_p = new EcalPreshowerTopology(geoHandle);
00115
00116
00117 evt.getByLabel(endcapSClusterProducer_, pSuperClusters);
00118 const reco::SuperClusterCollection* SClusts = pSuperClusters.product();
00119 if ( debugL <= PreshowerClusterAlgo::pINFO ) std::cout <<"### Total # Endcap Superclusters: " << SClusts->size() << std::endl;
00120
00121
00122 evt.getByLabel( preshHitProducer_, pRecHits);
00123
00124 const EcalRecHitCollection* rechits = pRecHits.product();
00125 if ( debugL == PreshowerClusterAlgo::pDEBUG ) std::cout << "PreshowerClusterProducerInfo: ### Total # of preshower RecHits: "
00126 << rechits->size() << std::endl;
00127
00128
00129 std::map<DetId, EcalRecHit> rechits_map;
00130 EcalRecHitCollection::const_iterator it;
00131 for (it = rechits->begin(); it != rechits->end(); it++) {
00132
00133 if (it->recoFlag()==14 || (it->recoFlag()<=10 && it->recoFlag()>=5)) continue;
00134
00135 rechits_map.insert(std::make_pair(it->id(), *it));
00136 }
00137
00138 std::set<DetId> used_strips;
00139 used_strips.clear();
00140
00141 if ( debugL <= PreshowerClusterAlgo::pINFO ) std::cout << "PreshowerClusterProducerInfo: ### rechits_map of size "
00142 << rechits_map.size() <<" was created!" << std::endl;
00143
00144 reco::PreshowerClusterCollection clusters1, clusters2;
00145 reco::SuperClusterCollection new_SC;
00146
00147 if ( debugL == PreshowerClusterAlgo::pDEBUG ) std::cout << " Making a cycle over Superclusters ..." << std::endl;
00148
00149 reco::SuperClusterCollection::const_iterator it_super;
00150 int isc = 0;
00151 for ( it_super=SClusts->begin(); it_super!=SClusts->end(); it_super++ ) {
00152 float e1=0;
00153 float e2=0;
00154 float deltaE=0;
00155 reco::CaloClusterPtrVector new_BC;
00156 ++isc;
00157
00158 if ( debugL <= PreshowerClusterAlgo::pINFO ) std::cout << " superE = " << it_super->energy() << " superETA = " << it_super->eta()
00159 << " superPHI = " << it_super->phi() << std::endl;
00160 if ( debugL == PreshowerClusterAlgo::pINFO ) std::cout << " This SC contains " << it_super->clustersSize() << " BCs" << std::endl;
00161
00162 reco::CaloCluster_iterator bc_iter = it_super->clustersBegin();
00163 for ( ; bc_iter !=it_super->clustersEnd(); ++bc_iter ) {
00164 if (geometry)
00165 {
00166
00167 double X = (*bc_iter)->x();
00168 double Y = (*bc_iter)->y();
00169 double Z = (*bc_iter)->z();
00170 const GlobalPoint point(X,Y,Z);
00171
00172 DetId tmp1 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, 1);
00173 DetId tmp2 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, 2);
00174 ESDetId strip1 = (tmp1 == DetId(0)) ? ESDetId(0) : ESDetId(tmp1);
00175 ESDetId strip2 = (tmp2 == DetId(0)) ? ESDetId(0) : ESDetId(tmp2);
00176
00177 if ( debugL <= PreshowerClusterAlgo::pINFO ) {
00178 if ( strip1 != ESDetId(0) && strip2 != ESDetId(0) ) {
00179 std::cout << " Intersected preshower strips are: " << std::endl;
00180 std::cout << strip1 << std::endl;
00181 std::cout << strip2 << std::endl;
00182 }
00183 else if ( strip1 == ESDetId(0) )
00184 std::cout << " No intersected strip in plane 1 " << std::endl;
00185 else if ( strip2 == ESDetId(0) )
00186 std::cout << " No intersected strip in plane 2 " << std::endl;
00187 }
00188
00189
00190 for (int i=0; i<preshNclust_; i++) {
00191 reco::PreshowerCluster cl1 = presh_algo->makeOneCluster(strip1,&used_strips,&rechits_map,geometry_p,topology_p);
00192 cl1.setBCRef(*bc_iter);
00193 if ( cl1.energy() > preshClustECut) {
00194 clusters1.push_back(cl1);
00195 e1 += cl1.energy();
00196 }
00197 reco::PreshowerCluster cl2 = presh_algo->makeOneCluster(strip2,&used_strips,&rechits_map,geometry_p,topology_p);
00198 cl2.setBCRef(*bc_iter);
00199
00200 if ( cl2.energy() > preshClustECut) {
00201 clusters2.push_back(cl2);
00202 e2 += cl2.energy();
00203 }
00204 }
00205 }
00206 new_BC.push_back(*bc_iter);
00207 }
00208
00209 if ( debugL <= PreshowerClusterAlgo::pINFO ) std::cout << " For SC #" << isc-1 << ", containing " << it_super->clustersSize()
00210 << " basic clusters, PreshowerClusterAlgo made "
00211 << clusters1.size() << " in X plane and " << clusters2.size()
00212 << " in Y plane " << " preshower clusters " << std::endl;
00213
00214
00215 if(e1+e2 > 1.0e-10) {
00216
00217 e1 = e1 / mip_;
00218 e2 = e2 / mip_;
00219 deltaE = gamma_*(e1+alpha_*e2);
00220 }
00221
00222
00223 float E = it_super->energy() + deltaE;
00224
00225 if ( debugL == PreshowerClusterAlgo::pDEBUG ) std::cout << " Creating corrected SC " << std::endl;
00226 reco::SuperCluster sc( E, it_super->position(), it_super->seed(), new_BC, deltaE);
00227
00228 if(sc.energy()*sin(sc.position().theta())>etThresh_)
00229 new_SC.push_back(sc);
00230 if ( debugL <= PreshowerClusterAlgo::pINFO ) std::cout << " SuperClusters energies: new E = " << sc.energy()
00231 << " vs. old E =" << it_super->energy() << std::endl;
00232
00233 }
00234
00235
00236
00237
00238 clusters_p1->assign(clusters1.begin(), clusters1.end());
00239 clusters_p2->assign(clusters2.begin(), clusters2.end());
00240
00241 evt.put( clusters_p1, preshClusterCollectionX_ );
00242 evt.put( clusters_p2, preshClusterCollectionY_ );
00243 if ( debugL <= PreshowerClusterAlgo::pINFO ) std::cout << "Preshower clusters added to the event" << std::endl;
00244
00245
00246 superclusters_p->assign(new_SC.begin(), new_SC.end());
00247 evt.put(superclusters_p, assocSClusterCollection_);
00248 if ( debugL <= PreshowerClusterAlgo::pINFO ) std::cout << "Corrected SClusters added to the event" << std::endl;
00249
00250 if (topology_p)
00251 delete topology_p;
00252
00253 nEvt_++;
00254
00255 }
00256
00257 void PreshowerClusterProducer::set(const edm::EventSetup& es) {
00258
00259 es.get<ESGainRcd>().get(esgain_);
00260 const ESGain *gain = esgain_.product();
00261
00262 es.get<ESMIPToGeVConstantRcd>().get(esMIPToGeV_);
00263 const ESMIPToGeVConstant *mipToGeV = esMIPToGeV_.product();
00264
00265 es.get<ESEEIntercalibConstantsRcd>().get(esEEInterCalib_);
00266 const ESEEIntercalibConstants *esEEInterCalib = esEEInterCalib_.product();
00267
00268 double ESGain = gain->getESGain();
00269 mip_ = (ESGain == 1) ? mipToGeV->getESValueLow() : mipToGeV->getESValueHigh();
00270 gamma_ = (ESGain == 1) ? esEEInterCalib->getGammaLow0() : esEEInterCalib->getGammaHigh0();
00271 alpha_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow0() : esEEInterCalib->getAlphaHigh0();
00272 }