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