CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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"))),
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_)
209  L1TkElectronTrackMatchAlgo::doMatchClusterET(egIter, L1TrackPtr, dPhi, dR, dEta);
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
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
const_iterator end(int bx) const
const edm::EDGetTokenT< EGammaBxCollection > egToken_
L1TkElectronTrackProducer(const edm::ParameterSet &)
std::vector< L1TTTrackType > L1TTTrackCollectionType
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
std::vector< TkElectron > TkElectronCollection
Definition: TkElectronFwd.h:15
edm::Ref< EGammaBxCollection > EGammaRef
Definition: TkEGTau.h:35
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static constexpr float EB_MaxEta
void doMatchClusterET(BXVector< l1t::EGamma >::const_iterator egIter, const edm::Ptr< L1TTTrackType > &pTrk, double &dph, double &dr, double &deta)
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
tuple result
Definition: mps_fire.py:311
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
bool selectMatchedTrack(double &d_r, double &d_phi, double &d_eta, double &tk_pt, float &eg_eta)
std::vector< T >::const_iterator const_iterator
Definition: BXVector.h:18
const edm::EDGetTokenT< std::vector< TTTrack< Ref_Phase2TrackerDigi_ > > > trackToken_
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
void produce(edm::Event &, const edm::EventSetup &) override
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void setTrackCurvature(double trackCurvature)
Definition: TkElectron.h:46
void doMatch(BXVector< l1t::EGamma >::const_iterator egIter, const edm::Ptr< L1TTTrackType > &pTrk, double &dph, double &dr, double &deta)
bool isValid() const
Definition: HandleBase.h:70
TTTrack< Ref_Phase2TrackerDigi_ > L1TTTrackType
float isolation(const edm::Handle< L1TTTrackCollectionType > &trkHandle, int match_index)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T const * product() const
Definition: Handle.h:70
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:29
T const * product() const
Definition: ESHandle.h:86
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
double getPtScaledCut(double pt, std::vector< double > &parameters)
float pTFrom2(std::vector< TTTrack< Ref_Phase2TrackerDigi_ > >::const_iterator trk, const TrackerGeometry *tkGeometry)
Definition: pTFrom2Stubs.cc:72
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
const_iterator begin(int bx) const
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)