BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
Millepede Class Reference

#include <AlignmentTools/Millepede.h>

Public Member Functions

 Millepede ()
 Standard constructor.
 
 ~Millepede ()
 Destructor.
 
bool initialize ()
 Initialization.
 
bool InitMille (bool DOF[], double Sigm[], int nglo, int nloc, double startfact, int nstd, double res_cut, double res_cut_init)
 
bool MakeGlobalFit (double par[], double error[], double pull[])
 
bool ParGlo (int index, double param)
 
bool ParSig (int index, double sigma)
 
bool ConstF (double dercs[], double rhs)
 
bool EquLoc (double dergb[], double derlc[], double dernl[], double rmeas, double sigma)
 
bool ZerLoc (double dergb[], double derlc[], double dernl[])
 
bool FitLoc (int n, double track_params[], int single_fit)
 
int GetTrackNumber ()
 
void SetTrackNumber (int value)
 

Detailed Description

Author
Sebastien Viret
Date
2005-07-29

Definition at line 16 of file Millepede.h.

Constructor & Destructor Documentation

◆ Millepede()

Millepede::Millepede ( )

Standard constructor.

Definition at line 24 of file Millepede.cxx.

25{}

◆ ~Millepede()

Millepede::~Millepede ( )

Destructor.

Definition at line 29 of file Millepede.cxx.

29{}

Member Function Documentation

◆ ConstF()

bool Millepede::ConstF ( double dercs[],
double rhs )

Definition at line 263 of file Millepede.cxx.

264{
265 if (ncs>=mcs) // mcs is defined in Millepede.h
266 {
267 cout << "Too many constraints !!!" << endl;
268 return false;
269 }
270
271 for (int i=0; i<nagb; i++) {adercs[ncs][i] = dercs[i];}
272
273 arhs[ncs] = rhs;
274 ncs++ ;
275 cout << "Number of constraints increased to " << ncs << endl;
276 return true;
277}

◆ EquLoc()

bool Millepede::EquLoc ( double dergb[],
double derlc[],
double dernl[],
double rmeas,
double sigma )

Definition at line 293 of file Millepede.cxx.

294{
295
296 if (sigma<=0.0) // If parameter is fixed, then no equation
297 {
298 for (int i=0; i<nalc; i++)
299 {
300 derlc[i] = 0.0;
301 }
302 for (int i=0; i<nagb; i++)
303 {
304 dergb[i] = 0.0;
305 }
306 return true;
307 }
308
309 // Serious equation, initialize parameters
310
311 double wght = 1.0/(sigma*sigma);
312 int nonzer = 0;
313 int ialc = -1;
314 int iblc = -1;
315 int iagb = -1;
316 int ibgb = -1;
317
318 for (int i=0; i<nalc; i++) // Retrieve local param interesting indices
319 {
320 if (derlc[i]!=0.0)
321 {
322 nonzer++;
323 if (ialc == -1) ialc=i; // first index
324 iblc = i; // last index
325 }
326 }
327
328 if (verbose_mode) cout << ialc << " / " << iblc << endl;
329
330 for (int i=0; i<nagb; i++) // Idem for global parameters
331 {
332 if (dergb[i]!=0.0)
333 {
334 nonzer++;
335 if (iagb == -1) iagb=i; // first index
336 ibgb = i; // last index
337 }
338 }
339
340 if (verbose_mode) cout << iagb << " / " << ibgb << endl;
341
342 indst.push_back(-1);
343 arest.push_back(rmeas);
344 arenl.push_back(0.);
345
346 for (int i=ialc; i<=iblc; i++)
347 {
348 if (derlc[i]!=0.0)
349 {
350 indst.push_back(i);
351 arest.push_back(derlc[i]);
352 arenl.push_back(0.0);
353 derlc[i] = 0.0;
354 }
355 }
356
357 indst.push_back(-1);
358 arest.push_back(wght);
359 arenl.push_back(0.0);
360
361 for (int i=iagb; i<=ibgb; i++)
362 {
363 if (dergb[i]!=0.0)
364 {
365 indst.push_back(i);
366 arest.push_back(dergb[i]);
367 arenl.push_back(dernl[i]);
368 dergb[i] = 0.0;
369 }
370 }
371
372 if (verbose_mode) cout << "Out Equloc -- NST = " << arest.size() << endl;
373
374 return true;
375}
TTree * sigma
const bool verbose_mode
Definition Alignment.h:68

