]>
Commit | Line | Data |
---|---|---|
108615fc | 1 | //Author: Uli Frankenfeld |
2 | //Author: Anders Strand Vestbo | |
3 | //Last Modified: 13.12.2000 | |
4 | ||
5 | #include "AliL3Logging.h" | |
6 | ||
7 | #include <TFile.h> | |
8 | #include <TDirectory.h> | |
9 | #include <TClonesArray.h> | |
10 | #include <TStopwatch.h> | |
11 | #include <iostream.h> | |
12 | ||
13 | //#include <AliTPCcluster.h> | |
14 | //#include "AliTPCParam.h" | |
15 | #include "AliLevel3.h" | |
16 | #include "AliL3ConfMapper.h" | |
17 | #include "AliL3Vertex.h" | |
18 | #include "AliL3VertexFinder.h" | |
19 | #include "AliL3TrackMerger.h" | |
20 | #include "AliL3GlobalMerger.h" | |
21 | #include "AliL3InterMerger.h" | |
22 | #include "AliL3ConfMapPoint.h" | |
23 | #include "AliL3ConfMapTrack.h" | |
24 | #include "AliL3Transform.h" | |
25 | #include "AliL3ClustFinder.h" | |
26 | #include "AliL3DigitData.h" | |
27 | #include "AliL3TrackArray.h" | |
28 | #include "AliL3MemHandler.h" | |
29 | #include "AliL3FileHandler.h" | |
30 | #include "AliL3Benchmark.h" | |
31 | ||
32 | #include "AliL3DigitData.h" | |
33 | #include "AliL3TrackSegmentData.h" | |
34 | #include "AliL3SpacePointData.h" | |
35 | #include "AliL3VertexData.h" | |
36 | ||
37 | //_______________________________________ | |
38 | // | |
39 | // AliLevel3 | |
40 | // | |
41 | // Interface class for Level3 tracker. | |
42 | // Tracking is done by calling constructor with input,output | |
43 | // given as argument. | |
44 | // You must always remember to set the tracking parameters. E.g.: | |
45 | // | |
46 | // AliLevel3 *level3 = new AliLevel3(inputfile,outputfile); | |
47 | // level3->SetTrackerParam(); //Sets default tracking parameters | |
48 | // level3->ProcessSector(2,2); //Does tracking on sector 2 (actually 2+38) | |
49 | ||
50 | ClassImp(AliLevel3) | |
51 | ||
52 | AliLevel3::AliLevel3(){ | |
53 | fInputFile=0; | |
54 | fOutputFile=0; | |
55 | Init(); | |
56 | } | |
57 | ||
58 | AliLevel3::AliLevel3(Char_t *infile,Char_t *outfile){ | |
59 | //Constructor. Calls constructor of the tracker, vertexfinder and merger classes. | |
60 | ||
61 | fOutputFile = new TFile(outfile,"NEW"); | |
62 | ||
63 | if(!fOutputFile->IsOpen()) | |
64 | { | |
65 | LOG(AliL3Log::kWarning, "AliLevel3::AliLevel3","File Open") | |
66 | <<"Delete your old "<<outfile<<" file!"<<ENDLOG; | |
67 | } | |
68 | fInputFile = new TFile(infile,"READ"); | |
69 | ||
70 | if(!fInputFile->IsOpen()) | |
71 | { | |
72 | LOG(AliL3Log::kError,"AliLevel3::AliLevel3","File Open") | |
73 | <<"Inputfile "<<infile<<" does not exist"<<ENDLOG; | |
74 | return; | |
75 | } | |
76 | ||
77 | Init(); | |
78 | } | |
79 | ||
80 | AliLevel3::AliLevel3(TFile *in, TFile *out){ | |
81 | fOutputFile = out; | |
82 | fInputFile = in; | |
83 | if(!in){ | |
84 | LOG(AliL3Log::kError,"AliLevel3::AliLevel3","File Open") | |
85 | <<"Pointer to InFile 0x0!"<<ENDLOG; | |
86 | return; | |
87 | } | |
88 | if(!out){ | |
89 | LOG(AliL3Log::kError,"AliLevel3::AliLevel3","File Open") | |
90 | <<"Pointer to OutFile 0x0!"<<ENDLOG; | |
91 | return; | |
92 | } | |
93 | ||
94 | if(!fOutputFile->IsOpen()) | |
95 | { | |
96 | LOG(AliL3Log::kWarning,"AliLevel3::AliLevel3","File Open") | |
97 | <<"no output file!"<<ENDLOG; | |
98 | return; | |
99 | } | |
100 | if(!fInputFile->IsOpen()) | |
101 | { | |
102 | LOG(AliL3Log::kError,"AliLevel3::AliLevel3","File Open") | |
103 | <<"Inputfile does not exist"<<ENDLOG; | |
104 | return; | |
105 | } | |
106 | Init(); | |
107 | } | |
108 | ||
109 | void AliLevel3::Init(){ | |
110 | fWriteOut = kFALSE; | |
111 | fGlobalMerger=0; | |
112 | fTransformer = new AliL3Transform(); | |
113 | fDoRoi = kFALSE; | |
114 | fUseBinary =kFALSE; | |
115 | SetPath(""); | |
116 | fFindVertex =kTRUE; | |
117 | fNPatch = 5; //number of patches change row in process | |
118 | fVertexFinder = new AliL3VertexFinder(); | |
119 | fVertex = new AliL3Vertex(); | |
120 | fTracker = new AliL3ConfMapper(); | |
121 | fTrackMerger = new AliL3TrackMerger(fNPatch); | |
122 | fInterMerger = new AliL3InterMerger(); | |
123 | fFileHandler = new AliL3FileHandler(); | |
124 | fFileHandler->SetAliInput(fInputFile); | |
125 | fBenchmark = new AliL3Benchmark(); | |
126 | } | |
127 | ||
128 | void AliLevel3::DoBench(char* name){ | |
129 | fBenchmark->Analyze(name); | |
130 | } | |
131 | ||
132 | void AliLevel3::DoMc(char* file){ | |
133 | if(!fFileHandler->IsDigit()) | |
134 | fFileHandler->SetMCOutput(file); | |
135 | } | |
136 | ||
137 | AliLevel3::~AliLevel3(){ | |
138 | //Destructor | |
139 | if(fVertexFinder) delete fVertexFinder; | |
140 | if(fVertex) delete fVertex; | |
141 | if(fTracker) delete fTracker; | |
142 | if(fTransformer) delete fTransformer; | |
143 | if(fTrackMerger) delete fTrackMerger; | |
144 | if(fInterMerger) delete fInterMerger; | |
145 | if(fFileHandler) delete fFileHandler; | |
146 | } | |
147 | ||
148 | void AliLevel3::SetTrackerParam(Int_t phi_segments, Int_t eta_segments, | |
149 | Int_t trackletlength, Int_t tracklength, | |
150 | Int_t rowscopetracklet, Int_t rowscopetrack, | |
151 | Double_t min_pt_fit, Double_t maxangle, | |
152 | Double_t goodDist, Double_t hitChi2Cut, | |
153 | Double_t goodHitChi2, Double_t trackChi2Cut, | |
154 | Int_t maxdist) | |
155 | { | |
156 | //Set parameters input to the tracker | |
157 | //If no arguments are given, default parameters will be used | |
158 | ||
159 | fTracker->SetNSegments(phi_segments,eta_segments); | |
160 | fTracker->MainVertexSettings(trackletlength,tracklength,rowscopetracklet,rowscopetrack); | |
161 | fTracker->SetMaxDca(min_pt_fit); | |
162 | fTracker->SetTrackletCuts(maxangle,goodDist,true); | |
163 | fTracker->SetTrackCuts(hitChi2Cut,goodHitChi2,trackChi2Cut,maxdist); | |
164 | ||
165 | fTracker->SetParamDone(true); | |
166 | } | |
167 | ||
168 | void AliLevel3::ProcessEvent(Int_t first,Int_t last){ | |
169 | //Do tracking on all slices in region [first,last] | |
170 | //Slices numbering in TPC goes from 0-35, which means that 1 slice | |
171 | //corresponds to inner+outer sector.E.g. slice 2 corresponds to | |
172 | //inner=2 + outer=38. | |
173 | fGlobalMerger= new AliL3GlobalMerger(first,last); | |
174 | for(Int_t i=first; i<=last; i++){ | |
175 | ProcessSlice(i); | |
176 | fGlobalMerger->SetVertex(fVertex); | |
177 | fGlobalMerger->SetTransformer(fTransformer); | |
178 | fGlobalMerger->InitSlice(i); | |
179 | fBenchmark->Start("Fill Global Merger"); | |
180 | fGlobalMerger->FillTracks(fNTrackData,fTrackData); | |
181 | fBenchmark->Stop("Fill Global Merger"); | |
182 | fFileHandler->Free(); //free the memory | |
183 | fNTrackData=0; | |
184 | fTrackData=0; | |
185 | } | |
186 | fBenchmark->Start("Global Merger"); | |
187 | fGlobalMerger->Merge(); | |
188 | // fGlobalMerger->SlowMerge(); | |
189 | fBenchmark->Stop("Global Merger"); | |
190 | ||
191 | if(fWriteOut) WriteResults(); | |
192 | delete fGlobalMerger; fGlobalMerger = 0; | |
193 | } | |
194 | ||
195 | void AliLevel3::ProcessSlice(Int_t slice){ | |
196 | char name[256]; | |
197 | Bool_t isdigit = fFileHandler->IsDigit(); | |
198 | // Int_t row[5][2] = {{ 0,173}}; | |
199 | Int_t row[5][2] = {{ 0, 45},{46,77},{78,109},{110,141},{142,173}}; | |
200 | const Int_t maxpoints=100000; | |
201 | const Int_t pointsize = maxpoints * sizeof(AliL3SpacePointData); | |
202 | AliL3MemHandler *memory = new AliL3MemHandler(); | |
203 | ||
204 | fTrackMerger->Reset(); | |
205 | fTrackMerger->SetTransformer(fTransformer); | |
206 | fTrackMerger->SetRows(row[0]); | |
207 | for(Int_t patch=fNPatch-1;patch>=0;patch--){ | |
208 | fFileHandler->Init(slice,patch,row[patch]); | |
209 | fFileHandler->Init(fTransformer); | |
210 | UInt_t npoints=0; | |
211 | AliL3SpacePointData *points =0; | |
212 | UInt_t ndigits=0; | |
213 | AliL3DigitRowData *digits =0; | |
214 | if(fUseBinary){ | |
215 | ||
216 | if(!fDoRoi){ | |
217 | if(0){ //Binary to Memory | |
218 | fFileHandler->Free(); | |
219 | sprintf(name,"%sdigits_%d_%d.raw",fPath,slice,patch); | |
220 | fFileHandler->SetBinaryInput(name); | |
221 | digits= (AliL3DigitRowData *)fFileHandler->CompBinary2Memory(ndigits); | |
222 | fFileHandler->CloseBinaryInput(); | |
223 | } | |
224 | ||
225 | if(1){ //Binary to Memory with Benchmark | |
226 | fFileHandler->Free(); | |
227 | sprintf(name,"%sdigits_%d_%d.raw",fPath,slice,patch); | |
228 | memory->SetBinaryInput(name); | |
229 | UInt_t compsize=memory->GetFileSize(); | |
230 | UInt_t *comp=(UInt_t *)memory->Allocate(compsize); | |
231 | memory->CompBinary2CompMemory(ndigits,comp); | |
232 | memory->CloseBinaryInput(); | |
233 | UInt_t datasize=memory->GetMemorySize(ndigits,comp); | |
234 | digits=(AliL3DigitRowData *)fFileHandler->Allocate(datasize); | |
235 | fBenchmark->Start("Unpacker"); | |
236 | fFileHandler->CompMemory2Memory(ndigits,digits,comp); | |
237 | fBenchmark->Stop("Unpacker"); | |
238 | memory->Free(); | |
239 | } | |
240 | ||
241 | if(0){ //Binary to Memory with Random | |
242 | fFileHandler->Free(); | |
243 | fFileHandler->ResetRandom(); | |
244 | fFileHandler->SetRandomCluster(100); | |
245 | fFileHandler->SetNGenerate(100); | |
246 | sprintf(name,"%sdigits_%d_%d.raw",fPath,slice,patch); | |
247 | memory->SetBinaryInput(name); | |
248 | UInt_t compsize=memory->GetFileSize(); | |
249 | UInt_t *comp=(UInt_t *)memory->Allocate(compsize); | |
250 | memory->CompBinary2CompMemory(ndigits,comp); | |
251 | memory->CloseBinaryInput(); | |
252 | UInt_t dsize=memory->GetMemorySize(ndigits,comp); | |
253 | UInt_t rsize=fFileHandler->GetRandomSize(); | |
254 | digits=(AliL3DigitRowData*)fFileHandler->Allocate(dsize+rsize); | |
255 | fBenchmark->Start("Unpacker"); | |
256 | fFileHandler->CompMemory2Memory(ndigits,digits,comp); | |
257 | fBenchmark->Stop("Unpacker"); | |
258 | memory->Free(); | |
259 | if(1) | |
260 | cerr<<endl<<dsize/1024<<" "<<rsize/1024<<" " | |
261 | <<100.*rsize/dsize<<"%"<<endl; | |
262 | } | |
263 | } | |
264 | ||
265 | else{ //Binary to Memory with Roi | |
266 | fFileHandler->Free(); | |
267 | Int_t sli[2]={0,0}; | |
268 | fFileHandler->SetROI(fEta,sli); | |
269 | sprintf(name,"%sdigits_%d_%d.raw",fPath,slice,patch); | |
270 | memory->SetBinaryInput(name); | |
271 | UInt_t compsize=memory->GetFileSize(); | |
272 | UInt_t *comp=(UInt_t *)memory->Allocate(compsize); | |
273 | memory->CompBinary2CompMemory(ndigits,comp); | |
274 | memory->CloseBinaryInput(); | |
275 | UInt_t datasize=memory->GetMemorySize(ndigits,comp); | |
276 | digits=(AliL3DigitRowData *)fFileHandler->Allocate(datasize); | |
277 | fBenchmark->Start("Unpacker"); | |
278 | datasize = fFileHandler->CompMemory2Memory(ndigits,digits,comp); | |
279 | fBenchmark->Stop("Unpacker"); | |
280 | memory->Free(); | |
281 | if(1) | |
282 | cerr<<endl<<datasize/1024<<" "<<endl; | |
283 | } | |
284 | ||
285 | ||
286 | points = (AliL3SpacePointData *) memory->Allocate(pointsize); | |
287 | ||
288 | fClusterFinder = new AliL3ClustFinder(fTransformer); | |
289 | fClusterFinder->InitSlice(slice,patch,row[patch][0],row[patch][1] | |
290 | ,maxpoints); | |
291 | fClusterFinder->SetXYError(0.1); | |
292 | fClusterFinder->SetZError(0.2); | |
293 | fClusterFinder->SetOutputArray(points); | |
294 | fBenchmark->Start("Read Cluster Finder"); | |
295 | fClusterFinder->Read(ndigits,digits); | |
296 | fBenchmark->Stop("Read Cluster Finder"); | |
297 | fBenchmark->Start("Cluster Finder"); | |
298 | fClusterFinder->ProcessDigits(); | |
299 | fBenchmark->Stop("Cluster Finder"); | |
300 | npoints = fClusterFinder->GetNumberOfClusters(); | |
301 | delete fClusterFinder; | |
302 | fClusterFinder =0; | |
303 | fFileHandler->Free(); | |
304 | ||
305 | LOG(AliL3Log::kInformational,"AliLevel3::ProcessSlice","Cluster Finder") | |
306 | <<AliL3Log::kDec<<"Found "<<npoints<<" Points"<<ENDLOG; | |
307 | } | |
308 | ||
309 | else{ | |
310 | if(isdigit){ | |
311 | sprintf(name,"digits_%d_%d.raw",slice,patch); | |
312 | ||
313 | if(0){ //Ali to Binary | |
314 | fFileHandler->SetBinaryOutput(name); | |
315 | fFileHandler->AliDigits2CompBinary(); | |
316 | fFileHandler->CloseBinaryOutput(); | |
317 | } | |
318 | ||
319 | if(1){ //Ali to Memory | |
320 | digits=(AliL3DigitRowData *)fFileHandler->AliDigits2Memory(ndigits); | |
321 | if(fWriteOut){ //Memory to Binary | |
322 | fFileHandler->SetBinaryOutput(name); | |
323 | fFileHandler->Memory2CompBinary(ndigits,digits); | |
324 | fFileHandler->CloseBinaryOutput(); | |
325 | } | |
326 | } | |
327 | } | |
328 | else points = fFileHandler->AliPoints2Memory(npoints); | |
329 | } | |
330 | ||
331 | if(patch == fNPatch-1){ | |
332 | // Vertex | |
333 | if(fFindVertex){ | |
334 | // Vertex Finder | |
335 | ||
336 | fBenchmark->Start("Vertex Finder Read"); | |
337 | fVertexFinder->Reset(); | |
338 | fVertexFinder->Read(npoints,points); | |
339 | fBenchmark->Stop("Vertex Finder Read"); | |
340 | fBenchmark->Start("Vertex Finder"); | |
341 | fVertexFinder->Analyze(); | |
342 | AliL3VertexData vertex[1]; | |
343 | fVertexFinder->Write(vertex); | |
344 | fVertex->Read(vertex); | |
345 | fBenchmark->Stop("Vertex Finder"); | |
346 | } | |
347 | else{ | |
348 | //use 0,0,0 for vertex | |
349 | fVertex->SetZero(); | |
350 | } | |
351 | fTrackMerger->SetVertex(fVertex); | |
352 | } | |
353 | fTracker->InitSector(slice,row[patch]); | |
354 | fTracker->SetVertex(fVertex); | |
355 | fBenchmark->Start("Tracker Read Hits"); | |
356 | fTracker->ReadHits(npoints,points); | |
357 | fBenchmark->Stop("Tracker Read Hits"); | |
358 | fBenchmark->Start("MainVertexTracking A"); | |
359 | fTracker->MainVertexTracking_a(); | |
360 | fBenchmark->Stop("MainVertexTracking A"); | |
361 | fBenchmark->Start("MainVertexTracking B"); | |
362 | fTracker->MainVertexTracking_b(); | |
363 | fBenchmark->Stop("MainVertexTracking B"); | |
364 | fBenchmark->Start("Tracking fit"); | |
365 | fTracker->FillTracks(); | |
366 | fBenchmark->Stop("Tracking fit"); | |
367 | ||
368 | if(fWriteOut) | |
369 | WriteSpacePoints(npoints, points, slice, patch); //do after Tracking | |
370 | fFileHandler->Free(); | |
371 | ||
372 | UInt_t ntracks0 =0; | |
373 | AliL3TrackSegmentData *trackdata0 = | |
374 | (AliL3TrackSegmentData *) memory->Allocate(fTracker->GetTracks()); | |
375 | memory->TrackArray2Memory(ntracks0,trackdata0,fTracker->GetTracks()); | |
376 | ||
377 | //write tracks | |
378 | if(fWriteOut){ | |
379 | sprintf(name,"tracks_tr_%d_%d.raw",slice,patch); | |
380 | memory->SetBinaryOutput(name); | |
381 | memory->Memory2Binary(ntracks0,trackdata0); | |
382 | memory->CloseBinaryOutput(); | |
383 | } | |
384 | ||
385 | fInterMerger->Reset(); | |
386 | fInterMerger->SetTransformer(fTransformer); | |
387 | fInterMerger->Init(row[patch],patch); | |
388 | ||
389 | fBenchmark->Start("Fill Inter Merger"); | |
390 | fInterMerger->FillTracks(ntracks0,trackdata0); | |
391 | fBenchmark->Stop("Fill Inter Merger"); | |
392 | fBenchmark->Start("Inter Merger"); | |
393 | fInterMerger->Merge(); | |
394 | // fInterMerger->SlowMerge(); | |
395 | ||
396 | fBenchmark->Stop("Inter Merger"); | |
397 | ||
398 | //write inter merged tracks | |
399 | if(fWriteOut){ | |
400 | sprintf(name,"tracks_im_%d_%d.raw",slice,patch); | |
401 | WriteTracks(name,fInterMerger,'i'); //write output of intermerger | |
402 | } | |
403 | memory->Free(); | |
404 | ||
405 | UInt_t ntracks1 =0; | |
406 | AliL3TrackSegmentData *trackdata1 = | |
407 | (AliL3TrackSegmentData *) memory->Allocate(fInterMerger->GetInTracks(0)); | |
408 | memory->TrackArray2Memory(ntracks1,trackdata1,fInterMerger->GetInTracks(0)); | |
409 | ||
410 | fTrackMerger->InitSector(slice,patch); | |
411 | fBenchmark->Start("Fill Patch Merger"); | |
412 | fTrackMerger->FillTracks(ntracks1,trackdata1); | |
413 | fBenchmark->Stop("Fill Patch Merger"); | |
414 | ||
415 | memory->Free(); | |
416 | } | |
417 | fBenchmark->Start("Patch Merger"); | |
418 | // fTrackMerger->SlowMerge(); | |
419 | fTrackMerger->Merge(); | |
420 | fBenchmark->Stop("Patch Merger"); | |
421 | //write merged tracks | |
422 | if(fWriteOut){ | |
423 | sprintf(name,"tracks_tm_%d.raw",slice); | |
424 | WriteTracks(name,fTrackMerger,'o'); //write output of trackmerger | |
425 | } | |
426 | ||
427 | fTrackData = (AliL3TrackSegmentData *) | |
428 | fFileHandler->Allocate(fTrackMerger->GetOutTracks()); | |
429 | ||
430 | fFileHandler->TrackArray2Memory(fNTrackData,fTrackData, | |
431 | fTrackMerger->GetOutTracks()); | |
432 | ||
433 | delete memory; | |
434 | } | |
435 | ||
436 | void AliLevel3::WriteSpacePoints(UInt_t npoints,AliL3SpacePointData *points, | |
437 | Int_t slice,Int_t patch){ | |
438 | char name[256]; | |
439 | sprintf(name,"points_%d_%d.raw",slice,patch); | |
440 | AliL3MemHandler * memory = new AliL3MemHandler(); | |
441 | memory->SetBinaryOutput(name); | |
442 | memory->Transform(npoints,points,slice,fTransformer); | |
443 | memory->Memory2Binary(npoints,points); | |
444 | memory->CloseBinaryOutput(); | |
445 | delete memory; | |
446 | } | |
447 | ||
448 | ||
449 | Int_t AliLevel3::WriteTracks(char *filename,AliL3Merger *merger,char opt){ | |
450 | AliL3FileHandler *memory = new AliL3FileHandler(); | |
451 | memory->SetBinaryOutput(filename); | |
452 | if(opt=='a'||opt=='i'){ //add intracks | |
453 | for(Int_t i=0;i<merger->GetNIn();i++){ | |
454 | AliL3TrackArray *tr=merger->GetInTracks(i); | |
455 | memory->TrackArray2Binary(tr); | |
456 | } | |
457 | } | |
458 | ||
459 | if(opt=='o'||opt=='a'){ | |
460 | AliL3TrackArray *tr=merger->GetOutTracks(); | |
461 | memory->TrackArray2Binary(tr); | |
462 | } | |
463 | ||
464 | memory->CloseBinaryOutput(); | |
465 | ||
466 | return 1; | |
467 | } | |
468 | ||
469 | void AliLevel3::WriteResults() | |
470 | { | |
471 | //Write the resulting tracks to outputfile | |
472 | WriteTracks("tracks.raw",fGlobalMerger,'a'); | |
473 | } |