CGEM BOSS 6.6.5.g
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 nlay, int nglo_on_lay, 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)
 
 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 19 of file Cgem/CgemAlignAlg/CgemAlignAlg-00-00-08/CgemAlignAlg/Millepede.h.

Constructor & Destructor Documentation

◆ Millepede() [1/2]

Millepede::Millepede ( )

Standard constructor.

Definition at line 25 of file Cgem/CgemAlignAlg/CgemAlignAlg-00-00-08/src/Millepede.cxx.

26{}

◆ ~Millepede() [1/2]

Millepede::~Millepede ( )

Destructor.

Definition at line 30 of file Cgem/CgemAlignAlg/CgemAlignAlg-00-00-08/src/Millepede.cxx.

30{}

◆ Millepede() [2/2]

Millepede::Millepede ( )

Standard constructor.

◆ ~Millepede() [2/2]

Millepede::~Millepede ( )

Destructor.

Member Function Documentation

◆ ConstF() [1/2]

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

Definition at line 275 of file Cgem/CgemAlignAlg/CgemAlignAlg-00-00-08/src/Millepede.cxx.

276{
277 if (ncs>=mcs) // mcs is defined in Millepede.h
278 {
279 cout << "Too many constraints !!!" << endl;
280 return false;
281 }
282
283 for (int i=0; i<nagb; i++) {adercs[ncs][i] = dercs[i];}
284
285 arhs[ncs] = rhs;
286 ncs++ ;
287 cout << "Number of constraints increased to " << ncs << endl;
288 return true;
289}

◆ ConstF() [2/2]

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

◆ EquLoc() [1/2]

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

Definition at line 305 of file Cgem/CgemAlignAlg/CgemAlignAlg-00-00-08/src/Millepede.cxx.

306{
307 //if (verbose_mode) cout << " sigma " << sigma << endl;
308
309 if (sigma<=0.0) // If parameter is fixed, then no equation
310 {
311 for (int i=0; i<nalc; i++)
312 {
313 derlc[i] = 0.0;
314 }
315 for (int i=0; i<nagb; i++)
316 {
317 dergb[i] = 0.0;
318 }
319 return true;
320 }
321
322 // Serious equation, initialize parameters
323
324 double wght = 1.0/(sigma*sigma);
325 int nonzer = 0;
326 int ialc = -1;
327 int iblc = -1;
328 int iagb = -1;
329 int ibgb = -1;
330
331 if (verbose_mode) cout<<"meas "<<rmeas<<endl;
332 for (int i=0; i<nalc; i++) // Retrieve local param interesting indices
333 {
334 if (verbose_mode) cout<<"i = "<<i<<", derlc = "<<derlc[i]<<endl;
335 if (derlc[i]!=0.0)
336 {
337 nonzer++;
338 if (ialc == -1) ialc=i; // first index
339 iblc = i; // last index
340 }
341 }
342
343 if (verbose_mode) cout << ialc << " / " << iblc << endl;
344
345 if (verbose_mode) cout<<"weight "<<wght<<endl;
346 for (int i=0; i<nagb; i++) // Idem for global parameters
347 {
348 if (verbose_mode) cout<<"i = "<<i<<", dergb = "<<dergb[i]<<endl;
349 if (dergb[i]!=0.0)
350 {
351 nonzer++;
352 if (iagb == -1) iagb=i; // first index
353 ibgb = i; // last index
354 }
355 }
356
357 if (verbose_mode) cout << iagb << " / " << ibgb << endl;
358
359 indst.push_back(-1);
360 arest.push_back(rmeas);
361 arenl.push_back(0.);
362
363 for (int i=ialc; i<=iblc; i++)
364 {
365 if (derlc[i]!=0.0)
366 {
367 indst.push_back(i);
368 arest.push_back(derlc[i]);
369 arenl.push_back(0.0);
370 derlc[i] = 0.0;
371 }
372 }
373
374 indst.push_back(-1);
375 arest.push_back(wght);
376 arenl.push_back(0.0);
377
378 for (int i=iagb; i<=ibgb; i++)
379 {
380 if (dergb[i]!=0.0)
381 {
382 indst.push_back(i);
383 arest.push_back(dergb[i]);
384 arenl.push_back(dernl[i]);
385 dergb[i] = 0.0;
386 }
387 }
388
389 if (verbose_mode) cout << "Out Equloc -- NST = " << arest.size() << endl;
390
391 return true;
392}

◆ EquLoc() [2/2]

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

◆ FitLoc() [1/2]

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

