]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSTrackSegmentMakerv1.cxx
Fixing copy/paste erro. Additional protections
[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 /* History of cvs commits:
18  *
19  * $Log$
20  * Revision 1.83  2007/03/06 21:07:37  kharlov
21  * DP: xz CPV-EMC distance filled to TS
22  *
23  * Revision 1.82  2007/03/06 06:54:48  kharlov
24  * DP:Calculation of cluster properties dep. on vertex added
25  *
26  * Revision 1.81  2007/02/05 10:02:40  kharlov
27  * Module numbering is corrected
28  *
29  * Revision 1.80  2006/08/28 10:01:56  kharlov
30  * Effective C++ warnings fixed (Timur Pocheptsov)
31  *
32  * Revision 1.79  2006/04/25 12:41:15  hristov
33  * Moving non-persistent data to AliESDfriend (Yu.Belikov)
34  *
35  * Revision 1.78  2005/11/18 13:04:51  hristov
36  * Bug fix
37  *
38  * Revision 1.77  2005/11/17 23:34:36  hristov
39  * Corrected logics
40  *
41  * Revision 1.76  2005/11/17 22:29:12  hristov
42  * Faster version, no attempt to match tracks outside the PHOS acceptance
43  *
44  * Revision 1.75  2005/11/17 12:35:27  hristov
45  * Use references instead of objects. Avoid to create objects when they are not really needed
46  *
47  * Revision 1.74  2005/07/08 14:01:36  hristov
48  * Tracking in non-uniform nmagnetic field (Yu.Belikov)
49  *
50  * Revision 1.73  2005/05/28 14:19:05  schutz
51  * Compilation warnings fixed by T.P.
52  *
53  */
54
55 //_________________________________________________________________________
56 // Implementation version 1 of algorithm class to construct PHOS track segments
57 // Track segment for PHOS is list of 
58 //        EMC RecPoint + (possibly) CPV RecPoint
59 // To find TrackSegments we do the following: 
60 //  for each EMC RecPoints we look at
61 //   CPV RecPoints in the radious fRcpv. 
62 //  If there is such a CPV RecPoint, 
63 //   we make "Link" it is just indexes of EMC and CPV RecPoint and distance
64 //   between them in the PHOS plane. 
65 //  Then we sort "Links" and starting from the 
66 //   least "Link" pointing to the unassined EMC and CPV RecPoints assing them to 
67 //   new TrackSegment. 
68 // If there is no CPV RecPoint we make TrackSegment 
69 // consisting from EMC alone. There is no TrackSegments without EMC RecPoint.
70 //// In principle this class should be called from AliPHOSReconstructor, but 
71 // one can use it as well in standalone mode.
72 // Use  case:
73 //  root [0] AliPHOSTrackSegmentMakerv1 * t = new AliPHOSTrackSegmentMaker("galice.root", "tracksegmentsname", "recpointsname")
74 //  Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
75 //               // reads gAlice from header file "galice.root", uses recpoints stored in the branch names "recpointsname" (default = "Default")
76 //               // and saves recpoints in branch named "tracksegmentsname" (default = "recpointsname")                       
77 //  root [1] t->ExecuteTask()
78 //  root [3] t->SetTrackSegmentsBranch("max distance 5 cm")
79 //  root [4] t->ExecuteTask("deb all time") 
80 //                 
81 //*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH) & Yves Schutz (SUBATECH) 
82 //
83
84 // --- ROOT system ---
85 #include "TTree.h"
86 #include "TBenchmark.h"
87
88 // --- Standard library ---
89 #include "Riostream.h"
90 // --- AliRoot header files ---
91 #include "AliPHOSGeometry.h"
92 #include "AliPHOSTrackSegmentMakerv1.h"
93 #include "AliPHOSTrackSegment.h"
94 #include "AliPHOSLink.h"
95 #include "AliPHOSGetter.h"
96 #include "AliESD.h"
97 #include "AliESDtrack.h"
98
99 ClassImp( AliPHOSTrackSegmentMakerv1) 
100
101
102 //____________________________________________________________________________
103 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() :
104   AliPHOSTrackSegmentMaker(),
105   fDefaultInit(kTRUE),
106   fWrite(kFALSE),
107   fNTrackSegments(0),
108   fRcpv(0.f),
109   fRtpc(0.f),
110   fLinkUpArray(0),
111   fEmcFirst(0),
112   fEmcLast(0),
113   fCpvFirst(0),
114   fCpvLast(0),
115   fModule(0),
116   fTrackSegmentsInRun(0)
117   
118 {
119   // default ctor (to be used mainly by Streamer)
120   InitParameters() ; 
121 }
122
123 //____________________________________________________________________________
124 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const TString & alirunFileName, const TString & eventFolderName) :
125   AliPHOSTrackSegmentMaker(alirunFileName, eventFolderName),
126   fDefaultInit(kFALSE),
127   fWrite(kFALSE),
128   fNTrackSegments(0),
129   fRcpv(0.f),
130   fRtpc(0.f),
131   fLinkUpArray(0),
132   fEmcFirst(0),
133   fEmcLast(0),
134   fCpvFirst(0),
135   fCpvLast(0),
136   fModule(0),
137   fTrackSegmentsInRun(0)
138 {
139   // ctor
140   InitParameters() ; 
141   Init() ;
142   fESD = 0;
143 }
144
145
146 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const AliPHOSTrackSegmentMakerv1 & tsm) :
147   AliPHOSTrackSegmentMaker(tsm),
148   fDefaultInit(kFALSE),
149   fWrite(kFALSE),
150   fNTrackSegments(0),
151   fRcpv(0.f),
152   fRtpc(0.f),
153   fLinkUpArray(0),
154   fEmcFirst(0),
155   fEmcLast(0),
156   fCpvFirst(0),
157   fCpvLast(0),
158   fModule(0),
159   fTrackSegmentsInRun(0)
160 {
161   // cpy ctor: no implementation yet
162   // requested by the Coding Convention
163   Fatal("cpy ctor", "not implemented") ;
164 }
165
166
167 //____________________________________________________________________________
168  AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
169
170   // dtor
171   // fDefaultInit = kTRUE if TrackSegmentMaker created by default ctor (to get just the parameters)
172   if (!fDefaultInit)  
173     delete fLinkUpArray ;
174 }
175
176
177 //____________________________________________________________________________
178 const TString AliPHOSTrackSegmentMakerv1::BranchName() const 
179 {  
180  
181   return GetName() ;
182 }
183
184 //____________________________________________________________________________
185 void  AliPHOSTrackSegmentMakerv1::FillOneModule()
186 {
187   // Finds first and last indexes between which 
188   // clusters from one PHOS module are
189
190   AliPHOSGetter * gime = AliPHOSGetter::Instance() ; 
191   
192   TObjArray * emcRecPoints = gime->EmcRecPoints() ; 
193   TObjArray * cpvRecPoints = gime->CpvRecPoints() ; 
194  
195   //First EMC clusters
196   Int_t totalEmc = emcRecPoints->GetEntriesFast() ;
197   for(fEmcFirst = fEmcLast; (fEmcLast < totalEmc) &&  
198         ((dynamic_cast<AliPHOSRecPoint *>(emcRecPoints->At(fEmcLast)))->GetPHOSMod() == fModule ); 
199       fEmcLast ++)  ;
200   
201   //Now CPV clusters
202   Int_t totalCpv = cpvRecPoints->GetEntriesFast() ;
203
204     for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) && 
205          ((dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(fCpvLast)))->GetPHOSMod() == fModule ); 
206        fCpvLast ++) ;
207       
208 }
209
210 //____________________________________________________________________________
211 void  AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcClu,
212                                                          AliPHOSCpvRecPoint * cpvClu, 
213                                                          Int_t &trackindex, 
214                                                          Float_t &dx, Float_t &dz) const
215 {
216   // Calculates the distance between the EMC RecPoint and the CPV RecPoint
217   // Clusters are sorted in "rows" and "columns" of width 1 cm
218
219 //  Float_t delta = 1 ;  // Width of the rows in sorting of RecPoints (in cm)
220 //                       // if you change this value, change it as well in xxxRecPoint::Compare()
221   Float_t distance2Track = fRtpc ; 
222
223   trackindex = -1 ; // closest track within fRCpv 
224
225   TVector3 vecEmc ;   // Local position of EMC recpoint
226   TVector3 vecP ;     // Momentum direction at CPV plain
227   TVector3 vecPloc ;     // Momentum direction at CPV plain
228   
229   //toofar = kTRUE ;
230   if(emcClu->GetPHOSMod() != cpvClu->GetPHOSMod()){
231     dx=999. ;
232     dz=999. ;
233     return ;
234   }
235
236   emcClu->GetLocalPosition(vecEmc) ;
237
238   AliPHOSGetter * gime = AliPHOSGetter::Instance() ; 
239   const AliPHOSGeometry * geom = gime->PHOSGeometry() ; 
240     
241   Double_t xCPV,zCPV ; //EMC-projected coordinates of CPV cluster 
242   TVector3 cpvGlobal; // Global position of the CPV recpoint
243   geom->GetGlobal((AliRecPoint*)cpvClu,cpvGlobal);
244   Double_t vtxCPV[3]={cpvGlobal.X(),cpvGlobal.Y(),cpvGlobal.Z()} ;
245
246   if (fESD == 0x0) {
247      //if no track information available, assume straight line from IP to emcal
248      Int_t dummyMod ;
249      geom->ImpactOnEmc(vtxCPV,cpvGlobal.Theta(),cpvGlobal.Phi(),dummyMod,xCPV,zCPV) ;
250      dx=xCPV - vecEmc.X() ;
251      dz=zCPV - vecEmc.Z() ;
252      return ;
253   } 
254
255   //if there is ESD try to correct distance using TPC information on particle direct in CPV 
256   if (fESD != 0x0) {
257
258     Double_t rCPV = cpvGlobal.Pt() ;// Radius from IP to current point 
259
260     // Extrapolate the global track direction if any to CPV and find the closest track
261     Int_t nTracks = fESD->GetNumberOfTracks();
262     Int_t iClosestTrack = -1;
263     Double_t minDistance = 1.e6;
264     TVector3 inPHOS ; 
265
266     AliESDtrack *track;
267     Double_t xyz[3] ;
268     Double_t pxyz[3]; 
269     for (Int_t iTrack=0; iTrack<nTracks; iTrack++) {
270       track = fESD->GetTrack(iTrack);
271       if (!track->GetXYZAt(rCPV, fESD->GetMagneticField(), xyz))
272            continue; //track coord on the cylinder of PHOS radius
273       if ((TMath::Abs(xyz[0])+TMath::Abs(xyz[1])+TMath::Abs(xyz[2]))<=0)
274            continue;
275       //Check if this track hits PHOS
276       inPHOS.SetXYZ(xyz[0],xyz[1],xyz[2]);
277       distance2Track = inPHOS.Angle(cpvGlobal) ;
278       // Find the closest track to the CPV recpoint
279       if (distance2Track < minDistance) {
280          minDistance = distance2Track;
281          iClosestTrack = iTrack;
282       }
283     }
284
285     if (iClosestTrack != -1) {
286       track = fESD->GetTrack(iClosestTrack);
287       if (track->GetPxPyPzAt(rCPV, fESD->GetMagneticField(), pxyz)) { // track momentum ibid.
288         vecP.SetXYZ(pxyz[0],pxyz[1],pxyz[2]);
289         Int_t dummyMod ;
290         geom->ImpactOnEmc(vtxCPV,vecP.Theta(),vecP.Phi(),dummyMod,xCPV,zCPV) ;
291       }
292     }
293     
294     if(minDistance < fRtpc ){
295       trackindex = iClosestTrack ; 
296     }
297   }
298   if(trackindex!=-1){
299     dx=xCPV - vecEmc.X() ;
300     dz=zCPV - vecEmc.Z() ;
301   }
302   else{
303     dz=999. ;
304     dx=999. ;
305   }
306   return ;
307 }
308 //____________________________________________________________________________
309 void  AliPHOSTrackSegmentMakerv1::Init()
310 {
311   // Make all memory allocations that are not possible in default constructor
312   
313   AliPHOSGetter* gime = AliPHOSGetter::Instance();
314   if(!gime)
315     gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
316   
317   fLinkUpArray  = new TClonesArray("AliPHOSLink", 1000); 
318   if ( !gime->TrackSegmentMaker() ) {
319     gime->PostTrackSegmentMaker(this);
320   }
321 }
322
323 //____________________________________________________________________________
324 void  AliPHOSTrackSegmentMakerv1::InitParameters()
325 {
326   //Initializes parameters
327   fRcpv      = 10. ;
328   fRtpc      = 4. ;
329   fEmcFirst  = 0 ;    
330   fEmcLast   = 0 ;   
331   fCpvFirst  = 0 ;   
332   fCpvLast   = 0 ;   
333   fLinkUpArray = 0 ;
334   fWrite                   = kTRUE ;
335   fTrackSegmentsInRun       = 0 ; 
336   SetEventRange(0,-1) ;
337 }
338
339
340 //____________________________________________________________________________
341 void  AliPHOSTrackSegmentMakerv1::MakeLinks()const
342
343   // Finds distances (links) between all EMC and CPV clusters, 
344   // which are not further apart from each other than fRcpv 
345   // and sort them in accordance with this distance
346   
347   AliPHOSGetter * gime = AliPHOSGetter::Instance() ; 
348   TObjArray * emcRecPoints = gime->EmcRecPoints() ; 
349   TObjArray * cpvRecPoints = gime->CpvRecPoints() ; 
350
351   fLinkUpArray->Clear() ;    
352
353   AliPHOSCpvRecPoint * cpv ;
354   AliPHOSEmcRecPoint * emcclu ;
355
356   Int_t iLinkUp  = 0 ;
357   
358   Int_t iEmcRP;
359   for(iEmcRP = fEmcFirst; iEmcRP < fEmcLast; iEmcRP++ ) {
360     emcclu = dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP)) ;
361
362     //Bool_t toofar ;        
363     Int_t iCpv = 0 ;    
364     for(iCpv = fCpvFirst; iCpv < fCpvLast;iCpv++ ) { 
365       
366       cpv = dynamic_cast<AliPHOSCpvRecPoint *>(cpvRecPoints->At(iCpv)) ;
367       Int_t track = -1 ; 
368       Float_t dx,dz ;
369       GetDistanceInPHOSPlane(emcclu, cpv, track,dx,dz) ;     
370       if(TMath::Sqrt(dx*dx+dz*dz) < fRcpv ){ 
371         new ((*fLinkUpArray)[iLinkUp++])  AliPHOSLink(dx, dz, iEmcRP, iCpv, track) ;
372       }      
373     }
374   } 
375   
376   fLinkUpArray->Sort() ;  //first links with smallest distances
377 }
378
379 //____________________________________________________________________________
380 void  AliPHOSTrackSegmentMakerv1::MakePairs()
381
382   // Using the previously made list of "links", we found the smallest link - i.e. 
383   // link with the least distance between EMC and CPV and pointing to still 
384   // unassigned RecParticles. We assign these RecPoints to TrackSegment and 
385   // remove them from the list of "unassigned". 
386
387   AliPHOSGetter * gime = AliPHOSGetter::Instance() ; 
388
389   TObjArray * emcRecPoints = gime->EmcRecPoints() ; 
390   TObjArray * cpvRecPoints = gime->CpvRecPoints() ; 
391   TClonesArray * trackSegments = gime->TrackSegments();
392     
393   //Make arrays to mark clusters already chosen
394   Int_t * emcExist = 0;
395   if(fEmcLast > fEmcFirst)
396     emcExist = new Int_t[fEmcLast-fEmcFirst] ;
397   
398   Int_t index;
399   for(index = 0; index <fEmcLast-fEmcFirst; index ++)
400     emcExist[index] = 1 ;
401   
402   Bool_t * cpvExist = 0;
403   if(fCpvLast > fCpvFirst)
404     cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
405   for(index = 0; index <fCpvLast-fCpvFirst; index ++)
406     cpvExist[index] = kTRUE ;
407   
408   
409   // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance 
410   TIter nextUp(fLinkUpArray) ;
411   
412   AliPHOSLink * linkUp ;
413   
414   AliPHOSCpvRecPoint * nullpointer = 0 ;
415   
416   while ( (linkUp =  static_cast<AliPHOSLink *>(nextUp()) ) ){  
417
418     if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){
419
420       if(cpvExist[linkUp->GetCpv()-fCpvFirst]){ //CPV still exist
421          Float_t dx,dz ;
422          linkUp->GetXZ(dx,dz) ;
423          new ((* trackSegments)[fNTrackSegments]) 
424            AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(linkUp->GetEmc())) , 
425                                dynamic_cast<AliPHOSCpvRecPoint *>(cpvRecPoints->At(linkUp->GetCpv())) , 
426                                linkUp->GetTrack(),dx,dz) ;
427          
428        (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
429        fNTrackSegments++ ;
430        emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc  that Cpv was found 
431        //mark CPV recpoint as already used 
432        cpvExist[linkUp->GetCpv()-fCpvFirst] = kFALSE ;
433       } //if CpvUp still exist
434     } 
435   }        
436
437   //look through emc recPoints left without CPV
438   if(emcExist){ //if there is emc rec point
439     Int_t iEmcRP ;
440     for(iEmcRP = 0; iEmcRP < fEmcLast-fEmcFirst  ; iEmcRP++ ){
441       if(emcExist[iEmcRP] > 0 ){
442        new ((*trackSegments)[fNTrackSegments])  
443          AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP+fEmcFirst)), 
444                            nullpointer) ;
445        (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
446        fNTrackSegments++;    
447       } 
448     }
449   }
450   delete [] emcExist ; 
451   delete [] cpvExist ; 
452 }
453
454 //____________________________________________________________________________
455 void  AliPHOSTrackSegmentMakerv1::Exec(Option_t *option)
456 {
457   // Steering method to perform track segment construction for events
458   // in the range from fFirstEvent to fLastEvent.
459   // This range is optionally set by SetEventRange().
460   // if fLastEvent=-1 (by default), then process events until the end.
461   
462   if(strstr(option,"tim"))
463     gBenchmark->Start("PHOSTSMaker");
464  
465   if(strstr(option,"print")) {
466     Print() ; 
467     return ; 
468   }
469   
470   AliPHOSGetter * gime = AliPHOSGetter::Instance() ;  
471  
472   const AliPHOSGeometry * geom = gime->PHOSGeometry() ; 
473
474   if (fLastEvent == -1) 
475     fLastEvent = gime->MaxEvent() - 1 ;
476   else 
477     fLastEvent = TMath::Min(fFirstEvent,gime->MaxEvent());
478   Int_t nEvents   = fLastEvent - fFirstEvent + 1;
479
480   Int_t ievent ; 
481   for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
482     gime->Event(ievent,"DR") ;
483    //Make some initializations 
484     fNTrackSegments = 0 ;
485     fEmcFirst = 0 ;    
486     fEmcLast  = 0 ;   
487     fCpvFirst = 0 ;   
488     fCpvLast  = 0 ;   
489     
490     gime->TrackSegments()->Clear();
491
492     GetVertex() ;
493     EvalRecPoints() ;
494
495     //    if(!ReadRecPoints(ievent))   continue; //reads RecPoints for event ievent
496     
497     for(fModule = 1; fModule <= geom->GetNModules() ; fModule++ ) {
498       FillOneModule() ; 
499       MakeLinks() ;
500       MakePairs() ;
501     }
502
503     WriteTrackSegments() ;
504
505     if(strstr(option,"deb"))
506       PrintTrackSegments(option);
507     
508     //increment the total number of track segments per run 
509     fTrackSegmentsInRun += gime->TrackSegments()->GetEntriesFast() ; 
510   }
511   
512   if(strstr(option,"tim")){
513     gBenchmark->Stop("PHOSTSMaker");
514     Info("Exec", "took %f seconds for making TS %f seconds per event", 
515           gBenchmark->GetCpuTime("PHOSTSMaker"), 
516           gBenchmark->GetCpuTime("PHOSTSMaker")/nEvents) ;
517    }
518   if(fWrite) //do not unload in "on flight" mode
519     Unload();
520 }
521 //____________________________________________________________________________
522 void AliPHOSTrackSegmentMakerv1::GetVertex(void)
523 { //extract vertex either using ESD or generator
524   
525   //Try to extract vertex from data
526   if(fESD){
527     const AliESDVertex *esdVtx = fESD->GetVertex() ;
528     if(esdVtx){
529       fVtx.SetXYZ(esdVtx->GetXv(),esdVtx->GetYv(),esdVtx->GetZv()) ;
530       return ;
531     }
532   }
533   
534   AliWarning("Can not read vertex from data, use fixed \n") ;
535   fVtx.SetXYZ(0.,0.,0.) ;
536  
537 }
538 //____________________________________________________________________________
539 void AliPHOSTrackSegmentMakerv1::EvalRecPoints(void)
540 { //calculate parameters of RecPoints using vertex and writing them
541
542   AliPHOSGetter * gime = AliPHOSGetter::Instance() ; 
543   TClonesArray * digits = gime->Digits() ;
544   AliPHOSClusterizer * cl = gime->Clusterizer() ;
545   TObjArray * emcRecPoints = gime->EmcRecPoints() ; 
546   if (!emcRecPoints) {
547     AliError("No CPV rec. points!");
548   }
549   else {
550     Double_t w0=cl->GetEmcLogWeight() ;
551     for(Int_t i=0; i<emcRecPoints->GetEntriesFast() ; i++){
552       AliPHOSEmcRecPoint * point = static_cast<AliPHOSEmcRecPoint*>(emcRecPoints->At(i));
553       if (point) point->EvalAll(w0,fVtx,digits) ;
554       else {
555         AliError(Form("No AliPHOSEmcRecPoint is found at %d",i));
556       }
557     }
558     emcRecPoints->Sort() ;
559   }
560
561   TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
562   if (!cpvRecPoints) {
563     AliError("No CPV rec. points!");
564   }
565   else {
566     Double_t w0CPV=cl->GetCpvLogWeight() ;
567     for(Int_t i=0; i<cpvRecPoints->GetEntriesFast() ; i++){
568       AliPHOSCpvRecPoint * point = static_cast<AliPHOSCpvRecPoint*>(cpvRecPoints->At(i));
569       if (point) point->EvalAll(w0CPV,fVtx,digits) ;
570       else {
571         AliError(Form("No AliPHOSCpvRecPoint is found at %d",i));
572       }
573     }
574     cpvRecPoints->Sort() ;
575   }
576
577   //write recaculated RecPoints
578   gime->WriteRecPoints("OVERWRITE");
579   gime->WriteClusterizer("OVERWRITE");
580  
581
582 }
583 //____________________________________________________________________________
584 void AliPHOSTrackSegmentMakerv1::Unload() 
585 {
586   // Unloads the task from the folder
587   AliPHOSGetter * gime = AliPHOSGetter::Instance() ;  
588   gime->PhosLoader()->UnloadRecPoints() ;
589   gime->PhosLoader()->UnloadTracks() ;
590 }
591
592 //____________________________________________________________________________
593 void AliPHOSTrackSegmentMakerv1::Print(const Option_t *)const
594 {
595   //  Print TrackSegmentMaker parameters
596
597   TString message("") ;
598   if( strcmp(GetName(), "") != 0 ) {
599     message = "\n======== AliPHOSTrackSegmentMakerv1 ========\n" ; 
600     message += "Making Track segments\n" ;
601     message += "with parameters:\n" ; 
602     message += "     Maximal EMC - CPV distance (cm) %f\n" ;
603     message += "============================================\n" ;
604     Info("Print", message.Data(),fRcpv) ;
605   }
606   else
607     Info("Print", "AliPHOSTrackSegmentMakerv1 not initialized ") ;
608 }
609
610 //____________________________________________________________________________
611 void AliPHOSTrackSegmentMakerv1::WriteTrackSegments()
612 {
613   // Writes found TrackSegments to TreeR. Creates branches 
614   // "PHOSTS" and "AliPHOSTrackSegmentMaker" with the same title.
615   // In the former branch found TrackSegments are stored, while 
616   // in the latter all parameters, with which TS were made. 
617   // ROOT does not allow overwriting existing branches, therefore
618   // first we check, if branches with the same title already exist.
619   // If yes - exits without writing.
620
621   AliPHOSGetter *gime = AliPHOSGetter::Instance() ; 
622
623   TClonesArray * trackSegments = gime->TrackSegments() ; 
624   trackSegments->Expand(trackSegments->GetEntriesFast()) ;
625
626   if(fWrite){ //We write TreeT
627     TTree * treeT = gime->TreeT();
628     
629     //First TS
630     Int_t bufferSize = 32000 ; 
631     TBranch * tsBranch = treeT->Branch("PHOSTS",&trackSegments,bufferSize);
632     tsBranch->Fill() ;  
633     
634     gime->WriteTracks("OVERWRITE");
635     gime->WriteTrackSegmentMaker("OVERWRITE");
636   }
637 }
638
639
640 //____________________________________________________________________________
641 void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option)
642 {
643   // option deb - prints # of found TrackSegments
644   // option deb all - prints as well indexed of found RecParticles assigned to the TS
645
646   TClonesArray * trackSegments = AliPHOSGetter::Instance()->TrackSegments() ; 
647
648   Info("PrintTrackSegments", "Results from TrackSegmentMaker:") ; 
649   printf("nevent: %d\n", gAlice->GetEvNumber()) ; 
650   printf("        Found %d TrackSegments\n", trackSegments->GetEntriesFast() ); 
651   
652   if(strstr(option,"all")) {  // printing found TS
653     printf("TrackSegment #  EMC RP#  CPV RP#\n") ; 
654     Int_t index;
655     for (index = 0 ; index <trackSegments->GetEntriesFast() ; index++) {
656       AliPHOSTrackSegment * ts = (AliPHOSTrackSegment * )trackSegments->At(index) ; 
657       printf("   %d           %d        %d \n", ts->GetIndexInList(), ts->GetEmcIndex(), ts->GetCpvIndex() ) ; 
658     }   
659   }
660 }