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 "AliESDEvent.h"
38 #include "AliESDtrack.h"
39 #include "AliCDBEntry.h"
40 #include "AliCDBManager.h"
44 #include "AliHLTESDCaloClusterMaker.h"
45 #include "AliHLTCaloClusterDataStruct.h"
46 #include "AliHLTCaloClusterReader.h"
47 #include "AliESDCaloCluster.h"
48 #include "AliHLTVertexer.h"
49 #include "AliTPCseed.h"
51 /** ROOT macro for the implementation of ROOT specific class methods */
52 ClassImp(AliHLTGlobalEsdConverterComponent)
54 AliHLTGlobalEsdConverterComponent::AliHLTGlobalEsdConverterComponent()
59 , fSolenoidBz(-5.00668)
60 , fFillVtxConstrainedTracks( 0 )
62 // see header file for class documentation
64 // refer to README to build package
66 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
69 AliHLTGlobalEsdConverterComponent::~AliHLTGlobalEsdConverterComponent()
71 // see header file for class documentation
72 if (fESD) delete fESD;
76 int AliHLTGlobalEsdConverterComponent::Configure(const char* arguments)
78 // see header file for class documentation
80 if (!arguments) return iResult;
82 TString allArgs=arguments;
86 TObjArray* pTokens=allArgs.Tokenize(" ");
88 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
89 argument=((TObjString*)pTokens->At(i))->GetString();
90 if (argument.IsNull()) continue;
92 if (argument.CompareTo("-solenoidBz")==0) {
93 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
94 HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
95 fSolenoidBz=((TObjString*)pTokens->At(i))->GetString().Atof();
98 else if (argument.CompareTo("-fitTracks2Vertex")==0) {
99 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
100 HLTInfo("Filling of vertex constrained tracks is set set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
101 fFillVtxConstrainedTracks=((TObjString*)pTokens->At(i))->GetString().Atoi();
104 HLTError("unknown argument %s", argument.Data());
112 HLTError("missing parameter for argument %s", argument.Data());
119 int AliHLTGlobalEsdConverterComponent::Reconfigure(const char* cdbEntry, const char* chainId)
121 // see header file for class documentation
123 const char* path=kAliHLTCDBSolenoidBz;
124 const char* defaultNotify="";
127 defaultNotify=" (default)";
130 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
131 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
133 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
135 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
136 iResult=Configure(pString->GetString().Data());
138 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
141 HLTError("can not fetch object \"%s\" from CDB", path);
148 void AliHLTGlobalEsdConverterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
150 // see header file for class documentation
151 list.push_back(kAliHLTDataTypeTrack);
152 list.push_back(kAliHLTDataTypeTrackMC);
153 list.push_back(kAliHLTDataTypeCaloCluster);
154 list.push_back(kAliHLTDataTypedEdx );
157 AliHLTComponentDataType AliHLTGlobalEsdConverterComponent::GetOutputDataType()
159 // see header file for class documentation
160 return kAliHLTDataTypeESDObject|kAliHLTDataOriginOut;
163 void AliHLTGlobalEsdConverterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
165 // see header file for class documentation
167 inputMultiplier=10.0;
170 int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
172 // see header file for class documentation
176 for (int i=0; i<argc && iResult>=0; i++) {
178 if (argument.IsNull()) continue;
181 if (argument.CompareTo("-notree")==0) {
185 } else if (argument.CompareTo("-tree")==0) {
189 HLTError("unknown argument %s", argument.Data());
194 HLTError("missing parameter for argument %s", argument.Data());
199 iResult=Reconfigure(NULL, NULL);
203 fESD = new AliESDEvent;
205 fESD->CreateStdContent();
216 int AliHLTGlobalEsdConverterComponent::DoDeinit()
218 // see header file for class documentation
219 if (fESD) delete fESD;
225 int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
226 AliHLTComponentTriggerData& trigData)
228 // see header file for class documentation
230 if (!fESD) return -ENODEV;
232 AliESDEvent* pESD = fESD;
235 pESD->SetMagneticField(fSolenoidBz);
236 pESD->SetRunNumber(GetRunNo());
237 pESD->SetPeriodNumber(GetPeriodNumber());
238 pESD->SetOrbitNumber(GetOrbitNumber());
239 pESD->SetBunchCrossNumber(GetBunchCrossNumber());
240 pESD->SetTimeStamp(GetTimeStamp());
242 const AliHLTCTPData* pCTPData=CTPData();
244 AliHLTUInt64_t mask=pCTPData->ActiveTriggers(trigData);
245 for (int index=0; index<gkNCTPTriggerClasses; index++) {
246 if ((mask&((AliHLTUInt64_t)0x1<<index)) == 0) continue;
247 pESD->SetTriggerClass(pCTPData->Name(index), index);
249 pESD->SetTriggerMask(mask);
254 pTree = new TTree("esdTree", "Tree with HLT ESD objects");
257 pTree->SetDirectory(0);
260 if ((iResult=ProcessBlocks(pTree, pESD))>=0) {
261 // TODO: set the specification correctly
263 // the esd structure is written to the user info and is
264 // needed in te ReadFromTree method to read all objects correctly
265 pTree->GetUserInfo()->Add(pESD);
266 pESD->WriteToTree(pTree);
267 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginOut, 0);
269 iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginOut, 0);
273 // clear user info list to prevent objects from being deleted
274 pTree->GetUserInfo()->Clear();
280 int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD)
282 // see header file for class documentation
285 int iAddedDataBlocks=0;
289 // in the first attempt this component reads the TPC tracks and updates in the
290 // second step from the ITS tracks
293 // first read MC information (if present)
294 std::map<int,int> mcLabels;
296 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC);
297 pBlock!=NULL; pBlock=GetNextInputBlock()) {
298 AliHLTTrackMCData* dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr );
299 if (sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize) {
300 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
301 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
302 mcLabels[lab.fTrackID] = lab.fMCLabel;
305 HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information",
306 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification,
307 dataPtr->fCount, pBlock->fSize);
311 // read dEdx information (if present)
313 AliHLTFloat32_t *dEdxTPC = 0;
315 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypedEdx|kAliHLTDataOriginTPC);
316 pBlock!=NULL; pBlock=GetNextInputBlock()) {
317 dEdxTPC = reinterpret_cast<AliHLTFloat32_t*>( pBlock->fPtr );
318 ndEdxTPC = pBlock->fSize / sizeof(AliHLTFloat32_t);
322 // convert the TPC tracks to ESD tracks
323 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
324 pBlock!=NULL; pBlock=GetNextInputBlock()) {
325 vector<AliHLTGlobalBarrelTrack> tracks;
326 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>=0) {
327 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
328 element!=tracks.end(); element++) {
329 Float_t points[4] = {
332 element->GetLastPointX(),
333 element->GetLastPointY()
337 if( mcLabels.find(element->TrackID())!=mcLabels.end() )
338 mcLabel = mcLabels[element->TrackID()];
339 element->SetLabel( mcLabel );
343 // for the moment, the number of clusters are not set when processing the
344 // kTPCin update, only at kTPCout
345 // there ar emainly three parameters updated for kTPCout
346 // number of clusters
349 // The first one can be updated already at that stage here, while the two others
350 // eventually require to update from the ITS tracks before. The exact scheme
351 // needs to be checked
352 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCin);
353 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCout);
354 iotrack.SetTPCPoints(points);
355 if( element->TrackID()<ndEdxTPC ){
357 s.Set( element->GetX(), element->GetAlpha(),
358 element->GetParameter(), element->GetCovariance() );
359 s.SetdEdx( dEdxTPC[element->TrackID()] );
361 iotrack.SetTPCpid(s.TPCrPIDs() );
363 if( dEdxTPC ) HLTWarning("Wrong number of dEdx TPC labels");
365 pESD->AddTrack(&iotrack);
366 if (fVerbosity>0) element->Print();
368 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
370 } else if (iResult<0) {
371 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
372 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
376 // now update ESD tracks with the ITS info
377 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITS);
378 pBlock!=NULL; pBlock=GetNextInputBlock()) {
379 vector<AliHLTGlobalBarrelTrack> tracks;
380 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
381 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
382 element!=tracks.end(); element++) {
384 const UInt_t* pointsArray=element->GetPoints();
385 for( unsigned il=0; il<element->GetNumberOfPoints(); il++ ){
386 // TODO: check what needs to be done with the clusters
387 if( pointsArray[il]<~(UInt_t)0 ) {/*tITS.SetClusterIndex(ncl, tr.fClusterIds[il]);*/}
390 //tITS.SetNumberOfClusters( ncl );
391 int tpcID=element->TrackID();
392 // the ITS tracker assigns the TPC track used as seed for a certain track to
394 if( tpcID<0 || tpcID>=pESD->GetNumberOfTracks()) continue;
396 AliESDtrack *tESD = pESD->GetTrack( tpcID );
397 if( tESD ) tESD->UpdateTrackParams( &(*element), AliESDtrack::kITSin );
402 // convert the HLT TRD tracks to ESD tracks
403 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack | kAliHLTDataOriginTRD);
404 pBlock!=NULL; pBlock=GetNextInputBlock()) {
405 vector<AliHLTGlobalBarrelTrack> tracks;
406 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
407 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
408 element!=tracks.end(); element++) {
410 Double_t TRDpid[AliPID::kSPECIES], eProb(0.2), restProb((1-eProb)/(AliPID::kSPECIES-1)); //eprob(element->GetTRDpid...);
411 for(Int_t i=0; i<AliPID::kSPECIES; i++){
413 case AliPID::kElectron: TRDpid[AliPID::kElectron]=eProb; break;
414 default: TRDpid[i]=restProb; break;
419 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTRDin);
420 iotrack.SetTRDpid(TRDpid);
422 pESD->AddTrack(&iotrack);
423 if (fVerbosity>0) element->Print();
425 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
427 } else if (iResult<0) {
428 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
429 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
432 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeCaloCluster | kAliHLTDataOriginPHOS); pBlock!=NULL; pBlock=GetNextInputBlock())
434 AliHLTCaloClusterHeaderStruct *caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
436 HLTDebug("%d HLT clusters from spec: 0x%X", caloClusterHeaderPtr->fNClusters, pBlock->fSpecification);
438 AliHLTCaloClusterReader reader;
439 reader.SetMemory(caloClusterHeaderPtr);
441 AliHLTESDCaloClusterMaker clusterMaker;
443 int nClusters = clusterMaker.FillESD(pESD, caloClusterHeaderPtr);
445 HLTInfo("converted %d cluster(s) to AliESDCaloCluster and added to ESD", nClusters);
449 // primary vertex & V0's
451 AliHLTVertexer vertexer;
452 vertexer.SetESD( pESD );
453 vertexer.FindPrimaryVertex();
456 // relate the tracks to vertex
457 if( fFillVtxConstrainedTracks ){
458 for( Int_t i = 0; i<pESD->GetNumberOfTracks(); i++){
459 if( !vertexer.TrackInfos()[i].fPrimUsedFlag ) continue;
460 pESD->GetTrack(i)->RelateToVertex( pESD->GetPrimaryVertex(), fESD->GetMagneticField(),5. );
464 if (iAddedDataBlocks>0 && pTree) {
468 if (iResult>=0) iResult=iAddedDataBlocks;