23 TDirectory *dirSave = gDirectory;
28 f =
new TFile(
"./LocalMillepedeResults.root",
"RECREATE");
47 TMatrixD ****
C =
new TMatrixD ***[5];
48 TMatrixD ****
b =
new TMatrixD ***[5];
50 for (
int whI = -2; whI < 3; ++whI) {
51 C[whI + 2] =
new TMatrixD **[4];
52 b[whI + 2] =
new TMatrixD **[4];
53 for (
int stI = 1; stI < 5; ++stI) {
54 C[whI + 2][stI - 1] =
new TMatrixD *[14];
55 b[whI + 2][stI - 1] =
new TMatrixD *[14];
56 for (
int seI = 1; seI < 15; ++seI) {
57 if (seI > 12 && stI != 4)
60 C[whI + 2][stI - 1][seI - 1] =
new TMatrixD(24, 24);
61 b[whI + 2][stI - 1][seI - 1] =
new TMatrixD(24, 1);
63 C[whI + 2][stI - 1][seI - 1] =
new TMatrixD(60, 60);
64 b[whI + 2][stI - 1][seI - 1] =
new TMatrixD(60, 1);
71 if (workingmode <= 3) {
72 Int_t nentries = (Int_t)
tali->GetEntries();
73 for (Int_t
i = 0;
i < nentries;
i++) {
77 std::cout <<
"Analyzing track number " <<
i << std::endl;
100 for (
int counterHi = 0; counterHi <
nhits[
counter]; counterHi++) {
104 }
else if (
sl[
counter][counterHi] == 2) {
121 A(row, row * 5) = -1.0;
122 A(row, row * 5 + 1) =
dydz;
123 A(row, row * 5 + 2) =
y *
dydz;
124 A(row, row * 5 + 3) = -
x *
dydz;
125 A(row, row * 5 + 4) = -
x;
128 A(row, row * 5 + 0) = -1.0;
129 A(row, row * 5 + 1) =
dxdz;
130 A(row, row * 5 + 2) =
y *
dxdz;
131 A(row, row * 5 + 3) = -
x *
dxdz;
132 A(row, row * 5 + 4) =
y;
137 A(row, row * 3 + 0) = -1.0;
138 A(row, row * 3 + 1) =
dxdz;
139 A(row, row * 3 + 2) = -
x *
dxdz;
144 E(row, row) = 1.0 /
error;
160 TMatrixD
gamma = (Bt * E *
B);
168 if (workingmode == 3)
178 TString CtrName =
"Ctr_";
186 TString btrName =
"btr_";
196 if (workingmode % 2 == 0) {
203 if (workingmode == 4) {
204 for (
int mf = -1; mf <= -1; mf++) {
219 TMatrixD SC = Ctr + Ccs;
220 TMatrixD Sb = btr + bcs;
224 TMatrixD solution = SC * Sb;
225 for (
int icounter = 0; icounter < SC.GetNrows(); icounter++) {
226 for (
int jcounter = 0; jcounter < SC.GetNrows(); jcounter++) {
227 cov[icounter][jcounter] = SC(icounter, jcounter);
231 int nLayer = 12, nDeg = 5;
236 for (
int counterLayer = 0; counterLayer < nLayer; ++counterLayer)
237 for (
int counterDeg = 0; counterDeg < nDeg; ++counterDeg) {
238 if (counterLayer < 4) {
239 slC[counterLayer] = 1;
240 laC[counterLayer] = counterLayer + 1;
241 }
else if (counterLayer > 3 && counterLayer < 8) {
242 slC[counterLayer] = 3;
243 laC[counterLayer] = counterLayer - 3;
245 slC[counterLayer] = 2;
246 laC[counterLayer] = counterLayer - 7;
249 if (counterLayer < 8) {
250 dx[counterLayer] = solution(counterLayer * nDeg, 0);
251 dy[counterLayer] = 0.0;
253 dx[counterLayer] = 0.0;
254 dy[counterLayer] = solution(counterLayer * nDeg, 0);
256 dz[counterLayer] = solution(counterLayer * nDeg + 1, 0);
259 phix[counterLayer] = solution(counterLayer * nDeg + 2, 0);
260 phiy[counterLayer] = solution(counterLayer * nDeg + 3, 0);
261 phiz[counterLayer] = solution(counterLayer * nDeg + 4, 0);
263 phix[counterLayer] = 0.;
264 phiy[counterLayer] = solution(counterLayer * nDeg + 2, 0);
265 phiz[counterLayer] = 0.;
350 float Error[3][6] = {{0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001},
351 {0.005, 0.005, 0.005, 0.00005, 0.00005, 0.00005},
352 {0.005, 0.005, 0.005, 0.00005, 0.00005, 0.00005}};
354 float TollerancyPosition = 0.01;
355 float TollerancyRotation = 0.0001;
360 if (ConsQC.GetNrows() < 70)
363 int nLayer = 12, nDeg = 5;
369 for (
int la = 0;
la < nLayer;
la++)
370 for (
int dg = 0; dg < nDeg; dg++) {
374 if (
la < 8 && rdg == 1)
376 if (
st == 4 && rdg == 3)
382 ThisError2 += ConsQC(
la, 1) * ConsQC(
la, 1);
384 ThisError2 += TollerancyPosition * TollerancyPosition;
386 }
else if (rdg == 2) {
387 ThisError2 += TollerancyPosition * TollerancyPosition;
389 ThisError2 += TollerancyRotation * TollerancyRotation;
405 float Error[3][6] = {{0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001},
406 {0.005, 0.005, 0.005, 0.00005, 0.00005, 0.00005},
407 {0.005, 0.005, 0.005, 0.00005, 0.00005, 0.00005}};
409 float TollerancyPosition = 0.01;
410 float TollerancyRotation = 0.0001;
415 if (ConsQC.GetNrows() < 70)
420 int nLayer = 12, nDeg = 5;
426 for (
int la = 0;
la < nLayer;
la++)
427 for (
int dg = 0; dg < nDeg; dg++) {
431 if (
la < 8 && rdg == 1)
433 if (
st == 4 && rdg == 3)
439 ThisError2 += ConsQC(
la, 1) * ConsQC(
la, 1);
441 ThisError2 += TollerancyPosition * TollerancyPosition;
443 }
else if (rdg == 2) {
444 ThisError2 += TollerancyPosition * TollerancyPosition;
446 ThisError2 += TollerancyRotation * TollerancyRotation;
449 float Constraint = 0.;
451 Constraint += Survey(rdg,
la / 4 - 1);
452 if (UseQC && rdg == 0)
453 Constraint += ConsQC(
la, 0);
455 if (UseQC && rdg == 1)
456 Constraint -= ConsQC(
la, 0);
465 TString MtxFileName =
"./LocalMillepedeMatrix_";
467 MtxFileName +=
".root";
469 MtxFileName =
"./LocalMillepedeMatrix.root";
471 TDirectory *dirSave = gDirectory;
473 TFile *MatrixFile =
new TFile(MtxFileName);
475 TString MtxName = Code;
481 TMatrixD *ThisMtx = (TMatrixD *)MatrixFile->Get(MtxName);
491 TMatrixD
matrix(60 + 6, 60 + 6);
493 matrix.ResizeTo(40 + 6, 40 + 6);
495 for (
int counterDeg = 0; counterDeg < 5; ++counterDeg) {
496 for (
int counterLayer = 0; counterLayer < 12; ++counterLayer) {
498 matrix(40 + counterDeg, counterLayer * 5 + counterDeg) = 10000.0;
499 matrix(counterLayer * 5 + counterDeg, 40 + counterDeg) = 10000.0;
501 int realCounter = counterDeg + 1;
502 if (counterDeg == 1 && counterLayer < 8) {
503 realCounter = counterDeg - 1;
505 matrix(counterLayer * 5 + counterDeg, 40 + realCounter) = 10000.0;
506 if ((realCounter == 0 && counterLayer > 7) || (realCounter == 1 && counterLayer < 7))
508 matrix(60 + realCounter, counterLayer * 5 + counterDeg) = 10000.0;
517 TMatrixD sigmaQC(5, 12);
523 if (surv.GetNrows() < 7) {
524 for (
int counterDeg = 0; counterDeg < 5; counterDeg++) {
525 for (
int counterLayer = 0; counterLayer < 12; ++counterLayer) {
526 if (
st != 4 && counterLayer > 7)
528 if (counterDeg == 0) {
529 sigmaQC(counterDeg, counterLayer) = 0.05;
530 }
else if (counterDeg < 3) {
531 sigmaQC(counterDeg, counterLayer) = 0.05;
533 sigmaQC(counterDeg, counterLayer) = 0.05;
539 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)) /
541 float meanvarSL2 = 0;
542 if (surv.GetNrows() > 9)
543 meanvarSL2 =
sqrt(surv(8, 1) * surv(8, 1) + surv(9, 1) * surv(9, 1) + surv(10, 1) * surv(10, 1) +
544 surv(11, 1) * surv(11, 1)) /
547 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)) /
549 for (
int counterDeg = 0; counterDeg < 5; counterDeg++) {
550 for (
int counterLayer = 0; counterLayer < 12; ++counterLayer) {
551 if (
st != 4 && counterLayer > 7)
554 if (counterLayer < 4) {
555 meanerror = meanvarSL1;
556 }
else if (counterLayer > 3 && counterLayer < 8) {
557 meanerror = meanvarSL2;
559 meanerror = meanvarSL3;
561 if (counterDeg == 0) {
562 sigmaQC(counterDeg, counterLayer) =
563 sqrt((surv(counterLayer, 1) / 10000.0) * (surv(counterLayer, 1) / 10000.0) + meanerror * meanerror);
564 }
else if (counterDeg < 3) {
565 sigmaQC(counterDeg, counterLayer) = 0.05;
567 sigmaQC(counterDeg, counterLayer) = 0.05;
572 std::array<std::array<double, 12>, 12> Eta{};
573 for (
size_t counterLayer = 0; counterLayer < Eta.size(); counterLayer++) {
574 if (counterLayer > 7 &&
st == 4)
576 for (
size_t counterLayer2 = 0; counterLayer2 < Eta[counterLayer].size(); counterLayer2++) {
577 if (counterLayer2 > 7 &&
st == 4)
579 if ((counterLayer2 < 4 && counterLayer < 4) || (counterLayer2 > 3 && counterLayer > 3)) {
580 if (counterLayer == counterLayer2) {
581 Eta[counterLayer][counterLayer2] = 3.0 / (4.0);
583 Eta[counterLayer][counterLayer2] = -1.0 / (4.0);
589 for (
int counterDeg = 0; counterDeg < 5; counterDeg++) {
590 for (
size_t counterLayer = 0; counterLayer < 12; counterLayer++) {
591 if (counterLayer > 7 &&
st == 4)
593 for (
size_t counterLayer2 = 0; counterLayer2 < 12; counterLayer2++) {
594 if (counterLayer2 > 7 &&
st == 4)
596 for (
size_t counterLayer3 = 0; counterLayer3 < 12; counterLayer3++) {
597 if (counterLayer3 > 7 &&
st == 4)
599 matrix(5 * counterLayer2 + counterDeg, 5 * counterLayer3 + counterDeg) +=
600 Eta[counterLayer][counterLayer2] * Eta[counterLayer][counterLayer3] /
601 (sigmaQC(counterDeg, counterLayer) * sigmaQC(counterDeg, counterLayer));
612 TMatrixD ResQC(5, 12);
613 TMatrixD sigmaQC(5, 12);
618 if (surv.GetNrows() < 7) {
619 for (
int counterDeg = 0; counterDeg < 5; counterDeg++) {
620 for (
int counterLayer = 0; counterLayer < 12; ++counterLayer) {
621 if (
st != 4 && counterLayer > 7)
623 if (counterDeg == 0) {
624 sigmaQC(counterDeg, counterLayer) = 0.05;
625 }
else if (counterDeg < 3) {
626 sigmaQC(counterDeg, counterLayer) = 0.05;
628 sigmaQC(counterDeg, counterLayer) = 0.05;
633 for (
int counterChamber = 0; counterChamber < 12; ++counterChamber) {
634 ResQC(0, counterChamber) = -surv(counterChamber, 0) / 10000.0;
637 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)) /
639 float meanvarSL2 = 0;
640 if (surv.GetNrows() > 9) {
641 meanvarSL2 =
sqrt(surv(8, 1) * surv(8, 1) + surv(9, 1) * surv(9, 1) + surv(10, 1) * surv(10, 1) +
642 surv(11, 1) * surv(11, 1)) /
646 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)) /
648 for (
int counterDeg = 0; counterDeg < 5; counterDeg++) {
649 for (
int counterLayer = 0; counterLayer < 12; ++counterLayer) {
650 if (
st != 4 && counterLayer > 7)
653 if (counterLayer < 4) {
654 meanerror = meanvarSL1;
655 }
else if (counterLayer > 3 && counterLayer < 8) {
656 meanerror = meanvarSL2;
658 meanerror = meanvarSL3;
660 if (counterDeg == 0) {
661 sigmaQC(counterDeg, counterLayer) =
662 sqrt((surv(counterLayer, 1) / 10000.0) * (surv(counterLayer, 1) / 10000.0) + meanerror * meanerror);
663 }
else if (counterDeg < 3) {
664 sigmaQC(counterDeg, counterLayer) = 0.05;
666 sigmaQC(counterDeg, counterLayer) = 0.05;
670 std::array<std::array<double, 12>, 12> Eta{};
671 for (
size_t counterLayer = 0; counterLayer < Eta.size(); counterLayer++) {
672 if (counterLayer > 7 &&
st == 4)
674 for (
size_t counterLayer2 = 0; counterLayer2 < Eta[counterLayer].size(); counterLayer2++) {
675 if (counterLayer2 > 7 &&
st == 4)
677 if ((counterLayer2 < 4 && counterLayer < 4) || (counterLayer2 > 3 && counterLayer > 3)) {
678 if (counterLayer == counterLayer2) {
679 Eta[counterLayer][counterLayer2] = 3.0 / (4.0);
681 Eta[counterLayer][counterLayer2] = -1.0 / (4.0);
684 Eta[counterLayer][counterLayer2] = 0.0;
689 for (
int counterDeg = 0; counterDeg < 5; counterDeg++) {
690 for (
size_t counterLayer = 0; counterLayer < 12; counterLayer++) {
691 if (counterLayer > 7 &&
st == 4)
693 for (
size_t counterLayer2 = 0; counterLayer2 < 12; counterLayer2++) {
694 if (counterLayer2 > 7 &&
st == 4)
697 if (counterDeg != 0) {
698 if (counterLayer < 4) {
699 mean = (ResQC(counterDeg, 0) + ResQC(counterDeg, 1) + ResQC(counterDeg, 2) + ResQC(counterDeg, 3)) / 4.0;
700 }
else if (counterLayer > 3 && counterLayer < 8) {
701 mean = (ResQC(counterDeg, 4) + ResQC(counterDeg, 5) + ResQC(counterDeg, 6) + ResQC(counterDeg, 7)) / 4.0;
704 (ResQC(counterDeg, 8) + ResQC(counterDeg, 9) + ResQC(counterDeg, 10) + ResQC(counterDeg, 11)) / 4.0;
707 matrix(5 * counterLayer2 + counterDeg, 0) +=
708 Eta[counterLayer][counterLayer2] * (ResQC(counterDeg, counterLayer) -
mean) /
709 (sigmaQC(counterDeg, counterLayer) * sigmaQC(counterDeg, counterLayer));
748 float error[2][6] = {{0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001},
749 {0.05, 0.05, 0.05, 0.005, 0.005, 0.005}};
750 for (
int counterLayer = 0; counterLayer <
size / 5; counterLayer++) {
751 for (
int counterLayer2 = 0; counterLayer2 <
size / 5; counterLayer2++) {
752 int sl1 = counterLayer / 4;
753 int sl2 = counterLayer2 / 4;
755 for (
int counterDeg = 0; counterDeg < 5; counterDeg++) {
756 int counterDegAux = counterDeg + 1;
757 if (counterLayer < 8 && counterDeg == 1)
759 int sl = (sl1 + 1) / 2;
760 matrix(5 * counterLayer + counterDeg, 5 * counterLayer2 + counterDeg) =
761 1.0 / (16.0 *
error[
sl][counterDegAux] *
error[
sl][counterDegAux]);
801 float error[2][6] = {{0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001},
802 {0.05, 0.05, 0.05, 0.005, 0.005, 0.005}};
803 for (
int counterLayer = 0; counterLayer <
size / 5; counterLayer++) {
804 for (
int counterDeg = 0; counterDeg < 5; counterDeg++) {
805 int counterDegAux = counterDeg + 1;
806 if (counterLayer < 8 && counterDeg == 1)
808 int superlayerAux = counterLayer / 4;
809 int sl = (superlayerAux + 1) / 2;
810 matrix(5 * counterLayer + counterDeg, 0) =
811 survey(counterDegAux, superlayerAux) / (4.0 *
error[
sl][counterDegAux] *
error[
sl][counterDegAux]);
819 TMatrixD updatedMatrix =
m;
820 updatedMatrix.ResizeTo(
m.GetNrows() + 6,
m.GetNcols() + 6);
821 return updatedMatrix;
825 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)
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)