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