31d9405a |
1 | //$Id$ |
2 | |
5d2d32e3 |
3 | // Author: Uli Frankenfeld <mailto:franken@fi.uib.no>, Anders Vestbo <mailto:vestbo$fi.uib.no> |
b661165c |
4 | //*-- Copyright © Uli |
108615fc |
5 | |
6 | #include <math.h> |
7 | #include <iostream.h> |
108615fc |
8 | |
9 | #include "AliL3Transform.h" |
10 | #include "AliL3Logging.h" |
11 | #include "AliL3MemHandler.h" |
12 | #include "AliL3FileHandler.h" |
13 | |
0d319e67 |
14 | #include "AliTPCDigitsArray.h" |
108615fc |
15 | #include "AliTPCClustersArray.h" |
16 | #include "AliTPCcluster.h" |
17 | #include "AliTPCClustersRow.h" |
108615fc |
18 | |
19 | #include "AliL3DigitData.h" |
20 | #include "AliL3TrackSegmentData.h" |
21 | #include "AliL3SpacePointData.h" |
22 | #include "AliL3TrackArray.h" |
b661165c |
23 | |
108615fc |
24 | //_____________________________________________________________ |
b661165c |
25 | // AliL3FileHandler |
108615fc |
26 | // |
9183aa27 |
27 | // The HLT ROOT <-> binary files handling class |
108615fc |
28 | // |
9183aa27 |
29 | // This class provides the interface between AliROOT files, |
30 | // and HLT binary files. It should be used for converting |
31 | // TPC data stored in AliROOT format (outputfile from a simulation), |
32 | // into the data format currently used by in the HLT framework. |
33 | // This enables the possibility to always use the same data format, |
34 | // whether you are using a binary file as an input, or a AliROOT file. |
35 | // |
36 | // For example on how to create binary files from a AliROOT simulation, |
37 | // see example macro exa/Binary.C. |
38 | // |
39 | // For reading a AliROOT file into HLT format in memory, do the following: |
40 | // |
41 | // AliL3FileHandler file; |
42 | // file.SetAliInput("galice.root"); |
43 | // AliL3DigitRowData *dataPt = (AliL3DigitRowData*)file.AliDigits2Memory(nrows,eventnr); |
44 | // |
45 | // All the data are then stored in memory and accessible via the pointer dataPt. |
46 | // Accesing the data is then identical to the example 1) showed in AliL3MemHandler class. |
47 | // |
48 | // For converting the data back, and writing it to a new AliROOT file do: |
49 | // |
50 | // AliL3FileHandler file; |
51 | // file.SetAliInput("galice.root"); |
52 | // file.Init(slice,patch,NumberOfRowsInPatch); |
53 | // file.AliDigits2RootFile(dataPt,"new_galice.root"); |
54 | // file.CloseAliInput(); |
108615fc |
55 | |
56 | ClassImp(AliL3FileHandler) |
57 | |
9183aa27 |
58 | AliL3FileHandler::AliL3FileHandler() |
59 | { |
108615fc |
60 | //Default constructor |
61 | fInAli = 0; |
62 | fParam = 0; |
108615fc |
63 | fMC =0; |
a6e4f9d6 |
64 | fLastIndex=0; |
65 | fDigits=0; |
66 | fDigitsTree=0; |
108615fc |
67 | } |
68 | |
9183aa27 |
69 | AliL3FileHandler::~AliL3FileHandler() |
70 | { |
108615fc |
71 | //Destructor |
108615fc |
72 | if(fMC) CloseMCOutput(); |
a6e4f9d6 |
73 | if(fDigitsTree) delete fDigitsTree; |
8f1a9904 |
74 | if(fInAli) CloseAliInput(); |
a6e4f9d6 |
75 | |
108615fc |
76 | } |
77 | |
9183aa27 |
78 | Bool_t AliL3FileHandler::SetMCOutput(char *name) |
79 | { |
108615fc |
80 | fMC = fopen(name,"w"); |
81 | if(!fMC){ |
82 | LOG(AliL3Log::kWarning,"AliL3FileHandler::SetMCOutput","File Open") |
9183aa27 |
83 | <<"Pointer to File = 0x0 "<<ENDLOG; |
108615fc |
84 | return kFALSE; |
85 | } |
86 | return kTRUE; |
87 | } |
88 | |
9183aa27 |
89 | Bool_t AliL3FileHandler::SetMCOutput(FILE *file) |
90 | { |
108615fc |
91 | fMC = file; |
92 | if(!fMC){ |
93 | LOG(AliL3Log::kWarning,"AliL3FileHandler::SetMCOutput","File Open") |
9183aa27 |
94 | <<"Pointer to File = 0x0 "<<ENDLOG; |
108615fc |
95 | return kFALSE; |
96 | } |
97 | return kTRUE; |
98 | } |
99 | |
9183aa27 |
100 | void AliL3FileHandler::CloseMCOutput() |
101 | { |
108615fc |
102 | if(!fMC){ |
103 | LOG(AliL3Log::kWarning,"AliL3FileHandler::CloseMCOutPut","File Close") |
9183aa27 |
104 | <<"Nothing to Close"<<ENDLOG; |
108615fc |
105 | return; |
106 | } |
107 | fclose(fMC); |
108 | fMC =0; |
109 | } |
110 | |
9183aa27 |
111 | Bool_t AliL3FileHandler::SetAliInput() |
112 | { |
108615fc |
113 | if(!fInAli->IsOpen()){ |
114 | LOG(AliL3Log::kError,"AliL3FileHandler::SetAliInput","File Open") |
9183aa27 |
115 | <<"Ali File "<<fInAli->GetName()<<" does not exist"<<ENDLOG; |
108615fc |
116 | return kFALSE; |
117 | } |
118 | fParam = (AliTPCParam*)fInAli->Get("75x40_100x60"); |
119 | if(!fParam){ |
120 | LOG(AliL3Log::kError,"AliL3FileHandler::SetAliInput","File Open") |
9183aa27 |
121 | <<"No AliTPCParam 75x40_100x60 in File "<<fInAli->GetName()<<ENDLOG; |
122 | return kFALSE; |
108615fc |
123 | } |
108615fc |
124 | return kTRUE; |
125 | } |
126 | |
9183aa27 |
127 | Bool_t AliL3FileHandler::SetAliInput(char *name) |
128 | { |
129 | //Open the AliROOT file with name. |
130 | |
108615fc |
131 | fInAli= new TFile(name,"READ"); |
132 | if(!fInAli){ |
133 | LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File Open") |
134 | <<"Pointer to TFile = 0x0 "<<ENDLOG; |
135 | return kFALSE; |
136 | } |
137 | return SetAliInput(); |
138 | } |
139 | |
9183aa27 |
140 | Bool_t AliL3FileHandler::SetAliInput(TFile *file) |
141 | { |
142 | //Specify already opened AliROOT file to use as an input. |
143 | |
108615fc |
144 | fInAli=file; |
145 | if(!fInAli){ |
146 | LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File Open") |
147 | <<"Pointer to TFile = 0x0 "<<ENDLOG; |
148 | return kFALSE; |
149 | } |
150 | return SetAliInput(); |
151 | } |
152 | |
9183aa27 |
153 | void AliL3FileHandler::CloseAliInput() |
154 | { |
108615fc |
155 | if(!fInAli){ |
156 | LOG(AliL3Log::kWarning,"AliL3FileHandler::CloseAliInput","File Close") |
9183aa27 |
157 | <<"Nothing to Close"<<ENDLOG; |
158 | return; |
108615fc |
159 | } |
160 | if(fInAli->IsOpen()) fInAli->Close(); |
161 | delete fInAli; |
162 | fInAli = 0; |
9183aa27 |
163 | |
108615fc |
164 | } |
165 | |
9183aa27 |
166 | Bool_t AliL3FileHandler::IsDigit() |
167 | { |
168 | //Check if there is a TPC digit tree in the current file. |
169 | //Return kTRUE if tree was found, and kFALSE if not found. |
170 | |
108615fc |
171 | if(!fInAli){ |
172 | LOG(AliL3Log::kWarning,"AliL3FileHandler::IsDigit","File") |
173 | <<"Pointer to TFile = 0x0 "<<ENDLOG; |
174 | return kTRUE; //may you are use binary input which is Digits!! |
175 | } |
03b6adf7 |
176 | TTree *t=(TTree*)fInAli->Get("TreeD_75x40_100x60_0"); |
108615fc |
177 | if(t){ |
178 | LOG(AliL3Log::kInformational,"AliL3FileHandler::IsDigit","File Type") |
179 | <<"Found Digit Tree -> Use Fast Cluster Finder"<<ENDLOG; |
180 | return kTRUE; |
181 | } |
182 | else{ |
183 | LOG(AliL3Log::kInformational,"AliL3FileHandler::IsDigit","File Type") |
184 | <<"No Digit Tree -> Use Cluster Tree"<<ENDLOG; |
185 | return kFALSE; |
186 | } |
187 | } |
188 | |
189 | ///////////////////////////////////////// Digit IO |
9183aa27 |
190 | Bool_t AliL3FileHandler::AliDigits2Binary(Int_t event) |
191 | { |
192 | |
108615fc |
193 | Bool_t out = kTRUE; |
194 | UInt_t nrow; |
31d9405a |
195 | AliL3DigitRowData* data = AliDigits2Memory(nrow,event); |
108615fc |
196 | out = Memory2Binary(nrow,data); |
197 | Free(); |
198 | return out; |
199 | } |
200 | |
201 | |
9183aa27 |
202 | Bool_t AliL3FileHandler::AliDigits2CompBinary(Int_t event) |
203 | { |
204 | //Convert AliROOT TPC data, into HLT data format. |
205 | //event specifies the event you want in the aliroot file. |
206 | |
108615fc |
207 | Bool_t out = kTRUE; |
208 | UInt_t ndigits=0; |
31d9405a |
209 | AliL3DigitRowData* digits = AliDigits2Memory(ndigits,event); |
108615fc |
210 | out = Memory2CompBinary(ndigits,digits); |
211 | Free(); |
212 | return out; |
213 | } |
214 | |
215 | |
9183aa27 |
216 | AliL3DigitRowData * AliL3FileHandler::AliDigits2Memory(UInt_t & nrow,Int_t event) |
217 | { |
218 | //Read data from AliROOT file into memory, and store it in the HLT data format. |
219 | //Returns a pointer to the data. |
220 | |
108615fc |
221 | AliL3DigitRowData *data = 0; |
222 | nrow=0; |
223 | if(!fInAli){ |
224 | LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2Memory","File") |
225 | <<"No Input avalible: no object TFile"<<ENDLOG; |
226 | return 0; |
227 | } |
228 | if(!fInAli->IsOpen()){ |
229 | LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2Memory","File") |
230 | <<"No Input avalible: TFile not opend"<<ENDLOG; |
231 | return 0; |
232 | } |
b25c64e5 |
233 | |
a6e4f9d6 |
234 | if(!fDigitsTree) |
235 | GetDigitsTree(event); |
236 | |
108615fc |
237 | UShort_t dig; |
238 | Int_t time,pad,sector,row; |
239 | Int_t nrows=0; |
240 | Int_t ndigitcount=0; |
a6e4f9d6 |
241 | Int_t entries = (Int_t)fDigitsTree->GetEntries(); |
108615fc |
242 | Int_t ndigits[entries]; |
243 | Int_t lslice,lrow; |
a6e4f9d6 |
244 | |
245 | for(Int_t n=fLastIndex; n<fDigitsTree->GetEntries(); n++) |
108615fc |
246 | { |
a6e4f9d6 |
247 | fDigitsTree->GetEvent(n); |
248 | fParam->AdjustSectorRow(fDigits->GetID(),sector,row); |
494fad94 |
249 | AliL3Transform::Sector2Slice(lslice,lrow,sector,row); |
a6e4f9d6 |
250 | //if(fSlice != lslice || lrow<fRowMin || lrow>fRowMax) continue; |
251 | if(lslice < fSlice) continue; |
252 | if(lslice != fSlice) break; |
253 | if(lrow < fRowMin) continue; |
254 | if(lrow > fRowMax) break; |
108615fc |
255 | |
256 | Float_t xyz[3]; |
257 | ndigits[lrow] = 0; |
a6e4f9d6 |
258 | fDigits->First(); |
108615fc |
259 | do { |
a6e4f9d6 |
260 | time=fDigits->CurrentRow(); |
261 | pad=fDigits->CurrentColumn(); |
262 | dig = fDigits->GetDigit(time,pad); |
108615fc |
263 | if(dig<=fParam->GetZeroSup()) continue; |
7a9b2a20 |
264 | |
265 | /* |
266 | if(time < fParam->GetMaxTBin()-1 && time > 0) |
267 | if(fDigits->GetDigit(time+1,pad) <= fParam->GetZeroSup() |
268 | && fDigits->GetDigit(time-1,pad) <= fParam->GetZeroSup()) |
269 | continue; |
270 | */ |
271 | |
494fad94 |
272 | AliL3Transform::Raw2Local(xyz,sector,row,pad,time); |
108615fc |
273 | if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2])) |
274 | continue; |
275 | |
276 | ndigits[lrow]++; //for this row only |
277 | ndigitcount++; //total number of digits to be published |
278 | |
a6e4f9d6 |
279 | } while (fDigits->Next()); |
108615fc |
280 | |
281 | nrows++; |
282 | } |
283 | Int_t size = sizeof(AliL3DigitData)*ndigitcount |
8f1a9904 |
284 | + nrows*sizeof(AliL3DigitRowData); |
108615fc |
285 | |
286 | LOG(AliL3Log::kDebug,"AliL3FileHandler::AliDigits2Memory","Digits") |
a6e4f9d6 |
287 | <<AliL3Log::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG; |
288 | |
108615fc |
289 | data=(AliL3DigitRowData*) Allocate(size); |
290 | nrow = (UInt_t)nrows; |
291 | AliL3DigitRowData *tempPt = data; |
a6e4f9d6 |
292 | for(Int_t n=fLastIndex; n<fDigitsTree->GetEntries(); n++) |
108615fc |
293 | { |
a6e4f9d6 |
294 | fDigitsTree->GetEvent(n); |
108615fc |
295 | Float_t xyz[3]; |
a6e4f9d6 |
296 | fParam->AdjustSectorRow(fDigits->GetID(),sector,row); |
494fad94 |
297 | AliL3Transform::Sector2Slice(lslice,lrow,sector,row); |
a6e4f9d6 |
298 | //if(fSlice != lslice || lrow<fRowMin || lrow>fRowMax) continue; |
299 | if(lslice < fSlice) continue; |
300 | if(lslice != fSlice) break; |
301 | if(lrow < fRowMin) continue; |
302 | if(lrow > fRowMax) break; |
303 | |
108615fc |
304 | tempPt->fRow = lrow; |
305 | tempPt->fNDigit = ndigits[lrow]; |
306 | |
307 | Int_t localcount=0; |
a6e4f9d6 |
308 | fDigits->First(); |
108615fc |
309 | do { |
a6e4f9d6 |
310 | //dig=fDigits->CurrentDigit(); |
03b6adf7 |
311 | //if (dig<=fParam->GetZeroSup()) continue; |
a6e4f9d6 |
312 | time=fDigits->CurrentRow(); |
313 | pad=fDigits->CurrentColumn(); |
314 | dig = fDigits->GetDigit(time,pad); |
03b6adf7 |
315 | if (dig <= fParam->GetZeroSup()) continue; |
7a9b2a20 |
316 | |
317 | /* |
318 | if(time < fParam->GetMaxTBin()-1 && time > 0) |
a6e4f9d6 |
319 | if(fDigits->GetDigit(time-1,pad) <= fParam->GetZeroSup() && |
7a9b2a20 |
320 | fDigits->GetDigit(time+1,pad) <= fParam->GetZeroSup()) continue; |
321 | */ |
322 | |
323 | //Exclude data outside cone: |
494fad94 |
324 | AliL3Transform::Raw2Local(xyz,sector,row,pad,time); |
108615fc |
325 | if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2])) |
326 | continue; |
327 | |
328 | if(localcount >= ndigits[lrow]) |
329 | LOG(AliL3Log::kFatal,"AliL3FileHandler::AliDigits2Binary","Memory") |
03b6adf7 |
330 | <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits " |
331 | <<ndigits[lrow]<<ENDLOG; |
332 | |
108615fc |
333 | tempPt->fDigitData[localcount].fCharge=dig; |
334 | tempPt->fDigitData[localcount].fPad=pad; |
335 | tempPt->fDigitData[localcount].fTime=time; |
10f815d9 |
336 | #ifdef do_mc |
337 | tempPt->fDigitData[localcount].fTrackID[0] = fDigits->GetTrackID(time,pad,0); |
338 | tempPt->fDigitData[localcount].fTrackID[1] = fDigits->GetTrackID(time,pad,1); |
339 | tempPt->fDigitData[localcount].fTrackID[2] = fDigits->GetTrackID(time,pad,2); |
340 | #endif |
108615fc |
341 | localcount++; |
a6e4f9d6 |
342 | } while (fDigits->Next()); |
108615fc |
343 | |
344 | Byte_t *tmp = (Byte_t*)tempPt; |
345 | Int_t size = sizeof(AliL3DigitRowData) |
346 | + ndigits[lrow]*sizeof(AliL3DigitData); |
347 | tmp += size; |
348 | tempPt = (AliL3DigitRowData*)tmp; |
a6e4f9d6 |
349 | //fLastIndex=n; |
108615fc |
350 | } |
a6e4f9d6 |
351 | //fLastIndex++; |
108615fc |
352 | return data; |
353 | } |
354 | |
a6e4f9d6 |
355 | Bool_t AliL3FileHandler::GetDigitsTree(Int_t event) |
356 | { |
9183aa27 |
357 | //Connects to the TPC digit tree in the AliROOT file. |
a6e4f9d6 |
358 | |
359 | fInAli->cd(); |
360 | Char_t dname[100]; |
361 | sprintf(dname,"TreeD_75x40_100x60_%d",event); |
362 | fDigitsTree = (TTree*)fInAli->Get("TreeD_75x40_100x60_0"); |
363 | if(!fDigitsTree) |
364 | { |
365 | LOG(AliL3Log::kError,"AliL3FileHandler::GetDigitsTree","Digits Tree") |
366 | <<AliL3Log::kHex<<"Error getting digitstree "<<(Int_t)fDigitsTree<<ENDLOG; |
367 | return kFALSE; |
368 | } |
369 | fDigitsTree->GetBranch("Segment")->SetAddress(&fDigits); |
370 | return kTRUE; |
371 | } |
372 | |
0d319e67 |
373 | void AliL3FileHandler::AliDigits2RootFile(AliL3DigitRowData *rowPt,Char_t *new_digitsfile) |
374 | { |
9183aa27 |
375 | //Write the data stored in rowPt, into a new AliROOT file. |
376 | //The data is stored in the AliROOT format |
377 | //This is specially a nice thing if you have modified data, and wants to run it |
378 | //through the offline reconstruction chain. |
379 | //The arguments is a pointer to the data, and the name of the new AliROOT file. |
380 | //Remember to pass the original AliROOT file (the one that contains the original |
381 | //simulated data) to this object, in order to retrieve the MC id's of the digits. |
382 | |
0d319e67 |
383 | if(!fInAli) |
384 | { |
8f1a9904 |
385 | printf("AliL3FileHandler::AliDigits2RootFile : No rootfile\n"); |
0d319e67 |
386 | return; |
387 | } |
388 | if(!fParam) |
389 | { |
390 | printf("AliL3FileHandler::AliDigits2RootFile : No parameter object. Run on rootfile\n"); |
391 | return; |
392 | } |
0d319e67 |
393 | |
394 | //Get the original digitstree: |
395 | fInAli->cd(); |
396 | AliTPCDigitsArray *old_array = new AliTPCDigitsArray(); |
397 | old_array->Setup(fParam); |
398 | old_array->SetClass("AliSimDigits"); |
03b6adf7 |
399 | Bool_t ok = old_array->ConnectTree("TreeD_75x40_100x60_0"); |
0d319e67 |
400 | if(!ok) |
401 | { |
402 | printf("AliL3FileHandler::AliDigits2RootFile : No digits tree object\n"); |
403 | return; |
404 | } |
0d319e67 |
405 | |
03b6adf7 |
406 | Bool_t create=kFALSE; |
407 | TFile *digFile; |
408 | |
8f1a9904 |
409 | digFile = TFile::Open(new_digitsfile,"NEW"); |
410 | if(digFile->IsOpen()) |
03b6adf7 |
411 | { |
03b6adf7 |
412 | create = kTRUE; |
413 | fParam->Write(fParam->GetTitle()); |
414 | } |
415 | else |
416 | { |
8f1a9904 |
417 | LOG(AliL3Log::kDebug,"AliL3FileHandler::AliDigits2RootFile","Rootfile") |
418 | <<"Rootfile did already exist, so I will just open it for updates"<<ENDLOG; |
03b6adf7 |
419 | digFile = TFile::Open(new_digitsfile,"UPDATE"); |
420 | create=kFALSE; |
421 | } |
422 | if(!digFile->IsOpen()) |
423 | { |
8f1a9904 |
424 | LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2RootFile","Rootfile") |
425 | <<"Error opening rootfile "<<new_digitsfile<<ENDLOG; |
03b6adf7 |
426 | return; |
427 | } |
428 | |
429 | digFile->cd(); |
430 | |
431 | //setup a new one, or connect it to the existing one: |
0d319e67 |
432 | AliTPCDigitsArray *arr = new AliTPCDigitsArray; |
433 | arr->SetClass("AliSimDigits"); |
434 | arr->Setup(fParam); |
03b6adf7 |
435 | if(create) |
436 | arr->MakeTree(); |
437 | else |
438 | { |
439 | Bool_t ok = arr->ConnectTree("TreeD_75x40_100x60_0"); |
440 | if(!ok) |
441 | { |
442 | printf("AliL3FileHandler::AliDigits2RootFile : No digits tree object in existing file\n"); |
443 | return; |
444 | } |
445 | } |
54efe57a |
446 | Int_t digcounter=0; |
49898c33 |
447 | |
0d319e67 |
448 | for(Int_t i=fRowMin; i<=fRowMax; i++) |
449 | { |
03b6adf7 |
450 | |
49898c33 |
451 | if((Int_t)rowPt->fRow != i) printf("AliL3FileHandler::AliDigits2RootFile : Mismatching row numbering!!!\n"); |
03b6adf7 |
452 | |
0d319e67 |
453 | Int_t sector,row; |
494fad94 |
454 | AliL3Transform::Slice2Sector(fSlice,i,sector,row); |
49898c33 |
455 | AliSimDigits * dig = (AliSimDigits*)arr->CreateRow(sector,row); |
456 | AliSimDigits *old_dig = (AliSimDigits*)old_array->LoadRow(sector,row); |
0d319e67 |
457 | if(!old_dig) |
458 | printf("AliL3FileHandler::AliDigits2RootFile : No padrow %d %d\n",sector,row); |
459 | |
460 | AliL3DigitData *digPt = rowPt->fDigitData; |
54efe57a |
461 | digcounter=0; |
0d319e67 |
462 | for(UInt_t j=0; j<rowPt->fNDigit; j++) |
463 | { |
49898c33 |
464 | Int_t charge = (Int_t)digPt[j].fCharge; |
465 | Int_t pad = (Int_t)digPt[j].fPad; |
466 | Int_t time = (Int_t)digPt[j].fTime; |
03b6adf7 |
467 | |
468 | if(charge == 0) //Only write the digits that has not been removed |
469 | continue; |
54efe57a |
470 | digcounter++; |
471 | dig->SetDigitFast(charge,time,pad); |
49898c33 |
472 | |
473 | Int_t trackID[3] = {old_dig->GetTrackID(time,pad,0),old_dig->GetTrackID(time,pad,1),old_dig->GetTrackID(time,pad,2)}; |
474 | Int_t s_pad = pad; |
475 | Int_t s_time = time - 1; |
476 | while(trackID[0] < 0) |
477 | { |
494fad94 |
478 | if(s_time >= 0 && s_time < AliL3Transform::GetNTimeBins() && s_pad >= 0 && s_pad < AliL3Transform::GetNPads(i)) |
49898c33 |
479 | { |
480 | if(old_dig->GetTrackID(s_time,s_pad,0) > 0) |
481 | { |
482 | trackID[0]=old_dig->GetTrackID(s_time,s_pad,0); |
483 | trackID[1]=old_dig->GetTrackID(s_time,s_pad,1); |
484 | trackID[2]=old_dig->GetTrackID(s_time,s_pad,2); |
485 | } |
486 | } |
487 | if(s_pad == pad && s_time == time - 1) |
488 | s_time = time + 1; |
489 | else if(s_pad == pad && s_time == time + 1) |
490 | {s_pad = pad - 1; s_time = time;} |
491 | else if(s_pad == pad - 1 && s_time == time) |
492 | s_time = time - 1; |
493 | else if(s_pad == pad - 1 && s_time == time - 1) |
494 | s_time = time + 1; |
495 | else if(s_pad == pad - 1 && s_time == time + 1) |
496 | {s_pad = pad + 1; s_time = time;} |
497 | else if(s_pad == pad + 1 && s_time == time) |
498 | s_time = time - 1; |
499 | else if(s_pad == pad + 1 && s_time == time - 1) |
500 | s_time = time + 1; |
501 | else |
502 | break; |
503 | } |
504 | |
505 | dig->SetTrackIDFast(trackID[0],time,pad,0); |
506 | dig->SetTrackIDFast(trackID[1],time,pad,1); |
507 | dig->SetTrackIDFast(trackID[2],time,pad,2); |
0d319e67 |
508 | |
509 | } |
54efe57a |
510 | //cout<<"Wrote "<<digcounter<<" on row "<<i<<endl; |
0d319e67 |
511 | UpdateRowPointer(rowPt); |
512 | arr->StoreRow(sector,row); |
513 | arr->ClearRow(sector,row); |
514 | old_array->ClearRow(sector,row); |
515 | } |
516 | digFile->cd(); |
517 | char treeName[100]; |
03b6adf7 |
518 | sprintf(treeName,"TreeD_%s_0",fParam->GetTitle()); |
8f1a9904 |
519 | printf("Writing tree to file....."); |
0d319e67 |
520 | arr->GetTree()->Write(treeName,TObject::kOverwrite); |
8f1a9904 |
521 | printf("done\n"); |
0d319e67 |
522 | digFile->Close(); |
03b6adf7 |
523 | //arr->GetTree()->Delete(); |
524 | //delete arr; |
0d319e67 |
525 | } |
526 | |
108615fc |
527 | ///////////////////////////////////////// Point IO |
528 | Bool_t AliL3FileHandler::AliPoints2Binary(){ |
529 | Bool_t out = kTRUE; |
530 | UInt_t npoint; |
531 | AliL3SpacePointData *data = AliPoints2Memory(npoint); |
532 | out = Memory2Binary(npoint,data); |
533 | Free(); |
534 | return out; |
535 | } |
536 | |
537 | AliL3SpacePointData * AliL3FileHandler::AliPoints2Memory(UInt_t & npoint){ |
538 | AliL3SpacePointData *data = 0; |
539 | npoint=0; |
540 | if(!fInAli){ |
541 | LOG(AliL3Log::kWarning,"AliL3FileHandler::AliPoints2Memory","File") |
542 | <<"No Input avalible: no object TFile"<<ENDLOG; |
543 | return 0; |
544 | } |
545 | if(!fInAli->IsOpen()){ |
546 | LOG(AliL3Log::kWarning,"AliL3FileHandler::AliPoints2Memory","File") |
547 | <<"No Input avalible: TFile not opend"<<ENDLOG; |
548 | return 0; |
549 | } |
494fad94 |
550 | |
108615fc |
551 | TDirectory *savedir = gDirectory; |
552 | fInAli->cd(); |
8f1a9904 |
553 | |
554 | Char_t cname[100]; |
555 | Int_t eventn = 0; |
556 | sprintf(cname,"TreeC_TPC_%d",eventn); |
108615fc |
557 | AliTPCClustersArray carray; |
558 | carray.Setup(fParam); |
559 | carray.SetClusterType("AliTPCcluster"); |
8f1a9904 |
560 | Bool_t clusterok = carray.ConnectTree(cname); |
108615fc |
561 | if(!clusterok) return 0; |
562 | |
563 | AliTPCClustersRow ** clusterrow = |
564 | new AliTPCClustersRow*[ (int)carray.GetTree()->GetEntries()]; |
565 | Int_t *rows = new int[ (int)carray.GetTree()->GetEntries()]; |
566 | Int_t *sects = new int[ (int)carray.GetTree()->GetEntries()]; |
567 | Int_t sum=0; |
568 | |
569 | Int_t lslice,lrow; |
570 | for(Int_t i=0; i<carray.GetTree()->GetEntries(); i++){ |
571 | AliSegmentID *s = carray.LoadEntry(i); |
572 | Int_t sector,row; |
573 | fParam->AdjustSectorRow(s->GetID(),sector,row); |
574 | rows[i] = row; |
575 | sects[i] = sector; |
576 | clusterrow[i] = 0; |
494fad94 |
577 | AliL3Transform::Sector2Slice(lslice,lrow,sector,row); |
108615fc |
578 | if(fSlice != lslice || lrow<fRowMin || lrow>fRowMax) continue; |
579 | clusterrow[i] = carray.GetRow(sector,row); |
580 | if(clusterrow[i]) |
581 | sum+=clusterrow[i]->GetArray()->GetEntriesFast(); |
582 | } |
583 | UInt_t size = sum*sizeof(AliL3SpacePointData); |
584 | |
585 | LOG(AliL3Log::kDebug,"AliL3FileHandler::AliPoints2Memory","File") |
586 | <<AliL3Log::kDec<<"Found "<<sum<<" SpacePoints"<<ENDLOG; |
587 | |
588 | data = (AliL3SpacePointData *) Allocate(size); |
589 | npoint = sum; |
590 | UInt_t n=0; |
591 | for(Int_t i=0; i<carray.GetTree()->GetEntries(); i++){ |
592 | if(!clusterrow[i]) continue; |
593 | Int_t row = rows[i]; |
594 | Int_t sector = sects[i]; |
494fad94 |
595 | AliL3Transform::Sector2Slice(lslice,lrow,sector,row); |
108615fc |
596 | Int_t entries_in_row = clusterrow[i]->GetArray()->GetEntriesFast(); |
597 | for(Int_t j = 0;j<entries_in_row;j++){ |
598 | AliTPCcluster *c = (AliTPCcluster*)(*clusterrow[i])[j]; |
599 | data[n].fZ = c->GetZ(); |
600 | data[n].fY = c->GetY(); |
601 | data[n].fX = fParam->GetPadRowRadii(sector,row); |
602 | data[n].fID = n+((fSlice&0x7f)<<25)+((fPatch&0x7)<<22);//uli |
603 | data[n].fPadRow = lrow; |
604 | data[n].fXYErr = c->GetSigmaY2(); |
605 | data[n].fZErr = c->GetSigmaZ2(); |
606 | if(fMC) fprintf(fMC,"%d %d\n",data[n].fID,c->GetLabel(0)); |
607 | n++; |
608 | } |
609 | } |
610 | for(Int_t i=0;i<carray.GetTree()->GetEntries();i++){ |
611 | Int_t row = rows[i]; |
612 | Int_t sector = sects[i]; |
613 | if(carray.GetRow(sector,row)) |
614 | carray.ClearRow(sector,row); |
615 | } |
616 | |
617 | delete [] clusterrow; |
618 | delete [] rows; |
619 | delete [] sects; |
620 | savedir->cd(); |
621 | |
622 | return data; |
623 | } |
624 | |