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 "AliHLTTPCDefinitions.h"
38 #include "AliHLTTPCSpacePointData.h"
39 #include "AliHLTTPCClusterDataFormat.h"
40 #include "AliTPCclusterMI.h"
41 #include "AliTPCseed.h"
42 #include "AliESDfriend.h"
43 #include "AliESDfriendTrack.h"
44 #include "AliHLTTPCTransform.h"
45 #include "AliHLTErrorGuard.h"
46 #include "AliESDEvent.h"
47 #include "AliESDtrack.h"
48 #include "AliESDMuonTrack.h"
49 #include "AliESDMuonCluster.h"
50 #include "AliCDBEntry.h"
51 #include "AliCDBManager.h"
55 #include "TClonesArray.h"
56 #include "TTimeStamp.h"
57 #include "THnSparse.h"
58 #include "AliHLTESDCaloClusterMaker.h"
59 #include "AliHLTCaloClusterDataStruct.h"
60 #include "AliHLTCaloClusterReader.h"
61 #include "AliESDCaloCluster.h"
62 #include "AliESDVZERO.h"
63 #include "AliHLTGlobalVertexerComponent.h"
64 #include "AliHLTVertexFinderBase.h"
65 #include "AliSysInfo.h"
67 /** ROOT macro for the implementation of ROOT specific class methods */
68 ClassImp(AliHLTGlobalEsdConverterComponent)
70 AliHLTGlobalEsdConverterComponent::AliHLTGlobalEsdConverterComponent()
75 , fSolenoidBz(-5.00668)
77 , fBenchmark("EsdConverter")
79 // see header file for class documentation
81 // refer to README to build package
83 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
84 for( int i=0; i<fkNPartition; i++ ){
85 fPartitionClusters[i] = 0;
86 fNPartitionClusters[i] = 0;
90 AliHLTGlobalEsdConverterComponent::~AliHLTGlobalEsdConverterComponent()
92 // see header file for class documentation
93 if (fESD) delete fESD;
95 for( int i=0; i<fkNPartition; i++ ){
96 delete[] fPartitionClusters[i];
100 int AliHLTGlobalEsdConverterComponent::Configure(const char* arguments)
102 // see header file for class documentation
104 if (!arguments) return iResult;
106 TString allArgs=arguments;
110 TObjArray* pTokens=allArgs.Tokenize(" ");
112 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
113 argument=((TObjString*)pTokens->At(i))->String();
114 if (argument.IsNull()) continue;
116 if (argument.CompareTo("-solenoidBz")==0) {
117 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
118 HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
121 HLTError("unknown argument %s", argument.Data());
129 HLTError("missing parameter for argument %s", argument.Data());
136 int AliHLTGlobalEsdConverterComponent::Reconfigure(const char* cdbEntry, const char* chainId)
138 // see header file for class documentation
140 const char* path=NULL;
141 const char* defaultNotify="";
144 defaultNotify=" (default)";
147 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
148 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
150 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
152 HLTInfo("received configuration object string: \'%s\'", pString->String().Data());
153 iResult=Configure(pString->String().Data());
155 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
158 HLTError("can not fetch object \"%s\" from CDB", path);
165 void AliHLTGlobalEsdConverterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
167 // see header file for class documentation
168 list.push_back(kAliHLTDataTypeTrack);
169 list.push_back(kAliHLTDataTypeTrackMC);
170 list.push_back(kAliHLTDataTypeCaloCluster);
171 list.push_back(kAliHLTDataTypedEdx );
172 list.push_back(kAliHLTDataTypeESDVertex );
173 list.push_back(kAliHLTDataTypeESDObject);
174 list.push_back(kAliHLTDataTypeTObject);
175 list.push_back(kAliHLTDataTypeGlobalVertexer);
176 list.push_back(kAliHLTDataTypeV0Finder); // array of track ids for V0s
177 list.push_back(kAliHLTDataTypeKFVertex); // KFVertex object from vertexer
178 list.push_back(kAliHLTDataTypePrimaryFinder); // array of track ids for prim vertex
179 list.push_back(kAliHLTDataTypeESDContent);
180 list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
183 AliHLTComponentDataType AliHLTGlobalEsdConverterComponent::GetOutputDataType()
185 // see header file for class documentation
186 return kAliHLTDataTypeESDObject|kAliHLTDataOriginOut;
189 void AliHLTGlobalEsdConverterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
191 // see header file for class documentation
193 inputMultiplier=10.0;
196 int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
198 // see header file for class documentation
203 // default list of skiped ESD objects
214 // "AliMultiplicity,"
217 // "SPDPileupVertices,"
218 // "TrkPileupVertices,"
221 "AliRawDataErrorLogs,"
224 iResult=Reconfigure(NULL, NULL);
225 TString allArgs = "";
226 for ( int i = 0; i < argc; i++ ) {
227 if ( !allArgs.IsNull() ) allArgs += " ";
231 TObjArray* pTokens=allArgs.Tokenize(" ");
233 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
234 argument=((TObjString*)pTokens->At(i))->String();
235 if (argument.IsNull()) continue;
238 if (argument.CompareTo("-notree")==0) {
242 } else if (argument.CompareTo("-tree")==0) {
244 } else if (argument.CompareTo("-solenoidBz")==0) {
245 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
246 HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->String().Data());
247 HLTWarning("argument '-solenoidBz' is deprecated, solenoid field initiaized from CDB settings");
249 } else if (argument.Contains("-skipobject=")) {
250 argument.ReplaceAll("-skipobject=", "");
251 skipObjects=argument;
253 HLTError("unknown argument %s", argument.Data());
260 HLTError("missing parameter for argument %s", argument.Data());
267 fESD = new AliESDEvent;
269 fESD->CreateStdContent();
271 // remove some of the objects which are not needed
272 if (fESD->GetList() && !skipObjects.IsNull()) {
273 pTokens=skipObjects.Tokenize(",");
277 TObject* pObject=NULL;
278 while ((pObject=next())!=NULL) {
279 id=((TObjString*)pObject)->String().Data();
280 TObject* pObj=fESD->GetList()->FindObject(id);
282 HLTDebug("removing object %s", id);
283 fESD->GetList()->Remove(pObj);
286 HLTWarning("failed to remove object '%s' from ESD", id);
289 fESD->GetStdContent();
300 fBenchmark.SetTimer(0,"total");
305 int AliHLTGlobalEsdConverterComponent::DoDeinit()
307 // see header file for class documentation
308 if (fESD) delete fESD;
314 int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& evtData,
315 AliHLTComponentTriggerData& trigData)
317 // see header file for class documentation
321 AliSysInfo::AddStamp("DoEvent.Start", evtData.fStructSize);
323 bool benchmark = true;
325 if (!fESD) return -ENODEV;
327 if (!IsDataEvent()) return iResult;
328 fBenchmark.StartNewEvent();
331 for(Int_t i=0; i<fkNPartition; i++){
332 delete[] fPartitionClusters[i];
333 fPartitionClusters[i] = 0;
334 fNPartitionClusters[i] = 0;
337 AliESDEvent* pESD = fESD;
340 pESD->SetMagneticField(fSolenoidBz);
341 pESD->SetRunNumber(GetRunNo());
342 pESD->SetPeriodNumber(GetPeriodNumber());
343 pESD->SetOrbitNumber(GetOrbitNumber());
344 pESD->SetBunchCrossNumber(GetBunchCrossNumber());
345 pESD->SetTimeStamp(GetTimeStamp());
347 const AliHLTCTPData* pCTPData=CTPData();
349 AliHLTTriggerMask_t mask=pCTPData->ActiveTriggers(trigData);
350 for (int index=0; index<gkNCTPTriggerClasses; index++) {
351 if ((mask&(AliHLTTriggerMask_t(0x1)<<index)) == 0) continue;
352 pESD->SetTriggerClass(pCTPData->Name(index), index);
355 AliHLTTriggerMask_t mask50;
356 mask50.set(); // set all bits
357 mask50 >>= 50; // shift 50 right
358 pESD->SetTriggerMask((mask&mask50).to_ulong());
360 pESD->SetTriggerMaskNext50((mask>>50).to_ulong());
365 pTree = new TTree("esdTree", "Tree with HLT ESD objects");
368 pTree->SetDirectory(0);
371 if ((iResult=ProcessBlocks(pTree, pESD))>=0) {
372 // TODO: set the specification correctly
374 // the esd structure is written to the user info and is
375 // needed in te ReadFromTree method to read all objects correctly
376 pTree->GetUserInfo()->Add(pESD);
377 pESD->WriteToTree(pTree);
378 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginOut, 0);
380 iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginOut, 0);
382 fBenchmark.AddOutput(GetLastObjectSize());
385 // clear user info list to prevent objects from being deleted
386 pTree->GetUserInfo()->Clear();
391 HLTWarning( fBenchmark.GetStatistics() );
400 Int_t nV0s = pESD->GetNumberOfV0s();
401 Int_t nTracks = pESD->GetNumberOfTracks();
404 Double_t statistics[10];
406 fBenchmark.GetStatisticsData(statistics, names);
407 // statistics[5] = nTracks;
408 // statistics[6] = time;
409 // statistics[7] = nV0s;
411 // FillBenchmarkHistos( statistics, names);
414 AliSysInfo::AddStamp("DoEvent.Stop", (int)(statistics[1]), (int)(statistics[2]),pESD->GetNumberOfV0s(),pESD->GetNumberOfTracks() );
417 for(Int_t i=0; i<fkNPartition; i++){
418 delete[] fPartitionClusters[i];
419 fPartitionClusters[i] = 0;
420 fNPartitionClusters[i] = 0;
426 int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD)
428 // see header file for class documentation
431 int iAddedDataBlocks=0;
433 // check if there is an ESD block in the input and copy its content first to the
435 const TObject* pEsdObj = GetFirstInputObject(kAliHLTDataTypeESDObject, "AliESDEvent");
436 AliESDEvent* pInputESD=NULL;
437 if (pEsdObj) pInputESD=dynamic_cast<AliESDEvent*>(const_cast<TObject*>(pEsdObj));
439 pInputESD->GetStdContent();
442 if (GetNextInputObject()!=NULL) {
443 HLTWarning("handling of multiple ESD input objects not implemented, skipping input");
446 AliESDfriend *esdFriend = new AliESDfriend;
449 // tracks are based on the TPC tracks, and only updated from the ITS information
451 // 1) extract MC information for TPC and ITS from specific data blocks and store in
452 // intermediate vector arrays
453 // 2) extract TPC tracks, update with MC labels if available, the track parameters
454 // are estimated at the first cluster position
455 // 2.1) propagate to last cluster position and update kTPCout, sets also outer param (fOp)
456 // 2.2) update kTPCin, sets also inner param (fIp) and TPC inner param (fTPCInner)
457 // 2.3) update kTPCrefit using the same parameters at the first cluster position
458 // HLT has strictly spoking no refit, but we want the flag to be set
459 // can be changed to be done after all the individual barrel detector parameters
460 // have been updated by looping over the tracks again
461 // 3) extract ITS tracks, the tracks are actually TPC tracks updated from the ITS
462 // tracking information
463 // 3.1) TODO 2010-07-12: handle ITS standalone tracks by updating kITSout before kITSin
464 // 3.2) update with kITSin
465 // TODO 2010-07-12 find out if the kITSrefit has to be set as well
466 // 4) extract TRD tracks and add to ESD
467 // TODO 2010-07-12 at the moment there is no matching or merging of TPC and TRD tracks
468 // 5) Add Trigger Detectors
472 // ---------- Access to clusters --------------------//
474 for(Int_t i=0; i<fkNPartition; i++){
475 delete[] fPartitionClusters[i];
476 fPartitionClusters[i] = 0;
477 fNPartitionClusters[i] = 0;
482 int nInputClusters = 0;
484 for(const AliHLTComponentBlockData *iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkClustersDataType); iter != NULL; iter = GetNextInputBlock()){
486 if(iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType) continue;
487 Int_t slice = AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
488 Int_t partition = AliHLTTPCDefinitions::GetMinPatchNr(iter->fSpecification);
489 Int_t slicepartition = slice*6+partition;
490 if(slicepartition<0 || slicepartition > fkNPartition){
491 HLTWarning("Wrong header of TPC cluster data, slice %d, partition %d", slice, partition );
495 AliHLTTPCClusterData *inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
496 nInputClusters += inPtrSP->fSpacePointCnt;
498 delete[] fPartitionClusters[slicepartition];
499 fPartitionClusters[slicepartition] = new AliTPCclusterMI[inPtrSP->fSpacePointCnt];
500 fNPartitionClusters[slicepartition] = inPtrSP->fSpacePointCnt;
502 // create offline clusters out of the HLT clusters
504 for ( unsigned int i = 0; i < inPtrSP->fSpacePointCnt; i++ ) {
505 AliHLTTPCSpacePointData *chlt = &( inPtrSP->fSpacePoints[i] );
506 AliTPCclusterMI *c = fPartitionClusters[slicepartition]+i;
510 c->SetSigmaY2(chlt->fSigmaY2);
512 c->SetSigmaZ2(chlt->fSigmaZ2);
513 c->SetQ( chlt->fCharge );
514 c->SetMax( chlt->fQMax );
516 Float_t padtime[3] = {0,chlt->fY,chlt->fZ};
517 AliHLTTPCTransform::Slice2Sector(slice,chlt->fPadRow, sector, row);
518 AliHLTTPCTransform::Local2Raw( padtime, sector, row);
519 c->SetDetector( sector );
521 c->SetPad( (Int_t) padtime[1] );
522 c->SetTimeBin( (Int_t) padtime[2] );
524 } // end of loop over blocks of clusters
527 // 1) first read MC information (if present)
528 std::map<int,int> mcLabelsTPC;
529 std::map<int,int> mcLabelsITS;
531 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC);
532 pBlock!=NULL; pBlock=GetNextInputBlock()) {
534 fBenchmark.AddInput(pBlock->fSize);
536 AliHLTTrackMCData* dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr );
537 if (sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize) {
538 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
539 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
540 mcLabelsTPC[lab.fTrackID] = lab.fMCLabel;
543 HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information",
544 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification,
545 dataPtr->fCount, pBlock->fSize);
549 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginITS);
550 pBlock!=NULL; pBlock=GetNextInputBlock()) {
552 fBenchmark.AddInput(pBlock->fSize);
554 AliHLTTrackMCData* dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr );
555 if (sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize) {
556 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
557 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
558 mcLabelsITS[lab.fTrackID] = lab.fMCLabel;
561 HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information",
562 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification,
563 dataPtr->fCount, pBlock->fSize);
568 // read dEdx information (if present)
569 // TODO 2010-07-12 this needs to be verified
571 AliHLTFloat32_t *dEdxTPC = 0;
573 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypedEdx|kAliHLTDataOriginTPC);
574 pBlock!=NULL; pBlock=NULL/*GetNextInputBlock() there is only one block*/) {
575 fBenchmark.AddInput(pBlock->fSize);
576 dEdxTPC = reinterpret_cast<AliHLTFloat32_t*>( pBlock->fPtr );
577 ndEdxTPC = pBlock->fSize / (3*sizeof(AliHLTFloat32_t));
580 // 2) convert the TPC tracks to ESD tracks
581 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
582 pBlock!=NULL; pBlock=GetNextInputBlock()) {
583 if (pInputESD && pInputESD->GetNumberOfTracks()>0) {
584 HLTWarning("Tracks array already filled from the input esd block, additional filling from TPC tracks block might cause inconsistent content");
586 fBenchmark.AddInput(pBlock->fSize);
587 vector<AliHLTGlobalBarrelTrack> tracks;
588 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>=0) {
589 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
590 element!=tracks.end(); element++) {
591 Float_t points[4] = {
592 static_cast<Float_t>(element->GetX()),
593 static_cast<Float_t>(element->GetY()),
594 static_cast<Float_t>(element->GetLastPointX()),
595 static_cast<Float_t>(element->GetLastPointY())
599 if( mcLabelsTPC.find(element->TrackID())!=mcLabelsTPC.end() )
600 mcLabel = mcLabelsTPC[element->TrackID()];
601 element->SetLabel( mcLabel );
605 // for the moment, the number of clusters are not set when processing the
606 // kTPCin update, only at kTPCout
607 // there ar emainly three parameters updated for kTPCout
608 // number of clusters
611 // The first one can be updated already at that stage here, while the two others
612 // eventually require to update from the ITS tracks before. The exact scheme
613 // needs to be checked
614 iotrack.SetID( element->TrackID() );
617 // TODO 2010-07-12 disabled for the moment because of bug
618 // https://savannah.cern.ch/bugs/index.php?69875
619 // the propagation does not work, there is an offset in z
620 // propagate to last cluster and update parameters with flag kTPCout
621 // Note: updating with flag kITSout further down will overwrite the outer
622 // parameter again so this can be done only for ITS standalone tracks, meaning
623 // tracks in the ITS not associated with any TPC track
624 // HLT does not provide such standalone tracking
626 AliHLTGlobalBarrelTrack outPar(*element);
627 //outPar.AliExternalTrackParam::PropagateTo( element->GetLastPointX(), fSolenoidBz );
628 const Int_t N=10; // number of steps.
629 const Float_t xRange = element->GetLastPointX() - element->GetX();
630 const Float_t xStep = xRange / N ;
631 for(int i = 1; i <= N; ++i) {
632 if(!outPar.AliExternalTrackParam::PropagateTo(element->GetX() + xStep * i, fSolenoidBz)) break;
634 outPar.SetLabel(element->GetLabel());
635 iotrack.UpdateTrackParams(&outPar,AliESDtrack::kTPCout);
637 // 2.2 TPC tracking estimates parameters at first cluster
638 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCin);
640 // 2.3 use the same parameters also for kTPCrefit, there is no proper refit in HLT
641 // maybe this can be done later, however also the inner parameter is changed which
642 // is used as a reference point in the display. That point should be at the first
644 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCrefit);
645 iotrack.SetTPCPoints(points);
646 if( element->TrackID()<ndEdxTPC ){
647 AliHLTFloat32_t *val = &(dEdxTPC[3*element->TrackID()]);
648 iotrack.SetTPCsignal( val[0], val[1], (UChar_t) val[2] );
650 //s.Set( element->GetX(), element->GetAlpha(),
651 //element->GetParameter(), element->GetCovariance() );
652 //s.SetdEdx( val[0] );
654 //iotrack.SetTPCpid(s.TPCrPIDs() );
656 if( dEdxTPC ) HLTWarning("Wrong number of dEdx TPC labels");
658 iotrack.SetLabel(mcLabel);
659 pESD->AddTrack(&iotrack);
660 if (fVerbosity>0) element->Print();
662 if( fMakeFriends ){ // create friend track
664 AliHLTGlobalBarrelTrack gb(*element);
666 tTPC.Set( gb.GetX(), gb.GetAlpha(), gb.GetParameter(), gb.GetCovariance() );
667 tTPC.SetLabel(mcLabel);
670 UInt_t nClusters = element->GetNumberOfPoints();
671 const UInt_t*clusterIDs = element->GetPoints();
673 tTPC.SetNumberOfClusters(nClusters);
675 for(UInt_t ic=0; ic<nClusters; ic++){
677 UInt_t id = clusterIDs[ic];
678 int iSlice = AliHLTTPCSpacePointData::GetSlice(id);
679 int iPartition = AliHLTTPCSpacePointData::GetPatch(id);
680 int iCluster = AliHLTTPCSpacePointData::GetNumber(id);
682 if(iSlice<0 || iSlice>36 || iPartition<0 || iPartition>5){
683 HLTError("Corrupted TPC cluster Id: slice %d, partition %d, cluster %d", iSlice, iPartition, iCluster);
687 AliTPCclusterMI *patchClusters = fPartitionClusters[iSlice*6 + iPartition];
689 HLTError("Clusters are missed for slice %d, partition %d", iSlice, iPartition );
693 if(iCluster >= fNPartitionClusters[iSlice*6 + iPartition]){
694 HLTError("TPC slice %d, partition %d: ClusterID==%d >= N Cluaters==%d ", iSlice, iPartition,iCluster, fNPartitionClusters[iSlice*6 + iPartition] );
698 AliTPCclusterMI *c = &(patchClusters[iCluster]);
699 int sec = c->GetDetector();
700 int row = c->GetRow();
701 if(sec >= 36) row = row + AliHLTTPCTransform::GetNRowLow();
703 tTPC.SetClusterPointer(row, c);
705 AliTPCTrackerPoint &point = *( tTPC.GetTrackPoint( row ) );
706 //tTPC.Propagate( TMath::DegToRad()*(sec%18*20.+10.), c->GetX(), fSolenoidBz );
707 Double_t angle2 = tTPC.GetSnp()*tTPC.GetSnp();
708 angle2 = (angle2<1) ?TMath::Sqrt(angle2/(1-angle2)) :10.;
709 point.SetAngleY( angle2 );
710 point.SetAngleZ( tTPC.GetTgl() );
711 } // end of associated cluster loop
715 AliTPCseed *seed = &(tTPC);
716 //fSeedArray->AddAt( seed, TMath::Abs(seed->GetLabel()) );
717 //fdEdx->Fill( seed->P()*seed->Charge(), seed->CookdEdx(0.02, 0.6) );
719 AliESDfriendTrack friendTrack;
720 friendTrack.AddCalibObject(&tTPC);
721 esdFriend->AddTrack(&friendTrack);
725 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
727 } else if (iResult<0) {
728 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
729 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
734 // Get ITS SPD vertex
735 for( const AliHLTComponentBlockData *i= GetFirstInputBlock(kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS); i!=NULL; i=GetNextInputBlock() ){
736 fBenchmark.AddInput(i->fSize);
739 for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS); iter != NULL; iter = GetNextInputObject() ) {
740 AliESDVertex *vtx = dynamic_cast<AliESDVertex*>(const_cast<TObject*>( iter ) );
741 pESD->SetPrimaryVertexSPD( vtx );
744 // 3.1. now update ESD tracks with the ITSOut info
745 // updating track parameters with flag kITSout will overwrite parameter set above with flag kTPCout
746 // TODO 2010-07-12 there are some issues with this updating sequence, for the moment update with
747 // flag kITSout is disabled, would require
748 // a) to update kTPCout after kITSout
749 // b) update only for ITS standalone tracks. The HLT ITS tracker does not provide standalone
750 // tracking, every track is related to a TPC track
751 // Furthermore there seems to be a bug as the data blocks describe track parameters around the
752 // vertex, not at the outer ITS
753 // bug https://savannah.cern.ch/bugs/index.php?69872
754 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITSOut);
755 pBlock!=NULL; pBlock=GetNextInputBlock()) {
756 fBenchmark.AddInput(pBlock->fSize);
757 vector<AliHLTGlobalBarrelTrack> tracks;
758 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
759 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
760 element!=tracks.end(); element++) {
761 int tpcID=element->TrackID();
762 // the ITS tracker assigns the TPC track used as seed for a certain track to
764 if( tpcID<0 || tpcID>=pESD->GetNumberOfTracks()) continue;
765 AliESDtrack *tESD = pESD->GetTrack( tpcID );
766 element->SetLabel(tESD->GetLabel());
767 // 2010-07-12 disabled, see above, bugfix https://savannah.cern.ch/bugs/index.php?69872
768 //if( tESD ) tESD->UpdateTrackParams( &(*element), AliESDtrack::kITSout );
773 // 3.2. now update ESD tracks with the ITS info
774 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITS);
775 pBlock!=NULL; pBlock=GetNextInputBlock()) {
776 fBenchmark.AddInput(pBlock->fSize);
777 vector<AliHLTGlobalBarrelTrack> tracks;
778 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
779 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
780 element!=tracks.end(); element++) {
781 int tpcID=element->TrackID();
782 // the ITS tracker assigns the TPC track used as seed for a certain track to
784 if( tpcID<0 || tpcID>=pESD->GetNumberOfTracks()) continue;
786 if( mcLabelsITS.find(element->TrackID())!=mcLabelsITS.end() )
787 mcLabel = mcLabelsITS[element->TrackID()];
788 AliESDtrack *tESD = pESD->GetTrack( tpcID );
790 // the labels for the TPC and ITS tracking params can be different, e.g.
791 // there can be a decay. The ITS label should then be the better one, the
792 // TPC label is saved in a member of AliESDtrack
794 // upadte only if the ITS label is available, otherwise keep TPC label
795 element->SetLabel( mcLabel );
797 // bugfix https://savannah.cern.ch/bugs/?69713
798 element->SetLabel( tESD->GetLabel() );
800 tESD->UpdateTrackParams( &(*element), AliESDtrack::kITSin );
802 // TODO: add a proper refit
803 //tESD->UpdateTrackParams( &(*element), AliESDtrack::kTPCrefit );
808 // update with vertices and vertex-fitted tracks
809 // output of the GlobalVertexerComponent
810 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeGlobalVertexer);
811 pBlock!=NULL; pBlock=GetNextInputBlock()) {
812 fBenchmark.AddInput(pBlock->fSize);
813 AliHLTGlobalVertexerComponent::FillESD( pESD, reinterpret_cast<AliHLTGlobalVertexerComponent::AliHLTGlobalVertexerData* >(pBlock->fPtr) );
816 // update with vertices and vertex-fitted tracks
817 // output of PrimaryVertexer and V0Finder components
819 TObject* pBase = (TObject*)GetFirstInputObject(kAliHLTDataTypeKFVertex | kAliHLTDataOriginOut);
821 AliKFVertex* kfVertex = dynamic_cast<AliKFVertex *>(pBase);
823 const AliHLTComponentBlockData* pP = GetFirstInputBlock(kAliHLTDataTypePrimaryFinder | kAliHLTDataOriginOut);
824 if (pP && pP->fSize && pP->fPtr) {
825 const AliHLTComponentBlockData* pV0 = GetFirstInputBlock(kAliHLTDataTypeV0Finder | kAliHLTDataOriginOut);
826 if (pV0 && pV0->fPtr && pInputESD && pInputESD->GetNumberOfV0s()>0) {
827 const int* v0s = static_cast<const int*>(pV0->fPtr);
828 HLTWarning("V0 array already filled from the input esd block, additional filling from V0 block of %d entries might cause inconsistent content", v0s[0]);
830 AliHLTVertexFinderBase::FillESD(pESD, kfVertex, pP->fPtr, pV0?pV0->fPtr:NULL);
832 HLTWarning("Problem with primary finder's data block");
834 HLTWarning("primary vertex block of wrong type, expecting AliKFVertex instead of %s", pBase->GetName());
837 // throw an error if there is a V0 data block which can not be handled without
838 // the AliKFVertex object
839 if (GetFirstInputBlock(kAliHLTDataTypeV0Finder | kAliHLTDataOriginOut)!=NULL) {
840 ALIHLTERRORGUARD(1, "missing AliKFVertex object ignoring V0 data block of type %s",
841 DataType2Text(kAliHLTDataTypeV0Finder|kAliHLTDataOriginOut).c_str());
845 // Fill DCA parameters for TPC tracks
846 // TODO 2010-07-12 this propagates also the TPC inner param to beamline
847 // sounds not very reasonable
848 // https://savannah.cern.ch/bugs/index.php?69873
849 for (int i=0; i<pESD->GetNumberOfTracks(); i++) {
850 if (!pESD->GetTrack(i) ||
851 !pESD->GetTrack(i)->GetTPCInnerParam() ) continue;
852 pESD->GetTrack(i)->RelateToVertexTPC(pESD->GetPrimaryVertexTracks(), fSolenoidBz, 1000 );
855 // loop over all tracks and set the TPC refit flag by updating with the
856 // original TPC inner parameter if not yet set
857 // TODO: replace this by a proper refit
858 // code is comented for the moment as it does not fully solve the problems with
860 // - would set the main parameters to the TPC inner wall again, or
861 // - changes the inner param if the parameters are propagated, so we loose the track
862 // reference point for the display
863 // with the current sequence we have the latter case as the DCA operations above
864 // change the TPC inner parameters
866 for (int i=0; i<pESD->GetNumberOfTracks(); i++) {
867 if (!pESD->GetTrack(i) ||
868 !pESD->GetTrack(i)->GetTPCInnerParam() ||
869 pESD->GetTrack(i)->IsOn(AliESDtrack::kTPCrefit)) continue;
870 AliESDtrack* tESD=pESD->GetTrack(i);
871 AliHLTGlobalBarrelTrack inner(*tESD->GetTPCInnerParam());
872 inner.SetLabel(tESD->GetLabel());
873 tESD->UpdateTrackParams(&inner, AliESDtrack::kTPCrefit);
877 // 4. convert the HLT TRD tracks to ESD tracks
878 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack | kAliHLTDataOriginTRD);
879 pBlock!=NULL; pBlock=GetNextInputBlock()) {
880 fBenchmark.AddInput(pBlock->fSize);
881 vector<AliHLTGlobalBarrelTrack> tracks;
882 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
883 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
884 element!=tracks.end(); element++) {
886 Double_t TRDpid[AliPID::kSPECIES], eProb(0.2), restProb((1-eProb)/(AliPID::kSPECIES-1)); //eprob(element->GetTRDpid...);
887 for(Int_t i=0; i<AliPID::kSPECIES; i++){
889 case AliPID::kElectron: TRDpid[AliPID::kElectron]=eProb; break;
890 default: TRDpid[i]=restProb; break;
895 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTRDout);
896 iotrack.SetStatus(AliESDtrack::kTRDin);
897 iotrack.SetTRDpid(TRDpid);
899 pESD->AddTrack(&iotrack);
900 if (fVerbosity>0) element->Print();
902 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
904 } else if (iResult<0) {
905 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
906 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
909 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeCaloCluster | kAliHLTDataOriginAny); pBlock!=NULL; pBlock=GetNextInputBlock())
911 fBenchmark.AddInput(pBlock->fSize);
912 AliHLTCaloClusterHeaderStruct *caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
914 HLTDebug("%d HLT clusters from spec: 0x%X", caloClusterHeaderPtr->fNClusters, pBlock->fSpecification);
916 //AliHLTCaloClusterReader reader;
917 //reader.SetMemory(caloClusterHeaderPtr);
919 AliHLTESDCaloClusterMaker clusterMaker;
921 int nClusters = clusterMaker.FillESD(pESD, caloClusterHeaderPtr);
923 HLTInfo("converted %d cluster(s) to AliESDCaloCluster and added to ESD", nClusters);
927 // 5) Add Trigger Detectors
930 // FIXME: the size of all input blocks can be added in one loop
931 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeESDContent|kAliHLTDataOriginVZERO);
932 pBlock!=NULL; pBlock=GetNextInputBlock()) {
933 fBenchmark.AddInput(pBlock->fSize);
936 for ( const TObject *pObject = GetFirstInputObject(kAliHLTDataTypeESDContent|kAliHLTDataOriginVZERO);
937 pObject != NULL; pObject = GetNextInputObject() ) {
938 AliESDVZERO *esdVZERO = dynamic_cast<AliESDVZERO*>(const_cast<TObject*>( pObject ) );
940 pESD->SetVZEROData( esdVZERO );
943 ALIHLTERRORGUARD(1, "input object of data type %s is not of class AliESDVZERO",
944 DataType2Text(kAliHLTDataTypeESDContent|kAliHLTDataOriginVZERO).c_str());
948 // FIXME: the size of all input blocks can be added in one loop
949 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC);
950 pBlock!=NULL; pBlock=GetNextInputBlock()) {
951 fBenchmark.AddInput(pBlock->fSize);
953 for ( const TObject *pObject = GetFirstInputObject(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC);
954 pObject != NULL; pObject = GetNextInputObject() ) {
955 AliESDZDC *esdZDC = dynamic_cast<AliESDZDC*>(const_cast<TObject*>( pObject ) );
957 #ifndef HAVE_NOT_ALIZDCRECONSTRUCTOR_r43770
958 pESD->SetZDCData( esdZDC );
960 ALIHLTERRORGUARD(1, "Processing of ZDC data requires AliRoot r43770m skipping data block of type %s",
961 DataType2Text(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC).c_str());
965 ALIHLTERRORGUARD(1, "input object of data type %s is not of class AliESDZDC",
966 DataType2Text(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC).c_str());
970 // Add tracks and clusters from MUON.
971 for( const AliHLTComponentBlockData *i= GetFirstInputBlock(kAliHLTAnyDataType | kAliHLTDataOriginMUON); i!=NULL; i=GetNextInputBlock() ){
972 fBenchmark.AddInput(i->fSize);
975 for (const TObject* obj = GetFirstInputObject(kAliHLTAnyDataType | kAliHLTDataOriginMUON);
977 obj = GetNextInputObject()
980 const TClonesArray* tracklist = NULL;
981 const TClonesArray* clusterlist = NULL;
982 if (obj->IsA() == AliESDEvent::Class())
984 const AliESDEvent* event = static_cast<const AliESDEvent*>(obj);
985 HLTDebug("Received a MUON ESD with specification: 0x%X", GetSpecification(obj));
986 if (event->GetList() == NULL) continue;
987 tracklist = dynamic_cast<const TClonesArray*>(event->GetList()->FindObject("MuonTracks"));
988 if (tracklist == NULL) continue;
989 clusterlist = dynamic_cast<const TClonesArray*>(event->GetList()->FindObject("MuonClusters"));
990 if (clusterlist == NULL) continue;
992 else if (obj->IsA() == TClonesArray::Class())
994 if (!strcmp(obj->GetName(), "MuonTracks")) {
995 tracklist = static_cast<const TClonesArray*>(obj);
996 HLTDebug("Received a MUON TClonesArray of tracks with specification: 0x%X", GetSpecification(obj));
998 clusterlist = static_cast<const TClonesArray*>(obj);
999 HLTDebug("Received a MUON TClonesArray of clusters with specification: 0x%X", GetSpecification(obj));
1004 // Cannot handle this object type.
1009 HLTDebug("Received %d MUON tracks.", tracklist->GetEntriesFast());
1010 if (tracklist->GetEntriesFast() > 0)
1012 const AliESDMuonTrack* track = dynamic_cast<const AliESDMuonTrack*>(tracklist->UncheckedAt(0));
1015 HLTError(Form("%s from MUON does not contain AliESDMuonTrack objects.", obj->ClassName()));
1019 for (Int_t i = 0; i < tracklist->GetEntriesFast(); ++i)
1021 AliESDMuonTrack* track = pESD->NewMuonTrack();
1022 *track = *(static_cast<const AliESDMuonTrack*>(tracklist->UncheckedAt(i)));
1027 HLTDebug("Received %d MUON clusters.", clusterlist->GetEntriesFast());
1028 if (clusterlist->GetEntriesFast() > 0)
1030 const AliESDMuonCluster* cluster = dynamic_cast<const AliESDMuonCluster*>(clusterlist->UncheckedAt(0));
1031 if (cluster == NULL)
1033 HLTError(Form("%s from MUON does not contain AliESDMuonCluster objects.", obj->ClassName()));
1037 for (Int_t i = 0; i < clusterlist->GetEntriesFast(); ++i)
1039 AliESDMuonCluster* cluster = pESD->NewMuonCluster();
1040 *cluster = *(static_cast<const AliESDMuonCluster*>(clusterlist->UncheckedAt(i)));
1045 if( fMakeFriends ){ // create friend track
1046 pESD->SetESDfriend( esdFriend );
1051 if (iAddedDataBlocks>0 && pTree) {
1058 if (iResult>=0) iResult=iAddedDataBlocks;
1065 void AliHLTGlobalEsdConverterComponent::FillBenchmarkHistos(Double_t *statistics, TString *names){
1068 // cout<<"Now writing benchmarks to " << fBenchmarkHistosFilename <<endl<<endl;
1070 TFile *f = TFile::Open(fBenchmarkHistosFilename,"UPDATE");
1071 THnSparseD *s = (THnSparseD*)f->Get("benchmarkInformation");
1072 TNamed *t = (TNamed*)f->Get("time");
1075 HLTWarning( "Benchmark Histograms not available!" );
1078 s->Fill(statistics);
1083 histosList.SaveAs(fBenchmarkHistosFilename);