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"
48 #include "AliTPCcalibDB.h"
49 #include "AliTPCRecoParam.h"
50 #include "AliTPCTransform.h"
52 /** ROOT macro for the implementation of ROOT specific class methods */
53 ClassImp( AliHLTTPCdEdxComponent )
54 AliHLTTPCdEdxComponent::AliHLTTPCdEdxComponent()
60 // see header file for class documentation
62 // refer to README to build package
64 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
65 for( int i=0; i<fkNPatches; i++ ){
66 fPatchClusters[i] = 0;
67 fNPatchClusters[i] = 0;
71 AliHLTTPCdEdxComponent::AliHLTTPCdEdxComponent( const AliHLTTPCdEdxComponent& )
79 for( int i=0; i<fkNPatches; i++ ){
80 fPatchClusters[i] = 0;
81 fNPatchClusters[i] = 0;
83 HLTFatal( "copy constructor untested" );
86 AliHLTTPCdEdxComponent& AliHLTTPCdEdxComponent::operator=( const AliHLTTPCdEdxComponent& )
88 // see header file for class documentation
89 HLTFatal( "assignment operator untested" );
90 for( int i=0; i<fkNPatches; i++ ){
91 fPatchClusters[i] = 0;
92 fNPatchClusters[i] = 0;
97 AliHLTTPCdEdxComponent::~AliHLTTPCdEdxComponent()
99 // see header file for class documentation
100 for( int i=0; i<fkNPatches; i++ ){
101 delete[] fPatchClusters[i];
106 // Public functions to implement AliHLTComponent's interface.
107 // These functions are required for the registration process
110 const char* AliHLTTPCdEdxComponent::GetComponentID()
112 // see header file for class documentation
116 void AliHLTTPCdEdxComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
118 // see header file for class documentation
120 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
121 list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
124 AliHLTComponentDataType AliHLTTPCdEdxComponent::GetOutputDataType()
126 // see header file for class documentation
127 return kAliHLTDataTypedEdx|kAliHLTDataOriginTPC;
130 void AliHLTTPCdEdxComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
132 // define guess for the output data size
133 constBase = 200; // minimum size
134 inputMultiplier = 0.1; // size relative to input
137 AliHLTComponent* AliHLTTPCdEdxComponent::Spawn()
139 // see header file for class documentation
140 return new AliHLTTPCdEdxComponent;
143 void AliHLTTPCdEdxComponent::SetDefaultConfiguration()
145 // Set default configuration for the CA tracker component
146 // Some parameters can be later overwritten from the OCDB
148 fSolenoidBz = -5.00668;
153 int AliHLTTPCdEdxComponent::ReadConfigurationString( const char* arguments )
155 // Set configuration parameters for the CA tracker component from the string
158 if ( !arguments ) return iResult;
160 TString allArgs = arguments;
162 int bMissingParam = 0;
164 TObjArray* pTokens = allArgs.Tokenize( " " );
166 int nArgs = pTokens ? pTokens->GetEntries() : 0;
168 for ( int i = 0; i < nArgs; i++ ) {
169 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
170 if ( argument.IsNull() ) continue;
172 if ( argument.CompareTo( "-solenoidBz" ) == 0 ) {
173 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
174 HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
178 HLTError( "Unknown option \"%s\"", argument.Data() );
183 if ( bMissingParam ) {
184 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
192 int AliHLTTPCdEdxComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
194 // see header file for class documentation
196 const char* defaultNotify = "";
199 return 0;// need to add the HLT/ConfigTPC/TPCdEdx directory to cdb SG!!!
200 //cdbEntry = "HLT/ConfigTPC/TPCdEdx";
201 //defaultNotify = " (default)";
205 HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
206 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
209 HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
213 TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
216 HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
220 HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
222 return ReadConfigurationString( pString->GetString().Data() );
226 int AliHLTTPCdEdxComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
228 // Configure the component
229 // There are few levels of configuration,
230 // parameters which are set on one step can be overwritten on the next step
232 //* read hard-coded values
234 SetDefaultConfiguration();
236 //* read the default CDB entry
238 int iResult1 = ReadCDBEntry( NULL, chainId );
240 //* read magnetic field
244 //* read the actual CDB entry if required
246 int iResult2 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
248 //* read extra parameters from input (if they are)
252 if ( commandLine && commandLine[0] != '\0' ) {
253 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
254 iResult3 = ReadConfigurationString( commandLine );
257 // Initialise the tracker here
259 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : iResult3 );
264 int AliHLTTPCdEdxComponent::DoInit( int argc, const char** argv )
266 // Configure the component
268 TString arguments = "";
269 for ( int i = 0; i < argc; i++ ) {
270 if ( !arguments.IsNull() ) arguments += " ";
271 arguments += argv[i];
274 int ret = Configure( NULL, NULL, arguments.Data() );
277 if (!TGeoGlobalMagField::Instance()) {
278 HLTError("magnetic field not initialized, please set up TGeoGlobalMagField and AliMagF");
282 AliTPCcalibDB::Instance()->SetRun(GetRunNo());
283 AliTPCcalibDB::Instance()->UpdateRunInformations(GetRunNo());
285 AliTPCcalibDB::Instance()->GetTransform()->SetCurrentRun(GetRunNo());
286 AliTPCcalibDB::Instance()->GetTransform()->SetCurrentTimeStamp( GetTimeStamp() );
287 AliTPCcalibDB::Instance()->GetTransform()->SetCurrentRecoParam(AliTPCRecoParam::GetHLTParam());
289 //AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform();
291 //AliTPCRecoParam *reco = transform->GetCurrentRecoParam();
293 //reco = new AliTPCRecoParam;
294 //reco->SetUseTotalCharge(0);
295 //transform->SetCurrentRecoParam( reco );
302 int AliHLTTPCdEdxComponent::DoDeinit()
304 // see header file for class documentation
310 int AliHLTTPCdEdxComponent::Reconfigure( const char* cdbEntry, const char* chainId )
312 // Reconfigure the component from OCDB .
314 return Configure( cdbEntry, chainId, NULL );
319 int AliHLTTPCdEdxComponent::DoEvent
321 const AliHLTComponentEventData& evtData,
322 const AliHLTComponentBlockData* blocks,
323 AliHLTComponentTriggerData& /*trigData*/,
324 AliHLTUInt8_t* outputPtr,
325 AliHLTUInt32_t& size,
326 vector<AliHLTComponentBlockData>& outputBlocks )
328 //* process the event
330 AliHLTUInt32_t maxBufferSize = size;
331 size = 0; // output size
333 if (!IsDataEvent()) return 0;
335 if ( evtData.fBlockCnt <= 0 ) {
336 HLTWarning( "no blocks in event" );
347 // Initialise the data pointers
349 for( int i=0; i<fkNPatches; i++ ){
350 delete[] fPatchClusters[i];
351 fPatchClusters[i] = 0;
352 fNPatchClusters[i] = 0;
355 int nBlocks = (int)evtData.fBlockCnt;
357 int nInputClusters = 0;
358 int nInputTracks = 0;
360 // first read all the clusters
362 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
363 const AliHLTComponentBlockData* iter = blocks+ndx;
364 if ( iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType ) continue;
365 Int_t slice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
366 Int_t patch=AliHLTTPCDefinitions::GetMinPatchNr(iter->fSpecification);
367 Int_t slicepatch=slice*6+patch;
368 if( slicepatch >= fkNPatches ){
369 HLTWarning("Wrong header of TPC cluster data, slice %d, patch %d",
373 AliHLTTPCClusterData* inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
374 nInputClusters += inPtrSP->fSpacePointCnt;
376 delete[] fPatchClusters[slicepatch];
377 fPatchClusters[slicepatch] = new AliTPCclusterMI[inPtrSP->fSpacePointCnt];
378 fNPatchClusters[slicepatch] = inPtrSP->fSpacePointCnt;
380 // create off-line clusters out of the HLT clusters
381 // todo: check which cluster information is really needed for the dEdx
383 for ( unsigned int i = 0; i < inPtrSP->fSpacePointCnt; i++ ) {
384 AliHLTTPCSpacePointData *chlt = &( inPtrSP->fSpacePoints[i] );
385 AliTPCclusterMI *c = fPatchClusters[slicepatch]+i;
389 c->SetSigmaY2(chlt->fSigmaY2);
391 c->SetSigmaZ2(chlt->fSigmaZ2);
392 c->SetQ( chlt->fCharge );
393 c->SetMax( chlt->fQMax );
395 Float_t padtime[3]={0,chlt->fY,chlt->fZ};
396 AliHLTTPCTransform::Slice2Sector(slice,chlt->fPadRow, sector, row);
397 AliHLTTPCTransform::Local2Raw( padtime, sector, row);
398 c->SetDetector( sector );
400 c->SetPad( (Int_t) padtime[1] );
401 c->SetTimeBin( (Int_t) padtime[2] );
406 // loop over the input tracks: calculate dEdx and write output
408 unsigned int outSize = 0;
409 AliHLTFloat32_t *outPtr = ( AliHLTFloat32_t * )( outputPtr );
411 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
412 pBlock!=NULL; pBlock=GetNextInputBlock()) {
414 AliHLTComponentBlockData outBlock;
415 FillBlockData( outBlock );
416 outBlock.fOffset = outSize;
418 outBlock.fDataType = kAliHLTDataTypedEdx|kAliHLTDataOriginTPC;
419 outBlock.fSpecification = pBlock->fSpecification;
421 AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) pBlock->fPtr;
422 int nTracks = dataPtr->fCount;
423 AliHLTExternalTrackParam* currTrack = dataPtr->fTracklets;
424 nInputTracks+=nTracks;
427 itr<nTracks && ( (AliHLTUInt8_t *)currTrack < ((AliHLTUInt8_t *) pBlock->fPtr)+pBlock->fSize);
430 // create an off-line track
431 AliHLTGlobalBarrelTrack gb(*currTrack);
433 tTPC.Set( gb.GetX(), gb.GetAlpha(),
434 gb.GetParameter(), gb.GetCovariance() );
438 for( UInt_t ic=0; ic<currTrack->fNPoints; ic++){
439 UInt_t id = currTrack->fPointIDs[ic];
440 int iSlice = AliHLTTPCSpacePointData::GetSlice(id);
441 int iPatch = AliHLTTPCSpacePointData::GetPatch(id);
442 int iCluster = AliHLTTPCSpacePointData::GetNumber(id);
443 if( iSlice<0 || iSlice>36 || iPatch<0 || iPatch>5 ){
444 HLTError("Corrupted TPC cluster Id: slice %d, patch %d, cluster %d",
445 iSlice, iPatch,iCluster );
448 AliTPCclusterMI *patchClusters = fPatchClusters[iSlice*6 + iPatch];
449 if( !patchClusters ){
450 HLTError("Clusters are missed for slice %d, patch %d",
454 if( iCluster >= fNPatchClusters[iSlice*6 + iPatch] ){
455 HLTError("TPC slice %d, patch %d: ClusterID==%d >= N Cluaters==%d ",
456 iSlice, iPatch,iCluster, fNPatchClusters[iSlice*6 + iPatch] );
459 AliTPCclusterMI *c = &(patchClusters[iCluster]);
461 int sec = c->GetDetector();
462 int row = c->GetRow();
464 row = row + AliHLTTPCTransform::GetNRowLow();
466 tTPC.SetClusterPointer( row, c );
468 AliTPCTrackerPoint &point = *( tTPC.GetTrackPoint( row ) );
469 tTPC.Propagate( TMath::DegToRad()*(sec%18*20.+10.), c->GetX(), fSolenoidBz );
470 Double_t angle2 = tTPC.GetSnp()*tTPC.GetSnp();
471 angle2 = (angle2<1) ?TMath::Sqrt(angle2/(1-angle2)) :10.;
472 point.SetAngleY( angle2 );
473 point.SetAngleZ( tTPC.GetTgl() );
478 if( outSize+3*sizeof( AliHLTFloat32_t ) > maxBufferSize ){
479 HLTWarning( "Output buffer size %d exceed", maxBufferSize );
486 tTPC.CookdEdx( 0.02, 0.6 );
487 outPtr[0] = tTPC.GetdEdx();
488 outPtr[1] = tTPC.GetSDEDX(0);
489 outPtr[2] = tTPC.GetNCDEDX(0);
493 outPtr[0] = tTPC.CookdEdxAnalytical(0.02,0.6,1,0,159,0);
498 outSize+=3*sizeof( AliHLTFloat32_t );
499 outBlock.fSize+=3*sizeof( AliHLTFloat32_t );
501 unsigned int step = sizeof( AliHLTExternalTrackParam ) + currTrack->fNPoints * sizeof( unsigned int );
502 currTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currTrack) + step );
504 if( iResult<0 ) break;
505 outputBlocks.push_back( outBlock );
510 fStatTime += timer.RealTime();
513 // Set log level to "Warning" for on-line system monitoring
514 int hz = ( int ) ( fStatTime > 1.e-10 ? fStatNEvents / fStatTime : 100000 );
516 HLTInfo( "TPCdEdx : %d clusters and %d tracks processed; average time %d Hz",
517 nInputClusters, nInputTracks, hz );