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) override
 
 ~ME0SegAlgoRU () override
 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=nullptr;
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.
ME0SegAlgoRU::~ME0SegAlgoRU ( )
inlineoverride

Member Function Documentation

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

Definition at line 367 of file ME0SegAlgoRU.cc.

References makeFit().

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

367  {
368  proto_segment.push_back(&aHit);
369  // make a fit
370  return makeFit(proto_segment);
371 }
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 242 of file ME0SegAlgoRU.cc.

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

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

242  {
243  std::sort(proto_segments.begin(),proto_segments.end(),
244  [](const std::pair<float,HitAndPositionPtrContainer> & a,
245  const std::pair<float,HitAndPositionPtrContainer> & b) { return a.first < b.first;});
246 
247  //Now add to the collect based on minChi2 marking the hits as used after
248  std::vector<unsigned int> usedHits;
249  for(unsigned int iS = 0; iS < proto_segments.size(); ++iS){
250  HitAndPositionPtrContainer currentProtoSegment = proto_segments[iS].second;
251 
252  //check to see if we already used thes hits this round
253  bool alreadyFilled=false;
254  for(unsigned int iH = 0; iH < currentProtoSegment.size(); ++iH){
255  for(unsigned int iOH = 0; iOH < usedHits.size(); ++iOH){
256  if(usedHits[iOH]!=currentProtoSegment[iH]->idx) continue;
257  alreadyFilled = true;
258  break;
259  }
260  }
261  if(alreadyFilled) continue;
262  for(const auto* h : currentProtoSegment){
263  usedHits.push_back(h->idx);
264  used[h->idx] = true;
265  }
266 
267  std::unique_ptr<MuonSegFit> current_fit = makeFit(currentProtoSegment);
268 
269  // Create an actual ME0Segment - retrieve all info from the fit
270  // calculate the timing fron rec hits associated to the TrackingRecHits used
271  // to fit the segment
272  float averageTime=0.;
273  for(const auto* h : currentProtoSegment){
274  averageTime += h->rh->tof();
275  }
276  averageTime /= float(currentProtoSegment.size());
277  float timeUncrt=0.;
278  for(const auto* h : currentProtoSegment){
279  timeUncrt += (h->rh->tof()-averageTime)*(h->rh->tof()-averageTime);
280  }
281  timeUncrt = std::sqrt(timeUncrt/float(currentProtoSegment.size()-1));
282 
283  std::sort(currentProtoSegment.begin(),currentProtoSegment.end(),
284  [](const HitAndPosition* a, const HitAndPosition *b) {return a->layer < b->layer;}
285  );
286 
287  std::vector<const ME0RecHit*> bareRHs; bareRHs.reserve(currentProtoSegment.size());
288  for(const auto* rh : currentProtoSegment) bareRHs.push_back(rh->rh);
289  const float dPhi = theChamber->computeDeltaPhi(current_fit->intercept(),current_fit->localdir());
290  ME0Segment temp(bareRHs, current_fit->intercept(),
291  current_fit->localdir(), current_fit->covarianceMatrix(), current_fit->chi2(), averageTime, timeUncrt, dPhi);
292  segments.push_back(temp);
293 
294 
295  }
296 }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
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 325 of file ME0SegAlgoRU.cc.

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

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

325  {
326  float diff = 0;
327  diff = std::fabs(h1.eta() - h1.eta());
328  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;
329  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.
330 }
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 332 of file ME0SegAlgoRU.cc.

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

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

332  {
333  float dphi12 = deltaPhi(h1.barePhi(),h2.barePhi());
334  edm::LogVerbatim("ME0SegAlgoRU") << "[ME0SegAlgoRU::areHitsCloseInGlobalPhi] gp1 = "<<h1<<" and gp2 = "<<h2<<" ==> dPhi = "<<dphi12<<" ==> return "<<(fabs(dphi12) < std::max(maxPHI,float(0.02)))<<std::endl;
335  return fabs(dphi12) < std::max(maxPHI, float(float(nLayDisp)*0.004));
336 }
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 352 of file ME0SegAlgoRU.cc.

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

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

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

Definition at line 425 of file ME0SegAlgoRU.cc.

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

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

425  {
426  const HitAndPosition * old_hit = nullptr;
427  HitAndPositionPtrContainer new_proto_segment = current_proto_segment;
428 
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 == nullptr) 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 }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
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:511
float ME0SegAlgoRU::getHitSegChi2 ( const std::unique_ptr< MuonSegFit > &  fit,
const ME0RecHit hit 
) const
private

Definition at line 404 of file ME0SegAlgoRU.cc.

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

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

404  {
405  const auto lp = hit.localPosition();
406  const auto le = hit.localPositionError();
407  const float du = fit->xdev(lp.x(),lp.z());
408  const float dv = fit->ydev(lp.y(),lp.z());
409 
410  ROOT::Math::SMatrix<double,2,2,ROOT::Math::MatRepSym<double,2> > IC;
411  IC(0,0) = le.xx();
412  IC(1,0) = le.xy();
413  IC(1,1) = le.yy();
414 
415  // Invert covariance matrix
416  IC.Invert();
417  return du*du*IC(0,0) + 2.*du*dv*IC(0,1) + dv*dv*IC(1,1);
418 }
LocalError localPositionError() const override
Return the 3-dimensional error on the local position.
Definition: ME0RecHit.h:53
LocalPoint localPosition() const override
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 361 of file ME0SegAlgoRU.cc.

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

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

