CMS 3D CMS Logo

GoodSeedProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PFTracking
4 // Class: GoodSeedProducer
5 //
6 // Original Author: Michele Pioppi
7 // March 2010. F. Beaudette. Produce PreId information
8 
10 
54 
55 #include "TMath.h"
56 #include "Math/VectorUtil.h"
57 
58 #include <fstream>
59 
60 namespace goodseedhelpers {
62  constexpr static unsigned int kMaxWeights = 9;
64  std::array<std::unique_ptr<const GBRForest>, kMaxWeights> gbr;
65  };
66 } // namespace goodseedhelpers
67 
68 class GoodSeedProducer final : public edm::stream::EDProducer<edm::GlobalCache<goodseedhelpers::HeavyObjectCache>> {
70 
71 public:
73 
74  static std::unique_ptr<goodseedhelpers::HeavyObjectCache> initializeGlobalCache(const edm::ParameterSet& conf) {
75  return std::make_unique<goodseedhelpers::HeavyObjectCache>(conf);
76  }
77 
79  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
80 
81 private:
82  void beginRun(const edm::Run& run, const edm::EventSetup&) override;
83  void produce(edm::Event&, const edm::EventSetup&) override;
84 
86  int getBin(float, float);
87 
91  // ----------member data ---------------------------
92 
95 
98 
101 
102  // needed by the above
104 
106  std::unique_ptr<PFTrackTransformer> pfTransformer_;
107 
110 
112  double minPt_;
113  double maxPt_;
114  double maxEta_;
115 
121  double minEoverP_;
122  double maxHoverP_;
123 
126 
128  double minEp_;
129  double maxEp_;
130 
133 
136 
139 
142 
144  float thr[150];
145 
146  // ----------access to event data
151  std::vector<edm::EDGetTokenT<std::vector<Trajectory>>> trajContainers_;
152  std::vector<edm::EDGetTokenT<reco::TrackCollection>> tracksContainers_;
153 
158 
159  std::unique_ptr<PFResolutionMap> resMapEtaECAL_;
160  std::unique_ptr<PFResolutionMap> resMapPhiECAL_;
161 
167 
171 
175  double Min_dr_;
176 
178  bool useTmva_;
179 
182 
184  std::map<reco::TrackRef, unsigned> refMap_;
185 };
186 
187 using namespace edm;
188 using namespace std;
189 using namespace reco;
190 
193  desc.add<double>("MaxEOverP", 3.0);
194  desc.add<std::string>("Smoother", "GsfTrajectorySmoother_forPreId");
195  desc.add<bool>("UseQuality", true);
196  desc.add<edm::InputTag>("PFPSClusterLabel", {"particleFlowClusterPS"});
197  desc.add<std::string>("ThresholdFile", "RecoParticleFlow/PFTracking/data/Threshold.dat");
198  desc.add<std::string>("TMVAMethod", "BDT");
199  desc.add<double>("MaxEta", 2.4);
200  desc.add<std::string>("EtaMap", "RecoParticleFlow/PFBlockProducer/data/resmap_ECAL_eta.dat");
201  desc.add<std::string>("PhiMap", "RecoParticleFlow/PFBlockProducer/data/resmap_ECAL_phi.dat");
202  desc.add<std::string>("PreCkfLabel", "SeedsForCkf");
203  desc.add<int>("NHitsInSeed", 3);
204  desc.add<std::string>("Fitter", "GsfTrajectoryFitter_forPreId");
205  desc.add<std::string>("TTRHBuilder", "WithAngleAndTemplate");
206  desc.add<std::string>("PreGsfLabel", "SeedsForGsf");
207  desc.add<double>("MinEOverP", 0.3);
208  desc.add<std::string>("Weights1", "RecoParticleFlow/PFTracking/data/MVA_BDTTrackDrivenSeed_cat1.xml");
209  desc.add<std::string>("Weights2", "RecoParticleFlow/PFTracking/data/MVA_BDTTrackDrivenSeed_cat2.xml");
210  desc.add<std::string>("Weights3", "RecoParticleFlow/PFTracking/data/MVA_BDTTrackDrivenSeed_cat3.xml");
211  desc.add<std::string>("Weights4", "RecoParticleFlow/PFTracking/data/MVA_BDTTrackDrivenSeed_cat4.xml");
212  desc.add<std::string>("Weights5", "RecoParticleFlow/PFTracking/data/MVA_BDTTrackDrivenSeed_cat5.xml");
213  desc.add<std::string>("Weights6", "RecoParticleFlow/PFTracking/data/MVA_BDTTrackDrivenSeed_cat6.xml");
214  desc.add<std::string>("Weights7", "RecoParticleFlow/PFTracking/data/MVA_BDTTrackDrivenSeed_cat7.xml");
215  desc.add<std::string>("Weights8", "RecoParticleFlow/PFTracking/data/MVA_BDTTrackDrivenSeed_cat8.xml");
216  desc.add<std::string>("Weights9", "RecoParticleFlow/PFTracking/data/MVA_BDTTrackDrivenSeed_cat9.xml");
217  desc.add<edm::InputTag>("PFEcalClusterLabel", {"particleFlowClusterECAL"});
218  desc.add<edm::InputTag>("PFHcalClusterLabel", {"particleFlowClusterHCAL"}),
219  desc.add<std::string>("PSThresholdFile", "RecoParticleFlow/PFTracking/data/PSThreshold.dat");
220  desc.add<double>("MinPt", 2.0);
221  desc.add<std::vector<edm::InputTag>>("TkColList", {edm::InputTag("generalTracks")});
222  desc.addUntracked<bool>("UseTMVA", true);
223  desc.add<std::string>("TrackQuality", "highPurity");
224  desc.add<double>("MaxPt", 50.0);
225  desc.add<bool>("ApplyIsolation", false);
226  desc.add<double>("EcalStripSumE_deltaPhiOverQ_minValue", -0.1);
227  desc.add<double>("EcalStripSumE_minClusEnergy", 0.1);
228  desc.add<double>("EcalStripSumE_deltaEta", 0.03);
229  desc.add<double>("EcalStripSumE_deltaPhiOverQ_maxValue", 0.5);
230  desc.add<double>("EOverPLead_minValue", 0.95);
231  desc.add<double>("HOverPLead_maxValue", 0.05);
232  desc.add<double>("HcalWindow", 0.184);
233  desc.add<double>("ClusterThreshold", 0.5);
234  desc.add<bool>("UsePreShower", false);
235  desc.add<std::string>("PreIdLabel", "preid");
236  desc.addUntracked<bool>("ProducePreId", true);
237  desc.addUntracked<double>("PtThresholdSavePreId", 1.0);
238  desc.add<double>("Min_dr", 0.2);
239  descriptions.addWithDefaultLabel(desc);
240 }
241 
243  : pfTransformer_(nullptr),
244  conf_(iConfig),
245  resMapEtaECAL_(nullptr),
246  resMapPhiECAL_(nullptr),
247  fitterToken_(esConsumes(edm::ESInputTag("", iConfig.getParameter<string>("Fitter")))),
248  smootherToken_(esConsumes(edm::ESInputTag("", iConfig.getParameter<string>("Smoother")))),
249  trackerRecHitBuilderToken_(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("TTRHBuilder")))),
250  magneticFieldToken_(esConsumes()),
251  magneticFieldTokenBeginRun_(esConsumes<edm::Transition::BeginRun>()) {
252  LogInfo("GoodSeedProducer") << "Electron PreIdentification started ";
253 
254  //now do what ever initialization is needed
255  std::vector<edm::InputTag> tags = iConfig.getParameter<vector<InputTag>>("TkColList");
256  for (unsigned int i = 0; i < tags.size(); ++i) {
257  trajContainers_.push_back(consumes<vector<Trajectory>>(tags[i]));
258  tracksContainers_.push_back(consumes<reco::TrackCollection>(tags[i]));
259  }
260 
261  minPt_ = iConfig.getParameter<double>("MinPt");
262  maxPt_ = iConfig.getParameter<double>("MaxPt");
263  maxEta_ = iConfig.getParameter<double>("MaxEta");
264 
265  HcalIsolWindow_ = iConfig.getParameter<double>("HcalWindow");
266  EcalStripSumE_minClusEnergy_ = iConfig.getParameter<double>("EcalStripSumE_minClusEnergy");
267  EcalStripSumE_deltaEta_ = iConfig.getParameter<double>("EcalStripSumE_deltaEta");
268  EcalStripSumE_deltaPhiOverQ_minValue_ = iConfig.getParameter<double>("EcalStripSumE_deltaPhiOverQ_minValue");
269  EcalStripSumE_deltaPhiOverQ_maxValue_ = iConfig.getParameter<double>("EcalStripSumE_deltaPhiOverQ_maxValue");
270  minEoverP_ = iConfig.getParameter<double>("EOverPLead_minValue");
271  maxHoverP_ = iConfig.getParameter<double>("HOverPLead_maxValue");
272 
273  pfCLusTagECLabel_ = consumes<reco::PFClusterCollection>(iConfig.getParameter<InputTag>("PFEcalClusterLabel"));
274 
275  pfCLusTagHCLabel_ = consumes<reco::PFClusterCollection>(iConfig.getParameter<InputTag>("PFHcalClusterLabel"));
276 
277  pfCLusTagPSLabel_ = consumes<reco::PFClusterCollection>(iConfig.getParameter<InputTag>("PFPSClusterLabel"));
278 
279  preidgsf_ = iConfig.getParameter<string>("PreGsfLabel");
280  preidckf_ = iConfig.getParameter<string>("PreCkfLabel");
281  preidname_ = iConfig.getParameter<string>("PreIdLabel");
282 
283  fitterName_ = iConfig.getParameter<string>("Fitter");
284  smootherName_ = iConfig.getParameter<string>("Smoother");
285 
286  nHitsInSeed_ = iConfig.getParameter<int>("NHitsInSeed");
287 
288  clusThreshold_ = iConfig.getParameter<double>("ClusterThreshold");
289 
290  minEp_ = iConfig.getParameter<double>("MinEOverP");
291  maxEp_ = iConfig.getParameter<double>("MaxEOverP");
292 
293  //collection to produce
294  produceCkfseed_ = iConfig.getUntrackedParameter<bool>("ProduceCkfSeed", false);
295 
296  // to disable the electron part (for HI collisions for examples)
297  disablePreId_ = iConfig.getUntrackedParameter<bool>("DisablePreId", false);
298 
299  producePreId_ = iConfig.getUntrackedParameter<bool>("ProducePreId", true);
300  // if no electron, cannot produce the preid
301  if (disablePreId_)
302  producePreId_ = false;
303  PtThresholdSavePredId_ = iConfig.getUntrackedParameter<double>("PtThresholdSavePreId", 1.);
304 
305  LogDebug("GoodSeedProducer") << "Seeds for GSF will be produced ";
306 
307  // no disablePreId_ switch here. The collection will be empty if it is true
308  produces<ElectronSeedCollection>(preidgsf_);
309 
310  if (produceCkfseed_) {
311  LogDebug("GoodSeedProducer") << "Seeds for CKF will be produced ";
312  produces<TrajectorySeedCollection>(preidckf_);
313  }
314 
315  if (producePreId_) {
316  LogDebug("GoodSeedProducer") << "PreId debugging information will be produced ";
317 
318  produces<PreIdCollection>(preidname_);
319  if (tracksContainers_.size() == 1) // do not make a value map if more than one input track collection
321  }
322 
323  useQuality_ = iConfig.getParameter<bool>("UseQuality");
325 
326  useTmva_ = iConfig.getUntrackedParameter<bool>("UseTMVA", false);
327 
328  Min_dr_ = iConfig.getParameter<double>("Min_dr");
329 
330  trackerRecHitBuilderName_ = iConfig.getParameter<std::string>("TTRHBuilder");
331 }
332 
333 //
334 // member functions
335 //
336 
337 // ------------ method called to produce the data ------------
339  LogDebug("GoodSeedProducer") << "START event: " << iEvent.id().event() << " in run " << iEvent.id().run();
340  //Create empty output collections
341  auto output_preid = std::make_unique<ElectronSeedCollection>();
342  auto output_nopre = std::make_unique<TrajectorySeedCollection>();
343  auto output_preidinfo = std::make_unique<PreIdCollection>();
344  auto preIdMap_p = std::make_unique<edm::ValueMap<reco::PreIdRef>>();
345  edm::ValueMap<reco::PreIdRef>::Filler mapFiller(*preIdMap_p);
346 
347  std::unique_ptr<TrajectoryFitter> fitter;
348  std::unique_ptr<TrajectorySmoother> smoother;
349 
350  //Tracking Tools
351  if (!disablePreId_) {
352  auto const& aFitter = &iSetup.getData(fitterToken_);
353  auto const& aSmoother = &iSetup.getData(smootherToken_);
354 
355  smoother.reset(aSmoother->clone());
356  fitter = aFitter->clone();
357  auto const& theTrackerRecHitBuilder = &iSetup.getData(trackerRecHitBuilderToken_);
358  hitCloner = static_cast<TkTransientTrackingRecHitBuilder const*>(theTrackerRecHitBuilder)->cloner();
359  fitter->setHitCloner(&hitCloner);
360  smoother->setHitCloner(&hitCloner);
361  }
362 
363  // clear temporary maps
364  refMap_.clear();
365 
366  //Magnetic Field
367  auto const& magneticField = &iSetup.getData(magneticFieldToken_);
368 
369  //Handle input collections
370  //ECAL clusters
371  Handle<PFClusterCollection> theECPfClustCollection;
372  iEvent.getByToken(pfCLusTagECLabel_, theECPfClustCollection);
373 
374  vector<PFCluster const*> basClus;
375  for (auto const& klus : *theECPfClustCollection.product()) {
376  if (klus.correctedEnergy() > clusThreshold_)
377  basClus.push_back(&klus);
378  }
379 
380  //HCAL clusters
381  Handle<PFClusterCollection> theHCPfClustCollection;
382  iEvent.getByToken(pfCLusTagHCLabel_, theHCPfClustCollection);
383 
384  //PS clusters
385  Handle<PFClusterCollection> thePSPfClustCollection;
386  iEvent.getByToken(pfCLusTagPSLabel_, thePSPfClustCollection);
387 
388  //Vector of track collections
389  for (unsigned int istr = 0; istr < tracksContainers_.size(); ++istr) {
390  //Track collection
391  Handle<TrackCollection> tkRefCollection;
392  iEvent.getByToken(tracksContainers_[istr], tkRefCollection);
393  const TrackCollection& Tk = *(tkRefCollection.product());
394 
395  LogDebug("GoodSeedProducer") << "Number of tracks in collection "
396  << "tracksContainers_[" << istr << "] to be analyzed " << Tk.size();
397 
398  //loop over the track collection
399  for (unsigned int i = 0; i < Tk.size(); ++i) {
400  if (useQuality_ && (!(Tk[i].quality(trackQuality_))))
401  continue;
402 
403  reco::PreId myPreId;
404  bool GoodPreId = false;
405 
406  TrackRef trackRef(tkRefCollection, i);
407  math::XYZVectorF tkmom(Tk[i].momentum());
408  auto tketa = tkmom.eta();
409  auto tkpt = std::sqrt(tkmom.perp2());
410  auto const& Seed = (*trackRef->seedRef());
411 
412  if (!disablePreId_) {
413  int ipteta = getBin(Tk[i].eta(), Tk[i].pt());
414  int ibin = ipteta * 9;
415 
416  // FIXME the original code was buggy should be outerMomentum...
417  float oPTOB = 1.f / std::sqrt(Tk[i].innerMomentum().mag2());
418  // float chikfred=Tk[i].normalizedChi2();
419  float nchi = Tk[i].normalizedChi2();
420 
421  int nhitpi = Tk[i].found();
422  float EP = 0;
423 
424  // set track info
425  myPreId.setTrack(trackRef);
426  //CLUSTERS - TRACK matching
427 
428  auto pfmass = 0.0005;
429  auto pfoutenergy = sqrt((pfmass * pfmass) + Tk[i].outerMomentum().Mag2());
430 
432  Tk[i].outerMomentum().x(), Tk[i].outerMomentum().y(), Tk[i].outerMomentum().z(), pfoutenergy);
434  XYZTLorentzVector(Tk[i].outerPosition().x(), Tk[i].outerPosition().y(), Tk[i].outerPosition().z(), 0.);
435 
436  BaseParticlePropagator theOutParticle(RawParticle(mom, pos, Tk[i].charge()), 0, 0, B_.z());
437 
438  theOutParticle.propagateToEcalEntrance(false);
439 
440  float toteta = 1000.f;
441  float totphi = 1000.f;
442  float dr = 1000.f;
443  float EE = 0.f;
444  float feta = 0.f;
445  GlobalPoint ElecTrkEcalPos(0, 0, 0);
446 
447  PFClusterRef clusterRef;
448  math::XYZPoint meanShowerSaved;
449  if (theOutParticle.getSuccess() != 0) {
450  ElecTrkEcalPos = GlobalPoint(theOutParticle.particle().vertex().x(),
451  theOutParticle.particle().vertex().y(),
452  theOutParticle.particle().vertex().z());
453 
454  constexpr float psLim = 2.50746495928f; // std::sinh(1.65f);
455  bool isBelowPS = (ElecTrkEcalPos.z() * ElecTrkEcalPos.z()) > (psLim * psLim) * ElecTrkEcalPos.perp2();
456  // bool isBelowPS=(std::abs(ElecTrkEcalPos.eta())>1.65f);
457 
458  unsigned clusCounter = 0;
459  float max_ee = 0;
460  for (auto aClus : basClus) {
461  float tmp_ep = float(aClus->correctedEnergy()) * oPTOB;
462  if ((tmp_ep < minEp_) | (tmp_ep > maxEp_)) {
463  ++clusCounter;
464  continue;
465  }
466 
467  double ecalShowerDepth = PFCluster::getDepthCorrection(aClus->correctedEnergy(), isBelowPS, false);
468  auto mom = theOutParticle.particle().momentum().Vect();
469  auto meanShower = ElecTrkEcalPos + GlobalVector(mom.x(), mom.y(), mom.z()).unit() * ecalShowerDepth;
470 
471  float etarec = meanShower.eta();
472  float phirec = meanShower.phi();
473 
474  float tmp_phi = std::abs(aClus->positionREP().phi() - phirec);
475  if (tmp_phi > float(TMath::Pi()))
476  tmp_phi -= float(TMath::TwoPi());
477 
478  float tmp_dr = std::sqrt(std::pow(tmp_phi, 2.f) + std::pow(aClus->positionREP().eta() - etarec, 2.f));
479 
480  if (tmp_dr < dr) {
481  dr = tmp_dr;
482  if (dr < Min_dr_) { // find the most closest and energetic ECAL cluster
483  if (aClus->correctedEnergy() > max_ee) {
484  toteta = aClus->positionREP().eta() - etarec;
485  totphi = tmp_phi;
486  EP = tmp_ep;
487  EE = aClus->correctedEnergy();
488  feta = aClus->positionREP().eta();
489  clusterRef = PFClusterRef(theECPfClustCollection, clusCounter);
490  meanShowerSaved = meanShower;
491  }
492  }
493  }
494  ++clusCounter;
495  }
496  }
497  float trk_ecalDeta_ = fabs(toteta);
498  float trk_ecalDphi_ = fabs(totphi);
499 
500  //Resolution maps
501  auto ecaletares = resMapEtaECAL_->GetBinContent(resMapEtaECAL_->FindBin(feta, EE));
502  auto ecalphires = resMapPhiECAL_->GetBinContent(resMapPhiECAL_->FindBin(feta, EE));
503 
504  //geomatrical compatibility
505  float chieta = (toteta != 1000.f) ? toteta / ecaletares : toteta;
506  float chiphi = (totphi != 1000.f) ? totphi / ecalphires : totphi;
507  float chichi = sqrt(chieta * chieta + chiphi * chiphi);
508 
509  //Matching criteria
510  float eta_cut = thr[ibin + 0];
511  float phi_cut = thr[ibin + 1];
512  float ep_cutmin = thr[ibin + 2];
513  bool GoodMatching =
514  ((trk_ecalDeta_ < eta_cut) && (trk_ecalDphi_ < phi_cut) && (EP > ep_cutmin) && (nhitpi > 10));
515 
516  bool EcalMatching = GoodMatching;
517 
518  if (tkpt > maxPt_)
519  GoodMatching = true;
520  if (tkpt < minPt_)
521  GoodMatching = false;
522 
523  math::XYZPoint myPoint(ElecTrkEcalPos.x(), ElecTrkEcalPos.y(), ElecTrkEcalPos.z());
525  clusterRef, myPoint, meanShowerSaved, std::abs(toteta), std::abs(totphi), chieta, chiphi, chichi, EP);
526  myPreId.setECALMatching(EcalMatching);
527 
528  bool GoodRange = ((std::abs(tketa) < maxEta_) & (tkpt > minPt_));
529  //KF FILTERING FOR UNMATCHED EVENTS
530  int hit1max = int(thr[ibin + 3]);
531  float chiredmin = thr[ibin + 4];
532  bool GoodKFFiltering = ((nchi > chiredmin) | (nhitpi < hit1max));
533 
534  myPreId.setTrackFiltering(GoodKFFiltering);
535 
536  bool GoodTkId = false;
537 
538  if ((!GoodMatching) && (GoodKFFiltering) && (GoodRange)) {
539  chired = 1000;
540  chiRatio = 1000;
541  dpt = 0;
542  nhit = nhitpi;
543  chikfred = nchi;
544  trk_ecalDeta = trk_ecalDeta_;
545  trk_ecalDphi = trk_ecalDphi_;
546 
548  for (auto const& hit : Tk[i].recHits())
549  tmp.push_back(hit->cloneSH());
550  auto const& theTrack = Tk[i];
551  GlobalVector gv(theTrack.innerMomentum().x(), theTrack.innerMomentum().y(), theTrack.innerMomentum().z());
552  GlobalPoint gp(theTrack.innerPosition().x(), theTrack.innerPosition().y(), theTrack.innerPosition().z());
553  GlobalTrajectoryParameters gtps(gp, gv, theTrack.charge(), &*magneticField);
554  TrajectoryStateOnSurface tsos(gtps, theTrack.innerStateCovariance(), *tmp[0]->surface());
555  Trajectory&& FitTjs = fitter->fitOne(Seed, tmp, tsos);
556 
557  if (FitTjs.isValid()) {
558  Trajectory&& SmooTjs = smoother->trajectory(FitTjs);
559  if (SmooTjs.isValid()) {
560  //Track refitted with electron hypothesis
561 
562  float pt_out = SmooTjs.firstMeasurement().updatedState().globalMomentum().perp();
563  float pt_in = SmooTjs.lastMeasurement().updatedState().globalMomentum().perp();
564  dpt = (pt_in > 0) ? fabs(pt_out - pt_in) / pt_in : 0.;
565  // the following is simply the number of degrees of freedom
566  chiRatio = SmooTjs.chiSquared() / Tk[i].chi2();
567  chired = chiRatio * chikfred;
568  }
569  }
570 
571  //TMVA Analysis
572  if (useTmva_) {
573  float vars[10] = {nhit, chikfred, dpt, EP, chiRatio, chired, trk_ecalDeta, trk_ecalDphi, tkpt, tketa};
574 
575  float Ytmva = globalCache()->gbr[ipteta]->GetClassifier(vars);
576 
577  float BDTcut = thr[ibin + 5];
578  if (Ytmva > BDTcut)
579  GoodTkId = true;
580  myPreId.setMVA(GoodTkId, Ytmva);
581  myPreId.setTrackProperties(chired, chiRatio, dpt);
582  } else {
583  float chiratiocut = thr[ibin + 6];
584  float gschicut = thr[ibin + 7];
585  float gsptmin = thr[ibin + 8];
586 
587  GoodTkId = ((dpt > gsptmin) & (chired < gschicut) & (chiRatio < chiratiocut));
588  }
589  }
590 
591  GoodPreId = GoodTkId | GoodMatching;
592 
593  myPreId.setFinalDecision(GoodPreId);
594 
595 #ifdef EDM_ML_DEBUG
596  if (GoodPreId)
597  LogDebug("GoodSeedProducer") << "Track (pt= " << Tk[i].pt() << "GeV/c, eta= " << Tk[i].eta()
598  << ") preidentified for agreement between track and ECAL cluster";
599  if (GoodPreId && (!GoodMatching))
600  LogDebug("GoodSeedProducer") << "Track (pt= " << Tk[i].pt() << "GeV/c, eta= " << Tk[i].eta()
601  << ") preidentified only for track properties";
602 #endif
603 
604  } // end of !disablePreId_
605 
606  if (GoodPreId) {
607  //NEW SEED with n hits
608  ElectronSeed NewSeed(Seed);
609  NewSeed.setCtfTrack(trackRef);
610  output_preid->push_back(NewSeed);
611  } else {
612  if (produceCkfseed_) {
613  output_nopre->push_back(Seed);
614  }
615  }
616  if (producePreId_ && myPreId.pt() > PtThresholdSavePredId_) {
617  // save the index of the PreId object as to be able to create a Ref later
618  refMap_[trackRef] = output_preidinfo->size();
619  output_preidinfo->push_back(myPreId);
620  }
621  } //end loop on track collection
622  } //end loop on the vector of track collections
623 
624  // no disablePreId_ switch, it is simpler to have an empty collection rather than no collection
625  iEvent.put(std::move(output_preid), preidgsf_);
626  if (produceCkfseed_)
627  iEvent.put(std::move(output_nopre), preidckf_);
628  if (producePreId_) {
629  const edm::OrphanHandle<reco::PreIdCollection> preIdRefProd = iEvent.put(std::move(output_preidinfo), preidname_);
630  // now make the Value Map, but only if one input collection
631  if (tracksContainers_.size() == 1) {
632  Handle<TrackCollection> tkRefCollection;
633  iEvent.getByToken(tracksContainers_[0], tkRefCollection);
634  fillPreIdRefValueMap(tkRefCollection, preIdRefProd, mapFiller);
635  mapFiller.fill();
636  iEvent.put(std::move(preIdMap_p), preidname_);
637  }
638  }
639  // clear temporary maps
640  refMap_.clear();
641 }
642 
643 // intialize the cross-thread cache to hold gbr trees and resolution maps
644 namespace goodseedhelpers {
646  // mvas
647  const bool useTmva = conf.getUntrackedParameter<bool>("UseTMVA", false);
648 
649  if (useTmva) {
650  std::array<edm::FileInPath, kMaxWeights> weights = {{edm::FileInPath(conf.getParameter<string>("Weights1")),
651  edm::FileInPath(conf.getParameter<string>("Weights2")),
652  edm::FileInPath(conf.getParameter<string>("Weights3")),
653  edm::FileInPath(conf.getParameter<string>("Weights4")),
654  edm::FileInPath(conf.getParameter<string>("Weights5")),
655  edm::FileInPath(conf.getParameter<string>("Weights6")),
656  edm::FileInPath(conf.getParameter<string>("Weights7")),
657  edm::FileInPath(conf.getParameter<string>("Weights8")),
658  edm::FileInPath(conf.getParameter<string>("Weights9"))}};
659 
660  for (UInt_t j = 0; j < gbr.size(); ++j) {
662  }
663  }
664  }
665 } // namespace goodseedhelpers
666 
667 // ------------ method called once each job just before starting event loop ------------
669  //Magnetic Field
670  auto const& magneticField = &es.getData(magneticFieldTokenBeginRun_);
671  B_ = magneticField->inTesla(GlobalPoint(0, 0, 0));
672 
673  pfTransformer_ = std::make_unique<PFTrackTransformer>(B_);
674  pfTransformer_->OnlyProp();
675 
676  //Resolution maps
677  FileInPath ecalEtaMap(conf_.getParameter<string>("EtaMap"));
678  FileInPath ecalPhiMap(conf_.getParameter<string>("PhiMap"));
679  resMapEtaECAL_ = std::make_unique<PFResolutionMap>("ECAL_eta", ecalEtaMap.fullPath().c_str());
680  resMapPhiECAL_ = std::make_unique<PFResolutionMap>("ECAL_phi", ecalPhiMap.fullPath().c_str());
681 
682  //read threshold
683  FileInPath parFile(conf_.getParameter<string>("ThresholdFile"));
684  ifstream ifs(parFile.fullPath().c_str());
685  for (int iy = 0; iy < 81; ++iy)
686  ifs >> thr[iy];
687 }
688 
689 int GoodSeedProducer::getBin(float eta, float pt) {
690  int ie = 0;
691  int ip = 0;
692  if (fabs(eta) < 0.8)
693  ie = 0;
694  else {
695  if (fabs(eta) < 1.479)
696  ie = 1;
697  else
698  ie = 2;
699  }
700  if (pt < 6)
701  ip = 0;
702  else {
703  if (pt < 12)
704  ip = 1;
705  else
706  ip = 2;
707  }
708  int iep = ie * 3 + ip;
709  LogDebug("GoodSeedProducer") << "Track pt =" << pt << " eta=" << eta << " bin=" << iep;
710  return iep;
711 }
712 
714  const edm::OrphanHandle<reco::PreIdCollection>& preidhandle,
716  std::vector<reco::PreIdRef> values;
717 
718  unsigned ntracks = tracks->size();
719  for (unsigned itrack = 0; itrack < ntracks; ++itrack) {
720  reco::TrackRef theTrackRef(tracks, itrack);
721  std::map<reco::TrackRef, unsigned>::const_iterator itcheck = refMap_.find(theTrackRef);
722  if (itcheck == refMap_.end()) {
723  // the track has been early discarded
724  values.push_back(reco::PreIdRef());
725  } else {
726  edm::Ref<reco::PreIdCollection> preIdRef(preidhandle, itcheck->second);
727  values.push_back(preIdRef);
728  // std::cout << " Checking Refs " << (theTrackRef==preIdRef->trackRef()) << std::endl;
729  }
730  }
731  filler.insert(tracks, values.begin(), values.end());
732 }
733 
734 DEFINE_FWK_MODULE(GoodSeedProducer);
int nHitsInSeed_
Number of hits in the seed;.
const double TwoPi
const double Pi
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magneticFieldToken_
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
HeavyObjectCache(const edm::ParameterSet &conf)
T perp() const
Definition: PV3DBase.h:69
void setECALMatchingProperties(PFClusterRef clusterRef, const math::XYZPoint &ecalpos, const math::XYZPoint &meanShower, float deta, float dphi, float chieta, float chiphi, float chi2, float eop)
Definition: PreId.h:33
bool isValid() const
Definition: Trajectory.h:257
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
std::string preidckf_
Name of the Seed(Ckf) Collection.
std::string fullPath() const
Definition: FileInPath.cc:161
Quality qualityByName(std::string const &name)
edm::EDGetTokenT< reco::PFClusterCollection > pfCLusTagPSLabel_
T z() const
Definition: PV3DBase.h:61
TrackQuality
track quality
Definition: TrackBase.h:150
vars
Definition: DeepTauIdBase.h:60
T const * product() const
Definition: Handle.h:70
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
float pt() const
Definition: PreId.h:80
std::unique_ptr< PFResolutionMap > resMapEtaECAL_
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magneticFieldTokenBeginRun_
float chiSquared() const
Definition: Trajectory.h:241
double EcalStripSumE_minClusEnergy_
float thr[150]
vector of thresholds for different bins of eta and pt
std::array< std::unique_ptr< const GBRForest >, kMaxWeights > gbr
GoodSeedProducer(const edm::ParameterSet &, const goodseedhelpers::HeavyObjectCache *)
float float float z
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:150
TkClonerImpl hitCloner
void setCtfTrack(const CtfTrackRef &)
Set additional info.
Definition: ElectronSeed.cc:39
T getUntrackedParameter(std::string const &, T const &) const
void setTrack(reco::TrackRef trackref)
Definition: PreId.h:31
string quality
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
int getBin(float, float)
Find the bin in pt and eta.
int iEvent
Definition: GenABIO.cc:224
edm::ParameterSet conf_
void setMVA(bool accepted, float mva, unsigned n=0)
Definition: PreId.h:63
double EcalStripSumE_deltaPhiOverQ_minValue_
double EcalStripSumE_deltaPhiOverQ_maxValue_
void setTrackFiltering(bool accepted, unsigned n=0)
Definition: PreId.h:62
void produce(edm::Event &, const edm::EventSetup &) override
T sqrt(T t)
Definition: SSEVec.h:23
TrajectoryStateOnSurface TSOS
math::XYZVector B_
B field.
std::string preidname_
Name of the preid Collection (FB)
std::string propagatorName_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Transition
Definition: Transition.h:12
bool useQuality_
TRACK QUALITY.
double z() const
z of vertex
Definition: RawParticle.h:284
void fillPreIdRefValueMap(edm::Handle< reco::TrackCollection > tkhandle, const edm::OrphanHandle< reco::PreIdCollection > &, edm::ValueMap< reco::PreIdRef >::Filler &filler)
double f[11][100]
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< edm::EDGetTokenT< reco::TrackCollection > > tracksContainers_
double minPt_
Minimum transverse momentum and maximum pseudorapidity.
std::string fitterName_
bool disablePreId_
switch to disable the pre-id
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float > > XYZVectorF
spatial vector with cartesian internal representation
Definition: Vector3D.h:16
static void globalEndJob(goodseedhelpers::HeavyObjectCache const *)
void beginRun(const edm::Run &run, const edm::EventSetup &) override
int getBin(double x, std::vector< double > boundaries)
Definition: Utilities.h:456
reco::TrackBase::TrackQuality trackQuality_
Basic3DVector unit() const
double clusThreshold_
Cut on the energy of the clusters.
bool propagateToEcalEntrance(bool first=true)
Log< level::Info, false > LogInfo
static constexpr unsigned int kMaxWeights
bool produceCkfseed_
Produce the Seed for Ckf tracks?
const edm::ESGetToken< TrajectorySmoother, TrajectoryFitter::Record > smootherToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool useTmva_
USE OF TMVA.
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
std::unique_ptr< PFResolutionMap > resMapPhiECAL_
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const edm::ESGetToken< TrajectoryFitter, TrajectoryFitter::Record > fitterToken_
std::map< reco::TrackRef, unsigned > refMap_
Map used to create the TrackRef, PreIdRef value map.
GlobalVector globalMomentum() const
T perp2() const
Definition: PV3DBase.h:68
TrajectoryStateOnSurface const & updatedState() const
TrackingRecHit::ConstRecHitContainer ConstRecHitContainer
Definition: Trajectory.h:41
void setTrackProperties(float newchi2, float chi2ratio, float dpt)
Definition: PreId.h:53
fixed size matrix
HLT enums.
void setECALMatching(bool accepted, unsigned n=0)
Definition: PreId.h:60
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:166
bool producePreId_
Produce the pre-id debugging collection.
float x
std::unique_ptr< PFTrackTransformer > pfTransformer_
PFTrackTransformer.
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iy(uint32_t id)
std::string trackerRecHitBuilderName_
std::string smootherName_
edm::EDGetTokenT< reco::PFClusterCollection > pfCLusTagHCLabel_
const edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > trackerRecHitBuilderToken_
tmp
align.sh
Definition: createJobs.py:716
std::string preidgsf_
Name of the Seed(Gsf) Collection.
edm::EDGetTokenT< reco::PFClusterCollection > pfCLusTagECLabel_
double minEp_
Min and MAx allowed values forEoverP.
float nhit
VARIABLES NEEDED FOR TMVA.
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
def move(src, dest)
Definition: eostools.py:511
std::vector< edm::EDGetTokenT< std::vector< Trajectory > > > trajContainers_
static std::unique_ptr< goodseedhelpers::HeavyObjectCache > initializeGlobalCache(const edm::ParameterSet &conf)
std::unique_ptr< const GBRForest > createGBRForest(const std::string &weightsFile)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Run.h:45
double PtThresholdSavePredId_
Threshold to save Pre Idinfo.
Global3DVector GlobalVector
Definition: GlobalVector.h:10
void setFinalDecision(bool accepted, unsigned n=0)
Definition: PreId.h:59
math::XYZTLorentzVector XYZTLorentzVector
Definition: RawParticle.h:25
edm::Ref< l1t::PFClusterCollection > PFClusterRef
Definition: PFCluster.h:88
#define LogDebug(id)