496 static const double rphiHitSmallestError = 0.0001 ;
497 static const double stereoHitSmallestError = 0.0001 ;
502 static const double stereoPitchAngle = 0.100 ;
503 static const double cos2SiPitchAngle =
cos(stereoPitchAngle)*
cos(stereoPitchAngle) ;
504 static const double sin2SiPitchAngle =
sin(stereoPitchAngle)*
sin(stereoPitchAngle) ;
507 static const double rphiErrFudge = 0.0200 ;
508 static const double stereoErrFudge = 0.0200 ;
511 static const double chi2HitMax = 25.0 ;
514 static const unsigned int nHitsLeftMinimum = 3 ;
517 std::vector<const SiStripRecHit2D*> stereoHits;
518 std::vector<const SiStripRecHit2D*> rphiBarrelHits;
519 std::vector<const SiStripRecHit2D*> zphiEndcapHits;
528 std::ostringstream debugstr1;
529 debugstr1 <<
" Getting barrel rphi hits " <<
" \n" ;
536 debugstr1 <<
" Getting matched hits " <<
" \n" ;
537 std::vector<const SiStripMatchedRecHit2D*> matchedHits;
542 double energy = superclusterIn->energy();
543 double pT = energy * superclusterIn->position().rho()/
sqrt(superclusterIn->x()*superclusterIn->x() +
544 superclusterIn->y()*superclusterIn->y() +
545 superclusterIn->z()*superclusterIn->z());
550 const double scr = superclusterIn->position().rho();
551 const double scz = superclusterIn->position().z();
554 std::vector<bool> uselist;
555 std::vector<double> rlist, philist, w2list;
556 std::vector<int> typelist;
557 std::vector<const SiStripRecHit2D*> hitlist;
559 std::vector<bool> matcheduselist;
560 std::vector<const SiStripMatchedRecHit2D*> matchedhitlist;
563 double zSlopeFitNumer = 0.;
564 double zSlopeFitDenom = 0.;
567 debugstr1 <<
" There are a total of " << stereoHits.size() <<
" stereoHits in this event " <<
" \n"
568 <<
" There are a total of " << rphiBarrelHits.size() <<
" rphiBarrelHits in this event " <<
" \n"
569 <<
" There are a total of " << zphiEndcapHits.size() <<
" zphiEndcapHits in this event " <<
" \n\n";
580 LogDebug(
"") <<
" Loop over matched hits " <<
" \n";
582 for (std::vector<const SiStripMatchedRecHit2D*>::const_iterator
hit = matchedHits.begin() ;
583 hit != matchedHits.end() ; ++
hit) {
591 double r =
sqrt(position.
x()*position.
x() + position.
y()*position.
y());
592 double phi =
unwrapPhi(position.
phi() - superclusterIn->position().phi());
593 double z = position.
z();
603 matcheduselist.push_back(
true);
604 matchedhitlist.push_back(*hit);
609 zSlopeFitNumer += -(scr -
r) * (z - scz);
610 zSlopeFitDenom += (scr -
r) * (scr - r);
619 if (zSlopeFitDenom > 0.) {
620 zVsRSlope = zSlopeFitNumer / zSlopeFitDenom;
628 LogDebug(
"") <<
" Loop over stereo hits" <<
" \n";
631 unsigned int numberOfStereoHits = 0;
632 for (std::vector<const SiStripRecHit2D*>::const_iterator hit = stereoHits.begin(); hit != stereoHits.end(); ++hit) {
637 double r_stereo =
sqrt(position.x()*position.x() + position.y()*position.y());
638 double phi_stereo =
unwrapPhi(position.phi() - superclusterIn->position().phi());
642 double r_stereo_err =
sqrt((*hit)->localPositionError().xx()*cos2SiPitchAngle +
643 (*hit)->localPositionError().yy()*sin2SiPitchAngle ) ;
649 if(r_stereo_err > stereoHitSmallestError ) {
650 r_stereo_err =
sqrt(r_stereo_err*r_stereo_err+stereoErrFudge*stereoErrFudge);
654 bool thisHitIsMatched =
false ;
658 unsigned int matcheduselist_size = matcheduselist.size();
659 for (
unsigned int i = 0;
i < matcheduselist_size;
i++) {
660 if (matcheduselist[
i]) {
661 OmniClusterRef const & mystereocluster = matchedhitlist[
i]->stereoClusterRef();
662 if( stereocluster == mystereocluster ) {
663 thisHitIsMatched =
true ;
670 if(thisHitIsMatched) {
672 uselist.push_back(
true);
673 rlist.push_back(r_stereo);
674 philist.push_back(phi_stereo);
675 w2list.push_back(1./(r_stereo_err/r_stereo)/(r_stereo_err/r_stereo));
676 typelist.push_back(0);
677 hitlist.push_back(*hit);
685 LogDebug(
"") <<
" There are " << uselist.size() <<
" good hits after stereo loop " ;
689 LogDebug(
"") <<
" Looping over barrel rphi hits " ;
690 unsigned int rphiMatchedCounter = 0 ;
691 unsigned int rphiUnMatchedCounter = 0 ;
692 unsigned int numberOfBarrelRphiHits = 0;
693 for (std::vector<const SiStripRecHit2D*>::const_iterator hit = rphiBarrelHits.begin(); hit != rphiBarrelHits.end(); ++hit) {
697 double r =
sqrt(position.x()*position.x() + position.y()*position.y());
698 double phi =
unwrapPhi(position.phi() - superclusterIn->position().phi());
699 double z = position.z();
700 double r_mono_err =
sqrt((*hit)->localPositionError().xx()) ;
703 if( r_mono_err > rphiHitSmallestError) {
705 r_mono_err=
sqrt(r_mono_err*r_mono_err+rphiErrFudge*rphiErrFudge);
712 (tTopo->
tibLayer((*hit)->geographicalId())==1 || tTopo->
tibLayer((*hit)->geographicalId())==2)) ||
714 && (tTopo->
tobLayer((*hit)->geographicalId())==1 || tTopo->
tobLayer((*hit)->geographicalId())==2)) ) {
715 bool thisHitIsMatched =
false ;
716 unsigned int matcheduselist_size = matcheduselist.size();
717 for (
unsigned int i = 0; i < matcheduselist_size; i++) {
718 if (matcheduselist[i]) {
719 OmniClusterRef const & mymonocluster = matchedhitlist[
i]->monoClusterRef();
720 if( monocluster == mymonocluster ) {
721 thisHitIsMatched =
true ;
727 if( thisHitIsMatched ) {
729 uselist.push_back(
true);
731 philist.push_back(phi);
732 w2list.push_back(1./(r_mono_err/r)/(r_mono_err/r));
733 typelist.push_back(1);
734 hitlist.push_back(*hit);
735 rphiMatchedCounter++;
742 double zFit = zVsRSlope * (r - scr) + scz;
755 uselist.push_back(
true);
757 philist.push_back(phi);
758 w2list.push_back(1./(r_mono_err/r)/(r_mono_err/r));
759 typelist.push_back(1);
760 hitlist.push_back(*hit);
761 rphiUnMatchedCounter++;
770 LogDebug(
"") <<
" There are " << rphiMatchedCounter <<
" matched rphi hits";
771 LogDebug(
"") <<
" There are " << rphiUnMatchedCounter <<
" unmatched rphi hits";
772 LogDebug(
"") <<
" There are " << uselist.size() <<
" good stereo+rphi hits " ;
782 LogDebug(
"") <<
" Looping over barrel zphi hits " ;
785 unsigned int numberOfEndcapZphiHits = 0;
786 for (std::vector<const SiStripRecHit2D*>::const_iterator hit = zphiEndcapHits.begin();
787 hit != zphiEndcapHits.end(); ++hit) {
792 double z = position.
z();
793 double phi =
unwrapPhi(position.
phi() - superclusterIn->position().phi());
797 double rFit = (z - scz)/zVsRSlope + scr;
808 uselist.push_back(
true);
809 rlist.push_back(rFit);
810 philist.push_back(phi);
811 w2list.push_back(1./(0.05/rFit)/(0.05/rFit));
812 typelist.push_back(2);
813 hitlist.push_back(*hit);
819 LogDebug(
"") <<
" There are " << uselist.size() <<
" good stereo+rphi+zphi hits " ;
823 std::ostringstream debugstr5;
824 debugstr5 <<
" List of hits before uniqification " <<
" \n" ;
825 for (
unsigned int i = 0; i < uselist.size(); i++) {
827 const SiStripRecHit2D* hit = hitlist[
i];
828 debugstr5 <<
" DetID " << ((hit)->geographicalId()).rawId()
830 <<
" Phi " << philist[
i]
831 <<
" Weight " << w2list[
i]
832 <<
" PhiPred " << (rlist[
i]-scr)*phiVsRSlope
833 <<
" Chi2 " << (philist[i]-(rlist[i]-scr)*phiVsRSlope)*(philist[i]-(rlist[i]-scr)*phiVsRSlope)*w2list[i]
837 debugstr5 <<
" \n\n\n" ;
839 debugstr5 <<
" Counting number of unique detectors " <<
" \n" ;
841 debugstr5 <<
" These are all the detectors with hits " <<
" \n";
845 std::vector<uint32_t> detIdList ;
847 for (
unsigned int i = 0; i < uselist.size(); i++) {
849 const SiStripRecHit2D* hit = hitlist[
i];
850 uint32_t detIDUsed = ((hit)->geographicalId()).rawId() ;
852 debugstr5<<
" DetId " << detIDUsed <<
"\n";
854 detIdList.push_back(detIDUsed) ;
859 debugstr5 <<
" There are " << detIdList.size() <<
" hits on detectors \n";
862 std::sort(detIdList.begin(), detIdList.end());
864 std::unique(detIdList.begin(), detIdList.end()), detIdList.end());
866 debugstr5 <<
" There are " << detIdList.size() <<
" unique detectors \n";
872 debugstr5 <<
" Looping over detectors to choose best hit " <<
" \n";
875 for (
unsigned int idet = 0 ; idet < detIdList.size() ; idet++ ) {
876 for (
unsigned int i = 0; i+1 < uselist.size(); i++) {
879 const SiStripRecHit2D* hit1 = hitlist[
i];
880 double r_hit1 = rlist[
i];
881 double phi_hit1 = philist[
i];
882 double w2_hit1 = w2list[
i] ;
883 double phi_pred1 = (r_hit1-scr)*phiVsRSlope ;
884 double chi1 = (phi_hit1-phi_pred1)*(phi_hit1-phi_pred1)*w2_hit1;
885 if(detIdList[idet]== ((hit1)->geographicalId()).rawId()) {
886 for (
unsigned int j = i+1;
j < uselist.size();
j++) {
888 const SiStripRecHit2D* hit2 = hitlist[
j];
889 if(detIdList[idet]== ((hit2)->geographicalId()).rawId()) {
891 debugstr5 <<
" Found 2 hits on same Si Detector "
892 << ((hit2)->geographicalId()).rawId() <<
"\n";
895 double r_hit2 = rlist[
j];
896 double phi_hit2 = philist[
j];
897 double w2_hit2 = w2list[
j] ;
898 double phi_pred2 = (r_hit2-scr)*phiVsRSlope ;
899 double chi2 = (phi_hit2-phi_pred2)*(phi_hit2-phi_pred2)*w2_hit2;
901 debugstr5 <<
" Chi1 " << chi1 <<
" Chi2 " << chi2 <<
"\n";
923 for (
unsigned int i = 0; i < uselist.size(); i++ ) {
925 double localchi2 = (philist[
i]-(rlist[
i]-scr)*phiVsRSlope)*(philist[
i]-(rlist[
i]-scr)*phiVsRSlope)*w2list[
i] ;
926 if(localchi2 > chi2HitMax ) {
928 const SiStripRecHit2D* hit = hitlist[
i];
929 debugstr5 <<
" Throwing out "
930 <<
" DetID " << ((hit)->geographicalId()).rawId()
932 <<
" Phi " << philist[
i]
933 <<
" Weight " << w2list[
i]
934 <<
" PhiPred " << (rlist[
i]-scr)*phiVsRSlope
935 <<
" Chi2 " << (philist[i]-(rlist[i]-scr)*phiVsRSlope)*(philist[i]-(rlist[i]-scr)*phiVsRSlope)*w2list[i]
944 debugstr5 <<
" List of hits after uniqification " <<
" \n" ;
945 for (
unsigned int i = 0; i < uselist.size(); i++) {
947 const SiStripRecHit2D* hit = hitlist[
i];
948 debugstr5 <<
" DetID " << ((hit)->geographicalId()).rawId()
950 <<
" Phi " << philist[
i]
951 <<
" Weight " << w2list[
i]
952 <<
" PhiPred " << (rlist[
i]-scr)*phiVsRSlope
953 <<
" Chi2 " << (philist[i]-(rlist[i]-scr)*phiVsRSlope)*(philist[i]-(rlist[i]-scr)*phiVsRSlope)*w2list[i]
957 debugstr5 <<
" \n\n\n" ;
961 unsigned int nHitsLeft =0;
962 for (
unsigned int i = 0; i < uselist.size(); i++) {
967 if(nHitsLeft < nHitsLeftMinimum ) {
969 debugstr5 <<
" Too few hits "<< nHitsLeft
970 <<
" left - return false " <<
" \n";
981 double intercept = 0 ;
985 std::ostringstream debugstr4;
986 debugstr4 <<
" Calc of phi(r) "<<
" \n";
996 double phiBarOld = 0.;
1000 double r2BarOld = 0.;
1001 double phirBar = 0.;
1002 double phirBarOld = 0.;
1003 double totalWeight = 0.;
1004 double totalWeightOld = 0.;
1005 unsigned int uselist_size = uselist.size();
1006 for (
unsigned int i = 0; i < uselist_size; i++) {
1008 double r = rlist[
i];
1009 double phi = philist[
i];
1010 double weight2 = w2list[
i];
1012 totalWeight = totalWeightOld + weight2 ;
1017 double totalWeightRatio = totalWeightOld/totalWeight ;
1018 double localWeightRatio = weight2/totalWeight ;
1020 phiBar = phiBarOld*totalWeightRatio + phi*localWeightRatio ;
1021 rBar = rBarOld*totalWeightRatio + r*localWeightRatio ;
1022 r2Bar= r2BarOld*totalWeightRatio + r*r*localWeightRatio ;
1023 phirBar = phirBarOld*totalWeightRatio + phi*r*localWeightRatio ;
1025 totalWeightOld = totalWeight ;
1026 phiBarOld = phiBar ;
1029 phirBarOld = phirBar ;
1031 debugstr4 <<
" totalWeight " << totalWeight
1032 <<
" totalWeightRatio " << totalWeightRatio
1033 <<
" localWeightRatio "<< localWeightRatio
1034 <<
" phiBar " << phiBar
1036 <<
" r2Bar " << r2Bar
1037 <<
" phirBar " << phirBar
1043 slope = (phirBar-phiBar*rBar)/(r2Bar-rBar*rBar);
1044 intercept = phiBar-slope*rBar ;
1046 debugstr4 <<
" end of loop slope " << slope
1047 <<
" intercept " << intercept <<
" \n";
1051 double biggest_normresid = -1.;
1052 unsigned int biggest_index = 0;
1053 for (
unsigned int i = 0; i < uselist_size; i++) {
1055 double r = rlist[
i];
1056 double phi = philist[
i];
1057 double weight2 = w2list[
i];
1059 double normresid = weight2 * (phi - intercept - slope*
r)*(phi - intercept - slope*r);
1062 if (normresid > biggest_normresid) {
1063 biggest_normresid = normresid;
1071 debugstr4 <<
"Dropping hit from fit due to Chi2 " <<
" \n" ;
1072 const SiStripRecHit2D* hit = hitlist[biggest_index];
1073 debugstr4 <<
" DetID " << ((hit)->geographicalId()).rawId()
1074 <<
" R " << rlist[biggest_index]
1075 <<
" Phi " << philist[biggest_index]
1076 <<
" Weight " << w2list[biggest_index]
1077 <<
" PhiPred " << (rlist[biggest_index]-scr)*phiVsRSlope
1078 <<
" Chi2 " << (philist[biggest_index]-(rlist[biggest_index]-scr)*phiVsRSlope)*(philist[biggest_index]-(rlist[biggest_index]-scr)*phiVsRSlope)*w2list[biggest_index]
1079 <<
" normresid " << biggest_normresid
1082 uselist[biggest_index] =
false;
1090 <<
" Intercept " << intercept
1091 <<
" slope " << slope
1101 const SiStripRecHit2D* innerhit = (SiStripRecHit2D*)(0);
1102 double innerhitRadius = -1.;
1105 std::vector<const TrackingRecHit*> outputHits;
1107 std::vector<SiStripRecHit2D> outputRphiHits;
1108 std::vector<SiStripRecHit2D> outputStereoHits;
1113 for (
unsigned int i = 0; i < uselist.size(); i++) {
1115 double r = rlist[
i];
1116 const SiStripRecHit2D* hit = hitlist[
i];
1119 if (innerhit == (SiStripRecHit2D*)(0) || r < innerhitRadius) {
1124 if (typelist[i] == 0) {
1125 numberOfStereoHits++;
1128 outputHits.push_back(hit);
1129 outputStereoHits.push_back(*hit);
1131 else if (typelist[i] == 1) {
1132 numberOfBarrelRphiHits++;
1135 outputHits.push_back(hit);
1136 outputRphiHits.push_back(*hit);
1138 else if (typelist[i] == 2) {
1139 numberOfEndcapZphiHits++;
1142 outputHits.push_back(hit);
1143 outputRphiHits.push_back(*hit);
1148 unsigned int totalNumberOfHits = numberOfStereoHits + numberOfBarrelRphiHits + numberOfEndcapZphiHits;
1149 double reducedChi2 = (totalNumberOfHits > 2 ? chi2 / (totalNumberOfHits - 2) : 1e10);
1160 double correct_pT = pT * phiVsRSlope /
slope;
1163 double phi = intercept + slope*
sqrt(position.
x()*position.
x() + position.
y()*position.
y()) + superclusterIn->position().phi();
1166 double pZ = correct_pT * zVsRSlope;
1171 if (chargeHypothesis > 0.) {
1212 LogDebug(
"") <<
" return from projectFindBand with True \n" << std::endl ;
1217 LogDebug(
"") <<
" return from projectFindBand with False \n" << std::endl ;
virtual const TrackerGeomDet * idToDetUnit(DetId) const
Return the pointer to the GeomDetUnit corresponding to a given DetId.
std::vector< const TrackingRecHit * > outputHits_pos_
unsigned int tibLayer(const DetId &id) const
std::vector< SiStripRecHit2D > outputRphiHits_pos_
GlobalPoint position_pos_
GlobalPoint position_neg_
const SiStripRecHit2D * innerhit_neg_
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
static const double slope[3]
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Sin< T >::type sin(const T &t)
Geom::Phi< T > phi() const
Global3DPoint GlobalPoint
const SiStripRecHit2D * innerhit_pos_
static int position[TOTALCHAMBERS][3]
std::vector< SiStripRecHit2D > outputStereoHits_pos_
GlobalVector momentum_pos_
std::map< const TrackingRecHit *, bool > matchedHitUsed_
Cos< T >::type cos(const T &t)
GlobalVector momentum_neg_
Abs< T >::type abs(const T &t)
double unwrapPhi(double phi) const
unsigned numberOfBarrelRphiHits_neg_
std::vector< SiStripRecHit2D > outputRphiHits_neg_
unsigned int numberOfStereoHits_pos_
unsigned numberOfEndcapZphiHits_neg_
unsigned int numberOfBarrelRphiHits_pos_
std::vector< SiStripRecHit2D > outputStereoHits_neg_
void coarseHitSelection(std::vector< const SiStripRecHit2D * > &hitPointersOut, const TrackerTopology *tTopo, bool stereo, bool endcap)
const TrackerGeometry * tracker_p_
double originUncertainty_
unsigned numberOfStereoHits_neg_
std::map< const TrackingRecHit *, bool > hitUsed_
void coarseMatchedHitSelection(std::vector< const SiStripMatchedRecHit2D * > &coarseMatchedHitPointersOut)
const MagneticField * magneticField_p_
volatile std::atomic< bool > shutdown_flag false
unsigned int numberOfEndcapZphiHits_pos_
unsigned int tobLayer(const DetId &id) const
Global3DVector GlobalVector
std::vector< const TrackingRecHit * > outputHits_neg_
virtual const TrackerGeomDet * idToDet(DetId) const