3 ///////////////////////////////////////////////////////////////////////////////
5 // class for HLT reconstruction //
6 // <Cvetan.Cheshkov@cern.ch> //
7 // <loizides@ikf.uni-frankfurt.de> //
8 ///////////////////////////////////////////////////////////////////////////////
10 #include <Riostream.h>
13 #include <TObjString.h>
15 #include <AliRunLoader.h>
16 #include <AliHeader.h>
17 #include <AliGenEventHeader.h>
18 #include <AliESDEvent.h>
19 #include <AliESDHLTtrack.h>
21 #include "AliHLTStandardIncludes.h"
22 #include "AliHLTLogging.h"
23 //#include "AliLevel3.h"
24 //#include "AliHLTEvaluate.h"
25 #include "AliHLTReconstructor.h"
26 #include "AliHLTTransform.h"
27 #include "AliHLTHough.h"
28 #include "AliHLTFileHandler.h"
29 #include "AliHLTTrack.h"
30 #include "AliHLTHoughTrack.h"
31 #include "AliHLTTrackArray.h"
36 #include "AliHLTITStracker.h"
37 #include "AliHLTTPCtracker.h"
38 //#include "MUON/src/AliRoot/AliHLTMUONTracker.h"
39 //#include "MUON/src/AliRoot/AliHLTMUONHitReconstructor.h"
40 #include "AliRawReader.h"
41 #include "AliHLTSystem.h"
47 /** HLT default component libraries */
48 const char* kHLTDefaultLibs[]= {
51 // "libAliHLTSample.so",
56 ClassImp(AliHLTReconstructor)
58 AliHLTReconstructor::AliHLTReconstructor()
69 AliHLTLog::fgLevel=AliHLTLog::kWarning;
73 AliHLTReconstructor::AliHLTReconstructor(Bool_t doTracker, Bool_t doHough)
77 fDoTracker(doTracker),
80 fpSystem(new AliHLTSystem)
84 AliHLTLog::fgLevel=AliHLTLog::kWarning;
88 AliHLTReconstructor::AliHLTReconstructor(const AliHLTReconstructor&)
97 // not a valid copy constructor
100 AliHLTReconstructor& AliHLTReconstructor::operator=(const AliHLTReconstructor&)
102 // not a valid assignment operator
111 AliHLTReconstructor::~AliHLTReconstructor()
116 gSystem->Exec("rm -rf hlt");
117 sprintf(name, "rm -f confmap_*.root confmap_*.dat");
119 gSystem->Exec("rm -rf hough");
120 sprintf(name, "rm -f hough_*.root hough_*.dat");
129 void AliHLTReconstructor::Init(AliRunLoader* runLoader)
131 // init the reconstructor
133 AliError("Missing RunLoader! 0x0");
137 if (!fpSystem) fpSystem=new AliHLTSystem;
139 AliError("can not create AliHLTSystem object");
142 if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
143 AliError("HLT system in error state");
148 TString option = GetOption();
149 TObjArray* pTokens=option.Tokenize(" ");
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()) {
161 sscanf(param.Data(),"%x", &severity);
162 fpSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
164 AliWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
166 } else if (token.Contains("alilog=off")) {
167 fpSystem->SwitchAliLog(0);
168 } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
172 AliWarning(Form("unknown option: %s", token.Data()));
178 Bool_t bForceLibLoad=0;
179 if (bForceLibLoad=(libs.IsNull())) {
180 const char** deflib=kHLTDefaultLibs;
186 if ((bForceLibLoad || !fpSystem->CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
187 (fpSystem->LoadComponentLibraries(libs.Data())<0)) {
188 AliError("error while loading HLT libraries");
191 if (!fpSystem->CheckStatus(AliHLTSystem::kReady) &&
192 (fpSystem->Configure(runLoader))<0) {
193 AliError("error during HLT system configuration");
198 void AliHLTReconstructor::Reconstruct(AliRunLoader* runLoader) const
200 // reconstruction of simulated data
201 Reconstruct(runLoader, NULL);
204 void AliHLTReconstructor::Reconstruct(AliRunLoader* runLoader, AliRawReader* rawReader) const
206 // reconstruction of real data if rawReader!=NULL
208 AliError("Missing RunLoader! 0x0");
212 Int_t nEvents = runLoader->GetNumberOfEvents();
216 if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
217 AliError("HLT system in error state");
220 if ((iResult=fpSystem->Reconstruct(nEvents, runLoader, rawReader))>=0) {
225 void AliHLTReconstructor::ReconstructWithConformalMapping(AliRunLoader* runLoader,Int_t iEvent) const
227 // reconstruct with conformal mapper
229 AliLevel3 *fHLT = new AliLevel3(runLoader);
230 fHLT->Init("./", AliLevel3::kRunLoader, 1);
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;
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);
255 fHLT->SetTrackerParam(phiSegments, etaSegments,
256 trackletlength, tracklength,
257 rowscopetracklet, rowscopetrack,
258 minPtFit, maxangle, goodDist, hitChi2Cut,
259 goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kFALSE);
260 fHLT->SetMergerParameters(2,3,0.003,0.1,0.05);
262 fHLT->DoNonVertexTracking(); // 2 tracking passes, last without vertex contraint.
263 fHLT->WriteFiles("./hlt/");
264 fHLT->ProcessEvent(0, 35, iEvent);
267 sprintf(filename, "confmap_%d",iEvent);
268 fHLT->DoBench(filename);
275 void AliHLTReconstructor::ReconstructWithHoughTransform(AliRunLoader* runLoader,Int_t iEvent) const
277 //reconstruct with hough
278 //not used anymore, Hough tracking is moved out of the local
279 //reconstruction chain
280 Float_t ptmin = 0.1*AliHLTTransform::GetSolenoidField();
284 AliHeader * header = runLoader->GetHeader();
286 AliGenEventHeader * genHeader = header->GenEventHeader();
287 if (genHeader) genHeader->PrimaryVertex(mcVertex);
289 zvertex = mcVertex[2];
291 AliInfo(Form("Hough Transform will run with ptmin=%f and zvertex=%f", ptmin, zvertex));
293 AliHLTHough *hough = new AliHLTHough();
295 hough->SetThreshold(4);
296 hough->CalcTransformerParams(ptmin);
297 hough->SetPeakThreshold(70,-1);
298 hough->SetRunLoader(runLoader);
299 hough->Init("./", kFALSE, 100, kFALSE,4,0,0,zvertex);
300 hough->SetAddHistograms();
302 for(Int_t slice=0; slice<=35; slice++)
304 //cout<<"Processing slice "<<slice<<endl;
305 hough->ReadData(slice,iEvent);
307 hough->AddAllHistogramsRows();
308 hough->FindTrackCandidatesRow();
309 //hough->WriteTracks(slice,"./hough");
312 hough->WriteTracks("./hough");
316 sprintf(filename, "hough_%d",iEvent);
317 hough->DoBench(filename);
322 void AliHLTReconstructor::FillESD(AliRunLoader* runLoader,
323 AliESDEvent* esd) const
325 //fill the esd file with found tracks
327 AliError("Missing RunLoader! 0x0");
330 Int_t iEvent = runLoader->GetEventNumber();
332 if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
333 AliError("HLT system in error state");
336 if (!fpSystem->CheckStatus(AliHLTSystem::kReady)) {
337 AliError("HLT system in wrong state");
340 fpSystem->FillESD(iEvent, runLoader, esd);
343 if(fDoTracker) FillESDforConformalMapping(esd,iEvent);
344 if(fDoHough) FillESDforHoughTransform(esd,iEvent);
348 void AliHLTReconstructor::FillESDforConformalMapping(AliESDEvent* esd,Int_t iEvent) const
350 //fill esd with tracks from conformal mapping
352 Int_t slicerange[2]={0,35};
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());
358 Float_t maxfalseratio = 0.1;
360 AliHLTEvaluate *fHLTEval = new AliHLTEvaluate("./hlt",nclusters,good,ptmin,ptmax,slicerange);
361 fHLTEval->SetMaxFalseClusters(maxfalseratio);
362 fHLTEval->LoadData(iEvent,kTRUE);
363 fHLTEval->AssignPIDs();
364 fHLTEval->AssignIDs();
365 AliHLTTrackArray *fTracks = fHLTEval->GetTracks();
370 for(Int_t i=0; i<fTracks->GetNTracks(); i++)
372 AliHLTTrack *tpt = (AliHLTTrack *)fTracks->GetCheckedTrack(i);
374 if(tpt->GetNumberOfPoints() < nminpointsontracks) continue;
376 AliESDHLTtrack *esdtrack = new AliESDHLTtrack() ;
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());
391 esd->AddHLTConfMapTrack(esdtrack);
398 void AliHLTReconstructor::FillESDforHoughTransform(AliESDEvent* esd,Int_t iEvent) const
400 //fill esd with tracks from hough
402 sprintf(filename,"./hough/tracks_%d.raw",iEvent);
404 AliHLTFileHandler *tfile = new AliHLTFileHandler();
405 if(!tfile->SetBinaryInput(filename)){
406 AliError(Form("Missing file %s", filename));
410 AliHLTTrackArray *fTracks = new AliHLTTrackArray("AliHLTHoughTrack");
411 tfile->Binary2TrackArray(fTracks);
412 tfile->CloseBinaryInput();
415 for(Int_t i=0; i<fTracks->GetNTracks(); i++)
417 AliHLTHoughTrack *tpt = (AliHLTHoughTrack *)fTracks->GetCheckedTrack(i);
420 AliESDHLTtrack *esdtrack = new AliESDHLTtrack() ;
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());
437 esd->AddHLTHoughTrack(esdtrack);
444 /* The following functions are deprecated and need to be removed.
445 AliTracker* AliHLTReconstructor::CreateTracker(AliRunLoader* runLoader) const
447 //Create HLT trackers for TPC and ITS
449 TString opt = GetOption();
450 if(!opt.CompareTo("TPC")) {
451 // Create Hough tracker for TPC
452 return new AliHLTTPCtracker(runLoader);
454 if(!opt.CompareTo("ITS")) {
455 // Create ITS tracker
456 return new AliHLTITStracker(0);
458 if(!opt.CompareTo("MUON")) {
459 return new AliHLTMUONTracker(runLoader);
465 void AliHLTReconstructor::FillDHLTRecPoint(AliRawReader* rawReader, Int_t nofEvent, Int_t dcCut = 0) const
467 // Hit recontruction for dimuon-HLT
468 AliHLTMUONHitReconstructor kdHLTRec(rawReader);
471 kdHLTRec.SetDCCut(dcCut);
472 TString lookupTablePath = getenv("ALICE_ROOT");
473 lookupTablePath += "/HLT/MUON/src/AliRoot/Lut";
474 kdHLTRec.Init(lookupTablePath.Data(),lookupTablePath.Data());
476 while(rawReader->NextEvent() && iEvent < nofEvent){
477 AliInfo(Form("Event : %d",iEvent));
478 kdHLTRec.WriteDHLTRecHits(iEvent);