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"
49 /** ROOT macro for the implementation of ROOT specific class methods */
50 ClassImp(AliHLTGlobalEsdConverterComponent)
52 AliHLTGlobalEsdConverterComponent::AliHLTGlobalEsdConverterComponent()
57 , fSolenoidBz(-5.00668)
59 // see header file for class documentation
61 // refer to README to build package
63 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
66 AliHLTGlobalEsdConverterComponent::~AliHLTGlobalEsdConverterComponent()
68 // see header file for class documentation
69 if (fESD) delete fESD;
73 int AliHLTGlobalEsdConverterComponent::Configure(const char* arguments)
75 // see header file for class documentation
77 if (!arguments) return iResult;
79 TString allArgs=arguments;
83 TObjArray* pTokens=allArgs.Tokenize(" ");
85 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
86 argument=((TObjString*)pTokens->At(i))->GetString();
87 if (argument.IsNull()) continue;
89 if (argument.CompareTo("-solenoidBz")==0) {
90 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
91 HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
94 HLTError("unknown argument %s", argument.Data());
102 HLTError("missing parameter for argument %s", argument.Data());
109 int AliHLTGlobalEsdConverterComponent::Reconfigure(const char* cdbEntry, const char* chainId)
111 // see header file for class documentation
113 const char* path=NULL;
114 const char* defaultNotify="";
117 defaultNotify=" (default)";
120 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
121 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
123 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
125 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
126 iResult=Configure(pString->GetString().Data());
128 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
131 HLTError("can not fetch object \"%s\" from CDB", path);
138 void AliHLTGlobalEsdConverterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
140 // see header file for class documentation
141 list.push_back(kAliHLTDataTypeTrack);
142 list.push_back(kAliHLTDataTypeTrackMC);
143 list.push_back(kAliHLTDataTypeCaloCluster);
144 list.push_back(kAliHLTDataTypedEdx );
145 list.push_back(kAliHLTDataTypeESDVertex );
148 AliHLTComponentDataType AliHLTGlobalEsdConverterComponent::GetOutputDataType()
150 // see header file for class documentation
151 return kAliHLTDataTypeESDObject|kAliHLTDataOriginOut;
154 void AliHLTGlobalEsdConverterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
156 // see header file for class documentation
158 inputMultiplier=10.0;
161 int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
163 // see header file for class documentation
168 iResult=Reconfigure(NULL, NULL);
169 TString allArgs = "";
170 for ( int i = 0; i < argc; i++ ) {
171 if ( !allArgs.IsNull() ) allArgs += " ";
175 TObjArray* pTokens=allArgs.Tokenize(" ");
177 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
178 argument=((TObjString*)pTokens->At(i))->GetString();
179 if (argument.IsNull()) continue;
182 if (argument.CompareTo("-notree")==0) {
186 } else if (argument.CompareTo("-tree")==0) {
188 } else if (argument.CompareTo("-solenoidBz")==0) {
189 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
190 HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
191 fSolenoidBz=((TObjString*)pTokens->At(i))->GetString().Atof();
194 HLTError("unknown argument %s", argument.Data());
200 HLTError("missing parameter for argument %s", argument.Data());
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.SetID( element->TrackID() );
357 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCin);
359 AliHLTGlobalBarrelTrack outPar(*element);
360 outPar.AliExternalTrackParam::PropagateTo( element->GetLastPointX(), fSolenoidBz );
361 iotrack.UpdateTrackParams(&outPar,AliESDtrack::kTPCout);
363 iotrack.SetTPCPoints(points);
364 if( element->TrackID()<ndEdxTPC ){
365 iotrack.SetTPCsignal( dEdxTPC[element->TrackID()], 0, 0 );
367 //s.Set( element->GetX(), element->GetAlpha(),
368 //element->GetParameter(), element->GetCovariance() );
369 //s.SetdEdx( dEdxTPC[element->TrackID()] );
371 //iotrack.SetTPCpid(s.TPCrPIDs() );
373 if( dEdxTPC ) HLTWarning("Wrong number of dEdx TPC labels");
375 pESD->AddTrack(&iotrack);
376 if (fVerbosity>0) element->Print();
378 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
380 } else if (iResult<0) {
381 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
382 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
387 // Get ITS SPD vertex
389 for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS); iter != NULL; iter = GetNextInputObject() ) {
390 AliESDVertex *vtx = dynamic_cast<AliESDVertex*>(const_cast<TObject*>( iter ) );
391 pESD->SetPrimaryVertexSPD( vtx );
394 // now update ESD tracks with the ITSOut info
395 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITSOut);
396 pBlock!=NULL; pBlock=GetNextInputBlock()) {
397 vector<AliHLTGlobalBarrelTrack> tracks;
398 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
399 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
400 element!=tracks.end(); element++) {
401 int tpcID=element->TrackID();
402 // the ITS tracker assigns the TPC track used as seed for a certain track to
404 if( tpcID<0 || tpcID>=pESD->GetNumberOfTracks()) continue;
405 AliESDtrack *tESD = pESD->GetTrack( tpcID );
406 if( tESD ) tESD->UpdateTrackParams( &(*element), AliESDtrack::kITSout );
411 // now update ESD tracks with the ITS info
412 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITS);
413 pBlock!=NULL; pBlock=GetNextInputBlock()) {
414 vector<AliHLTGlobalBarrelTrack> tracks;
415 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
416 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
417 element!=tracks.end(); element++) {
418 int tpcID=element->TrackID();
419 // the ITS tracker assigns the TPC track used as seed for a certain track to
421 if( tpcID<0 || tpcID>=pESD->GetNumberOfTracks()) continue;
422 AliESDtrack *tESD = pESD->GetTrack( tpcID );
423 if( tESD ) tESD->UpdateTrackParams( &(*element), AliESDtrack::kITSin );
429 // convert the HLT TRD tracks to ESD tracks
430 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack | kAliHLTDataOriginTRD);
431 pBlock!=NULL; pBlock=GetNextInputBlock()) {
432 vector<AliHLTGlobalBarrelTrack> tracks;
433 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
434 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
435 element!=tracks.end(); element++) {
437 Double_t TRDpid[AliPID::kSPECIES], eProb(0.2), restProb((1-eProb)/(AliPID::kSPECIES-1)); //eprob(element->GetTRDpid...);
438 for(Int_t i=0; i<AliPID::kSPECIES; i++){
440 case AliPID::kElectron: TRDpid[AliPID::kElectron]=eProb; break;
441 default: TRDpid[i]=restProb; break;
446 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTRDin);
447 iotrack.SetTRDpid(TRDpid);
449 pESD->AddTrack(&iotrack);
450 if (fVerbosity>0) element->Print();
452 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
454 } else if (iResult<0) {
455 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
456 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
459 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeCaloCluster | kAliHLTDataOriginPHOS); pBlock!=NULL; pBlock=GetNextInputBlock())
461 AliHLTCaloClusterHeaderStruct *caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
463 HLTDebug("%d HLT clusters from spec: 0x%X", caloClusterHeaderPtr->fNClusters, pBlock->fSpecification);
465 AliHLTCaloClusterReader reader;
466 reader.SetMemory(caloClusterHeaderPtr);
468 AliHLTESDCaloClusterMaker clusterMaker;
470 int nClusters = clusterMaker.FillESD(pESD, caloClusterHeaderPtr);
472 HLTInfo("converted %d cluster(s) to AliESDCaloCluster and added to ESD", nClusters);
477 if (iAddedDataBlocks>0 && pTree) {
481 if (iResult>=0) iResult=iAddedDataBlocks;