StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AliHLTTPCCANeighboursCleaner.cxx
1 // @(#) $Id: AliHLTTPCCANeighboursCleaner.cxx,v 1.2 2016/07/15 14:43:33 fisyak Exp $
2 // **************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project *
4 // ALICE Experiment at CERN, All rights reserved. *
5 // *
6 // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
7 // Ivan Kisel <kisel@kip.uni-heidelberg.de> *
8 // for The ALICE HLT Project. *
9 // *
10 // Developed by: Igor Kulakov <I.Kulakov@gsi.de> *
11 // Maksym Zyzak <M.Zyzak@gsi.de> *
12 // *
13 // Permission to use, copy, modify and distribute this software and its *
14 // documentation strictly for non-commercial purposes is hereby granted *
15 // without fee, provided that the above copyright notice appears in all *
16 // copies and that both the copyright notice and this permission notice *
17 // appear in the supporting documentation. The authors make no claims *
18 // about the suitability of this software for any purpose. It is *
19 // provided "as is" without express or implied warranty. *
20 // *
21 //***************************************************************************
22 
23 
24 #include "AliHLTTPCCANeighboursCleaner.h"
25 #include "AliHLTTPCCAMath.h"
26 #include "AliHLTTPCCATracker.h"
27 
28 // *
29 // * kill link to the neighbour if the neighbour is not pointed to the hit
30 // *
31 
32 void AliHLTTPCCANeighboursCleaner::run( const int numberOfRows, SliceData &data, const AliHLTTPCCAParam &param )
33 {
34  sfloat_v X,Y,Z,Xup,Yup,Zup,Xdown,Ydown,Zdown, X4,Y4,Z4;
35  sfloat_v Yx1, Yx2, Yxx1, Yxx2, Yxxx, Zx1, Zx2, Zxx1, Zxx2, Zxxx, iX;
36  const short_v minusOne(-1);
37 
38  const int rowStep = AliHLTTPCCAParameters::RowStep;
39  const int beginRowIndex = rowStep;
40  const int endRowIndex = numberOfRows - rowStep;
41  for ( int rowIndex = beginRowIndex; rowIndex < endRowIndex; ++rowIndex ) {
42  const AliHLTTPCCARow &row = data.Row( rowIndex );
43  const AliHLTTPCCARow &rowUp = data.Row( rowIndex + rowStep );
44  const AliHLTTPCCARow &rowDown = data.Row( rowIndex - rowStep );
45  const int numberOfHits = row.NHits();
46 
47  // - look at up link, if it's valid but the down link in the row above doesn't link to us remove
48  // the link
49  // - look at down link, if it's valid but the up link in the row below doesn't link to us remove
50  // the link
51  for ( int hitIndex = 0; hitIndex < numberOfHits; hitIndex += short_v::Size ) {
52 
53  const ushort_v hitIndexes = ushort_v( Vc::IndexesFromZero ) + hitIndex;
54  short_m validHitsMask = hitIndexes < numberOfHits;
55  assert( ( validHitsMask && ((hitIndexes >= 0 ) && (hitIndexes < row.NHits() )) ) == validHitsMask );
56  validHitsMask &= ( short_v(data.HitDataIsUsed( row ), hitIndexes, validHitsMask ) == short_v( Vc::Zero ) ); // not-used hits can be connected only with not-used, so only one check is needed
57 
58  // collect information
59  // up part
60  assert( ( validHitsMask && ((hitIndexes >= 0 ) && (hitIndexes < row.NHits() )) ) == validHitsMask );
61  const short_v up = short_v(data.HitLinkUpData( row ), hitIndexes, validHitsMask );
62  const ushort_v upIndexes = up.staticCast<ushort_v>();
63  assert ( (validHitsMask && (up >= minusOne) ) == validHitsMask );
64  short_m upMask = validHitsMask && up >= short_v( Vc::Zero );
65  assert( ( upMask && ((upIndexes >= 0 ) && (upIndexes < rowUp.NHits() )) ) == upMask );
66  short_v downFromUp = short_v(data.HitLinkDownData( rowUp ), upIndexes, upMask );
67  // down part
68  const short_v dn = short_v(data.HitLinkDownData( row ), hitIndexes, validHitsMask );
69  assert ( ( validHitsMask && (dn >= minusOne) ) == validHitsMask );
70  const ushort_v downIndexes = dn.staticCast<ushort_v>();
71  short_m dnMask = validHitsMask && dn >= short_v( Vc::Zero );
72  assert( ( dnMask && ((downIndexes >= 0 ) && (downIndexes < rowDown.NHits() )) ) == dnMask );
73  short_v upFromDown = short_v(data.HitLinkUpData( rowDown ), downIndexes, dnMask );
74 
75  // -- make clean --
76 
77  // check if some one-way links can be good
78 #define USE_EDGE_HITS // use edge links, which are not reciprocall
79 #ifdef USE_EDGE_HITS
80 // std::cout << "downFromUp " << downFromUp << " upFromDown " << upFromDown << " validHitsMask " << validHitsMask << " dnMask " << dnMask << " upMask " << upMask << std::endl; // IKu debug
81  upMask &= (downFromUp == -1) && (upFromDown == static_cast<short_v>(hitIndexes)); // have mutual link only downwards. is up-link good?
82  dnMask &= (upFromDown == -1) && (downFromUp == static_cast<short_v>(hitIndexes)); // have mutual link only upwards. is down-link good?
83 
84  dnMask &= short_m(rowIndex + 2*rowStep < numberOfRows); // will use up & upup hits for check. If no one there then have to delete link
85  upMask &= short_m(rowIndex - 2*rowStep >= 0);
86  upMask &= dn >= short_v( Vc::Zero );
87  dnMask &= up >= short_v( Vc::Zero );
88 
89  // #define SELECT_EDGE_HITS // select edge links before use. otherwise all not reciprocall links will be used
90 #ifdef SELECT_EDGE_HITS
91  const short_m upOrDnMask = upMask || dnMask;
92  if(!upOrDnMask.isEmpty()) // TODO do we need edge links - investigate
93  {
94  X = data.RowX( rowIndex );
95  assert( ( upOrDnMask && ((hitIndexes >= 0 ) && (hitIndexes < row.NHits() )) ) == upOrDnMask );
96  Y.gather( data.HitDataY( row ), hitIndexes, static_cast<sfloat_m>(upOrDnMask) );//HitDataY( row, hitIndex );
97  Z.gather( data.HitDataZ( row ), hitIndexes, static_cast<sfloat_m>(upOrDnMask) );// data.HitDataZ( row, hitIndex );
98 
99  if(!dnMask.isEmpty())
100  {
101  Xdown = data.RowX( rowIndex - rowStep );
102  assert( ( dnMask && ((downIndexes >= 0 ) && (downIndexes < rowDown.NHits() )) ) == dnMask );
103  Ydown.gather( data.HitDataY( rowDown ), downIndexes, static_cast<sfloat_m>(dnMask) );
104  Zdown.gather( data.HitDataZ( rowDown ), downIndexes, static_cast<sfloat_m>(dnMask) );
105 
106  const AliHLTTPCCARow &rowUpUp = data.Row( rowIndex + 2*rowStep );
107  assert( ( dnMask && ((upIndexes >= 0 ) && (upIndexes < rowUp.NHits() )) ) == dnMask );
108  const short_v upup = short_v(data.HitLinkUpData( rowUp ), upIndexes, dnMask );
109 
110  dnMask &= upup >= short_v( Vc::Zero ); // can't check, so can't save any other link
111 // short_v downFromUpUp = short_v(data.HitLinkDownData( rowUpUp ), static_cast<ushort_v>(upupIndexes), dnMask );
112 // dnMask &= downFromUpUp != -1;
113 
114  X4 = data.RowX( rowIndex + 2*rowStep );
115  const ushort_v upupIndexes = upup.staticCast<ushort_v>();
116  ASSERT( ( dnMask && (upupIndexes < rowUpUp.NHits() ) ) == dnMask,
117  " dnMask= " << dnMask << " upupIndexes= " << upupIndexes << " rowUpUp.NHits()= "<< rowUpUp.NHits() );
118  Y4.gather( data.HitDataY( rowUpUp ), upupIndexes, static_cast<sfloat_m>(dnMask) );
119  Z4.gather( data.HitDataZ( rowUpUp ), upupIndexes, static_cast<sfloat_m>(dnMask) );
120 
121  iX = Vc::One/(X - X4);
122  Yx1 = (Y - Y4)*iX;
123  Yx2 = Y - X*Yx1;
124  Yxx2 = Yx2 + Yx1*Xdown;
125  Zx1 = (Z - Z4)*iX;
126  Zx2 = Z - X*Zx1;
127  Zxx2 = Zx2 + Zx1*Xdown;
128 
129  sfloat_v err2Y, err2Z;
130  param.GetClusterErrors2(upIndexes,Xdown,Ydown,Zdown,err2Y, err2Z);
131 
132  // sfloat_v ch = CAMath::Abs((Yxx2 - Ydown)/CAMath::Sqrt(err2Y))+CAMath::Abs((Zxx2 - Zdown)/CAMath::Sqrt(err2Z));
133  // upMask &= static_cast<short_m>(ch < 50.f);
134  dnMask &= static_cast<short_m>(CAMath::Abs((Yxx2 - Ydown)*CAMath::RSqrt(err2Y)) < 50.f);
135 // dnMask &= static_cast<short_m>(CAMath::Abs((Zxx2 - Zdown)/CAMath::Sqrt(err2Z)) < 80.f);
136  }
137 
138  if(!upMask.isEmpty())
139  {
140  Xup = data.RowX( rowIndex + rowStep );
141  assert( ( upMask && ((upIndexes >= 0 ) && (upIndexes < rowUp.NHits() )) ) == upMask );
142  Yup.gather( data.HitDataY( rowUp ), upIndexes, static_cast<sfloat_m>(upMask) );
143  Zup.gather( data.HitDataZ( rowUp ), upIndexes, static_cast<sfloat_m>(upMask) );
144 
145  const AliHLTTPCCARow &rowDownDown = data.Row( rowIndex - 2*rowStep );
146  assert( ( upMask && ((downIndexes >= 0 ) && (downIndexes < rowDown.NHits() )) ) == upMask );
147  const short_v downdown = short_v(data.HitLinkDownData( rowDown ), downIndexes, upMask );
148  upMask &= downdown >= short_v( Vc::Zero ); // can't check, so can't save any other link
149 // short_v upFromDownDown = short_v(data.HitLinkUpData( rowDownDown ), static_cast<ushort_v>(downdownIndexes), upMask );
150 // upMask &= upFromDownDown != -1;
151 
152  ASSERT( ( upMask && (downdown >= 0 ) && (downdown < rowDownDown.NHits()) ) == upMask,
153  " upMask= " << upMask << " dn= " << dn << " downdown= " << downdown << " row= " << rowIndex << " rowDownDown.NHits= " << rowDownDown.NHits());
154  X4 = data.RowX( rowIndex - 2*rowStep );
155  const ushort_v downdownIndexes = downdown.staticCast<ushort_v>();
156  Y4.gather( data.HitDataY( rowDownDown ), downdownIndexes, static_cast<sfloat_m>(upMask) );
157  Z4.gather( data.HitDataZ( rowDownDown ), downdownIndexes, static_cast<sfloat_m>(upMask) );
158 
159  iX = Vc::One/(X - X4);
160  Yx1 = (Y - Y4)*iX;
161  Yx2 = Y - X*Yx1;
162  Yxx2 = Yx2 + Yx1*Xup;
163  Zx1 = (Z - Z4)*iX;
164  Zx2 = Z - X*Zx1;
165  Zxx2 = Zx2 + Zx1*Xup;
166 
167  sfloat_v err2Y, err2Z;
168  param.GetClusterErrors2(upIndexes,Xup,Yup,Zup,err2Y, err2Z);
169 
170  //std::cout << upMask << " "<<CAMath::Abs((Yxx2 - Yup)/CAMath::Sqrt(err2Y))<< " " << (CAMath::Abs((Yxx2 - Yup)/CAMath::Sqrt(err2Y))+CAMath::Abs((Zxx2 - Zup)/CAMath::Sqrt(err2Z)))<<std::endl;
171  const sfloat_v ch = CAMath::Abs((Yxx2 - Yup)*CAMath::RSqrt(err2Y));
172  upMask &= static_cast<short_m>(ch < 50.f);
173 // upMask &= static_cast<short_m>(CAMath::Abs((Yxx2 - Yup)/CAMath::Sqrt(err2Y)) < 50.f);
174 // upMask &= static_cast<short_m>(CAMath::Abs((Zxx2 - Zup)/CAMath::Sqrt(err2Z)) < 80.f);
175 // std::cout << upMask << " "<<std::endl;
176 
177  // Zx1 = (Zdown - Z4)/(Xdown - X4);
178  // Zx2 = (Z - Zdown)/(X - Xdown);
179  // Zxx2 = (Zx1 - Zx2)*2*iX;
180  }
181  } // if(!dnMask.isEmpty() || !upMask.isEmpty())
182 #else // SELECT_EDGE_HITS
183  UNUSED_PARAM1( param );
184 #endif // SELECT_EDGE_HITS
185 
186  assert( ( upMask && ((upIndexes >= 0 ) && (upIndexes < rowUp.NHits() )) ) == upMask );
187  assert( ( dnMask && ((downIndexes >= 0 ) && (downIndexes < rowDown.NHits() )) ) == dnMask );
188  // make from good one-way links mutual links
189  downFromUp( upMask ) = static_cast<short_v>(hitIndexes);
190  upFromDown( dnMask ) = static_cast<short_v>(hitIndexes);
191  data.SetHitLinkDownData( rowUp, upIndexes, downFromUp, upMask );
192  data.SetHitLinkUpData( rowDown, downIndexes, upFromDown, dnMask );
193  // data.SetHitLinkDownData( rowUp, upIndexes, static_cast<short_v>(hitIndexes), upMask );
194  // data.SetHitLinkUpData( rowDown, downIndexes, static_cast<short_v>(hitIndexes), dnMask );
195 #endif // USE_EDGE_HITS
196  // delete one-way links (all other one-way links)
197  const short_m badUpMask = validHitsMask && (downFromUp != static_cast<short_v>(hitIndexes));
198 
199  assert( ( badUpMask && ((hitIndexes >= 0 ) && (hitIndexes < row.NHits() )) ) == badUpMask );
200  data.SetHitLinkUpData( row, hitIndexes, minusOne, badUpMask );
201 
202  const short_m badDnMask = validHitsMask && (upFromDown != static_cast<short_v>(hitIndexes));
203  assert( ( badDnMask && ((hitIndexes >= 0 ) && (hitIndexes < row.NHits() )) ) == badDnMask );
204  data.SetHitLinkDownData( row, hitIndexes, minusOne, badDnMask );
205  } // for iHit
206  } // for iRow
207 }
const AliHLTTPCCARow & Row(int rowIndex) const
void GetClusterErrors2(int iRow, const AliHLTTPCCATrackParam &t, float &Err2Y, float &Err2Z) const
mvz start 20.01.2010