]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/global/AliHLTGlobalFlatEsdConverterComponent.cxx
remove unneccassary TStopWatch
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalFlatEsdConverterComponent.cxx
CommitLineData
251a2c81 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 AliHLTGlobalFlatEsdConverterComponent.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 "AliHLTGlobalFlatEsdConverterComponent.h"
33#include "AliFlatESDEvent.h"
34#include "AliFlatESDTrack.h"
35#include "AliFlatExternalTrackParam.h"
36#include "AliExternalTrackParam.h"
37
38#include "AliHLTGlobalBarrelTrack.h"
39#include "AliHLTExternalTrackParam.h"
40#include "AliHLTTrackMCLabel.h"
41#include "AliHLTCTPData.h"
42#include "AliHLTErrorGuard.h"
43#include "AliESDEvent.h"
44#include "AliESDtrack.h"
45#include "AliESDMuonTrack.h"
46#include "AliESDMuonCluster.h"
47#include "AliCDBEntry.h"
48#include "AliCDBManager.h"
49#include "AliPID.h"
50#include "TTree.h"
51#include "TList.h"
52#include "TClonesArray.h"
f9ce172e 53#include "TTimeStamp.h"
54#include "THnSparse.h"
251a2c81 55//#include "AliHLTESDCaloClusterMaker.h"
56//#include "AliHLTCaloClusterDataStruct.h"
57//#include "AliHLTCaloClusterReader.h"
58//#include "AliESDCaloCluster.h"
59//#include "AliESDVZERO.h"
60#include "AliHLTGlobalVertexerComponent.h"
61#include "AliHLTVertexFinderBase.h"
62#include "AliHLTTPCSpacePointData.h"
63#include "AliHLTTPCClusterDataFormat.h"
64#include "AliHLTTPCDefinitions.h"
65#include "AliHLTTPCClusterMCData.h"
66#include "AliHLTTPCTransform.h"
67
68/** ROOT macro for the implementation of ROOT specific class methods */
69ClassImp(AliHLTGlobalFlatEsdConverterComponent)
70
71AliHLTGlobalFlatEsdConverterComponent::AliHLTGlobalFlatEsdConverterComponent()
72 : AliHLTProcessor()
73 , fWriteClusters(0)
74 , fVerbosity(0)
75 , fSolenoidBz(-5.00668)
76 , fBenchmark("FlatEsdConverter")
f9ce172e 77 , fBenchmarkHistosFilename("$PWD/histosBenchmark.root")
78 , fInitialTime(0)
251a2c81 79{
80 // see header file for class documentation
81 // or
82 // refer to README to build package
83 // or
84 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
f9ce172e 85
86
87
88
89 TFile *f = TFile::Open(fBenchmarkHistosFilename,"READ");
90 if(f!=0x0){
91 TNamed *t = (TNamed*)f->Get("time");
92 if(t!=0x0){
93 fInitialTime = atoi(t->GetTitle());
94 }
95 }
251a2c81 96}
97
98AliHLTGlobalFlatEsdConverterComponent::~AliHLTGlobalFlatEsdConverterComponent()
99{
100 // see header file for class documentation
101}
102
103int AliHLTGlobalFlatEsdConverterComponent::Configure(const char* arguments)
104{
105 // see header file for class documentation
106 int iResult=0;
107 if (!arguments) return iResult;
108
109 TString allArgs=arguments;
110 TString argument;
111 int bMissingParam=0;
112
113 TObjArray* pTokens=allArgs.Tokenize(" ");
114 if (pTokens) {
115 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
116 argument=((TObjString*)pTokens->At(i))->String();
117 if (argument.IsNull()) continue;
118 HLTError("unknown argument %s", argument.Data());
119 iResult=-EINVAL;
120 break;
121 }
122 delete pTokens;
123 }
124 if (bMissingParam) {
125 HLTError("missing parameter for argument %s", argument.Data());
126 iResult=-EINVAL;
127 }
128
129 return iResult;
130}
131
132int AliHLTGlobalFlatEsdConverterComponent::Reconfigure(const char* cdbEntry, const char* chainId)
133{
134 // see header file for class documentation
135 int iResult=0;
136 const char* path=NULL;
137 const char* defaultNotify="";
138 if (cdbEntry) {
139 path=cdbEntry;
140 defaultNotify=" (default)";
141 }
142 if (path) {
143 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
144 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
145 if (pEntry) {
146 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
147 if (pString) {
148 HLTInfo("received configuration object string: \'%s\'", pString->String().Data());
149 iResult=Configure(pString->String().Data());
150 } else {
151 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
152 }
153 } else {
154 HLTError("can not fetch object \"%s\" from CDB", path);
155 }
156 }
157
158 return iResult;
159}
160
161void AliHLTGlobalFlatEsdConverterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
162{
163 // see header file for class documentation
164 list.push_back(kAliHLTDataTypeTrack);
165 list.push_back(kAliHLTDataTypeTrackMC);
166 list.push_back(kAliHLTDataTypeCaloCluster);
167 list.push_back(kAliHLTDataTypedEdx );
168 list.push_back(kAliHLTDataTypeESDVertex );
169 list.push_back(kAliHLTDataTypeESDObject);
170 list.push_back(kAliHLTDataTypeTObject);
171 list.push_back(kAliHLTDataTypeGlobalVertexer);
172 list.push_back(kAliHLTDataTypeV0Finder); // array of track ids for V0s
173 list.push_back(kAliHLTDataTypeKFVertex); // KFVertex object from vertexer
174 list.push_back(kAliHLTDataTypePrimaryFinder); // array of track ids for prim vertex
175 list.push_back(kAliHLTDataTypeESDContent);
176 list.push_back(AliHLTTPCDefinitions::fgkClustersDataType| kAliHLTDataOriginTPC);
177 list.push_back(AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo| kAliHLTDataOriginTPC);
178}
179
180AliHLTComponentDataType AliHLTGlobalFlatEsdConverterComponent::GetOutputDataType()
181{
182 // see header file for class documentation
183 return kAliHLTDataTypeFlatESD|kAliHLTDataOriginOut;
184}
185
186void AliHLTGlobalFlatEsdConverterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
187{
188 // see header file for class documentation
189 constBase=2000000;
190 inputMultiplier=10.0;
191}
192
193int AliHLTGlobalFlatEsdConverterComponent::DoInit(int argc, const char** argv)
194{
195 // see header file for class documentation
196 int iResult=0;
197 TString argument="";
198 int bMissingParam=0;
199
200 // default list of skiped ESD objects
201 TString skipObjects=
202 // "AliESDRun,"
203 // "AliESDHeader,"
204 // "AliESDZDC,"
205 "AliESDFMD,"
206 // "AliESDVZERO,"
207 // "AliESDTZERO,"
208 // "TPCVertex,"
209 // "SPDVertex,"
210 // "PrimaryVertex,"
211 // "AliMultiplicity,"
212 // "PHOSTrigger,"
213 // "EMCALTrigger,"
214 // "SPDPileupVertices,"
215 // "TrkPileupVertices,"
216 "Cascades,"
217 "Kinks,"
218 "AliRawDataErrorLogs,"
219 "AliESDACORDE";
220
221 iResult=Reconfigure(NULL, NULL);
222 TString allArgs = "";
223 for ( int i = 0; i < argc; i++ ) {
224 if ( !allArgs.IsNull() ) allArgs += " ";
225 allArgs += argv[i];
226 }
227
228 TObjArray* pTokens=allArgs.Tokenize(" ");
229 if (pTokens) {
230 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
231 argument=((TObjString*)pTokens->At(i))->String();
232 if (argument.IsNull()) continue;
233
234 // -noclusters
235 if (argument.CompareTo("-noclusters")==0) {
236 fWriteClusters=0;
237 // -clusters
238 } else if (argument.CompareTo("-clusters")==0) {
239 fWriteClusters=1;
240 } else if (argument.Contains("-skipobject=")) {
241 argument.ReplaceAll("-skipobject=", "");
242 skipObjects=argument;
243 } else {
244 HLTError("unknown argument %s", argument.Data());
245 iResult=-EINVAL;
246 break;
247 }
248 }
249 }
250 if (bMissingParam) {
251 HLTError("missing parameter for argument %s", argument.Data());
252 iResult=-EINVAL;
253 }
254
255 fSolenoidBz=GetBz();
256
257 if (iResult>=0) {
258 SetupCTPData();
259 }
260
261 fBenchmark.SetTimer(0,"total");
262
263 return iResult;
264}
265
266int AliHLTGlobalFlatEsdConverterComponent::DoDeinit()
267{
268 // see header file for class documentation
269
270 return 0;
271}
272
27595dcc 273int AliHLTGlobalFlatEsdConverterComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/,
274 const AliHLTComponentBlockData* /*blocks*/,
275 AliHLTComponentTriggerData& /*trigData*/,
251a2c81 276 AliHLTUInt8_t* outputPtr,
277 AliHLTUInt32_t& size,
eb70c0fb 278 AliHLTComponentBlockDataList& outputBlocks)
251a2c81 279{
280 // see header file for class documentation
281 int iResult=0;
eb70c0fb 282 bool benchmark = true;
251a2c81 283
284 if (!IsDataEvent()) return iResult;
285
286 fBenchmark.StartNewEvent();
287 fBenchmark.Start(0);
f9ce172e 288
f9ce172e 289
251a2c81 290
291 size_t maxOutputSize = size;
292 size = 0;
293
294 AliFlatESDEvent *flatEsd = reinterpret_cast<AliFlatESDEvent*>(outputPtr);
295 new (flatEsd) AliFlatESDEvent;
296
297 /*
298 pESD->Reset();
299 pESD->SetMagneticField(fSolenoidBz);
300 pESD->SetRunNumber(GetRunNo());
301 pESD->SetPeriodNumber(GetPeriodNumber());
302 pESD->SetOrbitNumber(GetOrbitNumber());
303 pESD->SetBunchCrossNumber(GetBunchCrossNumber());
304 pESD->SetTimeStamp(GetTimeStamp());
305
306 const AliHLTCTPData* pCTPData=CTPData();
307 if (pCTPData) {
308 AliHLTUInt64_t mask=pCTPData->ActiveTriggers(trigData);
309 for (int index=0; index<gkNCTPTriggerClasses; index++) {
310 if ((mask&((AliHLTUInt64_t)0x1<<index)) == 0) continue;
311 pESD->SetTriggerClass(pCTPData->Name(index), index);
312 }
313 pESD->SetTriggerMask(mask);
314 }
315 */
316
317 // Barrel tracking
318 // tracks are based on the TPC tracks, and only updated from the ITS information
319 // Sequence:
320 // 1) extract MC information for TPC and ITS from specific data blocks and store in
321 // intermediate vector arrays
322 // 2) extract TPC tracks, update with MC labels if available, the track parameters
323 // are estimated at the first cluster position
324 // 2.1) propagate to last cluster position and update kTPCout, sets also outer param (fOp)
325 // 2.2) update kTPCin, sets also inner param (fIp) and TPC inner param (fTPCInner)
326 // 2.3) update kTPCrefit using the same parameters at the first cluster position
327 // HLT has strictly spoking no refit, but we want the flag to be set
328 // can be changed to be done after all the individual barrel detector parameters
329 // have been updated by looping over the tracks again
330 // 3) extract ITS tracks, the tracks are actually TPC tracks updated from the ITS
331 // tracking information
332 // 3.1) TODO 2010-07-12: handle ITS standalone tracks by updating kITSout before kITSin
333 // 3.2) update with kITSin
334 // TODO 2010-07-12 find out if the kITSrefit has to be set as well
335 // 4) extract TRD tracks and add to ESD
336 // TODO 2010-07-12 at the moment there is no matching or merging of TPC and TRD tracks
337 // 5) Add Trigger Detectors
338 // VZERO, ZDC
339
340 // 1) first read MC information (if present)
341
342 std::map<int,int> mcLabelsTPC;
343 std::map<int,int> mcLabelsITS;
344
345 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC);
346 pBlock!=NULL; pBlock=GetNextInputBlock()) {
347 fBenchmark.AddInput(pBlock->fSize);
348 AliHLTTrackMCData* dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr );
349 if (sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize) {
350 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
351 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
352 mcLabelsTPC[lab.fTrackID] = lab.fMCLabel;
353 }
354 } else {
355 HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information",
356 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification,
357 dataPtr->fCount, pBlock->fSize);
358 }
359 }
360
361 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginITS);
362 pBlock!=NULL; pBlock=GetNextInputBlock()) {
363 fBenchmark.AddInput(pBlock->fSize);
364 AliHLTTrackMCData* dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr );
365 if (sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize) {
366 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
367 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
368 mcLabelsITS[lab.fTrackID] = lab.fMCLabel;
369 }
370 } else {
371 HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information",
372 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification,
373 dataPtr->fCount, pBlock->fSize);
374 }
375 }
376
377 // 2) read dEdx information (if present)
378
379 AliHLTFloat32_t *dEdxTPC = 0;
380 Int_t ndEdxTPC = 0;
381 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypedEdx|kAliHLTDataOriginTPC);
382 pBlock!=NULL; pBlock=NULL/*GetNextInputBlock() there is only one block*/) {
383 fBenchmark.AddInput(pBlock->fSize);
384 dEdxTPC = reinterpret_cast<AliHLTFloat32_t*>( pBlock->fPtr );
385 ndEdxTPC = pBlock->fSize / (3*sizeof(AliHLTFloat32_t));
386 }
387
388 // 3) read TPC tracks
389
390 vector<AliHLTGlobalBarrelTrack> tracksTPC;
391
392 { // there is only one block of TPC data expected
393 const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
394 if( pBlock ){
395 fBenchmark.AddInput(pBlock->fSize);
396 iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracksTPC);
397 }
398 if( iResult>=0 ){
399 HLTWarning("converted %d track(s) to AliESDtrack and added to ESD", tracksTPC.size());
400 } else if (iResult<0) {
401 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
402 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
403 }
404 }
405
406 // 4) read ITS refitted tracks
407
408 vector<AliHLTGlobalBarrelTrack> tracksITS;
409 vector<AliHLTGlobalBarrelTrack> tracksITSOut;
410
411 if( iResult>=0 ) { // there is only one block of ITS tracks expected
412 const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITS);
413 if( pBlock ){
414 fBenchmark.AddInput(pBlock->fSize);
415 iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracksITS);
416 }
417 }
418
419 if( iResult>=0 ) { // there is only one block of ITS tracks expected
420 const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITSOut);
421 if( pBlock ){
422 fBenchmark.AddInput(pBlock->fSize);
423 iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracksITS);
424 }
425 }
426
427
428 // read TPC clusters
27595dcc 429 const UInt_t kNSlices = 36;
430 const UInt_t kNPatches = 6;
251a2c81 431
432 const AliHLTTPCClusterData *clustersTPC[kNSlices][kNPatches];
433 const AliHLTTPCClusterMCLabel *clustersTPCMC[kNSlices][kNPatches];
27595dcc 434 for( UInt_t i=0; i<kNSlices; i++){
435 for( UInt_t j=0; j<kNPatches; j++){
251a2c81 436 clustersTPC[i][j] = 0;
437 clustersTPCMC[i][j] =0;
438 }
439 }
440
441 fWriteClusters = 1;
442
443 if( fWriteClusters ){
444
445 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(AliHLTTPCDefinitions::fgkClustersDataType| kAliHLTDataOriginTPC);
446 pBlock!=NULL; pBlock=GetNextInputBlock()) {
447 //fBenchmark.AddInput(pBlock->fSize);
448 UInt_t slice = AliHLTTPCDefinitions::GetMinSliceNr(*pBlock);
449 UInt_t patch = AliHLTTPCDefinitions::GetMinPatchNr(*pBlock);
450 if( slice >= kNSlices || patch>= kNPatches ){
451 HLTWarning("Wrong slice / patch number of cluster block");
452 continue;
453 }
454 clustersTPC[slice][patch] = reinterpret_cast <const AliHLTTPCClusterData*> ( pBlock->fPtr );
455 }
456
457 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo| kAliHLTDataOriginTPC);
458 pBlock!=NULL; pBlock=GetNextInputBlock()) {
459 //fBenchmark.AddInput(pBlock->fSize);
460 UInt_t slice = AliHLTTPCDefinitions::GetMinSliceNr(*pBlock);
461 UInt_t patch = AliHLTTPCDefinitions::GetMinPatchNr(*pBlock);
462 if( slice >= kNSlices || patch>= kNPatches ){
463 HLTWarning("Wrong slice / patch number of cluster MC block");
464 continue;
465 }
466 clustersTPCMC[slice][patch] = reinterpret_cast <const AliHLTTPCClusterMCLabel*> ( pBlock->fPtr );
467 }
468
469 }
470
471 // Fill vertex information to the flat ESD
472
473 const AliESDVertex *primaryVertex = 0;
474 {
475 const AliESDVertex *primaryVertexSPD = dynamic_cast<const AliESDVertex*>( GetFirstInputObject( kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS ) );
476 const AliESDVertex *primaryVertexTracks = dynamic_cast<const AliESDVertex*>( GetFirstInputObject( kAliHLTDataTypeESDVertex|kAliHLTDataOriginOut ) );
477
f9ce172e 478 // cout<<endl<<" Primary vertex Tracks: "<<primaryVertexTracks<<", SPD: "<< primaryVertexSPD <<endl<<endl;
251a2c81 479
480 flatEsd->FillPrimaryVertices( primaryVertexSPD, primaryVertexTracks );
481
482 primaryVertex = primaryVertexTracks;
483 if( !primaryVertex ) primaryVertex = primaryVertexSPD;
484 }
485
486 // Fill the track information to the flat ESD structure
487 {
488 UInt_t itsIter = 0;
489 UInt_t itsOutIter = 0;
490 for( UInt_t tpcIter=0; tpcIter < tracksTPC.size(); tpcIter++) {
491
492 const AliHLTGlobalBarrelTrack *tpcTrack = &(tracksTPC[tpcIter]);
493 /*
494 Float_t points[4] = {
495 static_cast<Float_t>(tpcTrack->GetX()),
496 static_cast<Float_t>(tpcTrack->GetY()),
497 static_cast<Float_t>(tpcTrack->GetLastPointX()),
498 static_cast<Float_t>(tpcTrack->GetLastPointY())
499 };
500 */
501 Int_t tpcLabel = -1;
502 if( mcLabelsTPC.find(tpcTrack->TrackID())!=mcLabelsTPC.end() )
503 tpcLabel = mcLabelsTPC[tpcTrack->TrackID()];
504
505 //tpcTrack->SetLabel( tpcLabel );
506 // iotrack.SetID( tpcTrack->TrackID() );
507
508 // set kTPCout - just propagate to the outermost TPC cluster
509
510 AliHLTGlobalBarrelTrack outPar(*tpcTrack);
511 {
512 //outPar.AliExternalTrackParam::PropagateTo( tpcTrack->GetLastPointX(), fSolenoidBz );
513 const Int_t N=10; // number of steps.
514 const Float_t xRange = tpcTrack->GetLastPointX() - tpcTrack->GetX();
515 const Float_t xStep = xRange / N ;
516 for(int i = 1; i <= N; ++i) {
517 if(!outPar.AliExternalTrackParam::PropagateTo(tpcTrack->GetX() + xStep * i, fSolenoidBz)) break;
518 }
519 }
520
521 //iotrack.SetTPCPoints(points);
522 /*
523 if( tpcTrack->TrackID()<ndEdxTPC ){
524 AliHLTFloat32_t *val = &(dEdxTPC[3*tpcTrack->TrackID()]);
525 iotrack.SetTPCsignal( val[0], val[1], (UChar_t) val[2] );
526 //AliTPCseed s;
527 //s.Set( tpcTrack->GetX(), tpcTrack->GetAlpha(),
528 //tpcTrack->GetParameter(), tpcTrack->GetCovariance() );
529 //s.SetdEdx( val[0] );
530 //s.CookPID();
531 //iotrack.SetTPCpid(s.TPCrPIDs() );
532 } else {
533 if( dEdxTPC ) HLTWarning("Wrong number of dEdx TPC labels");
534 }
535 */
536 //iotrack.SetLabel(mcLabel);
537
538 // ITS track
539
540 AliHLTGlobalBarrelTrack *itsRefit=0;
541 Int_t itsLabel = -1;
542
543 for(; itsIter< tracksITS.size() && tracksITS[itsIter].TrackID()<(int) tpcIter; itsIter++ );
544
545 if( itsIter< tracksITS.size() && tracksITS[itsIter].TrackID() == (int) tpcIter ){
546 itsRefit = &(tracksITS[itsIter]);
547 if( mcLabelsITS.find(tpcIter)!=mcLabelsITS.end() ) itsLabel = mcLabelsITS[tpcIter];
548 itsIter++;
549 }
550
551 // ITS Out track
552
553 AliHLTGlobalBarrelTrack *itsOut=0;
554
555 for(; itsOutIter< tracksITSOut.size() && tracksITSOut[itsOutIter].TrackID()<(int) tpcIter; itsOutIter++ );
556
557 if( itsOutIter< tracksITSOut.size() && tracksITSOut[itsOutIter].TrackID() == (int) tpcIter ){
558 itsOut = &(tracksITSOut[itsOutIter]);
559 itsOutIter++;
560 }
561
562 // Fill DCA parameters for TPC tracks
563 AliESDtrack cP;
564
565 if( primaryVertex ){
566 cP.UpdateTrackParams( (itsRefit ?itsRefit :tpcTrack), AliESDtrack::kTPCin );
567 cP.RelateToVertex( primaryVertex, fSolenoidBz, 1000 );
568 }
569
570 AliFlatESDTrack *flatTrack = flatEsd->GetNextTrackPointer();
571
572 UInt_t nClustersTPC = tpcTrack->GetNumberOfPoints();
573 UInt_t nClustersITS = itsRefit ?itsRefit->GetNumberOfPoints() :0;
574
575 flatTrack->SetNumberOfITSClusters( nClustersITS );
576
577 if( flatEsd->GetSize() + flatTrack->EstimateSize( kTRUE, nClustersTPC ) >= maxOutputSize ){
578 cout<<endl<<endl<<"NOT ENOUGH MEMORY!!!!"<<endl<<endl;
579 iResult=-ENOMEM;
580 break;
581 }
582
583 flatTrack->FillExternalTrackParam( itsRefit, NULL, tpcTrack, &outPar, cP.GetConstrainedParam(), itsOut);
584
585 if( fWriteClusters && tpcTrack->GetPoints() ){
586 const UInt_t* clusterIDs = tpcTrack->GetPoints();
587 for( UInt_t i=0; i<nClustersTPC; i++ ){
588 UInt_t id = clusterIDs[i];
589 UInt_t iSlice = AliHLTTPCSpacePointData::GetSlice(id);
590 UInt_t iPatch = AliHLTTPCSpacePointData::GetPatch(id);
591 UInt_t iCluster = AliHLTTPCSpacePointData::GetNumber(id);
592 if( iSlice >= kNSlices || iPatch>= kNPatches ){
593 HLTWarning("Wrong slice / patch number of TPC cluster");
594 continue;
595 }
596 const AliHLTTPCClusterData *clusterBlock = clustersTPC[iSlice][iPatch];
597 if( !clusterBlock ){
598 HLTWarning("no cluster block found for slice %d, patch %d",iSlice,iPatch);
599 continue;
600 }
601 if( iCluster>= clusterBlock->fSpacePointCnt ){
602 HLTWarning("no cluster block found for slice %d, patch %d, cluster %d",iSlice,iPatch,iCluster);
603 continue;
604 }
605 const AliHLTTPCSpacePointData &cIn = clusterBlock->fSpacePoints[iCluster];
606 AliFlatTPCCluster *c= flatTrack->GetNextTPCClusterPointer();
607 c->fX = cIn.GetX();
608 c->fY = cIn.GetY();
609 c->fZ = cIn.GetZ();
610 c->fPadRow = cIn.GetPadRow() + AliHLTTPCTransform::GetFirstRow(iPatch);
611 c->fSigmaY2 = cIn.GetSigmaY2();
612 c->fSigmaZ2 = cIn.GetSigmaZ2();
613 c->fCharge = cIn.GetCharge();
614 c->fQMax = cIn.GetQMax();
615 flatTrack->StoreLastTPCCluster();
616 }
617 }
618
619
620 flatEsd->StoreLastTrack();
621
622 if (fVerbosity>0) tpcTrack->Print();
623 }
624 }
625
626 // Fill v0's
627
251a2c81 628 int nV0s =0;
f9ce172e 629 {
251a2c81 630 const AliHLTComponentBlockData* pP = GetFirstInputBlock(kAliHLTDataTypeGlobalVertexer|kAliHLTDataOriginOut);
631 if (pP && pP->fSize && pP->fPtr) {
632 const AliHLTGlobalVertexerComponent::AliHLTGlobalVertexerData *data = reinterpret_cast<AliHLTGlobalVertexerComponent::AliHLTGlobalVertexerData*>(pP->fPtr);
633 const int* v0s = data->fTrackIndices + data->fNPrimTracks;
634 nV0s = data->fNV0s;
635 for (int i = 0; i < nV0s; ++i) {
636 AliFlatESDV0 *v0 = flatEsd->GetNextV0Pointer();
637 v0->fNegTrackID = v0s[2 * i];
638 v0->fPosTrackID = v0s[2 * i + 1];
639 flatEsd->StoreLastV0();
640 }
641 } else {
f9ce172e 642 HLTWarning(" No V0 data block");
251a2c81 643 }
251a2c81 644 }
645
646 // Get ITS SPD vertex
647 for( const AliHLTComponentBlockData *i= GetFirstInputBlock(kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS); i!=NULL; i=GetNextInputBlock() ){
648 fBenchmark.AddInput(i->fSize);
649 }
650
651 /*
652 for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS); iter != NULL; iter = GetNextInputObject() ) {
653 AliESDVertex *vtx = dynamic_cast<AliESDVertex*>(const_cast<TObject*>( iter ) );
654 pESD->SetPrimaryVertexSPD( vtx );
655 }
656
657
658 // update with vertices and vertex-fitted tracks
659 // output of the GlobalVertexerComponent
660 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeGlobalVertexer);
661 pBlock!=NULL; pBlock=GetNextInputBlock()) {
662 fBenchmark.AddInput(pBlock->fSize);
663 AliHLTGlobalVertexerComponent::FillESD( pESD, reinterpret_cast<AliHLTGlobalVertexerComponent::AliHLTGlobalVertexerData* >(pBlock->fPtr) );
664 }
665
666 // update with vertices and vertex-fitted tracks
667 // output of PrimaryVertexer and V0Finder components
668 TObject* pBase = (TObject*)GetFirstInputObject(kAliHLTDataTypeKFVertex | kAliHLTDataOriginOut);
669 if (pBase) {
670 AliKFVertex* kfVertex = dynamic_cast<AliKFVertex *>(pBase);
671 if (kfVertex) {
672 const AliHLTComponentBlockData* pP = GetFirstInputBlock(kAliHLTDataTypePrimaryFinder | kAliHLTDataOriginOut);
673 if (pP && pP->fSize && pP->fPtr) {
674 const AliHLTComponentBlockData* pV0 = GetFirstInputBlock(kAliHLTDataTypeV0Finder | kAliHLTDataOriginOut);
675 if (pV0 && pV0->fPtr && pInputESD && pInputESD->GetNumberOfV0s()>0) {
676 const int* v0s = static_cast<const int*>(pV0->fPtr);
677 HLTWarning("V0 array already filled from the input esd block, additional filling from V0 block of %d entries might cause inconsistent content", v0s[0]);
678 }
679 AliHLTVertexFinderBase::FillESD(pESD, kfVertex, pP->fPtr, pV0?pV0->fPtr:NULL);
680 } else
681 HLTWarning("Problem with primary finder's data block");
682 } else {
683 HLTWarning("primary vertex block of wrong type, expecting AliKFVertex instead of %s", pBase->GetName());
684 }
685 } else {
686 // throw an error if there is a V0 data block which can not be handled without
687 // the AliKFVertex object
688 if (GetFirstInputBlock(kAliHLTDataTypeV0Finder | kAliHLTDataOriginOut)!=NULL) {
689 ALIHLTERRORGUARD(1, "missing AliKFVertex object ignoring V0 data block of type %s",
690 DataType2Text(kAliHLTDataTypeV0Finder|kAliHLTDataOriginOut).c_str());
691 }
692 }
693 */
694
695
696 // loop over all tracks and set the TPC refit flag by updating with the
697 // original TPC inner parameter if not yet set
698 // TODO: replace this by a proper refit
699 // code is comented for the moment as it does not fully solve the problems with
700 // the display
701 // - would set the main parameters to the TPC inner wall again, or
702 // - changes the inner param if the parameters are propagated, so we loose the track
703 // reference point for the display
704 // with the current sequence we have the latter case as the DCA operations above
705 // change the TPC inner parameters
706 /*
707 for (int i=0; i<pESD->GetNumberOfTracks(); i++) {
708 if (!pESD->GetTrack(i) ||
709 !pESD->GetTrack(i)->GetTPCInnerParam() ||
710 pESD->GetTrack(i)->IsOn(AliESDtrack::kTPCrefit)) continue;
711 AliESDtrack* tESD=pESD->GetTrack(i);
712 AliHLTGlobalBarrelTrack inner(*tESD->GetTPCInnerParam());
713 inner.SetLabel(tESD->GetLabel());
714 tESD->UpdateTrackParams(&inner, AliESDtrack::kTPCrefit);
715 }
716 */
717
718 if (iResult>=0) {
719
720 AliHLTComponentBlockData outBlock;
721 FillBlockData( outBlock );
722 outBlock.fOffset = size;
723 outBlock.fSize = flatEsd->GetSize();
724 outBlock.fDataType = kAliHLTDataTypeFlatESD|kAliHLTDataOriginOut;
725 outBlock.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( 0, 35, 0, 5 );
726
727 outputBlocks.push_back( outBlock );
728
729 fBenchmark.AddOutput(outBlock.fSize);
730
731 size += outBlock.fSize;
732 }
733
734 fBenchmark.Stop(0);
735 HLTWarning( fBenchmark.GetStatistics() );
eb70c0fb 736
737
738
eb70c0fb 739 if(benchmark){
f9ce172e 740
741 TTimeStamp ts;
742 Double_t time = (Double_t) ts.GetSec() - fInitialTime;
eb70c0fb 743
f9ce172e 744
745
746 Double_t statistics[10];
747 TString names[10];
eb70c0fb 748 fBenchmark.GetStatisticsData(statistics, names);
f9ce172e 749 statistics[5] = tracksTPC.size();
750 statistics[6] = time;
751 statistics[7] = nV0s;
752
753 FillBenchmarkHistos( statistics, names);
754 printf("\nTIME: %.1f \n\n",time);
755 // printf("\nreal time: %.9f \n\n",statistics[4]);
756 // printf("\ncpu time: %.9f \n\n",statistics[3]);
757 fBenchmark.Reset();
eb70c0fb 758
759 }
251a2c81 760 return iResult;
761}
762
eb70c0fb 763
45ab7544 764void AliHLTGlobalFlatEsdConverterComponent::FillBenchmarkHistos(Double_t *statistics, TString */*names*/){
eb70c0fb 765
f9ce172e 766
767// cout<<"Now writing benchmarks to " << fBenchmarkHistosFilename <<endl<<endl;
768
769 TFile *f = TFile::Open(fBenchmarkHistosFilename,"UPDATE");
770 THnSparseD *s = (THnSparseD*)f->Get("benchmarkInformation");
771 TNamed *t = (TNamed*)f->Get("time");
eb70c0fb 772
f9ce172e 773 if(!s){
45ab7544 774 HLTWarning( "Benchmark Histograms not available!" );
775 return;
eb70c0fb 776 }
f9ce172e 777 s->Fill(statistics);
eb70c0fb 778
f9ce172e 779 TList histosList;
780 histosList.Add(s);
781 histosList.Add(t);
782 histosList.SaveAs(fBenchmarkHistosFilename);
eb70c0fb 783
784}