CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes
GE0SegAlgoRU Class Reference

#include <GE0SegAlgoRU.h>

Inheritance diagram for GE0SegAlgoRU:
GEMSegmentAlgorithmBase

Classes

struct  HitAndPosition
 
struct  SegmentParameters
 

Public Types

typedef std::vector< bool > BoolContainer
 
typedef std::vector< HitAndPositionHitAndPositionContainer
 
typedef std::vector< const HitAndPosition * > HitAndPositionPtrContainer
 
typedef std::vector< std::pair< float, HitAndPositionPtrContainer > > SegmentByMetricContainer
 
- Public Types inherited from GEMSegmentAlgorithmBase
typedef std::pair< const GEMSuperChamber *, std::map< uint32_t, const GEMEtaPartition * > > GEMEnsemble
 

Public Member Functions

 GE0SegAlgoRU (const edm::ParameterSet &ps)
 Constructor. More...
 
std::vector< GEMSegmentrun (const GEMSuperChamber *chamber, const HitAndPositionContainer &rechits)
 
std::vector< GEMSegmentrun (const GEMEnsemble &ensemble, const std::vector< const GEMRecHit *> &rechits) override
 
 ~GE0SegAlgoRU () override
 Destructor. More...
 
- Public Member Functions inherited from GEMSegmentAlgorithmBase
 GEMSegmentAlgorithmBase (const edm::ParameterSet &)
 Constructor. More...
 
virtual ~GEMSegmentAlgorithmBase ()
 Destructor. More...
 

Private Member Functions

std::unique_ptr< MuonSegFitaddHit (HitAndPositionPtrContainer &proto_segment, const HitAndPosition &aHit) const
 
void addUniqueSegments (SegmentByMetricContainer &proto_segments, std::vector< GEMSegment > &segments, BoolContainer &used) const
 
bool areHitsCloseInEta (const float maxETA, const bool beamConst, const GlobalPoint &h1, const GlobalPoint &h2) const
 
bool areHitsCloseInGlobalPhi (const float maxPHI, const unsigned int nLayDisp, const GlobalPoint &h1, const GlobalPoint &h2) const
 
void compareProtoSegment (std::unique_ptr< MuonSegFit > &current_fit, HitAndPositionPtrContainer &current_proto_segment, const HitAndPosition &new_hit) const
 
float getHitSegChi2 (const std::unique_ptr< MuonSegFit > &fit, const GEMRecHit &hit) const
 
GlobalPoint globalAtZ (const std::unique_ptr< MuonSegFit > &fit, float z) const
 
bool hasHitOnLayer (const HitAndPositionPtrContainer &proto_segment, const unsigned int layer) const
 
void increaseProtoSegment (const float maxChi2, std::unique_ptr< MuonSegFit > &current_fit, HitAndPositionPtrContainer &current_proto_segment, const HitAndPosition &new_hit) const
 
bool isHitNearSegment (const float maxETA, const float maxPHI, const std::unique_ptr< MuonSegFit > &fit, const HitAndPositionPtrContainer &proto_segment, const HitAndPosition &h) const
 
void lookForSegments (const SegmentParameters &params, const unsigned int n_seg_min, const HitAndPositionContainer &rechits, const std::vector< unsigned int > &recHits_per_layer, BoolContainer &used, std::vector< GEMSegment > &segments) const
 
std::unique_ptr< MuonSegFitmakeFit (const HitAndPositionPtrContainer &proto_segment) const
 
void pruneBadHits (const float maxChi2, HitAndPositionPtrContainer &proto_segment, std::unique_ptr< MuonSegFit > &fit, const unsigned int n_seg_min) const
 
void tryAddingHitsToSegment (const float maxETA, const float maxPhi, const float maxChi2, std::unique_ptr< MuonSegFit > &current_fit, HitAndPositionPtrContainer &proto_segment, const BoolContainer &used, HitAndPositionContainer::const_iterator i1, HitAndPositionContainer::const_iterator i2) const
 

Private Attributes

bool allowWideSegments
 
SegmentParameters displacedParameters
 
bool doCollisions
 
const std::string myName
 
SegmentParameters stdParameters
 
const GEMSuperChambertheChamber
 
SegmentParameters wideParameters
 

Detailed Description

adapted from CSC to ME0 bt Marcello Maggi and ME0 to GE0 by Ian J. Watson

This is the original algorithm for building endcap muon track segments out of the rechit's in a GE0Chamber 'RU' = 'RUssia' = Road Usage

A GEMSegment is a RecSegment4D, and is built from GEMRecHit2D objects, each of which is a RecHit2DLocalPos.

This class is used by the GEMSegmentAlgorithm.
Alternative algorithms can be used for the segment building by writing classes like this, and then selecting which one is actually used via the GEMSegmentBuilder.

developed and implemented by Vladimir Palichik Vladi.nosp@m.mir..nosp@m.Paltc.nosp@m.hik@.nosp@m.cern..nosp@m.ch and Nikolay Voytishin nikol.nosp@m.ay.v.nosp@m.oytis.nosp@m.hin@.nosp@m.cern..nosp@m.ch

Definition at line 32 of file GE0SegAlgoRU.h.

Member Typedef Documentation

◆ BoolContainer

typedef std::vector<bool> GE0SegAlgoRU::BoolContainer

Definition at line 62 of file GE0SegAlgoRU.h.

◆ HitAndPositionContainer

Definition at line 58 of file GE0SegAlgoRU.h.

◆ HitAndPositionPtrContainer

Definition at line 59 of file GE0SegAlgoRU.h.

◆ SegmentByMetricContainer

