25 #include "gsl/gsl_statistics.h"
33 isPatternChecked =
false;
35 MagnecticFieldThreshold = 0.5;
42 deltaRThreshold = iConfig.
getParameter<
double>(
"deltaRThreshold");
44 autoAlgorithmChoose = iConfig.
getParameter<
bool>(
"autoAlgorithmChoose");
46 MinDeltaPhi = iConfig.
getParameter<
double>(
"MinDeltaPhi");
47 MagnecticFieldThreshold = iConfig.
getParameter<
double>(
"MagnecticFieldThreshold");
49 sampleCount = iConfig.
getParameter<
unsigned int>(
"sampleCount");
54 if (isConfigured ==
false) {
55 cout <<
"Configuration not set yet" << endl;
56 return createFakeSeed(isGoodSeed, eSetup);
60 unsigned int NumberofHitsinSeed = nrhit();
61 if (NumberofHitsinSeed < 3)
62 return createFakeSeed(isGoodSeed, eSetup);
64 if (NumberofHitsinSeed == 3)
65 ThreePointsAlgorithm();
67 if (NumberofHitsinSeed > 3) {
68 if (autoAlgorithmChoose ==
false) {
69 cout <<
"computePtWithmorerecHits" << endl;
71 ThreePointsAlgorithm();
73 MiddlePointsAlgorithm();
78 SegmentAlgorithmSpecial(eSetup);
80 cout <<
"Not enough recHits for Special Segment Algorithm" << endl;
81 return createFakeSeed(isGoodSeed, eSetup);
87 SegmentAlgorithmSpecial(eSetup);
96 if (isPatternChecked ==
false) {
98 checkSimplePattern(eSetup);
100 checkSegmentAlgorithmSpecial(eSetup);
104 return createSeed(isGoodSeed, eSetup);
108 cout <<
"computePtWith3recHits" << endl;
109 unsigned int NumberofHitsinSeed = nrhit();
111 if (NumberofHitsinSeed < 3) {
112 isPatternChecked =
true;
117 unsigned int NumberofPart = NumberofHitsinSeed * (NumberofHitsinSeed - 1) * (NumberofHitsinSeed - 2) / (3 * 2);
119 double*
pt =
new double[NumberofPart];
120 double* pt_err =
new double[NumberofPart];
124 unsigned int NumberofStraight = 0;
125 for (
unsigned int i = 0;
i < (NumberofHitsinSeed - 2);
i++)
126 for (
unsigned int j = (
i + 1);
j < (NumberofHitsinSeed - 1);
j++)
127 for (
unsigned int k = (
j + 1);
k < NumberofHitsinSeed;
k++) {
128 precHit[0] = theRecHits[
i];
129 precHit[1] = theRecHits[
j];
130 precHit[2] = theRecHits[
k];
131 bool checkStraight = checkStraightwithThreerecHits(precHit, MinDeltaPhi);
132 if (!checkStraight) {
133 GlobalVector Center_temp = computePtwithThreerecHits(pt[n], pt_err[n], precHit);
135 Center += Center_temp;
145 if (NumberofStraight == NumberofPart) {
150 Center /= (NumberofPart - NumberofStraight);
152 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
153 meanR += getDistance(*iter, Center);
154 meanR /= NumberofHitsinSeed;
159 isPatternChecked =
false;
170 cout <<
"Using middle points algorithm" << endl;
171 unsigned int NumberofHitsinSeed = nrhit();
173 if (NumberofHitsinSeed < 4) {
174 isPatternChecked =
true;
178 double*
X =
new double[NumberofHitsinSeed];
179 double*
Y =
new double[NumberofHitsinSeed];
181 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++) {
182 X[
n] = (*iter)->globalPosition().x();
183 Y[
n] = (*iter)->globalPosition().y();
184 cout <<
"X[" << n <<
"] = " << X[
n] <<
", Y[" << n <<
"]= " << Y[
n] << endl;
187 unsigned int NumberofPoints = NumberofHitsinSeed;
188 while (NumberofPoints > 3) {
189 for (
unsigned int i = 0;
i <= (NumberofPoints - 2);
i++) {
190 X[
i] = (X[
i] + X[
i + 1]) / 2;
191 Y[
i] = (Y[
i] + Y[
i + 1]) / 2;
196 for (
unsigned int i = 0;
i < 3;
i++) {
202 bool checkStraight = checkStraightwithThreerecHits(x, y, MinDeltaPhi);
203 if (!checkStraight) {
204 GlobalVector Center_temp = computePtWithThreerecHits(pt, pt_err, x, y);
206 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
207 meanR += getDistance(*iter, Center_temp);
208 meanR /= NumberofHitsinSeed;
211 Center = Center_temp;
220 isPatternChecked =
false;
227 cout <<
"Using segments algorithm" << endl;
228 unsigned int NumberofHitsinSeed = nrhit();
230 if (NumberofHitsinSeed < 4) {
231 isPatternChecked =
true;
237 unsigned int NumberofSegment = NumberofHitsinSeed - 2;
240 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != (theRecHits.end() - 2); iter++) {
241 Segment[
n].first = (*iter);
242 Segment[
n].second = (*(iter + 2));
245 unsigned int NumberofStraight = 0;
246 for (
unsigned int i = 0;
i < NumberofSegment - 1;
i++) {
247 bool checkStraight = checkStraightwithSegment(Segment[
i], Segment[i + 1], MinDeltaPhi);
248 if (checkStraight ==
true) {
252 GlobalVector Center_temp = computePtwithSegment(Segment[i], Segment[i + 1]);
254 Center += Center_temp;
258 if ((NumberofSegment - 1 - NumberofStraight) > 0) {
260 Center /= (NumberofSegment - 1 - NumberofStraight);
262 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
263 meanR += getDistance(*iter, Center);
264 meanR /= NumberofHitsinSeed;
272 isPatternChecked =
false;
283 if (!checkSegment()) {
284 isPatternChecked =
true;
290 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != (theRecHits.end() - 1); iter++) {
292 GlobalPoint gpLast = (*(iter + 1))->globalPosition();
294 double dx = (gpLast.
x() - gpFirst.
x()) / (sampleCount + 1);
295 double dy = (gpLast.
y() - gpFirst.
y()) / (sampleCount + 1);
296 double dz = (gpLast.
z() - gpFirst.
z()) / (sampleCount + 1);
299 (gpFirst.
x() + dx * (
index + 1)), (gpFirst.
y() + dy * (
index + 1)), (gpFirst.
z() + dz * (
index + 1)));
301 cout <<
"Sampling magnetic field : " << MagneticVec_temp << endl;
308 ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin();
309 for (
unsigned int n = 0;
n <= 1;
n++) {
310 SegmentRB[
n].first = (*iter);
311 cout <<
"SegmentRB " <<
n <<
" recHit: " << (*iter)->globalPosition() << endl;
313 SegmentRB[
n].second = (*iter);
314 cout <<
"SegmentRB " <<
n <<
" recHit: " << (*iter)->globalPosition() << endl;
317 GlobalVector segvec1 = (SegmentRB[0].second)->globalPosition() - (SegmentRB[0].first)->globalPosition();
318 GlobalVector segvec2 = (SegmentRB[1].second)->globalPosition() - (SegmentRB[1].first)->globalPosition();
321 entryPosition = (SegmentRB[0].second)->globalPosition();
322 leavePosition = (SegmentRB[1].first)->globalPosition();
323 while (fabs(Field->inTesla(entryPosition).z()) < MagnecticFieldThreshold) {
324 cout <<
"Entry position is : " << entryPosition <<
", and stepping into next point" << endl;
325 entryPosition += segvec1.
unit() * stepLength;
328 while (fabs(Field->inTesla(entryPosition).z()) >= MagnecticFieldThreshold) {
329 cout <<
"Entry position is : " << entryPosition <<
", and stepping back into next point" << endl;
330 entryPosition -= segvec1.
unit() * stepLength / 10;
332 entryPosition += 0.5 * segvec1.
unit() * stepLength / 10;
333 cout <<
"Final entry position is : " << entryPosition << endl;
335 while (fabs(Field->inTesla(leavePosition).z()) < MagnecticFieldThreshold) {
336 cout <<
"Leave position is : " << leavePosition <<
", and stepping into next point" << endl;
337 leavePosition -= segvec2.
unit() * stepLength;
340 while (fabs(Field->inTesla(leavePosition).z()) >= MagnecticFieldThreshold) {
341 cout <<
"Leave position is : " << leavePosition <<
", and stepping back into next point" << endl;
342 leavePosition += segvec2.
unit() * stepLength / 10;
344 leavePosition -= 0.5 * segvec2.
unit() * stepLength / 10;
345 cout <<
"Final leave position is : " << leavePosition << endl;
349 double dx = (leavePosition.x() - entryPosition.x()) / (sampleCount + 1);
350 double dy = (leavePosition.y() - entryPosition.y()) / (sampleCount + 1);
351 double dz = (leavePosition.z() - entryPosition.z()) / (sampleCount + 1);
352 std::vector<GlobalVector> BValue;
356 (entryPosition.y() + dy * (
index + 1)),
357 (entryPosition.z() + dz * (
index + 1)));
359 cout <<
"Sampling magnetic field : " << MagneticVec_temp << endl;
360 BValue.push_back(MagneticVec_temp);
364 for (std::vector<GlobalVector>::const_iterator BIter = BValue.begin(); BIter != BValue.end(); BIter++)
366 meanB2 /= BValue.size();
367 cout <<
"Mean B field is " << meanB2 << endl;
368 meanMagneticField2 = meanB2;
370 double meanBz2 = meanB2.
z();
371 double deltaBz2 = 0.;
372 for (std::vector<GlobalVector>::const_iterator BIter = BValue.begin(); BIter != BValue.end(); BIter++)
373 deltaBz2 += (BIter->z() - meanBz2) * (BIter->z() - meanBz2);
374 deltaBz2 /= BValue.size();
375 deltaBz2 =
sqrt(deltaBz2);
376 cout <<
"delta Bz is " << deltaBz2 << endl;
380 bool checkStraight = checkStraightwithSegment(SegmentRB[0], SegmentRB[1], MinDeltaPhi);
381 if (checkStraight ==
true) {
383 isStraight2 = checkStraight;
386 GlobalVector MomentumVec = (SegmentRB[1].second)->globalPosition() - (SegmentRB[0].first)->globalPosition();
387 S += MomentumVec.
perp();
388 lastPhi = MomentumVec.
phi().value();
390 GlobalVector seg1 = entryPosition - (SegmentRB[0].first)->globalPosition();
392 GlobalVector seg2 = (SegmentRB[1].second)->globalPosition() - leavePosition;
397 double A1 = gvec1.
x();
398 double B1 = gvec1.
y();
399 double A2 = gvec2.
x();
400 double B2 = gvec2.
y();
401 double X1 = entryPosition.x();
402 double Y1 = entryPosition.y();
403 double X2 = leavePosition.x();
404 double Y2 = leavePosition.y();
405 double XO = (A1 * A2 * (Y2 - Y1) + A2 * B1 * X1 - A1 * B2 * X2) / (A2 * B1 - A1 * B2);
406 double YO = (B1 * B2 * (X2 - X1) + B2 * A1 * Y1 - B1 * A2 * Y2) / (B2 * A1 - B1 * A2);
409 isStraight2 = checkStraight;
410 Center2 = Center_temp;
412 cout <<
"entryPosition: " << entryPosition << endl;
413 cout <<
"leavePosition: " << leavePosition << endl;
414 cout <<
"Center2 is : " << Center_temp << endl;
416 double R1 =
GlobalVector((entryPosition.x() - Center_temp.
x()),
417 (entryPosition.y() - Center_temp.
y()),
418 (entryPosition.z() - Center_temp.
z()))
420 double R2 =
GlobalVector((leavePosition.x() - Center_temp.
x()),
421 (leavePosition.y() - Center_temp.
y()),
422 (leavePosition.z() - Center_temp.
z()))
424 double meanR = (R1 + R2) / 2;
425 double deltaR =
sqrt(((R1 - meanR) * (R1 - meanR) + (R2 - meanR) * (R2 - meanR)) / 2);
427 cout <<
"R1 is " << R1 <<
", R2 is " << R2 << endl;
428 cout <<
"Mean radius is " << meanR << endl;
429 cout <<
"Delta R is " << deltaR << endl;
433 lastPhi = seg2.
phi().value();
437 isPatternChecked =
false;
442 unsigned int count = 0;
444 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++) {
447 if (dynamic_cast<const RPCChamber*>(Detector) !=
nullptr) {
450 int Region = RPCId.
region();
451 unsigned int Station = RPCId.
station();
464 cout <<
"Check for segment fit: " << isFit << endl;
475 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++) {
486 return sqrt((precHit->globalPosition().x() - Center.
x()) * (precHit->globalPosition().x() - Center.
x()) +
487 (precHit->globalPosition().y() - Center.
y()) * (precHit->globalPosition().y() - Center.
y()));
491 GlobalVector segvec1 = precHit[1]->globalPosition() - precHit[0]->globalPosition();
492 GlobalVector segvec2 = precHit[2]->globalPosition() - precHit[1]->globalPosition();
493 double dPhi = (segvec2.
phi() - segvec1.
phi()).
value();
494 if (fabs(dPhi) > MinDeltaPhi) {
495 cout <<
"Part is estimate to be not straight" << endl;
498 cout <<
"Part is estimate to be straight" << endl;
507 x[0] = precHit[0]->globalPosition().x();
508 y[0] = precHit[0]->globalPosition().y();
509 x[1] = precHit[1]->globalPosition().x();
510 y[1] = precHit[1]->globalPosition().y();
511 x[2] = precHit[2]->globalPosition().x();
512 y[2] = precHit[2]->globalPosition().y();
513 double A = (y[2] - y[1]) / (x[2] - x[1]) - (y[1] - y[0]) / (x[1] - x[0]);
514 double TYO = (x[2] - x[0]) / A + (y[2] * y[2] - y[1] * y[1]) / ((x[2] - x[1]) * A) -
515 (y[1] * y[1] - y[0] * y[0]) / ((x[1] - x[0]) *
A);
516 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]);
517 double XO = 0.5 * TXO;
518 double YO = 0.5 * TYO;
519 double R2 = (x[0] - XO) * (x[0] - XO) + (y[0] - YO) * (y[0] - YO);
520 cout <<
"R2 is " << R2 << endl;
522 pt = 0.01 *
sqrt(R2) * 2 * 0.3;
523 cout <<
"pt is " << pt << endl;
530 double MinDeltaPhi)
const {
531 GlobalVector segvec1 = (Segment1.second)->globalPosition() - (Segment1.first)->globalPosition();
532 GlobalVector segvec2 = (Segment2.second)->globalPosition() - (Segment2.first)->globalPosition();
533 GlobalVector segvec3 = (Segment2.first)->globalPosition() - (Segment1.first)->globalPosition();
535 double dPhi1 = (segvec2.
phi() - segvec1.
phi()).
value();
536 double dPhi2 = (segvec3.
phi() - segvec1.
phi()).
value();
537 cout <<
"Checking straight with 2 segments. dPhi1: " << dPhi1 <<
", dPhi2: " << dPhi2 << endl;
538 cout <<
"Checking straight with 2 segments. dPhi1 in degree: " << dPhi1 * 180 / 3.1415926
539 <<
", dPhi2 in degree: " << dPhi2 * 180 / 3.1415926 << endl;
540 if (fabs(dPhi1) > MinDeltaPhi || fabs(dPhi2) > MinDeltaPhi) {
541 cout <<
"Segment is estimate to be not straight" << endl;
544 cout <<
"Segment is estimate to be straight" << endl;
550 GlobalVector segvec1 = (Segment1.second)->globalPosition() - (Segment1.first)->globalPosition();
551 GlobalVector segvec2 = (Segment2.second)->globalPosition() - (Segment2.first)->globalPosition();
552 GlobalPoint Point1(((Segment1.second)->globalPosition().x() + (Segment1.first)->globalPosition().x()) / 2,
553 ((Segment1.second)->globalPosition().y() + (Segment1.first)->globalPosition().y()) / 2,
554 ((Segment1.second)->globalPosition().z() + (Segment1.first)->globalPosition().z()) / 2);
555 GlobalPoint Point2(((Segment2.second)->globalPosition().x() + (Segment2.first)->globalPosition().x()) / 2,
556 ((Segment2.second)->globalPosition().y() + (Segment2.first)->globalPosition().y()) / 2,
557 ((Segment2.second)->globalPosition().z() + (Segment2.first)->globalPosition().z()) / 2);
561 double A1 = gvec1.
x();
562 double B1 = gvec1.
y();
563 double A2 = gvec2.
x();
564 double B2 = gvec2.
y();
565 double X1 = Point1.
x();
566 double Y1 = Point1.
y();
567 double X2 = Point2.
x();
568 double Y2 = Point2.
y();
569 double XO = (A1 * A2 * (Y2 - Y1) + A2 * B1 * X1 - A1 * B2 * X2) / (A2 * B1 - A1 * B2);
570 double YO = (B1 * B2 * (X2 - X1) + B2 * A1 * Y1 - B1 * A2 * Y2) / (B2 * A1 - B1 * A2);
578 double dPhi = (segvec2.
phi() - segvec1.
phi()).
value();
579 if (fabs(dPhi) > MinDeltaPhi) {
580 cout <<
"Part is estimate to be not straight" << endl;
583 cout <<
"Part is estimate to be straight" << endl;
591 double (&y)[3])
const {
592 double A = (y[2] - y[1]) / (x[2] - x[1]) - (y[1] - y[0]) / (x[1] - x[0]);
593 double TYO = (x[2] - x[0]) / A + (y[2] * y[2] - y[1] * y[1]) / ((x[2] - x[1]) * A) -
594 (y[1] * y[1] - y[0] * y[0]) / ((x[1] - x[0]) *
A);
595 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]);
596 double XO = 0.5 * TXO;
597 double YO = 0.5 * TYO;
598 double R2 = (x[0] - XO) * (x[0] - XO) + (y[0] - YO) * (y[0] - YO);
599 cout <<
"R2 is " << R2 << endl;
601 pt = 0.01 *
sqrt(R2) * 2 * 0.3;
602 cout <<
"pt is " << pt << endl;
608 if (isPatternChecked ==
true)
615 unsigned int NumberofHitsinSeed = nrhit();
618 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
619 cout <<
"Position of recHit is: " << (*iter)->globalPosition() << endl;
622 std::vector<double> BzValue;
623 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != (theRecHits.end() - 1); iter++) {
625 GlobalPoint gpLast = (*(iter + 1))->globalPosition();
627 double dx = (gpLast.
x() - gpFirst.
x()) / (sampleCount + 1);
628 double dy = (gpLast.
y() - gpFirst.
y()) / (sampleCount + 1);
629 double dz = (gpLast.
z() - gpFirst.
z()) / (sampleCount + 1);
632 (gpFirst.
x() + dx * (
index + 1)), (gpFirst.
y() + dy * (
index + 1)), (gpFirst.
z() + dz * (
index + 1)));
634 cout <<
"Sampling magnetic field : " << MagneticVec_temp << endl;
635 BzValue.push_back(MagneticVec_temp.z());
641 meanBz += BzValue[
index];
642 meanBz /= BzValue.size();
643 cout <<
"Mean Bz is " << meanBz << endl;
646 deltaBz += (BzValue[
index] - meanBz) * (BzValue[
index] - meanBz);
647 deltaBz /= BzValue.size();
648 deltaBz =
sqrt(deltaBz);
649 cout <<
"delata Bz is " << deltaBz << endl;
655 if (fabs((*(theRecHits.end() - 1))->globalPosition().z() - (*(theRecHits.begin()))->globalPosition().z()) > ZError) {
656 if (((*(theRecHits.end() - 1))->globalPosition().z() - (*(theRecHits.begin()))->globalPosition().z()) > ZError)
663 cout <<
" Check isParralZ is :" << isParralZ << endl;
664 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != (theRecHits.end() - 1); iter++) {
665 if (isParralZ == 0) {
666 if (fabs((*(iter + 1))->globalPosition().z() - (*iter)->globalPosition().z()) > ZError) {
667 cout <<
"Pattern find error in Z direction: wrong perpendicular direction" << endl;
671 if ((
int)(((*(iter + 1))->globalPosition().z() - (*iter)->globalPosition().z()) / ZError) * isParralZ < 0) {
672 cout <<
"Pattern find error in Z direction: wrong Z direction" << endl;
679 if (isStraight ==
false) {
682 unsigned int index = 0;
683 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++) {
684 GlobalVector vec_temp(((*iter)->globalPosition().x() - Center.x()),
685 ((*iter)->globalPosition().y() - Center.y()),
686 ((*iter)->globalPosition().z() - Center.z()));
687 vec[
index] = vec_temp;
691 for (
unsigned int index = 0; index < (NumberofHitsinSeed - 1); index++) {
693 if ((vec[index + 1].phi() - vec[index].phi()) > 0)
697 cout <<
"Current isClockwise is : " << isClockwise << endl;
699 cout <<
"Check isClockwise is : " << isClockwise << endl;
700 if ((
unsigned int)
abs(isClockwise) != (NumberofHitsinSeed - 1)) {
701 cout <<
"Pattern find error in Phi direction" << endl;
705 isClockwise /=
abs(isClockwise);
709 double deltaRwithBz = fabs(deltaBz * meanRadius / meanBz);
710 cout <<
"deltaR with Bz is " << deltaRwithBz << endl;
712 if (isClockwise == 0)
715 meanPt = 0.01 * meanRadius * meanBz * 0.3 * isClockwise;
718 cout <<
" meanRadius is " << meanRadius << endl;
719 cout <<
" meanPt is " << meanPt << endl;
722 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++) {
723 deltaR += (getDistance(*iter, Center) - meanRadius) * (getDistance(*iter, Center) - meanRadius);
725 deltaR = deltaR / NumberofHitsinSeed;
726 deltaR =
sqrt(deltaR);
729 cout <<
"DeltaR is " << deltaR << endl;
730 if (deltaR > deltaRThreshold) {
731 cout <<
"Pattern find error: deltaR over threshold" << endl;
739 meanSpt = deltaRThreshold;
741 cout <<
"III--> Seed Pt : " << meanPt << endl;
742 cout <<
"III--> Pattern is: " << isGoodPattern << endl;
745 isPatternChecked =
true;
749 if (isPatternChecked ==
true)
752 if (!checkSegment()) {
753 isPatternChecked =
true;
762 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
763 cout <<
"Position of recHit is: " << (*iter)->globalPosition() << endl;
766 if (fabs((*(theRecHits.end() - 1))->globalPosition().z() - (*(theRecHits.begin()))->globalPosition().z()) > ZError) {
767 if (((*(theRecHits.end() - 1))->globalPosition().z() - (*(theRecHits.begin()))->globalPosition().z()) > ZError)
774 cout <<
" Check isParralZ is :" << isParralZ << endl;
775 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != (theRecHits.end() - 1); iter++) {
776 if (isParralZ == 0) {
777 if (fabs((*(iter + 1))->globalPosition().z() - (*iter)->globalPosition().z()) > ZError) {
778 cout <<
"Pattern find error in Z direction: wrong perpendicular direction" << endl;
782 if ((
int)(((*(iter + 1))->globalPosition().z() - (*iter)->globalPosition().z()) / ZError) * isParralZ < 0) {
783 cout <<
"Pattern find error in Z direction: wrong Z direction" << endl;
790 if (isStraight2 ==
true) {
795 meanSpt = deltaRThreshold;
798 GlobalVector startSegment = (SegmentRB[1].second)->globalPosition() - (SegmentRB[1].first)->globalPosition();
799 GlobalPoint startPosition = (SegmentRB[1].first)->globalPosition();
801 unsigned int index = 0;
802 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++) {
807 double tracklength = 0;
808 cout <<
"Now checking recHit " << index << endl;
809 double Distance = extropolateStep(startPosition, startMomentum, iter, isClockwise, tracklength, eSetup);
810 cout <<
"Final distance is " << Distance << endl;
811 if (Distance > MaxRSD) {
812 cout <<
"Pattern find error in distance for other recHits: " << Distance << endl;
821 (entryPosition.x() - Center2.x()), (entryPosition.y() - Center2.y()), (entryPosition.z() - Center2.z()));
823 (leavePosition.x() - Center2.x()), (leavePosition.y() - Center2.y()), (leavePosition.z() - Center2.z()));
825 if ((vec[1].phi() - vec[0].phi()).
value() > 0)
830 cout <<
"Check isClockwise is : " << isClockwise << endl;
833 meanPt = 0.01 * meanRadius2 * meanMagneticField2.z() * 0.3 * isClockwise;
835 cout <<
" meanRadius is " << meanRadius2 <<
", with meanBz " << meanMagneticField2.z() << endl;
836 cout <<
" meanPt is " << meanPt << endl;
841 cout <<
"entryPosition: " << entryPosition << endl;
842 cout <<
"leavePosition: " << leavePosition << endl;
843 cout <<
"Center2 is : " << Center2 << endl;
844 double R1 = vec[0].
perp();
845 double R2 = vec[1].
perp();
846 double deltaR =
sqrt(((R1 - meanRadius2) * (R1 - meanRadius2) + (R2 - meanRadius2) * (R2 - meanRadius2)) / 2);
848 cout <<
"R1 is " << R1 <<
", R2 is " << R2 << endl;
849 cout <<
"Delta R for the initial 3 segments is " << deltaR << endl;
850 if (deltaR > deltaRThreshold) {
851 cout <<
"Pattern find error in delta R for the initial 3 segments" << endl;
856 GlobalVector startSegment = (SegmentRB[1].second)->globalPosition() - (SegmentRB[1].first)->globalPosition();
857 GlobalPoint startPosition = (SegmentRB[1].first)->globalPosition();
858 GlobalVector startMomentum = startSegment * (fabs(meanPt) / startSegment.
perp());
859 unsigned int index = 0;
860 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++) {
865 double tracklength = 0;
866 cout <<
"Now checking recHit " << index << endl;
867 double Distance = extropolateStep(startPosition, startMomentum, iter, isClockwise, tracklength, eSetup);
868 cout <<
"Final distance is " << Distance << endl;
869 if (Distance > MaxRSD) {
870 cout <<
"Pattern find error in distance for other recHits: " << Distance << endl;
877 cout <<
"Checking finish, isGoodPattern now is " << isGoodPattern << endl;
879 isPatternChecked =
true;
884 ConstMuonRecHitContainer::const_iterator iter,
885 const int ClockwiseDirection,
892 cout <<
"Extrapolating the track to check the pattern" << endl;
895 DetId hitDet = (*iter)->hit()->geographicalId();
903 double startSide = RPCSurface.localZ(startPosition);
904 cout <<
"Start side : " << startSide;
911 double currentDistance = ((
GlobalVector)(currentPosition - (*iter)->globalPosition())).perp();
912 cout <<
"Start current position is : " << currentPosition << endl;
913 cout <<
"Start current Momentum is: " << currentMomentum.
mag() <<
", in vector: " << currentMomentum << endl;
914 cout <<
"Start current distance is " << currentDistance << endl;
915 cout <<
"Start current radius is " << currentPosition.
perp() << endl;
916 cout <<
"Destination radius is " << (*iter)->globalPosition().perp() << endl;
920 double currentDistance_next = currentDistance;
922 currentDistance = currentDistance_next;
923 if (ClockwiseDirection == 0) {
924 currentPosition += currentMomentum.
unit() * stepLength;
926 double Bz = Field->inTesla(currentPosition).z();
927 double Radius = currentMomentum.
perp() / fabs(Bz * 0.01 * 0.3);
928 double deltaPhi = (stepLength * currentMomentum.
perp() / currentMomentum.
mag()) / Radius;
932 currentPositiontoCenter *= Radius;
934 currentPositiontoCenter *= ClockwiseDirection;
937 currentCenter += currentPositiontoCenter;
941 double Phi = CentertocurrentPosition.
phi().value();
942 Phi += deltaPhi * (-1) * ClockwiseDirection;
943 double deltaZ = stepLength * currentMomentum.
z() / currentMomentum.
mag();
945 double PtPhi = currentMomentum.
phi().value();
946 PtPhi += deltaPhi * (-1) * ClockwiseDirection;
948 currentPosition = currentCenter + CentertonewPosition;
952 tracklength += stepLength * currentMomentum.
perp() / currentMomentum.
mag();
955 double currentSide = RPCSurface.localZ(currentPosition);
956 cout <<
"Stepping current side : " << currentSide << endl;
957 cout <<
"Stepping current position is: " << currentPosition << endl;
958 cout <<
"Stepping current Momentum is: " << currentMomentum.
mag() <<
", in vector: " << currentMomentum << endl;
959 currentDistance_next = ((
GlobalVector)(currentPosition - (*iter)->globalPosition())).
perp();
960 cout <<
"Stepping current distance is " << currentDistance << endl;
961 cout <<
"Stepping current radius is " << currentPosition.
perp() << endl;
962 }
while (currentDistance_next < currentDistance);
964 return currentDistance;
969 cout <<
"Now create a fake seed" << endl;
970 isPatternChecked =
true;
986 LocalVector segDirFromPos = best->det()->toLocal(Momentum);
991 mat = best->parametersError().similarityT(best->projectionMatrix());
1000 DetId id = best->geographicalId();
1005 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++)
1006 container.
push_back((*iter)->hit()->clone());
1010 theweightedSeed.first = theSeed;
1011 theweightedSeed.second = meanSpt;
1012 isGoodSeed = isGoodPattern;
1014 return theweightedSeed;
1018 if (isPatternChecked ==
false || isGoodPattern == -1) {
1019 cout <<
"Pattern is not yet checked! Create a fake seed instead!" << endl;
1020 return createFakeSeed(isGoodSeed, eSetup);
1033 if (isClockwise == 0)
1036 Charge = (int)(meanPt / fabs(meanPt));
1042 if (isClockwise != 0) {
1045 GlobalVector vecRef1((first->globalPosition().x() - Center.x()),
1046 (first->globalPosition().y() - Center.y()),
1047 (first->globalPosition().z() - Center.z()));
1048 GlobalVector vecRef2((best->globalPosition().x() - Center.x()),
1049 (best->globalPosition().y() - Center.y()),
1050 (best->globalPosition().z() - Center.z()));
1053 double deltaS = meanRadius * fabs(deltaPhi);
1054 double deltaZ = best->globalPosition().z() - first->globalPosition().z();
1058 if (isClockwise == -1)
1063 Momentum *= fabs(meanPt / deltaS);
1065 double deltaZ = best->globalPosition().z() - first->globalPosition().z();
1067 Momentum *= fabs(meanPt /
S);
1070 Momentum = best->globalPosition() - first->globalPosition();
1071 double deltaS = Momentum.perp();
1072 Momentum *= fabs(meanPt / deltaS);
1075 LocalVector segDirFromPos = best->det()->toLocal(Momentum);
1081 cout <<
"Trajectory State on Surface before the extrapolation" << endl;
1083 DetId id = best->geographicalId();
1084 cout <<
"The RecSegment relies on: " << endl;
1091 for (ConstMuonRecHitContainer::const_iterator iter = theRecHits.begin(); iter != theRecHits.end(); iter++) {
1096 container.
push_back((*iter)->hit()->clone());
1101 theweightedSeed.first = theSeed;
1102 theweightedSeed.second = meanSpt;
1103 isGoodSeed = isGoodPattern;
1105 return theweightedSeed;
1115 mat = best->parametersError().similarityT(best->projectionMatrix());
1117 GlobalVector vecRef1((first->globalPosition().x() - Center.x()),
1118 (first->globalPosition().y() - Center.y()),
1119 (first->globalPosition().z() - Center.z()));
1120 GlobalVector vecRef2((best->globalPosition().x() - Center.x()),
1121 (best->globalPosition().y() - Center.y()),
1122 (best->globalPosition().z() - Center.z()));
1124 double L = meanRadius * fabs(deltaPhi);
1126 double A_N = 180 * N * N * N / ((N - 1) * (N + 1) * (N + 2) * (N + 3));
1127 double sigma_x =
sqrt(mat[3][3]);
1128 double betaovergame = Momentum.mag() / 0.1066;
1129 double beta =
sqrt((betaovergame * betaovergame) / (1 + betaovergame * betaovergame));
1130 double dPt = meanPt * (0.0136 *
sqrt(1 / 100) *
sqrt(4 * A_N / N) / (beta * 0.3 * meanBz *
L) +
1131 sigma_x * meanPt *
sqrt(4 * A_N) / (0.3 * meanBz * L *
L));
1132 double dP = dPt * Momentum.mag() / meanPt;
1133 mat[0][0] = (dP * dP) / (Momentum.mag() * Momentum.mag() * Momentum.mag() * Momentum.mag());
1134 mat[1][1] = dXdZ * dXdZ;
1135 mat[2][2] = dYdZ * dYdZ;
1139 mat0 = (SegmentRB[0].first)->parametersError().similarityT((SegmentRB[0].first)->projectionMatrix());
1140 double dX0 =
sqrt(mat0[3][3]);
1141 double dY0 =
sqrt(mat0[4][4]);
1143 mat1 = (SegmentRB[0].second)->parametersError().similarityT((SegmentRB[0].
second)->projectionMatrix());
1144 double dX1 =
sqrt(mat1[3][3]);
1145 double dY1 =
sqrt(mat1[4][4]);
1147 mat2 = (SegmentRB[1].first)->parametersError().similarityT((SegmentRB[1].first)->projectionMatrix());
1148 double dX2 =
sqrt(mat2[3][3]);
1149 double dY2 =
sqrt(mat2[4][4]);
1151 mat3 = (SegmentRB[1].second)->parametersError().similarityT((SegmentRB[1].second)->projectionMatrix());
1152 double dX3 =
sqrt(mat3[3][3]);
1153 double dY3 =
sqrt(mat3[4][4]);
1154 cout <<
"Local error for 4 recHits are: " << dX0 <<
", " << dY0 <<
", " << dX1 <<
", " << dY1 <<
", " << dX2 <<
", "
1155 << dY2 <<
", " << dX3 <<
", " << dY3 << endl;
1156 const GeomDetUnit* refRPC1 = (SegmentRB[0].second)->detUnit();
1166 const GeomDetUnit* refRPC2 = (SegmentRB[1].first)->detUnit();
1176 if (isClockwise != 0) {
1179 (entryPosition.x() - Center2.x()), (entryPosition.y() - Center2.y()), (entryPosition.z() - Center2.z()));
1181 (leavePosition.x() - Center2.x()), (leavePosition.y() - Center2.y()), (leavePosition.z() - Center2.z()));
1182 double halfPhiCenter = fabs((vec[1].phi() - vec[0].phi()).
value()) / 2;
1184 double dPhi0 = (((globalSegment00.phi() - globalSegment01.
phi()).
value() * isClockwise) > 0)
1185 ? fabs((globalSegment00.phi() - globalSegment01.
phi()).
value())
1186 : fabs((globalSegment00.phi() - globalSegment02.
phi()).
value());
1187 double dPhi1 = (((globalSegment10.phi() - globalSegment11.
phi()).
value() * isClockwise) < 0)
1188 ? fabs((globalSegment10.phi() - globalSegment11.
phi()).
value())
1189 : fabs((globalSegment10.phi() - globalSegment12.
phi()).
value());
1191 double dPhi = (dPhi0 <= dPhi1) ? dPhi0 : dPhi1;
1192 cout <<
"DPhi for new Segment is about " << dPhi << endl;
1194 double newhalfPhiCenter = ((halfPhiCenter - dPhi) > 0 ? (halfPhiCenter - dPhi) : 0);
1195 if (newhalfPhiCenter != 0) {
1196 double newmeanPt = meanPt * halfPhiCenter / newhalfPhiCenter;
1199 cout <<
"The error is inside range. Max meanPt could be " << newmeanPt << endl;
1200 dP = fabs(Momentum.mag() * (newmeanPt - meanPt) / meanPt);
1203 cout <<
"The error is outside range. Max meanPt could be " << newmeanPt << endl;
1204 dP = fabs(Momentum.mag() * (newmeanPt - meanPt) / meanPt);
1207 double dPhi0 = (fabs((globalSegment00.phi() - globalSegment01.
phi()).
value()) <=
1208 fabs((globalSegment00.phi() - globalSegment02.
phi()).
value()))
1209 ? fabs((globalSegment00.phi() - globalSegment01.
phi()).
value())
1210 : fabs((globalSegment00.phi() - globalSegment02.
phi()).
value());
1211 double dPhi1 = (fabs((globalSegment10.phi() - globalSegment11.
phi()).
value()) <=
1212 fabs((globalSegment10.phi() - globalSegment12.
phi()).
value()))
1213 ? fabs((globalSegment10.phi() - globalSegment11.
phi()).
value())
1214 : fabs((globalSegment10.phi() - globalSegment12.
phi()).
value());
1215 double dPhi = (dPhi0 <= dPhi1) ? dPhi0 : dPhi1;
1216 GlobalVector middleSegment = leavePosition - entryPosition;
1217 double halfDistance = middleSegment.
perp() / 2;
1218 double newmeanPt = halfDistance / dPhi;
1219 cout <<
"The error is for straight. Max meanPt could be " << newmeanPt << endl;
1220 dP = fabs(Momentum.mag() * (newmeanPt - meanPt) / meanPt);
1223 double dXdZ1 = globalSegment11.
x() / globalSegment11.
z() - globalSegment10.x() / globalSegment10.z();
1224 double dXdZ2 = globalSegment12.
x() / globalSegment12.
z() - globalSegment10.x() / globalSegment10.z();
1225 dXdZ = (fabs(dXdZ1) >= fabs(dXdZ2)) ? dXdZ1 : dXdZ2;
1231 double dYdZ1 = globalSegment13.
y() / globalSegment13.z() - globalSegment10.y() / globalSegment10.z();
1232 double dYdZ2 = globalSegment14.
y() / globalSegment14.
z() - globalSegment10.y() / globalSegment10.z();
1233 dYdZ = (fabs(dYdZ1) >= fabs(dYdZ2)) ? dYdZ1 : dYdZ2;
1235 mat[0][0] = (dP * dP) / (Momentum.mag() * Momentum.mag() * Momentum.mag() * Momentum.mag());
1236 mat[1][1] = dXdZ * dXdZ;
1237 mat[2][2] = dYdZ * dYdZ;
MuonTransientTrackingRecHit::ConstMuonRecHitPointer ConstMuonRecHitPointer
edm::ErrorSummaryEntry Error
weightedTrajectorySeed createFakeSeed(int &isGoodSeed, const edm::EventSetup &eSetup)
void configure(const edm::ParameterSet &iConfig)
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
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
constexpr uint32_t rawId() const
get the raw id
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
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)
RPCDetId id() const
Return the RPCChamberId of this chamber.
void ThreePointsAlgorithm()
Abs< T >::type abs(const T &t)
ConstMuonRecHitPointer BestRefRecHit() const
std::pair< TrajectorySeed, double > weightedTrajectorySeed
Vector3DBase unit() const
T getParameter(std::string const &) 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.