3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 // @file AliHLTGlobalEsdConverterComponent.cxx
20 // @author Matthias Richter
22 // @brief Global ESD converter component.
25 // see header file for class documentation
27 // refer to README to build package
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
32 #include "AliHLTGlobalEsdConverterComponent.h"
33 #include "AliHLTGlobalBarrelTrack.h"
34 #include "AliHLTExternalTrackParam.h"
35 #include "AliHLTTrackMCLabel.h"
36 #include "AliHLTCTPData.h"
37 #include "AliHLTErrorGuard.h"
38 #include "AliESDEvent.h"
39 #include "AliESDtrack.h"
40 #include "AliESDMuonTrack.h"
41 #include "AliESDMuonCluster.h"
42 #include "AliCDBEntry.h"
43 #include "AliCDBManager.h"
47 #include "TClonesArray.h"
48 #include "AliHLTESDCaloClusterMaker.h"
49 #include "AliHLTCaloClusterDataStruct.h"
50 #include "AliHLTCaloClusterReader.h"
51 #include "AliESDCaloCluster.h"
52 #include "AliESDVZERO.h"
53 #include "AliHLTGlobalVertexerComponent.h"
54 #include "AliHLTVertexFinderBase.h"
56 /** ROOT macro for the implementation of ROOT specific class methods */
57 ClassImp(AliHLTGlobalEsdConverterComponent)
59 AliHLTGlobalEsdConverterComponent::AliHLTGlobalEsdConverterComponent()
64 , fSolenoidBz(-5.00668)
65 , fBenchmark("EsdConverter")
67 // see header file for class documentation
69 // refer to README to build package
71 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
74 AliHLTGlobalEsdConverterComponent::~AliHLTGlobalEsdConverterComponent()
76 // see header file for class documentation
77 if (fESD) delete fESD;
81 int AliHLTGlobalEsdConverterComponent::Configure(const char* arguments)
83 // see header file for class documentation
85 if (!arguments) return iResult;
87 TString allArgs=arguments;
91 TObjArray* pTokens=allArgs.Tokenize(" ");
93 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
94 argument=((TObjString*)pTokens->At(i))->String();
95 if (argument.IsNull()) continue;
97 if (argument.CompareTo("-solenoidBz")==0) {
98 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
99 HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
102 HLTError("unknown argument %s", argument.Data());
110 HLTError("missing parameter for argument %s", argument.Data());
117 int AliHLTGlobalEsdConverterComponent::Reconfigure(const char* cdbEntry, const char* chainId)
119 // see header file for class documentation
121 const char* path=NULL;
122 const char* defaultNotify="";
125 defaultNotify=" (default)";
128 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
129 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
131 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
133 HLTInfo("received configuration object string: \'%s\'", pString->String().Data());
134 iResult=Configure(pString->String().Data());
136 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
139 HLTError("can not fetch object \"%s\" from CDB", path);
146 void AliHLTGlobalEsdConverterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
148 // see header file for class documentation
149 list.push_back(kAliHLTDataTypeTrack);
150 list.push_back(kAliHLTDataTypeTrackMC);
151 list.push_back(kAliHLTDataTypeCaloCluster);
152 list.push_back(kAliHLTDataTypedEdx );
153 list.push_back(kAliHLTDataTypeESDVertex );
154 list.push_back(kAliHLTDataTypeESDObject);
155 list.push_back(kAliHLTDataTypeTObject);
156 list.push_back(kAliHLTDataTypeGlobalVertexer);
157 list.push_back(kAliHLTDataTypeV0Finder); // array of track ids for V0s
158 list.push_back(kAliHLTDataTypeKFVertex); // KFVertex object from vertexer
159 list.push_back(kAliHLTDataTypePrimaryFinder); // array of track ids for prim vertex
160 list.push_back(kAliHLTDataTypeESDContent);
163 AliHLTComponentDataType AliHLTGlobalEsdConverterComponent::GetOutputDataType()
165 // see header file for class documentation
166 return kAliHLTDataTypeESDObject|kAliHLTDataOriginOut;
169 void AliHLTGlobalEsdConverterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
171 // see header file for class documentation
173 inputMultiplier=10.0;
176 int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
178 // see header file for class documentation
183 // default list of skiped ESD objects
194 // "AliMultiplicity,"
197 // "SPDPileupVertices,"
198 // "TrkPileupVertices,"
201 "AliRawDataErrorLogs,"
204 iResult=Reconfigure(NULL, NULL);
205 TString allArgs = "";
206 for ( int i = 0; i < argc; i++ ) {
207 if ( !allArgs.IsNull() ) allArgs += " ";
211 TObjArray* pTokens=allArgs.Tokenize(" ");
213 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
214 argument=((TObjString*)pTokens->At(i))->String();
215 if (argument.IsNull()) continue;
218 if (argument.CompareTo("-notree")==0) {
222 } else if (argument.CompareTo("-tree")==0) {
224 } else if (argument.CompareTo("-solenoidBz")==0) {
225 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
226 HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->String().Data());
227 HLTWarning("argument '-solenoidBz' is deprecated, solenoid field initiaized from CDB settings");
229 } else if (argument.Contains("-skipobject=")) {
230 argument.ReplaceAll("-skipobject=", "");
231 skipObjects=argument;
233 HLTError("unknown argument %s", argument.Data());
240 HLTError("missing parameter for argument %s", argument.Data());
247 fESD = new AliESDEvent;
249 fESD->CreateStdContent();
251 // remove some of the objects which are not needed
252 if (fESD->GetList() && !skipObjects.IsNull()) {
253 pTokens=skipObjects.Tokenize(",");
257 TObject* pObject=NULL;
258 while ((pObject=next())!=NULL) {
259 id=((TObjString*)pObject)->String().Data();
260 TObject* pObj=fESD->GetList()->FindObject(id);
262 HLTDebug("removing object %s", id);
263 fESD->GetList()->Remove(pObj);
266 HLTWarning("failed to remove object '%s' from ESD", id);
269 fESD->GetStdContent();
280 fBenchmark.SetTimer(0,"total");
285 int AliHLTGlobalEsdConverterComponent::DoDeinit()
287 // see header file for class documentation
288 if (fESD) delete fESD;
294 int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
295 AliHLTComponentTriggerData& trigData)
297 // see header file for class documentation
299 if (!fESD) return -ENODEV;
301 if (!IsDataEvent()) return iResult;
302 fBenchmark.StartNewEvent();
305 AliESDEvent* pESD = fESD;
308 pESD->SetMagneticField(fSolenoidBz);
309 pESD->SetRunNumber(GetRunNo());
310 pESD->SetPeriodNumber(GetPeriodNumber());
311 pESD->SetOrbitNumber(GetOrbitNumber());
312 pESD->SetBunchCrossNumber(GetBunchCrossNumber());
313 pESD->SetTimeStamp(GetTimeStamp());
315 const AliHLTCTPData* pCTPData=CTPData();
317 AliHLTTriggerMask_t mask=pCTPData->ActiveTriggers(trigData);
318 for (int index=0; index<gkNCTPTriggerClasses; index++) {
319 if ((mask&(AliHLTTriggerMask_t(0x1)<<index)) == 0) continue;
320 pESD->SetTriggerClass(pCTPData->Name(index), index);
323 AliHLTTriggerMask_t mask50;
324 mask50.set(); // set all bits
325 mask50 >>= 50; // shift 50 right
326 pESD->SetTriggerMask((mask&mask50).to_ulong());
327 /* next 50, to be implemented
328 pESD->SetTriggerMaskNext50((mask>>50).to_ulong());
334 pTree = new TTree("esdTree", "Tree with HLT ESD objects");
337 pTree->SetDirectory(0);
340 if ((iResult=ProcessBlocks(pTree, pESD))>=0) {
341 // TODO: set the specification correctly
343 // the esd structure is written to the user info and is
344 // needed in te ReadFromTree method to read all objects correctly
345 pTree->GetUserInfo()->Add(pESD);
346 pESD->WriteToTree(pTree);
347 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginOut, 0);
349 iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginOut, 0);
351 fBenchmark.AddOutput(GetLastObjectSize());
354 // clear user info list to prevent objects from being deleted
355 pTree->GetUserInfo()->Clear();
360 HLTWarning( fBenchmark.GetStatistics() );
365 int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD)
367 // see header file for class documentation
370 int iAddedDataBlocks=0;
372 // check if there is an ESD block in the input and copy its content first to the
374 const TObject* pEsdObj = GetFirstInputObject(kAliHLTDataTypeESDObject, "AliESDEvent");
375 AliESDEvent* pInputESD=NULL;
376 if (pEsdObj) pInputESD=dynamic_cast<AliESDEvent*>(const_cast<TObject*>(pEsdObj));
378 pInputESD->GetStdContent();
381 if (GetNextInputObject()!=NULL) {
382 HLTWarning("handling of multiple ESD input objects not implemented, skipping input");
386 // tracks are based on the TPC tracks, and only updated from the ITS information
388 // 1) extract MC information for TPC and ITS from specific data blocks and store in
389 // intermediate vector arrays
390 // 2) extract TPC tracks, update with MC labels if available, the track parameters
391 // are estimated at the first cluster position
392 // 2.1) propagate to last cluster position and update kTPCout, sets also outer param (fOp)
393 // 2.2) update kTPCin, sets also inner param (fIp) and TPC inner param (fTPCInner)
394 // 2.3) update kTPCrefit using the same parameters at the first cluster position
395 // HLT has strictly spoking no refit, but we want the flag to be set
396 // can be changed to be done after all the individual barrel detector parameters
397 // have been updated by looping over the tracks again
398 // 3) extract ITS tracks, the tracks are actually TPC tracks updated from the ITS
399 // tracking information
400 // 3.1) TODO 2010-07-12: handle ITS standalone tracks by updating kITSout before kITSin
401 // 3.2) update with kITSin
402 // TODO 2010-07-12 find out if the kITSrefit has to be set as well
403 // 4) extract TRD tracks and add to ESD
404 // TODO 2010-07-12 at the moment there is no matching or merging of TPC and TRD tracks
405 // 5) Add Trigger Detectors
408 // 1) first read MC information (if present)
409 std::map<int,int> mcLabelsTPC;
410 std::map<int,int> mcLabelsITS;
412 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC);
413 pBlock!=NULL; pBlock=GetNextInputBlock()) {
415 fBenchmark.AddInput(pBlock->fSize);
417 AliHLTTrackMCData* dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr );
418 if (sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize) {
419 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
420 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
421 mcLabelsTPC[lab.fTrackID] = lab.fMCLabel;
424 HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information",
425 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification,
426 dataPtr->fCount, pBlock->fSize);
430 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginITS);
431 pBlock!=NULL; pBlock=GetNextInputBlock()) {
433 fBenchmark.AddInput(pBlock->fSize);
435 AliHLTTrackMCData* dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr );
436 if (sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize) {
437 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
438 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
439 mcLabelsITS[lab.fTrackID] = lab.fMCLabel;
442 HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information",
443 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification,
444 dataPtr->fCount, pBlock->fSize);
449 // read dEdx information (if present)
450 // TODO 2010-07-12 this needs to be verified
452 AliHLTFloat32_t *dEdxTPC = 0;
454 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypedEdx|kAliHLTDataOriginTPC);
455 pBlock!=NULL; pBlock=NULL/*GetNextInputBlock() there is only one block*/) {
456 fBenchmark.AddInput(pBlock->fSize);
457 dEdxTPC = reinterpret_cast<AliHLTFloat32_t*>( pBlock->fPtr );
458 ndEdxTPC = pBlock->fSize / (3*sizeof(AliHLTFloat32_t));
461 // 2) convert the TPC tracks to ESD tracks
462 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
463 pBlock!=NULL; pBlock=GetNextInputBlock()) {
464 if (pInputESD && pInputESD->GetNumberOfTracks()>0) {
465 HLTWarning("Tracks array already filled from the input esd block, additional filling from TPC tracks block might cause inconsistent content");
467 fBenchmark.AddInput(pBlock->fSize);
468 vector<AliHLTGlobalBarrelTrack> tracks;
469 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>=0) {
470 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
471 element!=tracks.end(); element++) {
472 Float_t points[4] = {
473 static_cast<Float_t>(element->GetX()),
474 static_cast<Float_t>(element->GetY()),
475 static_cast<Float_t>(element->GetLastPointX()),
476 static_cast<Float_t>(element->GetLastPointY())
480 if( mcLabelsTPC.find(element->TrackID())!=mcLabelsTPC.end() )
481 mcLabel = mcLabelsTPC[element->TrackID()];
482 element->SetLabel( mcLabel );
486 // for the moment, the number of clusters are not set when processing the
487 // kTPCin update, only at kTPCout
488 // there ar emainly three parameters updated for kTPCout
489 // number of clusters
492 // The first one can be updated already at that stage here, while the two others
493 // eventually require to update from the ITS tracks before. The exact scheme
494 // needs to be checked
495 iotrack.SetID( element->TrackID() );
498 // TODO 2010-07-12 disabled for the moment because of bug
499 // https://savannah.cern.ch/bugs/index.php?69875
500 // the propagation does not work, there is an offset in z
501 // propagate to last cluster and update parameters with flag kTPCout
502 // Note: updating with flag kITSout further down will overwrite the outer
503 // parameter again so this can be done only for ITS standalone tracks, meaning
504 // tracks in the ITS not associated with any TPC track
505 // HLT does not provide such standalone tracking
507 AliHLTGlobalBarrelTrack outPar(*element);
508 //outPar.AliExternalTrackParam::PropagateTo( element->GetLastPointX(), fSolenoidBz );
509 const Int_t N=10; // number of steps.
510 const Float_t xRange = element->GetLastPointX() - element->GetX();
511 const Float_t xStep = xRange / N ;
512 for(int i = 1; i <= N; ++i) {
513 if(!outPar.AliExternalTrackParam::PropagateTo(element->GetX() + xStep * i, fSolenoidBz)) break;
515 outPar.SetLabel(element->GetLabel());
516 iotrack.UpdateTrackParams(&outPar,AliESDtrack::kTPCout);
518 // 2.2 TPC tracking estimates parameters at first cluster
519 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCin);
521 // 2.3 use the same parameters also for kTPCrefit, there is no proper refit in HLT
522 // maybe this can be done later, however also the inner parameter is changed which
523 // is used as a reference point in the display. That point should be at the first
525 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCrefit);
526 iotrack.SetTPCPoints(points);
527 if( element->TrackID()<ndEdxTPC ){
528 AliHLTFloat32_t *val = &(dEdxTPC[3*element->TrackID()]);
529 iotrack.SetTPCsignal( val[0], val[1], (UChar_t) val[2] );
531 //s.Set( element->GetX(), element->GetAlpha(),
532 //element->GetParameter(), element->GetCovariance() );
533 //s.SetdEdx( val[0] );
535 //iotrack.SetTPCpid(s.TPCrPIDs() );
537 if( dEdxTPC ) HLTWarning("Wrong number of dEdx TPC labels");
539 iotrack.SetLabel(mcLabel);
540 pESD->AddTrack(&iotrack);
541 if (fVerbosity>0) element->Print();
543 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
545 } else if (iResult<0) {
546 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
547 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
552 // Get ITS SPD vertex
553 for( const AliHLTComponentBlockData *i= GetFirstInputBlock(kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS); i!=NULL; i=GetNextInputBlock() ){
554 fBenchmark.AddInput(i->fSize);
557 for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS); iter != NULL; iter = GetNextInputObject() ) {
558 AliESDVertex *vtx = dynamic_cast<AliESDVertex*>(const_cast<TObject*>( iter ) );
559 pESD->SetPrimaryVertexSPD( vtx );
562 // 3.1. now update ESD tracks with the ITSOut info
563 // updating track parameters with flag kITSout will overwrite parameter set above with flag kTPCout
564 // TODO 2010-07-12 there are some issues with this updating sequence, for the moment update with
565 // flag kITSout is disabled, would require
566 // a) to update kTPCout after kITSout
567 // b) update only for ITS standalone tracks. The HLT ITS tracker does not provide standalone
568 // tracking, every track is related to a TPC track
569 // Furthermore there seems to be a bug as the data blocks describe track parameters around the
570 // vertex, not at the outer ITS
571 // bug https://savannah.cern.ch/bugs/index.php?69872
572 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITSOut);
573 pBlock!=NULL; pBlock=GetNextInputBlock()) {
574 fBenchmark.AddInput(pBlock->fSize);
575 vector<AliHLTGlobalBarrelTrack> tracks;
576 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
577 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
578 element!=tracks.end(); element++) {
579 int tpcID=element->TrackID();
580 // the ITS tracker assigns the TPC track used as seed for a certain track to
582 if( tpcID<0 || tpcID>=pESD->GetNumberOfTracks()) continue;
583 AliESDtrack *tESD = pESD->GetTrack( tpcID );
584 element->SetLabel(tESD->GetLabel());
585 // 2010-07-12 disabled, see above, bugfix https://savannah.cern.ch/bugs/index.php?69872
586 //if( tESD ) tESD->UpdateTrackParams( &(*element), AliESDtrack::kITSout );
591 // 3.2. now update ESD tracks with the ITS info
592 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITS);
593 pBlock!=NULL; pBlock=GetNextInputBlock()) {
594 fBenchmark.AddInput(pBlock->fSize);
595 vector<AliHLTGlobalBarrelTrack> tracks;
596 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
597 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
598 element!=tracks.end(); element++) {
599 int tpcID=element->TrackID();
600 // the ITS tracker assigns the TPC track used as seed for a certain track to
602 if( tpcID<0 || tpcID>=pESD->GetNumberOfTracks()) continue;
604 if( mcLabelsITS.find(element->TrackID())!=mcLabelsITS.end() )
605 mcLabel = mcLabelsITS[element->TrackID()];
606 AliESDtrack *tESD = pESD->GetTrack( tpcID );
608 // the labels for the TPC and ITS tracking params can be different, e.g.
609 // there can be a decay. The ITS label should then be the better one, the
610 // TPC label is saved in a member of AliESDtrack
612 // upadte only if the ITS label is available, otherwise keep TPC label
613 element->SetLabel( mcLabel );
615 // bugfix https://savannah.cern.ch/bugs/?69713
616 element->SetLabel( tESD->GetLabel() );
618 tESD->UpdateTrackParams( &(*element), AliESDtrack::kITSin );
620 // TODO: add a proper refit
621 //tESD->UpdateTrackParams( &(*element), AliESDtrack::kTPCrefit );
626 // update with vertices and vertex-fitted tracks
627 // output of the GlobalVertexerComponent
628 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeGlobalVertexer);
629 pBlock!=NULL; pBlock=GetNextInputBlock()) {
630 fBenchmark.AddInput(pBlock->fSize);
631 AliHLTGlobalVertexerComponent::FillESD( pESD, reinterpret_cast<AliHLTGlobalVertexerComponent::AliHLTGlobalVertexerData* >(pBlock->fPtr) );
634 // update with vertices and vertex-fitted tracks
635 // output of PrimaryVertexer and V0Finder components
636 TObject* pBase = (TObject*)GetFirstInputObject(kAliHLTDataTypeKFVertex | kAliHLTDataOriginOut);
638 AliKFVertex* kfVertex = dynamic_cast<AliKFVertex *>(pBase);
640 const AliHLTComponentBlockData* pP = GetFirstInputBlock(kAliHLTDataTypePrimaryFinder | kAliHLTDataOriginOut);
641 if (pP && pP->fSize && pP->fPtr) {
642 const AliHLTComponentBlockData* pV0 = GetFirstInputBlock(kAliHLTDataTypeV0Finder | kAliHLTDataOriginOut);
643 if (pV0 && pV0->fPtr && pInputESD && pInputESD->GetNumberOfV0s()>0) {
644 const int* v0s = static_cast<const int*>(pV0->fPtr);
645 HLTWarning("V0 array already filled from the input esd block, additional filling from V0 block of %d entries might cause inconsistent content", v0s[0]);
647 AliHLTVertexFinderBase::FillESD(pESD, kfVertex, pP->fPtr, pV0?pV0->fPtr:NULL);
649 HLTWarning("Problem with primary finder's data block");
651 HLTWarning("primary vertex block of wrong type, expecting AliKFVertex instead of %s", pBase->GetName());
654 // throw an error if there is a V0 data block which can not be handled without
655 // the AliKFVertex object
656 if (GetFirstInputBlock(kAliHLTDataTypeV0Finder | kAliHLTDataOriginOut)!=NULL) {
657 ALIHLTERRORGUARD(1, "missing AliKFVertex object ignoring V0 data block of type %s",
658 DataType2Text(kAliHLTDataTypeV0Finder|kAliHLTDataOriginOut).c_str());
662 // Fill DCA parameters for TPC tracks
663 // TODO 2010-07-12 this propagates also the TPC inner param to beamline
664 // sounds not very reasonable
665 // https://savannah.cern.ch/bugs/index.php?69873
666 for (int i=0; i<pESD->GetNumberOfTracks(); i++) {
667 if (!pESD->GetTrack(i) ||
668 !pESD->GetTrack(i)->GetTPCInnerParam() ) continue;
669 pESD->GetTrack(i)->RelateToVertexTPC(pESD->GetPrimaryVertexTracks(), fSolenoidBz, 1000 );
672 // loop over all tracks and set the TPC refit flag by updating with the
673 // original TPC inner parameter if not yet set
674 // TODO: replace this by a proper refit
675 // code is comented for the moment as it does not fully solve the problems with
677 // - would set the main parameters to the TPC inner wall again, or
678 // - changes the inner param if the parameters are propagated, so we loose the track
679 // reference point for the display
680 // with the current sequence we have the latter case as the DCA operations above
681 // change the TPC inner parameters
683 for (int i=0; i<pESD->GetNumberOfTracks(); i++) {
684 if (!pESD->GetTrack(i) ||
685 !pESD->GetTrack(i)->GetTPCInnerParam() ||
686 pESD->GetTrack(i)->IsOn(AliESDtrack::kTPCrefit)) continue;
687 AliESDtrack* tESD=pESD->GetTrack(i);
688 AliHLTGlobalBarrelTrack inner(*tESD->GetTPCInnerParam());
689 inner.SetLabel(tESD->GetLabel());
690 tESD->UpdateTrackParams(&inner, AliESDtrack::kTPCrefit);
694 // 4. convert the HLT TRD tracks to ESD tracks
695 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack | kAliHLTDataOriginTRD);
696 pBlock!=NULL; pBlock=GetNextInputBlock()) {
697 fBenchmark.AddInput(pBlock->fSize);
698 vector<AliHLTGlobalBarrelTrack> tracks;
699 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
700 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
701 element!=tracks.end(); element++) {
703 Double_t TRDpid[AliPID::kSPECIES], eProb(0.2), restProb((1-eProb)/(AliPID::kSPECIES-1)); //eprob(element->GetTRDpid...);
704 for(Int_t i=0; i<AliPID::kSPECIES; i++){
706 case AliPID::kElectron: TRDpid[AliPID::kElectron]=eProb; break;
707 default: TRDpid[i]=restProb; break;
712 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTRDout);
713 iotrack.SetStatus(AliESDtrack::kTRDin);
714 iotrack.SetTRDpid(TRDpid);
716 pESD->AddTrack(&iotrack);
717 if (fVerbosity>0) element->Print();
719 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
721 } else if (iResult<0) {
722 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
723 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
726 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeCaloCluster | kAliHLTDataOriginAny); pBlock!=NULL; pBlock=GetNextInputBlock())
728 fBenchmark.AddInput(pBlock->fSize);
729 AliHLTCaloClusterHeaderStruct *caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
731 HLTDebug("%d HLT clusters from spec: 0x%X", caloClusterHeaderPtr->fNClusters, pBlock->fSpecification);
733 //AliHLTCaloClusterReader reader;
734 //reader.SetMemory(caloClusterHeaderPtr);
736 AliHLTESDCaloClusterMaker clusterMaker;
738 int nClusters = clusterMaker.FillESD(pESD, caloClusterHeaderPtr);
740 HLTInfo("converted %d cluster(s) to AliESDCaloCluster and added to ESD", nClusters);
744 // 5) Add Trigger Detectors
747 // FIXME: the size of all input blocks can be added in one loop
748 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeESDContent|kAliHLTDataOriginVZERO);
749 pBlock!=NULL; pBlock=GetNextInputBlock()) {
750 fBenchmark.AddInput(pBlock->fSize);
753 for ( const TObject *pObject = GetFirstInputObject(kAliHLTDataTypeESDContent|kAliHLTDataOriginVZERO);
754 pObject != NULL; pObject = GetNextInputObject() ) {
755 AliESDVZERO *esdVZERO = dynamic_cast<AliESDVZERO*>(const_cast<TObject*>( pObject ) );
757 pESD->SetVZEROData( esdVZERO );
760 ALIHLTERRORGUARD(1, "input object of data type %s is not of class AliESDVZERO",
761 DataType2Text(kAliHLTDataTypeESDContent|kAliHLTDataOriginVZERO).c_str());
765 // FIXME: the size of all input blocks can be added in one loop
766 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC);
767 pBlock!=NULL; pBlock=GetNextInputBlock()) {
768 fBenchmark.AddInput(pBlock->fSize);
770 for ( const TObject *pObject = GetFirstInputObject(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC);
771 pObject != NULL; pObject = GetNextInputObject() ) {
772 AliESDZDC *esdZDC = dynamic_cast<AliESDZDC*>(const_cast<TObject*>( pObject ) );
774 #ifndef HAVE_NOT_ALIZDCRECONSTRUCTOR_r43770
775 pESD->SetZDCData( esdZDC );
777 ALIHLTERRORGUARD(1, "Processing of ZDC data requires AliRoot r43770m skipping data block of type %s",
778 DataType2Text(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC).c_str());
782 ALIHLTERRORGUARD(1, "input object of data type %s is not of class AliESDZDC",
783 DataType2Text(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC).c_str());
787 // Add tracks and clusters from MUON.
788 for( const AliHLTComponentBlockData *i= GetFirstInputBlock(kAliHLTAnyDataType | kAliHLTDataOriginMUON); i!=NULL; i=GetNextInputBlock() ){
789 fBenchmark.AddInput(i->fSize);
792 for (const TObject* obj = GetFirstInputObject(kAliHLTAnyDataType | kAliHLTDataOriginMUON);
794 obj = GetNextInputObject()
797 const TClonesArray* tracklist = NULL;
798 const TClonesArray* clusterlist = NULL;
799 if (obj->IsA() == AliESDEvent::Class())
801 const AliESDEvent* event = static_cast<const AliESDEvent*>(obj);
802 HLTDebug("Received a MUON ESD with specification: 0x%X", GetSpecification(obj));
803 if (event->GetList() == NULL) continue;
804 tracklist = dynamic_cast<const TClonesArray*>(event->GetList()->FindObject("MuonTracks"));
805 if (tracklist == NULL) continue;
806 clusterlist = dynamic_cast<const TClonesArray*>(event->GetList()->FindObject("MuonClusters"));
807 if (clusterlist == NULL) continue;
809 else if (obj->IsA() == TClonesArray::Class())
811 if (!strcmp(obj->GetName(), "MuonTracks")) {
812 tracklist = static_cast<const TClonesArray*>(obj);
813 HLTDebug("Received a MUON TClonesArray of tracks with specification: 0x%X", GetSpecification(obj));
815 clusterlist = static_cast<const TClonesArray*>(obj);
816 HLTDebug("Received a MUON TClonesArray of clusters with specification: 0x%X", GetSpecification(obj));
821 // Cannot handle this object type.
826 HLTDebug("Received %d MUON tracks.", tracklist->GetEntriesFast());
827 if (tracklist->GetEntriesFast() > 0)
829 const AliESDMuonTrack* track = dynamic_cast<const AliESDMuonTrack*>(tracklist->UncheckedAt(0));
832 HLTError(Form("%s from MUON does not contain AliESDMuonTrack objects.", obj->ClassName()));
836 for (Int_t i = 0; i < tracklist->GetEntriesFast(); ++i)
838 AliESDMuonTrack* track = pESD->NewMuonTrack();
839 *track = *(static_cast<const AliESDMuonTrack*>(tracklist->UncheckedAt(i)));
844 HLTDebug("Received %d MUON clusters.", clusterlist->GetEntriesFast());
845 if (clusterlist->GetEntriesFast() > 0)
847 const AliESDMuonCluster* cluster = dynamic_cast<const AliESDMuonCluster*>(clusterlist->UncheckedAt(0));
850 HLTError(Form("%s from MUON does not contain AliESDMuonCluster objects.", obj->ClassName()));
854 for (Int_t i = 0; i < clusterlist->GetEntriesFast(); ++i)
856 AliESDMuonCluster* cluster = pESD->NewMuonCluster();
857 *cluster = *(static_cast<const AliESDMuonCluster*>(clusterlist->UncheckedAt(i)));
862 if (iAddedDataBlocks>0 && pTree) {
866 if (iResult>=0) iResult=iAddedDataBlocks;