◆ FitLoc()

bool Millepede::FitLoc ( int n,
double track_params[],
int single_fit )

Definition at line 418 of file Millepede.cxx.

419{
420 // Few initializations
421
422 int i, j, k, ik, ij, ist, nderlc, ndergl, ndf;
423 int ja = -1;
424 int jb = 0;
425 int nagbn = 0;
426
427 double rmeas, wght, rms, cutval;
428
429 double summ = 0.0;
430 int nsum = 0;
431 nst = 0;
432 nst = arest.size();
433
434
435 // Fill the track store at first pass
436
437 if (itert < 2 && single_fit != 1) // Do it only once
438 {
439 if (debug_mode) cout << "Store equation no: " << n << endl;
440
441 for (i=0; i<nst; i++) // Store the track parameters
442 {
443 storeind.push_back(indst[i]);
444 storeare.push_back(arest[i]);
445 storenl.push_back(arenl[i]);
446
447 if (arenl[i] != 0.) arest[i] = 0.0; // Reset global derivatives if non linear and first iteration
448 }
449
450 arenl.clear();
451
452 storeplace.push_back(storeind.size());
453
454 if (verbose_mode) cout << "StorePlace size = " << storeplace[n] << endl;
455 if (verbose_mode) cout << "StoreInd size = " << storeind.size() << endl;
456 }
457
458
459 for (i=0; i<nalc; i++) // reset local params
460 {
461 blvec[i] = 0.0;
462
463 for (j=0; j<nalc; j++) {clmat[i][j] = 0.0;}
464 }
465
466 for (i=0; i<nagb; i++) {indnz[i] = -1;} // reset mixed params
467
468
469 /*
470
471 LOOPS : HOW DOES IT WORKS ?
472
473 Now start by reading the informations stored with EquLoc.
474 Those informations are in vector INDST and AREST.
475 Each -1 in INDST delimits the equation parameters:
476
477 First -1 ---> rmeas in AREST
478 Then we have indices of local eq in INDST, and derivatives in AREST
479 Second -1 ---> weight in AREST
480 Then follows indices and derivatives of global eq.
481 ....
482
483 We took them and store them into matrices.
484
485 As we want ONLY local params, we substract the part of the estimated value
486 due to global params. Indeed we could have already an idea of these params,
487 with previous alignment constants for example (set with PARGLO). Also if there
488 are more than one iteration (FITLOC could be called by FITGLO)
489
490 */
491
492
493 //
494 // FIRST LOOP : local track fit
495 //
496
497 ist = 0;
498 indst.push_back(-1);
499
500 while (ist <= nst)
501 {
502 if (indst[ist] == -1)
503 {
504 if (ja == -1) {ja = ist;} // First 0 : rmeas
505 else if (jb == 0) {jb = ist;} // Second 0 : weight
506 else // Third 0 : end of equation
507 {
508 rmeas = arest[ja];
509 wght = arest[jb];
510 if (verbose_mode) cout << "rmeas = " << rmeas << endl ;
511 if (verbose_mode) cout << "wght = " << wght << endl ;
512
513 for (i=(jb+1); i<ist; i++) // Now suppress the global part
514 // (only relevant with iterations)
515 {
516 j = indst[i]; // Global param indice
517 if (verbose_mode) cout << "dparm[" << j << "] = " << dparm[j] << endl;
518 if (verbose_mode) cout << "Starting misalignment = " << pparm[j] << endl;
519 rmeas -= arest[i]*(pparm[j]+dparm[j]);
520 }
521
522 if (verbose_mode) cout << "rmeas after global stuff removal = " << rmeas << endl ;
523
524 for (i=(ja+1); i<jb; i++) // Finally fill local matrix and vector
525 {
526 j = indst[i]; // Local param indice (the matrix line)
527 blvec[j] += wght*rmeas*arest[i]; // See note for precisions
528
529 if (verbose_mode) cout << "blvec[" << j << "] = " << blvec[j] << endl ;
530
531 for (k=(ja+1); k<=i ; k++) // Symmetric matrix, don't bother k>j coeffs
532 {
533 ik = indst[k];
534 clmat[j][ik] += wght*arest[i]*arest[k];
535
536 if (verbose_mode) cout << "clmat[" << j << "][" << ik << "] = " << clmat[j][ik] << endl;
537 }
538 }
539 ja = -1;
540 jb = 0;
541 ist--;
542 } // End of "end of equation" operations
543 } // End of loop on equation
544 ist++;
545 } // End of loop on all equations used in the fit
546
547
548 //
549 // Local params matrix is completed, now invert to solve...
550 //
551
552 nrank = 0; // Rank is the number of nonzero diagonal elements
553 nrank = Millepede::SpmInv(clmat, blvec, nalc, scdiag, scflag);
554
555 if (debug_mode) cout << "" << endl;
556 if (debug_mode) cout << " __________________________________________________" << endl;
557 if (debug_mode) cout << " Printout of local fit (FITLOC) with rank= "<< nrank << endl;
558 if (debug_mode) cout << " Result of local fit : (index/parameter/error)" << endl;
559
560 for (i=0; i<nalc; i++)
561 {
562 if (debug_mode) cout << std::setprecision(4) << std::fixed;
563 if (debug_mode) cout << std::setw(20) << i << " / " << std::setw(10)
564 << blvec[i] << " / " << sqrt(clmat[i][i]) << endl;
565 }
566
567
568 // Store the track params and errors
569
570 for (i=0; i<nalc; i++)
571 {
572 track_params[2*i] = blvec[i];
573 track_params[2*i+1] = sqrt(fabs(clmat[i][i]));
574 }
575
576
577 //
578 // SECOND LOOP : residual calculation
579 //
580
581 ist = 0;
582 ja = -1;
583 jb = 0;
584
585 while (ist <= nst)
586 {
587 if (indst[ist] == -1)
588 {
589 if (ja == -1) {ja = ist;} // First 0 : rmeas
590 else if (jb == 0) {jb = ist;} // Second 0 : weight
591 else // Third 0 : end of equation
592 {
593 rmeas = arest[ja];
594 wght = arest[jb];
595
596 nderlc = jb-ja-1; // Number of local derivatives involved
597 ndergl = ist-jb-1; // Number of global derivatives involved
598
599 // Print all (for debugging purposes)
600
601 if (verbose_mode) cout << "" << endl;
602 if (verbose_mode) cout << std::setprecision(4) << std::fixed;
603 if (verbose_mode) cout << ". equation: measured value " << std::setw(13)
604 << rmeas << " +/- " << std::setw(13) << 1.0/sqrt(wght) << endl;
605 if (verbose_mode) cout << "Number of derivatives (global, local): "
606 << ndergl << ", " << nderlc << endl;
607 if (verbose_mode) cout << "Global derivatives are: (index/derivative/parvalue) " << endl;
608
609 for (i=(jb+1); i<ist; i++)
610 {if (verbose_mode) cout << indst[i] << " / " << arest[i]
611 << " / " << pparm[indst[i]] << endl;}
612
613 if (verbose_mode) cout << "Local derivatives are: (index/derivative) " << endl;
614
615 for (i=(ja+1); i<jb; i++) {if (verbose_mode) cout << indst[i] << " / " << arest[i] << endl;}
616
617 // Now suppress local and global parts to RMEAS;
618
619 for (i=(ja+1); i<jb; i++) // First the local part
620 {
621 j = indst[i];
622 rmeas -= arest[i]*blvec[j];
623 }
624
625 for (i=(jb+1); i<ist; i++) // Then the global part
626 {
627 j = indst[i];
628 rmeas -= arest[i]*(pparm[j]+dparm[j]);
629 }
630
631 // rmeas contains now the residual value
632 // if (verbose_mode) cout << "Residual value : "<< rmeas << endl;
633 if (verbose_reject) cout << "Residual value : "<< rmeas << endl;
634
635 // reject the track if rmeas is too important (outlier)
636 if (fabs(rmeas) >= m_residual_cut_init && itert <= 1)
637 {
638 // if (verbose_mode) cout << "Rejected track !!!!!" << endl;
639 if (verbose_reject) cout << "Rejected track !!!!!" << endl;
640 locrej++;
641 indst.clear(); // reset stores and go to the next track
642 arest.clear();
643 return false;
644 }
645
646 if (fabs(rmeas) >= m_residual_cut && itert > 1)
647 {
648 // if (verbose_mode) cout << "Rejected track !!!!!" << endl;
649 if (verbose_reject) cout << "Rejected track !!!!!" << endl;
650 locrej++;
651 indst.clear(); // reset stores and go to the next track
652 arest.clear();
653 return false;
654 }
655
656 summ += wght*rmeas*rmeas ; // total chi^2
657 nsum++; // number of equations
658 ja = -1;
659 jb = 0;
660 ist--;
661 } // End of "end of equation" operations
662 } // End of loop on equation
663 ist++;
664 } // End of loop on all equations used in the fit
665
666 ndf = nsum-nrank;
667 rms = 0.0;
668
669 if (debug_mode) cout << "Final chi square / degrees of freedom "<< summ << " / " << ndf << endl;
670
671 if (ndf > 0) rms = summ/float(ndf); // Chi^2/dof
672
673 if (single_fit == 0) loctot++;
674
675 if (nstdev != 0 && ndf > 0 && single_fit != 1) // Chisquare cut
676 {
677 cutval = Millepede::chindl(nstdev, ndf)*cfactr;
678
679 if (debug_mode) cout << "Reject if Chisq/Ndf = " << rms << " > " << cutval << endl;
680
681 if (rms > cutval) // Reject the track if too much...
682 {
683 if (verbose_mode) cout << "Rejected track !!!!!" << endl;
684 if (single_fit == 0) locrej++;
685 indst.clear(); // reset stores and go to the next track
686 arest.clear();
687 return false;
688 }
689 }
690
691 if (single_fit == 1) // Stop here if just updating the track parameters
692 {
693 indst.clear(); // Reset store for the next track
694 arest.clear();
695 return true;
696 }
697
698 //
699 // THIRD LOOP: local operations are finished, track is accepted
700 // We now update the global parameters (other matrices)
701 //
702
703 ist = 0;
704 ja = -1;
705 jb = 0;
706
707 while (ist <= nst)
708 {
709 if (indst[ist] == -1)
710 {
711 if (ja == -1) {ja = ist;} // First 0 : rmeas
712 else if (jb == 0) {jb = ist;} // Second 0 : weight
713 else // Third 0 : end of equation
714 {
715 rmeas = arest[ja];
716 wght = arest[jb];
717
718 for (i=(jb+1); i<ist; i++) // Now suppress the global part
719 {
720 j = indst[i]; // Global param indice
721 rmeas -= arest[i]*(pparm[j]+dparm[j]);
722 }
723
724 // First of all, the global/global terms (exactly like local matrix)
725
726 for (i=(jb+1); i<ist; i++)
727 {
728 j = indst[i]; // Global param indice (the matrix line)
729
730 bgvec[j] += wght*rmeas*arest[i]; // See note for precisions
731 if (verbose_mode) cout << "bgvec[" << j << "] = " << bgvec[j] << endl ;
732
733 for (k=(jb+1); k<ist ; k++)
734 {
735 ik = indst[k];
736 cgmat[j][ik] += wght*arest[i]*arest[k];
737 if (verbose_mode) cout << "cgmat[" << j << "][" << ik << "] = " << cgmat[j][ik] << endl;
738 }
739 }
740
741 // Now we have also rectangular matrices containing global/local terms.
742
743 for (i=(jb+1); i<ist; i++)
744 {
745 j = indst[i]; // Global param indice (the matrix line)
746 ik = indnz[j]; // Index of index
747
748 if (ik == -1) // New global variable
749 {
750 for (k=0; k<nalc; k++) {clcmat[nagbn][k] = 0.0;} // Initialize the row
751
752 indnz[j] = nagbn;
753 indbk[nagbn] = j;
754 ik = nagbn;
755 nagbn++;
756 }
757
758 for (k=(ja+1); k<jb ; k++) // Now fill the rectangular matrix
759 {
760 ij = indst[k];
761 clcmat[ik][ij] += wght*arest[i]*arest[k];
762 if (verbose_mode) cout << "clcmat[" << ik << "][" << ij << "] = " << clcmat[ik][ij] << endl;
763 }
764 }
765 ja = -1;
766 jb = 0;
767 ist--;
768 } // End of "end of equation" operations
769 } // End of loop on equation
770 ist++;
771 } // End of loop on all equations used in the fit
772
773 // Third loop is finished, now we update the correction matrices (see notes)
774
775 Millepede::SpAVAt(clmat, clcmat, corrm, nalc, nagbn);
776 Millepede::SpAX(clcmat, blvec, corrv, nalc, nagbn);
777
778 for (i=0; i<nagbn; i++)
779 {
780 j = indbk[i];
781 bgvec[j] -= corrv[i];
782
783 for (k=0; k<nagbn; k++)
784 {
785 ik = indbk[k];
786 cgmat[j][ik] -= corrm[i][k];
787 }
788 }
789
790 indst.clear(); // Reset store for the next track
791 arest.clear();
792
793 return true;
794}
const Int_t n
const bool verbose_reject
Definition Alignment.h:69
const bool debug_mode
Definition Alignment.h:67

