CMS 3D CMS Logo

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