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"
50 /** ROOT macro for the implementation of ROOT specific class methods */
51 ClassImp( AliHLTTPCdEdxComponent )
52 AliHLTTPCdEdxComponent::AliHLTTPCdEdxComponent()
58 // see header file for class documentation
60 // refer to README to build package
62 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
63 for( int i=0; i<fkNPatches; i++ ){
64 fPatchClusters[i] = 0;
65 fNPatchClusters[i] = 0;
69 AliHLTTPCdEdxComponent::AliHLTTPCdEdxComponent( const AliHLTTPCdEdxComponent& )
77 for( int i=0; i<fkNPatches; i++ ){
78 fPatchClusters[i] = 0;
79 fNPatchClusters[i] = 0;
81 HLTFatal( "copy constructor untested" );
84 AliHLTTPCdEdxComponent& AliHLTTPCdEdxComponent::operator=( const AliHLTTPCdEdxComponent& )
86 // see header file for class documentation
87 HLTFatal( "assignment operator untested" );
88 for( int i=0; i<fkNPatches; i++ ){
89 fPatchClusters[i] = 0;
90 fNPatchClusters[i] = 0;
95 AliHLTTPCdEdxComponent::~AliHLTTPCdEdxComponent()
97 // see header file for class documentation
98 for( int i=0; i<fkNPatches; i++ ){
99 delete[] fPatchClusters[i];
104 // Public functions to implement AliHLTComponent's interface.
105 // These functions are required for the registration process
108 const char* AliHLTTPCdEdxComponent::GetComponentID()
110 // see header file for class documentation
114 void AliHLTTPCdEdxComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
116 // see header file for class documentation
118 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
119 list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
122 AliHLTComponentDataType AliHLTTPCdEdxComponent::GetOutputDataType()
124 // see header file for class documentation
125 return kAliHLTDataTypedEdx|kAliHLTDataOriginTPC;
128 void AliHLTTPCdEdxComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
130 // define guess for the output data size
131 constBase = 200; // minimum size
132 inputMultiplier = 0.1; // size relative to input
135 AliHLTComponent* AliHLTTPCdEdxComponent::Spawn()
137 // see header file for class documentation
138 return new AliHLTTPCdEdxComponent;
141 void AliHLTTPCdEdxComponent::SetDefaultConfiguration()
143 // Set default configuration for the CA tracker component
144 // Some parameters can be later overwritten from the OCDB
146 fSolenoidBz = -5.00668;
151 int AliHLTTPCdEdxComponent::ReadConfigurationString( const char* arguments )
153 // Set configuration parameters for the CA tracker component from the string
156 if ( !arguments ) return iResult;
158 TString allArgs = arguments;
160 int bMissingParam = 0;
162 TObjArray* pTokens = allArgs.Tokenize( " " );
164 int nArgs = pTokens ? pTokens->GetEntries() : 0;
166 for ( int i = 0; i < nArgs; i++ ) {
167 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
168 if ( argument.IsNull() ) continue;
170 if ( argument.CompareTo( "-solenoidBz" ) == 0 ) {
171 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
172 HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
176 HLTError( "Unknown option \"%s\"", argument.Data() );
181 if ( bMissingParam ) {
182 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
190 int AliHLTTPCdEdxComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
192 // see header file for class documentation
194 const char* defaultNotify = "";
197 return 0;// need to add the HLT/ConfigTPC/TPCdEdx directory to cdb SG!!!
198 //cdbEntry = "HLT/ConfigTPC/TPCdEdx";
199 //defaultNotify = " (default)";
203 HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
204 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
207 HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
211 TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
214 HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
218 HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
220 return ReadConfigurationString( pString->GetString().Data() );
224 int AliHLTTPCdEdxComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
226 // Configure the component
227 // There are few levels of configuration,
228 // parameters which are set on one step can be overwritten on the next step
230 //* read hard-coded values
232 SetDefaultConfiguration();
234 //* read the default CDB entry
236 int iResult1 = ReadCDBEntry( NULL, chainId );
238 //* read magnetic field
242 //* read the actual CDB entry if required
244 int iResult2 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
246 //* read extra parameters from input (if they are)
250 if ( commandLine && commandLine[0] != '\0' ) {
251 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
252 iResult3 = ReadConfigurationString( commandLine );
255 // Initialise the tracker here
257 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : iResult3 );
262 int AliHLTTPCdEdxComponent::DoInit( int argc, const char** argv )
264 // Configure the component
266 TString arguments = "";
267 for ( int i = 0; i < argc; i++ ) {
268 if ( !arguments.IsNull() ) arguments += " ";
269 arguments += argv[i];
272 int ret = Configure( NULL, NULL, arguments.Data() );
275 if (!TGeoGlobalMagField::Instance()) {
276 HLTError("magnetic field not initialized, please set up TGeoGlobalMagField and AliMagF");
280 //AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform();
282 //AliTPCRecoParam *reco = transform->GetCurrentRecoParam();
284 //reco = new AliTPCRecoParam;
285 //reco->SetUseTotalCharge(0);
286 //transform->SetCurrentRecoParam( reco );
293 int AliHLTTPCdEdxComponent::DoDeinit()
295 // see header file for class documentation
301 int AliHLTTPCdEdxComponent::Reconfigure( const char* cdbEntry, const char* chainId )
303 // Reconfigure the component from OCDB .
305 return Configure( cdbEntry, chainId, NULL );
310 int AliHLTTPCdEdxComponent::DoEvent
312 const AliHLTComponentEventData& evtData,
313 const AliHLTComponentBlockData* blocks,
314 AliHLTComponentTriggerData& /*trigData*/,
315 AliHLTUInt8_t* outputPtr,
316 AliHLTUInt32_t& size,
317 vector<AliHLTComponentBlockData>& outputBlocks )
319 //* process the event
321 AliHLTUInt32_t maxBufferSize = size;
322 size = 0; // output size
324 if (!IsDataEvent()) return 0;
326 if ( evtData.fBlockCnt <= 0 ) {
327 HLTWarning( "no blocks in event" );
338 // Initialise the data pointers
340 for( int i=0; i<fkNPatches; i++ ){
341 delete[] fPatchClusters[i];
342 fPatchClusters[i] = 0;
343 fNPatchClusters[i] = 0;
346 int nBlocks = (int)evtData.fBlockCnt;
348 int nInputClusters = 0;
349 int nInputTracks = 0;
351 // first read all the clusters
353 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
354 const AliHLTComponentBlockData* iter = blocks+ndx;
355 if ( iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType ) continue;
356 Int_t slice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
357 Int_t patch=AliHLTTPCDefinitions::GetMinPatchNr(iter->fSpecification);
358 Int_t slicepatch=slice*6+patch;
359 if( slicepatch >= fkNPatches ){
360 HLTWarning("Wrong header of TPC cluster data, slice %d, patch %d",
364 AliHLTTPCClusterData* inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
365 nInputClusters += inPtrSP->fSpacePointCnt;
367 delete[] fPatchClusters[slicepatch];
368 fPatchClusters[slicepatch] = new AliTPCclusterMI[inPtrSP->fSpacePointCnt];
369 fNPatchClusters[slicepatch] = inPtrSP->fSpacePointCnt;
371 // create off-line clusters out of the HLT clusters
372 // todo: check which cluster information is really needed for the dEdx
374 for ( unsigned int i = 0; i < inPtrSP->fSpacePointCnt; i++ ) {
375 AliHLTTPCSpacePointData *chlt = &( inPtrSP->fSpacePoints[i] );
376 AliTPCclusterMI *c = fPatchClusters[slicepatch]+i;
380 c->SetSigmaY2(chlt->fSigmaY2);
382 c->SetSigmaZ2(chlt->fSigmaZ2);
383 c->SetQ( chlt->fCharge );
384 c->SetMax( chlt->fQMax );
386 Float_t padtime[3]={0,chlt->fY,chlt->fZ};
387 AliHLTTPCTransform::Slice2Sector(slice,chlt->fPadRow, sector, row);
388 AliHLTTPCTransform::Local2Raw( padtime, sector, row);
389 c->SetDetector( sector );
391 c->SetPad( (Int_t) padtime[1] );
392 c->SetTimeBin( (Int_t) padtime[2] );
397 // loop over the input tracks: calculate dEdx and write output
399 unsigned int outSize = 0;
400 AliHLTFloat32_t *outPtr = ( AliHLTFloat32_t * )( outputPtr );
402 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
403 pBlock!=NULL; pBlock=GetNextInputBlock()) {
405 AliHLTComponentBlockData outBlock;
406 FillBlockData( outBlock );
407 outBlock.fOffset = outSize;
409 outBlock.fDataType = kAliHLTDataTypedEdx|kAliHLTDataOriginTPC;
410 outBlock.fSpecification = pBlock->fSpecification;
412 AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) pBlock->fPtr;
413 int nTracks = dataPtr->fCount;
414 AliHLTExternalTrackParam* currTrack = dataPtr->fTracklets;
415 nInputTracks+=nTracks;
418 itr<nTracks && ( (AliHLTUInt8_t *)currTrack < ((AliHLTUInt8_t *) pBlock->fPtr)+pBlock->fSize);
421 // create an off-line track
422 AliHLTGlobalBarrelTrack gb(*currTrack);
424 tTPC.Set( gb.GetX(), gb.GetAlpha(),
425 gb.GetParameter(), gb.GetCovariance() );
429 for( UInt_t ic=0; ic<currTrack->fNPoints; ic++){
430 UInt_t id = currTrack->fPointIDs[ic];
431 int iSlice = AliHLTTPCSpacePointData::GetSlice(id);
432 int iPatch = AliHLTTPCSpacePointData::GetPatch(id);
433 int iCluster = AliHLTTPCSpacePointData::GetNumber(id);
434 if( iSlice<0 || iSlice>36 || iPatch<0 || iPatch>5 ){
435 HLTError("Corrupted TPC cluster Id: slice %d, patch %d, cluster %d",
436 iSlice, iPatch,iCluster );
439 AliTPCclusterMI *patchClusters = fPatchClusters[iSlice*6 + iPatch];
440 if( !patchClusters ){
441 HLTError("Clusters are missed for slice %d, patch %d",
445 if( iCluster >= fNPatchClusters[iSlice*6 + iPatch] ){
446 HLTError("TPC slice %d, patch %d: ClusterID==%d >= N Cluaters==%d ",
447 iSlice, iPatch,iCluster, fNPatchClusters[iSlice*6 + iPatch] );
450 AliTPCclusterMI *c = &(patchClusters[iCluster]);
452 int sec = c->GetDetector();
453 int row = c->GetRow();
455 row = row + AliHLTTPCTransform::GetNRowLow();
457 tTPC.SetClusterPointer( row, c );
459 AliTPCTrackerPoint &point = *( tTPC.GetTrackPoint( row ) );
460 tTPC.Propagate( TMath::DegToRad()*(sec%18*20.+10.), c->GetX(), fSolenoidBz );
461 Double_t angle2 = tTPC.GetSnp()*tTPC.GetSnp();
462 angle2 = (angle2<1) ?TMath::Sqrt(angle2/(1-angle2)) :10.;
463 point.SetAngleY( angle2 );
464 point.SetAngleZ( tTPC.GetTgl() );
469 if( outSize+3*sizeof( AliHLTFloat32_t ) > maxBufferSize ){
470 HLTWarning( "Output buffer size %d exceed", maxBufferSize );
475 tTPC.CookdEdx( 0.02, 0.6 );
476 outPtr[0] = tTPC.GetdEdx();
477 outPtr[1] = tTPC.GetSDEDX(0);
478 outPtr[2] = tTPC.GetNCDEDX(0);
480 outSize+=3*sizeof( AliHLTFloat32_t );
481 outBlock.fSize+=3*sizeof( AliHLTFloat32_t );
483 unsigned int step = sizeof( AliHLTExternalTrackParam ) + currTrack->fNPoints * sizeof( unsigned int );
484 currTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currTrack) + step );
486 if( iResult<0 ) break;
487 outputBlocks.push_back( outBlock );
492 fStatTime += timer.RealTime();
495 // Set log level to "Warning" for on-line system monitoring
496 int hz = ( int ) ( fStatTime > 1.e-10 ? fStatNEvents / fStatTime : 100000 );
498 HLTInfo( "TPCdEdx : %d clusters and %d tracks processed; average time %d Hz",
499 nInputClusters, nInputTracks, hz );