Referenced by MakeGlobalFit().

◆ GetTrackNumber()

int Millepede::GetTrackNumber ( )

Definition at line 1515 of file Millepede.cxx.

1515{return m_track_number;}

Referenced by MilleAlign::fillHist(), and MakeGlobalFit().

◆ initialize()

bool Millepede::initialize ( )

Initialization.

◆ InitMille()

bool Millepede::InitMille ( bool DOF[],
double Sigm[],
int nglo,
int nloc,
double startfact,
int nstd,
double res_cut,
double res_cut_init )

Definition at line 46 of file Millepede.cxx.

49{
50
51 cout << " " << endl;
52 cout << " * o o o " << endl;
53 cout << " o o o " << endl;
54 cout << " o ooooo o o o oo ooo oo ooo oo " << endl;
55 cout << " o o o o o o o o o o o o o o o o " << endl;
56 cout << " o o o o o o oooo o o oooo o o oooo " << endl;
57 cout << " o o o o o o o ooo o o o o " << endl;
58 cout << " o o o o o o oo o oo ooo oo ++ starts" << endl;
59 cout << " " << endl;
60
61 if (debug_mode) cout << "" << endl;
62 if (debug_mode) cout << "----------------------------------------------------" << endl;
63 if (debug_mode) cout << "" << endl;
64 if (debug_mode) cout << " Entering InitMille" << endl;
65 if (debug_mode) cout << "" << endl;
66 if (debug_mode) cout << "-----------------------------------------------------" << endl;
67 if (debug_mode) cout << "" << endl;
68
69 ncs = 0;
70 loctot = 0; // Total number of local fits
71 locrej = 0; // Total number of local fits rejected
72 cfactref = 1.0; // Reference value for Chi^2/ndof cut
73
74 Millepede::SetTrackNumber(0); // Number of local fits (starts at 0)
75
76 m_residual_cut = res_cut;
77 m_residual_cut_init = res_cut_init;
78
79 // nagb = 6*nglo; // Number of global derivatives
80 nagb = 3*nglo; // modified by wulh
81 nalc = nloc; // Number of local derivatives
82 nstdev = nstd; // Number of StDev for local fit chisquare cut
83
84 if (debug_mode) cout << "Number of global parameters : " << nagb << endl;
85 if (debug_mode) cout << "Number of local parameters : " << nalc << endl;
86 if (debug_mode) cout << "Number of standard deviations : " << nstdev << endl;
87
88 if (nagb>mglobl || nalc>mlocal)
89 {
90 if (debug_mode) cout << "Two many parameters !!!!!" << endl;
91 return false;
92 }
93
94 // Global parameters initializations
95
96 for (int i=0; i<nagb; i++)
97 {
98 bgvec[i]=0.;
99 pparm[i]=0.;
100 dparm[i]=0.;
101 psigm[i]=-1.;
102 indnz[i]=-1;
103 indbk[i]=-1;
104 nlnpa[i]=0;
105
106 for (int j=0; j<nagb;j++)
107 {
108 cgmat[i][j]=0.;
109 }
110 }
111
112 // Local parameters initializations
113
114 for (int i=0; i<nalc; i++)
115 {
116 blvec[i]=0.;
117
118 for (int j=0; j<nalc;j++)
119 {
120 clmat[i][j]=0.;
121 }
122 }
123
124 // Then we fix all parameters...
125
126 for (int j=0; j<nagb; j++) {Millepede::ParSig(j,0.0);}
127
128 // ...and we allow them to move if requested
129
130 // for (int i=0; i<3; i++)
131 for (int i=0; i<3; i++) // modified by wulh on 06/08/27
132 {
133 if (verbose_mode) cout << "GetDOF(" << i << ")= " << DOF[i] << endl;
134
135 if (DOF[i])
136 {
137 for (int j=i*nglo; j<(i+1)*nglo; j++)
138 {Millepede::ParSig(j,Sigm[i]);}
139 }
140 }
141
142 // Activate iterations (if requested)
143
144 itert = 0; // By default iterations are turned off
145 cfactr = 500.0;
146 if (m_iteration) Millepede::InitUn(startfact);
147
148 arest.clear(); // Number of stored parameters when doing local fit
149 arenl.clear(); // Is it linear or not?
150 indst.clear();
151
152 storeind.clear();
153 storeare.clear();
154 storenl.clear();
155 storeplace.clear();
156
157 if (debug_mode) cout << "" << endl;
158 if (debug_mode) cout << "----------------------------------------------------" << endl;
159 if (debug_mode) cout << "" << endl;
160 if (debug_mode) cout << " InitMille has been successfully called!" << endl;
161 if (debug_mode) cout << "" << endl;
162 if (debug_mode) cout << "-----------------------------------------------------" << endl;
163 if (debug_mode) cout << "" << endl;
164
165 return true;
166}
void SetTrackNumber(int value)
bool ParSig(int index, double sigma)
const bool m_iteration
Definition Alignment.h:66

