25 #include "gsl/gsl_statistics.h" 35 isPatternChecked =
false;
37 MagnecticFieldThreshold = 0.5;
47 deltaRThreshold = iConfig.
getParameter<
double>(
"deltaRThreshold");
49 autoAlgorithmChoose = iConfig.
getParameter<
bool>(
"autoAlgorithmChoose");
51 MinDeltaPhi = iConfig.
getParameter<
double>(
"MinDeltaPhi");
52 MagnecticFieldThreshold = iConfig.
getParameter<
double>(
"MagnecticFieldThreshold");
54 sampleCount = iConfig.
getParameter<
unsigned int>(
"sampleCount");
60 if(isConfigured ==
false)
62 cout <<
"Configuration not set yet" << endl;
63 return createFakeSeed(isGoodSeed, eSetup);
67 unsigned int NumberofHitsinSeed = nrhit();
68 if(NumberofHitsinSeed < 3)
69 return createFakeSeed(isGoodSeed, eSetup);
71 if(NumberofHitsinSeed == 3)
72 ThreePointsAlgorithm();
74 if(NumberofHitsinSeed > 3)
76 if(autoAlgorithmChoose ==
false)
78 cout <<
"computePtWithmorerecHits" << endl;
80 ThreePointsAlgorithm();
82 MiddlePointsAlgorithm();
88 SegmentAlgorithmSpecial(eSetup);
91 cout <<
"Not enough recHits for Special Segment Algorithm" << endl;
92 return createFakeSeed(isGoodSeed, eSetup);
101 SegmentAlgorithmSpecial(eSetup);
112 if(isPatternChecked ==
false){
114 checkSimplePattern(eSetup);
116 checkSegmentAlgorithmSpecial(eSetup);
120 return createSeed(isGoodSeed, eSetup);
125 cout <<
"computePtWith3recHits" << endl;
126 unsigned int NumberofHitsinSeed = nrhit();
128 if(NumberofHitsinSeed < 3)
130 isPatternChecked =
true;
135 unsigned int NumberofPart = NumberofHitsinSeed * (NumberofHitsinSeed - 1) * (NumberofHitsinSeed - 2) / (3 * 2);;
136 double *
pt =
new double[NumberofPart];
137 double *pt_err =
new double[NumberofPart];
141 unsigned int NumberofStraight = 0;
142 for(
unsigned int i = 0;
i < (NumberofHitsinSeed - 2);
i++)
143 for(
unsigned int j = (
i + 1); j < (NumberofHitsinSeed - 1); j++)
144 for(
unsigned int k = (j + 1);
k < NumberofHitsinSeed;
k++)
146 precHit[0] = theRecHits[
i];
147 precHit[1] = theRecHits[j];
148 precHit[2] = theRecHits[
k];
149 bool checkStraight = checkStraightwithThreerecHits(precHit, MinDeltaPhi);
152 GlobalVector Center_temp = computePtwithThreerecHits(pt[n], pt_err[n], precHit);
154 Center += Center_temp;
166 if(NumberofStraight == NumberofPart)
174 Center /= (NumberofPart - NumberofStraight);
176 for(ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
177 meanR += getDistance(*iter, Center);
178 meanR /= NumberofHitsinSeed;
183 isPatternChecked =
false;
195 cout <<
"Using middle points algorithm" << endl;
196 unsigned int NumberofHitsinSeed = nrhit();
198 if(NumberofHitsinSeed < 4)
200 isPatternChecked =
true;
204 double *
X =
new double[NumberofHitsinSeed];
205 double *
Y =
new double[NumberofHitsinSeed];
207 for(ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
209 X[
n] = (*iter)->globalPosition().x();
210 Y[
n] = (*iter)->globalPosition().y();
211 cout <<
"X[" << n <<
"] = " << X[
n] <<
", Y[" << n <<
"]= " << Y[
n] << endl;
214 unsigned int NumberofPoints = NumberofHitsinSeed;
215 while(NumberofPoints > 3)
217 for(
unsigned int i = 0;
i <= (NumberofPoints - 2);
i++)
219 X[
i] = (X[
i] + X[
i+1]) / 2;
220 Y[
i] = (Y[
i] + Y[
i+1]) / 2;
225 for(
unsigned int i = 0;
i < 3;
i++)
232 bool checkStraight = checkStraightwithThreerecHits(x, y, MinDeltaPhi);
236 GlobalVector Center_temp = computePtWithThreerecHits(pt, pt_err, x, y);
238 for(ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
239 meanR += getDistance(*iter, Center_temp);
240 meanR /= NumberofHitsinSeed;
243 Center = Center_temp;
254 isPatternChecked =
false;
262 cout <<
"Using segments algorithm" << endl;
263 unsigned int NumberofHitsinSeed = nrhit();
265 if(NumberofHitsinSeed < 4)
267 isPatternChecked =
true;
273 unsigned int NumberofSegment = NumberofHitsinSeed - 2;
276 for(ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != (theRecHits.end()-2); iter++)
278 Segment[
n].first = (*iter);
279 Segment[
n].second = (*(iter + 2));
282 unsigned int NumberofStraight = 0;
283 for(
unsigned int i = 0;
i < NumberofSegment - 1;
i++)
285 bool checkStraight = checkStraightwithSegment(Segment[
i], Segment[i+1], MinDeltaPhi);
286 if(checkStraight ==
true)
293 GlobalVector Center_temp = computePtwithSegment(Segment[i], Segment[i+1]);
295 Center += Center_temp;
299 if((NumberofSegment-1-NumberofStraight) > 0)
302 Center /= (NumberofSegment - 1 - NumberofStraight);
304 for(ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
305 meanR += getDistance(*iter, Center);
306 meanR /= NumberofHitsinSeed;
316 isPatternChecked =
false;
330 isPatternChecked =
true;
336 for(ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != (theRecHits.end()-1); iter++)
339 GlobalPoint gpLast = (*(iter+1))->globalPosition();
341 double dx = (gpLast.
x() - gpFirst.
x()) / (sampleCount + 1);
342 double dy = (gpLast.
y() - gpFirst.
y()) / (sampleCount + 1);
343 double dz = (gpLast.
z() - gpFirst.
z()) / (sampleCount + 1);
348 cout <<
"Sampling magnetic field : " << MagneticVec_temp << endl;
355 ConstMuonRecHitContainer::const_iterator iter=theRecHits.begin();
356 for(
unsigned int n = 0;
n <= 1;
n++)
358 SegmentRB[
n].first = (*iter);
359 cout <<
"SegmentRB " <<
n <<
" recHit: " << (*iter)->globalPosition() << endl;
361 SegmentRB[
n].second = (*iter);
362 cout <<
"SegmentRB " <<
n <<
" recHit: " << (*iter)->globalPosition() << endl;
365 GlobalVector segvec1 = (SegmentRB[0].second)->globalPosition() - (SegmentRB[0].first)->globalPosition();
366 GlobalVector segvec2 = (SegmentRB[1].second)->globalPosition() - (SegmentRB[1].first)->globalPosition();
369 entryPosition = (SegmentRB[0].second)->globalPosition();
370 leavePosition = (SegmentRB[1].first)->globalPosition();
371 while(fabs(Field->
inTesla(entryPosition).
z()) < MagnecticFieldThreshold)
373 cout <<
"Entry position is : " << entryPosition <<
", and stepping into next point" << endl;
374 entryPosition += segvec1.
unit() * stepLength;
377 while(fabs(Field->
inTesla(entryPosition).
z()) >= MagnecticFieldThreshold)
379 cout <<
"Entry position is : " << entryPosition <<
", and stepping back into next point" << endl;
380 entryPosition -= segvec1.
unit() * stepLength / 10;
382 entryPosition += 0.5 * segvec1.
unit() * stepLength / 10;
383 cout <<
"Final entry position is : " << entryPosition << endl;
385 while(fabs(Field->
inTesla(leavePosition).
z()) < MagnecticFieldThreshold)
387 cout <<
"Leave position is : " << leavePosition <<
", and stepping into next point" << endl;
388 leavePosition -= segvec2.
unit() * stepLength;
391 while(fabs(Field->
inTesla(leavePosition).
z()) >= MagnecticFieldThreshold)
393 cout <<
"Leave position is : " << leavePosition <<
", and stepping back into next point" << endl;
394 leavePosition += segvec2.
unit() * stepLength / 10;
396 leavePosition -= 0.5 * segvec2.
unit() * stepLength / 10;
397 cout <<
"Final leave position is : " << leavePosition << endl;
401 double dx = (leavePosition.x() - entryPosition.x()) / (sampleCount + 1);
402 double dy = (leavePosition.y() - entryPosition.y()) / (sampleCount + 1);
403 double dz = (leavePosition.z() - entryPosition.z()) / (sampleCount + 1);
404 std::vector<GlobalVector> BValue;
410 cout <<
"Sampling magnetic field : " << MagneticVec_temp << endl;
411 BValue.push_back(MagneticVec_temp);
415 for(std::vector<GlobalVector>::const_iterator BIter = BValue.begin(); BIter != BValue.end(); BIter++)
417 meanB2 /= BValue.size();
418 cout <<
"Mean B field is " << meanB2 << endl;
419 meanMagneticField2 = meanB2;
421 double meanBz2 = meanB2.
z();
422 double deltaBz2 = 0.;
423 for(std::vector<GlobalVector>::const_iterator BIter = BValue.begin(); BIter != BValue.end(); BIter++)
424 deltaBz2 += (BIter->z() - meanBz2) * (BIter->z() - meanBz2);;
425 deltaBz2 /= BValue.size();
426 deltaBz2 =
sqrt(deltaBz2);
427 cout<<
"delta Bz is " << deltaBz2 << endl;
431 bool checkStraight = checkStraightwithSegment(SegmentRB[0], SegmentRB[1], MinDeltaPhi);
432 if(checkStraight ==
true)
435 isStraight2 = checkStraight;
438 GlobalVector MomentumVec = (SegmentRB[1].second)->globalPosition() - (SegmentRB[0].first)->globalPosition();
439 S += MomentumVec.
perp();
440 lastPhi = MomentumVec.
phi().
value();
444 GlobalVector seg1 = entryPosition - (SegmentRB[0].first)->globalPosition();
446 GlobalVector seg2 = (SegmentRB[1].second)->globalPosition() - leavePosition;
451 double A1 = gvec1.
x();
452 double B1 = gvec1.
y();
453 double A2 = gvec2.
x();
454 double B2 = gvec2.
y();
455 double X1 = entryPosition.x();
456 double Y1 = entryPosition.y();
457 double X2 = leavePosition.x();
458 double Y2 = leavePosition.y();
459 double XO = (A1*A2*(Y2-Y1)+A2*B1*X1-A1*B2*X2)/(A2*B1-A1*B2);
460 double YO = (B1*B2*(X2-X1)+B2*A1*Y1-B1*A2*Y2)/(B2*A1-B1*A2);
463 isStraight2 = checkStraight;
464 Center2 = Center_temp;
466 cout <<
"entryPosition: " << entryPosition << endl;
467 cout <<
"leavePosition: " << leavePosition << endl;
468 cout <<
"Center2 is : " << Center_temp << endl;
470 double R1 =
GlobalVector((entryPosition.x() - Center_temp.
x()), (entryPosition.y() - Center_temp.
y()), (entryPosition.z() - Center_temp.
z())).
perp();
471 double R2 =
GlobalVector((leavePosition.x() - Center_temp.
x()), (leavePosition.y() - Center_temp.
y()), (leavePosition.z() - Center_temp.
z())).
perp();
472 double meanR = (R1 + R2) / 2;
473 double deltaR =
sqrt(((R1-meanR)*(R1-meanR)+(R2-meanR)*(R2-meanR))/2);
475 cout <<
"R1 is " << R1 <<
", R2 is " << R2 << endl;
476 cout <<
"Mean radius is " << meanR << endl;
477 cout <<
"Delta R is " << deltaR << endl;
484 isPatternChecked =
false;
490 unsigned int count = 0;
492 for(ConstMuonRecHitContainer::const_iterator iter=theRecHits.begin(); iter!=theRecHits.end(); iter++)
496 if(dynamic_cast<const RPCChamber*>(Detector) !=
nullptr)
501 unsigned int Station = RPCId.
station();
515 cout <<
"Check for segment fit: " << isFit << endl;
521 return theRecHits.front();
530 for (ConstMuonRecHitContainer::const_iterator iter=theRecHits.begin(); iter!=theRecHits.end(); iter++)
544 return sqrt((precHit->globalPosition().x()-Center.
x())*(precHit->globalPosition().x()-Center.
x())+(precHit->globalPosition().y()-Center.
y())*(precHit->globalPosition().y()-Center.
y()));
549 GlobalVector segvec1 = precHit[1]->globalPosition() - precHit[0]->globalPosition();
550 GlobalVector segvec2 = precHit[2]->globalPosition() - precHit[1]->globalPosition();
551 double dPhi = (segvec2.
phi() - segvec1.
phi()).
value();
552 if(fabs(dPhi) > MinDeltaPhi)
554 cout <<
"Part is estimate to be not straight" << endl;
559 cout <<
"Part is estimate to be straight" << endl;
567 x[0] = precHit[0]->globalPosition().x();
568 y[0] = precHit[0]->globalPosition().y();
569 x[1] = precHit[1]->globalPosition().x();
570 y[1] = precHit[1]->globalPosition().y();
571 x[2] = precHit[2]->globalPosition().x();
572 y[2] = precHit[2]->globalPosition().y();
573 double A = (y[2]-y[1])/(x[2]-x[1]) - (y[1]-y[0])/(x[1]-x[0]);
574 double TYO = (x[2]-x[0])/A + (y[2]*y[2]-y[1]*y[1])/((x[2]-x[1])*A) - (y[1]*y[1]-y[0]*y[0])/((x[1]-x[0])*
A);
575 double TXO = (x[2]+x[1]) + (y[2]*y[2]-y[1]*y[1])/(x[2]-x[1]) - TYO*(y[2]-y[1])/(x[2]-x[1]);
576 double XO = 0.5 * TXO;
577 double YO = 0.5 * TYO;
578 double R2 = (x[0]-XO)*(x[0]-XO) + (y[0]-YO)*(y[0]-YO);
579 cout <<
"R2 is " << R2 << endl;
581 pt = 0.01 *
sqrt(R2) * 2 * 0.3;
582 cout <<
"pt is " << pt << endl;
589 GlobalVector segvec1 = (Segment1.second)->globalPosition() - (Segment1.first)->globalPosition();
590 GlobalVector segvec2 = (Segment2.second)->globalPosition() - (Segment2.first)->globalPosition();
591 GlobalVector segvec3 = (Segment2.first)->globalPosition() - (Segment1.first)->globalPosition();
593 double dPhi1 = (segvec2.
phi() - segvec1.
phi()).
value();
594 double dPhi2 = (segvec3.
phi() - segvec1.
phi()).
value();
595 cout <<
"Checking straight with 2 segments. dPhi1: " << dPhi1 <<
", dPhi2: " << dPhi2 << endl;
596 cout <<
"Checking straight with 2 segments. dPhi1 in degree: " << dPhi1*180/3.1415926 <<
", dPhi2 in degree: " << dPhi2*180/3.1415926 << endl;
597 if(fabs(dPhi1) > MinDeltaPhi || fabs(dPhi2) > MinDeltaPhi)
599 cout <<
"Segment is estimate to be not straight" << endl;
604 cout <<
"Segment is estimate to be straight" << endl;
611 GlobalVector segvec1 = (Segment1.second)->globalPosition() - (Segment1.first)->globalPosition();
612 GlobalVector segvec2 = (Segment2.second)->globalPosition() - (Segment2.first)->globalPosition();
613 GlobalPoint Point1(((Segment1.second)->globalPosition().x() + (Segment1.first)->globalPosition().x()) / 2, ((Segment1.second)->globalPosition().y() + (Segment1.first)->globalPosition().y()) / 2, ((Segment1.second)->globalPosition().z() + (Segment1.first)->globalPosition().z()) / 2);
614 GlobalPoint Point2(((Segment2.second)->globalPosition().x() + (Segment2.first)->globalPosition().x()) / 2, ((Segment2.second)->globalPosition().y() + (Segment2.first)->globalPosition().y()) / 2, ((Segment2.second)->globalPosition().z() + (Segment2.first)->globalPosition().z()) / 2);
618 double A1 = gvec1.
x();
619 double B1 = gvec1.
y();
620 double A2 = gvec2.
x();
621 double B2 = gvec2.
y();
622 double X1 = Point1.
x();
623 double Y1 = Point1.
y();
624 double X2 = Point2.
x();
625 double Y2 = Point2.
y();
626 double XO = (A1*A2*(Y2-Y1)+A2*B1*X1-A1*B2*X2)/(A2*B1-A1*B2);
627 double YO = (B1*B2*(X2-X1)+B2*A1*Y1-B1*A2*Y2)/(B2*A1-B1*A2);
636 double dPhi = (segvec2.
phi() - segvec1.
phi()).
value();
637 if(fabs(dPhi) > MinDeltaPhi)
639 cout <<
"Part is estimate to be not straight" << endl;
644 cout <<
"Part is estimate to be straight" << endl;
651 double A = (y[2]-y[1])/(x[2]-x[1]) - (y[1]-y[0])/(x[1]-x[0]);
652 double TYO = (x[2]-x[0])/A + (y[2]*y[2]-y[1]*y[1])/((x[2]-x[1])*A) - (y[1]*y[1]-y[0]*y[0])/((x[1]-x[0])*
A);
653 double TXO = (x[2]+x[1]) + (y[2]*y[2]-y[1]*y[1])/(x[2]-x[1]) - TYO*(y[2]-y[1])/(x[2]-x[1]);
654 double XO = 0.5 * TXO;
655 double YO = 0.5 * TYO;
656 double R2 = (x[0]-XO)*(x[0]-XO) + (y[0]-YO)*(y[0]-YO);
657 cout <<
"R2 is " << R2 << endl;
659 pt = 0.01 *
sqrt(R2) * 2 * 0.3;
660 cout <<
"pt is " << pt << endl;
667 if(isPatternChecked ==
true)
674 unsigned int NumberofHitsinSeed = nrhit();
677 for(ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
678 cout <<
"Position of recHit is: " << (*iter)->globalPosition() << endl;
681 std::vector<double> BzValue;
682 for(ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != (theRecHits.end()-1); iter++)
685 GlobalPoint gpLast = (*(iter+1))->globalPosition();
687 double dx = (gpLast.
x() - gpFirst.
x()) / (sampleCount + 1);
688 double dy = (gpLast.
y() - gpFirst.
y()) / (sampleCount + 1);
689 double dz = (gpLast.
z() - gpFirst.
z()) / (sampleCount + 1);
694 cout <<
"Sampling magnetic field : " << MagneticVec_temp << endl;
695 BzValue.push_back(MagneticVec_temp.z());
701 meanBz += BzValue[
index];
702 meanBz /= BzValue.size();
703 cout <<
"Mean Bz is " << meanBz << endl;
706 deltaBz += (BzValue[
index] - meanBz) * (BzValue[
index] - meanBz);
707 deltaBz /= BzValue.size();
708 deltaBz =
sqrt(deltaBz);
709 cout<<
"delata Bz is " << deltaBz << endl;
715 if(fabs((*(theRecHits.end()-1))->globalPosition().z() - (*(theRecHits.begin()))->globalPosition().z()) > ZError)
717 if(((*(theRecHits.end()-1))->globalPosition().z() - (*(theRecHits.begin()))->globalPosition().z()) > ZError)
725 cout <<
" Check isParralZ is :" << isParralZ << endl;
726 for(ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != (theRecHits.end()-1); iter++)
730 if(fabs((*(iter+1))->globalPosition().z()-(*iter)->globalPosition().z()) > ZError)
732 cout <<
"Pattern find error in Z direction: wrong perpendicular direction" << endl;
738 if((
int)(((*(iter+1))->globalPosition().z()-(*iter)->globalPosition().z())/ZError)*isParralZ < 0)
740 cout <<
"Pattern find error in Z direction: wrong Z direction" << endl;
747 if(isStraight ==
false)
751 unsigned int index = 0;
752 for(ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
754 GlobalVector vec_temp(((*iter)->globalPosition().x()-Center.x()), ((*iter)->globalPosition().y()-Center.y()), ((*iter)->globalPosition().z()-Center.z()));
755 vec[
index] = vec_temp;
759 for(
unsigned int index = 0; index < (NumberofHitsinSeed-1); index++)
762 if((vec[index+1].phi()-vec[index].phi()) > 0)
766 cout <<
"Current isClockwise is : " << isClockwise << endl;
768 cout <<
"Check isClockwise is : " << isClockwise << endl;
769 if((
unsigned int)
abs(isClockwise) != (NumberofHitsinSeed-1))
771 cout <<
"Pattern find error in Phi direction" << endl;
776 isClockwise /=
abs(isClockwise);
780 double deltaRwithBz = fabs(deltaBz * meanRadius / meanBz);
781 cout <<
"deltaR with Bz is " << deltaRwithBz << endl;
786 meanPt = 0.01 * meanRadius * meanBz * 0.3 * isClockwise;
789 cout <<
" meanRadius is " << meanRadius << endl;
790 cout <<
" meanPt is " << meanPt << endl;
793 for(ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
795 deltaR += (getDistance(*iter, Center) - meanRadius) * (getDistance(*iter, Center) - meanRadius);
797 deltaR = deltaR / NumberofHitsinSeed;
798 deltaR =
sqrt(deltaR);
801 cout <<
"DeltaR is " << deltaR << endl;
802 if(deltaR > deltaRThreshold)
804 cout <<
"Pattern find error: deltaR over threshold" << endl;
814 meanSpt = deltaRThreshold;
816 cout <<
"III--> Seed Pt : " << meanPt << endl;
817 cout <<
"III--> Pattern is: " << isGoodPattern << endl;
820 isPatternChecked =
true;
825 if(isPatternChecked ==
true)
830 isPatternChecked =
true;
839 for(ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
840 cout <<
"Position of recHit is: " << (*iter)->globalPosition() << endl;
843 if(fabs((*(theRecHits.end()-1))->globalPosition().z() - (*(theRecHits.begin()))->globalPosition().z()) > ZError)
845 if(((*(theRecHits.end()-1))->globalPosition().z() - (*(theRecHits.begin()))->globalPosition().z()) > ZError)
853 cout <<
" Check isParralZ is :" << isParralZ << endl;
854 for(ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != (theRecHits.end()-1); iter++)
858 if(fabs((*(iter+1))->globalPosition().z()-(*iter)->globalPosition().z()) > ZError)
860 cout <<
"Pattern find error in Z direction: wrong perpendicular direction" << endl;
866 if((
int)(((*(iter+1))->globalPosition().z()-(*iter)->globalPosition().z())/ZError)*isParralZ < 0)
868 cout <<
"Pattern find error in Z direction: wrong Z direction" << endl;
875 if(isStraight2 ==
true)
881 meanSpt = deltaRThreshold;
884 GlobalVector startSegment = (SegmentRB[1].second)->globalPosition() - (SegmentRB[1].first)->globalPosition();
885 GlobalPoint startPosition = (SegmentRB[1].first)->globalPosition();
887 unsigned int index = 0;
888 for(ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
895 double tracklength = 0;
896 cout <<
"Now checking recHit " << index << endl;
897 double Distance = extropolateStep(startPosition, startMomentum, iter, isClockwise, tracklength, eSetup);
898 cout <<
"Final distance is " << Distance << endl;
899 if(Distance > MaxRSD)
901 cout <<
"Pattern find error in distance for other recHits: " << Distance << endl;
911 vec[0] =
GlobalVector((entryPosition.x()-Center2.x()), (entryPosition.y()-Center2.y()), (entryPosition.z()-Center2.z()));
912 vec[1] =
GlobalVector((leavePosition.x()-Center2.x()), (leavePosition.y()-Center2.y()), (leavePosition.z()-Center2.z()));
914 if((vec[1].phi()-vec[0].phi()).
value() > 0)
919 cout <<
"Check isClockwise is : " << isClockwise << endl;
922 meanPt = 0.01 * meanRadius2 * meanMagneticField2.z() * 0.3 * isClockwise;
924 cout <<
" meanRadius is " << meanRadius2 <<
", with meanBz " << meanMagneticField2.z() << endl;
925 cout <<
" meanPt is " << meanPt << endl;
930 cout <<
"entryPosition: " << entryPosition << endl;
931 cout <<
"leavePosition: " << leavePosition << endl;
932 cout <<
"Center2 is : " << Center2 << endl;
933 double R1 = vec[0].
perp();
934 double R2 = vec[1].
perp();
935 double deltaR =
sqrt(((R1-meanRadius2)*(R1-meanRadius2)+(R2-meanRadius2)*(R2-meanRadius2))/2);
937 cout <<
"R1 is " << R1 <<
", R2 is " << R2 << endl;
938 cout <<
"Delta R for the initial 3 segments is " << deltaR << endl;
939 if(deltaR > deltaRThreshold)
941 cout <<
"Pattern find error in delta R for the initial 3 segments" << endl;
946 GlobalVector startSegment = (SegmentRB[1].second)->globalPosition() - (SegmentRB[1].first)->globalPosition();
947 GlobalPoint startPosition = (SegmentRB[1].first)->globalPosition();
948 GlobalVector startMomentum = startSegment*(fabs(meanPt)/startSegment.
perp());
949 unsigned int index = 0;
950 for(ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
957 double tracklength = 0;
958 cout <<
"Now checking recHit " << index << endl;
959 double Distance = extropolateStep(startPosition, startMomentum, iter, isClockwise, tracklength, eSetup);
960 cout <<
"Final distance is " << Distance << endl;
961 if(Distance > MaxRSD)
963 cout <<
"Pattern find error in distance for other recHits: " << Distance << endl;
970 cout <<
"Checking finish, isGoodPattern now is " << isGoodPattern << endl;
972 isPatternChecked =
true;
981 cout <<
"Extrapolating the track to check the pattern" << endl;
984 DetId hitDet = (*iter)->hit()->geographicalId();
992 double startSide = RPCSurface.localZ(startPosition);
993 cout <<
"Start side : " << startSide;
1000 double currentDistance = ((
GlobalVector)(currentPosition - (*iter)->globalPosition())).perp();
1001 cout <<
"Start current position is : " << currentPosition << endl;
1002 cout <<
"Start current Momentum is: " << currentMomentum.
mag() <<
", in vector: " << currentMomentum << endl;
1003 cout <<
"Start current distance is " << currentDistance << endl;
1004 cout <<
"Start current radius is " << currentPosition.
perp() << endl;
1005 cout <<
"Destination radius is " << (*iter)->globalPosition().perp() << endl;
1009 double currentDistance_next = currentDistance;
1012 currentDistance = currentDistance_next;
1013 if(ClockwiseDirection == 0)
1015 currentPosition += currentMomentum.
unit() * stepLength;
1019 double Bz = Field->
inTesla(currentPosition).
z();
1020 double Radius = currentMomentum.
perp()/fabs(Bz*0.01*0.3);
1021 double deltaPhi = (stepLength*currentMomentum.
perp()/currentMomentum.
mag())/Radius;
1025 currentPositiontoCenter *= Radius;
1027 currentPositiontoCenter *= ClockwiseDirection;
1030 currentCenter += currentPositiontoCenter;
1034 double Phi = CentertocurrentPosition.
phi().
value();
1035 Phi += deltaPhi * (-1) * ClockwiseDirection;
1036 double deltaZ = stepLength*currentMomentum.
z()/currentMomentum.
mag();
1038 double PtPhi = currentMomentum.
phi().
value();
1039 PtPhi += deltaPhi * (-1) * ClockwiseDirection;
1041 currentPosition = currentCenter + CentertonewPosition;
1045 tracklength += stepLength * currentMomentum.
perp() / currentMomentum.
mag();
1048 double currentSide = RPCSurface.localZ(currentPosition);
1049 cout <<
"Stepping current side : " << currentSide << endl;
1050 cout <<
"Stepping current position is: " << currentPosition << endl;
1051 cout <<
"Stepping current Momentum is: " << currentMomentum.
mag() <<
", in vector: " << currentMomentum << endl;
1052 currentDistance_next = ((
GlobalVector)(currentPosition - (*iter)->globalPosition())).
perp();
1053 cout <<
"Stepping current distance is " << currentDistance << endl;
1054 cout <<
"Stepping current radius is " << currentPosition.
perp() << endl;
1055 }
while(currentDistance_next < currentDistance);
1057 return currentDistance;
1063 cout <<
"Now create a fake seed" << endl;
1064 isPatternChecked =
true;
1080 LocalVector segDirFromPos=best->det()->toLocal(Momentum);
1085 mat = best->parametersError().similarityT(best->projectionMatrix());
1086 mat[0][0] = meanSpt;
1094 DetId id = best->geographicalId();
1099 for(ConstMuonRecHitContainer::const_iterator iter=theRecHits.begin(); iter!=theRecHits.end(); iter++)
1100 container.
push_back((*iter)->hit()->clone());
1104 theweightedSeed.first = theSeed;
1105 theweightedSeed.second = meanSpt;
1106 isGoodSeed = isGoodPattern;
1108 return theweightedSeed;
1113 if(isPatternChecked ==
false || isGoodPattern == -1)
1115 cout <<
"Pattern is not yet checked! Create a fake seed instead!" << endl;
1116 return createFakeSeed(isGoodSeed, eSetup);
1129 if(isClockwise == 0)
1132 Charge = (
int)(meanPt / fabs(meanPt));
1138 if(isClockwise != 0)
1143 GlobalVector vecRef1((first->globalPosition().x()-Center.x()), (first->globalPosition().y()-Center.y()), (first->globalPosition().z()-Center.z()));
1144 GlobalVector vecRef2((best->globalPosition().x()-Center.x()), (best->globalPosition().y()-Center.y()), (best->globalPosition().z()-Center.z()));
1147 double deltaS = meanRadius * fabs(deltaPhi);
1148 double deltaZ = best->globalPosition().z() - first->globalPosition().z();
1152 if(isClockwise == -1)
1157 Momentum *= fabs(meanPt / deltaS);
1161 double deltaZ = best->globalPosition().z() - first->globalPosition().z();
1163 Momentum *= fabs(meanPt /
S);
1168 Momentum = best->globalPosition() - first->globalPosition();
1169 double deltaS = Momentum.perp();
1170 Momentum *= fabs(meanPt / deltaS);
1173 LocalVector segDirFromPos = best->det()->toLocal(Momentum);
1179 cout <<
"Trajectory State on Surface before the extrapolation" << endl;
1181 DetId id = best->geographicalId();
1182 cout <<
"The RecSegment relies on: " << endl;
1189 for(ConstMuonRecHitContainer::const_iterator iter=theRecHits.begin(); iter!=theRecHits.end(); iter++)
1195 container.
push_back((*iter)->hit()->clone());
1200 theweightedSeed.first = theSeed;
1201 theweightedSeed.second = meanSpt;
1202 isGoodSeed = isGoodPattern;
1204 return theweightedSeed;
1214 mat = best->parametersError().similarityT(best->projectionMatrix());
1216 GlobalVector vecRef1((first->globalPosition().x()-Center.x()), (first->globalPosition().y()-Center.y()), (first->globalPosition().z()-Center.z()));
1217 GlobalVector vecRef2((best->globalPosition().x()-Center.x()), (best->globalPosition().y()-Center.y()), (best->globalPosition().z()-Center.z()));
1219 double L = meanRadius * fabs(deltaPhi);
1221 double A_N = 180*N*N*N/((N-1)*(N+1)*(N+2)*(N+3));
1223 double betaovergame = Momentum.mag()/0.1066;
1224 double beta =
sqrt((betaovergame*betaovergame)/(1+betaovergame*betaovergame));
1225 double dPt = meanPt*(0.0136*
sqrt(1/100)*
sqrt(4*A_N/N)/(beta*0.3*meanBz*
L) + sigma_x*meanPt*
sqrt(4*A_N)/(0.3*meanBz*L*
L));
1226 double dP = dPt * Momentum.mag() / meanPt;
1227 mat[0][0] = (dP * dP) / (Momentum.mag() * Momentum.mag() * Momentum.mag() * Momentum.mag());
1228 mat[1][1] = dXdZ * dXdZ;
1229 mat[2][2] = dYdZ * dYdZ;
1234 mat0 = (SegmentRB[0].first)->parametersError().similarityT((SegmentRB[0].first)->projectionMatrix());
1235 double dX0 =
sqrt(mat0[3][3]);
1236 double dY0 =
sqrt(mat0[4][4]);
1238 mat1 = (SegmentRB[0].second)->parametersError().similarityT((SegmentRB[0].
second)->projectionMatrix());
1239 double dX1 =
sqrt(mat1[3][3]);
1240 double dY1 =
sqrt(mat1[4][4]);
1242 mat2 = (SegmentRB[1].first)->parametersError().similarityT((SegmentRB[1].first)->projectionMatrix());
1243 double dX2 =
sqrt(mat2[3][3]);
1244 double dY2 =
sqrt(mat2[4][4]);
1246 mat3 = (SegmentRB[1].second)->parametersError().similarityT((SegmentRB[1].second)->projectionMatrix());
1247 double dX3 =
sqrt(mat3[3][3]);
1248 double dY3 =
sqrt(mat3[4][4]);
1249 cout <<
"Local error for 4 recHits are: " << dX0 <<
", " << dY0 <<
", " << dX1 <<
", " << dY1 <<
", " << dX2 <<
", " << dY2 <<
", " << dX3 <<
", " << dY3 << endl;
1250 const GeomDetUnit* refRPC1 = (SegmentRB[0].second)->detUnit();
1260 const GeomDetUnit* refRPC2 = (SegmentRB[1].first)->detUnit();
1270 if(isClockwise != 0) {
1272 vec[0] =
GlobalVector((entryPosition.x()-Center2.x()), (entryPosition.y()-Center2.y()), (entryPosition.z()-Center2.z()));
1273 vec[1] =
GlobalVector((leavePosition.x()-Center2.x()), (leavePosition.y()-Center2.y()), (leavePosition.z()-Center2.z()));
1274 double halfPhiCenter = fabs((vec[1].phi() - vec[0].phi()).
value()) / 2;
1276 double dPhi0 = (((globalSegment00.phi() - globalSegment01.
phi()).
value()*isClockwise) > 0) ? fabs((globalSegment00.phi() - globalSegment01.
phi()).
value()) : fabs((globalSegment00.phi() - globalSegment02.
phi()).
value());
1277 double dPhi1 = (((globalSegment10.phi() - globalSegment11.
phi()).
value()*isClockwise) < 0) ? fabs((globalSegment10.phi() - globalSegment11.
phi()).
value()) : fabs((globalSegment10.phi() - globalSegment12.
phi()).
value());
1279 double dPhi = (dPhi0 <= dPhi1) ? dPhi0 : dPhi1;
1280 cout <<
"DPhi for new Segment is about " << dPhi << endl;
1282 double newhalfPhiCenter = ((halfPhiCenter-dPhi) > 0 ? (halfPhiCenter-dPhi) : 0);
1283 if(newhalfPhiCenter != 0) {
1284 double newmeanPt = meanPt * halfPhiCenter / newhalfPhiCenter;
1287 cout <<
"The error is inside range. Max meanPt could be " << newmeanPt << endl;
1288 dP = fabs(Momentum.mag() * (newmeanPt - meanPt) / meanPt);
1292 cout <<
"The error is outside range. Max meanPt could be " << newmeanPt << endl;
1293 dP = fabs(Momentum.mag() * (newmeanPt - meanPt) / meanPt);
1297 double dPhi0 = (fabs((globalSegment00.phi() - globalSegment01.
phi()).
value()) <= fabs((globalSegment00.phi() - globalSegment02.
phi()).
value())) ? fabs((globalSegment00.phi() - globalSegment01.
phi()).
value()) : fabs((globalSegment00.phi() - globalSegment02.
phi()).
value());
1298 double dPhi1 = (fabs((globalSegment10.phi() - globalSegment11.
phi()).
value()) <= fabs((globalSegment10.phi() - globalSegment12.
phi()).
value())) ? fabs((globalSegment10.phi() - globalSegment11.
phi()).
value()) : fabs((globalSegment10.phi() - globalSegment12.
phi()).
value());
1299 double dPhi = (dPhi0 <= dPhi1) ? dPhi0 : dPhi1;
1300 GlobalVector middleSegment = leavePosition - entryPosition;
1301 double halfDistance = middleSegment.
perp() / 2;
1302 double newmeanPt = halfDistance / dPhi;
1303 cout <<
"The error is for straight. Max meanPt could be " << newmeanPt << endl;
1304 dP = fabs(Momentum.mag() * (newmeanPt - meanPt) / meanPt);
1307 double dXdZ1 = globalSegment11.
x() / globalSegment11.
z() - globalSegment10.x() / globalSegment10.z();
1308 double dXdZ2 = globalSegment12.
x() / globalSegment12.
z() - globalSegment10.x() / globalSegment10.z();
1309 dXdZ = (fabs(dXdZ1) >= fabs(dXdZ2)) ? dXdZ1 : dXdZ2;
1315 double dYdZ1 = globalSegment13.
y() / globalSegment13.z() - globalSegment10.y() / globalSegment10.z();
1316 double dYdZ2 = globalSegment14.
y() / globalSegment14.
z() - globalSegment10.y() / globalSegment10.z();
1317 dYdZ = (fabs(dYdZ1) >= fabs(dYdZ2)) ? dYdZ1 : dYdZ2;
1319 mat[0][0] = (dP * dP) / (Momentum.mag() * Momentum.mag() * Momentum.mag() * Momentum.mag());
1320 mat[1][1] = dXdZ * dXdZ;
1321 mat[2][2] = dYdZ * dYdZ;
MuonTransientTrackingRecHit::ConstMuonRecHitPointer ConstMuonRecHitPointer
edm::ErrorSummaryEntry Error
T getParameter(std::string const &) const
weightedTrajectorySeed createFakeSeed(int &isGoodSeed, const edm::EventSetup &eSetup)
void configure(const edm::ParameterSet &iConfig)
Local3DVector LocalVector
void checkSegmentAlgorithmSpecial(const edm::EventSetup &eSetup)
void MiddlePointsAlgorithm()
ConstMuonRecHitPointer FirstRecHit() const
bool checkStraightwithThreerecHits(ConstMuonRecHitPointer(&precHit)[3], double MinDeltaPhi) const
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Geom::Phi< T > phi() const
weightedTrajectorySeed createSeed(int &isGoodSeed, const edm::EventSetup &eSetup)
Global3DPoint GlobalPoint
double extropolateStep(const GlobalPoint &startPosition, const GlobalVector &startMomentum, ConstMuonRecHitContainer::const_iterator iter, const int ClockwiseDirection, double &tracklength, const edm::EventSetup &eSetup)
std::pair< ConstMuonRecHitPointer, ConstMuonRecHitPointer > RPCSegment
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
LocalTrajectoryError getSpecialAlgorithmErrorMatrix(const ConstMuonRecHitPointer &first, const ConstMuonRecHitPointer &best)
double getDistance(const ConstMuonRecHitPointer &precHit, const GlobalVector &Center) const
const Plane & surface() const
The nominal surface of the GeomDet.
std::string dumpMuonId(const DetId &id) const
uint32_t rawId() const
get the raw id
U second(std::pair< T, U > const &p)
const RPCChamber * chamber(RPCDetId id) const
std::string dumpTSOS(const TrajectoryStateOnSurface &tsos) const
weightedTrajectorySeed seed(const edm::EventSetup &eSetup, int &isGoodSeed)
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
RPCDetId id() const
Return the RPCChamberId of this chamber.
void ThreePointsAlgorithm()
Abs< T >::type abs(const T &t)
ConstMuonRecHitPointer BestRefRecHit() const
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
std::pair< TrajectorySeed, double > weightedTrajectorySeed
double deltaR(double eta1, double eta2, double phi1, double phi2)
T value() const
Explicit access to value in case implicit conversion not OK.
Vector3DBase unit() const
void checkSimplePattern(const edm::EventSetup &eSetup)
void SegmentAlgorithmSpecial(const edm::EventSetup &eSetup)
GlobalVector computePtWithThreerecHits(double &pt, double &pt_err, double(&x)[3], double(&y)[3]) const
CLHEP::HepSymMatrix AlgebraicSymMatrix
bool checkSegment() const
bool checkStraightwithSegment(const RPCSegment &Segment1, const RPCSegment &Segment2, double MinDeltaPhi) const
std::shared_ptr< MuonTransientTrackingRecHit const > ConstMuonRecHitPointer
GlobalVector computePtwithSegment(const RPCSegment &Segment1, const RPCSegment &Segment2) const
GlobalVector computePtwithThreerecHits(double &pt, double &pt_err, ConstMuonRecHitPointer(&precHit)[3]) const
Global3DVector GlobalVector
Basic3DVector cross(const Basic3DVector &v) const
Vector product, or "cross" product, with a vector of same type.
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.