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;
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]) {
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 (
TIBDetId((*hit)->geographicalId()).layer()==1 ||
TIBDetId((*hit)->geographicalId()).layer()==2)) ||
714 && (
TOBDetId((*hit)->geographicalId()).layer()==1 ||
TOBDetId((*hit)->geographicalId()).layer()==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]) {
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 " ;
822 std::ostringstream debugstr5;
823 debugstr5 <<
" List of hits before uniqification " <<
" \n" ;
824 for (
unsigned int i = 0; i < uselist.size(); i++) {
827 debugstr5 <<
" DetID " << ((hit)->geographicalId()).rawId()
829 <<
" Phi " << philist[
i]
830 <<
" Weight " << w2list[
i]
831 <<
" PhiPred " << (rlist[
i]-scr)*phiVsRSlope
832 <<
" Chi2 " << (philist[i]-(rlist[i]-scr)*phiVsRSlope)*(philist[i]-(rlist[i]-scr)*phiVsRSlope)*w2list[i]
836 debugstr5 <<
" \n\n\n" ;
838 debugstr5 <<
" Counting number of unique detectors " <<
" \n" ;
840 debugstr5 <<
" These are all the detectors with hits " <<
" \n";
843 std::vector<uint32_t> detIdList ;
845 for (
unsigned int i = 0; i < uselist.size(); i++) {
848 uint32_t detIDUsed = ((hit)->geographicalId()).rawId() ;
849 debugstr5<<
" DetId " << detIDUsed <<
"\n";
850 detIdList.push_back(detIDUsed) ;
853 debugstr5 <<
" There are " << detIdList.size() <<
" hits on detectors \n";
855 std::sort(detIdList.begin(), detIdList.end());
857 std::unique(detIdList.begin(), detIdList.end()), detIdList.end());
859 debugstr5 <<
" There are " << detIdList.size() <<
" unique detectors \n";
865 debugstr5 <<
" Looping over detectors to choose best hit " <<
" \n";
867 for (
unsigned int idet = 0 ; idet < detIdList.size() ; idet++ ) {
868 for (
unsigned int i = 0; i+1 < uselist.size(); i++) {
872 double r_hit1 = rlist[
i];
873 double phi_hit1 = philist[
i];
874 double w2_hit1 = w2list[
i] ;
875 double phi_pred1 = (r_hit1-scr)*phiVsRSlope ;
876 double chi1 = (phi_hit1-phi_pred1)*(phi_hit1-phi_pred1)*w2_hit1;
877 if(detIdList[idet]== ((hit1)->geographicalId()).rawId()) {
878 for (
unsigned int j = i+1;
j < uselist.size();
j++) {
881 if(detIdList[idet]== ((hit2)->geographicalId()).rawId()) {
882 debugstr5 <<
" Found 2 hits on same Si Detector "
883 << ((hit2)->geographicalId()).rawId() <<
"\n";
885 double r_hit2 = rlist[
j];
886 double phi_hit2 = philist[
j];
887 double w2_hit2 = w2list[
j] ;
888 double phi_pred2 = (r_hit2-scr)*phiVsRSlope ;
889 double chi2 = (phi_hit2-phi_pred2)*(phi_hit2-phi_pred2)*w2_hit2;
890 debugstr5 <<
" Chi1 " << chi1 <<
" Chi2 " << chi2 <<
"\n";
911 for (
unsigned int i = 0; i < uselist.size(); i++ ) {
914 double localchi2 = (philist[
i]-(rlist[
i]-scr)*phiVsRSlope)*(philist[
i]-(rlist[
i]-scr)*phiVsRSlope)*w2list[
i] ;
915 if(localchi2 > chi2HitMax ) {
916 debugstr5 <<
" Throwing out "
917 <<
" DetID " << ((hit)->geographicalId()).rawId()
919 <<
" Phi " << philist[
i]
920 <<
" Weight " << w2list[
i]
921 <<
" PhiPred " << (rlist[
i]-scr)*phiVsRSlope
922 <<
" Chi2 " << (philist[i]-(rlist[i]-scr)*phiVsRSlope)*(philist[i]-(rlist[i]-scr)*phiVsRSlope)*w2list[i]
929 debugstr5 <<
" List of hits after uniqification " <<
" \n" ;
930 for (
unsigned int i = 0; i < uselist.size(); i++) {
933 debugstr5 <<
" DetID " << ((hit)->geographicalId()).rawId()
935 <<
" Phi " << philist[
i]
936 <<
" Weight " << w2list[
i]
937 <<
" PhiPred " << (rlist[
i]-scr)*phiVsRSlope
938 <<
" Chi2 " << (philist[i]-(rlist[i]-scr)*phiVsRSlope)*(philist[i]-(rlist[i]-scr)*phiVsRSlope)*w2list[i]
942 debugstr5 <<
" \n\n\n" ;
946 unsigned int nHitsLeft =0;
947 for (
unsigned int i = 0; i < uselist.size(); i++) {
952 if(nHitsLeft < nHitsLeftMinimum ) {
953 debugstr5 <<
" Too few hits "<< nHitsLeft
954 <<
" left - return false " <<
" \n";
963 double intercept = 0 ;
967 std::ostringstream debugstr4;
968 debugstr4 <<
" Calc of phi(r) "<<
" \n";
978 double phiBarOld = 0.;
982 double r2BarOld = 0.;
984 double phirBarOld = 0.;
985 double totalWeight = 0.;
986 double totalWeightOld = 0.;
987 unsigned int uselist_size = uselist.size();
988 for (
unsigned int i = 0; i < uselist_size; i++) {
991 double phi = philist[
i];
992 double weight2 = w2list[
i];
994 totalWeight = totalWeightOld + weight2 ;
999 double totalWeightRatio = totalWeightOld/totalWeight ;
1000 double localWeightRatio = weight2/totalWeight ;
1002 phiBar = phiBarOld*totalWeightRatio + phi*localWeightRatio ;
1003 rBar = rBarOld*totalWeightRatio + r*localWeightRatio ;
1004 r2Bar= r2BarOld*totalWeightRatio + r*r*localWeightRatio ;
1005 phirBar = phirBarOld*totalWeightRatio + phi*r*localWeightRatio ;
1007 totalWeightOld = totalWeight ;
1008 phiBarOld = phiBar ;
1011 phirBarOld = phirBar ;
1013 debugstr4 <<
" totalWeight " << totalWeight
1014 <<
" totalWeightRatio " << totalWeightRatio
1015 <<
" localWeightRatio "<< localWeightRatio
1016 <<
" phiBar " << phiBar
1018 <<
" r2Bar " << r2Bar
1019 <<
" phirBar " << phirBar
1025 slope = (phirBar-phiBar*rBar)/(r2Bar-rBar*rBar);
1026 intercept = phiBar-slope*rBar ;
1028 debugstr4 <<
" end of loop slope " << slope
1029 <<
" intercept " << intercept <<
" \n";
1033 double biggest_normresid = -1.;
1034 unsigned int biggest_index = 0;
1035 for (
unsigned int i = 0; i < uselist_size; i++) {
1037 double r = rlist[
i];
1038 double phi = philist[
i];
1039 double weight2 = w2list[
i];
1041 double normresid = weight2 * (phi - intercept - slope*
r)*(phi - intercept - slope*r);
1044 if (normresid > biggest_normresid) {
1045 biggest_normresid = normresid;
1052 debugstr4 <<
"Dropping hit from fit due to Chi2 " <<
" \n" ;
1054 debugstr4 <<
" DetID " << ((hit)->geographicalId()).rawId()
1055 <<
" R " << rlist[biggest_index]
1056 <<
" Phi " << philist[biggest_index]
1057 <<
" Weight " << w2list[biggest_index]
1058 <<
" PhiPred " << (rlist[biggest_index]-scr)*phiVsRSlope
1059 <<
" Chi2 " << (philist[biggest_index]-(rlist[biggest_index]-scr)*phiVsRSlope)*(philist[biggest_index]-(rlist[biggest_index]-scr)*phiVsRSlope)*w2list[biggest_index]
1060 <<
" normresid " << biggest_normresid
1062 uselist[biggest_index] =
false;
1070 <<
" Intercept " << intercept
1071 <<
" slope " << slope
1082 double innerhitRadius = -1.;
1085 std::vector<const TrackingRecHit*> outputHits;
1087 std::vector<SiStripRecHit2D> outputRphiHits;
1088 std::vector<SiStripRecHit2D> outputStereoHits;
1093 for (
unsigned int i = 0; i < uselist.size(); i++) {
1095 double r = rlist[
i];
1104 if (typelist[i] == 0) {
1105 numberOfStereoHits++;
1108 outputHits.push_back(hit);
1109 outputStereoHits.push_back(*hit);
1111 else if (typelist[i] == 1) {
1112 numberOfBarrelRphiHits++;
1115 outputHits.push_back(hit);
1116 outputRphiHits.push_back(*hit);
1118 else if (typelist[i] == 2) {
1119 numberOfEndcapZphiHits++;
1122 outputHits.push_back(hit);
1123 outputRphiHits.push_back(*hit);
1128 unsigned int totalNumberOfHits = numberOfStereoHits + numberOfBarrelRphiHits + numberOfEndcapZphiHits;
1129 double reducedChi2 = (totalNumberOfHits > 2 ? chi2 / (totalNumberOfHits - 2) : 1e10);
1140 double correct_pT = pT * phiVsRSlope /
slope;
1143 double phi = intercept + slope*
sqrt(position.
x()*position.
x() + position.
y()*position.
y()) + superclusterIn->position().phi();
1146 double pZ = correct_pT * zVsRSlope;
1151 if (chargeHypothesis > 0.) {
1192 LogDebug(
"") <<
" return from projectFindBand with True \n" << std::endl ;
1197 LogDebug(
"") <<
" return from projectFindBand with False \n" << std::endl ;
std::vector< const TrackingRecHit * > outputHits_pos_
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]
virtual LocalPoint localPosition() const
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_
void coarseHitSelection(std::vector< const SiStripRecHit2D * > &hitPointersOut, bool stereo, bool endcap)
std::vector< SiStripRecHit2D > outputStereoHits_neg_
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_
DetId geographicalId() const
unsigned int numberOfEndcapZphiHits_pos_
Global3DVector GlobalVector
std::vector< const TrackingRecHit * > outputHits_neg_