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"
50 /** ROOT macro for the implementation of ROOT specific class methods */
51 ClassImp(AliHLTGlobalEsdConverterComponent)
53 AliHLTGlobalEsdConverterComponent::AliHLTGlobalEsdConverterComponent()
58 , fSolenoidBz(-5.00668)
59 , fFillVtxConstrainedTracks( 0 )
61 // see header file for class documentation
63 // refer to README to build package
65 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
68 AliHLTGlobalEsdConverterComponent::~AliHLTGlobalEsdConverterComponent()
70 // see header file for class documentation
71 if (fESD) delete fESD;
75 int AliHLTGlobalEsdConverterComponent::Configure(const char* arguments)
77 // see header file for class documentation
79 if (!arguments) return iResult;
81 TString allArgs=arguments;
85 TObjArray* pTokens=allArgs.Tokenize(" ");
87 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
88 argument=((TObjString*)pTokens->At(i))->GetString();
89 if (argument.IsNull()) continue;
91 if (argument.CompareTo("-solenoidBz")==0) {
92 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
93 HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
94 fSolenoidBz=((TObjString*)pTokens->At(i))->GetString().Atof();
97 else if (argument.CompareTo("-fitTracks2Vertex")==0) {
98 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
99 HLTInfo("Filling of vertex constrained tracks is set set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
100 fFillVtxConstrainedTracks=((TObjString*)pTokens->At(i))->GetString().Atoi();
103 HLTError("unknown argument %s", argument.Data());
111 HLTError("missing parameter for argument %s", argument.Data());
118 int AliHLTGlobalEsdConverterComponent::Reconfigure(const char* cdbEntry, const char* chainId)
120 // see header file for class documentation
122 const char* path=kAliHLTCDBSolenoidBz;
123 const char* defaultNotify="";
126 defaultNotify=" (default)";
129 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
130 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
132 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
134 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
135 iResult=Configure(pString->GetString().Data());
137 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
140 HLTError("can not fetch object \"%s\" from CDB", path);
147 void AliHLTGlobalEsdConverterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
149 // see header file for class documentation
150 list.push_back(kAliHLTDataTypeTrack);
151 list.push_back(kAliHLTDataTypeTrackMC);
152 list.push_back(kAliHLTDataTypeCaloCluster);
155 AliHLTComponentDataType AliHLTGlobalEsdConverterComponent::GetOutputDataType()
157 // see header file for class documentation
158 return kAliHLTDataTypeESDObject|kAliHLTDataOriginOut;
161 void AliHLTGlobalEsdConverterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
163 // see header file for class documentation
165 inputMultiplier=10.0;
168 int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
170 // see header file for class documentation
174 for (int i=0; i<argc && iResult>=0; i++) {
176 if (argument.IsNull()) continue;
179 if (argument.CompareTo("-notree")==0) {
183 } else if (argument.CompareTo("-tree")==0) {
187 HLTError("unknown argument %s", argument.Data());
192 HLTError("missing parameter for argument %s", argument.Data());
197 iResult=Reconfigure(NULL, NULL);
201 fESD = new AliESDEvent;
203 fESD->CreateStdContent();
214 int AliHLTGlobalEsdConverterComponent::DoDeinit()
216 // see header file for class documentation
217 if (fESD) delete fESD;
223 int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
224 AliHLTComponentTriggerData& trigData)
226 // see header file for class documentation
228 if (!fESD) return -ENODEV;
230 AliESDEvent* pESD = fESD;
233 pESD->SetMagneticField(fSolenoidBz);
234 pESD->SetRunNumber(GetRunNo());
235 pESD->SetPeriodNumber(GetPeriodNumber());
236 pESD->SetOrbitNumber(GetOrbitNumber());
237 pESD->SetBunchCrossNumber(GetBunchCrossNumber());
238 pESD->SetTimeStamp(GetTimeStamp());
240 const AliHLTCTPData* pCTPData=CTPData();
242 AliHLTUInt64_t mask=pCTPData->ActiveTriggers(trigData);
243 for (int index=0; index<gkNCTPTriggerClasses; index++) {
244 if ((mask&((AliHLTUInt64_t)0x1<<index)) == 0) continue;
245 pESD->SetTriggerClass(pCTPData->Name(index), index);
247 pESD->SetTriggerMask(mask);
252 pTree = new TTree("esdTree", "Tree with HLT ESD objects");
255 pTree->SetDirectory(0);
258 if ((iResult=ProcessBlocks(pTree, pESD))>=0) {
259 // TODO: set the specification correctly
261 // the esd structure is written to the user info and is
262 // needed in te ReadFromTree method to read all objects correctly
263 pTree->GetUserInfo()->Add(pESD);
264 pESD->WriteToTree(pTree);
265 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginOut, 0);
267 iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginOut, 0);
271 // clear user info list to prevent objects from being deleted
272 pTree->GetUserInfo()->Clear();
278 int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD)
280 // see header file for class documentation
283 int iAddedDataBlocks=0;
287 // in the first attempt this component reads the TPC tracks and updates in the
288 // second step from the ITS tracks
291 // first read MC information (if present)
292 std::map<int,int> mcLabels;
294 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC);
295 pBlock!=NULL; pBlock=GetNextInputBlock()) {
296 AliHLTTrackMCData* dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr );
297 if (sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize) {
298 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
299 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
300 mcLabels[lab.fTrackID] = lab.fMCLabel;
303 HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information",
304 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification,
305 dataPtr->fCount, pBlock->fSize);
309 // convert the TPC tracks to ESD tracks
310 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
311 pBlock!=NULL; pBlock=GetNextInputBlock()) {
312 vector<AliHLTGlobalBarrelTrack> tracks;
313 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>=0) {
314 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
315 element!=tracks.end(); element++) {
316 Float_t points[4] = {
319 element->GetLastPointX(),
320 element->GetLastPointY()
324 if( mcLabels.find(element->TrackID())!=mcLabels.end() )
325 mcLabel = mcLabels[element->TrackID()];
326 element->SetLabel( mcLabel );
330 // for the moment, the number of clusters are not set when processing the
331 // kTPCin update, only at kTPCout
332 // there ar emainly three parameters updated for kTPCout
333 // number of clusters
336 // The first one can be updated already at that stage here, while the two others
337 // eventually require to update from the ITS tracks before. The exact scheme
338 // needs to be checked
339 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCin);
340 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCout);
341 iotrack.SetTPCPoints(points);
343 pESD->AddTrack(&iotrack);
344 if (fVerbosity>0) element->Print();
346 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
348 } else if (iResult<0) {
349 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
350 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
354 // now update ESD tracks with the ITS info
355 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITS);
356 pBlock!=NULL; pBlock=GetNextInputBlock()) {
357 vector<AliHLTGlobalBarrelTrack> tracks;
358 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
359 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
360 element!=tracks.end(); element++) {
362 const UInt_t* pointsArray=element->GetPoints();
363 for( unsigned il=0; il<element->GetNumberOfPoints(); il++ ){
364 // TODO: check what needs to be done with the clusters
365 if( pointsArray[il]<~(UInt_t)0 ) {/*tITS.SetClusterIndex(ncl, tr.fClusterIds[il]);*/}
368 //tITS.SetNumberOfClusters( ncl );
369 int tpcID=element->TrackID();
370 // the ITS tracker assigns the TPC track used as seed for a certain track to
372 if( tpcID<0 || tpcID>=pESD->GetNumberOfTracks()) continue;
374 AliESDtrack *tESD = pESD->GetTrack( tpcID );
375 if( tESD ) tESD->UpdateTrackParams( &(*element), AliESDtrack::kITSin );
380 // convert the HLT TRD tracks to ESD tracks
381 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack | kAliHLTDataOriginTRD);
382 pBlock!=NULL; pBlock=GetNextInputBlock()) {
383 vector<AliHLTGlobalBarrelTrack> tracks;
384 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
385 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
386 element!=tracks.end(); element++) {
388 Double_t TRDpid[AliPID::kSPECIES], eProb(0.2), restProb((1-eProb)/(AliPID::kSPECIES-1)); //eprob(element->GetTRDpid...);
389 for(Int_t i=0; i<AliPID::kSPECIES; i++){
391 case AliPID::kElectron: TRDpid[AliPID::kElectron]=eProb; break;
392 default: TRDpid[i]=restProb; break;
397 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTRDin);
398 iotrack.SetTRDpid(TRDpid);
400 pESD->AddTrack(&iotrack);
401 if (fVerbosity>0) element->Print();
403 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
405 } else if (iResult<0) {
406 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
407 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
410 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeCaloCluster | kAliHLTDataOriginPHOS); pBlock!=NULL; pBlock=GetNextInputBlock())
412 AliHLTCaloClusterHeaderStruct *caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
414 HLTDebug("%d HLT clusters from spec: 0x%X", caloClusterHeaderPtr->fNClusters, pBlock->fSpecification);
416 AliHLTCaloClusterReader reader;
417 reader.SetMemory(caloClusterHeaderPtr);
419 AliHLTESDCaloClusterMaker clusterMaker;
421 int nClusters = clusterMaker.FillESD(pESD, caloClusterHeaderPtr);
423 HLTInfo("converted %d cluster(s) to AliESDCaloCluster and added to ESD", nClusters);
427 // primary vertex & V0's
429 AliHLTVertexer vertexer;
430 vertexer.SetESD( pESD );
431 vertexer.FindPrimaryVertex();
434 // relate the tracks to vertex
435 if( fFillVtxConstrainedTracks ){
436 for( Int_t i = 0; i<pESD->GetNumberOfTracks(); i++){
437 if( !vertexer.TrackInfos()[i].fPrimUsedFlag ) continue;
438 pESD->GetTrack(i)->RelateToVertex( pESD->GetPrimaryVertex(), fESD->GetMagneticField(),5. );
442 if (iAddedDataBlocks>0 && pTree) {
446 if (iResult>=0) iResult=iAddedDataBlocks;