Added support for NEWIO, merged cern-hlt tree, updated to latest track candidate...
[u/mrichter/AliRoot.git] / HLT / src / AliL3FileHandler.cxx
CommitLineData
3e87ef69 1// @(#) $Id$
31d9405a 2
02f030e3 3// Author: Uli Frankenfeld <mailto:franken@fi.uib.no>, Anders Vestbo <mailto:vestbo$fi.uib.no>, C. Loizides <mailto:loizides@ikf.uni-frankfurt.de>
3e87ef69 4//*-- Copyright &copy ALICE HLT Group
108615fc 5
118c26c3 6#include "AliL3StandardIncludes.h"
5e0f9911 7#include <TClonesArray.h>
f6670bec 8#include <TSystem.h>
5e0f9911 9
b2a02bce 10#ifdef use_newio
11#include <AliRunLoader.h>
12#include <AliTPC.h>
13#endif
02f030e3 14#include <AliTPCParamSR.h>
118c26c3 15#include <AliTPCDigitsArray.h>
16#include <AliTPCClustersArray.h>
17#include <AliTPCcluster.h>
18#include <AliTPCClustersRow.h>
5e0f9911 19#include <AliSimDigits.h>
108615fc 20
108615fc 21#include "AliL3Logging.h"
118c26c3 22#include "AliL3Transform.h"
108615fc 23#include "AliL3MemHandler.h"
108615fc 24#include "AliL3DigitData.h"
25#include "AliL3TrackSegmentData.h"
26#include "AliL3SpacePointData.h"
27#include "AliL3TrackArray.h"
b2a02bce 28#include "AliL3FileHandler.h"
b661165c 29
3e87ef69 30#if GCCVERSION == 3
31using namespace std;
32#endif
748e01f4 33
3e87ef69 34/** \class AliL3FileHandler
35<pre>
108615fc 36//_____________________________________________________________
b661165c 37// AliL3FileHandler
108615fc 38//
9183aa27 39// The HLT ROOT <-> binary files handling class
108615fc 40//
9183aa27 41// This class provides the interface between AliROOT files,
42// and HLT binary files. It should be used for converting
43// TPC data stored in AliROOT format (outputfile from a simulation),
44// into the data format currently used by in the HLT framework.
45// This enables the possibility to always use the same data format,
46// whether you are using a binary file as an input, or a AliROOT file.
47//
48// For example on how to create binary files from a AliROOT simulation,
49// see example macro exa/Binary.C.
50//
51// For reading a AliROOT file into HLT format in memory, do the following:
52//
53// AliL3FileHandler file;
2330399d 54// file.Init(slice,patch);
9183aa27 55// file.SetAliInput("galice.root");
56// AliL3DigitRowData *dataPt = (AliL3DigitRowData*)file.AliDigits2Memory(nrows,eventnr);
57//
58// All the data are then stored in memory and accessible via the pointer dataPt.
59// Accesing the data is then identical to the example 1) showed in AliL3MemHandler class.
60//
61// For converting the data back, and writing it to a new AliROOT file do:
62//
63// AliL3FileHandler file;
2330399d 64// file.Init(slice,patch);
9183aa27 65// file.SetAliInput("galice.root");
66// file.Init(slice,patch,NumberOfRowsInPatch);
67// file.AliDigits2RootFile(dataPt,"new_galice.root");
68// file.CloseAliInput();
3e87ef69 69</pre>
70*/
108615fc 71
72ClassImp(AliL3FileHandler)
73
9183aa27 74AliL3FileHandler::AliL3FileHandler()
75{
108615fc 76 //Default constructor
77 fInAli = 0;
78 fParam = 0;
108615fc 79 fMC =0;
a6e4f9d6 80 fDigits=0;
81 fDigitsTree=0;
02f030e3 82 for(Int_t i=0;i<AliL3Transform::GetNSlice();i++){
83 for(Int_t j=0;j<AliL3Transform::GetNRows();j++)
84 fIndex[i][j]=-1;
85 }
86 fIndexCreated=kFALSE;
108615fc 87}
88
9183aa27 89AliL3FileHandler::~AliL3FileHandler()
90{
108615fc 91 //Destructor
108615fc 92 if(fMC) CloseMCOutput();
a815f9dd 93 FreeDigitsTree();
8f1a9904 94 if(fInAli) CloseAliInput();
108615fc 95}
96
a815f9dd 97void AliL3FileHandler::FreeDigitsTree()
98{
99 if(!fDigitsTree)
100 {
101 LOG(AliL3Log::kWarning,"AliL3FileHandler::FreeDigitsTree()","Pointer")
102 <<"Cannot free digitstree, it is not present"<<ENDLOG;
103 return;
104 }
105 fDigits=0;
b2a02bce 106#ifndef use_newio
a815f9dd 107 fDigitsTree->Delete();
b2a02bce 108#endif
a815f9dd 109 fDigitsTree=0;
b2a02bce 110
02f030e3 111 for(Int_t i=0;i<AliL3Transform::GetNSlice();i++){
112 for(Int_t j=0;j<AliL3Transform::GetNRows();j++)
113 fIndex[i][j]=-1;
114 }
115 fIndexCreated=kFALSE;
a815f9dd 116}
117
3e87ef69 118Bool_t AliL3FileHandler::SetMCOutput(Char_t *name)
9183aa27 119{
108615fc 120 fMC = fopen(name,"w");
121 if(!fMC){
122 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetMCOutput","File Open")
9183aa27 123 <<"Pointer to File = 0x0 "<<ENDLOG;
108615fc 124 return kFALSE;
125 }
126 return kTRUE;
127}
128
9183aa27 129Bool_t AliL3FileHandler::SetMCOutput(FILE *file)
130{
108615fc 131 fMC = file;
132 if(!fMC){
133 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetMCOutput","File Open")
9183aa27 134 <<"Pointer to File = 0x0 "<<ENDLOG;
108615fc 135 return kFALSE;
136 }
137 return kTRUE;
138}
139
9183aa27 140void AliL3FileHandler::CloseMCOutput()
141{
108615fc 142 if(!fMC){
143 LOG(AliL3Log::kWarning,"AliL3FileHandler::CloseMCOutPut","File Close")
9183aa27 144 <<"Nothing to Close"<<ENDLOG;
108615fc 145 return;
146 }
147 fclose(fMC);
148 fMC =0;
149}
150
9183aa27 151Bool_t AliL3FileHandler::SetAliInput()
152{
b2a02bce 153#ifdef use_newio
a27af97b 154 fInAli->CdGAFile();
155 fParam = AliTPC::LoadTPCParam(gFile);
02f030e3 156 if(!fParam){
157 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File")
a27af97b 158 <<"No TPC parameters found in \""<<gFile->GetName()
02f030e3 159 <<"\", creating standard parameters "
160 <<"which might not be what you want!"<<ENDLOG;
161 fParam = new AliTPCParamSR;
162 }
108615fc 163 if(!fParam){
164 LOG(AliL3Log::kError,"AliL3FileHandler::SetAliInput","File Open")
a27af97b 165 <<"No AliTPCParam "<<AliL3Transform::GetParamName()<<" in File "<<gFile->GetName()<<ENDLOG;
9183aa27 166 return kFALSE;
108615fc 167 }
b2a02bce 168#else
169 if(!fInAli->IsOpen()){
170 LOG(AliL3Log::kError,"AliL3FileHandler::SetAliInput","File Open")
171 <<"Ali File "<<fInAli->GetName()<<" does not exist"<<ENDLOG;
172 return kFALSE;
173 }
174 fParam = (AliTPCParam*)fInAli->Get(AliL3Transform::GetParamName());
175 if(!fParam){
176 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File")
177 <<"No TPC parameters found in \""<<fInAli->GetName()
178 <<"\", creating standard parameters "
179 <<"which might not be what you want!"<<ENDLOG;
180 fParam = new AliTPCParamSR;
181 }
182 if(!fParam){
183 LOG(AliL3Log::kError,"AliL3FileHandler::SetAliInput","File Open")
184 <<"No AliTPCParam "<<AliL3Transform::GetParamName()<<" in File "<<fInAli->GetName()<<ENDLOG;
185 return kFALSE;
186 }
187#endif
188
108615fc 189 return kTRUE;
190}
191
3e87ef69 192Bool_t AliL3FileHandler::SetAliInput(Char_t *name)
9183aa27 193{
194 //Open the AliROOT file with name.
b2a02bce 195#ifdef use_newio
a27af97b 196 fInAli= AliRunLoader::Open(name);
b2a02bce 197#else
198 fInAli= new TFile(name,"READ");
199#endif
108615fc 200 if(!fInAli){
201 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File Open")
b2a02bce 202 <<"Pointer to fInAli = 0x0 "<<ENDLOG;
108615fc 203 return kFALSE;
204 }
205 return SetAliInput();
206}
207
b2a02bce 208#ifdef use_newio
a27af97b 209Bool_t AliL3FileHandler::SetAliInput(AliRunLoader *runLoader)
9183aa27 210{
a27af97b 211 fInAli=runLoader;
108615fc 212 if(!fInAli){
213 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File Open")
a27af97b 214 <<"Pointer to AliRunLoader = 0x0 "<<ENDLOG;
108615fc 215 return kFALSE;
216 }
217 return SetAliInput();
218}
b2a02bce 219#endif
220
221#ifdef use_newio
222Bool_t AliL3FileHandler::SetAliInput(TFile *file)
223{
224 LOG(AliL3Log::kFatal,"AliL3FileHandler::SetAliInput","File Open")
225 <<"This function is not supported for NEWIO, check ALIHLT_USENEWIO settings in Makefile.conf"<<ENDLOG;
226 return kFALSE;
227}
228#else
229Bool_t AliL3FileHandler::SetAliInput(TFile *file)
230{
231 //Specify already opened AliROOT file to use as an input.
232 fInAli=file;
233 if(!fInAli){
234 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File Open")
235 <<"Pointer to fInAli = 0x0 "<<ENDLOG;
236 return kFALSE;
237 }
238 return SetAliInput();
239}
240#endif
108615fc 241
9183aa27 242void AliL3FileHandler::CloseAliInput()
243{
108615fc 244 if(!fInAli){
245 LOG(AliL3Log::kWarning,"AliL3FileHandler::CloseAliInput","File Close")
9183aa27 246 <<"Nothing to Close"<<ENDLOG;
247 return;
108615fc 248 }
b2a02bce 249#ifndef use_newio
250 if(fInAli->IsOpen()) fInAli->Close();
251#endif
108615fc 252 delete fInAli;
253 fInAli = 0;
254}
255
68a27388 256Bool_t AliL3FileHandler::IsDigit(Int_t event)
9183aa27 257{
258 //Check if there is a TPC digit tree in the current file.
259 //Return kTRUE if tree was found, and kFALSE if not found.
260
108615fc 261 if(!fInAli){
262 LOG(AliL3Log::kWarning,"AliL3FileHandler::IsDigit","File")
b2a02bce 263 <<"Pointer to fInAli = 0x0 "<<ENDLOG;
264 return kTRUE; //maybe you are using binary input which is Digits!!
a27af97b 265 }
b2a02bce 266#ifdef use_newio
a27af97b 267 AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader");
268 if(!tpcLoader){
b2a02bce 269 LOG(AliL3Log::kWarning,"AliL3FileHandlerNewIO::IsDigit","File")
a27af97b 270 <<"Pointer to AliLoader for TPC = 0x0 "<<ENDLOG;
271 return kFALSE;
108615fc 272 }
a27af97b 273 fInAli->GetEvent(event);
274 tpcLoader->LoadDigits();
275 TTree *t=tpcLoader->TreeD();
b2a02bce 276#else
277 Char_t name[1024];
278 sprintf(name,"TreeD_%s_%d",AliL3Transform::GetParamName(),event);
279 TTree *t=(TTree*)fInAli->Get(name);
280#endif
108615fc 281 if(t){
b2a02bce 282 LOG(AliL3Log::kInformational,"AliL3FileHandlerNewIO::IsDigit","File Type")
108615fc 283 <<"Found Digit Tree -> Use Fast Cluster Finder"<<ENDLOG;
284 return kTRUE;
285 }
286 else{
b2a02bce 287 LOG(AliL3Log::kInformational,"AliL3FileHandlerNewIO::IsDigit","File Type")
108615fc 288 <<"No Digit Tree -> Use Cluster Tree"<<ENDLOG;
289 return kFALSE;
290 }
291}
292
293///////////////////////////////////////// Digit IO
3e87ef69 294Bool_t AliL3FileHandler::AliDigits2Binary(Int_t event,Bool_t altro)
9183aa27 295{
108615fc 296 Bool_t out = kTRUE;
297 UInt_t nrow;
3e87ef69 298 AliL3DigitRowData* data = 0;
299 if(altro)
300 data = AliAltroDigits2Memory(nrow,event);
301 else
302 data = AliDigits2Memory(nrow,event);
108615fc 303 out = Memory2Binary(nrow,data);
304 Free();
305 return out;
306}
307
954beff0 308Bool_t AliL3FileHandler::AliDigits2CompBinary(Int_t event,Bool_t altro)
9183aa27 309{
310 //Convert AliROOT TPC data, into HLT data format.
311 //event specifies the event you want in the aliroot file.
312
108615fc 313 Bool_t out = kTRUE;
314 UInt_t ndigits=0;
954beff0 315 AliL3DigitRowData *digits=0;
02f030e3 316 if(altro)
954beff0 317 digits = AliAltroDigits2Memory(ndigits,event);
02f030e3 318 else
319 digits = AliDigits2Memory(ndigits,event);
108615fc 320 out = Memory2CompBinary(ndigits,digits);
321 Free();
322 return out;
323}
324
02f030e3 325Bool_t AliL3FileHandler::CreateIndex()
326{
327 //create the access index
328
329 LOG(AliL3Log::kInformational,"AliL3FileHandler::CreateIndex","Index")
330 <<"Starting to create index, this can take a while."<<ENDLOG;
331
332 fIndexCreated=kFALSE;
333 for(Int_t i=0;i<AliL3Transform::GetNSlice();i++){
334 for(Int_t j=0;j<AliL3Transform::GetNRows();j++)
335 fIndex[i][j]=-1;
336 }
337
338 for(Int_t n=0; n<fDigitsTree->GetEntries(); n++){
339 Int_t sector, row;
340 Int_t lslice,lrow;
341 fDigitsTree->GetEvent(n);
342 fParam->AdjustSectorRow(fDigits->GetID(),sector,row);
343 if(!AliL3Transform::Sector2Slice(lslice,lrow,sector,row)){
344 LOG(AliL3Log::kError,"AliL3FileHandler::CreateIndex","Slice/Row")
345 <<AliL3Log::kDec<<"Index could not be created. Wrong values "
346 <<sector<<" "<<row<<ENDLOG;
347 return kFALSE;
348 }
02f030e3 349 if(fIndex[lslice][lrow]==-1) fIndex[lslice][lrow]=n;
350 }
351
02f030e3 352 LOG(AliL3Log::kInformational,"AliL3FileHandler::CreateIndex","Index")
353 <<"Index successfully created."<<ENDLOG;
354
b2a02bce 355 //for(Int_t i=0;i<AliL3Transform::GetNSlice();i++){
356 // for(Int_t j=0;j<AliL3Transform::GetNRows();j++)
357 // cout << fIndex[i][j] << " ";
358 //cout << endl;}
359
02f030e3 360 fIndexCreated=kTRUE;
b2a02bce 361 return kTRUE;
02f030e3 362}
363
9183aa27 364AliL3DigitRowData * AliL3FileHandler::AliDigits2Memory(UInt_t & nrow,Int_t event)
365{
366 //Read data from AliROOT file into memory, and store it in the HLT data format.
367 //Returns a pointer to the data.
368
108615fc 369 AliL3DigitRowData *data = 0;
370 nrow=0;
4499ed26 371
108615fc 372 if(!fInAli){
373 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2Memory","File")
b2a02bce 374 <<"No Input avalible: Pointer to fInAli == NULL"<<ENDLOG;
108615fc 375 return 0;
376 }
b2a02bce 377
378#ifndef use_newio
379 if(!fInAli->IsOpen()){
380 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2Memory","File")
381 <<"No Input avalible: TFile not opened"<<ENDLOG;
382 return 0;
383 }
384#endif
385
a6e4f9d6 386 if(!fDigitsTree)
3e87ef69 387 if(!GetDigitsTree(event)) return 0;
b2a02bce 388
108615fc 389 UShort_t dig;
390 Int_t time,pad,sector,row;
02f030e3 391 Int_t lslice,lrow;
108615fc 392 Int_t nrows=0;
393 Int_t ndigitcount=0;
a6e4f9d6 394 Int_t entries = (Int_t)fDigitsTree->GetEntries();
108615fc 395 Int_t ndigits[entries];
4499ed26 396 Float_t xyz[3];
02f030e3 397
398 for(Int_t r=fRowMin;r<=fRowMax;r++){
399 Int_t n=fIndex[fSlice][r];
400 if(n==-1) continue; //no data on that row
401
402 fDigitsTree->GetEvent(n);
403 fParam->AdjustSectorRow(fDigits->GetID(),sector,row);
404 AliL3Transform::Sector2Slice(lslice,lrow,sector,row);
405
406 if(lrow!=r){
407 LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2Memory","Row")
b2a02bce 408 <<AliL3Log::kDec<<"Rows in slice " << fSlice << " dont match "<<lrow<<" "<<r<<ENDLOG;
409 continue;
02f030e3 410 }
411
412 ndigits[lrow] = 0;
413 fDigits->First();
414 do {
415 time=fDigits->CurrentRow();
416 pad=fDigits->CurrentColumn();
417 dig = fDigits->GetDigit(time,pad);
418 if(dig <= fParam->GetZeroSup()) continue;
419 if(dig >= AliL3Transform::GetADCSat())
420 dig = AliL3Transform::GetADCSat();
3e87ef69 421
02f030e3 422 AliL3Transform::Raw2Local(xyz,sector,row,pad,time);
423 if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2]))
424 continue; // why 230???
108615fc 425
02f030e3 426 ndigits[lrow]++; //for this row only
427 ndigitcount++; //total number of digits to be published
108615fc 428
02f030e3 429 } while (fDigits->Next());
430 //cout << lrow << " " << ndigits[lrow] << " - " << ndigitcount << endl;
431 nrows++;
432 }
4499ed26 433
108615fc 434 Int_t size = sizeof(AliL3DigitData)*ndigitcount
8f1a9904 435 + nrows*sizeof(AliL3DigitRowData);
108615fc 436
437 LOG(AliL3Log::kDebug,"AliL3FileHandler::AliDigits2Memory","Digits")
a6e4f9d6 438 <<AliL3Log::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG;
439
108615fc 440 data=(AliL3DigitRowData*) Allocate(size);
441 nrow = (UInt_t)nrows;
442 AliL3DigitRowData *tempPt = data;
108615fc 443
02f030e3 444 for(Int_t r=fRowMin;r<=fRowMax;r++){
445 Int_t n=fIndex[fSlice][r];
446
447 if(n==-1) continue; //no data on that row
448
449 fDigitsTree->GetEvent(n);
450 fParam->AdjustSectorRow(fDigits->GetID(),sector,row);
451 AliL3Transform::Sector2Slice(lslice,lrow,sector,row);
452 if(lrow!=r){
453 LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2Memory","Row")
b2a02bce 454 <<AliL3Log::kDec<<"Rows on slice " << fSlice << " dont match "<<lrow<<" "<<r<<ENDLOG;
455 continue;
02f030e3 456 }
457 tempPt->fRow = lrow;
458 tempPt->fNDigit = ndigits[lrow];
459
460 Int_t localcount=0;
461 fDigits->First();
462 do {
463 time=fDigits->CurrentRow();
464 pad=fDigits->CurrentColumn();
465 dig = fDigits->GetDigit(time,pad);
466 if (dig <= fParam->GetZeroSup()) continue;
467 if(dig >= AliL3Transform::GetADCSat())
468 dig = AliL3Transform::GetADCSat();
469
470 //Exclude data outside cone:
471 AliL3Transform::Raw2Local(xyz,sector,row,pad,time);
472 if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2]))
473 continue; // why 230???
474
475 if(localcount >= ndigits[lrow])
476 LOG(AliL3Log::kFatal,"AliL3FileHandler::AliDigits2Binary","Memory")
477 <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits "
478 <<ndigits[lrow]<<ENDLOG;
03b6adf7 479
02f030e3 480 tempPt->fDigitData[localcount].fCharge=dig;
481 tempPt->fDigitData[localcount].fPad=pad;
482 tempPt->fDigitData[localcount].fTime=time;
10f815d9 483#ifdef do_mc
02f030e3 484 tempPt->fDigitData[localcount].fTrackID[0] = fDigits->GetTrackID(time,pad,0);
485 tempPt->fDigitData[localcount].fTrackID[1] = fDigits->GetTrackID(time,pad,1);
486 tempPt->fDigitData[localcount].fTrackID[2] = fDigits->GetTrackID(time,pad,2);
10f815d9 487#endif
02f030e3 488 localcount++;
489 } while (fDigits->Next());
108615fc 490
02f030e3 491 Byte_t *tmp = (Byte_t*)tempPt;
492 Int_t size = sizeof(AliL3DigitRowData)
108615fc 493 + ndigits[lrow]*sizeof(AliL3DigitData);
02f030e3 494 tmp += size;
495 tempPt = (AliL3DigitRowData*)tmp;
496 }
108615fc 497 return data;
498}
499
3e87ef69 500AliL3DigitRowData * AliL3FileHandler::AliAltroDigits2Memory(UInt_t & nrow,Int_t event,Bool_t eventmerge)
954beff0 501{
502 //Read data from AliROOT file into memory, and store it in the HLT data format.
503 //Returns a pointer to the data.
504 //This functions filter out single timebins, which is noise. The timebins which
505 //are removed are timebins which have the 4 zero neighbours;
506 //(pad-1,time),(pad+1,time),(pad,time-1),(pad,time+1).
507
508 AliL3DigitRowData *data = 0;
509 nrow=0;
510
511 if(!fInAli){
512 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliAltroDigits2Memory","File")
b2a02bce 513 <<"No Input avalible: Pointer to TFile == NULL"<<ENDLOG;
954beff0 514 return 0;
515 }
b2a02bce 516#ifndef use_newio
517 if(!fInAli->IsOpen()){
518 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliAltroDigits2Memory","File")
519 <<"No Input avalible: TFile not opened"<<ENDLOG;
520 return 0;
521 }
522#endif
3e87ef69 523 if(eventmerge == kTRUE && event >= 1024)
524 {
525 LOG(AliL3Log::kError,"AliL3FileHandler::AliAltroDigits2Memory","TrackIDs")
526 <<"Too many events if you want to merge!!"<<ENDLOG;
527 return 0;
528 }
529
b2a02bce 530#ifdef use_newio
531 /* Dont understand why we have to do
532 reload the tree,
533 but otherwise code crashes */
534 fDigits=0;
535 fDigitsTree=0;
536 if(!GetDigitsTree(event)) return 0;
537#else
538 if(!fDigitsTree){
3e87ef69 539 if(!GetDigitsTree(event)) return 0;
b2a02bce 540 }
541#endif
542
543
544
954beff0 545 UShort_t dig;
546 Int_t time,pad,sector,row;
547 Int_t nrows=0;
548 Int_t ndigitcount=0;
549 Int_t entries = (Int_t)fDigitsTree->GetEntries();
550 Int_t ndigits[entries];
551 Int_t lslice,lrow;
02f030e3 552 Int_t zerosupval=AliL3Transform::GetZeroSup();
954beff0 553 Float_t xyz[3];
b2a02bce 554
02f030e3 555 for(Int_t r=fRowMin;r<=fRowMax;r++){
556 Int_t n=fIndex[fSlice][r];
b2a02bce 557
02f030e3 558 if(n==-1) continue; //no data on that row
559
560 fDigitsTree->GetEvent(n);
561 fParam->AdjustSectorRow(fDigits->GetID(),sector,row);
562 AliL3Transform::Sector2Slice(lslice,lrow,sector,row);
b2a02bce 563 //cout << lslice << " " << fSlice << " " << lrow << " " << r << " " << sector << " " << row << endl;
564 if((lslice!=fSlice)||(lrow!=r)){
02f030e3 565 LOG(AliL3Log::kError,"AliL3FileHandler::AliAltroDigits2Memory","Row")
b2a02bce 566 <<AliL3Log::kDec<<"Rows on slice " << fSlice << " dont match "<<lrow<<" "<<r<<ENDLOG;
567 continue;
02f030e3 568 }
569
570 ndigits[lrow] = 0;
571 fDigits->ExpandBuffer();
572 fDigits->ExpandTrackBuffer();
573 for(Int_t i=0; i<fDigits->GetNCols(); i++){
574 for(Int_t j=0; j<fDigits->GetNRows(); j++){
575 pad=i;
576 time=j;
577 dig = fDigits->GetDigitFast(time,pad);
578 if(dig <= zerosupval) continue;
579 if(dig >= AliL3Transform::GetADCSat())
580 dig = AliL3Transform::GetADCSat();
581
582 //Check for single timebins, and remove them because they are noise for sure.
583 if(i>0 && i<fDigits->GetNCols()-1 && j>0 && j<fDigits->GetNRows()-1)
584 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
585 fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
586 fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
587 fDigits->GetDigitFast(time,pad+1)<=zerosupval)
588 continue;
954beff0 589
02f030e3 590 //Boundaries:
591 if(i==0) //pad==0
592 {
593 if(j < fDigits->GetNRows()-1 && j > 0)
594 {
595 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
596 fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
597 fDigits->GetDigitFast(time,pad+1)<=zerosupval)
954beff0 598 continue;
02f030e3 599 }
600 else if(j > 0)
601 {
602 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
603 fDigits->GetDigitFast(time,pad+1)<=zerosupval)
954beff0 604 continue;
605 }
02f030e3 606 }
607 if(j==0)
608 {
609 if(i < fDigits->GetNCols()-1 && i > 0)
610 {
611 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
612 fDigits->GetDigitFast(time,pad+1)<=zerosupval &&
613 fDigits->GetDigitFast(time+1,pad)<=zerosupval)
614 continue;
615 }
616 else if(i > 0)
617 {
618 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
619 fDigits->GetDigitFast(time+1,pad)<=zerosupval)
620 continue;
621 }
622 }
623
624 if(i==fDigits->GetNCols()-1)
625 {
626 if(j>0 && j<fDigits->GetNRows()-1)
627 {
628 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
629 fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
630 fDigits->GetDigitFast(time,pad-1)<=zerosupval)
631 continue;
632 }
633 else if(j==0 && j<fDigits->GetNRows()-1)
634 {
635 if(fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
636 fDigits->GetDigitFast(time,pad-1)<=zerosupval)
637 continue;
638 }
639 else
640 {
641 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
642 fDigits->GetDigitFast(time,pad-1)<=zerosupval)
643 continue;
644 }
645 }
646
647 if(j==fDigits->GetNRows()-1)
648 {
649 if(i>0 && i<fDigits->GetNCols()-1)
650 {
651 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
652 fDigits->GetDigitFast(time,pad+1)<=zerosupval &&
653 fDigits->GetDigitFast(time-1,pad)<=zerosupval)
654 continue;
655 }
656 else if(i==0 && fDigits->GetNCols()-1)
657 {
658 if(fDigits->GetDigitFast(time,pad+1)<=zerosupval &&
659 fDigits->GetDigitFast(time-1,pad)<=zerosupval)
660 continue;
661 }
662 else
663 {
664 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
665 fDigits->GetDigitFast(time-1,pad)<=zerosupval)
666 continue;
667 }
668 }
669
670 AliL3Transform::Raw2Local(xyz,sector,row,pad,time);
671 if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2]))
672 continue;
954beff0 673
02f030e3 674 ndigits[lrow]++; //for this row only
675 ndigitcount++; //total number of digits to be published
676 }
954beff0 677 }
02f030e3 678
679 nrows++;
680 }
681
954beff0 682 Int_t size = sizeof(AliL3DigitData)*ndigitcount
683 + nrows*sizeof(AliL3DigitRowData);
684
685 LOG(AliL3Log::kDebug,"AliL3FileHandler::AliAltroDigits2Memory","Digits")
686 <<AliL3Log::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG;
687
688 data=(AliL3DigitRowData*) Allocate(size);
689 nrow = (UInt_t)nrows;
690 AliL3DigitRowData *tempPt = data;
02f030e3 691
692 for(Int_t r=fRowMin;r<=fRowMax;r++){
693 Int_t n=fIndex[fSlice][r];
694 if(n==-1) continue; //no data on that row
695
696 fDigitsTree->GetEvent(n);
697 fParam->AdjustSectorRow(fDigits->GetID(),sector,row);
698 AliL3Transform::Sector2Slice(lslice,lrow,sector,row);
699
700 if(lrow!=r){
701 LOG(AliL3Log::kError,"AliL3FileHandler::AliAltroDigits2Memory","Row")
b2a02bce 702 <<AliL3Log::kDec<<"Rows on slice " << fSlice << " dont match "<<lrow<<" "<<r<<ENDLOG;
703 continue;
02f030e3 704 }
954beff0 705
02f030e3 706 tempPt->fRow = lrow;
707 tempPt->fNDigit = ndigits[lrow];
708
709 Int_t localcount=0;
710 fDigits->ExpandBuffer();
711 fDigits->ExpandTrackBuffer();
712 for(Int_t i=0; i<fDigits->GetNCols(); i++){
713 for(Int_t j=0; j<fDigits->GetNRows(); j++){
714 pad=i;
715 time=j;
716 dig = fDigits->GetDigitFast(time,pad);
717 if(dig <= zerosupval) continue;
718 if(dig >= AliL3Transform::GetADCSat())
719 dig = AliL3Transform::GetADCSat();
954beff0 720
02f030e3 721 //Check for single timebins, and remove them because they are noise for sure.
722 if(i>0 && i<fDigits->GetNCols()-1 && j>0 && j<fDigits->GetNRows()-1)
723 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
724 fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
725 fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
726 fDigits->GetDigitFast(time,pad+1)<=zerosupval)
727 continue;
728
729 //Boundaries:
730 if(i==0) //pad ==0
731 {
732 if(j < fDigits->GetNRows()-1 && j > 0)
733 {
734 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
735 fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
736 fDigits->GetDigitFast(time,pad+1)<=zerosupval)
737 continue;
738 }
739 else if(j > 0)
740 {
741 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
742 fDigits->GetDigitFast(time,pad+1)<=zerosupval)
743 continue;
744 }
745 }
746 if(j==0)
747 {
748 if(i < fDigits->GetNCols()-1 && i > 0)
749 {
750 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
751 fDigits->GetDigitFast(time,pad+1)<=zerosupval &&
752 fDigits->GetDigitFast(time+1,pad)<=zerosupval)
753 continue;
754 }
755 else if(i > 0)
756 {
757 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
758 fDigits->GetDigitFast(time+1,pad)<=zerosupval)
759 continue;
760 }
761 }
762
763 if(i == fDigits->GetNCols()-1)
764 {
765 if(j>0 && j<fDigits->GetNRows()-1)
766 {
767 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
768 fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
769 fDigits->GetDigitFast(time,pad-1)<=zerosupval)
770 continue;
771 }
772 else if(j==0 && j<fDigits->GetNRows()-1)
773 {
774 if(fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
775 fDigits->GetDigitFast(time,pad-1)<=zerosupval)
776 continue;
777 }
778 else
779 {
780 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
781 fDigits->GetDigitFast(time,pad-1)<=zerosupval)
782 continue;
783 }
784 }
785 if(j==fDigits->GetNRows()-1)
786 {
787 if(i>0 && i<fDigits->GetNCols()-1)
788 {
789 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
790 fDigits->GetDigitFast(time,pad+1)<=zerosupval &&
791 fDigits->GetDigitFast(time-1,pad)<=zerosupval)
792 continue;
793 }
794 else if(i==0 && fDigits->GetNCols()-1)
795 {
796 if(fDigits->GetDigitFast(time,pad+1)<=zerosupval &&
797 fDigits->GetDigitFast(time-1,pad)<=zerosupval)
798 continue;
799 }
800 else
801 {
802 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
803 fDigits->GetDigitFast(time-1,pad)<=zerosupval)
804 continue;
805 }
806 }
807
808 AliL3Transform::Raw2Local(xyz,sector,row,pad,time);
809 if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2]))
810 continue;
954beff0 811
02f030e3 812 if(localcount >= ndigits[lrow])
813 LOG(AliL3Log::kFatal,"AliL3FileHandler::AliAltroDigits2Binary","Memory")
814 <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits "
815 <<ndigits[lrow]<<ENDLOG;
816
817 tempPt->fDigitData[localcount].fCharge=dig;
818 tempPt->fDigitData[localcount].fPad=pad;
819 tempPt->fDigitData[localcount].fTime=time;
954beff0 820#ifdef do_mc
02f030e3 821 tempPt->fDigitData[localcount].fTrackID[0] = (fDigits->GetTrackIDFast(time,pad,0)-2);
822 tempPt->fDigitData[localcount].fTrackID[1] = (fDigits->GetTrackIDFast(time,pad,1)-2);
823 tempPt->fDigitData[localcount].fTrackID[2] = (fDigits->GetTrackIDFast(time,pad,2)-2);
824 if(eventmerge == kTRUE) //careful track mc info will be touched
825 {//Event are going to be merged, so event number is stored in the upper 10 bits.
826 tempPt->fDigitData[localcount].fTrackID[0] += 128; //leave some room
827 tempPt->fDigitData[localcount].fTrackID[1] += 128; //for neg. numbers
828 tempPt->fDigitData[localcount].fTrackID[2] += 128;
829 tempPt->fDigitData[localcount].fTrackID[0] += ((event&0x3ff)<<22);
830 tempPt->fDigitData[localcount].fTrackID[1] += ((event&0x3ff)<<22);
831 tempPt->fDigitData[localcount].fTrackID[2] += ((event&0x3ff)<<22);
832 }
954beff0 833#endif
02f030e3 834 localcount++;
835 }
954beff0 836 }
02f030e3 837
838 Byte_t *tmp = (Byte_t*)tempPt;
839 Int_t size = sizeof(AliL3DigitRowData)
840 + ndigits[lrow]*sizeof(AliL3DigitData);
841 tmp += size;
842 tempPt = (AliL3DigitRowData*)tmp;
843 }
954beff0 844 return data;
845}
02f030e3 846
a6e4f9d6 847Bool_t AliL3FileHandler::GetDigitsTree(Int_t event)
848{
9183aa27 849 //Connects to the TPC digit tree in the AliROOT file.
b2a02bce 850#ifdef use_newio
a27af97b 851 AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader");
852 if(!tpcLoader){
853 LOG(AliL3Log::kWarning,"AliL3FileHandler::GetDigitsTree","File")
854 <<"Pointer to AliLoader for TPC = 0x0 "<<ENDLOG;
855 return kFALSE;
856 }
857 fInAli->GetEvent(event);
858 tpcLoader->LoadDigits();
859 fDigitsTree = tpcLoader->TreeD();
b2a02bce 860#else
861 fInAli->cd();
862 Char_t dname[100];
863 sprintf(dname,"TreeD_%s_%d",AliL3Transform::GetParamName(),event);
864 fDigitsTree = (TTree*)fInAli->Get(dname);
865#endif
a6e4f9d6 866 if(!fDigitsTree)
867 {
868 LOG(AliL3Log::kError,"AliL3FileHandler::GetDigitsTree","Digits Tree")
869 <<AliL3Log::kHex<<"Error getting digitstree "<<(Int_t)fDigitsTree<<ENDLOG;
870 return kFALSE;
871 }
872 fDigitsTree->GetBranch("Segment")->SetAddress(&fDigits);
02f030e3 873
b2a02bce 874 if(!fIndexCreated) return CreateIndex();
875 else return kTRUE;
a6e4f9d6 876}
877
0d319e67 878void AliL3FileHandler::AliDigits2RootFile(AliL3DigitRowData *rowPt,Char_t *new_digitsfile)
879{
9183aa27 880 //Write the data stored in rowPt, into a new AliROOT file.
881 //The data is stored in the AliROOT format
882 //This is specially a nice thing if you have modified data, and wants to run it
883 //through the offline reconstruction chain.
884 //The arguments is a pointer to the data, and the name of the new AliROOT file.
885 //Remember to pass the original AliROOT file (the one that contains the original
886 //simulated data) to this object, in order to retrieve the MC id's of the digits.
f6670bec 887
0d319e67 888 if(!fInAli)
889 {
b2a02bce 890 LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2RootFile","File")
891 <<"No rootfile "<<ENDLOG;
0d319e67 892 return;
893 }
894 if(!fParam)
895 {
b2a02bce 896 LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2RootFile","File")
897 <<"No parameter object. Run on rootfile "<<ENDLOG;
0d319e67 898 return;
899 }
b2a02bce 900
901#ifdef use_newio
0d319e67 902 //Get the original digitstree:
a27af97b 903 AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader");
904 if(!tpcLoader){
905 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2RootFile","File")
906 <<"Pointer to AliLoader for TPC = 0x0 "<<ENDLOG;
907 return;
908 }
909 tpcLoader->LoadDigits();
910 TTree *t=tpcLoader->TreeD();
6df3cddf 911
0d319e67 912 AliTPCDigitsArray *old_array = new AliTPCDigitsArray();
913 old_array->Setup(fParam);
914 old_array->SetClass("AliSimDigits");
5e0f9911 915
a27af97b 916 Bool_t ok = old_array->ConnectTree(t);
0d319e67 917 if(!ok)
918 {
b2a02bce 919 LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2RootFile","File")
920 << "No digits tree object" << ENDLOG;
0d319e67 921 return;
922 }
6df3cddf 923
a27af97b 924 tpcLoader->SetDigitsFileName(new_digitsfile);
925 tpcLoader->MakeDigitsContainer();
03b6adf7 926
927 //setup a new one, or connect it to the existing one:
6df3cddf 928 AliTPCDigitsArray *arr = new AliTPCDigitsArray();
0d319e67 929 arr->SetClass("AliSimDigits");
930 arr->Setup(fParam);
a27af97b 931 arr->MakeTree(tpcLoader->TreeD());
b2a02bce 932#else
933
934 //Get the original digitstree:
935 Char_t dname[100];
936 sprintf(dname,"TreeD_%s_0",AliL3Transform::GetParamName());
937
938 fInAli->cd();
939 AliTPCDigitsArray *old_array = new AliTPCDigitsArray();
940 old_array->Setup(fParam);
941 old_array->SetClass("AliSimDigits");
942
943 Bool_t ok = old_array->ConnectTree(dname);
944 if(!ok)
945 {
946 LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2RootFile","File")
947 <<"No digits tree object." <<ENDLOG;
948 return;
949 }
950
951 Bool_t create=kFALSE;
952 TFile *digFile;
953
954 if(gSystem->AccessPathName(new_digitsfile))
955 {
956 LOG(AliL3Log::kInformational,"AliL3FileHandler::AliDigits2RootFile","File")
957 <<"Creating new file "<<new_digitsfile<<ENDLOG;
958 create = kTRUE;
959 digFile = TFile::Open(new_digitsfile,"RECREATE");
960 fParam->Write(fParam->GetTitle());
961 }
962 else
963 {
964 create = kFALSE;
965 digFile = TFile::Open(new_digitsfile,"UPDATE");
966
967 }
968 if(!digFile->IsOpen())
969 {
970 LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2RootFile","Rootfile")
971 <<"Error opening rootfile "<<new_digitsfile<<ENDLOG;
972 return;
973 }
974
975 digFile->cd();
976
977 //setup a new one, or connect it to the existing one:
978 AliTPCDigitsArray *arr = new AliTPCDigitsArray();
979 arr->SetClass("AliSimDigits");
980 arr->Setup(fParam);
981 if(create)
982 arr->MakeTree();
983 else
984 {
985 Bool_t ok = arr->ConnectTree(dname);
986 if(!ok)
987 {
988 LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2RootFile","Rootfile")
989 <<"No digits tree object in existing file"<<ENDLOG;
990 return;
991 }
992 }
993#endif
a27af97b 994
6df3cddf 995 Int_t digcounter=0,trackID[3];
49898c33 996
0d319e67 997 for(Int_t i=fRowMin; i<=fRowMax; i++)
998 {
03b6adf7 999
6df3cddf 1000 if((Int_t)rowPt->fRow != i)
b2a02bce 1001 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2RootFile","Data")
1002 <<"Mismatching row numbering "<<(Int_t)rowPt->fRow<<" "<<i<<ENDLOG;
03b6adf7 1003
0d319e67 1004 Int_t sector,row;
494fad94 1005 AliL3Transform::Slice2Sector(fSlice,i,sector,row);
6df3cddf 1006
49898c33 1007 AliSimDigits *old_dig = (AliSimDigits*)old_array->LoadRow(sector,row);
6df3cddf 1008 AliSimDigits * dig = (AliSimDigits*)arr->CreateRow(sector,row);
1009 old_dig->ExpandBuffer();
1010 old_dig->ExpandTrackBuffer();
1011 dig->ExpandBuffer();
1012 dig->ExpandTrackBuffer();
1013
0d319e67 1014 if(!old_dig)
b2a02bce 1015 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2RootFile","Data")
1016 <<"No padrow " << sector << " " << row <<ENDLOG;
1017
0d319e67 1018 AliL3DigitData *digPt = rowPt->fDigitData;
54efe57a 1019 digcounter=0;
0d319e67 1020 for(UInt_t j=0; j<rowPt->fNDigit; j++)
1021 {
6df3cddf 1022 Short_t charge = (Short_t)digPt[j].fCharge;
49898c33 1023 Int_t pad = (Int_t)digPt[j].fPad;
1024 Int_t time = (Int_t)digPt[j].fTime;
03b6adf7 1025
1026 if(charge == 0) //Only write the digits that has not been removed
6df3cddf 1027 {
b2a02bce 1028 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2RootFile","Data")
1029 <<"Zero charge" <<ENDLOG;
6df3cddf 1030 continue;
1031 }
1032
54efe57a 1033 digcounter++;
49898c33 1034
6df3cddf 1035 //Tricks to get and set the correct track id's.
1036 for(Int_t t=0; t<3; t++)
97543115 1037 {
6df3cddf 1038 Int_t label = old_dig->GetTrackIDFast(time,pad,t);
1039 if(label > 1)
1040 trackID[t] = label - 2;
1041 else if(label==0)
1042 trackID[t] = -2;
1043 else
1044 trackID[t] = -1;
49898c33 1045 }
6df3cddf 1046
1047 dig->SetDigitFast(charge,time,pad);
1048
1049 for(Int_t t=0; t<3; t++)
1050 ((AliSimDigits*)dig)->SetTrackIDFast(trackID[t],time,pad,t);
0d319e67 1051
1052 }
54efe57a 1053 //cout<<"Wrote "<<digcounter<<" on row "<<i<<endl;
0d319e67 1054 UpdateRowPointer(rowPt);
1055 arr->StoreRow(sector,row);
1056 arr->ClearRow(sector,row);
1057 old_array->ClearRow(sector,row);
1058 }
b2a02bce 1059
0d319e67 1060 char treeName[100];
03b6adf7 1061 sprintf(treeName,"TreeD_%s_0",fParam->GetTitle());
b2a02bce 1062
1063#ifdef use_newio
6df3cddf 1064 arr->GetTree()->SetName(treeName);
1065 arr->GetTree()->AutoSave();
a27af97b 1066 tpcLoader->WriteDigits("OVERWRITE");
b2a02bce 1067#else
1068 digFile->cd();
1069 arr->GetTree()->SetName(treeName);
1070 arr->GetTree()->AutoSave();
1071 digFile->Close();
1072#endif
6df3cddf 1073 delete arr;
1074 delete old_array;
0d319e67 1075}
1076
108615fc 1077///////////////////////////////////////// Point IO
3e87ef69 1078Bool_t AliL3FileHandler::AliPoints2Binary(Int_t eventn){
108615fc 1079 Bool_t out = kTRUE;
1080 UInt_t npoint;
3e87ef69 1081 AliL3SpacePointData *data = AliPoints2Memory(npoint,eventn);
108615fc 1082 out = Memory2Binary(npoint,data);
1083 Free();
1084 return out;
1085}
1086
3e87ef69 1087AliL3SpacePointData * AliL3FileHandler::AliPoints2Memory(UInt_t & npoint,Int_t eventn){
108615fc 1088 AliL3SpacePointData *data = 0;
1089 npoint=0;
1090 if(!fInAli){
1091 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliPoints2Memory","File")
b2a02bce 1092 <<"No Input avalible: no object fInAli"<<ENDLOG;
1093 return 0;
1094 }
1095#ifndef use_newio
1096 if(!fInAli->IsOpen()){
1097 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliPoints2Memory","File")
1098 <<"No Input avalible: TFile not opend"<<ENDLOG;
108615fc 1099 return 0;
1100 }
b2a02bce 1101#endif
a27af97b 1102
1103 TDirectory *savedir = gDirectory;
b2a02bce 1104#ifdef use_newio
a27af97b 1105 AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader");
1106 if(!tpcLoader){
108615fc 1107 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliPoints2Memory","File")
a27af97b 1108 <<"Pointer to AliLoader for TPC = 0x0 "<<ENDLOG;
1109 return kFALSE;
108615fc 1110 }
a27af97b 1111 fInAli->GetEvent(eventn);
1112 tpcLoader->LoadRecPoints();
494fad94 1113
108615fc 1114 AliTPCClustersArray carray;
1115 carray.Setup(fParam);
1116 carray.SetClusterType("AliTPCcluster");
a27af97b 1117 Bool_t clusterok = carray.ConnectTree(tpcLoader->TreeR());
b2a02bce 1118#else
1119 fInAli->cd();
1120
1121 Char_t cname[100];
1122 sprintf(cname,"TreeC_TPC_%d",eventn);
1123 AliTPCClustersArray carray;
1124 carray.Setup(fParam);
1125 carray.SetClusterType("AliTPCcluster");
1126 Bool_t clusterok = carray.ConnectTree(cname);
1127#endif
1128
108615fc 1129 if(!clusterok) return 0;
1130
1131 AliTPCClustersRow ** clusterrow =
1132 new AliTPCClustersRow*[ (int)carray.GetTree()->GetEntries()];
1133 Int_t *rows = new int[ (int)carray.GetTree()->GetEntries()];
1134 Int_t *sects = new int[ (int)carray.GetTree()->GetEntries()];
1135 Int_t sum=0;
1136
1137 Int_t lslice,lrow;
1138 for(Int_t i=0; i<carray.GetTree()->GetEntries(); i++){
1139 AliSegmentID *s = carray.LoadEntry(i);
1140 Int_t sector,row;
1141 fParam->AdjustSectorRow(s->GetID(),sector,row);
1142 rows[i] = row;
1143 sects[i] = sector;
1144 clusterrow[i] = 0;
494fad94 1145 AliL3Transform::Sector2Slice(lslice,lrow,sector,row);
108615fc 1146 if(fSlice != lslice || lrow<fRowMin || lrow>fRowMax) continue;
1147 clusterrow[i] = carray.GetRow(sector,row);
1148 if(clusterrow[i])
1149 sum+=clusterrow[i]->GetArray()->GetEntriesFast();
1150 }
1151 UInt_t size = sum*sizeof(AliL3SpacePointData);
1152
1153 LOG(AliL3Log::kDebug,"AliL3FileHandler::AliPoints2Memory","File")
1154 <<AliL3Log::kDec<<"Found "<<sum<<" SpacePoints"<<ENDLOG;
1155
1156 data = (AliL3SpacePointData *) Allocate(size);
1157 npoint = sum;
1158 UInt_t n=0;
3e87ef69 1159 Int_t pat=fPatch;
1160 if(fPatch==-1)
1161 pat=0;
108615fc 1162 for(Int_t i=0; i<carray.GetTree()->GetEntries(); i++){
1163 if(!clusterrow[i]) continue;
1164 Int_t row = rows[i];
1165 Int_t sector = sects[i];
494fad94 1166 AliL3Transform::Sector2Slice(lslice,lrow,sector,row);
108615fc 1167 Int_t entries_in_row = clusterrow[i]->GetArray()->GetEntriesFast();
1168 for(Int_t j = 0;j<entries_in_row;j++){
1169 AliTPCcluster *c = (AliTPCcluster*)(*clusterrow[i])[j];
1170 data[n].fZ = c->GetZ();
1171 data[n].fY = c->GetY();
1172 data[n].fX = fParam->GetPadRowRadii(sector,row);
8e348d6a 1173 data[n].fCharge = (UInt_t)c->GetQ();
3e87ef69 1174 data[n].fID = n+((fSlice&0x7f)<<25)+((pat&0x7)<<22);//uli
108615fc 1175 data[n].fPadRow = lrow;
3e87ef69 1176 data[n].fSigmaY2 = c->GetSigmaY2();
1177 data[n].fSigmaZ2 = c->GetSigmaZ2();
1178#ifdef do_mc
1179 data[n].fTrackID[0] = c->GetLabel(0);
1180 data[n].fTrackID[1] = c->GetLabel(1);
1181 data[n].fTrackID[2] = c->GetLabel(2);
1182#endif
108615fc 1183 if(fMC) fprintf(fMC,"%d %d\n",data[n].fID,c->GetLabel(0));
1184 n++;
1185 }
1186 }
1187 for(Int_t i=0;i<carray.GetTree()->GetEntries();i++){
1188 Int_t row = rows[i];
1189 Int_t sector = sects[i];
1190 if(carray.GetRow(sector,row))
1191 carray.ClearRow(sector,row);
1192 }
1193
1194 delete [] clusterrow;
1195 delete [] rows;
1196 delete [] sects;
1197 savedir->cd();
1198
1199 return data;
1200}
1201