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