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 //
14 //
16 
19 
24 
27 
32 
35 
38 
41 
44 
45 using namespace edm;
46 using namespace std;
47 using namespace reco;
48 
50  trackProducer_(conf.getParameter<edm::InputTag>("TrackProducer")),
51  gsfTrackProducer_(conf.getParameter<edm::InputTag>("GsfTrackProducer")),
52  useGsfTracks_(conf.getParameter<bool>("UseGsfTracks")),
53  bsProducer_(conf.getParameter<edm::InputTag>("BSProducer")),
54  mtsMode_(new MultiTrajectoryStateMode()),
55  mtsTransform_(0),
56  cacheIDTDGeom_(0),
57  cacheIDMagField_(0)
58 {
59 
60 }
61 
63 {
64  delete mtsTransform_;
65  delete mtsMode_;
66  }
67 
69  //services
70 
71  bool updateField(false);
73  updateField = true;
74  cacheIDMagField_=es.get<IdealMagneticFieldRecord>().cacheIdentifier();
76  }
77 
78  if(useGsfTracks_){ //only need the geom and mtsTransform if we are doing gsf tracks
79  bool updateGeometry(false);
81  updateGeometry = true;
82  cacheIDTDGeom_=es.get<TrackerDigiGeometryRecord>().cacheIdentifier();
84  }
85  if ( updateField || updateGeometry || !mtsTransform_ ) {
86  delete mtsTransform_;
88  }
89  }
90 
91 
92 }
93 
95 
96  // get the input
98  if (!useGsfTracks_)
99  e.getByLabel(trackProducer_,tracksH);
100 
101  // get the input
103  if (useGsfTracks_)
104  e.getByLabel(gsfTrackProducer_, gsfTracksH);
105 
106  //Get the Beam Spot position
107  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
108  e.getByLabel(bsProducer_,recoBeamSpotHandle);
109 
110  // gets its position
111  const BeamSpot::Point& bsPosition = recoBeamSpotHandle->position();
112  Global3DPoint bs(bsPosition.x(),bsPosition.y(),0);
113  process(tracksH, gsfTracksH, outEle, bs);
114 
115  return;
116 }
117 
119 
120  if (!useGsfTracks_) {
121 
122  for (unsigned int i=0; i<tracksH->size(); ++i) {
123 
124  const TrackRef trackRef = edm::Ref<TrackCollection>(tracksH, i);
125  edm::RefToBase<TrajectorySeed> seed = trackRef->extra()->seedRef();
126  ElectronSeedRef elseed=seed.castTo<ElectronSeedRef>();
127 
128  edm::RefToBase<CaloCluster> caloCluster = elseed->caloCluster() ;
129  SuperClusterRef scRef = caloCluster.castTo<SuperClusterRef>() ;
130 
131  // Get the momentum at vertex (not at the innermost layer)
132  TSCPBuilderNoMaterial tscpBuilder;
133 
135  TrajectoryStateClosestToPoint tscp = tscpBuilder(fts, bs);
136 
137  float scale = scRef->energy()/tscp.momentum().mag();
138 
139  const math::XYZTLorentzVector momentum(tscp.momentum().x()*scale,
140  tscp.momentum().y()*scale,
141  tscp.momentum().z()*scale,
142  scRef->energy());
143 
144  Electron ele(trackRef->charge(), momentum, trackRef->vertex());
145  ele.setSuperCluster(scRef);
146  edm::Ref<TrackCollection> myRef(tracksH, i);
147  ele.setTrack(myRef);
148  outEle.push_back(ele);
149  } // loop over tracks
150  } else {
151 
152  // clean gsf tracks
153  std::vector<unsigned int> flag(gsfTracksH->size(), 0);
154  if (gsfTracksH->size() == 0)
155  return;
156 
157  for (unsigned int i=0; i<gsfTracksH->size()-1; ++i) {
158  const GsfTrackRef trackRef1 = edm::Ref<GsfTrackCollection>(gsfTracksH, i);
159  ElectronSeedRef elseed1 = trackRef1->extra()->seedRef().castTo<ElectronSeedRef>();
160  SuperClusterRef scRef1 = elseed1->caloCluster().castTo<SuperClusterRef>();
161 
164  GlobalVector innMom;
165  float pin1 = trackRef1->pMode();
166  if (fts.isValid()) {
167  mtsMode_->momentumFromModeCartesian(fts, innMom);
168  pin1 = innMom.mag();
169  }
170 
171  for (unsigned int j=i+1; j<gsfTracksH->size(); ++j) {
172  const GsfTrackRef trackRef2 = edm::Ref<GsfTrackCollection>(gsfTracksH, j);
173  ElectronSeedRef elseed2 = trackRef2->extra()->seedRef().castTo<ElectronSeedRef>();
174  SuperClusterRef scRef2 = elseed2->caloCluster().castTo<SuperClusterRef>();
175 
178  GlobalVector innMom;
179  float pin2 = trackRef2->pMode();
180  if (fts.isValid()) {
181  mtsMode_->momentumFromModeCartesian(fts, innMom);
182  pin2 = innMom.mag();
183  }
184 
185  if (scRef1 == scRef2) {
186  bool isSameLayer = false;
187  bool iGsfInnermostWithLostHits = isInnerMostWithLostHits(trackRef2, trackRef1, isSameLayer);
188 
189  if (iGsfInnermostWithLostHits) {
190  flag[j] = 1;
191  } else if(isSameLayer) {
192  if(fabs((scRef1->energy()/pin1)-1) < fabs((scRef2->energy()/pin2)-1))
193  flag[j] = 1;
194  } else {
195  flag[i] = 1;
196  }
197  }
198  }
199  }
200 
201  for (unsigned int i=0; i<gsfTracksH->size(); ++i) {
202  if (flag[i] == 1)
203  continue;
204 
205  const GsfTrackRef trackRef = edm::Ref<GsfTrackCollection>(gsfTracksH, i);
206  ElectronSeedRef elseed = trackRef->extra()->seedRef().castTo<ElectronSeedRef>();
207  SuperClusterRef scRef = elseed->caloCluster().castTo<SuperClusterRef>();
208 
209  // Get the momentum at vertex (not at the innermost layer)
212  GlobalVector innMom;
213  mtsMode_->momentumFromModeCartesian(inTSOS, innMom);
214  if (fts.isValid()) {
215  mtsMode_->momentumFromModeCartesian(fts, innMom);
216  }
217 
218  float scale = scRef->energy()/innMom.mag();
219  const math::XYZTLorentzVector momentum(innMom.x()*scale,
220  innMom.y()*scale,
221  innMom.z()*scale,
222  scRef->energy());
223 
224  Electron ele(trackRef->charge(), momentum, trackRef->vertex());
225  ele.setSuperCluster(scRef);
226  edm::Ref<GsfTrackCollection> myRef(gsfTracksH, i);
227  ele.setGsfTrack(myRef);
228  outEle.push_back(ele);
229  }
230  }
231 }
232 
233 bool EgammaHLTPixelMatchElectronAlgo::isInnerMostWithLostHits(const reco::GsfTrackRef& nGsfTrack, const reco::GsfTrackRef& iGsfTrack, bool& sameLayer) {
234 
235  // define closest using the lost hits on the expectedhitsineer
236  unsigned int nLostHits = nGsfTrack->trackerExpectedHitsInner().numberOfLostHits();
237  unsigned int iLostHits = iGsfTrack->trackerExpectedHitsInner().numberOfLostHits();
238 
239  if (nLostHits!=iLostHits) {
240  return (nLostHits > iLostHits);
241  } else {
242  sameLayer = true;
243  return false;
244  }
245 }
246 
247 
unsigned long long cacheIdentifier() const
int i
Definition: DBlmapReader.cc:9
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:63
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:29
bool momentumFromModeCartesian(const TrajectoryStateOnSurface tsos, GlobalVector &momentum) const
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
edm::ESHandle< MagneticField > magField_
T mag() const
Definition: PV3DBase.h:67
TrajectoryStateOnSurface extrapolatedState(const TrajectoryStateOnSurface tsos, const GlobalPoint &point) const
void run(edm::Event &, reco::ElectronCollection &)
T z() const
Definition: PV3DBase.h:64
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:390
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:35
T x() const
Definition: PV3DBase.h:62