ATLAS Offline Software
RobTest.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 #include <cmath>
9 #include <iostream>
10 #include <vector>
11 
12 namespace Trk {
13 
14 void robtest(VKVertex * vk, int ifl, int nIteration/*=10*/)
15 {
16  long int i, j, k, kk, it;
17  double rob, res, c[5], darg, absX, roba[5];
18 
19 /* ------------------------------------------------------------ */
20 /* Robustification procedure for weight matrix */
21 /* IROB = 0 - Standard chi^2 */
22 /* = 1 - Geman-McClure function */
23 /* = 2 - Welch function */
24 /* = 3 - Cauchy function */
25 /* = 4 - L1-L2 function */
26 /* = 5 - Fair function */
27 /* = 6 - Huber function */
28 /* = 7 - Modified Huber function */
29 /* (1,2,3) - Zero outliers */
30 /* (4,5,6,7) - Downweight outliers */
31 /* Author: V.Kostyukhin */
32 /* ------------------------------------------------------------ */
33 
34  int NTRK = vk->TrackList.size();
35 
36  long int irob = vk->vk_fitterControl->vk_forcft.irob;
37  double Scl = vk->vk_fitterControl->vk_forcft.RobustScale; //Tuning constant
38  double C; // Breakdown constant
39 
40  if(!vk->vk_fitterControl->m_frozenVersionForBTagging)Scl *= (1.+exp(3.-nIteration)); //Annealing
41 
42  if ( ifl == 0) { /* FILLING OF EIGENVALUES AND VECTORS */
43  for (it = 0; it < NTRK ; ++it) { /* RESTORE MATRIX */
44  VKTrack *trk=vk->TrackList[it].get();
45  if(trk->Id < 0) continue; // Not a real track
46  vkGetEigVect(trk->WgtM, trk->e ,&(trk->v[0][0]), 5);
47  }
48  return;
49  }
50 /* -- */
51  double halfPi=M_PI/2.;
52  for (it = 0; it < NTRK; ++it) {
53  VKTrack *trk=vk->TrackList[it].get();
54  if(trk->Id < 0) continue; // Not a real track
55  c[0]=c[1]=c[2]=c[3]=c[4]=0.;
56  for( k = 0; k < 5; k++){
57  c[0] += trk->rmnd[k] * trk->v[0][k];
58  c[1] += trk->rmnd[k] * trk->v[1][k];
59  c[2] += trk->rmnd[k] * trk->v[2][k];
60  c[3] += trk->rmnd[k] * trk->v[3][k];
61  c[4] += trk->rmnd[k] * trk->v[4][k];
62  }
63  for (k = 0; k < 5; ++k) {
64  darg = c[k]*c[k]*trk->e[k];
65  if(darg < 1.e-10) darg = 1.e-10;
66  absX = sqrt(darg); /* Abs(X) == sqrt(X)*/
67  rob = 1.; C=1;
68  if(irob == 1)C = 1.58*Scl; /* Geman-McClure Standard =1 but c^2=2.5 is better(Gem.McC) */
69  if(irob == 2)C = 2.9846*Scl; /* Welch def c^2=2.9846^2 */
70  if(irob == 3)C = 2.3849*Scl; /* Cauchy def 2.385^2=5.7 */
71  if(irob == 4)C = 1.; /* L1-L2 no tuning*/
72  if(irob == 5)C = 1.3998*Scl; /* Fair (def=1.3998)*/
73  if(irob == 6)C = 1.345 *Scl; /* Huber (def=1.345)*/
74  if(irob == 7)C = 1.2107 *Scl; /* Modified Huber (def=1.2107)*/
75 /* Functionals here are divided by (X^2/2)!!!*/
76  double C2=C*C;
77  if(irob == 1)rob = 1. / (darg/C2 + 1.); /* Geman-McClure */
78  if(irob == 2)rob = C2*(1. - exp(-darg/C2) )/darg; /* Welch */
79  if(irob == 3)rob = C2*log(darg/C2 + 1.)/darg; /* Cauchy */
80  if(irob == 4)rob = 4.*(sqrt(darg / 2. + 1.) - 1.)/darg; /* L1-L2 */
81  if(irob == 5)rob = 2.*C2*(absX/C - log(absX/C + 1.))/darg; /* Fair */
82  if(irob == 6)rob = C>absX ? 1. : (2*C/absX - C*C/darg) ; /* Huber */
83  if(irob == 7)rob = halfPi>(absX/C) ? 2*C*C*(1-cos(absX/C))/darg :
84  2*(C*absX+C*C*(1.-halfPi))/darg; /* Modified Huber */
85  roba[k] = rob;
86  if(rob>0.99)roba[k] = 1.; //To improve precision
87  }
88  for (i = 0; i < 5; ++i) if(roba[i]<1.e-3)roba[i]=1.e-3;
89  kk = 0;
90  for (i = 0; i < 5; ++i) {
91  for (j = 0; j <= i; ++j) {
92  res = 0.;
93  for (k = 0; k < 5; ++k) {
94  res += trk->v[k][i] * trk->e[k] * trk->v[k][j]*roba[k];
95  }
96  trk->WgtM[kk]=res;
97  kk++;
98  }
99  }
100  vk->vk_fitterControl->vk_forcft.robres[it] = roba[0] * roba[1] * roba[2] * roba[3] * roba[4];
101  if(vk->vk_fitterControl->vk_forcft.robres[it]>1.)vk->vk_fitterControl->vk_forcft.robres[it]=1.;
102  }
103 }
104 
105 
106 } /* End of namespace */
107 
108 
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
Trk::VKTrack::WgtM
double WgtM[15]
Definition: TrkVKalVrtCoreBase.h:87
skel.it
it
Definition: skel.GENtoEVGEN.py:396
M_PI
#define M_PI
Definition: ActiveFraction.h:11
Trk::VKTrack::Id
long int Id
Definition: TrkVKalVrtCoreBase.h:72
Trk::VKTrack
Definition: TrkVKalVrtCoreBase.h:64
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
TrkVKalVrtCoreBase.h
Trk::VKVertex::TrackList
std::vector< std::unique_ptr< VKTrack > > TrackList
Definition: TrkVKalVrtCoreBase.h:167
python.changerun.kk
list kk
Definition: changerun.py:41
lumiFormat.i
int i
Definition: lumiFormat.py:85
Trk::VKTrack::rmnd
double rmnd[5]
Definition: TrkVKalVrtCoreBase.h:91
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
Matrix.h
Trk::VKTrack::e
double e[5]
Definition: TrkVKalVrtCoreBase.h:92
Trk::vkGetEigVect
void vkGetEigVect(const double ci[], double d[], double vect[], int n)
Definition: Tracking/TrkVertexFitter/TrkVKalVrtCore/src/Matrix.cxx:847
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::VKVertex::vk_fitterControl
std::unique_ptr< VKalVrtControl > vk_fitterControl
Definition: TrkVKalVrtCoreBase.h:194
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
Trk::VKVertex
Definition: TrkVKalVrtCoreBase.h:128
Trk::robtest
void robtest(VKVertex *vk, int ifl, int nIteration)
Definition: RobTest.cxx:14
Trk::VKTrack::v
double v[5][5]
Definition: TrkVKalVrtCoreBase.h:93
python.compressB64.c
def c
Definition: compressB64.py:93
fitman.k
k
Definition: fitman.py:528
RobTest.h