Updated source list update
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalEsdConverterComponent.cxx
CommitLineData
a1408c4b 1// $Id$
2
3//**************************************************************************
4//* This file is property of and copyright by the ALICE HLT Project *
5//* ALICE Experiment at CERN, All rights reserved. *
6//* *
7//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8//* for The ALICE HLT Project. *
9//* *
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. *
17//**************************************************************************
18
a0b62fd1 19// @file AliHLTGlobalEsdConverterComponent.cxx
20// @author Matthias Richter
21// @date
22// @brief Global ESD converter component.
23//
a1408c4b 24
25// see header file for class documentation
26// or
27// refer to README to build package
28// or
29// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30
31#include <cassert>
32#include "AliHLTGlobalEsdConverterComponent.h"
33#include "AliHLTGlobalBarrelTrack.h"
34#include "AliHLTExternalTrackParam.h"
093b64dc 35#include "AliHLTTrackMCLabel.h"
6117ef63 36#include "AliHLTCTPData.h"
331d51c5 37#include "AliHLTErrorGuard.h"
a1408c4b 38#include "AliESDEvent.h"
39#include "AliESDtrack.h"
f064ef44 40#include "AliESDMuonTrack.h"
a1408c4b 41#include "AliCDBEntry.h"
42#include "AliCDBManager.h"
18ada816 43#include "AliPID.h"
a1408c4b 44#include "TTree.h"
45#include "TList.h"
f064ef44 46#include "TClonesArray.h"
9a9467ed 47#include "AliHLTESDCaloClusterMaker.h"
48#include "AliHLTCaloClusterDataStruct.h"
49#include "AliHLTCaloClusterReader.h"
50#include "AliESDCaloCluster.h"
331d51c5 51#include "AliESDVZERO.h"
d9386025 52#include "AliHLTGlobalVertexerComponent.h"
a1408c4b 53
54/** ROOT macro for the implementation of ROOT specific class methods */
55ClassImp(AliHLTGlobalEsdConverterComponent)
56
57AliHLTGlobalEsdConverterComponent::AliHLTGlobalEsdConverterComponent()
58 : AliHLTProcessor()
a1408c4b 59 , fWriteTree(0)
093b64dc 60 , fVerbosity(0)
8b7a0f3c 61 , fESD(NULL)
a8714ffa 62 , fSolenoidBz(-5.00668)
57a4102f 63 , fBenchmark("EsdConverter")
a1408c4b 64{
65 // see header file for class documentation
66 // or
67 // refer to README to build package
68 // or
69 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
70}
71
72AliHLTGlobalEsdConverterComponent::~AliHLTGlobalEsdConverterComponent()
73{
74 // see header file for class documentation
75 if (fESD) delete fESD;
76 fESD=NULL;
77}
78
79int AliHLTGlobalEsdConverterComponent::Configure(const char* arguments)
80{
81 // see header file for class documentation
82 int iResult=0;
83 if (!arguments) return iResult;
84
85 TString allArgs=arguments;
86 TString argument;
87 int bMissingParam=0;
88
89 TObjArray* pTokens=allArgs.Tokenize(" ");
90 if (pTokens) {
91 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
fe0af255 92 argument=((TObjString*)pTokens->At(i))->GetString();
a1408c4b 93 if (argument.IsNull()) continue;
94
95 if (argument.CompareTo("-solenoidBz")==0) {
96 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
75970b8d 97 HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
a1408c4b 98 continue;
99 } else {
100 HLTError("unknown argument %s", argument.Data());
101 iResult=-EINVAL;
102 break;
103 }
104 }
105 delete pTokens;
106 }
107 if (bMissingParam) {
108 HLTError("missing parameter for argument %s", argument.Data());
109 iResult=-EINVAL;
110 }
111
112 return iResult;
113}
114
115int AliHLTGlobalEsdConverterComponent::Reconfigure(const char* cdbEntry, const char* chainId)
116{
117 // see header file for class documentation
118 int iResult=0;
75970b8d 119 const char* path=NULL;
a1408c4b 120 const char* defaultNotify="";
121 if (cdbEntry) {
122 path=cdbEntry;
123 defaultNotify=" (default)";
124 }
125 if (path) {
126 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
127 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
128 if (pEntry) {
129 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
130 if (pString) {
131 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
132 iResult=Configure(pString->GetString().Data());
133 } else {
134 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
135 }
136 } else {
137 HLTError("can not fetch object \"%s\" from CDB", path);
138 }
139 }
140
141 return iResult;
142}
143
144void AliHLTGlobalEsdConverterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
145{
146 // see header file for class documentation
147 list.push_back(kAliHLTDataTypeTrack);
148 list.push_back(kAliHLTDataTypeTrackMC);
9a9467ed 149 list.push_back(kAliHLTDataTypeCaloCluster);
0973c527 150 list.push_back(kAliHLTDataTypedEdx );
7f167a74 151 list.push_back(kAliHLTDataTypeESDVertex );
f064ef44 152 list.push_back(kAliHLTDataTypeESDObject);
153 list.push_back(kAliHLTDataTypeTObject);
d9963894 154 list.push_back(kAliHLTDataTypeGlobalVertexer);
331d51c5 155 list.push_back(kAliHLTDataTypeESDContent);
a1408c4b 156}
157
158AliHLTComponentDataType AliHLTGlobalEsdConverterComponent::GetOutputDataType()
159{
160 // see header file for class documentation
7a9de6d1 161 return kAliHLTDataTypeESDObject|kAliHLTDataOriginOut;
a1408c4b 162}
163
164void AliHLTGlobalEsdConverterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
165{
166 // see header file for class documentation
167 constBase=2000000;
168 inputMultiplier=10.0;
169}
170
171int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
172{
173 // see header file for class documentation
174 int iResult=0;
175 TString argument="";
176 int bMissingParam=0;
a1408c4b 177
d57fc872 178 // default list of skiped ESD objects
179 TString skipObjects=
180 // "AliESDRun,"
181 // "AliESDHeader,"
421e1221 182 // "AliESDZDC,"
d57fc872 183 "AliESDFMD,"
184 // "AliESDVZERO,"
185 // "AliESDTZERO,"
186 // "TPCVertex,"
187 // "SPDVertex,"
188 // "PrimaryVertex,"
189 // "AliMultiplicity,"
190 // "PHOSTrigger,"
191 // "EMCALTrigger,"
192 // "SPDPileupVertices,"
193 // "TrkPileupVertices,"
194 "Cascades,"
195 "Kinks,"
196 "AliRawDataErrorLogs,"
197 "AliESDACORDE";
198
f167b631 199 iResult=Reconfigure(NULL, NULL);
200 TString allArgs = "";
201 for ( int i = 0; i < argc; i++ ) {
202 if ( !allArgs.IsNull() ) allArgs += " ";
203 allArgs += argv[i];
204 }
a1408c4b 205
f167b631 206 TObjArray* pTokens=allArgs.Tokenize(" ");
207 if (pTokens) {
208 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
209 argument=((TObjString*)pTokens->At(i))->GetString();
210 if (argument.IsNull()) continue;
211
212 // -notree
213 if (argument.CompareTo("-notree")==0) {
214 fWriteTree=0;
215
216 // -tree
217 } else if (argument.CompareTo("-tree")==0) {
218 fWriteTree=1;
219 } else if (argument.CompareTo("-solenoidBz")==0) {
220 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
221 HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
d57fc872 222 HLTWarning("argument '-solenoidBz' is deprecated, solenoid field initiaized from CDB settings");
f167b631 223 continue;
d57fc872 224 } else if (argument.Contains("-skipobject=")) {
225 argument.ReplaceAll("-skipobject=", "");
226 skipObjects=argument;
f167b631 227 } else {
228 HLTError("unknown argument %s", argument.Data());
d57fc872 229 iResult=-EINVAL;
f167b631 230 break;
231 }
a1408c4b 232 }
233 }
234 if (bMissingParam) {
235 HLTError("missing parameter for argument %s", argument.Data());
236 iResult=-EINVAL;
237 }
238
75970b8d 239 fSolenoidBz=GetBz();
240
a1408c4b 241 if (iResult>=0) {
a1408c4b 242 fESD = new AliESDEvent;
243 if (fESD) {
244 fESD->CreateStdContent();
d57fc872 245
246 // remove some of the objects which are not needed
247 if (fESD->GetList() && !skipObjects.IsNull()) {
248 pTokens=skipObjects.Tokenize(",");
249 if (pTokens) {
250 const char* id=NULL;
251 TIter next(pTokens);
252 TObject* pObject=NULL;
253 while ((pObject=next())!=NULL) {
254 id=((TObjString*)pObject)->GetString().Data();
a0b62fd1 255 TObject* pObj=fESD->GetList()->FindObject(id);
256 if (pObj) {
d57fc872 257 HLTDebug("removing object %s", id);
a0b62fd1 258 fESD->GetList()->Remove(pObj);
259 delete pObj;
d57fc872 260 } else {
261 HLTWarning("failed to remove object '%s' from ESD", id);
262 }
263 }
d57fc872 264 fESD->GetStdContent();
265 delete pTokens;
266 }
267 }
a1408c4b 268 } else {
269 iResult=-ENOMEM;
270 }
6117ef63 271
272 SetupCTPData();
a1408c4b 273 }
274
57a4102f 275 fBenchmark.SetTimer(0,"total");
276
a1408c4b 277 return iResult;
278}
279
280int AliHLTGlobalEsdConverterComponent::DoDeinit()
281{
282 // see header file for class documentation
283 if (fESD) delete fESD;
284 fESD=NULL;
285
286 return 0;
287}
288
289int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
6117ef63 290 AliHLTComponentTriggerData& trigData)
a1408c4b 291{
292 // see header file for class documentation
293 int iResult=0;
294 if (!fESD) return -ENODEV;
295
57a4102f 296 if (IsDataEvent()) fBenchmark.StartNewEvent();
297 fBenchmark.Start(0);
298
a1408c4b 299 AliESDEvent* pESD = fESD;
300
301 pESD->Reset();
302 pESD->SetMagneticField(fSolenoidBz);
6117ef63 303 pESD->SetRunNumber(GetRunNo());
6700298e 304 pESD->SetPeriodNumber(GetPeriodNumber());
305 pESD->SetOrbitNumber(GetOrbitNumber());
306 pESD->SetBunchCrossNumber(GetBunchCrossNumber());
307 pESD->SetTimeStamp(GetTimeStamp());
a1408c4b 308
6117ef63 309 const AliHLTCTPData* pCTPData=CTPData();
310 if (pCTPData) {
311 AliHLTUInt64_t mask=pCTPData->ActiveTriggers(trigData);
312 for (int index=0; index<gkNCTPTriggerClasses; index++) {
313 if ((mask&((AliHLTUInt64_t)0x1<<index)) == 0) continue;
314 pESD->SetTriggerClass(pCTPData->Name(index), index);
315 }
316 pESD->SetTriggerMask(mask);
317 }
318
a1408c4b 319 TTree* pTree = NULL;
320 if (fWriteTree)
321 pTree = new TTree("esdTree", "Tree with HLT ESD objects");
322
323 if (pTree) {
324 pTree->SetDirectory(0);
325 }
326
81509fd3 327 if ((iResult=ProcessBlocks(pTree, pESD))>=0) {
a1408c4b 328 // TODO: set the specification correctly
329 if (pTree) {
330 // the esd structure is written to the user info and is
331 // needed in te ReadFromTree method to read all objects correctly
332 pTree->GetUserInfo()->Add(pESD);
333 pESD->WriteToTree(pTree);
7a9de6d1 334 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginOut, 0);
a1408c4b 335 } else {
7a9de6d1 336 iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginOut, 0);
a1408c4b 337 }
57a4102f 338 fBenchmark.AddOutput(GetLastObjectSize());
a1408c4b 339 }
340 if (pTree) {
341 // clear user info list to prevent objects from being deleted
342 pTree->GetUserInfo()->Clear();
343 delete pTree;
344 }
57a4102f 345
346 fBenchmark.Stop(0);
347 HLTInfo( fBenchmark.GetStatistics() );
348
a1408c4b 349 return iResult;
350}
351
352int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD)
353{
354 // see header file for class documentation
355
356 int iResult=0;
357 int iAddedDataBlocks=0;
358
359 // Barrel tracking
e85f2e31 360 // tracks are based on the TPC tracks, and only updated from the ITS information
361 // Sequence:
362 // 1) extract MC information for TPC and ITS from specific data blocks and store in
363 // intermediate vector arrays
364 // 2) extract TPC tracks, update with MC labels if available, the track parameters
365 // are estimated at the first cluster position
366 // 2.1) propagate to last cluster position and update kTPCout, sets also outer param (fOp)
367 // 2.2) update kTPCin, sets also inner param (fIp) and TPC inner param (fTPCInner)
368 // 2.3) update kTPCrefit using the same parameters at the first cluster position
369 // HLT has strictly spoking no refit, but we want the flag to be set
370 // can be changed to be done after all the individual barrel detector parameters
371 // have been updated by looping over the tracks again
372 // 3) extract ITS tracks, the tracks are actually TPC tracks updated from the ITS
373 // tracking information
374 // 3.1) TODO 2010-07-12: handle ITS standalone tracks by updating kITSout before kITSin
375 // 3.2) update with kITSin
376 // TODO 2010-07-12 find out if the kITSrefit has to be set as well
377 // 4) extract TRD tracks and add to ESD
378 // TODO 2010-07-12 at the moment there is no matching or merging of TPC and TRD tracks
331d51c5 379 // 5) Add Trigger Detectors
380 // VZERO, ZDC
e85f2e31 381
382 // 1) first read MC information (if present)
eb60b0c1 383 std::map<int,int> mcLabelsTPC;
d72d9d99 384 std::map<int,int> mcLabelsITS;
093b64dc 385
386 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC);
387 pBlock!=NULL; pBlock=GetNextInputBlock()) {
57a4102f 388
389 fBenchmark.AddInput(pBlock->fSize);
390
093b64dc 391 AliHLTTrackMCData* dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr );
392 if (sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize) {
393 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
394 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
eb60b0c1 395 mcLabelsTPC[lab.fTrackID] = lab.fMCLabel;
093b64dc 396 }
397 } else {
398 HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information",
399 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification,
400 dataPtr->fCount, pBlock->fSize);
401 }
402 }
d72d9d99 403
404 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginITS);
405 pBlock!=NULL; pBlock=GetNextInputBlock()) {
406
407 fBenchmark.AddInput(pBlock->fSize);
408
409 AliHLTTrackMCData* dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr );
410 if (sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize) {
411 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
412 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
413 mcLabelsITS[lab.fTrackID] = lab.fMCLabel;
414 }
415 } else {
416 HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information",
417 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification,
418 dataPtr->fCount, pBlock->fSize);
419 }
420 }
421
093b64dc 422
0973c527 423 // read dEdx information (if present)
e85f2e31 424 // TODO 2010-07-12 this needs to be verified
0973c527 425
426 AliHLTFloat32_t *dEdxTPC = 0;
427 Int_t ndEdxTPC = 0;
428 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypedEdx|kAliHLTDataOriginTPC);
429 pBlock!=NULL; pBlock=GetNextInputBlock()) {
57a4102f 430 fBenchmark.AddInput(pBlock->fSize);
0973c527 431 dEdxTPC = reinterpret_cast<AliHLTFloat32_t*>( pBlock->fPtr );
72a916d9 432 ndEdxTPC = pBlock->fSize / (3*sizeof(AliHLTFloat32_t));
0973c527 433 break;
434 }
435
e85f2e31 436 // 2) convert the TPC tracks to ESD tracks
6bb8f4a4 437
a1408c4b 438 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
439 pBlock!=NULL; pBlock=GetNextInputBlock()) {
57a4102f 440 fBenchmark.AddInput(pBlock->fSize);
a1408c4b 441 vector<AliHLTGlobalBarrelTrack> tracks;
81509fd3 442 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>=0) {
a1408c4b 443 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
444 element!=tracks.end(); element++) {
445 Float_t points[4] = {
446 element->GetX(),
447 element->GetY(),
448 element->GetLastPointX(),
449 element->GetLastPointY()
450 };
093b64dc 451
452 Int_t mcLabel = -1;
eb60b0c1 453 if( mcLabelsTPC.find(element->TrackID())!=mcLabelsTPC.end() )
454 mcLabel = mcLabelsTPC[element->TrackID()];
093b64dc 455 element->SetLabel( mcLabel );
456
a1408c4b 457 AliESDtrack iotrack;
550ecaab 458
459 // for the moment, the number of clusters are not set when processing the
460 // kTPCin update, only at kTPCout
461 // there ar emainly three parameters updated for kTPCout
462 // number of clusters
463 // chi2
464 // pid signal
465 // The first one can be updated already at that stage here, while the two others
466 // eventually require to update from the ITS tracks before. The exact scheme
ab700b08 467 // needs to be checked
c3261a7d 468 iotrack.SetID( element->TrackID() );
e85f2e31 469
470 // 2.1 set kTPCout
471 // TODO 2010-07-12 disabled for the moment because of bug
472 // https://savannah.cern.ch/bugs/index.php?69875
473 // the propagation does not work, there is an offset in z
474 // propagate to last cluster and update parameters with flag kTPCout
475 // Note: updating with flag kITSout further down will overwrite the outer
476 // parameter again so this can be done only for ITS standalone tracks, meaning
477 // tracks in the ITS not associated with any TPC track
478 // HLT does not provide such standalone tracking
c3261a7d 479 {
f167b631 480 AliHLTGlobalBarrelTrack outPar(*element);
114e074b 481 //outPar.AliExternalTrackParam::PropagateTo( element->GetLastPointX(), fSolenoidBz );
482 const Int_t N=10; // number of steps.
483 const Float_t xRange = element->GetLastPointX() - element->GetX();
484 const Float_t xStep = xRange / N ;
485 for(int i = 1; i <= N; ++i) {
486 if(!outPar.AliExternalTrackParam::PropagateTo(element->GetX() + xStep * i, fSolenoidBz)) break;
487 }
b9838c05 488 outPar.SetLabel(element->GetLabel());
114e074b 489 iotrack.UpdateTrackParams(&outPar,AliESDtrack::kTPCout);
c3261a7d 490 }
e85f2e31 491 // 2.2 TPC tracking estimates parameters at first cluster
ab700b08 492 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCin);
e85f2e31 493
494 // 2.3 use the same parameters also for kTPCrefit, there is no proper refit in HLT
495 // maybe this can be done later, however also the inner parameter is changed which
496 // is used as a reference point in the display. That point should be at the first
497 // TPC cluster
498 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCrefit);
a1408c4b 499 iotrack.SetTPCPoints(points);
0973c527 500 if( element->TrackID()<ndEdxTPC ){
72a916d9 501 AliHLTFloat32_t *val = &(dEdxTPC[3*element->TrackID()]);
5c2dca91 502 iotrack.SetTPCsignal( val[0], val[1], (UChar_t) val[2] );
7e32fedf 503 //AliTPCseed s;
504 //s.Set( element->GetX(), element->GetAlpha(),
505 //element->GetParameter(), element->GetCovariance() );
72a916d9 506 //s.SetdEdx( val[0] );
7e32fedf 507 //s.CookPID();
508 //iotrack.SetTPCpid(s.TPCrPIDs() );
0973c527 509 } else {
510 if( dEdxTPC ) HLTWarning("Wrong number of dEdx TPC labels");
511 }
b9838c05 512 iotrack.SetLabel(mcLabel);
6bb8f4a4 513 pESD->AddTrack(&iotrack);
093b64dc 514 if (fVerbosity>0) element->Print();
a1408c4b 515 }
093b64dc 516 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
a1408c4b 517 iAddedDataBlocks++;
518 } else if (iResult<0) {
093b64dc 519 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
520 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
a1408c4b 521 }
522 }
523
7f167a74 524
525 // Get ITS SPD vertex
57a4102f 526 for( const AliHLTComponentBlockData *i= GetFirstInputBlock(kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS); i!=NULL; i=GetNextInputBlock() ){
527 fBenchmark.AddInput(i->fSize);
528 }
7f167a74 529
530 for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS); iter != NULL; iter = GetNextInputObject() ) {
531 AliESDVertex *vtx = dynamic_cast<AliESDVertex*>(const_cast<TObject*>( iter ) );
532 pESD->SetPrimaryVertexSPD( vtx );
533 }
534
e85f2e31 535 // 3.1. now update ESD tracks with the ITSOut info
536 // updating track parameters with flag kITSout will overwrite parameter set above with flag kTPCout
537 // TODO 2010-07-12 there are some issues with this updating sequence, for the moment update with
538 // flag kITSout is disabled, would require
539 // a) to update kTPCout after kITSout
540 // b) update only for ITS standalone tracks. The HLT ITS tracker does not provide standalone
541 // tracking, every track is related to a TPC track
542 // Furthermore there seems to be a bug as the data blocks describe track parameters around the
543 // vertex, not at the outer ITS
544 // bug https://savannah.cern.ch/bugs/index.php?69872
f167b631 545 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITSOut);
cd60a73f 546 pBlock!=NULL; pBlock=GetNextInputBlock()) {
57a4102f 547 fBenchmark.AddInput(pBlock->fSize);
cd60a73f 548 vector<AliHLTGlobalBarrelTrack> tracks;
549 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
550 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
551 element!=tracks.end(); element++) {
cd60a73f 552 int tpcID=element->TrackID();
553 // the ITS tracker assigns the TPC track used as seed for a certain track to
554 // the trackID
555 if( tpcID<0 || tpcID>=pESD->GetNumberOfTracks()) continue;
cd60a73f 556 AliESDtrack *tESD = pESD->GetTrack( tpcID );
b9838c05 557 element->SetLabel(tESD->GetLabel());
e85f2e31 558 // 2010-07-12 disabled, see above, bugfix https://savannah.cern.ch/bugs/index.php?69872
559 //if( tESD ) tESD->UpdateTrackParams( &(*element), AliESDtrack::kITSout );
a1408c4b 560 }
cd60a73f 561 }
562 }
18ada816 563
e85f2e31 564 // 3.2. now update ESD tracks with the ITS info
f167b631 565 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITS);
b7ed2eb4 566 pBlock!=NULL; pBlock=GetNextInputBlock()) {
57a4102f 567 fBenchmark.AddInput(pBlock->fSize);
b7ed2eb4 568 vector<AliHLTGlobalBarrelTrack> tracks;
569 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
570 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
571 element!=tracks.end(); element++) {
b7ed2eb4 572 int tpcID=element->TrackID();
573 // the ITS tracker assigns the TPC track used as seed for a certain track to
574 // the trackID
575 if( tpcID<0 || tpcID>=pESD->GetNumberOfTracks()) continue;
d72d9d99 576 Int_t mcLabel = -1;
577 if( mcLabelsITS.find(element->TrackID())!=mcLabelsITS.end() )
578 mcLabel = mcLabelsITS[element->TrackID()];
b7ed2eb4 579 AliESDtrack *tESD = pESD->GetTrack( tpcID );
b9838c05 580 if (!tESD) continue;
eb60b0c1 581 // the labels for the TPC and ITS tracking params can be different, e.g.
582 // there can be a decay. The ITS label should then be the better one, the
583 // TPC label is saved in a member of AliESDtrack
584 if (mcLabel>=0) {
585 // upadte only if the ITS label is available, otherwise keep TPC label
586 element->SetLabel( mcLabel );
e85f2e31 587 } else {
588 // bugfix https://savannah.cern.ch/bugs/?69713
589 element->SetLabel( tESD->GetLabel() );
b9838c05 590 }
b9838c05 591 tESD->UpdateTrackParams( &(*element), AliESDtrack::kITSin );
592
593 // TODO: add a proper refit
594 //tESD->UpdateTrackParams( &(*element), AliESDtrack::kTPCrefit );
b7ed2eb4 595 }
596 }
597 }
598
d9386025 599 // update with vertices and vertex-fitted tracks
600
601 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeGlobalVertexer);
602 pBlock!=NULL; pBlock=GetNextInputBlock()) {
57a4102f 603 fBenchmark.AddInput(pBlock->fSize);
d9386025 604 AliHLTGlobalVertexerComponent::FillESD( pESD, reinterpret_cast<AliHLTGlobalVertexerComponent::AliHLTGlobalVertexerData* >(pBlock->fPtr) );
605 }
606
0d2e4e41 607 // Fill DCA parameters for TPC tracks
e85f2e31 608 // TODO 2010-07-12 this propagates also the TPC inner param to beamline
609 // sounds not very reasonable
610 // https://savannah.cern.ch/bugs/index.php?69873
6bb8f4a4 611 for (UInt_t i=0; (int) i<pESD->GetNumberOfTracks(); i++) {
0d2e4e41 612 if (!pESD->GetTrack(i) ||
613 !pESD->GetTrack(i)->GetTPCInnerParam() ) continue;
6bb8f4a4 614
615 AliESDtrack* tESD=pESD->GetTrack(i);
616 AliHLTGlobalBarrelTrack inner(*tESD->GetTPCInnerParam());
617 inner.SetLabel(tESD->GetLabel());
618
619 tESD->RelateToVertexTPC(pESD->GetPrimaryVertexTracks(), fSolenoidBz, 1000 );
620 // Restore TPC inner parameters!!!
621 tESD->UpdateTrackParams(&inner, AliESDtrack::kTPCin);
0d2e4e41 622 }
623
b9838c05 624 // loop over all tracks and set the TPC refit flag by updating with the
625 // original TPC inner parameter if not yet set
626 // TODO: replace this by a proper refit
627 // code is comented for the moment as it does not fully solve the problems with
628 // the display
e85f2e31 629 // - would set the main parameters to the TPC inner wall again, or
630 // - changes the inner param if the parameters are propagated, so we loose the track
631 // reference point for the display
632 // with the current sequence we have the latter case as the DCA operations above
633 // change the TPC inner parameters
b9838c05 634 /*
635 for (int i=0; i<pESD->GetNumberOfTracks(); i++) {
636 if (!pESD->GetTrack(i) ||
637 !pESD->GetTrack(i)->GetTPCInnerParam() ||
638 pESD->GetTrack(i)->IsOn(AliESDtrack::kTPCrefit)) continue;
639 AliESDtrack* tESD=pESD->GetTrack(i);
640 AliHLTGlobalBarrelTrack inner(*tESD->GetTPCInnerParam());
641 inner.SetLabel(tESD->GetLabel());
642 tESD->UpdateTrackParams(&inner, AliESDtrack::kTPCrefit);
643 }
644 */
b7ed2eb4 645
e85f2e31 646 // 4. convert the HLT TRD tracks to ESD tracks
18ada816 647 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack | kAliHLTDataOriginTRD);
648 pBlock!=NULL; pBlock=GetNextInputBlock()) {
57a4102f 649 fBenchmark.AddInput(pBlock->fSize);
18ada816 650 vector<AliHLTGlobalBarrelTrack> tracks;
651 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
652 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
653 element!=tracks.end(); element++) {
654
655 Double_t TRDpid[AliPID::kSPECIES], eProb(0.2), restProb((1-eProb)/(AliPID::kSPECIES-1)); //eprob(element->GetTRDpid...);
656 for(Int_t i=0; i<AliPID::kSPECIES; i++){
657 switch(i){
658 case AliPID::kElectron: TRDpid[AliPID::kElectron]=eProb; break;
659 default: TRDpid[i]=restProb; break;
660 }
661 }
662
663 AliESDtrack iotrack;
0d096bba 664 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTRDout);
0b745718 665 iotrack.SetStatus(AliESDtrack::kTRDin);
18ada816 666 iotrack.SetTRDpid(TRDpid);
667
668 pESD->AddTrack(&iotrack);
669 if (fVerbosity>0) element->Print();
670 }
671 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
672 iAddedDataBlocks++;
673 } else if (iResult<0) {
674 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
675 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
676 }
677 }
b4479a87 678 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeCaloCluster | kAliHLTDataOriginAny); pBlock!=NULL; pBlock=GetNextInputBlock())
9a9467ed 679 {
57a4102f 680 fBenchmark.AddInput(pBlock->fSize);
9a9467ed 681 AliHLTCaloClusterHeaderStruct *caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
682
683 HLTDebug("%d HLT clusters from spec: 0x%X", caloClusterHeaderPtr->fNClusters, pBlock->fSpecification);
684
2a24cbbe 685 //AliHLTCaloClusterReader reader;
686 //reader.SetMemory(caloClusterHeaderPtr);
9a9467ed 687
688 AliHLTESDCaloClusterMaker clusterMaker;
689
690 int nClusters = clusterMaker.FillESD(pESD, caloClusterHeaderPtr);
2a24cbbe 691
9a9467ed 692 HLTInfo("converted %d cluster(s) to AliESDCaloCluster and added to ESD", nClusters);
693 iAddedDataBlocks++;
694 }
f064ef44 695
331d51c5 696 // 5) Add Trigger Detectors
697 // VZERO, ZDC
698
699 // FIXME: the size of all input blocks can be added in one loop
700 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeESDContent|kAliHLTDataOriginVZERO);
701 pBlock!=NULL; pBlock=GetNextInputBlock()) {
702 fBenchmark.AddInput(pBlock->fSize);
703 }
704
705 for ( const TObject *pObject = GetFirstInputObject(kAliHLTDataTypeESDContent|kAliHLTDataOriginVZERO);
706 pObject != NULL; pObject = GetNextInputObject() ) {
707 AliESDVZERO *esdVZERO = dynamic_cast<AliESDVZERO*>(const_cast<TObject*>( pObject ) );
708 if (esdVZERO) {
709 pESD->SetVZEROData( esdVZERO );
710 break;
711 } else {
712 ALIHLTERRORGUARD(1, "input object of data type %s is not of class AliESDVZERO",
713 DataType2Text(kAliHLTDataTypeESDContent|kAliHLTDataOriginVZERO).c_str());
714 }
715 }
716
421e1221 717 // FIXME: the size of all input blocks can be added in one loop
718 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC);
719 pBlock!=NULL; pBlock=GetNextInputBlock()) {
720 fBenchmark.AddInput(pBlock->fSize);
721 }
722 for ( const TObject *pObject = GetFirstInputObject(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC);
723 pObject != NULL; pObject = GetNextInputObject() ) {
724 AliESDZDC *esdZDC = dynamic_cast<AliESDZDC*>(const_cast<TObject*>( pObject ) );
725 if (esdZDC) {
8cd67fda 726#ifndef HAVE_NOT_ALIZDCRECONSTRUCTOR_r43770
421e1221 727 pESD->SetZDCData( esdZDC );
8cd67fda 728#else
729 ALIHLTERRORGUARD(1, "Processing of ZDC data requires AliRoot r43770m skipping data block of type %s",
730 DataType2Text(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC).c_str());
731#endif
421e1221 732 break;
733 } else {
734 ALIHLTERRORGUARD(1, "input object of data type %s is not of class AliESDZDC",
735 DataType2Text(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC).c_str());
736 }
737 }
738
f064ef44 739 // Add tracks from MUON.
57a4102f 740 for( const AliHLTComponentBlockData *i= GetFirstInputBlock(kAliHLTAnyDataType | kAliHLTDataOriginMUON); i!=NULL; i=GetNextInputBlock() ){
741 fBenchmark.AddInput(i->fSize);
742 }
743
f064ef44 744 for (const TObject* obj = GetFirstInputObject(kAliHLTAnyDataType | kAliHLTDataOriginMUON);
745 obj != NULL;
746 obj = GetNextInputObject()
747 )
748 {
749 const TClonesArray* tracklist = NULL;
750 if (obj->IsA() == AliESDEvent::Class())
751 {
752 const AliESDEvent* event = static_cast<const AliESDEvent*>(obj);
753 HLTDebug("Received a MUON ESD with specification: 0x%X", GetSpecification(obj));
754 if (event->GetList() == NULL) continue;
755 tracklist = dynamic_cast<const TClonesArray*>(event->GetList()->FindObject("MuonTracks"));
756 if (tracklist == NULL) continue;
757 }
758 else if (obj->IsA() == TClonesArray::Class())
759 {
760 tracklist = static_cast<const TClonesArray*>(obj);
761 HLTDebug("Received a MUON TClonesArray of tracks with specification: 0x%X", GetSpecification(obj));
762 }
763 else
764 {
765 // Cannot handle this object type.
766 continue;
767 }
768 HLTDebug("Received %d MUON tracks.", tracklist->GetEntriesFast());
769 if (tracklist->GetEntriesFast() > 0)
770 {
771 const AliESDMuonTrack* track = dynamic_cast<const AliESDMuonTrack*>(tracklist->UncheckedAt(0));
772 if (track == NULL)
773 {
774 HLTError(Form("%s from MUON does not contain AliESDMuonTrack objects.", obj->ClassName()));
775 continue;
a1408c4b 776 }
f064ef44 777 }
778 for (Int_t i = 0; i < tracklist->GetEntriesFast(); ++i)
779 {
780 const AliESDMuonTrack* track = static_cast<const AliESDMuonTrack*>(tracklist->UncheckedAt(i));
781 pESD->AddMuonTrack(track);
782 }
783 }
784
785 if (iAddedDataBlocks>0 && pTree) {
786 pTree->Fill();
787 }
a1408c4b 788
789 if (iResult>=0) iResult=iAddedDataBlocks;
790 return iResult;
791}