]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSTrackSegmentMakerv1.cxx
new classes that were automatically generated from mysql tables
[u/mrichter/AliRoot.git] / PHOS / AliPHOSTrackSegmentMakerv1.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 /* $Id$ */
16 //_________________________________________________________________________
17 // Implementation version 1 of algorithm class to construct PHOS track segments
18 // Associates EMC and PPSD clusters
19 // Unfolds the EMC cluster   
20 //                  
21 //*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH)
22 //
23
24 // --- ROOT system ---
25 #include "TROOT.h"
26 #include "TFile.h"
27 #include "TTree.h"
28 #include "TSystem.h"
29 #include "TBenchmark.h"
30 // --- Standard library ---
31
32 #include <iostream.h>
33 #include <iomanip.h>
34
35 // --- AliRoot header files ---
36
37 #include "AliPHOSTrackSegmentMakerv1.h"
38 #include "AliPHOSClusterizerv1.h"
39 #include "AliPHOSTrackSegment.h"
40 #include "AliPHOSCpvRecPoint.h"
41 #include "AliPHOSPpsdRecPoint.h"
42 #include "AliPHOSLink.h"
43 #include "AliPHOSv0.h"
44 #include "AliRun.h"
45
46 ClassImp( AliPHOSTrackSegmentMakerv1) 
47
48
49 //____________________________________________________________________________
50  AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() : AliPHOSTrackSegmentMaker()
51 {
52   // ctor
53   SetTitle("version 1") ;
54   SetName("AliPHOSTrackSegmentMaker") ;
55   fR0 = 10. ;   
56   fEmcFirst = 0 ;    
57   fEmcLast  = 0 ;   
58   fCpvFirst = 0 ;   
59   fCpvLast  = 0 ;   
60   fPpsdFirst= 0 ;   
61   fPpsdLast = 0 ;   
62   fLinkLowArray = 0 ;
63   fLinkUpArray  = 0 ;
64   fIsInitialized = kFALSE ;
65 }
66 //____________________________________________________________________________
67  AliPHOSTrackSegmentMakerv1::  AliPHOSTrackSegmentMakerv1(const char* headerFile, const char* branchTitle): AliPHOSTrackSegmentMaker()
68 {
69   // ctor
70   SetTitle("version 1") ;
71   SetName("AliPHOSTrackSegmentMaker") ;
72   fR0 = 10. ;   
73   fEmcFirst = 0 ;    
74   fEmcLast  = 0 ;   
75   fCpvFirst = 0 ;   
76   fCpvLast  = 0 ;   
77   fPpsdFirst= 0 ;   
78   fPpsdLast = 0 ;   
79
80   fHeaderFileName = headerFile ;
81   fRecPointsBranchTitle = branchTitle ;
82     
83   TFile * file = (TFile*) gROOT->GetFile(fHeaderFileName.Data() ) ;
84   
85   if(file == 0){
86     file = new TFile(fHeaderFileName.Data(),"update") ;
87     gAlice = (AliRun *) file->Get("gAlice") ;
88   }
89   
90   AliPHOS * phos = (AliPHOS *) gAlice->GetDetector("PHOS") ;    
91   fGeom  = AliPHOSGeometry::GetInstance(phos->GetGeometry()->GetName(),phos->GetGeometry()->GetTitle() );
92   
93   fEmcRecPoints = new TObjArray(200) ;
94   fCpvRecPoints = new TObjArray(200) ;
95   fClusterizer  = new AliPHOSClusterizerv1() ;
96   
97   fTrackSegments = new TClonesArray("AliPHOSTrackSegment",200) ;
98   
99   fLinkLowArray = new TClonesArray("AliPHOSLink", 1000);
100   fLinkUpArray  = new TClonesArray("AliPHOSLink", 1000); 
101   
102   fIsInitialized = kTRUE ;
103
104 }
105 //____________________________________________________________________________
106 void  AliPHOSTrackSegmentMakerv1::Init(){
107
108   if(!fIsInitialized){
109     if(fHeaderFileName.IsNull())
110       fHeaderFileName = "galice.root" ;
111     
112     
113     TFile * file = (TFile*) gROOT->GetFile(fHeaderFileName.Data() ) ;
114     
115     if(file == 0){
116       file = new TFile(fHeaderFileName.Data(),"update") ;
117       gAlice = (AliRun *) file->Get("gAlice") ;
118     }
119     
120     AliPHOS * phos = (AliPHOS *) gAlice->GetDetector("PHOS") ;    
121     fGeom  = AliPHOSGeometry::GetInstance(phos->GetGeometry()->GetName(),phos->GetGeometry()->GetTitle() );
122
123
124     fEmcRecPoints = new TObjArray(200) ;
125     fCpvRecPoints = new TObjArray(200) ;
126     fClusterizer  = new AliPHOSClusterizerv1() ;
127
128     
129     fTrackSegments = new TClonesArray("AliPHOSTrackSegment",200) ;
130
131     fLinkLowArray = new TClonesArray("AliPHOSLink", 1000);
132     fLinkUpArray  = new TClonesArray("AliPHOSLink", 1000); 
133     
134     fIsInitialized = kTRUE ;
135    }
136 }
137
138 //____________________________________________________________________________
139  AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
140
141   // dtor
142   if(fLinkLowArray) delete fLinkLowArray ;
143   if(fLinkUpArray)  delete fLinkUpArray  ;
144 }
145
146 //____________________________________________________________________________
147 void  AliPHOSTrackSegmentMakerv1::FillOneModule()
148 {
149   // Finds bounds in which clusters from one PHOS module are
150  
151
152   //First EMC clusters
153   Int_t totalEmc = fEmcRecPoints->GetEntriesFast() ;
154   for(fEmcFirst = fEmcLast; (fEmcLast < totalEmc) &&  
155         (((AliPHOSRecPoint *) fEmcRecPoints->At(fEmcLast))->GetPHOSMod() == fModule ); 
156       fEmcLast ++)  ;
157   
158   
159   //Now CPV clusters
160   Int_t totalCpv = fCpvRecPoints->GetEntriesFast() ;
161
162   if(fModule <= fGeom->GetNCPVModules()){ // in CPV geometry
163     
164     for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) && 
165           (((AliPHOSRecPoint *) fCpvRecPoints->At(fCpvLast))->GetPHOSMod() == fModule ); 
166         fCpvLast ++) ;
167     
168     fPpsdFirst = fCpvLast ; //To avoid scanning RecPoints between fPpsdFirst and fPpsdLast
169     fPpsdLast  = fCpvLast ; //and to be ready to switch to mixed geometry 
170   }
171   else{  //in PPSD geometry    
172     fCpvLast = fPpsdLast ;
173     //Upper layer first
174     for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) &&  
175           (((AliPHOSPpsdRecPoint *) fCpvRecPoints->At(fCpvLast))->GetPHOSMod() == fModule ) &&
176           (((AliPHOSPpsdRecPoint *) fCpvRecPoints->At(fCpvLast))->GetUp()) ; 
177         fCpvLast ++)  ;
178     
179     fPpsdLast= fCpvLast ;
180     for(fPpsdFirst = fPpsdLast; (fPpsdLast < totalCpv)  &&
181           (((AliPHOSPpsdRecPoint *) fCpvRecPoints->At(fPpsdLast))->GetPHOSMod() == fModule ) &&
182           (!((AliPHOSPpsdRecPoint *) fCpvRecPoints->At(fPpsdLast))->GetUp()) ; 
183         fPpsdLast ++) ;
184   }
185     
186 }
187 //____________________________________________________________________________
188 Float_t  AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcClu,AliPHOSRecPoint * cpvClu, Bool_t &toofar)
189 {
190   // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
191   //clusters are sorted in "rows" and "columns" of width 1 cm
192   Float_t delta = 1 ;  // Width of the rows in sorting of RecPoints (in cm)
193                        // if you change this value, change it as well in xxxRecPoint::Compare()
194   Float_t r = fR0 ;
195  
196   TVector3 vecEmc ;
197   TVector3 vecCpv ;
198   
199   emcClu->GetLocalPosition(vecEmc) ;
200   cpvClu->GetLocalPosition(vecCpv)  ; 
201
202   if(emcClu->GetPHOSMod() == cpvClu->GetPHOSMod()){ 
203     if(vecCpv.X() <= vecEmc.X() + fR0 + 2*delta ){ 
204
205       vecCpv = vecCpv  - vecEmc ; 
206       r = vecCpv.Mag() ;
207       toofar = kFALSE ;
208
209     } // if  xPpsd >= xEmc + ...
210     else 
211       toofar = kTRUE ;
212   } 
213   else 
214     toofar = kTRUE ;
215
216   //toofar = kFALSE ;
217  
218   
219   return r ;
220 }
221
222 //____________________________________________________________________________
223 void  AliPHOSTrackSegmentMakerv1::MakeLinks()
224
225   // Finds distances (links) between all EMC and PPSD clusters, which are not further apart from each other than fR0 
226   
227   fLinkUpArray->Clear() ;    
228   fLinkLowArray->Clear() ;
229
230   AliPHOSRecPoint * ppsd ; 
231   AliPHOSRecPoint * cpv ;
232   AliPHOSEmcRecPoint * emcclu ;
233
234   Int_t iLinkLow = 0 ;
235   Int_t iLinkUp  = 0 ;
236   
237   Int_t iEmcRP;
238   for(iEmcRP = fEmcFirst; iEmcRP < fEmcLast; iEmcRP++ ) {
239     emcclu = (AliPHOSEmcRecPoint *) fEmcRecPoints->At(iEmcRP) ;
240
241     Bool_t toofar ;    
242     Int_t iPpsd ;
243     for(iPpsd = fPpsdFirst; iPpsd < fPpsdLast;iPpsd++ ) {
244       
245       ppsd = (AliPHOSRecPoint *) fCpvRecPoints->At(iPpsd) ;
246       Float_t r = GetDistanceInPHOSPlane(emcclu, ppsd, toofar) ;
247
248       if(toofar) 
249         break ;  
250       if(r < fR0)
251         new ((*fLinkLowArray)[iLinkLow++])  AliPHOSLink(r, iEmcRP, iPpsd) ;
252     }
253     
254     Int_t iCpv = 0 ;    
255     for(iCpv = fCpvFirst; iCpv < fCpvLast;iCpv++ ) { 
256       
257       cpv = (AliPHOSRecPoint *) fCpvRecPoints->At(iCpv) ;
258       Float_t r = GetDistanceInPHOSPlane(emcclu, cpv, toofar) ;
259       
260       if(toofar)
261         break ;  
262       if(r < fR0) { 
263         new ((*fLinkUpArray)[iLinkUp++])  AliPHOSLink(r, iEmcRP, iCpv) ;
264       }      
265     }
266   } 
267   
268   fLinkLowArray->Sort() ; //first links with smallest distances
269   fLinkUpArray->Sort() ;
270 }
271
272 //____________________________________________________________________________
273 void  AliPHOSTrackSegmentMakerv1::MakePairs()
274
275   
276   //Make arrays to mark clusters already chousen
277   Int_t * emcExist = 0;
278   if(fEmcLast > fEmcFirst)
279     emcExist = new Int_t[fEmcLast-fEmcFirst] ;
280   
281   Int_t index;
282   for(index = 0; index <fEmcLast-fEmcFirst; index ++)
283     emcExist[index] = 1 ;
284   
285   Bool_t * cpvExist = 0;
286   if(fCpvLast > fCpvFirst)
287     cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
288   for(index = 0; index <fCpvLast-fCpvFirst; index ++)
289     cpvExist[index] = kTRUE ;
290   
291   Bool_t * ppsdExist = 0;
292   if(fPpsdLast > fPpsdFirst)
293     ppsdExist = new Bool_t[fPpsdLast-fPpsdFirst] ;
294   for(index = 0; index <fPpsdLast-fPpsdFirst; index ++)
295     ppsdExist[index] = kTRUE ;
296   
297   // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance 
298   TIter nextLow(fLinkLowArray) ;
299   TIter nextUp(fLinkUpArray) ;
300   
301   AliPHOSLink * linkLow ;
302   AliPHOSLink * linkUp ;
303
304
305   AliPHOSRecPoint * nullpointer = 0 ;
306
307   while ( (linkLow =  (AliPHOSLink *)nextLow() ) ){
308   
309     if( (emcExist[linkLow->GetEmc()-fEmcFirst]> 0) && ppsdExist[linkLow->GetPpsd()-fPpsdFirst]  ){ // RecPoints not removed yet 
310       new ((*fTrackSegments)[fNTrackSegments]) AliPHOSTrackSegment((AliPHOSEmcRecPoint *) fEmcRecPoints->At(linkLow->GetEmc()), 
311                                                  nullpointer, 
312                                                 (AliPHOSPpsdRecPoint *)fCpvRecPoints->At(linkLow->GetPpsd()) ) ;
313          
314       ((AliPHOSTrackSegment* )fTrackSegments->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);    
315       //replace index of emc to negative and shifted index of TS      
316       emcExist[linkLow->GetEmc()-fEmcFirst] = -2 - fNTrackSegments ;  
317       //mark ppsd as used
318       ppsdExist[linkLow->GetPpsd()-fPpsdFirst] = kFALSE ; 
319       fNTrackSegments++ ;
320     } 
321   } 
322          
323
324   while ( (linkUp =  (AliPHOSLink *)nextUp() ) ){  
325     if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){ //without ppsd Up yet 
326
327       if(cpvExist[linkUp->GetPpsd()-fCpvFirst]){ //CPV still exist
328         
329         if(emcExist[linkUp->GetEmc()-fEmcFirst] > 0){ //without ppsd Low => create new TS
330
331           new ((* fTrackSegments)[fNTrackSegments]) AliPHOSTrackSegment((AliPHOSEmcRecPoint *) fEmcRecPoints->At(linkUp->GetEmc()) , 
332                                                                       (AliPHOSPpsdRecPoint *)fCpvRecPoints->At(linkUp->GetPpsd()), 
333                                                                       nullpointer) ;
334           ((AliPHOSTrackSegment *) fTrackSegments->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);
335           fNTrackSegments++ ;
336         }
337         else{ // append ppsd Up to existing TS
338           ((AliPHOSTrackSegment *)fTrackSegments->At(-2-emcExist[linkUp->GetEmc()-fEmcFirst]))->SetCpvRecPoint((AliPHOSCpvRecPoint *)fCpvRecPoints->At(linkUp->GetPpsd()));
339         }
340
341         emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc  that Cpv was found 
342         //mark CPV recpoint as already used 
343         cpvExist[linkUp->GetPpsd()-fCpvFirst] = kFALSE ;
344       } //if ppsdUp still exist
345     } 
346   }      
347
348   //look through emc recPoints left without CPV/PPSD
349   if(emcExist){ //if there is emc rec point
350     Int_t iEmcRP ;
351     for(iEmcRP = 0; iEmcRP < fEmcLast-fEmcFirst  ; iEmcRP++ ){
352       if(emcExist[iEmcRP] > 0 ){
353         new ((*fTrackSegments)[fNTrackSegments])  AliPHOSTrackSegment((AliPHOSEmcRecPoint *)fEmcRecPoints->At(iEmcRP+fEmcFirst), 
354                                                                     nullpointer, 
355                                                                     nullpointer ) ;
356         ((AliPHOSTrackSegment *) fTrackSegments->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);
357         fNTrackSegments++;    
358       } 
359     }
360   }
361   
362 }
363
364 //____________________________________________________________________________
365 void  AliPHOSTrackSegmentMakerv1::Exec(Option_t * option)
366 {
367   // Makes the track segments out of the list of EMC and PPSD Recpoints and stores them in a list
368
369   if(! fIsInitialized) Init() ;
370
371   if(strstr(option,"tim"))
372     gBenchmark->Start("PHOSTSMaker");  
373
374   Int_t nEvents = (Int_t) gAlice->TreeE()->GetEntries() ;
375   
376   for(fEvent = 0;fEvent< nEvents; fEvent++){
377     if(!ReadRecPoints())  //reads RecPoints for event fEvent
378       return;
379     
380     for(fModule = 1; fModule <= fGeom->GetNModules() ; fModule++ ){
381       
382       FillOneModule() ; 
383       
384       MakeLinks() ;
385       
386       MakePairs() ;
387       
388     }
389
390     WriteTrackSegments() ;
391     if(strstr(option,"deb"))
392       PrintTrackSegments(option) ;
393   }
394
395   if(strstr(option,"tim")){
396     gBenchmark->Stop("PHOSTSMaker");
397     cout << "AliPHOSTSMaker:" << endl ;
398     cout << "  took " << gBenchmark->GetCpuTime("PHOSTSMaker") << " seconds for making TS " 
399          <<  gBenchmark->GetCpuTime("PHOSTSMaker")/nEvents << " seconds per event " << endl ;
400     cout << endl ;
401   }
402
403
404 }
405 //____________________________________________________________________________
406 void AliPHOSTrackSegmentMakerv1::Print(Option_t * option)const {
407   if(fIsInitialized){
408     cout <<  "======== AliPHOSTrackSegmentMakerv1 ========" << endl ;
409     cout <<  "Making Track segments "<< endl ;
410     cout <<  "    Headers file: " << fHeaderFileName.Data() << endl ;
411     cout <<  "    RecPoints branch file name: " <<fRecPointsBranchTitle.Data() << endl ;
412     cout <<  "    TrackSegments Branch file name: " << fTSBranchTitle.Data() << endl ;
413     cout <<  "with parameters: " << endl ;
414     cout <<  "    Maximal EMC - CPV (PPSD) distance " << fR0 << endl ;
415     cout <<  "============================================" << endl ;
416   }
417   else
418     cout << "AliPHOSTrackSegmentMakerv1 not initialized " << endl ;
419 }
420 //____________________________________________________________________________
421 Bool_t AliPHOSTrackSegmentMakerv1::ReadRecPoints(){
422
423   //Make some initializations 
424   fEmcRecPoints->Clear() ;
425   fCpvRecPoints->Clear() ;
426   fTrackSegments->Clear() ;
427   fNTrackSegments = 0 ;
428   fEmcFirst = 0 ;    
429   fEmcLast  = 0 ;   
430   fCpvFirst = 0 ;   
431   fCpvLast  = 0 ;   
432   fPpsdFirst= 0 ;   
433   fPpsdLast = 0 ;   
434
435
436   gAlice->GetEvent(fEvent) ;
437
438   // Get TreeR header from file
439   char treeName[20]; 
440   sprintf(treeName,"TreeR%d",fEvent);
441
442   if(gAlice->TreeR()==0){
443     cout << "Error in AliPHOSTrackSegmentMakerv1 : no "<<treeName << endl  ;
444     cout << "   Do nothing " << endl ;
445     return kFALSE ;
446   }
447
448   char * emcBranchName = new char[30];
449   // sprintf(emcBranchName,"PHOSEmcRP%d",fEvent);
450   sprintf(emcBranchName,"PHOSEmcRP");
451   char * cpvBranchName = new char[30];
452   //  sprintf(cpvBranchName,"PHOSCpvRP%d",fEvent);
453   sprintf(cpvBranchName,"PHOSCpvRP");
454   char * cluBranchName = new char[30];
455   //  sprintf(cluBranchName,"AliPHOSClusterizer%d",fEvent);
456   sprintf(cluBranchName,"AliPHOSClusterizer");
457
458   TBranch * emcBranch = 0;
459   TBranch * cpvBranch = 0;
460   TBranch * clusterizerBranch = 0;
461
462   TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
463   Int_t ibranch;
464   Bool_t emcNotFound = kTRUE ;
465   Bool_t cpvNotFound = kTRUE ;  
466   Bool_t clusterizerNotFound = kTRUE ;
467   
468   for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
469
470     if(emcNotFound){
471       emcBranch=(TBranch *) branches->At(ibranch) ;
472       if( fRecPointsBranchTitle.CompareTo(emcBranch->GetTitle())==0 )
473         if( strcmp(emcBranch->GetName(),emcBranchName) == 0) {
474           emcNotFound = kFALSE ;
475         }
476     }
477     
478     if(cpvNotFound){
479       cpvBranch=(TBranch *) branches->At(ibranch) ;
480       if( fRecPointsBranchTitle.CompareTo(cpvBranch->GetTitle())==0 )
481         if( strcmp(cpvBranch->GetName(),cpvBranchName) == 0) 
482           cpvNotFound = kFALSE ;
483     }
484     
485     if(clusterizerNotFound){
486       clusterizerBranch = (TBranch *) branches->At(ibranch) ;
487       if( fRecPointsBranchTitle.CompareTo(clusterizerBranch->GetTitle()) == 0)
488         if( strcmp(clusterizerBranch->GetName(),cluBranchName) == 0) 
489           clusterizerNotFound = kFALSE ;
490     }
491     
492   }
493
494   if(clusterizerNotFound || emcNotFound || cpvNotFound){
495     cout << "AliPHOSTrackSegmentMakerv1: " << endl ;
496     cout << "    Can't find Branch with RecPoints or Clusterizer " ;
497     cout << "    Do nothing" <<endl  ;
498     return kFALSE ;
499   }
500   
501   emcBranch->SetAddress(&fEmcRecPoints) ;
502   cpvBranch->SetAddress(&fCpvRecPoints) ;
503   clusterizerBranch->SetAddress(&fClusterizer) ;
504   
505   gAlice->TreeR()->GetEvent(0) ;
506   
507   delete emcBranchName;
508   delete cpvBranchName;
509   delete cluBranchName;
510
511   return kTRUE ;
512   
513 }
514 //____________________________________________________________________________
515 void AliPHOSTrackSegmentMakerv1::WriteTrackSegments(){
516
517   char treeName[20]; 
518   sprintf(treeName,"TreeR%d",fEvent);
519   
520   
521   //First, check, if branches already exist
522   TBranch * tsMakerBranch = 0;
523   TBranch * tsBranch = 0;
524   
525   TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
526   Int_t ibranch;
527   Bool_t tsMakerNotFound = kTRUE ;
528   Bool_t tsNotFound = kTRUE ;
529   
530   for(ibranch = 0;(ibranch <branches->GetEntries())&&(tsMakerNotFound||tsNotFound);ibranch++){
531     if(tsMakerNotFound){
532       tsMakerBranch=(TBranch *) branches->At(ibranch) ;
533       if( (strcmp(tsMakerBranch->GetName(),"AliPHOSTrackSegmentMaker") == 0) &&
534           (fTSBranchTitle.CompareTo( tsMakerBranch->GetTitle())==0 ))
535         tsMakerNotFound = kFALSE ;
536     }
537     if(tsNotFound){
538       tsBranch=(TBranch *) branches->At(ibranch) ;
539       if( (strcmp(tsBranch->GetName(),"PHOSTS") == 0)  &&
540           (fTSBranchTitle.CompareTo( tsBranch->GetTitle())==0 ))
541         tsNotFound = kFALSE ;
542     }
543   }
544
545   if(!(tsMakerNotFound && tsNotFound )){ 
546     cout << "AliPHOSTrackSegmentMakerv1 error:"<< endl ;
547     cout << "       Branches PHOSTS and AliPHOSTrackSegementMaker " << endl ;
548     cout << "       with title '"<<fTSBranchTitle.Data() << "' already exist " << endl ;
549     cout << "       can not overwrite " << endl ;
550     return ;
551   }
552
553   //Make branch in TreeR for TrackSegments 
554   char * filename = 0;
555   if(gSystem->Getenv("CONFIG_SPLIT_FILE")!=0){   //generating file name
556     filename = new char[strlen(gAlice->GetBaseFile())+20] ;
557     sprintf(filename,"%s/PHOS.Reco.root",gAlice->GetBaseFile()) ; 
558   }
559
560   TDirectory *cwd = gDirectory;
561   
562   //First TS
563   Int_t bufferSize = 32000 ;    
564   tsBranch = gAlice->TreeR()->Branch("PHOSTS",&fTrackSegments,bufferSize);
565   tsBranch->SetTitle(fTSBranchTitle.Data());
566   if (filename) {
567     tsBranch->SetFile(filename);
568     TIter next( tsBranch->GetListOfBranches());
569     while ((tsBranch=(TBranch*)next())) {
570       tsBranch->SetFile(filename);
571     }   
572     cwd->cd();
573   } 
574   
575   //Second -TSMaker
576   Int_t splitlevel = 0 ;
577   AliPHOSTrackSegmentMakerv1 * ts = this ;
578   tsMakerBranch = gAlice->TreeR()->Branch("AliPHOSTrackSegmentMaker","AliPHOSTrackSegmentMakerv1",
579                                           &ts,bufferSize,splitlevel);
580   tsMakerBranch->SetTitle(fTSBranchTitle.Data());
581   if (filename) {
582     tsMakerBranch->SetFile(filename);
583     TIter next( tsMakerBranch->GetListOfBranches());
584     while ((tsMakerBranch=(TBranch*)next())) {
585       tsMakerBranch->SetFile(filename);
586     }   
587     cwd->cd();
588   } 
589   
590   gAlice->TreeR()->Fill() ;    
591   gAlice->TreeR()->Write(0,kOverwrite) ;  
592   
593 }
594
595
596 //____________________________________________________________________________
597 void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option){
598   
599   cout << "AliPHOSTrackSegmentMakerv1: " << endl ;
600   cout << "       Found " << fTrackSegments->GetEntriesFast() << "  trackSegments " << endl ;
601   
602   if(strstr(option,"all")) {  // printing found TS
603     cout << "TrackSegment # " << "    EMC RP#    " << "    CPV RP#    " << "     PPSD RP#" << endl ; 
604     
605     Int_t index;
606     for (index = 0 ; index <fTrackSegments->GetEntriesFast() ; index++) {
607       AliPHOSTrackSegment * ts = (AliPHOSTrackSegment * )fTrackSegments->At(index) ; 
608       cout<<"   "<< setw(4) << ts->GetIndexInList() << "            " 
609           <<setw(4) << ts->GetEmcIndex()<< "            " 
610           <<setw(4) << ts->GetCpvIndex()<< "            " 
611           <<setw(4) << ts->GetPpsdIndex()<< endl ;
612     }   
613     
614     cout << "-------------------------------------------------------"<< endl ;
615   }
616 }
617 //____________________________________________________________________________
618 void AliPHOSTrackSegmentMakerv1::SetRecPointsBranch(const char * title){
619   //set the title of RecPoints 
620     fRecPointsBranchTitle = title ;
621
622 }
623 //____________________________________________________________________________
624 void AliPHOSTrackSegmentMakerv1::SetTrackSegmentsBranch(const char * title){
625
626     fTSBranchTitle = title ; 
627 }