◆ MakeGlobalFit()

bool Millepede::MakeGlobalFit ( double par[],
double error[],
double pull[] )

Definition at line 814 of file Millepede.cxx.

815{
816 int i, j, nf, nvar;
817 int itelim = 0;
818
819 int nstillgood;
820
821 double sum;
822
823 double step[150];
824
825 double trackpars[2*mlocal];
826
827 int ntotal_start, ntotal;
828
829 cout << "..... Making global fit ....." << endl;
830
831 ntotal_start = Millepede::GetTrackNumber();
832
833 std::vector<double> track_slopes;
834
835 track_slopes.resize(2*ntotal_start);
836
837 for (i=0; i<2*ntotal_start; i++) track_slopes[i] = 0.;
838
839 if (itert <= 1) itelim=10; // Max number of iterations
840
841 while (itert < itelim) // Iteration for the final loop
842 {
843 if (debug_mode) cout << "ITERATION --> " << itert << endl;
844
845 ntotal = Millepede::GetTrackNumber();
846 cout << "...using " << ntotal << " tracks..." << endl;
847
848 // Start by saving the diagonal elements
849
850 for (i=0; i<nagb; i++) {diag[i] = cgmat[i][i];}
851
852 // Then we retrieve the different constraints: fixed parameter or global equation
853
854 nf = 0; // First look at the fixed global params
855
856 for (i=0; i<nagb; i++)
857 {
858 if (psigm[i] <= 0.0) // fixed global param
859 {
860 nf++;
861
862 for (j=0; j<nagb; j++)
863 {
864 cgmat[i][j] = 0.0; // Reset row and column
865 cgmat[j][i] = 0.0;
866 }
867 }
868 else if (psigm[i] > 0.0)
869 {
870 cgmat[i][i] += 1.0/(psigm[i]*psigm[i]);
871 }
872 }
873
874 nvar = nagb; // Current number of equations
875 if (debug_mode) cout << "Number of constraint equations : " << ncs << endl;
876
877 if (ncs > 0) // Then the constraint equation
878 {
879 for (i=0; i<ncs; i++)
880 {
881 sum = arhs[i];
882 for (j=0; j<nagb; j++)
883 {
884 cgmat[nvar][j] = float(ntotal)*adercs[i][j];
885 cgmat[j][nvar] = float(ntotal)*adercs[i][j];
886 sum -= adercs[i][j]*(pparm[j]+dparm[j]);
887 }
888
889 cgmat[nvar][nvar] = 0.0;
890 bgvec[nvar] = float(ntotal)*sum;
891 nvar++;
892 }
893 }
894
895
896 // Intended to compute the final global chisquare
897
898 double final_cor = 0.0;
899
900 if (itert > 1)
901 {
902 for (j=0; j<nagb; j++)
903 {
904 for (i=0; i<nagb; i++)
905 {
906 if (psigm[i] > 0.0)
907 {
908 final_cor += step[j]*cgmat[j][i]*step[i];
909 if (i == j) final_cor -= step[i]*step[i]/(psigm[i]*psigm[i]);
910 }
911 }
912 }
913 }
914
915 cout << " Final coeff is " << final_cor << endl;
916 cout << " Final NDOFs = " << nagb << endl;
917
918 // The final matrix inversion
919
920 nrank = Millepede::SpmInv(cgmat, bgvec, nvar, scdiag, scflag);
921
922 for (i=0; i<nagb; i++)
923 {
924 dparm[i] += bgvec[i]; // Update global parameters values (for iterations)
925 if (verbose_mode) cout << "dparm[" << i << "] = " << dparm[i] << endl;
926 if (verbose_mode) cout << "cgmat[" << i << "][" << i << "] = " << cgmat[i][i] << endl;
927 if (verbose_mode) cout << "err = " << sqrt(fabs(cgmat[i][i])) << endl;
928
929 step[i] = bgvec[i];
930
931 if (itert == 1) error[i] = cgmat[i][i]; // Unfitted error
932 }
933
934 cout << "" << endl;
935 cout << "The rank defect of the symmetric " << nvar << " by " << nvar
936 << " matrix is " << nvar-nf-nrank << " (bad if non 0)" << endl;
937
938 if (itert == 0) break;
939 itert++;
940
941 cout << "" << endl;
942 cout << "Total : " << loctot << " local fits, "
943 << locrej << " rejected." << endl;
944
945 // Reinitialize parameters for iteration
946
947 loctot = 0;
948 locrej = 0;
949
950 if (cfactr != cfactref && sqrt(cfactr) > 1.2*cfactref)
951 {
952 cfactr = sqrt(cfactr);
953 }
954 else
955 {
956 cfactr = cfactref;
957 // itert = itelim;
958 }
959
960 if (itert == itelim) break; // End of story
961
962 cout << "Iteration " << itert << " with cut factor " << cfactr << endl;
963
964 // Reset global variables
965
966 for (i=0; i<nvar; i++)
967 {
968 bgvec[i] = 0.0;
969 for (j=0; j<nvar; j++)
970 {
971 cgmat[i][j] = 0.0;
972 }
973 }
974
975 //
976 // We start a new iteration
977 //
978
979 // First we read the stores for retrieving the local params
980
981 nstillgood = 0;
982
983 for (i=0; i<ntotal_start; i++)
984 {
985 int rank_i = 0;
986 int rank_f = 0;
987
988 (i>0) ? rank_i = abs(storeplace[i-1]) : rank_i = 0;
989 rank_f = storeplace[i];
990
991 if (verbose_mode) cout << "Track " << i << " : " << endl;
992 if (verbose_mode) cout << "Starts at " << rank_i << endl;
993 if (verbose_mode) cout << "Ends at " << rank_f << endl;
994
995 if (rank_f >= 0) // Fit is still OK
996 {
997
998 if (itert > 3)
999 {
1000 indst.clear();
1001 arest.clear();
1002
1003 for (j=rank_i; j<rank_f; j++)
1004 {
1005 indst.push_back(storeind[j]);
1006
1007 if (storenl[j] == 0) arest.push_back(storeare[j]);
1008 if (storenl[j] == 1) arest.push_back(track_slopes[2*i]*storeare[j]);
1009 if (storenl[j] == 2) arest.push_back(track_slopes[2*i+1]*storeare[j]);
1010 }
1011
1012 for (j=0; j<2*nalc; j++) {trackpars[j] = 0.;}
1013
1014 Millepede::FitLoc(i,trackpars,1);
1015
1016 track_slopes[2*i] = trackpars[2];
1017 track_slopes[2*i+1] = trackpars[6];
1018 }
1019
1020 indst.clear();
1021 arest.clear();
1022
1023 for (j=rank_i; j<rank_f; j++)
1024 {
1025 indst.push_back(storeind[j]);
1026
1027 if (storenl[j] == 0) arest.push_back(storeare[j]);
1028 if (storenl[j] == 1) arest.push_back(track_slopes[2*i]*storeare[j]);
1029 if (storenl[j] == 2) arest.push_back(track_slopes[2*i+1]*storeare[j]);
1030 }
1031
1032 for (j=0; j<2*nalc; j++) {trackpars[j] = 0.;}
1033
1034 bool sc = Millepede::FitLoc(i,trackpars,0);
1035
1036 (sc)
1037 ? nstillgood++
1038 : storeplace[i] = -rank_f;
1039 }
1040 } // End of loop on fits
1041
1042 Millepede::SetTrackNumber(nstillgood);
1043
1044 } // End of iteration loop
1045
1046 Millepede::PrtGlo(); // Print the final results
1047
1048 for (j=0; j<nagb; j++)
1049 {
1050 par[j] = dparm[j];
1051 dparm[j] = 0.;
1052 pull[j] = par[j]/sqrt(psigm[j]*psigm[j]-cgmat[j][j]);
1053 error[j] = sqrt(fabs(cgmat[j][j]));
1054 }
1055
1056 cout << std::setw(10) << " " << endl;
1057 cout << std::setw(10) << " * o o o " << endl;
1058 cout << std::setw(10) << " o o o " << endl;
1059 cout << std::setw(10) << " o ooooo o o o oo ooo oo ooo oo " << endl;
1060 cout << std::setw(10) << " o o o o o o o o o o o o o o o o " << endl;
1061 cout << std::setw(10) << " o o o o o o oooo o o oooo o o oooo " << endl;
1062 cout << std::setw(10) << " o o o o o o o ooo o o o o " << endl;
1063 cout << std::setw(10) << " o o o o o o oo o oo ooo oo ++ ends." << endl;
1064 cout << std::setw(10) << " o " << endl;
1065
1066 return true;
1067}
bool FitLoc(int n, double track_params[], int single_fit)
int GetTrackNumber()
@ error
Definition Core.h:24

