CMS 3D CMS Logo

L1TkElectronTrackProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
10 //
11 // system include files
12 #include <memory>
13 
14 // user include files
17 
22 
27 
30 
32 
35 
36 // Matching Algorithm
40 
43 
44 #include <string>
45 
46 static constexpr float EB_MaxEta = 0.9;
47 
48 using namespace l1t;
49 
50 //
51 // class declaration
52 //
53 
55 public:
57  typedef std::vector<L1TTTrackType> L1TTTrackCollectionType;
58 
60  ~L1TkElectronTrackProducer() override;
61 
62  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
63 
64 private:
65  //void beginJob() override;
66  void produce(edm::Event&, const edm::EventSetup&) override;
67  //void endJob() override;
68 
69  float isolation(const edm::Handle<L1TTTrackCollectionType>& trkHandle, int match_index);
70  double getPtScaledCut(double pt, std::vector<double>& parameters);
71  bool selectMatchedTrack(double& d_r, double& d_phi, double& d_eta, double& tk_pt, float& eg_eta);
72 
73  // ----------member data ---------------------------
75 
76  float etMin_; // min ET in GeV of L1EG objects
77 
78  float dRMin_;
79  float dRMax_;
80  float pTMinTra_;
82  unsigned int minNStubsIsoTracks_;
83 
84  bool primaryVtxConstrain_; // use the primary vertex (default = false)
85  float deltaZ_; // | z_track - z_ref_track | < deltaZ_ in cm.
86  // Used only when primaryVtxConstrain_ = True.
87  float isoCut_;
89 
92  bool useClusterET_; // use cluster et to extrapolate tracks
94  std::vector<double> dPhiCutoff_;
95  std::vector<double> dRCutoff_;
96  std::vector<double> dEtaCutoff_;
98 
102 };
103 
104 //
105 // constructors and destructor
106 //
108  : egToken_(consumes<EGammaBxCollection>(iConfig.getParameter<edm::InputTag>("L1EGammaInputTag"))),
109  trackToken_(consumes<std::vector<TTTrack<Ref_Phase2TrackerDigi_> > >(
110  iConfig.getParameter<edm::InputTag>("L1TrackInputTag"))),
111  geomToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()) {
112  // label of the collection produced
113  // e.g. EG or IsoEG if all objects are kept
114  // EGIsoTrk or IsoEGIsoTrk if only the EG or IsoEG
115  // objects that pass a cut RelIso < isoCut_ are written
116  // in the new collection.
117  label = iConfig.getParameter<std::string>("label");
118 
119  etMin_ = (float)iConfig.getParameter<double>("ETmin");
120 
121  // parameters for the calculation of the isolation :
122  pTMinTra_ = (float)iConfig.getParameter<double>("PTMINTRA");
123  dRMin_ = (float)iConfig.getParameter<double>("DRmin");
124  dRMax_ = (float)iConfig.getParameter<double>("DRmax");
125  deltaZ_ = (float)iConfig.getParameter<double>("DeltaZ");
126  maxChi2IsoTracks_ = iConfig.getParameter<double>("maxChi2IsoTracks");
127  minNStubsIsoTracks_ = iConfig.getParameter<int>("minNStubsIsoTracks");
128  // cut applied on the isolation (if this number is <= 0, no cut is applied)
129  isoCut_ = (float)iConfig.getParameter<double>("IsoCut");
130  relativeIsolation_ = iConfig.getParameter<bool>("RelativeIsolation");
131 
132  // parameters to select tracks to match with L1EG
133  trkQualityChi2_ = (float)iConfig.getParameter<double>("TrackChi2");
134  trkQualityPtMin_ = (float)iConfig.getParameter<double>("TrackMinPt");
135  useTwoStubsPT_ = iConfig.getParameter<bool>("useTwoStubsPT");
136  useClusterET_ = iConfig.getParameter<bool>("useClusterET");
137  dPhiCutoff_ = iConfig.getParameter<std::vector<double> >("TrackEGammaDeltaPhi");
138  dRCutoff_ = iConfig.getParameter<std::vector<double> >("TrackEGammaDeltaR");
139  dEtaCutoff_ = iConfig.getParameter<std::vector<double> >("TrackEGammaDeltaEta");
140  matchType_ = iConfig.getParameter<std::string>("TrackEGammaMatchType");
141 
142  produces<TkElectronCollection>(label);
143 }
144 
146 
147 // ------------ method called to produce the data ------------
149  std::unique_ptr<TkElectronCollection> result(new TkElectronCollection);
150 
151  // geometry needed to call pTFrom2Stubs
153  const TrackerGeometry* tGeom = geomHandle.product();
154 
155  // the L1EGamma objects
156  edm::Handle<EGammaBxCollection> eGammaHandle;
157  iEvent.getByToken(egToken_, eGammaHandle);
158  EGammaBxCollection eGammaCollection = (*eGammaHandle.product());
160 
161  // the L1Tracks
162  edm::Handle<L1TTTrackCollectionType> L1TTTrackHandle;
163  iEvent.getByToken(trackToken_, L1TTTrackHandle);
164  L1TTTrackCollectionType::const_iterator trackIter;
165 
166  if (!eGammaHandle.isValid()) {
167  throw cms::Exception("L1TkElectronTrackProducer")
168  << "\nWarning: L1EmCollection not found in the event. Exit" << std::endl;
169  return;
170  }
171  if (!L1TTTrackHandle.isValid()) {
172  throw cms::Exception("TkEmProducer") << "\nWarning: L1TTTrackCollectionType not found in the event. Exit."
173  << std::endl;
174  return;
175  }
176 
177  int ieg = 0;
178  for (egIter = eGammaCollection.begin(0); egIter != eGammaCollection.end(0); ++egIter) { // considering BX = only
179  edm::Ref<EGammaBxCollection> EGammaRef(eGammaHandle, ieg);
180  ieg++;
181 
182  float e_ele = egIter->energy();
183  float eta_ele = egIter->eta();
184  float et_ele = 0;
185  float cosh_eta_ele = cosh(eta_ele);
186  if (cosh_eta_ele > 0.0)
187  et_ele = e_ele / cosh_eta_ele;
188  else
189  et_ele = -1.0;
190  if (etMin_ > 0.0 && et_ele <= etMin_)
191  continue;
192  // match the L1EG object with a L1Track
193  float drmin = 999;
194  int itr = 0;
195  int itrack = -1;
196  for (trackIter = L1TTTrackHandle->begin(); trackIter != L1TTTrackHandle->end(); ++trackIter) {
197  edm::Ptr<L1TTTrackType> L1TrackPtr(L1TTTrackHandle, itr);
198  double trkPt_fit = trackIter->momentum().perp();
199  double trkPt_stubs = pTFrom2Stubs::pTFrom2(trackIter, tGeom);
200  double trkPt = trkPt_fit;
201  if (useTwoStubsPT_)
202  trkPt = trkPt_stubs;
203 
204  if (trkPt > trkQualityPtMin_ && trackIter->chi2() < trkQualityChi2_) {
205  double dPhi = 99.;
206  double dR = 99.;
207  double dEta = 99.;
208  if (useClusterET_)
210  else
211  L1TkElectronTrackMatchAlgo::doMatch(egIter, L1TrackPtr, dPhi, dR, dEta);
212  if (dR < drmin && selectMatchedTrack(dR, dPhi, dEta, trkPt, eta_ele)) {
213  drmin = dR;
214  itrack = itr;
215  }
216  }
217  itr++;
218  }
219  if (itrack >= 0) {
220  edm::Ptr<L1TTTrackType> matchedL1TrackPtr(L1TTTrackHandle, itrack);
221 
222  const math::XYZTLorentzVector P4 = egIter->p4();
223  float trkisol = isolation(L1TTTrackHandle, itrack);
224  if (relativeIsolation_ && et_ele > 0.0) { // relative isolation
225  trkisol = trkisol / et_ele;
226  }
227 
228  TkElectron trkEm(P4, EGammaRef, matchedL1TrackPtr, trkisol);
229 
230  trkEm.setTrackCurvature(matchedL1TrackPtr->rInv()); // should this have npars? 4? 5?
231 
232  //std::cout<<matchedL1TrackPtr->rInv()<<" "<<matchedL1TrackPtr->rInv(4)<<" "<<matchedL1TrackPtr->rInv()<<std::endl;
233 
234  if (isoCut_ <= 0) {
235  // write the L1TkEm particle to the collection,
236  // irrespective of its relative isolation
237  result->push_back(trkEm);
238  } else {
239  // the object is written to the collection only
240  // if it passes the isolation cut
241  if (trkisol <= isoCut_)
242  result->push_back(trkEm);
243  }
244  }
245 
246  } // end loop over EGamma objects
247 
248  iEvent.put(std::move(result), label);
249 }
250 
251 // ------------ method called once each job just before starting event loop ------------
252 //void L1TkElectronTrackProducer::beginJob() {}
253 
254 // ------------ method called once each job just after ending the event loop ------------
255 //void L1TkElectronTrackProducer::endJob() {}
256 
257 // ------------ method called when starting to processes a run ------------
258 /*
259 void
260 L1TkElectronTrackProducer::beginRun(edm::Run& iRun, edm::EventSetup const& iSetup)
261 {
262 }
263 */
264 
265 // ------------ method called when ending the processing of a run ------------
266 /*
267 void
268 L1TkElectronTrackProducer::endRun(edm::Run&, edm::EventSetup const&)
269 {
270 }
271 */
272 
273 // ------------ method called when starting to processes a luminosity block ------------
274 /*
275 void
276 L1TkElectronTrackProducer::beginLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&)
277 {
278 }
279 */
280 
281 // ------------ method called when ending the processing of a luminosity block ------------
282 /*
283 void
284 L1TkElectronTrackProducer::endLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&)
285 {
286 }
287 */
288 
289 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
291  //The following says we do not know what parameters are allowed so do no validation
292  // Please change this to state exactly what you do use, even if it is no parameters
294  desc.setUnknown();
295  descriptions.addDefault(desc);
296 }
297 // method to calculate isolation
299  edm::Ptr<L1TTTrackType> matchedTrkPtr(trkHandle, match_index);
300  L1TTTrackCollectionType::const_iterator trackIter;
301 
302  float sumPt = 0.0;
303  int itr = 0;
304 
305  float dRMin2 = dRMin_ * dRMin_;
306  float dRMax2 = dRMax_ * dRMax_;
307 
308  for (trackIter = trkHandle->begin(); trackIter != trkHandle->end(); ++trackIter) {
309  if (itr++ != match_index) {
310  if (trackIter->chi2() > maxChi2IsoTracks_ || trackIter->momentum().perp() <= pTMinTra_ ||
311  trackIter->getStubRefs().size() < minNStubsIsoTracks_) {
312  continue;
313  }
314 
315  float dZ = std::abs(trackIter->POCA().z() - matchedTrkPtr->POCA().z());
316 
317  float phi1 = trackIter->momentum().phi();
318  float phi2 = matchedTrkPtr->momentum().phi();
319  float dPhi = reco::deltaPhi(phi1, phi2);
320  float dEta = (trackIter->momentum().eta() - matchedTrkPtr->momentum().eta());
321  float dR2 = (dPhi * dPhi + dEta * dEta);
322 
323  if (dR2 > dRMin2 && dR2 < dRMax2 && dZ < deltaZ_ && trackIter->momentum().perp() > pTMinTra_) {
324  sumPt += trackIter->momentum().perp();
325  }
326  }
327  }
328 
329  return sumPt;
330 }
331 double L1TkElectronTrackProducer::getPtScaledCut(double pt, std::vector<double>& parameters) {
332  return (parameters[0] + parameters[1] * exp(parameters[2] * pt));
333 }
335  double& d_r, double& d_phi, double& d_eta, double& tk_pt, float& eg_eta) {
336  if (matchType_ == "PtDependentCut") {
337  if (std::abs(d_phi) < getPtScaledCut(tk_pt, dPhiCutoff_) && d_r < getPtScaledCut(tk_pt, dRCutoff_))
338  return true;
339  } else {
340  double deta_max = dEtaCutoff_[0];
341  if (std::abs(eg_eta) < EB_MaxEta)
342  deta_max = dEtaCutoff_[1];
343  double dphi_max = dPhiCutoff_[0];
344  if ((d_eta / deta_max) * (d_eta / deta_max) + (d_phi / dphi_max) * (d_phi / dphi_max) < 1)
345  return true;
346  }
347  return false;
348 }
349 //define this as a plug-in
l1t::TkElectron
Definition: TkElectron.h:24
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
L1TkElectronTrackProducer::etMin_
float etMin_
Definition: L1TkElectronTrackProducer.cc:76
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:29
Handle.h
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
L1TkElectronTrackProducer::trkQualityChi2_
float trkQualityChi2_
Definition: L1TkElectronTrackProducer.cc:90
TrackerGeometry.h
L1TkElectronTrackProducer::pTMinTra_
float pTMinTra_
Definition: L1TkElectronTrackProducer.cc:80
edm::Handle::product
T const * product() const
Definition: Handle.h:70
TTTrack::momentum
GlobalVector momentum() const
Track momentum.
Definition: TTTrack.h:281
L1TkElectronTrackProducer::selectMatchedTrack
bool selectMatchedTrack(double &d_r, double &d_phi, double &d_eta, double &tk_pt, float &eg_eta)
Definition: L1TkElectronTrackProducer.cc:334
L1TkElectronTrackProducer::~L1TkElectronTrackProducer
~L1TkElectronTrackProducer() override
Definition: L1TkElectronTrackProducer.cc:145
ESHandle.h
L1TkElectronEtComparator.h
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
L1TkElectronTrackProducer::isolation
float isolation(const edm::Handle< L1TTTrackCollectionType > &trkHandle, int match_index)
Definition: L1TkElectronTrackProducer.cc:298
reco::deltaPhi
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
deltaPhi.h
edm::EDGetTokenT< EGammaBxCollection >
L1TkElectronTrackProducer::maxChi2IsoTracks_
float maxChi2IsoTracks_
Definition: L1TkElectronTrackProducer.cc:81
BXVector::const_iterator
std::vector< T >::const_iterator const_iterator
Definition: BXVector.h:18
edm
HLT enums.
Definition: AlignableModifier.h:19
L1TkElectronTrackProducer::dPhiCutoff_
std::vector< double > dPhiCutoff_
Definition: L1TkElectronTrackProducer.cc:94
L1TkElectronTrackProducer::primaryVtxConstrain_
bool primaryVtxConstrain_
Definition: L1TkElectronTrackProducer.cc:84
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
L1TkElectronTrackMatchAlgo.h
TTTrack
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:26
EDProducer.h
L1TkElectronTrackProducer::matchType_
std::string matchType_
Definition: L1TkElectronTrackProducer.cc:97
L1TkElectronTrackProducer::trkQualityPtMin_
float trkQualityPtMin_
Definition: L1TkElectronTrackProducer.cc:93
HLT_FULL_cff.dPhi
dPhi
Definition: HLT_FULL_cff.py:13702
edm::Handle
Definition: AssociativeIterator.h:50
TTTrack::rInv
double rInv() const
Track curvature.
Definition: TTTrack.h:286
ESGetToken.h
L1TkElectronTrackProducer::dEtaCutoff_
std::vector< double > dEtaCutoff_
Definition: L1TkElectronTrackProducer.cc:96
L1TkElectronTrackProducer::isoCut_
float isoCut_
Definition: L1TkElectronTrackProducer.cc:87
L1TkElectronTrackProducer::L1TTTrackType
TTTrack< Ref_Phase2TrackerDigi_ > L1TTTrackType
Definition: L1TkElectronTrackProducer.cc:56
L1TkElectronTrackProducer::getPtScaledCut
double getPtScaledCut(double pt, std::vector< double > &parameters)
Definition: L1TkElectronTrackProducer.cc:331
edm::Ref
Definition: AssociativeIterator.h:58
TtFullHadEvtBuilder_cfi.sumPt
sumPt
Definition: TtFullHadEvtBuilder_cfi.py:38
L1TkElectronTrackProducer::L1TkElectronTrackProducer
L1TkElectronTrackProducer(const edm::ParameterSet &)
Definition: L1TkElectronTrackProducer.cc:107
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
BXVector
Definition: BXVector.h:15
L1TkElectronTrackProducer::egToken_
const edm::EDGetTokenT< EGammaBxCollection > egToken_
Definition: L1TkElectronTrackProducer.cc:99
TTTrack::POCA
GlobalPoint POCA() const
POCA.
Definition: TTTrack.h:316
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
L1TkElectronTrackProducer
Definition: L1TkElectronTrackProducer.cc:54
EGamma.h
l1t::EGammaRef
edm::Ref< EGammaBxCollection > EGammaRef
Definition: TkEGTau.h:35
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
L1TkElectronTrackMatchAlgo::doMatchClusterET
void doMatchClusterET(BXVector< l1t::EGamma >::const_iterator egIter, const edm::Ptr< L1TTTrackType > &pTrk, double &dph, double &dr, double &deta)
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::ESHandle< TrackerGeometry >
L1TkElectronTrackMatchAlgo::doMatch
void doMatch(BXVector< l1t::EGamma >::const_iterator egIter, const edm::Ptr< L1TTTrackType > &pTrk, double &dph, double &dr, double &deta)
L1TkElectronTrackProducer::dRMax_
float dRMax_
Definition: L1TkElectronTrackProducer.cc:79
L1TkElectronTrackProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: L1TkElectronTrackProducer.cc:290
BXVector::begin
const_iterator begin(int bx) const
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
L1TkElectronTrackProducer::minNStubsIsoTracks_
unsigned int minNStubsIsoTracks_
Definition: L1TkElectronTrackProducer.cc:82
TrackerDigiGeometryRecord.h
BXVector::end
const_iterator end(int bx) const
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
L1TkElectronTrackProducer::L1TTTrackCollectionType
std::vector< L1TTTrackType > L1TTTrackCollectionType
Definition: L1TkElectronTrackProducer.cc:57
l1t::TkElectronCollection
std::vector< TkElectron > TkElectronCollection
Definition: TkElectronFwd.h:15
l1t
delete x;
Definition: CaloConfig.h:22
pTFrom2Stubs::pTFrom2
float pTFrom2(std::vector< TTTrack< Ref_Phase2TrackerDigi_ > >::const_iterator trk, const TrackerGeometry *tkGeometry)
Definition: pTFrom2Stubs.cc:72
PV3DBase::eta
T eta() const
Definition: PV3DBase.h:73
LorentzVector.h
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:148
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
L1TkElectronTrackProducer::label
std::string label
Definition: L1TkElectronTrackProducer.cc:74
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
itr
std::vector< std::pair< float, float > >::iterator itr
Definition: HGCDigitizer.cc:29
L1TkElectronTrackProducer::trackToken_
const edm::EDGetTokenT< std::vector< TTTrack< Ref_Phase2TrackerDigi_ > > > trackToken_
Definition: L1TkElectronTrackProducer.cc:100
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord >
L1TkElectronTrackProducer::deltaZ_
float deltaZ_
Definition: L1TkElectronTrackProducer.cc:85
L1TkElectronTrackProducer::dRMin_
float dRMin_
Definition: L1TkElectronTrackProducer.cc:78
InputTag.h
l1t::TkElectron::setTrackCurvature
void setTrackCurvature(double trackCurvature)
Definition: TkElectron.h:46
edm::Ptr
Definition: AssociationVector.h:31
TkElectron.h
L1TkElectronTrackProducer::geomToken_
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
Definition: L1TkElectronTrackProducer.cc:101
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
TkElectronFwd.h
L1TkElectronTrackProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: L1TkElectronTrackProducer.cc:148
Frameworkfwd.h
HLT_FULL_cff.dEta
dEta
Definition: HLT_FULL_cff.py:13701
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
Exception
Definition: hltDiff.cc:246
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
L1TkElectronTrackProducer::useTwoStubsPT_
bool useTwoStubsPT_
Definition: L1TkElectronTrackProducer.cc:91
mps_fire.result
result
Definition: mps_fire.py:311
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
L1TkElectronTrackProducer::useClusterET_
bool useClusterET_
Definition: L1TkElectronTrackProducer.cc:92
HGC3DClusterGenMatchSelector_cfi.dR
dR
Definition: HGC3DClusterGenMatchSelector_cfi.py:7
ParameterSet.h
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
L1TkElectronTrackProducer::relativeIsolation_
bool relativeIsolation_
Definition: L1TkElectronTrackProducer.cc:88
edm::Event
Definition: Event.h:73
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
PV3DBase::phi
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
pTFrom2Stubs.h
isolation
double isolation
Definition: AssociatedVariableMaxCutCandRefSelector.cc:25
EB_MaxEta
static constexpr float EB_MaxEta
Definition: L1TkElectronTrackProducer.cc:46
L1TkElectronTrackProducer::dRCutoff_
std::vector< double > dRCutoff_
Definition: L1TkElectronTrackProducer.cc:95
TrackerGeometry
Definition: TrackerGeometry.h:14