28 myName(
"CSCSegAlgoTC") {
42 <<
"--------------------------------------------------------------------\n"
43 <<
"dRPhiMax = " << dRPhiMax <<
'\n'
44 <<
"dPhiMax = " << dPhiMax <<
'\n'
45 <<
"dRPhiFineMax = " << dRPhiFineMax <<
'\n'
46 <<
"dPhiFineMax = " << dPhiFineMax <<
'\n'
47 <<
"chi2Max = " << chi2Max <<
'\n'
48 <<
"chi2ndfProbMin = " << chi2ndfProbMin <<
'\n'
49 <<
"minLayersApart = " << minLayersApart <<
'\n'
50 <<
"SegmentSorting = " << SegmentSorting << std::endl;
62 LogDebug(
"CSC") <<
"*********************************************";
64 LogDebug(
"CSC") <<
"*********************************************";
68 for(
unsigned int i = 0;
i < rechits.size();
i++) {
70 layerIndex[
i] = rechits[
i]->cscDetId().layer();
78 reverse(layerIndex.begin(), layerIndex.end());
79 reverse(rechits.begin(), rechits.end());
84 reverse(layerIndex.begin(), layerIndex.end());
85 reverse(rechits.begin(), rechits.end());
94 if (rechits.size() < 2) {
96 " hit(s) in chamber is not enough to build a segment.\n";
97 return std::vector<CSCSegment>();
117 std::vector<CSCSegment> segments;
124 int layer1 = layerIndex[i1-
ib];
129 int layer2 = layerIndex[i2-
ib];
144 LogDebug(
"CSC") <<
"start new segment from hits " <<
"h1: " << gp1 <<
" - h2: " << gp2 <<
"\n";
146 if (!
addHit(h1, layer1)) {
147 LogDebug(
"CSC") <<
" failed to add hit h1\n";
151 if (!
addHit(h2, layer2)) {
152 LogDebug(
"CSC") <<
" failed to add hit h2\n";
161 LogDebug(
"CSC") <<
"No segment has been found !!!\n";
175 errors.push_back(error_matrix);
177 LogDebug(
"CSC") <<
"Found a segment !!!\n";
190 segments.push_back(temp);
221 if (
i == i1 ||
i == i2 )
224 int layer = (*i)->cscDetId().layer();
231 LogDebug(
"CSC") <<
" hit at global " << gp1 <<
" is near segment\n.";
236 <<
" hits on segment...skip hit on same layer.\n";
254 ChamberHitContainer::const_iterator it;
257 if (((*it)->cscDetId().layer() == layer) && (aHit != *it))
270 ChamberHitContainer::iterator it;
272 if ((*it)->cscDetId().layer() == layer)
303 ChamberHitContainer::const_iterator ih =
proto_segment.begin();
304 int il1 = (*ih)->cscDetId().layer();
307 int il2 = (*ih)->cscDetId().layer();
327 float dz = h2pos.
z()-h1pos.
z();
328 uz = (h2pos.
x()-h1pos.
x())/dz ;
329 vz = (h2pos.
y()-h1pos.
y())/dz ;
424 CLHEP::HepMatrix M(4,4,0);
425 CLHEP::HepVector
B(4,0);
427 ChamberHitContainer::const_iterator ih =
proto_segment.begin();
442 CLHEP::HepMatrix IC(2,2);
443 IC(1,1) = hit.localPositionError().xx();
444 IC(1,2) = hit.localPositionError().xy();
446 IC(2,2) = hit.localPositionError().yy();
452 LogDebug(
"CSC") <<
"CSCSegment::fitSlopes: failed to invert covariance matrix=\n" << IC <<
"\n";
460 M(1,3) += IC(1,1) *
z;
461 M(1,4) += IC(1,2) *
z;
462 B(1) += u * IC(1,1) + v * IC(1,2);
466 M(2,3) += IC(2,1) *
z;
467 M(2,4) += IC(2,2) *
z;
468 B(2) += u * IC(2,1) + v * IC(2,2);
470 M(3,1) += IC(1,1) *
z;
471 M(3,2) += IC(1,2) *
z;
472 M(3,3) += IC(1,1) * z *
z;
473 M(3,4) += IC(1,2) * z *
z;
474 B(3) += ( u * IC(1,1) + v * IC(1,2) ) * z;
476 M(4,1) += IC(2,1) *
z;
477 M(4,2) += IC(2,2) *
z;
478 M(4,3) += IC(2,1) * z *
z;
479 M(4,4) += IC(2,2) * z *
z;
480 B(4) += ( u * IC(2,1) + v * IC(2,2) ) * z;
485 CLHEP::HepVector
p = solve(M, B);
503 ChamberHitContainer::const_iterator ih;
515 double du = u0 +
uz * hz - hu;
516 double dv = v0 +
vz * hz -
hv;
518 CLHEP::HepMatrix IC(2,2);
519 IC(1,1) = hit.localPositionError().xx();
520 IC(1,2) = hit.localPositionError().xy();
522 IC(2,2) = hit.localPositionError().yy();
528 LogDebug(
"CSC") <<
"CSCSegment::fillChiSquared: failed to invert covariance matrix=\n" << IC <<
"\n";
533 chsq += du*du*IC(1,1) + 2.*du*dv*IC(1,2) + dv*dv*IC(2,2);
545 double dz = 1./
sqrt(1. + dxdz*dxdz + dydz*dydz);
556 double directionSign = globalZpos * globalZdir;
568 float x = gp.
x() + (gv.
x()/gv.
z())*(z - gp.
z());
569 float y = gp.
y() + (gv.
y()/gv.
z())*(z - gp.
z());
570 float phi = atan2(y, x);
588 LogDebug(
"CSC") <<
" hit in same layer as a hit on segment; try replacing old one..."
589 <<
" chi2 new: " <<
theChi2 <<
" old: " << oldChi2 <<
"\n";
592 if ((
theChi2 < oldChi2) && (ok)) {
593 LogDebug(
"CSC") <<
" segment with replaced hit is better.\n";
613 LogDebug(
"CSC") <<
" hit in new layer: added to segment, new chi2: "
620 LogDebug(
"CSC") <<
" segment with added hit is good.\n" ;
631 float h1x = h1->localPosition().x();
632 float h2x = h2->localPosition().x();
633 float deltaX = (h1->localPosition()-h2->localPosition()).
x();
634 LogDebug(
"CSC") <<
" Hits at local x= " << h1x <<
", "
635 << h2x <<
" have separation= " << deltaX;
636 return (fabs(deltaX) < (
dRPhiMax))?
true:
false;
646 float h1p = gp1.
phi();
647 float h2p = gp2.
phi();
648 float dphi12 = h1p - h2p;
655 LogDebug(
"CSC") <<
" Hits at global phi= " << h1p <<
", "
656 << h2p <<
" have separation= " << dphi12;
657 return (fabs(dphi12) <
dPhiMax)?
true:
false;
671 float hphi = hp.
phi();
675 float phidif = sphi-hphi;
681 float dRPhi = fabs(phidif)*hp.
perp();
682 LogDebug(
"CSC") <<
" is hit at phi_h= " << hphi <<
" near segment phi_seg= " << sphi
684 <<
" and is |" << phidif <<
"|<" <<
dPhiFineMax <<
" ?";
687 (fabs(phidif) < dPhiFineMax))?
true:
false;
696 if ((*it)->cscDetId().layer() == layer)
707 for(it=rechits.begin(); it!=rechits.end(); it++) {
712 LogDebug(
"CSC") <<
"Global pos.: " << gp1 <<
", phi: " << gp1.
phi() <<
". Local position: "
713 << (*it)->localPosition() <<
", phi: "
714 << (*it)->localPosition().
phi() <<
". Layer: "
715 << (*it)->cscDetId().layer() <<
"\n";
731 unsigned int iadd = (rechitsInChamber.size() > 20 )? 1 : 0;
733 if (seg->size() < 3 + iadd)
742 if( (*chi2) != 0 && ((2*seg->size())-4) >0 ) {
747 if((*chi2) == 0 )
return false;
751 for(
unsigned int ish = 0; ish < seg->size(); ++ish) {
757 if(((*seg)[ish] == (*ic)) && used[ic-
ib])
772 for(
unsigned int ish = 0; ish < seg->size(); ish++) {
775 if((*seg)[ish] == (*iu))
798 std::vector<ChamberHitContainer>::iterator is;
799 std::vector<double>::iterator ichi =
chi2s.begin();
800 std::vector<AlgebraicSymMatrix>::iterator iErr =
errors.begin();
801 std::vector<LocalPoint>::iterator iOrig =
origins.begin();
802 std::vector<LocalVector>::iterator iDir =
directions.begin();
806 bool goodSegment =
isSegmentGood(is, ichi, rechitsInChamber, used);
809 LogDebug(
"CSC") <<
"Accepting segment: ";
819 LogDebug(
"CSC") <<
"Rejecting segment: ";
821 ichi =
chi2s.erase(ichi);
822 iErr =
errors.erase(iErr);
867 if(
chi2s[
i] != 0. && 2*n2-4 > 0 ) {
916 LogDebug(
"CSC") <<
"No valid segment sorting specified - BAD !!!\n";
939 ChamberHitContainer::const_iterator it;
941 CLHEP::HepMatrix
matrix(2*nhits, 4);
964 std::vector<const CSCRecHit2D*>::const_iterator it;
973 matrix(row, row) = hit.localPositionError().xx();
974 matrix(row, row+1) = hit.localPositionError().xy();
976 matrix(row, row-1) = hit.localPositionError().xy();
977 matrix(row, row) = hit.localPositionError().yy();
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void fillLocalDirection()
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
std::vector< CSCSegment > buildSegments(const ChamberHitContainer &rechits)
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
Abs< T >::type abs(const T &t)
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)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
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 > run(const CSCChamber *aChamber, const ChamberHitContainer &rechits)
ChamberHitContainer proto_segment
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
CLHEP::HepSymMatrix AlgebraicSymMatrix
std::vector< int > LayerIndex
Typedefs.
std::vector< ChamberHitContainer > candidates
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.