◆ ParGlo()

bool Millepede::ParGlo ( int index,
double param )

Definition at line 182 of file Millepede.cxx.

183{
184 if (index<0 || index>=nagb)
185 {return false;}
186 else
187 {pparm[index] = param;}
188
189 return true;
190}

◆ ParSig()

bool Millepede::ParSig ( int index,
double sigma )

Definition at line 209 of file Millepede.cxx.

210{
211 if (index>=nagb)
212 {return false;}
213 else
214 {psigm[index] = sigma;}
215
216 return true;
217}

Referenced by InitMille().

◆ SetTrackNumber()

void Millepede::SetTrackNumber ( int value)

Definition at line 1516 of file Millepede.cxx.

1516{m_track_number = value;}

Referenced by InitMille(), and MakeGlobalFit().

◆ ZerLoc()

bool Millepede::ZerLoc ( double dergb[],
double derlc[],
double dernl[] )

Definition at line 388 of file Millepede.cxx.

389{
390 for(int i=0; i<nalc; i++) {derlc[i] = 0.0;}
391 for(int i=0; i<nagb; i++) {dergb[i] = 0.0;}
392 for(int i=0; i<nagb; i++) {dernl[i] = 0.0;}
393
394 return true;
395}

The documentation for this class was generated from the following files: