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 HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
92 fSolenoidBz=((TObjString*)pTokens->At(i))->GetString().Atof();
95 HLTError("unknown argument %s", argument.Data());
103 HLTError("missing parameter for argument %s", argument.Data());
110 int AliHLTGlobalEsdConverterComponent::Reconfigure(const char* cdbEntry, const char* chainId)
112 // see header file for class documentation
114 const char* path=kAliHLTCDBSolenoidBz;
115 const char* defaultNotify="";
118 defaultNotify=" (default)";
121 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
122 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
124 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
126 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
127 iResult=Configure(pString->GetString().Data());
129 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
132 HLTError("can not fetch object \"%s\" from CDB", path);
139 void AliHLTGlobalEsdConverterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
141 // see header file for class documentation
142 list.push_back(kAliHLTDataTypeTrack);
143 list.push_back(kAliHLTDataTypeTrackMC);
144 list.push_back(kAliHLTDataTypeCaloCluster);
147 AliHLTComponentDataType AliHLTGlobalEsdConverterComponent::GetOutputDataType()
149 // see header file for class documentation
150 return kAliHLTDataTypeESDObject|kAliHLTDataOriginOut;
153 void AliHLTGlobalEsdConverterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
155 // see header file for class documentation
157 inputMultiplier=10.0;
160 int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
162 // see header file for class documentation
166 for (int i=0; i<argc && iResult>=0; i++) {
168 if (argument.IsNull()) continue;
171 if (argument.CompareTo("-notree")==0) {
175 } else if (argument.CompareTo("-tree")==0) {
179 HLTError("unknown argument %s", argument.Data());
184 HLTError("missing parameter for argument %s", argument.Data());
189 iResult=Reconfigure(NULL, NULL);
193 fESD = new AliESDEvent;
195 fESD->CreateStdContent();
206 int AliHLTGlobalEsdConverterComponent::DoDeinit()
208 // see header file for class documentation
209 if (fESD) delete fESD;
215 int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
216 AliHLTComponentTriggerData& trigData)
218 // see header file for class documentation
220 if (!fESD) return -ENODEV;
222 AliESDEvent* pESD = fESD;
225 pESD->SetMagneticField(fSolenoidBz);
226 pESD->SetRunNumber(GetRunNo());
227 pESD->SetPeriodNumber(GetPeriodNumber());
228 pESD->SetOrbitNumber(GetOrbitNumber());
229 pESD->SetBunchCrossNumber(GetBunchCrossNumber());
230 pESD->SetTimeStamp(GetTimeStamp());
232 const AliHLTCTPData* pCTPData=CTPData();
234 AliHLTUInt64_t mask=pCTPData->ActiveTriggers(trigData);
235 for (int index=0; index<gkNCTPTriggerClasses; index++) {
236 if ((mask&((AliHLTUInt64_t)0x1<<index)) == 0) continue;
237 pESD->SetTriggerClass(pCTPData->Name(index), index);
239 pESD->SetTriggerMask(mask);
244 pTree = new TTree("esdTree", "Tree with HLT ESD objects");
247 pTree->SetDirectory(0);
250 if ((iResult=ProcessBlocks(pTree, pESD))>=0) {
251 // TODO: set the specification correctly
253 // the esd structure is written to the user info and is
254 // needed in te ReadFromTree method to read all objects correctly
255 pTree->GetUserInfo()->Add(pESD);
256 pESD->WriteToTree(pTree);
257 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginOut, 0);
259 iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginOut, 0);
263 // clear user info list to prevent objects from being deleted
264 pTree->GetUserInfo()->Clear();
270 int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD)
272 // see header file for class documentation
275 int iAddedDataBlocks=0;
279 // in the first attempt this component reads the TPC tracks and updates in the
280 // second step from the ITS tracks
283 // first read MC information (if present)
284 std::map<int,int> mcLabels;
286 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC);
287 pBlock!=NULL; pBlock=GetNextInputBlock()) {
288 AliHLTTrackMCData* dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr );
289 if (sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize) {
290 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
291 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
292 mcLabels[lab.fTrackID] = lab.fMCLabel;
295 HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information",
296 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification,
297 dataPtr->fCount, pBlock->fSize);
301 // convert the TPC tracks to ESD tracks
302 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
303 pBlock!=NULL; pBlock=GetNextInputBlock()) {
304 vector<AliHLTGlobalBarrelTrack> tracks;
305 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>=0) {
306 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
307 element!=tracks.end(); element++) {
308 Float_t points[4] = {
311 element->GetLastPointX(),
312 element->GetLastPointY()
316 if( mcLabels.find(element->TrackID())!=mcLabels.end() )
317 mcLabel = mcLabels[element->TrackID()];
318 element->SetLabel( mcLabel );
322 // for the moment, the number of clusters are not set when processing the
323 // kTPCin update, only at kTPCout
324 // there ar emainly three parameters updated for kTPCout
325 // number of clusters
328 // The first one can be updated already at that stage here, while the two others
329 // eventually require to update from the ITS tracks before. The exact scheme
330 // needs to be checked
331 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCin);
332 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCout);
333 iotrack.SetTPCPoints(points);
335 pESD->AddTrack(&iotrack);
336 if (fVerbosity>0) element->Print();
338 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
340 } else if (iResult<0) {
341 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
342 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
346 // now update ESD tracks with the ITS info
347 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITS);
348 pBlock!=NULL; pBlock=GetNextInputBlock()) {
349 vector<AliHLTGlobalBarrelTrack> tracks;
350 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
351 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
352 element!=tracks.end(); element++) {
354 const UInt_t* pointsArray=element->GetPoints();
355 for( unsigned il=0; il<element->GetNumberOfPoints(); il++ ){
356 // TODO: check what needs to be done with the clusters
357 if( pointsArray[il]<~(UInt_t)0 ) {/*tITS.SetClusterIndex(ncl, tr.fClusterIds[il]);*/}
360 //tITS.SetNumberOfClusters( ncl );
361 int tpcID=element->TrackID();
362 // the ITS tracker assigns the TPC track used as seed for a certain track to
364 if( tpcID<0 || tpcID>=pESD->GetNumberOfTracks()) continue;
366 AliESDtrack *tESD = pESD->GetTrack( tpcID );
367 if( tESD ) tESD->UpdateTrackParams( &(*element), AliESDtrack::kITSin );
372 // convert the HLT TRD tracks to ESD tracks
373 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack | kAliHLTDataOriginTRD);
374 pBlock!=NULL; pBlock=GetNextInputBlock()) {
375 vector<AliHLTGlobalBarrelTrack> tracks;
376 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
377 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
378 element!=tracks.end(); element++) {
380 Double_t TRDpid[AliPID::kSPECIES], eProb(0.2), restProb((1-eProb)/(AliPID::kSPECIES-1)); //eprob(element->GetTRDpid...);
381 for(Int_t i=0; i<AliPID::kSPECIES; i++){
383 case AliPID::kElectron: TRDpid[AliPID::kElectron]=eProb; break;
384 default: TRDpid[i]=restProb; break;
389 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTRDin);
390 iotrack.SetTRDpid(TRDpid);
392 pESD->AddTrack(&iotrack);
393 if (fVerbosity>0) element->Print();
395 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
397 } else if (iResult<0) {
398 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
399 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
402 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeCaloCluster | kAliHLTDataOriginPHOS); pBlock!=NULL; pBlock=GetNextInputBlock())
404 AliHLTCaloClusterHeaderStruct *caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
406 HLTDebug("%d HLT clusters from spec: 0x%X", caloClusterHeaderPtr->fNClusters, pBlock->fSpecification);
408 AliHLTCaloClusterReader reader;
409 reader.SetMemory(caloClusterHeaderPtr);
411 AliHLTESDCaloClusterMaker clusterMaker;
413 int nClusters = clusterMaker.FillESD(pESD, caloClusterHeaderPtr);
415 HLTInfo("converted %d cluster(s) to AliESDCaloCluster and added to ESD", nClusters);
419 // primary vertex & V0's
421 //AliHLTVertexer vertexer;
422 //vertexer.SetESD( pESD );
423 //vertexer.FindPrimaryVertex();
424 //vertexer.FindV0s();
426 if (iAddedDataBlocks>0 && pTree) {
430 if (iResult>=0) iResult=iAddedDataBlocks;