typedef std::vector<std::pair<float, HitAndPositionPtrContainer> > GE0SegAlgoRU::SegmentByMetricContainer

Definition at line 63 of file GE0SegAlgoRU.h.

Constructor & Destructor Documentation

◆ GE0SegAlgoRU()

GE0SegAlgoRU::GE0SegAlgoRU ( const edm::ParameterSet ps)
explicit

Constructor.

Definition at line 26 of file GE0SegAlgoRU.cc.

References allowWideSegments, displacedParameters, doCollisions, edm::ParameterSet::getParameter(), LogDebug, GE0SegAlgoRU::SegmentParameters::maxChi2Additional, GE0SegAlgoRU::SegmentParameters::maxChi2GoodSeg, GE0SegAlgoRU::SegmentParameters::maxChi2Prune, GE0SegAlgoRU::SegmentParameters::maxETASeeds, GE0SegAlgoRU::SegmentParameters::maxNumberOfHits, GE0SegAlgoRU::SegmentParameters::maxNumberOfHitsPerLayer, GE0SegAlgoRU::SegmentParameters::maxPhiAdditional, GE0SegAlgoRU::SegmentParameters::maxPhiSeeds, GE0SegAlgoRU::SegmentParameters::minNumberOfHits, myName, GE0SegAlgoRU::SegmentParameters::requireBeamConstr, GE0SegAlgoRU::SegmentParameters::requireCentralBX, stdParameters, theChamber, and wideParameters.

