CMS 3D CMS Logo

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

#include <ME0SegAlgoRU.h>

Inheritance diagram for ME0SegAlgoRU:
ME0SegmentAlgorithmBase

Classes

struct  SegmentParameters
 

Public Types

typedef std::vector< bool > BoolContainer
 
typedef std::vector< std::pair< float, HitAndPositionPtrContainer > > SegmentByMetricContainer
 
- Public Types inherited from ME0SegmentAlgorithmBase
typedef std::vector< HitAndPositionHitAndPositionContainer
 
typedef std::vector< const HitAndPosition * > HitAndPositionPtrContainer
 

Public Member Functions

 ME0SegAlgoRU (const edm::ParameterSet &ps)
 Constructor. More...
 
std::vector< ME0Segmentrun (const ME0Chamber *chamber, const HitAndPositionContainer &rechits)
 
virtual ~ME0SegAlgoRU ()
 Destructor. More...
 
- Public Member Functions inherited from ME0SegmentAlgorithmBase
 ME0SegmentAlgorithmBase (const edm::ParameterSet &)
 Constructor. More...
 
virtual ~ME0SegmentAlgorithmBase ()
 Destructor. More...
 

Private Member Functions

std::unique_ptr< MuonSegFitaddHit (HitAndPositionPtrContainer &proto_segment, const HitAndPosition &aHit) const
 
