7 float MaxPt,
float MinPt,
8 int nPhihits,
int nThetahits,
9 int workingmode,
int nMtxSection) {
20 TDirectory * dirSave = gDirectory;
25 f =
new TFile(
"./LocalMillepedeResults.root",
"RECREATE");
48 TMatrixD ****
C =
new TMatrixD ***[5];
49 TMatrixD ****
b =
new TMatrixD ***[5];
51 for(
int whI = -2; whI < 3; ++whI) {
52 C[whI+2] =
new TMatrixD **[4];
53 b[whI+2] =
new TMatrixD **[4];
54 for(
int stI = 1; stI < 5; ++stI) {
55 C[whI+2][stI-1] =
new TMatrixD * [14];
56 b[whI+2][stI-1] =
new TMatrixD * [14];
57 for(
int seI = 1; seI < 15; ++seI) {
58 if(seI > 12 && stI != 4)
continue;
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);
73 Int_t nentries = (Int_t)
tali->GetEntries();
74 for (Int_t
i=0;
i<nentries;
i++) {
77 if (
i%100000==0)
std::cout <<
"Analyzing track number " <<
i << std::endl;
99 for(
int counterHi = 0; counterHi <
nhits[
counter]; counterHi++) {
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;
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;
157 TMatrixD Bt =
B; Bt.T();
158 TMatrixD At =
A; At.T();
159 TMatrixD gamma = (Bt*E*
B); gamma.Invert();
170 for(
int wheel = -2; wheel < 3; ++wheel)
172 for(
int sector = 1; sector < 15; ++sector) {
174 if(sector > 12 &&
station != 4)
continue;
176 TMatrixD Ctr = *C[wheel+2][
station-1][sector-1];
177 TMatrixD btr = *b[wheel+2][
station-1][sector-1];
179 TString CtrName =
"Ctr_"; CtrName += wheel; CtrName +=
"_"; CtrName +=
station;
180 CtrName +=
"_"; CtrName += sector;
183 TString btrName =
"btr_"; btrName += wheel; btrName +=
"_"; btrName +=
station;
184 btrName +=
"_"; btrName += sector;
190 if (workingmode%2==0) {
192 for(
int wheel = -2; wheel < 3; ++wheel)
194 for(
int sector = 1; sector < 15; ++sector) {
196 if(sector > 12 &&
station != 4)
continue;
198 if (workingmode==4) {
200 for (
int mf = -1; mf<=-1; mf++) {
205 *(C[wheel+2][
station-1][sector-1]) += Ch;
206 *(b[wheel+2][
station-1][sector-1]) += bh;
212 TMatrixD Ctr = *C[wheel+2][
station-1][sector-1];
213 TMatrixD btr = *b[wheel+2][
station-1][sector-1];
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;
231 if (
station==4) { nLayer = 8; nDeg = 3; }
232 for(
int counterLayer = 0; counterLayer < nLayer; ++counterLayer)
233 for(
int counterDeg = 0; counterDeg < nDeg; ++counterDeg) {
235 if(counterLayer < 4) {
236 slC[counterLayer] = 1;
237 laC[counterLayer] = counterLayer+1;
238 }
else if(counterLayer > 3 && counterLayer < 8) {
239 slC[counterLayer] = 3;
240 laC[counterLayer] = counterLayer-3;
242 slC[counterLayer] = 2;
243 laC[counterLayer] = counterLayer-7;
246 if(counterLayer < 8) {
247 dx[counterLayer] = solution(counterLayer*nDeg, 0);
248 dy[counterLayer] = 0.0;
250 dx[counterLayer] = 0.0;
251 dy[counterLayer] = solution(counterLayer*nDeg, 0);
253 dz[counterLayer] = solution(counterLayer*nDeg+1, 0);
256 phix[counterLayer] = solution(counterLayer*nDeg+2, 0);
257 phiy[counterLayer] = solution(counterLayer*nDeg+3, 0);
258 phiz[counterLayer] = solution(counterLayer*nDeg+4, 0);
260 phix[counterLayer] = 0.;
261 phiy[counterLayer] = solution(counterLayer*nDeg+2, 0);
262 phiz[counterLayer] = 0.;
347 if(st == 4) size = 24;
349 TMatrixD
matrix(size, size);
351 float Error[3][6] = {{0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001},
352 {0.005, 0.005, 0.005, 0.00005, 0.00005, 0.00005},
353 {0.005, 0.005, 0.005, 0.00005, 0.00005, 0.00005}};
355 float TollerancyPosition = 0.01;
356 float TollerancyRotation = 0.0001;
361 if (ConsQC.GetNrows()<70) UseQC =
false;
363 int nLayer = 12, nDeg = 5;
364 if (st==4) { nLayer = 8; nDeg = 3; }
366 for (
int la = 0;
la<nLayer;
la++)
367 for (
int dg = 0; dg<nDeg; dg++) {
372 if (
la<8 && rdg==1) rdg = 0;
373 if (st==4 && rdg==3) rdg = 4;
375 double ThisError2 = Error[
la/4][rdg]*Error[
la/4][rdg];
377 if (UseQC) { ThisError2 += ConsQC(
la, 1)*ConsQC(
la, 1);
378 }
else { ThisError2 += TollerancyPosition*TollerancyPosition; }
379 }
else if (rdg==2) { ThisError2 += TollerancyPosition*TollerancyPosition;
380 }
else { ThisError2 += TollerancyRotation*TollerancyRotation; }
382 matrix(index, index) = 1./ThisError2;
395 if(st == 4) size = 24;
399 float Error[3][6] = {{0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001},
400 {0.005, 0.005, 0.005, 0.00005, 0.00005, 0.00005},
401 {0.005, 0.005, 0.005, 0.00005, 0.00005, 0.00005}};
403 float TollerancyPosition = 0.01;
404 float TollerancyRotation = 0.0001;
409 if (ConsQC.GetNrows()<70) UseQC =
false;
413 int nLayer = 12, nDeg = 5;
414 if (st==4) { nLayer = 8; nDeg = 3; }
416 for (
int la = 0;
la<nLayer;
la++)
417 for (
int dg = 0; dg<nDeg; dg++) {
422 if (
la<8 && rdg==1) rdg = 0;
423 if (st==4 && rdg==3) rdg = 4;
425 double ThisError2 = Error[
la/4][rdg]*Error[
la/4][rdg];
427 if (UseQC) { ThisError2 += ConsQC(
la, 1)*ConsQC(
la, 1);
428 }
else { ThisError2 += TollerancyPosition*TollerancyPosition; }
429 }
else if (rdg==2) { ThisError2 += TollerancyPosition*TollerancyPosition;
430 }
else { ThisError2 += TollerancyRotation*TollerancyRotation; }
432 float Constraint = 0.;
434 Constraint += Survey(rdg,
la/4-1);
435 if (UseQC && rdg==0) Constraint += ConsQC(
la, 0);;
436 if (UseQC && rdg==1) Constraint -= ConsQC(
la, 0);
438 matrix(index, 0) = Constraint/ThisError2;
448 TString MtxFileName =
"./LocalMillepedeMatrix_"; MtxFileName += mf; MtxFileName +=
".root";
449 if (mf==-1) MtxFileName =
"./LocalMillepedeMatrix.root";
451 TDirectory *dirSave = gDirectory;
453 TFile *MatrixFile =
new TFile(MtxFileName);
455 TString MtxName = Code; MtxName +=
wh; MtxName +=
"_"; MtxName +=
st; MtxName +=
"_"; MtxName += se;
456 TMatrixD *ThisMtx = (TMatrixD *)MatrixFile->Get(MtxName);
468 TMatrixD
matrix(60+6,60+6);
469 if(st == 4) matrix.ResizeTo(40+6, 40+6);
471 for(
int counterDeg = 0; counterDeg < 5; ++counterDeg) {
472 for(
int counterLayer = 0; counterLayer < 12; ++counterLayer) {
474 matrix(40+counterDeg, counterLayer*5+counterDeg) = 10000.0;
475 matrix(counterLayer*5+counterDeg, 40+counterDeg) = 10000.0;
477 int realCounter = counterDeg+1;
478 if(counterDeg == 1 && counterLayer < 8) {
479 realCounter = counterDeg-1;
481 matrix(counterLayer*5+counterDeg,40+realCounter) = 10000.0;
482 if( (realCounter == 0 && counterLayer > 7) ||
483 (realCounter == 1 && counterLayer < 7))
continue;
484 matrix(60+realCounter,counterLayer*5+counterDeg) = 10000.0;
495 TMatrixD sigmaQC(5, 12);
498 if(st == 4) matrix.ResizeTo(40, 40);
501 if(surv.GetNrows() < 7) {
502 for(
int counterDeg = 0; counterDeg < 5; counterDeg++) {
503 for(
int counterLayer = 0; counterLayer < 12; ++counterLayer) {
504 if(st != 4 && counterLayer > 7)
continue;
505 if(counterDeg == 0) {
506 sigmaQC(counterDeg, counterLayer) = 0.05;
507 }
else if(counterDeg < 3) {
508 sigmaQC(counterDeg, counterLayer) = 0.05;
510 sigmaQC(counterDeg, counterLayer) = 0.05;
515 float meanvarSL1 =
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))/10000.0;
516 float meanvarSL2 = 0;
517 if(surv.GetNrows() > 9) meanvarSL2 =
sqrt(surv(8,1)*surv(8,1)+surv(9,1)*surv(9,1)+surv(10,1)*surv(10,1)+surv(11,1)*surv(11,1))/10000.0;
518 float meanvarSL3 =
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))/10000.0;
519 for(
int counterDeg = 0; counterDeg < 5; counterDeg++) {
520 for(
int counterLayer = 0; counterLayer < 12; ++counterLayer) {
521 if(st != 4 && counterLayer > 7)
continue;
523 if(counterLayer < 4) {
524 meanerror = meanvarSL1;
525 }
else if(counterLayer > 3 && counterLayer < 8){
526 meanerror = meanvarSL2;
528 meanerror = meanvarSL3;
530 if(counterDeg == 0) {
531 sigmaQC(counterDeg, counterLayer) =
sqrt((surv(counterLayer, 1)/10000.0)*(surv(counterLayer, 1)/10000.0)+meanerror*meanerror);
532 }
else if(counterDeg < 3) {
533 sigmaQC(counterDeg, counterLayer) = 0.05;
535 sigmaQC(counterDeg, counterLayer) = 0.05;
539 double **
Eta =
new double *[12];
540 for(
int counterLayer = 0; counterLayer < 12; counterLayer++) {
542 if(counterLayer > 7 && st == 4)
continue;
543 Eta[counterLayer] =
new double [5];
544 for(
int counterLayer2 = 0; counterLayer2 < 12; counterLayer2++) {
545 if(counterLayer > 7 && st == 4)
continue;
546 if((counterLayer2 < 4 && counterLayer < 4) || (counterLayer2 > 3 && counterLayer > 3)) {
547 if(counterLayer == counterLayer2) {
548 Eta[counterLayer][counterLayer2] = 3.0/(4.0);
550 Eta[counterLayer][counterLayer2] = -1.0/(4.0);
553 Eta[counterLayer][counterLayer2] = 0.0;
558 for(
int counterDeg = 0; counterDeg < 5; counterDeg++) {
559 for(
int counterLayer = 0; counterLayer < 12; counterLayer++) {
560 if(counterLayer > 7 && st == 4)
continue;
561 for(
int counterLayer2 = 0; counterLayer2 < 12; counterLayer2++) {
562 if(counterLayer2 > 7 && st == 4)
continue;
563 for(
int counterLayer3 = 0; counterLayer3 < 12; counterLayer3++) {
564 if(counterLayer3 > 7 && st == 4)
continue;
565 matrix(5*counterLayer2+counterDeg, 5*counterLayer3+counterDeg) +=
566 Eta[counterLayer][counterLayer2]*Eta[counterLayer][counterLayer3]/(sigmaQC(counterDeg,counterLayer)*sigmaQC(counterDeg,counterLayer));
579 TMatrixD ResQC(5, 12);
580 TMatrixD sigmaQC(5, 12);
582 if(st == 4) matrix.ResizeTo(40, 1);
584 if(surv.GetNrows() < 7) {
585 for(
int counterDeg = 0; counterDeg < 5; counterDeg++) {
586 for(
int counterLayer = 0; counterLayer < 12; ++counterLayer) {
587 if(st != 4 && counterLayer > 7)
continue;
588 if(counterDeg == 0) {
589 sigmaQC(counterDeg, counterLayer) = 0.05;
590 }
else if(counterDeg < 3) {
591 sigmaQC(counterDeg, counterLayer) = 0.05;
593 sigmaQC(counterDeg, counterLayer) = 0.05;
598 for(
int counterChamber = 0; counterChamber < 12; ++counterChamber) {
599 ResQC(0, counterChamber) = -surv(counterChamber, 0)/10000.0;
601 float meanvarSL1 =
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))/10000.0;
602 float meanvarSL2 = 0;
603 if(surv.GetNrows() > 9) {
604 meanvarSL2 =
sqrt(surv(8,1)*surv(8,1)+surv(9,1)*surv(9,1)+surv(10,1)*surv(10,1)+surv(11,1)*surv(11,1))/10000.0;
606 float meanvarSL3 =
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))/10000.0;
607 for(
int counterDeg = 0; counterDeg < 5; counterDeg++) {
608 for(
int counterLayer = 0; counterLayer < 12; ++counterLayer) {
609 if(st != 4 && counterLayer > 7)
continue;
611 if(counterLayer < 4) {
612 meanerror = meanvarSL1;
613 }
else if(counterLayer > 3 && counterLayer < 8){
614 meanerror = meanvarSL2;
616 meanerror = meanvarSL3;
618 if(counterDeg == 0) {
619 sigmaQC(counterDeg, counterLayer) =
sqrt((surv(counterLayer, 1)/10000.0)*(surv(counterLayer, 1)/10000.0)+meanerror*meanerror);
620 }
else if(counterDeg < 3) {
621 sigmaQC(counterDeg, counterLayer) = 0.05;
623 sigmaQC(counterDeg, counterLayer) = 0.05;
627 double **
Eta =
new double *[12];
628 for(
int counterLayer = 0; counterLayer < 12; counterLayer++) {
629 if(counterLayer > 7 && st == 4)
continue;
630 Eta[counterLayer] =
new double [5];
631 for(
int counterLayer2 = 0; counterLayer2 < 12; counterLayer2++) {
632 if(counterLayer > 7 && st == 4)
continue;
633 if((counterLayer2 < 4 && counterLayer < 4) || (counterLayer2 > 3 && counterLayer > 3)) {
634 if(counterLayer == counterLayer2) {
635 Eta[counterLayer][counterLayer2] = 3.0/(4.0);
637 Eta[counterLayer][counterLayer2] = -1.0/(4.0);
640 Eta[counterLayer][counterLayer2] = 0.0;
645 for(
int counterDeg = 0; counterDeg < 5; counterDeg++) {
646 for(
int counterLayer = 0; counterLayer < 12; counterLayer++) {
647 if(counterLayer > 7 && st == 4)
continue;
648 for(
int counterLayer2 = 0; counterLayer2 < 12; counterLayer2++) {
649 if(counterLayer2 > 7 && st == 4)
continue;
651 if(counterDeg != 0) {
652 if(counterLayer < 4) {
653 mean = (ResQC(counterDeg, 0)+ResQC(counterDeg, 1)+ResQC(counterDeg, 2)+ResQC(counterDeg, 3))/4.0;
654 }
else if(counterLayer > 3 && counterLayer < 8) {
655 mean = (ResQC(counterDeg, 4)+ResQC(counterDeg, 5)+ResQC(counterDeg, 6)+ResQC(counterDeg, 7))/4.0;
657 mean = (ResQC(counterDeg, 8)+ResQC(counterDeg, 9)+ResQC(counterDeg, 10)+ResQC(counterDeg, 11))/4.0;
660 matrix(5*counterLayer2+counterDeg, 0) += Eta[counterLayer][counterLayer2]*(ResQC(counterDeg,counterLayer)-
mean)/(sigmaQC(counterDeg,counterLayer)*sigmaQC(counterDeg,counterLayer));
697 if(st == 4) size = 40;
699 TMatrixD
matrix(size+6, size+6);
701 float error[2][6] = {{0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001},
702 {0.05, 0.05, 0.05, 0.005, 0.005, 0.005}};
703 for(
int counterLayer = 0; counterLayer < size/5; counterLayer++) {
704 for(
int counterLayer2 = 0; counterLayer2 < size/5; counterLayer2++) {
705 int sl1 = counterLayer/4;
706 int sl2 = counterLayer2/4;
708 for(
int counterDeg = 0; counterDeg < 5; counterDeg++) {
709 int counterDegAux = counterDeg+1;
710 if(counterLayer < 8 && counterDeg == 1) counterDegAux = 0;
711 int sl = (sl1 + 1)/2;
712 matrix(5*counterLayer+counterDeg, 5*counterLayer2+counterDeg) = 1.0/(16.0*error[
sl][counterDegAux]*error[
sl][counterDegAux]);
753 if(st == 4) size = 40;
755 TMatrixD
matrix(size+6, 1);
757 float error[2][6] = {{0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001},
758 {0.05, 0.05, 0.05, 0.005, 0.005, 0.005}};
759 for(
int counterLayer = 0; counterLayer < size/5; counterLayer++) {
760 for(
int counterDeg = 0; counterDeg < 5; counterDeg++) {
761 int counterDegAux = counterDeg+1;
762 if(counterLayer < 8 && counterDeg == 1) counterDegAux = 0;
763 int superlayerAux = counterLayer/4;
764 int sl = (superlayerAux + 1)/2;
765 matrix(5*counterLayer+counterDeg, 0) = survey(counterDegAux, superlayerAux)/(4.0*error[
sl][counterDegAux]*error[
sl][counterDegAux]);
776 TMatrixD updatedMatrix =
m;
777 updatedMatrix.ResizeTo(m.GetNrows()+6, m.GetNcols()+6);
778 return updatedMatrix;
785 ttreeOutput =
new TTree(
"DTLocalMillepede",
"DTLocalMillepede");
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)
tuple path
else: Piece not in the list, fine.
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
tuple size
Write out results.
TMatrixD getLagMatrix(int, int, int)