CMS 3D CMS Logo

TSGForOIDNN.cc
Go to the documentation of this file.
1 
34 #include <boost/property_tree/ptree.hpp>
35 #include <boost/property_tree/json_parser.hpp>
36 #include <boost/range/adaptor/reversed.hpp>
37 #include <memory>
38 namespace pt = boost::property_tree;
39 
41 public:
42  explicit TSGForOIDNN(const edm::ParameterSet& iConfig);
43  ~TSGForOIDNN() override;
44  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
45  void produce(edm::StreamID sid, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
46  void beginJob() override;
47 
48 private:
60  const std::unique_ptr<TrajectoryStateUpdator> updator_;
63 
65  const unsigned int maxSeeds_;
67  const unsigned int maxHitSeeds_;
69  const unsigned int maxHitlessSeeds_;
71  const unsigned int numOfLayersToTry_;
73  const unsigned int numOfHitsToTry_;
79  const double minEtaForTEC_;
81  const double maxEtaForTOB_;
82 
85  const unsigned int maxHitlessSeedsIP_;
86  const unsigned int maxHitlessSeedsMuS_;
87  const unsigned int maxHitDoubletSeeds_;
88 
90  const bool getStrategyFromDNN_;
92  const bool useRegressor_;
93 
96  std::unique_ptr<tensorflow::GraphDef> graphDef_;
97  tensorflow::Session* tf_session_;
98 
103  std::unique_ptr<tensorflow::GraphDef> graphDef_HB_;
104  tensorflow::Session* tf_session_HB_;
105  std::unique_ptr<tensorflow::GraphDef> graphDef_HLIP_;
106  tensorflow::Session* tf_session_HLIP_;
107  std::unique_ptr<tensorflow::GraphDef> graphDef_HLMuS_;
108  tensorflow::Session* tf_session_HLMuS_;
109 
112  pt::ptree metadata_;
113 
116  const TrajectoryStateOnSurface& tsos,
119  double errorSF,
120  unsigned int& hitlessSeedsMade,
121  unsigned int& numSeedsMade,
122  std::vector<TrajectorySeed>& out) const;
123 
126  const TrajectoryStateOnSurface& tsos,
130  unsigned int& hitSeedsMade,
131  unsigned int& numSeedsMade,
132  const unsigned int& maxHitSeeds,
133  unsigned int& layerCount,
134  std::vector<TrajectorySeed>& out) const;
135 
138  const TrajectoryStateOnSurface& tsos,
143  unsigned int& hitDoubletSeedsMade,
144  unsigned int& numSeedsMade,
145  const unsigned int& maxHitDoubletSeeds,
146  unsigned int& layerCount,
147  std::vector<TrajectorySeed>& out) const;
148 
150  void updateFeatureMap(std::unordered_map<std::string, float>& the_map,
151  const reco::Track& l2,
152  const TrajectoryStateOnSurface& tsos_IP,
153  const TrajectoryStateOnSurface& tsos_MuS) const;
154 
155  void initializeTensorflow() const;
156 
159  int nHBd, nHLIP, nHLMuS, sf;
160  };
161 
163  void evaluateClassifier(const std::unordered_map<std::string, float>& feature_map,
164  tensorflow::Session* session,
165  const pt::ptree& metadata,
167  bool& dnnSuccess) const;
168 
170  void evaluateRegressor(const std::unordered_map<std::string, float>& feature_map,
171  tensorflow::Session* session_HB,
172  const pt::ptree& metadata_HB,
173  tensorflow::Session* session_HLIP,
174  const pt::ptree& metadata_HLIP,
175  tensorflow::Session* session_HLMuS,
176  const pt::ptree& metadata_HLMuS,
178  bool& dnnSuccess) const;
179 };
180 
182  : src_(consumes(iConfig.getParameter<edm::InputTag>("src"))),
183  t_estimatorH_(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("estimator")))),
184  t_magfieldH_(esConsumes()),
185  t_propagatorAlongH_(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("propagatorName")))),
186  t_propagatorOppositeH_(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("propagatorName")))),
187  t_tmpTkGeometryH_(esConsumes()),
188  t_geometryH_(esConsumes()),
189  t_navSchool_(esConsumes(edm::ESInputTag("", "SimpleNavigationSchool"))),
190  t_SHPOpposite_(esConsumes(edm::ESInputTag("", "hltESPSteppingHelixPropagatorOpposite"))),
191  updator_(new KFUpdator()),
192  measurementTrackerTag_(consumes(iConfig.getParameter<edm::InputTag>("MeasurementTrackerEvent"))),
193  theCategory_(std::string("Muon|RecoMuon|TSGForOIDNN")),
194  maxSeeds_(iConfig.getParameter<uint32_t>("maxSeeds")),
195  maxHitSeeds_(iConfig.getParameter<uint32_t>("maxHitSeeds")),
196  maxHitlessSeeds_(iConfig.getParameter<uint32_t>("maxHitlessSeeds")),
197  numOfLayersToTry_(iConfig.getParameter<int32_t>("layersToTry")),
198  numOfHitsToTry_(iConfig.getParameter<int32_t>("hitsToTry")),
199  fixedErrorRescalingForHitless_(iConfig.getParameter<double>("fixedErrorRescaleFactorForHitless")),
200  minEtaForTEC_(iConfig.getParameter<double>("minEtaForTEC")),
201  maxEtaForTOB_(iConfig.getParameter<double>("maxEtaForTOB")),
202  maxHitlessSeedsIP_(iConfig.getParameter<uint32_t>("maxHitlessSeedsIP")),
203  maxHitlessSeedsMuS_(iConfig.getParameter<uint32_t>("maxHitlessSeedsMuS")),
204  maxHitDoubletSeeds_(iConfig.getParameter<uint32_t>("maxHitDoubletSeeds")),
205  getStrategyFromDNN_(iConfig.getParameter<bool>("getStrategyFromDNN")),
206  useRegressor_(iConfig.getParameter<bool>("useRegressor")),
207  dnnMetadataPath_(iConfig.getParameter<std::string>("dnnMetadataPath")) {
208  if (getStrategyFromDNN_) {
210  pt::read_json(dnnMetadataPath.fullPath(), metadata_);
212 
213  if (useRegressor_) {
214  // use regressor
215  dnnModelPath_HB_ = metadata_.get<std::string>("HB.dnnmodel_path");
216  edm::FileInPath dnnPath_HB(dnnModelPath_HB_);
217  graphDef_HB_ = std::unique_ptr<tensorflow::GraphDef>(tensorflow::loadGraphDef(dnnPath_HB.fullPath()));
219 
220  dnnModelPath_HLIP_ = metadata_.get<std::string>("HLIP.dnnmodel_path");
221  edm::FileInPath dnnPath_HLIP(dnnModelPath_HLIP_);
222  graphDef_HLIP_ = std::unique_ptr<tensorflow::GraphDef>(tensorflow::loadGraphDef(dnnPath_HLIP.fullPath()));
224 
225  dnnModelPath_HLMuS_ = metadata_.get<std::string>("HLMuS.dnnmodel_path");
226  edm::FileInPath dnnPath_HLMuS(dnnModelPath_HLMuS_);
227  graphDef_HLMuS_ = std::unique_ptr<tensorflow::GraphDef>(tensorflow::loadGraphDef(dnnPath_HLMuS.fullPath()));
229  } else {
230  // use classifier (default)
231  dnnModelPath_ = metadata_.get<std::string>("dnnmodel_path");
233  graphDef_ = std::unique_ptr<tensorflow::GraphDef>(tensorflow::loadGraphDef(dnnPath.fullPath()));
235  }
236  }
237  produces<std::vector<TrajectorySeed> >();
238 }
239 
241  if (getStrategyFromDNN_) {
242  if (useRegressor_) {
246  } else {
248  }
249  }
250 }
251 
253 
254 namespace {
255  std::unordered_map<std::string, float> dummyFeatureMap() {
256  std::unordered_map<std::string, float> the_map;
257  the_map["pt"] = 2.0;
258  the_map["eta"] = 0.5;
259  the_map["phi"] = 1.0;
260  the_map["validHits"] = 0.;
261  the_map["tsos_IP_eta"] = -999;
262  the_map["tsos_IP_phi"] = -999;
263  the_map["tsos_IP_pt"] = -999;
264  the_map["tsos_IP_pt_eta"] = -999;
265  the_map["tsos_IP_pt_phi"] = -999;
266  the_map["err0_IP"] = -999;
267  the_map["err1_IP"] = -999;
268  the_map["err2_IP"] = -999;
269  the_map["err3_IP"] = -999;
270  the_map["err4_IP"] = -999;
271  the_map["tsos_IP_valid"] = 0.0;
272  the_map["tsos_MuS_eta"] = -999;
273  the_map["tsos_MuS_phi"] = -999;
274  the_map["tsos_MuS_pt"] = -999;
275  the_map["tsos_MuS_pt_eta"] = -999;
276  the_map["tsos_MuS_pt_phi"] = -999;
277  the_map["err0_MuS"] = -999;
278  the_map["err1_MuS"] = -999;
279  the_map["err2_MuS"] = -999;
280  the_map["err3_MuS"] = -999;
281  the_map["err4_MuS"] = -999;
282  the_map["tsos_MuS_valid"] = 0.0;
283  return the_map;
284  }
285 } // namespace
286 
288  if (getStrategyFromDNN_ and not useRegressor_) {
289  // Container for DNN outputs
290  StrategyParameters strPars;
291  bool dnnSuccess = false;
292  evaluateClassifier(dummyFeatureMap(), tf_session_, metadata_, strPars, dnnSuccess);
293  }
294 }
295 
296 //
297 // Produce seeds
298 //
299 void TSGForOIDNN::produce(edm::StreamID sid, edm::Event& iEvent, edm::EventSetup const& iEventSetup) const {
300  // Initialize variables
301  unsigned int numSeedsMade = 0;
302  unsigned int layerCount = 0;
303  unsigned int hitlessSeedsMadeIP = 0;
304  unsigned int hitlessSeedsMadeMuS = 0;
305  unsigned int hitSeedsMade = 0;
306  unsigned int hitDoubletSeedsMade = 0;
307 
308  // Container for DNN inputs
309  std::unordered_map<std::string, float> feature_map;
310 
311  // Container for DNN outputs
312  StrategyParameters strPars;
313 
314  // Surface used to make a TSOS at the PCA to the beamline
316 
317  // Get setup objects
318  const MagneticField& magfield = iEventSetup.getData(t_magfieldH_);
320  const Propagator& tmpPropagatorAlong = iEventSetup.getData(t_propagatorAlongH_);
321  const Propagator& tmpPropagatorOpposite = iEventSetup.getData(t_propagatorOppositeH_);
322  const TrackerGeometry& tmpTkGeometry = iEventSetup.getData(t_tmpTkGeometryH_);
323  const GlobalTrackingGeometry& geometry = iEventSetup.getData(t_geometryH_);
324  const NavigationSchool& navSchool = iEventSetup.getData(t_navSchool_);
326 
327  // Read L2 track collection
328  auto const& l2TrackCol = iEvent.get(src_);
329 
330  // The product
331  std::unique_ptr<std::vector<TrajectorySeed> > result(new std::vector<TrajectorySeed>());
332 
333  // Get vector of Detector layers
334  auto const* gsTracker = measurementTracker.geometricSearchTracker();
335  std::vector<BarrelDetLayer const*> const& tob = gsTracker->tobLayers();
336  std::vector<ForwardDetLayer const*> const& tecPositive =
337  tmpTkGeometry.isThere(GeomDetEnumerators::P2OTEC) ? gsTracker->posTidLayers() : gsTracker->posTecLayers();
338  std::vector<ForwardDetLayer const*> const& tecNegative =
339  tmpTkGeometry.isThere(GeomDetEnumerators::P2OTEC) ? gsTracker->negTidLayers() : gsTracker->negTecLayers();
340 
341  // Get suitable propagators
342  std::unique_ptr<Propagator> propagatorAlong = SetPropagationDirection(tmpPropagatorAlong, alongMomentum);
343  std::unique_ptr<Propagator> propagatorOpposite = SetPropagationDirection(tmpPropagatorOpposite, oppositeToMomentum);
344 
345  // Stepping Helix Propagator for propogation from muon system to tracker
346  edm::ESHandle<Propagator> shpOpposite = iEventSetup.getHandle(t_SHPOpposite_);
347 
348  // Loop over the L2's and make seeds for all of them
349  LogTrace(theCategory_) << "TSGForOIDNN::produce: Number of L2's: " << l2TrackCol.size();
350 
351  for (auto const& l2 : l2TrackCol) {
352  // Container of Seeds
353  std::vector<TrajectorySeed> out;
354  LogTrace("TSGForOIDNN") << "TSGForOIDNN::produce: L2 muon pT, eta, phi --> " << l2.pt() << " , " << l2.eta()
355  << " , " << l2.phi();
356 
358 
359  dummyPlane->move(fts.position() - dummyPlane->position());
360  TrajectoryStateOnSurface tsosAtIP = TrajectoryStateOnSurface(fts, *dummyPlane);
361  LogTrace("TSGForOIDNN") << "TSGForOIDNN::produce: Created TSOSatIP: " << tsosAtIP;
362 
363  // Get the TSOS on the innermost layer of the L2
365  LogTrace("TSGForOIDNN") << "TSGForOIDNN::produce: Created TSOSatMuonSystem: " << tsosAtMuonSystem;
366 
367  LogTrace("TSGForOIDNN")
368  << "TSGForOIDNN::produce: Check the error of the L2 parameter and use hit seeds if big errors";
369 
370  StateOnTrackerBound fromInside(propagatorAlong.get());
371  TrajectoryStateOnSurface outerTkStateInside = fromInside(fts);
372 
373  StateOnTrackerBound fromOutside(&*shpOpposite);
374  TrajectoryStateOnSurface outerTkStateOutside = fromOutside(tsosAtMuonSystem);
375 
376  // Check if the two positions (using updated and not-updated TSOS) agree withing certain extent.
377  // If both TSOSs agree, use only the one at vertex, as it uses more information. If they do not agree, search for seeds based on both.
378  double l2muonEta = l2.eta();
379  double absL2muonEta = std::abs(l2muonEta);
380 
381  // make non-const copies of parameters, so they can be overriden for individual L2 muons
382  unsigned int maxHitSeeds = maxHitSeeds_;
384  unsigned int maxHitlessSeedsIP = maxHitlessSeedsIP_;
386 
387  float errorSFHitless = fixedErrorRescalingForHitless_;
388 
389  // update strategy parameters by evaluating DNN
390  if (getStrategyFromDNN_) {
391  bool dnnSuccess = false;
392 
393  // Update feature map with parameters of the current muon
394  updateFeatureMap(feature_map, l2, tsosAtIP, outerTkStateOutside);
395 
396  if (useRegressor_) {
397  // Use regressor
398  evaluateRegressor(feature_map,
400  metadata_.get_child("HB"),
402  metadata_.get_child("HLIP"),
404  metadata_.get_child("HLMuS"),
405  strPars,
406  dnnSuccess);
407  } else {
408  // Use classifier
409  evaluateClassifier(feature_map, tf_session_, metadata_, strPars, dnnSuccess);
410  }
411  if (!dnnSuccess)
412  break;
413 
414  maxHitSeeds = 0;
415  maxHitDoubletSeeds = strPars.nHBd;
416  maxHitlessSeedsIP = strPars.nHLIP;
417  maxHitlessSeedsMuS = strPars.nHLMuS;
418  errorSFHitless = strPars.sf;
419  }
420 
421  numSeedsMade = 0;
422  hitlessSeedsMadeIP = 0;
423  hitlessSeedsMadeMuS = 0;
424  hitSeedsMade = 0;
425  hitDoubletSeedsMade = 0;
426 
427  auto createSeeds = [&](auto const& layers) {
428  for (auto const& layer : boost::adaptors::reverse(layers)) {
429  if (hitlessSeedsMadeIP < maxHitlessSeedsIP && numSeedsMade < maxSeeds_)
431  tsosAtIP,
432  *(propagatorAlong.get()),
433  estimator,
434  errorSFHitless,
435  hitlessSeedsMadeIP,
436  numSeedsMade,
437  out);
438 
439  if (outerTkStateInside.isValid() && outerTkStateOutside.isValid() && hitlessSeedsMadeMuS < maxHitlessSeedsMuS &&
440  numSeedsMade < maxSeeds_)
442  outerTkStateOutside,
443  *(propagatorOpposite.get()),
444  estimator,
445  errorSFHitless,
446  hitlessSeedsMadeMuS,
447  numSeedsMade,
448  out);
449 
450  if (hitSeedsMade < maxHitSeeds && numSeedsMade < maxSeeds_)
452  tsosAtIP,
453  *(propagatorAlong.get()),
454  estimator,
456  hitSeedsMade,
457  numSeedsMade,
458  maxHitSeeds,
459  layerCount,
460  out);
461 
462  if (hitDoubletSeedsMade < maxHitDoubletSeeds && numSeedsMade < maxSeeds_)
464  tsosAtIP,
465  *(propagatorAlong.get()),
466  estimator,
468  navSchool,
469  hitDoubletSeedsMade,
470  numSeedsMade,
472  layerCount,
473  out);
474  };
475  };
476 
477  // BARREL
478  if (absL2muonEta < maxEtaForTOB_) {
479  layerCount = 0;
480  createSeeds(tob);
481  LogTrace("TSGForOIDNN") << "TSGForOIDNN:::produce: NumSeedsMade = " << numSeedsMade
482  << " , layerCount = " << layerCount;
483  }
484 
485  // Reset number of seeds if in overlap region
486  if (absL2muonEta > minEtaForTEC_ && absL2muonEta < maxEtaForTOB_) {
487  numSeedsMade = 0;
488  hitlessSeedsMadeIP = 0;
489  hitlessSeedsMadeMuS = 0;
490  hitSeedsMade = 0;
491  hitDoubletSeedsMade = 0;
492  }
493 
494  // ENDCAP+
495  if (l2muonEta > minEtaForTEC_) {
496  layerCount = 0;
497  createSeeds(tecPositive);
498  LogTrace("TSGForOIDNN") << "TSGForOIDNN:::produce: NumSeedsMade = " << numSeedsMade
499  << " , layerCount = " << layerCount;
500  }
501 
502  // ENDCAP-
503  if (l2muonEta < -minEtaForTEC_) {
504  layerCount = 0;
505  createSeeds(tecNegative);
506  LogTrace("TSGForOIDNN") << "TSGForOIDNN:::produce: NumSeedsMade = " << numSeedsMade
507  << " , layerCount = " << layerCount;
508  }
509 
510  for (std::vector<TrajectorySeed>::iterator it = out.begin(); it != out.end(); ++it) {
511  result->push_back(*it);
512  }
513 
514  } // L2Collection
515 
516  edm::LogInfo(theCategory_) << "TSGForOIDNN::produce: number of seeds made: " << result->size();
517 
518  iEvent.put(std::move(result));
519 }
520 
521 //
522 // Create seeds without hits on a given layer (TOB or TEC)
523 //
525  const TrajectoryStateOnSurface& tsos,
528  double errorSF,
529  unsigned int& hitlessSeedsMade,
530  unsigned int& numSeedsMade,
531  std::vector<TrajectorySeed>& out) const {
532  // create hitless seeds
533  LogTrace("TSGForOIDNN") << "TSGForOIDNN::makeSeedsWithoutHits: Start hitless";
534  std::vector<GeometricSearchDet::DetWithState> dets;
535  layer.compatibleDetsV(tsos, propagatorAlong, estimator, dets);
536  if (!dets.empty()) {
537  auto const& detOnLayer = dets.front().first;
538  auto& tsosOnLayer = dets.front().second;
539  LogTrace("TSGForOIDNN") << "TSGForOIDNN::makeSeedsWithoutHits: tsosOnLayer " << tsosOnLayer;
540  if (!tsosOnLayer.isValid()) {
541  edm::LogInfo(theCategory_) << "ERROR!: Hitless TSOS is not valid!";
542  } else {
543  tsosOnLayer.rescaleError(errorSF);
544  PTrajectoryStateOnDet const& ptsod =
545  trajectoryStateTransform::persistentState(tsosOnLayer, detOnLayer->geographicalId().rawId());
547  out.push_back(TrajectorySeed(ptsod, rHC, oppositeToMomentum));
548  LogTrace("TSGForOIDNN") << "TSGForOIDNN::makeSeedsWithoutHits: TSOS (Hitless) done ";
549  hitlessSeedsMade++;
550  numSeedsMade++;
551  }
552  }
553 }
554 
555 //
556 // Find hits on a given layer (TOB or TEC) and create seeds from updated TSOS with hit
557 //
559  const TrajectoryStateOnSurface& tsos,
563  unsigned int& hitSeedsMade,
564  unsigned int& numSeedsMade,
565  const unsigned int& maxHitSeeds,
566  unsigned int& layerCount,
567  std::vector<TrajectorySeed>& out) const {
568  if (layerCount > numOfLayersToTry_)
569  return;
570 
571  const TrajectoryStateOnSurface& onLayer(tsos);
572 
573  std::vector<GeometricSearchDet::DetWithState> dets;
574  layer.compatibleDetsV(onLayer, propagatorAlong, estimator, dets);
575 
576  // Find Measurements on each DetWithState
577  LogTrace("TSGForOIDNN") << "TSGForOIDNN::makeSeedsFromHits: Find measurements on each detWithState " << dets.size();
578  std::vector<TrajectoryMeasurement> meas;
579  for (auto const& detI : dets) {
580  MeasurementDetWithData det = measurementTracker.idToDet(detI.first->geographicalId());
581  if (det.isNull())
582  continue;
583  if (!detI.second.isValid())
584  continue; // Skip if TSOS is not valid
585 
586  std::vector<TrajectoryMeasurement> mymeas =
587  det.fastMeasurements(detI.second, onLayer, propagatorAlong, estimator); // Second TSOS is not used
588  for (auto const& measurement : mymeas) {
589  if (measurement.recHit()->isValid())
590  meas.push_back(measurement); // Only save those which are valid
591  }
592  }
593 
594  // Update TSOS using TMs after sorting, then create Trajectory Seed and put into vector
595  LogTrace("TSGForOIDNN") << "TSGForOIDNN::makeSeedsFromHits: Update TSOS using TMs after sorting, then create "
596  "Trajectory Seed, number of TM = "
597  << meas.size();
598  std::sort(meas.begin(), meas.end(), TrajMeasLessEstim());
599 
600  unsigned int found = 0;
601  for (auto const& measurement : meas) {
602  if (hitSeedsMade >= maxHitSeeds)
603  return;
604  TrajectoryStateOnSurface updatedTSOS = updator_->update(measurement.forwardPredictedState(), *measurement.recHit());
605  LogTrace("TSGForOIDNN") << "TSGForOIDNN::makeSeedsFromHits: TSOS for TM " << found;
606  if (not updatedTSOS.isValid())
607  continue;
608 
610  seedHits.push_back(*measurement.recHit()->hit());
611  PTrajectoryStateOnDet const& pstate =
612  trajectoryStateTransform::persistentState(updatedTSOS, measurement.recHit()->geographicalId().rawId());
613  LogTrace("TSGForOIDNN") << "TSGForOIDNN::makeSeedsFromHits: Number of seedHits: " << seedHits.size();
614  TrajectorySeed seed(pstate, std::move(seedHits), oppositeToMomentum);
615  out.push_back(seed);
616  found++;
617  numSeedsMade++;
618  hitSeedsMade++;
619  if (found == numOfHitsToTry_)
620  break;
621  }
622 
623  if (found)
624  layerCount++;
625 }
626 
627 //
628 // Find hits compatible with L2 trajectory on two adjacent layers; if found, create a seed using both hits
629 //
631  const TrajectoryStateOnSurface& tsos,
636  unsigned int& hitDoubletSeedsMade,
637  unsigned int& numSeedsMade,
638  const unsigned int& maxHitDoubletSeeds,
639  unsigned int& layerCount,
640  std::vector<TrajectorySeed>& out) const {
641  // This method is similar to makeSeedsFromHits, but the seed is created
642  // only when in addition to a hit on a given layer, there are more compatible hits
643  // on next layers (going from outside inwards), compatible with updated TSOS.
644  // If that's the case, multiple compatible hits are used to create a single seed.
645 
646  // Configured to only check the immideately adjacent layer and add one more hit
647  int max_addtnl_layers = 1; // max number of additional layers to scan
648  int max_meas = 1; // number of measurements to consider on each additional layer
649 
650  // // // First, regular procedure to find a compatible hit - like in makeSeedsFromHits // // //
651 
652  const TrajectoryStateOnSurface& onLayer(tsos);
653 
654  // Find dets compatible with original TSOS
655  std::vector<GeometricSearchDet::DetWithState> dets;
656  layer.compatibleDetsV(onLayer, propagatorAlong, estimator, dets);
657 
658  LogTrace("TSGForOIDNN") << "TSGForOIDNN::makeSeedsFromHitDoublets: Find measurements on each detWithState "
659  << dets.size();
660  std::vector<TrajectoryMeasurement> meas;
661 
662  // Loop over dets
663  for (auto const& detI : dets) {
664  MeasurementDetWithData det = measurementTracker.idToDet(detI.first->geographicalId());
665 
666  if (det.isNull())
667  continue; // skip if det does not exist
668  if (!detI.second.isValid())
669  continue; // skip if TSOS is invalid
670 
671  // Find measurements on this det
672  std::vector<TrajectoryMeasurement> mymeas = det.fastMeasurements(detI.second, onLayer, propagatorAlong, estimator);
673 
674  // Save valid measurements
675  for (auto const& measurement : mymeas) {
676  if (measurement.recHit()->isValid())
677  meas.push_back(measurement);
678  } // end loop over meas
679  } // end loop over dets
680 
681  LogTrace("TSGForOIDNN") << "TSGForOIDNN::makeSeedsFromHitDoublets: Update TSOS using TMs after sorting, then create "
682  "Trajectory Seed, number of TM = "
683  << meas.size();
684 
685  // sort valid measurements found on the first layer
686  std::sort(meas.begin(), meas.end(), TrajMeasLessEstim());
687 
688  unsigned int found = 0;
689 
690  // Loop over all valid measurements compatible with original TSOS
691  //for (std::vector<TrajectoryMeasurement>::const_iterator mea = meas.begin(); mea != meas.end(); ++mea) {
692  for (auto const& measurement : meas) {
693  if (hitDoubletSeedsMade >= maxHitDoubletSeeds)
694  return; // abort if enough seeds created
695 
696  // Update TSOS with measurement on first considered layer
697  TrajectoryStateOnSurface updatedTSOS = updator_->update(measurement.forwardPredictedState(), *measurement.recHit());
698 
699  LogTrace("TSGForOIDNN") << "TSGForOIDNN::makeSeedsFromHitDoublets: TSOS for TM " << found;
700  if (not updatedTSOS.isValid())
701  continue; // Skip if updated TSOS is invalid
702 
704 
705  // Save hit on first layer
706  seedHits.push_back(*measurement.recHit()->hit());
707  const DetLayer* detLayer = dynamic_cast<const DetLayer*>(&layer);
708 
709  // // // Now for this measurement we will loop over additional layers and try to update the TSOS again // // //
710 
711  // find layers compatible with updated TSOS
712  auto const& compLayers = navSchool.nextLayers(*detLayer, *updatedTSOS.freeState(), alongMomentum);
713 
714  int addtnl_layers_scanned = 0;
715  int found_compatible_on_next_layer = 0;
716  int det_id = 0;
717 
718  // Copy updated TSOS - we will update it again with a measurement from the next layer, if we find it
719  TrajectoryStateOnSurface updatedTSOS_next(updatedTSOS);
720 
721  // loop over layers compatible with updated TSOS
722  for (auto compLayer : compLayers) {
723  int nmeas = 0;
724 
725  if (addtnl_layers_scanned >= max_addtnl_layers)
726  break; // break if we already looped over enough layers
727  if (found_compatible_on_next_layer > 0)
728  break; // break if we already found additional hit
729 
730  // find dets compatible with updated TSOS
731  std::vector<GeometricSearchDet::DetWithState> dets_next;
732  TrajectoryStateOnSurface onLayer_next(updatedTSOS);
733 
734  compLayer->compatibleDetsV(onLayer_next, propagatorAlong, estimator, dets_next);
735 
736  //if (!detWithState.size()) continue;
737  std::vector<TrajectoryMeasurement> meas_next;
738 
739  // find measurements on dets_next and save the valid ones
740  for (auto const& detI_next : dets_next) {
741  MeasurementDetWithData det = measurementTracker.idToDet(detI_next.first->geographicalId());
742 
743  if (det.isNull())
744  continue; // skip if det does not exist
745  if (!detI_next.second.isValid())
746  continue; // skip if TSOS is invalid
747 
748  // Find measurements on this det
749  std::vector<TrajectoryMeasurement> mymeas_next =
750  det.fastMeasurements(detI_next.second, onLayer_next, propagatorAlong, estimator);
751 
752  for (auto const& mea_next : mymeas_next) {
753  // save valid measurements
754  if (mea_next.recHit()->isValid())
755  meas_next.push_back(mea_next);
756 
757  } // end loop over mymeas_next
758  } // end loop over dets_next
759 
760  // sort valid measurements found on this layer
761  std::sort(meas_next.begin(), meas_next.end(), TrajMeasLessEstim());
762 
763  // loop over valid measurements compatible with updated TSOS (TSOS updated with a hit on the first layer)
764  for (auto const& mea_next : meas_next) {
765  if (nmeas >= max_meas)
766  break; // skip if we already found enough hits
767 
768  // try to update TSOS again, with an additional hit
769  updatedTSOS_next = updator_->update(mea_next.forwardPredictedState(), *mea_next.recHit());
770 
771  if (not updatedTSOS_next.isValid())
772  continue; // skip if TSOS updated with additional hit is not valid
773 
774  // If there was a compatible hit on this layer, we end up here.
775  // An additional compatible hit is saved.
776  seedHits.push_back(*mea_next.recHit()->hit());
777  det_id = mea_next.recHit()->geographicalId().rawId();
778  nmeas++;
779  found_compatible_on_next_layer++;
780 
781  } // end loop over meas_next
782 
783  addtnl_layers_scanned++;
784 
785  } // end loop over compLayers (additional layers scanned after the original layer)
786 
787  if (found_compatible_on_next_layer == 0)
788  continue;
789  // only consider the hit if there was a compatible hit on one of the additional scanned layers
790 
791  // Create a seed from two saved hits
792  PTrajectoryStateOnDet const& pstate = trajectoryStateTransform::persistentState(updatedTSOS_next, det_id);
793  TrajectorySeed seed(pstate, std::move(seedHits), oppositeToMomentum);
794 
795  LogTrace("TSGForOIDNN") << "TSGForOIDNN::makeSeedsFromHitDoublets: Number of seedHits: " << seedHits.size();
796  out.push_back(seed);
797 
798  found++;
799  numSeedsMade++;
800  hitDoubletSeedsMade++;
801 
802  if (found == numOfHitsToTry_)
803  break; // break if enough measurements scanned
804 
805  } // end loop over measurements compatible with original TSOS
806 
807  if (found)
808  layerCount++;
809 }
810 
811 //
812 // Update the dictionary of variables to use as input features for DNN
813 //
814 void TSGForOIDNN::updateFeatureMap(std::unordered_map<std::string, float>& the_map,
815  const reco::Track& l2,
816  const TrajectoryStateOnSurface& tsos_IP,
817  const TrajectoryStateOnSurface& tsos_MuS) const {
818  the_map["pt"] = l2.pt();
819  the_map["eta"] = l2.eta();
820  the_map["phi"] = l2.phi();
821  the_map["validHits"] = l2.found();
822  if (tsos_IP.isValid()) {
823  the_map["tsos_IP_eta"] = tsos_IP.globalPosition().eta();
824  the_map["tsos_IP_phi"] = tsos_IP.globalPosition().phi();
825  the_map["tsos_IP_pt"] = tsos_IP.globalMomentum().perp();
826  the_map["tsos_IP_pt_eta"] = tsos_IP.globalMomentum().eta();
827  the_map["tsos_IP_pt_phi"] = tsos_IP.globalMomentum().phi();
828  const AlgebraicSymMatrix55& matrix_IP = tsos_IP.curvilinearError().matrix();
829  the_map["err0_IP"] = sqrt(matrix_IP[0][0]);
830  the_map["err1_IP"] = sqrt(matrix_IP[1][1]);
831  the_map["err2_IP"] = sqrt(matrix_IP[2][2]);
832  the_map["err3_IP"] = sqrt(matrix_IP[3][3]);
833  the_map["err4_IP"] = sqrt(matrix_IP[4][4]);
834  the_map["tsos_IP_valid"] = 1.0;
835  } else {
836  the_map["tsos_IP_eta"] = -999;
837  the_map["tsos_IP_phi"] = -999;
838  the_map["tsos_IP_pt"] = -999;
839  the_map["tsos_IP_pt_eta"] = -999;
840  the_map["tsos_IP_pt_phi"] = -999;
841  the_map["err0_IP"] = -999;
842  the_map["err1_IP"] = -999;
843  the_map["err2_IP"] = -999;
844  the_map["err3_IP"] = -999;
845  the_map["err4_IP"] = -999;
846  the_map["tsos_IP_valid"] = 0.0;
847  }
848  if (tsos_MuS.isValid()) {
849  the_map["tsos_MuS_eta"] = tsos_MuS.globalPosition().eta();
850  the_map["tsos_MuS_phi"] = tsos_MuS.globalPosition().phi();
851  the_map["tsos_MuS_pt"] = tsos_MuS.globalMomentum().perp();
852  the_map["tsos_MuS_pt_eta"] = tsos_MuS.globalMomentum().eta();
853  the_map["tsos_MuS_pt_phi"] = tsos_MuS.globalMomentum().phi();
854  const AlgebraicSymMatrix55& matrix_MuS = tsos_MuS.curvilinearError().matrix();
855  the_map["err0_MuS"] = sqrt(matrix_MuS[0][0]);
856  the_map["err1_MuS"] = sqrt(matrix_MuS[1][1]);
857  the_map["err2_MuS"] = sqrt(matrix_MuS[2][2]);
858  the_map["err3_MuS"] = sqrt(matrix_MuS[3][3]);
859  the_map["err4_MuS"] = sqrt(matrix_MuS[4][4]);
860  the_map["tsos_MuS_valid"] = 1.0;
861  } else {
862  the_map["tsos_MuS_eta"] = -999;
863  the_map["tsos_MuS_phi"] = -999;
864  the_map["tsos_MuS_pt"] = -999;
865  the_map["tsos_MuS_pt_eta"] = -999;
866  the_map["tsos_MuS_pt_phi"] = -999;
867  the_map["err0_MuS"] = -999;
868  the_map["err1_MuS"] = -999;
869  the_map["err2_MuS"] = -999;
870  the_map["err3_MuS"] = -999;
871  the_map["err4_MuS"] = -999;
872  the_map["tsos_MuS_valid"] = 0.0;
873  }
874 }
875 
876 //
877 // Obtain seeding strategy parameters by evaluating DNN classifier for a given muon
878 //
879 void TSGForOIDNN::evaluateClassifier(const std::unordered_map<std::string, float>& feature_map,
880  tensorflow::Session* session,
881  const pt::ptree& metadata,
883  bool& dnnSuccess) const {
884  int n_features = metadata.get<int>("n_features", 0);
885 
886  // Prepare tensor for DNN inputs
887  tensorflow::Tensor input(tensorflow::DT_FLOAT, {1, n_features});
889  int i_feature = 0;
890  for (const pt::ptree::value_type& feature : metadata.get_child("feature_names")) {
891  fname = feature.second.data();
892  if (feature_map.find(fname) == feature_map.end()) {
893  // don't evaluate DNN if any input feature is missing
894  dnnSuccess = false;
895  } else {
896  input.matrix<float>()(0, i_feature) = float(feature_map.at(fname));
897  i_feature++;
898  }
899  }
900 
901  // Prepare tensor for DNN outputs
902  std::vector<tensorflow::Tensor> outputs;
903 
904  // Evaluate DNN and put results in output tensor
905  std::string inputLayer = metadata.get<std::string>("input_layer");
906  std::string outputLayer = metadata.get<std::string>("output_layer");
907 
908  tensorflow::run(session, {{inputLayer, input}}, {outputLayer}, &outputs);
909  tensorflow::Tensor out_tensor = outputs[0];
910  tensorflow::TTypes<float, 1>::Matrix dnn_outputs = out_tensor.matrix<float>();
911 
912  // Find output with largest prediction
913  int imax = 0;
914  float out_max = 0;
915  for (long long int i = 0; i < out_tensor.dim_size(1); i++) {
916  float ith_output = dnn_outputs(0, i);
917  if (ith_output > out_max) {
918  imax = i;
919  out_max = ith_output;
920  }
921  }
922 
923  // Decode output
924  const std::string label = "output_labels.label_" + std::to_string(imax);
925  out.nHBd = metadata.get<int>(label + ".nHBd");
926  out.nHLIP = metadata.get<int>(label + ".nHLIP");
927  out.nHLMuS = metadata.get<int>(label + ".nHLMuS");
928  out.sf = metadata.get<int>(label + ".SF");
929 
930  dnnSuccess = true;
931 }
932 
933 //
934 // Obtain seeding strategy parameters by evaluating DNN regressor for a given muon
935 //
936 void TSGForOIDNN::evaluateRegressor(const std::unordered_map<std::string, float>& feature_map,
937  tensorflow::Session* session_HB,
938  const pt::ptree& metadata_HB,
939  tensorflow::Session* session_HLIP,
940  const pt::ptree& metadata_HLIP,
941  tensorflow::Session* session_HLMuS,
942  const pt::ptree& metadata_HLMuS,
944  bool& dnnSuccess) const {
945  int n_features = metadata_HB.get<int>("n_features", 0);
946 
947  // Prepare tensor for DNN inputs
948  tensorflow::Tensor input(tensorflow::DT_FLOAT, {1, n_features});
950  int i_feature = 0;
951  for (const pt::ptree::value_type& feature : metadata_HB.get_child("feature_names")) {
952  fname = feature.second.data();
953  if (feature_map.find(fname) == feature_map.end()) {
954  // don't evaluate DNN if any input feature is missing
955  dnnSuccess = false;
956  } else {
957  input.matrix<float>()(0, i_feature) = float(feature_map.at(fname));
958  i_feature++;
959  }
960  }
961 
962  // Prepare tensor for DNN outputs
963  std::vector<tensorflow::Tensor> outputs_HB;
964  // Evaluate DNN and put results in output tensor
965  std::string inputLayer_HB = metadata_HB.get<std::string>("input_layer");
966  std::string outputLayer_HB = metadata_HB.get<std::string>("output_layer");
967  tensorflow::run(session_HB, {{inputLayer_HB, input}}, {outputLayer_HB}, &outputs_HB);
968  tensorflow::Tensor out_tensor_HB = outputs_HB[0];
969  tensorflow::TTypes<float, 1>::Matrix dnn_outputs_HB = out_tensor_HB.matrix<float>();
970 
971  // Prepare tensor for DNN outputs
972  std::vector<tensorflow::Tensor> outputs_HLIP;
973  // Evaluate DNN and put results in output tensor
974  std::string inputLayer_HLIP = metadata_HLIP.get<std::string>("input_layer");
975  std::string outputLayer_HLIP = metadata_HLIP.get<std::string>("output_layer");
976  tensorflow::run(session_HLIP, {{inputLayer_HLIP, input}}, {outputLayer_HLIP}, &outputs_HLIP);
977  tensorflow::Tensor out_tensor_HLIP = outputs_HLIP[0];
978  tensorflow::TTypes<float, 1>::Matrix dnn_outputs_HLIP = out_tensor_HLIP.matrix<float>();
979 
980  // Prepare tensor for DNN outputs
981  std::vector<tensorflow::Tensor> outputs_HLMuS;
982  // Evaluate DNN and put results in output tensor
983  std::string inputLayer_HLMuS = metadata_HLMuS.get<std::string>("input_layer");
984  std::string outputLayer_HLMuS = metadata_HLMuS.get<std::string>("output_layer");
985  tensorflow::run(session_HLMuS, {{inputLayer_HLMuS, input}}, {outputLayer_HLMuS}, &outputs_HLMuS);
986  tensorflow::Tensor out_tensor_HLMuS = outputs_HLMuS[0];
987  tensorflow::TTypes<float, 1>::Matrix dnn_outputs_HLMuS = out_tensor_HLMuS.matrix<float>();
988 
989  // Decode output
990  out.nHBd = round(dnn_outputs_HB(0, 0));
991  out.nHLIP = round(dnn_outputs_HLIP(0, 0));
992  out.sf = round(dnn_outputs_HLIP(0, 1));
993  out.nHLMuS = round(dnn_outputs_HLMuS(0, 0));
994 
995  // Prevent prediction of negative number of seeds or too many seeds
996  out.nHBd = std::clamp(out.nHBd, 0, 10);
997  out.nHLIP = std::clamp(out.nHLIP, 0, 10);
998  out.nHLMuS = std::clamp(out.nHLMuS, 0, 10);
999 
1000  // Prevent prediction of 0 seeds in total
1001  if (out.nHBd == 0 && out.nHLIP == 0 && out.nHLMuS == 0) {
1002  // default strategy, similar to Run 2
1003  out.nHBd = 1;
1004  out.nHLIP = 5;
1005  }
1006 
1007  // Prevent extreme predictions for scale factors
1008  // (on average SF=2 was found to be optimal)
1009  if (out.sf <= 0)
1010  out.sf = 2;
1011  if (out.sf > 10)
1012  out.sf = 10;
1013 
1014  dnnSuccess = true;
1015 }
1016 
1017 //
1018 // Default values of configuration parameters
1019 //
1022  desc.add<edm::InputTag>("src", edm::InputTag("hltL2Muons", "UpdatedAtVtx"));
1023  desc.add<int>("layersToTry", 2);
1024  desc.add<double>("fixedErrorRescaleFactorForHitless", 2.0);
1025  desc.add<int>("hitsToTry", 1);
1026  desc.add<edm::InputTag>("MeasurementTrackerEvent", edm::InputTag("hltSiStripClusters"));
1027  desc.add<std::string>("estimator", "hltESPChi2MeasurementEstimator100");
1028  desc.add<double>("maxEtaForTOB", 1.8);
1029  desc.add<double>("minEtaForTEC", 0.7);
1030  desc.addUntracked<bool>("debug", false);
1031  desc.add<unsigned int>("maxSeeds", 20);
1032  desc.add<unsigned int>("maxHitlessSeeds", 5);
1033  desc.add<unsigned int>("maxHitSeeds", 1);
1034  desc.add<std::string>("propagatorName", "PropagatorWithMaterialParabolicMf");
1035  desc.add<unsigned int>("maxHitlessSeedsIP", 5);
1036  desc.add<unsigned int>("maxHitlessSeedsMuS", 0);
1037  desc.add<unsigned int>("maxHitDoubletSeeds", 0);
1038  desc.add<bool>("getStrategyFromDNN", false);
1039  desc.add<bool>("useRegressor", false);
1040  desc.add<std::string>("dnnMetadataPath", "");
1041  descriptions.add("tsgForOIDNN", desc);
1042 }
1043 
const unsigned int numOfHitsToTry_
How many hits to try per layer.
Definition: TSGForOIDNN.cc:73
std::string dnnModelPath_HLIP_
Definition: TSGForOIDNN.cc:101
const unsigned int maxSeeds_
Maximum number of seeds for each L2.
Definition: TSGForOIDNN.cc:65
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void evaluateRegressor(const std::unordered_map< std::string, float > &feature_map, tensorflow::Session *session_HB, const pt::ptree &metadata_HB, tensorflow::Session *session_HLIP, const pt::ptree &metadata_HLIP, tensorflow::Session *session_HLMuS, const pt::ptree &metadata_HLMuS, StrategyParameters &out, bool &dnnSuccess) const
Evaluate DNN regressor.
Definition: TSGForOIDNN.cc:936
T perp() const
Definition: PV3DBase.h:69
void updateFeatureMap(std::unordered_map< std::string, float > &the_map, const reco::Track &l2, const TrajectoryStateOnSurface &tsos_IP, const TrajectoryStateOnSurface &tsos_MuS) const
Update dictionary of inputs for DNN.
Definition: TSGForOIDNN.cc:814
std::string dnnModelPath_HLMuS_
Definition: TSGForOIDNN.cc:102
void beginJob() override
Definition: TSGForOIDNN.cc:252
tensorflow::Session * tf_session_HLMuS_
Definition: TSGForOIDNN.cc:108
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const edm::ESGetToken< NavigationSchool, NavigationSchoolRecord > t_navSchool_
Definition: TSGForOIDNN.cc:58
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > t_geometryH_
Definition: TSGForOIDNN.cc:57
const edm::EDGetTokenT< MeasurementTrackerEvent > measurementTrackerTag_
Definition: TSGForOIDNN.cc:61
std::vector< TrajectoryMeasurement > fastMeasurements(const TrajectoryStateOnSurface &stateOnThisDet, const TrajectoryStateOnSurface &tsos2, const Propagator &prop, const MeasurementEstimator &est) const
GraphDef * loadGraphDef(const std::string &pbFile)
Definition: TensorFlow.cc:120
void makeSeedsFromHitDoublets(const GeometricSearchDet &layer, const TrajectoryStateOnSurface &tsos, const Propagator &propagatorAlong, const Chi2MeasurementEstimatorBase &estimator, const MeasurementTrackerEvent &measurementTracker, const NavigationSchool &navSchool, unsigned int &hitDoubletSeedsMade, unsigned int &numSeedsMade, const unsigned int &maxHitDoubletSeeds, unsigned int &layerCount, std::vector< TrajectorySeed > &out) const
Similar to makeSeedsFromHits, but seed is created only if there are compatible hits on two adjacent l...
Definition: TSGForOIDNN.cc:630
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
tensorflow::Session * tf_session_HB_
Definition: TSGForOIDNN.cc:104
const unsigned int maxHitlessSeedsMuS_
Definition: TSGForOIDNN.cc:86
T eta() const
Definition: PV3DBase.h:73
const edm::EDGetTokenT< reco::TrackCollection > src_
Labels for input collections.
Definition: TSGForOIDNN.cc:50
const unsigned int maxHitlessSeedsIP_
Definition: TSGForOIDNN.cc:85
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
std::unique_ptr< tensorflow::GraphDef > graphDef_HLIP_
Definition: TSGForOIDNN.cc:105
const edm::ESGetToken< Chi2MeasurementEstimatorBase, TrackingComponentsRecord > t_estimatorH_
Tokens for ESHandle.
Definition: TSGForOIDNN.cc:52
const double minEtaForTEC_
Minimum eta value to activate searching in the TEC.
Definition: TSGForOIDNN.cc:79
Container for DNN outupts.
Definition: TSGForOIDNN.cc:158
static std::string to_string(const XMLCh *ch)
#define LogTrace(id)
static std::string const input
Definition: EdmProvDump.cc:50
unsigned short found() const
Number of valid hits on track.
Definition: Track.h:142
static PlanePointer build(Args &&... args)
Definition: Plane.h:33
GlobalPoint position() const
double pt() const
track transverse momentum
Definition: TrackBase.h:637
char const * label
std::unique_ptr< Propagator > SetPropagationDirection(Propagator const &iprop, PropagationDirection dir)
void push_back(D *&d)
Definition: OwnVector.h:326
int iEvent
Definition: GenABIO.cc:224
const double fixedErrorRescalingForHitless_
Rescale L2 parameter uncertainties (fixed error vs pT, eta)
Definition: TSGForOIDNN.cc:75
GlobalPoint globalPosition() const
const std::string dnnMetadataPath_
DNN metadata.
Definition: TSGForOIDNN.cc:111
bool isThere(GeomDetEnumerators::SubDetector subdet) const
const std::string theCategory_
Definition: TSGForOIDNN.cc:62
T sqrt(T t)
Definition: SSEVec.h:19
const edm::ESGetToken< Propagator, TrackingComponentsRecord > t_propagatorOppositeH_
Definition: TSGForOIDNN.cc:55
const std::string estimatorName_
Estimator used to find dets and TrajectoryMeasurements.
Definition: TSGForOIDNN.cc:77
size_type size() const
Definition: OwnVector.h:300
const unsigned int maxHitSeeds_
Maximum number of hitbased seeds for each L2.
Definition: TSGForOIDNN.cc:67
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Definition: TensorFlow.cc:259
bool closeSession(Session *&session)
Definition: TensorFlow.cc:234
const unsigned int maxHitDoubletSeeds_
Definition: TSGForOIDNN.cc:87
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::string dnnModelPath_
Settings for classifier.
Definition: TSGForOIDNN.cc:95
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:649
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TSGForOIDNN(const edm::ParameterSet &iConfig)
Definition: TSGForOIDNN.cc:181
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
void initializeTensorflow() const
Definition: TSGForOIDNN.cc:287
const bool useRegressor_
Whether to use DNN regressor (if false, will use classifier)
Definition: TSGForOIDNN.cc:92
Session * createSession()
Definition: TensorFlow.cc:137
void makeSeedsWithoutHits(const GeometricSearchDet &layer, const TrajectoryStateOnSurface &tsos, const Propagator &propagatorAlong, const Chi2MeasurementEstimatorBase &estimator, double errorSF, unsigned int &hitlessSeedsMade, unsigned int &numSeedsMade, std::vector< TrajectorySeed > &out) const
Create seeds without hits on a given layer (TOB or TEC)
Definition: TSGForOIDNN.cc:524
Log< level::Info, false > LogInfo
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
void setLogging(const std::string &level="3")
Definition: TensorFlow.cc:81
const CurvilinearTrajectoryError & curvilinearError() const
const edm::ESGetToken< Propagator, TrackingComponentsRecord > t_SHPOpposite_
Definition: TSGForOIDNN.cc:59
const double maxEtaForTOB_
Maximum eta value to activate searching in the TOB.
Definition: TSGForOIDNN.cc:81
const AlgebraicSymMatrix55 & matrix() const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
std::string dnnModelPath_HB_
Settings for regressor.
Definition: TSGForOIDNN.cc:100
void add(std::string const &label, ParameterSetDescription const &psetDescription)
GlobalVector globalMomentum() const
std::unique_ptr< tensorflow::GraphDef > graphDef_
Definition: TSGForOIDNN.cc:96
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > t_magfieldH_
Definition: TSGForOIDNN.cc:53
string fname
main script
std::unique_ptr< tensorflow::GraphDef > graphDef_HB_
Definition: TSGForOIDNN.cc:103
tensorflow::Session * tf_session_
Definition: TSGForOIDNN.cc:97
HLT enums.
FreeTrajectoryState const * freeState(bool withErrors=true) const
const edm::ESGetToken< Propagator, TrackingComponentsRecord > t_propagatorAlongH_
Definition: TSGForOIDNN.cc:54
const unsigned int numOfLayersToTry_
How many layers to try.
Definition: TSGForOIDNN.cc:71
const bool getStrategyFromDNN_
Get number of seeds to use from DNN output instead of "max..Seeds" parameters.
Definition: TSGForOIDNN.cc:90
std::unique_ptr< tensorflow::GraphDef > graphDef_HLMuS_
Definition: TSGForOIDNN.cc:107
pt::ptree metadata_
Definition: TSGForOIDNN.cc:112
const std::unique_ptr< TrajectoryStateUpdator > updator_
Definition: TSGForOIDNN.cc:60
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > t_tmpTkGeometryH_
Definition: TSGForOIDNN.cc:56
portabletest::Matrix Matrix
FreeTrajectoryState initialFreeState(const reco::Track &tk, const MagneticField *field, bool withErr=true)
~TSGForOIDNN() override
Definition: TSGForOIDNN.cc:240
Create L3MuonTrajectorySeeds from L2 Muons in an outside-in manner.
Definition: TSGForOIDNN.cc:40
void evaluateClassifier(const std::unordered_map< std::string, float > &feature_map, tensorflow::Session *session, const pt::ptree &metadata, StrategyParameters &out, bool &dnnSuccess) const
Evaluate DNN classifier.
Definition: TSGForOIDNN.cc:879
void produce(edm::StreamID sid, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
Definition: TSGForOIDNN.cc:299
def move(src, dest)
Definition: eostools.py:511
void makeSeedsFromHits(const GeometricSearchDet &layer, const TrajectoryStateOnSurface &tsos, const Propagator &propagatorAlong, const Chi2MeasurementEstimatorBase &estimator, const MeasurementTrackerEvent &measurementTracker, unsigned int &hitSeedsMade, unsigned int &numSeedsMade, const unsigned int &maxHitSeeds, unsigned int &layerCount, std::vector< TrajectorySeed > &out) const
Find hits on a given layer (TOB or TEC) and create seeds from updated TSOS with hit.
Definition: TSGForOIDNN.cc:558
const unsigned int maxHitlessSeeds_
Maximum number of hitless seeds for each L2.
Definition: TSGForOIDNN.cc:69
TrajectoryStateOnSurface innerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)
tensorflow::Session * tf_session_HLIP_
Definition: TSGForOIDNN.cc:106