StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AliHLTTPCCAHitArea.cxx
1 //***************************************************************************
2 // This file is property of and copyright by the ALICE HLT Project *
3 // ALICE Experiment at CERN, All rights reserved. *
4 // *
5 // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
6 // Ivan Kisel <kisel@kip.uni-heidelberg.de> *
7 // for The ALICE HLT Project. *
8 // *
9 // Developed by: Igor Kulakov <I.Kulakov@gsi.de> *
10 // Maksym Zyzak <M.Zyzak@gsi.de> *
11 // *
12 // Permission to use, copy, modify and distribute this software and its *
13 // documentation strictly for non-commercial purposes is hereby granted *
14 // without fee, provided that the above copyright notice appears in all *
15 // copies and that both the copyright notice and this permission notice *
16 // appear in the supporting documentation. The authors make no claims *
17 // about the suitability of this software for any purpose. It is *
18 // provided "as is" without express or implied warranty. *
19 // *
20 //***************************************************************************
21 
22 #include "AliHLTTPCCAHitArea.h"
23 #include "AliHLTTPCCASliceDataVector.h"
24 #include "AliHLTTPCCAGrid.h"
25 #include "AliHLTTPCCARow.h"
26 #include "debug.h"
27 
28 AliHLTTPCCAHitArea::AliHLTTPCCAHitArea( const AliHLTTPCCARow &row, const AliHLTTPCCASliceData &slice,
29  const sfloat_v &y, const sfloat_v &z, float dy, float dz, short_m mask )
30  : fRow( row ), fSlice( slice ),
31  fHitYlst( Vc::Zero ),
32  fIh( Vc::Zero ),
33  fNy( fRow.Grid().Ny() )
34 {
35  const AliHLTTPCCAGrid &grid = fRow.Grid();
36 
37  const sfloat_v minZ = z - dz;
38  const sfloat_v maxZ = z + dz;
39  const sfloat_v minY = y - dy;
40  const sfloat_v maxY = y + dy;
41 
42  ushort_v bYmin, bZmin, bYmax; // boundary bin indexes
43  grid.GetBinBounded( minY, minZ, &bYmin, &bZmin );
44  grid.GetBinBounded( maxY, maxZ, &bYmax, &fBZmax );
45 
46  fBDY = ( bYmax - bYmin + 1 ); // bin index span in y direction
47 
48  fIndYmin = ( bZmin * fNy + bYmin ); // same as grid.GetBin(fMinY, fMinZ), i.e. the smallest bin index of interest
49  // fIndYmin + fBDY then is the largest bin index of interest with the same Z
50 
51  fIz = bZmin;
52 
53  const short_m invalidMask = !mask;
54  if ( !invalidMask.isEmpty() ) {
55  debugS() << "not all parts of the HitArea are valid: " << mask << std::endl;
56 
57  fBZmax.setZero( invalidMask );
58  fBDY.setZero( invalidMask );
59  fIndYmin.setZero( invalidMask );
60  fIz.setZero( invalidMask );
61 
62  // for given fIz (which is min atm.) get
63  fIh.gather( fSlice.FirstHitInBin( fRow ), fIndYmin, mask ); // first and
64  fHitYlst.gather( fSlice.FirstHitInBin( fRow ), fIndYmin + fBDY, mask ); // last hit index in the bin
65  } else {
66  fIh = fSlice.FirstHitInBin( fRow, fIndYmin );
67  fHitYlst = fSlice.FirstHitInBin( fRow, fIndYmin + fBDY );
68  }
69  assert( fHitYlst <= fRow.NHits() || invalidMask );
70 
71  debugS() << "HitArea created:\n"
72  << "bYmin: " << bYmin << "\n"
73  << "bZmin: " << bZmin << "\n"
74  << "bYmax: " << bYmax << "\n"
75  << "fBZmax: " << fBZmax << "\n"
76  << "fBDY: " << fBDY << "\n"
77  << "fIndYmin: " << fIndYmin << "\n"
78  << "fIz: " << fIz << "\n"
79  << "fHitYlst: " << fHitYlst << "\n"
80  << "fIh: " << fIh << "\n"
81  << "fNy: " << fNy << std::endl;
82 }
83 
85 {
86  // get next hit index
87  ushort_m yIndexOutOfRange = fIh >= fHitYlst; // current y is not in the area
88  ushort_m nextZIndexOutOfRange = fIz >= fBZmax; // there isn't any new z-line
89  if ( yIndexOutOfRange && nextZIndexOutOfRange ) { // all iterators are over the end
90  return ushort_m(false);
91  }
92 
93  ushort_m isUsed = static_cast<ushort_m>( short_v(fSlice.HitDataIsUsed( fRow ), fIh) != short_v( Vc::Zero ) );
94 
95 
96  // at least one entry in the vector has (fIh >= fHitYlst && fIz < fBZmax)
97  ushort_m needNextZ = yIndexOutOfRange && !nextZIndexOutOfRange;
98  ushort_m needNextHit = (isUsed || yIndexOutOfRange) && !nextZIndexOutOfRange;
99 
100  debugS() << "fIh >= fHitYlst: " << yIndexOutOfRange << " fIz >= fBZmax: " << nextZIndexOutOfRange << " -> " << needNextZ << std::endl;
101 
102  // skip as long as fIh is outside of the interesting bin y-index
103  while ( !needNextHit.isEmpty() ) {
104 
105  ++fIh( needNextHit );
106  // if ( !needNextZ.isEmpty() ) { // slower
107  ++fIz( needNextZ ); // get new z-line
108  nextZIndexOutOfRange = fIz >= fBZmax;
109 
110  // get next hit
111  fIndYmin( needNextZ ) += fNy;
112  fIh.gather( fSlice.FirstHitInBin( fRow ), fIndYmin, needNextZ ); // get first hit in cell, if z-line is new
113  fHitYlst.gather( fSlice.FirstHitInBin( fRow ), fIndYmin + fBDY, needNextZ );
114  // }
115  isUsed = static_cast<ushort_m>( short_v(fSlice.HitDataIsUsed( fRow ), fIh) != short_v( Vc::Zero ) );
116 
117  assert( fHitYlst <= fRow.NHits() || !needNextZ );
118  yIndexOutOfRange = fIh >= fHitYlst;
119 
120  needNextZ = yIndexOutOfRange && !nextZIndexOutOfRange;
121  // needNextHit = (isUsed && !yIndexOutOfRange) || (!isUsed && needNextZ); // slower
122  needNextHit = (isUsed || yIndexOutOfRange) && !nextZIndexOutOfRange; // incorrect
123  debugS() << "fIh >= fHitYlst: " << yIndexOutOfRange << " fIz >= fBZmax: " << nextZIndexOutOfRange << " -> " << needNextZ << std::endl;
124  }
125 
126  data->fValid = !yIndexOutOfRange && !isUsed;
127  const sfloat_m valid( data->fValid );
128 
129  data->fY.setZero();
130  data->fY.gather( fSlice.HitDataY( fRow ), fIh, valid );
131  data->fZ.setZero();
132  data->fZ.gather( fSlice.HitDataZ( fRow ), fIh, valid );
133 
134  data->fLinks = fIh.staticCast<short_v>();
135 
136  ++fIh;
137 
138  debugS() << "HitArea found next. New state:\n"
139  << "fIndYmin: " << fIndYmin << "\n"
140  << "fIz: " << fIz << "\n"
141  << "fHitYlst: " << fHitYlst << "\n"
142  << "fIh: " << fIh << std::endl;
143 
144 
145  return data->fValid;
146 }
ushort_v FirstHitInBin(const AliHLTTPCCARow &row, ushort_v binIndexes) const
ushort_m GetNext(NeighbourData *data)
ushort_v GetBinBounded(const sfloat_v &Y, const sfloat_v &Z) const