3 // Author: Uli Frankenfeld <mailto:franken@fi.uib.no>, Anders Vestbo <mailto:vestbo$fi.uib.no>, C. Loizides <mailto:loizides@ikf.uni-frankfurt.de>
4 //*-- Copyright © ALICE HLT Group
6 #include "AliL3StandardIncludes.h"
7 #include <TClonesArray.h>
11 #include <AliRunLoader.h>
14 #include <AliTPCParamSR.h>
15 #include <AliTPCDigitsArray.h>
16 #include <AliTPCClustersArray.h>
17 #include <AliTPCcluster.h>
18 #include <AliTPCClustersRow.h>
19 #include <AliSimDigits.h>
21 #include "AliL3Logging.h"
22 #include "AliL3Transform.h"
23 #include "AliL3MemHandler.h"
24 #include "AliL3DigitData.h"
25 #include "AliL3TrackSegmentData.h"
26 #include "AliL3SpacePointData.h"
27 #include "AliL3TrackArray.h"
28 #include "AliL3FileHandler.h"
34 /** \class AliL3FileHandler
36 //_____________________________________________________________
39 // The HLT ROOT <-> binary files handling class
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.
48 // For example on how to create binary files from a AliROOT simulation,
49 // see example macro exa/Binary.C.
51 // For reading a AliROOT file into HLT format in memory, do the following:
53 // AliL3FileHandler file;
54 // file.Init(slice,patch);
55 // file.SetAliInput("galice.root");
56 // AliL3DigitRowData *dataPt = (AliL3DigitRowData*)file.AliDigits2Memory(nrows,eventnr);
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.
61 // For converting the data back, and writing it to a new AliROOT file do:
63 // AliL3FileHandler file;
64 // file.Init(slice,patch);
65 // file.SetAliInput("galice.root");
66 // file.Init(slice,patch,NumberOfRowsInPatch);
67 // file.AliDigits2RootFile(dataPt,"new_galice.root");
68 // file.CloseAliInput();
72 ClassImp(AliL3FileHandler)
74 // of course on start up the index is not created
75 Bool_t AliL3FileHandler::fStaticIndexCreated=kFALSE;
76 Int_t AliL3FileHandler::fStaticIndex[36][159];
78 void AliL3FileHandler::CleanStaticIndex()
79 { // use this static call to clean static index after
80 // running over one event
82 for(Int_t i=0;i<AliL3Transform::GetNSlice();i++){
83 for(Int_t j=0;j<AliL3Transform::GetNRows();j++)
84 fStaticIndex[i][j]=-1;
86 fStaticIndexCreated=kFALSE;
89 Int_t AliL3FileHandler::SaveStaticIndex(Char_t *prefix,Int_t event)
90 { // use this static call to store static index after
91 if(!fStaticIndexCreated) return -1;
95 sprintf(fname,"%s-%d.txt",prefix,event);
97 sprintf(fname,"TPC.Digits.staticindex-%d.txt",event);
99 ofstream file(fname,ios::trunc);
100 if(!file.good()) return -1;
102 for(Int_t i=0;i<AliL3Transform::GetNSlice();i++){
103 for(Int_t j=0;j<AliL3Transform::GetNRows();j++)
104 file << fStaticIndex[i][j] << " ";
111 Int_t AliL3FileHandler::LoadStaticIndex(Char_t *prefix,Int_t event)
112 { // use this static call to store static index after
113 if(fStaticIndexCreated){
114 LOG(AliL3Log::kWarning,"AliL3FileHandler::LoadStaticIndex","Inxed")
115 <<"Static index already created, will overwrite"<<ENDLOG;
121 sprintf(fname,"%s-%d.txt",prefix,event);
123 sprintf(fname,"TPC.Digits.staticindex-%d.txt",event);
125 ifstream file(fname);
126 if(!file.good()) return -1;
128 for(Int_t i=0;i<AliL3Transform::GetNSlice();i++){
129 for(Int_t j=0;j<AliL3Transform::GetNRows();j++)
130 file >> fStaticIndex[i][j];
134 fStaticIndexCreated=kTRUE;
138 AliL3FileHandler::AliL3FileHandler(Bool_t b)
140 //Default constructor
143 fUseRunLoader = kFALSE;
149 fIndexCreated=kFALSE;
152 for(Int_t i=0;i<AliL3Transform::GetNSlice();i++)
153 for(Int_t j=0;j<AliL3Transform::GetNRows();j++)
156 if(fUseStaticIndex&&!fStaticIndexCreated) CleanStaticIndex();
159 AliL3FileHandler::~AliL3FileHandler()
162 if(fMC) CloseMCOutput();
164 if(fInAli) CloseAliInput();
167 void AliL3FileHandler::FreeDigitsTree()
171 LOG(AliL3Log::kInformational,"AliL3FileHandler::FreeDigitsTree()","Pointer")
172 <<"Cannot free digitstree, it is not present"<<ENDLOG;
178 fDigitsTree->Delete();
182 for(Int_t i=0;i<AliL3Transform::GetNSlice();i++){
183 for(Int_t j=0;j<AliL3Transform::GetNRows();j++)
186 fIndexCreated=kFALSE;
189 Bool_t AliL3FileHandler::SetMCOutput(Char_t *name)
191 fMC = fopen(name,"w");
193 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetMCOutput","File Open")
194 <<"Pointer to File = 0x0 "<<ENDLOG;
200 Bool_t AliL3FileHandler::SetMCOutput(FILE *file)
204 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetMCOutput","File Open")
205 <<"Pointer to File = 0x0 "<<ENDLOG;
211 void AliL3FileHandler::CloseMCOutput()
214 LOG(AliL3Log::kWarning,"AliL3FileHandler::CloseMCOutPut","File Close")
215 <<"Nothing to Close"<<ENDLOG;
222 Bool_t AliL3FileHandler::SetAliInput()
226 fParam = AliTPC::LoadTPCParam(gFile);
228 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File")
229 <<"No TPC parameters found in \""<<gFile->GetName()
230 <<"\", creating standard parameters "
231 <<"which might not be what you want!"<<ENDLOG;
232 fParam = new AliTPCParamSR;
235 LOG(AliL3Log::kError,"AliL3FileHandler::SetAliInput","File Open")
236 <<"No AliTPCParam "<<AliL3Transform::GetParamName()<<" in File "<<gFile->GetName()<<ENDLOG;
240 if(!fInAli->IsOpen()){
241 LOG(AliL3Log::kError,"AliL3FileHandler::SetAliInput","File Open")
242 <<"Ali File "<<fInAli->GetName()<<" does not exist"<<ENDLOG;
245 fParam = (AliTPCParam*)fInAli->Get(AliL3Transform::GetParamName());
247 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File")
248 <<"No TPC parameters found in \""<<fInAli->GetName()
249 <<"\", creating standard parameters "
250 <<"which might not be what you want!"<<ENDLOG;
251 fParam = new AliTPCParamSR;
254 LOG(AliL3Log::kError,"AliL3FileHandler::SetAliInput","File Open")
255 <<"No AliTPCParam "<<AliL3Transform::GetParamName()<<" in File "<<fInAli->GetName()<<ENDLOG;
263 Bool_t AliL3FileHandler::SetAliInput(Char_t *name)
265 //Open the AliROOT file with name.
267 fInAli= AliRunLoader::Open(name);
269 fInAli= new TFile(name,"READ");
272 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File Open")
273 <<"Pointer to fInAli = 0x0 "<<ENDLOG;
276 return SetAliInput();
280 Bool_t AliL3FileHandler::SetAliInput(AliRunLoader *runLoader)
283 fUseRunLoader = kTRUE;
285 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File Open")
286 <<"Pointer to AliRunLoader = 0x0 "<<ENDLOG;
289 return SetAliInput();
294 Bool_t AliL3FileHandler::SetAliInput(TFile */*file*/)
296 LOG(AliL3Log::kFatal,"AliL3FileHandler::SetAliInput","File Open")
297 <<"This function is not supported for NEWIO, check ALIHLT_USENEWIO settings in Makefile.conf"<<ENDLOG;
301 Bool_t AliL3FileHandler::SetAliInput(TFile *file)
303 //Specify already opened AliROOT file to use as an input.
306 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File Open")
307 <<"Pointer to fInAli = 0x0 "<<ENDLOG;
310 return SetAliInput();
314 void AliL3FileHandler::CloseAliInput()
317 if(fUseRunLoader) return;
320 LOG(AliL3Log::kWarning,"AliL3FileHandler::CloseAliInput","RunLoader")
321 <<"Nothing to Close"<<ENDLOG;
325 if(fInAli->IsOpen()) fInAli->Close();
332 Bool_t AliL3FileHandler::IsDigit(Int_t event)
334 //Check if there is a TPC digit tree in the current file.
335 //Return kTRUE if tree was found, and kFALSE if not found.
338 LOG(AliL3Log::kWarning,"AliL3FileHandler::IsDigit","File")
339 <<"Pointer to fInAli = 0x0 "<<ENDLOG;
340 return kTRUE; //maybe you are using binary input which is Digits!
343 AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader");
345 LOG(AliL3Log::kWarning,"AliL3FileHandlerNewIO::IsDigit","File")
346 <<"Pointer to AliLoader for TPC = 0x0 "<<ENDLOG;
349 fInAli->GetEvent(event);
350 tpcLoader->LoadDigits();
351 TTree *t=tpcLoader->TreeD();
354 sprintf(name,"TreeD_%s_%d",AliL3Transform::GetParamName(),event);
355 TTree *t=(TTree*)fInAli->Get(name);
358 LOG(AliL3Log::kInformational,"AliL3FileHandlerNewIO::IsDigit","File Type")
359 <<"Found Digit Tree -> Use Fast Cluster Finder"<<ENDLOG;
363 LOG(AliL3Log::kInformational,"AliL3FileHandlerNewIO::IsDigit","File Type")
364 <<"No Digit Tree -> Use Cluster Tree"<<ENDLOG;
369 ///////////////////////////////////////// Digit IO
370 Bool_t AliL3FileHandler::AliDigits2Binary(Int_t event,Bool_t altro)
374 AliL3DigitRowData* data = 0;
376 data = AliAltroDigits2Memory(nrow,event);
378 data = AliDigits2Memory(nrow,event);
379 out = Memory2Binary(nrow,data);
384 Bool_t AliL3FileHandler::AliDigits2CompBinary(Int_t event,Bool_t altro)
386 //Convert AliROOT TPC data, into HLT data format.
387 //event specifies the event you want in the aliroot file.
391 AliL3DigitRowData *digits=0;
393 digits = AliAltroDigits2Memory(ndigits,event);
395 digits = AliDigits2Memory(ndigits,event);
396 out = Memory2CompBinary(ndigits,digits);
401 Bool_t AliL3FileHandler::CreateIndex()
403 //create the access index or copy from static index
404 fIndexCreated=kFALSE;
406 if(!fStaticIndexCreated || !fUseStaticIndex) { //we have to create index
407 LOG(AliL3Log::kInformational,"AliL3FileHandler::CreateIndex","Index")
408 <<"Starting to create index, this can take a while."<<ENDLOG;
410 for(Int_t n=0; n<fDigitsTree->GetEntries(); n++) {
413 fDigitsTree->GetEvent(n);
414 fParam->AdjustSectorRow(fDigits->GetID(),sector,row);
415 if(!AliL3Transform::Sector2Slice(lslice,lrow,sector,row)){
416 LOG(AliL3Log::kError,"AliL3FileHandler::CreateIndex","Slice/Row")
417 <<AliL3Log::kDec<<"Index could not be created. Wrong values "
418 <<sector<<" "<<row<<ENDLOG;
421 if(fIndex[lslice][lrow]==-1) {
422 fIndex[lslice][lrow]=n;
425 if(fUseStaticIndex) { // create static index
426 for(Int_t i=0;i<AliL3Transform::GetNSlice();i++){
427 for(Int_t j=0;j<AliL3Transform::GetNRows();j++)
428 fStaticIndex[i][j]=fIndex[i][j];
430 fStaticIndexCreated=kTRUE; //remember that index has been created
433 LOG(AliL3Log::kInformational,"AliL3FileHandler::CreateIndex","Index")
434 <<"Index successfully created."<<ENDLOG;
436 } else if(fUseStaticIndex) { //simply copy static index
437 for(Int_t i=0;i<AliL3Transform::GetNSlice();i++){
438 for(Int_t j=0;j<AliL3Transform::GetNRows();j++)
439 fIndex[i][j]=fStaticIndex[i][j];
442 LOG(AliL3Log::kInformational,"AliL3FileHandler::CreateIndex","Index")
443 <<"Index successfully taken from static copy."<<ENDLOG;
451 AliL3DigitRowData * AliL3FileHandler::AliDigits2Memory(UInt_t & nrow,Int_t event)
453 //Read data from AliROOT file into memory, and store it in the HLT data format.
454 //Returns a pointer to the data.
456 AliL3DigitRowData *data = 0;
460 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2Memory","File")
461 <<"No Input avalible: Pointer to fInAli == NULL"<<ENDLOG;
466 if(!fInAli->IsOpen()){
467 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2Memory","File")
468 <<"No Input avalible: TFile not opened"<<ENDLOG;
474 if(!GetDigitsTree(event)) return 0;
477 Int_t time,pad,sector,row;
481 Int_t entries = (Int_t)fDigitsTree->GetEntries();
483 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2Memory","ndigits")
484 <<"No TPC digits (entries==0)!"<<ENDLOG;
485 nrow = (UInt_t)(fRowMax-fRowMin+1);
486 Int_t size = nrow*sizeof(AliL3DigitRowData);
487 data=(AliL3DigitRowData*) Allocate(size);
488 AliL3DigitRowData *tempPt = data;
489 for(Int_t r=fRowMin;r<=fRowMax;r++){
497 Int_t * ndigits = new Int_t[entries];
500 for(Int_t r=fRowMin;r<=fRowMax;r++){
501 Int_t n=fIndex[fSlice][r];
502 if(n!=-1){ //data on that row
503 fDigitsTree->GetEvent(n);
504 fParam->AdjustSectorRow(fDigits->GetID(),sector,row);
505 AliL3Transform::Sector2Slice(lslice,lrow,sector,row);
508 LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2Memory","Row")
509 <<AliL3Log::kDec<<"Rows in slice " << fSlice << " dont match "<<lrow<<" "<<r<<ENDLOG;
516 time=fDigits->CurrentRow();
517 pad=fDigits->CurrentColumn();
518 dig = fDigits->GetDigit(time,pad);
519 if(dig <= fParam->GetZeroSup()) continue;
520 if(dig >= AliL3Transform::GetADCSat())
521 dig = AliL3Transform::GetADCSat();
523 AliL3Transform::Raw2Local(xyz,sector,row,pad,time);
524 if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2]))
525 continue; // why 230???
527 ndigits[lrow]++; //for this row only
528 ndigitcount++; //total number of digits to be published
530 } while (fDigits->Next());
531 //cout << lrow << " " << ndigits[lrow] << " - " << ndigitcount << endl;
536 Int_t size = sizeof(AliL3DigitData)*ndigitcount
537 + nrows*sizeof(AliL3DigitRowData);
539 LOG(AliL3Log::kDebug,"AliL3FileHandler::AliDigits2Memory","Digits")
540 <<AliL3Log::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG;
542 data=(AliL3DigitRowData*) Allocate(size);
543 nrow = (UInt_t)nrows;
544 AliL3DigitRowData *tempPt = data;
546 for(Int_t r=fRowMin;r<=fRowMax;r++){
547 Int_t n=fIndex[fSlice][r];
551 if(n!=-1){//data on that row
552 fDigitsTree->GetEvent(n);
553 fParam->AdjustSectorRow(fDigits->GetID(),sector,row);
554 AliL3Transform::Sector2Slice(lslice,lrow,sector,row);
556 LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2Memory","Row")
557 <<AliL3Log::kDec<<"Rows on slice " << fSlice << " dont match "<<lrow<<" "<<r<<ENDLOG;
561 tempPt->fNDigit = ndigits[lrow];
566 time=fDigits->CurrentRow();
567 pad=fDigits->CurrentColumn();
568 dig = fDigits->GetDigit(time,pad);
569 if (dig <= fParam->GetZeroSup()) continue;
570 if(dig >= AliL3Transform::GetADCSat())
571 dig = AliL3Transform::GetADCSat();
573 //Exclude data outside cone:
574 AliL3Transform::Raw2Local(xyz,sector,row,pad,time);
575 if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2]))
576 continue; // why 230???
578 if(localcount >= ndigits[lrow])
579 LOG(AliL3Log::kFatal,"AliL3FileHandler::AliDigits2Binary","Memory")
580 <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits "
581 <<ndigits[lrow]<<ENDLOG;
583 tempPt->fDigitData[localcount].fCharge=dig;
584 tempPt->fDigitData[localcount].fPad=pad;
585 tempPt->fDigitData[localcount].fTime=time;
587 tempPt->fDigitData[localcount].fTrackID[0] = fDigits->GetTrackID(time,pad,0);
588 tempPt->fDigitData[localcount].fTrackID[1] = fDigits->GetTrackID(time,pad,1);
589 tempPt->fDigitData[localcount].fTrackID[2] = fDigits->GetTrackID(time,pad,2);
592 } while (fDigits->Next());
594 Byte_t *tmp = (Byte_t*)tempPt;
595 Int_t size = sizeof(AliL3DigitRowData)
596 + ndigits[lrow]*sizeof(AliL3DigitData);
598 tempPt = (AliL3DigitRowData*)tmp;
604 AliL3DigitRowData * AliL3FileHandler::AliAltroDigits2Memory(UInt_t & nrow,Int_t event,Bool_t eventmerge)
606 //Read data from AliROOT file into memory, and store it in the HLT data format.
607 //Returns a pointer to the data.
608 //This functions filter out single timebins, which is noise. The timebins which
609 //are removed are timebins which have the 4 zero neighbours;
610 //(pad-1,time),(pad+1,time),(pad,time-1),(pad,time+1).
612 AliL3DigitRowData *data = 0;
616 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliAltroDigits2Memory","File")
617 <<"No Input avalible: Pointer to TFile == NULL"<<ENDLOG;
621 if(!fInAli->IsOpen()){
622 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliAltroDigits2Memory","File")
623 <<"No Input avalible: TFile not opened"<<ENDLOG;
627 if(eventmerge == kTRUE && event >= 1024)
629 LOG(AliL3Log::kError,"AliL3FileHandler::AliAltroDigits2Memory","TrackIDs")
630 <<"Too many events if you want to merge!"<<ENDLOG;
636 /* Dont understand why we have to do
637 reload the tree, but otherwise the code crashes */
639 if(!GetDigitsTree(event)) return 0;
642 if(!GetDigitsTree(event)) return 0;
647 Int_t time,pad,sector,row;
650 Int_t entries = (Int_t)fDigitsTree->GetEntries();
652 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliAltroDigits2Memory","ndigits")
653 <<"No TPC digits (entries==0)!"<<ENDLOG;
654 nrow = (UInt_t)(fRowMax-fRowMin+1);
655 Int_t size = nrow*sizeof(AliL3DigitRowData);
656 data=(AliL3DigitRowData*) Allocate(size);
657 AliL3DigitRowData *tempPt = data;
658 for(Int_t r=fRowMin;r<=fRowMax;r++){
665 Int_t * ndigits = new Int_t[entries];
667 Int_t zerosupval=AliL3Transform::GetZeroSup();
670 for(Int_t r=fRowMin;r<=fRowMax;r++){
671 Int_t n=fIndex[fSlice][r];
675 if(n!=-1){//data on that row
676 fDigitsTree->GetEvent(n);
677 fParam->AdjustSectorRow(fDigits->GetID(),sector,row);
678 AliL3Transform::Sector2Slice(lslice,lrow,sector,row);
679 //cout << lslice << " " << fSlice << " " << lrow << " " << r << " " << sector << " " << row << endl;
680 if((lslice!=fSlice)||(lrow!=r)){
681 LOG(AliL3Log::kError,"AliL3FileHandler::AliAltroDigits2Memory","Row")
682 <<AliL3Log::kDec<<"Rows on slice " << fSlice << " dont match "<<lrow<<" "<<r<<ENDLOG;
686 fDigits->ExpandBuffer();
687 fDigits->ExpandTrackBuffer();
688 for(Int_t i=0; i<fDigits->GetNCols(); i++){
689 for(Int_t j=0; j<fDigits->GetNRows(); j++){
692 dig = fDigits->GetDigitFast(time,pad);
693 if(dig <= zerosupval) continue;
694 if(dig >= AliL3Transform::GetADCSat())
695 dig = AliL3Transform::GetADCSat();
697 //Check for single timebins, and remove them because they are noise for sure.
698 if(i>0 && i<fDigits->GetNCols()-1 && j>0 && j<fDigits->GetNRows()-1)
699 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
700 fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
701 fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
702 fDigits->GetDigitFast(time,pad+1)<=zerosupval)
708 if(j < fDigits->GetNRows()-1 && j > 0)
710 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
711 fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
712 fDigits->GetDigitFast(time,pad+1)<=zerosupval)
717 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
718 fDigits->GetDigitFast(time,pad+1)<=zerosupval)
724 if(i < fDigits->GetNCols()-1 && i > 0)
726 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
727 fDigits->GetDigitFast(time,pad+1)<=zerosupval &&
728 fDigits->GetDigitFast(time+1,pad)<=zerosupval)
733 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
734 fDigits->GetDigitFast(time+1,pad)<=zerosupval)
739 if(i==fDigits->GetNCols()-1)
741 if(j>0 && j<fDigits->GetNRows()-1)
743 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
744 fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
745 fDigits->GetDigitFast(time,pad-1)<=zerosupval)
748 else if(j==0 && j<fDigits->GetNRows()-1)
750 if(fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
751 fDigits->GetDigitFast(time,pad-1)<=zerosupval)
756 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
757 fDigits->GetDigitFast(time,pad-1)<=zerosupval)
762 if(j==fDigits->GetNRows()-1)
764 if(i>0 && i<fDigits->GetNCols()-1)
766 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
767 fDigits->GetDigitFast(time,pad+1)<=zerosupval &&
768 fDigits->GetDigitFast(time-1,pad)<=zerosupval)
771 else if(i==0 && fDigits->GetNCols()-1)
773 if(fDigits->GetDigitFast(time,pad+1)<=zerosupval &&
774 fDigits->GetDigitFast(time-1,pad)<=zerosupval)
779 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
780 fDigits->GetDigitFast(time-1,pad)<=zerosupval)
785 AliL3Transform::Raw2Local(xyz,sector,row,pad,time);
786 if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2]))
789 ndigits[lrow]++; //for this row only
790 ndigitcount++; //total number of digits to be published
797 Int_t size = sizeof(AliL3DigitData)*ndigitcount
798 + nrows*sizeof(AliL3DigitRowData);
800 LOG(AliL3Log::kDebug,"AliL3FileHandler::AliAltroDigits2Memory","Digits")
801 <<AliL3Log::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG;
803 data=(AliL3DigitRowData*) Allocate(size);
804 nrow = (UInt_t)nrows;
805 AliL3DigitRowData *tempPt = data;
807 for(Int_t r=fRowMin;r<=fRowMax;r++){
808 Int_t n=fIndex[fSlice][r];
811 if(n!=-1){ //no data on that row
812 fDigitsTree->GetEvent(n);
813 fParam->AdjustSectorRow(fDigits->GetID(),sector,row);
814 AliL3Transform::Sector2Slice(lslice,lrow,sector,row);
817 LOG(AliL3Log::kError,"AliL3FileHandler::AliAltroDigits2Memory","Row")
818 <<AliL3Log::kDec<<"Rows on slice " << fSlice << " dont match "<<lrow<<" "<<r<<ENDLOG;
822 tempPt->fNDigit = ndigits[lrow];
825 fDigits->ExpandBuffer();
826 fDigits->ExpandTrackBuffer();
827 for(Int_t i=0; i<fDigits->GetNCols(); i++){
828 for(Int_t j=0; j<fDigits->GetNRows(); j++){
831 dig = fDigits->GetDigitFast(time,pad);
832 if(dig <= zerosupval) continue;
833 if(dig >= AliL3Transform::GetADCSat())
834 dig = AliL3Transform::GetADCSat();
836 //Check for single timebins, and remove them because they are noise for sure.
837 if(i>0 && i<fDigits->GetNCols()-1 && j>0 && j<fDigits->GetNRows()-1)
838 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
839 fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
840 fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
841 fDigits->GetDigitFast(time,pad+1)<=zerosupval)
847 if(j < fDigits->GetNRows()-1 && j > 0)
849 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
850 fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
851 fDigits->GetDigitFast(time,pad+1)<=zerosupval)
856 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
857 fDigits->GetDigitFast(time,pad+1)<=zerosupval)
863 if(i < fDigits->GetNCols()-1 && i > 0)
865 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
866 fDigits->GetDigitFast(time,pad+1)<=zerosupval &&
867 fDigits->GetDigitFast(time+1,pad)<=zerosupval)
872 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
873 fDigits->GetDigitFast(time+1,pad)<=zerosupval)
878 if(i == fDigits->GetNCols()-1)
880 if(j>0 && j<fDigits->GetNRows()-1)
882 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
883 fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
884 fDigits->GetDigitFast(time,pad-1)<=zerosupval)
887 else if(j==0 && j<fDigits->GetNRows()-1)
889 if(fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
890 fDigits->GetDigitFast(time,pad-1)<=zerosupval)
895 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
896 fDigits->GetDigitFast(time,pad-1)<=zerosupval)
900 if(j==fDigits->GetNRows()-1)
902 if(i>0 && i<fDigits->GetNCols()-1)
904 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
905 fDigits->GetDigitFast(time,pad+1)<=zerosupval &&
906 fDigits->GetDigitFast(time-1,pad)<=zerosupval)
909 else if(i==0 && fDigits->GetNCols()-1)
911 if(fDigits->GetDigitFast(time,pad+1)<=zerosupval &&
912 fDigits->GetDigitFast(time-1,pad)<=zerosupval)
917 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
918 fDigits->GetDigitFast(time-1,pad)<=zerosupval)
923 AliL3Transform::Raw2Local(xyz,sector,row,pad,time);
924 if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2]))
927 if(localcount >= ndigits[lrow])
928 LOG(AliL3Log::kFatal,"AliL3FileHandler::AliAltroDigits2Binary","Memory")
929 <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits "
930 <<ndigits[lrow]<<ENDLOG;
932 tempPt->fDigitData[localcount].fCharge=dig;
933 tempPt->fDigitData[localcount].fPad=pad;
934 tempPt->fDigitData[localcount].fTime=time;
936 tempPt->fDigitData[localcount].fTrackID[0] = (fDigits->GetTrackIDFast(time,pad,0)-2);
937 tempPt->fDigitData[localcount].fTrackID[1] = (fDigits->GetTrackIDFast(time,pad,1)-2);
938 tempPt->fDigitData[localcount].fTrackID[2] = (fDigits->GetTrackIDFast(time,pad,2)-2);
939 if(eventmerge == kTRUE) //careful track mc info will be touched
940 {//Event are going to be merged, so event number is stored in the upper 10 bits.
941 tempPt->fDigitData[localcount].fTrackID[0] += 128; //leave some room
942 tempPt->fDigitData[localcount].fTrackID[1] += 128; //for neg. numbers
943 tempPt->fDigitData[localcount].fTrackID[2] += 128;
944 tempPt->fDigitData[localcount].fTrackID[0] += ((event&0x3ff)<<22);
945 tempPt->fDigitData[localcount].fTrackID[1] += ((event&0x3ff)<<22);
946 tempPt->fDigitData[localcount].fTrackID[2] += ((event&0x3ff)<<22);
953 Byte_t *tmp = (Byte_t*)tempPt;
954 Int_t size = sizeof(AliL3DigitRowData)
955 + ndigits[r]*sizeof(AliL3DigitData);
957 tempPt = (AliL3DigitRowData*)tmp;
963 Bool_t AliL3FileHandler::GetDigitsTree(Int_t event)
965 //Connects to the TPC digit tree in the AliROOT file.
967 AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader");
969 LOG(AliL3Log::kWarning,"AliL3FileHandler::GetDigitsTree","File")
970 <<"Pointer to AliLoader for TPC = 0x0 "<<ENDLOG;
973 fInAli->GetEvent(event);
974 tpcLoader->LoadDigits();
975 fDigitsTree = tpcLoader->TreeD();
979 sprintf(dname,"TreeD_%s_%d",AliL3Transform::GetParamName(),event);
980 fDigitsTree = (TTree*)fInAli->Get(dname);
984 LOG(AliL3Log::kError,"AliL3FileHandler::GetDigitsTree","Digits Tree")
985 <<AliL3Log::kHex<<"Error getting digitstree "<<(Int_t)fDigitsTree<<ENDLOG;
988 fDigitsTree->GetBranch("Segment")->SetAddress(&fDigits);
990 if(!fIndexCreated) return CreateIndex();
994 void AliL3FileHandler::AliDigits2RootFile(AliL3DigitRowData *rowPt,Char_t *new_digitsfile)
996 //Write the data stored in rowPt, into a new AliROOT file.
997 //The data is stored in the AliROOT format
998 //This is specially a nice thing if you have modified data, and wants to run it
999 //through the offline reconstruction chain.
1000 //The arguments is a pointer to the data, and the name of the new AliROOT file.
1001 //Remember to pass the original AliROOT file (the one that contains the original
1002 //simulated data) to this object, in order to retrieve the MC id's of the digits.
1006 LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2RootFile","File")
1007 <<"No rootfile "<<ENDLOG;
1012 LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2RootFile","File")
1013 <<"No parameter object. Run on rootfile "<<ENDLOG;
1018 //Get the original digitstree:
1019 AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader");
1021 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2RootFile","File")
1022 <<"Pointer to AliLoader for TPC = 0x0 "<<ENDLOG;
1025 tpcLoader->LoadDigits();
1026 TTree *t=tpcLoader->TreeD();
1028 AliTPCDigitsArray *old_array = new AliTPCDigitsArray();
1029 old_array->Setup(fParam);
1030 old_array->SetClass("AliSimDigits");
1032 Bool_t ok = old_array->ConnectTree(t);
1035 LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2RootFile","File")
1036 << "No digits tree object" << ENDLOG;
1040 tpcLoader->SetDigitsFileName(new_digitsfile);
1041 tpcLoader->MakeDigitsContainer();
1043 //setup a new one, or connect it to the existing one:
1044 AliTPCDigitsArray *arr = new AliTPCDigitsArray();
1045 arr->SetClass("AliSimDigits");
1047 arr->MakeTree(tpcLoader->TreeD());
1050 //Get the original digitstree:
1052 sprintf(dname,"TreeD_%s_0",AliL3Transform::GetParamName());
1055 AliTPCDigitsArray *old_array = new AliTPCDigitsArray();
1056 old_array->Setup(fParam);
1057 old_array->SetClass("AliSimDigits");
1059 Bool_t ok = old_array->ConnectTree(dname);
1062 LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2RootFile","File")
1063 <<"No digits tree object." <<ENDLOG;
1067 Bool_t create=kFALSE;
1070 if(gSystem->AccessPathName(new_digitsfile))
1072 LOG(AliL3Log::kInformational,"AliL3FileHandler::AliDigits2RootFile","File")
1073 <<"Creating new file "<<new_digitsfile<<ENDLOG;
1075 digFile = TFile::Open(new_digitsfile,"RECREATE");
1076 fParam->Write(fParam->GetTitle());
1081 digFile = TFile::Open(new_digitsfile,"UPDATE");
1084 if(!digFile->IsOpen())
1086 LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2RootFile","Rootfile")
1087 <<"Error opening rootfile "<<new_digitsfile<<ENDLOG;
1093 //setup a new one, or connect it to the existing one:
1094 AliTPCDigitsArray *arr = new AliTPCDigitsArray();
1095 arr->SetClass("AliSimDigits");
1101 Bool_t ok = arr->ConnectTree(dname);
1104 LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2RootFile","Rootfile")
1105 <<"No digits tree object in existing file"<<ENDLOG;
1111 Int_t digcounter=0,trackID[3];
1113 for(Int_t i=fRowMin; i<=fRowMax; i++)
1116 if((Int_t)rowPt->fRow != i)
1117 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2RootFile","Data")
1118 <<"Mismatching row numbering "<<(Int_t)rowPt->fRow<<" "<<i<<ENDLOG;
1121 AliL3Transform::Slice2Sector(fSlice,i,sector,row);
1123 AliSimDigits *old_dig = (AliSimDigits*)old_array->LoadRow(sector,row);
1124 AliSimDigits * dig = (AliSimDigits*)arr->CreateRow(sector,row);
1125 old_dig->ExpandBuffer();
1126 old_dig->ExpandTrackBuffer();
1127 dig->ExpandBuffer();
1128 dig->ExpandTrackBuffer();
1131 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2RootFile","Data")
1132 <<"No padrow " << sector << " " << row <<ENDLOG;
1134 AliL3DigitData *digPt = rowPt->fDigitData;
1136 for(UInt_t j=0; j<rowPt->fNDigit; j++)
1138 Short_t charge = (Short_t)digPt[j].fCharge;
1139 Int_t pad = (Int_t)digPt[j].fPad;
1140 Int_t time = (Int_t)digPt[j].fTime;
1142 if(charge == 0) //Only write the digits that has not been removed
1144 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2RootFile","Data")
1145 <<"Zero charge" <<ENDLOG;
1151 //Tricks to get and set the correct track id's.
1152 for(Int_t t=0; t<3; t++)
1154 Int_t label = old_dig->GetTrackIDFast(time,pad,t);
1156 trackID[t] = label - 2;
1163 dig->SetDigitFast(charge,time,pad);
1165 for(Int_t t=0; t<3; t++)
1166 ((AliSimDigits*)dig)->SetTrackIDFast(trackID[t],time,pad,t);
1169 //cout<<"Wrote "<<digcounter<<" on row "<<i<<endl;
1170 UpdateRowPointer(rowPt);
1171 arr->StoreRow(sector,row);
1172 arr->ClearRow(sector,row);
1173 old_array->ClearRow(sector,row);
1177 sprintf(treeName,"TreeD_%s_0",fParam->GetTitle());
1180 arr->GetTree()->SetName(treeName);
1181 arr->GetTree()->AutoSave();
1182 tpcLoader->WriteDigits("OVERWRITE");
1185 arr->GetTree()->SetName(treeName);
1186 arr->GetTree()->AutoSave();
1193 ///////////////////////////////////////// Point IO
1194 Bool_t AliL3FileHandler::AliPoints2Binary(Int_t eventn){
1197 AliL3SpacePointData *data = AliPoints2Memory(npoint,eventn);
1198 out = Memory2Binary(npoint,data);
1203 AliL3SpacePointData * AliL3FileHandler::AliPoints2Memory(UInt_t & npoint,Int_t eventn){
1204 AliL3SpacePointData *data = 0;
1207 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliPoints2Memory","File")
1208 <<"No Input avalible: no object fInAli"<<ENDLOG;
1212 if(!fInAli->IsOpen()){
1213 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliPoints2Memory","File")
1214 <<"No Input avalible: TFile not opend"<<ENDLOG;
1219 TDirectory *savedir = gDirectory;
1221 AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader");
1223 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliPoints2Memory","File")
1224 <<"Pointer to AliLoader for TPC = 0x0 "<<ENDLOG;
1227 fInAli->GetEvent(eventn);
1228 tpcLoader->LoadRecPoints();
1230 AliTPCClustersArray carray;
1231 carray.Setup(fParam);
1232 carray.SetClusterType("AliTPCcluster");
1233 Bool_t clusterok = carray.ConnectTree(tpcLoader->TreeR());
1238 sprintf(cname,"TreeC_TPC_%d",eventn);
1239 AliTPCClustersArray carray;
1240 carray.Setup(fParam);
1241 carray.SetClusterType("AliTPCcluster");
1242 Bool_t clusterok = carray.ConnectTree(cname);
1245 if(!clusterok) return 0;
1247 AliTPCClustersRow ** clusterrow =
1248 new AliTPCClustersRow*[ (int)carray.GetTree()->GetEntries()];
1249 Int_t *rows = new int[ (int)carray.GetTree()->GetEntries()];
1250 Int_t *sects = new int[ (int)carray.GetTree()->GetEntries()];
1254 for(Int_t i=0; i<carray.GetTree()->GetEntries(); i++){
1255 AliSegmentID *s = carray.LoadEntry(i);
1257 fParam->AdjustSectorRow(s->GetID(),sector,row);
1261 AliL3Transform::Sector2Slice(lslice,lrow,sector,row);
1262 if(fSlice != lslice || lrow<fRowMin || lrow>fRowMax) continue;
1263 clusterrow[i] = carray.GetRow(sector,row);
1265 sum+=clusterrow[i]->GetArray()->GetEntriesFast();
1267 UInt_t size = sum*sizeof(AliL3SpacePointData);
1269 LOG(AliL3Log::kDebug,"AliL3FileHandler::AliPoints2Memory","File")
1270 <<AliL3Log::kDec<<"Found "<<sum<<" SpacePoints"<<ENDLOG;
1272 data = (AliL3SpacePointData *) Allocate(size);
1278 for(Int_t i=0; i<carray.GetTree()->GetEntries(); i++){
1279 if(!clusterrow[i]) continue;
1280 Int_t row = rows[i];
1281 Int_t sector = sects[i];
1282 AliL3Transform::Sector2Slice(lslice,lrow,sector,row);
1283 Int_t entries_in_row = clusterrow[i]->GetArray()->GetEntriesFast();
1284 for(Int_t j = 0;j<entries_in_row;j++){
1285 AliTPCcluster *c = (AliTPCcluster*)(*clusterrow[i])[j];
1286 data[n].fZ = c->GetZ();
1287 data[n].fY = c->GetY();
1288 data[n].fX = fParam->GetPadRowRadii(sector,row);
1289 data[n].fCharge = (UInt_t)c->GetQ();
1290 data[n].fID = n+((fSlice&0x7f)<<25)+((pat&0x7)<<22);//uli
1291 data[n].fPadRow = lrow;
1292 data[n].fSigmaY2 = c->GetSigmaY2();
1293 data[n].fSigmaZ2 = c->GetSigmaZ2();
1295 data[n].fTrackID[0] = c->GetLabel(0);
1296 data[n].fTrackID[1] = c->GetLabel(1);
1297 data[n].fTrackID[2] = c->GetLabel(2);
1299 if(fMC) fprintf(fMC,"%d %d\n",data[n].fID,c->GetLabel(0));
1303 for(Int_t i=0;i<carray.GetTree()->GetEntries();i++){
1304 Int_t row = rows[i];
1305 Int_t sector = sects[i];
1306 if(carray.GetRow(sector,row))
1307 carray.ClearRow(sector,row);
1310 delete [] clusterrow;