]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/tracking-ca/AliHLTTPCCATrackerComponent.cxx
Store list of fired trigger classes.
[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
4c256004 112 delete fTracker;
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
330 fTracker = new AliHLTTPCCATrackerFramework();
768b27af 331
332 TString arguments = "";
333 for ( int i = 0; i < argc; i++ ) {
334 if ( !arguments.IsNull() ) arguments += " ";
335 arguments += argv[i];
fbb9b71b 336 }
c26cae51 337
338 return Configure( NULL, NULL, arguments.Data() );
53a9c37c 339}
340
341
768b27af 342int AliHLTTPCCATrackerComponent::DoDeinit()
eb30eb49 343{
768b27af 344 // see header file for class documentation
345 delete fTracker;
346 fTracker = NULL;
347 return 0;
eb30eb49 348}
349
53a9c37c 350
768b27af 351
352int AliHLTTPCCATrackerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
53a9c37c 353{
17d6eada 354 // Reconfigure the component from OCDB .
fbb9b71b 355
17d6eada 356 return Configure( cdbEntry, chainId, NULL );
53a9c37c 357}
53a9c37c 358
359
768b27af 360bool AliHLTTPCCATrackerComponent::CompareClusters( AliHLTTPCSpacePointData *a, AliHLTTPCSpacePointData *b )
361{
362 //* Comparison function for sort clusters
363
364 if ( a->fPadRow < b->fPadRow ) return 1;
365 if ( a->fPadRow > b->fPadRow ) return 0;
366 return ( a->fZ < b->fZ );
367}
368
53a9c37c 369
fbb9b71b 370
371int AliHLTTPCCATrackerComponent::DoEvent
372(
373 const AliHLTComponentEventData& evtData,
374 const AliHLTComponentBlockData* blocks,
375 AliHLTComponentTriggerData& /*trigData*/,
376 AliHLTUInt8_t* outputPtr,
377 AliHLTUInt32_t& size,
378 vector<AliHLTComponentBlockData>& outputBlocks )
cf471b1e 379{
768b27af 380 //* process event
381
00d07bcd 382 AliHLTUInt32_t maxBufferSize = size;
dc4788ec 383 size = 0; // output size
384
fbb9b71b 385 if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) ) {
eb30eb49 386 return 0;
387 }
388
dc4788ec 389 TStopwatch timer;
390
4c256004 391 // Event reconstruction in one TPC slice with CA Tracker
fbb9b71b 392
d54804bf 393 //Logging( kHLTLogWarning, "HLT::TPCCATracker::DoEvent", "DoEvent", "CA::DoEvent()" );
fbb9b71b 394 if ( evtData.fBlockCnt <= 0 ) {
395 HLTWarning( "no blocks in event" );
396 return 0;
397 }
398
cf471b1e 399 const AliHLTComponentBlockData* iter = NULL;
400 unsigned long ndx;
fbb9b71b 401
402 // Determine the slice number
403
d4594e7d 404 //Find min and max slice number with now slice missing in between (for default output)
405 int minslice = -1, maxslice = -1;
fbb9b71b 406 int slice = -1;
4c256004 407 {
fbb9b71b 408 std::vector<int> slices;
409 std::vector<int>::iterator slIter;
4acc2401 410 std::vector<unsigned> sliceCnts;
411 std::vector<unsigned>::iterator slCntIter;
fbb9b71b 412
413 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) {
414 iter = blocks + ndx;
751d16ac 415 if ( iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType
416 && iter->fDataType != AliHLTTPCCADefinitions::fgkCompressedInputDataType
417 ) continue;
4c256004 418
cf471b1e 419 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
d4594e7d 420 if (slice < minslice || minslice == -1) minslice = slice;
421 if (slice > maxslice) maxslice = slice;
dc4788ec 422
fbb9b71b 423 bool found = 0;
cf471b1e 424 slCntIter = sliceCnts.begin();
fbb9b71b 425 for ( slIter = slices.begin(); slIter != slices.end(); slIter++, slCntIter++ ) {
426 if ( *slIter == slice ) {
427 found = kTRUE;
428 break;
429 }
4c256004 430 }
fbb9b71b 431 if ( !found ) {
432 slices.push_back( slice );
433 sliceCnts.push_back( 1 );
434 } else *slCntIter++;
cf471b1e 435 }
fbb9b71b 436
d4594e7d 437 if ( slices.size() == 0 ) {
438 HLTWarning( "no slices found in event" );
439 return 0;
440 }
fbb9b71b 441
d4594e7d 442
443 // Determine slice number to really use. (for obsolete output)
fbb9b71b 444 if ( slices.size() > 1 ) {
d4594e7d 445 Logging( fOutputTRAKSEGS ? kHLTLogError : kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
fbb9b71b 446 "Multiple slice numbers found in event 0x%08lX (%lu). Determining maximum occuring slice number...",
447 evtData.fEventID, evtData.fEventID );
4acc2401 448 unsigned maxCntSlice = 0;
fbb9b71b 449 slCntIter = sliceCnts.begin();
450 for ( slIter = slices.begin(); slIter != slices.end(); slIter++, slCntIter++ ) {
d4594e7d 451 Logging( fOutputTRAKSEGS ? kHLTLogError : kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
fbb9b71b 452 "Slice %lu found %lu times.", *slIter, *slCntIter );
d4594e7d 453 if ( fOutputTRAKSEGS && maxCntSlice < *slCntIter ) {
fbb9b71b 454 maxCntSlice = *slCntIter;
455 slice = *slIter;
456 }
4c256004 457 }
d4594e7d 458 if (fOutputTRAKSEGS)
459 {
460 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
fbb9b71b 461 "Using slice %lu.", slice );
d4594e7d 462 }
fbb9b71b 463 } else if ( slices.size() > 0 ) {
464 slice = *( slices.begin() );
465 }
4c256004 466
4c256004 467
d4594e7d 468 if (fOutputTRAKSEGS)
469 {
470 minslice = maxslice = slice;
471 }
472 else
473 {
474 for (int islice = minslice;islice <= maxslice;islice++)
475 {
476 bool found = false;
477 for(slIter = slices.begin(); slIter != slices.end();slIter++)
478 {
479 if (*slIter == islice)
480 {
481 found = true;
482 break;
483 }
484 }
485 if (!found)
486 {
487 maxslice = islice - 1;
488 break;
489 }
490 }
491 }
492 }
fbb9b71b 493
d4594e7d 494 if ( !fTracker ) fTracker = new AliHLTTPCCATrackerFramework;
495 int slicecount = maxslice + 1 - minslice;
496 if (slicecount > fTracker->MaxSliceCount())
cf471b1e 497 {
d4594e7d 498 maxslice = minslice + (slicecount = fTracker->MaxSliceCount());
cf471b1e 499 }
d4594e7d 500 int nClustersTotalSum = 0;
501 AliHLTTPCCAClusterData* clusterData = new AliHLTTPCCAClusterData[slicecount];
cf471b1e 502
fbb9b71b 503
4c256004 504 // min and max patch numbers and row numbers
d4594e7d 505 int* slicerow = new int[slicecount * 2];
506 int* sliceminPatch = new int[slicecount];
507 int* slicemaxPatch = new int[slicecount];
508 memset(slicerow, 0, slicecount * 2 * sizeof(int));
509 for (int i = 0;i < slicecount;i++)
510 {
511 sliceminPatch[i] = 100;
512 slicemaxPatch[i] = -1;
cf471b1e 513 }
fbb9b71b 514
d4594e7d 515 //Prepare everything for all slices
4c256004 516
d4594e7d 517 for (int islice = 0;islice < slicecount;islice++)
518 {
519 slice = minslice + islice;
520
521 // Initialize the tracker slice
522 {
523 int iSec = slice;
524 float inRmin = 83.65;
525 // float inRmax = 133.3;
526 // float outRmin = 133.5;
527 float outRmax = 247.7;
528 float plusZmin = 0.0529937;
529 float plusZmax = 249.778;
530 float minusZmin = -249.645;
531 float minusZmax = -0.0799937;
532 float dalpha = 0.349066;
533 float alpha = 0.174533 + dalpha * iSec;
534
535 bool zPlus = ( iSec < 18 );
536 float zMin = zPlus ? plusZmin : minusZmin;
537 float zMax = zPlus ? plusZmax : minusZmax;
538 //TPCZmin = -249.645, ZMax = 249.778
539 // float rMin = inRmin;
540 // float rMax = outRmax;
541 int nRows = AliHLTTPCTransform::GetNRows();
542
543 float padPitch = 0.4;
544 float sigmaZ = 0.228808;
545
546 float *rowX = new float [nRows];
547 for ( int irow = 0; irow < nRows; irow++ ) {
548 rowX[irow] = AliHLTTPCTransform::Row2X( irow );
549 }
550
551 AliHLTTPCCAParam param;
552
553 param.Initialize( iSec, nRows, rowX, alpha, dalpha,
554 inRmin, outRmax, zMin, zMax, padPitch, sigmaZ, fSolenoidBz );
555 param.SetHitPickUpFactor( 2 );
556 if( fNeighboursSearchArea>0 ) param.SetNeighboursSearchArea( fNeighboursSearchArea );
557 if( fClusterErrorCorrectionY>1.e-4 ) param.SetClusterError2CorrectionY( fClusterErrorCorrectionY*fClusterErrorCorrectionY );
558 if( fClusterErrorCorrectionZ>1.e-4 ) param.SetClusterError2CorrectionZ( fClusterErrorCorrectionZ*fClusterErrorCorrectionZ );
559 param.Update();
560 fTracker->InitializeSliceParam( slice, param );
561 delete[] rowX;
562 }
563
564 // total n Hits
565 int nClustersTotal = 0;
566
567 // sort patches
568 std::vector<unsigned long> patchIndices;
569
570 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) {
571 iter = blocks + ndx;
d4594e7d 572 if ( slice != AliHLTTPCDefinitions::GetMinSliceNr( *iter ) ) continue;
751d16ac 573 if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType ){
574 AliHLTTPCClusterData* inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
575 nClustersTotal += inPtrSP->fSpacePointCnt;
576 }
577 else if ( iter->fDataType == AliHLTTPCCADefinitions::fgkCompressedInputDataType){
578 const AliHLTUInt8_t * inPtr = (const AliHLTUInt8_t *)iter->fPtr;
579 while( inPtr< ((const AliHLTUInt8_t *) iter->fPtr) + iter->fSize ){
580 AliHLTTPCCACompressedClusterRow *row = (AliHLTTPCCACompressedClusterRow*)inPtr;
581 nClustersTotal+= row->fNClusters;
582 inPtr = (const AliHLTUInt8_t *)(row->fClusters+row->fNClusters);
583 }
584 }
585 else continue;
586
d4594e7d 587 int patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
588 if ( sliceminPatch[islice] > patch ) {
589 sliceminPatch[islice] = patch;
590 slicerow[2 * islice + 0] = AliHLTTPCTransform::GetFirstRow( patch );
591 }
592 if ( slicemaxPatch[islice] < patch ) {
593 slicemaxPatch[islice] = patch;
594 slicerow[2 * islice + 1] = AliHLTTPCTransform::GetLastRow( patch );
595 }
596 std::vector<unsigned long>::iterator pIter = patchIndices.begin();
597 while ( pIter != patchIndices.end() && AliHLTTPCDefinitions::GetMinPatchNr( blocks[*pIter] ) < patch ) {
598 pIter++;
599 }
600 patchIndices.insert( pIter, ndx );
601 }
602
603
604 // pass event to CA Tracker
605
606
607 Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reading hits",
608 "Total %d hits to read for slice %d", nClustersTotal, slice );
609
610
611 clusterData[islice].StartReading( slice, nClustersTotal );
612
613 for ( std::vector<unsigned long>::iterator pIter = patchIndices.begin(); pIter != patchIndices.end(); pIter++ ) {
614 ndx = *pIter;
615 iter = blocks + ndx;
d4594e7d 616 int patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
751d16ac 617 int nPatchClust = 0;
618 if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType ){
619 AliHLTTPCClusterData* inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
620 nPatchClust = inPtrSP->fSpacePointCnt;
621 for ( unsigned int i = 0; i < inPtrSP->fSpacePointCnt; i++ ) {
622 AliHLTTPCSpacePointData *c = &( inPtrSP->fSpacePoints[i] );
623 if ( CAMath::Abs( c->fZ ) > fClusterZCut ) continue;
624 if ( c->fPadRow > 159 ) {
625 HLTError( "Wrong TPC cluster with row number %d received", c->fPadRow );
626 continue;
627 }
628 clusterData[islice].ReadCluster( c->fID, c->fPadRow, c->fX, c->fY, c->fZ, c->fCharge );
629 }
630 }
631 else if ( iter->fDataType == AliHLTTPCCADefinitions::fgkCompressedInputDataType){
632 const AliHLTUInt8_t * inPtr = (const AliHLTUInt8_t *)iter->fPtr;
633 nPatchClust=0;
634 while( inPtr< ((const AliHLTUInt8_t *)iter->fPtr) + iter->fSize ){
635 AliHLTTPCCACompressedClusterRow *row = (AliHLTTPCCACompressedClusterRow*)inPtr;
636 UInt_t id = row->fSlicePatchRowID;
637 UInt_t jslice = id>>10;
638 UInt_t jpatch = (id>>6) & 0x7;
639 UInt_t jrow = id & 0x3F;
640 jrow+= AliHLTTPCTransform::GetFirstRow( jpatch );
641 Double_t rowX = AliHLTTPCTransform::Row2X( jrow );
642 //cout<<"Read row: s "<<jslice<<" p "<<jpatch<<" r "<<jrow<<" x "<<row->fX<<" nclu "<<row->fNClusters<<" :"<<endl;
643 if( jrow > 159 ) {
644 HLTError( "Wrong TPC cluster with row number %d received", jrow );
645 continue;
646 }
647 for ( unsigned int i = 0; i < row->fNClusters; i++ ) {
648 AliHLTTPCCACompressedCluster *c = &( row->fClusters[i] );
649
650 UInt_t ix0 = c->fP0 >>24;
651 UInt_t ix1 = c->fP1 >>24;
652 Double_t x = (ix1<<8) + ix0;
653 Double_t y = c->fP0 & 0x00FFFFFF;
654 Double_t z = c->fP1 & 0x00FFFFFF;
655 x = (x - 32768.)*1.e-4 + rowX;
656 y = (y - 8388608.)*1.e-4;
657 z = (z - 8388608.)*1.e-4;
658
659 UInt_t cluId = nPatchClust + ((jslice&0x7f)<<25)+((jpatch&0x7)<<22);
660 //cout<<"clu "<<i<<": "<<x<<" "<<y<<" "<<z<<" "<<cluId<<endl;
661 if ( CAMath::Abs( z ) <= fClusterZCut ){
662 clusterData[islice].ReadCluster( cluId, jrow, x, y, z, 0 );
663 }
664 nPatchClust++;
665 }
666 inPtr = (const AliHLTUInt8_t *)(row->fClusters+row->fNClusters);
d4594e7d 667 }
d4594e7d 668 }
751d16ac 669 Logging( kHLTLogInfo, "HLT::TPCCATracker::DoEvent", "Reading hits",
670 "Read %d hits for slice %d - patch %d", nPatchClust, slice, patch );
d4594e7d 671 }
672
673 clusterData[islice].FinishReading();
674 nClustersTotalSum += nClustersTotal;
675 }
fbb9b71b 676
d4594e7d 677 //Prepare Output
678 AliHLTTPCCASliceOutput::outputControlStruct outputControl;
679 //Set tracker output so tracker does not have to output both formats!
680 outputControl.fObsoleteOutput = fOutputTRAKSEGS;
681 outputControl.fDefaultOutput = !fOutputTRAKSEGS;
fbb9b71b 682
d4594e7d 683 //For new output we can write directly to output buffer
684 outputControl.fOutputPtr = fOutputTRAKSEGS ? NULL : (char*) outputPtr;
685 outputControl.fOutputMaxSize = maxBufferSize;
4c256004 686
d4594e7d 687 AliHLTTPCCASliceOutput** sliceOutput = new AliHLTTPCCASliceOutput*[slicecount];
688 memset(sliceOutput, 0, slicecount * sizeof(AliHLTTPCCASliceOutput*));
b8139972 689
fbb9b71b 690 // reconstruct the event
dc4788ec 691 TStopwatch timerReco;
d4594e7d 692 fTracker->SetOutputControl(&outputControl);
693 fTracker->ProcessSlices(minslice, slicecount, clusterData, sliceOutput);
dc4788ec 694 timerReco.Stop();
d4594e7d 695
fbb9b71b 696 int ret = 0;
fbb9b71b 697 unsigned int mySize = 0;
a59a784e 698 int ntracks = 0;
d4594e7d 699 int error = 0;
fbb9b71b 700
d4594e7d 701 for (int islice = 0;islice < slicecount;islice++)
702 {
703 slice = minslice + islice;
704
705 if (sliceOutput[islice])
706 {
d4594e7d 707 // write reconstructed tracks
fbb9b71b 708
d4594e7d 709 if ( fOutputTRAKSEGS ) {
fbb9b71b 710
c7d6f78b 711 Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reconstruct",
712 "%d tracks found for slice %d", sliceOutput[islice]->NOutTracks(), slice );
713
d4594e7d 714 ntracks = sliceOutput[islice]->NOutTracks();
fbb9b71b 715
d4594e7d 716 AliHLTTPCTrackletData* outPtr = ( AliHLTTPCTrackletData* )( outputPtr );
fbb9b71b 717
d4594e7d 718 AliHLTTPCTrackSegmentData* currOutTracklet = outPtr->fTracklets;
fbb9b71b 719
d4594e7d 720 mySize = ( ( AliHLTUInt8_t * )currOutTracklet ) - ( ( AliHLTUInt8_t * )outputPtr );
721
722 outPtr->fTrackletCnt = 0;
723
724 for ( int itr = 0; itr < ntracks; itr++ ) {
725
726 AliHLTTPCCAOutTrack &t = sliceOutput[islice]->OutTracks()[itr];
727
728 //Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Wrtite output","track %d with %d hits", itr, t.NHits());
729
730 if ( t.NHits() < fMinNTrackClusters ) continue;
731
732 // calculate output track size
733
734 unsigned int dSize = sizeof( AliHLTTPCTrackSegmentData ) + t.NHits() * sizeof( unsigned int );
735
736 if ( mySize + dSize > maxBufferSize ) {
737 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d tracks are not stored", maxBufferSize, mySize, ntracks - itr + 1 );
738 ret = -ENOSPC;
739 error = 1;
740 break;
741 }
742
743 // convert CA track parameters to HLT Track Segment
744
745 int iFirstRow = 1000;
746 int iLastRow = -1;
747 int iFirstHit = sliceOutput[islice]->OutTrackHit(t.FirstHitRef());
748 int iLastHit = iFirstHit;
749 for ( int ih = 0; ih < t.NHits(); ih++ ) {
750 int hitID = sliceOutput[islice]->OutTrackHit(t.FirstHitRef() + ih);
751 int iRow = clusterData[islice].RowNumber( hitID );
752 if ( iRow < iFirstRow ) { iFirstRow = iRow; iFirstHit = hitID; }
753 if ( iRow > iLastRow ) { iLastRow = iRow; iLastHit = hitID; }
754 }
755
756 AliHLTTPCCATrackParam par = t.StartPoint();
757
758 par.TransportToX( clusterData[islice].X( iFirstHit ), .99 );
759
760 AliExternalTrackParam tp;
761 AliHLTTPCCATrackConvertor::GetExtParam( par, tp, 0 );
762
763 currOutTracklet->fX = tp.GetX();
764 currOutTracklet->fY = tp.GetY();
765 currOutTracklet->fZ = tp.GetZ();
766 currOutTracklet->fCharge = ( int ) tp.GetSign();
767 currOutTracklet->fPt = TMath::Abs( tp.GetSignedPt() );
768 float snp = tp.GetSnp() ;
769 if ( snp > .999 ) snp = .999;
770 if ( snp < -.999 ) snp = -.999;
771 currOutTracklet->fPsi = TMath::ASin( snp );
772 currOutTracklet->fTgl = tp.GetTgl();
773
774 currOutTracklet->fY0err = tp.GetSigmaY2();
775 currOutTracklet->fZ0err = tp.GetSigmaZ2();
776 float h = -currOutTracklet->fPt * currOutTracklet->fPt;
777 currOutTracklet->fPterr = h * h * tp.GetSigma1Pt2();
778 h = 1. / TMath::Sqrt( 1 - snp * snp );
779 currOutTracklet->fPsierr = h * h * tp.GetSigmaSnp2();
780 currOutTracklet->fTglerr = tp.GetSigmaTgl2();
781
782 if ( par.TransportToX( clusterData[islice].X( iLastHit ), .99 ) ) {
783 currOutTracklet->fLastX = par.GetX();
784 currOutTracklet->fLastY = par.GetY();
785 currOutTracklet->fLastZ = par.GetZ();
786 } else {
787 currOutTracklet->fLastX = clusterData[islice].X( iLastHit );
788 currOutTracklet->fLastY = clusterData[islice].Y( iLastHit );
789 currOutTracklet->fLastZ = clusterData[islice].Z( iLastHit );
790 }
791 //if( currOutTracklet->fLastX<10. ) {
792 //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],
793 //par.GetX(), par.GetY(),par.GetZ(),currOutTracklet->fLastX,currOutTracklet->fLastY ,currOutTracklet->fLastZ, t.NHits());
794 //}
795 #ifdef INCLUDE_TPC_HOUGH
796 #ifdef ROWHOUGHPARAMS
797 currOutTracklet->fTrackID = 0;
798 currOutTracklet->fRowRange1 = clusterData[islice].RowNumber( iFirstHit );
799 currOutTracklet->fRowRange2 = clusterData[islice].RowNumber( iLastHit );
800 currOutTracklet->fSector = slice;
801 currOutTracklet->fPID = 211;
802 #endif
803 #endif // INCLUDE_TPC_HOUGH
804
805
806 currOutTracklet->fNPoints = t.NHits();
807
808 for ( int i = 0; i < t.NHits(); i++ ) {
809 currOutTracklet->fPointIDs[i] = clusterData[islice].Id( sliceOutput[islice]->OutTrackHit(t.FirstHitRef()+i) );
810 }
811
812 currOutTracklet = ( AliHLTTPCTrackSegmentData* )( ( Byte_t * )currOutTracklet + dSize );
813 mySize += dSize;
814 outPtr->fTrackletCnt++;
815 }
816
817 } else { // default output type
c7d6f78b 818
819 Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reconstruct",
820 "%d tracks found for slice %d", sliceOutput[islice]->NTracks(), slice );
821
d4594e7d 822 mySize += sliceOutput[islice]->OutputMemorySize();
823 ntracks += sliceOutput[islice]->NTracks();
824 }
825 }
826 else
827 {
828 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), tracks are not stored", maxBufferSize, mySize );
829 mySize = 0;
830 ret = -ENOSPC;
831 ntracks = 0;
832 error = 1;
833 break;
834 }
cf471b1e 835 }
fbb9b71b 836
d4594e7d 837 size = 0;
838 if (error == 0)
839 {
840 for (int islice = 0;islice < slicecount;islice++)
841 {
842 slice = minslice + islice;
843 if (!fOutputTRAKSEGS) mySize = sliceOutput[islice]->OutputMemorySize();
844 if (mySize > 0)
845 {
846 AliHLTComponentBlockData bd;
847 FillBlockData( bd );
848 bd.fOffset = fOutputTRAKSEGS ? 0 : ((char*) sliceOutput[islice] - (char*) outputPtr);
849 bd.fSize = mySize;
850 bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, sliceminPatch[islice], slicemaxPatch[islice] );
851 bd.fDataType = GetOutputDataType();
852 outputBlocks.push_back( bd );
853 size += mySize;
854 }
855 }
e1f2d1c3 856 }
d4594e7d 857
858 //No longer needed
859 delete[] clusterData;
860 //These are only temporary pointers to the output and no longer needed
861 delete[] sliceOutput;
fbb9b71b 862
d54804bf 863 timer.Stop();
864
fbb9b71b 865 fFullTime += timer.RealTime();
866 fRecoTime += timerReco.RealTime();
d54804bf 867 fNEvents++;
dc4788ec 868
869 // Set log level to "Warning" for on-line system monitoring
fbb9b71b 870 int hz = ( int ) ( fFullTime > 1.e-10 ? fNEvents / fFullTime : 100000 );
871 int hz1 = ( int ) ( fRecoTime > 1.e-10 ? fNEvents / fRecoTime : 100000 );
d4594e7d 872 //Min and Max Patch are taken for first slice processed...
873 HLTInfo( "CATracker slices %d-%d: output %d tracks; input %d clusters, patches %d..%d, rows %d..%d; time: full %d / reco %d Hz",
874 minslice, maxslice, ntracks, nClustersTotalSum, sliceminPatch[0], slicemaxPatch[0], slicerow[0], slicerow[1], hz, hz1 );
dc4788ec 875
4c256004 876 return ret;
cf471b1e 877}
878
fbb9b71b 879