00001
00002 #include <vector>
00003 #include <iostream>
00004 #include <boost/regex.hpp>
00005
00006 #include "FWCore/Framework/interface/Frameworkfwd.h"
00007 #include "FWCore/Framework/interface/EDProducer.h"
00008 #include "FWCore/Framework/interface/ESHandle.h"
00009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 #include "FWCore/Utilities/interface/Exception.h"
00012
00013 #include "DataFormats/Common/interface/Handle.h"
00014 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00015 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
00016 #include "DataFormats/TrackReco/interface/Track.h"
00017 #include "DataFormats/VertexReco/interface/Vertex.h"
00018 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00019 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
00020 #include "DataFormats/EgammaReco/interface/ClusterShape.h"
00021 #include "DataFormats/EgammaCandidates/interface/Electron.h"
00022 #include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
00023 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00024
00025 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00026
00027 #include "RecoCaloTools/Selectors/interface/CaloConeSelector.h"
00028 #include "RecoCaloTools/MetaCollections/interface/CaloRecHitMetaCollections.h"
00029
00030 #include "TrackingTools/TrackAssociator/interface/TrackAssociatorParameters.h"
00031 #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h"
00032 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h"
00033
00034 #include "ElectronIdMLP.h"
00035 #include "SoftElectronProducer.h"
00036
00037
00038
00039 using namespace std;
00040 using namespace edm;
00041
00042
00043
00044 SoftElectronProducer::SoftElectronProducer(const edm::ParameterSet &iConf) :
00045 theConf(iConf), theTrackAssociator(0), theElecNN(0)
00046 {
00047 theTrackTag = theConf.getParameter<InputTag>("TrackTag");
00048
00049 theHBHERecHitTag = theConf.getParameter<InputTag>("HBHERecHitTag");
00050 theBasicClusterTag = theConf.getParameter<InputTag>("BasicClusterTag");
00051
00052
00053 theHOverEConeSize = theConf.getParameter<double>("HOverEConeSize");
00054
00055 barrelRecHitCollection_ = theConf.getParameter<edm::InputTag>("BarrelRecHitCollection");
00056 endcapRecHitCollection_ = theConf.getParameter<edm::InputTag>("EndcapRecHitCollection");
00057
00058
00059 theTrackAssociator = new TrackDetectorAssociator();
00060 theTrackAssociator->useDefaultPropagator();
00061 edm::ParameterSet parameters = iConf.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
00062 theTrackAssociatorParameters = new TrackAssociatorParameters( parameters );
00063
00064 theDiscriminatorCut = theConf.getParameter<double>("DiscriminatorCut");
00065
00066 theElecNN = new ElectronIdMLP;
00067
00068
00069 produces<reco::ElectronCollection>();
00070 }
00071
00072
00073
00074 SoftElectronProducer::~SoftElectronProducer()
00075 {
00076 if (theElecNN) delete theElecNN;
00077 if (theTrackAssociator) delete theTrackAssociator;
00078 if (theTrackAssociatorParameters) delete theTrackAssociatorParameters;
00079 }
00080
00081
00082
00083 void SoftElectronProducer::produce(edm::Event &iEvent,
00084 const edm::EventSetup &iSetup)
00085 {
00086
00087 auto_ptr<reco::ElectronCollection> candidates(new reco::ElectronCollection());
00088
00089 Handle<reco::TrackCollection> handleTrack;
00090 reco::TrackCollection::const_iterator itTrack;
00091
00092 Handle<reco::BasicClusterCollection> handleCluster;
00093 reco::BasicClusterCollection::const_iterator itCluster;
00094
00095
00096
00097
00098 Handle<HBHERecHitCollection> handleRecHit;
00099 CaloRecHitMetaCollectionV::const_iterator itRecHit;
00100
00101 ESHandle<CaloGeometry> handleCaloGeom;
00102
00103
00104 double hcalEnergy, clusEnergy, trkP;
00105 double x[2], y[2], z[2], eta[2], phi[2];
00106 double covEtaEta, covEtaPhi, covPhiPhi, emFraction, deltaE;
00107 double eMax, e2x2, e3x3, e5x5, v1, v2, v3, v4;
00108 double value, dist, distMin;
00109
00110 const reco::BasicCluster *matchedCluster;
00111
00112 const reco::Track *track;
00113
00114
00115 iEvent.getByLabel(theBasicClusterTag, handleCluster);
00116
00117
00118
00119
00120
00121 iEvent.getByLabel(theHBHERecHitTag, handleRecHit);
00122 HBHERecHitMetaCollection metaRecHit(*handleRecHit);
00123
00124
00125
00126
00127 EcalClusterLazyTools ecalTool(iEvent, iSetup, barrelRecHitCollection_, endcapRecHitCollection_ );
00128
00129
00130 iSetup.get<CaloGeometryRecord>().get(handleCaloGeom);
00131
00132 CaloConeSelector selectorRecHit(theHOverEConeSize, handleCaloGeom.product(), DetId::Hcal);
00133
00134
00135 iEvent.getByLabel(theTrackTag, handleTrack);
00136
00137 FreeTrajectoryState tmpFTS;
00138 TrackDetMatchInfo info;
00139 unsigned int counterTrack;
00140
00141
00142 for(itTrack = handleTrack->begin(), counterTrack = 0;
00143 itTrack != handleTrack->end();
00144 ++itTrack, ++counterTrack)
00145 {
00146 track = &(*itTrack);
00147
00148 try {
00149 tmpFTS = theTrackAssociator->getFreeTrajectoryState(iSetup, *track);
00150 info = theTrackAssociator->associate(iEvent, iSetup, tmpFTS, *theTrackAssociatorParameters);
00151 } catch (cms::Exception e) {
00152
00153 std::cerr << "Caught exception during track extrapolation: " << e.what() << ". Skipping track" << endl;
00154 continue;
00155 }
00156
00157 x[0] = info.trkGlobPosAtEcal.x();
00158 y[0] = info.trkGlobPosAtEcal.y();
00159 z[0] = info.trkGlobPosAtEcal.z();
00160 eta[0] = info.trkGlobPosAtEcal.eta();
00161 phi[0] = info.trkGlobPosAtEcal.phi();
00162
00163
00164 if(track->numberOfValidHits() >= 8 && track->pt() > 2.0 &&
00165 abs(track->eta()) < 1.2 && info.isGoodEcal)
00166 {
00167 distMin = 1.0e6;
00168 matchedCluster = 0;
00169
00170
00171
00172 for(itCluster = handleCluster->begin(); itCluster != handleCluster->end();++itCluster)
00173 {
00174 x[1] = itCluster->x();
00175 y[1] = itCluster->y();
00176 z[1] = itCluster->z();
00177
00178 eta[1] = itCluster->eta();
00179 phi[1] = itCluster->phi();
00180
00181
00182 dist = hypot(x[0] - x[1], y[0] - y[1]);
00183 dist = hypot(dist, z[0] - z[1]);
00184
00185 if(dist < distMin)
00186 {
00187 distMin = dist;
00188 matchedCluster = &(*itCluster);
00189 }
00190 }
00191
00192
00193 if(matchedCluster && distMin < 10.0)
00194 {
00195 GlobalPoint position(matchedCluster->x(), matchedCluster->y(), matchedCluster->z());
00196 auto_ptr<CaloRecHitMetaCollectionV> chosen = selectorRecHit.select(position, metaRecHit);
00197 hcalEnergy = 0.0;
00198 for(itRecHit = chosen->begin(); itRecHit != chosen->end(); ++itRecHit)
00199 {
00200 hcalEnergy += itRecHit->energy();
00201 }
00202
00203 clusEnergy = matchedCluster->energy();
00204 trkP = track->p();
00205
00206 deltaE = (clusEnergy - trkP)/(clusEnergy + trkP);
00207 emFraction = clusEnergy/(clusEnergy + hcalEnergy);
00208
00209 eMax = ecalTool.eMax(*matchedCluster);
00210 e2x2 = ecalTool.e2x2(*matchedCluster);
00211 e3x3 = ecalTool.e3x3(*matchedCluster);
00212 e5x5 = ecalTool.e5x5(*matchedCluster);
00213 v1 = eMax/e3x3;
00214 v2 = eMax/e2x2;
00215 v3 = e2x2/e5x5;
00216 v4 = ((e5x5 - eMax) < 0.001) ? 1.0 : (e3x3 - eMax)/(e5x5 - eMax);
00217 std::vector<float> cov = ecalTool.covariances(*matchedCluster);
00218 covEtaEta = cov[0];
00219 covEtaPhi = cov[1];
00220 covPhiPhi = cov[2];
00221
00222 value = theElecNN->value(0, covEtaEta, covEtaPhi, covPhiPhi,
00223 v1, v2, v3, v4, emFraction, deltaE);
00224 if (value > theDiscriminatorCut)
00225 {
00226 const reco::Particle::LorentzVector p4(0.0, 0.0, 0.0, clusEnergy);
00227 const reco::Particle::Point vtx(0.0, 0.0, 0.0);
00228 reco::Electron newCandidate(0, p4, vtx);
00229 reco::TrackRef refTrack(handleTrack, counterTrack);
00230 newCandidate.setTrack(refTrack);
00231 candidates->push_back(newCandidate);
00232 }
00233 }
00234 }
00235 }
00236
00237
00238 iEvent.put(candidates);
00239
00240 }