CMS 3D CMS Logo

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_(iC.consumes<reco::TrackCollection>(conf.getParameter<edm::InputTag>("TrackProducer"))),
51  gsfTrackProducer_(iC.consumes<reco::GsfTrackCollection>(conf.getParameter<edm::InputTag>("GsfTrackProducer"))),
52  useGsfTracks_(conf.getParameter<bool>("UseGsfTracks")),
53  bsProducer_(iC.consumes<reco::BeamSpot>(conf.getParameter<edm::InputTag>("BSProducer"))),
54  mtsTransform_(nullptr),
55  cacheIDTDGeom_(0),
56  cacheIDMagField_(0)
57 {
58 
59 }
60 
62 {
63  delete mtsTransform_;
64  }
65 
67  //services
68 
69  bool updateField(false);
71  updateField = true;
72  cacheIDMagField_=es.get<IdealMagneticFieldRecord>().cacheIdentifier();
74  }
75 
76  if(useGsfTracks_){ //only need the geom and mtsTransform if we are doing gsf tracks
77  bool updateGeometry(false);
79  updateGeometry = true;
80  cacheIDTDGeom_=es.get<TrackerDigiGeometryRecord>().cacheIdentifier();
82  }
83  if ( updateField || updateGeometry || !mtsTransform_ ) {
84  delete mtsTransform_;
86  }
87  }
88 
89 
90 }
91 
93 
94  // get the input
96  if (!useGsfTracks_)
97  e.getByToken(trackProducer_,tracksH);
98 
99  // get the input
101  if (useGsfTracks_)
102  e.getByToken(gsfTrackProducer_, gsfTracksH);
103 
104  //Get the Beam Spot position
105  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
106  e.getByToken(bsProducer_,recoBeamSpotHandle);
107 
108  // gets its position
109  const BeamSpot::Point& bsPosition = recoBeamSpotHandle->position();
110  Global3DPoint bs(bsPosition.x(),bsPosition.y(),0);
111  process(tracksH, gsfTracksH, outEle, bs);
112 
113  return;
114 }
115 
117 
118  if (!useGsfTracks_) {
119 
120  for (unsigned int i=0; i<tracksH->size(); ++i) {
121 
122  const TrackRef trackRef = edm::Ref<TrackCollection>(tracksH, i);
123  edm::RefToBase<TrajectorySeed> seed = trackRef->extra()->seedRef();
124  ElectronSeedRef elseed=seed.castTo<ElectronSeedRef>();
125 
126  edm::RefToBase<CaloCluster> caloCluster = elseed->caloCluster() ;
127  SuperClusterRef scRef = caloCluster.castTo<SuperClusterRef>() ;
128 
129  // Get the momentum at vertex (not at the innermost layer)
130  TSCPBuilderNoMaterial tscpBuilder;
131 
133  TrajectoryStateClosestToPoint tscp = tscpBuilder(fts, bs);
134 
135  float scale = scRef->energy()/tscp.momentum().mag();
136 
137  const math::XYZTLorentzVector momentum(tscp.momentum().x()*scale,
138  tscp.momentum().y()*scale,
139  tscp.momentum().z()*scale,
140  scRef->energy());
141 
142  Electron ele(trackRef->charge(), momentum, trackRef->vertex());
143  ele.setSuperCluster(scRef);
144  edm::Ref<TrackCollection> myRef(tracksH, i);
145  ele.setTrack(myRef);
146  outEle.push_back(ele);
147  } // loop over tracks
148  } else {
149 
150  // clean gsf tracks
151  std::vector<unsigned int> flag(gsfTracksH->size(), 0);
152  if (gsfTracksH->empty())
153  return;
154 
155  for (unsigned int i=0; i<gsfTracksH->size()-1; ++i) {
156  const GsfTrackRef trackRef1 = edm::Ref<GsfTrackCollection>(gsfTracksH, i);
157  ElectronSeedRef elseed1 = trackRef1->extra()->seedRef().castTo<ElectronSeedRef>();
158  SuperClusterRef scRef1 = elseed1->caloCluster().castTo<SuperClusterRef>();
159 
162  GlobalVector innMom;
163  float pin1 = trackRef1->pMode();
164  if (fts.isValid()) {
166  pin1 = innMom.mag();
167  }
168 
169  for (unsigned int j=i+1; j<gsfTracksH->size(); ++j) {
170  const GsfTrackRef trackRef2 = edm::Ref<GsfTrackCollection>(gsfTracksH, j);
171  ElectronSeedRef elseed2 = trackRef2->extra()->seedRef().castTo<ElectronSeedRef>();
172  SuperClusterRef scRef2 = elseed2->caloCluster().castTo<SuperClusterRef>();
173 
176  GlobalVector innMom;
177  float pin2 = trackRef2->pMode();
178  if (fts.isValid()) {
180  pin2 = innMom.mag();
181  }
182 
183  if (scRef1 == scRef2) {
184  bool isSameLayer = false;
185  bool iGsfInnermostWithLostHits = isInnerMostWithLostHits(trackRef2, trackRef1, isSameLayer);
186 
187  if (iGsfInnermostWithLostHits) {
188  flag[j] = 1;
189  } else if(isSameLayer) {
190  if(fabs((scRef1->energy()/pin1)-1) < fabs((scRef2->energy()/pin2)-1))
191  flag[j] = 1;
192  } else {
193  flag[i] = 1;
194  }
195  }
196  }
197  }
198 
199  for (unsigned int i=0; i<gsfTracksH->size(); ++i) {
200  if (flag[i] == 1)
201  continue;
202 
203  const GsfTrackRef trackRef = edm::Ref<GsfTrackCollection>(gsfTracksH, i);
204  ElectronSeedRef elseed = trackRef->extra()->seedRef().castTo<ElectronSeedRef>();
205  SuperClusterRef scRef = elseed->caloCluster().castTo<SuperClusterRef>();
206 
207  // Get the momentum at vertex (not at the innermost layer)
210  GlobalVector innMom;
212  if (fts.isValid()) {
214  }
215 
216  float scale = scRef->energy()/innMom.mag();
217  const math::XYZTLorentzVector momentum(innMom.x()*scale,
218  innMom.y()*scale,
219  innMom.z()*scale,
220  scRef->energy());
221 
222  Electron ele(trackRef->charge(), momentum, trackRef->vertex());
223  ele.setSuperCluster(scRef);
224  edm::Ref<GsfTrackCollection> myRef(gsfTracksH, i);
225  ele.setGsfTrack(myRef);
226  outEle.push_back(ele);
227  }
228  }
229 }
230 
231 bool EgammaHLTPixelMatchElectronAlgo::isInnerMostWithLostHits(const reco::GsfTrackRef& nGsfTrack, const reco::GsfTrackRef& iGsfTrack, bool& sameLayer) {
232 
233  // define closest using the lost hits on the expectedhitsineer
234  unsigned int nLostHits = nGsfTrack->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS);
235  unsigned int iLostHits = iGsfTrack->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS);
236 
237  if (nLostHits!=iLostHits) {
238  return (nLostHits > iLostHits);
239  } else {
240  sameLayer = true;
241  return false;
242  }
243 }
244 
245 
unsigned long long cacheIdentifier() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
void process(edm::Handle< reco::TrackCollection > tracksH, edm::Handle< reco::GsfTrackCollection > gsfTracksH, reco::ElectronCollection &outEle, Global3DPoint &bs)
#define nullptr
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
T y() const
Definition: PV3DBase.h:63
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:29
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
edm::EDGetTokenT< reco::GsfTrackCollection > gsfTrackProducer_
void run(edm::Event &, reco::ElectronCollection &)
EgammaHLTPixelMatchElectronAlgo(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
T z() const
Definition: PV3DBase.h:64
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h: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
edm::EDGetTokenT< reco::BeamSpot > bsProducer_
edm::EDGetTokenT< reco::TrackCollection > trackProducer_
TrajectoryStateOnSurface innerStateOnSurface(const reco::GsfTrack &tk) const
fixed size matrix
HLT enums.
T get() const
Definition: EventSetup.h:71
edm::ESHandle< TrackerGeometry > trackerGeom_
const Point & position() const
position
Definition: BeamSpot.h:62
FreeTrajectoryState innerFreeState(const reco::Track &tk, const MagneticField *field, bool withErr=true)
bool momentumFromModeCartesian(TrajectoryStateOnSurface const &tsos, GlobalVector &momentum)
T x() const
Definition: PV3DBase.h:62
T const * product() const
Definition: ESHandle.h:86