Definition at line 435 of file Cgem/CgemAlignAlg/CgemAlignAlg-00-00-08/src/Millepede.cxx.

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

Referenced by MakeGlobalFit().

◆ FitLoc() [2/2]

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

◆ GetTrackNumber() [1/2]

int Millepede::GetTrackNumber ( )

Definition at line 1591 of file Cgem/CgemAlignAlg/CgemAlignAlg-00-00-08/src/Millepede.cxx.

1591{return m_track_number;}

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

◆ GetTrackNumber() [2/2]

int Millepede::GetTrackNumber ( )

◆ initialize() [1/2]

bool Millepede::initialize ( )

Initialization.

◆ initialize() [2/2]

bool Millepede::initialize ( )

Initialization.

◆ InitMille() [1/2]

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 Mdc/MdcAlignAlg/MdcAlignAlg-00-01-04/src/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}

◆ InitMille() [2/2]

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

Definition at line 47 of file Cgem/CgemAlignAlg/CgemAlignAlg-00-00-08/src/Millepede.cxx.

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

◆ MakeGlobalFit() [1/2]

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

Definition at line 851 of file Cgem/CgemAlignAlg/CgemAlignAlg-00-00-08/src/Millepede.cxx.

852{
853 int i, j, nf, nvar;
854 int itelim = 0;
855
856 int nstillgood;
857
858 double sum;
859
860 double step[150];
861
862 double trackpars[2*mlocal];
863
864 int ntotal_start, ntotal;
865
866 cout << "..... Making global fit ....." << endl;
867
868 ntotal_start = Millepede::GetTrackNumber();
869
870 std::vector<double> track_slopes; // What is track_slopes? - By Guoaq-19-10-10
871
872 track_slopes.resize(2*ntotal_start);
873
874 for (i=0; i<2*ntotal_start; i++) track_slopes[i] = 0.;
875
876 if (itert <= 1) itelim=10; // Max number of iterations how to optimize this value - By Guoaq-19-09-26
877
878 cout<<"itert, itelim = "<<itert<<", "<<itelim<<endl;
879
880 while (itert < itelim) // Iteration for the final loop
881 {
882 if (debug_mode) cout << "ITERATION --> " << itert << endl;
883
884 ntotal = Millepede::GetTrackNumber();
885 cout << "...using " << ntotal << " tracks..." << endl;
886
887 // Start by saving the diagonal elements
888
889 for (i=0; i<nagb; i++) {diag[i] = cgmat[i][i];}
890
891 // Then we retrieve the different constraints: fixed parameter or global equation
892
893 nf = 0; // First look at the fixed global params
894
895 for (i=0; i<nagb; i++)
896 {
897 if (psigm[i] <= 0.0) // fixed global param
898 {
899 nf++;
900
901 for (j=0; j<nagb; j++)
902 {
903 cgmat[i][j] = 0.0; // Reset row and column
904 cgmat[j][i] = 0.0;
905 }
906 }
907 else if (psigm[i] > 0.0)
908 {
909 cgmat[i][i] += 1.0/(psigm[i]*psigm[i]);
910 }
911 }
912
913 nvar = nagb; // Current number of equations
914 if (debug_mode) cout << "Number of constraint equations : " << ncs << endl;
915
916 if (ncs > 0) // Then the constraint equation
917 {
918 for (i=0; i<ncs; i++)
919 {
920 sum = arhs[i];
921 for (j=0; j<nagb; j++)
922 {
923 cgmat[nvar][j] = float(ntotal)*adercs[i][j];
924 cgmat[j][nvar] = float(ntotal)*adercs[i][j];
925 sum -= adercs[i][j]*(pparm[j]+dparm[j]);
926
927 }
928
929 cgmat[nvar][nvar] = 0.0;
930 bgvec[nvar] = float(ntotal)*sum;
931 nvar++;
932 }
933 }
934
935
936 // Intended to compute the final global chisquare
937
938 double final_cor = 0.0;
939
940 if (itert > 1)
941 {
942 for (j=0; j<nagb; j++)
943 {
944 for (i=0; i<nagb; i++)
945 {
946 if (psigm[i] > 0.0)
947 {
948 final_cor += step[j]*cgmat[j][i]*step[i];
949 if (i == j) final_cor -= step[i]*step[i]/(psigm[i]*psigm[i]);
950 }
951 }
952 }
953 }
954
955 cout << " Final coeff is " << final_cor << endl;
956 cout << " Final NDOFs = " << nagb << endl;
957
958 // The final matrix inversion
959
960 nrank = Millepede::SpmInv(cgmat, bgvec, nvar, scdiag, scflag);
961
962 for (i=0; i<nagb; i++)
963 {
964 dparm[i] += bgvec[i]; // Update global parameters values (for iterations)
965 if (verbose_mode) cout << "dparm[" << i << "] = " << dparm[i] << endl;
966 if (verbose_mode) cout << "cgmat[" << i << "][" << i << "] = " << cgmat[i][i] << endl;
967 if (verbose_mode) cout << "err = " << sqrt(fabs(cgmat[i][i])) << endl;
968
969 step[i] = bgvec[i];
970
971 if (itert == 1) error[i] = cgmat[i][i]; // Unfitted error
972 }
973
974 cout << "" << endl;
975 cout << "The rank defect of the symmetric " << nvar << " by " << nvar
976 << " matrix is " << nvar-nf-nrank << " (bad if non 0)" << endl;
977
978 if (itert == 0) break;
979 itert++;
980
981 cout << "" << endl;
982 cout << "Total : " << loctot << " local fits, "
983 << locrej << " rejected." << endl;
984
985 // Reinitialize parameters for iteration
986
987 loctot = 0;
988 locrej = 0;
989
990 if (cfactr != cfactref && sqrt(cfactr) > 1.2*cfactref)
991 {
992 cfactr = sqrt(cfactr);
993 }
994 else
995 {
996 cfactr = cfactref;
997 // itert = itelim;
998 }
999
1000 if (itert == itelim) break; // End of story
1001
1002 cout << "Iteration " << itert << " with cut factor " << cfactr << endl;
1003
1004 // Reset global variables
1005
1006 for (i=0; i<nvar; i++)
1007 {
1008 bgvec[i] = 0.0;
1009 for (j=0; j<nvar; j++)
1010 {
1011 cgmat[i][j] = 0.0;
1012 }
1013 }
1014
1015 //
1016 // We start a new iteration
1017 //
1018
1019 // First we read the stores for retrieving the local params
1020
1021 nstillgood = 0;
1022
1023 for (i=0; i<ntotal_start; i++)
1024 {
1025 int rank_i = 0;
1026 int rank_f = 0;
1027
1028 (i>0) ? rank_i = abs(storeplace[i-1]) : rank_i = 0;
1029 rank_f = storeplace[i];
1030
1031 if (verbose_mode) cout << "Track " << i << " : " << endl;
1032 if (verbose_mode) cout << "Starts at " << rank_i << endl;
1033 if (verbose_mode) cout << "Ends at " << rank_f << endl;
1034
1035 if (rank_f >= 0) // Fit is still OK
1036 {
1037
1038 if (itert > 3)
1039 {
1040 indst.clear();
1041 arest.clear();
1042
1043 for (j=rank_i; j<rank_f; j++)
1044 {
1045 indst.push_back(storeind[j]);
1046
1047 if (storenl[j] == 0) arest.push_back(storeare[j]);
1048 if (storenl[j] == 1) arest.push_back(track_slopes[2*i]*storeare[j]);
1049 if (storenl[j] == 2) arest.push_back(track_slopes[2*i+1]*storeare[j]);
1050 }
1051
1052 for (j=0; j<2*nalc; j++) {trackpars[j] = 0.;}
1053
1054 Millepede::FitLoc(i,trackpars,1);
1055
1056 track_slopes[2*i] = trackpars[2];
1057 track_slopes[2*i+1] = trackpars[6];
1058 }
1059
1060 if (verbose_mode) cout << "after inters>3 " << endl;
1061
1062 indst.clear();
1063 arest.clear();
1064
1065
1066 if (verbose_mode) cout << "rank_f is "<< rank_f << endl;
1067 for (j=rank_i; j<rank_f; j++)
1068 {
1069 if (verbose_mode) cout << "storeind "<<j<<" is "<<storeind[j] << endl;
1070 if (verbose_mode) cout << "storearea "<<j<<" is "<<storeare[j] << endl;
1071 if (verbose_mode) cout << "storenl "<<j<<" is "<<storenl[j] << endl;
1072
1073 indst.push_back(storeind[j]);
1074 if (verbose_mode) cout << "after 1st push_back " << endl;
1075 if (storenl[j] == 0) arest.push_back(storeare[j]);
1076 if (verbose_mode) cout << "after 2nd push_back " << endl;
1077 if (storenl[j] == 1) arest.push_back(track_slopes[2*i]*storeare[j]);
1078 if (verbose_mode) cout << "after 3rd push_back " << endl;
1079 if (storenl[j] == 2) arest.push_back(track_slopes[2*i+1]*storeare[j]);
1080 }
1081
1082 if (verbose_mode) cout << "after push_back arest " << endl;
1083
1084 for (j=0; j<2*nalc; j++) {trackpars[j] = 0.;}
1085
1086 bool sc = Millepede::FitLoc(i,trackpars,0);
1087
1088 if (verbose_mode) cout << "after invork FitLoc " << endl;
1089
1090 (sc)
1091 ? nstillgood++
1092 : storeplace[i] = -rank_f;
1093 }
1094 } // End of loop on fits
1095
1096 Millepede::SetTrackNumber(nstillgood);
1097
1098 } // End of iteration loop
1099
1100 // record the track number fit parameters and error
1101
1102 Millepede::PrtGlo(); // Print the final results
1103
1104 for (j=0; j<nagb; j++)
1105 {
1106 par[j] = dparm[j];
1107 dparm[j] = 0.;
1108 pull[j] = par[j]/sqrt(psigm[j]*psigm[j]-cgmat[j][j]);
1109 error[j] = sqrt(fabs(cgmat[j][j]));
1110 }
1111
1112 if(record_err)
1113 {
1114 ofstream ferr("merr.csv",ios::app);
1115 ferr<<ntotal<<", "<< par[0]<<", "<< error[0]<<", "<<par[1]<<", "<< error[1]<<", "<<par[2]<<", "<< error[2]<<", "<<par[3]<<", "<< error[3]<<", "<<par[4]<<", "<< error[4]<<", "<<par[5]<<", "<< error[5]<<", "<<par[6]<<", "<< error[6]<<", "<<par[7] <<", "<< error[7]<<", "<<par[8]<<", "<< error[8]<<", "<<par[9]<<", "<< error[9]<<", "<<par[10]<<", "<< error[10]<<", "<<par[11]<<", "<< error[11]<< endl;
1116 ferr.close();
1117 }
1118
1119 cout << std::setw(10) << " " << endl;
1120 cout << std::setw(10) << " * o o o " << endl;
1121 cout << std::setw(10) << " o o o " << endl;
1122 cout << std::setw(10) << " o ooooo o o o oo ooo oo ooo oo " << endl;
1123 cout << std::setw(10) << " o o o o o o o o o o o o o o o o " << endl;
1124 cout << std::setw(10) << " o o o o o o oooo o o oooo o o oooo " << endl;
1125 cout << std::setw(10) << " o o o o o o o ooo o o o o " << endl;
1126 cout << std::setw(10) << " o o o o o o oo o oo ooo oo ++ ends." << endl;
1127 cout << std::setw(10) << " o " << endl;
1128
1129 return true;
1130}
double abs(const EvtComplex &c)
Definition: EvtComplex.hh:212
bool FitLoc(int n, double track_params[], int single_fit)
@ error
Definition: Core.h:24

