CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SoftElectronProducer.cc
Go to the documentation of this file.
1 
2 #include <vector>
3 #include <iostream>
4 #include <boost/regex.hpp>
5 
12 
24 
26 
29 
33 
34 #include "ElectronIdMLP.h"
35 #include "SoftElectronProducer.h"
36 
37 //------------------------------------------------------------------------------
38 
39 using namespace std;
40 using namespace edm;
41 
42 //------------------------------------------------------------------------------
43 
45  theConf(iConf), theTrackAssociator(0), theElecNN(0)
46 {
48 
49  theHBHERecHitTag = theConf.getParameter<InputTag>("HBHERecHitTag");
50  theBasicClusterTag = theConf.getParameter<InputTag>("BasicClusterTag");
51  // theBasicClusterShapeTag = theConf.getParameter<InputTag>("BasicClusterShapeTag");
52 
53  theHOverEConeSize = theConf.getParameter<double>("HOverEConeSize");
54 
55  barrelRecHitCollection_ = theConf.getParameter<edm::InputTag>("BarrelRecHitCollection");
56  endcapRecHitCollection_ = theConf.getParameter<edm::InputTag>("EndcapRecHitCollection");
57 
58  // TrackAssociator and its parameters
60  theTrackAssociator->useDefaultPropagator();
61  edm::ParameterSet parameters = iConf.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
63 
64  theDiscriminatorCut = theConf.getParameter<double>("DiscriminatorCut");
65 
67 
68  // register the product
69  produces<reco::ElectronCollection>();
70 }
71 
72 //------------------------------------------------------------------------------
73 
75 {
76  if (theElecNN) delete theElecNN;
79 }
80 
81 //------------------------------------------------------------------------------
82 
84  const edm::EventSetup &iSetup)
85 {
86 
87  auto_ptr<reco::ElectronCollection> candidates(new reco::ElectronCollection());
88 
90  reco::TrackCollection::const_iterator itTrack;
91 
93  reco::BasicClusterCollection::const_iterator itCluster;
94 
95  //Handle<reco::ClusterShapeCollection> handleShape;
96  //reco::ClusterShapeCollection::const_iterator itShape;
97 
98  Handle<HBHERecHitCollection> handleRecHit;
100 
101  ESHandle<CaloGeometry> handleCaloGeom;
102 
103 
104  double hcalEnergy, clusEnergy, trkP;
105  double x[2], y[2], z[2], eta[2], phi[2];
106  double covEtaEta, covEtaPhi, covPhiPhi, emFraction, deltaE;
107  double eMax, e2x2, e3x3, e5x5, v1, v2, v3, v4;
108  double value, dist, distMin;
109 
110  const reco::BasicCluster *matchedCluster;
111  //const reco::ClusterShape *matchedShape;
112  const reco::Track *track;
113 
114  // get basic clusters
115  iEvent.getByLabel(theBasicClusterTag, handleCluster);
116 
117  // get basic cluster shapes
118  //iEvent.getByLabel(theBasicClusterShapeTag, handleShape);
119 
120  // get rec. hits
121  iEvent.getByLabel(theHBHERecHitTag, handleRecHit);
122  HBHERecHitMetaCollection metaRecHit(*handleRecHit);
123 
124  //only barrel is used, giving twice the same inputag..
125 
126 
128 
129  // get calorimeter geometry
130  iSetup.get<CaloGeometryRecord>().get(handleCaloGeom);
131 
132  CaloConeSelector selectorRecHit(theHOverEConeSize, handleCaloGeom.product(), DetId::Hcal);
133 
134  // get tracks
135  iEvent.getByLabel(theTrackTag, handleTrack);
136 
137  FreeTrajectoryState tmpFTS;
139  unsigned int counterTrack;
140 
141  // loop over tracks
142  for(itTrack = handleTrack->begin(), counterTrack = 0;
143  itTrack != handleTrack->end();
144  ++itTrack, ++counterTrack)
145  {
146  track = &(*itTrack);
147 
148  try {
149  tmpFTS = theTrackAssociator->getFreeTrajectoryState(iSetup, *track);
150  info = theTrackAssociator->associate(iEvent, iSetup, tmpFTS, *theTrackAssociatorParameters);
151  } catch (cms::Exception e) {
152  // extrapolation failed, skip this track
153  std::cerr << "Caught exception during track extrapolation: " << e.what() << ". Skipping track" << endl;
154  continue;
155  }
156 
157  x[0] = info.trkGlobPosAtEcal.x();
158  y[0] = info.trkGlobPosAtEcal.y();
159  z[0] = info.trkGlobPosAtEcal.z();
160  eta[0] = info.trkGlobPosAtEcal.eta();
161  phi[0] = info.trkGlobPosAtEcal.phi();
162 
163  // analyse only tracks passing quality cuts
164  if(track->numberOfValidHits() >= 8 && track->pt() > 2.0 &&
165  abs(track->eta()) < 1.2 && info.isGoodEcal)
166  {
167  distMin = 1.0e6;
168  matchedCluster = 0;
169 // matchedShape = 0;
170 
171  // loop over basic clusters
172  for(itCluster = handleCluster->begin(); itCluster != handleCluster->end();++itCluster)
173  {
174  x[1] = itCluster->x();
175  y[1] = itCluster->y();
176  z[1] = itCluster->z();
177 
178  eta[1] = itCluster->eta();
179  phi[1] = itCluster->phi();
180 
181 
182  dist = hypot(x[0] - x[1], y[0] - y[1]);
183  dist = hypot(dist, z[0] - z[1]);
184 
185  if(dist < distMin)
186  {
187  distMin = dist;
188  matchedCluster = &(*itCluster);
189  }
190  }
191 
192  // identify electrons based on cluster properties
193  if(matchedCluster && distMin < 10.0)
194  {
195  GlobalPoint position(matchedCluster->x(), matchedCluster->y(), matchedCluster->z());
196  auto_ptr<CaloRecHitMetaCollectionV> chosen = selectorRecHit.select(position, metaRecHit);
197  hcalEnergy = 0.0;
198  for(itRecHit = chosen->begin(); itRecHit != chosen->end(); ++itRecHit)
199  {
200  hcalEnergy += itRecHit->energy();
201  }
202 
203  clusEnergy = matchedCluster->energy();
204  trkP = track->p();
205 
206  deltaE = (clusEnergy - trkP)/(clusEnergy + trkP);
207  emFraction = clusEnergy/(clusEnergy + hcalEnergy);
208 
209  eMax = ecalTool.eMax(*matchedCluster);
210  e2x2 = ecalTool.e2x2(*matchedCluster);
211  e3x3 = ecalTool.e3x3(*matchedCluster);
212  e5x5 = ecalTool.e5x5(*matchedCluster);
213  v1 = eMax/e3x3;
214  v2 = eMax/e2x2;
215  v3 = e2x2/e5x5;
216  v4 = ((e5x5 - eMax) < 0.001) ? 1.0 : (e3x3 - eMax)/(e5x5 - eMax);
217  std::vector<float> cov = ecalTool.covariances(*matchedCluster);
218  covEtaEta = cov[0];
219  covEtaPhi = cov[1];
220  covPhiPhi = cov[2];
221 
222  value = theElecNN->value(0, covEtaEta, covEtaPhi, covPhiPhi,
223  v1, v2, v3, v4, emFraction, deltaE);
224  if (value > theDiscriminatorCut)
225  {
226  const reco::Particle::LorentzVector p4(0.0, 0.0, 0.0, clusEnergy);
227  const reco::Particle::Point vtx(0.0, 0.0, 0.0);
228  reco::Electron newCandidate(0, p4, vtx);
229  reco::TrackRef refTrack(handleTrack, counterTrack);
230  newCandidate.setTrack(refTrack);
231  candidates->push_back(newCandidate);
232  }
233  }
234  }
235  }
236 
237  // put the product in the event
238  iEvent.put(candidates);
239 
240 }
virtual char const * what() const
Definition: Exception.cc:97
double p() const
momentum vector magnitude
Definition: TrackBase.h:128
T getParameter(std::string const &) const
float e2x2(const reco::BasicCluster &cluster)
TrackDetectorAssociator * theTrackAssociator
static FreeTrajectoryState getFreeTrajectoryState(const edm::EventSetup &, const reco::Track &)
get FreeTrajectoryState from different track representations
float e3x3(const reco::BasicCluster &cluster)
#define abs(x)
Definition: mlp_lapack.h:159
float eMax(const reco::BasicCluster &cluster)
T eta() const
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
edm::InputTag barrelRecHitCollection_
int iEvent
Definition: GenABIO.cc:243
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:140
Definition: DDAxes.h:10
SoftElectronProducer(const edm::ParameterSet &iConf)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
float energy() const
Definition: CaloRecHit.h:19
double p4[4]
Definition: TauolaWrapper.h:92
double pt() const
track transverse momentum
Definition: TrackBase.h:130
math::XYZPoint Point
point in the space
Definition: Particle.h:30
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:225
std::vector< Electron > ElectronCollection
collectin of Electron objects
Definition: ElectronFwd.h:9
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
std::vector< float > covariances(const reco::BasicCluster &cluster, float w0=4.7)
float e5x5(const reco::BasicCluster &cluster)
edm::InputTag endcapRecHitCollection_
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
double value(int index, double in0, double in1, double in2, double in3, double in4, double in5, double in6, double in7, double in8)
Definition: ElectronIdMLP.cc:4
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
edm::InputTag theBasicClusterTag
edm::InputTag theHBHERecHitTag
TrackDetMatchInfo associate(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const AssociatorParameters &)
math::XYZPoint trkGlobPosAtEcal
Track position at different parts of the calorimeter.
TrackAssociatorParameters * theTrackAssociatorParameters
void setTrack(const reco::TrackRef &r)
set refrence to Track component
Definition: Electron.h:35
edm::ParameterSet theConf
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:26
Definition: DDAxes.h:10