2 //Author: Uli Frankenfeld
3 //Last Modified: 17.12.2000
11 #include "AliL3Transform.h"
12 #include "AliL3Logging.h"
13 #include "AliL3MemHandler.h"
14 #include "AliL3FileHandler.h"
16 #include "AliTPCClustersArray.h"
17 #include "AliTPCcluster.h"
18 #include "AliTPCClustersRow.h"
19 #include "AliTPCParam.h"
20 #include "AliSimDigits.h"
22 #include "AliL3DigitData.h"
23 #include "AliL3TrackSegmentData.h"
24 #include "AliL3SpacePointData.h"
25 #include "AliL3TrackArray.h"
26 //_____________________________________________________________
28 // The L3 Binary File handler
31 ClassImp(AliL3FileHandler)
33 AliL3FileHandler::AliL3FileHandler(){
42 AliL3FileHandler::~AliL3FileHandler(){
44 if(fTransformer) delete fTransformer;
45 if(fMC) CloseMCOutput();
48 Bool_t AliL3FileHandler::SetMCOutput(char *name){
49 fMC = fopen(name,"w");
51 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetMCOutput","File Open")
52 <<"Pointer to File = 0x0 "<<ENDLOG;
58 Bool_t AliL3FileHandler::SetMCOutput(FILE *file){
61 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetMCOutput","File Open")
62 <<"Pointer to File = 0x0 "<<ENDLOG;
68 void AliL3FileHandler::CloseMCOutput(){
70 LOG(AliL3Log::kWarning,"AliL3FileHandler::CloseMCOutPut","File Close")
71 <<"Nothing to Close"<<ENDLOG;
78 Bool_t AliL3FileHandler::SetAliInput(){
79 if(!fInAli->IsOpen()){
80 LOG(AliL3Log::kError,"AliL3FileHandler::SetAliInput","File Open")
81 <<"Ali File "<<fInAli->GetName()<<" does not exist"<<ENDLOG;
84 fParam = (AliTPCParam*)fInAli->Get("75x40_100x60");
86 LOG(AliL3Log::kError,"AliL3FileHandler::SetAliInput","File Open")
87 <<"No AliTPCParam 75x40_100x60 in File "<<fInAli->GetName()<<ENDLOG;
90 fTransformer = new AliL3Transform();
94 Bool_t AliL3FileHandler::SetAliInput(char *name){
95 fInAli= new TFile(name,"READ");
97 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File Open")
98 <<"Pointer to TFile = 0x0 "<<ENDLOG;
101 return SetAliInput();
104 Bool_t AliL3FileHandler::SetAliInput(TFile *file){
107 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File Open")
108 <<"Pointer to TFile = 0x0 "<<ENDLOG;
111 return SetAliInput();
114 void AliL3FileHandler::CloseAliInput(){
116 LOG(AliL3Log::kWarning,"AliL3FileHandler::CloseAliInput","File Close")
117 <<"Nothing to Close"<<ENDLOG;
120 if(fInAli->IsOpen()) fInAli->Close();
125 Bool_t AliL3FileHandler::IsDigit(){
127 LOG(AliL3Log::kWarning,"AliL3FileHandler::IsDigit","File")
128 <<"Pointer to TFile = 0x0 "<<ENDLOG;
129 return kTRUE; //may you are use binary input which is Digits!!
131 TTree *t=(TTree*)fInAli->Get("TreeD_75x40_100x60");
133 LOG(AliL3Log::kInformational,"AliL3FileHandler::IsDigit","File Type")
134 <<"Found Digit Tree -> Use Fast Cluster Finder"<<ENDLOG;
138 LOG(AliL3Log::kInformational,"AliL3FileHandler::IsDigit","File Type")
139 <<"No Digit Tree -> Use Cluster Tree"<<ENDLOG;
144 ///////////////////////////////////////// Digit IO
145 Bool_t AliL3FileHandler::AliDigits2Binary(){
148 AliL3DigitRowData* data = AliDigits2Memory(nrow);
149 out = Memory2Binary(nrow,data);
155 Bool_t AliL3FileHandler::AliDigits2CompBinary(){
158 AliL3DigitRowData* digits = AliDigits2Memory(ndigits);
159 out = Memory2CompBinary(ndigits,digits);
165 AliL3DigitRowData * AliL3FileHandler::AliDigits2Memory(UInt_t & nrow){
166 AliL3DigitRowData *data = 0;
169 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2Memory","File")
170 <<"No Input avalible: no object TFile"<<ENDLOG;
173 if(!fInAli->IsOpen()){
174 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2Memory","File")
175 <<"No Input avalible: TFile not opend"<<ENDLOG;
179 TDirectory *savedir = gDirectory;
181 TTree *t=(TTree*)fInAli->Get("TreeD_75x40_100x60");
183 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2Binary","AliRoot")
184 <<"No Digit Tree inside!"<<ENDLOG;
187 AliSimDigits digarr, *dummy=&digarr;
188 t->GetBranch("Segment")->SetAddress(&dummy);
190 Int_t time,pad,sector,row;
193 Int_t entries = (Int_t)t->GetEntries();
194 Int_t ndigits[entries];
196 for(Int_t n=0; n<t->GetEntries(); n++)
199 fParam->AdjustSectorRow(digarr.GetID(),sector,row);
200 fTransformer->Sector2Slice(lslice,lrow,sector,row);
201 if(fSlice != lslice || lrow<fRowMin || lrow>fRowMax) continue;
202 // if(fSlice != lslice) continue;
208 time=digarr.CurrentRow();
209 pad=digarr.CurrentColumn();
210 dig = digarr.GetDigit(time,pad);
211 if(dig<=fParam->GetZeroSup()) continue;
212 if(time < fParam->GetMaxTBin()-1 && time > 0)
213 if(digarr.GetDigit(time+1,pad) <= fParam->GetZeroSup()
214 && digarr.GetDigit(time-1,pad) <= fParam->GetZeroSup())
217 fTransformer->Raw2Local(xyz,sector,row,pad,time);
218 if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2]))
221 ndigits[lrow]++; //for this row only
222 ndigitcount++; //total number of digits to be published
224 } while (digarr.Next());
228 Int_t size = sizeof(AliL3DigitData)*ndigitcount
229 + nrows*sizeof(AliL3DigitRowData);
231 LOG(AliL3Log::kDebug,"AliL3FileHandler::AliDigits2Memory","Digits")
232 <<AliL3Log::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG;
234 data=(AliL3DigitRowData*) Allocate(size);
235 nrow = (UInt_t)nrows;
236 AliL3DigitRowData *tempPt = data;
237 for(Int_t n=0; n<t->GetEntries(); n++)
242 fParam->AdjustSectorRow(digarr.GetID(),sector,row);
243 fTransformer->Sector2Slice(lslice,lrow,sector,row);
244 // if(fSlice != lslice) continue;
245 if(fSlice != lslice || lrow<fRowMin || lrow>fRowMax) continue;
247 tempPt->fNDigit = ndigits[lrow];
252 dig=digarr.CurrentDigit();
253 if (dig<=fParam->GetZeroSup()) continue;
254 time=digarr.CurrentRow();
255 pad=digarr.CurrentColumn();
256 if(time < fParam->GetMaxTBin()-1 && time > 0)
257 if(digarr.GetDigit(time-1,pad) <= fParam->GetZeroSup() &&
258 digarr.GetDigit(time+1,pad) <= fParam->GetZeroSup()) continue;
260 //Exclude data outside cone:
261 fTransformer->Raw2Local(xyz,sector,row,pad,time);
262 if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2]))
265 if(localcount >= ndigits[lrow])
266 LOG(AliL3Log::kFatal,"AliL3FileHandler::AliDigits2Binary","Memory")
267 <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits "
268 <<ndigits[lrow]<<ENDLOG;
270 tempPt->fDigitData[localcount].fCharge=dig;
271 tempPt->fDigitData[localcount].fPad=pad;
272 tempPt->fDigitData[localcount].fTime=time;
274 } while (digarr.Next());
276 Byte_t *tmp = (Byte_t*)tempPt;
277 Int_t size = sizeof(AliL3DigitRowData)
278 + ndigits[lrow]*sizeof(AliL3DigitData);
280 tempPt = (AliL3DigitRowData*)tmp;
286 ///////////////////////////////////////// Point IO
287 Bool_t AliL3FileHandler::AliPoints2Binary(){
290 AliL3SpacePointData *data = AliPoints2Memory(npoint);
291 out = Memory2Binary(npoint,data);
296 AliL3SpacePointData * AliL3FileHandler::AliPoints2Memory(UInt_t & npoint){
297 AliL3SpacePointData *data = 0;
300 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliPoints2Memory","File")
301 <<"No Input avalible: no object TFile"<<ENDLOG;
304 if(!fInAli->IsOpen()){
305 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliPoints2Memory","File")
306 <<"No Input avalible: TFile not opend"<<ENDLOG;
309 TDirectory *savedir = gDirectory;
312 AliTPCClustersArray carray;
313 carray.Setup(fParam);
314 carray.SetClusterType("AliTPCcluster");
315 Bool_t clusterok = carray.ConnectTree("Segment Tree");
316 if(!clusterok) return 0;
318 AliTPCClustersRow ** clusterrow =
319 new AliTPCClustersRow*[ (int)carray.GetTree()->GetEntries()];
320 Int_t *rows = new int[ (int)carray.GetTree()->GetEntries()];
321 Int_t *sects = new int[ (int)carray.GetTree()->GetEntries()];
325 for(Int_t i=0; i<carray.GetTree()->GetEntries(); i++){
326 AliSegmentID *s = carray.LoadEntry(i);
328 fParam->AdjustSectorRow(s->GetID(),sector,row);
332 fTransformer->Sector2Slice(lslice,lrow,sector,row);
333 if(fSlice != lslice || lrow<fRowMin || lrow>fRowMax) continue;
334 clusterrow[i] = carray.GetRow(sector,row);
336 sum+=clusterrow[i]->GetArray()->GetEntriesFast();
338 UInt_t size = sum*sizeof(AliL3SpacePointData);
340 LOG(AliL3Log::kDebug,"AliL3FileHandler::AliPoints2Memory","File")
341 <<AliL3Log::kDec<<"Found "<<sum<<" SpacePoints"<<ENDLOG;
343 data = (AliL3SpacePointData *) Allocate(size);
346 for(Int_t i=0; i<carray.GetTree()->GetEntries(); i++){
347 if(!clusterrow[i]) continue;
349 Int_t sector = sects[i];
350 fTransformer->Sector2Slice(lslice,lrow,sector,row);
351 Int_t entries_in_row = clusterrow[i]->GetArray()->GetEntriesFast();
352 for(Int_t j = 0;j<entries_in_row;j++){
353 AliTPCcluster *c = (AliTPCcluster*)(*clusterrow[i])[j];
354 data[n].fZ = c->GetZ();
355 data[n].fY = c->GetY();
356 data[n].fX = fParam->GetPadRowRadii(sector,row);
357 data[n].fID = n+((fSlice&0x7f)<<25)+((fPatch&0x7)<<22);//uli
358 data[n].fPadRow = lrow;
359 data[n].fXYErr = c->GetSigmaY2();
360 data[n].fZErr = c->GetSigmaZ2();
361 if(fMC) fprintf(fMC,"%d %d\n",data[n].fID,c->GetLabel(0));
365 for(Int_t i=0;i<carray.GetTree()->GetEntries();i++){
367 Int_t sector = sects[i];
368 if(carray.GetRow(sector,row))
369 carray.ClearRow(sector,row);
372 delete [] clusterrow;