Added a method which loads TPC parameters in AliL3Transform through the runloader
[u/mrichter/AliRoot.git] / HLT / src / AliHLTReconstructor.cxx
1 // $Id$
2
3 ///////////////////////////////////////////////////////////////////////////////
4 //                                                                           //
5 // class for HLT reconstruction                                              //
6 // <Cvetan.Cheshkov@cern.ch>                                                 //
7 ///////////////////////////////////////////////////////////////////////////////
8
9 // very ugly but it has to work fast
10 #ifdef use_reconstruction
11
12 #include <Riostream.h>
13 #include <TSystem.h>
14 #include <TArrayF.h>
15
16 #include "AliL3StandardIncludes.h"
17 #include "AliL3Logging.h"
18 #include "AliLevel3.h"
19 #include "AliL3Evaluate.h"
20 #include "AliHLTReconstructor.h"
21 #include "AliL3Transform.h"
22 #include "AliL3Hough.h"
23 #include "AliL3FileHandler.h"
24 #include "AliL3Track.h"
25 #include "AliL3HoughTrack.h"
26 #include "AliL3TrackArray.h"
27 #include "AliRunLoader.h"
28 #include "AliHeader.h"
29 #include "AliGenEventHeader.h"
30 #include "AliESD.h"
31 #include "AliESDHLTtrack.h"
32
33 #if __GNUC__== 3
34 using namespace std;
35 #endif
36
37
38 ClassImp(AliHLTReconstructor)
39
40 void AliHLTReconstructor::Reconstruct(AliRunLoader* runLoader) const
41 {
42   if(!runLoader) {
43     LOG(AliL3Log::kFatal,"AliHLTReconstructor::Reconstruct","RunLoader")
44       <<" Missing RunLoader! 0x0"<<ENDLOG;
45     return;
46   }
47   gSystem->Exec("rm -rf hlt");
48   gSystem->MakeDirectory("hlt");
49   gSystem->Exec("rm -rf hough");
50   gSystem->MakeDirectory("hough");
51
52   Bool_t isinit=AliL3Transform::Init(runLoader);
53   if(!isinit){
54     cerr << "Could not create transform settings, please check log for error messages!" << endl;
55     return;
56   }
57
58   Int_t nEvents = runLoader->GetNumberOfEvents();
59
60   for(Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
61     runLoader->GetEvent(iEvent);
62
63     ReconstructWithConformalMapping(runLoader,iEvent);
64     ReconstructWithHoughTransform(runLoader,iEvent);
65   }
66 }
67
68 void AliHLTReconstructor::ReconstructWithConformalMapping(AliRunLoader* runLoader,Int_t iEvent) const
69 {
70   AliLevel3 *fHLT = new AliLevel3(runLoader);
71   fHLT->Init("./", AliLevel3::kRunLoader, 1);
72
73   Int_t phiSegments = 50;
74   Int_t etaSegments = 100;
75   Int_t trackletlength = 3;
76   Int_t tracklength = 10;
77   Int_t rowscopetracklet = 2;
78   Int_t rowscopetrack = 10;
79   Double_t minPtFit = 0;
80   Double_t maxangle = 0.1745;
81   Double_t goodDist = 5;
82   Double_t maxphi = 0.1;
83   Double_t maxeta = 0.1;
84   Double_t hitChi2Cut = 20;
85   Double_t goodHitChi2 = 5;
86   Double_t trackChi2Cut = 10;
87   Double_t xyerror = -1;
88   Double_t zerror =  -1;
89   
90   fHLT->SetClusterFinderParam(xyerror,zerror,kTRUE);
91   fHLT->SetTrackerParam(phiSegments, etaSegments, 
92                         trackletlength, tracklength,
93                         rowscopetracklet, rowscopetrack,
94                         minPtFit, maxangle, goodDist, hitChi2Cut,
95                         goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kTRUE);
96   fHLT->SetMergerParameters(2,3,0.003,0.1,0.05);
97   fHLT->DoMc();
98   fHLT->WriteFiles("./hlt/");  
99
100   fHLT->ProcessEvent(0, 35, iEvent);
101
102   char filename[256];
103   sprintf(filename, "confmap_%d",iEvent);
104   fHLT->DoBench(filename);
105
106   delete fHLT;
107
108 }
109
110 void AliHLTReconstructor::ReconstructWithHoughTransform(AliRunLoader* runLoader,Int_t iEvent) const
111 {
112   Float_t ptmin = 0.1*AliL3Transform::GetSolenoidField();
113
114   Float_t zvertex = 0;
115   TArrayF mcVertex(3); 
116   runLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
117   zvertex = mcVertex[2];
118
119   cout<<" Hough Tranform will run with ptmin="<<ptmin<<" and zvertex="<<zvertex<<endl;
120
121   AliL3Hough *hough = new AliL3Hough();
122     
123   hough->SetThreshold(4);
124   hough->SetTransformerParams(76,140,ptmin,-1);
125   hough->SetPeakThreshold(70,-1);
126   hough->SetRunLoader(runLoader);
127   hough->Init("./", kFALSE, 100, kFALSE,4,0,0,zvertex);
128   hough->SetAddHistograms();
129
130   for(int slice=0; slice<=35; slice++)
131     {
132       //     cout<<"Processing slice "<<slice<<endl;
133       hough->ReadData(slice,iEvent);
134       hough->Transform();
135       hough->AddAllHistogramsRows();
136       hough->FindTrackCandidatesRow();
137       //     hough->WriteTracks(slice,"./hough");
138       hough->AddTracks();
139     }
140   hough->WriteTracks("./hough");
141   
142   char filename[256];
143   sprintf(filename, "hough_%d",iEvent);
144   hough->DoBench(filename);
145
146   delete hough;
147 }
148
149 void AliHLTReconstructor::FillESD(AliRunLoader* runLoader, 
150                                   AliESD* esd) const
151 {
152   Int_t iEvent = runLoader->GetEventNumber();
153
154   FillESDforConformalMapping(esd,iEvent);
155   FillESDforHoughTransform(esd,iEvent);
156 }
157
158 void AliHLTReconstructor::FillESDforConformalMapping(AliESD* esd,Int_t iEvent) const
159 {
160   //Assign MC labels for found tracks
161   int slicerange[2]={0,35};
162   int good = (int)(0.4*AliL3Transform::GetNRows());
163   int nclusters = (int)(0.4*AliL3Transform::GetNRows());
164   float ptmin = 0.;
165   float ptmax = 0.;
166   float maxfalseratio = 0.1;
167   
168   AliL3Evaluate *fHLTEval = new AliL3Evaluate("./hlt",nclusters,good,ptmin,ptmax,slicerange);
169   fHLTEval->SetMaxFalseClusters(maxfalseratio);
170
171   fHLTEval->LoadData(iEvent,kTRUE);
172   fHLTEval->AssignPIDs();
173   fHLTEval->AssignIDs();
174   AliL3TrackArray *fTracks = fHLTEval->GetTracks();
175   for(Int_t i=0; i<fTracks->GetNTracks(); i++)
176     {
177       AliL3Track *tpt = (AliL3Track *)fTracks->GetCheckedTrack(i);
178       if(!tpt) continue; 
179       
180       AliESDHLTtrack *esdtrack = new AliESDHLTtrack() ; 
181
182       esdtrack->SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
183       esdtrack->SetNHits(tpt->GetNHits());
184       esdtrack->SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ());
185       esdtrack->SetLastPoint(tpt->GetLastPointX(),tpt->GetLastPointY(),tpt->GetLastPointZ());
186       esdtrack->SetPt(tpt->GetPt());
187       esdtrack->SetPsi(tpt->GetPsi());
188       esdtrack->SetTgl(tpt->GetTgl());
189       esdtrack->SetCharge(tpt->GetCharge());
190       esdtrack->SetMCid(tpt->GetMCid());
191       esdtrack->SetSector(tpt->GetSector());
192       esdtrack->SetPID(tpt->GetPID());
193       esdtrack->ComesFromMainVertex(tpt->ComesFromMainVertex());
194
195       esd->AddHLTConfMapTrack(esdtrack);
196       delete esdtrack;
197     }
198
199   delete fHLTEval;
200 }
201
202 void AliHLTReconstructor::FillESDforHoughTransform(AliESD* esd,Int_t iEvent) const
203 {
204   char filename[256];
205   sprintf(filename,"./hough/tracks_%d.raw",iEvent);
206   
207   AliL3FileHandler *tfile = new AliL3FileHandler();
208   if(!tfile->SetBinaryInput(filename)){
209     Error("FillESD","Inputfile ",filename," does not exist");
210     return;
211   }
212   
213   AliL3TrackArray *fTracks = new AliL3TrackArray("AliL3HoughTrack");
214   tfile->Binary2TrackArray(fTracks);
215   tfile->CloseBinaryInput();
216   delete tfile;
217   
218   for(Int_t i=0; i<fTracks->GetNTracks(); i++)
219     {
220       AliL3HoughTrack *tpt = (AliL3HoughTrack *)fTracks->GetCheckedTrack(i);
221       if(!tpt) continue; 
222       
223       AliESDHLTtrack *esdtrack = new AliESDHLTtrack() ; 
224
225       esdtrack->SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
226       esdtrack->SetNHits(tpt->GetNHits());
227       esdtrack->SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ());
228       esdtrack->SetLastPoint(tpt->GetLastPointX(),tpt->GetLastPointY(),tpt->GetLastPointZ());
229       esdtrack->SetPt(tpt->GetPt());
230       esdtrack->SetPsi(tpt->GetPsi());
231       esdtrack->SetTgl(tpt->GetTgl());
232       esdtrack->SetCharge(tpt->GetCharge());
233       esdtrack->SetMCid(tpt->GetMCid());
234       esdtrack->SetWeight(tpt->GetWeight());
235       esdtrack->SetSector(tpt->GetSector());
236       esdtrack->SetBinXY(tpt->GetBinX(),tpt->GetBinY(),tpt->GetSizeX(),tpt->GetSizeY());
237       esdtrack->SetPID(tpt->GetPID());
238       esdtrack->ComesFromMainVertex(tpt->ComesFromMainVertex());
239
240       esd->AddHLTHoughTrack(esdtrack);
241       delete esdtrack;
242     }
243
244   delete fTracks;
245 }
246
247 #endif