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