26  : GEMSegmentAlgorithmBase(ps), myName("GE0SegAlgoRU") {
27  allowWideSegments = ps.getParameter<bool>("allowWideSegments");
28  doCollisions = ps.getParameter<bool>("doCollisions");
29 
30  stdParameters.maxChi2Additional = ps.getParameter<double>("maxChi2Additional");
31  stdParameters.maxChi2Prune = ps.getParameter<double>("maxChi2Prune");
32  stdParameters.maxChi2GoodSeg = ps.getParameter<double>("maxChi2GoodSeg");
33  stdParameters.maxPhiSeeds = ps.getParameter<double>("maxPhiSeeds");
34  stdParameters.maxPhiAdditional = ps.getParameter<double>("maxPhiAdditional");
35  stdParameters.maxETASeeds = ps.getParameter<double>("maxETASeeds");
36  stdParameters.requireCentralBX = ps.getParameter<bool>("requireCentralBX");
37  stdParameters.minNumberOfHits = ps.getParameter<unsigned int>("minNumberOfHits");
38  stdParameters.maxNumberOfHits = ps.getParameter<unsigned int>("maxNumberOfHits");
39  stdParameters.maxNumberOfHitsPerLayer = ps.getParameter<unsigned int>("maxNumberOfHitsPerLayer");
41 
48 
57 
58  LogDebug("GE0SegAlgoRU") << myName << " has algorithm cuts set to: \n"
59  << "--------------------------------------------------------------------\n"
60  << "allowWideSegments = " << allowWideSegments << "\n"
61  << "doCollisions = " << doCollisions << "\n"
62  << "maxChi2Additional = " << stdParameters.maxChi2Additional << "\n"
63  << "maxChi2Prune = " << stdParameters.maxChi2Prune << "\n"
64  << "maxChi2GoodSeg = " << stdParameters.maxChi2GoodSeg << "\n"
65  << "maxPhiSeeds = " << stdParameters.maxPhiSeeds << "\n"
66  << "maxPhiAdditional = " << stdParameters.maxPhiAdditional << "\n"
67  << "maxETASeeds = " << stdParameters.maxETASeeds << "\n"
68  << std::endl;
69 
70  theChamber = nullptr;
71 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
SegmentParameters wideParameters
Definition: GE0SegAlgoRU.h:147
bool allowWideSegments
Definition: GE0SegAlgoRU.h:143
const std::string myName
Definition: GE0SegAlgoRU.h:141
const GEMSuperChamber * theChamber
Definition: GE0SegAlgoRU.h:150
GEMSegmentAlgorithmBase(const edm::ParameterSet &)
Constructor.
SegmentParameters displacedParameters
Definition: GE0SegAlgoRU.h:146
SegmentParameters stdParameters
Definition: GE0SegAlgoRU.h:145
#define LogDebug(id)

◆ ~GE0SegAlgoRU()

GE0SegAlgoRU::~GE0SegAlgoRU ( )
inlineoverride

Destructor.

Definition at line 68 of file GE0SegAlgoRU.h.

68 {};

Member Function Documentation

◆ addHit()

std::unique_ptr< MuonSegFit > GE0SegAlgoRU::addHit ( HitAndPositionPtrContainer proto_segment,
const HitAndPosition aHit 
) const
private

Definition at line 429 of file GE0SegAlgoRU.cc.

References makeFit().

Referenced by compareProtoSegment(), increaseProtoSegment(), and lookForSegments().

430  {
431  proto_segment.push_back(&aHit);
432  // make a fit
433  return makeFit(proto_segment);
434 }
std::unique_ptr< MuonSegFit > makeFit(const HitAndPositionPtrContainer &proto_segment) const

◆ addUniqueSegments()

void GE0SegAlgoRU::addUniqueSegments ( SegmentByMetricContainer proto_segments,
std::vector< GEMSegment > &  segments,
BoolContainer used 
) const
private

Definition at line 286 of file GE0SegAlgoRU.cc.

References a, b, GEMSuperChamber::computeDeltaPhi(), HLT_2022v12_cff::dPhi, h, createfilelist::int, makeFit(), jetUpdater_cfi::sort, groupFilesInBlocks::temp, and theChamber.

Referenced by lookForSegments().

288  {
289  std::sort(proto_segments.begin(),
290  proto_segments.end(),
291  [](const std::pair<float, HitAndPositionPtrContainer>& a,
292  const std::pair<float, HitAndPositionPtrContainer>& b) { return a.first < b.first; });
293 
294  //Now add to the collect based on minChi2 marking the hits as used after
295  std::vector<unsigned int> usedHits;
296  for (auto& container : proto_segments) {
297  HitAndPositionPtrContainer currentProtoSegment = container.second;
298 
299  //check to see if we already used thes hits this round
300  bool alreadyFilled = false;
301  for (const auto& h : currentProtoSegment) {
302  for (unsigned int iOH = 0; iOH < usedHits.size(); ++iOH) {
303  if (usedHits[iOH] != h->idx)
304  continue;
305  alreadyFilled = true;
306  break;
307  }
308  }
309  if (alreadyFilled)
310  continue;
311  for (const auto* h : currentProtoSegment) {
312  usedHits.push_back(h->idx);
313  used[h->idx] = true;
314  }
315 
316  std::unique_ptr<MuonSegFit> current_fit = makeFit(currentProtoSegment);
317 
318  // Create an actual GEMSegment - retrieve all info from the fit
319  // calculate the timing fron rec hits associated to the TrackingRecHits used
320  // to fit the segment
321  float averageBX = 0.;
322  for (const auto* h : currentProtoSegment) {
323  averageBX += h->rh->BunchX();
324  }
325  averageBX /= int(currentProtoSegment.size());
326 
327  std::sort(currentProtoSegment.begin(),
328  currentProtoSegment.end(),
329  [](const HitAndPosition* a, const HitAndPosition* b) { return a->layer < b->layer; });
330 
331  std::vector<const GEMRecHit*> bareRHs;
332  bareRHs.reserve(currentProtoSegment.size());
333  for (const auto* rh : currentProtoSegment)
334  bareRHs.push_back(rh->rh);
335  const float dPhi = theChamber->computeDeltaPhi(current_fit->intercept(), current_fit->localdir());
336  GEMSegment temp(bareRHs,
337  current_fit->intercept(),
338  current_fit->localdir(),
339  current_fit->covarianceMatrix(),
340  current_fit->chi2(),
341  averageBX,
342  dPhi);
343  segments.push_back(temp);
344  }
345 }
std::vector< const HitAndPosition * > HitAndPositionPtrContainer
Definition: GE0SegAlgoRU.h:59
const GEMSuperChamber * theChamber
Definition: GE0SegAlgoRU.h:150
std::unique_ptr< MuonSegFit > makeFit(const HitAndPositionPtrContainer &proto_segment) const
double b
Definition: hdecay.h:118
float computeDeltaPhi(const LocalPoint &position, const LocalVector &direction) const
double a
Definition: hdecay.h:119
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ areHitsCloseInEta()

bool GE0SegAlgoRU::areHitsCloseInEta ( const float  maxETA,
const bool  beamConst,
const GlobalPoint h1,
const GlobalPoint h2 
) const
private

Definition at line 383 of file GE0SegAlgoRU.cc.

References funct::abs(), change_name::diff, PV3DBase< T, PVType, FrameType >::eta(), f, LogDebug, SiStripPI::max, and HLT_2022v12_cff::maxETA.

Referenced by lookForSegments().

386  {
387  float diff = std::abs(h1.eta() - h2.eta());
388  LogDebug("GE0SegAlgoRU") << "[GE0SegAlgoRU::areHitsCloseInEta] gp1 = " << h1 << " in eta part = " << h1.eta()
389  << " and gp2 = " << h2 << " in eta part = " << h2.eta() << " ==> dEta = " << diff
390  << " ==> return " << (diff < 0.1) << std::endl;
391  //temp for floating point comparision...maxEta is the difference between partitions, so x1.5 to take into account non-circle geom.
392  return (diff < std::max(maxETA, 0.01f));
393 }
T eta() const
Definition: PV3DBase.h:73
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
#define LogDebug(id)

◆ areHitsCloseInGlobalPhi()

bool GE0SegAlgoRU::areHitsCloseInGlobalPhi ( const float  maxPHI,
const unsigned int  nLayDisp,
const GlobalPoint h1,
const GlobalPoint h2 
) const
private

Definition at line 395 of file GE0SegAlgoRU.cc.

References funct::abs(), PV3DBase< T, PVType, FrameType >::barePhi(), SiPixelRawToDigiRegional_cfi::deltaPhi, f, LogDebug, and SiStripPI::max.

Referenced by lookForSegments().

398  {
399  float dphi12 = deltaPhi(h1.barePhi(), h2.barePhi());
400  LogDebug("GE0SegAlgoRU") << "[GE0SegAlgoRU::areHitsCloseInGlobalPhi] gp1 = " << h1 << " and gp2 = " << h2
401  << " ==> dPhi = " << dphi12 << " ==> return " << (std::abs(dphi12) < std::max(maxPHI, 0.02f))
402  << std::endl;
403  return std::abs(dphi12) < std::max(maxPHI, float(float(nLayDisp) * 0.004));
404 }
T barePhi() const
Definition: PV3DBase.h:65
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
#define LogDebug(id)

◆ compareProtoSegment()

void GE0SegAlgoRU::compareProtoSegment ( std::unique_ptr< MuonSegFit > &  current_fit,
HitAndPositionPtrContainer current_proto_segment,
const HitAndPosition new_hit 
) const
private

Definition at line 496 of file GE0SegAlgoRU.cc.

References funct::abs(), addHit(), GEMRecHit::BunchX(), dqmMemoryStats::float, h, GE0SegAlgoRU::HitAndPosition::layer, GE0SegAlgoRU::HitAndPosition::lp, eostools::move(), and GE0SegAlgoRU::HitAndPosition::rh.

Referenced by tryAddingHitsToSegment().

498  {
499  const HitAndPosition* old_hit = nullptr;
500  HitAndPositionPtrContainer new_proto_segment = current_proto_segment;
501 
502  for (auto it = new_proto_segment.begin(); it != new_proto_segment.end();) {
503  if ((*it)->layer == new_hit.layer) {
504  old_hit = *it;
505  it = new_proto_segment.erase(it);
506  } else {
507  ++it;
508  }
509  }
510  if (old_hit == nullptr)
511  return;
512  auto new_fit = addHit(new_proto_segment, new_hit);
513 
514  //If on the same strip but different BX choose the closest
515  bool useNew = false;
516  if (old_hit->lp == new_hit.lp) {
517  float avgbx = 0;
518  for (const auto* h : current_proto_segment)
519  if (old_hit != h)
520  avgbx += h->rh->BunchX();
521  avgbx /= float(current_proto_segment.size() - 1);
522  if (std::abs(avgbx - new_hit.rh->BunchX()) < std::abs(avgbx - old_hit->rh->BunchX()))
523  useNew = true;
524  } //otherwise base it on chi2
525  else if (new_fit->chi2() < current_fit->chi2())
526  useNew = true;
527 
528  if (useNew) {
529  current_proto_segment = new_proto_segment;
530  current_fit = std::move(new_fit);
531  }
532 }
std::vector< const HitAndPosition * > HitAndPositionPtrContainer
Definition: GE0SegAlgoRU.h:59
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::unique_ptr< MuonSegFit > addHit(HitAndPositionPtrContainer &proto_segment, const HitAndPosition &aHit) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
def move(src, dest)
Definition: eostools.py:511

◆ getHitSegChi2()

float GE0SegAlgoRU::getHitSegChi2 ( const std::unique_ptr< MuonSegFit > &  fit,
const GEMRecHit hit 
) const
private

Definition at line 473 of file GE0SegAlgoRU.cc.

Referenced by pruneBadHits().

473  {
474  const auto lp = hit.localPosition();
475  const auto le = hit.localPositionError();
476  const float du = fit->xdev(lp.x(), lp.z());
477  const float dv = fit->ydev(lp.y(), lp.z());
478 
479  ROOT::Math::SMatrix<double, 2, 2, ROOT::Math::MatRepSym<double, 2> > IC;
480  IC(0, 0) = le.xx();
481  IC(1, 0) = le.xy();
482  IC(1, 1) = le.yy();
483 
484  // Invert covariance matrix
485  IC.Invert();
486  return du * du * IC(0, 0) + 2. * du * dv * IC(0, 1) + dv * dv * IC(1, 1);
487 }

◆ globalAtZ()

GlobalPoint GE0SegAlgoRU::globalAtZ ( const std::unique_ptr< MuonSegFit > &  fit,
float  z 
) const
private

Definition at line 423 of file GE0SegAlgoRU.cc.

References theChamber, GeomDet::toGlobal(), x, y, and z.

Referenced by isHitNearSegment().

423  {
424  float x = fit->xfit(z);
425  float y = fit->yfit(z);
426  return theChamber->toGlobal(LocalPoint(x, y, z));
427 }
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
const GEMSuperChamber * theChamber
Definition: GE0SegAlgoRU.h:150
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49

◆ hasHitOnLayer()

bool GE0SegAlgoRU::hasHitOnLayer ( const HitAndPositionPtrContainer proto_segment,
const unsigned int  layer 
) const
private

Definition at line 489 of file GE0SegAlgoRU.cc.

References h, and phase1PixelTopology::layer.

Referenced by tryAddingHitsToSegment().

489  {
490  for (const auto* h : proto_segment)
491  if (h->layer == layer)
492  return true;
493  return false;
494 }
constexpr std::array< uint8_t, layerIndexSize > layer
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ increaseProtoSegment()

void GE0SegAlgoRU::increaseProtoSegment ( const float  maxChi2,
std::unique_ptr< MuonSegFit > &  current_fit,
HitAndPositionPtrContainer current_proto_segment,
const HitAndPosition new_hit 
) const
private

Definition at line 534 of file GE0SegAlgoRU.cc.

References addHit(), beam_dqm_sourceclient-live_cfg::maxChi2, and eostools::move().

Referenced by tryAddingHitsToSegment().

537  {
538  HitAndPositionPtrContainer new_proto_segment = current_proto_segment;
539  auto new_fit = addHit(new_proto_segment, new_hit);
540  if (new_fit->chi2() / new_fit->ndof() < maxChi2) {
541  current_proto_segment = new_proto_segment;
542  current_fit = std::move(new_fit);
543  }
544 }
std::vector< const HitAndPosition * > HitAndPositionPtrContainer
Definition: GE0SegAlgoRU.h:59
std::unique_ptr< MuonSegFit > addHit(HitAndPositionPtrContainer &proto_segment, const HitAndPosition &aHit) const
def move(src, dest)
Definition: eostools.py:511

◆ isHitNearSegment()

bool GE0SegAlgoRU::isHitNearSegment ( const float  maxETA,
const float  maxPHI,
const std::unique_ptr< MuonSegFit > &  fit,
const HitAndPositionPtrContainer proto_segment,
const HitAndPosition h 
) const
private

Definition at line 406 of file GE0SegAlgoRU.cc.

References funct::abs(), SiPixelRawToDigiRegional_cfi::deltaPhi, HLT_2022v12_cff::dPhi, f, globalAtZ(), h, SiStripPI::max, HLT_2022v12_cff::maxETA, and PV3DBase< T, PVType, FrameType >::phi().

Referenced by tryAddingHitsToSegment().

410  {
411  //Get average eta, based on the two seeds...asssumes that we have not started pruning yet!
412  const float avgETA = (proto_segment[1]->gp.eta() + proto_segment[0]->gp.eta()) / 2.;
413  if (std::abs(h.gp.eta() - avgETA) > std::max(maxETA, 0.01f))
414  return false;
415 
416  //Now check the dPhi based on the segment fit
417  GlobalPoint globIntercept = globalAtZ(fit, h.lp.z());
418  float dPhi = deltaPhi(h.gp.barePhi(), globIntercept.phi());
419  //check to see if it is inbetween the two rolls of the outer and inner hits
420  return (std::abs(dPhi) < std::max(maxPHI, 0.001f));
421 }
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
GlobalPoint globalAtZ(const std::unique_ptr< MuonSegFit > &fit, float z) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ lookForSegments()

void GE0SegAlgoRU::lookForSegments ( const SegmentParameters params,
const unsigned int  n_seg_min,
const HitAndPositionContainer rechits,
const std::vector< unsigned int > &  recHits_per_layer,
BoolContainer used,
std::vector< GEMSegment > &  segments 
) const
private

Definition at line 200 of file GE0SegAlgoRU.cc.

References funct::abs(), addHit(), addUniqueSegments(), areHitsCloseInEta(), areHitsCloseInGlobalPhi(), testProducerWithPsetDescEmpty_cfi::i1, testProducerWithPsetDescEmpty_cfi::i2, cuy::ib, LogDebug, submitPVValidationJobs::params, pruneBadHits(), HI_PhotonSkim_cff::rechits, and tryAddingHitsToSegment().

Referenced by run().

205  {
206  auto ib = rechits.begin();
207  auto ie = rechits.end();
208  std::vector<std::pair<float, HitAndPositionPtrContainer> > proto_segments;
209  // the first hit is taken from the back
210  for (auto i1 = ib; i1 != ie; ++i1) {
211  const auto& h1 = *i1;
212 
213  //skip if rh is used and the layer tat has big rh multiplicity(>25RHs)
214  if (used[h1.idx])
215  continue;
216  if (recHits_per_layer[h1.layer - 1] > params.maxNumberOfHitsPerLayer)
217  continue;
218 
219  // the second hit from the front
220  for (auto i2 = ie - 1; i2 != i1; --i2) {
221  const auto& h2 = *i2;
222 
223  //skip if rh is used and the layer tat has big rh multiplicity(>25RHs)
224  if (used[h2.idx])
225  continue;
226  if (recHits_per_layer[h2.layer - 1] > params.maxNumberOfHitsPerLayer)
227  continue;
228 
229  //Stop if the distance between layers is not large enough
230  if ((std::abs(int(h2.layer) - int(h1.layer)) + 1) < int(n_seg_min))
231  break;
232 
233  if (!areHitsCloseInEta(params.maxETASeeds, params.requireBeamConstr, h1.gp, h2.gp))
234  continue;
235  if (!areHitsCloseInGlobalPhi(params.maxPhiSeeds, std::abs(int(h2.layer) - int(h1.layer)), h1.gp, h2.gp))
236  continue;
237 
238  HitAndPositionPtrContainer current_proto_segment;
239  std::unique_ptr<MuonSegFit> current_fit;
240  current_fit = addHit(current_proto_segment, h1);
241  current_fit = addHit(current_proto_segment, h2);
242 
243  tryAddingHitsToSegment(params.maxETASeeds,
244  params.maxPhiAdditional,
245  params.maxChi2Additional,
246  current_fit,
247  current_proto_segment,
248  used,
249  i1,
250  i2);
251 
252  if (current_proto_segment.size() > n_seg_min)
253  pruneBadHits(params.maxChi2Prune, current_proto_segment, current_fit, n_seg_min);
254 
255  LogDebug("GE0SegAlgoRU") << "[GE0SegAlgoRU::lookForSegments] # of hits in segment "
256  << current_proto_segment.size() << " min # " << n_seg_min << " => "
257  << (current_proto_segment.size() >= n_seg_min) << " chi2/ndof "
258  << current_fit->chi2() / current_fit->ndof() << " => "
259  << (current_fit->chi2() / current_fit->ndof() < params.maxChi2GoodSeg) << std::endl;
260 
261  if (current_proto_segment.size() < n_seg_min)
262  continue;
263  const float current_metric = current_fit->chi2() / current_fit->ndof();
264  if (current_metric > params.maxChi2GoodSeg)
265  continue;
266 
267  if (params.requireCentralBX) {
268  int nCentral = 0;
269  int nNonCentral = 0;
270  for (const auto* rh : current_proto_segment) {
271  if (std::abs(rh->rh->BunchX()) < 2)
272  nCentral++;
273  else
274  nNonCentral++;
275  }
276  if (nNonCentral >= nCentral)
277  continue;
278  }
279 
280  proto_segments.emplace_back(current_metric, current_proto_segment);
281  }
282  }
283  addUniqueSegments(proto_segments, segments, used);
284 }
std::vector< const HitAndPosition * > HitAndPositionPtrContainer
Definition: GE0SegAlgoRU.h:59
bool areHitsCloseInEta(const float maxETA, const bool beamConst, const GlobalPoint &h1, const GlobalPoint &h2) const
void pruneBadHits(const float maxChi2, HitAndPositionPtrContainer &proto_segment, std::unique_ptr< MuonSegFit > &fit, const unsigned int n_seg_min) const
void tryAddingHitsToSegment(const float maxETA, const float maxPhi, const float maxChi2, std::unique_ptr< MuonSegFit > &current_fit, HitAndPositionPtrContainer &proto_segment, const BoolContainer &used, HitAndPositionContainer::const_iterator i1, HitAndPositionContainer::const_iterator i2) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void addUniqueSegments(SegmentByMetricContainer &proto_segments, std::vector< GEMSegment > &segments, BoolContainer &used) const
bool areHitsCloseInGlobalPhi(const float maxPHI, const unsigned int nLayDisp, const GlobalPoint &h1, const GlobalPoint &h2) const
std::unique_ptr< MuonSegFit > addHit(HitAndPositionPtrContainer &proto_segment, const HitAndPosition &aHit) const
ib
Definition: cuy.py:661
#define LogDebug(id)

◆ makeFit()

std::unique_ptr< MuonSegFit > GE0SegAlgoRU::makeFit ( const HitAndPositionPtrContainer proto_segment) const
private

Definition at line 436 of file GE0SegAlgoRU.cc.

References GEMRecHit::clone(), and GEMRecHit::setPosition().

Referenced by addHit(), addUniqueSegments(), and pruneBadHits().

436  {
437  // for GE0 we take the gemrechit from the proto_segment we transform into Tracking Rechits
438  // the local rest frame is the GEMSuperChamber
440  for (const auto& rh : proto_segment) {
441  GEMRecHit* newRH = rh->rh->clone();
442  newRH->setPosition(rh->lp);
443  MuonSegFit::MuonRecHitPtr trkRecHit(newRH);
444  muonRecHits.push_back(trkRecHit);
445  }
446  auto currentFit = std::make_unique<MuonSegFit>(muonRecHits);
447  currentFit->fit();
448  return currentFit;
449 }
std::shared_ptr< TrackingRecHit > MuonRecHitPtr
Definition: MuonSegFit.h:38
GEMRecHit * clone() const override
Definition: GEMRecHit.cc:58
std::vector< MuonRecHitPtr > MuonRecHitContainer
Definition: MuonSegFit.h:39
void setPosition(LocalPoint pos)
Set local position.
Definition: GEMRecHit.h:53

◆ pruneBadHits()

void GE0SegAlgoRU::pruneBadHits ( const float  maxChi2,
HitAndPositionPtrContainer proto_segment,
std::unique_ptr< MuonSegFit > &  fit,
const unsigned int  n_seg_min 
) const
private

Definition at line 451 of file GE0SegAlgoRU.cc.

References getHitSegChi2(), LogDebug, makeFit(), and beam_dqm_sourceclient-live_cfg::maxChi2.

Referenced by lookForSegments().

454  {
455  while (proto_segment.size() > n_seg_min && fit->chi2() / fit->ndof() > maxChi2) {
456  float maxDev = -1;
457  HitAndPositionPtrContainer::iterator worstHit;
458  for (auto it = proto_segment.begin(); it != proto_segment.end(); ++it) {
459  const float dev = getHitSegChi2(fit, *(*it)->rh);
460  if (dev < maxDev)
461  continue;
462  maxDev = dev;
463  worstHit = it;
464  }
465  LogDebug("GE0SegAlgoRU") << "[GE0SegAlgoRU::pruneBadHits] pruning one hit-> layer: " << (*worstHit)->layer
466  << " eta: " << (*worstHit)->gp.eta() << " phi: " << (*worstHit)->gp.phi()
467  << " old chi2/dof: " << fit->chi2() / fit->ndof() << std::endl;
468  proto_segment.erase(worstHit);
469  fit = makeFit(proto_segment);
470  }
471 }
float getHitSegChi2(const std::unique_ptr< MuonSegFit > &fit, const GEMRecHit &hit) const
std::unique_ptr< MuonSegFit > makeFit(const HitAndPositionPtrContainer &proto_segment) const
#define LogDebug(id)

◆ run() [1/2]

std::vector< GEMSegment > GE0SegAlgoRU::run ( const GEMSuperChamber chamber,
const HitAndPositionContainer rechits 
)

Here we must implement the algorithm

Definition at line 98 of file GE0SegAlgoRU.cc.

References allowWideSegments, relativeConstraints::chamber, displacedParameters, doCollisions, h, lookForSegments(), GE0SegAlgoRU::SegmentParameters::maxNumberOfHits, GE0SegAlgoRU::SegmentParameters::minNumberOfHits, GEMSuperChamber::nChambers(), HI_PhotonSkim_cff::rechits, stdParameters, and theChamber.

Referenced by run().

98  {
99 #ifdef EDM_ML_DEBUG // have lines below only compiled when in debug mode
100  GEMDetId chId(chamber->id());
101  edm::LogVerbatim("GE0SegAlgoRU") << "[GEMSegmentAlgorithm::run] build segments in chamber " << chId
102  << " which contains " << rechits.size() << " rechits";
103  for (const auto& h : rechits) {
104  auto ge0id = h.rh->gemId();
105  auto rhLP = h.lp;
106  edm::LogVerbatim("GE0SegAlgoRU") << "[RecHit :: Loc x = " << std::showpos << std::setw(9) << rhLP.x()
107  << " Glb y = " << std::showpos << std::setw(9) << rhLP.y()
108  << " Time = " << std::showpos << h.rh->BunchX() << " -- " << ge0id.rawId() << " = "
109  << ge0id << " ]" << std::endl;
110  }
111 #endif
112 
114  return std::vector<GEMSegment>();
115  }
116 
118 
119  std::vector<unsigned int> recHits_per_layer(theChamber->nChambers(), 0);
120  for (const auto& rechit : rechits) {
121  recHits_per_layer[rechit.layer - 1]++;
122  }
123 
124  BoolContainer used(rechits.size(), false);
125 
126  // We have at least 2 hits. We intend to try all possible pairs of hits to start
127  // segment building. 'All possible' means each hit lies on different layers in the chamber.
128  // after all same size segs are build we get rid of the overcrossed segments using the chi2 criteria
129  // the hits from the segs that are left are marked as used and are not added to segs in future iterations
130  // the hits from 3p segs are marked as used separately in order to try to assamble them in longer segments
131  // in case there is a second pass
132 
133  // Choose first hit (as close to IP as possible) h1 and second hit
134  // (as far from IP as possible) h2 To do this we iterate over hits
135  // in the chamber by layer - pick two layers. Then we
136  // iterate over hits within each of these layers and pick h1 and h2
137  // these. If they are 'close enough' we build an empty
138  // segment. Then try adding hits to this segment.
139 
140  std::vector<GEMSegment> segments;
141 
142  auto doStd = [&]() {
143  for (unsigned int n_seg_min = 6u; n_seg_min >= stdParameters.minNumberOfHits; --n_seg_min)
144  lookForSegments(stdParameters, n_seg_min, rechits, recHits_per_layer, used, segments);
145  };
146  auto doDisplaced = [&]() {
147  for (unsigned int n_seg_min = 6u; n_seg_min >= displacedParameters.minNumberOfHits; --n_seg_min)
148  lookForSegments(displacedParameters, n_seg_min, rechits, recHits_per_layer, used, segments);
149  };
150  // Not currently used
151  // auto doWide = [&] () {
152  // for(unsigned int n_seg_min = 6u; n_seg_min >= wideParameters.minNumberOfHits; --n_seg_min)
153  // lookForSegments(wideParameters,n_seg_min,rechits,recHits_per_layer, used,segments);
154  // };
155  auto printSegments = [&] {
156 #ifdef EDM_ML_DEBUG // have lines below only compiled when in debug mode
157  for (const auto& seg : segments) {
158  GEMDetId chId(seg.gemDetId());
159  const auto& rechits = seg.specificRecHits();
160  edm::LogVerbatim("GE0SegAlgoRU") << "[GE0SegAlgoRU] segment in chamber " << chId << " which contains "
161  << rechits.size() << " rechits and with specs: \n"
162  << seg;
163  for (const auto& rh : rechits) {
164  auto ge0id = rh.gemId();
165  edm::LogVerbatim("GE0SegAlgoRU") << "[RecHit :: Loc x = " << std::showpos << std::setw(9)
166  << rh.localPosition().x() << " Loc y = " << std::showpos << std::setw(9)
167  << rh.localPosition().y() << " Time = " << std::showpos << rh.BunchX()
168  << " -- " << ge0id.rawId() << " = " << ge0id << " ]";
169  }
170  }
171 #endif
172  };
173 
174  //If we arent doing collisions, do a single iteration
175  if (!doCollisions) {
176  doDisplaced();
177  printSegments();
178  return segments;
179  }
180 
181  //Iteration 1: STD processing
182  doStd();
183 
184  if (false) {
185  //How the CSC algorithm ~does iterations. for now not considering
186  //displaced muons will not worry about it later
187  //Iteration 2a: If we don't allow wide segments simply do displaced
188  // Or if we already found a segment simply skip to displaced
189  if (!allowWideSegments || !segments.empty()) {
190  doDisplaced();
191  return segments;
192  }
193  //doWide();
194  doDisplaced();
195  }
196  printSegments();
197  return segments;
198 }
Log< level::Info, true > LogVerbatim
std::vector< bool > BoolContainer
Definition: GE0SegAlgoRU.h:62
bool allowWideSegments
Definition: GE0SegAlgoRU.h:143
const GEMSuperChamber * theChamber
Definition: GE0SegAlgoRU.h:150
int nChambers() const
Return numbers of chambers.
void lookForSegments(const SegmentParameters &params, const unsigned int n_seg_min, const HitAndPositionContainer &rechits, const std::vector< unsigned int > &recHits_per_layer, BoolContainer &used, std::vector< GEMSegment > &segments) const
SegmentParameters displacedParameters
Definition: GE0SegAlgoRU.h:146
SegmentParameters stdParameters
Definition: GE0SegAlgoRU.h:145
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ run() [2/2]

