]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/tracking-ca/AliHLTTPCCATrackerComponent.cxx
histogram cast requested by R.Vernet
[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"
d54804bf 34#include "AliHLTTPCCAParam.h"
eb30eb49 35#include "AliHLTTPCCATrackConvertor.h"
4acc2401 36#include "AliHLTArray.h"
cf471b1e 37
cf471b1e 38#include "AliHLTTPCSpacePointData.h"
cf471b1e 39#include "AliHLTTPCClusterDataFormat.h"
751d16ac 40#include "AliHLTTPCCACompressedInputData.h"
cf471b1e 41#include "AliHLTTPCTransform.h"
42#include "AliHLTTPCTrackSegmentData.h"
43#include "AliHLTTPCTrackArray.h"
44#include "AliHLTTPCTrackletDataFormat.h"
45#include "AliHLTTPCDefinitions.h"
d54804bf 46#include "AliExternalTrackParam.h"
cf471b1e 47#include "TMath.h"
53a9c37c 48#include "AliCDBEntry.h"
49#include "AliCDBManager.h"
50#include "TObjString.h"
51#include "TObjArray.h"
e1f2d1c3 52#include "AliHLTTPCCASliceOutput.h"
4acc2401 53#include "AliHLTTPCCAClusterData.h"
e1f2d1c3 54
55const AliHLTComponentDataType AliHLTTPCCADefinitions::fgkTrackletsDataType = AliHLTComponentDataTypeInitializer( "CATRACKL", kAliHLTDataOriginTPC );
56
57/** ROOT macro for the implementation of ROOT specific class methods */
fbb9b71b 58ClassImp( AliHLTTPCCATrackerComponent )
cf471b1e 59
cf471b1e 60AliHLTTPCCATrackerComponent::AliHLTTPCCATrackerComponent()
fbb9b71b 61 :
62 fTracker( NULL ),
63 fSolenoidBz( 0 ),
64 fMinNTrackClusters( 0 ),
65 fClusterZCut( 500. ),
f0fb467d 66 fNeighboursSearchArea( 0 ),
67 fClusterErrorCorrectionY(0),
68 fClusterErrorCorrectionZ(0),
57a4102f 69 fBenchmark("CATracker"),
fd6816cd 70 fAllowGPU( 0)
cf471b1e 71{
72 // see header file for class documentation
73 // or
74 // refer to README to build package
75 // or
76 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
77}
78
fbb9b71b 79AliHLTTPCCATrackerComponent::AliHLTTPCCATrackerComponent( const AliHLTTPCCATrackerComponent& )
80 :
81 AliHLTProcessor(),
82 fTracker( NULL ),
83 fSolenoidBz( 0 ),
84 fMinNTrackClusters( 30 ),
85 fClusterZCut( 500. ),
f0fb467d 86 fNeighboursSearchArea(0),
87 fClusterErrorCorrectionY(0),
88 fClusterErrorCorrectionZ(0),
57a4102f 89 fBenchmark("CATracker"),
fd6816cd 90 fAllowGPU( 0)
cf471b1e 91{
92 // see header file for class documentation
fbb9b71b 93 HLTFatal( "copy constructor untested" );
cf471b1e 94}
95
fbb9b71b 96AliHLTTPCCATrackerComponent& AliHLTTPCCATrackerComponent::operator=( const AliHLTTPCCATrackerComponent& )
cf471b1e 97{
98 // see header file for class documentation
fbb9b71b 99 HLTFatal( "assignment operator untested" );
cf471b1e 100 return *this;
101}
102
103AliHLTTPCCATrackerComponent::~AliHLTTPCCATrackerComponent()
4c256004 104{
cf471b1e 105 // see header file for class documentation
3a4ab1ca 106 if (fTracker) delete fTracker;
4c256004 107}
cf471b1e 108
4c256004 109//
cf471b1e 110// Public functions to implement AliHLTComponent's interface.
111// These functions are required for the registration process
4c256004 112//
cf471b1e 113
fbb9b71b 114const char* AliHLTTPCCATrackerComponent::GetComponentID()
4c256004 115{
cf471b1e 116 // see header file for class documentation
4c256004 117 return "TPCCATracker";
118}
cf471b1e 119
fbb9b71b 120void AliHLTTPCCATrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
4c256004 121{
cf471b1e 122 // see header file for class documentation
4c256004 123 list.clear();
64fc3975 124 list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
751d16ac 125 list.push_back( AliHLTTPCCADefinitions::fgkCompressedInputDataType );
4c256004 126}
cf471b1e 127
fbb9b71b 128AliHLTComponentDataType AliHLTTPCCATrackerComponent::GetOutputDataType()
4c256004 129{
cf471b1e 130 // see header file for class documentation
5cb6ddd4 131 return AliHLTTPCCADefinitions::fgkTrackletsDataType;
4c256004 132}
cf471b1e 133
fbb9b71b 134void AliHLTTPCCATrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
4c256004 135{
136 // define guess for the output data size
137 constBase = 200; // minimum size
751d16ac 138 inputMultiplier = 3.; // size relative to input
4c256004 139}
cf471b1e 140
fbb9b71b 141AliHLTComponent* AliHLTTPCCATrackerComponent::Spawn()
4c256004 142{
cf471b1e 143 // see header file for class documentation
4c256004 144 return new AliHLTTPCCATrackerComponent;
145}
cf471b1e 146
768b27af 147void AliHLTTPCCATrackerComponent::SetDefaultConfiguration()
4c256004 148{
c26cae51 149 // Set default configuration for the CA tracker component
768b27af 150 // Some parameters can be later overwritten from the OCDB
d54804bf 151
a8714ffa 152 fSolenoidBz = -5.00668;
53a9c37c 153 fMinNTrackClusters = 0;
154 fClusterZCut = 500.;
f0fb467d 155 fNeighboursSearchArea = 0;
156 fClusterErrorCorrectionY = 0;
157 fClusterErrorCorrectionZ = 0;
57a4102f 158 fBenchmark.Reset();
159 fBenchmark.SetTimer(0,"total");
160 fBenchmark.SetTimer(1,"reco");
768b27af 161}
d54804bf 162
768b27af 163int AliHLTTPCCATrackerComponent::ReadConfigurationString( const char* arguments )
164{
165 // Set configuration parameters for the CA tracker component from the string
d54804bf 166
fbb9b71b 167 int iResult = 0;
768b27af 168 if ( !arguments ) return iResult;
c26cae51 169
768b27af 170 TString allArgs = arguments;
171 TString argument;
172 int bMissingParam = 0;
eb30eb49 173
768b27af 174 TObjArray* pTokens = allArgs.Tokenize( " " );
175
176 int nArgs = pTokens ? pTokens->GetEntries() : 0;
c26cae51 177
768b27af 178 for ( int i = 0; i < nArgs; i++ ) {
179 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
180 if ( argument.IsNull() ) continue;
c26cae51 181
768b27af 182 if ( argument.CompareTo( "-solenoidBz" ) == 0 ) {
183 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
75970b8d 184 HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
768b27af 185 continue;
c26cae51 186 }
768b27af 187
188 if ( argument.CompareTo( "-minNClustersOnTrack" ) == 0 ) {
189 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
190 fMinNTrackClusters = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
191 HLTInfo( "minNClustersOnTrack set to: %d", fMinNTrackClusters );
192 continue;
193 }
c26cae51 194
768b27af 195 if ( argument.CompareTo( "-clusterZCut" ) == 0 ) {
196 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
197 fClusterZCut = TMath::Abs( ( ( TObjString* )pTokens->At( i ) )->GetString().Atof() );
198 HLTInfo( "ClusterZCut set to: %f", fClusterZCut );
199 continue;
200 }
f0fb467d 201
202 if ( argument.CompareTo( "-neighboursSearchArea" ) == 0 ) {
203 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
204 fNeighboursSearchArea = TMath::Abs( ( ( TObjString* )pTokens->At( i ) )->GetString().Atof() );
205 HLTInfo( "NeighboursSearchArea set to: %f", fNeighboursSearchArea );
206 continue;
207 }
c26cae51 208
f0fb467d 209 if ( argument.CompareTo( "-errorCorrectionY" ) == 0 ) {
210 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
211 fClusterErrorCorrectionY = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
212 HLTInfo( "Cluster Y error correction factor set to: %f", fClusterErrorCorrectionY );
213 continue;
214 }
215
216 if ( argument.CompareTo( "-errorCorrectionZ" ) == 0 ) {
217 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
218 fClusterErrorCorrectionZ = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
219 HLTInfo( "Cluster Z error correction factor set to: %f", fClusterErrorCorrectionZ );
220 continue;
221 }
222
fd6816cd 223 if (argument.CompareTo( "-allowGPU" ) == 0) {
224 fAllowGPU = 1;
225 HLTImportant( "Will try to run tracker on GPU" );
226 continue;
227 }
c26cae51 228
768b27af 229 HLTError( "Unknown option \"%s\"", argument.Data() );
230 iResult = -EINVAL;
4c256004 231 }
768b27af 232 delete pTokens;
233
234 if ( bMissingParam ) {
235 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
236 iResult = -EINVAL;
fbb9b71b 237 }
c26cae51 238
53a9c37c 239 return iResult;
4c256004 240}
cf471b1e 241
53a9c37c 242
768b27af 243int AliHLTTPCCATrackerComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
4c256004 244{
cf471b1e 245 // see header file for class documentation
cf471b1e 246
c26cae51 247 const char* defaultNotify = "";
e1f2d1c3 248
c26cae51 249 if ( !cdbEntry ) {
250 cdbEntry = "HLT/ConfigTPC/TPCCATracker";
251 defaultNotify = " (default)";
768b27af 252 chainId = 0;
253 }
53a9c37c 254
c26cae51 255 HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
256 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
fbb9b71b 257
c26cae51 258 if ( !pEntry ) {
259 HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
260 return -EINVAL;
53a9c37c 261 }
768b27af 262
c26cae51 263 TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
768b27af 264
c26cae51 265 if ( !pString ) {
266 HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
267 return -EINVAL;
53a9c37c 268 }
fbb9b71b 269
c26cae51 270 HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
fbb9b71b 271
768b27af 272 return ReadConfigurationString( pString->GetString().Data() );
273}
274
275
17d6eada 276int AliHLTTPCCATrackerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
277{
c26cae51 278 // Configure the component
279 // There are few levels of configuration,
17d6eada 280 // parameters which are set on one step can be overwritten on the next step
c26cae51 281
17d6eada 282 //* read hard-coded values
283
c26cae51 284 SetDefaultConfiguration();
17d6eada 285
286 //* read the default CDB entry
c26cae51 287
17d6eada 288 int iResult1 = ReadCDBEntry( NULL, chainId );
c26cae51 289
17d6eada 290 //* read magnetic field
c26cae51 291
a098ab46 292 int iResult2 = 0; //ReadCDBEntry( kAliHLTCDBSolenoidBz, chainId );
75970b8d 293 fSolenoidBz = GetBz();
c26cae51 294
17d6eada 295 //* read the actual CDB entry if required
c26cae51 296
297 int iResult3 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
298
17d6eada 299 //* read extra parameters from input (if they are)
300
301 int iResult4 = 0;
c26cae51 302
303 if ( commandLine && commandLine[0] != '\0' ) {
304 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
305 iResult4 = ReadConfigurationString( commandLine );
17d6eada 306 }
307
308 // Initialise the tracker here
c26cae51 309
310 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : ( iResult3 ? iResult3 : iResult4 ) );
17d6eada 311}
312
768b27af 313int AliHLTTPCCATrackerComponent::DoInit( int argc, const char** argv )
314{
315 // Configure the CA tracker component
316
d4594e7d 317 if ( fTracker ) return EINPROGRESS;
c26cae51 318
768b27af 319 TString arguments = "";
320 for ( int i = 0; i < argc; i++ ) {
321 if ( !arguments.IsNull() ) arguments += " ";
322 arguments += argv[i];
fbb9b71b 323 }
c26cae51 324
1e63725a 325 int retVal = Configure( NULL, NULL, arguments.Data() );
326 if (retVal == 0) fTracker = new AliHLTTPCCATrackerFramework(fAllowGPU);
327 return(retVal);
53a9c37c 328}
329
768b27af 330int AliHLTTPCCATrackerComponent::DoDeinit()
eb30eb49 331{
768b27af 332 // see header file for class documentation
3a4ab1ca 333 if (fTracker) delete fTracker;
768b27af 334 fTracker = NULL;
335 return 0;
eb30eb49 336}
337
768b27af 338int AliHLTTPCCATrackerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
53a9c37c 339{
17d6eada 340 // Reconfigure the component from OCDB .
fbb9b71b 341
17d6eada 342 return Configure( cdbEntry, chainId, NULL );
53a9c37c 343}
53a9c37c 344
768b27af 345bool AliHLTTPCCATrackerComponent::CompareClusters( AliHLTTPCSpacePointData *a, AliHLTTPCSpacePointData *b )
346{
347 //* Comparison function for sort clusters
348
349 if ( a->fPadRow < b->fPadRow ) return 1;
350 if ( a->fPadRow > b->fPadRow ) return 0;
351 return ( a->fZ < b->fZ );
352}
353
53a9c37c 354
fbb9b71b 355
356int AliHLTTPCCATrackerComponent::DoEvent
357(
358 const AliHLTComponentEventData& evtData,
359 const AliHLTComponentBlockData* blocks,
360 AliHLTComponentTriggerData& /*trigData*/,
361 AliHLTUInt8_t* outputPtr,
362 AliHLTUInt32_t& size,
363 vector<AliHLTComponentBlockData>& outputBlocks )
cf471b1e 364{
768b27af 365 //* process event
366
00d07bcd 367 AliHLTUInt32_t maxBufferSize = size;
dc4788ec 368 size = 0; // output size
369
fbb9b71b 370 if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) ) {
eb30eb49 371 return 0;
372 }
373
57a4102f 374 fBenchmark.StartNewEvent();
375 fBenchmark.Start(0);
dc4788ec 376
4c256004 377 // Event reconstruction in one TPC slice with CA Tracker
fbb9b71b 378
d54804bf 379 //Logging( kHLTLogWarning, "HLT::TPCCATracker::DoEvent", "DoEvent", "CA::DoEvent()" );
fbb9b71b 380 if ( evtData.fBlockCnt <= 0 ) {
381 HLTWarning( "no blocks in event" );
382 return 0;
383 }
384
cf471b1e 385 const AliHLTComponentBlockData* iter = NULL;
386 unsigned long ndx;
fbb9b71b 387
388 // Determine the slice number
389
d4594e7d 390 //Find min and max slice number with now slice missing in between (for default output)
391 int minslice = -1, maxslice = -1;
fbb9b71b 392 int slice = -1;
4c256004 393 {
fbb9b71b 394 std::vector<int> slices;
395 std::vector<int>::iterator slIter;
4acc2401 396 std::vector<unsigned> sliceCnts;
397 std::vector<unsigned>::iterator slCntIter;
fbb9b71b 398
399 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) {
400 iter = blocks + ndx;
64fc3975 401 if ( iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType &&
2f516e61 402 iter->fDataType != AliHLTTPCCADefinitions::fgkCompressedInputDataType
751d16ac 403 ) continue;
4c256004 404
cf471b1e 405 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
d4594e7d 406 if (slice < minslice || minslice == -1) minslice = slice;
407 if (slice > maxslice) maxslice = slice;
dc4788ec 408
fbb9b71b 409 bool found = 0;
cf471b1e 410 slCntIter = sliceCnts.begin();
fbb9b71b 411 for ( slIter = slices.begin(); slIter != slices.end(); slIter++, slCntIter++ ) {
412 if ( *slIter == slice ) {
413 found = kTRUE;
414 break;
415 }
4c256004 416 }
fbb9b71b 417 if ( !found ) {
418 slices.push_back( slice );
419 sliceCnts.push_back( 1 );
90da1ad5 420 } else (*slCntIter)++;
cf471b1e 421 }
fbb9b71b 422
d4594e7d 423 if ( slices.size() == 0 ) {
424 HLTWarning( "no slices found in event" );
425 return 0;
426 }
fbb9b71b 427
d4594e7d 428
429 // Determine slice number to really use. (for obsolete output)
fbb9b71b 430 if ( slices.size() > 1 ) {
5cb6ddd4 431 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
fbb9b71b 432 "Multiple slice numbers found in event 0x%08lX (%lu). Determining maximum occuring slice number...",
433 evtData.fEventID, evtData.fEventID );
fbb9b71b 434 slCntIter = sliceCnts.begin();
435 for ( slIter = slices.begin(); slIter != slices.end(); slIter++, slCntIter++ ) {
5cb6ddd4 436 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
fbb9b71b 437 "Slice %lu found %lu times.", *slIter, *slCntIter );
4c256004 438 }
fbb9b71b 439 } else if ( slices.size() > 0 ) {
440 slice = *( slices.begin() );
441 }
4c256004 442
4c256004 443
5cb6ddd4 444 for (int islice = minslice;islice <= maxslice;islice++)
445 {
446 bool found = false;
447 for(slIter = slices.begin(); slIter != slices.end();slIter++)
d4594e7d 448 {
5cb6ddd4 449 if (*slIter == islice)
450 {
451 found = true;
452 break;
453 }
d4594e7d 454 }
5cb6ddd4 455 if (!found)
d4594e7d 456 {
5cb6ddd4 457 maxslice = islice - 1;
458 break;
459 }
460 }
d4594e7d 461 }
fbb9b71b 462
fd6816cd 463 if ( !fTracker ) fTracker = new AliHLTTPCCATrackerFramework(fAllowGPU);
3a4ab1ca 464
d4594e7d 465 int slicecount = maxslice + 1 - minslice;
466 if (slicecount > fTracker->MaxSliceCount())
cf471b1e 467 {
90da1ad5 468 maxslice = minslice + (slicecount = fTracker->MaxSliceCount()) - 1;
cf471b1e 469 }
d4594e7d 470 int nClustersTotalSum = 0;
471 AliHLTTPCCAClusterData* clusterData = new AliHLTTPCCAClusterData[slicecount];
cf471b1e 472
fbb9b71b 473
4c256004 474 // min and max patch numbers and row numbers
d4594e7d 475 int* slicerow = new int[slicecount * 2];
476 int* sliceminPatch = new int[slicecount];
477 int* slicemaxPatch = new int[slicecount];
478 memset(slicerow, 0, slicecount * 2 * sizeof(int));
479 for (int i = 0;i < slicecount;i++)
480 {
481 sliceminPatch[i] = 100;
482 slicemaxPatch[i] = -1;
cf471b1e 483 }
fbb9b71b 484
d4594e7d 485 //Prepare everything for all slices
4c256004 486
d4594e7d 487 for (int islice = 0;islice < slicecount;islice++)
488 {
489 slice = minslice + islice;
490
491 // Initialize the tracker slice
492 {
493 int iSec = slice;
494 float inRmin = 83.65;
495 // float inRmax = 133.3;
496 // float outRmin = 133.5;
497 float outRmax = 247.7;
498 float plusZmin = 0.0529937;
499 float plusZmax = 249.778;
500 float minusZmin = -249.645;
501 float minusZmax = -0.0799937;
502 float dalpha = 0.349066;
503 float alpha = 0.174533 + dalpha * iSec;
504
505 bool zPlus = ( iSec < 18 );
506 float zMin = zPlus ? plusZmin : minusZmin;
507 float zMax = zPlus ? plusZmax : minusZmax;
508 //TPCZmin = -249.645, ZMax = 249.778
509 // float rMin = inRmin;
510 // float rMax = outRmax;
511 int nRows = AliHLTTPCTransform::GetNRows();
512
513 float padPitch = 0.4;
514 float sigmaZ = 0.228808;
515
516 float *rowX = new float [nRows];
517 for ( int irow = 0; irow < nRows; irow++ ) {
518 rowX[irow] = AliHLTTPCTransform::Row2X( irow );
519 }
520
521 AliHLTTPCCAParam param;
522
523 param.Initialize( iSec, nRows, rowX, alpha, dalpha,
524 inRmin, outRmax, zMin, zMax, padPitch, sigmaZ, fSolenoidBz );
525 param.SetHitPickUpFactor( 2 );
526 if( fNeighboursSearchArea>0 ) param.SetNeighboursSearchArea( fNeighboursSearchArea );
527 if( fClusterErrorCorrectionY>1.e-4 ) param.SetClusterError2CorrectionY( fClusterErrorCorrectionY*fClusterErrorCorrectionY );
528 if( fClusterErrorCorrectionZ>1.e-4 ) param.SetClusterError2CorrectionZ( fClusterErrorCorrectionZ*fClusterErrorCorrectionZ );
529 param.Update();
530 fTracker->InitializeSliceParam( slice, param );
531 delete[] rowX;
532 }
533
534 // total n Hits
535 int nClustersTotal = 0;
536
537 // sort patches
538 std::vector<unsigned long> patchIndices;
539
540 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) {
541 iter = blocks + ndx;
d4594e7d 542 if ( slice != AliHLTTPCDefinitions::GetMinSliceNr( *iter ) ) continue;
64fc3975 543 if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType ){
544 AliHLTTPCClusterData* inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
545 nClustersTotal += inPtrSP->fSpacePointCnt;
57a4102f 546 fBenchmark.AddInput(iter->fSize);
64fc3975 547 } else
2f516e61 548 if ( iter->fDataType == AliHLTTPCCADefinitions::fgkCompressedInputDataType){
57a4102f 549 fBenchmark.AddInput(iter->fSize);
751d16ac 550 const AliHLTUInt8_t * inPtr = (const AliHLTUInt8_t *)iter->fPtr;
551 while( inPtr< ((const AliHLTUInt8_t *) iter->fPtr) + iter->fSize ){
552 AliHLTTPCCACompressedClusterRow *row = (AliHLTTPCCACompressedClusterRow*)inPtr;
553 nClustersTotal+= row->fNClusters;
554 inPtr = (const AliHLTUInt8_t *)(row->fClusters+row->fNClusters);
555 }
556 }
557 else continue;
558
d4594e7d 559 int patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
560 if ( sliceminPatch[islice] > patch ) {
561 sliceminPatch[islice] = patch;
562 slicerow[2 * islice + 0] = AliHLTTPCTransform::GetFirstRow( patch );
563 }
564 if ( slicemaxPatch[islice] < patch ) {
565 slicemaxPatch[islice] = patch;
566 slicerow[2 * islice + 1] = AliHLTTPCTransform::GetLastRow( patch );
567 }
568 std::vector<unsigned long>::iterator pIter = patchIndices.begin();
569 while ( pIter != patchIndices.end() && AliHLTTPCDefinitions::GetMinPatchNr( blocks[*pIter] ) < patch ) {
570 pIter++;
571 }
572 patchIndices.insert( pIter, ndx );
573 }
574
575
576 // pass event to CA Tracker
577
578
579 Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reading hits",
580 "Total %d hits to read for slice %d", nClustersTotal, slice );
581
582
583 clusterData[islice].StartReading( slice, nClustersTotal );
584
585 for ( std::vector<unsigned long>::iterator pIter = patchIndices.begin(); pIter != patchIndices.end(); pIter++ ) {
586 ndx = *pIter;
587 iter = blocks + ndx;
d4594e7d 588 int patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
751d16ac 589 int nPatchClust = 0;
64fc3975 590
751d16ac 591 if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType ){
592 AliHLTTPCClusterData* inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
593 nPatchClust = inPtrSP->fSpacePointCnt;
594 for ( unsigned int i = 0; i < inPtrSP->fSpacePointCnt; i++ ) {
595 AliHLTTPCSpacePointData *c = &( inPtrSP->fSpacePoints[i] );
596 if ( CAMath::Abs( c->fZ ) > fClusterZCut ) continue;
597 if ( c->fPadRow > 159 ) {
598 HLTError( "Wrong TPC cluster with row number %d received", c->fPadRow );
599 continue;
600 }
601 clusterData[islice].ReadCluster( c->fID, c->fPadRow, c->fX, c->fY, c->fZ, c->fCharge );
602 }
64fc3975 603 } else
2f516e61 604 if ( iter->fDataType == AliHLTTPCCADefinitions::fgkCompressedInputDataType){
751d16ac 605 const AliHLTUInt8_t * inPtr = (const AliHLTUInt8_t *)iter->fPtr;
606 nPatchClust=0;
607 while( inPtr< ((const AliHLTUInt8_t *)iter->fPtr) + iter->fSize ){
608 AliHLTTPCCACompressedClusterRow *row = (AliHLTTPCCACompressedClusterRow*)inPtr;
609 UInt_t id = row->fSlicePatchRowID;
610 UInt_t jslice = id>>10;
611 UInt_t jpatch = (id>>6) & 0x7;
612 UInt_t jrow = id & 0x3F;
613 jrow+= AliHLTTPCTransform::GetFirstRow( jpatch );
614 Double_t rowX = AliHLTTPCTransform::Row2X( jrow );
615 //cout<<"Read row: s "<<jslice<<" p "<<jpatch<<" r "<<jrow<<" x "<<row->fX<<" nclu "<<row->fNClusters<<" :"<<endl;
616 if( jrow > 159 ) {
617 HLTError( "Wrong TPC cluster with row number %d received", jrow );
618 continue;
619 }
620 for ( unsigned int i = 0; i < row->fNClusters; i++ ) {
621 AliHLTTPCCACompressedCluster *c = &( row->fClusters[i] );
622
623 UInt_t ix0 = c->fP0 >>24;
624 UInt_t ix1 = c->fP1 >>24;
625 Double_t x = (ix1<<8) + ix0;
626 Double_t y = c->fP0 & 0x00FFFFFF;
627 Double_t z = c->fP1 & 0x00FFFFFF;
628 x = (x - 32768.)*1.e-4 + rowX;
629 y = (y - 8388608.)*1.e-4;
630 z = (z - 8388608.)*1.e-4;
631
632 UInt_t cluId = nPatchClust + ((jslice&0x7f)<<25)+((jpatch&0x7)<<22);
633 //cout<<"clu "<<i<<": "<<x<<" "<<y<<" "<<z<<" "<<cluId<<endl;
634 if ( CAMath::Abs( z ) <= fClusterZCut ){
635 clusterData[islice].ReadCluster( cluId, jrow, x, y, z, 0 );
636 }
637 nPatchClust++;
638 }
639 inPtr = (const AliHLTUInt8_t *)(row->fClusters+row->fNClusters);
d4594e7d 640 }
d4594e7d 641 }
751d16ac 642 Logging( kHLTLogInfo, "HLT::TPCCATracker::DoEvent", "Reading hits",
643 "Read %d hits for slice %d - patch %d", nPatchClust, slice, patch );
d4594e7d 644 }
645
646 clusterData[islice].FinishReading();
647 nClustersTotalSum += nClustersTotal;
648 }
fbb9b71b 649
d4594e7d 650 //Prepare Output
651 AliHLTTPCCASliceOutput::outputControlStruct outputControl;
652 //Set tracker output so tracker does not have to output both formats!
90da1ad5 653 outputControl.fEndOfSpace = 0;
fbb9b71b 654
d4594e7d 655 //For new output we can write directly to output buffer
5cb6ddd4 656 outputControl.fOutputPtr = (char*) outputPtr;
d4594e7d 657 outputControl.fOutputMaxSize = maxBufferSize;
4c256004 658
d4594e7d 659 AliHLTTPCCASliceOutput** sliceOutput = new AliHLTTPCCASliceOutput*[slicecount];
660 memset(sliceOutput, 0, slicecount * sizeof(AliHLTTPCCASliceOutput*));
b8139972 661
fbb9b71b 662 // reconstruct the event
57a4102f 663
664 fBenchmark.Start(1);
d4594e7d 665 fTracker->SetOutputControl(&outputControl);
666 fTracker->ProcessSlices(minslice, slicecount, clusterData, sliceOutput);
57a4102f 667 fBenchmark.Stop(1);
d4594e7d 668
fbb9b71b 669 int ret = 0;
fbb9b71b 670 unsigned int mySize = 0;
a59a784e 671 int ntracks = 0;
d4594e7d 672 int error = 0;
fbb9b71b 673
d4594e7d 674 for (int islice = 0;islice < slicecount;islice++)
675 {
90da1ad5 676 if( outputControl.fEndOfSpace ){
677 HLTWarning( "Output buffer size exceed, tracks are not stored" );
678 ret = -ENOSPC;
679 error = 1;
680 break;
681 }
5cb6ddd4 682 slice = minslice + islice;
683
684 if (sliceOutput[islice])
685 {
686 // write reconstructed tracks
687 Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reconstruct",
688 "%d tracks found for slice %d", sliceOutput[islice]->NTracks(), slice );
689
0f1f07c3 690 mySize += sliceOutput[islice]->Size();
5cb6ddd4 691 ntracks += sliceOutput[islice]->NTracks();
692 }
693 else
694 {
695 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), tracks are not stored", maxBufferSize, mySize );
696 mySize = 0;
697 ret = -ENOSPC;
698 ntracks = 0;
699 error = 1;
700 break;
701 }
cf471b1e 702 }
5cb6ddd4 703
d4594e7d 704 size = 0;
705 if (error == 0)
706 {
5cb6ddd4 707 for (int islice = 0;islice < slicecount;islice++)
708 {
709 slice = minslice + islice;
0f1f07c3 710 mySize = sliceOutput[islice]->Size();
5cb6ddd4 711 if (mySize > 0)
d4594e7d 712 {
5cb6ddd4 713 AliHLTComponentBlockData bd;
714 FillBlockData( bd );
715 bd.fOffset = ((char*) sliceOutput[islice] - (char*) outputPtr);
716 bd.fSize = mySize;
717 bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, sliceminPatch[islice], slicemaxPatch[islice] );
718 bd.fDataType = GetOutputDataType();
719 outputBlocks.push_back( bd );
720 size += mySize;
57a4102f 721 fBenchmark.AddOutput(bd.fSize);
d4594e7d 722 }
5cb6ddd4 723 }
e1f2d1c3 724 }
d4594e7d 725
57a4102f 726
d4594e7d 727 //No longer needed
44ec922a 728
d4594e7d 729 delete[] clusterData;
d4594e7d 730 delete[] sliceOutput;
fbb9b71b 731
57a4102f 732 fBenchmark.Stop(0);
dc4788ec 733
734 // Set log level to "Warning" for on-line system monitoring
57a4102f 735
d4594e7d 736 //Min and Max Patch are taken for first slice processed...
dc4788ec 737
57a4102f 738 if( minslice==maxslice ) fBenchmark.SetName(Form("CATracker slice %d",minslice));
739 else fBenchmark.SetName(Form("CATracker slices %d-%d",minslice,maxslice));
740
741 HLTInfo(fBenchmark.GetStatistics());
c24ec5c8 742 //No longer needed
743
744 delete[] slicerow;
745 delete[] sliceminPatch;
746 delete[] slicemaxPatch;
747
4c256004 748 return ret;
cf471b1e 749}
750
fbb9b71b 751