1 // **************************************************************************
2 // This file is property of and copyright by the ALICE HLT Project *
3 // ALICE Experiment at CERN, All rights reserved. *
5 // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
6 // Ivan Kisel <kisel@kip.uni-heidelberg.de> *
7 // Matthias Kretz <kretz@kde.org> *
8 // for The ALICE HLT Project. *
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. *
18 //***************************************************************************
21 /** @file AliHLTTPCCAGlobalMergerComponent.cxx
22 @author Matthias Kretz
24 @brief HLT TPC CA global merger component.
31 #include "AliHLTTPCCAGlobalMergerComponent.h"
32 #include "AliHLTTPCCAMergerOutput.h"
33 #include "AliHLTTPCTransform.h"
34 #include "AliHLTTPCCAMerger.h"
35 #include "AliHLTTPCVertex.h"
36 #include "AliHLTTPCVertexData.h"
37 #include "AliHLTTPCTrackSegmentData.h"
38 #include "AliHLTTPCTrack.h"
39 #include "AliHLTTPCTrackArray.h"
40 #include "AliHLTTPCTrackletDataFormat.h"
41 #include "AliHLTTPCCADef.h"
42 #include "AliHLTTPCDefinitions.h"
43 #include "AliHLTTPCCATrackConvertor.h"
44 #include "AliHLTTPCCASliceOutput.h"
46 #include "AliCDBEntry.h"
47 #include "AliCDBManager.h"
48 #include "TObjString.h"
49 #include "TObjArray.h"
56 // ROOT macro for the implementation of ROOT specific class methods
57 ClassImp( AliHLTTPCCAGlobalMergerComponent )
60 // global object for registration
61 AliHLTTPCCAGlobalMergerComponent AliHLTTPCCAGlobalMergerComponent::fgAliHLTTPCCAGlobalMergerComponent;
63 AliHLTTPCCAGlobalMergerComponent::AliHLTTPCCAGlobalMergerComponent()
64 : fGlobalMerger( 0 ), fSolenoidBz( 5 )
66 // see header file for class documentation
69 // Public functions to implement AliHLTComponent's interface.
70 // These functions are required for the registration process
72 const char *AliHLTTPCCAGlobalMergerComponent::GetComponentID()
74 // see header file for class documentation
75 return "TPCCAGlobalMerger";
78 void AliHLTTPCCAGlobalMergerComponent::GetInputDataTypes( AliHLTComponentDataTypeList &list )
80 // see header file for class documentation
82 list.push_back( AliHLTTPCCADefinitions::fgkTrackletsDataType );
83 //list.push_back( AliHLTTPCDefinitions::fgkTrackSegmentsDataType );
84 //list.push_back( AliHLTTPCDefinitions::fgkVertexDataType );
87 AliHLTComponentDataType AliHLTTPCCAGlobalMergerComponent::GetOutputDataType()
89 // see header file for class documentation
90 return AliHLTTPCDefinitions::fgkTracksDataType;
93 void AliHLTTPCCAGlobalMergerComponent::GetOutputDataSize( unsigned long &constBase, double &inputMultiplier )
95 // see header file for class documentation
96 // XXX TODO: Find more realistic values.
98 inputMultiplier = 1.0;
101 AliHLTComponent *AliHLTTPCCAGlobalMergerComponent::Spawn()
103 // see header file for class documentation
104 return new AliHLTTPCCAGlobalMergerComponent;
107 int AliHLTTPCCAGlobalMergerComponent::DoInit( int argc, const char** argv )
109 // see header file for class documentation
110 if ( fGlobalMerger ) {
114 // Initialize the merger
116 fGlobalMerger = new AliHLTTPCCAMerger();
118 AliHLTTPCCAParam param;
123 float inRmin = 83.65;
124 float outRmax = 247.7;
125 float plusZmin = 0.0529937;
126 float plusZmax = 249.778;
127 float minusZmin = -249.645;
128 float minusZmax = -0.0799937;
129 float dalpha = 0.349066;
130 float alpha = 0.174533 + dalpha * iSec;
131 bool zPlus = ( iSec < 18 );
132 float zMin = zPlus ? plusZmin : minusZmin;
133 float zMax = zPlus ? plusZmax : minusZmax;
134 int nRows = AliHLTTPCTransform::GetNRows();
135 float padPitch = 0.4;
136 float sigmaZ = 0.228808;
137 float *rowX = new float [nRows];
138 for ( int irow = 0; irow < nRows; irow++ ) {
139 rowX[irow] = AliHLTTPCTransform::Row2X( irow );
142 param.Initialize( iSec, nRows, rowX, alpha, dalpha,
143 inRmin, outRmax, zMin, zMax, padPitch, sigmaZ, fSolenoidBz );
148 fGlobalMerger->SetSliceParam( param );
152 TString arguments = "";
153 for ( int i = 0; i < argc; i++ ) {
154 TString argument = argv[i];
155 if ( !arguments.IsNull() ) arguments += " ";
156 arguments += argument;
158 if ( !arguments.IsNull() ) {
159 iResult = Configure( arguments.Data() );
161 iResult = Reconfigure( NULL, NULL );
166 int AliHLTTPCCAGlobalMergerComponent::DoDeinit()
168 // see header file for class documentation
169 delete fGlobalMerger;
175 int AliHLTTPCCAGlobalMergerComponent::DoEvent( const AliHLTComponentEventData &evtData,
176 const AliHLTComponentBlockData *blocks, AliHLTComponentTriggerData &/*trigData*/,
177 AliHLTUInt8_t *outputPtr, AliHLTUInt32_t &size, AliHLTComponentBlockDataList &outputBlocks )
179 // see header file for class documentation
181 unsigned int maxBufferSize = size;
188 if ( !IsDataEvent() ) {
192 fGlobalMerger->Clear();
194 const AliHLTComponentBlockData *const blocksEnd = blocks + evtData.fBlockCnt;
195 for ( const AliHLTComponentBlockData *block = blocks; block < blocksEnd; ++block ) {
196 if ( block->fDataType != AliHLTTPCCADefinitions::fgkTrackletsDataType ) {
200 int slice = AliHLTTPCDefinitions::GetMinSliceNr( *block );
201 if ( slice < 0 || slice >= AliHLTTPCTransform::GetNSlice() ) {
202 HLTError( "invalid slice number %d extracted from specification 0x%08lx, skipping block of type %s",
203 slice, block->fSpecification, DataType2Text( block->fDataType ).c_str() );
204 // just remember the error, if there are other valid blocks ignore the error, return code otherwise
209 if ( slice != AliHLTTPCDefinitions::GetMaxSliceNr( *block ) ) {
210 // the code was not written for/ never used with multiple slices in one data block/ specification
211 HLTWarning( "specification 0x%08lx indicates multiple slices in data block %s: never used before, please audit the code",
212 block->fSpecification, DataType2Text( block->fDataType ).c_str() );
214 AliHLTTPCCASliceOutput *sliceOut = reinterpret_cast<AliHLTTPCCASliceOutput *>( block->fPtr );
215 sliceOut->SetPointers();
216 fGlobalMerger->SetSliceData( slice, sliceOut );
218 fGlobalMerger->Reconstruct();
220 const AliHLTTPCCAMergerOutput *mergerOutput = fGlobalMerger->Output();
223 // Fill output tracks
225 unsigned int mySize = 0;
228 // check if there was enough space in the output buffer
230 int nTracks = mergerOutput->NTracks();
232 AliHLTTPCTrackArray array( nTracks );
235 for ( int itr = 0; itr < nTracks; itr++ ) {
237 // convert AliHLTTPCCAMergedTrack to AliHLTTPCTrack
239 const AliHLTTPCCAMergedTrack &track = mergerOutput->Track( itr );
242 // first convert to AliExternalTrackParam ( Kappa to Pt )
244 AliExternalTrackParam tp, tpEnd;
245 AliHLTTPCCATrackConvertor::GetExtParam( track.InnerParam(), tp, 0 );
246 AliHLTTPCCATrackConvertor::GetExtParam( track.OuterParam(), tpEnd, 0 );
248 // set parameters, with rotation to global coordinates
250 out.SetCharge( ( int ) tp.GetSign() );
251 out.SetPt( TMath::Abs( tp.GetSignedPt() ) );
252 out.SetPsi( fmod( TMath::ASin( tp.GetSnp() ) + track.InnerAlpha() , 2*TMath::Pi() ) );
253 out.SetTgl( tp.GetTgl() );
255 float sinA = TMath::Sin( track.InnerAlpha() );
256 float cosA = TMath::Cos( track.InnerAlpha() );
258 out.SetFirstPoint( tp.GetX()*cosA - tp.GetY()*sinA,
259 tp.GetX()*sinA + tp.GetY()*cosA,
264 float sinA = TMath::Sin( track.OuterAlpha() );
265 float cosA = TMath::Cos( track.OuterAlpha() );
267 out.SetLastPoint( tpEnd.GetX()*cosA - tpEnd.GetY()*sinA,
268 tpEnd.GetX()*sinA + tpEnd.GetY()*cosA,
272 // set parameter errors w/o rotation, as it is done in AliHLTTPCTrackArray
274 out.SetY0err( tp.GetSigmaY2() );
275 out.SetZ0err( tp.GetSigmaZ2() );
276 float h = -out.GetPt() * out.GetPt();
277 out.SetPterr( h*h*tp.GetSigma1Pt2() );
278 h = 1. / TMath::Sqrt( 1 - out.GetSnp() * out.GetSnp() );
279 out.SetPsierr( h*h*tp.GetSigmaSnp2() );
280 out.SetTglerr( tp.GetSigmaTgl2() );
284 unsigned int hitID[1000];
285 for ( int i = 0; i < track.NClusters(); i++ ) hitID[i] = mergerOutput->ClusterIDsrc( track.FirstClusterRef() + i );
287 out.SetNHits( track.NClusters() );
288 out.SetHits( track.NClusters(), hitID );
291 out.CalculateHelix();
292 if ( !out.CheckConsistency() ) *( array.NextTrack() ) = out;
293 nClusters += track.NClusters();
297 if ( sizeof( AliHLTTPCTrackletData ) + nTracks*sizeof( AliHLTTPCTrackSegmentData ) + nClusters*sizeof( unsigned int )
301 AliHLTTPCTrackletData *outPtr = ( AliHLTTPCTrackletData* )( outputPtr );
302 unsigned int nOutTracks = 0;
303 mySize = array.WriteTracks( nOutTracks, outPtr->fTracklets );
304 mySize += sizeof( AliHLTTPCTrackletData );
305 outPtr->fTrackletCnt = nOutTracks;
309 AliHLTComponentBlockData resultData;
310 FillBlockData( resultData );
311 resultData.fOffset = 0;
312 resultData.fSize = mySize;
313 resultData.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( 0, 35, 0, 5 );
314 outputBlocks.push_back( resultData );
315 size = resultData.fSize;
317 //HLTWarning("CAGlobalMerger:: output %d tracks",mergerOutput->NTracks());
324 int AliHLTTPCCAGlobalMergerComponent::Reconfigure( const char* /*cdbEntry*/, const char* /*chainId*/ )
326 // see header file for class documentation
329 HLTWarning( "TODO: dummy Reconfigure() method" );
334 const char* pathBField=kAliHLTCDBSolenoidBz;
337 HLTInfo("reconfigure B-Field from entry %s, chain id %s", pathBField,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
338 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(pathBField);//,GetRunNo());
340 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
342 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
343 iResult=Configure(pString->GetString().Data());
345 HLTError("configuration object \"%s\" has wrong type, required TObjString", pathBField);
348 HLTError("cannot fetch object \"%s\" from CDB", pathBField);
356 int AliHLTTPCCAGlobalMergerComponent::Configure( const char* arguments )
361 if ( !arguments ) return iResult;
363 TString allArgs = arguments;
365 int bMissingParam = 0;
367 TObjArray* pTokens = allArgs.Tokenize( " " );
369 int nArgs = pTokens ? pTokens->GetEntries() : 0;
371 for ( int i = 0; i < nArgs; i++ ) {
372 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
373 if ( argument.IsNull() ) {
374 } else if ( argument.CompareTo( "-solenoidBz" ) == 0 ) {
375 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
376 fSolenoidBz = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
377 HLTInfo( "Magnetic Field set to: %f", fSolenoidBz );
379 HLTError( "Unknown option %s ", argument.Data() );
385 if ( bMissingParam ) {
386 HLTError( "Specifier missed for %s", argument.Data() );