497 static const double rphiHitSmallestError = 0.0001 ;
498 static const double stereoHitSmallestError = 0.0001 ;
503 static const double stereoPitchAngle = 0.100 ;
504 static const double cos2SiPitchAngle =
cos(stereoPitchAngle)*
cos(stereoPitchAngle) ;
505 static const double sin2SiPitchAngle =
sin(stereoPitchAngle)*
sin(stereoPitchAngle) ;
508 static const double rphiErrFudge = 0.0200 ;
509 static const double stereoErrFudge = 0.0200 ;
512 static const double chi2HitMax = 25.0 ;
515 static const unsigned int nHitsLeftMinimum = 3 ;
518 std::vector<const SiStripRecHit2D*> stereoHits;
519 std::vector<const SiStripRecHit2D*> rphiBarrelHits;
520 std::vector<const SiStripRecHit2D*> zphiEndcapHits;
529 std::ostringstream debugstr1;
530 debugstr1 <<
" Getting barrel rphi hits " <<
" \n" ;
537 debugstr1 <<
" Getting matched hits " <<
" \n" ;
538 std::vector<const SiStripMatchedRecHit2D*> matchedHits;
543 double energy = superclusterIn->energy();
544 double pT = energy * superclusterIn->position().rho()/
sqrt(superclusterIn->x()*superclusterIn->x() +
545 superclusterIn->y()*superclusterIn->y() +
546 superclusterIn->z()*superclusterIn->z());
551 const double scr = superclusterIn->position().rho();
552 const double scz = superclusterIn->position().z();
555 std::vector<bool> uselist;
556 std::vector<double> rlist, philist, w2list;
557 std::vector<int> typelist;
558 std::vector<const SiStripRecHit2D*> hitlist;
560 std::vector<bool> matcheduselist;
561 std::vector<const SiStripMatchedRecHit2D*> matchedhitlist;
564 double zSlopeFitNumer = 0.;
565 double zSlopeFitDenom = 0.;
568 debugstr1 <<
" There are a total of " << stereoHits.size() <<
" stereoHits in this event " <<
" \n"
569 <<
" There are a total of " << rphiBarrelHits.size() <<
" rphiBarrelHits in this event " <<
" \n"
570 <<
" There are a total of " << zphiEndcapHits.size() <<
" zphiEndcapHits in this event " <<
" \n\n";
581 LogDebug(
"") <<
" Loop over matched hits " <<
" \n";
583 for (std::vector<const SiStripMatchedRecHit2D*>::const_iterator
hit = matchedHits.begin() ;
584 hit != matchedHits.end() ; ++
hit) {
592 double r =
sqrt(position.
x()*position.
x() + position.
y()*position.
y());
593 double phi =
unwrapPhi(position.
phi() - superclusterIn->position().phi());
594 double z = position.
z();
604 matcheduselist.push_back(
true);
605 matchedhitlist.push_back(*hit);
610 zSlopeFitNumer += -(scr -
r) * (z - scz);
611 zSlopeFitDenom += (scr -
r) * (scr - r);
620 if (zSlopeFitDenom > 0.) {
621 zVsRSlope = zSlopeFitNumer / zSlopeFitDenom;
629 LogDebug(
"") <<
" Loop over stereo hits" <<
" \n";
632 unsigned int numberOfStereoHits = 0;
633 for (std::vector<const SiStripRecHit2D*>::const_iterator hit = stereoHits.begin(); hit != stereoHits.end(); ++hit) {
638 double r_stereo =
sqrt(position.x()*position.x() + position.y()*position.y());
639 double phi_stereo =
unwrapPhi(position.phi() - superclusterIn->position().phi());
643 double r_stereo_err =
sqrt((*hit)->localPositionError().xx()*cos2SiPitchAngle +
644 (*hit)->localPositionError().yy()*sin2SiPitchAngle ) ;
650 if(r_stereo_err > stereoHitSmallestError ) {
651 r_stereo_err =
sqrt(r_stereo_err*r_stereo_err+stereoErrFudge*stereoErrFudge);
655 bool thisHitIsMatched =
false ;
659 unsigned int matcheduselist_size = matcheduselist.size();
660 for (
unsigned int i = 0;
i < matcheduselist_size;
i++) {
661 if (matcheduselist[
i]) {
662 OmniClusterRef const & mystereocluster = matchedhitlist[
i]->stereoClusterRef();
663 if( stereocluster == mystereocluster ) {
664 thisHitIsMatched =
true ;
671 if(thisHitIsMatched) {
673 uselist.push_back(
true);
674 rlist.push_back(r_stereo);
675 philist.push_back(phi_stereo);
676 w2list.push_back(1./(r_stereo_err/r_stereo)/(r_stereo_err/r_stereo));
677 typelist.push_back(0);
678 hitlist.push_back(*hit);
686 LogDebug(
"") <<
" There are " << uselist.size() <<
" good hits after stereo loop " ;
690 LogDebug(
"") <<
" Looping over barrel rphi hits " ;
691 unsigned int rphiMatchedCounter = 0 ;
692 unsigned int rphiUnMatchedCounter = 0 ;
693 unsigned int numberOfBarrelRphiHits = 0;
694 for (std::vector<const SiStripRecHit2D*>::const_iterator hit = rphiBarrelHits.begin(); hit != rphiBarrelHits.end(); ++hit) {
698 double r =
sqrt(position.x()*position.x() + position.y()*position.y());
699 double phi =
unwrapPhi(position.phi() - superclusterIn->position().phi());
700 double z = position.z();
701 double r_mono_err =
sqrt((*hit)->localPositionError().xx()) ;
704 if( r_mono_err > rphiHitSmallestError) {
706 r_mono_err=
sqrt(r_mono_err*r_mono_err+rphiErrFudge*rphiErrFudge);
713 (tTopo->
tibLayer((*hit)->geographicalId())==1 || tTopo->
tibLayer((*hit)->geographicalId())==2)) ||
715 && (tTopo->
tobLayer((*hit)->geographicalId())==1 || tTopo->
tobLayer((*hit)->geographicalId())==2)) ) {
716 bool thisHitIsMatched =
false ;
717 unsigned int matcheduselist_size = matcheduselist.size();
718 for (
unsigned int i = 0; i < matcheduselist_size; i++) {
719 if (matcheduselist[i]) {
720 OmniClusterRef const & mymonocluster = matchedhitlist[
i]->monoClusterRef();
721 if( monocluster == mymonocluster ) {
722 thisHitIsMatched =
true ;
728 if( thisHitIsMatched ) {
730 uselist.push_back(
true);
732 philist.push_back(phi);
733 w2list.push_back(1./(r_mono_err/r)/(r_mono_err/r));
734 typelist.push_back(1);
735 hitlist.push_back(*hit);
736 rphiMatchedCounter++;
743 double zFit = zVsRSlope * (r - scr) + scz;
756 uselist.push_back(
true);
758 philist.push_back(phi);
759 w2list.push_back(1./(r_mono_err/r)/(r_mono_err/r));
760 typelist.push_back(1);
761 hitlist.push_back(*hit);
762 rphiUnMatchedCounter++;
771 LogDebug(
"") <<
" There are " << rphiMatchedCounter <<
" matched rphi hits";
772 LogDebug(
"") <<
" There are " << rphiUnMatchedCounter <<
" unmatched rphi hits";
773 LogDebug(
"") <<
" There are " << uselist.size() <<
" good stereo+rphi hits " ;
783 LogDebug(
"") <<
" Looping over barrel zphi hits " ;
786 unsigned int numberOfEndcapZphiHits = 0;
787 for (std::vector<const SiStripRecHit2D*>::const_iterator hit = zphiEndcapHits.begin();
788 hit != zphiEndcapHits.end(); ++hit) {
793 double z = position.
z();
794 double phi =
unwrapPhi(position.
phi() - superclusterIn->position().phi());
798 double rFit = (z - scz)/zVsRSlope + scr;
809 uselist.push_back(
true);
810 rlist.push_back(rFit);
811 philist.push_back(phi);
812 w2list.push_back(1./(0.05/rFit)/(0.05/rFit));
813 typelist.push_back(2);
814 hitlist.push_back(*hit);
820 LogDebug(
"") <<
" There are " << uselist.size() <<
" good stereo+rphi+zphi hits " ;
824 std::ostringstream debugstr5;
825 debugstr5 <<
" List of hits before uniqification " <<
" \n" ;
826 for (
unsigned int i = 0; i < uselist.size(); i++) {
828 const SiStripRecHit2D* hit = hitlist[
i];
829 debugstr5 <<
" DetID " << ((hit)->geographicalId()).rawId()
831 <<
" Phi " << philist[
i]
832 <<
" Weight " << w2list[
i]
833 <<
" PhiPred " << (rlist[
i]-scr)*phiVsRSlope
834 <<
" Chi2 " << (philist[i]-(rlist[i]-scr)*phiVsRSlope)*(philist[i]-(rlist[i]-scr)*phiVsRSlope)*w2list[i]
838 debugstr5 <<
" \n\n\n" ;
840 debugstr5 <<
" Counting number of unique detectors " <<
" \n" ;
842 debugstr5 <<
" These are all the detectors with hits " <<
" \n";
846 std::vector<uint32_t> detIdList ;
848 for (
unsigned int i = 0; i < uselist.size(); i++) {
850 const SiStripRecHit2D* hit = hitlist[
i];
851 uint32_t detIDUsed = ((hit)->geographicalId()).rawId() ;
853 debugstr5<<
" DetId " << detIDUsed <<
"\n";
855 detIdList.push_back(detIDUsed) ;
860 debugstr5 <<
" There are " << detIdList.size() <<
" hits on detectors \n";
863 std::sort(detIdList.begin(), detIdList.end());
865 std::unique(detIdList.begin(), detIdList.end()), detIdList.end());
867 debugstr5 <<
" There are " << detIdList.size() <<
" unique detectors \n";
873 debugstr5 <<
" Looping over detectors to choose best hit " <<
" \n";
876 for (
unsigned int idet = 0 ; idet < detIdList.size() ; idet++ ) {
877 for (
unsigned int i = 0; i+1 < uselist.size(); i++) {
880 const SiStripRecHit2D* hit1 = hitlist[
i];
881 double r_hit1 = rlist[
i];
882 double phi_hit1 = philist[
i];
883 double w2_hit1 = w2list[
i] ;
884 double phi_pred1 = (r_hit1-scr)*phiVsRSlope ;
885 double chi1 = (phi_hit1-phi_pred1)*(phi_hit1-phi_pred1)*w2_hit1;
886 if(detIdList[idet]== ((hit1)->geographicalId()).rawId()) {
887 for (
unsigned int j = i+1;
j < uselist.size();
j++) {
889 const SiStripRecHit2D* hit2 = hitlist[
j];
890 if(detIdList[idet]== ((hit2)->geographicalId()).rawId()) {
892 debugstr5 <<
" Found 2 hits on same Si Detector "
893 << ((hit2)->geographicalId()).rawId() <<
"\n";
896 double r_hit2 = rlist[
j];
897 double phi_hit2 = philist[
j];
898 double w2_hit2 = w2list[
j] ;
899 double phi_pred2 = (r_hit2-scr)*phiVsRSlope ;
900 double chi2 = (phi_hit2-phi_pred2)*(phi_hit2-phi_pred2)*w2_hit2;
902 debugstr5 <<
" Chi1 " << chi1 <<
" Chi2 " << chi2 <<
"\n";
924 for (
unsigned int i = 0; i < uselist.size(); i++ ) {
926 double localchi2 = (philist[
i]-(rlist[
i]-scr)*phiVsRSlope)*(philist[
i]-(rlist[
i]-scr)*phiVsRSlope)*w2list[
i] ;
927 if(localchi2 > chi2HitMax ) {
929 const SiStripRecHit2D* hit = hitlist[
i];
930 debugstr5 <<
" Throwing out "
931 <<
" DetID " << ((hit)->geographicalId()).rawId()
933 <<
" Phi " << philist[
i]
934 <<
" Weight " << w2list[
i]
935 <<
" PhiPred " << (rlist[
i]-scr)*phiVsRSlope
936 <<
" Chi2 " << (philist[i]-(rlist[i]-scr)*phiVsRSlope)*(philist[i]-(rlist[i]-scr)*phiVsRSlope)*w2list[i]
945 debugstr5 <<
" List of hits after uniqification " <<
" \n" ;
946 for (
unsigned int i = 0; i < uselist.size(); i++) {
948 const SiStripRecHit2D* hit = hitlist[
i];
949 debugstr5 <<
" DetID " << ((hit)->geographicalId()).rawId()
951 <<
" Phi " << philist[
i]
952 <<
" Weight " << w2list[
i]
953 <<
" PhiPred " << (rlist[
i]-scr)*phiVsRSlope
954 <<
" Chi2 " << (philist[i]-(rlist[i]-scr)*phiVsRSlope)*(philist[i]-(rlist[i]-scr)*phiVsRSlope)*w2list[i]
958 debugstr5 <<
" \n\n\n" ;
962 unsigned int nHitsLeft =0;
963 for (
unsigned int i = 0; i < uselist.size(); i++) {
968 if(nHitsLeft < nHitsLeftMinimum ) {
970 debugstr5 <<
" Too few hits "<< nHitsLeft
971 <<
" left - return false " <<
" \n";
982 double intercept = 0 ;
986 std::ostringstream debugstr4;
987 debugstr4 <<
" Calc of phi(r) "<<
" \n";
997 double phiBarOld = 0.;
1001 double r2BarOld = 0.;
1002 double phirBar = 0.;
1003 double phirBarOld = 0.;
1004 double totalWeight = 0.;
1005 double totalWeightOld = 0.;
1006 unsigned int uselist_size = uselist.size();
1007 for (
unsigned int i = 0; i < uselist_size; i++) {
1009 double r = rlist[
i];
1010 double phi = philist[
i];
1011 double weight2 = w2list[
i];
1013 totalWeight = totalWeightOld + weight2 ;
1018 double totalWeightRatio = totalWeightOld/totalWeight ;
1019 double localWeightRatio = weight2/totalWeight ;
1021 phiBar = phiBarOld*totalWeightRatio + phi*localWeightRatio ;
1022 rBar = rBarOld*totalWeightRatio + r*localWeightRatio ;
1023 r2Bar= r2BarOld*totalWeightRatio + r*r*localWeightRatio ;
1024 phirBar = phirBarOld*totalWeightRatio + phi*r*localWeightRatio ;
1026 totalWeightOld = totalWeight ;
1027 phiBarOld = phiBar ;
1030 phirBarOld = phirBar ;
1032 debugstr4 <<
" totalWeight " << totalWeight
1033 <<
" totalWeightRatio " << totalWeightRatio
1034 <<
" localWeightRatio "<< localWeightRatio
1035 <<
" phiBar " << phiBar
1037 <<
" r2Bar " << r2Bar
1038 <<
" phirBar " << phirBar
1044 slope = (phirBar-phiBar*rBar)/(r2Bar-rBar*rBar);
1045 intercept = phiBar-slope*rBar ;
1047 debugstr4 <<
" end of loop slope " << slope
1048 <<
" intercept " << intercept <<
" \n";
1052 double biggest_normresid = -1.;
1053 unsigned int biggest_index = 0;
1054 for (
unsigned int i = 0; i < uselist_size; i++) {
1056 double r = rlist[
i];
1057 double phi = philist[
i];
1058 double weight2 = w2list[
i];
1060 double normresid = weight2 * (phi - intercept - slope*
r)*(phi - intercept - slope*r);
1063 if (normresid > biggest_normresid) {
1064 biggest_normresid = normresid;
1072 debugstr4 <<
"Dropping hit from fit due to Chi2 " <<
" \n" ;
1073 const SiStripRecHit2D* hit = hitlist[biggest_index];
1074 debugstr4 <<
" DetID " << ((hit)->geographicalId()).rawId()
1075 <<
" R " << rlist[biggest_index]
1076 <<
" Phi " << philist[biggest_index]
1077 <<
" Weight " << w2list[biggest_index]
1078 <<
" PhiPred " << (rlist[biggest_index]-scr)*phiVsRSlope
1079 <<
" Chi2 " << (philist[biggest_index]-(rlist[biggest_index]-scr)*phiVsRSlope)*(philist[biggest_index]-(rlist[biggest_index]-scr)*phiVsRSlope)*w2list[biggest_index]
1080 <<
" normresid " << biggest_normresid
1083 uselist[biggest_index] =
false;
1091 <<
" Intercept " << intercept
1092 <<
" slope " << slope
1102 const SiStripRecHit2D* innerhit = (SiStripRecHit2D*)(0);
1103 double innerhitRadius = -1.;
1106 std::vector<const TrackingRecHit*> outputHits;
1108 std::vector<SiStripRecHit2D> outputRphiHits;
1109 std::vector<SiStripRecHit2D> outputStereoHits;
1114 for (
unsigned int i = 0; i < uselist.size(); i++) {
1116 double r = rlist[
i];
1117 const SiStripRecHit2D* hit = hitlist[
i];
1120 if (innerhit == (SiStripRecHit2D*)(0) || r < innerhitRadius) {
1125 if (typelist[i] == 0) {
1126 numberOfStereoHits++;
1129 outputHits.push_back(hit);
1130 outputStereoHits.push_back(*hit);
1132 else if (typelist[i] == 1) {
1133 numberOfBarrelRphiHits++;
1136 outputHits.push_back(hit);
1137 outputRphiHits.push_back(*hit);
1139 else if (typelist[i] == 2) {
1140 numberOfEndcapZphiHits++;
1143 outputHits.push_back(hit);
1144 outputRphiHits.push_back(*hit);
1149 unsigned int totalNumberOfHits = numberOfStereoHits + numberOfBarrelRphiHits + numberOfEndcapZphiHits;
1150 double reducedChi2 = (totalNumberOfHits > 2 ? chi2 / (totalNumberOfHits - 2) : 1e10);
1161 double correct_pT = pT * phiVsRSlope /
slope;
1164 double phi = intercept + slope*
sqrt(position.
x()*position.
x() + position.
y()*position.
y()) + superclusterIn->position().phi();
1167 double pZ = correct_pT * zVsRSlope;
1172 if (chargeHypothesis > 0.) {
1213 LogDebug(
"") <<
" return from projectFindBand with True \n" << std::endl ;
1218 LogDebug(
"") <<
" return from projectFindBand with False \n" << std::endl ;
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_
double unwrapPhi(double phi) const
virtual const GeomDet * idToDet(DetId) 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_
virtual const GeomDetUnit * idToDetUnit(DetId) const
Return the pointer to the GeomDetUnit corresponding to a given DetId.
std::map< const TrackingRecHit *, bool > hitUsed_
void coarseMatchedHitSelection(std::vector< const SiStripMatchedRecHit2D * > &coarseMatchedHitPointersOut)
const MagneticField * magneticField_p_
unsigned int numberOfEndcapZphiHits_pos_
unsigned int tobLayer(const DetId &id) const
Global3DVector GlobalVector
std::vector< const TrackingRecHit * > outputHits_neg_