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