30 myName(
"CSCSegAlgoTC") {
44 <<
"--------------------------------------------------------------------\n"
45 <<
"dRPhiMax = " << dRPhiMax <<
'\n'
46 <<
"dPhiMax = " << dPhiMax <<
'\n'
47 <<
"dRPhiFineMax = " << dRPhiFineMax <<
'\n'
48 <<
"dPhiFineMax = " << dPhiFineMax <<
'\n'
49 <<
"chi2Max = " << chi2Max <<
'\n'
50 <<
"chi2ndfProbMin = " << chi2ndfProbMin <<
'\n'
51 <<
"minLayersApart = " << minLayersApart <<
'\n'
52 <<
"SegmentSorting = " << SegmentSorting << std::endl;
64 LogDebug(
"CSC") <<
"*********************************************";
66 LogDebug(
"CSC") <<
"*********************************************";
70 for(
unsigned int i = 0;
i < rechits.size();
i++) {
72 layerIndex[
i] = rechits[
i]->cscDetId().layer();
80 reverse(layerIndex.begin(), layerIndex.end());
81 reverse(rechits.begin(), rechits.end());
86 reverse(layerIndex.begin(), layerIndex.end());
87 reverse(rechits.begin(), rechits.end());
96 if (rechits.size() < 2) {
98 " hit(s) in chamber is not enough to build a segment.\n";
99 return std::vector<CSCSegment>();
119 std::vector<CSCSegment> segments;
126 int layer1 = layerIndex[i1-ib];
131 int layer2 = layerIndex[i2-ib];
146 LogDebug(
"CSC") <<
"start new segment from hits " <<
"h1: " << gp1 <<
" - h2: " << gp2 <<
"\n";
148 if (!
addHit(h1, layer1)) {
149 LogDebug(
"CSC") <<
" failed to add hit h1\n";
153 if (!
addHit(h2, layer2)) {
154 LogDebug(
"CSC") <<
" failed to add hit h2\n";
163 LogDebug(
"CSC") <<
"No segment has been found !!!\n";
177 errors.push_back(error_matrix);
179 LogDebug(
"CSC") <<
"Found a segment !!!\n";
192 segments.push_back(temp);
223 if (
i == i1 ||
i == i2 )
226 int layer = (*i)->cscDetId().layer();
233 LogDebug(
"CSC") <<
" hit at global " << gp1 <<
" is near segment\n.";
238 <<
" hits on segment...skip hit on same layer.\n";
256 ChamberHitContainer::const_iterator it;
259 if (((*it)->cscDetId().layer() == layer) && (aHit != *it))
272 ChamberHitContainer::iterator it;
274 if ((*it)->cscDetId().layer() == layer)
305 ChamberHitContainer::const_iterator ih =
proto_segment.begin();
306 int il1 = (*ih)->cscDetId().layer();
329 float dz = h2pos.
z()-h1pos.
z();
330 uz = (h2pos.
x()-h1pos.
x())/dz ;
331 vz = (h2pos.
y()-h1pos.
y())/dz ;
426 CLHEP::HepMatrix M(4,4,0);
427 CLHEP::HepVector
B(4,0);
429 ChamberHitContainer::const_iterator ih =
proto_segment.begin();
444 CLHEP::HepMatrix IC(2,2);
454 LogDebug(
"CSC") <<
"CSCSegment::fitSlopes: failed to invert covariance matrix=\n" << IC <<
"\n";
462 M(1,3) += IC(1,1) *
z;
463 M(1,4) += IC(1,2) *
z;
464 B(1) += u * IC(1,1) + v * IC(1,2);
468 M(2,3) += IC(2,1) *
z;
469 M(2,4) += IC(2,2) *
z;
470 B(2) += u * IC(2,1) + v * IC(2,2);
472 M(3,1) += IC(1,1) *
z;
473 M(3,2) += IC(1,2) *
z;
474 M(3,3) += IC(1,1) * z *
z;
475 M(3,4) += IC(1,2) * z *
z;
476 B(3) += ( u * IC(1,1) + v * IC(1,2) ) * z;
478 M(4,1) += IC(2,1) *
z;
479 M(4,2) += IC(2,2) *
z;
480 M(4,3) += IC(2,1) * z *
z;
481 M(4,4) += IC(2,2) * z *
z;
482 B(4) += ( u * IC(2,1) + v * IC(2,2) ) * z;
487 CLHEP::HepVector
p = solve(M, B);
505 ChamberHitContainer::const_iterator ih;
517 double du = u0 +
uz * hz - hu;
518 double dv = v0 +
vz * hz - hv;
520 CLHEP::HepMatrix IC(2,2);
530 LogDebug(
"CSC") <<
"CSCSegment::fillChiSquared: failed to invert covariance matrix=\n" << IC <<
"\n";
535 chsq += du*du*IC(1,1) + 2.*du*dv*IC(1,2) + dv*dv*IC(2,2);
547 double dz = 1./
sqrt(1. + dxdz*dxdz + dydz*dydz);
558 double directionSign = globalZpos * globalZdir;
570 float x = gp.
x() + (gv.
x()/gv.
z())*(z - gp.
z());
571 float y = gp.
y() + (gv.
y()/gv.
z())*(z - gp.
z());
572 float phi = atan2(y, x);
590 LogDebug(
"CSC") <<
" hit in same layer as a hit on segment; try replacing old one..."
591 <<
" chi2 new: " <<
theChi2 <<
" old: " << oldChi2 <<
"\n";
594 if ((
theChi2 < oldChi2) && (ok)) {
595 LogDebug(
"CSC") <<
" segment with replaced hit is better.\n";
615 LogDebug(
"CSC") <<
" hit in new layer: added to segment, new chi2: "
622 LogDebug(
"CSC") <<
" segment with added hit is good.\n" ;
636 LogDebug(
"CSC") <<
" Hits at local x= " << h1x <<
", "
637 << h2x <<
" have separation= " << deltaX;
638 return (fabs(deltaX) < (
dRPhiMax))?
true:
false;
648 float h1p = gp1.
phi();
649 float h2p = gp2.
phi();
650 float dphi12 = h1p - h2p;
657 LogDebug(
"CSC") <<
" Hits at global phi= " << h1p <<
", "
658 << h2p <<
" have separation= " << dphi12;
659 return (fabs(dphi12) <
dPhiMax)?
true:
false;
673 float hphi = hp.
phi();
677 float phidif = sphi-hphi;
683 float dRPhi = fabs(phidif)*hp.
perp();
684 LogDebug(
"CSC") <<
" is hit at phi_h= " << hphi <<
" near segment phi_seg= " << sphi
686 <<
" and is |" << phidif <<
"|<" <<
dPhiFineMax <<
" ?";
689 (fabs(phidif) < dPhiFineMax))?
true:
false;
698 if ((*it)->cscDetId().layer() == layer)
709 for(it=rechits.begin(); it!=rechits.end(); it++) {
714 LogDebug(
"CSC") <<
"Global pos.: " << gp1 <<
", phi: " << gp1.
phi() <<
". Local position: "
715 << (*it)->localPosition() <<
", phi: "
716 << (*it)->localPosition().phi() <<
". Layer: "
717 << (*it)->cscDetId().layer() <<
"\n";
733 unsigned int iadd = (rechitsInChamber.size() > 20 )? 1 : 0;
735 if (seg->size() < 3 + iadd)
744 if( (*chi2) != 0 && ((2*seg->size())-4) >0 ) {
749 if((*chi2) == 0 )
return false;
753 for(
unsigned int ish = 0; ish < seg->size(); ++ish) {
759 if(((*seg)[ish] == (*ic)) && used[ic-ib])
774 for(
unsigned int ish = 0; ish < seg->size(); ish++) {
777 if((*seg)[ish] == (*iu))
800 std::vector<ChamberHitContainer>::iterator is;
801 std::vector<double>::iterator ichi =
chi2s.begin();
802 std::vector<AlgebraicSymMatrix>::iterator iErr =
errors.begin();
803 std::vector<LocalPoint>::iterator iOrig =
origins.begin();
804 std::vector<LocalVector>::iterator iDir =
directions.begin();
808 bool goodSegment =
isSegmentGood(is, ichi, rechitsInChamber, used);
811 LogDebug(
"CSC") <<
"Accepting segment: ";
821 LogDebug(
"CSC") <<
"Rejecting segment: ";
823 ichi =
chi2s.erase(ichi);
824 iErr =
errors.erase(iErr);
869 if(
chi2s[
i] != 0. && 2*n2-4 > 0 ) {
918 LogDebug(
"CSC") <<
"No valid segment sorting specified - BAD !!!\n";
941 ChamberHitContainer::const_iterator it;
943 CLHEP::HepMatrix
matrix(2*nhits, 4);
966 std::vector<const CSCRecHit2D*>::const_iterator it;
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void fillLocalDirection()
CSCDetId cscDetId() const
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Geom::Phi< T > phi() const
std::vector< AlgebraicSymMatrix > errors
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
void compareProtoSegment(const CSCRecHit2D *h, int layer)
AlgebraicSymMatrix weightMatrix() const
std::deque< bool > BoolContainer
float phiAtZ(float z) const
AlgebraicSymMatrix calculateError() const
bool areHitsCloseInLocalX(const CSCRecHit2D *h1, const CSCRecHit2D *h2) const
bool isHitNearSegment(const CSCRecHit2D *h) const
std::string chamberTypeName() const
void dumpHits(const ChamberHitContainer &rechits) const
const Surface::PositionType & position() const
The position (origin of the R.F.)
const CSCChamberSpecs * specs() const
CLHEP::HepMatrix AlgebraicMatrix
std::vector< double > chi2s
LocalError localPositionError() const
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to the given id.
void flagHitsAsUsed(std::vector< ChamberHitContainer >::iterator is, const ChamberHitContainer &rechitsInChamber, BoolContainer &used) const
float ChiSquaredProbability(double chiSquared, double nrDOF)
bool isSegmentGood(std::vector< ChamberHitContainer >::iterator is, std::vector< double >::iterator ichi, const ChamberHitContainer &rechitsInChamber, BoolContainer &used) const
bool areHitsCloseInGlobalPhi(const CSCRecHit2D *h1, const CSCRecHit2D *h2) const
bool addHit(const CSCRecHit2D *aHit, int layer)
Utility functions.
const CSCChamber * theChamber
Member variables.
std::vector< CSCSegment > buildSegments(ChamberHitContainer rechits)
ChamberHitContainer proto_segment
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
std::vector< const CSCRecHit2D * > ChamberHitContainer
std::vector< LocalPoint > origins
void tryAddingHitsToSegment(const ChamberHitContainer &rechits, const ChamberHitContainerCIt i1, const ChamberHitContainerCIt i2)
bool hasHitOnLayer(int layer) const
CLHEP::HepMatrix derivativeMatrix() const
std::vector< CSCSegment > run(const CSCChamber *aChamber, ChamberHitContainer rechits)
CLHEP::HepSymMatrix AlgebraicSymMatrix
std::vector< int > LayerIndex
Typedefs.
std::vector< ChamberHitContainer > candidates
LocalPoint localPosition() const
ChamberHitContainer::const_iterator ChamberHitContainerCIt
void increaseProtoSegment(const CSCRecHit2D *h, int layer)
void pruneTheSegments(const ChamberHitContainer &rechitsInChamber)
void flipErrors(AlgebraicSymMatrix &) const
bool replaceHit(const CSCRecHit2D *h, int layer)
CSCSegAlgoTC(const edm::ParameterSet &ps)
Constructor.