std::vector< GEMSegment > GE0SegAlgoRU::run ( const GEMEnsemble ensemble,
const std::vector< const GEMRecHit *> &  rechits 
)
overridevirtual

Run the algorithm = build the segments in this chamber

Implements GEMSegmentAlgorithmBase.

Definition at line 73 of file GE0SegAlgoRU.cc.

References glb, GE0SegAlgoRU::HitAndPosition::layer, LogDebug, position, HI_PhotonSkim_cff::rechits, run(), and jetUpdater_cfi::sort.

73  {
74  HitAndPositionContainer hitAndPositions;
75  auto& superchamber = ensemble.first;
76  for (const auto& rechit : rechits) {
77  const GEMEtaPartition* part = ensemble.second.at(rechit->gemId().rawId());
78  GlobalPoint glb = part->toGlobal(rechit->localPosition());
79  LocalPoint nLoc = superchamber->toLocal(glb);
80  hitAndPositions.emplace_back(&(*rechit), nLoc, glb, hitAndPositions.size());
81  }
82 
83  LogDebug("GE0Segment|GE0") << "found " << hitAndPositions.size() << " rechits in superchamber " << superchamber->id();
84  //sort by layer
85  float z1 = superchamber->chamber(1)->position().z();
86  float zlast = superchamber->chamber(superchamber->nChambers())->position().z();
87  if (z1 < zlast)
88  std::sort(hitAndPositions.begin(), hitAndPositions.end(), [](const HitAndPosition& h1, const HitAndPosition& h2) {
89  return h1.layer < h2.layer;
90  });
91  else
92  std::sort(hitAndPositions.begin(), hitAndPositions.end(), [](const HitAndPosition& h1, const HitAndPosition& h2) {
93  return h1.layer > h2.layer;
94  });
95  return run(ensemble.first, hitAndPositions);
96 }
double glb
Definition: hdecay.h:103
std::vector< GEMSegment > run(const GEMSuperChamber *chamber, const HitAndPositionContainer &rechits)
Definition: GE0SegAlgoRU.cc:98
part
Definition: HCALResponse.h:20
std::vector< HitAndPosition > HitAndPositionContainer
Definition: GE0SegAlgoRU.h:58
static int position[264][3]
Definition: ReadPGInfo.cc:289
#define LogDebug(id)

