//$Id$ // Author: Uli Frankenfeld //*-- Copyright © Uli #include #include #include "AliL3Transform.h" #include "AliL3Logging.h" #include "AliL3MemHandler.h" #include "AliL3FileHandler.h" #include "AliTPCDigitsArray.h" #include "AliTPCClustersArray.h" #include "AliTPCcluster.h" #include "AliTPCClustersRow.h" #include "AliL3DigitData.h" #include "AliL3TrackSegmentData.h" #include "AliL3SpacePointData.h" #include "AliL3TrackArray.h" //_____________________________________________________________ // AliL3FileHandler // // The L3 Binary File handler // ClassImp(AliL3FileHandler) AliL3FileHandler::AliL3FileHandler(){ //Default constructor fInAli = 0; fParam = 0; fTransformer = 0; fMC =0; fLastIndex=0; fDigits=0; fDigitsTree=0; } AliL3FileHandler::~AliL3FileHandler(){ //Destructor if(fTransformer) delete fTransformer; if(fMC) CloseMCOutput(); if(fDigitsTree) delete fDigitsTree; if(fInAli) CloseAliInput(); } Bool_t AliL3FileHandler::SetMCOutput(char *name){ fMC = fopen(name,"w"); if(!fMC){ LOG(AliL3Log::kWarning,"AliL3FileHandler::SetMCOutput","File Open") <<"Pointer to File = 0x0 "<IsOpen()){ LOG(AliL3Log::kError,"AliL3FileHandler::SetAliInput","File Open") <<"Ali File "<GetName()<<" does not exist"<Get("75x40_100x60"); if(!fParam){ LOG(AliL3Log::kError,"AliL3FileHandler::SetAliInput","File Open") <<"No AliTPCParam 75x40_100x60 in File "<GetName()<IsOpen()) fInAli->Close(); delete fInAli; fInAli = 0; } Bool_t AliL3FileHandler::IsDigit(){ if(!fInAli){ LOG(AliL3Log::kWarning,"AliL3FileHandler::IsDigit","File") <<"Pointer to TFile = 0x0 "<Get("TreeD_75x40_100x60_0"); if(t){ LOG(AliL3Log::kInformational,"AliL3FileHandler::IsDigit","File Type") <<"Found Digit Tree -> Use Fast Cluster Finder"< Use Cluster Tree"<IsOpen()){ LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2Memory","File") <<"No Input avalible: TFile not opend"<GetEntries(); Int_t ndigits[entries]; Int_t lslice,lrow; for(Int_t n=fLastIndex; nGetEntries(); n++) { fDigitsTree->GetEvent(n); fParam->AdjustSectorRow(fDigits->GetID(),sector,row); fTransformer->Sector2Slice(lslice,lrow,sector,row); //if(fSlice != lslice || lrowfRowMax) continue; if(lslice < fSlice) continue; if(lslice != fSlice) break; if(lrow < fRowMin) continue; if(lrow > fRowMax) break; Float_t xyz[3]; ndigits[lrow] = 0; fDigits->First(); do { time=fDigits->CurrentRow(); pad=fDigits->CurrentColumn(); dig = fDigits->GetDigit(time,pad); if(dig<=fParam->GetZeroSup()) continue; if(time < fParam->GetMaxTBin()-1 && time > 0) if(fDigits->GetDigit(time+1,pad) <= fParam->GetZeroSup() && fDigits->GetDigit(time-1,pad) <= fParam->GetZeroSup()) continue; fTransformer->Raw2Local(xyz,sector,row,pad,time); if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2])) continue; ndigits[lrow]++; //for this row only ndigitcount++; //total number of digits to be published } while (fDigits->Next()); nrows++; } Int_t size = sizeof(AliL3DigitData)*ndigitcount + nrows*sizeof(AliL3DigitRowData); LOG(AliL3Log::kDebug,"AliL3FileHandler::AliDigits2Memory","Digits") <GetEntries(); n++) { fDigitsTree->GetEvent(n); Float_t xyz[3]; fParam->AdjustSectorRow(fDigits->GetID(),sector,row); fTransformer->Sector2Slice(lslice,lrow,sector,row); //if(fSlice != lslice || lrowfRowMax) continue; if(lslice < fSlice) continue; if(lslice != fSlice) break; if(lrow < fRowMin) continue; if(lrow > fRowMax) break; tempPt->fRow = lrow; tempPt->fNDigit = ndigits[lrow]; Int_t localcount=0; fDigits->First(); do { //dig=fDigits->CurrentDigit(); //if (dig<=fParam->GetZeroSup()) continue; time=fDigits->CurrentRow(); pad=fDigits->CurrentColumn(); dig = fDigits->GetDigit(time,pad); if (dig <= fParam->GetZeroSup()) continue; if(time < fParam->GetMaxTBin()-1 && time > 0) if(fDigits->GetDigit(time-1,pad) <= fParam->GetZeroSup() && fDigits->GetDigit(time+1,pad) <= fParam->GetZeroSup()) continue; //Exclude data outside cone: fTransformer->Raw2Local(xyz,sector,row,pad,time); if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2])) continue; if(localcount >= ndigits[lrow]) LOG(AliL3Log::kFatal,"AliL3FileHandler::AliDigits2Binary","Memory") <fDigitData[localcount].fCharge=dig; tempPt->fDigitData[localcount].fPad=pad; tempPt->fDigitData[localcount].fTime=time; #ifdef do_mc tempPt->fDigitData[localcount].fTrackID[0] = fDigits->GetTrackID(time,pad,0); tempPt->fDigitData[localcount].fTrackID[1] = fDigits->GetTrackID(time,pad,1); tempPt->fDigitData[localcount].fTrackID[2] = fDigits->GetTrackID(time,pad,2); #endif localcount++; } while (fDigits->Next()); Byte_t *tmp = (Byte_t*)tempPt; Int_t size = sizeof(AliL3DigitRowData) + ndigits[lrow]*sizeof(AliL3DigitData); tmp += size; tempPt = (AliL3DigitRowData*)tmp; //fLastIndex=n; } //fLastIndex++; return data; } Bool_t AliL3FileHandler::GetDigitsTree(Int_t event) { fInAli->cd(); Char_t dname[100]; sprintf(dname,"TreeD_75x40_100x60_%d",event); fDigitsTree = (TTree*)fInAli->Get("TreeD_75x40_100x60_0"); if(!fDigitsTree) { LOG(AliL3Log::kError,"AliL3FileHandler::GetDigitsTree","Digits Tree") <GetBranch("Segment")->SetAddress(&fDigits); return kTRUE; } void AliL3FileHandler::AliDigits2RootFile(AliL3DigitRowData *rowPt,Char_t *new_digitsfile) { //Write digits to a new alirootfile. if(!fInAli) { printf("AliL3FileHandler::AliDigits2RootFile : No rootfile\n"); return; } if(!fParam) { printf("AliL3FileHandler::AliDigits2RootFile : No parameter object. Run on rootfile\n"); return; } if(!fTransformer) { printf("AliL3FileHandler::AliDigits2RootFile : No transform object\n"); return; } //Get the original digitstree: fInAli->cd(); AliTPCDigitsArray *old_array = new AliTPCDigitsArray(); old_array->Setup(fParam); old_array->SetClass("AliSimDigits"); Bool_t ok = old_array->ConnectTree("TreeD_75x40_100x60_0"); if(!ok) { printf("AliL3FileHandler::AliDigits2RootFile : No digits tree object\n"); return; } Bool_t create=kFALSE; TFile *digFile; digFile = TFile::Open(new_digitsfile,"NEW"); if(digFile->IsOpen()) { create = kTRUE; fParam->Write(fParam->GetTitle()); } else { LOG(AliL3Log::kDebug,"AliL3FileHandler::AliDigits2RootFile","Rootfile") <<"Rootfile did already exist, so I will just open it for updates"<IsOpen()) { LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2RootFile","Rootfile") <<"Error opening rootfile "<cd(); //setup a new one, or connect it to the existing one: AliTPCDigitsArray *arr = new AliTPCDigitsArray; arr->SetClass("AliSimDigits"); arr->Setup(fParam); if(create) arr->MakeTree(); else { Bool_t ok = arr->ConnectTree("TreeD_75x40_100x60_0"); if(!ok) { printf("AliL3FileHandler::AliDigits2RootFile : No digits tree object in existing file\n"); return; } } Int_t digcounter=0; for(Int_t i=fRowMin; i<=fRowMax; i++) { if((Int_t)rowPt->fRow != i) printf("AliL3FileHandler::AliDigits2RootFile : Mismatching row numbering!!!\n"); Int_t sector,row; fTransformer->Slice2Sector(fSlice,i,sector,row); AliSimDigits * dig = (AliSimDigits*)arr->CreateRow(sector,row); AliSimDigits *old_dig = (AliSimDigits*)old_array->LoadRow(sector,row); if(!old_dig) printf("AliL3FileHandler::AliDigits2RootFile : No padrow %d %d\n",sector,row); AliL3DigitData *digPt = rowPt->fDigitData; digcounter=0; for(UInt_t j=0; jfNDigit; j++) { Int_t charge = (Int_t)digPt[j].fCharge; Int_t pad = (Int_t)digPt[j].fPad; Int_t time = (Int_t)digPt[j].fTime; if(charge == 0) //Only write the digits that has not been removed continue; digcounter++; dig->SetDigitFast(charge,time,pad); Int_t trackID[3] = {old_dig->GetTrackID(time,pad,0),old_dig->GetTrackID(time,pad,1),old_dig->GetTrackID(time,pad,2)}; Int_t s_pad = pad; Int_t s_time = time - 1; while(trackID[0] < 0) { if(s_time >= 0 && s_time < fTransformer->GetNTimeBins() && s_pad >= 0 && s_pad < fTransformer->GetNPads(i)) { if(old_dig->GetTrackID(s_time,s_pad,0) > 0) { trackID[0]=old_dig->GetTrackID(s_time,s_pad,0); trackID[1]=old_dig->GetTrackID(s_time,s_pad,1); trackID[2]=old_dig->GetTrackID(s_time,s_pad,2); } } if(s_pad == pad && s_time == time - 1) s_time = time + 1; else if(s_pad == pad && s_time == time + 1) {s_pad = pad - 1; s_time = time;} else if(s_pad == pad - 1 && s_time == time) s_time = time - 1; else if(s_pad == pad - 1 && s_time == time - 1) s_time = time + 1; else if(s_pad == pad - 1 && s_time == time + 1) {s_pad = pad + 1; s_time = time;} else if(s_pad == pad + 1 && s_time == time) s_time = time - 1; else if(s_pad == pad + 1 && s_time == time - 1) s_time = time + 1; else break; } dig->SetTrackIDFast(trackID[0],time,pad,0); dig->SetTrackIDFast(trackID[1],time,pad,1); dig->SetTrackIDFast(trackID[2],time,pad,2); } //cout<<"Wrote "<StoreRow(sector,row); arr->ClearRow(sector,row); old_array->ClearRow(sector,row); } digFile->cd(); char treeName[100]; sprintf(treeName,"TreeD_%s_0",fParam->GetTitle()); printf("Writing tree to file....."); arr->GetTree()->Write(treeName,TObject::kOverwrite); printf("done\n"); digFile->Close(); //arr->GetTree()->Delete(); //delete arr; } ///////////////////////////////////////// Point IO Bool_t AliL3FileHandler::AliPoints2Binary(){ Bool_t out = kTRUE; UInt_t npoint; AliL3SpacePointData *data = AliPoints2Memory(npoint); out = Memory2Binary(npoint,data); Free(); return out; } AliL3SpacePointData * AliL3FileHandler::AliPoints2Memory(UInt_t & npoint){ AliL3SpacePointData *data = 0; npoint=0; if(!fInAli){ LOG(AliL3Log::kWarning,"AliL3FileHandler::AliPoints2Memory","File") <<"No Input avalible: no object TFile"<IsOpen()){ LOG(AliL3Log::kWarning,"AliL3FileHandler::AliPoints2Memory","File") <<"No Input avalible: TFile not opend"<cd(); Char_t cname[100]; Int_t eventn = 0; sprintf(cname,"TreeC_TPC_%d",eventn); AliTPCClustersArray carray; carray.Setup(fParam); carray.SetClusterType("AliTPCcluster"); Bool_t clusterok = carray.ConnectTree(cname); if(!clusterok) return 0; AliTPCClustersRow ** clusterrow = new AliTPCClustersRow*[ (int)carray.GetTree()->GetEntries()]; Int_t *rows = new int[ (int)carray.GetTree()->GetEntries()]; Int_t *sects = new int[ (int)carray.GetTree()->GetEntries()]; Int_t sum=0; Int_t lslice,lrow; for(Int_t i=0; iGetEntries(); i++){ AliSegmentID *s = carray.LoadEntry(i); Int_t sector,row; fParam->AdjustSectorRow(s->GetID(),sector,row); rows[i] = row; sects[i] = sector; clusterrow[i] = 0; fTransformer->Sector2Slice(lslice,lrow,sector,row); if(fSlice != lslice || lrowfRowMax) continue; clusterrow[i] = carray.GetRow(sector,row); if(clusterrow[i]) sum+=clusterrow[i]->GetArray()->GetEntriesFast(); } UInt_t size = sum*sizeof(AliL3SpacePointData); LOG(AliL3Log::kDebug,"AliL3FileHandler::AliPoints2Memory","File") <GetEntries(); i++){ if(!clusterrow[i]) continue; Int_t row = rows[i]; Int_t sector = sects[i]; fTransformer->Sector2Slice(lslice,lrow,sector,row); Int_t entries_in_row = clusterrow[i]->GetArray()->GetEntriesFast(); for(Int_t j = 0;jGetZ(); data[n].fY = c->GetY(); data[n].fX = fParam->GetPadRowRadii(sector,row); data[n].fID = n+((fSlice&0x7f)<<25)+((fPatch&0x7)<<22);//uli data[n].fPadRow = lrow; data[n].fXYErr = c->GetSigmaY2(); data[n].fZErr = c->GetSigmaZ2(); if(fMC) fprintf(fMC,"%d %d\n",data[n].fID,c->GetLabel(0)); n++; } } for(Int_t i=0;iGetEntries();i++){ Int_t row = rows[i]; Int_t sector = sects[i]; if(carray.GetRow(sector,row)) carray.ClearRow(sector,row); } delete [] clusterrow; delete [] rows; delete [] sects; savedir->cd(); return data; }