361  {
362  float x = fit->xfit(z);
363  float y = fit->yfit(z);
364  return theChamber->toGlobal(LocalPoint(x,y,z));
365 }
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 420 of file ME0SegAlgoRU.cc.

References h.

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

420  {
421  for(const auto* h : proto_segment) if(h->layer == layer) return true;
422  return false;
423 }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
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:511
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 338 of file ME0SegAlgoRU.cc.

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

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

338  {
339  //Get average eta, based on the two seeds...asssumes that we have not started pruning yet!
340  const float avgETA = (proto_segment[1]->gp.eta() + proto_segment[0]->gp.eta())/2.;
341  // 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;
342  if(std::fabs(h.gp.eta() - avgETA) > std::max(maxETA,float(0.01) )) return false;
343 
344  //Now check the dPhi based on the segment fit
345  GlobalPoint globIntercept = globalAtZ(fit, h.lp.z());
346  float dPhi = deltaPhi(h.gp.barePhi(),globIntercept.phi());
347  //check to see if it is inbetween the two rolls of the outer and inner hits
348  // 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;
349  return (std::fabs(dPhi) < std::max(maxPHI,float(0.001)));
350 }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
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 176 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().

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

Definition at line 373 of file ME0SegAlgoRU.cc.

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

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

373  {
374  // for ME0 we take the me0rechit from the proto_segment we transform into Tracking Rechits
375  // the local rest frame is the ME0Chamber
377  for (auto rh=proto_segment.begin();rh<proto_segment.end(); rh++){
378  ME0RecHit *newRH = (*rh)->rh->clone();
379  newRH->setPosition((*rh)->lp);
380  MuonSegFit::MuonRecHitPtr trkRecHit(newRH);
381  muonRecHits.push_back(trkRecHit);
382  }
383  std::unique_ptr<MuonSegFit> currentFit(new MuonSegFit(muonRecHits));
384  currentFit->fit();
385  return currentFit;
386 }
std::shared_ptr< TrackingRecHit > MuonRecHitPtr
Definition: MuonSegFit.h:41
void setPosition(LocalPoint pos)
Set local position.
Definition: ME0RecHit.h:72
std::vector< MuonRecHitPtr > MuonRecHitContainer
Definition: MuonSegFit.h:42
ME0RecHit * clone() const override
Definition: ME0RecHit.cc:47
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 388 of file ME0SegAlgoRU.cc.

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

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

388  {
389  while(proto_segment.size() > n_seg_min && fit->chi2()/fit->ndof() > maxChi2){
390  float maxDev = -1;
391  HitAndPositionPtrContainer::iterator worstHit;
392  for(auto it = proto_segment.begin(); it != proto_segment.end(); ++it){
393  const float dev = getHitSegChi2(fit,*(*it)->rh);
394  if(dev < maxDev) continue;
395  maxDev = dev;
396  worstHit = it;
397  }
398  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;
399  proto_segment.erase( worstHit);
400  fit = makeFit(proto_segment);
401  }
402 }
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 
)
overridevirtual

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, and theChamber.

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  // Not currently used
130  // auto doWide = [&] () {
131  // for(unsigned int n_seg_min = 6u; n_seg_min >= wideParameters.minNumberOfHits; --n_seg_min)
132  // lookForSegments(wideParameters,n_seg_min,rechits,recHits_per_layer, used,segments);
133  // };
134  auto printSegments = [&] {
135 #ifdef EDM_ML_DEBUG // have lines below only compiled when in debug mode
136  for(unsigned int iS = 0; iS < segments.size(); ++iS) {
137  const auto& seg = segments[iS];
138  ME0DetId chId(seg.me0DetId());
139  const auto& rechits = seg.specificRecHits();
140  edm::LogVerbatim("ME0SegAlgoRU") << "[ME0SegAlgoRU] segment in chamber " << chId << " which contains "<<rechits.size()<<" rechits and with specs: \n"<<seg;
141  for (auto rh=rechits.begin(); rh!=rechits.end(); ++rh){
142  auto me0id = rh->me0Id();
143  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<<" ]";
144  }
145  }
146 #endif
147  };
148 
149 
150  //If we arent doing collisions, do a single iteration
151  if(!doCollisions){
152  doDisplaced();
153  printSegments();
154  return segments;
155  }
156 
157  //Iteration 1: STD processing
158  doStd();
159 
160  if(false){
161  //How the CSC algorithm ~does iterations. for now not considering
162  //displaced muons will not worry about it later
163  //Iteration 2a: If we don't allow wide segments simply do displaced
164  // Or if we already found a segment simply skip to displaced
165  if(!allowWideSegments || !segments.empty()){
166  doDisplaced();
167  return segments;
168  }
169  //doWide();
170  doDisplaced();
171  }
172  printSegments();
173  return segments;
174 }
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
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 298 of file ME0SegAlgoRU.cc.

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

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

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