]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSClusterizerv1.cxx
392f7be7428f5cba533a59900af9cad644162f09
[u/mrichter/AliRoot.git] / PHOS / AliPHOSClusterizerv1.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    1 October 2000. Yuri Kharlov:
20      AreNeighbours()
21      PPSD upper layer is considered if number of layers>1
22
23    18 October 2000. Yuri Kharlov:
24      AliPHOSClusterizerv1()
25      CPV clusterizing parameters added
26
27      MakeClusters()
28      After first PPSD digit remove EMC digits only once
29 */
30 //*-- Author: Yves Schutz (SUBATECH)  & Dmitri Peressounko (SUBATECH & Kurchatov Institute)
31 //////////////////////////////////////////////////////////////////////////////
32 //  Clusterization class. Performs clusterization (collects neighbouring active cells) and 
33 //  unfolds the clusters having several local maxima.  
34 //  Results are stored in TreeR#, branches PHOSEmcRP (EMC recPoints),
35 //  PHOSCpvRP (CPV RecPoints) and AliPHOSClusterizer (Clusterizer with all 
36 //  parameters including input digits branch title, thresholds etc.)
37 //  This TTask is normally called from Reconstructioner, but can as well be used in 
38 //  standalone mode.
39 // Use Case:
40 //  root [0] AliPHOSClusterizerv1 * cl = new AliPHOSClusterizerv1("galice.root")  
41 //  Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
42 //               //reads gAlice from header file "..."                      
43 //  root [1] cl->ExecuteTask()  
44 //               //finds RecPoints in all events stored in galice.root
45 //  root [2] cl->SetDigitsBranch("digits2") 
46 //               //sets another title for Digitis (input) branch
47 //  root [3] cl->SetRecPointsBranch("recp2")  
48 //               //sets another title four output branches
49 //  root [4] cl->SetEmcLocalMaxCut(0.03)  
50 //               //set clusterization parameters
51 //  root [5] cl->ExecuteTask("deb all time")  
52 //               //once more finds RecPoints options are 
53 //               // deb - print number of found rec points
54 //               // deb all - print number of found RecPoints and some their characteristics 
55 //               // time - print benchmarking results
56
57 // --- ROOT system ---
58
59 #include "TROOT.h" 
60 #include "TFile.h" 
61 #include "TFolder.h" 
62 #include "TMath.h" 
63 #include "TMinuit.h"
64 #include "TTree.h" 
65 #include "TSystem.h" 
66 #include "TBenchmark.h"
67
68 // --- Standard library ---
69
70 #include <iostream.h>
71 #include <iomanip.h>
72
73 // --- AliRoot header files ---
74
75 #include "AliPHOSClusterizerv1.h"
76 #include "AliPHOSCpvRecPoint.h"
77 #include "AliPHOSDigit.h"
78 #include "AliPHOSDigitizer.h"
79 #include "AliPHOSEmcRecPoint.h"
80 #include "AliPHOS.h"
81 #include "AliPHOSPpsdRecPoint.h"
82 #include "AliPHOSGetter.h"
83 #include "AliRun.h"
84
85 ClassImp(AliPHOSClusterizerv1)
86   
87 //____________________________________________________________________________
88   AliPHOSClusterizerv1::AliPHOSClusterizerv1() : AliPHOSClusterizer()
89 {
90   // default ctor (to be used mainly by Streamer)
91   
92   fNumberOfCpvClusters     = 0 ; 
93   fNumberOfEmcClusters     = 0 ; 
94   
95   fCpvClusteringThreshold  = 0.0;
96   fEmcClusteringThreshold  = 0.2;   
97   fPpsdClusteringThreshold = 0.0000002 ;
98   
99   fEmcLocMaxCut            = 0.03 ;
100   fCpvLocMaxCut            = 0.03 ;
101   
102   fW0                      = 4.5 ;
103   fW0CPV                   = 4.0 ;
104
105   fHeaderFileName          = "" ; 
106   fDigitsBranchTitle       = "" ;
107   
108 }
109
110 //____________________________________________________________________________
111 AliPHOSClusterizerv1::AliPHOSClusterizerv1(const char* headerFile,const char* name)
112 :AliPHOSClusterizer(headerFile, name)
113 {
114   // ctor with the indication of the file where header Tree and digits Tree are stored
115   
116
117   fNumberOfCpvClusters     = 0 ; 
118   fNumberOfEmcClusters     = 0 ; 
119   
120   fCpvClusteringThreshold  = 0.0;
121   fEmcClusteringThreshold  = 0.2;   
122   fPpsdClusteringThreshold = 0.0000002 ;
123   
124   fEmcLocMaxCut            = 0.03 ;
125   fCpvLocMaxCut            = 0.03 ;
126   
127   fW0                      = 4.5 ;
128   fW0CPV                   = 4.0 ;
129   
130   fToUnfold                = kTRUE ;
131   
132   fHeaderFileName          = GetTitle() ; 
133   fDigitsBranchTitle       = GetName() ;
134
135   TString tempo(GetName()) ; 
136   tempo.Append(Version()) ; 
137   SetName(tempo.Data()) ; 
138   
139   Init() ;
140
141 }
142
143 //____________________________________________________________________________
144 void AliPHOSClusterizerv1::Exec(Option_t * option)
145 {
146   // Steering method
147
148   if( strcmp(GetName(), "")== 0 ) 
149     Init() ;
150
151   if(strstr(option,"tim"))
152     gBenchmark->Start("PHOSClusterizer"); 
153   
154   if(strstr(option,"print"))
155     Print("") ; 
156
157  //check, if the branch with name of this" already exits?
158   TObjArray * lob = (TObjArray*)gAlice->TreeR()->GetListOfBranches() ;
159   TIter next(lob) ; 
160   TBranch * branch = 0 ;  
161   Bool_t phosemcfound = kFALSE, phoscpvfound = kFALSE, clusterizerfound = kFALSE ; 
162   
163   TString taskName(GetName()) ; 
164   taskName.ReplaceAll(Version(), "") ;
165
166   while ( (branch = (TBranch*)next()) && (!phosemcfound || !phoscpvfound || !clusterizerfound) ) {
167     if ( (strcmp(branch->GetName(), "PHOSEmcRP")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) ) 
168       phosemcfound = kTRUE ;
169     
170     else if ( (strcmp(branch->GetName(), "PHOSCpvRP")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) ) 
171       phoscpvfound = kTRUE ;
172    
173     else if ( (strcmp(branch->GetName(), "AliPHOSClusterizer")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) ) 
174       clusterizerfound = kTRUE ; 
175   }
176
177   if ( phoscpvfound || phosemcfound || clusterizerfound ) {
178     cerr << "WARNING: AliPHOSClusterizer::Exec -> Emc(Cpv)RecPoints and/or Clusterizer branch with name " 
179          << taskName.Data() << " already exits" << endl ;
180     return ; 
181   }       
182
183   Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
184   Int_t ievent ;
185
186   for(ievent = 0; ievent < nevents; ievent++){
187     
188     gAlice->GetEvent(ievent) ;
189     gAlice->SetEvent(ievent) ;
190
191     if(!ReadDigits(ievent))  //reads digits for event fEvent
192       continue;
193     
194     MakeClusters() ;
195     
196     if(fToUnfold) 
197       MakeUnfolding() ;
198
199     WriteRecPoints(ievent) ;
200
201     if(strstr(option,"deb"))
202       PrintRecPoints(option) ;
203   }
204   
205   if(strstr(option,"tim")){
206     gBenchmark->Stop("PHOSClusterizer");
207     cout << "AliPHOSClusterizer:" << endl ;
208     cout << "  took " << gBenchmark->GetCpuTime("PHOSClusterizer") << " seconds for Clusterizing " 
209          <<  gBenchmark->GetCpuTime("PHOSClusterizer")/nevents << " seconds per event " << endl ;
210     cout << endl ;
211   }
212   
213 }
214
215 //____________________________________________________________________________
216 Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, int * maxAt, Float_t * maxAtEnergy,
217                                     Int_t nPar, Float_t * fitparameters) const
218
219   // Calls TMinuit to fit the energy distribution of a cluster with several maxima 
220   // The initial values for fitting procedure are set equal to the positions of local maxima.
221   // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
222
223   AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
224   TClonesArray * digits = gime->Digits() ; 
225   
226
227   gMinuit->mncler();                     // Reset Minuit's list of paramters
228   gMinuit->SetPrintLevel(-1) ;           // No Printout
229   gMinuit->SetFCN(AliPHOSClusterizerv1::UnfoldingChiSquare) ;  
230                                          // To set the address of the minimization function 
231
232   TList * toMinuit = new TList();
233   toMinuit->AddAt(emcRP,0) ;
234   toMinuit->AddAt(digits,1) ;
235   
236   gMinuit->SetObjectFit(toMinuit) ;         // To tranfer pointer to UnfoldingChiSquare
237
238   // filling initial values for fit parameters
239   AliPHOSDigit * digit ;
240
241   Int_t ierflg  = 0; 
242   Int_t index   = 0 ;
243   Int_t nDigits = (Int_t) nPar / 3 ;
244
245   Int_t iDigit ;
246
247   const AliPHOSGeometry * geom = gime->PHOSGeometry() ; 
248
249   for(iDigit = 0; iDigit < nDigits; iDigit++){
250     digit = (AliPHOSDigit *) maxAt[iDigit]; 
251
252     Int_t relid[4] ;
253     Float_t x = 0.;
254     Float_t z = 0.;
255     geom->AbsToRelNumbering(digit->GetId(), relid) ;
256     geom->RelPosInModule(relid, x, z) ;
257
258     Float_t energy = maxAtEnergy[iDigit] ;
259
260     gMinuit->mnparm(index, "x",  x, 0.1, 0, 0, ierflg) ;
261     index++ ;   
262     if(ierflg != 0){ 
263       cout << "PHOS Unfolding>  Unable to set initial value for fit procedure : x = " << x << endl ;
264       return kFALSE;
265     }
266     gMinuit->mnparm(index, "z",  z, 0.1, 0, 0, ierflg) ;
267     index++ ;   
268     if(ierflg != 0){
269       cout << "PHOS Unfolding>  Unable to set initial value for fit procedure : z = " << z << endl ;
270       return kFALSE;
271     }
272     gMinuit->mnparm(index, "Energy",  energy , 0.05*energy, 0., 4.*energy, ierflg) ;
273     index++ ;   
274     if(ierflg != 0){
275       cout << "PHOS Unfolding>  Unable to set initial value for fit procedure : energy = " << energy << endl ;      
276       return kFALSE;
277     }
278   }
279
280   Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
281                       //  depends on it. 
282   Double_t p1 = 1.0 ;
283   Double_t p2 = 0.0 ;
284
285   gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ;   // force TMinuit to reduce function calls  
286   gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ;   // force TMinuit to use my gradient  
287   gMinuit->SetMaxIterations(5);
288   gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ;  // No Warnings
289
290   gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ;    // minimize 
291
292   if(ierflg == 4){  // Minimum not found   
293     cout << "PHOS Unfolding>  Fit not converged, cluster abandoned "<< endl ;      
294     return kFALSE ;
295   }            
296   for(index = 0; index < nPar; index++){
297     Double_t err ;
298     Double_t val ;
299     gMinuit->GetParameter(index, val, err) ;    // Returns value and error of parameter index
300     fitparameters[index] = val ;
301    }
302
303   delete toMinuit ;
304   return kTRUE;
305
306 }
307
308 //____________________________________________________________________________
309 void AliPHOSClusterizerv1::Init()
310 {
311   // Make all memory allocations which can not be done in default constructor.
312   // Attach the Clusterizer task to the list of PHOS tasks
313   
314   if ( strcmp(GetTitle(), "") == 0 )
315     SetTitle("galice.root") ;
316
317   TString taskName(GetName()) ; 
318   taskName.ReplaceAll(Version(), "") ;
319
320   AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), taskName.Data()) ; 
321   if ( gime == 0 ) {
322     cerr << "ERROR: AliPHOSClusterizerv1::Init -> Could not obtain the Getter object !" << endl ; 
323     return ;
324   } 
325     
326   if(!gMinuit) 
327     gMinuit = new TMinuit(100) ;
328
329   //add Task to //YSAlice/tasks/Reconstructioner/PHOS
330   TTask * aliceRe  = (TTask*)gROOT->FindObjectAny("YSAlice/tasks/Reconstructioner") ; 
331   TTask * phosRe   = (TTask*)aliceRe->GetListOfTasks()->FindObject("PHOS") ;
332   phosRe->Add(this) ; 
333   // create a folder on the white board //YSAlice/WhiteBoard/RecPoints/PHOS/recpointsName
334   gime->Post(GetTitle(), "R", taskName.Data() ) ; 
335   
336 }
337
338 //____________________________________________________________________________
339 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)const
340 {
341   // Gives the neighbourness of two digits = 0 are not neighbour but continue searching 
342   //                                       = 1 are neighbour
343   //                                       = 2 are not neighbour but do not continue searching
344   // neighbours are defined as digits having at least a common vertex 
345   // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster 
346   //                                      which is compared to a digit (d2)  not yet in a cluster  
347
348   const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
349
350   Int_t rv = 0 ; 
351
352   Int_t relid1[4] ; 
353   geom->AbsToRelNumbering(d1->GetId(), relid1) ; 
354
355   Int_t relid2[4] ; 
356   geom->AbsToRelNumbering(d2->GetId(), relid2) ; 
357  
358   if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module and the same PPSD Module 
359     Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;  
360     Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;  
361     
362     if (( coldiff <= 1 )  && ( rowdiff <= 1 )){
363       rv = 1 ; 
364     }
365     else {
366       if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1)) 
367         rv = 2; //  Difference in row numbers is too large to look further 
368     }
369
370   } 
371   else {
372     
373     if( (relid1[0] < relid2[0]) || (relid1[1] < relid2[1]) )  
374       rv=2 ;
375
376   }
377
378   //Do NOT clusterize upper PPSD  
379   if( IsInPpsd(d1) && IsInPpsd(d2) &&
380      relid1[1] > 0                 &&
381      relid1[1] < geom->GetNumberOfPadsPhi()*geom->GetNumberOfPadsPhi() ) rv = 2 ;
382
383   return rv ; 
384 }
385
386
387 //____________________________________________________________________________
388 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) const
389 {
390   // Tells if (true) or not (false) the digit is in a PHOS-EMC module
391  
392   Bool_t rv = kFALSE ; 
393   const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
394
395   Int_t relid[4] ; 
396   geom->AbsToRelNumbering(digit->GetId(), relid) ; 
397
398   if ( relid[1] == 0  ) rv = kTRUE; 
399
400   return rv ; 
401 }
402
403 //____________________________________________________________________________
404 Bool_t AliPHOSClusterizerv1::IsInPpsd(AliPHOSDigit * digit) const
405 {
406   // Tells if (true) or not (false) the digit is in a PHOS-PPSD module
407  
408   Bool_t rv = kFALSE ; 
409   const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
410
411   Int_t relid[4] ; 
412   geom->AbsToRelNumbering(digit->GetId(), relid) ; 
413
414   if ( relid[1] > 0 && relid[0] > geom->GetNCPVModules() ) rv = kTRUE; 
415
416   return rv ; 
417 }
418
419 //____________________________________________________________________________
420 Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) const
421 {
422   // Tells if (true) or not (false) the digit is in a PHOS-CPV module
423  
424   Bool_t rv = kFALSE ; 
425   const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
426
427   Int_t relid[4] ; 
428   geom->AbsToRelNumbering(digit->GetId(), relid) ; 
429
430   if ( relid[1] > 0 && relid[0] <= geom->GetNCPVModules() ) rv = kTRUE; 
431
432   return rv ; 
433 }
434 //____________________________________________________________________________
435 Bool_t AliPHOSClusterizerv1::ReadDigits(Int_t event)
436  {
437    // reads digitis with specified title from TreeD
438
439   fNumberOfEmcClusters  = 0 ;
440   fNumberOfCpvClusters  = 0 ;
441
442   if ( gAlice->TreeD()==0) {  
443    cerr << "ERROR: AliPHOSClusterizerv1::ReadDigits There is no Digit Tree" << endl;
444    return kFALSE;
445   }
446   
447   //set address of the Digits and Digitizer
448   TBranch * digitsBranch = 0;
449   TBranch * digitizerBranch = 0;
450   TObjArray * lob = (TObjArray*)gAlice->TreeD()->GetListOfBranches() ;
451   TIter next(lob) ; 
452   TBranch * branch = 0 ;  
453   Bool_t phosfound = kFALSE, digitizerfound = kFALSE ; 
454   
455   TString taskName(GetName()) ; 
456   taskName.ReplaceAll(Version(), "") ;
457
458   while ( (branch = (TBranch*)next()) && (!phosfound || !digitizerfound) ) {
459     if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) ) {
460       phosfound = kTRUE ;
461       digitsBranch = branch ; 
462     }
463     
464     else if ( (strcmp(branch->GetName(), "AliPHOSDigitizer")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) ) {
465       digitizerfound = kTRUE ; 
466       digitizerBranch = branch ;
467     }
468   }
469   if ( !phosfound || !digitizerfound ) {
470     cerr << "WARNING: AliPHOSClusterizerv1::ReadDigits -> Digits and/or Digitizer branch with name " << taskName.Data() 
471          << " not found" << endl ;
472     return kFALSE ; 
473   }   
474   
475   AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
476   
477   TClonesArray * digits = gime->Digits() ; 
478   digits->Clear() ;
479   digitsBranch->SetAddress(&digits) ;
480   
481   AliPHOSDigitizer * digitizer = gime->Digitizer() ; 
482   digitizerBranch->SetAddress(&digitizer) ;
483
484   digitsBranch->GetEntry(0) ;
485   digitizerBranch->GetEntry(0) ;
486   
487   fPedestal = digitizer->GetPedestal() ;
488   fSlope    = digitizer->GetSlope() ;
489  
490   return kTRUE ;
491 }
492
493 //____________________________________________________________________________
494 void AliPHOSClusterizerv1::WriteRecPoints(Int_t event)
495 {
496
497   // Creates new branches with given title
498   // fills and writes into TreeR.
499   
500   AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ; 
501   TObjArray * emcRecPoints = gime->EmcRecPoints() ; 
502   TObjArray * cpvRecPoints = gime->CpvRecPoints() ; 
503   TClonesArray * digits = gime->Digits() ; 
504
505   Int_t index ;
506   //Evaluate position, dispersion and other RecPoint properties...
507   for(index = 0; index < emcRecPoints->GetEntries(); index++)
508     ((AliPHOSEmcRecPoint *)emcRecPoints->At(index))->EvalAll(fW0,digits) ;
509
510   emcRecPoints->Sort() ;
511
512   for(index = 0; index < emcRecPoints->GetEntries(); index++)
513     ((AliPHOSEmcRecPoint *)emcRecPoints->At(index))->SetIndexInList(index) ;
514
515   emcRecPoints->Expand(emcRecPoints->GetEntriesFast()) ; 
516
517   //Now the same for CPV
518   for(index = 0; index < cpvRecPoints->GetEntries(); index++)
519     ((AliPHOSRecPoint *)cpvRecPoints->At(index))->EvalAll(fW0CPV,digits)  ;
520
521   cpvRecPoints->Sort() ;
522
523   for(index = 0; index < cpvRecPoints->GetEntries(); index++)
524     ((AliPHOSRecPoint *)cpvRecPoints->At(index))->SetIndexInList(index) ;
525
526   cpvRecPoints->Expand(cpvRecPoints->GetEntriesFast()) ;
527
528   gAlice->GetEvent(event) ; 
529   if(gAlice->TreeR()==0)
530     gAlice->MakeTree("R") ;
531   
532   //Make branches in TreeR for RecPoints and Clusterizer
533   char * filename = 0;
534   if(gSystem->Getenv("CONFIG_SPLIT_FILE")!=0){   //generating file name
535     filename = new char[strlen(gAlice->GetBaseFile())+20] ;
536     sprintf(filename,"%s/PHOS.Reco.root",gAlice->GetBaseFile()) ;
537   }
538   
539   //Make new branches
540   TDirectory *cwd = gDirectory;
541   
542   TString branchName(GetName()) ; 
543   branchName.ReplaceAll(Version(), "") ; 
544  
545   Int_t bufferSize = 32000 ;    
546   Int_t splitlevel = 0 ;
547
548   //First EMC
549   TBranch * emcBranch = gAlice->TreeR()->Branch("PHOSEmcRP","TObjArray",&emcRecPoints,bufferSize,splitlevel);
550   emcBranch->SetTitle(branchName);
551   if (filename) {
552     emcBranch->SetFile(filename);
553     TIter next( emcBranch->GetListOfBranches());
554     TBranch * sb ;
555     while ((sb=(TBranch*)next())) {
556       sb->SetFile(filename);
557     }   
558     
559     cwd->cd();
560   }
561     
562   //Now CPV branch
563   TBranch * cpvBranch = gAlice->TreeR()->Branch("PHOSCpvRP","TObjArray",&cpvRecPoints,bufferSize,splitlevel);
564   cpvBranch->SetTitle(branchName);
565   if (filename) {
566     cpvBranch->SetFile(filename);
567     TIter next( cpvBranch->GetListOfBranches());
568     TBranch * sb;
569     while ((sb=(TBranch*)next())) {
570       sb->SetFile(filename);
571     }   
572     cwd->cd();
573   } 
574     
575   //And Finally  clusterizer branch
576   AliPHOSClusterizerv1 * cl = (AliPHOSClusterizerv1*)gime->Clusterizer(GetName()) ;
577   TBranch * clusterizerBranch = gAlice->TreeR()->Branch("AliPHOSClusterizer","AliPHOSClusterizerv1",
578                                               &cl,bufferSize,splitlevel);
579   clusterizerBranch->SetTitle(branchName);
580   if (filename) {
581     clusterizerBranch->SetFile(filename);
582     TIter next( clusterizerBranch->GetListOfBranches());
583     TBranch * sb ;
584     while ((sb=(TBranch*)next())) {
585       sb->SetFile(filename);
586     }   
587     cwd->cd();
588   }
589   emcBranch        ->Fill() ;
590   cpvBranch        ->Fill() ;
591   clusterizerBranch->Fill() ;
592
593   gAlice->TreeR()->Write(0,kOverwrite) ;  
594   
595 }
596
597 //____________________________________________________________________________
598 void AliPHOSClusterizerv1::MakeClusters()
599 {
600   // Steering method to construct the clusters stored in a list of Reconstructed Points
601   // A cluster is defined as a list of neighbour digits
602
603   AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
604
605   TObjArray * emcRecPoints = gime->EmcRecPoints() ; 
606   TObjArray * cpvRecPoints = gime->CpvRecPoints() ; 
607   emcRecPoints->Delete() ;
608   cpvRecPoints->Delete() ;
609   
610   TClonesArray * digits = gime->Digits() ; 
611   TClonesArray * digitsC =  (TClonesArray*)digits->Clone() ;
612   
613  
614   // Clusterization starts  
615
616   TIter nextdigit(digitsC) ; 
617   AliPHOSDigit * digit ; 
618   Bool_t notremoved = kTRUE ;
619
620   while ( (digit = (AliPHOSDigit *)nextdigit()) ) { // scan over the list of digitsC
621     AliPHOSRecPoint * clu = 0 ; 
622
623     TArrayI clusterdigitslist(1500) ;   
624     Int_t index ;
625
626     if (( IsInEmc (digit) && Calibrate(digit->GetAmp()) > fEmcClusteringThreshold  ) || 
627         ( IsInPpsd(digit) && Calibrate(digit->GetAmp()) > fPpsdClusteringThreshold ) ||
628         ( IsInCpv (digit) && Calibrate(digit->GetAmp()) > fCpvClusteringThreshold  ) ) {
629       
630       Int_t iDigitInCluster = 0 ; 
631       
632       if  ( IsInEmc(digit) ) {   
633         // start a new EMC RecPoint
634         if(fNumberOfEmcClusters >= emcRecPoints->GetSize()) 
635           emcRecPoints->Expand(2*fNumberOfEmcClusters+1) ;
636         
637         emcRecPoints->AddAt(new  AliPHOSEmcRecPoint(), fNumberOfEmcClusters) ;
638         clu = (AliPHOSEmcRecPoint *) emcRecPoints->At(fNumberOfEmcClusters) ; 
639         fNumberOfEmcClusters++ ; 
640         clu->AddDigit(*digit, Calibrate(digit->GetAmp())) ; 
641         clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;  
642         iDigitInCluster++ ; 
643         digitsC->Remove(digit) ; 
644
645       } else { 
646         
647         // start a new PPSD/CPV cluster
648         if(fNumberOfCpvClusters >= cpvRecPoints->GetSize()) 
649           cpvRecPoints->Expand(2*fNumberOfCpvClusters+1);
650
651         if(IsInPpsd(digit)) 
652           cpvRecPoints->AddAt(new AliPHOSPpsdRecPoint(),fNumberOfCpvClusters) ;
653         else
654           cpvRecPoints->AddAt(new AliPHOSCpvRecPoint(), fNumberOfCpvClusters) ;
655
656         clu =  (AliPHOSPpsdRecPoint *) cpvRecPoints->At(fNumberOfCpvClusters)  ;  
657         fNumberOfCpvClusters++ ; 
658         clu->AddDigit(*digit, Calibrate(digit->GetAmp()) ) ;    
659         clusterdigitslist[iDigitInCluster] = digit->GetIndexInList()  ; 
660         iDigitInCluster++ ; 
661         digitsC->Remove(digit) ; 
662         nextdigit.Reset() ;
663         
664         // Here we remove remaining EMC digits, which cannot make a cluster
665         
666         if( notremoved ) { 
667           while( ( digit = (AliPHOSDigit *)nextdigit() ) ) {
668             if( IsInEmc(digit) ) 
669               digitsC->Remove(digit) ;
670             else 
671               break ;
672           }
673           notremoved = kFALSE ;
674         }
675         
676       } // else        
677       
678       nextdigit.Reset() ;
679       
680       AliPHOSDigit * digitN ; 
681       index = 0 ;
682       while (index < iDigitInCluster){ // scan over digits already in cluster 
683         digit =  (AliPHOSDigit*)digits->At(clusterdigitslist[index])  ;      
684         index++ ; 
685         while ( (digitN = (AliPHOSDigit *)nextdigit()) ) { // scan over the reduced list of digits 
686           Int_t ineb = AreNeighbours(digit, digitN);       // call (digit,digitN) in THAT oder !!!!!
687           switch (ineb ) {
688           case 0 :   // not a neighbour
689             break ;
690           case 1 :   // are neighbours 
691             clu->AddDigit(*digitN, Calibrate( digitN->GetAmp() ) ) ;
692             clusterdigitslist[iDigitInCluster] = digitN->GetIndexInList() ; 
693             iDigitInCluster++ ; 
694             digitsC->Remove(digitN) ;
695             break ;
696           case 2 :   // too far from each other
697             goto endofloop;   
698           } // switch
699           
700         } // while digitN
701         
702       endofloop: ;
703         nextdigit.Reset() ; 
704         
705       } // loop over cluster     
706
707     } // energy theshold  
708
709     
710   } // while digit
711
712   delete digitsC ;
713
714 }
715
716 //____________________________________________________________________________
717 void AliPHOSClusterizerv1::MakeUnfolding()
718 {
719   // Unfolds clusters using the shape of an ElectroMagnetic shower
720   // Performs unfolding of all EMC/CPV but NOT ppsd clusters
721
722   AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
723   
724   const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
725   TObjArray * emcRecPoints = gime->EmcRecPoints() ; 
726   TObjArray * cpvRecPoints = gime->CpvRecPoints() ; 
727   TClonesArray * digits = gime->Digits() ; 
728   
729   // Unfold first EMC clusters 
730   if(fNumberOfEmcClusters > 0){
731
732     Int_t nModulesToUnfold = geom->GetNModules() ; 
733
734     Int_t numberofNotUnfolded = fNumberOfEmcClusters ; 
735     Int_t index ;   
736     for(index = 0 ; index < numberofNotUnfolded ; index++){
737       
738       AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint *) emcRecPoints->At(index) ;
739       if(emcRecPoint->GetPHOSMod()> nModulesToUnfold)
740         break ;
741       
742       Int_t nMultipl = emcRecPoint->GetMultiplicity() ; 
743       Int_t * maxAt = new Int_t[nMultipl] ;
744       Float_t * maxAtEnergy = new Float_t[nMultipl] ;
745       Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fEmcLocMaxCut,digits) ;
746       
747       if( nMax > 1 ) {     // if cluster is very flat (no pronounced maximum) then nMax = 0       
748         UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
749         emcRecPoints->Remove(emcRecPoint); 
750         emcRecPoints->Compress() ;
751         index-- ;
752         fNumberOfEmcClusters -- ;
753         numberofNotUnfolded-- ;
754       }
755       
756       delete[] maxAt ; 
757       delete[] maxAtEnergy ; 
758     }
759   } 
760   // Unfolding of EMC clusters finished
761
762
763   // Unfold now CPV clusters
764   if(fNumberOfCpvClusters > 0){
765     
766     Int_t nModulesToUnfold = geom->GetNCPVModules() ;
767
768     Int_t numberofCpvNotUnfolded = fNumberOfCpvClusters ;     
769     Int_t index ;   
770     for(index = 0 ; index < numberofCpvNotUnfolded ; index++){
771       
772       AliPHOSRecPoint * recPoint = (AliPHOSRecPoint *) cpvRecPoints->At(index) ;
773
774       if(recPoint->GetPHOSMod()> nModulesToUnfold)
775         break ;
776       
777       AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint*) recPoint ; 
778       
779       Int_t nMultipl = emcRecPoint->GetMultiplicity() ; 
780       Int_t * maxAt = new Int_t[nMultipl] ;
781       Float_t * maxAtEnergy = new Float_t[nMultipl] ;
782       Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fCpvLocMaxCut,digits) ;
783       
784       if( nMax > 1 ) {     // if cluster is very flat (no pronounced maximum) then nMax = 0       
785         UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
786         cpvRecPoints->Remove(emcRecPoint); 
787         cpvRecPoints->Compress() ;
788         index-- ;
789         numberofCpvNotUnfolded-- ;
790         fNumberOfCpvClusters-- ;
791       }
792       
793       delete[] maxAt ; 
794       delete[] maxAtEnergy ; 
795     } 
796   }
797   //Unfolding of Cpv clusters finished
798   
799 }
800
801 //____________________________________________________________________________
802 Double_t  AliPHOSClusterizerv1::ShowerShape(Double_t r)
803
804   // Shape of the shower (see PHOS TDR)
805   // If you change this function, change also the gradient evaluation in ChiSquare()
806
807   Double_t r4    = r*r*r*r ;
808   Double_t r295  = TMath::Power(r, 2.95) ;
809   Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
810   return shape ;
811 }
812
813 //____________________________________________________________________________
814 void  AliPHOSClusterizerv1::UnfoldCluster(AliPHOSEmcRecPoint * iniEmc, 
815                                                  Int_t nMax, 
816                                                  int * maxAt, 
817                                                  Float_t * maxAtEnergy)
818
819   // Performs the unfolding of a cluster with nMax overlapping showers 
820
821   AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
822   const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
823   TClonesArray * digits = gime->Digits() ; 
824   TObjArray * emcRecPoints = gime->EmcRecPoints() ; 
825   TObjArray * cpvRecPoints = gime->CpvRecPoints() ; 
826
827   Int_t nPar = 3 * nMax ;
828   Float_t * fitparameters = new Float_t[nPar] ;
829
830   Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
831   if( !rv ) {
832     // Fit failed, return and remove cluster
833     delete[] fitparameters ; 
834     return ;
835   }
836
837   // create ufolded rec points and fill them with new energy lists
838   // First calculate energy deposited in each sell in accordance with fit (without fluctuations): efit[]
839   // and later correct this number in acordance with actual energy deposition
840
841   Int_t nDigits = iniEmc->GetMultiplicity() ;  
842   Float_t * efit = new Float_t[nDigits] ;
843   Float_t xDigit=0.,zDigit=0.,distance=0. ;
844   Float_t xpar=0.,zpar=0.,epar=0.  ;
845   Int_t relid[4] ;
846   AliPHOSDigit * digit = 0 ;
847   Int_t * emcDigits = iniEmc->GetDigitsList() ;
848
849   Int_t iparam ;
850   Int_t iDigit ;
851   for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
852     digit = (AliPHOSDigit*) digits->At(emcDigits[iDigit] ) ;   
853     geom->AbsToRelNumbering(digit->GetId(), relid) ;
854     geom->RelPosInModule(relid, xDigit, zDigit) ;
855     efit[iDigit] = 0;
856
857     iparam = 0 ;    
858     while(iparam < nPar ){
859       xpar = fitparameters[iparam] ;
860       zpar = fitparameters[iparam+1] ;
861       epar = fitparameters[iparam+2] ;
862       iparam += 3 ;
863       distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar)  ;
864       distance =  TMath::Sqrt(distance) ;
865       efit[iDigit] += epar * ShowerShape(distance) ;
866     }
867   }
868   
869
870   // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
871   // so that energy deposited in each cell is distributed betwin new clusters proportionally
872   // to its contribution to efit
873
874   Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
875   Float_t ratio ;
876
877   iparam = 0 ;
878   while(iparam < nPar ){
879     xpar = fitparameters[iparam] ;
880     zpar = fitparameters[iparam+1] ;
881     epar = fitparameters[iparam+2] ;
882     iparam += 3 ;    
883     
884     AliPHOSEmcRecPoint * emcRP = 0 ;  
885
886     if(iniEmc->IsEmc()){ //create new entries in fEmcRecPoints...
887       
888       if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
889         emcRecPoints->Expand(2*fNumberOfEmcClusters) ;
890       
891       (*emcRecPoints)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint() ;
892       emcRP = (AliPHOSEmcRecPoint *) emcRecPoints->At(fNumberOfEmcClusters);
893       fNumberOfEmcClusters++ ;
894     }
895     else{//create new entries in fCpvRecPoints
896       if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
897         cpvRecPoints->Expand(2*fNumberOfCpvClusters) ;
898       
899       (*cpvRecPoints)[fNumberOfCpvClusters] = new AliPHOSCpvRecPoint() ;
900       emcRP = (AliPHOSEmcRecPoint *) cpvRecPoints->At(fNumberOfCpvClusters);
901       fNumberOfCpvClusters++ ;
902     }
903     
904     Float_t eDigit ;
905     for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
906       digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ; 
907       geom->AbsToRelNumbering(digit->GetId(), relid) ;
908       geom->RelPosInModule(relid, xDigit, zDigit) ;
909       distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar)  ;
910       distance =  TMath::Sqrt(distance) ;
911       ratio = epar * ShowerShape(distance) / efit[iDigit] ; 
912       eDigit = emcEnergies[iDigit] * ratio ;
913       emcRP->AddDigit( *digit, eDigit ) ;
914     }   
915   }
916  
917   delete[] fitparameters ; 
918   delete[] efit ; 
919   
920 }
921
922 //_____________________________________________________________________________
923 void AliPHOSClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
924 {
925   // Calculates the Chi square for the cluster unfolding minimization
926   // Number of parameters, Gradient, Chi squared, parameters, what to do
927
928
929   TList * toMinuit = (TList*) gMinuit->GetObjectFit() ;
930
931   AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint*) toMinuit->At(0)  ;
932   TClonesArray * digits = (TClonesArray*)toMinuit->At(1)  ;
933
934
935   
936   //  AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
937
938   Int_t * emcDigits     = emcRP->GetDigitsList() ;
939
940   Int_t nOdigits = emcRP->GetDigitsMultiplicity() ; 
941
942   Float_t * emcEnergies = emcRP->GetEnergiesList() ;
943
944   const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ; 
945   fret = 0. ;     
946   Int_t iparam ;
947
948   if(iflag == 2)
949     for(iparam = 0 ; iparam < nPar ; iparam++)    
950       Grad[iparam] = 0 ; // Will evaluate gradient
951   
952   Double_t efit ;    
953
954   AliPHOSDigit * digit ;
955   Int_t iDigit ;
956
957   for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
958
959     digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ; 
960
961     Int_t relid[4] ;
962     Float_t xDigit ;
963     Float_t zDigit ;
964
965     geom->AbsToRelNumbering(digit->GetId(), relid) ;
966
967     geom->RelPosInModule(relid, xDigit, zDigit) ;
968
969      if(iflag == 2){  // calculate gradient
970        Int_t iParam = 0 ;
971        efit = 0 ;
972        while(iParam < nPar ){
973          Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
974          iParam++ ; 
975          distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ; 
976          distance = TMath::Sqrt( distance ) ; 
977          iParam++ ;      
978          efit += x[iParam] * ShowerShape(distance) ;
979          iParam++ ;
980        }
981        Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E) 
982        iParam = 0 ;
983        while(iParam < nPar ){
984          Double_t xpar = x[iParam] ;
985          Double_t zpar = x[iParam+1] ;
986          Double_t epar = x[iParam+2] ;
987          Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
988          Double_t shape = sum * ShowerShape(dr) ;
989          Double_t r4 = dr*dr*dr*dr ;
990          Double_t r295 = TMath::Power(dr,2.95) ;
991          Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
992                                          0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
993          
994          Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ;  // Derivative over x    
995          iParam++ ; 
996          Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ;  // Derivative over z         
997          iParam++ ; 
998          Grad[iParam] += shape ;                                  // Derivative over energy             
999          iParam++ ; 
1000        }
1001      }
1002      efit = 0;
1003      iparam = 0 ;
1004
1005      while(iparam < nPar ){
1006        Double_t xpar = x[iparam] ;
1007        Double_t zpar = x[iparam+1] ;
1008        Double_t epar = x[iparam+2] ;
1009        iparam += 3 ;
1010        Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar)  ;
1011        distance =  TMath::Sqrt(distance) ;
1012        efit += epar * ShowerShape(distance) ;
1013      }
1014
1015      fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ; 
1016      // Here we assume, that sigma = sqrt(E)
1017   }
1018
1019 }
1020
1021 //____________________________________________________________________________
1022 void AliPHOSClusterizerv1::Print(Option_t * option)const
1023 {
1024   // Print clusterizer parameters
1025
1026   if( strcmp(GetName(), "") !=0 ){
1027     
1028     // Print parameters
1029  
1030     TString taskName(GetName()) ; 
1031     taskName.ReplaceAll(Version(), "") ;
1032
1033     cout << "---------------"<< taskName.Data() << " " << GetTitle()<< "-----------" << endl 
1034          << "Clusterizing digits from the file: " << fHeaderFileName.Data() << endl 
1035          << "                           Branch: " << fDigitsBranchTitle.Data() << endl 
1036          << endl 
1037          << "                       EMC Clustering threshold = " << fEmcClusteringThreshold << endl
1038          << "                       EMC Local Maximum cut    = " << fEmcLocMaxCut << endl
1039          << "                       EMC Logarothmic weight   = " << fW0 << endl
1040          << endl
1041          << "                       CPV Clustering threshold = " << fCpvClusteringThreshold << endl
1042          << "                       CPV Local Maximum cut    = " << fCpvLocMaxCut << endl
1043        << "                       CPV Logarothmic weight   = " << fW0CPV << endl
1044          << endl
1045          << "                      PPSD  Clustering threshold = " << fPpsdClusteringThreshold << endl;
1046     if(fToUnfold)
1047       cout << " Unfolding on " << endl ;
1048     else
1049       cout << " Unfolding off " << endl ;
1050     
1051     cout << "------------------------------------------------------------------" <<endl ;
1052   }
1053   else
1054     cout << " AliPHOSClusterizerv1 not initialized " << endl ;
1055 }
1056 //____________________________________________________________________________
1057 void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
1058 {
1059   // Prints list of RecPoints produced at the current pass of AliPHOSClusterizer
1060
1061   TObjArray * emcRecPoints = AliPHOSGetter::GetInstance()->EmcRecPoints() ; 
1062   TObjArray * cpvRecPoints = AliPHOSGetter::GetInstance()->CpvRecPoints() ; 
1063
1064   cout << "AliPHOSClusterizerv1: : event "<<gAlice->GetEvNumber() << endl ;
1065   cout << "       Found "<< emcRecPoints->GetEntriesFast() << " EMC Rec Points and " 
1066            << cpvRecPoints->GetEntriesFast() << " CPV RecPoints" << endl ;
1067
1068   if(strstr(option,"all")) {
1069     cout << "EMC clusters " << endl ;
1070     cout << "  Index    " 
1071          << "  Ene(MeV) " 
1072          << "  Multi    "
1073          << "  Module   "  
1074          << "    X      "
1075          << "    Y      "
1076          << "    Z      "
1077          << " Lambda 1  "
1078          << " Lambda 2  "
1079          << " MaxEnergy "
1080          << " # of prim "
1081          << " Primaries list "      <<  endl;      
1082     
1083     Int_t index ;
1084     for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) {
1085       AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ; 
1086
1087       cout << setw(6) << rp->GetIndexInList() << "     ";
1088       cout << setw(6) << rp->GetEnergy()      << "     ";
1089       cout << setw(6) << rp->GetMultiplicity()<< "     ";
1090       cout << setw(6) << rp->GetPHOSMod()     << "     ";
1091
1092       TVector3  locpos;  
1093       rp->GetLocalPosition(locpos);
1094       cout << setw(8) <<  locpos.X()          << "     ";
1095       cout << setw(8) <<  locpos.Y()          << "     ";
1096       cout << setw(8) <<  locpos.Z()          << "     ";
1097
1098       Float_t lambda[2]; 
1099       rp->GetElipsAxis(lambda);
1100       cout << setw(10)<<  lambda[0]           << "     ";
1101       cout << setw(10)<<  lambda[1]           << "     ";
1102       
1103       
1104       Int_t * primaries; 
1105       Int_t nprimaries;
1106       primaries = rp->GetPrimaries(nprimaries);
1107       cout << setw(8) <<    primaries         << "     ";
1108
1109       for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
1110         cout << setw(4)  <<  primaries[iprimary] << " ";
1111       cout << endl;      
1112     }
1113     cout << endl ;
1114
1115     //Now plot CPV/PPSD recPoints
1116     cout << "EMC clusters " << endl ;
1117     cout << "  Index    " 
1118          << "  Multi    "
1119          << "  Module   "  
1120          << "  Layer    "  
1121          << "    X      "
1122          << "    Y      "
1123          << "    Z      "
1124          << " # of prim "
1125          << " Primaries list "      <<  endl;      
1126     
1127     for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
1128       AliPHOSRecPoint * rp = (AliPHOSRecPoint * )cpvRecPoints->At(index) ; 
1129       cout << setw(6) << rp->GetIndexInList() << "     ";
1130       cout << setw(6) << rp->GetPHOSMod()     << "     ";
1131
1132       if( (strcmp(rp->ClassName() , "AliPHOSPpsdRecPoint" )) == 0){
1133         AliPHOSPpsdRecPoint * ppsd = (AliPHOSPpsdRecPoint*) rp ;
1134         if(ppsd->GetUp())
1135           cout <<"        CPV     ";
1136         else
1137           cout <<"       PPSD     ";
1138       }
1139       else
1140         cout <<"        CPV     ";
1141       
1142       TVector3  locpos;  
1143       rp->GetLocalPosition(locpos);
1144       cout << setw(8) <<  locpos.X()          << "     ";
1145       cout << setw(8) <<  locpos.Y()          << "     ";
1146       cout << setw(8) <<  locpos.Z()          << "     ";
1147       
1148       Int_t * primaries; 
1149       Int_t nprimaries;
1150       primaries = rp->GetPrimaries(nprimaries);
1151       cout << setw(8) <<    primaries         << "     ";
1152
1153       for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
1154         cout << setw(4)  <<  primaries[iprimary] << " ";
1155       cout << endl;      
1156     }
1157
1158
1159     cout << "-------------------------------------------------"<<endl ;
1160   }
1161 }
1162