CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
CSCSegAlgoDF Class Reference

#include <CSCSegAlgoDF.h>

Inheritance diagram for CSCSegAlgoDF:
CSCSegmentAlgorithm

Public Types

typedef std::deque< bool > BoolContainer
 
typedef std::vector< const
CSCRecHit2D * > 
ChamberHitContainer
 
typedef std::vector< const
CSCRecHit2D * >
::const_iterator 
ChamberHitContainerCIt
 
typedef std::vector< int > LayerIndex
 Typedefs. More...
 

Public Member Functions

std::vector< CSCSegmentbuildSegments (const ChamberHitContainer &rechits)
 
 CSCSegAlgoDF (const edm::ParameterSet &ps)
 Constructor. More...
 
std::vector< CSCSegmentrun (const CSCChamber *aChamber, const ChamberHitContainer &rechits)
 
virtual ~CSCSegAlgoDF ()
 Destructor. More...
 
- Public Member Functions inherited from CSCSegmentAlgorithm
 CSCSegmentAlgorithm (const edm::ParameterSet &)
 Constructor. More...
 
virtual std::vector< CSCSegmentrun (const CSCChamber *chamber, const std::vector< const CSCRecHit2D * > &rechits)=0
 
virtual ~CSCSegmentAlgorithm ()
 Destructor. More...
 

Private Member Functions

bool addHit (const CSCRecHit2D *hit, int layer)
 
void compareProtoSegment (const CSCRecHit2D *h, int layer)
 
void dumpSegment (const CSCSegment &seg) const
 
void flagHitsAsUsed (const ChamberHitContainer &rechitsInChamber)
 
bool hasHitOnLayer (int layer) const
 
bool isHitNearSegment (const CSCRecHit2D *h) const
 
void pruneFromResidual (void)
 
void tryAddingHitsToSegment (const ChamberHitContainer &rechitsInChamber, const ChamberHitContainerCIt i1, const ChamberHitContainerCIt i2, const LayerIndex &layerIndex)
 Utility functions. More...
 
void updateParameters (void)
 

Private Attributes

float chi2Max
 
ChamberHitContainer closeHits
 
bool debug
 
double dPhiFineMax
 
double dRPhiFineMax
 
float maxRatioResidual
 
int minHitsForPreClustering
 
int minHitsPerSegment
 
int minLayersApart
 
const std::string myName
 
int nHitsPerClusterIsShower
 
CSCSegAlgoPreClusteringpreCluster_
 
bool preClustering
 
ChamberHitContainer protoSegment
 
bool Pruning
 
ChamberHitContainer secondSeedHits
 
CSCSegFitsfit_
 
CSCSegAlgoShoweringshowering_
 
float tanPhiMax
 
float tanThetaMax
 
const CSCChambertheChamber
 
BoolContainer usedHits
 

Detailed Description

This is a modified version of the SK algorithm for building endcap muon track segments out of the rechit's in a CSCChamber.

A CSCSegment is a RecSegment4D, and is built from CSCRecHit2D objects, each of which is a RecHit2DLocalPos.

This builds segments by first creating proto-segments from at least 3 hits. We intend to try all possible pairs of hits to start segment building. 'All possible' means each hit lies on different layers in the chamber. Once a hit has been assigned to a segment, we don't consider it again, THAT IS, FOR THE FIRST PASS ONLY ! In fact, this is one of the possible flaw with the SK algorithms as it sometimes manages to build segments with the wrong starting points. In the DF algorithm, the endpoints are tested as the best starting points in a 2nd and 3rd loop.

Another difference with the from the SK algorithm is that rechits can be added to proto segments if they fall within n sigmas of the projected track within a given layer. Hence, a cylinder isn't used as in the SK algorimthm, which allows for pseudo 2D hits built from wire or strip only hits to be used in segment reconstruction.

Also, only a certain muonsPerChamberMax maximum number of segments can be produced in the chamber. [Seems to be hardwired rather than using this variable?]

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

Author
Dominique Fortin - UCR

Definition at line 48 of file CSCSegAlgoDF.h.

Member Typedef Documentation

typedef std::deque<bool> CSCSegAlgoDF::BoolContainer

Definition at line 58 of file CSCSegAlgoDF.h.

typedef std::vector<const CSCRecHit2D*> CSCSegAlgoDF::ChamberHitContainer

Definition at line 56 of file CSCSegAlgoDF.h.

typedef std::vector<const CSCRecHit2D*>::const_iterator CSCSegAlgoDF::ChamberHitContainerCIt

Definition at line 57 of file CSCSegAlgoDF.h.

typedef std::vector<int> CSCSegAlgoDF::LayerIndex

Typedefs.

Definition at line 55 of file CSCSegAlgoDF.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 35 of file CSCSegAlgoDF.cc.

References chi2Max, debug, dPhiFineMax, dRPhiFineMax, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), maxRatioResidual, minHitsForPreClustering, minHitsPerSegment, minLayersApart, nHitsPerClusterIsShower, preCluster_, preClustering, Pruning, showering_, tanPhiMax, and tanThetaMax.

