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("-fitTracksToVertex")==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) {
187 }else if (argument.CompareTo("-fitTracksToVertex")==0) {
188 if ((bMissingParam=(++i>=argc))) break;
190 HLTInfo("Filling of vertex constrained tracks is set set to: %s", argument.Data());
191 fFillVtxConstrainedTracks=argument.Atoi();
193 HLTError("unknown argument %s", argument.Data());
198 HLTError("missing parameter for argument %s", argument.Data());
203 iResult=Reconfigure(NULL, NULL);
207 fESD = new AliESDEvent;
209 fESD->CreateStdContent();
220 int AliHLTGlobalEsdConverterComponent::DoDeinit()
222 // see header file for class documentation
223 if (fESD) delete fESD;
229 int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
230 AliHLTComponentTriggerData& trigData)
232 // see header file for class documentation
234 if (!fESD) return -ENODEV;
236 AliESDEvent* pESD = fESD;
239 pESD->SetMagneticField(fSolenoidBz);
240 pESD->SetRunNumber(GetRunNo());
241 pESD->SetPeriodNumber(GetPeriodNumber());
242 pESD->SetOrbitNumber(GetOrbitNumber());
243 pESD->SetBunchCrossNumber(GetBunchCrossNumber());
244 pESD->SetTimeStamp(GetTimeStamp());
246 const AliHLTCTPData* pCTPData=CTPData();
248 AliHLTUInt64_t mask=pCTPData->ActiveTriggers(trigData);
249 for (int index=0; index<gkNCTPTriggerClasses; index++) {
250 if ((mask&((AliHLTUInt64_t)0x1<<index)) == 0) continue;
251 pESD->SetTriggerClass(pCTPData->Name(index), index);
253 pESD->SetTriggerMask(mask);
258 pTree = new TTree("esdTree", "Tree with HLT ESD objects");
261 pTree->SetDirectory(0);
264 if ((iResult=ProcessBlocks(pTree, pESD))>=0) {
265 // TODO: set the specification correctly
267 // the esd structure is written to the user info and is
268 // needed in te ReadFromTree method to read all objects correctly
269 pTree->GetUserInfo()->Add(pESD);
270 pESD->WriteToTree(pTree);
271 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginOut, 0);
273 iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginOut, 0);
277 // clear user info list to prevent objects from being deleted
278 pTree->GetUserInfo()->Clear();
284 int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD)
286 // see header file for class documentation
289 int iAddedDataBlocks=0;
293 // in the first attempt this component reads the TPC tracks and updates in the
294 // second step from the ITS tracks
297 // first read MC information (if present)
298 std::map<int,int> mcLabels;
300 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC);
301 pBlock!=NULL; pBlock=GetNextInputBlock()) {
302 AliHLTTrackMCData* dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr );
303 if (sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize) {
304 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
305 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
306 mcLabels[lab.fTrackID] = lab.fMCLabel;
309 HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information",
310 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification,
311 dataPtr->fCount, pBlock->fSize);
315 // read dEdx information (if present)
317 AliHLTFloat32_t *dEdxTPC = 0;
319 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypedEdx|kAliHLTDataOriginTPC);
320 pBlock!=NULL; pBlock=GetNextInputBlock()) {
321 dEdxTPC = reinterpret_cast<AliHLTFloat32_t*>( pBlock->fPtr );
322 ndEdxTPC = pBlock->fSize / sizeof(AliHLTFloat32_t);
326 // convert the TPC tracks to ESD tracks
327 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
328 pBlock!=NULL; pBlock=GetNextInputBlock()) {
329 vector<AliHLTGlobalBarrelTrack> tracks;
330 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>=0) {
331 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
332 element!=tracks.end(); element++) {
333 Float_t points[4] = {
336 element->GetLastPointX(),
337 element->GetLastPointY()
341 if( mcLabels.find(element->TrackID())!=mcLabels.end() )
342 mcLabel = mcLabels[element->TrackID()];
343 element->SetLabel( mcLabel );
347 // for the moment, the number of clusters are not set when processing the
348 // kTPCin update, only at kTPCout
349 // there ar emainly three parameters updated for kTPCout
350 // number of clusters
353 // The first one can be updated already at that stage here, while the two others
354 // eventually require to update from the ITS tracks before. The exact scheme
355 // needs to be checked
356 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCin);
357 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCout);
358 iotrack.SetTPCPoints(points);
359 if( element->TrackID()<ndEdxTPC ){
360 iotrack.SetTPCsignal( dEdxTPC[element->TrackID()], 0, 0 );
362 //s.Set( element->GetX(), element->GetAlpha(),
363 //element->GetParameter(), element->GetCovariance() );
364 //s.SetdEdx( dEdxTPC[element->TrackID()] );
366 //iotrack.SetTPCpid(s.TPCrPIDs() );
368 if( dEdxTPC ) HLTWarning("Wrong number of dEdx TPC labels");
370 pESD->AddTrack(&iotrack);
371 if (fVerbosity>0) element->Print();
373 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
375 } else if (iResult<0) {
376 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
377 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
381 // now update ESD tracks with the ITS info
382 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITS);
383 pBlock!=NULL; pBlock=GetNextInputBlock()) {
384 vector<AliHLTGlobalBarrelTrack> tracks;
385 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
386 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
387 element!=tracks.end(); element++) {
389 const UInt_t* pointsArray=element->GetPoints();
390 for( unsigned il=0; il<element->GetNumberOfPoints(); il++ ){
391 // TODO: check what needs to be done with the clusters
392 if( pointsArray[il]<~(UInt_t)0 ) {/*tITS.SetClusterIndex(ncl, tr.fClusterIds[il]);*/}
395 //tITS.SetNumberOfClusters( ncl );
396 int tpcID=element->TrackID();
397 // the ITS tracker assigns the TPC track used as seed for a certain track to
399 if( tpcID<0 || tpcID>=pESD->GetNumberOfTracks()) continue;
401 AliESDtrack *tESD = pESD->GetTrack( tpcID );
402 if( tESD ) tESD->UpdateTrackParams( &(*element), AliESDtrack::kITSin );
407 // convert the HLT TRD tracks to ESD tracks
408 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack | kAliHLTDataOriginTRD);
409 pBlock!=NULL; pBlock=GetNextInputBlock()) {
410 vector<AliHLTGlobalBarrelTrack> tracks;
411 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
412 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
413 element!=tracks.end(); element++) {
415 Double_t TRDpid[AliPID::kSPECIES], eProb(0.2), restProb((1-eProb)/(AliPID::kSPECIES-1)); //eprob(element->GetTRDpid...);
416 for(Int_t i=0; i<AliPID::kSPECIES; i++){
418 case AliPID::kElectron: TRDpid[AliPID::kElectron]=eProb; break;
419 default: TRDpid[i]=restProb; break;
424 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTRDin);
425 iotrack.SetTRDpid(TRDpid);
427 pESD->AddTrack(&iotrack);
428 if (fVerbosity>0) element->Print();
430 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
432 } else if (iResult<0) {
433 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
434 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
437 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeCaloCluster | kAliHLTDataOriginPHOS); pBlock!=NULL; pBlock=GetNextInputBlock())
439 AliHLTCaloClusterHeaderStruct *caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
441 HLTDebug("%d HLT clusters from spec: 0x%X", caloClusterHeaderPtr->fNClusters, pBlock->fSpecification);
443 AliHLTCaloClusterReader reader;
444 reader.SetMemory(caloClusterHeaderPtr);
446 AliHLTESDCaloClusterMaker clusterMaker;
448 int nClusters = clusterMaker.FillESD(pESD, caloClusterHeaderPtr);
450 HLTInfo("converted %d cluster(s) to AliESDCaloCluster and added to ESD", nClusters);
454 // primary vertex & V0's
456 AliHLTVertexer vertexer;
457 vertexer.SetESD( pESD );
458 vertexer.SetFillVtxConstrainedTracks( fFillVtxConstrainedTracks );
459 vertexer.FindPrimaryVertex();
462 if (iAddedDataBlocks>0 && pTree) {
466 if (iResult>=0) iResult=iAddedDataBlocks;