]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSIndexToObject.cxx
comments added
[u/mrichter/AliRoot.git] / PHOS / AliPHOSIndexToObject.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id:  */
17
18 //_________________________________________________________________________
19 //  A singleton. This class should be used in the analysis stage to get 
20 //  reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles,
21 //  instead of directly reading them from galice.root file. This container 
22 //  ensures, that one reads Digits, made of these particular digits, RecPoints, 
23 //  made of these particular RecPoints, TrackSegments and RecParticles. 
24 //  This becomes non trivial if there are several identical branches, produced with
25 //  different set of parameters. 
26 //
27 //  An example of how to use (see also class AliPHOSAnalyser):
28 //  AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance("galice.root","RecParticles","") ;
29 //  for(Int_t irecp = 0; irecp < please->GimeNRecParticles() ; irecp++)
30 //     AliPHOSRecParticle * part = please->GimeRecParticle(1) ;
31 //     ................
32 //  please->GetEvent(event) ;    // reads new event from galice.root
33 //                  
34 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
35 //*--         Complitely redesigned by Dmitri Peressounko March 2001  
36 //////////////////////////////////////////////////////////////////////////////
37
38
39 // --- ROOT system ---
40
41 #include "TFile.h"
42 #include "TTree.h"
43 #include "TROOT.h"
44 #include "TObjString.h"
45
46 // --- Standard library ---
47 #include <iostream.h>
48
49 // --- AliRoot header files ---
50
51 #include "AliRun.h"
52 #include "AliPHOSIndexToObject.h"
53 #include "AliPHOSDigitizer.h"
54 #include "AliPHOSSDigitizer.h"
55 #include "AliPHOSClusterizer.h"
56 #include "AliPHOSClusterizerv1.h"
57 #include "AliPHOSTrackSegmentMaker.h"
58 #include "AliPHOSTrackSegmentMakerv1.h"
59 #include "AliPHOSTrackSegment.h"
60 #include "AliPHOSPID.h" 
61 #include "AliPHOSPIDv1.h" 
62
63 ClassImp(AliPHOSIndexToObject)
64   
65   AliPHOSIndexToObject * AliPHOSIndexToObject::fgObjGetter = 0 ; 
66
67 //____________________________________________________________________________ 
68 AliPHOSIndexToObject::AliPHOSIndexToObject(const char* headerFile,const char* branch,const char* branchTitle )
69 {
70   //Initialize  all lists
71   fEvent = 0 ;
72
73   fSDigits = new TClonesArray("AliPHOSDigit",100) ;
74   fDigits  = new TClonesArray("AliPHOSDigit",100) ;
75   fEmcRecPoints = new TObjArray(100) ;
76   fCpvRecPoints = new TObjArray(100) ;
77   fTS = new TClonesArray("AliPHOSTrackSegment",100) ;
78   fRecParticles = new TClonesArray("AliPHOSRecParticle",100) ;
79   fPrimaries = new TObjArray(1) ;
80
81   fSDigitizer = 0 ;
82   fDigitizer = 0 ;
83   fClusterizer = 0 ;
84   fTSMaker = 0 ;
85   fPID = 0 ;
86
87   //open headers file
88   fHeaderFile = headerFile ;
89   TFile * file = (TFile*) gROOT->GetFile(fHeaderFile.Data() ) ;
90
91   if(file == 0){
92     if(fHeaderFile.Contains("rfio")) // if we read file using HPSS
93       file =    TFile::Open(fHeaderFile.Data(),"update") ;
94     else
95       file = new TFile(fHeaderFile.Data(),"update") ;
96     gAlice = (AliRun *) file->Get("gAlice") ;
97   }
98
99   fMaxEvent = (Int_t) gAlice->TreeE()->GetEntries() ;
100
101   DefineBranchTitles(branch,branchTitle) ;
102
103   //Now read all data from trees
104   fEvent = -1 ;
105   GetEvent(0) ;
106
107 }
108 //____________________________________________________________________________ 
109 void AliPHOSIndexToObject:: DefineBranchTitles(const char* startBranch,const char* branchTitle)
110 {
111   // Points to the branches of all reconstructed objects with the specified names
112   gAlice->GetEvent(0) ;
113   // Read all reconstruction classes to extract titles of 
114   // branches, constituing "reconstruction branch"
115   AliPHOSPID * pids[50];  // here AliPHOSPID's will be stored
116   Int_t ipids = 0 ;
117   AliPHOSTrackSegmentMaker * tsms[50] ; 
118   Int_t itsms = 0 ;
119   AliPHOSClusterizer * clus[50] ;   
120   Int_t iclus = 0 ;
121   AliPHOSDigitizer * digs[50]; 
122   Int_t idigs = 0 ;
123   AliPHOSSDigitizer * sdigs[50];
124   Int_t isdigs = 0 ;
125   
126   //read TreeR
127   TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
128   Int_t ibranch;
129   TBranch * branch ;
130   for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
131     branch=(TBranch *) branches->At(ibranch) ;
132     if( (strcmp(branch->GetName(),"AliPHOSPID") == 0) ){
133       pids[ipids] =  new  AliPHOSPIDv1() ;
134       branch->SetAddress(& (pids[ipids])) ;
135       ipids++ ;
136     }
137     if( (strcmp(branch->GetName(),"AliPHOSTrackSegmentMaker") == 0) ){
138       tsms[itsms] = new  AliPHOSTrackSegmentMakerv1() ;
139       branch->SetAddress(&(tsms[itsms])) ;
140       itsms++ ;
141     }
142     if( (strcmp(branch->GetName(),"AliPHOSClusterizer") == 0) ){
143       clus[iclus] = new  AliPHOSClusterizerv1() ;
144       branch->SetAddress(&(clus[iclus])) ;
145       iclus++ ;
146     }
147   }
148   gAlice->TreeR()->GetEvent(0) ;
149
150
151   //read TreeD
152   branches = gAlice->TreeD()->GetListOfBranches() ;
153   for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
154     branch=(TBranch *) branches->At(ibranch) ;
155     if( (strcmp(branch->GetName(),"AliPHOSDigitizer") == 0) ){
156       digs[idigs] = new  AliPHOSDigitizer() ;
157       branch->SetAddress(&(digs[idigs])) ;
158       idigs++ ;
159     }
160   }
161   gAlice->TreeD()->GetEvent(0) ;
162
163   //read TreeS
164   branches = gAlice->TreeS()->GetListOfBranches() ;
165   for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
166     branch=(TBranch *) branches->At(ibranch) ;
167     if( (strcmp(branch->GetName(),"AliPHOSSDigitizer") == 0) ){
168       sdigs[isdigs] = new  AliPHOSSDigitizer() ;
169       branch->SetAddress(&(sdigs[isdigs])) ;
170       isdigs++ ;
171     }
172   }
173   gAlice->TreeS()->GetEvent(0) ;
174
175   // now choose among read Reconstruction classes those,
176   // which constituite "reconstruction branch"
177   Bool_t pidDefined = kFALSE ;
178   Bool_t tsmDefined = kFALSE ;
179   Bool_t cluDefined = kFALSE ;
180   Bool_t digDefined = kFALSE ;
181   Bool_t sdigDefined = kFALSE ;
182
183   Int_t index ;
184   // First, go from the end (RecParticles) to the beginning(SDigits)
185   if((strcmp(startBranch,"PHOSRP") == 0)||(strcmp(startBranch,"AliPHOSPID") == 0)){
186     fRPTitle = branchTitle ;
187     for(index = 0; index < ipids ; index++){
188       if(fRPTitle.CompareTo(((AliPHOSPID*)pids[index])->GetRecParticlesBranch())== 0){
189         pidDefined = kTRUE ;
190         fTSTitle =((AliPHOSPID*)pids[index])->GetTrackSegmentsBranch() ; 
191       }
192     }
193   }
194   if((strcmp(startBranch,"PHOSTS") == 0)||(strcmp(startBranch,"AliPHOSTrackSegmentMaker") == 0)|| pidDefined ) {
195     if(!pidDefined)
196       fTSTitle = branchTitle ;
197     for(index = 0; index < itsms ; index++)
198       if(fTSTitle.CompareTo(((AliPHOSTrackSegmentMaker*)tsms[index])->GetTrackSegmentsBranch())== 0){
199         tsmDefined = kTRUE ;
200         fRecPointsTitle =((AliPHOSTrackSegmentMaker*)tsms[index])->GetRecPointsBranch() ;
201       }
202   }
203   if((strcmp(startBranch,"PHOSEmcRP") == 0) || 
204      (strcmp(startBranch,"PHOSCpvRP") == 0) ||
205      (strcmp(startBranch,"AliPHOSClusterizer") == 0)  || tsmDefined ) {
206     if(!tsmDefined)
207       fRecPointsTitle = branchTitle ;
208     for(index = 0; index < iclus ; index++)
209       if(fRecPointsTitle.CompareTo(((AliPHOSClusterizer*)clus[index])->GetRecPointsBranch())== 0){
210         cluDefined = kTRUE ;
211         fDigitsTitle =((AliPHOSClusterizer*)clus[index])->GetDigitsBranch() ;
212       }
213   }
214   if((strcmp(startBranch,"PHOS") == 0) || (strcmp(startBranch,"AliPHOSDigitizer") == 0) ||cluDefined ) {
215     if(!cluDefined)
216       fDigitsTitle = branchTitle ; 
217     for(index = 0; index < idigs ; index++)
218       if(fDigitsTitle.CompareTo(((AliPHOSDigitizer*)digs[index])->GetDigitsBranch())== 0){
219         digDefined = kTRUE ;
220         fSDigitsTitle =((AliPHOSDigitizer*)digs[index])->GetSDigitsBranch() ;
221       }
222   }
223   for(index = 0; index < idigs ; index++)
224     if(fSDigitsTitle.CompareTo(((AliPHOSSDigitizer*)sdigs[index])->GetSDigitsBranch())== 0)
225       sdigDefined = kTRUE ;
226   
227   if(!sdigDefined){
228     cout << "Can not define titles of branches " << endl ;
229     cout << endl ;
230   }
231
232   // Now we go in the inverse direction: from sdigits to recparticles - for the 
233   // case, if we started decending not from RecParticles, but e.g. from digits
234
235   if( !cluDefined ) {
236     for(index = 0; index < iclus ; index++)
237       if(fDigitsTitle.CompareTo(((AliPHOSClusterizer*)clus[index])->GetDigitsBranch())== 0){
238         cluDefined = kTRUE ;
239         fRecPointsTitle =((AliPHOSClusterizer*)clus[index])->GetRecPointsBranch() ;
240       }
241   }
242   if(! tsmDefined ) {
243     for(index = 0; index < itsms ; index++)
244       if(fRecPointsTitle.CompareTo(((AliPHOSTrackSegmentMaker*)tsms[index])->GetRecPointsBranch())== 0){
245         tsmDefined = kTRUE ;
246         fTSTitle =((AliPHOSTrackSegmentMaker*)tsms[index])->GetTrackSegmentsBranch() ;
247       }
248   }
249   if(!pidDefined){
250     for(index = 0; index < ipids ; index++)
251       if(fTSTitle.CompareTo(((AliPHOSPID*)pids[index])->GetTrackSegmentsBranch())== 0){
252         pidDefined = kTRUE ;
253         fRPTitle = ((AliPHOSPID*)pids[index])->GetRecParticlesBranch() ;
254       }
255   }
256   
257   //delete created objects
258   for(index = 0; index < ipids ; index++)
259     delete pids[index] ;
260   for(index = 0; index < itsms ; index++)
261     delete tsms[index] ;
262   for(index = 0; index < iclus ; index++)
263     delete clus[index] ;
264   for(index = 0; index < idigs ; index++) 
265     delete digs[index] ;
266   for(index = 0; index < isdigs ; index++) 
267     delete sdigs[index] ;
268   
269 }
270 //____________________________________________________________________________ 
271 AliPHOSIndexToObject * AliPHOSIndexToObject::GetInstance()
272 {
273   // Returns the pointer of the unique instance already defined
274   
275   AliPHOSIndexToObject * rv = 0 ;
276   if ( fgObjGetter )
277     rv = fgObjGetter ;
278   else
279     cout << "AliPHOSIndexToObject::GetInstance ERROR: not yet initialized" << endl ;
280
281   return rv ;
282 }
283
284 //____________________________________________________________________________ 
285 AliPHOSIndexToObject * AliPHOSIndexToObject::GetInstance(const char* headerFile,
286                                                          const char* branch,
287                                                          const char* branchTitle)
288 {
289   // Creates and returns the pointer of the unique instance
290   // Must be called only when the environment has changed 
291
292   if(strcmp(branch,"PHOSRP") && strcmp(branch,"AliPHOSPID") &&
293      strcmp(branch,"PHOSTS") && strcmp(branch,"AliPHOSTrackSegmentMaker") && 
294      strcmp(branch,"PHOSEmcRP") && strcmp(branch,"PHOSCpvRP") && strcmp(branch,"AliPHOSClusterizer") &&
295      strcmp(branch,"PHOS") && strcmp(branch,"AliPHOSDigitizer") ){
296     
297     cout << "AliPHOSIndexToObject: wrong branch name specified: " << branch << endl ;
298     cout << "   avalilable names are `PHOSRP', `AliPHOSPID'"<<endl ;
299     cout << "                        `PHOSTS', `AliPHOSTrackSegmentMaker'"<<endl ;
300     cout << "                        `PHOSEmcRP', `PHOSCpvRP', `AliPHOSClusterizer'"<< endl ;
301     cout << "                        `PHOS' and `AliPHOSDigitizer'"<< endl ;
302     return 0 ;
303   }
304
305
306   if ( fgObjGetter )      // delete it if already exists
307     delete fgObjGetter ; 
308
309   fgObjGetter = new AliPHOSIndexToObject(headerFile,branch,branchTitle) ; 
310   
311   return fgObjGetter ; 
312   
313 }
314
315 //____________________________________________________________________________ 
316 TParticle * AliPHOSIndexToObject::GimePrimary(Int_t index)
317 {
318   // retrieves the primary particle indexed by index  
319   if(index < 0) 
320     return 0 ;
321   
322   Int_t primaryIndex = index % 10000000 ; 
323   Int_t primaryList = (Int_t ) ((index-primaryIndex)/10000000.)  ;
324   
325   if ( primaryList > 0  ) {
326     cout << " IndexToObject does not support currently Mixing of primary " << endl ;
327     cout << "   can not return primary: " << index<< " (list "<< primaryList<< " primary # " << primaryIndex << " )"<<endl ;
328     return 0;
329   }
330   
331   return gAlice->Particle(primaryIndex) ;
332   
333 }
334
335 //____________________________________________________________________________ 
336 void AliPHOSIndexToObject::ReadTreeD(){
337   
338   if(gAlice->TreeD()== 0){
339     cout << "AliPHOSIndexToObject : can not read TreeD " << endl;
340     return ;
341   }
342   
343   TBranch * digitsBranch = 0;
344   TBranch * digitizerBranch = 0;
345   
346   TObjArray * branches = gAlice->TreeD()->GetListOfBranches() ;
347   Int_t ibranch;
348   Bool_t phosNotFound = kTRUE ;
349   Bool_t digitizerNotFound = kTRUE ;
350   
351   for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
352     
353     if(phosNotFound){
354       digitsBranch=(TBranch *) branches->At(ibranch) ;
355       if( (strcmp(digitsBranch->GetTitle(),fDigitsTitle)==0 ) &&
356           (strcmp(digitsBranch->GetName(),"PHOS") == 0) )
357         phosNotFound = kFALSE ;
358     }
359     if(digitizerNotFound){
360       digitizerBranch = (TBranch *) branches->At(ibranch) ;
361       if( (strcmp(digitizerBranch->GetTitle(),fDigitsTitle) == 0) && 
362           (strcmp(digitizerBranch->GetName(),"AliPHOSDigitizer") == 0) )
363         digitizerNotFound = kFALSE ;
364     } 
365   }
366     
367   if(digitizerNotFound || phosNotFound){
368     cout << "AliPHOSIndexToObject error: " << endl ;
369     cout << "       Can't find Branch with Digits or Digitizer "<< endl ; ;
370     return  ;
371   }
372   
373   digitsBranch->SetAddress(&fDigits) ;
374   digitizerBranch->SetAddress(&fDigitizer) ;
375   
376   gAlice->TreeD()->GetEvent(0) ;
377   
378 }
379 //____________________________________________________________________________ 
380 void AliPHOSIndexToObject::ReadTreeS()
381 {
382   // Reads the contents of SDigits  
383   if(gAlice->TreeS()== 0){
384     cout <<   "AliPHOSIndexToObject: can not read TreeS " << endl ;
385     return ;
386   }
387   
388   TBranch * sdigitsBranch = 0;
389   TBranch * sdigitizerBranch = 0;
390   
391   TObjArray * branches = gAlice->TreeS()->GetListOfBranches() ;
392   Int_t ibranch;
393   Bool_t phosNotFound = kTRUE ;
394   Bool_t sdigitizerNotFound = kTRUE ;
395   
396   for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
397     
398     if(phosNotFound){
399       sdigitsBranch=(TBranch *) branches->At(ibranch) ;
400       if( (strcmp(sdigitsBranch->GetTitle(),fSDigitsTitle)==0 ) &&
401           (strcmp(sdigitsBranch->GetName(),"PHOS") == 0) )
402         phosNotFound = kFALSE ;
403     }
404     if(sdigitizerNotFound){
405       sdigitizerBranch = (TBranch *) branches->At(ibranch) ;
406       if( (strcmp(sdigitizerBranch->GetTitle(),fSDigitsTitle) == 0) && 
407           (strcmp(sdigitizerBranch->GetName(),"AliPHOSSDigitizer") == 0) )
408         sdigitizerNotFound = kFALSE ;
409     } 
410   }
411   
412   if(sdigitizerNotFound || phosNotFound){
413     cout << "AliPHOSIndexToObject error: " << endl ;
414     cout << "       Can't find Branch with SDigits or SDigitizer "<< endl ; ;
415     return ;
416   }
417   
418   sdigitsBranch->SetAddress(&fSDigits) ;
419   sdigitizerBranch->SetAddress(&fSDigitizer) ;
420   
421   gAlice->TreeS()->GetEvent(0) ;
422   
423 }
424 //____________________________________________________________________________ 
425 void AliPHOSIndexToObject::ReadTreeR()
426 {
427   // Reads the contents of reconstruction Tree
428   
429   if(gAlice->TreeR()== 0){
430     cout <<   "AliPHOSIndexToObject: can not read TreeR " << endl ;
431     return ;
432   }
433
434   TBranch * pidBranch = 0;
435   TBranch * rpBranch = 0;
436   TBranch * tsMakerBranch = 0;
437   TBranch * tsBranch = 0;
438   TBranch * emcBranch = 0;
439   TBranch * cpvBranch = 0;
440   TBranch * clusterizerBranch = 0;
441   
442   TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
443   Int_t ibranch;
444   Bool_t pidNotFound = kTRUE ;
445   Bool_t rpNotFound = kTRUE ;
446   Bool_t tsMakerNotFound = kTRUE ;
447   Bool_t tsNotFound = kTRUE ;
448   Bool_t emcNotFound = kTRUE ;
449   Bool_t cpvNotFound = kTRUE ;  
450   Bool_t clusterizerNotFound = kTRUE ;
451   
452   for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
453     
454     if(pidNotFound){
455       pidBranch=(TBranch *) branches->At(ibranch) ;
456       if( (fRPTitle.CompareTo(pidBranch->GetTitle())==0 ) &&
457           (strcmp(pidBranch->GetName(),"AliPHOSPID") == 0) )
458         pidNotFound = kFALSE ;
459     }
460     if(rpNotFound){
461       rpBranch=(TBranch *) branches->At(ibranch) ;
462       if( (fRPTitle.CompareTo(rpBranch->GetTitle())==0 ) &&
463           (strcmp(rpBranch->GetName(),"PHOSRP") == 0) )
464         rpNotFound = kFALSE ;
465     }
466     if(tsMakerNotFound){
467       tsMakerBranch=(TBranch *) branches->At(ibranch) ;
468       if( fTSTitle.CompareTo(tsMakerBranch->GetTitle())==0 )
469         if( strcmp(tsMakerBranch->GetName(),"AliPHOSTrackSegmentMaker") == 0) 
470           tsMakerNotFound = kFALSE ;
471     }
472     if(tsNotFound){
473       tsBranch=(TBranch *) branches->At(ibranch) ;
474       if( fTSTitle.CompareTo(tsBranch->GetTitle())==0 )
475         if( strcmp(tsBranch->GetName(),"PHOSTS") == 0) 
476           tsNotFound = kFALSE ;
477     }  
478     if(emcNotFound){
479       emcBranch=(TBranch *) branches->At(ibranch) ;
480       if( (fRecPointsTitle.CompareTo(emcBranch->GetTitle()) == 0) && 
481           (strcmp(emcBranch->GetName(),"PHOSEmcRP") == 0) )
482         emcNotFound = kFALSE ;
483     }
484     if(cpvNotFound){
485       cpvBranch=(TBranch *) branches->At(ibranch) ;
486       if( (fRecPointsTitle.CompareTo(cpvBranch->GetTitle()) == 0) &&
487           (strcmp(cpvBranch->GetName(),"PHOSCpvRP") == 0) )
488         cpvNotFound = kFALSE ;
489     }
490     if(clusterizerNotFound){
491       clusterizerBranch = (TBranch *) branches->At(ibranch) ;
492       if( (fRecPointsTitle.CompareTo(clusterizerBranch->GetTitle()) == 0) &&
493           (strcmp(clusterizerBranch->GetName(),"AliPHOSClusterizer") == 0) )
494         clusterizerNotFound = kFALSE ;
495     }
496   }
497
498   if(pidNotFound ||rpNotFound ){
499     cout << "AliPHOSIndexToObject error" << endl ;
500     cout << "     Can't find Branch with PID and RecParticles " ;
501     return  ;
502   }
503   if(tsMakerNotFound ||tsNotFound ){
504     cout << "AliPHOSIndexToObject error" << endl ;
505     cout << "       Can't find Branch with TrackSegmentMaker and TrackSegments " ;
506     cout << "       Do nothing" <<endl  ;
507     return ;
508   }
509   if(clusterizerNotFound || emcNotFound || cpvNotFound){
510     cout << "AliPHOSIndexToObject error" << endl ;
511     cout << "       Can't find Branch with RecPoints or Clusterizer " << endl ;
512     return ;
513   }
514
515   emcBranch->SetAddress(&fEmcRecPoints) ;
516   cpvBranch->SetAddress(&fCpvRecPoints) ;
517   clusterizerBranch->SetAddress(&fClusterizer) ;
518   
519   tsMakerBranch->SetAddress(&fTSMaker) ;
520   tsBranch->SetAddress(&fTS) ;
521     
522   pidBranch->SetAddress(&fPID) ;
523   rpBranch->SetAddress(&fRecParticles) ;
524   
525   gAlice->TreeR()->GetEvent(0) ;    
526
527 }
528 //____________________________________________________________________________ 
529 void AliPHOSIndexToObject::ReadPrimaries()
530 {
531   // Reads specific branches of primaries
532   
533   fNPrimaries = gAlice->GetNtrack();
534   
535   //   //Check, is it necessary to open new files
536   //   TArrayI* events = fDigitizer->GetCurrentEvents() ; 
537   //   TClonesArray * filenames = fDigitizer->GetHeadersFiles() ;
538 //   Int_t input ;
539 //   for(input = 0; input < filenames->GetEntriesFast(); input++){
540
541 //     TObjString * filename = (TObjString *) filenames->At(input) ;
542
543 //     //Test, if this file already open
544 //     TFile *file = (TFile*) gROOT->GetFile( filename->GetString() ) ;
545 //     if(file == 0)
546 //       file = new TFile( filename->GetString()) ;
547 //     file->cd() ;
548     
549 //     // Get Kine Tree from file
550 // //     char treeName[20];
551 // //     sprintf(treeName,"TreeK%d",events->At(input));
552 // //     TTree * treeK = (TTree*)gDirectory->Get(treeName);
553 // //     if (treeK) 
554 // //       treeK->SetBranchAddress("Particles", &fParticleBuffer);
555 // //     else    
556 // //       cout << "AliPHOSIndexToObject: cannot find Kine Tree for event:" << events->At(input) << endl;
557
558 // //     // Create the particle stack
559 // //     if(!fParticles) fParticles = new TClonesArray("TParticle",1000);
560 // //     // Build the pointer list
561 // //     if(fParticleMap) {     <----
562 // //       fParticleMap->Clear();
563 // //       fParticleMap->Expand(treeK->GetEntries());
564 // //     } else
565 // //       fParticleMap = new TObjArray(treeK->GetEntries());
566     
567 //     // From gAlice->Particle(i) 
568
569
570 // //   if(!(*fParticleMap)[i]) {
571 // //     Int_t nentries = fParticles->GetEntries();
572     
573 // //     // algorithmic way of getting entry index
574 // //     // (primary particles are filled after secondaries)
575 // //     Int_t entry;
576 // //     if (i<fHeader.GetNprimary())
577 // //       entry = i+fHeader.GetNsecondary();
578 // //     else 
579 // //       entry = i-fHeader.GetNprimary();
580       
581 // //     // only check the algorithmic way and give
582 // //     // the fatal error if it is wrong
583 // //     if (entry != fParticleFileMap[i]) {
584 // //       Fatal("Particle",
585 // //         "!!!! The algorithmic way is WRONG: !!!\n entry: %d map: %d",
586 // //   entry, fParticleFileMap[i]); 
587 // //     }  
588       
589 // //     fTreeK->GetEntry(fParticleFileMap[i]);
590 // //     new ((*fParticles)[nentries]) TParticle(*fParticleBuffer);
591 // //     fParticleMap->AddAt((*fParticles)[nentries],i);
592 // //   }
593 // //   return (TParticle *) (*fParticleMap)[i];
594
595    
596     
597 //   }
598
599
600 //   //scan over opened files and read corresponding TreeK##
601
602   return ;
603 }
604 //____________________________________________________________________________ 
605 void AliPHOSIndexToObject::GetEvent(Int_t event)
606 {
607   // Reads the content of all Tree's S, D and R
608   if(event == fEvent) // do nothing
609     return ;
610     
611   if(event > fMaxEvent){
612     cout << "There is no such event " << event << " total # of events " << fMaxEvent << endl ;
613     return ;
614   }
615
616   fEvent = event ;
617   gAlice->GetEvent(fEvent) ;
618   
619   ReadTreeS() ;
620   ReadTreeD() ;
621   ReadTreeR() ;
622   ReadPrimaries() ;
623
624   
625
626 }
627