◆ MakeGlobalFit() [2/2]

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

◆ ParGlo() [1/2]

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

Definition at line 194 of file Cgem/CgemAlignAlg/CgemAlignAlg-00-00-08/src/Millepede.cxx.

195{
196 if (index<0 || index>=nagb)
197 {return false;}
198 else
199 {pparm[index] = param;}
200
201 return true;
202}

◆ ParGlo() [2/2]

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

◆ ParSig() [1/2]

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

Definition at line 221 of file Cgem/CgemAlignAlg/CgemAlignAlg-00-00-08/src/Millepede.cxx.

222{
223 if (index>=nagb)
224 {return false;}
225 else
226 {psigm[index] = sigma;}
227
228 return true;
229}

Referenced by InitMille().

◆ ParSig() [2/2]

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

◆ SetTrackNumber() [1/2]

void Millepede::SetTrackNumber ( int  value)

Definition at line 1592 of file Cgem/CgemAlignAlg/CgemAlignAlg-00-00-08/src/Millepede.cxx.

1592{m_track_number = value;}

Referenced by InitMille(), and MakeGlobalFit().

◆ SetTrackNumber() [2/2]

void Millepede::SetTrackNumber ( int  value)

◆ ZerLoc() [1/2]

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

Definition at line 405 of file Cgem/CgemAlignAlg/CgemAlignAlg-00-00-08/src/Millepede.cxx.

406{
407 for(int i=0; i<nalc; i++) {derlc[i] = 0.0;}
408 for(int i=0; i<nagb; i++) {dergb[i] = 0.0;}
409 for(int i=0; i<nagb; i++) {dernl[i] = 0.0;}
410
411 return true;
412}

◆ ZerLoc() [2/2]

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

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