reverting to version 1.12 due to new library dependencies
[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>
16
b1ed0288 17#include <AliRunLoader.h>
18#include <AliHeader.h>
19#include <AliGenEventHeader.h>
20#include <AliESD.h>
21#include <AliESDHLTtrack.h>
22
4aa41877 23#include "AliHLTStandardIncludes.h"
24#include "AliHLTLogging.h"
de3c3890 25#include "AliLevel3.h"
4aa41877 26#include "AliHLTEvaluate.h"
de3c3890 27#include "AliHLTReconstructor.h"
4aa41877 28#include "AliHLTTransform.h"
29#include "AliHLTHough.h"
30#include "AliHLTFileHandler.h"
31#include "AliHLTTrack.h"
32#include "AliHLTHoughTrack.h"
33#include "AliHLTTrackArray.h"
de3c3890 34
f644512a 35#include "AliRun.h"
36#include "AliITS.h"
4aa41877 37#include "AliHLTITStracker.h"
38#include "AliHLTTPCtracker.h"
43f15f99 39#include "MUON/src/AliRoot/AliHLTMUONTracker.h"
8a296f1c 40#include "MUON/src/AliRoot/AliHLTMUONHitReconstructor.h"
41#include "AliRawReader.h"
de3c3890 42#if __GNUC__== 3
43using namespace std;
44#endif
45
de3c3890 46ClassImp(AliHLTReconstructor)
47
000fb6e2 48AliHLTReconstructor::AliHLTReconstructor(): AliReconstructor()
b1ed0288 49{
50 //constructor
6e61c746 51#ifndef use_logging
4aa41877 52 AliHLTLog::fgLevel=AliHLTLog::kWarning;
6e61c746 53#endif
000fb6e2 54 fDoTracker=1;
55 fDoHough=0;
56 fDoBench=0;
57 fDoCleanUp=1;
ff0a6788 58}
59
000fb6e2 60AliHLTReconstructor::AliHLTReconstructor(Bool_t doTracker, Bool_t doHough): AliReconstructor()
61{
b1ed0288 62 //constructor
6e61c746 63#ifndef use_logging
4aa41877 64 AliHLTLog::fgLevel=AliHLTLog::kWarning;
6e61c746 65#endif
000fb6e2 66 fDoTracker=doTracker;
67 fDoHough=doHough;
ff0a6788 68 fDoBench=0;
000fb6e2 69 fDoCleanUp=1;
ff0a6788 70}
71
72AliHLTReconstructor::~AliHLTReconstructor()
b1ed0288 73{
000fb6e2 74 //deconstructor
ff0a6788 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
000fb6e2 86void AliHLTReconstructor::Reconstruct(AliRunLoader* runLoader) const
de3c3890 87{
000fb6e2 88 // do the standard and hough reconstruction chain
9a74ed1c 89 if(!runLoader) {
000fb6e2 90 LOG(AliHLTLog::kFatal,"AliHLTReconstructor::Reconstruct","RunLoader")
91 <<" Missing RunLoader! 0x0"<<ENDLOG;
cefeb80d 92 return;
9a74ed1c 93 }
000fb6e2 94 gSystem->Exec("rm -rf hlt");
95 gSystem->MakeDirectory("hlt");
96 gSystem->Exec("rm -rf hough");
97 gSystem->MakeDirectory("hough");
de3c3890 98
000fb6e2 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;
9b4aa2e5 103 return;
104 }
105
106 Int_t nEvents = runLoader->GetNumberOfEvents();
9b4aa2e5 107
000fb6e2 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);
de3c3890 113 }
114}
115
116void AliHLTReconstructor::ReconstructWithConformalMapping(AliRunLoader* runLoader,Int_t iEvent) const
117{
b1ed0288 118 // reconstruct with conformal mapper
de3c3890 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);
8c717250 145 fHLT->SetTrackerParam(phiSegments, etaSegments,
146 trackletlength, tracklength,
147 rowscopetracklet, rowscopetrack,
148 minPtFit, maxangle, goodDist, hitChi2Cut,
149 goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kFALSE);
de3c3890 150 fHLT->SetMergerParameters(2,3,0.003,0.1,0.05);
151 fHLT->DoMc();
8c717250 152 fHLT->DoNonVertexTracking(); /*2 tracking passes, last without vertex contraint.*/
de3c3890 153 fHLT->WriteFiles("./hlt/");
de3c3890 154 fHLT->ProcessEvent(0, 35, iEvent);
2456c180 155 if(fDoBench){
156 char filename[256];
157 sprintf(filename, "confmap_%d",iEvent);
158 fHLT->DoBench(filename);
159 }
de3c3890 160
161 delete fHLT;
de3c3890 162}
163
164void AliHLTReconstructor::ReconstructWithHoughTransform(AliRunLoader* runLoader,Int_t iEvent) const
165{
b1ed0288 166 //reconstruct with hough
f644512a 167 //not used anymore, Hough tracking is moved out of the local
168 //reconstruction chain
4aa41877 169 Float_t ptmin = 0.1*AliHLTTransform::GetSolenoidField();
de3c3890 170
171 Float_t zvertex = 0;
172 TArrayF mcVertex(3);
69fe5bee 173 AliHeader * header = runLoader->GetHeader();
174 if (header) {
175 AliGenEventHeader * genHeader = header->GenEventHeader();
176 if (genHeader) genHeader->PrimaryVertex(mcVertex);
177 }
de3c3890 178 zvertex = mcVertex[2];
179
4aa41877 180 LOG(AliHLTLog::kInformational,"AliHLTReconstructor::Reconstruct","HoughTransform")
8c717250 181 <<" Hough Transform will run with ptmin="<<ptmin<<" and zvertex="<<zvertex<<ENDLOG;
de3c3890 182
4aa41877 183 AliHLTHough *hough = new AliHLTHough();
de3c3890 184
185 hough->SetThreshold(4);
1e75562a 186 hough->CalcTransformerParams(ptmin);
de3c3890 187 hough->SetPeakThreshold(70,-1);
188 hough->SetRunLoader(runLoader);
189 hough->Init("./", kFALSE, 100, kFALSE,4,0,0,zvertex);
190 hough->SetAddHistograms();
191
8c717250 192 for(Int_t slice=0; slice<=35; slice++)
de3c3890 193 {
8c717250 194 //cout<<"Processing slice "<<slice<<endl;
de3c3890 195 hough->ReadData(slice,iEvent);
196 hough->Transform();
197 hough->AddAllHistogramsRows();
198 hough->FindTrackCandidatesRow();
8c717250 199 //hough->WriteTracks(slice,"./hough");
de3c3890 200 hough->AddTracks();
201 }
202 hough->WriteTracks("./hough");
203
2456c180 204 if(fDoBench){
205 char filename[256];
206 sprintf(filename, "hough_%d",iEvent);
207 hough->DoBench(filename);
208 }
de3c3890 209 delete hough;
210}
211
212void AliHLTReconstructor::FillESD(AliRunLoader* runLoader,
213 AliESD* esd) const
214{
b1ed0288 215 //fill the esd file with found tracks
de3c3890 216 Int_t iEvent = runLoader->GetEventNumber();
000fb6e2 217
8c717250 218 if(fDoTracker) FillESDforConformalMapping(esd,iEvent);
219 if(fDoHough) FillESDforHoughTransform(esd,iEvent);
de3c3890 220}
221
222void AliHLTReconstructor::FillESDforConformalMapping(AliESD* esd,Int_t iEvent) const
223{
b1ed0288 224 //fill esd with tracks from conformal mapping
8c717250 225 Int_t slicerange[2]={0,35};
4aa41877 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());
8c717250 229 Float_t ptmin = 0.;
230 Float_t ptmax = 0.;
231 Float_t maxfalseratio = 0.1;
de3c3890 232
4aa41877 233 AliHLTEvaluate *fHLTEval = new AliHLTEvaluate("./hlt",nclusters,good,ptmin,ptmax,slicerange);
de3c3890 234 fHLTEval->SetMaxFalseClusters(maxfalseratio);
de3c3890 235 fHLTEval->LoadData(iEvent,kTRUE);
236 fHLTEval->AssignPIDs();
237 fHLTEval->AssignIDs();
4aa41877 238 AliHLTTrackArray *fTracks = fHLTEval->GetTracks();
2456c180 239 if(!fTracks){
240 delete fHLTEval;
241 return;
242 }
de3c3890 243 for(Int_t i=0; i<fTracks->GetNTracks(); i++)
244 {
4aa41877 245 AliHLTTrack *tpt = (AliHLTTrack *)fTracks->GetCheckedTrack(i);
de3c3890 246 if(!tpt) continue;
244a5ed5 247 if(tpt->GetNumberOfPoints() < nminpointsontracks) continue;
de3c3890 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 }
de3c3890 267 delete fHLTEval;
268}
269
270void AliHLTReconstructor::FillESDforHoughTransform(AliESD* esd,Int_t iEvent) const
271{
b1ed0288 272 //fill esd with tracks from hough
de3c3890 273 char filename[256];
274 sprintf(filename,"./hough/tracks_%d.raw",iEvent);
275
4aa41877 276 AliHLTFileHandler *tfile = new AliHLTFileHandler();
de3c3890 277 if(!tfile->SetBinaryInput(filename)){
4aa41877 278 LOG(AliHLTLog::kError,"AliHLTReconstructor::FillESDforHoughTransform","Input file")
2456c180 279 <<" Missing file "<<filename<<ENDLOG;
de3c3890 280 return;
281 }
282
4aa41877 283 AliHLTTrackArray *fTracks = new AliHLTTrackArray("AliHLTHoughTrack");
de3c3890 284 tfile->Binary2TrackArray(fTracks);
285 tfile->CloseBinaryInput();
286 delete tfile;
2456c180 287 if(!fTracks) return;
de3c3890 288 for(Int_t i=0; i<fTracks->GetNTracks(); i++)
289 {
4aa41877 290 AliHLTHoughTrack *tpt = (AliHLTHoughTrack *)fTracks->GetCheckedTrack(i);
de3c3890 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}
f644512a 316
317AliTracker* 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
4aa41877 324 return new AliHLTTPCtracker(runLoader);
f644512a 325 }
326 if(!opt.CompareTo("ITS")) {
327 // Create ITS tracker
e341247d 328 return new AliHLTITStracker(0);
f644512a 329 }
43f15f99 330 if(!opt.CompareTo("MUON")) {
331 return new AliHLTMUONTracker(runLoader);
332 }
f644512a 333
334 return NULL;
335}
336
8a296f1c 337void 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
de3c3890 356#endif