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 // for The ALICE HLT Project. *
8 // Permission to use, copy, modify and distribute this software and its *
9 // documentation strictly for non-commercial purposes is hereby granted *
10 // without fee, provided that the above copyright notice appears in all *
11 // copies and that both the copyright notice and this permission notice *
12 // appear in the supporting documentation. The authors make no claims *
13 // about the suitability of this software for any purpose. It is *
14 // provided "as is" without express or implied warranty. *
16 //***************************************************************************
18 /// @file AliHLTTPCdEdxComponent.cxx
19 /// @author Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de>
21 /// @brief An ITS tracker processing component for the HLT
24 /////////////////////////////////////////////////////
26 // dEdx calculation component for the HLT TPC //
28 /////////////////////////////////////////////////////
30 #include "AliHLTTPCdEdxComponent.h"
31 #include "TStopwatch.h"
33 #include "AliCDBEntry.h"
34 #include "AliCDBManager.h"
35 #include "TObjString.h"
36 #include "TObjArray.h"
37 #include "AliHLTDataTypes.h"
38 #include "AliHLTExternalTrackParam.h"
39 #include "AliHLTGlobalBarrelTrack.h"
40 #include "AliHLTTPCTransform.h"
41 #include "AliHLTTPCSpacePointData.h"
42 #include "AliHLTTPCClusterDataFormat.h"
43 #include "AliHLTTPCTrackletDataFormat.h"
44 #include "AliHLTTPCDefinitions.h"
45 #include "AliTPCseed.h"
46 #include "AliTPCclusterMI.h"
47 #include "TGeoGlobalMagField.h"
51 /** ROOT macro for the implementation of ROOT specific class methods */
52 ClassImp( AliHLTTPCdEdxComponent )
53 AliHLTTPCdEdxComponent::AliHLTTPCdEdxComponent()
59 // see header file for class documentation
61 // refer to README to build package
63 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
64 for( int i=0; i<fkNPatches; i++ ){
65 fPatchClusters[i] = 0;
66 fNPatchClusters[i] = 0;
70 AliHLTTPCdEdxComponent::AliHLTTPCdEdxComponent( const AliHLTTPCdEdxComponent& )
77 // see header file for class documentation
78 HLTFatal( "copy constructor untested" );
81 AliHLTTPCdEdxComponent& AliHLTTPCdEdxComponent::operator=( const AliHLTTPCdEdxComponent& )
83 // see header file for class documentation
84 HLTFatal( "assignment operator untested" );
85 for( int i=0; i<fkNPatches; i++ ){
86 fPatchClusters[i] = 0;
87 fNPatchClusters[i] = 0;
92 AliHLTTPCdEdxComponent::~AliHLTTPCdEdxComponent()
94 // see header file for class documentation
95 for( int i=0; i<fkNPatches; i++ ){
96 delete[] fPatchClusters[i];
101 // Public functions to implement AliHLTComponent's interface.
102 // These functions are required for the registration process
105 const char* AliHLTTPCdEdxComponent::GetComponentID()
107 // see header file for class documentation
111 void AliHLTTPCdEdxComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
113 // see header file for class documentation
115 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
116 list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
119 AliHLTComponentDataType AliHLTTPCdEdxComponent::GetOutputDataType()
121 // see header file for class documentation
122 return kAliHLTDataTypedEdx|kAliHLTDataOriginTPC;
125 void AliHLTTPCdEdxComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
127 // define guess for the output data size
128 constBase = 200; // minimum size
129 inputMultiplier = 0.1; // size relative to input
132 AliHLTComponent* AliHLTTPCdEdxComponent::Spawn()
134 // see header file for class documentation
135 return new AliHLTTPCdEdxComponent;
138 void AliHLTTPCdEdxComponent::SetDefaultConfiguration()
140 // Set default configuration for the CA tracker component
141 // Some parameters can be later overwritten from the OCDB
143 fSolenoidBz = -5.00668;
148 int AliHLTTPCdEdxComponent::ReadConfigurationString( const char* arguments )
150 // Set configuration parameters for the CA tracker component from the string
153 if ( !arguments ) return iResult;
155 TString allArgs = arguments;
157 int bMissingParam = 0;
159 TObjArray* pTokens = allArgs.Tokenize( " " );
161 int nArgs = pTokens ? pTokens->GetEntries() : 0;
163 for ( int i = 0; i < nArgs; i++ ) {
164 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
165 if ( argument.IsNull() ) continue;
167 if ( argument.CompareTo( "-solenoidBz" ) == 0 ) {
168 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
169 fSolenoidBz = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
170 HLTInfo( "Magnetic Field set to: %f", fSolenoidBz );
174 HLTError( "Unknown option \"%s\"", argument.Data() );
179 if ( bMissingParam ) {
180 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
188 int AliHLTTPCdEdxComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
190 // see header file for class documentation
192 const char* defaultNotify = "";
195 return 0;// need to add the HLT/ConfigTPC/TPCdEdx directory to cdb SG!!!
196 cdbEntry = "HLT/ConfigTPC/TPCdEdx";
197 defaultNotify = " (default)";
201 HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
202 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
205 HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
209 TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
212 HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
216 HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
218 return ReadConfigurationString( pString->GetString().Data() );
222 int AliHLTTPCdEdxComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
224 // Configure the component
225 // There are few levels of configuration,
226 // parameters which are set on one step can be overwritten on the next step
228 //* read hard-coded values
230 SetDefaultConfiguration();
232 //* read the default CDB entry
234 int iResult1 = ReadCDBEntry( NULL, chainId );
236 //* read magnetic field
238 int iResult2 = ReadCDBEntry( kAliHLTCDBSolenoidBz, chainId );
240 //* read the actual CDB entry if required
242 int iResult3 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
244 //* read extra parameters from input (if they are)
248 if ( commandLine && commandLine[0] != '\0' ) {
249 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
250 iResult4 = ReadConfigurationString( commandLine );
253 // Initialise the tracker here
255 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : ( iResult3 ? iResult3 : iResult4 ) );
260 int AliHLTTPCdEdxComponent::DoInit( int argc, const char** argv )
262 // Configure the component
264 TString arguments = "";
265 for ( int i = 0; i < argc; i++ ) {
266 if ( !arguments.IsNull() ) arguments += " ";
267 arguments += argv[i];
270 int ret = Configure( NULL, NULL, arguments.Data() );
273 if (!TGeoGlobalMagField::Instance()->IsLocked()) {
274 AliMagF* field = new AliMagF("Maps","Maps",1.,1.,AliMagF::k5kG);
275 field->SetFactorSol(1);
276 Double_t initialFieldStrengh=field->SolenoidField();
277 field->SetFactorSol(fSolenoidBz/initialFieldStrengh);
278 TGeoGlobalMagField::Instance()->SetField(field);
281 //AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform();
283 //AliTPCRecoParam *reco = transform->GetCurrentRecoParam();
285 //reco = new AliTPCRecoParam;
286 //reco->SetUseTotalCharge(0);
287 //transform->SetCurrentRecoParam( reco );
294 int AliHLTTPCdEdxComponent::DoDeinit()
296 // see header file for class documentation
302 int AliHLTTPCdEdxComponent::Reconfigure( const char* cdbEntry, const char* chainId )
304 // Reconfigure the component from OCDB .
306 return Configure( cdbEntry, chainId, NULL );
311 int AliHLTTPCdEdxComponent::DoEvent
313 const AliHLTComponentEventData& evtData,
314 const AliHLTComponentBlockData* blocks,
315 AliHLTComponentTriggerData& /*trigData*/,
316 AliHLTUInt8_t* outputPtr,
317 AliHLTUInt32_t& size,
318 vector<AliHLTComponentBlockData>& outputBlocks )
320 //* process the event
322 AliHLTUInt32_t maxBufferSize = size;
323 size = 0; // output size
325 if (!IsDataEvent()) return 0;
327 if ( evtData.fBlockCnt <= 0 ) {
328 HLTWarning( "no blocks in event" );
339 // Initialise the data pointers
341 for( int i=0; i<fkNPatches; i++ ){
342 delete[] fPatchClusters[i];
343 fPatchClusters[i] = 0;
344 fNPatchClusters[i] = 0;
347 int nBlocks = (int)evtData.fBlockCnt;
349 int nInputClusters = 0;
350 int nInputTracks = 0;
352 // first read all the clusters
354 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
355 const AliHLTComponentBlockData* iter = blocks+ndx;
356 if ( iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType ) continue;
357 Int_t slice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
358 Int_t patch=AliHLTTPCDefinitions::GetMinPatchNr(iter->fSpecification);
359 Int_t slicepatch=slice*6+patch;
360 if( slicepatch > fkNPatches ){
361 HLTWarning("Wrong header of TPC cluster data, slice %d, patch %d",
365 AliHLTTPCClusterData* inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
366 nInputClusters += inPtrSP->fSpacePointCnt;
368 delete[] fPatchClusters[slicepatch];
369 fPatchClusters[slicepatch] = new AliTPCclusterMI[inPtrSP->fSpacePointCnt];
370 fNPatchClusters[slicepatch] = inPtrSP->fSpacePointCnt;
372 // create off-line clusters out of the HLT clusters
373 // todo: check which cluster information is really needed for the dEdx
375 for ( unsigned int i = 0; i < inPtrSP->fSpacePointCnt; i++ ) {
376 AliHLTTPCSpacePointData *chlt = &( inPtrSP->fSpacePoints[i] );
377 AliTPCclusterMI *c = fPatchClusters[slicepatch]+i;
381 c->SetSigmaY2(chlt->fSigmaY2);
383 c->SetSigmaZ2(chlt->fSigmaZ2);
384 c->SetQ( chlt->fCharge );
385 c->SetMax( chlt->fQMax );
387 Float_t padtime[3]={0,chlt->fY,chlt->fZ};
388 AliHLTTPCTransform::Slice2Sector(slice,chlt->fPadRow, sector, row);
389 AliHLTTPCTransform::Local2Raw( padtime, sector, row);
390 c->SetDetector( sector );
392 c->SetPad( (Int_t) padtime[1] );
393 c->SetTimeBin( (Int_t) padtime[2] );
398 // loop over the input tracks: calculate dEdx and write output
400 unsigned int outSize = 0;
401 AliHLTFloat32_t *outPtr = ( AliHLTFloat32_t * )( outputPtr );
403 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
404 pBlock!=NULL; pBlock=GetNextInputBlock()) {
406 AliHLTComponentBlockData outBlock;
407 FillBlockData( outBlock );
408 outBlock.fOffset = outSize;
410 outBlock.fDataType = kAliHLTDataTypedEdx|kAliHLTDataOriginTPC;
411 outBlock.fSpecification = pBlock->fSpecification;
413 AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) pBlock->fPtr;
414 int nTracks = dataPtr->fCount;
415 AliHLTExternalTrackParam* currTrack = dataPtr->fTracklets;
416 nInputTracks+=nTracks;
419 itr<nTracks && ( (AliHLTUInt8_t *)currTrack < ((AliHLTUInt8_t *) pBlock->fPtr)+pBlock->fSize);
422 // create an off-line track
423 AliHLTGlobalBarrelTrack gb(*currTrack);
425 tTPC.Set( gb.GetX(), gb.GetAlpha(),
426 gb.GetParameter(), gb.GetCovariance() );
430 for( UInt_t ic=0; ic<currTrack->fNPoints; ic++){
431 UInt_t id = currTrack->fPointIDs[ic];
433 int iPatch = (id>>22)&0x7;
434 int iCluster = id&0x3fffff;
435 if( iSlice<0 || iSlice>36 || iPatch<0 || iPatch>5 ){
436 HLTError("Corrupted TPC cluster Id: slice %d, patch %d, cluster %d",
437 iSlice, iPatch,iCluster );
440 AliTPCclusterMI *patchClusters = fPatchClusters[iSlice*6 + iPatch];
441 if( !patchClusters ){
442 HLTError("Clusters are missed for slice %d, patch %d",
446 if( iCluster >= fNPatchClusters[iSlice*6 + iPatch] ){
447 HLTError("TPC slice %d, patch %d: ClusterID==%d >= N Cluaters==%d ",
448 iSlice, iPatch,iCluster, fNPatchClusters[iSlice*6 + iPatch] );
451 AliTPCclusterMI *c = &(patchClusters[iCluster]);
453 int sec = c->GetDetector();
454 int row = c->GetRow();
456 row = row + AliHLTTPCTransform::GetNRowLow();
458 tTPC.SetClusterPointer( row, c );
460 AliTPCTrackerPoint &point = *( tTPC.GetTrackPoint( row ) );
461 tTPC.Propagate( TMath::DegToRad()*(sec%18*20.+10.), c->GetX(), fSolenoidBz );
462 Double_t angle2 = tTPC.GetSnp()*tTPC.GetSnp();
463 angle2 = (angle2<1) ?TMath::Sqrt(angle2/(1-angle2)) :10.;
464 point.SetAngleY( angle2 );
465 point.SetAngleZ( tTPC.GetTgl() );
470 if( outSize+sizeof( AliHLTFloat32_t ) > maxBufferSize ){
471 HLTWarning( "Output buffer size %d exceed", maxBufferSize );
475 *outPtr = tTPC.CookdEdx( 0.02, 0.6 );
477 outSize+=sizeof( AliHLTFloat32_t );
478 outBlock.fSize+=sizeof( AliHLTFloat32_t );
480 unsigned int step = sizeof( AliHLTExternalTrackParam ) + currTrack->fNPoints * sizeof( unsigned int );
481 currTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currTrack) + step );
483 if( iResult<0 ) break;
484 outputBlocks.push_back( outBlock );
489 fStatTime += timer.RealTime();
492 // Set log level to "Warning" for on-line system monitoring
493 int hz = ( int ) ( fStatTime > 1.e-10 ? fStatNEvents / fStatTime : 100000 );
495 HLTInfo( "TPCdEdx : %d clusters and %d tracks processed; average time %d Hz",
496 nInputClusters, nInputTracks, hz );