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