]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/global/AliHLTGlobalVertexerComponent.cxx
Fixes of older problems and adaptation to heavy ions.
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalVertexerComponent.cxx
CommitLineData
4d5ee3db 1//**************************************************************************
2//* This file is property of and copyright by the ALICE HLT Project *
3//* ALICE Experiment at CERN, All rights reserved. *
4//* *
5//* Primary Authors: S.Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
6//* for The ALICE HLT Project. *
7//* *
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. *
15//**************************************************************************
16
17/** @file AliHLTGlobalVertexerComponent.cxx
18 @author Sergey Gorbunov
19 @brief Component for reconstruct primary vertex and V0's
20*/
21
22#if __GNUC__>= 3
23using namespace std;
24#endif
25
26#include "AliHLTGlobalVertexerComponent.h"
d9386025 27#include "AliHLTDataTypes.h"
28#include "AliHLTExternalTrackParam.h"
29#include "AliHLTGlobalBarrelTrack.h"
4d5ee3db 30#include "AliCDBEntry.h"
31#include "AliCDBManager.h"
32#include <TFile.h>
33#include <TString.h>
34#include "TObjString.h"
35#include "TObjArray.h"
4d5ee3db 36#include "AliESDEvent.h"
37#include "AliESDtrack.h"
38#include "AliESDVertex.h"
39#include "AliESDv0.h"
40#include "AliHLTMessage.h"
4d5ee3db 41#include "TMath.h"
42#include "AliKFParticle.h"
43#include "AliKFVertex.h"
9222a93a 44#include "TStopwatch.h"
4d5ee3db 45
46/** ROOT macro for the implementation of ROOT specific class methods */
47ClassImp(AliHLTGlobalVertexerComponent)
48
49AliHLTGlobalVertexerComponent::AliHLTGlobalVertexerComponent()
50:
d9386025 51 fNTracks(0),
4d5ee3db 52 fTrackInfos(0),
57a4102f 53 fPrimaryVtx(),
608cfbda 54 fFitTracksToVertex(1),
4d5ee3db 55 fConstrainedTrackDeviation(4.),
56 fV0DaughterPrimDeviation( 2.5 ),
57 fV0PrimDeviation( 3.5 ),
58 fV0Chi(3.5),
9222a93a 59 fV0DecayLengthInSigmas(3.),
d9386025 60 fV0TimeLimit(10.e-3),
57a4102f 61 fBenchmark("GlobalVertexer")
4d5ee3db 62{
63 // see header file for class documentation
64 // or
65 // refer to README to build package
66 // or
67 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
68
69}
70
71AliHLTGlobalVertexerComponent::~AliHLTGlobalVertexerComponent()
72{
73 // see header file for class documentation
74
dc546924 75 if( fTrackInfos ) delete[] fTrackInfos;
4d5ee3db 76}
77
78// Public functions to implement AliHLTComponent's interface.
79// These functions are required for the registration process
80
81const char* AliHLTGlobalVertexerComponent::GetComponentID()
82{
83 // see header file for class documentation
84
85 return "GlobalVertexer";
86}
87
88void AliHLTGlobalVertexerComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
89{
90 // see header file for class documentation
91 list.clear();
d9386025 92 list.push_back( kAliHLTDataTypeESDObject );
93 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginITS );
94 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
4d5ee3db 95}
96
97AliHLTComponentDataType AliHLTGlobalVertexerComponent::GetOutputDataType()
98{
99 // see header file for class documentation
100 return kAliHLTMultipleDataType;
101}
102
103int AliHLTGlobalVertexerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
104
105{
106 // see header file for class documentation
107 tgtList.clear();
d9386025 108 tgtList.push_back( kAliHLTDataTypeGlobalVertexer|kAliHLTDataOriginOut);
109 tgtList.push_back( kAliHLTDataTypeESDVertex|kAliHLTDataOriginOut);
110 tgtList.push_back( kAliHLTDataTypeESDObject|kAliHLTDataOriginOut);
4d5ee3db 111 return tgtList.size();
112}
113
114void AliHLTGlobalVertexerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
115{
116 // see header file for class documentation
117 // XXX TODO: Find more realistic values.
118 constBase = 80000;
119 inputMultiplier = 2.;
120}
121
122AliHLTComponent* AliHLTGlobalVertexerComponent::Spawn()
123{
124 // see header file for class documentation
125 return new AliHLTGlobalVertexerComponent;
126}
127
128int AliHLTGlobalVertexerComponent::DoInit( int argc, const char** argv )
129{
130 // init
9222a93a 131
57a4102f 132 fBenchmark.Reset();
133 fBenchmark.SetTimer(0,"total");
134 fBenchmark.SetTimer(1,"convert");
135 fBenchmark.SetTimer(2,"vprim");
136 fBenchmark.SetTimer(3,"v0");
d9386025 137 fV0TimeLimit = 10.e-3;
4d5ee3db 138
4d5ee3db 139 int iResult=0;
140 TString configuration="";
141 TString argument="";
142 for (int i=0; i<argc && iResult>=0; i++) {
143 argument=argv[i];
144 if (!configuration.IsNull()) configuration+=" ";
145 configuration+=argument;
146 }
147
148 if (!configuration.IsNull()) {
149 iResult=Configure(configuration.Data());
150 }
151
152 return iResult;
153}
154
155int AliHLTGlobalVertexerComponent::DoDeinit()
156{
157 // see header file for class documentation
158
dc546924 159 if( fTrackInfos ) delete[] fTrackInfos;
4d5ee3db 160
161 fTrackInfos = 0;
608cfbda 162 fFitTracksToVertex = 1;
4d5ee3db 163 fConstrainedTrackDeviation = 4.;
164 fV0DaughterPrimDeviation = 2.5 ;
165 fV0PrimDeviation =3.5;
166 fV0Chi = 3.5;
167 fV0DecayLengthInSigmas = 3.;
d9386025 168 fV0TimeLimit = 10.e-3;
9222a93a 169
4d5ee3db 170 return 0;
171}
172
d9386025 173int AliHLTGlobalVertexerComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/,
174 AliHLTComponentTriggerData& /*trigData*/ )
4d5ee3db 175{
9222a93a 176 //cout<<"AliHLTGlobalVertexerComponent::DoEvent called"<<endl;
d9386025 177
4d5ee3db 178 if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) )
179 return 0;
180
dc546924 181 int iResult = 0;
57a4102f 182 //cout<<"SG: GlobalVertexer:: DoEvent called"<<endl;
183 fBenchmark.StartNewEvent();
184 fBenchmark.Start(0);
185
d9386025 186 vector< AliExternalTrackParam > tracks;
187 vector< int > trackId;
188 vector< pair<int,int> > v0s;
4d5ee3db 189
d9386025 190 AliESDEvent *event = 0;
4d5ee3db 191
57a4102f 192 for( const AliHLTComponentBlockData *i= GetFirstInputBlock(kAliHLTDataTypeESDObject); i!=NULL; i=GetNextInputBlock() ){
193 fBenchmark.AddInput(i->fSize);
194 }
195
196
d9386025 197 for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDObject); iter != NULL; iter = GetNextInputObject() ) {
198 event = dynamic_cast<AliESDEvent*>(const_cast<TObject*>( iter ) );
dc546924 199 if( !event ) continue;
57a4102f 200
4d5ee3db 201 event->GetStdContent();
d9386025 202 Int_t nESDTracks=event->GetNumberOfTracks();
203
204 for (Int_t iTr=0; iTr<nESDTracks; iTr++){
205 AliESDtrack *pTrack = event->GetTrack(iTr);
206 if( !pTrack ) continue;
207 if( pTrack->GetKinkIndex(0)>0) continue;
208 if( !( pTrack->GetStatus()&AliESDtrack::kTPCin ) ) continue;
209 tracks.push_back(*pTrack);
210 trackId.push_back(iTr);
211 }
212 break;
213 }
214
215 if( tracks.size()==0 ){
216
217 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITS);
218 pBlock!=NULL; pBlock=GetNextInputBlock()) {
57a4102f 219
220 fBenchmark.AddInput(pBlock->fSize);
221
d9386025 222 AliHLTTracksData* dataPtr = reinterpret_cast<AliHLTTracksData*>( pBlock->fPtr );
223 int nTracks = dataPtr->fCount;
224
225 AliHLTExternalTrackParam* currOutTrack = dataPtr->fTracklets;
226 for( int itr=0; itr<nTracks; itr++ ){
227 AliHLTGlobalBarrelTrack t(*currOutTrack);
228 tracks.push_back( t );
229 trackId.push_back( currOutTrack->fTrackID );
230 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currOutTrack->fNPoints * sizeof( unsigned int );
231 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
232 }
233 }
234 }
4d5ee3db 235
d9386025 236 if( tracks.size()==0 ){
237 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
238 pBlock!=NULL; pBlock=GetNextInputBlock()) {
57a4102f 239
240 fBenchmark.AddInput(pBlock->fSize);
241
d9386025 242 AliHLTTracksData* dataPtr = reinterpret_cast<AliHLTTracksData*>( pBlock->fPtr );
243 int nTracks = dataPtr->fCount;
244 AliHLTExternalTrackParam* currOutTrack = dataPtr->fTracklets;
245 for( int itr=0; itr<nTracks; itr++ ){
246 AliHLTGlobalBarrelTrack t(*currOutTrack);
247 tracks.push_back( t );
248 trackId.push_back( currOutTrack->fTrackID );
249 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currOutTrack->fNPoints * sizeof( unsigned int );
250 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
251 }
252 }
253 }
254
255
256 // primary vertex & V0's
608cfbda 257
d9386025 258 AliKFParticle::SetField( GetBz() );
259
57a4102f 260 fBenchmark.Start(1);
261
d9386025 262 { //* Fill fTrackInfo array
263
d9386025 264 if( fTrackInfos ) delete[] fTrackInfos;
265 fTrackInfos = 0;
266 fNTracks=tracks.size();
267 fTrackInfos = new AliESDTrackInfo[ fNTracks ];
268 for (Int_t iTr=0; iTr<fNTracks; iTr++){
269 AliESDTrackInfo &info = fTrackInfos[iTr];
270 info.fOK = 1;
271 info.fPrimUsedFlag = 0;
272 info.fParticle = AliKFParticle( tracks[iTr], 211 );
57a4102f 273 for( int i=0; i<8; i++ ) if( !finite(info.fParticle.GetParameter(i)) ) info.fOK = 0;
274 for( int i=0; i<36; i++ ) if( !finite(info.fParticle.GetCovariance(i)) ) info.fOK = 0;
d9386025 275 }
d9386025 276 }
57a4102f 277
278 fBenchmark.Stop(1);
279 fBenchmark.Start(2);
d9386025 280 FindPrimaryVertex();
57a4102f 281 fBenchmark.Stop(2);
282 fBenchmark.Start(3);
d9386025 283 FindV0s( v0s );
57a4102f 284 fBenchmark.Stop(3);
d9386025 285
286 int *buf = new int[sizeof(AliHLTGlobalVertexerData)/sizeof(int)+1 + fNTracks + 2*v0s.size()];
287 AliHLTGlobalVertexerData *data = reinterpret_cast<AliHLTGlobalVertexerData*>(buf);
288
289 if( data) { // fill the output structure
290
291 data->fFitTracksToVertex = fFitTracksToVertex;
292 for( int i=0; i<3; i++ ) data->fPrimP[i] = fPrimaryVtx.Parameters()[i];
293 for( int i=0; i<6; i++ ) data->fPrimC[i] = fPrimaryVtx.CovarianceMatrix()[i];
294 data->fPrimChi2 = fPrimaryVtx.GetChi2();
295 data->fPrimNContributors = fPrimaryVtx.GetNContributors();
296 data->fNPrimTracks = 0;
297 for( Int_t i = 0; i<fNTracks; i++ ){
298 if( !fTrackInfos[i].fPrimUsedFlag ) continue;
299 if( fTrackInfos[i].fPrimDeviation > fConstrainedTrackDeviation ) continue;
300 data->fTrackIndices[ (data->fNPrimTracks)++ ] = trackId[i];
301 }
302 int *listV0 = data->fTrackIndices + data->fNPrimTracks;
303 data->fNV0s = v0s.size();
304 for( int i=0; i<data->fNV0s; i++ ){
305 listV0[2*i] = trackId[v0s[i].first];
306 listV0[2*i+1] = trackId[v0s[i].second];
307 }
4d5ee3db 308
d9386025 309 unsigned int blockSize = sizeof(AliHLTGlobalVertexerData) + (data->fNPrimTracks + 2*data->fNV0s)*sizeof(int);
310
311 iResult = PushBack( reinterpret_cast<void*>(data), blockSize, kAliHLTDataTypeGlobalVertexer|kAliHLTDataOriginOut );
57a4102f 312 fBenchmark.AddOutput(blockSize);
d9386025 313 }
314
315
316 // output the vertex if found
317 {
318 if( iResult==0 && data && data->fPrimNContributors >=3 ){
319 AliESDVertex vESD( data->fPrimP, data->fPrimC, data->fPrimChi2, data->fPrimNContributors );
320 iResult = PushBack( (TObject*) &vESD, kAliHLTDataTypeESDVertex|kAliHLTDataOriginOut,0 );
57a4102f 321 fBenchmark.AddOutput(GetLastObjectSize());
d9386025 322 }
323 }
324
325 // output the ESD event
326 if( iResult==0 && event && data ){
327 FillESD( event, data );
dc546924 328 iResult = PushBack( event, kAliHLTDataTypeESDObject|kAliHLTDataOriginOut, 0);
57a4102f 329 fBenchmark.AddOutput(GetLastObjectSize());
4d5ee3db 330 }
d9386025 331
332 delete[] buf;
333
57a4102f 334 fBenchmark.Stop(0);
335 HLTInfo(fBenchmark.GetStatistics());
dc546924 336 return iResult;
4d5ee3db 337}
338
d9386025 339
4d5ee3db 340int AliHLTGlobalVertexerComponent::Configure(const char* arguments)
341{
342
343 int iResult=0;
344 if (!arguments) return iResult;
345
346 TString allArgs=arguments;
347 TString argument;
348
349 TObjArray* pTokens=allArgs.Tokenize(" ");
350 int bMissingParam=0;
351
352 if (pTokens) {
353 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
354 argument=((TObjString*)pTokens->At(i))->GetString();
355 if (argument.IsNull()) continue;
356
357 if (argument.CompareTo("-fitTracksToVertex")==0) {
358 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
359 HLTInfo("fitTracksToVertex is set set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
608cfbda 360 fFitTracksToVertex=((TObjString*)pTokens->At(i))->GetString().Atoi();
4d5ee3db 361 continue;
362 }
4d5ee3db 363 else if (argument.CompareTo("-constrainedTrackDeviation")==0) {
364 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
365 HLTInfo("constrainedTrackDeviation is set set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
366 fConstrainedTrackDeviation=((TObjString*)pTokens->At(i))->GetString().Atof();
367 continue;
368 }
369 else if (argument.CompareTo("-v0DaughterPrimDeviation")==0) {
370 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
371 HLTInfo("v0DaughterPrimDeviation is set set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
372 fV0DaughterPrimDeviation=((TObjString*)pTokens->At(i))->GetString().Atof();
373 continue;
374 }
375 else if (argument.CompareTo("-v0PrimDeviation")==0) {
376 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
377 HLTInfo("v0PrimDeviation is set set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
378 fV0PrimDeviation=((TObjString*)pTokens->At(i))->GetString().Atof();
379 continue;
380 }
381 else if (argument.CompareTo("-v0Chi")==0) {
382 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
383 HLTInfo("v0Chi is set set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
384 fV0Chi=((TObjString*)pTokens->At(i))->GetString().Atof();
385 continue;
386 }
387 else if (argument.CompareTo("-v0DecayLengthInSigmas")==0) {
388 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
389 HLTInfo("v0DecayLengthInSigmas is set set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
390 fV0DecayLengthInSigmas=((TObjString*)pTokens->At(i))->GetString().Atof();
391 continue;
392 }
9222a93a 393 else if (argument.CompareTo("-v0MinEventRate")==0) {
394 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
395 HLTInfo("Minimum event rate for V0 finder is set set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
396 Double_t rate = ((TObjString*)pTokens->At(i))->GetString().Atof();
397 fV0TimeLimit = (rate >0 ) ?1./rate :60; // 1 minute maximum time
398 continue;
399 }
4d5ee3db 400 else {
401 HLTError("unknown argument %s", argument.Data());
402 iResult=-EINVAL;
403 break;
404 }
405 }
406 delete pTokens;
407 }
408 if (bMissingParam) {
409 HLTError("missing parameter for argument %s", argument.Data());
410 iResult=-EINVAL;
411 }
412
413 return iResult;
414}
415
416int AliHLTGlobalVertexerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
417{
418 // see header file for class documentation
9222a93a 419
420 return 0; // no CDB path is set so far
421
422 int iResult=0;
4d5ee3db 423 const char* path="HLT/ConfigTPC/KryptonHistoComponent";
424 const char* defaultNotify="";
425 if (cdbEntry) {
426 path=cdbEntry;
427 defaultNotify=" (default)";
428 }
429 if (path) {
430 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
431 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
432 if (pEntry) {
433 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
434 if (pString) {
435 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
436 iResult=Configure(pString->GetString().Data());
437 } else {
438 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
439 }
440 } else {
441 HLTError("can not fetch object \"%s\" from CDB", path);
442 }
443 }
444
445 return iResult;
446}
447
448
2e56583f 449struct AliHLTGlobalVertexerDeviation
450{
451 int fI; // track index
452 float fD; // deviation from vertex
453
454 bool operator<(const AliHLTGlobalVertexerDeviation &a) const { return fD<a.fD; }
455};
456
4d5ee3db 457
d9386025 458void AliHLTGlobalVertexerComponent::FindPrimaryVertex()
4d5ee3db 459{
460 //* Find event primary vertex
461
4d5ee3db 462 fPrimaryVtx.Initialize();
d9386025 463 //fPrimaryVtx.SetBeamConstraint(fESD->GetDiamondX(),fESD->GetDiamondY(),0,
464 //TMath::Sqrt(fESD->GetSigma2DiamondX()),TMath::Sqrt(fESD->GetSigma2DiamondY()),5.3);
d9386025 465 fPrimaryVtx.SetBeamConstraint( 0, 0, 0, 3., 3., 5.3 );
2e56583f 466
467 const AliKFParticle **vSelected = new const AliKFParticle*[fNTracks]; //* Selected particles for the vertex fit
468 AliHLTGlobalVertexerDeviation *dev = new AliHLTGlobalVertexerDeviation[fNTracks];
469
4d5ee3db 470 Int_t nSelected = 0;
2e56583f 471
d9386025 472 for( Int_t i = 0; i<fNTracks; i++){
4d5ee3db 473 if(!fTrackInfos[i].fOK ) continue;
474 //if( fESD->GetTrack(i)->GetTPCNcls()<60 ) continue;
475 const AliKFParticle &p = fTrackInfos[i].fParticle;
476 Double_t chi = p.GetDeviationFromVertex( fPrimaryVtx );
477 if( chi > fConstrainedTrackDeviation ) continue;
2e56583f 478 dev[nSelected].fI = i;
479 dev[nSelected].fD = chi;
4d5ee3db 480 vSelected[nSelected] = &(fTrackInfos[i].fParticle);
4d5ee3db 481 nSelected++;
2e56583f 482 }
483
2e56583f 484 // fit
485
2e56583f 486 while( nSelected>2 ){
487
488 //* Primary vertex finder with rejection of outliers
489
490 for( Int_t i = 0; i<nSelected; i++){
491 vSelected[i] = &(fTrackInfos[dev[i].fI].fParticle);
492 }
44fe6239 493
494 double xv = fPrimaryVtx.GetX();
495 double yv = fPrimaryVtx.GetY();
496 double zv = fPrimaryVtx.GetZ();
2e56583f 497 fPrimaryVtx.Initialize();
498 fPrimaryVtx.SetBeamConstraint( 0, 0, 0, 3., 3., 5.3 );
44fe6239 499 fPrimaryVtx.SetVtxGuess( xv, yv, zv );
2e56583f 500
501 fPrimaryVtx.Construct( vSelected, nSelected, 0, -1, 1 );
44fe6239 502
2e56583f 503 for( Int_t it=0; it<nSelected; it++ ){
504 const AliKFParticle &p = fTrackInfos[dev[it].fI].fParticle;
505 if( nSelected <= 20 ){
506 AliKFVertex tmp = fPrimaryVtx - p;
507 dev[it].fD = p.GetDeviationFromVertex( tmp );
508 } else {
509 dev[it].fD = p.GetDeviationFromVertex( fPrimaryVtx );
510 }
511 }
512 sort(dev,dev+nSelected);
513
514 int nRemove = (int) ( 0.3*nSelected );
515 if( nSelected - nRemove <=20 ) nRemove = 1;
516 int firstRemove = nSelected - nRemove;
517 while( firstRemove<nSelected ){
518 if( dev[firstRemove].fD >= fConstrainedTrackDeviation ) break;
519 firstRemove++;
520 }
521 if( firstRemove>=nSelected ) break;
2e56583f 522 nSelected = firstRemove;
523 }
524
2e56583f 525 for( Int_t i = 0; i<fNTracks; i++){
526 fTrackInfos[i].fPrimUsedFlag = 0;
527 }
528
529 if( nSelected < 3 ){
530 fPrimaryVtx.NDF() = -3;
531 fPrimaryVtx.Chi2() = 0;
532 nSelected = 0;
533 }
534
4d5ee3db 535 for( Int_t i = 0; i<nSelected; i++){
44fe6239 536 AliESDTrackInfo &info = fTrackInfos[dev[i].fI];
537 info.fPrimUsedFlag = 1;
538 info.fPrimDeviation = dev[i].fD;
4d5ee3db 539 }
540
d9386025 541 for( Int_t i = 0; i<fNTracks; i++ ){
4d5ee3db 542 AliESDTrackInfo &info = fTrackInfos[i];
44fe6239 543 if( info.fPrimUsedFlag ) continue;
4d5ee3db 544 info.fPrimDeviation = info.fParticle.GetDeviationFromVertex( fPrimaryVtx );
545 }
4d5ee3db 546
4d5ee3db 547 delete[] vSelected;
2e56583f 548 delete[] dev;
4d5ee3db 549}
550
551
2e56583f 552
f0d12ea5 553void AliHLTGlobalVertexerComponent::FindV0s( vector<pair<int,int> > &v0s )
4d5ee3db 554{
555 //* V0 finder
556
4d5ee3db 557 AliKFVertex &primVtx = fPrimaryVtx;
558 if( primVtx.GetNContributors()<3 ) return;
559
9222a93a 560 TStopwatch timer;
561 Int_t statN = 0;
562 Bool_t run = 1;
4d5ee3db 563
d9386025 564 for( Int_t iTr = 0; iTr<fNTracks && run; iTr++ ){ //* first daughter
4d5ee3db 565
566 AliESDTrackInfo &info = fTrackInfos[iTr];
567 if( !info.fOK ) continue;
568 if( info.fParticle.GetQ() >0 ) continue;
569 if( info.fPrimDeviation < fV0DaughterPrimDeviation ) continue;
570
d9386025 571 for( Int_t jTr = 0; jTr<fNTracks; jTr++ ){ //* second daughter
9222a93a 572
573
4d5ee3db 574 AliESDTrackInfo &jnfo = fTrackInfos[jTr];
575 if( !jnfo.fOK ) continue;
576 if( jnfo.fParticle.GetQ() < 0 ) continue;
577 if( jnfo.fPrimDeviation < fV0DaughterPrimDeviation ) continue;
9222a93a 578
579 // check the time once a while...
580
581 if( (++statN)%100 ==0 ){
582 if( timer.RealTime()>= fV0TimeLimit ){ run = 0; break; }
57a4102f 583 timer.Continue();
9222a93a 584 }
585
586 //* check if the particles fit
587
588 if( info.fParticle.GetDeviationFromParticle(jnfo.fParticle) > fV0Chi ) continue;
589
4d5ee3db 590 //* construct V0 mother
591
592 AliKFParticle v0( info.fParticle, jnfo.fParticle );
593
594 //* check V0 Chi^2
595
596 if( v0.GetChi2()<0 || v0.GetChi2() > fV0Chi*fV0Chi*v0.GetNDF() ) continue;
597
598 //* subtruct daughters from primary vertex
599
600 AliKFVertex primVtxCopy = primVtx;
601
602 if( info.fPrimUsedFlag ){
603 if( primVtxCopy.GetNContributors()<=2 ) continue;
604 primVtxCopy -= info.fParticle;
605 }
606 if( jnfo.fPrimUsedFlag ){
607 if( primVtxCopy.GetNContributors()<=2 ) continue;
608 primVtxCopy -= jnfo.fParticle;
609 }
610 //* Check v0 Chi^2 deviation from primary vertex
611
612 if( v0.GetDeviationFromVertex( primVtxCopy ) > fV0PrimDeviation ) continue;
613
614 //* Add V0 to primary vertex to improve the primary vertex resolution
615
616 primVtxCopy += v0;
617
618 //* Set production vertex for V0
619
620 v0.SetProductionVertex( primVtxCopy );
621
622 //* Get V0 decay length with estimated error
623
624 Double_t length, sigmaLength;
625 if( v0.GetDecayLength( length, sigmaLength ) ) continue;
626
627 //* Reject V0 if it decays too close[sigma] to the primary vertex
628
629 if( length < fV0DecayLengthInSigmas*sigmaLength ) continue;
4d5ee3db 630
d9386025 631 //* keep v0
632
633 v0s.push_back(pair<int,int>(iTr,jTr));
4d5ee3db 634 }
635 }
4d5ee3db 636}
637
d9386025 638
639
640
641void AliHLTGlobalVertexerComponent::FillESD( AliESDEvent *event, AliHLTGlobalVertexerData *data
642)
643{
644 //* put output of a vertexer to the esd event
645
646 Int_t nESDTracks = event->GetNumberOfTracks();
647
648 const int *listPrim = data->fTrackIndices;
649 const int *listV0 = data->fTrackIndices + data->fNPrimTracks;
650
651 std::map<int,int> mapId;
652 bool *constrainedToVtx = new bool[nESDTracks];
653
654 for( int i=0; i<nESDTracks; i++ ){
655 constrainedToVtx[i] = 0;
656 if( !event->GetTrack(i) ) continue;
657 mapId[ event->GetTrack(i)->GetID() ] = i;
658 }
659
660 if( data->fPrimNContributors >=3 ){
661
662 AliESDVertex vESD( data->fPrimP, data->fPrimC, data->fPrimChi2, data->fPrimNContributors );
39a4205e 663 event->SetPrimaryVertexTPC( &vESD );
d9386025 664 event->SetPrimaryVertexTracks( &vESD );
665
666 // relate tracks to the primary vertex
667
668 if( data->fFitTracksToVertex ){
669 for( Int_t i = 0; i<data->fNPrimTracks; i++ ){
670 Int_t id = listPrim[ i ];
671 map<int,int>::iterator it = mapId.find(id);
672 if( it==mapId.end() ) continue;
673 Int_t itr = it->second;
674 event->GetTrack(itr)->RelateToVertex( &vESD, event->GetMagneticField(),100. );
675 constrainedToVtx[ itr ] = 1;
676 }
677 }
678 }
679
680 //* add ESD v0s and relate tracks to v0s
681
682
683 for( int i=0; i<data->fNV0s; i++ ){
684
685 Int_t id1 = listV0[ 2*i ];
686 Int_t id2 = listV0[ 2*i + 1];
687 map<int,int>::iterator it = mapId.find(id1);
688 if( it==mapId.end() ) continue;
689 Int_t iTr = it->second;
690 it = mapId.find(id2);
691 if( it==mapId.end() ) continue;
692 Int_t jTr = it->second;
693
694 AliESDv0 v0( *event->GetTrack( iTr ), iTr, *event->GetTrack( jTr ), jTr );
695 event->AddV0( &v0 );
696
697 // relate the tracks to the vertex
698
699 if( data->fFitTracksToVertex ){
700 if( constrainedToVtx[iTr] || constrainedToVtx[jTr] ) continue;
701 double pos[3];
702 double sigma[3] = {.1,.1,.1};
703 v0.XvYvZv(pos);
704 AliESDVertex vESD(pos, sigma);
705 event->GetTrack(iTr)->RelateToVertex( &vESD, event->GetMagneticField(),100. );
706 event->GetTrack(jTr)->RelateToVertex( &vESD, event->GetMagneticField(),100. );
707 constrainedToVtx[iTr] = 1;
708 constrainedToVtx[jTr] = 1;
709 }
710 }
711
712 delete[] constrainedToVtx;
713}