]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/src/AliHLTReconstructor.cxx
integration of AliHLTSystem into Reconstructor (LocalReconstruction); handling of...
[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
10// very ugly but it has to work fast
11#ifdef use_reconstruction
12
13#include <Riostream.h>
14#include <TSystem.h>
15#include <TArrayF.h>
9b4aa2e5 16#include <TObjString.h>
de3c3890 17
b1ed0288 18#include <AliRunLoader.h>
19#include <AliHeader.h>
20#include <AliGenEventHeader.h>
21#include <AliESD.h>
22#include <AliESDHLTtrack.h>
23
4aa41877 24#include "AliHLTStandardIncludes.h"
25#include "AliHLTLogging.h"
de3c3890 26#include "AliLevel3.h"
4aa41877 27#include "AliHLTEvaluate.h"
de3c3890 28#include "AliHLTReconstructor.h"
4aa41877 29#include "AliHLTTransform.h"
30#include "AliHLTHough.h"
31#include "AliHLTFileHandler.h"
32#include "AliHLTTrack.h"
33#include "AliHLTHoughTrack.h"
34#include "AliHLTTrackArray.h"
de3c3890 35
9b4aa2e5 36#include "AliLog.h"
f644512a 37#include "AliRun.h"
38#include "AliITS.h"
4aa41877 39#include "AliHLTITStracker.h"
40#include "AliHLTTPCtracker.h"
43f15f99 41#include "MUON/src/AliRoot/AliHLTMUONTracker.h"
8a296f1c 42#include "MUON/src/AliRoot/AliHLTMUONHitReconstructor.h"
43#include "AliRawReader.h"
9b4aa2e5 44#include "AliHLTSystem.h"
45
de3c3890 46#if __GNUC__== 3
47using namespace std;
48#endif
49
9b4aa2e5 50const char* kHLTDefaultLibs[]= {
51 "libAliHLTUtil.so",
52 "libAliHLTTPC.so",
53 // "libAliHLTSample.so",
54 "libAliHLTPHOS.so",
55 NULL
56};
57
de3c3890 58ClassImp(AliHLTReconstructor)
59
9b4aa2e5 60AliHLTReconstructor::AliHLTReconstructor()
61 :
62 AliReconstructor(),
63 fDoHough(0),
64 fDoTracker(1),
65 fDoBench(0),
66 fDoCleanUp(0),
67 fpSystem(NULL)
b1ed0288 68{
69 //constructor
6e61c746 70#ifndef use_logging
4aa41877 71 AliHLTLog::fgLevel=AliHLTLog::kWarning;
6e61c746 72#endif
ff0a6788 73}
74
9b4aa2e5 75AliHLTReconstructor::AliHLTReconstructor(Bool_t doTracker, Bool_t doHough)
76 :
77 AliReconstructor(),
78 fDoHough(doHough),
79 fDoTracker(doTracker),
80 fDoBench(0),
81 fDoCleanUp(0),
82 fpSystem(new AliHLTSystem)
83{
b1ed0288 84 //constructor
6e61c746 85#ifndef use_logging
4aa41877 86 AliHLTLog::fgLevel=AliHLTLog::kWarning;
6e61c746 87#endif
9b4aa2e5 88}
89
90AliHLTReconstructor::AliHLTReconstructor(const AliHLTReconstructor&)
91 :
92 AliReconstructor(),
93 fDoHough(0),
94 fDoTracker(0),
95 fDoBench(0),
96 fDoCleanUp(0),
97 fpSystem(NULL)
98{
99 // not a valid copy constructor
100}
101
102AliHLTReconstructor& AliHLTReconstructor::operator=(const AliHLTReconstructor&)
103{
104 // not a valid assignment operator
105 fDoHough=0;
106 fDoTracker=0;
ff0a6788 107 fDoBench=0;
9b4aa2e5 108 fDoCleanUp=0;
109 fpSystem=NULL;
110 return *this;
ff0a6788 111}
112
113AliHLTReconstructor::~AliHLTReconstructor()
b1ed0288 114{
9b4aa2e5 115 //destructor
ff0a6788 116 if(fDoCleanUp){
117 char name[256];
118 gSystem->Exec("rm -rf hlt");
119 sprintf(name, "rm -f confmap_*.root confmap_*.dat");
120 gSystem->Exec(name);
121 gSystem->Exec("rm -rf hough");
122 sprintf(name, "rm -f hough_*.root hough_*.dat");
123 gSystem->Exec(name);
124 }
9b4aa2e5 125 if (fpSystem) {
126 delete fpSystem;
127 }
128 fpSystem=NULL;
ff0a6788 129}
130
9b4aa2e5 131void AliHLTReconstructor::Init(AliRunLoader* runLoader)
de3c3890 132{
9b4aa2e5 133 // init the reconstructor
9a74ed1c 134 if(!runLoader) {
9b4aa2e5 135 AliError("Missing RunLoader! 0x0");
cefeb80d 136 return;
9a74ed1c 137 }
de3c3890 138
9b4aa2e5 139 if (!fpSystem) fpSystem=new AliHLTSystem;
140 if (!fpSystem) {
141 AliError("can not create AliHLTSystem object");
142 return;
143 }
144 if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
145 AliError("HLT system in error state");
de3c3890 146 return;
147 }
148
9b4aa2e5 149 TString libs("");
150 TString option = GetOption();
151 TObjArray* pTokens=option.Tokenize(" ");
152 if (pTokens) {
153 int iEntries=pTokens->GetEntries();
154 for (int i=0; i<iEntries; i++) {
155 TString token=(((TObjString*)pTokens->At(i))->GetString());
156 if (token.Contains("loglevel=")) {
157 TString param=token.ReplaceAll("loglevel=", "");
158 if (param.IsDigit()) {
159 fpSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
160 } else if (param.BeginsWith("0x") &&
161 param.Replace(0,2,"",0).IsHex()) {
162 int severity=0;
163 sscanf(param.Data(),"%x", &severity);
164 fpSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
165 } else {
166 AliWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
167 }
168 } else if (token.Contains("alilog=off")) {
169 fpSystem->SwitchAliLog(0);
170 } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
171 libs+=token;
172 libs+=" ";
173 } else {
174 AliWarning(Form("unknown option: %s", token.Data()));
175 }
176 }
177 delete pTokens;
178 }
179
180 Bool_t bForceLibLoad=0;
181 if (bForceLibLoad=(libs.IsNull())) {
182 const char** deflib=kHLTDefaultLibs;
183 while (*deflib) {
184 libs+=*deflib++;
185 libs+=" ";
186 }
187 }
188 if ((bForceLibLoad || !fpSystem->CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
189 (fpSystem->LoadComponentLibraries(libs.Data())<0)) {
190 AliError("error while loading HLT libraries");
191 return;
192 }
193 if (!fpSystem->CheckStatus(AliHLTSystem::kReady) &&
194 (fpSystem->Configure(runLoader))<0) {
195 AliError("error during HLT system configuration");
196 return;
197 }
198}
de3c3890 199
9b4aa2e5 200void AliHLTReconstructor::Reconstruct(AliRunLoader* runLoader) const
201{
202 // reconstruction of simulated data
203 Reconstruct(runLoader, NULL);
204}
de3c3890 205
9b4aa2e5 206void AliHLTReconstructor::Reconstruct(AliRunLoader* runLoader, AliRawReader* rawReader) const
207{
208 // reconstruction of real data if rawReader!=NULL
209 if(!runLoader) {
210 AliError("Missing RunLoader! 0x0");
211 return;
212 }
213
214 Int_t nEvents = runLoader->GetNumberOfEvents();
215 int iResult=0;
216
217 if (fpSystem) {
218 if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
219 AliError("HLT system in error state");
220 return;
221 }
222 if ((iResult=fpSystem->Reconstruct(nEvents, runLoader, rawReader))>=0) {
223 }
de3c3890 224 }
225}
226
227void AliHLTReconstructor::ReconstructWithConformalMapping(AliRunLoader* runLoader,Int_t iEvent) const
228{
b1ed0288 229 // reconstruct with conformal mapper
de3c3890 230 AliLevel3 *fHLT = new AliLevel3(runLoader);
231 fHLT->Init("./", AliLevel3::kRunLoader, 1);
232
233 Int_t phiSegments = 50;
234 Int_t etaSegments = 100;
235 Int_t trackletlength = 3;
236 Int_t tracklength = 10;
237 Int_t rowscopetracklet = 2;
238 Int_t rowscopetrack = 10;
239 Double_t minPtFit = 0;
240 Double_t maxangle = 0.1745;
241 Double_t goodDist = 5;
242 Double_t maxphi = 0.1;
243 Double_t maxeta = 0.1;
244 Double_t hitChi2Cut = 20;
245 Double_t goodHitChi2 = 5;
246 Double_t trackChi2Cut = 10;
247 Double_t xyerror = -1;
248 Double_t zerror = -1;
249
250 fHLT->SetClusterFinderParam(xyerror,zerror,kTRUE);
251 fHLT->SetTrackerParam(phiSegments, etaSegments,
252 trackletlength, tracklength,
253 rowscopetracklet, rowscopetrack,
254 minPtFit, maxangle, goodDist, hitChi2Cut,
255 goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kTRUE);
8c717250 256 fHLT->SetTrackerParam(phiSegments, etaSegments,
257 trackletlength, tracklength,
258 rowscopetracklet, rowscopetrack,
259 minPtFit, maxangle, goodDist, hitChi2Cut,
260 goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kFALSE);
de3c3890 261 fHLT->SetMergerParameters(2,3,0.003,0.1,0.05);
262 fHLT->DoMc();
8c717250 263 fHLT->DoNonVertexTracking(); /*2 tracking passes, last without vertex contraint.*/
de3c3890 264 fHLT->WriteFiles("./hlt/");
de3c3890 265 fHLT->ProcessEvent(0, 35, iEvent);
2456c180 266 if(fDoBench){
267 char filename[256];
268 sprintf(filename, "confmap_%d",iEvent);
269 fHLT->DoBench(filename);
270 }
de3c3890 271
272 delete fHLT;
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
4aa41877 291 LOG(AliHLTLog::kInformational,"AliHLTReconstructor::Reconstruct","HoughTransform")
8c717250 292 <<" Hough Transform will run with ptmin="<<ptmin<<" and zvertex="<<zvertex<<ENDLOG;
de3c3890 293
4aa41877 294 AliHLTHough *hough = new AliHLTHough();
de3c3890 295
296 hough->SetThreshold(4);
1e75562a 297 hough->CalcTransformerParams(ptmin);
de3c3890 298 hough->SetPeakThreshold(70,-1);
299 hough->SetRunLoader(runLoader);
300 hough->Init("./", kFALSE, 100, kFALSE,4,0,0,zvertex);
301 hough->SetAddHistograms();
302
8c717250 303 for(Int_t slice=0; slice<=35; slice++)
de3c3890 304 {
8c717250 305 //cout<<"Processing slice "<<slice<<endl;
de3c3890 306 hough->ReadData(slice,iEvent);
307 hough->Transform();
308 hough->AddAllHistogramsRows();
309 hough->FindTrackCandidatesRow();
8c717250 310 //hough->WriteTracks(slice,"./hough");
de3c3890 311 hough->AddTracks();
312 }
313 hough->WriteTracks("./hough");
314
2456c180 315 if(fDoBench){
316 char filename[256];
317 sprintf(filename, "hough_%d",iEvent);
318 hough->DoBench(filename);
319 }
de3c3890 320 delete hough;
321}
322
323void AliHLTReconstructor::FillESD(AliRunLoader* runLoader,
324 AliESD* esd) const
325{
b1ed0288 326 //fill the esd file with found tracks
9b4aa2e5 327 if(!runLoader) {
328 AliError("Missing RunLoader! 0x0");
329 return;
330 }
de3c3890 331 Int_t iEvent = runLoader->GetEventNumber();
9b4aa2e5 332 if (fpSystem) {
333 if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
334 AliError("HLT system in error state");
335 return;
336 }
337 if (!fpSystem->CheckStatus(AliHLTSystem::kReady)) {
338 AliError("HLT system in wrong state");
339 return;
340 }
341 fpSystem->FillESD(iEvent, runLoader, esd);
342 }
343 /*
8c717250 344 if(fDoTracker) FillESDforConformalMapping(esd,iEvent);
345 if(fDoHough) FillESDforHoughTransform(esd,iEvent);
9b4aa2e5 346 */
de3c3890 347}
348
349void AliHLTReconstructor::FillESDforConformalMapping(AliESD* esd,Int_t iEvent) const
350{
b1ed0288 351 //fill esd with tracks from conformal mapping
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;
395}
396
397void AliHLTReconstructor::FillESDforHoughTransform(AliESD* esd,Int_t iEvent) const
398{
b1ed0288 399 //fill esd with tracks from hough
de3c3890 400 char filename[256];
401 sprintf(filename,"./hough/tracks_%d.raw",iEvent);
402
4aa41877 403 AliHLTFileHandler *tfile = new AliHLTFileHandler();
de3c3890 404 if(!tfile->SetBinaryInput(filename)){
4aa41877 405 LOG(AliHLTLog::kError,"AliHLTReconstructor::FillESDforHoughTransform","Input file")
2456c180 406 <<" Missing file "<<filename<<ENDLOG;
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
444AliTracker* AliHLTReconstructor::CreateTracker(AliRunLoader* runLoader) const
445{
446 //Create HLT trackers for TPC and ITS
447
448 TString opt = GetOption();
449 if(!opt.CompareTo("TPC")) {
450 // Create Hough tracker for TPC
4aa41877 451 return new AliHLTTPCtracker(runLoader);
f644512a 452 }
453 if(!opt.CompareTo("ITS")) {
454 // Create ITS tracker
e341247d 455 return new AliHLTITStracker(0);
f644512a 456 }
43f15f99 457 if(!opt.CompareTo("MUON")) {
458 return new AliHLTMUONTracker(runLoader);
459 }
f644512a 460
461 return NULL;
462}
463
8a296f1c 464void AliHLTReconstructor::FillDHLTRecPoint(AliRawReader* rawReader, Int_t nofEvent, Int_t dcCut = 0) const
465{
466 // Hit recontruction for dimuon-HLT
467 AliHLTMUONHitReconstructor kdHLTRec(rawReader);
468
469 Int_t iEvent = 0 ;
470 kdHLTRec.SetDCCut(dcCut);
471 TString lookupTablePath = getenv("ALICE_ROOT");
472 lookupTablePath += "/HLT/MUON/src/AliRoot/Lut";
473 kdHLTRec.Init(lookupTablePath.Data(),lookupTablePath.Data());
474
475 while(rawReader->NextEvent() && iEvent < nofEvent){
476 AliInfo(Form("Event : %d",iEvent));
477 kdHLTRec.WriteDHLTRecHits(iEvent);
478 iEvent++;
479 }
480
481}
482
de3c3890 483#endif