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 "AliESDEvent.h"
37 #include "AliESDtrack.h"
38 #include "AliCDBEntry.h"
39 #include "AliCDBManager.h"
43 #include "AliHLTESDCaloClusterMaker.h"
44 #include "AliHLTCaloClusterDataStruct.h"
45 #include "AliHLTCaloClusterReader.h"
46 #include "AliESDCaloCluster.h"
48 /** ROOT macro for the implementation of ROOT specific class methods */
49 ClassImp(AliHLTGlobalEsdConverterComponent)
51 AliHLTGlobalEsdConverterComponent::AliHLTGlobalEsdConverterComponent()
58 // see header file for class documentation
60 // refer to README to build package
62 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
65 AliHLTGlobalEsdConverterComponent::~AliHLTGlobalEsdConverterComponent()
67 // see header file for class documentation
68 if (fESD) delete fESD;
72 int AliHLTGlobalEsdConverterComponent::Configure(const char* arguments)
74 // see header file for class documentation
76 if (!arguments) return iResult;
78 TString allArgs=arguments;
82 TObjArray* pTokens=allArgs.Tokenize(" ");
84 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
85 argument=((TObjString*)pTokens->At(i))->GetString();
86 if (argument.IsNull()) continue;
88 if (argument.CompareTo("-solenoidBz")==0) {
89 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
90 HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
91 fSolenoidBz=((TObjString*)pTokens->At(i))->GetString().Atof();
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=kAliHLTCDBSolenoidBz;
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);
146 AliHLTComponentDataType AliHLTGlobalEsdConverterComponent::GetOutputDataType()
148 // see header file for class documentation
149 return kAliHLTDataTypeESDObject|kAliHLTDataOriginOut;
152 void AliHLTGlobalEsdConverterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
154 // see header file for class documentation
156 inputMultiplier=10.0;
159 int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
161 // see header file for class documentation
165 for (int i=0; i<argc && iResult>=0; i++) {
167 if (argument.IsNull()) continue;
170 if (argument.CompareTo("-notree")==0) {
174 } else if (argument.CompareTo("-tree")==0) {
178 HLTError("unknown argument %s", argument.Data());
183 HLTError("missing parameter for argument %s", argument.Data());
188 iResult=Reconfigure(NULL, NULL);
192 fESD = new AliESDEvent;
194 fESD->CreateStdContent();
203 int AliHLTGlobalEsdConverterComponent::DoDeinit()
205 // see header file for class documentation
206 if (fESD) delete fESD;
212 int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
213 AliHLTComponentTriggerData& /*trigData*/)
215 // see header file for class documentation
217 if (!fESD) return -ENODEV;
219 AliESDEvent* pESD = fESD;
222 pESD->SetMagneticField(fSolenoidBz);
223 pESD->SetPeriodNumber(GetPeriodNumber());
224 pESD->SetOrbitNumber(GetOrbitNumber());
225 pESD->SetBunchCrossNumber(GetBunchCrossNumber());
226 pESD->SetTimeStamp(GetTimeStamp());
230 pTree = new TTree("esdTree", "Tree with HLT ESD objects");
233 pTree->SetDirectory(0);
236 if ((iResult=ProcessBlocks(pTree, pESD))>=0) {
237 // TODO: set the specification correctly
239 // the esd structure is written to the user info and is
240 // needed in te ReadFromTree method to read all objects correctly
241 pTree->GetUserInfo()->Add(pESD);
242 pESD->WriteToTree(pTree);
243 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginOut, 0);
245 iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginOut, 0);
249 // clear user info list to prevent objects from being deleted
250 pTree->GetUserInfo()->Clear();
256 int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD)
258 // see header file for class documentation
261 int iAddedDataBlocks=0;
265 // in the first attempt this component reads the TPC tracks and updates in the
266 // second step from the ITS tracks
269 // first read MC information (if present)
270 std::map<int,int> mcLabels;
272 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC);
273 pBlock!=NULL; pBlock=GetNextInputBlock()) {
274 AliHLTTrackMCData* dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr );
275 if (sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize) {
276 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
277 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
278 mcLabels[lab.fTrackID] = lab.fMCLabel;
281 HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information",
282 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification,
283 dataPtr->fCount, pBlock->fSize);
287 // convert the TPC tracks to ESD tracks
288 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
289 pBlock!=NULL; pBlock=GetNextInputBlock()) {
290 vector<AliHLTGlobalBarrelTrack> tracks;
291 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>=0) {
292 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
293 element!=tracks.end(); element++) {
294 Float_t points[4] = {
297 element->GetLastPointX(),
298 element->GetLastPointY()
302 if( mcLabels.find(element->TrackID())!=mcLabels.end() )
303 mcLabel = mcLabels[element->TrackID()];
304 element->SetLabel( mcLabel );
307 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCin);
308 iotrack.SetTPCPoints(points);
310 pESD->AddTrack(&iotrack);
311 if (fVerbosity>0) element->Print();
313 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
315 } else if (iResult<0) {
316 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
317 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
321 // now update ESD tracks with the ITS info
322 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITS);
323 pBlock!=NULL; pBlock=GetNextInputBlock()) {
324 vector<AliHLTGlobalBarrelTrack> tracks;
325 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
326 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
327 element!=tracks.end(); element++) {
329 const UInt_t* pointsArray=element->GetPoints();
330 for( unsigned il=0; il<element->GetNumberOfPoints(); il++ ){
331 // TODO: check what needs to be done with the clusters
332 if( pointsArray[il]<~(UInt_t)0 ) {/*tITS.SetClusterIndex(ncl, tr.fClusterIds[il]);*/}
335 //tITS.SetNumberOfClusters( ncl );
336 int tpcID=element->TrackID();
337 // the ITS tracker assigns the TPC track used as seed for a certain track to
339 if( tpcID<0 || tpcID>=pESD->GetNumberOfTracks()) continue;
341 AliESDtrack *tESD = pESD->GetTrack( tpcID );
342 if( tESD ) tESD->UpdateTrackParams( &(*element), AliESDtrack::kITSin );
347 // convert the HLT TRD tracks to ESD tracks
348 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack | kAliHLTDataOriginTRD);
349 pBlock!=NULL; pBlock=GetNextInputBlock()) {
350 vector<AliHLTGlobalBarrelTrack> tracks;
351 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
352 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
353 element!=tracks.end(); element++) {
355 Double_t TRDpid[AliPID::kSPECIES], eProb(0.2), restProb((1-eProb)/(AliPID::kSPECIES-1)); //eprob(element->GetTRDpid...);
356 for(Int_t i=0; i<AliPID::kSPECIES; i++){
358 case AliPID::kElectron: TRDpid[AliPID::kElectron]=eProb; break;
359 default: TRDpid[i]=restProb; break;
364 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTRDin);
365 iotrack.SetTRDpid(TRDpid);
367 pESD->AddTrack(&iotrack);
368 if (fVerbosity>0) element->Print();
370 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
372 } else if (iResult<0) {
373 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
374 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
377 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeCaloCluster | kAliHLTDataOriginPHOS); pBlock!=NULL; pBlock=GetNextInputBlock())
379 AliHLTCaloClusterHeaderStruct *caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
381 HLTDebug("%d HLT clusters from spec: 0x%X", caloClusterHeaderPtr->fNClusters, pBlock->fSpecification);
383 AliHLTCaloClusterReader reader;
384 reader.SetMemory(caloClusterHeaderPtr);
386 AliHLTESDCaloClusterMaker clusterMaker;
388 int nClusters = clusterMaker.FillESD(pESD, caloClusterHeaderPtr);
390 HLTInfo("converted %d cluster(s) to AliESDCaloCluster and added to ESD", nClusters);
394 // primary vertex & V0's
396 //AliHLTVertexer vertexer;
397 //vertexer.SetESD( pESD );
398 //vertexer.FindPrimaryVertex();
399 //vertexer.FindV0s();
401 if (iAddedDataBlocks>0 && pTree) {
405 if (iResult>=0) iResult=iAddedDataBlocks;