CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
< HitAndPosition
HitAndPositionContainer
 
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

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

Definition at line 62 of file GE0SegAlgoRU.h.

Definition at line 58 of file GE0SegAlgoRU.h.

Definition at line 59 of file GE0SegAlgoRU.h.

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

Definition at line 63 of file GE0SegAlgoRU.h.

Constructor & Destructor Documentation

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 }
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
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
SegmentParameters stdParameters
Definition: GE0SegAlgoRU.h:145
#define LogDebug(id)
GE0SegAlgoRU::~GE0SegAlgoRU ( )
inlineoverride

Destructor.

Definition at line 68 of file GE0SegAlgoRU.h.

68 {};

Member Function Documentation

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

Definition at line 430 of file GE0SegAlgoRU.cc.

References makeFit().

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

431  {
432  proto_segment.push_back(&aHit);
433  // make a fit
434  return makeFit(proto_segment);
435 }
std::unique_ptr< MuonSegFit > makeFit(const HitAndPositionPtrContainer &proto_segment) const
void GE0SegAlgoRU::addUniqueSegments ( SegmentByMetricContainer proto_segments,
std::vector< GEMSegment > &  segments,
BoolContainer used 
) const
private

Definition at line 287 of file GE0SegAlgoRU.cc.

References a, b, GEMSuperChamber::computeDeltaPhi(), h, GE0SegAlgoRU::HitAndPosition::layer, makeFit(), groupFilesInBlocks::temp, and theChamber.

Referenced by lookForSegments().

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

Definition at line 384 of file GE0SegAlgoRU.cc.

References funct::abs(), change_name::diff, PV3DBase< T, PVType, FrameType >::eta(), validate-o2o-wbm::f, and SiStripPI::max.

Referenced by lookForSegments().

387  {
388  float diff = std::abs(h1.eta() - h2.eta());
389  edm::LogVerbatim("GE0SegAlgoRU") << "[GE0SegAlgoRU::areHitsCloseInEta] gp1 = " << h1 << " in eta part = " << h1.eta()
390  << " and gp2 = " << h2 << " in eta part = " << h2.eta() << " ==> dEta = " << diff
391  << " ==> return " << (diff < 0.1) << std::endl;
392  //temp for floating point comparision...maxEta is the difference between partitions, so x1.5 to take into account non-circle geom.
393  return (diff < std::max(maxETA, 0.01f));
394 }
Log< level::Info, true > LogVerbatim
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T eta() const
Definition: PV3DBase.h:73
bool GE0SegAlgoRU::areHitsCloseInGlobalPhi ( const float  maxPHI,
const unsigned int  nLayDisp,
const GlobalPoint h1,
const GlobalPoint h2 
) const
private

Definition at line 396 of file GE0SegAlgoRU.cc.

References funct::abs(), PV3DBase< T, PVType, FrameType >::barePhi(), srCondWrite_cfg::deltaPhi, validate-o2o-wbm::f, and SiStripPI::max.

Referenced by lookForSegments().

399  {
400  float dphi12 = deltaPhi(h1.barePhi(), h2.barePhi());
401  edm::LogVerbatim("GE0SegAlgoRU") << "[GE0SegAlgoRU::areHitsCloseInGlobalPhi] gp1 = " << h1 << " and gp2 = " << h2
402  << " ==> dPhi = " << dphi12 << " ==> return "
403  << (std::abs(dphi12) < std::max(maxPHI, 0.02f)) << std::endl;
404  return std::abs(dphi12) < std::max(maxPHI, float(float(nLayDisp) * 0.004));
405 }
Log< level::Info, true > LogVerbatim
T barePhi() const
Definition: PV3DBase.h:65
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void GE0SegAlgoRU::compareProtoSegment ( std::unique_ptr< MuonSegFit > &  current_fit,
HitAndPositionPtrContainer current_proto_segment,
const HitAndPosition new_hit 
) const
private

Definition at line 497 of file GE0SegAlgoRU.cc.

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

Referenced by tryAddingHitsToSegment().

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

Definition at line 474 of file GE0SegAlgoRU.cc.

References GEMRecHit::localPosition(), GEMRecHit::localPositionError(), and LocalError::xx().

Referenced by pruneBadHits().

474  {
475  const auto lp = hit.localPosition();
476  const auto le = hit.localPositionError();
477  const float du = fit->xdev(lp.x(), lp.z());
478  const float dv = fit->ydev(lp.y(), lp.z());
479 
480  ROOT::Math::SMatrix<double, 2, 2, ROOT::Math::MatRepSym<double, 2> > IC;
481  IC(0, 0) = le.xx();
482  IC(1, 0) = le.xy();
483  IC(1, 1) = le.yy();
484 
485  // Invert covariance matrix
486  IC.Invert();
487  return du * du * IC(0, 0) + 2. * du * dv * IC(0, 1) + dv * dv * IC(1, 1);
488 }
LocalPoint localPosition() const override
Return the 3-dimensional local position.
Definition: GEMRecHit.h:37
auto const & fit
LocalError localPositionError() const override
Return the 3-dimensional error on the local position.
Definition: GEMRecHit.h:40
GlobalPoint GE0SegAlgoRU::globalAtZ ( const std::unique_ptr< MuonSegFit > &  fit,
float  z 
) const
private

Definition at line 424 of file GE0SegAlgoRU.cc.

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

Referenced by isHitNearSegment().

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

Definition at line 490 of file GE0SegAlgoRU.cc.

References h.

Referenced by tryAddingHitsToSegment().

490  {
491  for (const auto* h : proto_segment)
492  if (h->layer == layer)
493  return true;
494  return false;
495 }
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
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 535 of file GE0SegAlgoRU.cc.

References addHit(), HLT_FULL_cff::maxChi2, and eostools::move().

Referenced by tryAddingHitsToSegment().

538  {
539  HitAndPositionPtrContainer new_proto_segment = current_proto_segment;
540  auto new_fit = addHit(new_proto_segment, new_hit);
541  if (new_fit->chi2() / new_fit->ndof() < maxChi2) {
542  current_proto_segment = new_proto_segment;
543  current_fit = std::move(new_fit);
544  }
545 }
std::unique_ptr< MuonSegFit > addHit(HitAndPositionPtrContainer &proto_segment, const HitAndPosition &aHit) const
std::vector< const HitAndPosition * > HitAndPositionPtrContainer
Definition: GE0SegAlgoRU.h:59
def move
Definition: eostools.py:511
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 407 of file GE0SegAlgoRU.cc.

References funct::abs(), PV3DBase< T, PVType, FrameType >::barePhi(), srCondWrite_cfg::deltaPhi, PV3DBase< T, PVType, FrameType >::eta(), validate-o2o-wbm::f, globalAtZ(), GE0SegAlgoRU::HitAndPosition::gp, GE0SegAlgoRU::HitAndPosition::lp, SiStripPI::max, PV3DBase< T, PVType, FrameType >::phi(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by tryAddingHitsToSegment().

411  {
412  //Get average eta, based on the two seeds...asssumes that we have not started pruning yet!
413  const float avgETA = (proto_segment[1]->gp.eta() + proto_segment[0]->gp.eta()) / 2.;
414  if (std::abs(h.gp.eta() - avgETA) > std::max(maxETA, 0.01f))
415  return false;
416 
417  //Now check the dPhi based on the segment fit
418  GlobalPoint globIntercept = globalAtZ(fit, h.lp.z());
419  float dPhi = deltaPhi(h.gp.barePhi(), globIntercept.phi());
420  //check to see if it is inbetween the two rolls of the outer and inner hits
421  return (std::abs(dPhi) < std::max(maxPHI, 0.001f));
422 }
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
auto const & fit
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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
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(), cuy::ib, GE0SegAlgoRU::SegmentParameters::maxChi2Additional, GE0SegAlgoRU::SegmentParameters::maxChi2GoodSeg, GE0SegAlgoRU::SegmentParameters::maxChi2Prune, GE0SegAlgoRU::SegmentParameters::maxETASeeds, GE0SegAlgoRU::SegmentParameters::maxNumberOfHitsPerLayer, GE0SegAlgoRU::SegmentParameters::maxPhiAdditional, GE0SegAlgoRU::SegmentParameters::maxPhiSeeds, pruneBadHits(), GE0SegAlgoRU::SegmentParameters::requireBeamConstr, GE0SegAlgoRU::SegmentParameters::requireCentralBX, 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  edm::LogVerbatim("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)
260  << std::endl;
261 
262  if (current_proto_segment.size() < n_seg_min)
263  continue;
264  const float current_metric = current_fit->chi2() / current_fit->ndof();
265  if (current_metric > params.maxChi2GoodSeg)
266  continue;
267 
268  if (params.requireCentralBX) {
269  int nCentral = 0;
270  int nNonCentral = 0;
271  for (const auto* rh : current_proto_segment) {
272  if (std::abs(rh->rh->BunchX()) < 2)
273  nCentral++;
274  else
275  nNonCentral++;
276  }
277  if (nNonCentral >= nCentral)
278  continue;
279  }
280 
281  proto_segments.emplace_back(current_metric, current_proto_segment);
282  }
283  }
284  addUniqueSegments(proto_segments, segments, used);
285 }
std::unique_ptr< MuonSegFit > addHit(HitAndPositionPtrContainer &proto_segment, const HitAndPosition &aHit) const
Log< level::Info, true > LogVerbatim
int ib
Definition: cuy.py:661
bool areHitsCloseInEta(const float maxETA, const bool beamConst, const GlobalPoint &h1, const GlobalPoint &h2) const
std::vector< const HitAndPosition * > HitAndPositionPtrContainer
Definition: GE0SegAlgoRU.h:59
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
void pruneBadHits(const float maxChi2, HitAndPositionPtrContainer &proto_segment, std::unique_ptr< MuonSegFit > &fit, const unsigned int n_seg_min) 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 > GE0SegAlgoRU::makeFit ( const HitAndPositionPtrContainer proto_segment) const
private