◆ tryAddingHitsToSegment()

void GE0SegAlgoRU::tryAddingHitsToSegment ( const float  maxETA,
const float  maxPhi,
const float  maxChi2,
std::unique_ptr< MuonSegFit > &  current_fit,
HitAndPositionPtrContainer proto_segment,
const BoolContainer used,
HitAndPositionContainer::const_iterator  i1,
HitAndPositionContainer::const_iterator  i2 
) const
private

Definition at line 347 of file GE0SegAlgoRU.cc.

References compareProtoSegment(), hasHitOnLayer(), testProducerWithPsetDescEmpty_cfi::i1, testProducerWithPsetDescEmpty_cfi::i2, increaseProtoSegment(), isHitNearSegment(), beam_dqm_sourceclient-live_cfg::maxChi2, HLT_2022v12_cff::maxETA, and HLT_2022v12_cff::maxPhi.

Referenced by lookForSegments().

354  {
355  // Iterate over the layers with hits in the chamber
356  // Skip the layers containing the segment endpoints
357  // Test each hit on the other layers to see if it is near the segment
358  // If it is, see whether there is already a hit on the segment from the same layer
359  // - if so, and there are more than 2 hits on the segment, copy the segment,
360  // replace the old hit with the new hit. If the new segment chi2 is better
361  // then replace the original segment with the new one (by swap)
362  // - if not, copy the segment, add the hit. If the new chi2/dof is still satisfactory
363  // then replace the original segment with the new one (by swap)
364 
365  //Hits are ordered by layer, "i1" is the inner hit and i2 is the outer hit
366  //so possible hits to add must be between these two iterators
367  for (auto iH = i1 + 1; iH != i2; ++iH) {
368  if (iH->layer == i1->layer)
369  continue;
370  if (iH->layer == i2->layer)
371  break;
372  if (used[iH->idx])
373  continue;
374  if (!isHitNearSegment(maxETA, maxPhi, current_fit, proto_segment, *iH))
375  continue;
376  if (hasHitOnLayer(proto_segment, iH->layer))
377  compareProtoSegment(current_fit, proto_segment, *iH);
378  else
379  increaseProtoSegment(maxChi2, current_fit, proto_segment, *iH);
380  }
381 }
bool isHitNearSegment(const float maxETA, const float maxPHI, const std::unique_ptr< MuonSegFit > &fit, const HitAndPositionPtrContainer &proto_segment, const HitAndPosition &h) const
void compareProtoSegment(std::unique_ptr< MuonSegFit > &current_fit, HitAndPositionPtrContainer &current_proto_segment, const HitAndPosition &new_hit) const
bool hasHitOnLayer(const HitAndPositionPtrContainer &proto_segment, const unsigned int layer) const
void increaseProtoSegment(const float maxChi2, std::unique_ptr< MuonSegFit > &current_fit, HitAndPositionPtrContainer &current_proto_segment, const HitAndPosition &new_hit) const

