]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/global/AliHLTGlobalEsdConverterComponent.cxx
vertex finder moved from GlobalESDConverter to a separate component GlobalVertexer
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalEsdConverterComponent.cxx
CommitLineData
a1408c4b 1// $Id$
2
3//**************************************************************************
4//* This file is property of and copyright by the ALICE HLT Project *
5//* ALICE Experiment at CERN, All rights reserved. *
6//* *
7//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8//* for The ALICE HLT Project. *
9//* *
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//**************************************************************************
18
19/** @file AliHLTGlobalEsdConverterComponent.cxx
20 @author Matthias Richter
21 @date
22 @brief Global ESD converter component.
23*/
24
25// see header file for class documentation
26// or
27// refer to README to build package
28// or
29// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30
31#include <cassert>
32#include "AliHLTGlobalEsdConverterComponent.h"
33#include "AliHLTGlobalBarrelTrack.h"
34#include "AliHLTExternalTrackParam.h"
093b64dc 35#include "AliHLTTrackMCLabel.h"
6117ef63 36#include "AliHLTCTPData.h"
a1408c4b 37#include "AliESDEvent.h"
38#include "AliESDtrack.h"
39#include "AliCDBEntry.h"
40#include "AliCDBManager.h"
18ada816 41#include "AliPID.h"
a1408c4b 42#include "TTree.h"
43#include "TList.h"
9a9467ed 44#include "AliHLTESDCaloClusterMaker.h"
45#include "AliHLTCaloClusterDataStruct.h"
46#include "AliHLTCaloClusterReader.h"
47#include "AliESDCaloCluster.h"
a1408c4b 48
49/** ROOT macro for the implementation of ROOT specific class methods */
50ClassImp(AliHLTGlobalEsdConverterComponent)
51
52AliHLTGlobalEsdConverterComponent::AliHLTGlobalEsdConverterComponent()
53 : AliHLTProcessor()
a1408c4b 54 , fWriteTree(0)
093b64dc 55 , fVerbosity(0)
8b7a0f3c 56 , fESD(NULL)
a8714ffa 57 , fSolenoidBz(-5.00668)
a1408c4b 58{
59 // see header file for class documentation
60 // or
61 // refer to README to build package
62 // or
63 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
64}
65
66AliHLTGlobalEsdConverterComponent::~AliHLTGlobalEsdConverterComponent()
67{
68 // see header file for class documentation
69 if (fESD) delete fESD;
70 fESD=NULL;
71}
72
73int AliHLTGlobalEsdConverterComponent::Configure(const char* arguments)
74{
75 // see header file for class documentation
76 int iResult=0;
77 if (!arguments) return iResult;
78
79 TString allArgs=arguments;
80 TString argument;
81 int bMissingParam=0;
82
83 TObjArray* pTokens=allArgs.Tokenize(" ");
84 if (pTokens) {
85 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
fe0af255 86 argument=((TObjString*)pTokens->At(i))->GetString();
a1408c4b 87 if (argument.IsNull()) continue;
88
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();
93 continue;
94 } else {
95 HLTError("unknown argument %s", argument.Data());
96 iResult=-EINVAL;
97 break;
98 }
99 }
100 delete pTokens;
101 }
102 if (bMissingParam) {
103 HLTError("missing parameter for argument %s", argument.Data());
104 iResult=-EINVAL;
105 }
106
107 return iResult;
108}
109
110int AliHLTGlobalEsdConverterComponent::Reconfigure(const char* cdbEntry, const char* chainId)
111{
112 // see header file for class documentation
113 int iResult=0;
114 const char* path=kAliHLTCDBSolenoidBz;
115 const char* defaultNotify="";
116 if (cdbEntry) {
117 path=cdbEntry;
118 defaultNotify=" (default)";
119 }
120 if (path) {
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()*/);
123 if (pEntry) {
124 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
125 if (pString) {
126 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
127 iResult=Configure(pString->GetString().Data());
128 } else {
129 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
130 }
131 } else {
132 HLTError("can not fetch object \"%s\" from CDB", path);
133 }
134 }
135
136 return iResult;
137}
138
139void AliHLTGlobalEsdConverterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
140{
141 // see header file for class documentation
142 list.push_back(kAliHLTDataTypeTrack);
143 list.push_back(kAliHLTDataTypeTrackMC);
9a9467ed 144 list.push_back(kAliHLTDataTypeCaloCluster);
0973c527 145 list.push_back(kAliHLTDataTypedEdx );
a1408c4b 146}
147
148AliHLTComponentDataType AliHLTGlobalEsdConverterComponent::GetOutputDataType()
149{
150 // see header file for class documentation
7a9de6d1 151 return kAliHLTDataTypeESDObject|kAliHLTDataOriginOut;
a1408c4b 152}
153
154void AliHLTGlobalEsdConverterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
155{
156 // see header file for class documentation
157 constBase=2000000;
158 inputMultiplier=10.0;
159}
160
161int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
162{
163 // see header file for class documentation
164 int iResult=0;
165 TString argument="";
166 int bMissingParam=0;
167 for (int i=0; i<argc && iResult>=0; i++) {
168 argument=argv[i];
169 if (argument.IsNull()) continue;
170
171 // -notree
172 if (argument.CompareTo("-notree")==0) {
173 fWriteTree=0;
174
175 // -tree
176 } else if (argument.CompareTo("-tree")==0) {
177 fWriteTree=1;
a1408c4b 178 } else {
179 HLTError("unknown argument %s", argument.Data());
180 break;
181 }
182 }
183 if (bMissingParam) {
184 HLTError("missing parameter for argument %s", argument.Data());
185 iResult=-EINVAL;
186 }
187
188 if (iResult>=0) {
189 iResult=Reconfigure(NULL, NULL);
190 }
191
192 if (iResult>=0) {
193 fESD = new AliESDEvent;
194 if (fESD) {
195 fESD->CreateStdContent();
196 } else {
197 iResult=-ENOMEM;
198 }
6117ef63 199
200 SetupCTPData();
a1408c4b 201 }
202
203 return iResult;
204}
205
206int AliHLTGlobalEsdConverterComponent::DoDeinit()
207{
208 // see header file for class documentation
209 if (fESD) delete fESD;
210 fESD=NULL;
211
212 return 0;
213}
214
215int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
6117ef63 216 AliHLTComponentTriggerData& trigData)
a1408c4b 217{
218 // see header file for class documentation
219 int iResult=0;
220 if (!fESD) return -ENODEV;
221
222 AliESDEvent* pESD = fESD;
223
224 pESD->Reset();
225 pESD->SetMagneticField(fSolenoidBz);
6117ef63 226 pESD->SetRunNumber(GetRunNo());
6700298e 227 pESD->SetPeriodNumber(GetPeriodNumber());
228 pESD->SetOrbitNumber(GetOrbitNumber());
229 pESD->SetBunchCrossNumber(GetBunchCrossNumber());
230 pESD->SetTimeStamp(GetTimeStamp());
a1408c4b 231
6117ef63 232 const AliHLTCTPData* pCTPData=CTPData();
233 if (pCTPData) {
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);
238 }
239 pESD->SetTriggerMask(mask);
240 }
241
a1408c4b 242 TTree* pTree = NULL;
243 if (fWriteTree)
244 pTree = new TTree("esdTree", "Tree with HLT ESD objects");
245
246 if (pTree) {
247 pTree->SetDirectory(0);
248 }
249
81509fd3 250 if ((iResult=ProcessBlocks(pTree, pESD))>=0) {
a1408c4b 251 // TODO: set the specification correctly
252 if (pTree) {
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);
7a9de6d1 257 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginOut, 0);
a1408c4b 258 } else {
7a9de6d1 259 iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginOut, 0);
a1408c4b 260 }
261 }
262 if (pTree) {
263 // clear user info list to prevent objects from being deleted
264 pTree->GetUserInfo()->Clear();
265 delete pTree;
266 }
267 return iResult;
268}
269
270int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD)
271{
272 // see header file for class documentation
273
274 int iResult=0;
275 int iAddedDataBlocks=0;
276
277 // Barrel tracking
278
279 // in the first attempt this component reads the TPC tracks and updates in the
280 // second step from the ITS tracks
093b64dc 281
282
283 // first read MC information (if present)
284 std::map<int,int> mcLabels;
285
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;
293 }
294 } else {
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);
298 }
299 }
300
0973c527 301 // read dEdx information (if present)
302
303 AliHLTFloat32_t *dEdxTPC = 0;
304 Int_t ndEdxTPC = 0;
305 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypedEdx|kAliHLTDataOriginTPC);
306 pBlock!=NULL; pBlock=GetNextInputBlock()) {
307 dEdxTPC = reinterpret_cast<AliHLTFloat32_t*>( pBlock->fPtr );
308 ndEdxTPC = pBlock->fSize / sizeof(AliHLTFloat32_t);
309 break;
310 }
311
cd60a73f 312 // convert the TPC tracks to ESD tracks
a1408c4b 313 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
314 pBlock!=NULL; pBlock=GetNextInputBlock()) {
315 vector<AliHLTGlobalBarrelTrack> tracks;
81509fd3 316 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>=0) {
a1408c4b 317 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
318 element!=tracks.end(); element++) {
319 Float_t points[4] = {
320 element->GetX(),
321 element->GetY(),
322 element->GetLastPointX(),
323 element->GetLastPointY()
324 };
093b64dc 325
326 Int_t mcLabel = -1;
327 if( mcLabels.find(element->TrackID())!=mcLabels.end() )
328 mcLabel = mcLabels[element->TrackID()];
329 element->SetLabel( mcLabel );
330
a1408c4b 331 AliESDtrack iotrack;
550ecaab 332
333 // for the moment, the number of clusters are not set when processing the
334 // kTPCin update, only at kTPCout
335 // there ar emainly three parameters updated for kTPCout
336 // number of clusters
337 // chi2
338 // pid signal
339 // The first one can be updated already at that stage here, while the two others
340 // eventually require to update from the ITS tracks before. The exact scheme
341 // needs to be checked
a1408c4b 342 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCin);
550ecaab 343 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCout);
a1408c4b 344 iotrack.SetTPCPoints(points);
0973c527 345 if( element->TrackID()<ndEdxTPC ){
7e32fedf 346 iotrack.SetTPCsignal( dEdxTPC[element->TrackID()], 0, 0 );
347 //AliTPCseed s;
348 //s.Set( element->GetX(), element->GetAlpha(),
349 //element->GetParameter(), element->GetCovariance() );
350 //s.SetdEdx( dEdxTPC[element->TrackID()] );
351 //s.CookPID();
352 //iotrack.SetTPCpid(s.TPCrPIDs() );
0973c527 353 } else {
354 if( dEdxTPC ) HLTWarning("Wrong number of dEdx TPC labels");
355 }
a1408c4b 356 pESD->AddTrack(&iotrack);
093b64dc 357 if (fVerbosity>0) element->Print();
a1408c4b 358 }
093b64dc 359 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
a1408c4b 360 iAddedDataBlocks++;
361 } else if (iResult<0) {
093b64dc 362 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
363 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
a1408c4b 364 }
365 }
366
cd60a73f 367 // now update ESD tracks with the ITS info
af3250a3 368 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITS);
cd60a73f 369 pBlock!=NULL; pBlock=GetNextInputBlock()) {
370 vector<AliHLTGlobalBarrelTrack> tracks;
371 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
372 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
373 element!=tracks.end(); element++) {
374 int ncl=0;
375 const UInt_t* pointsArray=element->GetPoints();
376 for( unsigned il=0; il<element->GetNumberOfPoints(); il++ ){
377 // TODO: check what needs to be done with the clusters
378 if( pointsArray[il]<~(UInt_t)0 ) {/*tITS.SetClusterIndex(ncl, tr.fClusterIds[il]);*/}
379 ncl++;
a1408c4b 380 }
cd60a73f 381 //tITS.SetNumberOfClusters( ncl );
382 int tpcID=element->TrackID();
383 // the ITS tracker assigns the TPC track used as seed for a certain track to
384 // the trackID
385 if( tpcID<0 || tpcID>=pESD->GetNumberOfTracks()) continue;
386
387 AliESDtrack *tESD = pESD->GetTrack( tpcID );
388 if( tESD ) tESD->UpdateTrackParams( &(*element), AliESDtrack::kITSin );
a1408c4b 389 }
cd60a73f 390 }
391 }
18ada816 392
393 // convert the HLT TRD tracks to ESD tracks
394 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack | kAliHLTDataOriginTRD);
395 pBlock!=NULL; pBlock=GetNextInputBlock()) {
396 vector<AliHLTGlobalBarrelTrack> tracks;
397 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
398 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
399 element!=tracks.end(); element++) {
400
401 Double_t TRDpid[AliPID::kSPECIES], eProb(0.2), restProb((1-eProb)/(AliPID::kSPECIES-1)); //eprob(element->GetTRDpid...);
402 for(Int_t i=0; i<AliPID::kSPECIES; i++){
403 switch(i){
404 case AliPID::kElectron: TRDpid[AliPID::kElectron]=eProb; break;
405 default: TRDpid[i]=restProb; break;
406 }
407 }
408
409 AliESDtrack iotrack;
410 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTRDin);
411 iotrack.SetTRDpid(TRDpid);
412
413 pESD->AddTrack(&iotrack);
414 if (fVerbosity>0) element->Print();
415 }
416 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
417 iAddedDataBlocks++;
418 } else if (iResult<0) {
419 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
420 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
421 }
422 }
9a9467ed 423 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeCaloCluster | kAliHLTDataOriginPHOS); pBlock!=NULL; pBlock=GetNextInputBlock())
424 {
425 AliHLTCaloClusterHeaderStruct *caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
426
427 HLTDebug("%d HLT clusters from spec: 0x%X", caloClusterHeaderPtr->fNClusters, pBlock->fSpecification);
428
429 AliHLTCaloClusterReader reader;
430 reader.SetMemory(caloClusterHeaderPtr);
431
432 AliHLTESDCaloClusterMaker clusterMaker;
433
434 int nClusters = clusterMaker.FillESD(pESD, caloClusterHeaderPtr);
435
436 HLTInfo("converted %d cluster(s) to AliESDCaloCluster and added to ESD", nClusters);
437 iAddedDataBlocks++;
438 }
a1408c4b 439
4d5ee3db 440
a1408c4b 441 if (iAddedDataBlocks>0 && pTree) {
cd60a73f 442 pTree->Fill();
a1408c4b 443 }
444
445 if (iResult>=0) iResult=iAddedDataBlocks;
446 return iResult;
447}