]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/src/AliHLTReconstructor.cxx
New class AliESDEvent, backward compatibility with the old AliESD (Christian)
[u/mrichter/AliRoot.git] / HLT / src / AliHLTReconstructor.cxx
CommitLineData
de3c3890 1// $Id$
2
3///////////////////////////////////////////////////////////////////////////////
4// //
5// class for HLT reconstruction //
6// <Cvetan.Cheshkov@cern.ch> //
2456c180 7// <loizides@ikf.uni-frankfurt.de> //
de3c3890 8///////////////////////////////////////////////////////////////////////////////
9
de3c3890 10#include <Riostream.h>
11#include <TSystem.h>
12#include <TArrayF.h>
73e81c35 13#include <TObjString.h>
de3c3890 14
b1ed0288 15#include <AliRunLoader.h>
16#include <AliHeader.h>
17#include <AliGenEventHeader.h>
af885e0f 18#include <AliESDEvent.h>
b1ed0288 19#include <AliESDHLTtrack.h>
20
4aa41877 21#include "AliHLTStandardIncludes.h"
22#include "AliHLTLogging.h"
73e81c35 23//#include "AliLevel3.h"
24//#include "AliHLTEvaluate.h"
de3c3890 25#include "AliHLTReconstructor.h"
4aa41877 26#include "AliHLTTransform.h"
27#include "AliHLTHough.h"
28#include "AliHLTFileHandler.h"
29#include "AliHLTTrack.h"
30#include "AliHLTHoughTrack.h"
31#include "AliHLTTrackArray.h"
de3c3890 32
73e81c35 33#include "AliLog.h"
f644512a 34#include "AliRun.h"
35#include "AliITS.h"
4aa41877 36#include "AliHLTITStracker.h"
37#include "AliHLTTPCtracker.h"
dfddae5f 38//#include "MUON/src/AliRoot/AliHLTMUONTracker.h"
39//#include "MUON/src/AliRoot/AliHLTMUONHitReconstructor.h"
8a296f1c 40#include "AliRawReader.h"
73e81c35 41#include "AliHLTSystem.h"
42
de3c3890 43#if __GNUC__== 3
44using namespace std;
45#endif
46
90ebac25 47/** HLT default component libraries */
73e81c35 48const char* kHLTDefaultLibs[]= {
49 "libAliHLTUtil.so",
50 "libAliHLTTPC.so",
51 // "libAliHLTSample.so",
52 "libAliHLTPHOS.so",
53 NULL
54};
55
de3c3890 56ClassImp(AliHLTReconstructor)
57
73e81c35 58AliHLTReconstructor::AliHLTReconstructor()
59 :
60 AliReconstructor(),
61 fDoHough(0),
62 fDoTracker(1),
63 fDoBench(0),
64 fDoCleanUp(0),
65 fpSystem(NULL)
b1ed0288 66{
67 //constructor
6e61c746 68#ifndef use_logging
4aa41877 69 AliHLTLog::fgLevel=AliHLTLog::kWarning;
6e61c746 70#endif
ff0a6788 71}
72
73e81c35 73AliHLTReconstructor::AliHLTReconstructor(Bool_t doTracker, Bool_t doHough)
74 :
75 AliReconstructor(),
76 fDoHough(doHough),
77 fDoTracker(doTracker),
78 fDoBench(0),
79 fDoCleanUp(0),
80 fpSystem(new AliHLTSystem)
81{
b1ed0288 82 //constructor
6e61c746 83#ifndef use_logging
4aa41877 84 AliHLTLog::fgLevel=AliHLTLog::kWarning;
6e61c746 85#endif
73e81c35 86}
87
88AliHLTReconstructor::AliHLTReconstructor(const AliHLTReconstructor&)
89 :
90 AliReconstructor(),
91 fDoHough(0),
92 fDoTracker(0),
93 fDoBench(0),
94 fDoCleanUp(0),
95 fpSystem(NULL)
96{
97 // not a valid copy constructor
98}
99
100AliHLTReconstructor& AliHLTReconstructor::operator=(const AliHLTReconstructor&)
101{
102 // not a valid assignment operator
103 fDoHough=0;
104 fDoTracker=0;
ff0a6788 105 fDoBench=0;
73e81c35 106 fDoCleanUp=0;
107 fpSystem=NULL;
108 return *this;
ff0a6788 109}
110
111AliHLTReconstructor::~AliHLTReconstructor()
b1ed0288 112{
73e81c35 113 //destructor
ff0a6788 114 if(fDoCleanUp){
115 char name[256];
116 gSystem->Exec("rm -rf hlt");
117 sprintf(name, "rm -f confmap_*.root confmap_*.dat");
118 gSystem->Exec(name);
119 gSystem->Exec("rm -rf hough");
120 sprintf(name, "rm -f hough_*.root hough_*.dat");
121 gSystem->Exec(name);
122 }
73e81c35 123 if (fpSystem) {
124 delete fpSystem;
125 }
126 fpSystem=NULL;
ff0a6788 127}
128
73e81c35 129void AliHLTReconstructor::Init(AliRunLoader* runLoader)
de3c3890 130{
73e81c35 131 // init the reconstructor
9a74ed1c 132 if(!runLoader) {
73e81c35 133 AliError("Missing RunLoader! 0x0");
134 return;
135 }
136
137 if (!fpSystem) fpSystem=new AliHLTSystem;
138 if (!fpSystem) {
139 AliError("can not create AliHLTSystem object");
cefeb80d 140 return;
9a74ed1c 141 }
73e81c35 142 if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
143 AliError("HLT system in error state");
9b4aa2e5 144 return;
145 }
146
73e81c35 147 TString libs("");
148 TString option = GetOption();
149 TObjArray* pTokens=option.Tokenize(" ");
150 if (pTokens) {
151 int iEntries=pTokens->GetEntries();
152 for (int i=0; i<iEntries; i++) {
153 TString token=(((TObjString*)pTokens->At(i))->GetString());
154 if (token.Contains("loglevel=")) {
155 TString param=token.ReplaceAll("loglevel=", "");
156 if (param.IsDigit()) {
157 fpSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
158 } else if (param.BeginsWith("0x") &&
159 param.Replace(0,2,"",0).IsHex()) {
160 int severity=0;
161 sscanf(param.Data(),"%x", &severity);
162 fpSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
163 } else {
164 AliWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
165 }
166 } else if (token.Contains("alilog=off")) {
167 fpSystem->SwitchAliLog(0);
168 } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
169 libs+=token;
170 libs+=" ";
171 } else {
172 AliWarning(Form("unknown option: %s", token.Data()));
173 }
174 }
175 delete pTokens;
176 }
177
178 Bool_t bForceLibLoad=0;
179 if (bForceLibLoad=(libs.IsNull())) {
180 const char** deflib=kHLTDefaultLibs;
181 while (*deflib) {
182 libs+=*deflib++;
183 libs+=" ";
184 }
185 }
186 if ((bForceLibLoad || !fpSystem->CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
187 (fpSystem->LoadComponentLibraries(libs.Data())<0)) {
188 AliError("error while loading HLT libraries");
189 return;
190 }
191 if (!fpSystem->CheckStatus(AliHLTSystem::kReady) &&
192 (fpSystem->Configure(runLoader))<0) {
193 AliError("error during HLT system configuration");
194 return;
195 }
196}
197
198void AliHLTReconstructor::Reconstruct(AliRunLoader* runLoader) const
199{
200 // reconstruction of simulated data
201 Reconstruct(runLoader, NULL);
202}
203
204void AliHLTReconstructor::Reconstruct(AliRunLoader* runLoader, AliRawReader* rawReader) const
205{
206 // reconstruction of real data if rawReader!=NULL
207 if(!runLoader) {
208 AliError("Missing RunLoader! 0x0");
209 return;
210 }
9b4aa2e5 211
73e81c35 212 Int_t nEvents = runLoader->GetNumberOfEvents();
213 int iResult=0;
000fb6e2 214
73e81c35 215 if (fpSystem) {
216 if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
217 AliError("HLT system in error state");
218 return;
219 }
220 if ((iResult=fpSystem->Reconstruct(nEvents, runLoader, rawReader))>=0) {
221 }
de3c3890 222 }
223}
224
225void AliHLTReconstructor::ReconstructWithConformalMapping(AliRunLoader* runLoader,Int_t iEvent) const
226{
b1ed0288 227 // reconstruct with conformal mapper
73e81c35 228 /*
de3c3890 229 AliLevel3 *fHLT = new AliLevel3(runLoader);
230 fHLT->Init("./", AliLevel3::kRunLoader, 1);
231
232 Int_t phiSegments = 50;
233 Int_t etaSegments = 100;
234 Int_t trackletlength = 3;
235 Int_t tracklength = 10;
236 Int_t rowscopetracklet = 2;
237 Int_t rowscopetrack = 10;
238 Double_t minPtFit = 0;
239 Double_t maxangle = 0.1745;
240 Double_t goodDist = 5;
241 Double_t maxphi = 0.1;
242 Double_t maxeta = 0.1;
243 Double_t hitChi2Cut = 20;
244 Double_t goodHitChi2 = 5;
245 Double_t trackChi2Cut = 10;
246 Double_t xyerror = -1;
247 Double_t zerror = -1;
248
249 fHLT->SetClusterFinderParam(xyerror,zerror,kTRUE);
250 fHLT->SetTrackerParam(phiSegments, etaSegments,
251 trackletlength, tracklength,
252 rowscopetracklet, rowscopetrack,
253 minPtFit, maxangle, goodDist, hitChi2Cut,
254 goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kTRUE);
8c717250 255 fHLT->SetTrackerParam(phiSegments, etaSegments,
256 trackletlength, tracklength,
257 rowscopetracklet, rowscopetrack,
258 minPtFit, maxangle, goodDist, hitChi2Cut,
259 goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kFALSE);
de3c3890 260 fHLT->SetMergerParameters(2,3,0.003,0.1,0.05);
261 fHLT->DoMc();
73e81c35 262 fHLT->DoNonVertexTracking(); // 2 tracking passes, last without vertex contraint.
de3c3890 263 fHLT->WriteFiles("./hlt/");
de3c3890 264 fHLT->ProcessEvent(0, 35, iEvent);
2456c180 265 if(fDoBench){
266 char filename[256];
267 sprintf(filename, "confmap_%d",iEvent);
268 fHLT->DoBench(filename);
269 }
de3c3890 270
271 delete fHLT;
73e81c35 272 */
de3c3890 273}
274
275void AliHLTReconstructor::ReconstructWithHoughTransform(AliRunLoader* runLoader,Int_t iEvent) const
276{
b1ed0288 277 //reconstruct with hough
f644512a 278 //not used anymore, Hough tracking is moved out of the local
279 //reconstruction chain
4aa41877 280 Float_t ptmin = 0.1*AliHLTTransform::GetSolenoidField();
de3c3890 281
282 Float_t zvertex = 0;
283 TArrayF mcVertex(3);
69fe5bee 284 AliHeader * header = runLoader->GetHeader();
285 if (header) {
286 AliGenEventHeader * genHeader = header->GenEventHeader();
287 if (genHeader) genHeader->PrimaryVertex(mcVertex);
288 }
de3c3890 289 zvertex = mcVertex[2];
290
73e81c35 291 AliInfo(Form("Hough Transform will run with ptmin=%f and zvertex=%f", ptmin, zvertex));
de3c3890 292
4aa41877 293 AliHLTHough *hough = new AliHLTHough();
de3c3890 294
295 hough->SetThreshold(4);
1e75562a 296 hough->CalcTransformerParams(ptmin);
de3c3890 297 hough->SetPeakThreshold(70,-1);
298 hough->SetRunLoader(runLoader);
299 hough->Init("./", kFALSE, 100, kFALSE,4,0,0,zvertex);
300 hough->SetAddHistograms();
301
8c717250 302 for(Int_t slice=0; slice<=35; slice++)
de3c3890 303 {
8c717250 304 //cout<<"Processing slice "<<slice<<endl;
de3c3890 305 hough->ReadData(slice,iEvent);
306 hough->Transform();
307 hough->AddAllHistogramsRows();
308 hough->FindTrackCandidatesRow();
8c717250 309 //hough->WriteTracks(slice,"./hough");
de3c3890 310 hough->AddTracks();
311 }
312 hough->WriteTracks("./hough");
313
2456c180 314 if(fDoBench){
315 char filename[256];
316 sprintf(filename, "hough_%d",iEvent);
317 hough->DoBench(filename);
318 }
de3c3890 319 delete hough;
320}
321
322void AliHLTReconstructor::FillESD(AliRunLoader* runLoader,
af885e0f 323 AliESDEvent* esd) const
de3c3890 324{
b1ed0288 325 //fill the esd file with found tracks
73e81c35 326 if(!runLoader) {
327 AliError("Missing RunLoader! 0x0");
328 return;
329 }
de3c3890 330 Int_t iEvent = runLoader->GetEventNumber();
73e81c35 331 if (fpSystem) {
332 if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
333 AliError("HLT system in error state");
334 return;
335 }
336 if (!fpSystem->CheckStatus(AliHLTSystem::kReady)) {
337 AliError("HLT system in wrong state");
338 return;
339 }
340 fpSystem->FillESD(iEvent, runLoader, esd);
341 }
342 /*
8c717250 343 if(fDoTracker) FillESDforConformalMapping(esd,iEvent);
344 if(fDoHough) FillESDforHoughTransform(esd,iEvent);
73e81c35 345 */
de3c3890 346}
347
af885e0f 348void AliHLTReconstructor::FillESDforConformalMapping(AliESDEvent* esd,Int_t iEvent) const
de3c3890 349{
b1ed0288 350 //fill esd with tracks from conformal mapping
73e81c35 351 /*
8c717250 352 Int_t slicerange[2]={0,35};
4aa41877 353 Int_t good = (int)(0.4*AliHLTTransform::GetNRows());
354 Int_t nclusters = (int)(0.4*AliHLTTransform::GetNRows());
355 Int_t nminpointsontracks = (int)(0.3*AliHLTTransform::GetNRows());
8c717250 356 Float_t ptmin = 0.;
357 Float_t ptmax = 0.;
358 Float_t maxfalseratio = 0.1;
de3c3890 359
4aa41877 360 AliHLTEvaluate *fHLTEval = new AliHLTEvaluate("./hlt",nclusters,good,ptmin,ptmax,slicerange);
de3c3890 361 fHLTEval->SetMaxFalseClusters(maxfalseratio);
de3c3890 362 fHLTEval->LoadData(iEvent,kTRUE);
363 fHLTEval->AssignPIDs();
364 fHLTEval->AssignIDs();
4aa41877 365 AliHLTTrackArray *fTracks = fHLTEval->GetTracks();
2456c180 366 if(!fTracks){
367 delete fHLTEval;
368 return;
369 }
de3c3890 370 for(Int_t i=0; i<fTracks->GetNTracks(); i++)
371 {
4aa41877 372 AliHLTTrack *tpt = (AliHLTTrack *)fTracks->GetCheckedTrack(i);
de3c3890 373 if(!tpt) continue;
244a5ed5 374 if(tpt->GetNumberOfPoints() < nminpointsontracks) continue;
de3c3890 375
376 AliESDHLTtrack *esdtrack = new AliESDHLTtrack() ;
377
378 esdtrack->SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
379 esdtrack->SetNHits(tpt->GetNHits());
380 esdtrack->SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ());
381 esdtrack->SetLastPoint(tpt->GetLastPointX(),tpt->GetLastPointY(),tpt->GetLastPointZ());
382 esdtrack->SetPt(tpt->GetPt());
383 esdtrack->SetPsi(tpt->GetPsi());
384 esdtrack->SetTgl(tpt->GetTgl());
385 esdtrack->SetCharge(tpt->GetCharge());
386 esdtrack->SetMCid(tpt->GetMCid());
387 esdtrack->SetSector(tpt->GetSector());
388 esdtrack->SetPID(tpt->GetPID());
389 esdtrack->ComesFromMainVertex(tpt->ComesFromMainVertex());
390
391 esd->AddHLTConfMapTrack(esdtrack);
392 delete esdtrack;
393 }
de3c3890 394 delete fHLTEval;
73e81c35 395 */
de3c3890 396}
397
af885e0f 398void AliHLTReconstructor::FillESDforHoughTransform(AliESDEvent* esd,Int_t iEvent) const
de3c3890 399{
b1ed0288 400 //fill esd with tracks from hough
de3c3890 401 char filename[256];
402 sprintf(filename,"./hough/tracks_%d.raw",iEvent);
403
4aa41877 404 AliHLTFileHandler *tfile = new AliHLTFileHandler();
de3c3890 405 if(!tfile->SetBinaryInput(filename)){
73e81c35 406 AliError(Form("Missing file %s", filename));
de3c3890 407 return;
408 }
409
4aa41877 410 AliHLTTrackArray *fTracks = new AliHLTTrackArray("AliHLTHoughTrack");
de3c3890 411 tfile->Binary2TrackArray(fTracks);
412 tfile->CloseBinaryInput();
413 delete tfile;
2456c180 414 if(!fTracks) return;
de3c3890 415 for(Int_t i=0; i<fTracks->GetNTracks(); i++)
416 {
4aa41877 417 AliHLTHoughTrack *tpt = (AliHLTHoughTrack *)fTracks->GetCheckedTrack(i);
de3c3890 418 if(!tpt) continue;
419
420 AliESDHLTtrack *esdtrack = new AliESDHLTtrack() ;
421
422 esdtrack->SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
423 esdtrack->SetNHits(tpt->GetNHits());
424 esdtrack->SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ());
425 esdtrack->SetLastPoint(tpt->GetLastPointX(),tpt->GetLastPointY(),tpt->GetLastPointZ());
426 esdtrack->SetPt(tpt->GetPt());
427 esdtrack->SetPsi(tpt->GetPsi());
428 esdtrack->SetTgl(tpt->GetTgl());
429 esdtrack->SetCharge(tpt->GetCharge());
430 esdtrack->SetMCid(tpt->GetMCid());
431 esdtrack->SetWeight(tpt->GetWeight());
432 esdtrack->SetSector(tpt->GetSector());
433 esdtrack->SetBinXY(tpt->GetBinX(),tpt->GetBinY(),tpt->GetSizeX(),tpt->GetSizeY());
434 esdtrack->SetPID(tpt->GetPID());
435 esdtrack->ComesFromMainVertex(tpt->ComesFromMainVertex());
436
437 esd->AddHLTHoughTrack(esdtrack);
438 delete esdtrack;
439 }
440
441 delete fTracks;
442}
f644512a 443
dfddae5f 444/* The following functions are deprecated and need to be removed.
f644512a 445AliTracker* AliHLTReconstructor::CreateTracker(AliRunLoader* runLoader) const
446{
447 //Create HLT trackers for TPC and ITS
448
449 TString opt = GetOption();
450 if(!opt.CompareTo("TPC")) {
451 // Create Hough tracker for TPC
4aa41877 452 return new AliHLTTPCtracker(runLoader);
f644512a 453 }
454 if(!opt.CompareTo("ITS")) {
455 // Create ITS tracker
e341247d 456 return new AliHLTITStracker(0);
f644512a 457 }
43f15f99 458 if(!opt.CompareTo("MUON")) {
459 return new AliHLTMUONTracker(runLoader);
460 }
f644512a 461
462 return NULL;
463}
464
8a296f1c 465void AliHLTReconstructor::FillDHLTRecPoint(AliRawReader* rawReader, Int_t nofEvent, Int_t dcCut = 0) const
466{
467 // Hit recontruction for dimuon-HLT
468 AliHLTMUONHitReconstructor kdHLTRec(rawReader);
469
470 Int_t iEvent = 0 ;
471 kdHLTRec.SetDCCut(dcCut);
472 TString lookupTablePath = getenv("ALICE_ROOT");
473 lookupTablePath += "/HLT/MUON/src/AliRoot/Lut";
474 kdHLTRec.Init(lookupTablePath.Data(),lookupTablePath.Data());
475
476 while(rawReader->NextEvent() && iEvent < nofEvent){
477 AliInfo(Form("Event : %d",iEvent));
478 kdHLTRec.WriteDHLTRecHits(iEvent);
479 iEvent++;
480 }
481
482}
483
dfddae5f 484*/