BOSS 8.0.0
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 23 of file Millepede.cxx.

23{}

◆ ~Millepede()

Millepede::~Millepede ( )

Destructor.

Definition at line 27 of file Millepede.cxx.

27{}

Member Function Documentation

◆ ConstF()

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

Definition at line 241 of file Millepede.cxx.

241 {
242 if ( ncs >= mcs ) // mcs is defined in Millepede.h
243 {
244 cout << "Too many constraints !!!" << endl;
245 return false;
246 }
247
248 for ( int i = 0; i < nagb; i++ ) { adercs[ncs][i] = dercs[i]; }
249
250 arhs[ncs] = rhs;
251 ncs++;
252 cout << "Number of constraints increased to " << ncs << endl;
253 return true;
254}

◆ EquLoc()

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

Definition at line 269 of file Millepede.cxx.

270 {
271
272 if ( sigma <= 0.0 ) // If parameter is fixed, then no equation
273 {
274 for ( int i = 0; i < nalc; i++ ) { derlc[i] = 0.0; }
275 for ( int i = 0; i < nagb; i++ ) { dergb[i] = 0.0; }
276 return true;
277 }
278
279 // Serious equation, initialize parameters
280
281 double wght = 1.0 / ( sigma * sigma );
282 int nonzer = 0;
283 int ialc = -1;
284 int iblc = -1;
285 int iagb = -1;
286 int ibgb = -1;
287
288 for ( int i = 0; i < nalc; i++ ) // Retrieve local param interesting indices
289 {
290 if ( derlc[i] != 0.0 )
291 {
292 nonzer++;
293 if ( ialc == -1 ) ialc = i; // first index
294 iblc = i; // last index
295 }
296 }
297
298 if ( verbose_mode ) cout << ialc << " / " << iblc << endl;
299
300 for ( int i = 0; i < nagb; i++ ) // Idem for global parameters
301 {
302 if ( dergb[i] != 0.0 )
303 {
304 nonzer++;
305 if ( iagb == -1 ) iagb = i; // first index
306 ibgb = i; // last index
307 }
308 }
309
310 if ( verbose_mode ) cout << iagb << " / " << ibgb << endl;
311
312 indst.push_back( -1 );
313 arest.push_back( rmeas );
314 arenl.push_back( 0. );
315
316 for ( int i = ialc; i <= iblc; i++ )
317 {
318 if ( derlc[i] != 0.0 )
319 {
320 indst.push_back( i );
321 arest.push_back( derlc[i] );
322 arenl.push_back( 0.0 );
323 derlc[i] = 0.0;
324 }
325 }
326
327 indst.push_back( -1 );
328 arest.push_back( wght );
329 arenl.push_back( 0.0 );
330
331 for ( int i = iagb; i <= ibgb; i++ )
332 {
333 if ( dergb[i] != 0.0 )
334 {
335 indst.push_back( i );
336 arest.push_back( dergb[i] );
337 arenl.push_back( dernl[i] );
338 dergb[i] = 0.0;
339 }
340 }
341
342 if ( verbose_mode ) cout << "Out Equloc -- NST = " << arest.size() << endl;
343
344 return true;
345}
const bool verbose_mode
Definition Alignment.h:66

◆ FitLoc()

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

Definition at line 387 of file Millepede.cxx.

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

Referenced by MakeGlobalFit().

◆ GetTrackNumber()

int Millepede::GetTrackNumber ( )

Definition at line 1444 of file Millepede.cxx.

1444{ return m_track_number; }

Referenced by 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 43 of file Millepede.cxx.

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

◆ MakeGlobalFit()

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

Definition at line 788 of file Millepede.cxx.

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

◆ ParGlo()

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

Definition at line 169 of file Millepede.cxx.

169 {
170 if ( index < 0 || index >= nagb ) { return false; }
171 else { pparm[index] = param; }
172
173 return true;
174}

◆ ParSig()

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

Definition at line 192 of file Millepede.cxx.

192 {
193 if ( index >= nagb ) { return false; }
194 else { psigm[index] = sigma; }
195
196 return true;
197}

Referenced by InitMille().

◆ SetTrackNumber()

void Millepede::SetTrackNumber ( int value)

Definition at line 1445 of file Millepede.cxx.

1445{ m_track_number = value; }

Referenced by InitMille(), and MakeGlobalFit().

◆ ZerLoc()

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

Definition at line 358 of file Millepede.cxx.

358 {
359 for ( int i = 0; i < nalc; i++ ) { derlc[i] = 0.0; }
360 for ( int i = 0; i < nagb; i++ ) { dergb[i] = 0.0; }
361 for ( int i = 0; i < nagb; i++ ) { dernl[i] = 0.0; }
362
363 return true;
364}

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