Definition at line 437 of file GE0SegAlgoRU.cc.

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

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

437  {
438  // for GE0 we take the gemrechit from the proto_segment we transform into Tracking Rechits
439  // the local rest frame is the GEMSuperChamber
441  for (const auto& rh : proto_segment) {
442  GEMRecHit* newRH = rh->rh->clone();
443  newRH->setPosition(rh->lp);
444  MuonSegFit::MuonRecHitPtr trkRecHit(newRH);
445  muonRecHits.push_back(trkRecHit);
446  }
447  auto currentFit = std::make_unique<MuonSegFit>(muonRecHits);
448  currentFit->fit();
449  return currentFit;
450 }
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
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 452 of file GE0SegAlgoRU.cc.

References getHitSegChi2(), makeFit(), and HLT_FULL_cff::maxChi2.

Referenced by lookForSegments().

455  {
456  while (proto_segment.size() > n_seg_min && fit->chi2() / fit->ndof() > maxChi2) {
457  float maxDev = -1;
458  HitAndPositionPtrContainer::iterator worstHit;
459  for (auto it = proto_segment.begin(); it != proto_segment.end(); ++it) {
460  const float dev = getHitSegChi2(fit, *(*it)->rh);
461  if (dev < maxDev)
462  continue;
463  maxDev = dev;
464  worstHit = it;
465  }
466  edm::LogVerbatim("GE0SegAlgoRU") << "[GE0SegAlgoRU::pruneBadHits] pruning one hit-> layer: " << (*worstHit)->layer
467  << " eta: " << (*worstHit)->gp.eta() << " phi: " << (*worstHit)->gp.phi()
468  << " old chi2/dof: " << fit->chi2() / fit->ndof() << std::endl;
469  proto_segment.erase(worstHit);
470  fit = makeFit(proto_segment);
471  }
472 }
Log< level::Info, true > LogVerbatim
float getHitSegChi2(const std::unique_ptr< MuonSegFit > &fit, const GEMRecHit &hit) const
auto const & fit
std::unique_ptr< MuonSegFit > makeFit(const HitAndPositionPtrContainer &proto_segment) const
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, displacedParameters, doCollisions, h, GEMSuperChamber::id(), lookForSegments(), GE0SegAlgoRU::SegmentParameters::maxNumberOfHits, GE0SegAlgoRU::SegmentParameters::minNumberOfHits, GEMSuperChamber::nChambers(), 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 
113  if (rechits.size() < stdParameters.minNumberOfHits || rechits.size() > stdParameters.maxNumberOfHits) {
114  return std::vector<GEMSegment>();
115  }
116 
117  theChamber = chamber;
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
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
int nChambers() const
Return numbers of chambers.
GEMDetId id() const
Return the GEMDetId of this super chamber.
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
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, run(), and GeomDet::toGlobal().

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 }
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
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)
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 348 of file GE0SegAlgoRU.cc.

References compareProtoSegment(), hasHitOnLayer(), increaseProtoSegment(), and isHitNearSegment().

Referenced by lookForSegments().

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

Member Data Documentation

bool GE0SegAlgoRU::allowWideSegments
private

Definition at line 143 of file GE0SegAlgoRU.h.

Referenced by GE0SegAlgoRU(), and run().

SegmentParameters GE0SegAlgoRU::displacedParameters
private

Definition at line 146 of file GE0SegAlgoRU.h.

Referenced by GE0SegAlgoRU(), and run().

bool GE0SegAlgoRU::doCollisions
private

Definition at line 142 of file GE0SegAlgoRU.h.

Referenced by GE0SegAlgoRU(), and run().

const std::string GE0SegAlgoRU::myName
private

Definition at line 141 of file GE0SegAlgoRU.h.

Referenced by GE0SegAlgoRU().

SegmentParameters GE0SegAlgoRU::stdParameters
private

Definition at line 145 of file GE0SegAlgoRU.h.

Referenced by GE0SegAlgoRU(), and run().

const GEMSuperChamber* GE0SegAlgoRU::theChamber
private

Definition at line 150 of file GE0SegAlgoRU.h.

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

SegmentParameters GE0SegAlgoRU::wideParameters
private

Definition at line 147 of file GE0SegAlgoRU.h.

Referenced by GE0SegAlgoRU().