]>
Commit | Line | Data |
---|---|---|
3e87ef69 | 1 | // @(#) $Id$ |
31d9405a | 2 | |
02f030e3 | 3 | // Author: Uli Frankenfeld <mailto:franken@fi.uib.no>, Anders Vestbo <mailto:vestbo$fi.uib.no>, C. Loizides <mailto:loizides@ikf.uni-frankfurt.de> |
3e87ef69 | 4 | //*-- Copyright © ALICE HLT Group |
108615fc | 5 | |
118c26c3 | 6 | #include "AliL3StandardIncludes.h" |
5e0f9911 | 7 | #include <TClonesArray.h> |
f6670bec | 8 | #include <TSystem.h> |
5e0f9911 | 9 | |
02f030e3 | 10 | #include <AliTPCParamSR.h> |
118c26c3 | 11 | #include <AliTPCDigitsArray.h> |
12 | #include <AliTPCClustersArray.h> | |
13 | #include <AliTPCcluster.h> | |
14 | #include <AliTPCClustersRow.h> | |
5e0f9911 | 15 | #include <AliSimDigits.h> |
108615fc | 16 | |
108615fc | 17 | #include "AliL3Logging.h" |
118c26c3 | 18 | #include "AliL3Transform.h" |
108615fc | 19 | #include "AliL3MemHandler.h" |
20 | #include "AliL3FileHandler.h" | |
108615fc | 21 | #include "AliL3DigitData.h" |
22 | #include "AliL3TrackSegmentData.h" | |
23 | #include "AliL3SpacePointData.h" | |
24 | #include "AliL3TrackArray.h" | |
b661165c | 25 | |
3e87ef69 | 26 | #if GCCVERSION == 3 |
27 | using namespace std; | |
28 | #endif | |
748e01f4 | 29 | |
3e87ef69 | 30 | /** \class AliL3FileHandler |
31 | <pre> | |
108615fc | 32 | //_____________________________________________________________ |
b661165c | 33 | // AliL3FileHandler |
108615fc | 34 | // |
9183aa27 | 35 | // The HLT ROOT <-> binary files handling class |
108615fc | 36 | // |
9183aa27 | 37 | // This class provides the interface between AliROOT files, |
38 | // and HLT binary files. It should be used for converting | |
39 | // TPC data stored in AliROOT format (outputfile from a simulation), | |
40 | // into the data format currently used by in the HLT framework. | |
41 | // This enables the possibility to always use the same data format, | |
42 | // whether you are using a binary file as an input, or a AliROOT file. | |
43 | // | |
44 | // For example on how to create binary files from a AliROOT simulation, | |
45 | // see example macro exa/Binary.C. | |
46 | // | |
47 | // For reading a AliROOT file into HLT format in memory, do the following: | |
48 | // | |
49 | // AliL3FileHandler file; | |
2330399d | 50 | // file.Init(slice,patch); |
9183aa27 | 51 | // file.SetAliInput("galice.root"); |
52 | // AliL3DigitRowData *dataPt = (AliL3DigitRowData*)file.AliDigits2Memory(nrows,eventnr); | |
53 | // | |
54 | // All the data are then stored in memory and accessible via the pointer dataPt. | |
55 | // Accesing the data is then identical to the example 1) showed in AliL3MemHandler class. | |
56 | // | |
57 | // For converting the data back, and writing it to a new AliROOT file do: | |
58 | // | |
59 | // AliL3FileHandler file; | |
2330399d | 60 | // file.Init(slice,patch); |
9183aa27 | 61 | // file.SetAliInput("galice.root"); |
62 | // file.Init(slice,patch,NumberOfRowsInPatch); | |
63 | // file.AliDigits2RootFile(dataPt,"new_galice.root"); | |
64 | // file.CloseAliInput(); | |
3e87ef69 | 65 | </pre> |
66 | */ | |
108615fc | 67 | |
68 | ClassImp(AliL3FileHandler) | |
69 | ||
9183aa27 | 70 | AliL3FileHandler::AliL3FileHandler() |
71 | { | |
108615fc | 72 | //Default constructor |
73 | fInAli = 0; | |
74 | fParam = 0; | |
108615fc | 75 | fMC =0; |
a6e4f9d6 | 76 | fLastIndex=0; |
77 | fDigits=0; | |
78 | fDigitsTree=0; | |
02f030e3 | 79 | for(Int_t i=0;i<AliL3Transform::GetNSlice();i++){ |
80 | for(Int_t j=0;j<AliL3Transform::GetNRows();j++) | |
81 | fIndex[i][j]=-1; | |
82 | } | |
83 | fIndexCreated=kFALSE; | |
108615fc | 84 | } |
85 | ||
9183aa27 | 86 | AliL3FileHandler::~AliL3FileHandler() |
87 | { | |
108615fc | 88 | //Destructor |
108615fc | 89 | if(fMC) CloseMCOutput(); |
a815f9dd | 90 | FreeDigitsTree(); |
8f1a9904 | 91 | if(fInAli) CloseAliInput(); |
108615fc | 92 | } |
93 | ||
a815f9dd | 94 | void AliL3FileHandler::FreeDigitsTree() |
95 | { | |
96 | if(!fDigitsTree) | |
97 | { | |
98 | LOG(AliL3Log::kWarning,"AliL3FileHandler::FreeDigitsTree()","Pointer") | |
99 | <<"Cannot free digitstree, it is not present"<<ENDLOG; | |
100 | return; | |
101 | } | |
102 | fDigits=0; | |
103 | fDigitsTree->Delete(); | |
104 | fDigitsTree=0; | |
3e87ef69 | 105 | fLastIndex=0; |
02f030e3 | 106 | for(Int_t i=0;i<AliL3Transform::GetNSlice();i++){ |
107 | for(Int_t j=0;j<AliL3Transform::GetNRows();j++) | |
108 | fIndex[i][j]=-1; | |
109 | } | |
110 | fIndexCreated=kFALSE; | |
a815f9dd | 111 | } |
112 | ||
3e87ef69 | 113 | Bool_t AliL3FileHandler::SetMCOutput(Char_t *name) |
9183aa27 | 114 | { |
108615fc | 115 | fMC = fopen(name,"w"); |
116 | if(!fMC){ | |
117 | LOG(AliL3Log::kWarning,"AliL3FileHandler::SetMCOutput","File Open") | |
9183aa27 | 118 | <<"Pointer to File = 0x0 "<<ENDLOG; |
108615fc | 119 | return kFALSE; |
120 | } | |
121 | return kTRUE; | |
122 | } | |
123 | ||
9183aa27 | 124 | Bool_t AliL3FileHandler::SetMCOutput(FILE *file) |
125 | { | |
108615fc | 126 | fMC = file; |
127 | if(!fMC){ | |
128 | LOG(AliL3Log::kWarning,"AliL3FileHandler::SetMCOutput","File Open") | |
9183aa27 | 129 | <<"Pointer to File = 0x0 "<<ENDLOG; |
108615fc | 130 | return kFALSE; |
131 | } | |
132 | return kTRUE; | |
133 | } | |
134 | ||
9183aa27 | 135 | void AliL3FileHandler::CloseMCOutput() |
136 | { | |
108615fc | 137 | if(!fMC){ |
138 | LOG(AliL3Log::kWarning,"AliL3FileHandler::CloseMCOutPut","File Close") | |
9183aa27 | 139 | <<"Nothing to Close"<<ENDLOG; |
108615fc | 140 | return; |
141 | } | |
142 | fclose(fMC); | |
143 | fMC =0; | |
144 | } | |
145 | ||
9183aa27 | 146 | Bool_t AliL3FileHandler::SetAliInput() |
147 | { | |
108615fc | 148 | if(!fInAli->IsOpen()){ |
149 | LOG(AliL3Log::kError,"AliL3FileHandler::SetAliInput","File Open") | |
9183aa27 | 150 | <<"Ali File "<<fInAli->GetName()<<" does not exist"<<ENDLOG; |
108615fc | 151 | return kFALSE; |
152 | } | |
5e0f9911 | 153 | fParam = (AliTPCParam*)fInAli->Get(AliL3Transform::GetParamName()); |
02f030e3 | 154 | if(!fParam){ |
155 | LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File") | |
156 | <<"No TPC parameters found in \""<<fInAli->GetName() | |
157 | <<"\", creating standard parameters " | |
158 | <<"which might not be what you want!"<<ENDLOG; | |
159 | fParam = new AliTPCParamSR; | |
160 | } | |
108615fc | 161 | if(!fParam){ |
162 | LOG(AliL3Log::kError,"AliL3FileHandler::SetAliInput","File Open") | |
748e01f4 | 163 | <<"No AliTPCParam "<<AliL3Transform::GetParamName()<<" in File "<<fInAli->GetName()<<ENDLOG; |
9183aa27 | 164 | return kFALSE; |
108615fc | 165 | } |
108615fc | 166 | return kTRUE; |
167 | } | |
168 | ||
3e87ef69 | 169 | Bool_t AliL3FileHandler::SetAliInput(Char_t *name) |
9183aa27 | 170 | { |
171 | //Open the AliROOT file with name. | |
172 | ||
108615fc | 173 | fInAli= new TFile(name,"READ"); |
174 | if(!fInAli){ | |
175 | LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File Open") | |
176 | <<"Pointer to TFile = 0x0 "<<ENDLOG; | |
177 | return kFALSE; | |
178 | } | |
179 | return SetAliInput(); | |
180 | } | |
181 | ||
9183aa27 | 182 | Bool_t AliL3FileHandler::SetAliInput(TFile *file) |
183 | { | |
184 | //Specify already opened AliROOT file to use as an input. | |
185 | ||
108615fc | 186 | fInAli=file; |
187 | if(!fInAli){ | |
188 | LOG(AliL3Log::kWarning,"AliL3FileHandler::SetAliInput","File Open") | |
189 | <<"Pointer to TFile = 0x0 "<<ENDLOG; | |
190 | return kFALSE; | |
191 | } | |
192 | return SetAliInput(); | |
193 | } | |
194 | ||
9183aa27 | 195 | void AliL3FileHandler::CloseAliInput() |
196 | { | |
108615fc | 197 | if(!fInAli){ |
198 | LOG(AliL3Log::kWarning,"AliL3FileHandler::CloseAliInput","File Close") | |
9183aa27 | 199 | <<"Nothing to Close"<<ENDLOG; |
200 | return; | |
108615fc | 201 | } |
202 | if(fInAli->IsOpen()) fInAli->Close(); | |
203 | delete fInAli; | |
204 | fInAli = 0; | |
205 | } | |
206 | ||
68a27388 | 207 | Bool_t AliL3FileHandler::IsDigit(Int_t event) |
9183aa27 | 208 | { |
209 | //Check if there is a TPC digit tree in the current file. | |
210 | //Return kTRUE if tree was found, and kFALSE if not found. | |
211 | ||
108615fc | 212 | if(!fInAli){ |
213 | LOG(AliL3Log::kWarning,"AliL3FileHandler::IsDigit","File") | |
214 | <<"Pointer to TFile = 0x0 "<<ENDLOG; | |
748e01f4 | 215 | return kTRUE; //maybe you are using binary input which is Digits!! |
108615fc | 216 | } |
68a27388 | 217 | Char_t name[1024]; |
5e0f9911 | 218 | sprintf(name,"TreeD_%s_%d",AliL3Transform::GetParamName(),event); |
68a27388 | 219 | TTree *t=(TTree*)fInAli->Get(name); |
108615fc | 220 | if(t){ |
221 | LOG(AliL3Log::kInformational,"AliL3FileHandler::IsDigit","File Type") | |
222 | <<"Found Digit Tree -> Use Fast Cluster Finder"<<ENDLOG; | |
223 | return kTRUE; | |
224 | } | |
225 | else{ | |
226 | LOG(AliL3Log::kInformational,"AliL3FileHandler::IsDigit","File Type") | |
227 | <<"No Digit Tree -> Use Cluster Tree"<<ENDLOG; | |
228 | return kFALSE; | |
229 | } | |
230 | } | |
231 | ||
232 | ///////////////////////////////////////// Digit IO | |
3e87ef69 | 233 | Bool_t AliL3FileHandler::AliDigits2Binary(Int_t event,Bool_t altro) |
9183aa27 | 234 | { |
108615fc | 235 | Bool_t out = kTRUE; |
236 | UInt_t nrow; | |
3e87ef69 | 237 | AliL3DigitRowData* data = 0; |
238 | if(altro) | |
239 | data = AliAltroDigits2Memory(nrow,event); | |
240 | else | |
241 | data = AliDigits2Memory(nrow,event); | |
108615fc | 242 | out = Memory2Binary(nrow,data); |
243 | Free(); | |
244 | return out; | |
245 | } | |
246 | ||
954beff0 | 247 | Bool_t AliL3FileHandler::AliDigits2CompBinary(Int_t event,Bool_t altro) |
9183aa27 | 248 | { |
249 | //Convert AliROOT TPC data, into HLT data format. | |
250 | //event specifies the event you want in the aliroot file. | |
251 | ||
108615fc | 252 | Bool_t out = kTRUE; |
253 | UInt_t ndigits=0; | |
954beff0 | 254 | AliL3DigitRowData *digits=0; |
02f030e3 | 255 | if(altro) |
954beff0 | 256 | digits = AliAltroDigits2Memory(ndigits,event); |
02f030e3 | 257 | else |
258 | digits = AliDigits2Memory(ndigits,event); | |
108615fc | 259 | out = Memory2CompBinary(ndigits,digits); |
260 | Free(); | |
261 | return out; | |
262 | } | |
263 | ||
02f030e3 | 264 | Bool_t AliL3FileHandler::CreateIndex() |
265 | { | |
266 | //create the access index | |
267 | ||
268 | LOG(AliL3Log::kInformational,"AliL3FileHandler::CreateIndex","Index") | |
269 | <<"Starting to create index, this can take a while."<<ENDLOG; | |
270 | ||
271 | fIndexCreated=kFALSE; | |
272 | for(Int_t i=0;i<AliL3Transform::GetNSlice();i++){ | |
273 | for(Int_t j=0;j<AliL3Transform::GetNRows();j++) | |
274 | fIndex[i][j]=-1; | |
275 | } | |
276 | ||
277 | for(Int_t n=0; n<fDigitsTree->GetEntries(); n++){ | |
278 | Int_t sector, row; | |
279 | Int_t lslice,lrow; | |
280 | fDigitsTree->GetEvent(n); | |
281 | fParam->AdjustSectorRow(fDigits->GetID(),sector,row); | |
282 | if(!AliL3Transform::Sector2Slice(lslice,lrow,sector,row)){ | |
283 | LOG(AliL3Log::kError,"AliL3FileHandler::CreateIndex","Slice/Row") | |
284 | <<AliL3Log::kDec<<"Index could not be created. Wrong values " | |
285 | <<sector<<" "<<row<<ENDLOG; | |
286 | return kFALSE; | |
287 | } | |
288 | //cout << lslice << " " << lrow << " " << sector << " " << row << endl; | |
289 | if(fIndex[lslice][lrow]==-1) fIndex[lslice][lrow]=n; | |
290 | } | |
291 | ||
292 | //for(Int_t i=0;i<AliL3Transform::GetNSlice();i++) cout << i << " " << fIndex[i][0] << endl; | |
293 | ||
294 | LOG(AliL3Log::kInformational,"AliL3FileHandler::CreateIndex","Index") | |
295 | <<"Index successfully created."<<ENDLOG; | |
296 | ||
297 | fIndexCreated=kTRUE; | |
298 | return fIndexCreated; | |
299 | } | |
300 | ||
9183aa27 | 301 | AliL3DigitRowData * AliL3FileHandler::AliDigits2Memory(UInt_t & nrow,Int_t event) |
302 | { | |
303 | //Read data from AliROOT file into memory, and store it in the HLT data format. | |
304 | //Returns a pointer to the data. | |
305 | ||
108615fc | 306 | AliL3DigitRowData *data = 0; |
307 | nrow=0; | |
4499ed26 | 308 | |
108615fc | 309 | if(!fInAli){ |
310 | LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2Memory","File") | |
311 | <<"No Input avalible: no object TFile"<<ENDLOG; | |
312 | return 0; | |
313 | } | |
314 | if(!fInAli->IsOpen()){ | |
315 | LOG(AliL3Log::kWarning,"AliL3FileHandler::AliDigits2Memory","File") | |
748e01f4 | 316 | <<"No Input avalible: TFile not opened"<<ENDLOG; |
108615fc | 317 | return 0; |
318 | } | |
748e01f4 | 319 | |
a6e4f9d6 | 320 | if(!fDigitsTree) |
3e87ef69 | 321 | if(!GetDigitsTree(event)) return 0; |
a815f9dd | 322 | |
108615fc | 323 | UShort_t dig; |
324 | Int_t time,pad,sector,row; | |
02f030e3 | 325 | Int_t lslice,lrow; |
108615fc | 326 | Int_t nrows=0; |
327 | Int_t ndigitcount=0; | |
a6e4f9d6 | 328 | Int_t entries = (Int_t)fDigitsTree->GetEntries(); |
108615fc | 329 | Int_t ndigits[entries]; |
4499ed26 | 330 | Float_t xyz[3]; |
02f030e3 | 331 | |
332 | for(Int_t r=fRowMin;r<=fRowMax;r++){ | |
333 | Int_t n=fIndex[fSlice][r]; | |
334 | if(n==-1) continue; //no data on that row | |
335 | ||
336 | fDigitsTree->GetEvent(n); | |
337 | fParam->AdjustSectorRow(fDigits->GetID(),sector,row); | |
338 | AliL3Transform::Sector2Slice(lslice,lrow,sector,row); | |
339 | ||
340 | if(lrow!=r){ | |
341 | LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2Memory","Row") | |
342 | <<AliL3Log::kDec<<"Rows dont match "<<lrow<<" "<<r<<ENDLOG; | |
343 | } | |
344 | ||
345 | ndigits[lrow] = 0; | |
346 | fDigits->First(); | |
347 | do { | |
348 | time=fDigits->CurrentRow(); | |
349 | pad=fDigits->CurrentColumn(); | |
350 | dig = fDigits->GetDigit(time,pad); | |
351 | if(dig <= fParam->GetZeroSup()) continue; | |
352 | if(dig >= AliL3Transform::GetADCSat()) | |
353 | dig = AliL3Transform::GetADCSat(); | |
3e87ef69 | 354 | |
02f030e3 | 355 | AliL3Transform::Raw2Local(xyz,sector,row,pad,time); |
356 | if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2])) | |
357 | continue; // why 230??? | |
108615fc | 358 | |
02f030e3 | 359 | ndigits[lrow]++; //for this row only |
360 | ndigitcount++; //total number of digits to be published | |
108615fc | 361 | |
02f030e3 | 362 | } while (fDigits->Next()); |
363 | //cout << lrow << " " << ndigits[lrow] << " - " << ndigitcount << endl; | |
364 | nrows++; | |
365 | } | |
4499ed26 | 366 | |
108615fc | 367 | Int_t size = sizeof(AliL3DigitData)*ndigitcount |
8f1a9904 | 368 | + nrows*sizeof(AliL3DigitRowData); |
108615fc | 369 | |
370 | LOG(AliL3Log::kDebug,"AliL3FileHandler::AliDigits2Memory","Digits") | |
a6e4f9d6 | 371 | <<AliL3Log::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG; |
372 | ||
108615fc | 373 | data=(AliL3DigitRowData*) Allocate(size); |
374 | nrow = (UInt_t)nrows; | |
375 | AliL3DigitRowData *tempPt = data; | |
108615fc | 376 | |
02f030e3 | 377 | for(Int_t r=fRowMin;r<=fRowMax;r++){ |
378 | Int_t n=fIndex[fSlice][r]; | |
379 | ||
380 | if(n==-1) continue; //no data on that row | |
381 | ||
382 | fDigitsTree->GetEvent(n); | |
383 | fParam->AdjustSectorRow(fDigits->GetID(),sector,row); | |
384 | AliL3Transform::Sector2Slice(lslice,lrow,sector,row); | |
385 | if(lrow!=r){ | |
386 | LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2Memory","Row") | |
387 | <<AliL3Log::kDec<<"Rows dont match "<<lrow<<" "<<r<<ENDLOG; | |
388 | } | |
389 | tempPt->fRow = lrow; | |
390 | tempPt->fNDigit = ndigits[lrow]; | |
391 | ||
392 | Int_t localcount=0; | |
393 | fDigits->First(); | |
394 | do { | |
395 | time=fDigits->CurrentRow(); | |
396 | pad=fDigits->CurrentColumn(); | |
397 | dig = fDigits->GetDigit(time,pad); | |
398 | if (dig <= fParam->GetZeroSup()) continue; | |
399 | if(dig >= AliL3Transform::GetADCSat()) | |
400 | dig = AliL3Transform::GetADCSat(); | |
401 | ||
402 | //Exclude data outside cone: | |
403 | AliL3Transform::Raw2Local(xyz,sector,row,pad,time); | |
404 | if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2])) | |
405 | continue; // why 230??? | |
406 | ||
407 | if(localcount >= ndigits[lrow]) | |
408 | LOG(AliL3Log::kFatal,"AliL3FileHandler::AliDigits2Binary","Memory") | |
409 | <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits " | |
410 | <<ndigits[lrow]<<ENDLOG; | |
03b6adf7 | 411 | |
02f030e3 | 412 | tempPt->fDigitData[localcount].fCharge=dig; |
413 | tempPt->fDigitData[localcount].fPad=pad; | |
414 | tempPt->fDigitData[localcount].fTime=time; | |
10f815d9 | 415 | #ifdef do_mc |
02f030e3 | 416 | tempPt->fDigitData[localcount].fTrackID[0] = fDigits->GetTrackID(time,pad,0); |
417 | tempPt->fDigitData[localcount].fTrackID[1] = fDigits->GetTrackID(time,pad,1); | |
418 | tempPt->fDigitData[localcount].fTrackID[2] = fDigits->GetTrackID(time,pad,2); | |
10f815d9 | 419 | #endif |
02f030e3 | 420 | localcount++; |
421 | } while (fDigits->Next()); | |
108615fc | 422 | |
02f030e3 | 423 | Byte_t *tmp = (Byte_t*)tempPt; |
424 | Int_t size = sizeof(AliL3DigitRowData) | |
108615fc | 425 | + ndigits[lrow]*sizeof(AliL3DigitData); |
02f030e3 | 426 | tmp += size; |
427 | tempPt = (AliL3DigitRowData*)tmp; | |
428 | } | |
108615fc | 429 | return data; |
430 | } | |
431 | ||
3e87ef69 | 432 | AliL3DigitRowData * AliL3FileHandler::AliAltroDigits2Memory(UInt_t & nrow,Int_t event,Bool_t eventmerge) |
954beff0 | 433 | { |
434 | //Read data from AliROOT file into memory, and store it in the HLT data format. | |
435 | //Returns a pointer to the data. | |
436 | //This functions filter out single timebins, which is noise. The timebins which | |
437 | //are removed are timebins which have the 4 zero neighbours; | |
438 | //(pad-1,time),(pad+1,time),(pad,time-1),(pad,time+1). | |
439 | ||
440 | AliL3DigitRowData *data = 0; | |
441 | nrow=0; | |
442 | ||
443 | if(!fInAli){ | |
444 | LOG(AliL3Log::kWarning,"AliL3FileHandler::AliAltroDigits2Memory","File") | |
445 | <<"No Input avalible: no object TFile"<<ENDLOG; | |
446 | return 0; | |
447 | } | |
448 | if(!fInAli->IsOpen()){ | |
449 | LOG(AliL3Log::kWarning,"AliL3FileHandler::AliAltroDigits2Memory","File") | |
450 | <<"No Input avalible: TFile not opened"<<ENDLOG; | |
451 | return 0; | |
452 | } | |
3e87ef69 | 453 | if(eventmerge == kTRUE && event >= 1024) |
454 | { | |
455 | LOG(AliL3Log::kError,"AliL3FileHandler::AliAltroDigits2Memory","TrackIDs") | |
456 | <<"Too many events if you want to merge!!"<<ENDLOG; | |
457 | return 0; | |
458 | } | |
459 | ||
954beff0 | 460 | if(!fDigitsTree) |
3e87ef69 | 461 | if(!GetDigitsTree(event)) return 0; |
954beff0 | 462 | |
463 | UShort_t dig; | |
464 | Int_t time,pad,sector,row; | |
465 | Int_t nrows=0; | |
466 | Int_t ndigitcount=0; | |
467 | Int_t entries = (Int_t)fDigitsTree->GetEntries(); | |
468 | Int_t ndigits[entries]; | |
469 | Int_t lslice,lrow; | |
02f030e3 | 470 | Int_t zerosupval=AliL3Transform::GetZeroSup(); |
954beff0 | 471 | Float_t xyz[3]; |
472 | ||
02f030e3 | 473 | for(Int_t r=fRowMin;r<=fRowMax;r++){ |
474 | Int_t n=fIndex[fSlice][r]; | |
475 | if(n==-1) continue; //no data on that row | |
476 | ||
477 | fDigitsTree->GetEvent(n); | |
478 | fParam->AdjustSectorRow(fDigits->GetID(),sector,row); | |
479 | AliL3Transform::Sector2Slice(lslice,lrow,sector,row); | |
480 | ||
481 | if(lrow!=r){ | |
482 | LOG(AliL3Log::kError,"AliL3FileHandler::AliAltroDigits2Memory","Row") | |
483 | <<AliL3Log::kDec<<"Rows dont match "<<lrow<<" "<<r<<ENDLOG; | |
484 | } | |
485 | ||
486 | ndigits[lrow] = 0; | |
487 | fDigits->ExpandBuffer(); | |
488 | fDigits->ExpandTrackBuffer(); | |
489 | for(Int_t i=0; i<fDigits->GetNCols(); i++){ | |
490 | for(Int_t j=0; j<fDigits->GetNRows(); j++){ | |
491 | pad=i; | |
492 | time=j; | |
493 | dig = fDigits->GetDigitFast(time,pad); | |
494 | if(dig <= zerosupval) continue; | |
495 | if(dig >= AliL3Transform::GetADCSat()) | |
496 | dig = AliL3Transform::GetADCSat(); | |
497 | ||
498 | //Check for single timebins, and remove them because they are noise for sure. | |
499 | if(i>0 && i<fDigits->GetNCols()-1 && j>0 && j<fDigits->GetNRows()-1) | |
500 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
501 | fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
502 | fDigits->GetDigitFast(time+1,pad)<=zerosupval && | |
503 | fDigits->GetDigitFast(time,pad+1)<=zerosupval) | |
504 | continue; | |
954beff0 | 505 | |
02f030e3 | 506 | //Boundaries: |
507 | if(i==0) //pad==0 | |
508 | { | |
509 | if(j < fDigits->GetNRows()-1 && j > 0) | |
510 | { | |
511 | if(fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
512 | fDigits->GetDigitFast(time+1,pad)<=zerosupval && | |
513 | fDigits->GetDigitFast(time,pad+1)<=zerosupval) | |
954beff0 | 514 | continue; |
02f030e3 | 515 | } |
516 | else if(j > 0) | |
517 | { | |
518 | if(fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
519 | fDigits->GetDigitFast(time,pad+1)<=zerosupval) | |
954beff0 | 520 | continue; |
521 | } | |
02f030e3 | 522 | } |
523 | if(j==0) | |
524 | { | |
525 | if(i < fDigits->GetNCols()-1 && i > 0) | |
526 | { | |
527 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
528 | fDigits->GetDigitFast(time,pad+1)<=zerosupval && | |
529 | fDigits->GetDigitFast(time+1,pad)<=zerosupval) | |
530 | continue; | |
531 | } | |
532 | else if(i > 0) | |
533 | { | |
534 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
535 | fDigits->GetDigitFast(time+1,pad)<=zerosupval) | |
536 | continue; | |
537 | } | |
538 | } | |
539 | ||
540 | if(i==fDigits->GetNCols()-1) | |
541 | { | |
542 | if(j>0 && j<fDigits->GetNRows()-1) | |
543 | { | |
544 | if(fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
545 | fDigits->GetDigitFast(time+1,pad)<=zerosupval && | |
546 | fDigits->GetDigitFast(time,pad-1)<=zerosupval) | |
547 | continue; | |
548 | } | |
549 | else if(j==0 && j<fDigits->GetNRows()-1) | |
550 | { | |
551 | if(fDigits->GetDigitFast(time+1,pad)<=zerosupval && | |
552 | fDigits->GetDigitFast(time,pad-1)<=zerosupval) | |
553 | continue; | |
554 | } | |
555 | else | |
556 | { | |
557 | if(fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
558 | fDigits->GetDigitFast(time,pad-1)<=zerosupval) | |
559 | continue; | |
560 | } | |
561 | } | |
562 | ||
563 | if(j==fDigits->GetNRows()-1) | |
564 | { | |
565 | if(i>0 && i<fDigits->GetNCols()-1) | |
566 | { | |
567 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
568 | fDigits->GetDigitFast(time,pad+1)<=zerosupval && | |
569 | fDigits->GetDigitFast(time-1,pad)<=zerosupval) | |
570 | continue; | |
571 | } | |
572 | else if(i==0 && fDigits->GetNCols()-1) | |
573 | { | |
574 | if(fDigits->GetDigitFast(time,pad+1)<=zerosupval && | |
575 | fDigits->GetDigitFast(time-1,pad)<=zerosupval) | |
576 | continue; | |
577 | } | |
578 | else | |
579 | { | |
580 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
581 | fDigits->GetDigitFast(time-1,pad)<=zerosupval) | |
582 | continue; | |
583 | } | |
584 | } | |
585 | ||
586 | AliL3Transform::Raw2Local(xyz,sector,row,pad,time); | |
587 | if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2])) | |
588 | continue; | |
954beff0 | 589 | |
02f030e3 | 590 | ndigits[lrow]++; //for this row only |
591 | ndigitcount++; //total number of digits to be published | |
592 | } | |
954beff0 | 593 | } |
02f030e3 | 594 | |
595 | nrows++; | |
596 | } | |
597 | ||
954beff0 | 598 | Int_t size = sizeof(AliL3DigitData)*ndigitcount |
599 | + nrows*sizeof(AliL3DigitRowData); | |
600 | ||
601 | LOG(AliL3Log::kDebug,"AliL3FileHandler::AliAltroDigits2Memory","Digits") | |
602 | <<AliL3Log::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG; | |
603 | ||
604 | data=(AliL3DigitRowData*) Allocate(size); | |
605 | nrow = (UInt_t)nrows; | |
606 | AliL3DigitRowData *tempPt = data; | |
02f030e3 | 607 | |
608 | for(Int_t r=fRowMin;r<=fRowMax;r++){ | |
609 | Int_t n=fIndex[fSlice][r]; | |
610 | if(n==-1) continue; //no data on that row | |
611 | ||
612 | fDigitsTree->GetEvent(n); | |
613 | fParam->AdjustSectorRow(fDigits->GetID(),sector,row); | |
614 | AliL3Transform::Sector2Slice(lslice,lrow,sector,row); | |
615 | ||
616 | if(lrow!=r){ | |
617 | LOG(AliL3Log::kError,"AliL3FileHandler::AliAltroDigits2Memory","Row") | |
618 | <<AliL3Log::kDec<<"Rows dont match "<<lrow<<" "<<r<<ENDLOG; | |
619 | } | |
954beff0 | 620 | |
02f030e3 | 621 | tempPt->fRow = lrow; |
622 | tempPt->fNDigit = ndigits[lrow]; | |
623 | ||
624 | Int_t localcount=0; | |
625 | fDigits->ExpandBuffer(); | |
626 | fDigits->ExpandTrackBuffer(); | |
627 | for(Int_t i=0; i<fDigits->GetNCols(); i++){ | |
628 | for(Int_t j=0; j<fDigits->GetNRows(); j++){ | |
629 | pad=i; | |
630 | time=j; | |
631 | dig = fDigits->GetDigitFast(time,pad); | |
632 | if(dig <= zerosupval) continue; | |
633 | if(dig >= AliL3Transform::GetADCSat()) | |
634 | dig = AliL3Transform::GetADCSat(); | |
954beff0 | 635 | |
02f030e3 | 636 | //Check for single timebins, and remove them because they are noise for sure. |
637 | if(i>0 && i<fDigits->GetNCols()-1 && j>0 && j<fDigits->GetNRows()-1) | |
638 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
639 | fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
640 | fDigits->GetDigitFast(time+1,pad)<=zerosupval && | |
641 | fDigits->GetDigitFast(time,pad+1)<=zerosupval) | |
642 | continue; | |
643 | ||
644 | //Boundaries: | |
645 | if(i==0) //pad ==0 | |
646 | { | |
647 | if(j < fDigits->GetNRows()-1 && j > 0) | |
648 | { | |
649 | if(fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
650 | fDigits->GetDigitFast(time+1,pad)<=zerosupval && | |
651 | fDigits->GetDigitFast(time,pad+1)<=zerosupval) | |
652 | continue; | |
653 | } | |
654 | else if(j > 0) | |
655 | { | |
656 | if(fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
657 | fDigits->GetDigitFast(time,pad+1)<=zerosupval) | |
658 | continue; | |
659 | } | |
660 | } | |
661 | if(j==0) | |
662 | { | |
663 | if(i < fDigits->GetNCols()-1 && i > 0) | |
664 | { | |
665 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
666 | fDigits->GetDigitFast(time,pad+1)<=zerosupval && | |
667 | fDigits->GetDigitFast(time+1,pad)<=zerosupval) | |
668 | continue; | |
669 | } | |
670 | else if(i > 0) | |
671 | { | |
672 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
673 | fDigits->GetDigitFast(time+1,pad)<=zerosupval) | |
674 | continue; | |
675 | } | |
676 | } | |
677 | ||
678 | if(i == fDigits->GetNCols()-1) | |
679 | { | |
680 | if(j>0 && j<fDigits->GetNRows()-1) | |
681 | { | |
682 | if(fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
683 | fDigits->GetDigitFast(time+1,pad)<=zerosupval && | |
684 | fDigits->GetDigitFast(time,pad-1)<=zerosupval) | |
685 | continue; | |
686 | } | |
687 | else if(j==0 && j<fDigits->GetNRows()-1) | |
688 | { | |
689 | if(fDigits->GetDigitFast(time+1,pad)<=zerosupval && | |
690 | fDigits->GetDigitFast(time,pad-1)<=zerosupval) | |
691 | continue; | |
692 | } | |
693 | else | |
694 | { | |
695 | if(fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
696 | fDigits->GetDigitFast(time,pad-1)<=zerosupval) | |
697 | continue; | |
698 | } | |
699 | } | |
700 | if(j==fDigits->GetNRows()-1) | |
701 | { | |
702 | if(i>0 && i<fDigits->GetNCols()-1) | |
703 | { | |
704 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
705 | fDigits->GetDigitFast(time,pad+1)<=zerosupval && | |
706 | fDigits->GetDigitFast(time-1,pad)<=zerosupval) | |
707 | continue; | |
708 | } | |
709 | else if(i==0 && fDigits->GetNCols()-1) | |
710 | { | |
711 | if(fDigits->GetDigitFast(time,pad+1)<=zerosupval && | |
712 | fDigits->GetDigitFast(time-1,pad)<=zerosupval) | |
713 | continue; | |
714 | } | |
715 | else | |
716 | { | |
717 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
718 | fDigits->GetDigitFast(time-1,pad)<=zerosupval) | |
719 | continue; | |
720 | } | |
721 | } | |
722 | ||
723 | AliL3Transform::Raw2Local(xyz,sector,row,pad,time); | |
724 | if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2])) | |
725 | continue; | |
954beff0 | 726 | |
02f030e3 | 727 | if(localcount >= ndigits[lrow]) |
728 | LOG(AliL3Log::kFatal,"AliL3FileHandler::AliAltroDigits2Binary","Memory") | |
729 | <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits " | |
730 | <<ndigits[lrow]<<ENDLOG; | |
731 | ||
732 | tempPt->fDigitData[localcount].fCharge=dig; | |
733 | tempPt->fDigitData[localcount].fPad=pad; | |
734 | tempPt->fDigitData[localcount].fTime=time; | |
954beff0 | 735 | #ifdef do_mc |
02f030e3 | 736 | tempPt->fDigitData[localcount].fTrackID[0] = (fDigits->GetTrackIDFast(time,pad,0)-2); |
737 | tempPt->fDigitData[localcount].fTrackID[1] = (fDigits->GetTrackIDFast(time,pad,1)-2); | |
738 | tempPt->fDigitData[localcount].fTrackID[2] = (fDigits->GetTrackIDFast(time,pad,2)-2); | |
739 | if(eventmerge == kTRUE) //careful track mc info will be touched | |
740 | {//Event are going to be merged, so event number is stored in the upper 10 bits. | |
741 | tempPt->fDigitData[localcount].fTrackID[0] += 128; //leave some room | |
742 | tempPt->fDigitData[localcount].fTrackID[1] += 128; //for neg. numbers | |
743 | tempPt->fDigitData[localcount].fTrackID[2] += 128; | |
744 | tempPt->fDigitData[localcount].fTrackID[0] += ((event&0x3ff)<<22); | |
745 | tempPt->fDigitData[localcount].fTrackID[1] += ((event&0x3ff)<<22); | |
746 | tempPt->fDigitData[localcount].fTrackID[2] += ((event&0x3ff)<<22); | |
747 | } | |
954beff0 | 748 | #endif |
02f030e3 | 749 | localcount++; |
750 | } | |
954beff0 | 751 | } |
02f030e3 | 752 | |
753 | Byte_t *tmp = (Byte_t*)tempPt; | |
754 | Int_t size = sizeof(AliL3DigitRowData) | |
755 | + ndigits[lrow]*sizeof(AliL3DigitData); | |
756 | tmp += size; | |
757 | tempPt = (AliL3DigitRowData*)tmp; | |
758 | } | |
954beff0 | 759 | return data; |
760 | } | |
02f030e3 | 761 | |
a6e4f9d6 | 762 | Bool_t AliL3FileHandler::GetDigitsTree(Int_t event) |
763 | { | |
9183aa27 | 764 | //Connects to the TPC digit tree in the AliROOT file. |
a6e4f9d6 | 765 | |
766 | fInAli->cd(); | |
767 | Char_t dname[100]; | |
5e0f9911 | 768 | sprintf(dname,"TreeD_%s_%d",AliL3Transform::GetParamName(),event); |
a815f9dd | 769 | fDigitsTree = (TTree*)fInAli->Get(dname); |
a6e4f9d6 | 770 | if(!fDigitsTree) |
771 | { | |
772 | LOG(AliL3Log::kError,"AliL3FileHandler::GetDigitsTree","Digits Tree") | |
773 | <<AliL3Log::kHex<<"Error getting digitstree "<<(Int_t)fDigitsTree<<ENDLOG; | |
774 | return kFALSE; | |
775 | } | |
776 | fDigitsTree->GetBranch("Segment")->SetAddress(&fDigits); | |
02f030e3 | 777 | |
778 | return CreateIndex(); | |
a6e4f9d6 | 779 | } |
780 | ||
0d319e67 | 781 | void AliL3FileHandler::AliDigits2RootFile(AliL3DigitRowData *rowPt,Char_t *new_digitsfile) |
782 | { | |
9183aa27 | 783 | //Write the data stored in rowPt, into a new AliROOT file. |
784 | //The data is stored in the AliROOT format | |
785 | //This is specially a nice thing if you have modified data, and wants to run it | |
786 | //through the offline reconstruction chain. | |
787 | //The arguments is a pointer to the data, and the name of the new AliROOT file. | |
788 | //Remember to pass the original AliROOT file (the one that contains the original | |
789 | //simulated data) to this object, in order to retrieve the MC id's of the digits. | |
f6670bec | 790 | |
0d319e67 | 791 | if(!fInAli) |
792 | { | |
8f1a9904 | 793 | printf("AliL3FileHandler::AliDigits2RootFile : No rootfile\n"); |
0d319e67 | 794 | return; |
795 | } | |
796 | if(!fParam) | |
797 | { | |
798 | printf("AliL3FileHandler::AliDigits2RootFile : No parameter object. Run on rootfile\n"); | |
799 | return; | |
800 | } | |
0d319e67 | 801 | |
802 | //Get the original digitstree: | |
6df3cddf | 803 | Char_t dname[100]; |
804 | sprintf(dname,"TreeD_%s_0",AliL3Transform::GetParamName()); | |
805 | ||
0d319e67 | 806 | fInAli->cd(); |
807 | AliTPCDigitsArray *old_array = new AliTPCDigitsArray(); | |
808 | old_array->Setup(fParam); | |
809 | old_array->SetClass("AliSimDigits"); | |
5e0f9911 | 810 | |
5e0f9911 | 811 | Bool_t ok = old_array->ConnectTree(dname); |
0d319e67 | 812 | if(!ok) |
813 | { | |
814 | printf("AliL3FileHandler::AliDigits2RootFile : No digits tree object\n"); | |
815 | return; | |
816 | } | |
6df3cddf | 817 | |
03b6adf7 | 818 | Bool_t create=kFALSE; |
819 | TFile *digFile; | |
820 | ||
f6670bec | 821 | if(gSystem->AccessPathName(new_digitsfile)) |
822 | { | |
823 | cout<<"AliL3FileHandler::AliDigits2RootFile : Creating new file :"<<new_digitsfile<<endl; | |
03b6adf7 | 824 | create = kTRUE; |
f6670bec | 825 | digFile = TFile::Open(new_digitsfile,"RECREATE"); |
03b6adf7 | 826 | fParam->Write(fParam->GetTitle()); |
827 | } | |
828 | else | |
829 | { | |
f6670bec | 830 | create = kFALSE; |
03b6adf7 | 831 | digFile = TFile::Open(new_digitsfile,"UPDATE"); |
f6670bec | 832 | |
03b6adf7 | 833 | } |
834 | if(!digFile->IsOpen()) | |
835 | { | |
8f1a9904 | 836 | LOG(AliL3Log::kError,"AliL3FileHandler::AliDigits2RootFile","Rootfile") |
837 | <<"Error opening rootfile "<<new_digitsfile<<ENDLOG; | |
03b6adf7 | 838 | return; |
839 | } | |
840 | ||
841 | digFile->cd(); | |
842 | ||
843 | //setup a new one, or connect it to the existing one: | |
6df3cddf | 844 | AliTPCDigitsArray *arr = new AliTPCDigitsArray(); |
0d319e67 | 845 | arr->SetClass("AliSimDigits"); |
846 | arr->Setup(fParam); | |
03b6adf7 | 847 | if(create) |
848 | arr->MakeTree(); | |
849 | else | |
850 | { | |
5e0f9911 | 851 | Bool_t ok = arr->ConnectTree(dname); |
03b6adf7 | 852 | if(!ok) |
853 | { | |
854 | printf("AliL3FileHandler::AliDigits2RootFile : No digits tree object in existing file\n"); | |
855 | return; | |
856 | } | |
857 | } | |
6df3cddf | 858 | Int_t digcounter=0,trackID[3]; |
49898c33 | 859 | |
0d319e67 | 860 | for(Int_t i=fRowMin; i<=fRowMax; i++) |
861 | { | |
03b6adf7 | 862 | |
6df3cddf | 863 | if((Int_t)rowPt->fRow != i) |
864 | cerr<<"AliL3FileHandler::AliDigits2RootFile : Mismatching row numbering!!!"<<endl; | |
03b6adf7 | 865 | |
0d319e67 | 866 | Int_t sector,row; |
494fad94 | 867 | AliL3Transform::Slice2Sector(fSlice,i,sector,row); |
6df3cddf | 868 | |
49898c33 | 869 | AliSimDigits *old_dig = (AliSimDigits*)old_array->LoadRow(sector,row); |
6df3cddf | 870 | AliSimDigits * dig = (AliSimDigits*)arr->CreateRow(sector,row); |
871 | old_dig->ExpandBuffer(); | |
872 | old_dig->ExpandTrackBuffer(); | |
873 | dig->ExpandBuffer(); | |
874 | dig->ExpandTrackBuffer(); | |
875 | ||
0d319e67 | 876 | if(!old_dig) |
6df3cddf | 877 | printf("AliL3FileHandler::AliDigits2RootFile : No padrow %d %d\n",sector,row); |
0d319e67 | 878 | |
879 | AliL3DigitData *digPt = rowPt->fDigitData; | |
54efe57a | 880 | digcounter=0; |
0d319e67 | 881 | for(UInt_t j=0; j<rowPt->fNDigit; j++) |
882 | { | |
6df3cddf | 883 | Short_t charge = (Short_t)digPt[j].fCharge; |
49898c33 | 884 | Int_t pad = (Int_t)digPt[j].fPad; |
885 | Int_t time = (Int_t)digPt[j].fTime; | |
03b6adf7 | 886 | |
887 | if(charge == 0) //Only write the digits that has not been removed | |
6df3cddf | 888 | { |
889 | cerr<<"AliL3FileHandler::AliDigits2RootFile : Zero charge!!! "<<endl; | |
890 | continue; | |
891 | } | |
892 | ||
54efe57a | 893 | digcounter++; |
49898c33 | 894 | |
6df3cddf | 895 | //Tricks to get and set the correct track id's. |
896 | for(Int_t t=0; t<3; t++) | |
97543115 | 897 | { |
6df3cddf | 898 | Int_t label = old_dig->GetTrackIDFast(time,pad,t); |
899 | if(label > 1) | |
900 | trackID[t] = label - 2; | |
901 | else if(label==0) | |
902 | trackID[t] = -2; | |
903 | else | |
904 | trackID[t] = -1; | |
49898c33 | 905 | } |
6df3cddf | 906 | |
907 | dig->SetDigitFast(charge,time,pad); | |
908 | ||
909 | for(Int_t t=0; t<3; t++) | |
910 | ((AliSimDigits*)dig)->SetTrackIDFast(trackID[t],time,pad,t); | |
0d319e67 | 911 | |
912 | } | |
54efe57a | 913 | //cout<<"Wrote "<<digcounter<<" on row "<<i<<endl; |
0d319e67 | 914 | UpdateRowPointer(rowPt); |
915 | arr->StoreRow(sector,row); | |
916 | arr->ClearRow(sector,row); | |
917 | old_array->ClearRow(sector,row); | |
918 | } | |
919 | digFile->cd(); | |
920 | char treeName[100]; | |
03b6adf7 | 921 | sprintf(treeName,"TreeD_%s_0",fParam->GetTitle()); |
6df3cddf | 922 | |
923 | arr->GetTree()->SetName(treeName); | |
924 | arr->GetTree()->AutoSave(); | |
925 | delete arr; | |
926 | delete old_array; | |
0d319e67 | 927 | digFile->Close(); |
6df3cddf | 928 | |
0d319e67 | 929 | } |
930 | ||
108615fc | 931 | ///////////////////////////////////////// Point IO |
3e87ef69 | 932 | Bool_t AliL3FileHandler::AliPoints2Binary(Int_t eventn){ |
108615fc | 933 | Bool_t out = kTRUE; |
934 | UInt_t npoint; | |
3e87ef69 | 935 | AliL3SpacePointData *data = AliPoints2Memory(npoint,eventn); |
108615fc | 936 | out = Memory2Binary(npoint,data); |
937 | Free(); | |
938 | return out; | |
939 | } | |
940 | ||
3e87ef69 | 941 | AliL3SpacePointData * AliL3FileHandler::AliPoints2Memory(UInt_t & npoint,Int_t eventn){ |
108615fc | 942 | AliL3SpacePointData *data = 0; |
943 | npoint=0; | |
944 | if(!fInAli){ | |
945 | LOG(AliL3Log::kWarning,"AliL3FileHandler::AliPoints2Memory","File") | |
946 | <<"No Input avalible: no object TFile"<<ENDLOG; | |
947 | return 0; | |
948 | } | |
949 | if(!fInAli->IsOpen()){ | |
950 | LOG(AliL3Log::kWarning,"AliL3FileHandler::AliPoints2Memory","File") | |
951 | <<"No Input avalible: TFile not opend"<<ENDLOG; | |
952 | return 0; | |
953 | } | |
494fad94 | 954 | |
108615fc | 955 | TDirectory *savedir = gDirectory; |
956 | fInAli->cd(); | |
8f1a9904 | 957 | |
958 | Char_t cname[100]; | |
8f1a9904 | 959 | sprintf(cname,"TreeC_TPC_%d",eventn); |
108615fc | 960 | AliTPCClustersArray carray; |
961 | carray.Setup(fParam); | |
962 | carray.SetClusterType("AliTPCcluster"); | |
8f1a9904 | 963 | Bool_t clusterok = carray.ConnectTree(cname); |
108615fc | 964 | if(!clusterok) return 0; |
965 | ||
966 | AliTPCClustersRow ** clusterrow = | |
967 | new AliTPCClustersRow*[ (int)carray.GetTree()->GetEntries()]; | |
968 | Int_t *rows = new int[ (int)carray.GetTree()->GetEntries()]; | |
969 | Int_t *sects = new int[ (int)carray.GetTree()->GetEntries()]; | |
970 | Int_t sum=0; | |
971 | ||
972 | Int_t lslice,lrow; | |
973 | for(Int_t i=0; i<carray.GetTree()->GetEntries(); i++){ | |
974 | AliSegmentID *s = carray.LoadEntry(i); | |
975 | Int_t sector,row; | |
976 | fParam->AdjustSectorRow(s->GetID(),sector,row); | |
977 | rows[i] = row; | |
978 | sects[i] = sector; | |
979 | clusterrow[i] = 0; | |
494fad94 | 980 | AliL3Transform::Sector2Slice(lslice,lrow,sector,row); |
108615fc | 981 | if(fSlice != lslice || lrow<fRowMin || lrow>fRowMax) continue; |
982 | clusterrow[i] = carray.GetRow(sector,row); | |
983 | if(clusterrow[i]) | |
984 | sum+=clusterrow[i]->GetArray()->GetEntriesFast(); | |
985 | } | |
986 | UInt_t size = sum*sizeof(AliL3SpacePointData); | |
987 | ||
988 | LOG(AliL3Log::kDebug,"AliL3FileHandler::AliPoints2Memory","File") | |
989 | <<AliL3Log::kDec<<"Found "<<sum<<" SpacePoints"<<ENDLOG; | |
990 | ||
991 | data = (AliL3SpacePointData *) Allocate(size); | |
992 | npoint = sum; | |
993 | UInt_t n=0; | |
3e87ef69 | 994 | Int_t pat=fPatch; |
995 | if(fPatch==-1) | |
996 | pat=0; | |
108615fc | 997 | for(Int_t i=0; i<carray.GetTree()->GetEntries(); i++){ |
998 | if(!clusterrow[i]) continue; | |
999 | Int_t row = rows[i]; | |
1000 | Int_t sector = sects[i]; | |
494fad94 | 1001 | AliL3Transform::Sector2Slice(lslice,lrow,sector,row); |
108615fc | 1002 | Int_t entries_in_row = clusterrow[i]->GetArray()->GetEntriesFast(); |
1003 | for(Int_t j = 0;j<entries_in_row;j++){ | |
1004 | AliTPCcluster *c = (AliTPCcluster*)(*clusterrow[i])[j]; | |
1005 | data[n].fZ = c->GetZ(); | |
1006 | data[n].fY = c->GetY(); | |
1007 | data[n].fX = fParam->GetPadRowRadii(sector,row); | |
8e348d6a | 1008 | data[n].fCharge = (UInt_t)c->GetQ(); |
3e87ef69 | 1009 | data[n].fID = n+((fSlice&0x7f)<<25)+((pat&0x7)<<22);//uli |
108615fc | 1010 | data[n].fPadRow = lrow; |
3e87ef69 | 1011 | data[n].fSigmaY2 = c->GetSigmaY2(); |
1012 | data[n].fSigmaZ2 = c->GetSigmaZ2(); | |
1013 | #ifdef do_mc | |
1014 | data[n].fTrackID[0] = c->GetLabel(0); | |
1015 | data[n].fTrackID[1] = c->GetLabel(1); | |
1016 | data[n].fTrackID[2] = c->GetLabel(2); | |
1017 | #endif | |
108615fc | 1018 | if(fMC) fprintf(fMC,"%d %d\n",data[n].fID,c->GetLabel(0)); |
1019 | n++; | |
1020 | } | |
1021 | } | |
1022 | for(Int_t i=0;i<carray.GetTree()->GetEntries();i++){ | |
1023 | Int_t row = rows[i]; | |
1024 | Int_t sector = sects[i]; | |
1025 | if(carray.GetRow(sector,row)) | |
1026 | carray.ClearRow(sector,row); | |
1027 | } | |
1028 | ||
1029 | delete [] clusterrow; | |
1030 | delete [] rows; | |
1031 | delete [] sects; | |
1032 | savedir->cd(); | |
1033 | ||
1034 | return data; | |
1035 | } | |
1036 |