CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules 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 //
17 
22 
25 
30 
33 
36 
39 
42 
44 
45 using namespace edm;
46 using namespace std;
47 using namespace reco;
48 
51  : trackProducer_(iC.consumes<reco::TrackCollection>(conf.getParameter<edm::InputTag>("TrackProducer"))),
52  gsfTrackProducer_(iC.consumes<reco::GsfTrackCollection>(conf.getParameter<edm::InputTag>("GsfTrackProducer"))),
53  useGsfTracks_(conf.getParameter<bool>("UseGsfTracks")),
54  bsProducer_(iC.consumes<reco::BeamSpot>(conf.getParameter<edm::InputTag>("BSProducer"))),
55  mtsTransform_(nullptr),
56  cacheIDTDGeom_(0),
57  cacheIDMagField_(0) {}
58 
60 
62  //services
63 
64  bool updateField(false);
66  updateField = true;
67  cacheIDMagField_ = es.get<IdealMagneticFieldRecord>().cacheIdentifier();
69  }
70 
71  if (useGsfTracks_) { //only need the geom and mtsTransform if we are doing gsf tracks
72  bool updateGeometry(false);
74  updateGeometry = true;
75  cacheIDTDGeom_ = es.get<TrackerDigiGeometryRecord>().cacheIdentifier();
77  }
78  if (updateField || updateGeometry || !mtsTransform_) {
79  delete mtsTransform_;
81  }
82  }
83 }
84 
86  // get the input
88  if (!useGsfTracks_)
89  e.getByToken(trackProducer_, tracksH);
90 
91  // get the input
93  if (useGsfTracks_)
94  e.getByToken(gsfTrackProducer_, gsfTracksH);
95 
96  //Get the Beam Spot position
97  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
98  e.getByToken(bsProducer_, recoBeamSpotHandle);
99 
100  // gets its position
101  const BeamSpot::Point& bsPosition = recoBeamSpotHandle->position();
102  Global3DPoint bs(bsPosition.x(), bsPosition.y(), 0);
103  process(tracksH, gsfTracksH, outEle, bs);
104 
105  return;
106 }
107 
110  ElectronCollection& outEle,
111  Global3DPoint& bs) {
112  if (!useGsfTracks_) {
113  for (unsigned int i = 0; i < tracksH->size(); ++i) {
114  const TrackRef trackRef = edm::Ref<TrackCollection>(tracksH, i);
115  edm::RefToBase<TrajectorySeed> seed = trackRef->extra()->seedRef();
116  ElectronSeedRef elseed = seed.castTo<ElectronSeedRef>();
117 
118  edm::RefToBase<CaloCluster> caloCluster = elseed->caloCluster();
119  SuperClusterRef scRef = caloCluster.castTo<SuperClusterRef>();
120 
121  // Get the momentum at vertex (not at the innermost layer)
122  TSCPBuilderNoMaterial tscpBuilder;
123 
125  TrajectoryStateClosestToPoint tscp = tscpBuilder(fts, bs);
126 
127  float scale = scRef->energy() / tscp.momentum().mag();
128 
129  const math::XYZTLorentzVector momentum(
130  tscp.momentum().x() * scale, tscp.momentum().y() * scale, tscp.momentum().z() * scale, scRef->energy());
131 
132  Electron ele(trackRef->charge(), momentum, trackRef->vertex());
133  ele.setSuperCluster(scRef);
134  edm::Ref<TrackCollection> myRef(tracksH, i);
135  ele.setTrack(myRef);
136  outEle.push_back(ele);
137  } // loop over tracks
138  } else {
139  // clean gsf tracks
140  std::vector<unsigned int> flag(gsfTracksH->size(), 0);
141  if (gsfTracksH->empty())
142  return;
143 
144  for (unsigned int i = 0; i < gsfTracksH->size() - 1; ++i) {
145  const GsfTrackRef trackRef1 = edm::Ref<GsfTrackCollection>(gsfTracksH, i);
146  ElectronSeedRef elseed1 = trackRef1->extra()->seedRef().castTo<ElectronSeedRef>();
147  SuperClusterRef scRef1 = elseed1->caloCluster().castTo<SuperClusterRef>();
148 
151  GlobalVector innMom;
152  float pin1 = trackRef1->pMode();
153  if (fts.isValid()) {
155  pin1 = innMom.mag();
156  }
157 
158  for (unsigned int j = i + 1; j < gsfTracksH->size(); ++j) {
159  const GsfTrackRef trackRef2 = edm::Ref<GsfTrackCollection>(gsfTracksH, j);
160  ElectronSeedRef elseed2 = trackRef2->extra()->seedRef().castTo<ElectronSeedRef>();
161  SuperClusterRef scRef2 = elseed2->caloCluster().castTo<SuperClusterRef>();
162 
165  GlobalVector innMom;
166  float pin2 = trackRef2->pMode();
167  if (fts.isValid()) {
169  pin2 = innMom.mag();
170  }
171 
172  if (scRef1 == scRef2) {
173  bool isSameLayer = false;
174  bool iGsfInnermostWithLostHits = isInnerMostWithLostHits(trackRef2, trackRef1, isSameLayer);
175 
176  if (iGsfInnermostWithLostHits) {
177  flag[j] = 1;
178  } else if (isSameLayer) {
179  if (fabs((scRef1->energy() / pin1) - 1) < fabs((scRef2->energy() / pin2) - 1))
180  flag[j] = 1;
181  } else {
182  flag[i] = 1;
183  }
184  }
185  }
186  }
187 
188  for (unsigned int i = 0; i < gsfTracksH->size(); ++i) {
189  if (flag[i] == 1)
190  continue;
191 
192  const GsfTrackRef trackRef = edm::Ref<GsfTrackCollection>(gsfTracksH, i);
193  ElectronSeedRef elseed = trackRef->extra()->seedRef().castTo<ElectronSeedRef>();
194  SuperClusterRef scRef = elseed->caloCluster().castTo<SuperClusterRef>();
195 
196  // Get the momentum at vertex (not at the innermost layer)
199  GlobalVector innMom;
201  if (fts.isValid()) {
203  }
204 
205  float scale = scRef->energy() / innMom.mag();
206  const math::XYZTLorentzVector momentum(
207  innMom.x() * scale, innMom.y() * scale, innMom.z() * scale, scRef->energy());
208 
209  Electron ele(trackRef->charge(), momentum, trackRef->vertex());
210  ele.setSuperCluster(scRef);
211  edm::Ref<GsfTrackCollection> myRef(gsfTracksH, i);
212  ele.setGsfTrack(myRef);
213  outEle.push_back(ele);
214  }
215  }
216 }
217 
219  const reco::GsfTrackRef& iGsfTrack,
220  bool& sameLayer) {
221  // define closest using the lost hits on the expectedhitsineer
222  unsigned int nLostHits = nGsfTrack->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS);
223  unsigned int iLostHits = iGsfTrack->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS);
224 
225  if (nLostHits != iLostHits) {
226  return (nLostHits > iLostHits);
227  } else {
228  sameLayer = true;
229  return false;
230  }
231 }
Vector3DBase
Definition: Vector3DBase.h:8
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
EgammaHLTPixelMatchElectronAlgo::trackProducer_
edm::EDGetTokenT< reco::TrackCollection > trackProducer_
Definition: EgammaHLTPixelMatchElectronAlgo.h:54
EgammaHLTPixelMatchElectronAlgo.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
EgammaHLTPixelMatchElectronAlgo::isInnerMostWithLostHits
bool isInnerMostWithLostHits(const reco::GsfTrackRef &, const reco::GsfTrackRef &, bool &)
Definition: EgammaHLTPixelMatchElectronAlgo.cc:218
FreeTrajectoryState.h
EgammaHLTPixelMatchElectronAlgo::EgammaHLTPixelMatchElectronAlgo
EgammaHLTPixelMatchElectronAlgo(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
Definition: EgammaHLTPixelMatchElectronAlgo.cc:49
MessageLogger.h
MultiTrajectoryStateTransform::extrapolatedState
TrajectoryStateOnSurface extrapolatedState(const TrajectoryStateOnSurface tsos, const GlobalPoint &point) const
Definition: MultiTrajectoryStateTransform.cc:104
TrackCandidateCollection.h
EgammaHLTPixelMatchElectronAlgo::useGsfTracks_
bool useGsfTracks_
Definition: EgammaHLTPixelMatchElectronAlgo.h:56
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
TrajectoryStateClosestToPoint.h
Electron
Definition: Electron.py:1
edm
HLT enums.
Definition: AlignableModifier.h:19
EgammaHLTPixelMatchElectronAlgo::~EgammaHLTPixelMatchElectronAlgo
~EgammaHLTPixelMatchElectronAlgo()
Definition: EgammaHLTPixelMatchElectronAlgo.cc:59
TrackerRecoGeometryRecord.h
EgammaHLTPixelMatchElectronAlgo::gsfTrackProducer_
edm::EDGetTokenT< reco::GsfTrackCollection > gsfTrackProducer_
Definition: EgammaHLTPixelMatchElectronAlgo.h:55
multiTrajectoryStateMode::momentumFromModeCartesian
bool momentumFromModeCartesian(TrajectoryStateOnSurface const &tsos, GlobalVector &momentum)
Definition: MultiTrajectoryStateMode.cc:16
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
EgammaHLTPixelMatchElectronAlgo::setupES
void setupES(const edm::EventSetup &setup)
Definition: EgammaHLTPixelMatchElectronAlgo.cc:61
edm::Handle
Definition: AssociativeIterator.h:50
ElectronSeedFwd.h
edm::Ref< TrackCollection >
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
cms::cuda::bs
bs
Definition: HistoContainer.h:127
EgammaHLTPixelMatchElectronAlgo::bsProducer_
edm::EDGetTokenT< reco::BeamSpot > bsProducer_
Definition: EgammaHLTPixelMatchElectronAlgo.h:57
EgammaHLTPixelMatchElectronAlgo::magField_
edm::ESHandle< MagneticField > magField_
Definition: EgammaHLTPixelMatchElectronAlgo.h:61
Track.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
TrackFwd.h
BeamSpot.h
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
MultiTrajectoryStateMode.h
reco::BeamSpot
Definition: BeamSpot.h:21
IdealMagneticFieldRecord.h
reco::BeamSpot::position
const Point & position() const
position
Definition: BeamSpot.h:59
Point3DBase< float, GlobalTag >
MultiTrajectoryStateTransform.h
EgammaHLTPixelMatchElectronAlgo::trackerGeom_
edm::ESHandle< TrackerGeometry > trackerGeom_
Definition: EgammaHLTPixelMatchElectronAlgo.h:62
EgammaHLTPixelMatchElectronAlgo::process
void process(edm::Handle< reco::TrackCollection > tracksH, edm::Handle< reco::GsfTrackCollection > gsfTracksH, reco::ElectronCollection &outEle, Global3DPoint &bs)
Definition: EgammaHLTPixelMatchElectronAlgo.cc:108
Scenarios_cff.scale
scale
Definition: Scenarios_cff.py:2186
edm::ParameterSet
Definition: ParameterSet.h:36
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
edm::EventSetup
Definition: EventSetup.h:57
TrajectoryStateClosestToPoint
Definition: TrajectoryStateClosestToPoint.h:18
TSCPBuilderNoMaterial.h
get
#define get
reco::ElectronCollection
std::vector< Electron > ElectronCollection
collectin of Electron objects
Definition: ElectronFwd.h:9
MultiTrajectoryStateTransform
Definition: MultiTrajectoryStateTransform.h:18
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
reco::GsfTrackCollection
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h:9
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:85
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
SuperCluster.h
EgammaHLTPixelMatchElectronAlgo::mtsTransform_
MultiTrajectoryStateTransform * mtsTransform_
Definition: EgammaHLTPixelMatchElectronAlgo.h:59
EgammaHLTPixelMatchElectronAlgo::cacheIDMagField_
unsigned long long cacheIDMagField_
Definition: EgammaHLTPixelMatchElectronAlgo.h:64
Point3D.h
edm::RefToBase< TrajectorySeed >
MultiTrajectoryStateTransform::innerStateOnSurface
TrajectoryStateOnSurface innerStateOnSurface(const reco::GsfTrack &tk) const
Definition: MultiTrajectoryStateTransform.cc:23
TrajectoryStateTransform.h
reco::BeamSpot::Point
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:27
edm::eventsetup::EventSetupRecord::cacheIdentifier
unsigned long long cacheIdentifier() const
Definition: EventSetupRecord.h:185
ParameterSet.h
TrackCandidate.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
SurveyInfoScenario_cff.seed
seed
Definition: SurveyInfoScenario_cff.py:295
ElectronSeed.h
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116
EgammaHLTPixelMatchElectronAlgo::cacheIDTDGeom_
int unsigned long long cacheIDTDGeom_
Definition: EgammaHLTPixelMatchElectronAlgo.h:63
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37