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];
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
00161
00162 if(track->numberOfValidHits() >= 8 && track->pt() > 2.0 &&
00163 abs(track->eta()) < 1.2 && info.isGoodEcal)
00164 {
00165 distMin = 1.0e6;
00166 matchedCluster = 0;
00167
00168
00169
00170 for(itCluster = handleCluster->begin(); itCluster != handleCluster->end();++itCluster)
00171 {
00172 x[1] = itCluster->x();
00173 y[1] = itCluster->y();
00174 z[1] = itCluster->z();
00175
00176 dist = hypot(x[0] - x[1], y[0] - y[1]);
00177 dist = hypot(dist, z[0] - z[1]);
00178
00179 if(dist < distMin)
00180 {
00181 distMin = dist;
00182 matchedCluster = &(*itCluster);
00183 }
00184 }
00185
00186
00187 if(matchedCluster && distMin < 10.0)
00188 {
00189 GlobalPoint position(matchedCluster->x(), matchedCluster->y(), matchedCluster->z());
00190 auto_ptr<CaloRecHitMetaCollectionV> chosen = selectorRecHit.select(position, metaRecHit);
00191 hcalEnergy = 0.0;
00192 for(itRecHit = chosen->begin(); itRecHit != chosen->end(); ++itRecHit)
00193 {
00194 hcalEnergy += itRecHit->energy();
00195 }
00196
00197 clusEnergy = matchedCluster->energy();
00198 trkP = track->p();
00199
00200 deltaE = (clusEnergy - trkP)/(clusEnergy + trkP);
00201 emFraction = clusEnergy/(clusEnergy + hcalEnergy);
00202
00203 eMax = ecalTool.eMax(*matchedCluster);
00204 e2x2 = ecalTool.e2x2(*matchedCluster);
00205 e3x3 = ecalTool.e3x3(*matchedCluster);
00206 e5x5 = ecalTool.e5x5(*matchedCluster);
00207 v1 = eMax/e3x3;
00208 v2 = eMax/e2x2;
00209 v3 = e2x2/e5x5;
00210 v4 = ((e5x5 - eMax) < 0.001) ? 1.0 : (e3x3 - eMax)/(e5x5 - eMax);
00211 std::vector<float> cov = ecalTool.covariances(*matchedCluster);
00212 covEtaEta = cov[0];
00213 covEtaPhi = cov[1];
00214 covPhiPhi = cov[2];
00215
00216 value = theElecNN->value(0, covEtaEta, covEtaPhi, covPhiPhi,
00217 v1, v2, v3, v4, emFraction, deltaE);
00218 if (value > theDiscriminatorCut)
00219 {
00220 const reco::Particle::LorentzVector p4(0.0, 0.0, 0.0, clusEnergy);
00221 const reco::Particle::Point vtx(0.0, 0.0, 0.0);
00222 reco::Electron newCandidate(0, p4, vtx);
00223 reco::TrackRef refTrack(handleTrack, counterTrack);
00224 newCandidate.setTrack(refTrack);
00225 candidates->push_back(newCandidate);
00226 }
00227 }
00228 }
00229 }
00230
00231
00232 iEvent.put(candidates);
00233
00234 }