void addUniqueSegments (SegmentByMetricContainer &proto_segments, std::vector< ME0Segment > &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
 
bool areHitsConsistentInTime (const float maxTOF, 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
 
float getHitSegChi2 (const std::unique_ptr< MuonSegFit > &fit, const ME0RecHit &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< ME0Segment > &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 maxTOF, 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 ME0ChambertheChamber
 
SegmentParameters wideParameters
 

Detailed Description

adapted from CSC to ME0 bt Marcello Maggi

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

A ME0Segment is a RecSegment4D, and is built from ME0RecHit2D objects, each of which is a RecHit2DLocalPos.

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

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 ME0SegAlgoRU.h.

Member Typedef Documentation

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

Definition at line 50 of file ME0SegAlgoRU.h.

Definition at line 51 of file ME0SegAlgoRU.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 27 of file ME0SegAlgoRU.cc.

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

28 : ME0SegmentAlgorithmBase(ps), myName("ME0SegAlgoRU") {
29 
30  allowWideSegments = ps.getParameter<bool>("allowWideSegments");
31  doCollisions = ps.getParameter<bool>("doCollisions");
32 
33  stdParameters.maxChi2Additional = ps.getParameter<double>("maxChi2Additional");
34  stdParameters.maxChi2Prune = ps.getParameter<double>("maxChi2Prune" );
35  stdParameters.maxChi2GoodSeg = ps.getParameter<double>("maxChi2GoodSeg" ) ;
36  stdParameters.maxPhiSeeds = ps.getParameter<double>("maxPhiSeeds" ) ;
37  stdParameters.maxPhiAdditional = ps.getParameter<double>("maxPhiAdditional" );
38  stdParameters.maxETASeeds = ps.getParameter<double>("maxETASeeds" );
39  stdParameters.maxTOFDiff = ps.getParameter<double>("maxTOFDiff" );
40  stdParameters.requireCentralBX = ps.getParameter<bool>("requireCentralBX" );
41  stdParameters.minNumberOfHits = ps.getParameter<unsigned int>("minNumberOfHits" );
43 
50 
51 
60 
61 
62  LogDebug("ME0SegAlgoRU") << myName << " has algorithm cuts set to: \n"
63  << "--------------------------------------------------------------------\n"
64  << "allowWideSegments = " <<allowWideSegments << "\n"
65  << "doCollisions = " <<doCollisions << "\n"
66  << "maxChi2Additional = " <<stdParameters.maxChi2Additional<< "\n"
67  << "maxChi2Prune = " <<stdParameters.maxChi2Prune << "\n"
68  << "maxChi2GoodSeg = " <<stdParameters.maxChi2GoodSeg << "\n"
69  << "maxPhiSeeds = " <<stdParameters.maxPhiSeeds << "\n"
70  << "maxPhiAdditional = " <<stdParameters.maxPhiAdditional << "\n"
71  << "maxETASeeds = " <<stdParameters.maxETASeeds << "\n"
72  << "maxTOFDiff = " <<stdParameters.maxTOFDiff << "\n"
73  << std::endl;
74 
75  theChamber=0;
76 
77 }
#define LogDebug(id)
T getParameter(std::string const &) const
SegmentParameters displacedParameters
Definition: ME0SegAlgoRU.h:106
const std::string myName
Definition: ME0SegAlgoRU.h:101
SegmentParameters stdParameters
Definition: ME0SegAlgoRU.h:105
const ME0Chamber * theChamber
Definition: ME0SegAlgoRU.h:110
bool allowWideSegments
Definition: ME0SegAlgoRU.h:103
SegmentParameters wideParameters
Definition: ME0SegAlgoRU.h:107
ME0SegmentAlgorithmBase(const edm::ParameterSet &)
Constructor.
virtual ME0SegAlgoRU::~ME0SegAlgoRU ( )
inlinevirtual

Member Function Documentation

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

Definition at line 366 of file ME0SegAlgoRU.cc.

References makeFit().

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

366  {
367  proto_segment.push_back(&aHit);
368  // make a fit
369  return makeFit(proto_segment);
370 }
std::unique_ptr< MuonSegFit > makeFit(const HitAndPositionPtrContainer &proto_segment) const
void ME0SegAlgoRU::addUniqueSegments ( SegmentByMetricContainer proto_segments,
std::vector< ME0Segment > &  segments,
BoolContainer used 
) const
private

Definition at line 241 of file ME0SegAlgoRU.cc.

References a, b, ME0Chamber::computeDeltaPhi(), objects.autophobj::float, training_settings::idx, ME0SegmentAlgorithmBase::HitAndPosition::layer, makeFit(), mathSSE::sqrt(), groupFilesInBlocks::temp, and theChamber.

Referenced by lookForSegments(), and ~ME0SegAlgoRU().

241  {
242  std::sort(proto_segments.begin(),proto_segments.end(),
243  [](const std::pair<float,HitAndPositionPtrContainer> & a,
244  const std::pair<float,HitAndPositionPtrContainer> & b) { return a.first < b.first;});
245 
246  //Now add to the collect based on minChi2 marking the hits as used after
247  std::vector<unsigned int> usedHits;
248  for(unsigned int iS = 0; iS < proto_segments.size(); ++iS){
249  HitAndPositionPtrContainer currentProtoSegment = proto_segments[iS].second;
250 
251  //check to see if we already used thes hits this round
252  bool alreadyFilled=false;
253  for(unsigned int iH = 0; iH < currentProtoSegment.size(); ++iH){
254  for(unsigned int iOH = 0; iOH < usedHits.size(); ++iOH){
255  if(usedHits[iOH]!=currentProtoSegment[iH]->idx) continue;
256  alreadyFilled = true;
257  break;
258  }
259  }
260  if(alreadyFilled) continue;
261  for(const auto* h : currentProtoSegment){
262  usedHits.push_back(h->idx);
263  used[h->idx] = true;
264  }
265 
266  std::unique_ptr<MuonSegFit> current_fit = makeFit(currentProtoSegment);
267 
268  // Create an actual ME0Segment - retrieve all info from the fit
269  // calculate the timing fron rec hits associated to the TrackingRecHits used
270  // to fit the segment
271  float averageTime=0.;
272  for(const auto* h : currentProtoSegment){
273  averageTime += h->rh->tof();
274  }
275  averageTime /= float(currentProtoSegment.size());
276  float timeUncrt=0.;
277  for(const auto* h : currentProtoSegment){
278  timeUncrt += (h->rh->tof()-averageTime)*(h->rh->tof()-averageTime);
279  }
280  timeUncrt = std::sqrt(timeUncrt/float(currentProtoSegment.size()-1));
281 
282  std::sort(currentProtoSegment.begin(),currentProtoSegment.end(),
283  [](const HitAndPosition* a, const HitAndPosition *b) {return a->layer < b->layer;}
284  );
285 
286  std::vector<const ME0RecHit*> bareRHs; bareRHs.reserve(currentProtoSegment.size());
287  for(const auto* rh : currentProtoSegment) bareRHs.push_back(rh->rh);
288  const float dPhi = theChamber->computeDeltaPhi(current_fit->intercept(),current_fit->localdir());
289  ME0Segment temp(bareRHs, current_fit->intercept(),
290  current_fit->localdir(), current_fit->covarianceMatrix(), current_fit->chi2(), averageTime, timeUncrt, dPhi);
291  segments.push_back(temp);
292 
293 
294  }
295 }
std::unique_ptr< MuonSegFit > makeFit(const HitAndPositionPtrContainer &proto_segment) const
std::vector< const HitAndPosition * > HitAndPositionPtrContainer
float computeDeltaPhi(const LocalPoint &position, const LocalVector &direction) const
Definition: ME0Chamber.cc:82
T sqrt(T t)
Definition: SSEVec.h:18
double b
Definition: hdecay.h:120
const ME0Chamber * theChamber
Definition: ME0SegAlgoRU.h:110
double a
Definition: hdecay.h:121
bool ME0SegAlgoRU::areHitsCloseInEta ( const float  maxETA,
const bool  beamConst,
const GlobalPoint h1,
const GlobalPoint h2 
) const
private

Definition at line 324 of file ME0SegAlgoRU.cc.

References mps_update::diff, PV3DBase< T, PVType, FrameType >::eta(), and hpstanc_transforms::max.

Referenced by lookForSegments(), and ~ME0SegAlgoRU().

324  {
325  float diff = 0;
326  diff = std::fabs(h1.eta() - h1.eta());
327  edm::LogVerbatim("ME0SegAlgoRU") << "[ME0SegAlgoRU::areHitsCloseInEta] gp1 = "<<h1<<" in eta part = "<<h1.eta() <<" and gp2 = "<<h2<<" in eta part = "<<h2.eta() <<" ==> dEta = "<<diff<<" ==> return "<<(diff < 0.1)<<std::endl;
328  return (diff < std::max(maxETA,float(0.01)) ); //temp for floating point comparision...maxEta is the difference between partitions, so x1.5 to take into account non-circle geom.
329 }
T eta() const
Definition: PV3DBase.h:76
bool ME0SegAlgoRU::areHitsCloseInGlobalPhi ( const float  maxPHI,
const unsigned int  nLayDisp,
const GlobalPoint h1,
const GlobalPoint h2 
) const
private

Definition at line 331 of file ME0SegAlgoRU.cc.

References PV3DBase< T, PVType, FrameType >::barePhi(), MuonCkfTrajectoryBuilder_cfi::deltaPhi, and hpstanc_transforms::max.

Referenced by lookForSegments(), and ~ME0SegAlgoRU().

331  {
332  float dphi12 = deltaPhi(h1.barePhi(),h2.barePhi());
333  edm::LogVerbatim("ME0SegAlgoRU") << "[ME0SegAlgoRU::areHitsCloseInGlobalPhi] gp1 = "<<h1<<" and gp2 = "<<h2<<" ==> dPhi = "<<dphi12<<" ==> return "<<(fabs(dphi12) < std::max(maxPHI,float(0.02)))<<std::endl;
334  return fabs(dphi12) < std::max(maxPHI, float(float(nLayDisp)*0.004));
335 }
T barePhi() const
Definition: PV3DBase.h:68
bool ME0SegAlgoRU::areHitsConsistentInTime ( const float  maxTOF,
const HitAndPositionPtrContainer proto_segment,
const HitAndPosition h 
) const
private

Definition at line 351 of file ME0SegAlgoRU.cc.

References ME0SegmentAlgorithmBase::HitAndPosition::rh, and ME0RecHit::tof().

Referenced by tryAddingHitsToSegment(), and ~ME0SegAlgoRU().

351  {
352  std::vector<float> tofs; tofs.reserve(proto_segment.size() + 1);
353  tofs.push_back(h.rh->tof());
354  for(const auto* ih : proto_segment) tofs.push_back(ih->rh->tof());
355  std::sort(tofs.begin(),tofs.end());
356  if(std::fabs(tofs.front() - tofs.back()) < maxTOF +1.0 ) return true;
357  return false;
358 }
void ME0SegAlgoRU::compareProtoSegment ( std::unique_ptr< MuonSegFit > &  current_fit,
HitAndPositionPtrContainer current_proto_segment,
const HitAndPosition new_hit 
) const
private

Definition at line 424 of file ME0SegAlgoRU.cc.

References funct::abs(), addHit(), objects.autophobj::float, ME0SegmentAlgorithmBase::HitAndPosition::layer, ME0SegmentAlgorithmBase::HitAndPosition::lp, eostools::move(), ME0SegmentAlgorithmBase::HitAndPosition::rh, and ME0RecHit::tof().

Referenced by tryAddingHitsToSegment(), and ~ME0SegAlgoRU().

424  {
425  const HitAndPosition * old_hit = 0;
426  HitAndPositionPtrContainer new_proto_segment = current_proto_segment;
427 
428  HitAndPositionPtrContainer::const_iterator it;
429  for (auto it = new_proto_segment.begin(); it != new_proto_segment.end();) {
430  if ((*it)->layer == new_hit.layer) {
431  old_hit = *it;
432  it = new_proto_segment.erase(it);
433  } else {
434  ++it;
435  }
436  }
437  if(old_hit == 0) return;
438  auto new_fit = addHit(new_proto_segment,new_hit);
439 
440  //If on the same strip but different BX choose the closest
441  bool useNew = false;
442  if(old_hit->lp == new_hit.lp ){
443  float avgtof = 0;
444  for(const auto* h : current_proto_segment)
445  if(old_hit != h) avgtof += h->rh->tof();
446  avgtof /= float(current_proto_segment.size() - 1);
447  if(std::abs(avgtof - new_hit.rh->tof() ) <
448  std::abs(avgtof - old_hit->rh->tof() )
449  ) useNew = true;
450  } //otherwise base it on chi2
451  else if(new_fit->chi2() < current_fit->chi2()) useNew = true;
452 
453  if(useNew){
454  current_proto_segment = new_proto_segment;
455  current_fit = std::move(new_fit);
456  }
457 
458 }
std::vector< const HitAndPosition * > HitAndPositionPtrContainer
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::unique_ptr< MuonSegFit > addHit(HitAndPositionPtrContainer &proto_segment, const HitAndPosition &aHit) const
def move(src, dest)
Definition: eostools.py:510
float ME0SegAlgoRU::getHitSegChi2 ( const std::unique_ptr< MuonSegFit > &  fit,
const ME0RecHit hit 
) const
private

Definition at line 403 of file ME0SegAlgoRU.cc.

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

Referenced by pruneBadHits(), and ~ME0SegAlgoRU().

403  {
404  const auto lp = hit.localPosition();
405  const auto le = hit.localPositionError();
406  const float du = fit->xdev(lp.x(),lp.z());
407  const float dv = fit->ydev(lp.y(),lp.z());
408 
409  ROOT::Math::SMatrix<double,2,2,ROOT::Math::MatRepSym<double,2> > IC;
410  IC(0,0) = le.xx();
411  IC(1,0) = le.xy();
412  IC(1,1) = le.yy();
413 
414  // Invert covariance matrix
415  IC.Invert();
416  return du*du*IC(0,0) + 2.*du*dv*IC(0,1) + dv*dv*IC(1,1);
417 }
virtual LocalError localPositionError() const
Return the 3-dimensional error on the local position.
Definition: ME0RecHit.h:53
virtual LocalPoint localPosition() const
Return the 3-dimensional local position.
Definition: ME0RecHit.h:47
GlobalPoint ME0SegAlgoRU::globalAtZ ( const std::unique_ptr< MuonSegFit > &  fit,
float  z 
) const
private

Definition at line 360 of file ME0SegAlgoRU.cc.

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

Referenced by isHitNearSegment(), and ~ME0SegAlgoRU().

360  {
361  float x = fit->xfit(z);
362  float y = fit->yfit(z);
363  return theChamber->toGlobal(LocalPoint(x,y,z));
364 }
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:32
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
const ME0Chamber * theChamber
Definition: ME0SegAlgoRU.h:110
bool ME0SegAlgoRU::hasHitOnLayer ( const HitAndPositionPtrContainer proto_segment,
const unsigned int  layer 
) const
private

Definition at line 419 of file ME0SegAlgoRU.cc.

Referenced by tryAddingHitsToSegment(), and ~ME0SegAlgoRU().

419  {
420  for(const auto* h : proto_segment) if(h->layer == layer) return true;
421  return false;
422 }
void ME0SegAlgoRU::increaseProtoSegment ( const float  maxChi2,
std::unique_ptr< MuonSegFit > &  current_fit,
HitAndPositionPtrContainer current_proto_segment,
const HitAndPosition new_hit 
) const
private

Definition at line 460 of file ME0SegAlgoRU.cc.

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

Referenced by tryAddingHitsToSegment(), and ~ME0SegAlgoRU().

460  {
461  HitAndPositionPtrContainer new_proto_segment = current_proto_segment;
462  auto new_fit = addHit(new_proto_segment,new_hit);
463  // edm::LogVerbatim("ME0SegAlgoRU") << "[ME0SegAlgoRU::increaseProtoSegment] new chi2 = "<<new_fit->chi2()<<" new chi2/dof = "<<new_fit->chi2()/new_fit->ndof() <<" ==> add: " << (new_fit->chi2()/new_fit->ndof() < maxChi2 ) <<std::endl;
464  if(new_fit->chi2()/new_fit->ndof() < maxChi2 ){
465  current_proto_segment = new_proto_segment;
466  current_fit = std::move(new_fit);
467  }
468 }
std::vector< const HitAndPosition * > HitAndPositionPtrContainer
std::unique_ptr< MuonSegFit > addHit(HitAndPositionPtrContainer &proto_segment, const HitAndPosition &aHit) const
def move(src, dest)
Definition: eostools.py:510
bool ME0SegAlgoRU::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 337 of file ME0SegAlgoRU.cc.

References PV3DBase< T, PVType, FrameType >::barePhi(), MuonCkfTrajectoryBuilder_cfi::deltaPhi, PV3DBase< T, PVType, FrameType >::eta(), globalAtZ(), ME0SegmentAlgorithmBase::HitAndPosition::gp, ME0SegmentAlgorithmBase::HitAndPosition::lp, hpstanc_transforms::max, PV3DBase< T, PVType, FrameType >::phi(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by tryAddingHitsToSegment(), and ~ME0SegAlgoRU().

337  {
338  //Get average eta, based on the two seeds...asssumes that we have not started pruning yet!
339  const float avgETA = (proto_segment[1]->gp.eta() + proto_segment[0]->gp.eta())/2.;
340  // edm::LogVerbatim("ME0SegAlgoRU") << "[ME0SegAlgoRU::isHitNearSegment] average eta = "<<avgETA<<" additionalHit eta = "<<h.gp.eta() <<" ==> dEta = "<<std::fabs(h.gp.eta() - avgETA) <<" ==> return "<<(std::fabs(h.gp.eta() - avgETA) < std::max(maxETA,float(0.01) ))<<std::endl;
341  if(std::fabs(h.gp.eta() - avgETA) > std::max(maxETA,float(0.01) )) return false;
342 
343  //Now check the dPhi based on the segment fit
344  GlobalPoint globIntercept = globalAtZ(fit, h.lp.z());
345  float dPhi = deltaPhi(h.gp.barePhi(),globIntercept.phi());
346  //check to see if it is inbetween the two rolls of the outer and inner hits
347  // edm::LogVerbatim("ME0SegAlgoRU") << "[ME0SegAlgoRU::isHitNearSegment] projected phi = "<<globIntercept.phi()<<" additionalHit phi = "<<h.gp.barePhi() <<" ==> dPhi = "<<dPhi <<" ==> return "<<(std::fabs(dPhi) < std::max(maxPHI,float(0.001)))<<std::endl;
348  return (std::fabs(dPhi) < std::max(maxPHI,float(0.001)));
349 }
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
GlobalPoint globalAtZ(const std::unique_ptr< MuonSegFit > &fit, float z) const
void ME0SegAlgoRU::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< ME0Segment > &  segments 
) const
private

Definition at line 175 of file ME0SegAlgoRU.cc.

References funct::abs(), addHit(), addUniqueSegments(), areHitsCloseInEta(), areHitsCloseInGlobalPhi(), cuy::ib, ME0SegAlgoRU::SegmentParameters::maxChi2Additional, ME0SegAlgoRU::SegmentParameters::maxChi2GoodSeg, ME0SegAlgoRU::SegmentParameters::maxChi2Prune, ME0SegAlgoRU::SegmentParameters::maxETASeeds, ME0SegAlgoRU::SegmentParameters::maxPhiAdditional, ME0SegAlgoRU::SegmentParameters::maxPhiSeeds, ME0SegAlgoRU::SegmentParameters::maxTOFDiff, pruneBadHits(), ME0SegAlgoRU::SegmentParameters::requireBeamConstr, ME0SegAlgoRU::SegmentParameters::requireCentralBX, and tryAddingHitsToSegment().

Referenced by run(), and ~ME0SegAlgoRU().

177  {
178  auto ib = rechits.begin();
179  auto ie = rechits.end();
180  std::vector<std::pair<float,HitAndPositionPtrContainer> > proto_segments;
181  // the first hit is taken from the back
182  for (auto i1 = ib; i1 != ie; ++i1) {
183  const auto& h1 = *i1;
184 
185  //skip if rh is used and the layer tat has big rh multiplicity(>25RHs)
186  if(used[h1.idx]) continue;
187  if(recHits_per_layer[h1.layer-1]>100) continue;
188 
189  // bool segok = false;
190  // the second hit from the front
191  for (auto i2 = ie-1; i2 != i1; --i2) {
192  // if(segok) break; //Currently turned off
193  const auto& h2 = *i2;
194 
195  //skip if rh is used and the layer tat has big rh multiplicity(>25RHs)
196  if(used[h2.idx]) continue;
197  if(recHits_per_layer[h2.layer-1]>100) continue;
198 
199  //Stop if the distance between layers is not large enough
200  if((std::abs(int(h2.layer) - int(h1.layer)) + 1) < int(n_seg_min)) break;
201 
202  if(std::fabs(h1.rh->tof()-h2.rh->tof()) > params.maxTOFDiff + 1.0 )continue;
203  if(!areHitsCloseInEta(params.maxETASeeds, params.requireBeamConstr, h1.gp, h2.gp)) continue;
204  if(!areHitsCloseInGlobalPhi(params.maxPhiSeeds,abs(int(h2.layer) - int(h1.layer)), h1.gp, h2.gp)) continue;
205 
206  HitAndPositionPtrContainer current_proto_segment;
207  std::unique_ptr<MuonSegFit> current_fit;
208  current_fit = addHit(current_proto_segment,h1);
209  current_fit = addHit(current_proto_segment,h2);
210 
211  tryAddingHitsToSegment(params.maxTOFDiff,params.maxETASeeds, params.maxPhiAdditional, params.maxChi2Additional, current_fit,current_proto_segment, used,i1,i2);
212 
213  if(current_proto_segment.size() > n_seg_min)
214  pruneBadHits(params.maxChi2Prune,current_proto_segment,current_fit,n_seg_min);
215 
216  edm::LogVerbatim("ME0SegAlgoRU") << "[ME0SegAlgoRU::lookForSegments] # of hits in segment " << current_proto_segment.size() <<" min # "<< n_seg_min <<" => "<< (current_proto_segment.size() >= n_seg_min) << " chi2/ndof "<<current_fit->chi2()/current_fit->ndof()<<" => "<<(current_fit->chi2()/current_fit->ndof() < params.maxChi2GoodSeg ) <<std::endl;
217 
218  if(current_proto_segment.size() < n_seg_min) continue;
219  const float current_metric = current_fit->chi2()/current_fit->ndof();
220  if(current_metric > params.maxChi2GoodSeg) continue;
221 
222  if(params.requireCentralBX){
223  int nCentral = 0;
224  int nNonCentral =0;
225  for(const auto* rh : current_proto_segment ) {
226  if(std::fabs(rh->rh->tof()) < 2 ) nCentral++;
227  else nNonCentral++;
228  }
229  if(nNonCentral >= nCentral) continue;
230  }
231  // segok = true;
232 
233  proto_segments.emplace_back( current_metric, current_proto_segment);
234  }
235 
236  }
237  addUniqueSegments(proto_segments,segments,used);
238 
239 }
bool areHitsCloseInGlobalPhi(const float maxPHI, const unsigned int nLayDisp, const GlobalPoint &h1, const GlobalPoint &h2) const
std::vector< const HitAndPosition * > HitAndPositionPtrContainer
void tryAddingHitsToSegment(const float maxTOF, 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 addUniqueSegments(SegmentByMetricContainer &proto_segments, std::vector< ME0Segment > &segments, BoolContainer &used) 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
bool areHitsCloseInEta(const float maxETA, const bool beamConst, const GlobalPoint &h1, const GlobalPoint &h2) const
std::unique_ptr< MuonSegFit > addHit(HitAndPositionPtrContainer &proto_segment, const HitAndPosition &aHit) const
ib
Definition: cuy.py:660
std::unique_ptr< MuonSegFit > ME0SegAlgoRU::makeFit ( const HitAndPositionPtrContainer proto_segment) const
private

Definition at line 372 of file ME0SegAlgoRU.cc.

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

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

372  {
373  // for ME0 we take the me0rechit from the proto_segment we transform into Tracking Rechits
374  // the local rest frame is the ME0Chamber
376  for (auto rh=proto_segment.begin();rh<proto_segment.end(); rh++){
377  ME0RecHit *newRH = (*rh)->rh->clone();
378  newRH->setPosition((*rh)->lp);
379  MuonSegFit::MuonRecHitPtr trkRecHit(newRH);
380  muonRecHits.push_back(trkRecHit);
381  }
382  std::unique_ptr<MuonSegFit> currentFit(new MuonSegFit(muonRecHits));
383  currentFit->fit();
384  return currentFit;
385 }
std::shared_ptr< TrackingRecHit > MuonRecHitPtr
Definition: MuonSegFit.h:41
virtual ME0RecHit * clone() const
Definition: ME0RecHit.cc:47
void setPosition(LocalPoint pos)
Set local position.
Definition: ME0RecHit.h:72
std::vector< MuonRecHitPtr > MuonRecHitContainer
Definition: MuonSegFit.h:42
void ME0SegAlgoRU::pruneBadHits ( const float  maxChi2,
HitAndPositionPtrContainer proto_segment,
std::unique_ptr< MuonSegFit > &  fit,
const unsigned int  n_seg_min 
) const
private

Definition at line 387 of file ME0SegAlgoRU.cc.

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

Referenced by lookForSegments(), and ~ME0SegAlgoRU().

387  {
388  while(proto_segment.size() > n_seg_min && fit->chi2()/fit->ndof() > maxChi2){
389  float maxDev = -1;
390  HitAndPositionPtrContainer::iterator worstHit;
391  for(auto it = proto_segment.begin(); it != proto_segment.end(); ++it){
392  const float dev = getHitSegChi2(fit,*(*it)->rh);
393  if(dev < maxDev) continue;
394  maxDev = dev;
395  worstHit = it;
396  }
397  edm::LogVerbatim("ME0SegAlgoRU") << "[ME0SegAlgoRU::pruneBadHits] pruning one hit-> layer: "<< (*worstHit)->layer <<" eta: "<< (*worstHit)->gp.eta() <<" phi: "<<(*worstHit)->gp.phi()<<" old chi2/dof: "<<fit->chi2()/fit->ndof() << std::endl;
398  proto_segment.erase( worstHit);
399  fit = makeFit(proto_segment);
400  }
401 }
std::unique_ptr< MuonSegFit > makeFit(const HitAndPositionPtrContainer &proto_segment) const
float getHitSegChi2(const std::unique_ptr< MuonSegFit > &fit, const ME0RecHit &hit) const
std::vector< ME0Segment > ME0SegAlgoRU::run ( const ME0Chamber chamber,
const HitAndPositionContainer rechits 
)
virtual

Here we must implement the algorithm

Implements ME0SegmentAlgorithmBase.

Definition at line 79 of file ME0SegAlgoRU.cc.

References allowWideSegments, relativeConstraints::chamber, displacedParameters, doCollisions, ME0Chamber::id(), lookForSegments(), ME0SegAlgoRU::SegmentParameters::minNumberOfHits, stdParameters, theChamber, and wideParameters.

Referenced by ~ME0SegAlgoRU().

79  {
80 
81 #ifdef EDM_ML_DEBUG // have lines below only compiled when in debug mode
82  ME0DetId chId(chamber->id());
83  edm::LogVerbatim("ME0SegAlgoRU") << "[ME0SegmentAlgorithm::run] build segments in chamber " << chId << " which contains "<<rechits.size()<<" rechits";
84  for(unsigned int iH = 0; iH < rechits.size(); ++iH){
85  auto me0id = rechits[iH].rh->me0Id();
86  auto rhLP = rechits[iH].lp;
87  edm::LogVerbatim("ME0SegAlgoRU") << "[RecHit :: Loc x = "<<std::showpos<<std::setw(9)<<rhLP.x()<<" Glb y = "<<std::showpos<<std::setw(9)<<rhLP.y()<<" Time = "<<std::showpos<<rechits[iH].rh->tof()<<" -- "<<me0id.rawId()<<" = "<<me0id<<" ]"<<std::endl;
88  }
89 #endif
90 
91 
92  if (rechits.size() < 3 || rechits.size()>300){
93  return std::vector<ME0Segment>();
94  }
95 
97 
98  std::vector<unsigned int> recHits_per_layer(6,0);
99  for(unsigned int iH = 0; iH < rechits.size(); ++iH) {
100  recHits_per_layer[rechits[iH].layer-1]++;
101  }
102 
103  BoolContainer used(rechits.size(),false);
104 
105  // We have at least 2 hits. We intend to try all possible pairs of hits to start
106  // segment building. 'All possible' means each hit lies on different layers in the chamber.
107  // after all same size segs are build we get rid of the overcrossed segments using the chi2 criteria
108  // the hits from the segs that are left are marked as used and are not added to segs in future iterations
109  // the hits from 3p segs are marked as used separately in order to try to assamble them in longer segments
110  // in case there is a second pass
111 
112  // Choose first hit (as close to IP as possible) h1 and second hit
113  // (as far from IP as possible) h2 To do this we iterate over hits
114  // in the chamber by layer - pick two layers. Then we
115  // iterate over hits within each of these layers and pick h1 and h2
116  // these. If they are 'close enough' we build an empty
117  // segment. Then try adding hits to this segment.
118 
119  std::vector<ME0Segment> segments;
120 
121  auto doStd = [&] () {
122  for(unsigned int n_seg_min = 6u; n_seg_min >= stdParameters.minNumberOfHits; --n_seg_min)
123  lookForSegments(stdParameters,n_seg_min,rechits,recHits_per_layer, used, segments);
124  };
125  auto doDisplaced = [&] () {
126  for(unsigned int n_seg_min = 6u; n_seg_min >= displacedParameters.minNumberOfHits; --n_seg_min)
127  lookForSegments(displacedParameters,n_seg_min,rechits,recHits_per_layer, used,segments);
128  };
129  auto doWide = [&] () {
130  for(unsigned int n_seg_min = 6u; n_seg_min >= wideParameters.minNumberOfHits; --n_seg_min)
131  lookForSegments(wideParameters,n_seg_min,rechits,recHits_per_layer, used,segments);
132  };
133  auto printSegments = [&] {
134 #ifdef EDM_ML_DEBUG // have lines below only compiled when in debug mode
135  for(unsigned int iS = 0; iS < segments.size(); ++iS) {
136  const auto& seg = segments[iS];
137  ME0DetId chId(seg.me0DetId());
138  const auto& rechits = seg.specificRecHits();
139  edm::LogVerbatim("ME0SegAlgoRU") << "[ME0SegAlgoRU] segment in chamber " << chId << " which contains "<<rechits.size()<<" rechits and with specs: \n"<<seg;
140  for (auto rh=rechits.begin(); rh!=rechits.end(); ++rh){
141  auto me0id = rh->me0Id();
142  edm::LogVerbatim("ME0SegAlgoRU") << "[RecHit :: Loc x = "<<std::showpos<<std::setw(9)<<rh->localPosition().x()<<" Loc y = "<<std::showpos<<std::setw(9)<<rh->localPosition().y()<<" Time = "<<std::showpos<<rh->tof()<<" -- "<<me0id.rawId()<<" = "<<me0id<<" ]";
143  }
144  }
145 #endif
146  };
147 
148 
149  //If we arent doing collisions, do a single iteration
150  if(!doCollisions){
151  doDisplaced();
152  printSegments();
153  return segments;
154  }
155 
156  //Iteration 1: STD processing
157  doStd();
158 
159  if(false){
160  //How the CSC algorithm ~does iterations. for now not considering
161  //displaced muons will not worry about it later
162  //Iteration 2a: If we don't allow wide segments simply do displaced
163  // Or if we already found a segment simply skip to displaced
164  if(!allowWideSegments || segments.size()){
165  doDisplaced();
166  return segments;
167  }
168  doWide();
169  doDisplaced();
170  }
171  printSegments();
172  return segments;
173 }
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< ME0Segment > &segments) const
SegmentParameters displacedParameters
Definition: ME0SegAlgoRU.h:106
ME0DetId id() const
Return the ME0DetId of this chamber.
Definition: ME0Chamber.cc:14
std::vector< bool > BoolContainer
Definition: ME0SegAlgoRU.h:50
SegmentParameters stdParameters
Definition: ME0SegAlgoRU.h:105
const ME0Chamber * theChamber
Definition: ME0SegAlgoRU.h:110
bool allowWideSegments
Definition: ME0SegAlgoRU.h:103
SegmentParameters wideParameters
Definition: ME0SegAlgoRU.h:107
void ME0SegAlgoRU::tryAddingHitsToSegment ( const float  maxTOF,
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 297 of file ME0SegAlgoRU.cc.

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

Referenced by lookForSegments(), and ~ME0SegAlgoRU().

298  {
299  // Iterate over the layers with hits in the chamber
300  // Skip the layers containing the segment endpoints
301  // Test each hit on the other layers to see if it is near the segment
302  // If it is, see whether there is already a hit on the segment from the same layer
303  // - if so, and there are more than 2 hits on the segment, copy the segment,
304  // replace the old hit with the new hit. If the new segment chi2 is better
305  // then replace the original segment with the new one (by swap)
306  // - if not, copy the segment, add the hit. If the new chi2/dof is still satisfactory
307  // then replace the original segment with the new one (by swap)
308 
309  //Hits are ordered by layer, "i1" is the inner hit and i2 is the outer hit
310  //so possible hits to add must be between these two iterators
311  for(auto iH = i1 + 1; iH != i2; ++iH ){
312  if(iH->layer == i1->layer) continue;
313  if(iH->layer == i2->layer) break;
314  if(used[iH->idx]) continue;
315  if(!areHitsConsistentInTime(maxTOF,proto_segment,*iH)) continue;
316  if (!isHitNearSegment(maxETA,maxPhi,current_fit,proto_segment,*iH)) continue;
317  if(hasHitOnLayer(proto_segment,iH->layer))
318  compareProtoSegment(current_fit,proto_segment,*iH);
319  else
320  increaseProtoSegment(maxChi2, current_fit,proto_segment,*iH);
321  }
322 }
void increaseProtoSegment(const float maxChi2, std::unique_ptr< MuonSegFit > &current_fit, HitAndPositionPtrContainer &current_proto_segment, const HitAndPosition &new_hit) const
bool areHitsConsistentInTime(const float maxTOF, 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 isHitNearSegment(const float maxETA, const float maxPHI, const std::unique_ptr< MuonSegFit > &fit, const HitAndPositionPtrContainer &proto_segment, const HitAndPosition &h) const
bool hasHitOnLayer(const HitAndPositionPtrContainer &proto_segment, const unsigned int layer) const

Member Data Documentation

bool ME0SegAlgoRU::allowWideSegments
private

Definition at line 103 of file ME0SegAlgoRU.h.

Referenced by ME0SegAlgoRU(), and run().

SegmentParameters ME0SegAlgoRU::displacedParameters
private

Definition at line 106 of file ME0SegAlgoRU.h.

Referenced by ME0SegAlgoRU(), and run().

bool ME0SegAlgoRU::doCollisions
private

Definition at line 102 of file ME0SegAlgoRU.h.

Referenced by ME0SegAlgoRU(), and run().

const std::string ME0SegAlgoRU::myName
private

Definition at line 101 of file ME0SegAlgoRU.h.

Referenced by ME0SegAlgoRU().

SegmentParameters ME0SegAlgoRU::stdParameters
private

Definition at line 105 of file ME0SegAlgoRU.h.

Referenced by ME0SegAlgoRU(), and run().

const ME0Chamber* ME0SegAlgoRU::theChamber
private

Definition at line 110 of file ME0SegAlgoRU.h.

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

SegmentParameters ME0SegAlgoRU::wideParameters
private

Definition at line 107 of file ME0SegAlgoRU.h.

Referenced by ME0SegAlgoRU(), and run().