]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/tracking-ca/AliHLTTPCCATrackerComponent.cxx
GPU update from David Rohr
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCATrackerComponent.cxx
CommitLineData
cf471b1e 1// @(#) $Id$
ce565086 2// **************************************************************************
fbb9b71b 3// This file is property of and copyright by the ALICE HLT Project *
d54804bf 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// Permission to use, copy, modify and distribute this software and its *
11// documentation strictly for non-commercial purposes is hereby granted *
12// without fee, provided that the above copyright notice appears in all *
13// copies and that both the copyright notice and this permission notice *
14// appear in the supporting documentation. The authors make no claims *
15// about the suitability of this software for any purpose. It is *
16// provided "as is" without express or implied warranty. *
ce565086 17// *
d54804bf 18//***************************************************************************
ce565086 19
fbb9b71b 20
cf471b1e 21///////////////////////////////////////////////////////////////////////////////
22// //
23// a TPC tracker processing component for the HLT based on CA by Ivan Kisel //
24// //
25///////////////////////////////////////////////////////////////////////////////
26
27#if __GNUC__>= 3
28using namespace std;
29#endif
30
31#include "AliHLTTPCCATrackerComponent.h"
32#include "AliHLTTPCTransform.h"
b22af1bf 33#include "AliHLTTPCCATrackerFramework.h"
cf471b1e 34#include "AliHLTTPCCAOutTrack.h"
d54804bf 35#include "AliHLTTPCCAParam.h"
eb30eb49 36#include "AliHLTTPCCATrackConvertor.h"
4acc2401 37#include "AliHLTArray.h"
cf471b1e 38
cf471b1e 39#include "AliHLTTPCSpacePointData.h"
cf471b1e 40#include "AliHLTTPCClusterDataFormat.h"
751d16ac 41#include "AliHLTTPCCACompressedInputData.h"
cf471b1e 42#include "AliHLTTPCTransform.h"
43#include "AliHLTTPCTrackSegmentData.h"
44#include "AliHLTTPCTrackArray.h"
45#include "AliHLTTPCTrackletDataFormat.h"
46#include "AliHLTTPCDefinitions.h"
d54804bf 47#include "AliExternalTrackParam.h"
dc4788ec 48#include "TStopwatch.h"
cf471b1e 49#include "TMath.h"
53a9c37c 50#include "AliCDBEntry.h"
51#include "AliCDBManager.h"
52#include "TObjString.h"
53#include "TObjArray.h"
e1f2d1c3 54#include "AliHLTTPCCASliceOutput.h"
4acc2401 55#include "AliHLTTPCCAClusterData.h"
e1f2d1c3 56
57const AliHLTComponentDataType AliHLTTPCCADefinitions::fgkTrackletsDataType = AliHLTComponentDataTypeInitializer( "CATRACKL", kAliHLTDataOriginTPC );
58
59/** ROOT macro for the implementation of ROOT specific class methods */
fbb9b71b 60ClassImp( AliHLTTPCCATrackerComponent )
cf471b1e 61
cf471b1e 62AliHLTTPCCATrackerComponent::AliHLTTPCCATrackerComponent()
fbb9b71b 63 :
64 fTracker( NULL ),
65 fSolenoidBz( 0 ),
66 fMinNTrackClusters( 0 ),
67 fClusterZCut( 500. ),
f0fb467d 68 fNeighboursSearchArea( 0 ),
69 fClusterErrorCorrectionY(0),
70 fClusterErrorCorrectionZ(0),
fbb9b71b 71 fFullTime( 0 ),
72 fRecoTime( 0 ),
73 fNEvents( 0 ),
768b27af 74 fOutputTRAKSEGS( 0 )
cf471b1e 75{
76 // see header file for class documentation
77 // or
78 // refer to README to build package
79 // or
80 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
81}
82
fbb9b71b 83AliHLTTPCCATrackerComponent::AliHLTTPCCATrackerComponent( const AliHLTTPCCATrackerComponent& )
84 :
85 AliHLTProcessor(),
86 fTracker( NULL ),
87 fSolenoidBz( 0 ),
88 fMinNTrackClusters( 30 ),
89 fClusterZCut( 500. ),
f0fb467d 90 fNeighboursSearchArea(0),
91 fClusterErrorCorrectionY(0),
92 fClusterErrorCorrectionZ(0),
fbb9b71b 93 fFullTime( 0 ),
94 fRecoTime( 0 ),
95 fNEvents( 0 ),
768b27af 96 fOutputTRAKSEGS( 0 )
cf471b1e 97{
98 // see header file for class documentation
fbb9b71b 99 HLTFatal( "copy constructor untested" );
cf471b1e 100}
101
fbb9b71b 102AliHLTTPCCATrackerComponent& AliHLTTPCCATrackerComponent::operator=( const AliHLTTPCCATrackerComponent& )
cf471b1e 103{
104 // see header file for class documentation
fbb9b71b 105 HLTFatal( "assignment operator untested" );
cf471b1e 106 return *this;
107}
108
109AliHLTTPCCATrackerComponent::~AliHLTTPCCATrackerComponent()
4c256004 110{
cf471b1e 111 // see header file for class documentation
3a4ab1ca 112 if (fTracker) delete fTracker;
4c256004 113}
cf471b1e 114
4c256004 115//
cf471b1e 116// Public functions to implement AliHLTComponent's interface.
117// These functions are required for the registration process
4c256004 118//
cf471b1e 119
fbb9b71b 120const char* AliHLTTPCCATrackerComponent::GetComponentID()
4c256004 121{
cf471b1e 122 // see header file for class documentation
4c256004 123 return "TPCCATracker";
124}
cf471b1e 125
fbb9b71b 126void AliHLTTPCCATrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
4c256004 127{
cf471b1e 128 // see header file for class documentation
4c256004 129 list.clear();
130 list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
751d16ac 131 list.push_back( AliHLTTPCCADefinitions::fgkCompressedInputDataType );
4c256004 132}
cf471b1e 133
fbb9b71b 134AliHLTComponentDataType AliHLTTPCCATrackerComponent::GetOutputDataType()
4c256004 135{
cf471b1e 136 // see header file for class documentation
768b27af 137 if ( fOutputTRAKSEGS ) return AliHLTTPCDefinitions::fgkTrackSegmentsDataType;
138 else return AliHLTTPCCADefinitions::fgkTrackletsDataType;
4c256004 139}
cf471b1e 140
fbb9b71b 141void AliHLTTPCCATrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
4c256004 142{
143 // define guess for the output data size
144 constBase = 200; // minimum size
751d16ac 145 inputMultiplier = 3.; // size relative to input
4c256004 146}
cf471b1e 147
fbb9b71b 148AliHLTComponent* AliHLTTPCCATrackerComponent::Spawn()
4c256004 149{
cf471b1e 150 // see header file for class documentation
4c256004 151 return new AliHLTTPCCATrackerComponent;
152}
cf471b1e 153
768b27af 154void AliHLTTPCCATrackerComponent::SetDefaultConfiguration()
4c256004 155{
c26cae51 156 // Set default configuration for the CA tracker component
768b27af 157 // Some parameters can be later overwritten from the OCDB
d54804bf 158
a8714ffa 159 fSolenoidBz = -5.00668;
53a9c37c 160 fMinNTrackClusters = 0;
161 fClusterZCut = 500.;
f0fb467d 162 fNeighboursSearchArea = 0;
163 fClusterErrorCorrectionY = 0;
164 fClusterErrorCorrectionZ = 0;
768b27af 165 fOutputTRAKSEGS = 0;
d54804bf 166 fFullTime = 0;
167 fRecoTime = 0;
00d07bcd 168 fNEvents = 0;
768b27af 169}
d54804bf 170
768b27af 171int AliHLTTPCCATrackerComponent::ReadConfigurationString( const char* arguments )
172{
173 // Set configuration parameters for the CA tracker component from the string
d54804bf 174
fbb9b71b 175 int iResult = 0;
768b27af 176 if ( !arguments ) return iResult;
c26cae51 177
768b27af 178 TString allArgs = arguments;
179 TString argument;
180 int bMissingParam = 0;
eb30eb49 181
768b27af 182 TObjArray* pTokens = allArgs.Tokenize( " " );
183
184 int nArgs = pTokens ? pTokens->GetEntries() : 0;
c26cae51 185
768b27af 186 for ( int i = 0; i < nArgs; i++ ) {
187 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
188 if ( argument.IsNull() ) continue;
c26cae51 189
768b27af 190 if ( argument.CompareTo( "-solenoidBz" ) == 0 ) {
191 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
192 fSolenoidBz = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
193 HLTInfo( "Magnetic Field set to: %f", fSolenoidBz );
194 continue;
c26cae51 195 }
768b27af 196
197 if ( argument.CompareTo( "-minNClustersOnTrack" ) == 0 ) {
198 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
199 fMinNTrackClusters = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
200 HLTInfo( "minNClustersOnTrack set to: %d", fMinNTrackClusters );
201 continue;
202 }
c26cae51 203
768b27af 204 if ( argument.CompareTo( "-clusterZCut" ) == 0 ) {
205 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
206 fClusterZCut = TMath::Abs( ( ( TObjString* )pTokens->At( i ) )->GetString().Atof() );
207 HLTInfo( "ClusterZCut set to: %f", fClusterZCut );
208 continue;
209 }
f0fb467d 210
211 if ( argument.CompareTo( "-neighboursSearchArea" ) == 0 ) {
212 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
213 fNeighboursSearchArea = TMath::Abs( ( ( TObjString* )pTokens->At( i ) )->GetString().Atof() );
214 HLTInfo( "NeighboursSearchArea set to: %f", fNeighboursSearchArea );
215 continue;
216 }
c26cae51 217
f0fb467d 218 if ( argument.CompareTo( "-errorCorrectionY" ) == 0 ) {
219 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
220 fClusterErrorCorrectionY = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
221 HLTInfo( "Cluster Y error correction factor set to: %f", fClusterErrorCorrectionY );
222 continue;
223 }
224
225 if ( argument.CompareTo( "-errorCorrectionZ" ) == 0 ) {
226 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
227 fClusterErrorCorrectionZ = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
228 HLTInfo( "Cluster Z error correction factor set to: %f", fClusterErrorCorrectionZ );
229 continue;
230 }
231
232 if ( argument.CompareTo( "-outputTRAKSEGS" ) == 0 ) {
768b27af 233 fOutputTRAKSEGS = 1;
234 HLTInfo( "The special output type \"TRAKSEGS\" is set" );
235 continue;
c26cae51 236 }
237
768b27af 238 HLTError( "Unknown option \"%s\"", argument.Data() );
239 iResult = -EINVAL;
4c256004 240 }
768b27af 241 delete pTokens;
242
243 if ( bMissingParam ) {
244 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
245 iResult = -EINVAL;
fbb9b71b 246 }
c26cae51 247
53a9c37c 248 return iResult;
4c256004 249}
cf471b1e 250
53a9c37c 251
768b27af 252int AliHLTTPCCATrackerComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
4c256004 253{
cf471b1e 254 // see header file for class documentation
cf471b1e 255
c26cae51 256 const char* defaultNotify = "";
e1f2d1c3 257
c26cae51 258 if ( !cdbEntry ) {
259 cdbEntry = "HLT/ConfigTPC/TPCCATracker";
260 defaultNotify = " (default)";
768b27af 261 chainId = 0;
262 }
53a9c37c 263
c26cae51 264 HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
265 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
fbb9b71b 266
c26cae51 267 if ( !pEntry ) {
268 HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
269 return -EINVAL;
53a9c37c 270 }
768b27af 271
c26cae51 272 TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
768b27af 273
c26cae51 274 if ( !pString ) {
275 HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
276 return -EINVAL;
53a9c37c 277 }
fbb9b71b 278
c26cae51 279 HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
fbb9b71b 280
768b27af 281 return ReadConfigurationString( pString->GetString().Data() );
282}
283
284
17d6eada 285int AliHLTTPCCATrackerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
286{
c26cae51 287 // Configure the component
288 // There are few levels of configuration,
17d6eada 289 // parameters which are set on one step can be overwritten on the next step
c26cae51 290
17d6eada 291 //* read hard-coded values
292
c26cae51 293 SetDefaultConfiguration();
17d6eada 294
295 //* read the default CDB entry
c26cae51 296
17d6eada 297 int iResult1 = ReadCDBEntry( NULL, chainId );
c26cae51 298
17d6eada 299 //* read magnetic field
c26cae51 300
301 int iResult2 = ReadCDBEntry( kAliHLTCDBSolenoidBz, chainId );
302
17d6eada 303 //* read the actual CDB entry if required
c26cae51 304
305 int iResult3 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
306
17d6eada 307 //* read extra parameters from input (if they are)
308
309 int iResult4 = 0;
c26cae51 310
311 if ( commandLine && commandLine[0] != '\0' ) {
312 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
313 iResult4 = ReadConfigurationString( commandLine );
17d6eada 314 }
315
316 // Initialise the tracker here
c26cae51 317
318 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : ( iResult3 ? iResult3 : iResult4 ) );
17d6eada 319}
320
321
322
768b27af 323int AliHLTTPCCATrackerComponent::DoInit( int argc, const char** argv )
324{
325 // Configure the CA tracker component
326
d4594e7d 327 if ( fTracker ) return EINPROGRESS;
c26cae51 328
b22af1bf 329
3a4ab1ca 330 //fTracker = new AliHLTTPCCATrackerFramework();
331 //Do not initialize the TrackerFramework here since the CUDA framework is thread local and DoInit is called from different thread than DoEvent
768b27af 332
333 TString arguments = "";
334 for ( int i = 0; i < argc; i++ ) {
335 if ( !arguments.IsNull() ) arguments += " ";
336 arguments += argv[i];
fbb9b71b 337 }
c26cae51 338
339 return Configure( NULL, NULL, arguments.Data() );
53a9c37c 340}
341
342
768b27af 343int AliHLTTPCCATrackerComponent::DoDeinit()
eb30eb49 344{
768b27af 345 // see header file for class documentation
3a4ab1ca 346 if (fTracker) delete fTracker;
768b27af 347 fTracker = NULL;
348 return 0;
eb30eb49 349}
350
53a9c37c 351
768b27af 352
353int AliHLTTPCCATrackerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
53a9c37c 354{
17d6eada 355 // Reconfigure the component from OCDB .
fbb9b71b 356
17d6eada 357 return Configure( cdbEntry, chainId, NULL );
53a9c37c 358}
53a9c37c 359
360
768b27af 361bool AliHLTTPCCATrackerComponent::CompareClusters( AliHLTTPCSpacePointData *a, AliHLTTPCSpacePointData *b )
362{
363 //* Comparison function for sort clusters
364
365 if ( a->fPadRow < b->fPadRow ) return 1;
366 if ( a->fPadRow > b->fPadRow ) return 0;
367 return ( a->fZ < b->fZ );
368}
369
53a9c37c 370
fbb9b71b 371
372int AliHLTTPCCATrackerComponent::DoEvent
373(
374 const AliHLTComponentEventData& evtData,
375 const AliHLTComponentBlockData* blocks,
376 AliHLTComponentTriggerData& /*trigData*/,
377 AliHLTUInt8_t* outputPtr,
378 AliHLTUInt32_t& size,
379 vector<AliHLTComponentBlockData>& outputBlocks )
cf471b1e 380{
768b27af 381 //* process event
382
00d07bcd 383 AliHLTUInt32_t maxBufferSize = size;
dc4788ec 384 size = 0; // output size
385
fbb9b71b 386 if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) ) {
eb30eb49 387 return 0;
388 }
389
dc4788ec 390 TStopwatch timer;
391
4c256004 392 // Event reconstruction in one TPC slice with CA Tracker
fbb9b71b 393
d54804bf 394 //Logging( kHLTLogWarning, "HLT::TPCCATracker::DoEvent", "DoEvent", "CA::DoEvent()" );
fbb9b71b 395 if ( evtData.fBlockCnt <= 0 ) {
396 HLTWarning( "no blocks in event" );
397 return 0;
398 }
399
cf471b1e 400 const AliHLTComponentBlockData* iter = NULL;
401 unsigned long ndx;
fbb9b71b 402
403 // Determine the slice number
404
d4594e7d 405 //Find min and max slice number with now slice missing in between (for default output)
406 int minslice = -1, maxslice = -1;
fbb9b71b 407 int slice = -1;
4c256004 408 {
fbb9b71b 409 std::vector<int> slices;
410 std::vector<int>::iterator slIter;
4acc2401 411 std::vector<unsigned> sliceCnts;
412 std::vector<unsigned>::iterator slCntIter;
fbb9b71b 413
414 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) {
415 iter = blocks + ndx;
751d16ac 416 if ( iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType
417 && iter->fDataType != AliHLTTPCCADefinitions::fgkCompressedInputDataType
418 ) continue;
4c256004 419
cf471b1e 420 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
d4594e7d 421 if (slice < minslice || minslice == -1) minslice = slice;
422 if (slice > maxslice) maxslice = slice;
dc4788ec 423
fbb9b71b 424 bool found = 0;
cf471b1e 425 slCntIter = sliceCnts.begin();
fbb9b71b 426 for ( slIter = slices.begin(); slIter != slices.end(); slIter++, slCntIter++ ) {
427 if ( *slIter == slice ) {
428 found = kTRUE;
429 break;
430 }
4c256004 431 }
fbb9b71b 432 if ( !found ) {
433 slices.push_back( slice );
434 sliceCnts.push_back( 1 );
435 } else *slCntIter++;
cf471b1e 436 }
fbb9b71b 437
d4594e7d 438 if ( slices.size() == 0 ) {
439 HLTWarning( "no slices found in event" );
440 return 0;
441 }
fbb9b71b 442
d4594e7d 443
444 // Determine slice number to really use. (for obsolete output)
fbb9b71b 445 if ( slices.size() > 1 ) {
d4594e7d 446 Logging( fOutputTRAKSEGS ? kHLTLogError : kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
fbb9b71b 447 "Multiple slice numbers found in event 0x%08lX (%lu). Determining maximum occuring slice number...",
448 evtData.fEventID, evtData.fEventID );
4acc2401 449 unsigned maxCntSlice = 0;
fbb9b71b 450 slCntIter = sliceCnts.begin();
451 for ( slIter = slices.begin(); slIter != slices.end(); slIter++, slCntIter++ ) {
d4594e7d 452 Logging( fOutputTRAKSEGS ? kHLTLogError : kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
fbb9b71b 453 "Slice %lu found %lu times.", *slIter, *slCntIter );
d4594e7d 454 if ( fOutputTRAKSEGS && maxCntSlice < *slCntIter ) {
fbb9b71b 455 maxCntSlice = *slCntIter;
456 slice = *slIter;
457 }
4c256004 458 }
d4594e7d 459 if (fOutputTRAKSEGS)
460 {
461 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
fbb9b71b 462 "Using slice %lu.", slice );
d4594e7d 463 }
fbb9b71b 464 } else if ( slices.size() > 0 ) {
465 slice = *( slices.begin() );
466 }
4c256004 467
4c256004 468
d4594e7d 469 if (fOutputTRAKSEGS)
470 {
471 minslice = maxslice = slice;
472 }
473 else
474 {
475 for (int islice = minslice;islice <= maxslice;islice++)
476 {
477 bool found = false;
478 for(slIter = slices.begin(); slIter != slices.end();slIter++)
479 {
480 if (*slIter == islice)
481 {
482 found = true;
483 break;
484 }
485 }
486 if (!found)
487 {
488 maxslice = islice - 1;
489 break;
490 }
491 }
492 }
493 }
fbb9b71b 494
d4594e7d 495 if ( !fTracker ) fTracker = new AliHLTTPCCATrackerFramework;
3a4ab1ca 496
d4594e7d 497 int slicecount = maxslice + 1 - minslice;
498 if (slicecount > fTracker->MaxSliceCount())
cf471b1e 499 {
d4594e7d 500 maxslice = minslice + (slicecount = fTracker->MaxSliceCount());
cf471b1e 501 }
d4594e7d 502 int nClustersTotalSum = 0;
503 AliHLTTPCCAClusterData* clusterData = new AliHLTTPCCAClusterData[slicecount];
cf471b1e 504
fbb9b71b 505
4c256004 506 // min and max patch numbers and row numbers
d4594e7d 507 int* slicerow = new int[slicecount * 2];
508 int* sliceminPatch = new int[slicecount];
509 int* slicemaxPatch = new int[slicecount];
510 memset(slicerow, 0, slicecount * 2 * sizeof(int));
511 for (int i = 0;i < slicecount;i++)
512 {
513 sliceminPatch[i] = 100;
514 slicemaxPatch[i] = -1;
cf471b1e 515 }
fbb9b71b 516
d4594e7d 517 //Prepare everything for all slices
4c256004 518
d4594e7d 519 for (int islice = 0;islice < slicecount;islice++)
520 {
521 slice = minslice + islice;
522
523 // Initialize the tracker slice
524 {
525 int iSec = slice;
526 float inRmin = 83.65;
527 // float inRmax = 133.3;
528 // float outRmin = 133.5;
529 float outRmax = 247.7;
530 float plusZmin = 0.0529937;
531 float plusZmax = 249.778;
532 float minusZmin = -249.645;
533 float minusZmax = -0.0799937;
534 float dalpha = 0.349066;
535 float alpha = 0.174533 + dalpha * iSec;
536
537 bool zPlus = ( iSec < 18 );
538 float zMin = zPlus ? plusZmin : minusZmin;
539 float zMax = zPlus ? plusZmax : minusZmax;
540 //TPCZmin = -249.645, ZMax = 249.778
541 // float rMin = inRmin;
542 // float rMax = outRmax;
543 int nRows = AliHLTTPCTransform::GetNRows();
544
545 float padPitch = 0.4;
546 float sigmaZ = 0.228808;
547
548 float *rowX = new float [nRows];
549 for ( int irow = 0; irow < nRows; irow++ ) {
550 rowX[irow] = AliHLTTPCTransform::Row2X( irow );
551 }
552
553 AliHLTTPCCAParam param;
554
555 param.Initialize( iSec, nRows, rowX, alpha, dalpha,
556 inRmin, outRmax, zMin, zMax, padPitch, sigmaZ, fSolenoidBz );
557 param.SetHitPickUpFactor( 2 );
558 if( fNeighboursSearchArea>0 ) param.SetNeighboursSearchArea( fNeighboursSearchArea );
559 if( fClusterErrorCorrectionY>1.e-4 ) param.SetClusterError2CorrectionY( fClusterErrorCorrectionY*fClusterErrorCorrectionY );
560 if( fClusterErrorCorrectionZ>1.e-4 ) param.SetClusterError2CorrectionZ( fClusterErrorCorrectionZ*fClusterErrorCorrectionZ );
561 param.Update();
562 fTracker->InitializeSliceParam( slice, param );
563 delete[] rowX;
564 }
565
566 // total n Hits
567 int nClustersTotal = 0;
568
569 // sort patches
570 std::vector<unsigned long> patchIndices;
571
572 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) {
573 iter = blocks + ndx;
d4594e7d 574 if ( slice != AliHLTTPCDefinitions::GetMinSliceNr( *iter ) ) continue;
751d16ac 575 if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType ){
576 AliHLTTPCClusterData* inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
577 nClustersTotal += inPtrSP->fSpacePointCnt;
578 }
579 else if ( iter->fDataType == AliHLTTPCCADefinitions::fgkCompressedInputDataType){
580 const AliHLTUInt8_t * inPtr = (const AliHLTUInt8_t *)iter->fPtr;
581 while( inPtr< ((const AliHLTUInt8_t *) iter->fPtr) + iter->fSize ){
582 AliHLTTPCCACompressedClusterRow *row = (AliHLTTPCCACompressedClusterRow*)inPtr;
583 nClustersTotal+= row->fNClusters;
584 inPtr = (const AliHLTUInt8_t *)(row->fClusters+row->fNClusters);
585 }
586 }
587 else continue;
588
d4594e7d 589 int patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
590 if ( sliceminPatch[islice] > patch ) {
591 sliceminPatch[islice] = patch;
592 slicerow[2 * islice + 0] = AliHLTTPCTransform::GetFirstRow( patch );
593 }
594 if ( slicemaxPatch[islice] < patch ) {
595 slicemaxPatch[islice] = patch;
596 slicerow[2 * islice + 1] = AliHLTTPCTransform::GetLastRow( patch );
597 }
598 std::vector<unsigned long>::iterator pIter = patchIndices.begin();
599 while ( pIter != patchIndices.end() && AliHLTTPCDefinitions::GetMinPatchNr( blocks[*pIter] ) < patch ) {
600 pIter++;
601 }
602 patchIndices.insert( pIter, ndx );
603 }
604
605
606 // pass event to CA Tracker
607
608
609 Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reading hits",
610 "Total %d hits to read for slice %d", nClustersTotal, slice );
611
612
613 clusterData[islice].StartReading( slice, nClustersTotal );
614
615 for ( std::vector<unsigned long>::iterator pIter = patchIndices.begin(); pIter != patchIndices.end(); pIter++ ) {
616 ndx = *pIter;
617 iter = blocks + ndx;
d4594e7d 618 int patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
751d16ac 619 int nPatchClust = 0;
620 if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType ){
621 AliHLTTPCClusterData* inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
622 nPatchClust = inPtrSP->fSpacePointCnt;
623 for ( unsigned int i = 0; i < inPtrSP->fSpacePointCnt; i++ ) {
624 AliHLTTPCSpacePointData *c = &( inPtrSP->fSpacePoints[i] );
625 if ( CAMath::Abs( c->fZ ) > fClusterZCut ) continue;
626 if ( c->fPadRow > 159 ) {
627 HLTError( "Wrong TPC cluster with row number %d received", c->fPadRow );
628 continue;
629 }
630 clusterData[islice].ReadCluster( c->fID, c->fPadRow, c->fX, c->fY, c->fZ, c->fCharge );
631 }
632 }
633 else if ( iter->fDataType == AliHLTTPCCADefinitions::fgkCompressedInputDataType){
634 const AliHLTUInt8_t * inPtr = (const AliHLTUInt8_t *)iter->fPtr;
635 nPatchClust=0;
636 while( inPtr< ((const AliHLTUInt8_t *)iter->fPtr) + iter->fSize ){
637 AliHLTTPCCACompressedClusterRow *row = (AliHLTTPCCACompressedClusterRow*)inPtr;
638 UInt_t id = row->fSlicePatchRowID;
639 UInt_t jslice = id>>10;
640 UInt_t jpatch = (id>>6) & 0x7;
641 UInt_t jrow = id & 0x3F;
642 jrow+= AliHLTTPCTransform::GetFirstRow( jpatch );
643 Double_t rowX = AliHLTTPCTransform::Row2X( jrow );
644 //cout<<"Read row: s "<<jslice<<" p "<<jpatch<<" r "<<jrow<<" x "<<row->fX<<" nclu "<<row->fNClusters<<" :"<<endl;
645 if( jrow > 159 ) {
646 HLTError( "Wrong TPC cluster with row number %d received", jrow );
647 continue;
648 }
649 for ( unsigned int i = 0; i < row->fNClusters; i++ ) {
650 AliHLTTPCCACompressedCluster *c = &( row->fClusters[i] );
651
652 UInt_t ix0 = c->fP0 >>24;
653 UInt_t ix1 = c->fP1 >>24;
654 Double_t x = (ix1<<8) + ix0;
655 Double_t y = c->fP0 & 0x00FFFFFF;
656 Double_t z = c->fP1 & 0x00FFFFFF;
657 x = (x - 32768.)*1.e-4 + rowX;
658 y = (y - 8388608.)*1.e-4;
659 z = (z - 8388608.)*1.e-4;
660
661 UInt_t cluId = nPatchClust + ((jslice&0x7f)<<25)+((jpatch&0x7)<<22);
662 //cout<<"clu "<<i<<": "<<x<<" "<<y<<" "<<z<<" "<<cluId<<endl;
663 if ( CAMath::Abs( z ) <= fClusterZCut ){
664 clusterData[islice].ReadCluster( cluId, jrow, x, y, z, 0 );
665 }
666 nPatchClust++;
667 }
668 inPtr = (const AliHLTUInt8_t *)(row->fClusters+row->fNClusters);
d4594e7d 669 }
d4594e7d 670 }
751d16ac 671 Logging( kHLTLogInfo, "HLT::TPCCATracker::DoEvent", "Reading hits",
672 "Read %d hits for slice %d - patch %d", nPatchClust, slice, patch );
d4594e7d 673 }
674
675 clusterData[islice].FinishReading();
676 nClustersTotalSum += nClustersTotal;
677 }
fbb9b71b 678
d4594e7d 679 //Prepare Output
680 AliHLTTPCCASliceOutput::outputControlStruct outputControl;
681 //Set tracker output so tracker does not have to output both formats!
682 outputControl.fObsoleteOutput = fOutputTRAKSEGS;
683 outputControl.fDefaultOutput = !fOutputTRAKSEGS;
fbb9b71b 684
d4594e7d 685 //For new output we can write directly to output buffer
686 outputControl.fOutputPtr = fOutputTRAKSEGS ? NULL : (char*) outputPtr;
687 outputControl.fOutputMaxSize = maxBufferSize;
4c256004 688
d4594e7d 689 AliHLTTPCCASliceOutput** sliceOutput = new AliHLTTPCCASliceOutput*[slicecount];
690 memset(sliceOutput, 0, slicecount * sizeof(AliHLTTPCCASliceOutput*));
b8139972 691
fbb9b71b 692 // reconstruct the event
dc4788ec 693 TStopwatch timerReco;
d4594e7d 694 fTracker->SetOutputControl(&outputControl);
695 fTracker->ProcessSlices(minslice, slicecount, clusterData, sliceOutput);
dc4788ec 696 timerReco.Stop();
d4594e7d 697
fbb9b71b 698 int ret = 0;
fbb9b71b 699 unsigned int mySize = 0;
a59a784e 700 int ntracks = 0;
d4594e7d 701 int error = 0;
fbb9b71b 702
d4594e7d 703 for (int islice = 0;islice < slicecount;islice++)
704 {
705 slice = minslice + islice;
706
707 if (sliceOutput[islice])
708 {
d4594e7d 709 // write reconstructed tracks
fbb9b71b 710
d4594e7d 711 if ( fOutputTRAKSEGS ) {
fbb9b71b 712
c7d6f78b 713 Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reconstruct",
714 "%d tracks found for slice %d", sliceOutput[islice]->NOutTracks(), slice );
715
d4594e7d 716 ntracks = sliceOutput[islice]->NOutTracks();
fbb9b71b 717
d4594e7d 718 AliHLTTPCTrackletData* outPtr = ( AliHLTTPCTrackletData* )( outputPtr );
fbb9b71b 719
d4594e7d 720 AliHLTTPCTrackSegmentData* currOutTracklet = outPtr->fTracklets;
fbb9b71b 721
d4594e7d 722 mySize = ( ( AliHLTUInt8_t * )currOutTracklet ) - ( ( AliHLTUInt8_t * )outputPtr );
723
724 outPtr->fTrackletCnt = 0;
725
726 for ( int itr = 0; itr < ntracks; itr++ ) {
727
728 AliHLTTPCCAOutTrack &t = sliceOutput[islice]->OutTracks()[itr];
729
730 //Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Wrtite output","track %d with %d hits", itr, t.NHits());
731
732 if ( t.NHits() < fMinNTrackClusters ) continue;
733
734 // calculate output track size
735
736 unsigned int dSize = sizeof( AliHLTTPCTrackSegmentData ) + t.NHits() * sizeof( unsigned int );
737
738 if ( mySize + dSize > maxBufferSize ) {
739 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d tracks are not stored", maxBufferSize, mySize, ntracks - itr + 1 );
740 ret = -ENOSPC;
741 error = 1;
742 break;
743 }
744
745 // convert CA track parameters to HLT Track Segment
746
747 int iFirstRow = 1000;
748 int iLastRow = -1;
749 int iFirstHit = sliceOutput[islice]->OutTrackHit(t.FirstHitRef());
750 int iLastHit = iFirstHit;
751 for ( int ih = 0; ih < t.NHits(); ih++ ) {
752 int hitID = sliceOutput[islice]->OutTrackHit(t.FirstHitRef() + ih);
753 int iRow = clusterData[islice].RowNumber( hitID );
754 if ( iRow < iFirstRow ) { iFirstRow = iRow; iFirstHit = hitID; }
755 if ( iRow > iLastRow ) { iLastRow = iRow; iLastHit = hitID; }
756 }
757
758 AliHLTTPCCATrackParam par = t.StartPoint();
759
760 par.TransportToX( clusterData[islice].X( iFirstHit ), .99 );
761
762 AliExternalTrackParam tp;
763 AliHLTTPCCATrackConvertor::GetExtParam( par, tp, 0 );
764
765 currOutTracklet->fX = tp.GetX();
766 currOutTracklet->fY = tp.GetY();
767 currOutTracklet->fZ = tp.GetZ();
768 currOutTracklet->fCharge = ( int ) tp.GetSign();
769 currOutTracklet->fPt = TMath::Abs( tp.GetSignedPt() );
770 float snp = tp.GetSnp() ;
771 if ( snp > .999 ) snp = .999;
772 if ( snp < -.999 ) snp = -.999;
773 currOutTracklet->fPsi = TMath::ASin( snp );
774 currOutTracklet->fTgl = tp.GetTgl();
775
776 currOutTracklet->fY0err = tp.GetSigmaY2();
777 currOutTracklet->fZ0err = tp.GetSigmaZ2();
778 float h = -currOutTracklet->fPt * currOutTracklet->fPt;
779 currOutTracklet->fPterr = h * h * tp.GetSigma1Pt2();
780 h = 1. / TMath::Sqrt( 1 - snp * snp );
781 currOutTracklet->fPsierr = h * h * tp.GetSigmaSnp2();
782 currOutTracklet->fTglerr = tp.GetSigmaTgl2();
783
784 if ( par.TransportToX( clusterData[islice].X( iLastHit ), .99 ) ) {
785 currOutTracklet->fLastX = par.GetX();
786 currOutTracklet->fLastY = par.GetY();
787 currOutTracklet->fLastZ = par.GetZ();
788 } else {
789 currOutTracklet->fLastX = clusterData[islice].X( iLastHit );
790 currOutTracklet->fLastY = clusterData[islice].Y( iLastHit );
791 currOutTracklet->fLastZ = clusterData[islice].Z( iLastHit );
792 }
793 //if( currOutTracklet->fLastX<10. ) {
794 //HLTError("CA last point: hitxyz=%f,%f,%f, track=%f,%f,%f, tracklet=%f,%f,%f, nhits=%d",clusterData[islice].X( iLastHit ),clusterData[islice].Y( iLastHit],clusterData[islice].Z( iLastHit],
795 //par.GetX(), par.GetY(),par.GetZ(),currOutTracklet->fLastX,currOutTracklet->fLastY ,currOutTracklet->fLastZ, t.NHits());
796 //}
797 #ifdef INCLUDE_TPC_HOUGH
798 #ifdef ROWHOUGHPARAMS
799 currOutTracklet->fTrackID = 0;
800 currOutTracklet->fRowRange1 = clusterData[islice].RowNumber( iFirstHit );
801 currOutTracklet->fRowRange2 = clusterData[islice].RowNumber( iLastHit );
802 currOutTracklet->fSector = slice;
803 currOutTracklet->fPID = 211;
804 #endif
805 #endif // INCLUDE_TPC_HOUGH
806
807
808 currOutTracklet->fNPoints = t.NHits();
809
810 for ( int i = 0; i < t.NHits(); i++ ) {
811 currOutTracklet->fPointIDs[i] = clusterData[islice].Id( sliceOutput[islice]->OutTrackHit(t.FirstHitRef()+i) );
812 }
813
814 currOutTracklet = ( AliHLTTPCTrackSegmentData* )( ( Byte_t * )currOutTracklet + dSize );
815 mySize += dSize;
816 outPtr->fTrackletCnt++;
817 }
818
819 } else { // default output type
c7d6f78b 820
821 Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reconstruct",
822 "%d tracks found for slice %d", sliceOutput[islice]->NTracks(), slice );
823
d4594e7d 824 mySize += sliceOutput[islice]->OutputMemorySize();
825 ntracks += sliceOutput[islice]->NTracks();
826 }
827 }
828 else
829 {
830 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), tracks are not stored", maxBufferSize, mySize );
831 mySize = 0;
832 ret = -ENOSPC;
833 ntracks = 0;
834 error = 1;
835 break;
836 }
cf471b1e 837 }
fbb9b71b 838
d4594e7d 839 size = 0;
840 if (error == 0)
841 {
842 for (int islice = 0;islice < slicecount;islice++)
843 {
844 slice = minslice + islice;
845 if (!fOutputTRAKSEGS) mySize = sliceOutput[islice]->OutputMemorySize();
846 if (mySize > 0)
847 {
848 AliHLTComponentBlockData bd;
849 FillBlockData( bd );
850 bd.fOffset = fOutputTRAKSEGS ? 0 : ((char*) sliceOutput[islice] - (char*) outputPtr);
851 bd.fSize = mySize;
852 bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, sliceminPatch[islice], slicemaxPatch[islice] );
853 bd.fDataType = GetOutputDataType();
854 outputBlocks.push_back( bd );
855 size += mySize;
856 }
857 }
e1f2d1c3 858 }
d4594e7d 859
860 //No longer needed
861 delete[] clusterData;
862 //These are only temporary pointers to the output and no longer needed
863 delete[] sliceOutput;
fbb9b71b 864
d54804bf 865 timer.Stop();
866
fbb9b71b 867 fFullTime += timer.RealTime();
868 fRecoTime += timerReco.RealTime();
d54804bf 869 fNEvents++;
dc4788ec 870
871 // Set log level to "Warning" for on-line system monitoring
fbb9b71b 872 int hz = ( int ) ( fFullTime > 1.e-10 ? fNEvents / fFullTime : 100000 );
873 int hz1 = ( int ) ( fRecoTime > 1.e-10 ? fNEvents / fRecoTime : 100000 );
d4594e7d 874 //Min and Max Patch are taken for first slice processed...
875 HLTInfo( "CATracker slices %d-%d: output %d tracks; input %d clusters, patches %d..%d, rows %d..%d; time: full %d / reco %d Hz",
876 minslice, maxslice, ntracks, nClustersTotalSum, sliceminPatch[0], slicemaxPatch[0], slicerow[0], slicerow[1], hz, hz1 );
dc4788ec 877
4c256004 878 return ret;
cf471b1e 879}
880
fbb9b71b 881