From a1408c4b31238e34fdab316ca38e5012a8b9d0c6 Mon Sep 17 00:00:00 2001 From: richterm Date: Sat, 27 Jun 2009 06:08:21 +0000 Subject: [PATCH] first version of global ESD converter, not yet tested, needs implementation of unit test --- HLT/global/AliHLTGlobalBarrelTrack.cxx | 133 +++++++ HLT/global/AliHLTGlobalBarrelTrack.h | 79 +++++ .../AliHLTGlobalEsdConverterComponent.cxx | 335 ++++++++++++++++++ .../AliHLTGlobalEsdConverterComponent.h | 102 ++++++ HLT/libAliHLTGlobal.pkg | 2 + 5 files changed, 651 insertions(+) create mode 100644 HLT/global/AliHLTGlobalBarrelTrack.cxx create mode 100644 HLT/global/AliHLTGlobalBarrelTrack.h create mode 100644 HLT/global/AliHLTGlobalEsdConverterComponent.cxx create mode 100644 HLT/global/AliHLTGlobalEsdConverterComponent.h diff --git a/HLT/global/AliHLTGlobalBarrelTrack.cxx b/HLT/global/AliHLTGlobalBarrelTrack.cxx new file mode 100644 index 00000000000..324bb7797e7 --- /dev/null +++ b/HLT/global/AliHLTGlobalBarrelTrack.cxx @@ -0,0 +1,133 @@ +// $Id$ + +//************************************************************************** +//* This file is property of and copyright by the ALICE HLT Project * +//* ALICE Experiment at CERN, All rights reserved. * +//* * +//* Primary Authors: Matthias Richter * +//* for The ALICE HLT Project. * +//* * +//* Permission to use, copy, modify and distribute this software and its * +//* documentation strictly for non-commercial purposes is hereby granted * +//* without fee, provided that the above copyright notice appears in all * +//* copies and that both the copyright notice and this permission notice * +//* appear in the supporting documentation. The authors make no claims * +//* about the suitability of this software for any purpose. It is * +//* provided "as is" without express or implied warranty. * +//************************************************************************** + +/** @file AliHLTGlobalBarrelTrack.cxx + @author Matthias Richter + @date 2009-06-24 + @brief An AliKalmanTrack implementation for global HLT barrel tracks. +*/ + +// see header file for class documentation +// or +// refer to README to build package +// or +// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt + +#include +#include "AliHLTGlobalBarrelTrack.h" + +/** ROOT macro for the implementation of ROOT specific class methods */ +ClassImp(AliHLTGlobalBarrelTrack) + +AliHLTGlobalBarrelTrack::AliHLTGlobalBarrelTrack() +: AliKalmanTrack() + , fPoints() + , fLastX(0.0) + , fLastY(0.0) +{ + // see header file for class documentation + // or + // refer to README to build package + // or + // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt +} + +AliHLTGlobalBarrelTrack::AliHLTGlobalBarrelTrack(const AliHLTGlobalBarrelTrack& t) + : AliKalmanTrack(t) + , fPoints() + , fLastX(t.GetLastPointX()) + , fLastY(t.GetLastPointY()) +{ + // see header file for class documentation + fPoints.assign(t.fPoints.begin(), t.fPoints.end()); +} + +AliHLTGlobalBarrelTrack& AliHLTGlobalBarrelTrack::operator=(const AliHLTGlobalBarrelTrack& t) +{ + // see header file for class documentation + this->~AliHLTGlobalBarrelTrack(); + new (this) AliHLTGlobalBarrelTrack(t); + return *this; +} + +AliHLTGlobalBarrelTrack& AliHLTGlobalBarrelTrack::operator=(const AliHLTExternalTrackParam& p) +{ + // see header file for class documentation + this->~AliHLTGlobalBarrelTrack(); + new (this) AliHLTGlobalBarrelTrack; + Float_t param[5]={p.fY, p.fZ, p.fq1Pt, p.fSinPsi, p.fTgl}; + Set(p.fX, p.fAlpha, param, p.fC); + SetPoints(p.fPointIDs, p.fNPoints); + fLastX=p.fLastX; + fLastY=p.fLastY; + return *this; +} + +AliHLTGlobalBarrelTrack::~AliHLTGlobalBarrelTrack() +{ + // see header file for class documentation +} + +int AliHLTGlobalBarrelTrack::ConvertTrackDataArray(const AliHLTTracksData* pTracks, int sizeInByte, vector &tgtArray) +{ + // see header file for class documentation + int iResult=0; + tgtArray.clear(); + if (!pTracks || sizeInBytefCount==0) return 0; + + const AliHLTUInt8_t* pEnd=reinterpret_cast(pTracks); + pEnd+=sizeInByte; + + tgtArray.resize(pTracks->fCount); + const AliHLTUInt8_t* pCurrent=reinterpret_cast(pTracks->fTracklets); + for (int i=0; ifCount; i++) { + if (pCurrent+sizeof(AliHLTExternalTrackParam)>=pEnd) { + iResult=-EINVAL; break; + } + const AliHLTExternalTrackParam* track=reinterpret_cast(pCurrent); + if (pCurrent+sizeof(AliHLTExternalTrackParam)+track->fNPoints+sizeof(UInt_t)<=pEnd) { + iResult=-EINVAL; break; + } + tgtArray[i]=*track; + } + if (iResult<0) tgtArray.clear(); + else iResult=tgtArray.size(); + return iResult; +} + +UInt_t AliHLTGlobalBarrelTrack::GetNumberOfPoints() const +{ + // see header file for class documentation + return fPoints.size(); +} + +const UInt_t* AliHLTGlobalBarrelTrack::GetPoints() const +{ + // see header file for class documentation + if (fPoints.size()==0) return NULL; + return &fPoints[0]; +} + +int AliHLTGlobalBarrelTrack::SetPoints(const UInt_t* pArray, UInt_t arraySize) +{ + // see header file for class documentation + if (!pArray || arraySize==0) return 0; + fPoints.resize(arraySize); + for (int i=0; i +using namespace std; + +/** + * @class AliHLTGlobalBarrelTrack + * Representation of global HLT barrel tracks. + * + * @ingroup alihlt_global_components + */ +class AliHLTGlobalBarrelTrack : public AliKalmanTrack +{ + public: + /** standard constructor */ + AliHLTGlobalBarrelTrack(); + /** copy constructor */ + AliHLTGlobalBarrelTrack(const AliHLTGlobalBarrelTrack& t); + /** assignment operator */ + AliHLTGlobalBarrelTrack& operator=(const AliHLTGlobalBarrelTrack& t); + /** assignment operator */ + AliHLTGlobalBarrelTrack& operator=(const AliHLTExternalTrackParam& extp); + /** destructor */ + ~AliHLTGlobalBarrelTrack(); + + /// Get the x position of the last assigned point + Double_t GetLastPointX() const {return fLastX;} + /// Get the y position of the last assigned point + Double_t GetLastPointY() const {return fLastY;} + + /// Get the number of associated points + UInt_t GetNumberOfPoints() const; + + /// Get the list of associated points + const UInt_t* GetPoints() const; + + /// Set the list of associated points + int SetPoints(const UInt_t* pArray, UInt_t arraySize); + + static int ConvertTrackDataArray(const AliHLTTracksData* pTracks, int sizeInByte, vector &tgtArray); + + /// dummy function required by AliKalmanTrack + Double_t GetPredictedChi2(const AliCluster*) const {return 0.0;} + + /// dummy function required by AliKalmanTrack + Bool_t PropagateTo(Double_t, Double_t, Double_t) {return kFALSE;} + + /// dummy function required by AliKalmanTrack + Bool_t Update(const AliCluster*, Double_t, Int_t) {return kFALSE;} + + protected: + + private: + /// array of points + vector fPoints; // + + /// x position of the last assigned point + Double_t fLastX; // + /// y position of the last assigned point + Double_t fLastY; // + + ClassDef(AliHLTGlobalBarrelTrack, 0) +}; +#endif diff --git a/HLT/global/AliHLTGlobalEsdConverterComponent.cxx b/HLT/global/AliHLTGlobalEsdConverterComponent.cxx new file mode 100644 index 00000000000..04724431f5f --- /dev/null +++ b/HLT/global/AliHLTGlobalEsdConverterComponent.cxx @@ -0,0 +1,335 @@ +// $Id$ + +//************************************************************************** +//* This file is property of and copyright by the ALICE HLT Project * +//* ALICE Experiment at CERN, All rights reserved. * +//* * +//* Primary Authors: Matthias Richter * +//* for The ALICE HLT Project. * +//* * +//* Permission to use, copy, modify and distribute this software and its * +//* documentation strictly for non-commercial purposes is hereby granted * +//* without fee, provided that the above copyright notice appears in all * +//* copies and that both the copyright notice and this permission notice * +//* appear in the supporting documentation. The authors make no claims * +//* about the suitability of this software for any purpose. It is * +//* provided "as is" without express or implied warranty. * +//************************************************************************** + +/** @file AliHLTGlobalEsdConverterComponent.cxx + @author Matthias Richter + @date + @brief Global ESD converter component. +*/ + +// see header file for class documentation +// or +// refer to README to build package +// or +// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt + +#include +#include "AliHLTGlobalEsdConverterComponent.h" +#include "AliHLTGlobalBarrelTrack.h" +#include "AliHLTExternalTrackParam.h" +#include "AliESDEvent.h" +#include "AliESDtrack.h" +#include "AliCDBEntry.h" +#include "AliCDBManager.h" +#include "TTree.h" +#include "TList.h" + +/** ROOT macro for the implementation of ROOT specific class methods */ +ClassImp(AliHLTGlobalEsdConverterComponent) + +AliHLTGlobalEsdConverterComponent::AliHLTGlobalEsdConverterComponent() + : AliHLTProcessor() + , fESD(NULL) + , fSolenoidBz(5) + , fWriteTree(0) + +{ + // see header file for class documentation + // or + // refer to README to build package + // or + // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt +} + +AliHLTGlobalEsdConverterComponent::~AliHLTGlobalEsdConverterComponent() +{ + // see header file for class documentation + if (fESD) delete fESD; + fESD=NULL; +} + +int AliHLTGlobalEsdConverterComponent::Configure(const char* arguments) +{ + // see header file for class documentation + int iResult=0; + if (!arguments) return iResult; + + TString allArgs=arguments; + TString argument; + int bMissingParam=0; + + TObjArray* pTokens=allArgs.Tokenize(" "); + if (pTokens) { + for (int i=0; iGetEntries() && iResult>=0; i++) { + argument=((TObjString*)pTokens->At(i))->GetString(); + if (argument.IsNull()) continue; + + if (argument.CompareTo("-solenoidBz")==0) { + if ((bMissingParam=(++i>=pTokens->GetEntries()))) break; + HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data()); + fSolenoidBz=((TObjString*)pTokens->At(i))->GetString().Atof(); + continue; + } else { + HLTError("unknown argument %s", argument.Data()); + iResult=-EINVAL; + break; + } + } + delete pTokens; + } + if (bMissingParam) { + HLTError("missing parameter for argument %s", argument.Data()); + iResult=-EINVAL; + } + + return iResult; +} + +int AliHLTGlobalEsdConverterComponent::Reconfigure(const char* cdbEntry, const char* chainId) +{ + // see header file for class documentation + int iResult=0; + const char* path=kAliHLTCDBSolenoidBz; + const char* defaultNotify=""; + if (cdbEntry) { + path=cdbEntry; + defaultNotify=" (default)"; + } + if (path) { + HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:""); + AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/); + if (pEntry) { + TObjString* pString=dynamic_cast(pEntry->GetObject()); + if (pString) { + HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data()); + iResult=Configure(pString->GetString().Data()); + } else { + HLTError("configuration object \"%s\" has wrong type, required TObjString", path); + } + } else { + HLTError("can not fetch object \"%s\" from CDB", path); + } + } + + return iResult; +} + +void AliHLTGlobalEsdConverterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list) +{ + // see header file for class documentation + list.push_back(kAliHLTDataTypeTrack); + list.push_back(kAliHLTDataTypeTrackMC); +} + +AliHLTComponentDataType AliHLTGlobalEsdConverterComponent::GetOutputDataType() +{ + // see header file for class documentation + return kAliHLTDataTypeESDObject|kAliHLTDataOriginHLT; +} + +void AliHLTGlobalEsdConverterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier) +{ + // see header file for class documentation + constBase=2000000; + inputMultiplier=10.0; +} + +int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv) +{ + // see header file for class documentation + int iResult=0; + TString argument=""; + int bMissingParam=0; + for (int i=0; i=0; i++) { + argument=argv[i]; + if (argument.IsNull()) continue; + + // -notree + if (argument.CompareTo("-notree")==0) { + fWriteTree=0; + + // -tree + } else if (argument.CompareTo("-tree")==0) { + fWriteTree=1; + + } else { + HLTError("unknown argument %s", argument.Data()); + break; + } + } + if (bMissingParam) { + HLTError("missing parameter for argument %s", argument.Data()); + iResult=-EINVAL; + } + + if (iResult>=0) { + iResult=Reconfigure(NULL, NULL); + } + + if (iResult>=0) { + fESD = new AliESDEvent; + if (fESD) { + fESD->CreateStdContent(); + } else { + iResult=-ENOMEM; + } + } + + return iResult; +} + +int AliHLTGlobalEsdConverterComponent::DoDeinit() +{ + // see header file for class documentation + if (fESD) delete fESD; + fESD=NULL; + + return 0; +} + +int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/, + AliHLTComponentTriggerData& /*trigData*/) +{ + // see header file for class documentation + int iResult=0; + if (!fESD) return -ENODEV; + + AliESDEvent* pESD = fESD; + + pESD->Reset(); + pESD->SetMagneticField(fSolenoidBz); + + TTree* pTree = NULL; + if (fWriteTree) + pTree = new TTree("esdTree", "Tree with HLT ESD objects"); + + if (pTree) { + pTree->SetDirectory(0); + } + + if ((iResult=ProcessBlocks(pTree, pESD))>0) { + // TODO: set the specification correctly + if (pTree) { + // the esd structure is written to the user info and is + // needed in te ReadFromTree method to read all objects correctly + pTree->GetUserInfo()->Add(pESD); + pESD->WriteToTree(pTree); + iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginHLT, 0); + } else { + iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginHLT, 0); + } + } + if (pTree) { + // clear user info list to prevent objects from being deleted + pTree->GetUserInfo()->Clear(); + delete pTree; + } + return iResult; +} + +int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD) +{ + // see header file for class documentation + + int iResult=0; + int iAddedDataBlocks=0; + + // Barrel tracking + + // in the first attempt this component reads the TPC tracks and updates in the + // second step from the ITS tracks + std::vector trackIdESD2TPCmap; // map esd index -> tpc index + + for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC); + pBlock!=NULL; pBlock=GetNextInputBlock()) { + vector tracks; + if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast(pBlock->fPtr), pBlock->fSize, tracks))>0) { + for (vector::iterator element=tracks.begin(); + element!=tracks.end(); element++) { + Float_t points[4] = { + element->GetX(), + element->GetY(), + element->GetLastPointX(), + element->GetLastPointY() + }; + AliESDtrack iotrack; + iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCin); + iotrack.SetTPCPoints(points); + + pESD->AddTrack(&iotrack); + } + iAddedDataBlocks++; + } else if (iResult<0) { + HLTError("can not extract tracks from data block of type %s (specification %08x) of size $d", + DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize); + } + } + + // ITS updated tracks + /* + int nESDTracks = pESD->GetNumberOfTracks(); + + // create map of tpc->esd track indices + + int *trackIdTPC2ESDmap = new int[ nTPCTracks ]; + { + for( int i=0; i=0 && tpcId=0; ndx++) { + iter = blocks+ndx; + if(iter->fDataType == fgkITSTracksDataType ) { + AliHLTITSTrackDataHeader *inPtr = reinterpret_cast( iter->fPtr ); + int nTracks = inPtr->fTrackletCnt; + for( int itr=0; itrfTracks[itr]; + AliHLTITSTrack tITS( tr.fTrackParam ); + int ncl=0; + for( int il=0; il<6; il++ ){ + if( tr.fClusterIds[il]>=0 ) tITS.SetClusterIndex(ncl++, tr.fClusterIds[il]); + } + tITS.SetNumberOfClusters( ncl ); + int tpcId = tr.fTPCId; + if( tpcId<0 || tpcId>=nTPCTracks ) continue; + int esdID = trackIdTPC2ESDmap[tpcId]; + if( esdID<0 || esdID>=nESDTracks ) continue; + AliESDtrack *tESD = pESD->GetTrack( esdID ); + if( tESD ) tESD->UpdateTrackParams( &tITS, AliESDtrack::kITSin ); + } + } + } + delete[] trackIdTPC2ESDmap; + + // primary vertex & V0's + + //AliHLTVertexer vertexer; + //vertexer.SetESD( pESD ); + //vertexer.FindPrimaryVertex(); + //vertexer.FindV0s(); + */ + if (iAddedDataBlocks>0 && pTree) { + pTree->Fill(); + } + + if (iResult>=0) iResult=iAddedDataBlocks; + return iResult; +} diff --git a/HLT/global/AliHLTGlobalEsdConverterComponent.h b/HLT/global/AliHLTGlobalEsdConverterComponent.h new file mode 100644 index 00000000000..9ba9e3fed08 --- /dev/null +++ b/HLT/global/AliHLTGlobalEsdConverterComponent.h @@ -0,0 +1,102 @@ +//-*- Mode: C++ -*- +// $Id$ +#ifndef ALIHLTGLOBALESDCONVERTERCOMPONENT_H +#define ALIHLTGLOBALESDCONVERTERCOMPONENT_H +//* This file is property of and copyright by the ALICE HLT Project * +//* ALICE Experiment at CERN, All rights reserved. * +//* See cxx source for full Copyright notice * + +/** @file AliHLTGlobalEsdConverterComponent.h + @author Matthias Richter + @date + @brief Global ESD converter component. +*/ + +#include "AliHLTProcessor.h" +#include + +// forward declarations +class AliESDEvent; +class TTree; +struct AliHLTTracksData; + +/** + * @class AliHLTGlobalEsdConverterComponent + * Global collector for information designated for the HLT ESD. + * + * componentid: \b GlobalEsdConverter
+ * componentlibrary: \b libAliHLTGlobal.so
+ * Arguments:
+ * + * \li -notree
+ * write ESD directly to output (::kAliHLTDataTypeESDObject) + * this has been made the default behavior in Sep 2008. + * \li -tree
+ * write ESD directly to TTree and to output (::kAliHLTDataTypeESDTree) + * + * @ingroup alihlt_tpc_components + */ +class AliHLTGlobalEsdConverterComponent : public AliHLTProcessor +{ + public: + /** standard constructor */ + AliHLTGlobalEsdConverterComponent(); + /** destructor */ + ~AliHLTGlobalEsdConverterComponent(); + + // interface methods of base class + const char* GetComponentID() {return "GlobalEsdConverter";}; + void GetInputDataTypes(AliHLTComponentDataTypeList& list); + AliHLTComponentDataType GetOutputDataType(); + void GetOutputDataSize(unsigned long& constBase, double& inputMultiplier); + AliHLTComponent* Spawn() {return new AliHLTGlobalEsdConverterComponent;} + + protected: + // interface methods of base class + int DoInit(int argc, const char** argv); + int DoDeinit(); + int DoEvent( const AliHLTComponentEventData& evtData, + AliHLTComponentTriggerData& trigData); + + using AliHLTProcessor::DoEvent; + + /** + * Process the input data blocks. + * @param pTree tree to be filled + * @param pESD ESD to be filled + * @return neg. error code if failed + */ + int ProcessBlocks(TTree* pTree, AliESDEvent* pESD); + + private: + /** copy constructor prohibited */ + AliHLTGlobalEsdConverterComponent(const AliHLTGlobalEsdConverterComponent&); + /** assignment operator prohibited */ + AliHLTGlobalEsdConverterComponent& operator=(const AliHLTGlobalEsdConverterComponent&); + + /** + * (Re)Configure from the CDB + * Loads the following objects: + * - HLT/ConfigHLT/SolenoidBz + */ + int Reconfigure(const char* cdbEntry, const char* chainId); + + /** + * Configure the component. + * Parse a string for the configuration arguments and set the component + * properties. + */ + int Configure(const char* arguments); + + /// the ESD + AliESDEvent* fESD; //! transient value + + /// solenoid b field + Double_t fSolenoidBz; //! transient + + /// write object to TTree or directly + int fWriteTree; //!transient + + ClassDef(AliHLTGlobalEsdConverterComponent, 0) +}; +#endif diff --git a/HLT/libAliHLTGlobal.pkg b/HLT/libAliHLTGlobal.pkg index 752c8a65b7b..a816bfd6366 100644 --- a/HLT/libAliHLTGlobal.pkg +++ b/HLT/libAliHLTGlobal.pkg @@ -3,6 +3,8 @@ CLASS_HDRS:= AliHLTGlobalTrackMerger.h \ AliHLTGlobalTrackMergerComponent.h \ + AliHLTGlobalEsdConverterComponent.h \ + AliHLTGlobalBarrelTrack.h \ AliHLTGlobalAgent.h \ AliHLTVertexer.h -- 2.43.5