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