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()
76 , fSolenoidBz(-5.00668)
78 , fBenchmark("EsdConverter")
80 // see header file for class documentation
82 // refer to README to build package
84 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
85 for( int i=0; i<fkNPartition; i++ ){
86 fPartitionClusters[i] = 0;
87 fNPartitionClusters[i] = 0;
91 AliHLTGlobalEsdConverterComponent::~AliHLTGlobalEsdConverterComponent()
93 // see header file for class documentation
96 for( int i=0; i<fkNPartition; i++ ){
97 delete[] fPartitionClusters[i];
101 int AliHLTGlobalEsdConverterComponent::Configure(const char* arguments)
103 // see header file for class documentation
105 if (!arguments) return iResult;
107 TString allArgs=arguments;
111 TObjArray* pTokens=allArgs.Tokenize(" ");
113 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
114 argument=((TObjString*)pTokens->At(i))->String();
115 if (argument.IsNull()) continue;
117 if (argument.CompareTo("-solenoidBz")==0) {
118 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
119 HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
122 HLTError("unknown argument %s", argument.Data());
130 HLTError("missing parameter for argument %s", argument.Data());
137 int AliHLTGlobalEsdConverterComponent::Reconfigure(const char* cdbEntry, const char* chainId)
139 // see header file for class documentation
141 const char* path=NULL;
142 const char* defaultNotify="";
145 defaultNotify=" (default)";
148 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
149 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
151 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
153 HLTInfo("received configuration object string: \'%s\'", pString->String().Data());
154 iResult=Configure(pString->String().Data());
156 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
159 HLTError("can not fetch object \"%s\" from CDB", path);
166 void AliHLTGlobalEsdConverterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
168 // see header file for class documentation
169 list.push_back(kAliHLTDataTypeTrack);
170 list.push_back(kAliHLTDataTypeTrackMC);
171 list.push_back(kAliHLTDataTypeCaloCluster);
172 list.push_back(kAliHLTDataTypedEdx );
173 list.push_back(kAliHLTDataTypeESDVertex );
174 list.push_back(kAliHLTDataTypeESDObject);
175 list.push_back(kAliHLTDataTypeTObject);
176 list.push_back(kAliHLTDataTypeGlobalVertexer);
177 list.push_back(kAliHLTDataTypeV0Finder); // array of track ids for V0s
178 list.push_back(kAliHLTDataTypeKFVertex); // KFVertex object from vertexer
179 list.push_back(kAliHLTDataTypePrimaryFinder); // array of track ids for prim vertex
180 list.push_back(kAliHLTDataTypeESDContent);
181 list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
184 AliHLTComponentDataType AliHLTGlobalEsdConverterComponent::GetOutputDataType()
186 // see header file for class documentation
187 return kAliHLTMultipleDataType;
190 int AliHLTGlobalEsdConverterComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList){
191 // see header file for class documentation
194 tgtList.push_back( kAliHLTDataTypeESDObject|kAliHLTDataOriginOut );
195 tgtList.push_back( kAliHLTDataTypeESDfriendObject|kAliHLTDataOriginOut );
196 return tgtList.size();
199 void AliHLTGlobalEsdConverterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
201 // see header file for class documentation
203 inputMultiplier=10.0;
206 int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
208 // see header file for class documentation
213 // default list of skiped ESD objects
224 // "AliMultiplicity,"
227 // "SPDPileupVertices,"
228 // "TrkPileupVertices,"
231 "AliRawDataErrorLogs,"
234 iResult=Reconfigure(NULL, NULL);
235 TString allArgs = "";
236 for ( int i = 0; i < argc; i++ ) {
237 if ( !allArgs.IsNull() ) allArgs += " ";
241 TObjArray* pTokens=allArgs.Tokenize(" ");
243 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
244 argument=((TObjString*)pTokens->At(i))->String();
245 if (argument.IsNull()) continue;
248 if (argument.CompareTo("-notree")==0) {
252 } else if (argument.CompareTo("-tree")==0) {
254 } else if (argument.CompareTo("-solenoidBz")==0) {
255 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
256 HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->String().Data());
257 HLTWarning("argument '-solenoidBz' is deprecated, solenoid field initiaized from CDB settings");
259 } else if (argument.Contains("-skipobject=")) {
260 argument.ReplaceAll("-skipobject=", "");
261 skipObjects=argument;
263 HLTError("unknown argument %s", argument.Data());
270 HLTError("missing parameter for argument %s", argument.Data());
282 fESD = new AliESDEvent;
284 fESD->CreateStdContent();
286 // remove some of the objects which are not needed
287 if (fESD->GetList() && !skipObjects.IsNull()) {
288 pTokens=skipObjects.Tokenize(",");
292 TObject* pObject=NULL;
293 while ((pObject=next())!=NULL) {
294 id=((TObjString*)pObject)->String().Data();
295 TObject* pObj=fESD->GetList()->FindObject(id);
297 HLTDebug("removing object %s", id);
298 fESD->GetList()->Remove(pObj);
301 HLTWarning("failed to remove object '%s' from ESD", id);
304 fESD->GetStdContent();
315 if( iResult>=0 && fMakeFriends ){
316 fESDfriend = new AliESDfriend();
319 fBenchmark.SetTimer(0,"total");
324 int AliHLTGlobalEsdConverterComponent::DoDeinit()
326 // see header file for class documentation
334 int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& evtData,
335 AliHLTComponentTriggerData& trigData)
337 // see header file for class documentation
341 AliSysInfo::AddStamp("DoEvent.Start", evtData.fStructSize);
343 bool benchmark = true;
345 if (!fESD) return -ENODEV;
347 if (!IsDataEvent()) return iResult;
348 fBenchmark.StartNewEvent();
351 for(Int_t i=0; i<fkNPartition; i++){
352 delete[] fPartitionClusters[i];
353 fPartitionClusters[i] = 0;
354 fNPartitionClusters[i] = 0;
357 AliESDEvent* pESD = fESD;
360 pESD->SetMagneticField(fSolenoidBz);
361 pESD->SetRunNumber(GetRunNo());
362 pESD->SetPeriodNumber(GetPeriodNumber());
363 pESD->SetOrbitNumber(GetOrbitNumber());
364 pESD->SetBunchCrossNumber(GetBunchCrossNumber());
365 pESD->SetTimeStamp(GetTimeStamp());
367 const AliHLTCTPData* pCTPData=CTPData();
369 AliHLTTriggerMask_t mask=pCTPData->ActiveTriggers(trigData);
370 for (int index=0; index<gkNCTPTriggerClasses; index++) {
371 if ((mask&(AliHLTTriggerMask_t(0x1)<<index)) == 0) continue;
372 pESD->SetTriggerClass(pCTPData->Name(index), index);
375 AliHLTTriggerMask_t mask50;
376 mask50.set(); // set all bits
377 mask50 >>= 50; // shift 50 right
378 pESD->SetTriggerMask((mask&mask50).to_ulong());
380 pESD->SetTriggerMaskNext50((mask>>50).to_ulong());
385 pTree = new TTree("esdTree", "Tree with HLT ESD objects");
388 pTree->SetDirectory(0);
391 if( fESDfriend ) fESDfriend->Reset();
393 if ((iResult=ProcessBlocks(pTree, pESD, fESDfriend))>=0) {
394 // TODO: set the specification correctly
396 // the esd structure is written to the user info and is
397 // needed in te ReadFromTree method to read all objects correctly
398 pTree->GetUserInfo()->Add(pESD);
399 pESD->WriteToTree(pTree);
400 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginOut, 0);
402 cout<<"Write ESD block: n tracks "<<pESD->GetNumberOfTracks()<<endl;
403 iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginOut, 0);
405 fBenchmark.AddOutput(GetLastObjectSize());
406 if( iResult>=0 && fMakeFriends ){
407 cout<<"Write ESD friend block: n friend tracks "<<fESDfriend->GetNumberOfTracks()<<endl;
408 iResult=PushBack(fESDfriend, kAliHLTDataTypeESDfriendObject|kAliHLTDataOriginOut, 0);
409 fBenchmark.AddOutput(GetLastObjectSize());
413 // clear user info list to prevent objects from being deleted
414 pTree->GetUserInfo()->Clear();
419 HLTWarning( fBenchmark.GetStatistics() );
428 Int_t nV0s = pESD->GetNumberOfV0s();
429 Int_t nTracks = pESD->GetNumberOfTracks();
432 Double_t statistics[10];
434 fBenchmark.GetStatisticsData(statistics, names);
435 // statistics[5] = nTracks;
436 // statistics[6] = time;
437 // statistics[7] = nV0s;
439 // FillBenchmarkHistos( statistics, names);
442 AliSysInfo::AddStamp("DoEvent.Stop", (int)(statistics[1]), (int)(statistics[2]),pESD->GetNumberOfV0s(),pESD->GetNumberOfTracks() );
445 for(Int_t i=0; i<fkNPartition; i++){
446 delete[] fPartitionClusters[i];
447 fPartitionClusters[i] = 0;
448 fNPartitionClusters[i] = 0;
451 if( fESDfriend ) fESDfriend->Reset();
452 if( fESD ) fESD->Reset();
457 int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD, AliESDfriend *pESDfriend )
459 // see header file for class documentation
462 int iAddedDataBlocks=0;
464 // check if there is an ESD block in the input and copy its content first to the
466 const TObject* pEsdObj = GetFirstInputObject(kAliHLTDataTypeESDObject, "AliESDEvent");
467 AliESDEvent* pInputESD=NULL;
468 if (pEsdObj) pInputESD=dynamic_cast<AliESDEvent*>(const_cast<TObject*>(pEsdObj));
470 pInputESD->GetStdContent();
473 if (GetNextInputObject()!=NULL) {
474 HLTWarning("handling of multiple ESD input objects not implemented, skipping input");
478 // tracks are based on the TPC tracks, and only updated from the ITS information
480 // 1) extract MC information for TPC and ITS from specific data blocks and store in
481 // intermediate vector arrays
482 // 2) extract TPC tracks, update with MC labels if available, the track parameters
483 // are estimated at the first cluster position
484 // 2.1) propagate to last cluster position and update kTPCout, sets also outer param (fOp)
485 // 2.2) update kTPCin, sets also inner param (fIp) and TPC inner param (fTPCInner)
486 // 2.3) update kTPCrefit using the same parameters at the first cluster position
487 // HLT has strictly spoking no refit, but we want the flag to be set
488 // can be changed to be done after all the individual barrel detector parameters
489 // have been updated by looping over the tracks again
490 // 3) extract ITS tracks, the tracks are actually TPC tracks updated from the ITS
491 // tracking information
492 // 3.1) TODO 2010-07-12: handle ITS standalone tracks by updating kITSout before kITSin
493 // 3.2) update with kITSin
494 // TODO 2010-07-12 find out if the kITSrefit has to be set as well
495 // 4) extract TRD tracks and add to ESD
496 // TODO 2010-07-12 at the moment there is no matching or merging of TPC and TRD tracks
497 // 5) Add Trigger Detectors
501 // ---------- Access to clusters --------------------//
503 for(Int_t i=0; i<fkNPartition; i++){
504 delete[] fPartitionClusters[i];
505 fPartitionClusters[i] = 0;
506 fNPartitionClusters[i] = 0;
511 int nInputClusters = 0;
513 for(const AliHLTComponentBlockData *iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkClustersDataType); iter != NULL; iter = GetNextInputBlock()){
515 if(iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType) continue;
516 Int_t slice = AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
517 Int_t partition = AliHLTTPCDefinitions::GetMinPatchNr(iter->fSpecification);
518 Int_t slicepartition = slice*6+partition;
519 if(slicepartition<0 || slicepartition > fkNPartition){
520 HLTWarning("Wrong header of TPC cluster data, slice %d, partition %d", slice, partition );
524 AliHLTTPCClusterData *inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
525 nInputClusters += inPtrSP->fSpacePointCnt;
527 delete[] fPartitionClusters[slicepartition];
528 fPartitionClusters[slicepartition] = new AliTPCclusterMI[inPtrSP->fSpacePointCnt];
529 fNPartitionClusters[slicepartition] = inPtrSP->fSpacePointCnt;
531 // create offline clusters out of the HLT clusters
533 for ( unsigned int i = 0; i < inPtrSP->fSpacePointCnt; i++ ) {
534 AliHLTTPCSpacePointData *chlt = &( inPtrSP->fSpacePoints[i] );
535 AliTPCclusterMI *c = fPartitionClusters[slicepartition]+i;
539 c->SetSigmaY2(chlt->fSigmaY2);
541 c->SetSigmaZ2(chlt->fSigmaZ2);
542 c->SetQ( chlt->fCharge );
543 c->SetMax( chlt->fQMax );
545 Float_t padtime[3] = {0,chlt->fY,chlt->fZ};
546 AliHLTTPCTransform::Slice2Sector(slice,chlt->fPadRow, sector, row);
547 AliHLTTPCTransform::Local2Raw( padtime, sector, row);
548 c->SetDetector( sector );
550 c->SetPad( (Int_t) padtime[1] );
551 c->SetTimeBin( (Int_t) padtime[2] );
553 } // end of loop over blocks of clusters
556 // 1) first read MC information (if present)
557 std::map<int,int> mcLabelsTPC;
558 std::map<int,int> mcLabelsITS;
560 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC);
561 pBlock!=NULL; pBlock=GetNextInputBlock()) {
563 fBenchmark.AddInput(pBlock->fSize);
565 AliHLTTrackMCData* dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr );
566 if (sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize) {
567 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
568 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
569 mcLabelsTPC[lab.fTrackID] = lab.fMCLabel;
572 HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information",
573 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification,
574 dataPtr->fCount, pBlock->fSize);
578 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginITS);
579 pBlock!=NULL; pBlock=GetNextInputBlock()) {
581 fBenchmark.AddInput(pBlock->fSize);
583 AliHLTTrackMCData* dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr );
584 if (sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize) {
585 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
586 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
587 mcLabelsITS[lab.fTrackID] = lab.fMCLabel;
590 HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information",
591 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification,
592 dataPtr->fCount, pBlock->fSize);
597 // read dEdx information (if present)
598 // TODO 2010-07-12 this needs to be verified
600 AliHLTFloat32_t *dEdxTPC = 0;
602 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypedEdx|kAliHLTDataOriginTPC);
603 pBlock!=NULL; pBlock=NULL/*GetNextInputBlock() there is only one block*/) {
604 fBenchmark.AddInput(pBlock->fSize);
605 dEdxTPC = reinterpret_cast<AliHLTFloat32_t*>( pBlock->fPtr );
606 ndEdxTPC = pBlock->fSize / (3*sizeof(AliHLTFloat32_t));
609 // 2) convert the TPC tracks to ESD tracks
610 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
611 pBlock!=NULL; pBlock=GetNextInputBlock()) {
612 if (pInputESD && pInputESD->GetNumberOfTracks()>0) {
613 HLTWarning("Tracks array already filled from the input esd block, additional filling from TPC tracks block might cause inconsistent content");
615 fBenchmark.AddInput(pBlock->fSize);
616 vector<AliHLTGlobalBarrelTrack> tracks;
617 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>=0) {
618 cout<<"\n\n ESD converter: input "<<tracks.size()<<" TPC tracks"<<endl;
619 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
620 element!=tracks.end(); element++) {
621 Float_t points[4] = {
622 static_cast<Float_t>(element->GetX()),
623 static_cast<Float_t>(element->GetY()),
624 static_cast<Float_t>(element->GetLastPointX()),
625 static_cast<Float_t>(element->GetLastPointY())
629 if( mcLabelsTPC.find(element->TrackID())!=mcLabelsTPC.end() )
630 mcLabel = mcLabelsTPC[element->TrackID()];
631 element->SetLabel( mcLabel );
635 // for the moment, the number of clusters are not set when processing the
636 // kTPCin update, only at kTPCout
637 // there ar emainly three parameters updated for kTPCout
638 // number of clusters
641 // The first one can be updated already at that stage here, while the two others
642 // eventually require to update from the ITS tracks before. The exact scheme
643 // needs to be checked
644 iotrack.SetID( element->TrackID() );
647 // TODO 2010-07-12 disabled for the moment because of bug
648 // https://savannah.cern.ch/bugs/index.php?69875
649 // the propagation does not work, there is an offset in z
650 // propagate to last cluster and update parameters with flag kTPCout
651 // Note: updating with flag kITSout further down will overwrite the outer
652 // parameter again so this can be done only for ITS standalone tracks, meaning
653 // tracks in the ITS not associated with any TPC track
654 // HLT does not provide such standalone tracking
656 AliHLTGlobalBarrelTrack outPar(*element);
657 //outPar.AliExternalTrackParam::PropagateTo( element->GetLastPointX(), fSolenoidBz );
658 const Int_t N=10; // number of steps.
659 const Float_t xRange = element->GetLastPointX() - element->GetX();
660 const Float_t xStep = xRange / N ;
661 for(int i = 1; i <= N; ++i) {
662 if(!outPar.AliExternalTrackParam::PropagateTo(element->GetX() + xStep * i, fSolenoidBz)) break;
664 outPar.SetLabel(element->GetLabel());
665 iotrack.UpdateTrackParams(&outPar,AliESDtrack::kTPCout);
667 // 2.2 TPC tracking estimates parameters at first cluster
668 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCin);
670 // 2.3 use the same parameters also for kTPCrefit, there is no proper refit in HLT
671 // maybe this can be done later, however also the inner parameter is changed which
672 // is used as a reference point in the display. That point should be at the first
674 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCrefit);
675 iotrack.SetTPCPoints(points);
676 if( element->TrackID()<ndEdxTPC ){
677 AliHLTFloat32_t *val = &(dEdxTPC[3*element->TrackID()]);
678 iotrack.SetTPCsignal( val[0], val[1], (UChar_t) val[2] );
680 //s.Set( element->GetX(), element->GetAlpha(),
681 //element->GetParameter(), element->GetCovariance() );
682 //s.SetdEdx( val[0] );
684 //iotrack.SetTPCpid(s.TPCrPIDs() );
686 if( dEdxTPC ) HLTWarning("Wrong number of dEdx TPC labels");
688 iotrack.SetLabel(mcLabel);
689 pESD->AddTrack(&iotrack);
690 if (fVerbosity>0) element->Print();
692 if( pESDfriend ){ // create friend track
694 AliHLTGlobalBarrelTrack gb(*element);
696 tTPC.Set( gb.GetX(), gb.GetAlpha(), gb.GetParameter(), gb.GetCovariance() );
697 tTPC.SetLabel(mcLabel);
700 UInt_t nClusters = element->GetNumberOfPoints();
701 const UInt_t*clusterIDs = element->GetPoints();
703 tTPC.SetNumberOfClusters(nClusters);
705 for(UInt_t ic=0; ic<nClusters; ic++){
707 UInt_t id = clusterIDs[ic];
708 int iSlice = AliHLTTPCSpacePointData::GetSlice(id);
709 int iPartition = AliHLTTPCSpacePointData::GetPatch(id);
710 int iCluster = AliHLTTPCSpacePointData::GetNumber(id);
712 if(iSlice<0 || iSlice>36 || iPartition<0 || iPartition>5){
713 HLTError("Corrupted TPC cluster Id: slice %d, partition %d, cluster %d", iSlice, iPartition, iCluster);
717 AliTPCclusterMI *patchClusters = fPartitionClusters[iSlice*6 + iPartition];
719 HLTError("Clusters are missed for slice %d, partition %d", iSlice, iPartition );
723 if(iCluster >= fNPartitionClusters[iSlice*6 + iPartition]){
724 HLTError("TPC slice %d, partition %d: ClusterID==%d >= N Cluaters==%d ", iSlice, iPartition,iCluster, fNPartitionClusters[iSlice*6 + iPartition] );
728 AliTPCclusterMI *c = &(patchClusters[iCluster]);
729 int sec = c->GetDetector();
730 int row = c->GetRow();
731 if(sec >= 36) row = row + AliHLTTPCTransform::GetNRowLow();
733 tTPC.SetClusterPointer(row, c);
735 AliTPCTrackerPoint &point = *( tTPC.GetTrackPoint( row ) );
736 //tTPC.Propagate( TMath::DegToRad()*(sec%18*20.+10.), c->GetX(), fSolenoidBz );
737 Double_t angle2 = tTPC.GetSnp()*tTPC.GetSnp();
738 angle2 = (angle2<1) ?TMath::Sqrt(angle2/(1-angle2)) :10.;
739 point.SetAngleY( angle2 );
740 point.SetAngleZ( tTPC.GetTgl() );
741 } // end of associated cluster loop
745 AliTPCseed *seed = &(tTPC);
746 //fSeedArray->AddAt( seed, TMath::Abs(seed->GetLabel()) );
747 //fdEdx->Fill( seed->P()*seed->Charge(), seed->CookdEdx(0.02, 0.6) );
749 AliESDfriendTrack friendTrack;
750 friendTrack.AddCalibObject(&tTPC);
751 pESDfriend->AddTrack(&friendTrack);
755 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
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);
764 // Get ITS SPD vertex
765 for( const AliHLTComponentBlockData *i= GetFirstInputBlock(kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS); i!=NULL; i=GetNextInputBlock() ){
766 fBenchmark.AddInput(i->fSize);
769 for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS); iter != NULL; iter = GetNextInputObject() ) {
770 AliESDVertex *vtx = dynamic_cast<AliESDVertex*>(const_cast<TObject*>( iter ) );
771 pESD->SetPrimaryVertexSPD( vtx );
774 // 3.1. now update ESD tracks with the ITSOut info
775 // updating track parameters with flag kITSout will overwrite parameter set above with flag kTPCout
776 // TODO 2010-07-12 there are some issues with this updating sequence, for the moment update with
777 // flag kITSout is disabled, would require
778 // a) to update kTPCout after kITSout
779 // b) update only for ITS standalone tracks. The HLT ITS tracker does not provide standalone
780 // tracking, every track is related to a TPC track
781 // Furthermore there seems to be a bug as the data blocks describe track parameters around the
782 // vertex, not at the outer ITS
783 // bug https://savannah.cern.ch/bugs/index.php?69872
784 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITSOut);
785 pBlock!=NULL; pBlock=GetNextInputBlock()) {
786 fBenchmark.AddInput(pBlock->fSize);
787 vector<AliHLTGlobalBarrelTrack> tracks;
788 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
789 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
790 element!=tracks.end(); element++) {
791 int tpcID=element->TrackID();
792 // the ITS tracker assigns the TPC track used as seed for a certain track to
794 if( tpcID<0 || tpcID>=pESD->GetNumberOfTracks()) continue;
795 AliESDtrack *tESD = pESD->GetTrack( tpcID );
796 element->SetLabel(tESD->GetLabel());
797 // 2010-07-12 disabled, see above, bugfix https://savannah.cern.ch/bugs/index.php?69872
798 //if( tESD ) tESD->UpdateTrackParams( &(*element), AliESDtrack::kITSout );
803 // 3.2. now update ESD tracks with the ITS info
804 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITS);
805 pBlock!=NULL; pBlock=GetNextInputBlock()) {
806 fBenchmark.AddInput(pBlock->fSize);
807 vector<AliHLTGlobalBarrelTrack> tracks;
808 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
809 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
810 element!=tracks.end(); element++) {
811 int tpcID=element->TrackID();
812 // the ITS tracker assigns the TPC track used as seed for a certain track to
814 if( tpcID<0 || tpcID>=pESD->GetNumberOfTracks()) continue;
816 if( mcLabelsITS.find(element->TrackID())!=mcLabelsITS.end() )
817 mcLabel = mcLabelsITS[element->TrackID()];
818 AliESDtrack *tESD = pESD->GetTrack( tpcID );
820 // the labels for the TPC and ITS tracking params can be different, e.g.
821 // there can be a decay. The ITS label should then be the better one, the
822 // TPC label is saved in a member of AliESDtrack
824 // upadte only if the ITS label is available, otherwise keep TPC label
825 element->SetLabel( mcLabel );
827 // bugfix https://savannah.cern.ch/bugs/?69713
828 element->SetLabel( tESD->GetLabel() );
830 tESD->UpdateTrackParams( &(*element), AliESDtrack::kITSin );
832 // TODO: add a proper refit
833 //tESD->UpdateTrackParams( &(*element), AliESDtrack::kTPCrefit );
838 // update with vertices and vertex-fitted tracks
839 // output of the GlobalVertexerComponent
840 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeGlobalVertexer);
841 pBlock!=NULL; pBlock=GetNextInputBlock()) {
842 fBenchmark.AddInput(pBlock->fSize);
843 AliHLTGlobalVertexerComponent::FillESD( pESD, reinterpret_cast<AliHLTGlobalVertexerComponent::AliHLTGlobalVertexerData* >(pBlock->fPtr) );
846 // update with vertices and vertex-fitted tracks
847 // output of PrimaryVertexer and V0Finder components
849 TObject* pBase = (TObject*)GetFirstInputObject(kAliHLTDataTypeKFVertex | kAliHLTDataOriginOut);
851 AliKFVertex* kfVertex = dynamic_cast<AliKFVertex *>(pBase);
853 const AliHLTComponentBlockData* pP = GetFirstInputBlock(kAliHLTDataTypePrimaryFinder | kAliHLTDataOriginOut);
854 if (pP && pP->fSize && pP->fPtr) {
855 const AliHLTComponentBlockData* pV0 = GetFirstInputBlock(kAliHLTDataTypeV0Finder | kAliHLTDataOriginOut);
856 if (pV0 && pV0->fPtr && pInputESD && pInputESD->GetNumberOfV0s()>0) {
857 const int* v0s = static_cast<const int*>(pV0->fPtr);
858 HLTWarning("V0 array already filled from the input esd block, additional filling from V0 block of %d entries might cause inconsistent content", v0s[0]);
860 AliHLTVertexFinderBase::FillESD(pESD, kfVertex, pP->fPtr, pV0?pV0->fPtr:NULL);
862 HLTWarning("Problem with primary finder's data block");
864 HLTWarning("primary vertex block of wrong type, expecting AliKFVertex instead of %s", pBase->GetName());
867 // throw an error if there is a V0 data block which can not be handled without
868 // the AliKFVertex object
869 if (GetFirstInputBlock(kAliHLTDataTypeV0Finder | kAliHLTDataOriginOut)!=NULL) {
870 ALIHLTERRORGUARD(1, "missing AliKFVertex object ignoring V0 data block of type %s",
871 DataType2Text(kAliHLTDataTypeV0Finder|kAliHLTDataOriginOut).c_str());
875 // Fill DCA parameters for TPC tracks
876 // TODO 2010-07-12 this propagates also the TPC inner param to beamline
877 // sounds not very reasonable
878 // https://savannah.cern.ch/bugs/index.php?69873
879 for (int i=0; i<pESD->GetNumberOfTracks(); i++) {
880 if (!pESD->GetTrack(i) ||
881 !pESD->GetTrack(i)->GetTPCInnerParam() ) continue;
882 pESD->GetTrack(i)->RelateToVertexTPC(pESD->GetPrimaryVertexTracks(), fSolenoidBz, 1000 );
885 // loop over all tracks and set the TPC refit flag by updating with the
886 // original TPC inner parameter if not yet set
887 // TODO: replace this by a proper refit
888 // code is comented for the moment as it does not fully solve the problems with
890 // - would set the main parameters to the TPC inner wall again, or
891 // - changes the inner param if the parameters are propagated, so we loose the track
892 // reference point for the display
893 // with the current sequence we have the latter case as the DCA operations above
894 // change the TPC inner parameters
896 for (int i=0; i<pESD->GetNumberOfTracks(); i++) {
897 if (!pESD->GetTrack(i) ||
898 !pESD->GetTrack(i)->GetTPCInnerParam() ||
899 pESD->GetTrack(i)->IsOn(AliESDtrack::kTPCrefit)) continue;
900 AliESDtrack* tESD=pESD->GetTrack(i);
901 AliHLTGlobalBarrelTrack inner(*tESD->GetTPCInnerParam());
902 inner.SetLabel(tESD->GetLabel());
903 tESD->UpdateTrackParams(&inner, AliESDtrack::kTPCrefit);
907 // 4. convert the HLT TRD tracks to ESD tracks
908 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack | kAliHLTDataOriginTRD);
909 pBlock!=NULL; pBlock=GetNextInputBlock()) {
910 fBenchmark.AddInput(pBlock->fSize);
911 vector<AliHLTGlobalBarrelTrack> tracks;
912 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
913 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
914 element!=tracks.end(); element++) {
916 Double_t TRDpid[AliPID::kSPECIES], eProb(0.2), restProb((1-eProb)/(AliPID::kSPECIES-1)); //eprob(element->GetTRDpid...);
917 for(Int_t i=0; i<AliPID::kSPECIES; i++){
919 case AliPID::kElectron: TRDpid[AliPID::kElectron]=eProb; break;
920 default: TRDpid[i]=restProb; break;
925 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTRDout);
926 iotrack.SetStatus(AliESDtrack::kTRDin);
927 iotrack.SetTRDpid(TRDpid);
929 pESD->AddTrack(&iotrack);
930 if (fVerbosity>0) element->Print();
932 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
934 } else if (iResult<0) {
935 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
936 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
939 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeCaloCluster | kAliHLTDataOriginAny); pBlock!=NULL; pBlock=GetNextInputBlock())
941 fBenchmark.AddInput(pBlock->fSize);
942 AliHLTCaloClusterHeaderStruct *caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
944 HLTDebug("%d HLT clusters from spec: 0x%X", caloClusterHeaderPtr->fNClusters, pBlock->fSpecification);
946 //AliHLTCaloClusterReader reader;
947 //reader.SetMemory(caloClusterHeaderPtr);
949 AliHLTESDCaloClusterMaker clusterMaker;
951 int nClusters = clusterMaker.FillESD(pESD, caloClusterHeaderPtr);
953 HLTInfo("converted %d cluster(s) to AliESDCaloCluster and added to ESD", nClusters);
957 // 5) Add Trigger Detectors
960 // FIXME: the size of all input blocks can be added in one loop
961 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeESDContent|kAliHLTDataOriginVZERO);
962 pBlock!=NULL; pBlock=GetNextInputBlock()) {
963 fBenchmark.AddInput(pBlock->fSize);
966 for ( const TObject *pObject = GetFirstInputObject(kAliHLTDataTypeESDContent|kAliHLTDataOriginVZERO);
967 pObject != NULL; pObject = GetNextInputObject() ) {
968 AliESDVZERO *esdVZERO = dynamic_cast<AliESDVZERO*>(const_cast<TObject*>( pObject ) );
970 pESD->SetVZEROData( esdVZERO );
973 ALIHLTERRORGUARD(1, "input object of data type %s is not of class AliESDVZERO",
974 DataType2Text(kAliHLTDataTypeESDContent|kAliHLTDataOriginVZERO).c_str());
978 // FIXME: the size of all input blocks can be added in one loop
979 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC);
980 pBlock!=NULL; pBlock=GetNextInputBlock()) {
981 fBenchmark.AddInput(pBlock->fSize);
983 for ( const TObject *pObject = GetFirstInputObject(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC);
984 pObject != NULL; pObject = GetNextInputObject() ) {
985 AliESDZDC *esdZDC = dynamic_cast<AliESDZDC*>(const_cast<TObject*>( pObject ) );
987 #ifndef HAVE_NOT_ALIZDCRECONSTRUCTOR_r43770
988 pESD->SetZDCData( esdZDC );
990 ALIHLTERRORGUARD(1, "Processing of ZDC data requires AliRoot r43770m skipping data block of type %s",
991 DataType2Text(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC).c_str());
995 ALIHLTERRORGUARD(1, "input object of data type %s is not of class AliESDZDC",
996 DataType2Text(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC).c_str());
1000 // Add tracks and clusters from MUON.
1001 for( const AliHLTComponentBlockData *i= GetFirstInputBlock(kAliHLTAnyDataType | kAliHLTDataOriginMUON); i!=NULL; i=GetNextInputBlock() ){
1002 fBenchmark.AddInput(i->fSize);
1005 for (const TObject* obj = GetFirstInputObject(kAliHLTAnyDataType | kAliHLTDataOriginMUON);
1007 obj = GetNextInputObject()
1010 const TClonesArray* tracklist = NULL;
1011 const TClonesArray* clusterlist = NULL;
1012 if (obj->IsA() == AliESDEvent::Class())
1014 const AliESDEvent* event = static_cast<const AliESDEvent*>(obj);
1015 HLTDebug("Received a MUON ESD with specification: 0x%X", GetSpecification(obj));
1016 if (event->GetList() == NULL) continue;
1017 tracklist = dynamic_cast<const TClonesArray*>(event->GetList()->FindObject("MuonTracks"));
1018 if (tracklist == NULL) continue;
1019 clusterlist = dynamic_cast<const TClonesArray*>(event->GetList()->FindObject("MuonClusters"));
1020 if (clusterlist == NULL) continue;
1022 else if (obj->IsA() == TClonesArray::Class())
1024 if (!strcmp(obj->GetName(), "MuonTracks")) {
1025 tracklist = static_cast<const TClonesArray*>(obj);
1026 HLTDebug("Received a MUON TClonesArray of tracks with specification: 0x%X", GetSpecification(obj));
1028 clusterlist = static_cast<const TClonesArray*>(obj);
1029 HLTDebug("Received a MUON TClonesArray of clusters with specification: 0x%X", GetSpecification(obj));
1034 // Cannot handle this object type.
1039 HLTDebug("Received %d MUON tracks.", tracklist->GetEntriesFast());
1040 if (tracklist->GetEntriesFast() > 0)
1042 const AliESDMuonTrack* track = dynamic_cast<const AliESDMuonTrack*>(tracklist->UncheckedAt(0));
1045 HLTError(Form("%s from MUON does not contain AliESDMuonTrack objects.", obj->ClassName()));
1049 for (Int_t i = 0; i < tracklist->GetEntriesFast(); ++i)
1051 AliESDMuonTrack* track = pESD->NewMuonTrack();
1052 *track = *(static_cast<const AliESDMuonTrack*>(tracklist->UncheckedAt(i)));
1057 HLTDebug("Received %d MUON clusters.", clusterlist->GetEntriesFast());
1058 if (clusterlist->GetEntriesFast() > 0)
1060 const AliESDMuonCluster* cluster = dynamic_cast<const AliESDMuonCluster*>(clusterlist->UncheckedAt(0));
1061 if (cluster == NULL)
1063 HLTError(Form("%s from MUON does not contain AliESDMuonCluster objects.", obj->ClassName()));
1067 for (Int_t i = 0; i < clusterlist->GetEntriesFast(); ++i)
1069 AliESDMuonCluster* cluster = pESD->NewMuonCluster();
1070 *cluster = *(static_cast<const AliESDMuonCluster*>(clusterlist->UncheckedAt(i)));
1075 if( fMakeFriends && pESDfriend ){ // create friend track
1076 pESD->SetESDfriend( pESDfriend );
1077 // cout<<"\n\n ESD Friend: "<<pESDfriend->GetNumberOfTracks()<<endl;
1081 if (iAddedDataBlocks>0 && pTree) {
1085 if (iResult>=0) iResult=iAddedDataBlocks;
1092 void AliHLTGlobalEsdConverterComponent::FillBenchmarkHistos(Double_t *statistics, TString *names){
1095 // cout<<"Now writing benchmarks to " << fBenchmarkHistosFilename <<endl<<endl;
1097 TFile *f = TFile::Open(fBenchmarkHistosFilename,"UPDATE");
1098 THnSparseD *s = (THnSparseD*)f->Get("benchmarkInformation");
1099 TNamed *t = (TNamed*)f->Get("time");
1102 HLTWarning( "Benchmark Histograms not available!" );
1105 s->Fill(statistics);
1110 histosList.SaveAs(fBenchmarkHistosFilename);