]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/src/AliHLTReconstructor.cxx
reverting to version 1.17 due to new library dependencies
[u/mrichter/AliRoot.git] / HLT / src / AliHLTReconstructor.cxx
1 // $Id$
2
3 ///////////////////////////////////////////////////////////////////////////////
4 //                                                                           //
5 // class for HLT reconstruction                                              //
6 // <Cvetan.Cheshkov@cern.ch>                                                 //
7 // <loizides@ikf.uni-frankfurt.de>                                           //
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>
16
17 #include <AliRunLoader.h>
18 #include <AliHeader.h>
19 #include <AliGenEventHeader.h>
20 #include <AliESD.h>
21 #include <AliESDHLTtrack.h>
22
23 #include "AliHLTStandardIncludes.h"
24 #include "AliHLTLogging.h"
25 #include "AliLevel3.h"
26 #include "AliHLTEvaluate.h"
27 #include "AliHLTReconstructor.h"
28 #include "AliHLTTransform.h"
29 #include "AliHLTHough.h"
30 #include "AliHLTFileHandler.h"
31 #include "AliHLTTrack.h"
32 #include "AliHLTHoughTrack.h"
33 #include "AliHLTTrackArray.h"
34
35 #include "AliRun.h"
36 #include "AliITS.h"
37 #include "AliHLTITStracker.h"
38 #include "AliHLTTPCtracker.h"
39 #include "MUON/src/AliRoot/AliHLTMUONTracker.h"
40 #include "MUON/src/AliRoot/AliHLTMUONHitReconstructor.h"
41 #include "AliRawReader.h"
42 #if __GNUC__== 3
43 using namespace std;
44 #endif
45
46 ClassImp(AliHLTReconstructor)
47
48 AliHLTReconstructor::AliHLTReconstructor(): AliReconstructor() 
49
50   //constructor
51 #ifndef use_logging
52   AliHLTLog::fgLevel=AliHLTLog::kWarning;
53 #endif
54   fDoTracker=1;
55   fDoHough=0;
56   fDoBench=0;
57   fDoCleanUp=1;
58 }
59
60 AliHLTReconstructor::AliHLTReconstructor(Bool_t doTracker, Bool_t doHough): AliReconstructor() 
61
62   //constructor
63 #ifndef use_logging
64   AliHLTLog::fgLevel=AliHLTLog::kWarning;
65 #endif
66   fDoTracker=doTracker;
67   fDoHough=doHough;
68   fDoBench=0;
69   fDoCleanUp=1;
70 }
71
72 AliHLTReconstructor::~AliHLTReconstructor()
73
74   //deconstructor
75   if(fDoCleanUp){
76     char name[256];
77     gSystem->Exec("rm -rf hlt");
78     sprintf(name, "rm -f confmap_*.root confmap_*.dat");
79     gSystem->Exec(name);
80     gSystem->Exec("rm -rf hough");
81     sprintf(name, "rm -f hough_*.root hough_*.dat");
82     gSystem->Exec(name);
83   }
84 }
85
86 void AliHLTReconstructor::Reconstruct(AliRunLoader* runLoader) const
87 {
88   // do the standard and hough reconstruction chain
89   if(!runLoader) {
90     LOG(AliHLTLog::kFatal,"AliHLTReconstructor::Reconstruct","RunLoader")
91       <<" Missing RunLoader! 0x0"<<ENDLOG;
92     return;
93   }
94   gSystem->Exec("rm -rf hlt");
95   gSystem->MakeDirectory("hlt");
96   gSystem->Exec("rm -rf hough");
97   gSystem->MakeDirectory("hough");
98
99   Bool_t isinit=AliHLTTransform::Init(runLoader);
100   if(!isinit){
101     LOG(AliHLTLog::kError,"AliHLTReconstructor::Reconstruct","Transformer")
102      << "Could not create transform settings, please check log for error messages!" << ENDLOG;
103     return;
104   }
105
106   Int_t nEvents = runLoader->GetNumberOfEvents();
107
108   for(Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
109     runLoader->GetEvent(iEvent);
110
111     if(fDoTracker) ReconstructWithConformalMapping(runLoader,iEvent);
112     if(fDoHough) ReconstructWithHoughTransform(runLoader,iEvent);
113   }
114 }
115
116 void AliHLTReconstructor::ReconstructWithConformalMapping(AliRunLoader* runLoader,Int_t iEvent) const
117 {
118   // reconstruct with conformal mapper
119   AliLevel3 *fHLT = new AliLevel3(runLoader);
120   fHLT->Init("./", AliLevel3::kRunLoader, 1);
121
122   Int_t phiSegments = 50;
123   Int_t etaSegments = 100;
124   Int_t trackletlength = 3;
125   Int_t tracklength = 10;
126   Int_t rowscopetracklet = 2;
127   Int_t rowscopetrack = 10;
128   Double_t minPtFit = 0;
129   Double_t maxangle = 0.1745;
130   Double_t goodDist = 5;
131   Double_t maxphi = 0.1;
132   Double_t maxeta = 0.1;
133   Double_t hitChi2Cut = 20;
134   Double_t goodHitChi2 = 5;
135   Double_t trackChi2Cut = 10;
136   Double_t xyerror = -1;
137   Double_t zerror =  -1;
138   
139   fHLT->SetClusterFinderParam(xyerror,zerror,kTRUE);
140   fHLT->SetTrackerParam(phiSegments, etaSegments, 
141                         trackletlength, tracklength,
142                         rowscopetracklet, rowscopetrack,
143                         minPtFit, maxangle, goodDist, hitChi2Cut,
144                         goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kTRUE);
145   fHLT->SetTrackerParam(phiSegments, etaSegments, 
146                         trackletlength, tracklength,
147                         rowscopetracklet, rowscopetrack,
148                         minPtFit, maxangle, goodDist, hitChi2Cut,
149                         goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kFALSE);
150   fHLT->SetMergerParameters(2,3,0.003,0.1,0.05);
151   fHLT->DoMc();
152   fHLT->DoNonVertexTracking(); /*2 tracking passes, last without vertex contraint.*/
153   fHLT->WriteFiles("./hlt/");  
154   fHLT->ProcessEvent(0, 35, iEvent);
155   if(fDoBench){
156     char filename[256];
157     sprintf(filename, "confmap_%d",iEvent);
158     fHLT->DoBench(filename);
159   }
160
161   delete fHLT;
162 }
163
164 void AliHLTReconstructor::ReconstructWithHoughTransform(AliRunLoader* runLoader,Int_t iEvent) const
165 {
166   //reconstruct with hough
167   //not used anymore, Hough tracking is moved out of the local
168   //reconstruction chain
169   Float_t ptmin = 0.1*AliHLTTransform::GetSolenoidField();
170
171   Float_t zvertex = 0;
172   TArrayF mcVertex(3); 
173   AliHeader * header = runLoader->GetHeader();
174   if (header) {
175     AliGenEventHeader * genHeader = header->GenEventHeader();
176     if (genHeader) genHeader->PrimaryVertex(mcVertex);
177   }
178   zvertex = mcVertex[2];
179
180   LOG(AliHLTLog::kInformational,"AliHLTReconstructor::Reconstruct","HoughTransform")
181     <<" Hough Transform will run with ptmin="<<ptmin<<" and zvertex="<<zvertex<<ENDLOG;
182
183   AliHLTHough *hough = new AliHLTHough();
184     
185   hough->SetThreshold(4);
186   hough->CalcTransformerParams(ptmin);
187   hough->SetPeakThreshold(70,-1);
188   hough->SetRunLoader(runLoader);
189   hough->Init("./", kFALSE, 100, kFALSE,4,0,0,zvertex);
190   hough->SetAddHistograms();
191
192   for(Int_t slice=0; slice<=35; slice++)
193     {
194       //cout<<"Processing slice "<<slice<<endl;
195       hough->ReadData(slice,iEvent);
196       hough->Transform();
197       hough->AddAllHistogramsRows();
198       hough->FindTrackCandidatesRow();
199       //hough->WriteTracks(slice,"./hough");
200       hough->AddTracks();
201     }
202   hough->WriteTracks("./hough");
203   
204   if(fDoBench){
205     char filename[256];
206     sprintf(filename, "hough_%d",iEvent);
207     hough->DoBench(filename);
208   }
209   delete hough;
210 }
211
212 void AliHLTReconstructor::FillESD(AliRunLoader* runLoader, 
213                                   AliESD* esd) const
214 {
215   //fill the esd file with found tracks
216   Int_t iEvent = runLoader->GetEventNumber();
217
218   if(fDoTracker) FillESDforConformalMapping(esd,iEvent);
219   if(fDoHough) FillESDforHoughTransform(esd,iEvent);
220 }
221
222 void AliHLTReconstructor::FillESDforConformalMapping(AliESD* esd,Int_t iEvent) const
223 {
224   //fill esd with tracks from conformal mapping
225   Int_t slicerange[2]={0,35};
226   Int_t good = (int)(0.4*AliHLTTransform::GetNRows());
227   Int_t nclusters = (int)(0.4*AliHLTTransform::GetNRows());
228   Int_t nminpointsontracks = (int)(0.3*AliHLTTransform::GetNRows());
229   Float_t ptmin = 0.;
230   Float_t ptmax = 0.;
231   Float_t maxfalseratio = 0.1;
232   
233   AliHLTEvaluate *fHLTEval = new AliHLTEvaluate("./hlt",nclusters,good,ptmin,ptmax,slicerange);
234   fHLTEval->SetMaxFalseClusters(maxfalseratio);
235   fHLTEval->LoadData(iEvent,kTRUE);
236   fHLTEval->AssignPIDs();
237   fHLTEval->AssignIDs();
238   AliHLTTrackArray *fTracks = fHLTEval->GetTracks();
239   if(!fTracks){
240     delete fHLTEval;
241     return;
242   }
243   for(Int_t i=0; i<fTracks->GetNTracks(); i++)
244     {
245       AliHLTTrack *tpt = (AliHLTTrack *)fTracks->GetCheckedTrack(i);
246       if(!tpt) continue; 
247       if(tpt->GetNumberOfPoints() < nminpointsontracks) continue;
248       
249       AliESDHLTtrack *esdtrack = new AliESDHLTtrack() ; 
250
251       esdtrack->SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
252       esdtrack->SetNHits(tpt->GetNHits());
253       esdtrack->SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ());
254       esdtrack->SetLastPoint(tpt->GetLastPointX(),tpt->GetLastPointY(),tpt->GetLastPointZ());
255       esdtrack->SetPt(tpt->GetPt());
256       esdtrack->SetPsi(tpt->GetPsi());
257       esdtrack->SetTgl(tpt->GetTgl());
258       esdtrack->SetCharge(tpt->GetCharge());
259       esdtrack->SetMCid(tpt->GetMCid());
260       esdtrack->SetSector(tpt->GetSector());
261       esdtrack->SetPID(tpt->GetPID());
262       esdtrack->ComesFromMainVertex(tpt->ComesFromMainVertex());
263
264       esd->AddHLTConfMapTrack(esdtrack);
265       delete esdtrack;
266     }
267   delete fHLTEval;
268 }
269
270 void AliHLTReconstructor::FillESDforHoughTransform(AliESD* esd,Int_t iEvent) const
271 {
272   //fill esd with tracks from hough
273   char filename[256];
274   sprintf(filename,"./hough/tracks_%d.raw",iEvent);
275   
276   AliHLTFileHandler *tfile = new AliHLTFileHandler();
277   if(!tfile->SetBinaryInput(filename)){
278     LOG(AliHLTLog::kError,"AliHLTReconstructor::FillESDforHoughTransform","Input file")
279       <<" Missing file "<<filename<<ENDLOG;
280     return;
281   }
282   
283   AliHLTTrackArray *fTracks = new AliHLTTrackArray("AliHLTHoughTrack");
284   tfile->Binary2TrackArray(fTracks);
285   tfile->CloseBinaryInput();
286   delete tfile;
287   if(!fTracks) return; 
288   for(Int_t i=0; i<fTracks->GetNTracks(); i++)
289     {
290       AliHLTHoughTrack *tpt = (AliHLTHoughTrack *)fTracks->GetCheckedTrack(i);
291       if(!tpt) continue; 
292       
293       AliESDHLTtrack *esdtrack = new AliESDHLTtrack() ; 
294
295       esdtrack->SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
296       esdtrack->SetNHits(tpt->GetNHits());
297       esdtrack->SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ());
298       esdtrack->SetLastPoint(tpt->GetLastPointX(),tpt->GetLastPointY(),tpt->GetLastPointZ());
299       esdtrack->SetPt(tpt->GetPt());
300       esdtrack->SetPsi(tpt->GetPsi());
301       esdtrack->SetTgl(tpt->GetTgl());
302       esdtrack->SetCharge(tpt->GetCharge());
303       esdtrack->SetMCid(tpt->GetMCid());
304       esdtrack->SetWeight(tpt->GetWeight());
305       esdtrack->SetSector(tpt->GetSector());
306       esdtrack->SetBinXY(tpt->GetBinX(),tpt->GetBinY(),tpt->GetSizeX(),tpt->GetSizeY());
307       esdtrack->SetPID(tpt->GetPID());
308       esdtrack->ComesFromMainVertex(tpt->ComesFromMainVertex());
309
310       esd->AddHLTHoughTrack(esdtrack);
311       delete esdtrack;
312     }
313
314   delete fTracks;
315 }
316
317 AliTracker* AliHLTReconstructor::CreateTracker(AliRunLoader* runLoader) const
318 {
319   //Create HLT trackers for TPC and ITS
320
321   TString opt = GetOption();
322   if(!opt.CompareTo("TPC")) {
323     // Create Hough tracker for TPC
324     return new AliHLTTPCtracker(runLoader);
325   }
326   if(!opt.CompareTo("ITS")) {
327     // Create ITS tracker
328     return new AliHLTITStracker(0);
329   }
330   if(!opt.CompareTo("MUON")) {
331     return new AliHLTMUONTracker(runLoader);
332   }
333
334   return NULL;
335 }
336
337 void AliHLTReconstructor::FillDHLTRecPoint(AliRawReader* rawReader, Int_t nofEvent, Int_t dcCut = 0) const
338 {
339   // Hit recontruction for dimuon-HLT
340   AliHLTMUONHitReconstructor kdHLTRec(rawReader);
341
342   Int_t iEvent = 0 ;
343   kdHLTRec.SetDCCut(dcCut);
344   TString lookupTablePath = getenv("ALICE_ROOT");
345   lookupTablePath += "/HLT/MUON/src/AliRoot/Lut";
346   kdHLTRec.Init(lookupTablePath.Data(),lookupTablePath.Data());
347
348    while(rawReader->NextEvent() && iEvent < nofEvent){
349      AliInfo(Form("Event : %d",iEvent));
350      kdHLTRec.WriteDHLTRecHits(iEvent);  
351      iEvent++;
352    }
353
354 }
355
356 #endif