CMS 3D CMS Logo

EgammaHLTGsfTrackVarProducer.cc
Go to the documentation of this file.
1 
9 //this class is designed to calculate dEtaIn,dPhiIn gsf track - supercluster pairs
10 //it can take as input std::vector<Electron> which the gsf track-sc is already done
11 //or it can run over the std::vector<GsfTrack> directly in which case it will pick the smallest dEta,dPhi
12 //the dEta, dPhi do not have to be from the same track
13 //it can optionally set dEta, dPhi to 0 based on the number of tracks found
14 
39 
41 public:
43  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
44  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
45 
46 private:
51 
54 
59 
68 };
69 
71  : recoEcalCandToken_(
72  consumes<reco::RecoEcalCandidateCollection>(config.getParameter<edm::InputTag>("recoEcalCandidateProducer"))),
73  electronToken_{consumes<reco::ElectronCollection>(config.getParameter<edm::InputTag>("inputCollection"))},
74  gsfTrackToken_{consumes<reco::GsfTrackCollection>(config.getParameter<edm::InputTag>("inputCollection"))},
75  beamSpotToken_{consumes<reco::BeamSpot>(config.getParameter<edm::InputTag>("beamSpotProducer"))},
76  magneticFieldToken_{esConsumes<MagneticField, IdealMagneticFieldRecord>()},
77  trackerGeometryToken_{esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()},
78  upperTrackNrToRemoveCut_{config.getParameter<int>("upperTrackNrToRemoveCut")},
79  lowerTrackNrToRemoveCut_{config.getParameter<int>("lowerTrackNrToRemoveCut")},
80  useDefaultValuesForBarrel_{config.getParameter<bool>("useDefaultValuesForBarrel")},
81  useDefaultValuesForEndcap_{config.getParameter<bool>("useDefaultValuesForEndcap")},
82  dEtaMapPutToken_{produces<reco::RecoEcalCandidateIsolationMap>("Deta").setBranchAlias("deta")},
83  dEtaSeedMapPutToken_{produces<reco::RecoEcalCandidateIsolationMap>("DetaSeed").setBranchAlias("detaseed")},
84  dPhiMapPutToken_{produces<reco::RecoEcalCandidateIsolationMap>("Dphi").setBranchAlias("dphi")},
85  oneOverESuperMinusOneOverPMapPutToken_{produces<reco::RecoEcalCandidateIsolationMap>("OneOESuperMinusOneOP")},
86  oneOverESeedMinusOneOverPMapPutToken_{produces<reco::RecoEcalCandidateIsolationMap>("OneOESeedMinusOneOP")},
87  missingHitsMapPutToken_{
88  produces<reco::RecoEcalCandidateIsolationMap>("MissingHits").setBranchAlias("missinghits")},
89  validHitsMapPutToken_{produces<reco::RecoEcalCandidateIsolationMap>("Chi2").setBranchAlias("chi2")},
90  chi2MapPutToken_{produces<reco::RecoEcalCandidateIsolationMap>("ValidHits").setBranchAlias("validhits")} {}
91 
94  desc.add<edm::InputTag>(("recoEcalCandidateProducer"), edm::InputTag("hltRecoEcalSuperClusterActivityCandidate"));
95  desc.add<edm::InputTag>(("inputCollection"), edm::InputTag("hltActivityElectronGsfTracks"));
96  desc.add<edm::InputTag>(("beamSpotProducer"), edm::InputTag("hltOnlineBeamSpot"));
97  desc.add<int>(("upperTrackNrToRemoveCut"), 9999);
98  desc.add<int>(("lowerTrackNrToRemoveCut"), -1);
99  desc.add<bool>(("useDefaultValuesForBarrel"), false);
100  desc.add<bool>(("useDefaultValuesForEndcap"), false);
101 
102  descriptions.add("hltEgammaHLTGsfTrackVarProducer", desc);
103 }
105  // Get the HLT filtered objects
106  auto recoEcalCandHandle = iEvent.getHandle(recoEcalCandToken_);
107 
108  auto const& beamSpotPosition = iEvent.get(beamSpotToken_).position();
109  auto const& magneticField = iSetup.getData(magneticFieldToken_);
110  auto const& trackerGeometry = iSetup.getData(trackerGeometryToken_);
111 
114 
115  reco::RecoEcalCandidateIsolationMap dEtaMap(recoEcalCandHandle);
116  reco::RecoEcalCandidateIsolationMap dEtaSeedMap(recoEcalCandHandle);
117  reco::RecoEcalCandidateIsolationMap dPhiMap(recoEcalCandHandle);
118  reco::RecoEcalCandidateIsolationMap oneOverESuperMinusOneOverPMap(recoEcalCandHandle);
119  reco::RecoEcalCandidateIsolationMap oneOverESeedMinusOneOverPMap(recoEcalCandHandle);
120  reco::RecoEcalCandidateIsolationMap missingHitsMap(recoEcalCandHandle);
121  reco::RecoEcalCandidateIsolationMap validHitsMap(recoEcalCandHandle);
122  reco::RecoEcalCandidateIsolationMap chi2Map(recoEcalCandHandle);
123 
124  for (unsigned int iRecoEcalCand = 0; iRecoEcalCand < recoEcalCandHandle->size(); ++iRecoEcalCand) {
125  reco::RecoEcalCandidateRef recoEcalCandRef(recoEcalCandHandle, iRecoEcalCand);
126 
127  const reco::SuperClusterRef scRef = recoEcalCandRef->superCluster();
128  //the idea is that we can take the tracks from properly associated electrons or just take all gsf tracks with that sc as a seed
129  std::vector<const reco::GsfTrack*> gsfTracks;
130  if (auto electronHandle = iEvent.getHandle(electronToken_)) {
131  for (auto const& ele : *electronHandle) {
132  if (ele.superCluster() == scRef) {
133  gsfTracks.push_back(ele.gsfTrack().get());
134  }
135  }
136  } else {
137  for (auto const& trk : iEvent.get(gsfTrackToken_)) {
138  auto elseed = trk.extra()->seedRef().castTo<reco::ElectronSeedRef>();
139  if (elseed->caloCluster().castTo<reco::SuperClusterRef>() == scRef) {
140  gsfTracks.push_back(&trk);
141  }
142  }
143  }
144 
145  int validHitsValue = 0;
146  float chi2Value = 9999999.;
147  float missingHitsValue = 9999999;
148  float dEtaInValue = 999999;
149  float dEtaSeedInValue = 999999;
150  float dPhiInValue = 999999;
151  float oneOverESuperMinusOneOverPValue = 999999;
152  float oneOverESeedMinusOneOverPValue = 999999;
153 
154  const int nrTracks = gsfTracks.size();
155  const bool rmCutsDueToNrTracks = nrTracks <= lowerTrackNrToRemoveCut_ || nrTracks >= upperTrackNrToRemoveCut_;
156  //to use the default values, we require at least one track...
157  const bool useDefaultValues = std::abs(recoEcalCandRef->eta()) < 1.479
158  ? useDefaultValuesForBarrel_ && nrTracks >= 1
159  : useDefaultValuesForEndcap_ && nrTracks >= 1;
160 
161  if (rmCutsDueToNrTracks || useDefaultValues) {
162  dEtaInValue = 0;
163  dEtaSeedInValue = 0;
164  dPhiInValue = 0;
165  missingHitsValue = 0;
166  validHitsValue = 100;
167  chi2Value = 0;
168  oneOverESuperMinusOneOverPValue = 0;
169  oneOverESeedMinusOneOverPValue = 0;
170  } else {
171  for (size_t trkNr = 0; trkNr < gsfTracks.size(); trkNr++) {
172  GlobalPoint scPos(scRef->x(), scRef->y(), scRef->z());
173 
174  GlobalPoint trackExtrapToSC;
175  {
176  auto innTSOS =
178  auto posTSOS = extrapolator.extrapolate(innTSOS, scPos);
179  multiTrajectoryStateMode::positionFromModeCartesian(posTSOS, trackExtrapToSC);
180  }
181 
182  EleRelPointPair scAtVtx(scRef->position(), trackExtrapToSC, beamSpotPosition);
183 
184  float trkP = gsfTracks[trkNr]->p();
185  if (scRef->energy() != 0 && trkP != 0) {
186  if (std::abs(1 / scRef->energy() - 1 / trkP) < oneOverESuperMinusOneOverPValue) {
187  oneOverESuperMinusOneOverPValue = std::abs(1 / scRef->energy() - 1 / trkP);
188  }
189  }
190  if (scRef->seed().isNonnull() && scRef->seed()->energy() != 0 && trkP != 0) {
191  if (std::abs(1 / scRef->seed()->energy() - 1 / trkP) < oneOverESeedMinusOneOverPValue) {
192  oneOverESeedMinusOneOverPValue = std::abs(1 / scRef->seed()->energy() - 1 / trkP);
193  }
194  }
195 
196  if (gsfTracks[trkNr]->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS) < missingHitsValue) {
197  missingHitsValue = gsfTracks[trkNr]->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS);
198  }
199 
200  if (gsfTracks[trkNr]->numberOfValidHits() < validHitsValue) {
201  validHitsValue = gsfTracks[trkNr]->numberOfValidHits();
202  }
203 
204  if (gsfTracks[trkNr]->numberOfValidHits() < chi2Value) {
205  chi2Value = gsfTracks[trkNr]->normalizedChi2();
206  }
207 
208  if (std::abs(scAtVtx.dEta()) < dEtaInValue) {
209  //we are allowing them to come from different tracks
210  dEtaInValue = std::abs(scAtVtx.dEta());
211  }
212 
213  if (std::abs(scAtVtx.dEta()) < dEtaSeedInValue) {
214  dEtaSeedInValue = std::abs(scAtVtx.dEta() - scRef->position().eta() + scRef->seed()->position().eta());
215  }
216 
217  if (std::abs(scAtVtx.dPhi()) < dPhiInValue) {
218  //we are allowing them to come from different tracks
219  dPhiInValue = std::abs(scAtVtx.dPhi());
220  }
221  }
222  }
223 
224  dEtaMap.insert(recoEcalCandRef, dEtaInValue);
225  dEtaSeedMap.insert(recoEcalCandRef, dEtaSeedInValue);
226  dPhiMap.insert(recoEcalCandRef, dPhiInValue);
227  oneOverESuperMinusOneOverPMap.insert(recoEcalCandRef, oneOverESuperMinusOneOverPValue);
228  oneOverESeedMinusOneOverPMap.insert(recoEcalCandRef, oneOverESeedMinusOneOverPValue);
229  missingHitsMap.insert(recoEcalCandRef, missingHitsValue);
230  validHitsMap.insert(recoEcalCandRef, validHitsValue);
231  chi2Map.insert(recoEcalCandRef, chi2Value);
232  }
233 
234  iEvent.emplace(dEtaMapPutToken_, dEtaMap);
235  iEvent.emplace(dEtaSeedMapPutToken_, dEtaSeedMap);
236  iEvent.emplace(dPhiMapPutToken_, dPhiMap);
237  iEvent.emplace(oneOverESuperMinusOneOverPMapPutToken_, oneOverESuperMinusOneOverPMap);
238  iEvent.emplace(oneOverESeedMinusOneOverPMapPutToken_, oneOverESeedMinusOneOverPMap);
239  iEvent.emplace(missingHitsMapPutToken_, missingHitsMap);
240  iEvent.emplace(validHitsMapPutToken_, validHitsMap);
241  iEvent.emplace(chi2MapPutToken_, chi2Map);
242 }
243 
RecoEcalCandidateIsolation.h
ConfigurationDescriptions.h
edm::StreamID
Definition: StreamID.h:30
EgammaHLTGsfTrackVarProducer::chi2MapPutToken_
const edm::EDPutTokenT< reco::RecoEcalCandidateIsolationMap > chi2MapPutToken_
Definition: EgammaHLTGsfTrackVarProducer.cc:67
TrajectoryStateOnSurface.h
reco::RecoEcalCandidateCollection
std::vector< RecoEcalCandidate > RecoEcalCandidateCollection
collectin of RecoEcalCandidate objects
Definition: RecoEcalCandidateFwd.h:9
anyDirection
Definition: PropagationDirection.h:4
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
TrackerGeometry.h
EgammaHLTGsfTrackVarProducer::trackerGeometryToken_
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerGeometryToken_
Definition: EgammaHLTGsfTrackVarProducer.cc:53
EgammaHLTGsfTrackVarProducer::dEtaSeedMapPutToken_
const edm::EDPutTokenT< reco::RecoEcalCandidateIsolationMap > dEtaSeedMapPutToken_
Definition: EgammaHLTGsfTrackVarProducer.cc:61
GsfPropagatorAdapter.h
HLT_2018_cff.magneticField
magneticField
Definition: HLT_2018_cff.py:348
EgammaHLTGsfTrackVarProducer::validHitsMapPutToken_
const edm::EDPutTokenT< reco::RecoEcalCandidateIsolationMap > validHitsMapPutToken_
Definition: EgammaHLTGsfTrackVarProducer.cc:66
edm::EDGetTokenT< reco::RecoEcalCandidateCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::EDPutTokenT
Definition: EDPutToken.h:33
EgammaHLTGsfTrackVarProducer::gsfTrackToken_
const edm::EDGetTokenT< reco::GsfTrackCollection > gsfTrackToken_
Definition: EgammaHLTGsfTrackVarProducer.cc:49
TrackCollections2monitor_cff.numberOfValidHits
numberOfValidHits
Definition: TrackCollections2monitor_cff.py:248
EgammaHLTGsfTrackVarProducer::upperTrackNrToRemoveCut_
const int upperTrackNrToRemoveCut_
Definition: EgammaHLTGsfTrackVarProducer.cc:55
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
TransverseImpactPointExtrapolator
Definition: TransverseImpactPointExtrapolator.h:26
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
ElectronUtilities.h
edm::Ref
Definition: AssociativeIterator.h:58
config
Definition: config.py:1
EgammaHLTGsfTrackVarProducer::electronToken_
const edm::EDGetTokenT< reco::ElectronCollection > electronToken_
Definition: EgammaHLTGsfTrackVarProducer.cc:48
MakerMacros.h
Track.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
EgammaHLTGsfTrackVarProducer::useDefaultValuesForBarrel_
const bool useDefaultValuesForBarrel_
Definition: EgammaHLTGsfTrackVarProducer.cc:57
MultiTrajectoryStateMode.h
EgammaHLTGsfTrackVarProducer
Definition: EgammaHLTGsfTrackVarProducer.cc:40
IdealMagneticFieldRecord.h
EgammaHLTGsfTrackVarProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: EgammaHLTGsfTrackVarProducer.cc:92
ecalDrivenGsfElectronCoresFromMultiCl_cff.gsfTracks
gsfTracks
Definition: ecalDrivenGsfElectronCoresFromMultiCl_cff.py:4
Point3DBase< float, GlobalTag >
ParameterSetDescription.h
EgammaHLTGsfTrackVarProducer::dPhiMapPutToken_
const edm::EDPutTokenT< reco::RecoEcalCandidateIsolationMap > dPhiMapPutToken_
Definition: EgammaHLTGsfTrackVarProducer.cc:62
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AnalyticalPropagator_cfi.AnalyticalPropagator
AnalyticalPropagator
Definition: AnalyticalPropagator_cfi.py:3
MultiTrajectoryStateTransform.h
TrackerDigiGeometryRecord.h
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
edm::AssociationMap
Definition: AssociationMap.h:48
EgammaHLTGsfTrackVarProducer::useDefaultValuesForEndcap_
const bool useDefaultValuesForEndcap_
Definition: EgammaHLTGsfTrackVarProducer.cc:58
EgammaHLTGsfTrackVarProducer::lowerTrackNrToRemoveCut_
const int lowerTrackNrToRemoveCut_
Definition: EgammaHLTGsfTrackVarProducer.cc:56
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
iEvent
int iEvent
Definition: GenABIO.cc:224
multiTrajectoryStateMode::positionFromModeCartesian
bool positionFromModeCartesian(TrajectoryStateOnSurface const &tsos, GlobalPoint &position)
Definition: MultiTrajectoryStateMode.cc:63
EgammaHLTGsfTrackVarProducer::beamSpotToken_
const edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
Definition: EgammaHLTGsfTrackVarProducer.cc:50
MagneticField.h
edm::EventSetup
Definition: EventSetup.h:57
AnalyticalPropagator.h
EleRelPointPair
Definition: ElectronUtilities.h:43
EgammaHLTGsfTrackVarProducer::missingHitsMapPutToken_
const edm::EDPutTokenT< reco::RecoEcalCandidateIsolationMap > missingHitsMapPutToken_
Definition: EgammaHLTGsfTrackVarProducer.cc:65
TrajectorySeedCollection.h
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord >
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:113
edm::AssociationMap::insert
void insert(const key_type &k, const data_type &v)
insert an association
Definition: AssociationMap.h:166
Electron.h
RecoEcalCandidate.h
SuperCluster.h
reco::HitPattern::MISSING_INNER_HITS
Definition: HitPattern.h:155
EgammaHLTGsfTrackVarProducer::dEtaMapPutToken_
const edm::EDPutTokenT< reco::RecoEcalCandidateIsolationMap > dEtaMapPutToken_
Definition: EgammaHLTGsfTrackVarProducer.cc:60
TransverseImpactPointExtrapolator.h
ElectronIsolationAssociation.h
MultiTrajectoryStateTransform::innerStateOnSurface
TrajectoryStateOnSurface innerStateOnSurface(const reco::GsfTrack &tk) const
Definition: MultiTrajectoryStateTransform.cc:23
EgammaHLTGsfTrackVarProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: EgammaHLTGsfTrackVarProducer.cc:104
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
EgammaHLTGsfTrackVarProducer::EgammaHLTGsfTrackVarProducer
EgammaHLTGsfTrackVarProducer(const edm::ParameterSet &)
Definition: EgammaHLTGsfTrackVarProducer.cc:70
EDProducer.h
GsfPropagatorAdapter
Definition: GsfPropagatorAdapter.h:14
edm::Event
Definition: Event.h:73
EgammaHLTGsfTrackVarProducer::oneOverESuperMinusOneOverPMapPutToken_
const edm::EDPutTokenT< reco::RecoEcalCandidateIsolationMap > oneOverESuperMinusOneOverPMapPutToken_
Definition: EgammaHLTGsfTrackVarProducer.cc:63
EgammaHLTGsfTrackVarProducer::recoEcalCandToken_
const edm::EDGetTokenT< reco::RecoEcalCandidateCollection > recoEcalCandToken_
Definition: EgammaHLTGsfTrackVarProducer.cc:47
EgammaHLTGsfTrackVarProducer::magneticFieldToken_
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magneticFieldToken_
Definition: EgammaHLTGsfTrackVarProducer.cc:52
edm::InputTag
Definition: InputTag.h:15
ElectronSeed.h
EgammaHLTGsfTrackVarProducer::oneOverESeedMinusOneOverPMapPutToken_
const edm::EDPutTokenT< reco::RecoEcalCandidateIsolationMap > oneOverESeedMinusOneOverPMapPutToken_
Definition: EgammaHLTGsfTrackVarProducer.cc:64