22 TDirectory *dirSave = gDirectory;
27 f =
new TFile(
"./LocalMillepedeResults.root",
"RECREATE");
46 TMatrixD ****
C =
new TMatrixD ***[5];
47 TMatrixD ****
b =
new TMatrixD ***[5];
49 for (
int whI = -2; whI < 3; ++whI) {
50 C[whI + 2] =
new TMatrixD **[4];
51 b[whI + 2] =
new TMatrixD **[4];
52 for (
int stI = 1; stI < 5; ++stI) {
53 C[whI + 2][stI - 1] =
new TMatrixD *[14];
54 b[whI + 2][stI - 1] =
new TMatrixD *[14];
55 for (
int seI = 1; seI < 15; ++seI) {
56 if (seI > 12 && stI != 4)
59 C[whI + 2][stI - 1][seI - 1] =
new TMatrixD(24, 24);
60 b[whI + 2][stI - 1][seI - 1] =
new TMatrixD(24, 1);
62 C[whI + 2][stI - 1][seI - 1] =
new TMatrixD(60, 60);
63 b[whI + 2][stI - 1][seI - 1] =
new TMatrixD(60, 1);
70 if (workingmode <= 3) {
71 Int_t nentries = (Int_t)
tali->GetEntries();
72 for (Int_t
i = 0;
i < nentries;
i++) {
76 std::cout <<
"Analyzing track number " <<
i << std::endl;
99 for (
int counterHi = 0; counterHi <
nhits[
counter]; counterHi++) {
103 }
else if (
sl[
counter][counterHi] == 2) {
120 A(row, row * 5) = -1.0;
121 A(row, row * 5 + 1) =
dydz;
122 A(row, row * 5 + 2) = y *
dydz;
123 A(row, row * 5 + 3) = -x *
dydz;
124 A(row, row * 5 + 4) = -
x;
127 A(row, row * 5 + 0) = -1.0;
128 A(row, row * 5 + 1) =
dxdz;
129 A(row, row * 5 + 2) = y *
dxdz;
130 A(row, row * 5 + 3) = -x *
dxdz;
131 A(row, row * 5 + 4) =
y;
136 A(row, row * 3 + 0) = -1.0;
137 A(row, row * 3 + 1) =
dxdz;
138 A(row, row * 3 + 2) = -x *
dxdz;
143 E(row, row) = 1.0 /
error;
159 TMatrixD
gamma = (Bt * E *
B);
167 if (workingmode == 3)
170 for (
int sector = 1; sector < 15; ++sector) {
171 if (sector > 12 &&
station != 4)
177 TString CtrName =
"Ctr_";
185 TString btrName =
"btr_";
195 if (workingmode % 2 == 0) {
198 for (
int sector = 1; sector < 15; ++sector) {
199 if (sector > 12 &&
station != 4)
202 if (workingmode == 4) {
203 for (
int mf = -1; mf <= -1; mf++) {
218 TMatrixD SC = Ctr + Ccs;
219 TMatrixD Sb = btr + bcs;
223 TMatrixD solution = SC * Sb;
224 for (
int icounter = 0; icounter < SC.GetNrows(); icounter++) {
225 for (
int jcounter = 0; jcounter < SC.GetNrows(); jcounter++) {
226 cov[icounter][jcounter] = SC(icounter, jcounter);
230 int nLayer = 12, nDeg = 5;
235 for (
int counterLayer = 0; counterLayer < nLayer; ++counterLayer)
236 for (
int counterDeg = 0; counterDeg < nDeg; ++counterDeg) {
237 if (counterLayer < 4) {
238 slC[counterLayer] = 1;
239 laC[counterLayer] = counterLayer + 1;
240 }
else if (counterLayer > 3 && counterLayer < 8) {
241 slC[counterLayer] = 3;
242 laC[counterLayer] = counterLayer - 3;
244 slC[counterLayer] = 2;
245 laC[counterLayer] = counterLayer - 7;
248 if (counterLayer < 8) {
249 dx[counterLayer] = solution(counterLayer * nDeg, 0);
250 dy[counterLayer] = 0.0;
252 dx[counterLayer] = 0.0;
253 dy[counterLayer] = solution(counterLayer * nDeg, 0);
255 dz[counterLayer] = solution(counterLayer * nDeg + 1, 0);
258 phix[counterLayer] = solution(counterLayer * nDeg + 2, 0);
259 phiy[counterLayer] = solution(counterLayer * nDeg + 3, 0);
260 phiz[counterLayer] = solution(counterLayer * nDeg + 4, 0);
262 phix[counterLayer] = 0.;
263 phiy[counterLayer] = solution(counterLayer * nDeg + 2, 0);
264 phiz[counterLayer] = 0.;
347 TMatrixD
matrix(size, size);
349 float Error[3][6] = {{0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001},
350 {0.005, 0.005, 0.005, 0.00005, 0.00005, 0.00005},
351 {0.005, 0.005, 0.005, 0.00005, 0.00005, 0.00005}};
353 float TollerancyPosition = 0.01;
354 float TollerancyRotation = 0.0001;
359 if (ConsQC.GetNrows() < 70)
362 int nLayer = 12, nDeg = 5;
368 for (
int la = 0;
la < nLayer;
la++)
369 for (
int dg = 0; dg < nDeg; dg++) {
373 if (
la < 8 && rdg == 1)
375 if (st == 4 && rdg == 3)
378 double ThisError2 = Error[
la / 4][rdg] * Error[
la / 4][rdg];
381 ThisError2 += ConsQC(
la, 1) * ConsQC(
la, 1);
383 ThisError2 += TollerancyPosition * TollerancyPosition;
385 }
else if (rdg == 2) {
386 ThisError2 += TollerancyPosition * TollerancyPosition;
388 ThisError2 += TollerancyRotation * TollerancyRotation;
391 matrix(index, index) = 1. / ThisError2;
404 float Error[3][6] = {{0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001},
405 {0.005, 0.005, 0.005, 0.00005, 0.00005, 0.00005},
406 {0.005, 0.005, 0.005, 0.00005, 0.00005, 0.00005}};
408 float TollerancyPosition = 0.01;
409 float TollerancyRotation = 0.0001;
414 if (ConsQC.GetNrows() < 70)
419 int nLayer = 12, nDeg = 5;
425 for (
int la = 0;
la < nLayer;
la++)
426 for (
int dg = 0; dg < nDeg; dg++) {
430 if (
la < 8 && rdg == 1)
432 if (st == 4 && rdg == 3)
435 double ThisError2 = Error[
la / 4][rdg] * Error[
la / 4][rdg];
438 ThisError2 += ConsQC(
la, 1) * ConsQC(
la, 1);
440 ThisError2 += TollerancyPosition * TollerancyPosition;
442 }
else if (rdg == 2) {
443 ThisError2 += TollerancyPosition * TollerancyPosition;
445 ThisError2 += TollerancyRotation * TollerancyRotation;
448 float Constraint = 0.;
450 Constraint += Survey(rdg,
la / 4 - 1);
451 if (UseQC && rdg == 0)
452 Constraint += ConsQC(
la, 0);
454 if (UseQC && rdg == 1)
455 Constraint -= ConsQC(
la, 0);
457 matrix(index, 0) = Constraint / ThisError2;
464 TString MtxFileName =
"./LocalMillepedeMatrix_";
466 MtxFileName +=
".root";
468 MtxFileName =
"./LocalMillepedeMatrix.root";
470 TDirectory *dirSave = gDirectory;
472 TFile *MatrixFile =
new TFile(MtxFileName);
474 TString MtxName = Code;
480 TMatrixD *ThisMtx = (TMatrixD *)MatrixFile->Get(MtxName);
490 TMatrixD
matrix(60 + 6, 60 + 6);
492 matrix.ResizeTo(40 + 6, 40 + 6);
494 for (
int counterDeg = 0; counterDeg < 5; ++counterDeg) {
495 for (
int counterLayer = 0; counterLayer < 12; ++counterLayer) {
497 matrix(40 + counterDeg, counterLayer * 5 + counterDeg) = 10000.0;
498 matrix(counterLayer * 5 + counterDeg, 40 + counterDeg) = 10000.0;
500 int realCounter = counterDeg + 1;
501 if (counterDeg == 1 && counterLayer < 8) {
502 realCounter = counterDeg - 1;
504 matrix(counterLayer * 5 + counterDeg, 40 + realCounter) = 10000.0;
505 if ((realCounter == 0 && counterLayer > 7) || (realCounter == 1 && counterLayer < 7))
507 matrix(60 + realCounter, counterLayer * 5 + counterDeg) = 10000.0;
516 TMatrixD sigmaQC(5, 12);
520 matrix.ResizeTo(40, 40);
522 if (surv.GetNrows() < 7) {
523 for (
int counterDeg = 0; counterDeg < 5; counterDeg++) {
524 for (
int counterLayer = 0; counterLayer < 12; ++counterLayer) {
525 if (st != 4 && counterLayer > 7)
527 if (counterDeg == 0) {
528 sigmaQC(counterDeg, counterLayer) = 0.05;
529 }
else if (counterDeg < 3) {
530 sigmaQC(counterDeg, counterLayer) = 0.05;
532 sigmaQC(counterDeg, counterLayer) = 0.05;
538 sqrt(surv(0, 1) * surv(0, 1) + surv(1, 1) * surv(1, 1) + surv(2, 1) * surv(2, 1) + surv(3, 1) * surv(3, 1)) /
540 float meanvarSL2 = 0;
541 if (surv.GetNrows() > 9)
542 meanvarSL2 =
sqrt(surv(8, 1) * surv(8, 1) + surv(9, 1) * surv(9, 1) + surv(10, 1) * surv(10, 1) +
543 surv(11, 1) * surv(11, 1)) /
546 sqrt(surv(4, 1) * surv(4, 1) + surv(5, 1) * surv(5, 1) + surv(6, 1) * surv(6, 1) + surv(7, 1) * surv(7, 1)) /
548 for (
int counterDeg = 0; counterDeg < 5; counterDeg++) {
549 for (
int counterLayer = 0; counterLayer < 12; ++counterLayer) {
550 if (st != 4 && counterLayer > 7)
553 if (counterLayer < 4) {
554 meanerror = meanvarSL1;
555 }
else if (counterLayer > 3 && counterLayer < 8) {
556 meanerror = meanvarSL2;
558 meanerror = meanvarSL3;
560 if (counterDeg == 0) {
561 sigmaQC(counterDeg, counterLayer) =
562 sqrt((surv(counterLayer, 1) / 10000.0) * (surv(counterLayer, 1) / 10000.0) + meanerror * meanerror);
563 }
else if (counterDeg < 3) {
564 sigmaQC(counterDeg, counterLayer) = 0.05;
566 sigmaQC(counterDeg, counterLayer) = 0.05;
570 double **Eta =
new double *[12];
571 for (
int counterLayer = 0; counterLayer < 12; counterLayer++) {
572 if (counterLayer > 7 && st == 4)
574 Eta[counterLayer] =
new double[5];
575 for (
int counterLayer2 = 0; counterLayer2 < 12; counterLayer2++) {
576 if (counterLayer > 7 && st == 4)
578 if ((counterLayer2 < 4 && counterLayer < 4) || (counterLayer2 > 3 && counterLayer > 3)) {
579 if (counterLayer == counterLayer2) {
580 Eta[counterLayer][counterLayer2] = 3.0 / (4.0);
582 Eta[counterLayer][counterLayer2] = -1.0 / (4.0);
585 Eta[counterLayer][counterLayer2] = 0.0;
590 for (
int counterDeg = 0; counterDeg < 5; counterDeg++) {
591 for (
int counterLayer = 0; counterLayer < 12; counterLayer++) {
592 if (counterLayer > 7 && st == 4)
594 for (
int counterLayer2 = 0; counterLayer2 < 12; counterLayer2++) {
595 if (counterLayer2 > 7 && st == 4)
597 for (
int counterLayer3 = 0; counterLayer3 < 12; counterLayer3++) {
598 if (counterLayer3 > 7 && st == 4)
600 matrix(5 * counterLayer2 + counterDeg, 5 * counterLayer3 + counterDeg) +=
601 Eta[counterLayer][counterLayer2] * Eta[counterLayer][counterLayer3] /
602 (sigmaQC(counterDeg, counterLayer) * sigmaQC(counterDeg, counterLayer));
613 TMatrixD ResQC(5, 12);
614 TMatrixD sigmaQC(5, 12);
617 matrix.ResizeTo(40, 1);
619 if (surv.GetNrows() < 7) {
620 for (
int counterDeg = 0; counterDeg < 5; counterDeg++) {
621 for (
int counterLayer = 0; counterLayer < 12; ++counterLayer) {
622 if (st != 4 && counterLayer > 7)
624 if (counterDeg == 0) {
625 sigmaQC(counterDeg, counterLayer) = 0.05;
626 }
else if (counterDeg < 3) {
627 sigmaQC(counterDeg, counterLayer) = 0.05;
629 sigmaQC(counterDeg, counterLayer) = 0.05;
634 for (
int counterChamber = 0; counterChamber < 12; ++counterChamber) {
635 ResQC(0, counterChamber) = -surv(counterChamber, 0) / 10000.0;
638 sqrt(surv(0, 1) * surv(0, 1) + surv(1, 1) * surv(1, 1) + surv(2, 1) * surv(2, 1) + surv(3, 1) * surv(3, 1)) /
640 float meanvarSL2 = 0;
641 if (surv.GetNrows() > 9) {
642 meanvarSL2 =
sqrt(surv(8, 1) * surv(8, 1) + surv(9, 1) * surv(9, 1) + surv(10, 1) * surv(10, 1) +
643 surv(11, 1) * surv(11, 1)) /
647 sqrt(surv(4, 1) * surv(4, 1) + surv(5, 1) * surv(5, 1) + surv(6, 1) * surv(6, 1) + surv(7, 1) * surv(7, 1)) /
649 for (
int counterDeg = 0; counterDeg < 5; counterDeg++) {
650 for (
int counterLayer = 0; counterLayer < 12; ++counterLayer) {
651 if (st != 4 && counterLayer > 7)
654 if (counterLayer < 4) {
655 meanerror = meanvarSL1;
656 }
else if (counterLayer > 3 && counterLayer < 8) {
657 meanerror = meanvarSL2;
659 meanerror = meanvarSL3;
661 if (counterDeg == 0) {
662 sigmaQC(counterDeg, counterLayer) =
663 sqrt((surv(counterLayer, 1) / 10000.0) * (surv(counterLayer, 1) / 10000.0) + meanerror * meanerror);
664 }
else if (counterDeg < 3) {
665 sigmaQC(counterDeg, counterLayer) = 0.05;
667 sigmaQC(counterDeg, counterLayer) = 0.05;
671 double **Eta =
new double *[12];
672 for (
int counterLayer = 0; counterLayer < 12; counterLayer++) {
673 if (counterLayer > 7 && st == 4)
675 Eta[counterLayer] =
new double[5];
676 for (
int counterLayer2 = 0; counterLayer2 < 12; counterLayer2++) {
677 if (counterLayer > 7 && st == 4)
679 if ((counterLayer2 < 4 && counterLayer < 4) || (counterLayer2 > 3 && counterLayer > 3)) {
680 if (counterLayer == counterLayer2) {
681 Eta[counterLayer][counterLayer2] = 3.0 / (4.0);
683 Eta[counterLayer][counterLayer2] = -1.0 / (4.0);
686 Eta[counterLayer][counterLayer2] = 0.0;
691 for (
int counterDeg = 0; counterDeg < 5; counterDeg++) {
692 for (
int counterLayer = 0; counterLayer < 12; counterLayer++) {
693 if (counterLayer > 7 && st == 4)
695 for (
int counterLayer2 = 0; counterLayer2 < 12; counterLayer2++) {
696 if (counterLayer2 > 7 && st == 4)
699 if (counterDeg != 0) {
700 if (counterLayer < 4) {
701 mean = (ResQC(counterDeg, 0) + ResQC(counterDeg, 1) + ResQC(counterDeg, 2) + ResQC(counterDeg, 3)) / 4.0;
702 }
else if (counterLayer > 3 && counterLayer < 8) {
703 mean = (ResQC(counterDeg, 4) + ResQC(counterDeg, 5) + ResQC(counterDeg, 6) + ResQC(counterDeg, 7)) / 4.0;
706 (ResQC(counterDeg, 8) + ResQC(counterDeg, 9) + ResQC(counterDeg, 10) + ResQC(counterDeg, 11)) / 4.0;
709 matrix(5 * counterLayer2 + counterDeg, 0) +=
710 Eta[counterLayer][counterLayer2] * (ResQC(counterDeg, counterLayer) -
mean) /
711 (sigmaQC(counterDeg, counterLayer) * sigmaQC(counterDeg, counterLayer));
748 TMatrixD
matrix(size + 6, size + 6);
750 float error[2][6] = {{0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001},
751 {0.05, 0.05, 0.05, 0.005, 0.005, 0.005}};
752 for (
int counterLayer = 0; counterLayer < size / 5; counterLayer++) {
753 for (
int counterLayer2 = 0; counterLayer2 < size / 5; counterLayer2++) {
754 int sl1 = counterLayer / 4;
755 int sl2 = counterLayer2 / 4;
757 for (
int counterDeg = 0; counterDeg < 5; counterDeg++) {
758 int counterDegAux = counterDeg + 1;
759 if (counterLayer < 8 && counterDeg == 1)
761 int sl = (sl1 + 1) / 2;
762 matrix(5 * counterLayer + counterDeg, 5 * counterLayer2 + counterDeg) =
763 1.0 / (16.0 * error[
sl][counterDegAux] * error[
sl][counterDegAux]);
801 TMatrixD
matrix(size + 6, 1);
803 float error[2][6] = {{0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001},
804 {0.05, 0.05, 0.05, 0.005, 0.005, 0.005}};
805 for (
int counterLayer = 0; counterLayer < size / 5; counterLayer++) {
806 for (
int counterDeg = 0; counterDeg < 5; counterDeg++) {
807 int counterDegAux = counterDeg + 1;
808 if (counterLayer < 8 && counterDeg == 1)
810 int superlayerAux = counterLayer / 4;
811 int sl = (superlayerAux + 1) / 2;
812 matrix(5 * counterLayer + counterDeg, 0) =
813 survey(counterDegAux, superlayerAux) / (4.0 * error[
sl][counterDegAux] * error[
sl][counterDegAux]);
821 TMatrixD updatedMatrix =
m;
822 updatedMatrix.ResizeTo(m.GetNrows() + 6, m.GetNcols() + 6);
823 return updatedMatrix;
827 ttreeOutput =
new TTree(
"DTLocalMillepede",
"DTLocalMillepede");
edm::ErrorSummaryEntry Error
void calculationMillepede(int)
TMatrixD getMatrixFromFile(const TString &Code, int, int, int, int)
TMatrixD getbsurveyMatrix(int, int, int)
TMatrixD getCsurveyMatrix(int, int, int)
TMatrixD getbcsMatrix(int, int, int)
TMatrixD giveQCCal(int, int, int)
const std::complex< double > I
TMatrixD getCcsMatrix(int, int, int)
static const std::string B
TMatrixD getCqcMatrix(int, int, int)
TMatrixD getbqcMatrix(int, int, int)
TMatrixD prepareForLagrange(const TMatrixD &)
DTMuonMillepede(std::string, int, float, float, int, int, int, int)
TMatrixD giveSurvey(int, int, int)
static std::atomic< unsigned int > counter
TMatrixD getLagMatrix(int, int, int)