Member Data Documentation

◆ allowWideSegments

bool GE0SegAlgoRU::allowWideSegments
private

Definition at line 143 of file GE0SegAlgoRU.h.

Referenced by GE0SegAlgoRU(), and run().

◆ displacedParameters

SegmentParameters GE0SegAlgoRU::displacedParameters
private

Definition at line 146 of file GE0SegAlgoRU.h.

Referenced by GE0SegAlgoRU(), and run().

◆ doCollisions

bool GE0SegAlgoRU::doCollisions
private

Definition at line 142 of file GE0SegAlgoRU.h.

Referenced by GE0SegAlgoRU(), and run().

◆ myName

const std::string GE0SegAlgoRU::myName
private

Definition at line 141 of file GE0SegAlgoRU.h.

Referenced by GE0SegAlgoRU().

◆ stdParameters

SegmentParameters GE0SegAlgoRU::stdParameters
private

Definition at line 145 of file GE0SegAlgoRU.h.

Referenced by GE0SegAlgoRU(), and run().

◆ theChamber

const GEMSuperChamber* GE0SegAlgoRU::theChamber
private

Definition at line 150 of file GE0SegAlgoRU.h.

Referenced by addUniqueSegments(), GE0SegAlgoRU(), globalAtZ(), and run().

◆ wideParameters

SegmentParameters GE0SegAlgoRU::wideParameters
private

Definition at line 147 of file GE0SegAlgoRU.h.

Referenced by GE0SegAlgoRU().