1 // $Id: AliHLTITSVertexerSPDComponent.cxx 32659 2009-06-02 16:08:40Z sgorbuno $
2 // **************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project *
4 // ALICE Experiment at CERN, All rights reserved. *
6 // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
7 // Ivan Kisel <kisel@kip.uni-heidelberg.de> *
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 //***************************************************************************
20 /// @file AliHLTITSVertexerSPDComponent.cxx
21 /// @author Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de>
23 /// @brief An ITS tracker processing component for the HLT
26 /////////////////////////////////////////////////////
28 // a ITS tracker processing component for the HLT //
30 /////////////////////////////////////////////////////
36 #include "AliHLTITSVertexerSPDComponent.h"
37 #include "AliHLTArray.h"
38 #include "AliExternalTrackParam.h"
39 #include "TStopwatch.h"
41 #include "AliCDBEntry.h"
42 #include "AliCDBManager.h"
43 #include "AliGeomManager.h"
44 #include "TObjString.h"
45 #include "TObjArray.h"
46 #include "AliITStrackerHLT.h"
47 #include "AliHLTITSSpacePointData.h"
48 #include "AliHLTITSClusterDataFormat.h"
49 #include "AliHLTDataTypes.h"
50 #include "AliHLTExternalTrackParam.h"
51 #include "AliHLTGlobalBarrelTrack.h"
52 #include "AliGeomManager.h"
53 #include "AliESDVertex.h"
55 /** ROOT macro for the implementation of ROOT specific class methods */
56 ClassImp( AliHLTITSVertexerSPDComponent )
57 AliHLTITSVertexerSPDComponent::AliHLTITSVertexerSPDComponent()
59 fAutoCalibration(1000),
70 // see header file for class documentation
72 // refer to README to build package
74 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
76 for( int i=0; i<9; i++ ) fSum[i] = 0;
83 AliHLTITSVertexerSPDComponent::AliHLTITSVertexerSPDComponent( const AliHLTITSVertexerSPDComponent& )
86 fAutoCalibration(1000),
97 // see header file for class documentation
98 HLTFatal( "copy constructor untested" );
101 AliHLTITSVertexerSPDComponent& AliHLTITSVertexerSPDComponent::operator=( const AliHLTITSVertexerSPDComponent& )
103 // see header file for class documentation
104 HLTFatal( "assignment operator untested" );
108 AliHLTITSVertexerSPDComponent::~AliHLTITSVertexerSPDComponent()
110 // see header file for class documentation
111 for( int i=0; i<9; i++ ){
120 // Public functions to implement AliHLTComponent's interface.
121 // These functions are required for the registration process
124 const char* AliHLTITSVertexerSPDComponent::GetComponentID()
126 // see header file for class documentation
127 return "ITSVertexerSPD";
130 void AliHLTITSVertexerSPDComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
132 // see header file for class documentation
134 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD );
137 AliHLTComponentDataType AliHLTITSVertexerSPDComponent::GetOutputDataType()
139 // see header file for class documentation
140 return kAliHLTMultipleDataType;
143 int AliHLTITSVertexerSPDComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
146 // see header file for class documentation
148 tgtList.push_back( kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS);
149 return tgtList.size();
152 void AliHLTITSVertexerSPDComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
154 // define guess for the output data size
155 constBase = 10000; // minimum size
156 inputMultiplier = 0.5; // size relative to input
159 AliHLTComponent* AliHLTITSVertexerSPDComponent::Spawn()
161 // see header file for class documentation
162 return new AliHLTITSVertexerSPDComponent;
165 void AliHLTITSVertexerSPDComponent::SetDefaultConfiguration()
167 // Set default configuration for the CA tracker component
168 // Some parameters can be later overwritten from the OCDB
170 fAutoCalibration = 1000;
181 int AliHLTITSVertexerSPDComponent::ReadConfigurationString( const char* arguments )
183 // Set configuration parameters for the CA tracker component from the string
186 if ( !arguments ) return iResult;
188 TString allArgs = arguments;
190 int bMissingParam = 0;
192 TObjArray* pTokens = allArgs.Tokenize( " " );
194 int nArgs = pTokens ? pTokens->GetEntries() : 0;
196 for ( int i = 0; i < nArgs; i++ ) {
197 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
198 if ( argument.IsNull() ) continue;
200 if ( argument.CompareTo( "-runVertex" ) == 0 ) {
201 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
202 fDefRunVtx[0] = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
203 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
204 fDefRunVtx[1] = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
205 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
206 fDefRunVtx[2] = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
207 HLTInfo( "Default run vertex is set to (%f,%f,%f)",fDefRunVtx[0],
208 fDefRunVtx[1],fDefRunVtx[2] );
212 if ( argument.CompareTo( "-zRange" ) == 0 ) {
213 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
214 fZRange = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
215 HLTInfo( "Z range for the vertex search is set to +-%f cm", fZRange );
219 if ( argument.CompareTo( "-zBinSize" ) == 0 ) {
220 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
221 fZBinSize = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
222 HLTInfo( "Size of the Z bin for the vertex search is set to %f cm", fZBinSize );
226 if ( argument.CompareTo( "-beamDiamondCalibration" ) == 0 ) {
227 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
228 fAutoCalibration = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
229 HLTInfo( "N events for recalibration of the run vertex is set to: %d", fAutoCalibration );
234 HLTError( "Unknown option \"%s\"", argument.Data() );
239 if ( bMissingParam ) {
240 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
248 int AliHLTITSVertexerSPDComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
250 // see header file for class documentation
252 const char* defaultNotify = "";
255 return 0;// need to add the HLT/ConfigITS/ITSTracker directory to cdb SG!!!
256 cdbEntry = "HLT/ConfigITS/ITSTracker";
257 defaultNotify = " (default)";
261 HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
262 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
265 HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
269 TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
272 HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
276 HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
278 return ReadConfigurationString( pString->GetString().Data() );
282 int AliHLTITSVertexerSPDComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
284 // Configure the component
285 // There are few levels of configuration,
286 // parameters which are set on one step can be overwritten on the next step
288 //* read hard-coded values
290 SetDefaultConfiguration();
292 //* read the default CDB entry
294 int iResult1 = ReadCDBEntry( NULL, chainId );
296 //* read the actual CDB entry if required
298 int iResult2 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
300 //* read extra parameters from input (if they are)
304 if ( commandLine && commandLine[0] != '\0' ) {
305 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
306 iResult3 = ReadConfigurationString( commandLine );
309 // Initialise the tracker here
311 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : iResult3 );
316 int AliHLTITSVertexerSPDComponent::DoInit( int argc, const char** argv )
318 // Configure the ITS tracker component
320 SetDefaultConfiguration();
322 if(AliGeomManager::GetGeometry()==NULL){
323 AliGeomManager::LoadGeometry("");
325 AliGeomManager::ApplyAlignObjsFromCDB("ITS");
327 TString arguments = "";
328 for ( int i = 0; i < argc; i++ ) {
329 if ( !arguments.IsNull() ) arguments += " ";
330 arguments += argv[i];
333 int ret = Configure( NULL, NULL, arguments.Data() );
335 for( int i=0; i<3; i++){
336 fRunVtx[i] = fDefRunVtx[i];
337 fRunVtxNew[i] = fDefRunVtx[i];
342 for( int i=0; i<9; i++ ) delete[] fSum[i];
347 fNZBins = ( (int) (2*fZRange/fZBinSize ))+1;
349 for( int i=0; i<9; i++ ) fSum[i] = new double [fNZBins];
351 fSumW = new double [fNZBins];
352 fSumN = new int [fNZBins];
358 int AliHLTITSVertexerSPDComponent::DoDeinit()
360 // see header file for class documentation
362 for( int i=0; i<9; i++ ){
371 SetDefaultConfiguration();
378 int AliHLTITSVertexerSPDComponent::Reconfigure( const char* cdbEntry, const char* chainId )
380 // Reconfigure the component from OCDB .
382 return Configure( cdbEntry, chainId, NULL );
386 int AliHLTITSVertexerSPDComponent::DoEvent
388 const AliHLTComponentEventData& evtData,
389 const AliHLTComponentBlockData* blocks,
390 AliHLTComponentTriggerData& /*trigData*/,
391 AliHLTUInt8_t* /*outputPtr*/,
392 AliHLTUInt32_t& size,
393 vector<AliHLTComponentBlockData>& /*outputBlocks*/ )
397 //AliHLTUInt32_t maxBufferSize = size;
398 size = 0; // output size
400 if (!IsDataEvent()) return 0;
402 if ( evtData.fBlockCnt <= 0 ) {
403 HLTWarning( "no blocks in event" );
409 // Event reconstruction in ITS
413 int nBlocks = evtData.fBlockCnt;
414 int nClustersTotal = 0;
417 const int kNPhiBins = 20;
418 const double kDPhi = TMath::TwoPi() / kNPhiBins;
419 double vtxX = fRunVtx[0], vtxY = fRunVtx[1], vtxZ = fRunVtx[2];
421 std::vector<AliHLTITSVertexerSPDComponent::AliHLTITSVZCluster> clusters[2][ kNPhiBins ];
423 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
425 const AliHLTComponentBlockData* iter = blocks+ndx;
427 // Read ITS SPD clusters
429 if ( iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD) ){
431 AliHLTITSClusterData *inPtr=reinterpret_cast<AliHLTITSClusterData*>( iter->fPtr );
432 int nClusters = inPtr->fSpacePointCnt;
433 nClustersTotal+=nClusters;
434 for( int icl=0; icl<nClusters; icl++ ){
435 AliHLTITSSpacePointData &d = inPtr->fSpacePoints[icl];
436 if( d.fLayer>1 ) continue;// SPD only;
437 if( d.fLayer<0 ) continue;// SPD only;
438 Int_t lab[4] = { d.fTracks[0], d.fTracks[1], d.fTracks[2], d.fIndex };
439 Int_t info[3] = { d.fNy, d.fNz, d.fLayer };
440 Float_t hit[6] = { d.fY, d.fZ, d.fSigmaY2, d.fSigmaZ2, d.fQ, d.fSigmaYZ };
441 if( d.fLayer==4 ) hit[5] = -hit[5];
444 AliITSRecPoint p( lab, hit, info );
447 HLTWarning("Can not misalign an SPD cluster");
453 double phi = TMath::ATan2( xyz[1]-vtxY, xyz[0]-vtxX );
454 if( phi<0 ) phi+=TMath::TwoPi();
455 int iphi = (int ) phi/kDPhi;
456 if( iphi<0 ) iphi = 0;
457 if( iphi>=kNPhiBins ) iphi = kNPhiBins-1;
458 AliHLTITSVZCluster c;
462 clusters[d.fLayer][iphi].push_back( c );
465 }// end read input blocks
468 // Reconstruct the vertex
470 TStopwatch timerReco;
472 double zScale = 1./fZBinSize;
474 // fit few times decreasing the radius cut
476 double vtxDR2[5] = { 1.*1., .5*.5, .4*.4, .4*.4, .2*.2};
477 double vtxDZ [5] = { 1., .5, .3, .3, .3};
481 for( int iter = 0; iter<3; iter++ ){
483 bool doZBins = (iter<2);
484 int nSearchBins = doZBins ?fNZBins :1;
486 for( int i=0; i<nSearchBins; i++ ){
501 for( int iPhi=0; iPhi<kNPhiBins; iPhi++ ){
502 int nCluUp = clusters[1][iPhi].size();
503 int nCluDn = clusters[0][iPhi].size();
504 for( int icUp=0; icUp<nCluUp; icUp++ ){
505 AliHLTITSVZCluster &cu = clusters[1][iPhi][icUp];
506 double x0 = cu.fX - vtxX;
507 double y0 = cu.fY - vtxY;
508 double z0 = cu.fZ;// - vtxZ;
509 double bestR2 = 1.e10;
510 int bestDn=-1, bestBinDn =0;
511 double bestP[3]={0,0,0};
512 for( int icDn=0; icDn<nCluDn; icDn++ ){
513 AliHLTITSVZCluster &cd = clusters[0][iPhi][icDn];
514 double x1 = cd.fX - vtxX;
515 double y1 = cd.fY - vtxY;
516 double z1 = cd.fZ;// - vtxZ;
519 double l2 = 1./(dx*dx + dy*dy);
520 double a = x1*y0 - x0*y1;
522 if( r2 > vtxDR2[iter] ) continue;
523 if( r2 > bestR2 ) continue;
524 //double xv = -dy*a*l2;
525 //double yv = dx*a*l2;
526 double zv = ( (x1*z0-x0*z1)*dx + (y1*z0-y0*z1)*dy )*l2;
529 zbin = (int)((zv - fZMin)*zScale);
530 if( zbin<0 || zbin>=fNZBins ) continue;
533 if( TMath::Abs( zv - vtxZ ) > vtxDZ[ iter ] ) continue;
542 if( bestDn < 0 ) continue;
544 double dx = bestP[0] - x0;
545 double dy = bestP[1] - y0;
546 double dz = bestP[2] - z0;
547 double w = 1./(1.+bestR2);
551 // A_i*x + B_i*y + C_i*z = D_i
553 // Sum[0] = sum A_i*A_i
554 // Sum[1] = sum B_i*A_i
555 // Sum[2] = sum B_i*B_i
556 // Sum[3] = sum C_i*A_i
557 // Sum[4] = sum C_i*B_i
558 // Sum[5] = sum C_i*C_i
559 // Sum[6] = sum A_i*D_i
560 // Sum[7] = sum B_i*D_i
561 // Sum[8] = sum C_i*D_i
563 double n = w / TMath::Sqrt(dx*dx + dy*dy + dz*dz);
568 a = dy; b = -dx; c = 0; d = dy*x0 - dx*y0;
570 fSum[0][bestBinDn]+= a*a;
571 fSum[1][bestBinDn]+= b*a;
572 fSum[2][bestBinDn]+= b*b;
573 //fSum[3][bestBinDn]+= c*a;
574 //fSum[4][bestBinDn]+= c*b;
575 //fSum[5][bestBinDn]+= c*c;
576 fSum[6][bestBinDn]+= a*d;
577 fSum[7][bestBinDn]+= b*d;
578 //fSum[8][bestBinDn]+= c*d;
580 a = dz; b = 0; c = -dx; d = dz*x0 - dx*z0;
582 fSum[0][bestBinDn]+= a*a;
583 //fSum[1][bestBinDn]+= b*a;
584 //fSum[2][bestBinDn]+= b*b;
585 fSum[3][bestBinDn]+= c*a;
586 //fSum[4][bestBinDn]+= c*b;
587 fSum[5][bestBinDn]+= c*c;
588 fSum[6][bestBinDn]+= a*d;
589 //fSum[7][bestBinDn]+= b*d;
590 fSum[8][bestBinDn]+= c*d;
593 a = 0; b = dz; c = -dy; d = dz*y0 - dy*z0;
595 //fSum[0][bestBinDn]+= a*a;
596 //fSum[1][bestBinDn]+= b*a;
597 fSum[2][bestBinDn]+= b*b;
598 //fSum[3][bestBinDn]+= c*a;
599 fSum[4][bestBinDn]+= c*b;
600 fSum[5][bestBinDn]+= c*c;
601 //fSum[6][bestBinDn]+= a*d;
602 fSum[7][bestBinDn]+= b*d;
603 fSum[8][bestBinDn]+= c*d;
606 a = dz; b = 0; c = -dx; d = dz*x0 - dx*z0;
608 fSum[0][bestBinDn]+= a*a;
609 //fSum[1][bestBinDn]+= b*a;
610 //fSum[2][bestBinDn]+= b*b;
611 fSum[3][bestBinDn]+= c*a;
612 //fSum[4][bestBinDn]+= c*b;
613 fSum[5][bestBinDn]+= c*c;
614 fSum[6][bestBinDn]+= a*d;
615 //fSum[7][bestBinDn]+= b*d;
616 fSum[8][bestBinDn]+= c*d;
626 for( int i=0; i<nSearchBins; i++ ){
632 if( bestBin<0 || fSumN[bestBin] < 5 ){
637 // calculate the vertex position in the best bin
638 Double_t w[6] = { fSum[0][bestBin],
639 fSum[1][bestBin], fSum[2][bestBin],
640 fSum[3][bestBin], fSum[4][bestBin], fSum[5][bestBin] };
643 wI[0] = w[2]*w[5] - w[4]*w[4];
644 wI[1] = w[3]*w[4] - w[1]*w[5];
645 wI[2] = w[0]*w[5] - w[3]*w[3];
646 wI[3] = w[1]*w[4] - w[2]*w[3];
647 wI[4] = w[1]*w[3] - w[0]*w[4];
648 wI[5] = w[0]*w[2] - w[1]*w[1];
650 Double_t s = ( w[0]*wI[0] + w[1]*wI[1] + w[3]*wI[3] );
665 vtxX += wI[0]*fSum[6][bestBin] + wI[1]*fSum[7][bestBin] + wI[3]*fSum[8][bestBin];
666 vtxY += wI[1]*fSum[6][bestBin] + wI[2]*fSum[7][bestBin] + wI[4]*fSum[8][bestBin];
667 vtxZ = wI[3]*fSum[6][bestBin] + wI[4]*fSum[7][bestBin] + wI[5]*fSum[8][bestBin];
668 //cout<<"SG: "<<iter<<": "<<vtxX<<" "<<vtxY<<" "<<vtxZ<<endl;
673 double nNew = fRunVtxNew[3] + nv;
674 double v[3] = {vtxX, vtxY, vtxZ};
675 for( int i=0; i<3; i++){
676 fRunVtxNew[i] = ( fRunVtxNew[i]*fRunVtxNew[3] + v[i]*nv )/nNew;
678 fRunVtxNew[3] = nNew;
681 if( fAutoCalibration>0 && fRunVtxNew[3] >= fAutoCalibration ){
682 for( int i=0; i<4; i++ ){
683 fRunVtx[i] = fRunVtxNew[i];
686 //cout<<"ITSVertexerSPD: set run vtx to "<<fRunVtx[0]<<" "<<fRunVtx[1]<<" "<<fRunVtx[2]<<endl;
687 if( fRunVtx[0]>3. ) fRunVtx[0] = 3;
688 if( fRunVtx[0]<-3. ) fRunVtx[0] = -3;
689 if( fRunVtx[1]>3. ) fRunVtx[1] = 3;
690 if( fRunVtx[1]<-3. ) fRunVtx[1] = -3;
691 if( fRunVtx[2]>30. ) fRunVtx[2] = 30;
692 if( fRunVtx[2]<30. ) fRunVtx[2] = -30;
700 double pos[3] = {vtxX, vtxY, vtxZ};
702 double cov[6] = {s*s,0,s*s,0,0,s*s};
703 AliESDVertex v(pos, cov, 0, fSumN[bestBin]);
704 PushBack( (TObject*) &v, kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS,0 );
706 //cout<<"ITSVertexerSPD: vtx found "<<vtxX<<" "<<vtxY<<" "<<vtxZ<<endl;
710 fFullTime += timer.RealTime();
711 fRecoTime += timerReco.RealTime();
714 // Set log level to "Warning" for on-line system monitoring
715 int hz = ( int ) ( fFullTime > 1.e-10 ? fNEvents / fFullTime : 100000 );
716 int hz1 = ( int ) ( fRecoTime > 1.e-10 ? fNEvents / fRecoTime : 100000 );
717 HLTInfo( "ITS Z Vertexer: input %d clusters; time: full %d / reco %d Hz",
718 nClustersTotal, hz, hz1 );