2 //Author: Uli Frankenfeld
3 //Last Modified: 17.12.2000
12 #include "AliL3Transform.h"
13 #include "AliL3Logging.h"
14 #include "AliL3MemHandler.h"
15 #include "AliL3FileHandler.h"
17 #include "AliTPCClustersArray.h"
18 #include "AliTPCcluster.h"
19 #include "AliTPCClustersRow.h"
20 #include "AliTPCParam.h"
21 #include "AliSimDigits.h"
23 #include "AliL3DigitData.h"
24 #include "AliL3TrackSegmentData.h"
25 #include "AliL3SpacePointData.h"
26 #include "AliL3TrackArray.h"
27 //_____________________________________________________________
29 // The L3 Binary File handler
32 ClassImp(AliL3FileHandler)
34 AliL3FileHandler::AliL3FileHandler(){
43 AliL3FileHandler::~AliL3FileHandler(){
45 if(fTransformer) delete fTransformer;
46 if(fMC) CloseMCOutput();
49 Bool_t AliL3FileHandler::SetMCOutput(char *name){
50 fMC = fopen(name,"w");
52 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetMCOutput","File Open")
53 <<"Pointer to File = 0x0 "<<ENDLOG;
59 Bool_t AliL3FileHandler::SetMCOutput(FILE *file){
62 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetMCOutput","File Open")
63 <<"Pointer to File = 0x0 "<<ENDLOG;
69 void AliL3FileHandler::CloseMCOutput(){
71 LOG(AliL3Log::kWarning,"AliL3FileHandler::CloseMCOutPut","File Close")
72 <<"Nothing to Close"<<ENDLOG;
79 Bool_t AliL3FileHandler::SetAliInput(){
80 if(!fInAli->IsOpen()){
81 LOG(AliL3Log::kError,"AliL3FileHandler::SetAliInput","File Open")
82 <<"Ali File "<<fInAli->GetName()<<" does not exist"<<ENDLOG;
85 fParam = (AliTPCParam*)fInAli->Get("75x40_100x60");
87 LOG(AliL3Log::kError,"AliL3FileHandler::SetAliInput","File Open")
88 <<"No AliTPCParam 75x40_100x60 in File "<<fInAli->GetName()<<ENDLOG;
91 fTransformer = new AliL3Transform();
95 Bool_t AliL3FileHandler::SetAliInput(char *name){
96 fInAli= new TFile(name,"READ");
98 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File Open")
99 <<"Pointer to TFile = 0x0 "<<ENDLOG;
102 return SetAliInput();
105 Bool_t AliL3FileHandler::SetAliInput(TFile *file){
108 LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File Open")
109 <<"Pointer to TFile = 0x0 "<<ENDLOG;
112 return SetAliInput();
115 void AliL3FileHandler::CloseAliInput(){
117 LOG(AliL3Log::kWarning,"AliL3FileHandler::CloseAliInput","File Close")
118 <<"Nothing to Close"<<ENDLOG;
121 if(fInAli->IsOpen()) fInAli->Close();
126 Bool_t AliL3FileHandler::IsDigit(){
128 LOG(AliL3Log::kWarning,"AliL3FileHandler::IsDigit","File")
129 <<"Pointer to TFile = 0x0 "<<ENDLOG;
130 return kTRUE; //may you are use binary input which is Digits!!
132 TTree *t=(TTree*)fInAli->Get("TreeD_75x40_100x60");
134 LOG(AliL3Log::kInformational,"AliL3FileHandler::IsDigit","File Type")
135 <<"Found Digit Tree -> Use Fast Cluster Finder"<<ENDLOG;
139 LOG(AliL3Log::kInformational,"AliL3FileHandler::IsDigit","File Type")
140 <<"No Digit Tree -> Use Cluster Tree"<<ENDLOG;
145 ///////////////////////////////////////// Digit IO
146 Bool_t AliL3FileHandler::AliDigits2Binary(){
149 AliL3DigitRowData* data = AliDigits2Memory(nrow);
150 out = Memory2Binary(nrow,data);
156 Bool_t AliL3FileHandler::AliDigits2CompBinary(){
159 AliL3DigitRowData* digits = AliDigits2Memory(ndigits);
160 out = Memory2CompBinary(ndigits,digits);
166 AliL3DigitRowData * AliL3FileHandler::AliDigits2Memory(UInt_t & nrow){
167 AliL3DigitRowData *data = 0;
170 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2Memory","File")
171 <<"No Input avalible: no object TFile"<<ENDLOG;
174 if(!fInAli->IsOpen()){
175 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2Memory","File")
176 <<"No Input avalible: TFile not opend"<<ENDLOG;
180 TDirectory *savedir = gDirectory;
182 TTree *t=(TTree*)fInAli->Get("TreeD_75x40_100x60");
184 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2Binary","AliRoot")
185 <<"No Digit Tree inside!"<<ENDLOG;
188 AliSimDigits digarr, *dummy=&digarr;
189 t->GetBranch("Segment")->SetAddress(&dummy);
191 Int_t time,pad,sector,row;
194 Int_t entries = (Int_t)t->GetEntries();
195 Int_t ndigits[entries];
197 for(Int_t n=0; n<t->GetEntries(); n++)
200 fParam->AdjustSectorRow(digarr.GetID(),sector,row);
201 fTransformer->Sector2Slice(lslice,lrow,sector,row);
202 if(fSlice != lslice || lrow<fRowMin || lrow>fRowMax) continue;
203 // if(fSlice != lslice) continue;
209 time=digarr.CurrentRow();
210 pad=digarr.CurrentColumn();
211 dig = digarr.GetDigit(time,pad);
212 if(dig<=fParam->GetZeroSup()) continue;
213 if(time < fParam->GetMaxTBin()-1 && time > 0)
214 if(digarr.GetDigit(time+1,pad) <= fParam->GetZeroSup()
215 && digarr.GetDigit(time-1,pad) <= fParam->GetZeroSup())
218 fTransformer->Raw2Local(xyz,sector,row,pad,time);
219 if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2]))
222 ndigits[lrow]++; //for this row only
223 ndigitcount++; //total number of digits to be published
225 } while (digarr.Next());
229 Int_t size = sizeof(AliL3DigitData)*ndigitcount
230 + nrows*sizeof(AliL3DigitRowData);
232 LOG(AliL3Log::kDebug,"AliL3FileHandler::AliDigits2Memory","Digits")
233 <<AliL3Log::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG;
235 data=(AliL3DigitRowData*) Allocate(size);
236 nrow = (UInt_t)nrows;
237 AliL3DigitRowData *tempPt = data;
238 for(Int_t n=0; n<t->GetEntries(); n++)
243 fParam->AdjustSectorRow(digarr.GetID(),sector,row);
244 fTransformer->Sector2Slice(lslice,lrow,sector,row);
245 // if(fSlice != lslice) continue;
246 if(fSlice != lslice || lrow<fRowMin || lrow>fRowMax) continue;
248 tempPt->fNDigit = ndigits[lrow];
253 dig=digarr.CurrentDigit();
254 if (dig<=fParam->GetZeroSup()) continue;
255 time=digarr.CurrentRow();
256 pad=digarr.CurrentColumn();
257 if(time < fParam->GetMaxTBin()-1 && time > 0)
258 if(digarr.GetDigit(time-1,pad) <= fParam->GetZeroSup() &&
259 digarr.GetDigit(time+1,pad) <= fParam->GetZeroSup()) continue;
261 //Exclude data outside cone:
262 fTransformer->Raw2Local(xyz,sector,row,pad,time);
263 if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2]))
266 if(localcount >= ndigits[lrow])
267 LOG(AliL3Log::kFatal,"AliL3FileHandler::AliDigits2Binary","Memory")
268 <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits "
269 <<ndigits[lrow]<<ENDLOG;
271 tempPt->fDigitData[localcount].fCharge=dig;
272 tempPt->fDigitData[localcount].fPad=pad;
273 tempPt->fDigitData[localcount].fTime=time;
275 } while (digarr.Next());
277 Byte_t *tmp = (Byte_t*)tempPt;
278 Int_t size = sizeof(AliL3DigitRowData)
279 + ndigits[lrow]*sizeof(AliL3DigitData);
281 tempPt = (AliL3DigitRowData*)tmp;
287 ///////////////////////////////////////// Point IO
288 Bool_t AliL3FileHandler::AliPoints2Binary(){
291 AliL3SpacePointData *data = AliPoints2Memory(npoint);
292 out = Memory2Binary(npoint,data);
297 AliL3SpacePointData * AliL3FileHandler::AliPoints2Memory(UInt_t & npoint){
298 AliL3SpacePointData *data = 0;
301 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliPoints2Memory","File")
302 <<"No Input avalible: no object TFile"<<ENDLOG;
305 if(!fInAli->IsOpen()){
306 LOG(AliL3Log::kWarning,"AliL3FileHandler::AliPoints2Memory","File")
307 <<"No Input avalible: TFile not opend"<<ENDLOG;
310 TDirectory *savedir = gDirectory;
313 AliTPCClustersArray carray;
314 carray.Setup(fParam);
315 carray.SetClusterType("AliTPCcluster");
316 Bool_t clusterok = carray.ConnectTree("Segment Tree");
317 if(!clusterok) return 0;
319 AliTPCClustersRow ** clusterrow =
320 new AliTPCClustersRow*[ (int)carray.GetTree()->GetEntries()];
321 Int_t *rows = new int[ (int)carray.GetTree()->GetEntries()];
322 Int_t *sects = new int[ (int)carray.GetTree()->GetEntries()];
326 for(Int_t i=0; i<carray.GetTree()->GetEntries(); i++){
327 AliSegmentID *s = carray.LoadEntry(i);
329 fParam->AdjustSectorRow(s->GetID(),sector,row);
333 fTransformer->Sector2Slice(lslice,lrow,sector,row);
334 if(fSlice != lslice || lrow<fRowMin || lrow>fRowMax) continue;
335 clusterrow[i] = carray.GetRow(sector,row);
337 sum+=clusterrow[i]->GetArray()->GetEntriesFast();
339 UInt_t size = sum*sizeof(AliL3SpacePointData);
341 LOG(AliL3Log::kDebug,"AliL3FileHandler::AliPoints2Memory","File")
342 <<AliL3Log::kDec<<"Found "<<sum<<" SpacePoints"<<ENDLOG;
344 data = (AliL3SpacePointData *) Allocate(size);
347 for(Int_t i=0; i<carray.GetTree()->GetEntries(); i++){
348 if(!clusterrow[i]) continue;
350 Int_t sector = sects[i];
351 fTransformer->Sector2Slice(lslice,lrow,sector,row);
352 Int_t entries_in_row = clusterrow[i]->GetArray()->GetEntriesFast();
353 for(Int_t j = 0;j<entries_in_row;j++){
354 AliTPCcluster *c = (AliTPCcluster*)(*clusterrow[i])[j];
355 data[n].fZ = c->GetZ();
356 data[n].fY = c->GetY();
357 data[n].fX = fParam->GetPadRowRadii(sector,row);
358 data[n].fID = n+((fSlice&0x7f)<<25)+((fPatch&0x7)<<22);//uli
359 data[n].fPadRow = lrow;
360 data[n].fXYErr = c->GetSigmaY2();
361 data[n].fZErr = c->GetSigmaZ2();
362 if(fMC) fprintf(fMC,"%d %d\n",data[n].fID,c->GetLabel(0));
366 for(Int_t i=0;i<carray.GetTree()->GetEntries();i++){
368 Int_t sector = sects[i];
369 if(carray.GetRow(sector,row))
370 carray.ClearRow(sector,row);
373 delete [] clusterrow;