23 #include "gsl/gsl_statistics.h" 31 isPatternChecked =
false;
33 MagnecticFieldThreshold = 0.5;
40 deltaRThreshold = iConfig.
getParameter<
double>(
"deltaRThreshold");
42 autoAlgorithmChoose = iConfig.
getParameter<
bool>(
"autoAlgorithmChoose");
45 MagnecticFieldThreshold = iConfig.
getParameter<
double>(
"MagnecticFieldThreshold");
47 sampleCount = iConfig.
getParameter<
unsigned int>(
"sampleCount");
54 if (isConfigured ==
false) {
55 cout <<
"Configuration not set yet" << endl;
56 return createFakeSeed(isGoodSeed, Field);
60 unsigned int NumberofHitsinSeed = nrhit();
61 if (NumberofHitsinSeed < 3) {
62 return createFakeSeed(isGoodSeed, Field);
65 if (NumberofHitsinSeed == 3)
66 ThreePointsAlgorithm();
68 if (NumberofHitsinSeed > 3) {
69 if (autoAlgorithmChoose ==
false) {
70 cout <<
"computePtWithmorerecHits" << endl;
72 ThreePointsAlgorithm();
74 MiddlePointsAlgorithm();
79 SegmentAlgorithmSpecial(Field);
81 cout <<
"Not enough recHits for Special Segment Algorithm" << endl;
82 return createFakeSeed(isGoodSeed, Field);
88 SegmentAlgorithmSpecial(Field);
97 if (isPatternChecked ==
false) {
99 checkSimplePattern(Field);
101 checkSegmentAlgorithmSpecial(Field, rpcGeom);
105 return createSeed(isGoodSeed, Field);
109 cout <<
"computePtWith3recHits" << endl;
110 unsigned int NumberofHitsinSeed = nrhit();
112 if (NumberofHitsinSeed < 3) {
113 isPatternChecked =
true;
118 unsigned int NumberofPart = NumberofHitsinSeed * (NumberofHitsinSeed - 1) * (NumberofHitsinSeed - 2) / (3 * 2);
120 double*
pt =
new double[NumberofPart];
121 double* pt_err =
new double[NumberofPart];
125 unsigned int NumberofStraight = 0;
126 for (
unsigned int i = 0;
i < (NumberofHitsinSeed - 2);
i++)
127 for (
unsigned int j = (
i + 1);
j < (NumberofHitsinSeed - 1);
j++)
128 for (
unsigned int k = (
j + 1);
k < NumberofHitsinSeed;
k++) {
129 precHit[0] = theRecHits[
i];
130 precHit[1] = theRecHits[
j];
131 precHit[2] = theRecHits[
k];
132 bool checkStraight = checkStraightwithThreerecHits(precHit,
MinDeltaPhi);
133 if (!checkStraight) {
134 GlobalVector Center_temp = computePtwithThreerecHits(
pt[
n], pt_err[
n], precHit);
136 Center += Center_temp;
146 if (NumberofStraight == NumberofPart) {
151 Center /= (NumberofPart - NumberofStraight);
153 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
154 meanR += getDistance(*iter, Center);
155 meanR /= NumberofHitsinSeed;
160 isPatternChecked =
false;
171 cout <<
"Using middle points algorithm" << endl;
172 unsigned int NumberofHitsinSeed = nrhit();
174 if (NumberofHitsinSeed < 4) {
175 isPatternChecked =
true;
179 double*
X =
new double[NumberofHitsinSeed];
180 double*
Y =
new double[NumberofHitsinSeed];
182 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++) {
183 X[
n] = (*iter)->globalPosition().x();
184 Y[
n] = (*iter)->globalPosition().y();
185 cout <<
"X[" <<
n <<
"] = " <<
X[
n] <<
", Y[" <<
n <<
"]= " <<
Y[
n] << endl;
188 unsigned int NumberofPoints = NumberofHitsinSeed;
189 while (NumberofPoints > 3) {
190 for (
unsigned int i = 0;
i <= (NumberofPoints - 2);
i++) {
191 X[
i] = (
X[
i] +
X[
i + 1]) / 2;
192 Y[
i] = (
Y[
i] +
Y[
i + 1]) / 2;
197 for (
unsigned int i = 0;
i < 3;
i++) {
203 bool checkStraight = checkStraightwithThreerecHits(
x, y,
MinDeltaPhi);
204 if (!checkStraight) {
205 GlobalVector Center_temp = computePtWithThreerecHits(
pt, pt_err,
x, y);
207 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
208 meanR += getDistance(*iter, Center_temp);
209 meanR /= NumberofHitsinSeed;
212 Center = Center_temp;
221 isPatternChecked =
false;
228 cout <<
"Using segments algorithm" << endl;
229 unsigned int NumberofHitsinSeed = nrhit();
231 if (NumberofHitsinSeed < 4) {
232 isPatternChecked =
true;
238 unsigned int NumberofSegment = NumberofHitsinSeed - 2;
241 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != (theRecHits.end() - 2); iter++) {
242 Segment[
n].first = (*iter);
243 Segment[
n].second = (*(iter + 2));
246 unsigned int NumberofStraight = 0;
247 for (
unsigned int i = 0;
i < NumberofSegment - 1;
i++) {
248 bool checkStraight = checkStraightwithSegment(Segment[
i], Segment[
i + 1],
MinDeltaPhi);
249 if (checkStraight ==
true) {
253 GlobalVector Center_temp = computePtwithSegment(Segment[
i], Segment[
i + 1]);
255 Center += Center_temp;
259 if ((NumberofSegment - 1 - NumberofStraight) > 0) {
261 Center /= (NumberofSegment - 1 - NumberofStraight);
263 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
264 meanR += getDistance(*iter, Center);
265 meanR /= NumberofHitsinSeed;
273 isPatternChecked =
false;
280 if (!checkSegment()) {
281 isPatternChecked =
true;
287 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != (theRecHits.end() - 1); iter++) {
289 GlobalPoint gpLast = (*(iter + 1))->globalPosition();
291 double dx = (gpLast.
x() - gpFirst.
x()) / (sampleCount + 1);
292 double dy = (gpLast.
y() - gpFirst.
y()) / (sampleCount + 1);
293 double dz = (gpLast.
z() - gpFirst.
z()) / (sampleCount + 1);
298 cout <<
"Sampling magnetic field : " << MagneticVec_temp << endl;
305 ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin();
306 for (
unsigned int n = 0;
n <= 1;
n++) {
307 SegmentRB[
n].first = (*iter);
308 cout <<
"SegmentRB " <<
n <<
" recHit: " << (*iter)->globalPosition() << endl;
310 SegmentRB[
n].second = (*iter);
311 cout <<
"SegmentRB " <<
n <<
" recHit: " << (*iter)->globalPosition() << endl;
314 GlobalVector segvec1 = (SegmentRB[0].second)->globalPosition() - (SegmentRB[0].first)->globalPosition();
315 GlobalVector segvec2 = (SegmentRB[1].second)->globalPosition() - (SegmentRB[1].first)->globalPosition();
318 entryPosition = (SegmentRB[0].second)->globalPosition();
319 leavePosition = (SegmentRB[1].first)->globalPosition();
320 while (fabs(Field.
inTesla(entryPosition).
z()) < MagnecticFieldThreshold) {
321 cout <<
"Entry position is : " << entryPosition <<
", and stepping into next point" << endl;
322 entryPosition += segvec1.
unit() * stepLength;
325 while (fabs(Field.
inTesla(entryPosition).
z()) >= MagnecticFieldThreshold) {
326 cout <<
"Entry position is : " << entryPosition <<
", and stepping back into next point" << endl;
327 entryPosition -= segvec1.
unit() * stepLength / 10;
329 entryPosition += 0.5 * segvec1.
unit() * stepLength / 10;
330 cout <<
"Final entry position is : " << entryPosition << endl;
332 while (fabs(Field.
inTesla(leavePosition).
z()) < MagnecticFieldThreshold) {
333 cout <<
"Leave position is : " << leavePosition <<
", and stepping into next point" << endl;
334 leavePosition -= segvec2.
unit() * stepLength;
337 while (fabs(Field.
inTesla(leavePosition).
z()) >= MagnecticFieldThreshold) {
338 cout <<
"Leave position is : " << leavePosition <<
", and stepping back into next point" << endl;
339 leavePosition += segvec2.
unit() * stepLength / 10;
341 leavePosition -= 0.5 * segvec2.
unit() * stepLength / 10;
342 cout <<
"Final leave position is : " << leavePosition << endl;
346 double dx = (leavePosition.x() - entryPosition.x()) / (sampleCount + 1);
347 double dy = (leavePosition.y() - entryPosition.y()) / (sampleCount + 1);
348 double dz = (leavePosition.z() - entryPosition.z()) / (sampleCount + 1);
349 std::vector<GlobalVector>
BValue;
353 (entryPosition.y() +
dy * (
index + 1)),
354 (entryPosition.z() +
dz * (
index + 1)));
356 cout <<
"Sampling magnetic field : " << MagneticVec_temp << endl;
357 BValue.push_back(MagneticVec_temp);
361 for (std::vector<GlobalVector>::const_iterator BIter =
BValue.begin(); BIter !=
BValue.end(); BIter++)
364 cout <<
"Mean B field is " << meanB2 << endl;
365 meanMagneticField2 = meanB2;
367 double meanBz2 = meanB2.
z();
368 double deltaBz2 = 0.;
369 for (std::vector<GlobalVector>::const_iterator BIter =
BValue.begin(); BIter !=
BValue.end(); BIter++)
370 deltaBz2 += (BIter->z() - meanBz2) * (BIter->z() - meanBz2);
371 deltaBz2 /=
BValue.size();
372 deltaBz2 =
sqrt(deltaBz2);
373 cout <<
"delta Bz is " << deltaBz2 << endl;
377 bool checkStraight = checkStraightwithSegment(SegmentRB[0], SegmentRB[1],
MinDeltaPhi);
378 if (checkStraight ==
true) {
380 isStraight2 = checkStraight;
383 GlobalVector MomentumVec = (SegmentRB[1].second)->globalPosition() - (SegmentRB[0].first)->globalPosition();
384 S += MomentumVec.
perp();
385 lastPhi = MomentumVec.
phi().value();
387 GlobalVector seg1 = entryPosition - (SegmentRB[0].first)->globalPosition();
389 GlobalVector seg2 = (SegmentRB[1].second)->globalPosition() - leavePosition;
394 double A1 = gvec1.
x();
395 double B1 = gvec1.
y();
396 double A2 = gvec2.
x();
397 double B2 = gvec2.
y();
398 double X1 = entryPosition.x();
399 double Y1 = entryPosition.y();
400 double X2 = leavePosition.x();
401 double Y2 = leavePosition.y();
402 double XO = (A1 * A2 * (Y2 - Y1) + A2 * B1 * X1 - A1 * B2 * X2) / (A2 * B1 - A1 * B2);
403 double YO = (B1 * B2 * (X2 - X1) + B2 * A1 * Y1 - B1 * A2 * Y2) / (B2 * A1 - B1 * A2);
406 isStraight2 = checkStraight;
407 Center2 = Center_temp;
409 cout <<
"entryPosition: " << entryPosition << endl;
410 cout <<
"leavePosition: " << leavePosition << endl;
411 cout <<
"Center2 is : " << Center_temp << endl;
413 double R1 =
GlobalVector((entryPosition.x() - Center_temp.
x()),
414 (entryPosition.y() - Center_temp.
y()),
415 (entryPosition.z() - Center_temp.
z()))
417 double R2 =
GlobalVector((leavePosition.x() - Center_temp.
x()),
418 (leavePosition.y() - Center_temp.
y()),
419 (leavePosition.z() - Center_temp.
z()))
421 double meanR = (R1 + R2) / 2;
422 double deltaR =
sqrt(((R1 - meanR) * (R1 - meanR) + (R2 - meanR) * (R2 - meanR)) / 2);
424 cout <<
"R1 is " << R1 <<
", R2 is " << R2 << endl;
425 cout <<
"Mean radius is " << meanR << endl;
430 lastPhi = seg2.
phi().value();
434 isPatternChecked =
false;
439 unsigned int count = 0;
441 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++) {
444 if (dynamic_cast<const RPCChamber*>(
Detector) !=
nullptr) {
448 unsigned int Station = RPCId.
station();
461 cout <<
"Check for segment fit: " << isFit << endl;
472 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++) {
483 return sqrt((precHit->globalPosition().x() - Center.
x()) * (precHit->globalPosition().x() - Center.
x()) +
484 (precHit->globalPosition().y() - Center.
y()) * (precHit->globalPosition().y() - Center.
y()));
488 GlobalVector segvec1 = precHit[1]->globalPosition() - precHit[0]->globalPosition();
489 GlobalVector segvec2 = precHit[2]->globalPosition() - precHit[1]->globalPosition();
490 double dPhi = (segvec2.
phi() - segvec1.
phi()).
value();
492 cout <<
"Part is estimate to be not straight" << endl;
495 cout <<
"Part is estimate to be straight" << endl;
504 x[0] = precHit[0]->globalPosition().x();
505 y[0] = precHit[0]->globalPosition().y();
506 x[1] = precHit[1]->globalPosition().x();
507 y[1] = precHit[1]->globalPosition().y();
508 x[2] = precHit[2]->globalPosition().x();
509 y[2] = precHit[2]->globalPosition().y();
510 double A = (y[2] - y[1]) / (
x[2] -
x[1]) - (y[1] - y[0]) / (
x[1] -
x[0]);
511 double TYO = (
x[2] -
x[0]) /
A + (y[2] * y[2] - y[1] * y[1]) / ((
x[2] -
x[1]) *
A) -
512 (y[1] * y[1] - y[0] * y[0]) / ((
x[1] -
x[0]) *
A);
513 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]);
514 double XO = 0.5 * TXO;
515 double YO = 0.5 * TYO;
516 double R2 = (
x[0] - XO) * (
x[0] - XO) + (y[0] - YO) * (y[0] - YO);
517 cout <<
"R2 is " << R2 << endl;
519 pt = 0.01 *
sqrt(R2) * 2 * 0.3;
520 cout <<
"pt is " <<
pt << endl;
528 GlobalVector segvec1 = (Segment1.second)->globalPosition() - (Segment1.first)->globalPosition();
529 GlobalVector segvec2 = (Segment2.second)->globalPosition() - (Segment2.first)->globalPosition();
530 GlobalVector segvec3 = (Segment2.first)->globalPosition() - (Segment1.first)->globalPosition();
532 double dPhi1 = (segvec2.
phi() - segvec1.
phi()).
value();
533 double dPhi2 = (segvec3.
phi() - segvec1.
phi()).
value();
534 cout <<
"Checking straight with 2 segments. dPhi1: " << dPhi1 <<
", dPhi2: " << dPhi2 << endl;
535 cout <<
"Checking straight with 2 segments. dPhi1 in degree: " << dPhi1 * 180 / 3.1415926
536 <<
", dPhi2 in degree: " << dPhi2 * 180 / 3.1415926 << endl;
538 cout <<
"Segment is estimate to be not straight" << endl;
541 cout <<
"Segment is estimate to be straight" << endl;
547 GlobalVector segvec1 = (Segment1.second)->globalPosition() - (Segment1.first)->globalPosition();
548 GlobalVector segvec2 = (Segment2.second)->globalPosition() - (Segment2.first)->globalPosition();
549 GlobalPoint Point1(((Segment1.second)->globalPosition().x() + (Segment1.first)->globalPosition().x()) / 2,
550 ((Segment1.second)->globalPosition().y() + (Segment1.first)->globalPosition().y()) / 2,
551 ((Segment1.second)->globalPosition().z() + (Segment1.first)->globalPosition().z()) / 2);
552 GlobalPoint Point2(((Segment2.second)->globalPosition().x() + (Segment2.first)->globalPosition().x()) / 2,
553 ((Segment2.second)->globalPosition().y() + (Segment2.first)->globalPosition().y()) / 2,
554 ((Segment2.second)->globalPosition().z() + (Segment2.first)->globalPosition().z()) / 2);
558 double A1 = gvec1.
x();
559 double B1 = gvec1.
y();
560 double A2 = gvec2.
x();
561 double B2 = gvec2.
y();
562 double X1 = Point1.
x();
563 double Y1 = Point1.
y();
564 double X2 = Point2.
x();
565 double Y2 = Point2.
y();
566 double XO = (A1 * A2 * (Y2 - Y1) + A2 * B1 * X1 - A1 * B2 * X2) / (A2 * B1 - A1 * B2);
567 double YO = (B1 * B2 * (X2 - X1) + B2 * A1 * Y1 - B1 * A2 * Y2) / (B2 * A1 - B1 * A2);
575 double dPhi = (segvec2.
phi() - segvec1.
phi()).
value();
577 cout <<
"Part is estimate to be not straight" << endl;
580 cout <<
"Part is estimate to be straight" << endl;
588 double (&y)[3])
const {
589 double A = (y[2] - y[1]) / (
x[2] -
x[1]) - (y[1] - y[0]) / (
x[1] -
x[0]);
590 double TYO = (
x[2] -
x[0]) /
A + (y[2] * y[2] - y[1] * y[1]) / ((
x[2] -
x[1]) *
A) -
591 (y[1] * y[1] - y[0] * y[0]) / ((
x[1] -
x[0]) *
A);
592 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]);
593 double XO = 0.5 * TXO;
594 double YO = 0.5 * TYO;
595 double R2 = (
x[0] - XO) * (
x[0] - XO) + (y[0] - YO) * (y[0] - YO);
596 cout <<
"R2 is " << R2 << endl;
598 pt = 0.01 *
sqrt(R2) * 2 * 0.3;
599 cout <<
"pt is " <<
pt << endl;
605 if (isPatternChecked ==
true)
608 unsigned int NumberofHitsinSeed = nrhit();
611 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
612 cout <<
"Position of recHit is: " << (*iter)->globalPosition() << endl;
615 std::vector<double> BzValue;
616 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != (theRecHits.end() - 1); iter++) {
618 GlobalPoint gpLast = (*(iter + 1))->globalPosition();
620 double dx = (gpLast.
x() - gpFirst.
x()) / (sampleCount + 1);
621 double dy = (gpLast.
y() - gpFirst.
y()) / (sampleCount + 1);
622 double dz = (gpLast.
z() - gpFirst.
z()) / (sampleCount + 1);
627 cout <<
"Sampling magnetic field : " << MagneticVec_temp << endl;
628 BzValue.push_back(MagneticVec_temp.z());
634 meanBz += BzValue[
index];
635 meanBz /= BzValue.size();
636 cout <<
"Mean Bz is " << meanBz << endl;
639 deltaBz += (BzValue[
index] - meanBz) * (BzValue[
index] - meanBz);
640 deltaBz /= BzValue.size();
641 deltaBz =
sqrt(deltaBz);
642 cout <<
"delata Bz is " << deltaBz << endl;
648 if (fabs((*(theRecHits.end() - 1))->globalPosition().z() - (*(theRecHits.begin()))->globalPosition().z()) > ZError) {
649 if (((*(theRecHits.end() - 1))->globalPosition().z() - (*(theRecHits.begin()))->globalPosition().z()) > ZError)
656 cout <<
" Check isParralZ is :" << isParralZ << endl;
657 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != (theRecHits.end() - 1); iter++) {
658 if (isParralZ == 0) {
659 if (fabs((*(iter + 1))->globalPosition().z() - (*iter)->globalPosition().z()) > ZError) {
660 cout <<
"Pattern find error in Z direction: wrong perpendicular direction" << endl;
664 if ((
int)(((*(iter + 1))->globalPosition().z() - (*iter)->globalPosition().z()) / ZError) * isParralZ < 0) {
665 cout <<
"Pattern find error in Z direction: wrong Z direction" << endl;
672 if (isStraight ==
false) {
675 unsigned int index = 0;
676 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++) {
677 GlobalVector vec_temp(((*iter)->globalPosition().x() - Center.x()),
678 ((*iter)->globalPosition().y() - Center.y()),
679 ((*iter)->globalPosition().z() - Center.z()));
680 vec[
index] = vec_temp;
684 for (
unsigned int index = 0;
index < (NumberofHitsinSeed - 1);
index++) {
686 if ((vec[
index + 1].phi() - vec[
index].phi()) > 0)
690 cout <<
"Current isClockwise is : " << isClockwise << endl;
692 cout <<
"Check isClockwise is : " << isClockwise << endl;
693 if ((
unsigned int)
abs(isClockwise) != (NumberofHitsinSeed - 1)) {
694 cout <<
"Pattern find error in Phi direction" << endl;
698 isClockwise /=
abs(isClockwise);
702 double deltaRwithBz = fabs(deltaBz * meanRadius / meanBz);
703 cout <<
"deltaR with Bz is " << deltaRwithBz << endl;
705 if (isClockwise == 0)
708 meanPt = 0.01 * meanRadius * meanBz * 0.3 * isClockwise;
711 cout <<
" meanRadius is " << meanRadius << endl;
712 cout <<
" meanPt is " << meanPt << endl;
715 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++) {
716 deltaR += (getDistance(*iter, Center) - meanRadius) * (getDistance(*iter, Center) - meanRadius);
723 if (
deltaR > deltaRThreshold) {
724 cout <<
"Pattern find error: deltaR over threshold" << endl;
732 meanSpt = deltaRThreshold;
734 cout <<
"III--> Seed Pt : " << meanPt << endl;
735 cout <<
"III--> Pattern is: " << isGoodPattern << endl;
738 isPatternChecked =
true;
742 if (isPatternChecked ==
true)
745 if (!checkSegment()) {
746 isPatternChecked =
true;
755 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
756 cout <<
"Position of recHit is: " << (*iter)->globalPosition() << endl;
759 if (fabs((*(theRecHits.end() - 1))->globalPosition().z() - (*(theRecHits.begin()))->globalPosition().z()) > ZError) {
760 if (((*(theRecHits.end() - 1))->globalPosition().z() - (*(theRecHits.begin()))->globalPosition().z()) > ZError)
767 cout <<
" Check isParralZ is :" << isParralZ << endl;
768 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != (theRecHits.end() - 1); iter++) {
769 if (isParralZ == 0) {
770 if (fabs((*(iter + 1))->globalPosition().z() - (*iter)->globalPosition().z()) > ZError) {
771 cout <<
"Pattern find error in Z direction: wrong perpendicular direction" << endl;
775 if ((
int)(((*(iter + 1))->globalPosition().z() - (*iter)->globalPosition().z()) / ZError) * isParralZ < 0) {
776 cout <<
"Pattern find error in Z direction: wrong Z direction" << endl;
783 if (isStraight2 ==
true) {
788 meanSpt = deltaRThreshold;
791 GlobalVector startSegment = (SegmentRB[1].second)->globalPosition() - (SegmentRB[1].first)->globalPosition();
792 GlobalPoint startPosition = (SegmentRB[1].first)->globalPosition();
794 unsigned int index = 0;
796 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++) {
801 double tracklength = 0;
802 cout <<
"Now checking recHit " <<
index << endl;
803 double Distance = extropolateStep(startPosition, startMomentum, iter, isClockwise, tracklength, Field, rpcGeom);
804 cout <<
"Final distance is " << Distance << endl;
805 if (Distance > MaxRSD) {
806 cout <<
"Pattern find error in distance for other recHits: " << Distance << endl;
815 (entryPosition.x() - Center2.x()), (entryPosition.y() - Center2.y()), (entryPosition.z() - Center2.z()));
817 (leavePosition.x() - Center2.x()), (leavePosition.y() - Center2.y()), (leavePosition.z() - Center2.z()));
819 if ((vec[1].phi() - vec[0].phi()).
value() > 0)
824 cout <<
"Check isClockwise is : " << isClockwise << endl;
827 meanPt = 0.01 * meanRadius2 * meanMagneticField2.z() * 0.3 * isClockwise;
829 cout <<
" meanRadius is " << meanRadius2 <<
", with meanBz " << meanMagneticField2.z() << endl;
830 cout <<
" meanPt is " << meanPt << endl;
835 cout <<
"entryPosition: " << entryPosition << endl;
836 cout <<
"leavePosition: " << leavePosition << endl;
837 cout <<
"Center2 is : " << Center2 << endl;
838 double R1 = vec[0].
perp();
839 double R2 = vec[1].
perp();
840 double deltaR =
sqrt(((R1 - meanRadius2) * (R1 - meanRadius2) + (R2 - meanRadius2) * (R2 - meanRadius2)) / 2);
842 cout <<
"R1 is " << R1 <<
", R2 is " << R2 << endl;
843 cout <<
"Delta R for the initial 3 segments is " <<
deltaR << endl;
844 if (
deltaR > deltaRThreshold) {
845 cout <<
"Pattern find error in delta R for the initial 3 segments" << endl;
850 GlobalVector startSegment = (SegmentRB[1].second)->globalPosition() - (SegmentRB[1].first)->globalPosition();
851 GlobalPoint startPosition = (SegmentRB[1].first)->globalPosition();
852 GlobalVector startMomentum = startSegment * (fabs(meanPt) / startSegment.
perp());
853 unsigned int index = 0;
854 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++) {
859 double tracklength = 0;
860 cout <<
"Now checking recHit " <<
index << endl;
861 double Distance = extropolateStep(startPosition, startMomentum, iter, isClockwise, tracklength, Field, rpcGeom);
862 cout <<
"Final distance is " << Distance << endl;
863 if (Distance > MaxRSD) {
864 cout <<
"Pattern find error in distance for other recHits: " << Distance << endl;
871 cout <<
"Checking finish, isGoodPattern now is " << isGoodPattern << endl;
873 isPatternChecked =
true;
878 ConstMuonRecHitContainer::const_iterator iter,
879 const int ClockwiseDirection,
883 cout <<
"Extrapolating the track to check the pattern" << endl;
886 DetId hitDet = (*iter)->hit()->geographicalId();
891 double startSide = RPCSurface.
localZ(startPosition);
892 cout <<
"Start side : " << startSide;
899 double currentDistance = ((
GlobalVector)(currentPosition - (*iter)->globalPosition())).perp();
900 cout <<
"Start current position is : " << currentPosition << endl;
901 cout <<
"Start current Momentum is: " << currentMomentum.
mag() <<
", in vector: " << currentMomentum << endl;
902 cout <<
"Start current distance is " << currentDistance << endl;
903 cout <<
"Start current radius is " << currentPosition.
perp() << endl;
904 cout <<
"Destination radius is " << (*iter)->globalPosition().perp() << endl;
908 double currentDistance_next = currentDistance;
910 currentDistance = currentDistance_next;
911 if (ClockwiseDirection == 0) {
912 currentPosition += currentMomentum.
unit() * stepLength;
914 double Bz = Field.
inTesla(currentPosition).
z();
915 double Radius = currentMomentum.
perp() / fabs(Bz * 0.01 * 0.3);
916 double deltaPhi = (stepLength * currentMomentum.
perp() / currentMomentum.
mag()) / Radius;
920 currentPositiontoCenter *= Radius;
922 currentPositiontoCenter *= ClockwiseDirection;
925 currentCenter += currentPositiontoCenter;
929 double Phi = CentertocurrentPosition.
phi().value();
931 double deltaZ = stepLength * currentMomentum.
z() / currentMomentum.
mag();
933 double PtPhi = currentMomentum.
phi().value();
934 PtPhi +=
deltaPhi * (-1) * ClockwiseDirection;
936 currentPosition = currentCenter + CentertonewPosition;
940 tracklength += stepLength * currentMomentum.
perp() / currentMomentum.
mag();
943 double currentSide = RPCSurface.localZ(currentPosition);
944 cout <<
"Stepping current side : " << currentSide << endl;
945 cout <<
"Stepping current position is: " << currentPosition << endl;
946 cout <<
"Stepping current Momentum is: " << currentMomentum.
mag() <<
", in vector: " << currentMomentum << endl;
947 currentDistance_next = ((
GlobalVector)(currentPosition - (*iter)->globalPosition())).
perp();
948 cout <<
"Stepping current distance is " << currentDistance << endl;
949 cout <<
"Stepping current radius is " << currentPosition.
perp() << endl;
950 }
while (currentDistance_next < currentDistance);
952 return currentDistance;
957 cout <<
"Now create a fake seed" << endl;
958 isPatternChecked =
true;
974 LocalVector segDirFromPos = best->det()->toLocal(Momentum);
979 mat = best->parametersError().similarityT(best->projectionMatrix());
985 DetId id = best->geographicalId();
990 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
991 container.
push_back((*iter)->hit()->clone());
995 theweightedSeed.first = theSeed;
996 theweightedSeed.second = meanSpt;
997 isGoodSeed = isGoodPattern;
999 return theweightedSeed;
1003 if (isPatternChecked ==
false || isGoodPattern == -1) {
1004 cout <<
"Pattern is not yet checked! Create a fake seed instead!" << endl;
1005 return createFakeSeed(isGoodSeed, Field);
1015 if (isClockwise == 0)
1024 if (isClockwise != 0) {
1028 (
first->globalPosition().y() - Center.y()),
1029 (
first->globalPosition().z() - Center.z()));
1030 GlobalVector vecRef2((best->globalPosition().x() - Center.x()),
1031 (best->globalPosition().y() - Center.y()),
1032 (best->globalPosition().z() - Center.z()));
1035 double deltaS = meanRadius * fabs(
deltaPhi);
1036 double deltaZ = best->globalPosition().z() -
first->globalPosition().z();
1040 if (isClockwise == -1)
1045 Momentum *= fabs(meanPt / deltaS);
1047 double deltaZ = best->globalPosition().z() -
first->globalPosition().z();
1049 Momentum *= fabs(meanPt /
S);
1052 Momentum = best->globalPosition() -
first->globalPosition();
1053 double deltaS = Momentum.perp();
1054 Momentum *= fabs(meanPt / deltaS);
1057 LocalVector segDirFromPos = best->det()->toLocal(Momentum);
1063 cout <<
"Trajectory State on Surface before the extrapolation" << endl;
1065 DetId id = best->geographicalId();
1066 cout <<
"The RecSegment relies on: " << endl;
1073 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++) {
1078 container.
push_back((*iter)->hit()->clone());
1083 theweightedSeed.first = theSeed;
1084 theweightedSeed.second = meanSpt;
1085 isGoodSeed = isGoodPattern;
1087 return theweightedSeed;
1097 mat = best->parametersError().similarityT(best->projectionMatrix());
1100 (
first->globalPosition().y() - Center.y()),
1101 (
first->globalPosition().z() - Center.z()));
1102 GlobalVector vecRef2((best->globalPosition().x() - Center.x()),
1103 (best->globalPosition().y() - Center.y()),
1104 (best->globalPosition().z() - Center.z()));
1108 double A_N = 180 *
N *
N *
N / ((
N - 1) * (
N + 1) * (
N + 2) * (
N + 3));
1110 double betaovergame = Momentum.mag() / 0.1066;
1111 double beta =
sqrt((betaovergame * betaovergame) / (1 + betaovergame * betaovergame));
1112 double dPt = meanPt * (0.0136 *
sqrt(1 / 100) *
sqrt(4 * A_N /
N) / (
beta * 0.3 * meanBz *
L) +
1114 double dP = dPt * Momentum.mag() / meanPt;
1115 mat[0][0] = (dP * dP) / (Momentum.mag() * Momentum.mag() * Momentum.mag() * Momentum.mag());
1116 mat[1][1] = dXdZ * dXdZ;
1117 mat[2][2] = dYdZ * dYdZ;
1121 mat0 = (SegmentRB[0].first)->parametersError().similarityT((SegmentRB[0].
first)->projectionMatrix());
1122 double dX0 =
sqrt(mat0[3][3]);
1123 double dY0 =
sqrt(mat0[4][4]);
1125 mat1 = (SegmentRB[0].second)->parametersError().similarityT((SegmentRB[0].
second)->projectionMatrix());
1126 double dX1 =
sqrt(mat1[3][3]);
1127 double dY1 =
sqrt(mat1[4][4]);
1129 mat2 = (SegmentRB[1].first)->parametersError().similarityT((SegmentRB[1].
first)->projectionMatrix());
1130 double dX2 =
sqrt(mat2[3][3]);
1131 double dY2 =
sqrt(mat2[4][4]);
1133 mat3 = (SegmentRB[1].second)->parametersError().similarityT((SegmentRB[1].
second)->projectionMatrix());
1134 double dX3 =
sqrt(mat3[3][3]);
1135 double dY3 =
sqrt(mat3[4][4]);
1136 cout <<
"Local error for 4 recHits are: " << dX0 <<
", " << dY0 <<
", " << dX1 <<
", " << dY1 <<
", " << dX2 <<
", " 1137 << dY2 <<
", " << dX3 <<
", " << dY3 << endl;
1138 const GeomDetUnit* refRPC1 = (SegmentRB[0].second)->detUnit();
1148 const GeomDetUnit* refRPC2 = (SegmentRB[1].first)->detUnit();
1158 if (isClockwise != 0) {
1161 (entryPosition.x() - Center2.x()), (entryPosition.y() - Center2.y()), (entryPosition.z() - Center2.z()));
1163 (leavePosition.x() - Center2.x()), (leavePosition.y() - Center2.y()), (leavePosition.z() - Center2.z()));
1164 double halfPhiCenter = fabs((vec[1].phi() - vec[0].phi()).
value()) / 2;
1166 double dPhi0 = (((globalSegment00.phi() - globalSegment01.
phi()).
value() * isClockwise) > 0)
1167 ? fabs((globalSegment00.phi() - globalSegment01.
phi()).
value())
1168 : fabs((globalSegment00.phi() - globalSegment02.
phi()).
value());
1169 double dPhi1 = (((globalSegment10.phi() - globalSegment11.
phi()).
value() * isClockwise) < 0)
1170 ? fabs((globalSegment10.phi() - globalSegment11.
phi()).
value())
1171 : fabs((globalSegment10.phi() - globalSegment12.
phi()).
value());
1173 double dPhi = (dPhi0 <= dPhi1) ? dPhi0 : dPhi1;
1174 cout <<
"DPhi for new Segment is about " << dPhi << endl;
1176 double newhalfPhiCenter = ((halfPhiCenter - dPhi) > 0 ? (halfPhiCenter - dPhi) : 0);
1177 if (newhalfPhiCenter != 0) {
1178 double newmeanPt = meanPt * halfPhiCenter / newhalfPhiCenter;
1181 cout <<
"The error is inside range. Max meanPt could be " << newmeanPt << endl;
1182 dP = fabs(Momentum.mag() * (newmeanPt - meanPt) / meanPt);
1185 cout <<
"The error is outside range. Max meanPt could be " << newmeanPt << endl;
1186 dP = fabs(Momentum.mag() * (newmeanPt - meanPt) / meanPt);
1189 double dPhi0 = (fabs((globalSegment00.phi() - globalSegment01.
phi()).
value()) <=
1190 fabs((globalSegment00.phi() - globalSegment02.
phi()).
value()))
1191 ? fabs((globalSegment00.phi() - globalSegment01.
phi()).
value())
1192 : fabs((globalSegment00.phi() - globalSegment02.
phi()).
value());
1193 double dPhi1 = (fabs((globalSegment10.phi() - globalSegment11.
phi()).
value()) <=
1194 fabs((globalSegment10.phi() - globalSegment12.
phi()).
value()))
1195 ? fabs((globalSegment10.phi() - globalSegment11.
phi()).
value())
1196 : fabs((globalSegment10.phi() - globalSegment12.
phi()).
value());
1197 double dPhi = (dPhi0 <= dPhi1) ? dPhi0 : dPhi1;
1198 GlobalVector middleSegment = leavePosition - entryPosition;
1199 double halfDistance = middleSegment.
perp() / 2;
1200 double newmeanPt = halfDistance / dPhi;
1201 cout <<
"The error is for straight. Max meanPt could be " << newmeanPt << endl;
1202 dP = fabs(Momentum.mag() * (newmeanPt - meanPt) / meanPt);
1205 double dXdZ1 = globalSegment11.
x() / globalSegment11.
z() - globalSegment10.x() / globalSegment10.z();
1206 double dXdZ2 = globalSegment12.
x() / globalSegment12.
z() - globalSegment10.x() / globalSegment10.z();
1207 dXdZ = (fabs(dXdZ1) >= fabs(dXdZ2)) ? dXdZ1 : dXdZ2;
1213 double dYdZ1 = globalSegment13.
y() / globalSegment13.z() - globalSegment10.y() / globalSegment10.z();
1214 double dYdZ2 = globalSegment14.
y() / globalSegment14.
z() - globalSegment10.y() / globalSegment10.z();
1215 dYdZ = (fabs(dYdZ1) >= fabs(dYdZ2)) ? dYdZ1 : dYdZ2;
1217 mat[0][0] = (dP * dP) / (Momentum.mag() * Momentum.mag() * Momentum.mag() * Momentum.mag());
1218 mat[1][1] = dXdZ * dXdZ;
1219 mat[2][2] = dYdZ * dYdZ;
MuonTransientTrackingRecHit::ConstMuonRecHitPointer ConstMuonRecHitPointer
double extropolateStep(const GlobalPoint &startPosition, const GlobalVector &startMomentum, ConstMuonRecHitContainer::const_iterator iter, const int ClockwiseDirection, double &tracklength, const MagneticField &Field, const RPCGeometry &rpcGeometry)
edm::ErrorSummaryEntry Error
void configure(const edm::ParameterSet &iConfig)
T getParameter(std::string const &) const
Basic3DVector cross(const Basic3DVector &v) const
Vector product, or "cross" product, with a vector of same type.
Local3DVector LocalVector
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
ConstMuonRecHitPointer BestRefRecHit() const
weightedTrajectorySeed createSeed(int &isGoodSeed, const MagneticField &)
void MiddlePointsAlgorithm()
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
Geom::Phi< T > phi() const
Global3DPoint GlobalPoint
std::pair< ConstMuonRecHitPointer, ConstMuonRecHitPointer > RPCSegment
GlobalVector computePtWithThreerecHits(double &pt, double &pt_err, double(&x)[3], double(&y)[3]) const
LocalTrajectoryError getSpecialAlgorithmErrorMatrix(const ConstMuonRecHitPointer &first, const ConstMuonRecHitPointer &best)
U second(std::pair< T, U > const &p)
GlobalVector computePtwithSegment(const RPCSegment &Segment1, const RPCSegment &Segment2) const
bool checkSegment() const
RPCDetId id() const
Return the RPCChamberId of this chamber.
void ThreePointsAlgorithm()
Abs< T >::type abs(const T &t)
bool checkStraightwithThreerecHits(ConstMuonRecHitPointer(&precHit)[3], double MinDeltaPhi) const
double getDistance(const ConstMuonRecHitPointer &precHit, const GlobalVector &Center) const
void SegmentAlgorithmSpecial(const MagneticField &Field)
std::pair< TrajectorySeed, double > weightedTrajectorySeed
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
ConstMuonRecHitPointer FirstRecHit() const
void checkSegmentAlgorithmSpecial(const MagneticField &Field, const RPCGeometry &rpcGeometry)
float localZ(const GlobalPoint &gp) const
const Plane & surface() const
The nominal surface of the GeomDet.
const RPCChamber * chamber(RPCDetId id) const
constexpr uint32_t rawId() const
get the raw id
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
void checkSimplePattern(const MagneticField &Field)
bool checkStraightwithSegment(const RPCSegment &Segment1, const RPCSegment &Segment2, double MinDeltaPhi) const
CLHEP::HepSymMatrix AlgebraicSymMatrix
Vector3DBase unit() const
GlobalVector computePtwithThreerecHits(double &pt, double &pt_err, ConstMuonRecHitPointer(&precHit)[3]) const
std::shared_ptr< MuonTransientTrackingRecHit const > ConstMuonRecHitPointer
weightedTrajectorySeed createFakeSeed(int &isGoodSeed, const MagneticField &)
Global3DVector GlobalVector
weightedTrajectorySeed seed(const MagneticField &Field, const RPCGeometry &rpcGeom, int &isGoodSeed)