CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EgammaHLTPixelMatchElectronAlgo.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EgammaHLTAlgos
4 // Class: EgammaHLTPixelMatchElectronAlgo.
5 //
11 //
12 // Original Author: Monica Vazquez Acosta (CERN)
13 // $Id: EgammaHLTPixelMatchElectronAlgo.cc,v 1.16 2012/01/23 12:52:30 sharper Exp $
14 //
15 //
17 
20 
25 
28 
33 
36 
39 
42 
45 
46 using namespace edm;
47 using namespace std;
48 using namespace reco;
49 
51  trackProducer_(conf.getParameter<edm::InputTag>("TrackProducer")),
52  gsfTrackProducer_(conf.getParameter<edm::InputTag>("GsfTrackProducer")),
53  useGsfTracks_(conf.getParameter<bool>("UseGsfTracks")),
54  bsProducer_(conf.getParameter<edm::InputTag>("BSProducer")),
55  mtsMode_(new MultiTrajectoryStateMode()),
56  mtsTransform_(0),
57  cacheIDTDGeom_(0),
58  cacheIDMagField_(0)
59 {
60 
61 }
62 
64 {
65  delete mtsTransform_;
66  delete mtsMode_;
67  }
68 
70  //services
71 
72  bool updateField(false);
74  updateField = true;
75  cacheIDMagField_=es.get<IdealMagneticFieldRecord>().cacheIdentifier();
77  }
78 
79  if(useGsfTracks_){ //only need the geom and mtsTransform if we are doing gsf tracks
80  bool updateGeometry(false);
82  updateGeometry = true;
83  cacheIDTDGeom_=es.get<TrackerDigiGeometryRecord>().cacheIdentifier();
85  }
86  if ( updateField || updateGeometry || !mtsTransform_ ) {
87  delete mtsTransform_;
89  }
90  }
91 
92 
93 }
94 
96 
97  // get the input
99  if (!useGsfTracks_)
100  e.getByLabel(trackProducer_,tracksH);
101 
102  // get the input
104  if (useGsfTracks_)
105  e.getByLabel(gsfTrackProducer_, gsfTracksH);
106 
107  //Get the Beam Spot position
108  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
109  e.getByLabel(bsProducer_,recoBeamSpotHandle);
110 
111  // gets its position
112  const BeamSpot::Point& bsPosition = recoBeamSpotHandle->position();
113  Global3DPoint bs(bsPosition.x(),bsPosition.y(),0);
114  process(tracksH, gsfTracksH, outEle, bs);
115 
116  return;
117 }
118 
120 
121  if (!useGsfTracks_) {
122 
123  for (unsigned int i=0; i<tracksH->size(); ++i) {
124 
125  const TrackRef trackRef = edm::Ref<TrackCollection>(tracksH, i);
126  edm::RefToBase<TrajectorySeed> seed = trackRef->extra()->seedRef();
127  ElectronSeedRef elseed=seed.castTo<ElectronSeedRef>();
128 
129  edm::RefToBase<CaloCluster> caloCluster = elseed->caloCluster() ;
130  SuperClusterRef scRef = caloCluster.castTo<SuperClusterRef>() ;
131 
132  // Get the momentum at vertex (not at the innermost layer)
133  TSCPBuilderNoMaterial tscpBuilder;
134 
136  TrajectoryStateClosestToPoint tscp = tscpBuilder(fts, bs);
137 
138  float scale = scRef->energy()/tscp.momentum().mag();
139 
140  const math::XYZTLorentzVector momentum(tscp.momentum().x()*scale,
141  tscp.momentum().y()*scale,
142  tscp.momentum().z()*scale,
143  scRef->energy());
144 
145  Electron ele(trackRef->charge(), momentum, trackRef->vertex());
146  ele.setSuperCluster(scRef);
147  edm::Ref<TrackCollection> myRef(tracksH, i);
148  ele.setTrack(myRef);
149  outEle.push_back(ele);
150  } // loop over tracks
151  } else {
152 
153  // clean gsf tracks
154  std::vector<unsigned int> flag(gsfTracksH->size(), 0);
155  if (gsfTracksH->size() == 0)
156  return;
157 
158  for (unsigned int i=0; i<gsfTracksH->size()-1; ++i) {
159  const GsfTrackRef trackRef1 = edm::Ref<GsfTrackCollection>(gsfTracksH, i);
160  ElectronSeedRef elseed1 = trackRef1->extra()->seedRef().castTo<ElectronSeedRef>();
161  SuperClusterRef scRef1 = elseed1->caloCluster().castTo<SuperClusterRef>();
162 
165  GlobalVector innMom;
166  float pin1 = trackRef1->pMode();
167  if (fts.isValid()) {
168  mtsMode_->momentumFromModeCartesian(fts, innMom);
169  pin1 = innMom.mag();
170  }
171 
172  for (unsigned int j=i+1; j<gsfTracksH->size(); ++j) {
173  const GsfTrackRef trackRef2 = edm::Ref<GsfTrackCollection>(gsfTracksH, j);
174  ElectronSeedRef elseed2 = trackRef2->extra()->seedRef().castTo<ElectronSeedRef>();
175  SuperClusterRef scRef2 = elseed2->caloCluster().castTo<SuperClusterRef>();
176 
179  GlobalVector innMom;
180  float pin2 = trackRef2->pMode();
181  if (fts.isValid()) {
182  mtsMode_->momentumFromModeCartesian(fts, innMom);
183  pin2 = innMom.mag();
184  }
185 
186  if (scRef1 == scRef2) {
187  bool isSameLayer = false;
188  bool iGsfInnermostWithLostHits = isInnerMostWithLostHits(trackRef2, trackRef1, isSameLayer);
189 
190  if (iGsfInnermostWithLostHits) {
191  flag[j] = 1;
192  } else if(isSameLayer) {
193  if(fabs((scRef1->energy()/pin1)-1) < fabs((scRef2->energy()/pin2)-1))
194  flag[j] = 1;
195  } else {
196  flag[i] = 1;
197  }
198  }
199  }
200  }
201 
202  for (unsigned int i=0; i<gsfTracksH->size(); ++i) {
203  if (flag[i] == 1)
204  continue;
205 
206  const GsfTrackRef trackRef = edm::Ref<GsfTrackCollection>(gsfTracksH, i);
207  ElectronSeedRef elseed = trackRef->extra()->seedRef().castTo<ElectronSeedRef>();
208  SuperClusterRef scRef = elseed->caloCluster().castTo<SuperClusterRef>();
209 
210  // Get the momentum at vertex (not at the innermost layer)
213  GlobalVector innMom;
214  mtsMode_->momentumFromModeCartesian(inTSOS, innMom);
215  if (fts.isValid()) {
216  mtsMode_->momentumFromModeCartesian(fts, innMom);
217  }
218 
219  float scale = scRef->energy()/innMom.mag();
220  const math::XYZTLorentzVector momentum(innMom.x()*scale,
221  innMom.y()*scale,
222  innMom.z()*scale,
223  scRef->energy());
224 
225  Electron ele(trackRef->charge(), momentum, trackRef->vertex());
226  ele.setSuperCluster(scRef);
227  edm::Ref<GsfTrackCollection> myRef(gsfTracksH, i);
228  ele.setGsfTrack(myRef);
229  outEle.push_back(ele);
230  }
231  }
232 }
233 
234 bool EgammaHLTPixelMatchElectronAlgo::isInnerMostWithLostHits(const reco::GsfTrackRef& nGsfTrack, const reco::GsfTrackRef& iGsfTrack, bool& sameLayer) {
235 
236  // define closest using the lost hits on the expectedhitsineer
237  unsigned int nLostHits = nGsfTrack->trackerExpectedHitsInner().numberOfLostHits();
238  unsigned int iLostHits = iGsfTrack->trackerExpectedHitsInner().numberOfLostHits();
239 
240  if (nLostHits!=iLostHits) {
241  return (nLostHits > iLostHits);
242  } else {
243  sameLayer = true;
244  return false;
245  }
246 }
247 
248 
unsigned long long cacheIdentifier() const
int i
Definition: DBlmapReader.cc:9
long int flag
Definition: mlp_lapack.h:47
FreeTrajectoryState innerFreeState(const reco::Track &tk, const MagneticField *field)
void process(edm::Handle< reco::TrackCollection > tracksH, edm::Handle< reco::GsfTrackCollection > gsfTracksH, reco::ElectronCollection &outEle, Global3DPoint &bs)
T y() const
Definition: PV3DBase.h:62
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:30
bool momentumFromModeCartesian(const TrajectoryStateOnSurface tsos, GlobalVector &momentum) const
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
edm::ESHandle< MagneticField > magField_
T mag() const
Definition: PV3DBase.h:66
TrajectoryStateOnSurface extrapolatedState(const TrajectoryStateOnSurface tsos, const GlobalPoint &point) const
void run(edm::Event &, reco::ElectronCollection &)
T z() const
Definition: PV3DBase.h:63
int j
Definition: DBlmapReader.cc:9
bool isInnerMostWithLostHits(const reco::GsfTrackRef &, const reco::GsfTrackRef &, bool &)
void setupES(const edm::EventSetup &setup)
MultiTrajectoryStateTransform * mtsTransform_
std::vector< Electron > ElectronCollection
collectin of Electron objects
Definition: ElectronFwd.h:9
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
tuple conf
Definition: dbtoconf.py:185
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
EgammaHLTPixelMatchElectronAlgo(const edm::ParameterSet &conf)
TrajectoryStateOnSurface innerStateOnSurface(const reco::GsfTrack &tk) const
edm::ESHandle< TrackerGeometry > trackerGeom_
void setSuperCluster(const reco::SuperClusterRef &r)
set refrence to Photon component
Definition: Electron.h:36
T x() const
Definition: PV3DBase.h:61