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 //
17 
22 
27 
30 
33 
36 
38 
40 
41 using namespace edm;
42 using namespace std;
43 using namespace reco;
44 
47  : trackProducer_(iC.consumes(conf.getParameter<edm::InputTag>("TrackProducer"))),
48  gsfTrackProducer_(iC.consumes(conf.getParameter<edm::InputTag>("GsfTrackProducer"))),
49  useGsfTracks_(conf.getParameter<bool>("UseGsfTracks")),
50  bsProducer_(iC.consumes<reco::BeamSpot>(conf.getParameter<edm::InputTag>("BSProducer"))),
51  magneticFieldToken_(iC.esConsumes()),
52  trackerGeometryToken_(iC.esConsumes()) {}
53 
55  //services
56  bool updateField = magneticFieldWatcher_.check(eventSetup);
57  bool updateGeometry = trackerGeometryWatcher_.check(eventSetup);
58 
59  if (updateField) {
61  }
62 
63  if (useGsfTracks_) { //only need the geom and mtsTransform if we are doing gsf tracks
64  if (updateGeometry) {
66  }
67  if (updateField || updateGeometry || !mtsTransform_) {
68  mtsTransform_ = std::make_unique<MultiTrajectoryStateTransform>(trackerGeom_.product(), magField_.product());
69  }
70  }
71 }
72 
74  // get the input
76  if (!useGsfTracks_)
77  e.getByToken(trackProducer_, tracksH);
78 
79  // get the input
81  if (useGsfTracks_)
82  e.getByToken(gsfTrackProducer_, gsfTracksH);
83 
84  //Get the Beam Spot position
85  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
86  e.getByToken(bsProducer_, recoBeamSpotHandle);
87 
88  // gets its position
89  const BeamSpot::Point& bsPosition = recoBeamSpotHandle->position();
90  Global3DPoint bs(bsPosition.x(), bsPosition.y(), 0);
91  process(tracksH, gsfTracksH, outEle, bs);
92 
93  return;
94 }
95 
98  ElectronCollection& outEle,
99  Global3DPoint& bs) {
100  if (!useGsfTracks_) {
101  for (unsigned int i = 0; i < tracksH->size(); ++i) {
102  const TrackRef trackRef = edm::Ref<TrackCollection>(tracksH, i);
103  edm::RefToBase<TrajectorySeed> seed = trackRef->extra()->seedRef();
104  ElectronSeedRef elseed = seed.castTo<ElectronSeedRef>();
105 
106  edm::RefToBase<CaloCluster> caloCluster = elseed->caloCluster();
107  SuperClusterRef scRef = caloCluster.castTo<SuperClusterRef>();
108 
109  // Get the momentum at vertex (not at the innermost layer)
110  TSCPBuilderNoMaterial tscpBuilder;
111 
113  TrajectoryStateClosestToPoint tscp = tscpBuilder(fts, bs);
114 
115  float scale = scRef->energy() / tscp.momentum().mag();
116 
117  const math::XYZTLorentzVector momentum(
118  tscp.momentum().x() * scale, tscp.momentum().y() * scale, tscp.momentum().z() * scale, scRef->energy());
119 
120  Electron ele(trackRef->charge(), momentum, trackRef->vertex());
121  ele.setSuperCluster(scRef);
122  edm::Ref<TrackCollection> myRef(tracksH, i);
123  ele.setTrack(myRef);
124  outEle.push_back(ele);
125  } // loop over tracks
126  } else {
127  // clean gsf tracks
128  std::vector<unsigned int> flag(gsfTracksH->size(), 0);
129  if (gsfTracksH->empty())
130  return;
131 
132  for (unsigned int i = 0; i < gsfTracksH->size() - 1; ++i) {
133  const GsfTrackRef trackRef1 = edm::Ref<GsfTrackCollection>(gsfTracksH, i);
134  ElectronSeedRef elseed1 = trackRef1->extra()->seedRef().castTo<ElectronSeedRef>();
135  SuperClusterRef scRef1 = elseed1->caloCluster().castTo<SuperClusterRef>();
136 
137  TrajectoryStateOnSurface inTSOS = mtsTransform_->innerStateOnSurface((*trackRef1));
138  TrajectoryStateOnSurface fts = mtsTransform_->extrapolatedState(inTSOS, bs);
139  GlobalVector innMom;
140  float pin1 = trackRef1->pMode();
141  if (fts.isValid()) {
143  pin1 = innMom.mag();
144  }
145 
146  for (unsigned int j = i + 1; j < gsfTracksH->size(); ++j) {
147  const GsfTrackRef trackRef2 = edm::Ref<GsfTrackCollection>(gsfTracksH, j);
148  ElectronSeedRef elseed2 = trackRef2->extra()->seedRef().castTo<ElectronSeedRef>();
149  SuperClusterRef scRef2 = elseed2->caloCluster().castTo<SuperClusterRef>();
150 
151  TrajectoryStateOnSurface inTSOS = mtsTransform_->innerStateOnSurface((*trackRef2));
152  TrajectoryStateOnSurface fts = mtsTransform_->extrapolatedState(inTSOS, bs);
153  GlobalVector innMom;
154  float pin2 = trackRef2->pMode();
155  if (fts.isValid()) {
157  pin2 = innMom.mag();
158  }
159 
160  if (scRef1 == scRef2) {
161  bool isSameLayer = false;
162  bool iGsfInnermostWithLostHits = isInnerMostWithLostHits(trackRef2, trackRef1, isSameLayer);
163 
164  if (iGsfInnermostWithLostHits) {
165  flag[j] = 1;
166  } else if (isSameLayer) {
167  if (fabs((scRef1->energy() / pin1) - 1) < fabs((scRef2->energy() / pin2) - 1))
168  flag[j] = 1;
169  } else {
170  flag[i] = 1;
171  }
172  }
173  }
174  }
175 
176  for (unsigned int i = 0; i < gsfTracksH->size(); ++i) {
177  if (flag[i] == 1)
178  continue;
179 
180  const GsfTrackRef trackRef = edm::Ref<GsfTrackCollection>(gsfTracksH, i);
181  ElectronSeedRef elseed = trackRef->extra()->seedRef().castTo<ElectronSeedRef>();
182  SuperClusterRef scRef = elseed->caloCluster().castTo<SuperClusterRef>();
183 
184  // Get the momentum at vertex (not at the innermost layer)
185  TrajectoryStateOnSurface inTSOS = mtsTransform_->innerStateOnSurface((*trackRef));
186  TrajectoryStateOnSurface fts = mtsTransform_->extrapolatedState(inTSOS, bs);
187  GlobalVector innMom;
189  if (fts.isValid()) {
191  }
192 
193  float scale = scRef->energy() / innMom.mag();
194  const math::XYZTLorentzVector momentum(
195  innMom.x() * scale, innMom.y() * scale, innMom.z() * scale, scRef->energy());
196 
197  Electron ele(trackRef->charge(), momentum, trackRef->vertex());
198  ele.setSuperCluster(scRef);
199  edm::Ref<GsfTrackCollection> myRef(gsfTracksH, i);
200  ele.setGsfTrack(myRef);
201  outEle.push_back(ele);
202  }
203  }
204 }
205 
207  const reco::GsfTrackRef& iGsfTrack,
208  bool& sameLayer) {
209  // define closest using the lost hits on the expectedhitsineer
210  auto nLostHits = nGsfTrack->missingInnerHits();
211  auto iLostHits = iGsfTrack->missingInnerHits();
212 
213  if (nLostHits != iLostHits) {
214  return (nLostHits > iLostHits);
215  } else {
216  sameLayer = true;
217  return false;
218  }
219 }
Vector3DBase
Definition: Vector3DBase.h:8
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
EgammaHLTPixelMatchElectronAlgo::trackProducer_
edm::EDGetTokenT< reco::TrackCollection > trackProducer_
Definition: EgammaHLTPixelMatchElectronAlgo.h:58
EgammaHLTPixelMatchElectronAlgo.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
EgammaHLTPixelMatchElectronAlgo::isInnerMostWithLostHits
bool isInnerMostWithLostHits(const reco::GsfTrackRef &, const reco::GsfTrackRef &, bool &)
Definition: EgammaHLTPixelMatchElectronAlgo.cc:206
FreeTrajectoryState.h
EgammaHLTPixelMatchElectronAlgo::magneticFieldToken_
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magneticFieldToken_
Definition: EgammaHLTPixelMatchElectronAlgo.h:71
EgammaHLTPixelMatchElectronAlgo::EgammaHLTPixelMatchElectronAlgo
EgammaHLTPixelMatchElectronAlgo(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
Definition: EgammaHLTPixelMatchElectronAlgo.cc:45
MessageLogger.h
L1EGammaCrystalsEmulatorProducer_cfi.scale
scale
Definition: L1EGammaCrystalsEmulatorProducer_cfi.py:10
TrackCandidateCollection.h
EgammaHLTPixelMatchElectronAlgo::useGsfTracks_
bool useGsfTracks_
Definition: EgammaHLTPixelMatchElectronAlgo.h:60
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
TrajectoryStateClosestToPoint.h
Electron
Definition: Electron.py:1
edm
HLT enums.
Definition: AlignableModifier.h:19
EgammaHLTPixelMatchElectronAlgo::gsfTrackProducer_
edm::EDGetTokenT< reco::GsfTrackCollection > gsfTrackProducer_
Definition: EgammaHLTPixelMatchElectronAlgo.h:59
EgammaHLTPixelMatchElectronAlgo::magneticFieldWatcher_
edm::ESWatcher< IdealMagneticFieldRecord > magneticFieldWatcher_
Definition: EgammaHLTPixelMatchElectronAlgo.h:68
multiTrajectoryStateMode::momentumFromModeCartesian
bool momentumFromModeCartesian(TrajectoryStateOnSurface const &tsos, GlobalVector &momentum)
Definition: MultiTrajectoryStateMode.cc:16
EgammaHLTPixelMatchElectronAlgo::trackerGeometryWatcher_
edm::ESWatcher< TrackerDigiGeometryRecord > trackerGeometryWatcher_
Definition: EgammaHLTPixelMatchElectronAlgo.h:69
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
EgammaHLTPixelMatchElectronAlgo::setupES
void setupES(const edm::EventSetup &setup)
Definition: EgammaHLTPixelMatchElectronAlgo.cc:54
edm::Handle
Definition: AssociativeIterator.h:50
ElectronSeedFwd.h
edm::Ref< TrackCollection >
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
fileCollector.seed
seed
Definition: fileCollector.py:127
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
cms::cuda::bs
bs
Definition: HistoContainer.h:76
EgammaHLTPixelMatchElectronAlgo::bsProducer_
edm::EDGetTokenT< reco::BeamSpot > bsProducer_
Definition: EgammaHLTPixelMatchElectronAlgo.h:61
EgammaHLTPixelMatchElectronAlgo::magField_
edm::ESHandle< MagneticField > magField_
Definition: EgammaHLTPixelMatchElectronAlgo.h:65
Track.h
TrackFwd.h
BeamSpot.h
MultiTrajectoryStateMode.h
reco::BeamSpot
Definition: BeamSpot.h:21
reco::BeamSpot::position
const Point & position() const
position
Definition: BeamSpot.h:59
Point3DBase< float, GlobalTag >
EgammaHLTPixelMatchElectronAlgo::trackerGeom_
edm::ESHandle< TrackerGeometry > trackerGeom_
Definition: EgammaHLTPixelMatchElectronAlgo.h:66
EgammaHLTPixelMatchElectronAlgo::process
void process(edm::Handle< reco::TrackCollection > tracksH, edm::Handle< reco::GsfTrackCollection > gsfTracksH, reco::ElectronCollection &outEle, Global3DPoint &bs)
Definition: EgammaHLTPixelMatchElectronAlgo.cc:96
edm::ParameterSet
Definition: ParameterSet.h:47
EgammaHLTPixelMatchElectronAlgo::mtsTransform_
std::unique_ptr< MultiTrajectoryStateTransform > mtsTransform_
Definition: EgammaHLTPixelMatchElectronAlgo.h:63
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
edm::EventSetup
Definition: EventSetup.h:58
TrajectoryStateClosestToPoint
Definition: TrajectoryStateClosestToPoint.h:18
TSCPBuilderNoMaterial.h
reco::ElectronCollection
std::vector< Electron > ElectronCollection
collectin of Electron objects
Definition: ElectronFwd.h:9
PV3DBase::mag
T mag() const
Definition: PV3DBase.h:64
trajectoryStateTransform::innerFreeState
FreeTrajectoryState innerFreeState(const reco::Track &tk, const MagneticField *field, bool withErr=true)
Definition: TrajectoryStateTransform.cc:86
std
Definition: JetResolutionObject.h:76
TSCPBuilderNoMaterial
Definition: TSCPBuilderNoMaterial.h:17
SuperClusterFwd.h
FreeTrajectoryState
Definition: FreeTrajectoryState.h:27
EgammaHLTPixelMatchElectronAlgo::run
void run(edm::Event &, reco::ElectronCollection &)
Definition: EgammaHLTPixelMatchElectronAlgo.cc:73
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
SuperCluster.h
Point3D.h
edm::RefToBase< TrajectorySeed >
TrajectoryStateTransform.h
reco::BeamSpot::Point
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:27
ParameterSet.h
TrackCandidate.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
EgammaHLTPixelMatchElectronAlgo::trackerGeometryToken_
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerGeometryToken_
Definition: EgammaHLTPixelMatchElectronAlgo.h:72
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
ElectronSeed.h
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:117
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37