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& )
76 // see header file for class documentation
77 HLTFatal( "copy constructor untested" );
80 AliHLTTPCdEdxComponent& AliHLTTPCdEdxComponent::operator=( const AliHLTTPCdEdxComponent& )
82 // see header file for class documentation
83 HLTFatal( "assignment operator untested" );
84 for( int i=0; i<fkNPatches; i++ ){
85 fPatchClusters[i] = 0;
86 fNPatchClusters[i] = 0;
91 AliHLTTPCdEdxComponent::~AliHLTTPCdEdxComponent()
93 // see header file for class documentation
94 for( int i=0; i<fkNPatches; i++ ){
95 delete[] fPatchClusters[i];
100 // Public functions to implement AliHLTComponent's interface.
101 // These functions are required for the registration process
104 const char* AliHLTTPCdEdxComponent::GetComponentID()
106 // see header file for class documentation
110 void AliHLTTPCdEdxComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
112 // see header file for class documentation
114 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
115 list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
118 AliHLTComponentDataType AliHLTTPCdEdxComponent::GetOutputDataType()
120 // see header file for class documentation
121 return kAliHLTDataTypedEdx|kAliHLTDataOriginTPC;
124 void AliHLTTPCdEdxComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
126 // define guess for the output data size
127 constBase = 200; // minimum size
128 inputMultiplier = 0.1; // size relative to input
131 AliHLTComponent* AliHLTTPCdEdxComponent::Spawn()
133 // see header file for class documentation
134 return new AliHLTTPCdEdxComponent;
137 void AliHLTTPCdEdxComponent::SetDefaultConfiguration()
139 // Set default configuration for the CA tracker component
140 // Some parameters can be later overwritten from the OCDB
142 fSolenoidBz = -5.00668;
147 int AliHLTTPCdEdxComponent::ReadConfigurationString( const char* arguments )
149 // Set configuration parameters for the CA tracker component from the string
152 if ( !arguments ) return iResult;
154 TString allArgs = arguments;
156 int bMissingParam = 0;
158 TObjArray* pTokens = allArgs.Tokenize( " " );
160 int nArgs = pTokens ? pTokens->GetEntries() : 0;
162 for ( int i = 0; i < nArgs; i++ ) {
163 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
164 if ( argument.IsNull() ) continue;
166 if ( argument.CompareTo( "-solenoidBz" ) == 0 ) {
167 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
168 HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
172 HLTError( "Unknown option \"%s\"", argument.Data() );
177 if ( bMissingParam ) {
178 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
186 int AliHLTTPCdEdxComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
188 // see header file for class documentation
190 const char* defaultNotify = "";
193 return 0;// need to add the HLT/ConfigTPC/TPCdEdx directory to cdb SG!!!
194 cdbEntry = "HLT/ConfigTPC/TPCdEdx";
195 defaultNotify = " (default)";
199 HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
200 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
203 HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
207 TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
210 HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
214 HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
216 return ReadConfigurationString( pString->GetString().Data() );
220 int AliHLTTPCdEdxComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
222 // Configure the component
223 // There are few levels of configuration,
224 // parameters which are set on one step can be overwritten on the next step
226 //* read hard-coded values
228 SetDefaultConfiguration();
230 //* read the default CDB entry
232 int iResult1 = ReadCDBEntry( NULL, chainId );
234 //* read magnetic field
236 int iResult2 = 0;//ReadCDBEntry( kAliHLTCDBSolenoidBz, chainId );
239 //* read the actual CDB entry if required
241 int iResult3 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
243 //* read extra parameters from input (if they are)
247 if ( commandLine && commandLine[0] != '\0' ) {
248 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
249 iResult4 = ReadConfigurationString( commandLine );
252 // Initialise the tracker here
254 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : ( iResult3 ? iResult3 : iResult4 ) );
259 int AliHLTTPCdEdxComponent::DoInit( int argc, const char** argv )
261 // Configure the component
263 TString arguments = "";
264 for ( int i = 0; i < argc; i++ ) {
265 if ( !arguments.IsNull() ) arguments += " ";
266 arguments += argv[i];
269 int ret = Configure( NULL, NULL, arguments.Data() );
272 if (!TGeoGlobalMagField::Instance()) {
273 HLTError("magnetic field not initialized, please set up TGeoGlobalMagField and AliMagF");
277 //AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform();
279 //AliTPCRecoParam *reco = transform->GetCurrentRecoParam();
281 //reco = new AliTPCRecoParam;
282 //reco->SetUseTotalCharge(0);
283 //transform->SetCurrentRecoParam( reco );
290 int AliHLTTPCdEdxComponent::DoDeinit()
292 // see header file for class documentation
298 int AliHLTTPCdEdxComponent::Reconfigure( const char* cdbEntry, const char* chainId )
300 // Reconfigure the component from OCDB .
302 return Configure( cdbEntry, chainId, NULL );
307 int AliHLTTPCdEdxComponent::DoEvent
309 const AliHLTComponentEventData& evtData,
310 const AliHLTComponentBlockData* blocks,
311 AliHLTComponentTriggerData& /*trigData*/,
312 AliHLTUInt8_t* outputPtr,
313 AliHLTUInt32_t& size,
314 vector<AliHLTComponentBlockData>& outputBlocks )
316 //* process the event
318 AliHLTUInt32_t maxBufferSize = size;
319 size = 0; // output size
321 if (!IsDataEvent()) return 0;
323 if ( evtData.fBlockCnt <= 0 ) {
324 HLTWarning( "no blocks in event" );
335 // Initialise the data pointers
337 for( int i=0; i<fkNPatches; i++ ){
338 delete[] fPatchClusters[i];
339 fPatchClusters[i] = 0;
340 fNPatchClusters[i] = 0;
343 int nBlocks = (int)evtData.fBlockCnt;
345 int nInputClusters = 0;
346 int nInputTracks = 0;
348 // first read all the clusters
350 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
351 const AliHLTComponentBlockData* iter = blocks+ndx;
352 if ( iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType ) continue;
353 Int_t slice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
354 Int_t patch=AliHLTTPCDefinitions::GetMinPatchNr(iter->fSpecification);
355 Int_t slicepatch=slice*6+patch;
356 if( slicepatch > fkNPatches ){
357 HLTWarning("Wrong header of TPC cluster data, slice %d, patch %d",
361 AliHLTTPCClusterData* inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
362 nInputClusters += inPtrSP->fSpacePointCnt;
364 delete[] fPatchClusters[slicepatch];
365 fPatchClusters[slicepatch] = new AliTPCclusterMI[inPtrSP->fSpacePointCnt];
366 fNPatchClusters[slicepatch] = inPtrSP->fSpacePointCnt;
368 // create off-line clusters out of the HLT clusters
369 // todo: check which cluster information is really needed for the dEdx
371 for ( unsigned int i = 0; i < inPtrSP->fSpacePointCnt; i++ ) {
372 AliHLTTPCSpacePointData *chlt = &( inPtrSP->fSpacePoints[i] );
373 AliTPCclusterMI *c = fPatchClusters[slicepatch]+i;
377 c->SetSigmaY2(chlt->fSigmaY2);
379 c->SetSigmaZ2(chlt->fSigmaZ2);
380 c->SetQ( chlt->fCharge );
381 c->SetMax( chlt->fQMax );
383 Float_t padtime[3]={0,chlt->fY,chlt->fZ};
384 AliHLTTPCTransform::Slice2Sector(slice,chlt->fPadRow, sector, row);
385 AliHLTTPCTransform::Local2Raw( padtime, sector, row);
386 c->SetDetector( sector );
388 c->SetPad( (Int_t) padtime[1] );
389 c->SetTimeBin( (Int_t) padtime[2] );
394 // loop over the input tracks: calculate dEdx and write output
396 unsigned int outSize = 0;
397 AliHLTFloat32_t *outPtr = ( AliHLTFloat32_t * )( outputPtr );
399 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
400 pBlock!=NULL; pBlock=GetNextInputBlock()) {
402 AliHLTComponentBlockData outBlock;
403 FillBlockData( outBlock );
404 outBlock.fOffset = outSize;
406 outBlock.fDataType = kAliHLTDataTypedEdx|kAliHLTDataOriginTPC;
407 outBlock.fSpecification = pBlock->fSpecification;
409 AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) pBlock->fPtr;
410 int nTracks = dataPtr->fCount;
411 AliHLTExternalTrackParam* currTrack = dataPtr->fTracklets;
412 nInputTracks+=nTracks;
415 itr<nTracks && ( (AliHLTUInt8_t *)currTrack < ((AliHLTUInt8_t *) pBlock->fPtr)+pBlock->fSize);
418 // create an off-line track
419 AliHLTGlobalBarrelTrack gb(*currTrack);
421 tTPC.Set( gb.GetX(), gb.GetAlpha(),
422 gb.GetParameter(), gb.GetCovariance() );
426 for( UInt_t ic=0; ic<currTrack->fNPoints; ic++){
427 UInt_t id = currTrack->fPointIDs[ic];
429 int iPatch = (id>>22)&0x7;
430 int iCluster = id&0x3fffff;
431 if( iSlice<0 || iSlice>36 || iPatch<0 || iPatch>5 ){
432 HLTError("Corrupted TPC cluster Id: slice %d, patch %d, cluster %d",
433 iSlice, iPatch,iCluster );
436 AliTPCclusterMI *patchClusters = fPatchClusters[iSlice*6 + iPatch];
437 if( !patchClusters ){
438 HLTError("Clusters are missed for slice %d, patch %d",
442 if( iCluster >= fNPatchClusters[iSlice*6 + iPatch] ){
443 HLTError("TPC slice %d, patch %d: ClusterID==%d >= N Cluaters==%d ",
444 iSlice, iPatch,iCluster, fNPatchClusters[iSlice*6 + iPatch] );
447 AliTPCclusterMI *c = &(patchClusters[iCluster]);
449 int sec = c->GetDetector();
450 int row = c->GetRow();
452 row = row + AliHLTTPCTransform::GetNRowLow();
454 tTPC.SetClusterPointer( row, c );
456 AliTPCTrackerPoint &point = *( tTPC.GetTrackPoint( row ) );
457 tTPC.Propagate( TMath::DegToRad()*(sec%18*20.+10.), c->GetX(), fSolenoidBz );
458 Double_t angle2 = tTPC.GetSnp()*tTPC.GetSnp();
459 angle2 = (angle2<1) ?TMath::Sqrt(angle2/(1-angle2)) :10.;
460 point.SetAngleY( angle2 );
461 point.SetAngleZ( tTPC.GetTgl() );
466 if( outSize+3*sizeof( AliHLTFloat32_t ) > maxBufferSize ){
467 HLTWarning( "Output buffer size %d exceed", maxBufferSize );
472 tTPC.CookdEdx( 0.02, 0.6 );
473 outPtr[0] = tTPC.GetdEdx();
474 outPtr[1] = tTPC.GetSDEDX(0);
475 outPtr[2] = tTPC.GetNCDEDX(0);
477 outSize+=3*sizeof( AliHLTFloat32_t );
478 outBlock.fSize+=3*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 );