491 static const double rphiHitSmallestError = 0.0001 ;
492 static const double stereoHitSmallestError = 0.0001 ;
497 static const double stereoPitchAngle = 0.100 ;
498 static const double cos2SiPitchAngle =
cos(stereoPitchAngle)*
cos(stereoPitchAngle) ;
499 static const double sin2SiPitchAngle =
sin(stereoPitchAngle)*
sin(stereoPitchAngle) ;
502 static const double rphiErrFudge = 0.0200 ;
503 static const double stereoErrFudge = 0.0200 ;
506 static const double chi2HitMax = 25.0 ;
509 static const unsigned int nHitsLeftMinimum = 3 ;
512 std::vector<const SiStripRecHit2D*> stereoHits;
513 std::vector<const SiStripRecHit2D*> rphiBarrelHits;
514 std::vector<const SiStripRecHit2D*> zphiEndcapHits;
523 std::ostringstream debugstr1;
524 debugstr1 <<
" Getting barrel rphi hits " <<
" \n" ;
531 debugstr1 <<
" Getting matched hits " <<
" \n" ;
532 std::vector<const SiStripMatchedRecHit2D*> matchedHits;
537 double energy = superclusterIn->energy();
538 double pT = energy * superclusterIn->position().rho()/
sqrt(superclusterIn->x()*superclusterIn->x() +
539 superclusterIn->y()*superclusterIn->y() +
540 superclusterIn->z()*superclusterIn->z());
545 const double scr = superclusterIn->position().rho();
546 const double scz = superclusterIn->position().z();
549 std::vector<bool> uselist;
550 std::vector<double> rlist, philist, w2list;
551 std::vector<int> typelist;
552 std::vector<const SiStripRecHit2D*> hitlist;
554 std::vector<bool> matcheduselist;
555 std::vector<const SiStripMatchedRecHit2D*> matchedhitlist;
558 double zSlopeFitNumer = 0.;
559 double zSlopeFitDenom = 0.;
562 debugstr1 <<
" There are a total of " << stereoHits.size() <<
" stereoHits in this event " <<
" \n" 563 <<
" There are a total of " << rphiBarrelHits.size() <<
" rphiBarrelHits in this event " <<
" \n" 564 <<
" There are a total of " << zphiEndcapHits.size() <<
" zphiEndcapHits in this event " <<
" \n\n";
575 LogDebug(
"") <<
" Loop over matched hits " <<
" \n";
577 for (std::vector<const SiStripMatchedRecHit2D*>::const_iterator
hit = matchedHits.begin() ;
578 hit != matchedHits.end() ; ++
hit) {
586 double r =
sqrt(position.
x()*position.
x() + position.
y()*position.
y());
587 double phi =
unwrapPhi(position.
phi() - superclusterIn->position().phi());
588 double z = position.
z();
598 matcheduselist.push_back(
true);
599 matchedhitlist.push_back(*hit);
604 zSlopeFitNumer += -(scr -
r) * (z - scz);
605 zSlopeFitDenom += (scr -
r) * (scr - r);
614 if (zSlopeFitDenom > 0.) {
615 zVsRSlope = zSlopeFitNumer / zSlopeFitDenom;
623 LogDebug(
"") <<
" Loop over stereo hits" <<
" \n";
626 unsigned int numberOfStereoHits = 0;
627 for (std::vector<const SiStripRecHit2D*>::const_iterator hit = stereoHits.begin(); hit != stereoHits.end(); ++hit) {
632 double r_stereo =
sqrt(position.x()*position.x() + position.y()*position.y());
633 double phi_stereo =
unwrapPhi(position.phi() - superclusterIn->position().phi());
637 double r_stereo_err =
sqrt((*hit)->localPositionError().xx()*cos2SiPitchAngle +
638 (*hit)->localPositionError().yy()*sin2SiPitchAngle ) ;
644 if(r_stereo_err > stereoHitSmallestError ) {
645 r_stereo_err =
sqrt(r_stereo_err*r_stereo_err+stereoErrFudge*stereoErrFudge);
649 bool thisHitIsMatched =
false ;
653 unsigned int matcheduselist_size = matcheduselist.size();
654 for (
unsigned int i = 0;
i < matcheduselist_size;
i++) {
655 if (matcheduselist[
i]) {
656 OmniClusterRef const & mystereocluster = matchedhitlist[
i]->stereoClusterRef();
657 if( stereocluster == mystereocluster ) {
658 thisHitIsMatched =
true ;
665 if(thisHitIsMatched) {
667 uselist.push_back(
true);
668 rlist.push_back(r_stereo);
669 philist.push_back(phi_stereo);
670 w2list.push_back(1./(r_stereo_err/r_stereo)/(r_stereo_err/r_stereo));
671 typelist.push_back(0);
672 hitlist.push_back(*hit);
680 LogDebug(
"") <<
" There are " << uselist.size() <<
" good hits after stereo loop " ;
684 LogDebug(
"") <<
" Looping over barrel rphi hits " ;
685 unsigned int rphiMatchedCounter = 0 ;
686 unsigned int rphiUnMatchedCounter = 0 ;
687 unsigned int numberOfBarrelRphiHits = 0;
688 for (std::vector<const SiStripRecHit2D*>::const_iterator hit = rphiBarrelHits.begin(); hit != rphiBarrelHits.end(); ++hit) {
692 double r =
sqrt(position.x()*position.x() + position.y()*position.y());
693 double phi =
unwrapPhi(position.phi() - superclusterIn->position().phi());
694 double z = position.z();
695 double r_mono_err =
sqrt((*hit)->localPositionError().xx()) ;
698 if( r_mono_err > rphiHitSmallestError) {
700 r_mono_err=
sqrt(r_mono_err*r_mono_err+rphiErrFudge*rphiErrFudge);
707 (tTopo->
tibLayer((*hit)->geographicalId())==1 || tTopo->
tibLayer((*hit)->geographicalId())==2)) ||
709 && (tTopo->
tobLayer((*hit)->geographicalId())==1 || tTopo->
tobLayer((*hit)->geographicalId())==2)) ) {
710 bool thisHitIsMatched =
false ;
711 unsigned int matcheduselist_size = matcheduselist.size();
712 for (
unsigned int i = 0; i < matcheduselist_size; i++) {
713 if (matcheduselist[i]) {
714 OmniClusterRef const & mymonocluster = matchedhitlist[
i]->monoClusterRef();
715 if( monocluster == mymonocluster ) {
716 thisHitIsMatched =
true ;
722 if( thisHitIsMatched ) {
724 uselist.push_back(
true);
726 philist.push_back(phi);
727 w2list.push_back(1./(r_mono_err/r)/(r_mono_err/r));
728 typelist.push_back(1);
729 hitlist.push_back(*hit);
730 rphiMatchedCounter++;
737 double zFit = zVsRSlope * (r -
scr) + scz;
750 uselist.push_back(
true);
752 philist.push_back(phi);
753 w2list.push_back(1./(r_mono_err/r)/(r_mono_err/r));
754 typelist.push_back(1);
755 hitlist.push_back(*hit);
756 rphiUnMatchedCounter++;
765 LogDebug(
"") <<
" There are " << rphiMatchedCounter <<
" matched rphi hits";
766 LogDebug(
"") <<
" There are " << rphiUnMatchedCounter <<
" unmatched rphi hits";
767 LogDebug(
"") <<
" There are " << uselist.size() <<
" good stereo+rphi hits " ;
777 LogDebug(
"") <<
" Looping over barrel zphi hits " ;
780 unsigned int numberOfEndcapZphiHits = 0;
781 for (std::vector<const SiStripRecHit2D*>::const_iterator hit = zphiEndcapHits.begin();
782 hit != zphiEndcapHits.end(); ++hit) {
787 double z = position.
z();
788 double phi =
unwrapPhi(position.
phi() - superclusterIn->position().phi());
792 double rFit = (z - scz)/zVsRSlope + scr;
803 uselist.push_back(
true);
804 rlist.push_back(rFit);
805 philist.push_back(phi);
806 w2list.push_back(1./(0.05/rFit)/(0.05/rFit));
807 typelist.push_back(2);
808 hitlist.push_back(*hit);
814 LogDebug(
"") <<
" There are " << uselist.size() <<
" good stereo+rphi+zphi hits " ;
818 std::ostringstream debugstr5;
819 debugstr5 <<
" List of hits before uniqification " <<
" \n" ;
820 for (
unsigned int i = 0; i < uselist.size(); i++) {
823 debugstr5 <<
" DetID " << ((hit)->geographicalId()).rawId()
825 <<
" Phi " << philist[
i]
826 <<
" Weight " << w2list[
i]
827 <<
" PhiPred " << (rlist[
i]-
scr)*phiVsRSlope
828 <<
" Chi2 " << (philist[i]-(rlist[i]-scr)*phiVsRSlope)*(philist[i]-(rlist[i]-scr)*phiVsRSlope)*w2list[i]
832 debugstr5 <<
" \n\n\n" ;
834 debugstr5 <<
" Counting number of unique detectors " <<
" \n" ;
836 debugstr5 <<
" These are all the detectors with hits " <<
" \n";
840 std::vector<uint32_t> detIdList ;
842 for (
unsigned int i = 0; i < uselist.size(); i++) {
845 uint32_t detIDUsed = ((hit)->geographicalId()).rawId() ;
847 debugstr5<<
" DetId " << detIDUsed <<
"\n";
849 detIdList.push_back(detIDUsed) ;
854 debugstr5 <<
" There are " << detIdList.size() <<
" hits on detectors \n";
857 std::sort(detIdList.begin(), detIdList.end());
859 std::unique(detIdList.begin(), detIdList.end()), detIdList.end());
861 debugstr5 <<
" There are " << detIdList.size() <<
" unique detectors \n";
867 debugstr5 <<
" Looping over detectors to choose best hit " <<
" \n";
870 for (
unsigned int idet = 0 ; idet < detIdList.size() ; idet++ ) {
871 for (
unsigned int i = 0; i+1 < uselist.size(); i++) {
875 double r_hit1 = rlist[
i];
876 double phi_hit1 = philist[
i];
877 double w2_hit1 = w2list[
i] ;
878 double phi_pred1 = (r_hit1-
scr)*phiVsRSlope ;
879 double chi1 = (phi_hit1-phi_pred1)*(phi_hit1-phi_pred1)*w2_hit1;
880 if(detIdList[idet]== ((hit1)->geographicalId()).rawId()) {
881 for (
unsigned int j = i+1; j < uselist.size(); j++) {
884 if(detIdList[idet]== ((hit2)->geographicalId()).rawId()) {
886 debugstr5 <<
" Found 2 hits on same Si Detector " 887 << ((hit2)->geographicalId()).rawId() <<
"\n";
890 double r_hit2 = rlist[j];
891 double phi_hit2 = philist[j];
892 double w2_hit2 = w2list[j] ;
893 double phi_pred2 = (r_hit2-
scr)*phiVsRSlope ;
894 double chi2 = (phi_hit2-phi_pred2)*(phi_hit2-phi_pred2)*w2_hit2;
896 debugstr5 <<
" Chi1 " << chi1 <<
" Chi2 " << chi2 <<
"\n";
918 for (
unsigned int i = 0; i < uselist.size(); i++ ) {
920 double localchi2 = (philist[
i]-(rlist[
i]-
scr)*phiVsRSlope)*(philist[
i]-(rlist[
i]-
scr)*phiVsRSlope)*w2list[
i] ;
921 if(localchi2 > chi2HitMax ) {
924 debugstr5 <<
" Throwing out " 925 <<
" DetID " << ((hit)->geographicalId()).rawId()
927 <<
" Phi " << philist[
i]
928 <<
" Weight " << w2list[
i]
929 <<
" PhiPred " << (rlist[
i]-
scr)*phiVsRSlope
930 <<
" Chi2 " << (philist[i]-(rlist[i]-scr)*phiVsRSlope)*(philist[i]-(rlist[i]-scr)*phiVsRSlope)*w2list[i]
939 debugstr5 <<
" List of hits after uniqification " <<
" \n" ;
940 for (
unsigned int i = 0; i < uselist.size(); i++) {
943 debugstr5 <<
" DetID " << ((hit)->geographicalId()).rawId()
945 <<
" Phi " << philist[
i]
946 <<
" Weight " << w2list[
i]
947 <<
" PhiPred " << (rlist[
i]-
scr)*phiVsRSlope
948 <<
" Chi2 " << (philist[i]-(rlist[i]-scr)*phiVsRSlope)*(philist[i]-(rlist[i]-scr)*phiVsRSlope)*w2list[i]
952 debugstr5 <<
" \n\n\n" ;
956 unsigned int nHitsLeft =0;
957 for (
unsigned int i = 0; i < uselist.size(); i++) {
962 if(nHitsLeft < nHitsLeftMinimum ) {
964 debugstr5 <<
" Too few hits "<< nHitsLeft
965 <<
" left - return false " <<
" \n";
976 double intercept = 0 ;
980 std::ostringstream debugstr4;
981 debugstr4 <<
" Calc of phi(r) "<<
" \n";
991 double phiBarOld = 0.;
995 double r2BarOld = 0.;
997 double phirBarOld = 0.;
998 double totalWeight = 0.;
999 double totalWeightOld = 0.;
1000 unsigned int uselist_size = uselist.size();
1001 for (
unsigned int i = 0; i < uselist_size; i++) {
1003 double r = rlist[
i];
1004 double phi = philist[
i];
1005 double weight2 = w2list[
i];
1007 totalWeight = totalWeightOld + weight2 ;
1012 double totalWeightRatio = totalWeightOld/totalWeight ;
1013 double localWeightRatio = weight2/totalWeight ;
1015 phiBar = phiBarOld*totalWeightRatio + phi*localWeightRatio ;
1016 rBar = rBarOld*totalWeightRatio + r*localWeightRatio ;
1017 r2Bar= r2BarOld*totalWeightRatio + r*r*localWeightRatio ;
1018 phirBar = phirBarOld*totalWeightRatio + phi*r*localWeightRatio ;
1020 totalWeightOld = totalWeight ;
1021 phiBarOld = phiBar ;
1024 phirBarOld = phirBar ;
1026 debugstr4 <<
" totalWeight " << totalWeight
1027 <<
" totalWeightRatio " << totalWeightRatio
1028 <<
" localWeightRatio "<< localWeightRatio
1029 <<
" phiBar " << phiBar
1031 <<
" r2Bar " << r2Bar
1032 <<
" phirBar " << phirBar
1038 slope = (phirBar-phiBar*rBar)/(r2Bar-rBar*rBar);
1039 intercept = phiBar-slope*rBar ;
1041 debugstr4 <<
" end of loop slope " << slope
1042 <<
" intercept " << intercept <<
" \n";
1046 double biggest_normresid = -1.;
1047 unsigned int biggest_index = 0;
1048 for (
unsigned int i = 0; i < uselist_size; i++) {
1050 double r = rlist[
i];
1051 double phi = philist[
i];
1052 double weight2 = w2list[
i];
1054 double normresid = weight2 * (phi - intercept - slope*
r)*(phi - intercept - slope*r);
1057 if (normresid > biggest_normresid) {
1058 biggest_normresid = normresid;
1066 debugstr4 <<
"Dropping hit from fit due to Chi2 " <<
" \n" ;
1068 debugstr4 <<
" DetID " << ((hit)->geographicalId()).rawId()
1069 <<
" R " << rlist[biggest_index]
1070 <<
" Phi " << philist[biggest_index]
1071 <<
" Weight " << w2list[biggest_index]
1072 <<
" PhiPred " << (rlist[biggest_index]-
scr)*phiVsRSlope
1073 <<
" Chi2 " << (philist[biggest_index]-(rlist[biggest_index]-scr)*phiVsRSlope)*(philist[biggest_index]-(rlist[biggest_index]-scr)*phiVsRSlope)*w2list[biggest_index]
1074 <<
" normresid " << biggest_normresid
1077 uselist[biggest_index] =
false;
1085 <<
" Intercept " << intercept
1086 <<
" slope " << slope
1097 double innerhitRadius = -1.;
1100 std::vector<const TrackingRecHit*> outputHits;
1102 std::vector<SiStripRecHit2D> outputRphiHits;
1103 std::vector<SiStripRecHit2D> outputStereoHits;
1108 for (
unsigned int i = 0; i < uselist.size(); i++) {
1110 double r = rlist[
i];
1119 if (typelist[i] == 0) {
1120 numberOfStereoHits++;
1123 outputHits.push_back(hit);
1124 outputStereoHits.push_back(*hit);
1126 else if (typelist[i] == 1) {
1127 numberOfBarrelRphiHits++;
1130 outputHits.push_back(hit);
1131 outputRphiHits.push_back(*hit);
1133 else if (typelist[i] == 2) {
1134 numberOfEndcapZphiHits++;
1137 outputHits.push_back(hit);
1138 outputRphiHits.push_back(*hit);
1143 unsigned int totalNumberOfHits = numberOfStereoHits + numberOfBarrelRphiHits + numberOfEndcapZphiHits;
1144 double reducedChi2 = (totalNumberOfHits > 2 ? chi2 / (totalNumberOfHits - 2) : 1e10);
1153 throw cms::Exception(
"projectPhiBand") <<
"Pointer to tracker product is null!";
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 ;
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_
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_
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
std::vector< SiStripRecHit2D > outputStereoHits_pos_
GlobalVector momentum_pos_
std::map< const TrackingRecHit *, bool > matchedHitUsed_
def unique(seq, keepstr=True)
Cos< T >::type cos(const T &t)
GlobalVector momentum_neg_
Abs< T >::type abs(const T &t)
double unwrapPhi(double phi) const
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
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_
static int position[264][3]
const TrackerGeomDet * idToDet(DetId) const override
std::map< const TrackingRecHit *, bool > hitUsed_
LocalPoint localPosition() const final
void coarseMatchedHitSelection(std::vector< const SiStripMatchedRecHit2D * > &coarseMatchedHitPointersOut)
const MagneticField * magneticField_p_
DetId geographicalId() const
unsigned int numberOfEndcapZphiHits_pos_
unsigned int tobLayer(const DetId &id) const
Global3DVector GlobalVector
std::vector< const TrackingRecHit * > outputHits_neg_