36  : CSCSegmentAlgorithm(ps), myName("CSCSegAlgoDF"), sfit_(0) {
37 
38  debug = ps.getUntrackedParameter<bool>("CSCSegmentDebug");
39  minLayersApart = ps.getParameter<int>("minLayersApart");
40  minHitsPerSegment = ps.getParameter<int>("minHitsPerSegment");
41  dRPhiFineMax = ps.getParameter<double>("dRPhiFineMax");
42  dPhiFineMax = ps.getParameter<double>("dPhiFineMax");
43  tanThetaMax = ps.getParameter<double>("tanThetaMax");
44  tanPhiMax = ps.getParameter<double>("tanPhiMax");
45  chi2Max = ps.getParameter<double>("chi2Max");
46  preClustering = ps.getUntrackedParameter<bool>("preClustering");
47  minHitsForPreClustering= ps.getParameter<int>("minHitsForPreClustering");
48  nHitsPerClusterIsShower= ps.getParameter<int>("nHitsPerClusterIsShower");
49  Pruning = ps.getUntrackedParameter<bool>("Pruning");
50  maxRatioResidual = ps.getParameter<double>("maxRatioResidualPrune");
51 
53  showering_ = new CSCSegAlgoShowering( ps );
54 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
CSCSegAlgoPreClustering * preCluster_
Definition: CSCSegAlgoDF.h:143
CSCSegmentAlgorithm(const edm::ParameterSet &)
Constructor.
CSCSegAlgoShowering * showering_
Definition: CSCSegAlgoDF.h:144
bool preClustering
Definition: CSCSegAlgoDF.h:127
const std::string myName
Definition: CSCSegAlgoDF.h:116
CSCSegFit * sfit_
Definition: CSCSegAlgoDF.h:145
float maxRatioResidual
Definition: CSCSegAlgoDF.h:141
int minHitsForPreClustering
Definition: CSCSegAlgoDF.h:128
float tanThetaMax
Definition: CSCSegAlgoDF.h:139
double dPhiFineMax
Definition: CSCSegAlgoDF.h:137
double dRPhiFineMax
Definition: CSCSegAlgoDF.h:136
int minHitsPerSegment
Definition: CSCSegAlgoDF.h:134
int nHitsPerClusterIsShower
Definition: CSCSegAlgoDF.h:132
CSCSegAlgoDF::~CSCSegAlgoDF ( )
virtual

Destructor.

Definition at line 60 of file CSCSegAlgoDF.cc.

References preCluster_, and showering_.

60  {
61  delete preCluster_;
62  delete showering_;
63 }
CSCSegAlgoPreClustering * preCluster_
Definition: CSCSegAlgoDF.h:143
CSCSegAlgoShowering * showering_
Definition: CSCSegAlgoDF.h:144

Member Function Documentation

bool CSCSegAlgoDF::addHit ( const CSCRecHit2D hit,
int  layer 
)
private

Definition at line 416 of file CSCSegAlgoDF.cc.

References protoSegment.

Referenced by compareProtoSegment(), and tryAddingHitsToSegment().

416  {
417 
418 
419  // std::cout << "[CSCSegAlgoDF::addHit] on layer " << layer << " to protoSegment.size() = "
420  // << protoSegment.size() << std::endl;
421 
422  // Return true if hit was added successfully and then parameters are updated.
423  // Return false if there is already a hit on the same layer, or insert failed.
424 
425  if ( protoSegment.size() > 5 ) return false; //@@ can only have 6 hits at most
426 
427  // Test that we are not trying to add the same hit again
428  for ( ChamberHitContainer::const_iterator it = protoSegment.begin(); it != protoSegment.end(); ++it )
429  if ( aHit == (*it) ) return false;
430 
431  protoSegment.push_back(aHit);
432 
433  return true;
434 }
ChamberHitContainer protoSegment
Definition: CSCSegAlgoDF.h:122
std::vector< CSCSegment > CSCSegAlgoDF::buildSegments ( const ChamberHitContainer rechits)

Build track segments in this chamber (this is where the actual segment-building algorithm hides.)

Definition at line 113 of file CSCSegAlgoDF.cc.

References CSCSegFit::chi2(), chi2Max, CSCSegFit::covarianceMatrix(), debug, dumpSegment(), flagHitsAsUsed(), CSCSegFit::hits(), i, cuy::ib, CSCSegFit::intercept(), CSCChamber::layer(), CSCSegFit::localdir(), CSCRecHit2D::localPosition(), minHitsPerSegment, minLayersApart, nHitsPerClusterIsShower, CSCSegment::nRecHits(), GeomDet::position(), preClustering, protoSegment, pruneFromResidual(), Pruning, HI_PhotonSkim_cff::rechits, sfit_, showering_, CSCSegAlgoShowering::showerSeg(), tanPhiMax, tanThetaMax, groupFilesInBlocks::temp, theChamber, GeomDet::toGlobal(), GeomDet::toLocal(), tryAddingHitsToSegment(), updateParameters(), usedHits, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by run().

113  {
114 
115  ChamberHitContainer rechits = _rechits;
116  // Clear buffer for segment vector
117  std::vector<CSCSegment> segmentInChamber;
118  segmentInChamber.clear();
119 
120  unsigned nHitInChamber = rechits.size();
121 
122  // std::cout << "[CSCSegAlgoDF::buildSegments] address of chamber = " << theChamber << std::endl;
123  // std::cout << "[CSCSegAlgoDF::buildSegments] starting in " << theChamber->id()
124  // << " with " << nHitInChamber << " rechits" << std::endl;
125 
126  // Return #1 - OK, there aren't enough rechits to build a segment
127  if ( nHitInChamber < 3 ) return segmentInChamber;
128 
129  LayerIndex layerIndex( nHitInChamber );
130 
131  size_t nLayers = 0;
132  size_t old_layer = 0;
133  for ( size_t i = 0; i < nHitInChamber; ++i ) {
134  size_t this_layer = rechits[i]->cscDetId().layer();
135  // std::cout << "[CSCSegAlgoDF::buildSegments] this_layer = " << this_layer << std::endl;
136  layerIndex[i] = this_layer;
137  // std::cout << "[CSCSegAlgoDF::buildSegments] layerIndex[" << i << "] = " << layerIndex[i] << std::endl;
138  if ( this_layer != old_layer ) {
139  old_layer = this_layer;
140  ++nLayers;
141  }
142  }
143 
144  // std::cout << "[CSCSegAlgoDF::buildSegments] layers with rechits = " << nLayers << std::endl;
145 
146  // Return #2 - OK, there aren't enough hit layers to build a segment
147  if ( nLayers < 3 ) return segmentInChamber;
148 
149  double z1 = theChamber->layer(1)->position().z();
150  double z6 = theChamber->layer(6)->position().z();
151 
152  if ( z1 > 0. ) {
153  if ( z1 > z6 ) {
154  reverse( layerIndex.begin(), layerIndex.end() );
155  reverse( rechits.begin(), rechits.end() );
156  }
157  }
158  else if ( z1 < 0. ) {
159  if ( z1 < z6 ) {
160  reverse( layerIndex.begin(), layerIndex.end() );
161  reverse( rechits.begin(), rechits.end() );
162  }
163  }
164 
165  // std::cout << "[CSCSegAlgoDF::buildSegments] rechits have been ordered" << std::endl;
166 
167  // Showering muon
168  if ( preClustering && int(nHitInChamber) > nHitsPerClusterIsShower && nLayers > 2 ) {
169 
170  // std::cout << "[CSCSegAlgoDF::buildSegments] showering block" << std::endl;
171 
172  CSCSegment segShower = showering_->showerSeg(theChamber, rechits);
173 
174  // Return #3 - OK, this is now 'effectve' rechits
175  // Make sure have at least 3 hits...
176  if ( segShower.nRecHits() < 3 ) return segmentInChamber;
177 
178  segmentInChamber.push_back(segShower);
179  if (debug) dumpSegment( segShower );
180 
181  // Return #4 - OK, only get one try at building a segment from shower
182  return segmentInChamber;
183  }
184 
185  // Initialize flags that a given hit has been allocated to a segment
186  BoolContainer used_ini(rechits.size(), false);
187  usedHits = used_ini;
188 
189  ChamberHitContainerCIt ib = rechits.begin();
190  ChamberHitContainerCIt ie = rechits.end();
191 
192  // std::cout << "[CSCSegAlgoDF::buildSegments] entering rechit loop" << std::endl;
193 
194  // Now Loop over hits within the chamber to find 1st seed for segment building
195  for ( ChamberHitContainerCIt i1 = ib; i1 < ie; ++i1 ) {
196  if ( usedHits[i1-ib] ) continue;
197 
198  const CSCRecHit2D* h1 = *i1;
199  int layer1 = layerIndex[i1-ib];
200  const CSCLayer* l1 = theChamber->layer(layer1);
201  GlobalPoint gp1 = l1->toGlobal(h1->localPosition());
202  LocalPoint lp1 = theChamber->toLocal(gp1);
203 
204  // Loop over hits backward to find 2nd seed for segment building
205  for ( ChamberHitContainerCIt i2 = ie-1; i2 > ib; --i2 ) {
206 
207  if ( usedHits[i2-ib] ) continue; // Hit has been used already
208 
209  int layer2 = layerIndex[i2-ib];
210  if ( (layer2 - layer1) < minLayersApart ) continue;
211 
212  const CSCRecHit2D* h2 = *i2;
213  const CSCLayer* l2 = theChamber->layer(layer2);
214  GlobalPoint gp2 = l2->toGlobal(h2->localPosition());
215  LocalPoint lp2 = theChamber->toLocal(gp2);
216 
217  // Clear proto segment so it can be (re)-filled
218  protoSegment.clear();
219 
220  // We want hit wrt chamber (and local z will be != 0)
221  float dz = gp2.z()-gp1.z();
222  float slope_u = (lp2.x() - lp1.x())/dz ;
223  float slope_v = (lp2.y() - lp1.y())/dz ;
224 
225  // Test if entrance angle is roughly pointing towards IP
226  if (fabs(slope_v) > tanThetaMax) continue;
227  if (fabs(slope_u) > tanPhiMax ) continue;
228 
229  protoSegment.push_back(h1);
230  protoSegment.push_back(h2);
231 
232  // std::cout << "[CSCSegAlgoDF::buildSegments] about to fit 2 hits on layers "
233  // << layer1 << " and " << layer2 << std::endl;
234 
235  // protoSegment has just 2 hits - but need to create a CSCSegFit to hold it in case
236  // we fail to add any more hits
238 
239  // Try adding hits to proto segment
240  tryAddingHitsToSegment(rechits, i1, i2, layerIndex);
241 
242  // Check no. of hits on segment to see if segment is large enough
243  bool segok = true;
244  unsigned iadd = 0;
245 
246  if (protoSegment.size() < minHitsPerSegment+iadd) segok = false;
247 
248  if ( Pruning && segok ) pruneFromResidual();
249 
250  // Check if segment satisfies chi2 requirement
251  if ( sfit_->chi2() > chi2Max) segok = false;
252 
253  if ( segok ) {
254 
255  // Create an actual CSCSegment - retrieve all info from the current fit
258  // std::cout << "[CSCSegAlgoDF::buildSegments] about to delete sfit= = " << sfit_ << std::endl;
259  delete sfit_;
260  sfit_ = 0; // avoid possibility of attempting a second delete later
261 
262  segmentInChamber.push_back(temp);
263  if (debug) dumpSegment( temp );
264 
265  // Return #5 - OK, fewer than 3 rechits not on this segment left in chamber
266  if (nHitInChamber-protoSegment.size() < 3) return segmentInChamber;
267  // Return $6 - already have more than 4 segments in this chamber
268  if (segmentInChamber.size() > 4) return segmentInChamber;
269 
270  // Flag used hits
271  flagHitsAsUsed(rechits);
272  }
273  }
274  }
275  // Return #7
276  return segmentInChamber;
277 }
void tryAddingHitsToSegment(const ChamberHitContainer &rechitsInChamber, const ChamberHitContainerCIt i1, const ChamberHitContainerCIt i2, const LayerIndex &layerIndex)
Utility functions.
int i
Definition: DBlmapReader.cc:9
ChamberHitContainer protoSegment
Definition: CSCSegAlgoDF.h:122
std::vector< const CSCRecHit2D * > ChamberHitContainer
Definition: CSCSegAlgoDF.h:56
std::vector< const CSCRecHit2D * >::const_iterator ChamberHitContainerCIt
Definition: CSCSegAlgoDF.h:57
CSCSetOfHits hits(void) const
Definition: CSCSegFit.h:82
int ib
Definition: cuy.py:660
LocalVector localdir() const
Definition: CSCSegFit.h:88
CSCSegment showerSeg(const CSCChamber *aChamber, const ChamberHitContainer &rechits)
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:52
T y() const
Definition: PV3DBase.h:63
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:67
CSCSegAlgoShowering * showering_
Definition: CSCSegAlgoDF.h:144
bool preClustering
Definition: CSCSegAlgoDF.h:127
CSCSegFit * sfit_
Definition: CSCSegAlgoDF.h:145
void updateParameters(void)
std::deque< bool > BoolContainer
Definition: CSCSegAlgoDF.h:58
const Surface::PositionType & position() const
The position (origin of the R.F.)
Definition: GeomDet.h:46
int nRecHits() const
Definition: CSCSegment.h:67
void dumpSegment(const CSCSegment &seg) const
double chi2(void) const
Definition: CSCSegFit.h:85
T z() const
Definition: PV3DBase.h:64
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to the given id.
Definition: CSCChamber.cc:39
std::vector< int > LayerIndex
Typedefs.
Definition: CSCSegAlgoDF.h:55
void flagHitsAsUsed(const ChamberHitContainer &rechitsInChamber)
float tanThetaMax
Definition: CSCSegAlgoDF.h:139
void pruneFromResidual(void)
AlgebraicSymMatrix covarianceMatrix(void)
Definition: CSCSegFit.cc:378
LocalPoint intercept() const
Definition: CSCSegFit.h:87
const CSCChamber * theChamber
Definition: CSCSegAlgoDF.h:117
LocalPoint localPosition() const
Definition: CSCRecHit2D.h:50
int minHitsPerSegment
Definition: CSCSegAlgoDF.h:134
int nHitsPerClusterIsShower
Definition: CSCSegAlgoDF.h:132
T x() const
Definition: PV3DBase.h:62
BoolContainer usedHits
Definition: CSCSegAlgoDF.h:118
void CSCSegAlgoDF::compareProtoSegment ( const CSCRecHit2D h,
int  layer 
)
private

Definition at line 481 of file CSCSegAlgoDF.cc.

References addHit(), CSCSegFit::chi2(), CSCSegFit::fit(), convertSQLiteXML::ok, protoSegment, sfit_, and theChamber.

Referenced by tryAddingHitsToSegment().

481  {
482 
483 
484  // std::cout << "[CSCSegAlgoDF::compareProtoSegment] for hit on layer " << layer
485  // << " with protoSegment.size() = " << protoSegment.size() << std::endl;
486 
487  // Try adding the hit to existing segment, and remove old one existing in same layer
488  ChamberHitContainer::iterator it;
489  for ( it = protoSegment.begin(); it != protoSegment.end(); ) {
490  if ( (*it)->cscDetId().layer() == layer ) {
491  it = protoSegment.erase(it);
492  } else {
493  ++it;
494  }
495  }
496 
497  // std::cout << "[CSCSegAlgoDF::compareProtoSegment] about to add hit on layer " << layer
498  // << " with protoSegment.size() = " << protoSegment.size() << std::endl;
499 
500  bool ok = addHit(h, layer);
501 
502  CSCSegFit* newfit = 0;
503  if ( ok ) {
504  newfit = new CSCSegFit( theChamber, protoSegment );
505  // std::cout << "[CSCSegAlgoDF::compareProtoSegment] newfit = " << newfit << std::endl;
506  newfit->fit();
507  }
508  if ( !ok || (newfit->chi2() > sfit_->chi2()) ) {
509  // std::cout << "[CSCSegAlgoDF::compareProtoSegment] about to delete newfit = " << newfit << std::endl;
510  delete newfit; // failed to add a hit or new fit is worse
511  }
512  else {
513  // std::cout << "[CSCSegAlgoDF::compareProtoSegment] about to delete sfit_ = " << sfit_ << std::endl;
514  delete sfit_; // new fit is better
515  sfit_ = newfit;
516  // std::cout << "[CSCSegAlgoDF::compareProtoSegment] reset sfit_ = " << sfit_ << std::endl;
517  }
518 }
void fit(void)
Definition: CSCSegFit.cc:14
ChamberHitContainer protoSegment
Definition: CSCSegAlgoDF.h:122
bool addHit(const CSCRecHit2D *hit, int layer)
CSCSegFit * sfit_
Definition: CSCSegAlgoDF.h:145
double chi2(void) const
Definition: CSCSegFit.h:85
const CSCChamber * theChamber
Definition: CSCSegAlgoDF.h:117
void CSCSegAlgoDF::dumpSegment ( const CSCSegment seg) const
private

Definition at line 611 of file CSCSegAlgoDF.cc.

References CSCSegment::chi2(), CSCSegment::degreesOfFreedom(), CSCChamber::id(), CSCSegment::localDirection(), CSCSegment::localDirectionError(), CSCSegment::localPosition(), CSCSegment::localPositionError(), CSCSegment::parametersError(), CSCSegment::specificRecHits(), theChamber, and CSCSegment::time().

Referenced by buildSegments().

611  {
612 
613  edm::LogVerbatim("CSCSegment") << "CSCSegment in " << theChamber->id()
614  << "\nlocal position = " << seg.localPosition()
615  << "\nerror = " << seg.localPositionError()
616  << "\nlocal direction = " << seg.localDirection()
617  << "\nerror =" << seg.localDirectionError()
618  << "\ncovariance matrix"
619  << seg.parametersError()
620  << "chi2/ndf = " << seg.chi2() << "/" << seg.degreesOfFreedom()
621  << "\n#rechits = " << seg.specificRecHits().size()
622  << "\ntime = " << seg.time();
623 }
CSCDetId id() const
Get the (concrete) DetId.
Definition: CSCChamber.h:37
LocalError localPositionError() const
Definition: CSCSegment.cc:47
virtual int degreesOfFreedom() const
Degrees of freedom of the segment fit.
Definition: CSCSegment.h:61
LocalPoint localPosition() const
Definition: CSCSegment.h:38
LocalVector localDirection() const
Local direction.
Definition: CSCSegment.h:41
const std::vector< CSCRecHit2D > & specificRecHits() const
Definition: CSCSegment.h:65
AlgebraicSymMatrix parametersError() const
Covariance matrix of parameters()
Definition: CSCSegment.h:48
double chi2() const
Chi2 of the segment fit.
Definition: CSCSegment.h:57
const CSCChamber * theChamber
Definition: CSCSegAlgoDF.h:117
float time() const
Definition: CSCSegment.cc:149
LocalError localDirectionError() const
Error on the local direction.
Definition: CSCSegment.cc:51
void CSCSegAlgoDF::flagHitsAsUsed ( const ChamberHitContainer rechitsInChamber)
private

Flag hits on segment as used

Definition at line 526 of file CSCSegAlgoDF.cc.

References closeHits, cuy::ib, protoSegment, and usedHits.

Referenced by buildSegments().

526  {
527 
528  // Flag hits on segment as used
529  ChamberHitContainerCIt ib = rechitsInChamber.begin();
530  ChamberHitContainerCIt hi, iu;
531 
532  for ( hi = protoSegment.begin(); hi != protoSegment.end(); ++hi ) {
533  for ( iu = ib; iu != rechitsInChamber.end(); ++iu ) {
534  if (*hi == *iu) usedHits[iu-ib] = true;
535  }
536  }
537  // Don't reject hits marked as "nearby" for now.
538  // So this is bypassed at all times for now !!!
539  // Perhaps add back to speed up algorithm some more
540  if (closeHits.size() > 0) return;
541  for ( hi = closeHits.begin(); hi != closeHits.end(); ++hi ) {
542  for ( iu = ib; iu != rechitsInChamber.end(); ++iu ) {
543  if (*hi == *iu) usedHits[iu-ib] = true;
544  }
545  }
546 
547 }
ChamberHitContainer protoSegment
Definition: CSCSegAlgoDF.h:122
std::vector< const CSCRecHit2D * >::const_iterator ChamberHitContainerCIt
Definition: CSCSegAlgoDF.h:57
int ib
Definition: cuy.py:660
ChamberHitContainer closeHits
Definition: CSCSegAlgoDF.h:120
BoolContainer usedHits
Definition: CSCSegAlgoDF.h:118
bool CSCSegAlgoDF::hasHitOnLayer ( int  layer) const
private

Definition at line 461 of file CSCSegAlgoDF.cc.

References protoSegment.

Referenced by tryAddingHitsToSegment().

461  {
462 
463 
464  // std::cout << "[CSCSegAlgoDF::hasHitOnLayer] on layer " << layer << std::endl;
465 
466 
467  // Is there already a hit on this layer?
468  for ( ChamberHitContainerCIt it = protoSegment.begin(); it != protoSegment.end(); it++ )
469  if ( (*it)->cscDetId().layer() == layer ) return true;
470 
471  return false;
472 }
ChamberHitContainer protoSegment
Definition: CSCSegAlgoDF.h:122
std::vector< const CSCRecHit2D * >::const_iterator ChamberHitContainerCIt
Definition: CSCSegAlgoDF.h:57
bool CSCSegAlgoDF::isHitNearSegment ( const CSCRecHit2D h) const
private

Definition at line 378 of file CSCSegAlgoDF.cc.

References CSCRecHit2D::cscDetId(), SiPixelRawToDigiRegional_cfi::deltaPhi, dPhiFineMax, dRPhiFineMax, CSCChamber::layer(), CSCDetId::layer(), CSCRecHit2D::localPosition(), M_PI, PV3DBase< T, PVType, FrameType >::phi(), dttmaxenums::R, sfit_, mathSSE::sqrt(), theChamber, GeomDet::toGlobal(), GeomDet::toLocal(), PV3DBase< T, PVType, FrameType >::x(), CSCSegFit::xfit(), PV3DBase< T, PVType, FrameType >::y(), CSCSegFit::yfit(), z, and PV3DBase< T, PVType, FrameType >::z().

Referenced by tryAddingHitsToSegment().

378  {
379 
380  const CSCLayer* layer = theChamber->layer(hit->cscDetId().layer());
381 
382  // hit phi position in global coordinates
383  GlobalPoint Hgp = layer->toGlobal(hit->localPosition());
384  float Hphi = Hgp.phi();
385  if (Hphi < 0.) Hphi += 2.*M_PI;
386  LocalPoint Hlp = theChamber->toLocal(Hgp);
387  float z = Hlp.z();
388 
389  float LocalX = sfit_->xfit(z);
390  float LocalY = sfit_->yfit(z);
391 
392  LocalPoint Slp(LocalX, LocalY, z);
393  GlobalPoint Sgp = theChamber->toGlobal(Slp);
394  float Sphi = Sgp.phi();
395  if (Sphi < 0.) Sphi += 2.*M_PI;
396  float R = sqrt(Sgp.x()*Sgp.x() + Sgp.y()*Sgp.y());
397 
398  float deltaPhi = Sphi - Hphi;
399  if (deltaPhi > 2.*M_PI) deltaPhi -= 2.*M_PI;
400  if (deltaPhi < -2.*M_PI) deltaPhi += 2.*M_PI;
401  if (deltaPhi < 0.) deltaPhi = -deltaPhi;
402 
403  float RdeltaPhi = R * deltaPhi;
404 
405  if (RdeltaPhi < dRPhiFineMax && deltaPhi < dPhiFineMax ) return true;
406 
407  return false;
408 }
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:52
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
T y() const
Definition: PV3DBase.h:63
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:67
CSCSegFit * sfit_
Definition: CSCSegAlgoDF.h:145
T sqrt(T t)
Definition: SSEVec.h:48
T z() const
Definition: PV3DBase.h:64
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to the given id.
Definition: CSCChamber.cc:39
float xfit(float z) const
Definition: CSCSegFit.cc:455
#define M_PI
double dPhiFineMax
Definition: CSCSegAlgoDF.h:137
double dRPhiFineMax
Definition: CSCSegAlgoDF.h:136
const CSCChamber * theChamber
Definition: CSCSegAlgoDF.h:117
T x() const
Definition: PV3DBase.h:62
float yfit(float z) const
Definition: CSCSegFit.cc:461
void CSCSegAlgoDF::pruneFromResidual ( void  )
private

Prune bad segment from the worse hit based on residuals

Definition at line 551 of file CSCSegAlgoDF.cc.

References CSCRecHit2D::cscDetId(), j, CSCChamber::layer(), CSCDetId::layer(), CSCRecHit2D::localPosition(), maxRatioResidual, protoSegment, CSCSegFit::Rdev(), sfit_, theChamber, GeomDet::toGlobal(), GeomDet::toLocal(), updateParameters(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by buildSegments().

551  {
552 
553  // Only prune if have at least 5 hits
554  if ( protoSegment.size() < 5 ) return ;
555 
556  // Now Study residuals
557 
558  float maxResidual = 0.;
559  float sumResidual = 0.;
560  int nHits = 0;
561  int badIndex = -1;
562  int j = 0;
563 
564 
565  ChamberHitContainer::const_iterator ih;
566 
567  for ( ih = protoSegment.begin(); ih != protoSegment.end(); ++ih ) {
568  const CSCRecHit2D& hit = (**ih);
569  const CSCLayer* layer = theChamber->layer(hit.cscDetId().layer());
570  GlobalPoint gp = layer->toGlobal(hit.localPosition());
571  LocalPoint lp = theChamber->toLocal(gp);
572 
573  float residual = sfit_->Rdev(lp.x(), lp.y(), lp.z());
574 
575  sumResidual += residual;
576  nHits++;
577  if ( residual > maxResidual ) {
578  maxResidual = residual;
579  badIndex = j;
580  }
581  j++;
582  }
583 
584  float corrAvgResidual = (sumResidual - maxResidual)/(nHits -1);
585 
586  // Keep all hits
587  if ( maxResidual/corrAvgResidual < maxRatioResidual ) return;
588 
589 
590  // Drop worse hit and recompute segment properties + fill
591 
592  ChamberHitContainer newProtoSegment;
593 
594  j = 0;
595  for ( ih = protoSegment.begin(); ih != protoSegment.end(); ++ih ) {
596  if ( j != badIndex ) newProtoSegment.push_back(*ih);
597  j++;
598  }
599 
600  protoSegment.clear();
601 
602  for ( ih = newProtoSegment.begin(); ih != newProtoSegment.end(); ++ih ) {
603  protoSegment.push_back(*ih);
604  }
605 
606  // Compute segment parameters
608 
609 }
ChamberHitContainer protoSegment
Definition: CSCSegAlgoDF.h:122
std::vector< const CSCRecHit2D * > ChamberHitContainer
Definition: CSCSegAlgoDF.h:56
CSCDetId cscDetId() const
Definition: CSCRecHit2D.h:52
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:52
T y() const
Definition: PV3DBase.h:63
float Rdev(float x, float y, float z) const
Definition: CSCSegFit.cc:473
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:67
int layer() const
Definition: CSCDetId.h:74
CSCSegFit * sfit_
Definition: CSCSegAlgoDF.h:145
void updateParameters(void)
T z() const
Definition: PV3DBase.h:64
int j
Definition: DBlmapReader.cc:9
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to the given id.
Definition: CSCChamber.cc:39
float maxRatioResidual
Definition: CSCSegAlgoDF.h:141
const CSCChamber * theChamber
Definition: CSCSegAlgoDF.h:117
LocalPoint localPosition() const
Definition: CSCRecHit2D.h:50
T x() const
Definition: PV3DBase.h:62
std::vector< CSCSegment > CSCSegAlgoDF::run ( const CSCChamber aChamber,
const ChamberHitContainer rechits 
)

Here we must implement the algorithm

Definition at line 69 of file CSCSegAlgoDF.cc.

References buildSegments(), CSCSegAlgoPreClustering::clusterHits(), minHitsForPreClustering, preCluster_, preClustering, and theChamber.

69  {
70 
71  // Store chamber info in temp memory
72  theChamber = aChamber;
73 
74  int nHits = rechits.size();
75 
76  // Segments prior to pruning
77  std::vector<CSCSegment> segments_temp;
78 
79  if ( preClustering && nHits > minHitsForPreClustering ) {
80  // This is where the segment origin is in the chamber on avg.
81  std::vector<CSCSegment> testSegments;
82  std::vector<ChamberHitContainer> clusteredHits = preCluster_->clusterHits(theChamber, rechits);
83  // loop over the found clusters:
84  for (std::vector<ChamberHitContainer>::iterator subrechits = clusteredHits.begin(); subrechits != clusteredHits.end(); ++subrechits ) {
85  // build the subset of segments:
86  std::vector<CSCSegment> segs = buildSegments( (*subrechits) );
87  // add the found subset of segments to the collection of all segments in this chamber:
88  segments_temp.insert( segments_temp.end(), segs.begin(), segs.end() );
89  }
90  } else {
91  std::vector<CSCSegment> segs = buildSegments( rechits );
92  // add the found subset of segments to the collection of all segments in this chamber:
93  segments_temp.insert( segments_temp.end(), segs.begin(), segs.end() );
94  }
95 
96  return segments_temp;
97 }
CSCSegAlgoPreClustering * preCluster_
Definition: CSCSegAlgoDF.h:143
bool preClustering
Definition: CSCSegAlgoDF.h:127
std::vector< CSCSegment > buildSegments(const ChamberHitContainer &rechits)
int minHitsForPreClustering
Definition: CSCSegAlgoDF.h:128
std::vector< std::vector< const CSCRecHit2D * > > clusterHits(const CSCChamber *aChamber, const ChamberHitContainer &rechits)
clusterize
const CSCChamber * theChamber
Definition: CSCSegAlgoDF.h:117
void CSCSegAlgoDF::tryAddingHitsToSegment ( const ChamberHitContainer rechitsInChamber,
const ChamberHitContainerCIt  i1,
const ChamberHitContainerCIt  i2,
const LayerIndex layerIndex 
)
private

Utility functions.

Try adding non-used hits to segment
Skip the layers containing the segment endpoints on first 2 passes, but then
try hits on layer containing the segment starting points on 2nd and/or 3rd pass
if segment has >2 hits. Test each hit on the other layers to see if it is near
the segment using rechit error matrix.
If it is, see whether there is already a hit on the segment from the same layer

  • if so, and there are more than 2 hits on the segment, copy the segment,
    replace the old hit with the new hit. If the new segment chi2 is better
    then replace the original segment with the new one
  • if not, copy the segment, add the hit if it's within a certain range.

Definition at line 286 of file CSCSegAlgoDF.cc.

References addHit(), closeHits, compareProtoSegment(), h, hasHitOnLayer(), i, cuy::ib, isHitNearSegment(), protoSegment, updateParameters(), and usedHits.

Referenced by buildSegments().

289  {
290 
291 /* Iterate over the layers with hits in the chamber
292  * Skip the layers containing the segment endpoints on first pass, but then
293  * try hits on layer containing the segment starting points on 2nd pass
294  * if segment has >2 hits. Once a hit is added to a layer, don't replace it
295  * until 2nd iteration
296  */
297 
298 
299 // std::cout << "[CSCSegAlgoDF::tryAddingHitsToSegment] entering"
300 // << " with rechits.size() = " << rechits.size() << std::endl;
301 
303  ChamberHitContainerCIt ie = rechits.end();
304  closeHits.clear();
305 
306 
307  // int counter1 = 0;
308  // int counter2 = 0;
309 
310  for ( ChamberHitContainerCIt i = ib; i != ie; ++i ) {
311  // std::cout << "counter1 = " << ++counter1 << std::endl;
312  if (i == i1 || i == i2 ) continue;
313  if ( usedHits[i-ib] ) continue; // Don't use hits already part of a segment.
314 
315  // std::cout << "counter2 = " << ++counter2 << std::endl;
316  const CSCRecHit2D* h = *i;
317  int layer = layerIndex[i-ib];
318  int layer1 = layerIndex[i1-ib];
319  int layer2 = layerIndex[i2-ib];
320 
321  // std::cout << "[CSCSegAlgoDF::tryAddingHitsToSegment] layer, layer1, layer2 = "
322  // << layer << ", " << layer1 << ", " << layer2 << std::endl;
323 
324  // Low multiplicity case
325  // only adds hit to protoSegment if no hit on layer already; otherwise adds to closeHits
326  if (rechits.size() < 9) {
327  // std::cout << "low mult" << std::endl;
328  if ( isHitNearSegment( h ) ) {
329  if ( !hasHitOnLayer(layer) ) {
330  addHit(h, layer);
331  } else {
332  closeHits.push_back(h);
333  }
334  }
335 
336  // High multiplicity case
337  // only adds hit to protoSegment if no hit on layer already AND then refits; otherwise adds to closeHits
338  } else {
339  // std::cout << "high mult" << std::endl;
340  if ( isHitNearSegment( h ) ) {
341  // std::cout << "near seg" << std::endl;
342  if ( !hasHitOnLayer(layer) ) {
343  // std::cout << "no hit on layer" << std::endl;
344  if ( addHit(h, layer) ) {
345  // std::cout << "update fit" << std::endl;
347  }
348  // Don't change the starting points at this stage !!!
349  } else {
350  // std::cout << "already hit on layer" << std::endl;
351  closeHits.push_back(h);
352  if (layer != layer1 && layer != layer2 ) compareProtoSegment(h, layer);
353  }
354  }
355  }
356  }
357 
358  if ( int(protoSegment.size()) < 3) return;
359  // std::cout << "final fit" << std::endl;
361 
362  // 2nd pass to remove biases
363  // This time, also consider changing the endpoints
364  for ( ChamberHitContainerCIt i = closeHits.begin() ; i != closeHits.end(); ++i ) {
365  // std::cout << "2nd pass" << std::endl;
366  const CSCRecHit2D* h = *i;
367  int layer = (*i)->cscDetId().layer();
368  compareProtoSegment(h, layer);
369  }
370 
371 }
int i
Definition: DBlmapReader.cc:9
ChamberHitContainer protoSegment
Definition: CSCSegAlgoDF.h:122
std::vector< const CSCRecHit2D * >::const_iterator ChamberHitContainerCIt
Definition: CSCSegAlgoDF.h:57
int ib
Definition: cuy.py:660
ChamberHitContainer closeHits
Definition: CSCSegAlgoDF.h:120
bool addHit(const CSCRecHit2D *hit, int layer)
bool isHitNearSegment(const CSCRecHit2D *h) const
void updateParameters(void)
void compareProtoSegment(const CSCRecHit2D *h, int layer)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
BoolContainer usedHits
Definition: CSCSegAlgoDF.h:118
bool hasHitOnLayer(int layer) const
void CSCSegAlgoDF::updateParameters ( void  )
private

Definition at line 442 of file CSCSegAlgoDF.cc.

References CSCSegFit::fit(), protoSegment, sfit_, and theChamber.

Referenced by buildSegments(), pruneFromResidual(), and tryAddingHitsToSegment().

442  {
443 
444  // Delete existing CSCSegFit, create a new one and make the fit
445  // Uses internal variables - theChamber & protoSegment
446 
447  // std::cout << "[CSCSegAlgoDF::updateParameters] about to delete sfit_ = " << sfit_ << std::endl;
448  delete sfit_;
449  // std::cout << "[CSCSegAlgoDF::updateParameters] protoSegment.size() = "
450  // << protoSegment.size() << std::endl;
451  // std::cout << "[CSCSegAlgoDF::updateParameters] theChamber = " << theChamber << std::endl;
453  // std::cout << "[CSCSegAlgoDF::updateParameters] new sfit_ = " << sfit_ << std::endl;
454  sfit_->fit();
455 }
void fit(void)
Definition: CSCSegFit.cc:14
ChamberHitContainer protoSegment
Definition: CSCSegAlgoDF.h:122
CSCSegFit * sfit_
Definition: CSCSegAlgoDF.h:145
const CSCChamber * theChamber
Definition: CSCSegAlgoDF.h:117

Member Data Documentation

float CSCSegAlgoDF::chi2Max
private

Definition at line 140 of file CSCSegAlgoDF.h.

Referenced by buildSegments(), and CSCSegAlgoDF().

ChamberHitContainer CSCSegAlgoDF::closeHits
private

Definition at line 120 of file CSCSegAlgoDF.h.

Referenced by flagHitsAsUsed(), and tryAddingHitsToSegment().

bool CSCSegAlgoDF::debug
private

Definition at line 126 of file CSCSegAlgoDF.h.

Referenced by buildSegments(), and CSCSegAlgoDF().

double CSCSegAlgoDF::dPhiFineMax
private

Definition at line 137 of file CSCSegAlgoDF.h.

Referenced by CSCSegAlgoDF(), and isHitNearSegment().

double CSCSegAlgoDF::dRPhiFineMax
private

Definition at line 136 of file CSCSegAlgoDF.h.

Referenced by CSCSegAlgoDF(), and isHitNearSegment().

float CSCSegAlgoDF::maxRatioResidual
private

Definition at line 141 of file CSCSegAlgoDF.h.

Referenced by CSCSegAlgoDF(), and pruneFromResidual().

int CSCSegAlgoDF::minHitsForPreClustering
private

Definition at line 128 of file CSCSegAlgoDF.h.

Referenced by CSCSegAlgoDF(), and run().

int CSCSegAlgoDF::minHitsPerSegment
private

Definition at line 134 of file CSCSegAlgoDF.h.

Referenced by buildSegments(), and CSCSegAlgoDF().

int CSCSegAlgoDF::minLayersApart
private

Definition at line 131 of file CSCSegAlgoDF.h.

Referenced by buildSegments(), and CSCSegAlgoDF().

const std::string CSCSegAlgoDF::myName
private

Definition at line 116 of file CSCSegAlgoDF.h.

int CSCSegAlgoDF::nHitsPerClusterIsShower
private

Definition at line 132 of file CSCSegAlgoDF.h.

Referenced by buildSegments(), and CSCSegAlgoDF().

CSCSegAlgoPreClustering* CSCSegAlgoDF::preCluster_
private

Definition at line 143 of file CSCSegAlgoDF.h.

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

bool CSCSegAlgoDF::preClustering
private

Definition at line 127 of file CSCSegAlgoDF.h.

Referenced by buildSegments(), CSCSegAlgoDF(), and run().

ChamberHitContainer CSCSegAlgoDF::protoSegment
private
bool CSCSegAlgoDF::Pruning
private

Definition at line 130 of file CSCSegAlgoDF.h.

Referenced by buildSegments(), and CSCSegAlgoDF().

ChamberHitContainer CSCSegAlgoDF::secondSeedHits
private

Definition at line 123 of file CSCSegAlgoDF.h.

CSCSegFit* CSCSegAlgoDF::sfit_
private
CSCSegAlgoShowering* CSCSegAlgoDF::showering_
private

Definition at line 144 of file CSCSegAlgoDF.h.

Referenced by buildSegments(), CSCSegAlgoDF(), and ~CSCSegAlgoDF().

float CSCSegAlgoDF::tanPhiMax
private

Definition at line 138 of file CSCSegAlgoDF.h.

Referenced by buildSegments(), and CSCSegAlgoDF().

float CSCSegAlgoDF::tanThetaMax
private

Definition at line 139 of file CSCSegAlgoDF.h.

Referenced by buildSegments(), and CSCSegAlgoDF().

const CSCChamber* CSCSegAlgoDF::theChamber
private
BoolContainer CSCSegAlgoDF::usedHits
private

Definition at line 118 of file CSCSegAlgoDF.h.

Referenced by buildSegments(), flagHitsAsUsed(), and tryAddingHitsToSegment().