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