Bugfix in AliL3FileHandler::GetDigitsTree.
[u/mrichter/AliRoot.git] / HLT / src / AliL3FileHandler.cxx
CommitLineData
31d9405a 1//$Id$
2
5d2d32e3 3// Author: Uli Frankenfeld <mailto:franken@fi.uib.no>, Anders Vestbo <mailto:vestbo$fi.uib.no>
b661165c 4//*-- Copyright &copy Uli
108615fc 5
6#include <math.h>
7#include <iostream.h>
108615fc 8
9#include "AliL3Transform.h"
10#include "AliL3Logging.h"
11#include "AliL3MemHandler.h"
12#include "AliL3FileHandler.h"
13
0d319e67 14#include "AliTPCDigitsArray.h"
108615fc 15#include "AliTPCClustersArray.h"
16#include "AliTPCcluster.h"
17#include "AliTPCClustersRow.h"
108615fc 18
19#include "AliL3DigitData.h"
20#include "AliL3TrackSegmentData.h"
21#include "AliL3SpacePointData.h"
22#include "AliL3TrackArray.h"
b661165c 23
108615fc 24//_____________________________________________________________
b661165c 25// AliL3FileHandler
108615fc 26//
9183aa27 27// The HLT ROOT <-> binary files handling class
108615fc 28//
9183aa27 29// This class provides the interface between AliROOT files,
30// and HLT binary files. It should be used for converting
31// TPC data stored in AliROOT format (outputfile from a simulation),
32// into the data format currently used by in the HLT framework.
33// This enables the possibility to always use the same data format,
34// whether you are using a binary file as an input, or a AliROOT file.
35//
36// For example on how to create binary files from a AliROOT simulation,
37// see example macro exa/Binary.C.
38//
39// For reading a AliROOT file into HLT format in memory, do the following:
40//
41// AliL3FileHandler file;
42// file.SetAliInput("galice.root");
43// AliL3DigitRowData *dataPt = (AliL3DigitRowData*)file.AliDigits2Memory(nrows,eventnr);
44//
45// All the data are then stored in memory and accessible via the pointer dataPt.
46// Accesing the data is then identical to the example 1) showed in AliL3MemHandler class.
47//
48// For converting the data back, and writing it to a new AliROOT file do:
49//
50// AliL3FileHandler file;
51// file.SetAliInput("galice.root");
52// file.Init(slice,patch,NumberOfRowsInPatch);
53// file.AliDigits2RootFile(dataPt,"new_galice.root");
54// file.CloseAliInput();
108615fc 55
56ClassImp(AliL3FileHandler)
57
9183aa27 58AliL3FileHandler::AliL3FileHandler()
59{
108615fc 60 //Default constructor
61 fInAli = 0;
62 fParam = 0;
108615fc 63 fMC =0;
a6e4f9d6 64 fLastIndex=0;
65 fDigits=0;
66 fDigitsTree=0;
108615fc 67}
68
9183aa27 69AliL3FileHandler::~AliL3FileHandler()
70{
108615fc 71 //Destructor
108615fc 72 if(fMC) CloseMCOutput();
a815f9dd 73 FreeDigitsTree();
8f1a9904 74 if(fInAli) CloseAliInput();
a6e4f9d6 75
108615fc 76}
77
a815f9dd 78void AliL3FileHandler::FreeDigitsTree()
79{
80 if(!fDigitsTree)
81 {
82 LOG(AliL3Log::kWarning,"AliL3FileHandler::FreeDigitsTree()","Pointer")
83 <<"Cannot free digitstree, it is not present"<<ENDLOG;
84 return;
85 }
86 fDigits=0;
87 fDigitsTree->Delete();
88 fDigitsTree=0;
89}
90
91
9183aa27 92Bool_t AliL3FileHandler::SetMCOutput(char *name)
93{
108615fc 94 fMC = fopen(name,"w");
95 if(!fMC){
96 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetMCOutput","File Open")
9183aa27 97 <<"Pointer to File = 0x0 "<<ENDLOG;
108615fc 98 return kFALSE;
99 }
100 return kTRUE;
101}
102
9183aa27 103Bool_t AliL3FileHandler::SetMCOutput(FILE *file)
104{
108615fc 105 fMC = file;
106 if(!fMC){
107 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetMCOutput","File Open")
9183aa27 108 <<"Pointer to File = 0x0 "<<ENDLOG;
108615fc 109 return kFALSE;
110 }
111 return kTRUE;
112}
113
9183aa27 114void AliL3FileHandler::CloseMCOutput()
115{
108615fc 116 if(!fMC){
117 LOG(AliL3Log::kWarning,"AliL3FileHandler::CloseMCOutPut","File Close")
9183aa27 118 <<"Nothing to Close"<<ENDLOG;
108615fc 119 return;
120 }
121 fclose(fMC);
122 fMC =0;
123}
124
9183aa27 125Bool_t AliL3FileHandler::SetAliInput()
126{
108615fc 127 if(!fInAli->IsOpen()){
128 LOG(AliL3Log::kError,"AliL3FileHandler::SetAliInput","File Open")
9183aa27 129 <<"Ali File "<<fInAli->GetName()<<" does not exist"<<ENDLOG;
108615fc 130 return kFALSE;
131 }
132 fParam = (AliTPCParam*)fInAli->Get("75x40_100x60");
133 if(!fParam){
134 LOG(AliL3Log::kError,"AliL3FileHandler::SetAliInput","File Open")
9183aa27 135 <<"No AliTPCParam 75x40_100x60 in File "<<fInAli->GetName()<<ENDLOG;
136 return kFALSE;
108615fc 137 }
108615fc 138 return kTRUE;
139}
140
9183aa27 141Bool_t AliL3FileHandler::SetAliInput(char *name)
142{
143 //Open the AliROOT file with name.
144
108615fc 145 fInAli= new TFile(name,"READ");
146 if(!fInAli){
147 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File Open")
148 <<"Pointer to TFile = 0x0 "<<ENDLOG;
149 return kFALSE;
150 }
151 return SetAliInput();
152}
153
9183aa27 154Bool_t AliL3FileHandler::SetAliInput(TFile *file)
155{
156 //Specify already opened AliROOT file to use as an input.
157
108615fc 158 fInAli=file;
159 if(!fInAli){
160 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File Open")
161 <<"Pointer to TFile = 0x0 "<<ENDLOG;
162 return kFALSE;
163 }
164 return SetAliInput();
165}
166
9183aa27 167void AliL3FileHandler::CloseAliInput()
168{
108615fc 169 if(!fInAli){
170 LOG(AliL3Log::kWarning,"AliL3FileHandler::CloseAliInput","File Close")
9183aa27 171 <<"Nothing to Close"<<ENDLOG;
172 return;
108615fc 173 }
174 if(fInAli->IsOpen()) fInAli->Close();
175 delete fInAli;
176 fInAli = 0;
9183aa27 177
108615fc 178}
179
9183aa27 180Bool_t AliL3FileHandler::IsDigit()
181{
182 //Check if there is a TPC digit tree in the current file.
183 //Return kTRUE if tree was found, and kFALSE if not found.
184
108615fc 185 if(!fInAli){
186 LOG(AliL3Log::kWarning,"AliL3FileHandler::IsDigit","File")
187 <<"Pointer to TFile = 0x0 "<<ENDLOG;
188 return kTRUE; //may you are use binary input which is Digits!!
189 }
03b6adf7 190 TTree *t=(TTree*)fInAli->Get("TreeD_75x40_100x60_0");
108615fc 191 if(t){
192 LOG(AliL3Log::kInformational,"AliL3FileHandler::IsDigit","File Type")
193 <<"Found Digit Tree -> Use Fast Cluster Finder"<<ENDLOG;
194 return kTRUE;
195 }
196 else{
197 LOG(AliL3Log::kInformational,"AliL3FileHandler::IsDigit","File Type")
198 <<"No Digit Tree -> Use Cluster Tree"<<ENDLOG;
199 return kFALSE;
200 }
201}
202
203///////////////////////////////////////// Digit IO
9183aa27 204Bool_t AliL3FileHandler::AliDigits2Binary(Int_t event)
205{
206
108615fc 207 Bool_t out = kTRUE;
208 UInt_t nrow;
31d9405a 209 AliL3DigitRowData* data = AliDigits2Memory(nrow,event);
108615fc 210 out = Memory2Binary(nrow,data);
211 Free();
212 return out;
213}
214
215
9183aa27 216Bool_t AliL3FileHandler::AliDigits2CompBinary(Int_t event)
217{
218 //Convert AliROOT TPC data, into HLT data format.
219 //event specifies the event you want in the aliroot file.
220
108615fc 221 Bool_t out = kTRUE;
222 UInt_t ndigits=0;
31d9405a 223 AliL3DigitRowData* digits = AliDigits2Memory(ndigits,event);
108615fc 224 out = Memory2CompBinary(ndigits,digits);
225 Free();
226 return out;
227}
228
229
9183aa27 230AliL3DigitRowData * AliL3FileHandler::AliDigits2Memory(UInt_t & nrow,Int_t event)
231{
232 //Read data from AliROOT file into memory, and store it in the HLT data format.
233 //Returns a pointer to the data.
234
108615fc 235 AliL3DigitRowData *data = 0;
236 nrow=0;
237 if(!fInAli){
238 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2Memory","File")
239 <<"No Input avalible: no object TFile"<<ENDLOG;
240 return 0;
241 }
242 if(!fInAli->IsOpen()){
243 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2Memory","File")
244 <<"No Input avalible: TFile not opend"<<ENDLOG;
245 return 0;
246 }
b25c64e5 247
a6e4f9d6 248 if(!fDigitsTree)
249 GetDigitsTree(event);
a815f9dd 250
108615fc 251 UShort_t dig;
252 Int_t time,pad,sector,row;
253 Int_t nrows=0;
254 Int_t ndigitcount=0;
a6e4f9d6 255 Int_t entries = (Int_t)fDigitsTree->GetEntries();
108615fc 256 Int_t ndigits[entries];
257 Int_t lslice,lrow;
a6e4f9d6 258
259 for(Int_t n=fLastIndex; n<fDigitsTree->GetEntries(); n++)
108615fc 260 {
a6e4f9d6 261 fDigitsTree->GetEvent(n);
262 fParam->AdjustSectorRow(fDigits->GetID(),sector,row);
494fad94 263 AliL3Transform::Sector2Slice(lslice,lrow,sector,row);
a6e4f9d6 264 //if(fSlice != lslice || lrow<fRowMin || lrow>fRowMax) continue;
265 if(lslice < fSlice) continue;
266 if(lslice != fSlice) break;
267 if(lrow < fRowMin) continue;
268 if(lrow > fRowMax) break;
a815f9dd 269
108615fc 270 Float_t xyz[3];
271 ndigits[lrow] = 0;
a6e4f9d6 272 fDigits->First();
108615fc 273 do {
a6e4f9d6 274 time=fDigits->CurrentRow();
275 pad=fDigits->CurrentColumn();
276 dig = fDigits->GetDigit(time,pad);
108615fc 277 if(dig<=fParam->GetZeroSup()) continue;
7a9b2a20 278
279 /*
280 if(time < fParam->GetMaxTBin()-1 && time > 0)
281 if(fDigits->GetDigit(time+1,pad) <= fParam->GetZeroSup()
282 && fDigits->GetDigit(time-1,pad) <= fParam->GetZeroSup())
283 continue;
284 */
285
494fad94 286 AliL3Transform::Raw2Local(xyz,sector,row,pad,time);
108615fc 287 if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2]))
288 continue;
289
290 ndigits[lrow]++; //for this row only
291 ndigitcount++; //total number of digits to be published
292
a6e4f9d6 293 } while (fDigits->Next());
108615fc 294
295 nrows++;
296 }
297 Int_t size = sizeof(AliL3DigitData)*ndigitcount
8f1a9904 298 + nrows*sizeof(AliL3DigitRowData);
108615fc 299
300 LOG(AliL3Log::kDebug,"AliL3FileHandler::AliDigits2Memory","Digits")
a6e4f9d6 301 <<AliL3Log::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG;
302
108615fc 303 data=(AliL3DigitRowData*) Allocate(size);
304 nrow = (UInt_t)nrows;
305 AliL3DigitRowData *tempPt = data;
a6e4f9d6 306 for(Int_t n=fLastIndex; n<fDigitsTree->GetEntries(); n++)
108615fc 307 {
a6e4f9d6 308 fDigitsTree->GetEvent(n);
108615fc 309 Float_t xyz[3];
a6e4f9d6 310 fParam->AdjustSectorRow(fDigits->GetID(),sector,row);
494fad94 311 AliL3Transform::Sector2Slice(lslice,lrow,sector,row);
a6e4f9d6 312 //if(fSlice != lslice || lrow<fRowMin || lrow>fRowMax) continue;
313 if(lslice < fSlice) continue;
314 if(lslice != fSlice) break;
315 if(lrow < fRowMin) continue;
316 if(lrow > fRowMax) break;
317
108615fc 318 tempPt->fRow = lrow;
319 tempPt->fNDigit = ndigits[lrow];
320
321 Int_t localcount=0;
a6e4f9d6 322 fDigits->First();
108615fc 323 do {
a6e4f9d6 324 //dig=fDigits->CurrentDigit();
03b6adf7 325 //if (dig<=fParam->GetZeroSup()) continue;
a6e4f9d6 326 time=fDigits->CurrentRow();
327 pad=fDigits->CurrentColumn();
328 dig = fDigits->GetDigit(time,pad);
03b6adf7 329 if (dig <= fParam->GetZeroSup()) continue;
7a9b2a20 330
331 /*
332 if(time < fParam->GetMaxTBin()-1 && time > 0)
a6e4f9d6 333 if(fDigits->GetDigit(time-1,pad) <= fParam->GetZeroSup() &&
7a9b2a20 334 fDigits->GetDigit(time+1,pad) <= fParam->GetZeroSup()) continue;
335 */
336
337 //Exclude data outside cone:
494fad94 338 AliL3Transform::Raw2Local(xyz,sector,row,pad,time);
108615fc 339 if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2]))
340 continue;
341
342 if(localcount >= ndigits[lrow])
343 LOG(AliL3Log::kFatal,"AliL3FileHandler::AliDigits2Binary","Memory")
03b6adf7 344 <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits "
345 <<ndigits[lrow]<<ENDLOG;
346
108615fc 347 tempPt->fDigitData[localcount].fCharge=dig;
348 tempPt->fDigitData[localcount].fPad=pad;
349 tempPt->fDigitData[localcount].fTime=time;
10f815d9 350#ifdef do_mc
351 tempPt->fDigitData[localcount].fTrackID[0] = fDigits->GetTrackID(time,pad,0);
352 tempPt->fDigitData[localcount].fTrackID[1] = fDigits->GetTrackID(time,pad,1);
353 tempPt->fDigitData[localcount].fTrackID[2] = fDigits->GetTrackID(time,pad,2);
354#endif
108615fc 355 localcount++;
a6e4f9d6 356 } while (fDigits->Next());
108615fc 357
358 Byte_t *tmp = (Byte_t*)tempPt;
359 Int_t size = sizeof(AliL3DigitRowData)
360 + ndigits[lrow]*sizeof(AliL3DigitData);
361 tmp += size;
362 tempPt = (AliL3DigitRowData*)tmp;
a6e4f9d6 363 //fLastIndex=n;
108615fc 364 }
a6e4f9d6 365 //fLastIndex++;
108615fc 366 return data;
367}
368
a815f9dd 369
a6e4f9d6 370Bool_t AliL3FileHandler::GetDigitsTree(Int_t event)
371{
9183aa27 372 //Connects to the TPC digit tree in the AliROOT file.
a6e4f9d6 373
374 fInAli->cd();
375 Char_t dname[100];
376 sprintf(dname,"TreeD_75x40_100x60_%d",event);
a815f9dd 377 fDigitsTree = (TTree*)fInAli->Get(dname);
a6e4f9d6 378 if(!fDigitsTree)
379 {
380 LOG(AliL3Log::kError,"AliL3FileHandler::GetDigitsTree","Digits Tree")
381 <<AliL3Log::kHex<<"Error getting digitstree "<<(Int_t)fDigitsTree<<ENDLOG;
382 return kFALSE;
383 }
384 fDigitsTree->GetBranch("Segment")->SetAddress(&fDigits);
385 return kTRUE;
386}
387
0d319e67 388void AliL3FileHandler::AliDigits2RootFile(AliL3DigitRowData *rowPt,Char_t *new_digitsfile)
389{
9183aa27 390 //Write the data stored in rowPt, into a new AliROOT file.
391 //The data is stored in the AliROOT format
392 //This is specially a nice thing if you have modified data, and wants to run it
393 //through the offline reconstruction chain.
394 //The arguments is a pointer to the data, and the name of the new AliROOT file.
395 //Remember to pass the original AliROOT file (the one that contains the original
396 //simulated data) to this object, in order to retrieve the MC id's of the digits.
397
0d319e67 398 if(!fInAli)
399 {
8f1a9904 400 printf("AliL3FileHandler::AliDigits2RootFile : No rootfile\n");
0d319e67 401 return;
402 }
403 if(!fParam)
404 {
405 printf("AliL3FileHandler::AliDigits2RootFile : No parameter object. Run on rootfile\n");
406 return;
407 }
0d319e67 408
409 //Get the original digitstree:
410 fInAli->cd();
411 AliTPCDigitsArray *old_array = new AliTPCDigitsArray();
412 old_array->Setup(fParam);
413 old_array->SetClass("AliSimDigits");
03b6adf7 414 Bool_t ok = old_array->ConnectTree("TreeD_75x40_100x60_0");
0d319e67 415 if(!ok)
416 {
417 printf("AliL3FileHandler::AliDigits2RootFile : No digits tree object\n");
418 return;
419 }
0d319e67 420
03b6adf7 421 Bool_t create=kFALSE;
422 TFile *digFile;
423
8f1a9904 424 digFile = TFile::Open(new_digitsfile,"NEW");
425 if(digFile->IsOpen())
03b6adf7 426 {
03b6adf7 427 create = kTRUE;
428 fParam->Write(fParam->GetTitle());
429 }
430 else
431 {
8f1a9904 432 LOG(AliL3Log::kDebug,"AliL3FileHandler::AliDigits2RootFile","Rootfile")
433 <<"Rootfile did already exist, so I will just open it for updates"<<ENDLOG;
03b6adf7 434 digFile = TFile::Open(new_digitsfile,"UPDATE");
435 create=kFALSE;
436 }
437 if(!digFile->IsOpen())
438 {
8f1a9904 439 LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2RootFile","Rootfile")
440 <<"Error opening rootfile "<<new_digitsfile<<ENDLOG;
03b6adf7 441 return;
442 }
443
444 digFile->cd();
445
446 //setup a new one, or connect it to the existing one:
0d319e67 447 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
448 arr->SetClass("AliSimDigits");
449 arr->Setup(fParam);
03b6adf7 450 if(create)
451 arr->MakeTree();
452 else
453 {
454 Bool_t ok = arr->ConnectTree("TreeD_75x40_100x60_0");
455 if(!ok)
456 {
457 printf("AliL3FileHandler::AliDigits2RootFile : No digits tree object in existing file\n");
458 return;
459 }
460 }
54efe57a 461 Int_t digcounter=0;
49898c33 462
0d319e67 463 for(Int_t i=fRowMin; i<=fRowMax; i++)
464 {
03b6adf7 465
49898c33 466 if((Int_t)rowPt->fRow != i) printf("AliL3FileHandler::AliDigits2RootFile : Mismatching row numbering!!!\n");
03b6adf7 467
0d319e67 468 Int_t sector,row;
494fad94 469 AliL3Transform::Slice2Sector(fSlice,i,sector,row);
49898c33 470 AliSimDigits * dig = (AliSimDigits*)arr->CreateRow(sector,row);
471 AliSimDigits *old_dig = (AliSimDigits*)old_array->LoadRow(sector,row);
0d319e67 472 if(!old_dig)
473 printf("AliL3FileHandler::AliDigits2RootFile : No padrow %d %d\n",sector,row);
474
475 AliL3DigitData *digPt = rowPt->fDigitData;
54efe57a 476 digcounter=0;
0d319e67 477 for(UInt_t j=0; j<rowPt->fNDigit; j++)
478 {
49898c33 479 Int_t charge = (Int_t)digPt[j].fCharge;
480 Int_t pad = (Int_t)digPt[j].fPad;
481 Int_t time = (Int_t)digPt[j].fTime;
03b6adf7 482
483 if(charge == 0) //Only write the digits that has not been removed
484 continue;
54efe57a 485 digcounter++;
486 dig->SetDigitFast(charge,time,pad);
49898c33 487
488 Int_t trackID[3] = {old_dig->GetTrackID(time,pad,0),old_dig->GetTrackID(time,pad,1),old_dig->GetTrackID(time,pad,2)};
489 Int_t s_pad = pad;
490 Int_t s_time = time - 1;
491 while(trackID[0] < 0)
492 {
494fad94 493 if(s_time >= 0 && s_time < AliL3Transform::GetNTimeBins() && s_pad >= 0 && s_pad < AliL3Transform::GetNPads(i))
49898c33 494 {
495 if(old_dig->GetTrackID(s_time,s_pad,0) > 0)
496 {
497 trackID[0]=old_dig->GetTrackID(s_time,s_pad,0);
498 trackID[1]=old_dig->GetTrackID(s_time,s_pad,1);
499 trackID[2]=old_dig->GetTrackID(s_time,s_pad,2);
500 }
501 }
502 if(s_pad == pad && s_time == time - 1)
503 s_time = time + 1;
504 else if(s_pad == pad && s_time == time + 1)
505 {s_pad = pad - 1; s_time = time;}
506 else if(s_pad == pad - 1 && s_time == time)
507 s_time = time - 1;
508 else if(s_pad == pad - 1 && s_time == time - 1)
509 s_time = time + 1;
510 else if(s_pad == pad - 1 && s_time == time + 1)
511 {s_pad = pad + 1; s_time = time;}
512 else if(s_pad == pad + 1 && s_time == time)
513 s_time = time - 1;
514 else if(s_pad == pad + 1 && s_time == time - 1)
515 s_time = time + 1;
516 else
517 break;
518 }
519
520 dig->SetTrackIDFast(trackID[0],time,pad,0);
521 dig->SetTrackIDFast(trackID[1],time,pad,1);
522 dig->SetTrackIDFast(trackID[2],time,pad,2);
0d319e67 523
524 }
54efe57a 525 //cout<<"Wrote "<<digcounter<<" on row "<<i<<endl;
0d319e67 526 UpdateRowPointer(rowPt);
527 arr->StoreRow(sector,row);
528 arr->ClearRow(sector,row);
529 old_array->ClearRow(sector,row);
530 }
531 digFile->cd();
532 char treeName[100];
03b6adf7 533 sprintf(treeName,"TreeD_%s_0",fParam->GetTitle());
8f1a9904 534 printf("Writing tree to file.....");
0d319e67 535 arr->GetTree()->Write(treeName,TObject::kOverwrite);
8f1a9904 536 printf("done\n");
0d319e67 537 digFile->Close();
03b6adf7 538 //arr->GetTree()->Delete();
539 //delete arr;
0d319e67 540}
541
108615fc 542///////////////////////////////////////// Point IO
543Bool_t AliL3FileHandler::AliPoints2Binary(){
544 Bool_t out = kTRUE;
545 UInt_t npoint;
546 AliL3SpacePointData *data = AliPoints2Memory(npoint);
547 out = Memory2Binary(npoint,data);
548 Free();
549 return out;
550}
551
552AliL3SpacePointData * AliL3FileHandler::AliPoints2Memory(UInt_t & npoint){
553 AliL3SpacePointData *data = 0;
554 npoint=0;
555 if(!fInAli){
556 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliPoints2Memory","File")
557 <<"No Input avalible: no object TFile"<<ENDLOG;
558 return 0;
559 }
560 if(!fInAli->IsOpen()){
561 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliPoints2Memory","File")
562 <<"No Input avalible: TFile not opend"<<ENDLOG;
563 return 0;
564 }
494fad94 565
108615fc 566 TDirectory *savedir = gDirectory;
567 fInAli->cd();
8f1a9904 568
569 Char_t cname[100];
570 Int_t eventn = 0;
571 sprintf(cname,"TreeC_TPC_%d",eventn);
108615fc 572 AliTPCClustersArray carray;
573 carray.Setup(fParam);
574 carray.SetClusterType("AliTPCcluster");
8f1a9904 575 Bool_t clusterok = carray.ConnectTree(cname);
108615fc 576 if(!clusterok) return 0;
577
578 AliTPCClustersRow ** clusterrow =
579 new AliTPCClustersRow*[ (int)carray.GetTree()->GetEntries()];
580 Int_t *rows = new int[ (int)carray.GetTree()->GetEntries()];
581 Int_t *sects = new int[ (int)carray.GetTree()->GetEntries()];
582 Int_t sum=0;
583
584 Int_t lslice,lrow;
585 for(Int_t i=0; i<carray.GetTree()->GetEntries(); i++){
586 AliSegmentID *s = carray.LoadEntry(i);
587 Int_t sector,row;
588 fParam->AdjustSectorRow(s->GetID(),sector,row);
589 rows[i] = row;
590 sects[i] = sector;
591 clusterrow[i] = 0;
494fad94 592 AliL3Transform::Sector2Slice(lslice,lrow,sector,row);
108615fc 593 if(fSlice != lslice || lrow<fRowMin || lrow>fRowMax) continue;
594 clusterrow[i] = carray.GetRow(sector,row);
595 if(clusterrow[i])
596 sum+=clusterrow[i]->GetArray()->GetEntriesFast();
597 }
598 UInt_t size = sum*sizeof(AliL3SpacePointData);
599
600 LOG(AliL3Log::kDebug,"AliL3FileHandler::AliPoints2Memory","File")
601 <<AliL3Log::kDec<<"Found "<<sum<<" SpacePoints"<<ENDLOG;
602
603 data = (AliL3SpacePointData *) Allocate(size);
604 npoint = sum;
605 UInt_t n=0;
606 for(Int_t i=0; i<carray.GetTree()->GetEntries(); i++){
607 if(!clusterrow[i]) continue;
608 Int_t row = rows[i];
609 Int_t sector = sects[i];
494fad94 610 AliL3Transform::Sector2Slice(lslice,lrow,sector,row);
108615fc 611 Int_t entries_in_row = clusterrow[i]->GetArray()->GetEntriesFast();
612 for(Int_t j = 0;j<entries_in_row;j++){
613 AliTPCcluster *c = (AliTPCcluster*)(*clusterrow[i])[j];
614 data[n].fZ = c->GetZ();
615 data[n].fY = c->GetY();
616 data[n].fX = fParam->GetPadRowRadii(sector,row);
617 data[n].fID = n+((fSlice&0x7f)<<25)+((fPatch&0x7)<<22);//uli
618 data[n].fPadRow = lrow;
619 data[n].fXYErr = c->GetSigmaY2();
620 data[n].fZErr = c->GetSigmaZ2();
621 if(fMC) fprintf(fMC,"%d %d\n",data[n].fID,c->GetLabel(0));
622 n++;
623 }
624 }
625 for(Int_t i=0;i<carray.GetTree()->GetEntries();i++){
626 Int_t row = rows[i];
627 Int_t sector = sects[i];
628 if(carray.GetRow(sector,row))
629 carray.ClearRow(sector,row);
630 }
631
632 delete [] clusterrow;
633 delete [] rows;
634 delete [] sects;
635 savedir->cd();
636
637 return data;
638}
639