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