]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/global/AliHLTGlobalEsdConverterComponent.cxx
Creation of vertex constrained track parameters is moved to AliHLTVertexer,
[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"
9334b5cb 48#include "AliHLTVertexer.h"
7e32fedf 49//#include "AliTPCseed.h"
a1408c4b 50
51/** ROOT macro for the implementation of ROOT specific class methods */
52ClassImp(AliHLTGlobalEsdConverterComponent)
53
54AliHLTGlobalEsdConverterComponent::AliHLTGlobalEsdConverterComponent()
55 : AliHLTProcessor()
a1408c4b 56 , fWriteTree(0)
093b64dc 57 , fVerbosity(0)
8b7a0f3c 58 , fESD(NULL)
a8714ffa 59 , fSolenoidBz(-5.00668)
36d0f159 60 , fFillVtxConstrainedTracks( 0 )
a1408c4b 61{
62 // see header file for class documentation
63 // or
64 // refer to README to build package
65 // or
66 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
67}
68
69AliHLTGlobalEsdConverterComponent::~AliHLTGlobalEsdConverterComponent()
70{
71 // see header file for class documentation
72 if (fESD) delete fESD;
73 fESD=NULL;
74}
75
76int AliHLTGlobalEsdConverterComponent::Configure(const char* arguments)
77{
78 // see header file for class documentation
79 int iResult=0;
80 if (!arguments) return iResult;
81
82 TString allArgs=arguments;
83 TString argument;
84 int bMissingParam=0;
85
86 TObjArray* pTokens=allArgs.Tokenize(" ");
87 if (pTokens) {
88 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
fe0af255 89 argument=((TObjString*)pTokens->At(i))->GetString();
a1408c4b 90 if (argument.IsNull()) continue;
91
92 if (argument.CompareTo("-solenoidBz")==0) {
93 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
94 HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
95 fSolenoidBz=((TObjString*)pTokens->At(i))->GetString().Atof();
96 continue;
36d0f159 97 }
fe0af255 98 else if (argument.CompareTo("-fitTracksToVertex")==0) {
36d0f159 99 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
100 HLTInfo("Filling of vertex constrained tracks is set set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
101 fFillVtxConstrainedTracks=((TObjString*)pTokens->At(i))->GetString().Atoi();
102 continue;
a1408c4b 103 } else {
104 HLTError("unknown argument %s", argument.Data());
105 iResult=-EINVAL;
106 break;
107 }
108 }
109 delete pTokens;
110 }
111 if (bMissingParam) {
112 HLTError("missing parameter for argument %s", argument.Data());
113 iResult=-EINVAL;
114 }
115
116 return iResult;
117}
118
119int AliHLTGlobalEsdConverterComponent::Reconfigure(const char* cdbEntry, const char* chainId)
120{
121 // see header file for class documentation
122 int iResult=0;
123 const char* path=kAliHLTCDBSolenoidBz;
124 const char* defaultNotify="";
125 if (cdbEntry) {
126 path=cdbEntry;
127 defaultNotify=" (default)";
128 }
129 if (path) {
130 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
131 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
132 if (pEntry) {
133 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
134 if (pString) {
135 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
136 iResult=Configure(pString->GetString().Data());
137 } else {
138 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
139 }
140 } else {
141 HLTError("can not fetch object \"%s\" from CDB", path);
142 }
143 }
144
145 return iResult;
146}
147
148void AliHLTGlobalEsdConverterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
149{
150 // see header file for class documentation
151 list.push_back(kAliHLTDataTypeTrack);
152 list.push_back(kAliHLTDataTypeTrackMC);
9a9467ed 153 list.push_back(kAliHLTDataTypeCaloCluster);
0973c527 154 list.push_back(kAliHLTDataTypedEdx );
a1408c4b 155}
156
157AliHLTComponentDataType AliHLTGlobalEsdConverterComponent::GetOutputDataType()
158{
159 // see header file for class documentation
7a9de6d1 160 return kAliHLTDataTypeESDObject|kAliHLTDataOriginOut;
a1408c4b 161}
162
163void AliHLTGlobalEsdConverterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
164{
165 // see header file for class documentation
166 constBase=2000000;
167 inputMultiplier=10.0;
168}
169
170int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
171{
172 // see header file for class documentation
173 int iResult=0;
174 TString argument="";
175 int bMissingParam=0;
176 for (int i=0; i<argc && iResult>=0; i++) {
177 argument=argv[i];
178 if (argument.IsNull()) continue;
179
180 // -notree
181 if (argument.CompareTo("-notree")==0) {
182 fWriteTree=0;
183
184 // -tree
185 } else if (argument.CompareTo("-tree")==0) {
186 fWriteTree=1;
fe0af255 187 }else if (argument.CompareTo("-fitTracksToVertex")==0) {
188 if ((bMissingParam=(++i>=argc))) break;
189 argument = argv[i];
190 HLTInfo("Filling of vertex constrained tracks is set set to: %s", argument.Data());
191 fFillVtxConstrainedTracks=argument.Atoi();
a1408c4b 192 } else {
193 HLTError("unknown argument %s", argument.Data());
194 break;
195 }
196 }
197 if (bMissingParam) {
198 HLTError("missing parameter for argument %s", argument.Data());
199 iResult=-EINVAL;
200 }
201
202 if (iResult>=0) {
203 iResult=Reconfigure(NULL, NULL);
204 }
205
206 if (iResult>=0) {
207 fESD = new AliESDEvent;
208 if (fESD) {
209 fESD->CreateStdContent();
210 } else {
211 iResult=-ENOMEM;
212 }
6117ef63 213
214 SetupCTPData();
a1408c4b 215 }
216
217 return iResult;
218}
219
220int AliHLTGlobalEsdConverterComponent::DoDeinit()
221{
222 // see header file for class documentation
223 if (fESD) delete fESD;
224 fESD=NULL;
225
226 return 0;
227}
228
229int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
6117ef63 230 AliHLTComponentTriggerData& trigData)
a1408c4b 231{
232 // see header file for class documentation
233 int iResult=0;
234 if (!fESD) return -ENODEV;
235
236 AliESDEvent* pESD = fESD;
237
238 pESD->Reset();
239 pESD->SetMagneticField(fSolenoidBz);
6117ef63 240 pESD->SetRunNumber(GetRunNo());
6700298e 241 pESD->SetPeriodNumber(GetPeriodNumber());
242 pESD->SetOrbitNumber(GetOrbitNumber());
243 pESD->SetBunchCrossNumber(GetBunchCrossNumber());
244 pESD->SetTimeStamp(GetTimeStamp());
a1408c4b 245
6117ef63 246 const AliHLTCTPData* pCTPData=CTPData();
247 if (pCTPData) {
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);
252 }
253 pESD->SetTriggerMask(mask);
254 }
255
a1408c4b 256 TTree* pTree = NULL;
257 if (fWriteTree)
258 pTree = new TTree("esdTree", "Tree with HLT ESD objects");
259
260 if (pTree) {
261 pTree->SetDirectory(0);
262 }
263
81509fd3 264 if ((iResult=ProcessBlocks(pTree, pESD))>=0) {
a1408c4b 265 // TODO: set the specification correctly
266 if (pTree) {
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);
7a9de6d1 271 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginOut, 0);
a1408c4b 272 } else {
7a9de6d1 273 iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginOut, 0);
a1408c4b 274 }
275 }
276 if (pTree) {
277 // clear user info list to prevent objects from being deleted
278 pTree->GetUserInfo()->Clear();
279 delete pTree;
280 }
281 return iResult;
282}
283
284int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD)
285{
286 // see header file for class documentation
287
288 int iResult=0;
289 int iAddedDataBlocks=0;
290
291 // Barrel tracking
292
293 // in the first attempt this component reads the TPC tracks and updates in the
294 // second step from the ITS tracks
093b64dc 295
296
297 // first read MC information (if present)
298 std::map<int,int> mcLabels;
299
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;
307 }
308 } else {
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);
312 }
313 }
314
0973c527 315 // read dEdx information (if present)
316
317 AliHLTFloat32_t *dEdxTPC = 0;
318 Int_t ndEdxTPC = 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);
323 break;
324 }
325
cd60a73f 326 // convert the TPC tracks to ESD tracks
a1408c4b 327 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
328 pBlock!=NULL; pBlock=GetNextInputBlock()) {
329 vector<AliHLTGlobalBarrelTrack> tracks;
81509fd3 330 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>=0) {
a1408c4b 331 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
332 element!=tracks.end(); element++) {
333 Float_t points[4] = {
334 element->GetX(),
335 element->GetY(),
336 element->GetLastPointX(),
337 element->GetLastPointY()
338 };
093b64dc 339
340 Int_t mcLabel = -1;
341 if( mcLabels.find(element->TrackID())!=mcLabels.end() )
342 mcLabel = mcLabels[element->TrackID()];
343 element->SetLabel( mcLabel );
344
a1408c4b 345 AliESDtrack iotrack;
550ecaab 346
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
351 // chi2
352 // pid signal
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
a1408c4b 356 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCin);
550ecaab 357 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCout);
a1408c4b 358 iotrack.SetTPCPoints(points);
0973c527 359 if( element->TrackID()<ndEdxTPC ){
7e32fedf 360 iotrack.SetTPCsignal( dEdxTPC[element->TrackID()], 0, 0 );
361 //AliTPCseed s;
362 //s.Set( element->GetX(), element->GetAlpha(),
363 //element->GetParameter(), element->GetCovariance() );
364 //s.SetdEdx( dEdxTPC[element->TrackID()] );
365 //s.CookPID();
366 //iotrack.SetTPCpid(s.TPCrPIDs() );
0973c527 367 } else {
368 if( dEdxTPC ) HLTWarning("Wrong number of dEdx TPC labels");
369 }
a1408c4b 370 pESD->AddTrack(&iotrack);
093b64dc 371 if (fVerbosity>0) element->Print();
a1408c4b 372 }
093b64dc 373 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
a1408c4b 374 iAddedDataBlocks++;
375 } else if (iResult<0) {
093b64dc 376 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
377 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
a1408c4b 378 }
379 }
380
cd60a73f 381 // now update ESD tracks with the ITS info
af3250a3 382 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITS);
cd60a73f 383 pBlock!=NULL; pBlock=GetNextInputBlock()) {
384 vector<AliHLTGlobalBarrelTrack> tracks;
385 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
386 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
387 element!=tracks.end(); element++) {
388 int ncl=0;
389 const UInt_t* pointsArray=element->GetPoints();
390 for( unsigned il=0; il<element->GetNumberOfPoints(); il++ ){
391 // TODO: check what needs to be done with the clusters
392 if( pointsArray[il]<~(UInt_t)0 ) {/*tITS.SetClusterIndex(ncl, tr.fClusterIds[il]);*/}
393 ncl++;
a1408c4b 394 }
cd60a73f 395 //tITS.SetNumberOfClusters( ncl );
396 int tpcID=element->TrackID();
397 // the ITS tracker assigns the TPC track used as seed for a certain track to
398 // the trackID
399 if( tpcID<0 || tpcID>=pESD->GetNumberOfTracks()) continue;
400
401 AliESDtrack *tESD = pESD->GetTrack( tpcID );
402 if( tESD ) tESD->UpdateTrackParams( &(*element), AliESDtrack::kITSin );
a1408c4b 403 }
cd60a73f 404 }
405 }
18ada816 406
407 // convert the HLT TRD tracks to ESD tracks
408 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack | kAliHLTDataOriginTRD);
409 pBlock!=NULL; pBlock=GetNextInputBlock()) {
410 vector<AliHLTGlobalBarrelTrack> tracks;
411 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
412 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
413 element!=tracks.end(); element++) {
414
415 Double_t TRDpid[AliPID::kSPECIES], eProb(0.2), restProb((1-eProb)/(AliPID::kSPECIES-1)); //eprob(element->GetTRDpid...);
416 for(Int_t i=0; i<AliPID::kSPECIES; i++){
417 switch(i){
418 case AliPID::kElectron: TRDpid[AliPID::kElectron]=eProb; break;
419 default: TRDpid[i]=restProb; break;
420 }
421 }
422
423 AliESDtrack iotrack;
424 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTRDin);
425 iotrack.SetTRDpid(TRDpid);
426
427 pESD->AddTrack(&iotrack);
428 if (fVerbosity>0) element->Print();
429 }
430 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
431 iAddedDataBlocks++;
432 } else if (iResult<0) {
433 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
434 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
435 }
436 }
9a9467ed 437 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeCaloCluster | kAliHLTDataOriginPHOS); pBlock!=NULL; pBlock=GetNextInputBlock())
438 {
439 AliHLTCaloClusterHeaderStruct *caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
440
441 HLTDebug("%d HLT clusters from spec: 0x%X", caloClusterHeaderPtr->fNClusters, pBlock->fSpecification);
442
443 AliHLTCaloClusterReader reader;
444 reader.SetMemory(caloClusterHeaderPtr);
445
446 AliHLTESDCaloClusterMaker clusterMaker;
447
448 int nClusters = clusterMaker.FillESD(pESD, caloClusterHeaderPtr);
449
450 HLTInfo("converted %d cluster(s) to AliESDCaloCluster and added to ESD", nClusters);
451 iAddedDataBlocks++;
452 }
a1408c4b 453
454 // primary vertex & V0's
9334b5cb 455
456 AliHLTVertexer vertexer;
457 vertexer.SetESD( pESD );
fe0af255 458 vertexer.SetFillVtxConstrainedTracks( fFillVtxConstrainedTracks );
9334b5cb 459 vertexer.FindPrimaryVertex();
460 vertexer.FindV0s();
461
a1408c4b 462 if (iAddedDataBlocks>0 && pTree) {
cd60a73f 463 pTree->Fill();
a1408c4b 464 }
465
466 if (iResult>=0) iResult=iAddedDataBlocks;
467 return iResult;
468}