]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALClusterizerv1.cxx
Corrected argument
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALClusterizerv1.cxx
1
2 /**************************************************************************
3  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  *                                                                        *
5  * Author: The ALICE Off-line Project.                                    *
6  * Contributors are mentioned in the code where appropriate.              *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16
17 /* $Id$ */
18
19 //*-- Author: Yves Schutz (SUBATECH)  & Dmitri Peressounko (SUBATECH & Kurchatov Institute)
20 //  August 2002 Yves Schutz: clone PHOS as closely as possible and intoduction
21 //                           of new  IO (à la PHOS)
22 //////////////////////////////////////////////////////////////////////////////
23 //  Clusterization class. Performs clusterization (collects neighbouring active cells) and 
24 //  unfolds the clusters having several local maxima.  
25 //  Results are stored in TreeR#, branches EMCALTowerRP (EMC recPoints),
26 //  EMCALPreShoRP (CPV RecPoints) and AliEMCALClusterizer (Clusterizer with all 
27 //  parameters including input digits branch title, thresholds etc.)
28 //  This TTask is normally called from Reconstructioner, but can as well be used in 
29 //  standalone mode.
30 // Use Case:
31 //  root [0] AliEMCALClusterizerv1 * cl = new AliEMCALClusterizerv1("galice.root")  
32 //  Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
33 //               //reads gAlice from header file "..."                      
34 //  root [1] cl->ExecuteTask()  
35 //               //finds RecPoints in all events stored in galice.root
36 //  root [2] cl->SetDigitsBranch("digits2") 
37 //               //sets another title for Digitis (input) branch
38 //  root [3] cl->SetRecPointsBranch("recp2")  
39 //               //sets another title four output branches
40 //  root [4] cl->SetTowerLocalMaxCut(0.03)  
41 //               //set clusterization parameters
42 //  root [5] cl->ExecuteTask("deb all time")  
43 //               //once more finds RecPoints options are 
44 //               // deb - print number of found rec points
45 //               // deb all - print number of found RecPoints and some their characteristics 
46 //               // time - print benchmarking results
47
48 // --- ROOT system ---
49
50 #include "TROOT.h" 
51 #include "TFile.h" 
52 #include "TFolder.h" 
53 #include "TMath.h" 
54 #include "TMinuit.h"
55 #include "TTree.h" 
56 #include "TSystem.h" 
57 #include "TBenchmark.h"
58
59 // --- Standard library ---
60
61
62 // --- AliRoot header files ---
63 #include "AliEMCALGetter.h"
64 #include "AliEMCALClusterizerv1.h"
65 #include "AliEMCALRecPoint.h"
66 #include "AliEMCALDigit.h"
67 #include "AliEMCALDigitizer.h"
68 #include "AliEMCAL.h"
69 #include "AliEMCALGeometry.h"
70
71 ClassImp(AliEMCALClusterizerv1)
72
73 Int_t addOn[20][60][60]; 
74
75 //____________________________________________________________________________
76   AliEMCALClusterizerv1::AliEMCALClusterizerv1() : AliEMCALClusterizer()
77 {
78   // default ctor (to be used mainly by Streamer)
79   
80   InitParameters() ; 
81   fDefaultInit = kTRUE ;
82   cout<<"file to read 1"<<endl;
83   ReadFile();
84   cout<<"file read 1"<<endl;
85 }
86
87 //____________________________________________________________________________
88 AliEMCALClusterizerv1::AliEMCALClusterizerv1(const TString alirunFileName, const TString eventFolderName)
89 :AliEMCALClusterizer(alirunFileName, eventFolderName)
90 {
91   // ctor with the indication of the file where header Tree and digits Tree are stored
92   
93   InitParameters() ; 
94   Init() ;
95   fDefaultInit = kFALSE ; 
96   for(Int_t is=0;is<20;is++){ 
97   for(Int_t i=0;i<60;i++){ 
98    for(Int_t j=0;j<60;j++){ 
99            addOn[is][i][j]=0;
100    }
101    }
102  }
103   cout<<"file to read 2"<<endl;
104   ReadFile();
105   cout<<"file read 2"<<endl;
106
107 }
108
109 //____________________________________________________________________________
110   AliEMCALClusterizerv1::~AliEMCALClusterizerv1()
111 {
112   // dtor
113   
114 }
115
116 //____________________________________________________________________________
117 const TString AliEMCALClusterizerv1::BranchName() const 
118
119    return GetName();
120
121 }
122
123 //____________________________________________________________________________
124 Float_t  AliEMCALClusterizerv1::Calibrate(Int_t amp) const
125 {
126   //To be replased later by the method, reading individual parameters from the database 
127   return -fADCpedestalECA + amp * fADCchannelECA ; 
128 }
129
130 //____________________________________________________________________________
131 void AliEMCALClusterizerv1::Exec(Option_t * option)
132 {
133   // Steering method to perform clusterization for events
134   // in the range from fFirstEvent to fLastEvent.
135   // This range is optionally set by SetEventRange().
136   // if fLastEvent=-1 (by default), then process events until the end.
137
138   if(strstr(option,"tim"))
139     gBenchmark->Start("EMCALClusterizer"); 
140   
141   if(strstr(option,"print"))
142     Print("") ; 
143
144   AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
145
146   if (fLastEvent == -1) 
147     //fLastEvent = gime->MaxEvent() - 1;
148     fLastEvent = 1000 - 1;
149   Int_t nEvents   = fLastEvent - fFirstEvent + 1;
150
151   Int_t ievent ;
152   for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
153     gime->Event(ievent,"D") ;
154     GetCalibrationParameters() ;
155
156     fNumberOfECAClusters = 0;
157            
158     MakeClusters() ;
159
160     if(fToUnfold)
161       MakeUnfolding() ;
162
163     WriteRecPoints() ;
164
165     if(strstr(option,"deb"))  
166       PrintRecPoints(option) ;
167
168     //increment the total number of recpoints per run   
169     fRecPointsInRun += gime->ECARecPoints()->GetEntriesFast() ;  
170   }
171   
172   Unload();
173
174   if(strstr(option,"tim")){
175     gBenchmark->Stop("EMCALClusterizer");
176     printf("Exec took %f seconds for Clusterizing %f seconds per event", 
177          gBenchmark->GetCpuTime("EMCALClusterizer"), gBenchmark->GetCpuTime("EMCALClusterizer")/nEvents ) ;
178   }
179
180   SaveHists();
181
182 }
183
184 //____________________________________________________________________________
185 Bool_t AliEMCALClusterizerv1::FindFit(AliEMCALRecPoint * emcRP, AliEMCALDigit ** maxAt, Float_t * maxAtEnergy,
186                                     Int_t nPar, Float_t * fitparameters) const
187
188   // Calls TMinuit to fit the energy distribution of a cluster with several maxima 
189   // The initial values for fitting procedure are set equal to the positions of local maxima.
190   // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
191
192   AliEMCALGetter * gime = AliEMCALGetter::Instance() ; 
193   TClonesArray * digits = gime->Digits() ; 
194   
195   gMinuit->mncler();                     // Reset Minuit's list of paramters
196   gMinuit->SetPrintLevel(-1) ;           // No Printout
197   gMinuit->SetFCN(AliEMCALClusterizerv1::UnfoldingChiSquare) ;  
198                                          // To set the address of the minimization function 
199   TList * toMinuit = new TList();
200   toMinuit->AddAt(emcRP,0) ;
201   toMinuit->AddAt(digits,1) ;
202   
203   gMinuit->SetObjectFit(toMinuit) ;         // To tranfer pointer to UnfoldingChiSquare
204
205   // filling initial values for fit parameters
206   AliEMCALDigit * digit ;
207
208   Int_t ierflg  = 0; 
209   Int_t index   = 0 ;
210   Int_t nDigits = (Int_t) nPar / 3 ;
211
212   Int_t iDigit ;
213
214   AliEMCALGeometry * geom = gime->EMCALGeometry() ; 
215
216   for(iDigit = 0; iDigit < nDigits; iDigit++){
217     digit = maxAt[iDigit]; 
218
219     Int_t relid[2] ;
220     Float_t x = 0.;
221     Float_t z = 0.;
222     geom->AbsToRelNumbering(digit->GetId(), relid) ;
223     geom->PosInAlice(relid, x, z) ;
224
225     Float_t energy = maxAtEnergy[iDigit] ;
226
227     gMinuit->mnparm(index, "x",  x, 0.1, 0, 0, ierflg) ;
228     index++ ;   
229     if(ierflg != 0){ 
230       Error("FindFit", "EMCAL Unfolding  Unable to set initial value for fit procedure : x = %f",  x ) ;
231       return kFALSE;
232     }
233     gMinuit->mnparm(index, "z",  z, 0.1, 0, 0, ierflg) ;
234     index++ ;   
235     if(ierflg != 0){
236        Error("FindFit", "EMCAL Unfolding  Unable to set initial value for fit procedure : z = %f", z) ;
237       return kFALSE;
238     }
239     gMinuit->mnparm(index, "Energy",  energy , 0.05*energy, 0., 4.*energy, ierflg) ;
240     index++ ;   
241     if(ierflg != 0){
242      Error("FindFit", "EMCAL Unfolding  Unable to set initial value for fit procedure : energy = %f", energy) ;      
243       return kFALSE;
244     }
245   }
246
247   Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
248                       //  depends on it. 
249   Double_t p1 = 1.0 ;
250   Double_t p2 = 0.0 ;
251
252   gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ;   // force TMinuit to reduce function calls  
253   gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ;   // force TMinuit to use my gradient  
254   gMinuit->SetMaxIterations(5);
255   gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ;  // No Warnings
256
257   gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ;    // minimize 
258
259   if(ierflg == 4){  // Minimum not found   
260     Error("FindFit", "EMCAL Unfolding  Fit not converged, cluster abandoned " ) ;      
261     return kFALSE ;
262   }            
263   for(index = 0; index < nPar; index++){
264     Double_t err ;
265     Double_t val ;
266     gMinuit->GetParameter(index, val, err) ;    // Returns value and error of parameter index
267     fitparameters[index] = val ;
268    }
269
270   delete toMinuit ;
271   return kTRUE;
272
273 }
274
275 //____________________________________________________________________________
276 void AliEMCALClusterizerv1::GetCalibrationParameters() 
277 {
278   // Gets the parameters for the calibration from the digitizer
279   AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
280
281   if ( !gime->Digitizer() ) 
282     gime->LoadDigitizer();
283   AliEMCALDigitizer * dig = gime->Digitizer();  
284
285   fADCchannelECA   = dig->GetECAchannel() ;
286   fADCpedestalECA  = dig->GetECApedestal();
287   cout<<"ChannelECA, peds "<<fADCchannelECA<<" "<<fADCpedestalECA<<endl;
288 }
289
290 //____________________________________________________________________________
291 void AliEMCALClusterizerv1::Init()
292 {
293   // Make all memory allocations which can not be done in default constructor.
294   // Attach the Clusterizer task to the list of EMCAL tasks
295   
296   AliEMCALGetter * gime = AliEMCALGetter::Instance();
297   if(!gime)
298     gime = AliEMCALGetter::Instance(GetTitle(), fEventFolderName.Data());
299
300   AliEMCALGeometry * geom = gime->EMCALGeometry() ;
301   cout<<"gime,geom "<<gime<<" "<<geom<<endl;
302
303 //Sub  fNTowers = geom->GetNZ() *  geom->GetNPhi() ;
304   fNTowers =400;
305   if(!gMinuit) 
306     gMinuit = new TMinuit(100) ;
307  //Sub if ( !gime->Clusterizer() ) 
308  //Sub   gime->PostClusterizer(this); 
309  BookHists();
310   cout<<"hists booked "<<endl;
311 }
312
313 //____________________________________________________________________________
314 void AliEMCALClusterizerv1::InitParameters()
315
316   // Initializes the parameters for the Clusterizer
317   fNumberOfECAClusters = 0;
318
319   fECAClusteringThreshold   = 0.5;  // value obtained from Alexei
320   fECALocMaxCut = 0.03;
321
322   fECAW0     = 4.5 ;
323   fTimeGate = 1.e-8 ; 
324   fToUnfold = kFALSE ;
325   fRecPointsInRun  = 0 ;
326   fMinECut = 0.3;
327 }
328
329 //____________________________________________________________________________
330 Int_t AliEMCALClusterizerv1::AreNeighbours(AliEMCALDigit * d1, AliEMCALDigit * d2)const
331 {
332   // Gives the neighbourness of two digits = 0 are not neighbour but continue searching 
333   //                                       = 1 are neighbour
334   //                                       = 2 are not neighbour but do not continue searching
335   // neighbours are defined as digits having at least a common vertex 
336   // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster 
337   //                                      which is compared to a digit (d2)  not yet in a cluster  
338
339    AliEMCALGeometry * geom = AliEMCALGetter::Instance()->EMCALGeometry() ;
340
341   Int_t rv = 0 ; 
342
343   Int_t relid1[2] ; 
344  //Sub geom->AbsToRelNumbering(d1->GetId(), relid1) ; 
345     Int_t nSupMod=0;
346     Int_t nTower=0;
347     Int_t nIphi=0;
348     Int_t nIeta=0;
349     Int_t iphi=0;
350     Int_t ieta=0;
351    geom->GetCellIndex(d1->GetId(), nSupMod,nTower,nIphi,nIeta);
352    geom->GetCellPhiEtaIndexInSModule(nTower,nIphi,nIeta, iphi,ieta);
353    relid1[0]=ieta;
354    relid1[1]=iphi;
355
356
357     Int_t nSupMod1=0;
358     Int_t nTower1=0;
359     Int_t nIphi1=0;
360     Int_t nIeta1=0;
361     Int_t iphi1=0;
362     Int_t ieta1=0;
363    geom->GetCellIndex(d2->GetId(), nSupMod1,nTower1,nIphi1,nIeta1);
364    geom->GetCellPhiEtaIndexInSModule(nTower1,nIphi1,nIeta1, iphi1,ieta1);
365    Int_t relid2[2] ; 
366    relid2[0]=ieta1;
367    relid2[1]=iphi1;
368
369   //Sub  geom->AbsToRelNumbering(d2->GetId(), relid2) ; 
370   
371
372   Int_t rowdiff = TMath::Abs( relid1[0] - relid2[0] ) ;  
373   Int_t coldiff = TMath::Abs( relid1[1] - relid2[1] ) ;  
374   
375   if (( coldiff <= 1 )  && ( rowdiff <= 1 )){
376       rv = 1 ; 
377   }
378   else {
379     if((relid2[0] > relid1[0]) && (relid2[1] > relid1[1]+1)) 
380       rv = 2; //  Difference in row numbers is too large to look further 
381   }
382  
383   if (gDebug == 2 ) 
384 if(rv==1)printf("AreNeighbours: neighbours=%d, id1=%d, relid1=%d,%d \n id2=%d, relid2=%d,%d \n", 
385          rv, d1->GetId(), relid1[0], relid1[1],
386          d2->GetId(), relid2[0], relid2[1]) ;   
387   
388   return rv ; 
389 }
390
391 //____________________________________________________________________________
392 void AliEMCALClusterizerv1::Unload() 
393 {
394   // Unloads the Digits and RecPoints
395   AliEMCALGetter * gime = AliEMCALGetter::Instance() ; 
396   gime->EmcalLoader()->UnloadDigits() ; 
397   gime->EmcalLoader()->UnloadRecPoints() ; 
398 }
399  
400 //____________________________________________________________________________
401 void AliEMCALClusterizerv1::WriteRecPoints()
402 {
403
404   // Creates new branches with given title
405   // fills and writes into TreeR.
406
407   AliEMCALGetter *gime = AliEMCALGetter::Instance() ; 
408
409   TObjArray * aECARecPoints = gime->ECARecPoints() ; 
410
411   TClonesArray * digits = gime->Digits() ; 
412   TTree * treeR = gime->TreeR(); ; 
413   
414   Int_t index ;
415
416   //Evaluate position, dispersion and other RecPoint properties for EC section
417   for(index = 0; index < aECARecPoints->GetEntries(); index++)
418     (dynamic_cast<AliEMCALRecPoint *>(aECARecPoints->At(index)))->EvalAll(fECAW0,digits) ;
419   
420   aECARecPoints->Sort() ;
421
422   for(index = 0; index < aECARecPoints->GetEntries(); index++)
423     (dynamic_cast<AliEMCALRecPoint *>(aECARecPoints->At(index)))->SetIndexInList(index) ;
424
425   aECARecPoints->Expand(aECARecPoints->GetEntriesFast()) ; 
426   
427   Int_t bufferSize = 32000 ;    
428   Int_t splitlevel = 0 ; 
429
430   //EC section branch
431   TBranch * branchECA = treeR->Branch("EMCALECARP","TObjArray",&aECARecPoints,bufferSize,splitlevel);
432   branchECA->SetTitle(BranchName());
433
434   branchECA->Fill() ;
435
436 //Sub  gime->WriteRecPoints("OVERWRITE");
437 //Sub  gime->WriteClusterizer("OVERWRITE");
438 }
439
440 //____________________________________________________________________________
441 void AliEMCALClusterizerv1::MakeClusters()
442 {
443   // Steering method to construct the clusters stored in a list of Reconstructed Points
444   // A cluster is defined as a list of neighbour digits
445     
446   AliEMCALGetter * gime = AliEMCALGetter::Instance() ; 
447
448   AliEMCALGeometry * geom = gime->EMCALGeometry() ; 
449
450   TObjArray * aECARecPoints  = gime->ECARecPoints() ; 
451
452   aECARecPoints->Delete() ;
453
454   TClonesArray * digits = gime->Digits() ; 
455   TClonesArray * digitsC =  dynamic_cast<TClonesArray*>(digits->Clone()) ;
456
457   // Clusterization starts    
458   TIter nextdigit(digitsC) ;
459   AliEMCALDigit * digit;
460
461 //just for hist
462 /*
463   while ( (digit = dynamic_cast<AliEMCALDigit *>(nextdigit())) ) { // scan over the list of digitsC
464           digitAmp->Fill(digit->GetAmp());
465   }
466   */
467 /////////// 
468
469   while ( (digit = dynamic_cast<AliEMCALDigit *>(nextdigit())) ) { // scan over the list of digitsC
470     AliEMCALRecPoint * clu = 0 ; 
471     
472     TArrayI clusterECAdigitslist(50000);   
473    
474 //Sub    if (gDebug == 2) { 
475    //  printf("MakeClusters: id = %d, ene = %f , thre = %f \n", digit->GetId(),Calibrate(digit->GetAmp()),
476 //         fECAClusteringThreshold) ;  
477 //    }
478 ////////////////////////temp solution, embedding///////////////////
479    int nSupMod=0, nTower=0, nIphi=0, nIeta=0;
480    int iphi=0, ieta=0;
481           geom->GetCellIndex(digit->GetId(), nSupMod,nTower,nIphi,nIeta);
482           geom->GetCellPhiEtaIndexInSModule(nTower,nIphi,nIeta, iphi,ieta);
483
484          /////////////////////////////////// 
485
486 //cout<<ieta<<" "<<iphi<<endl;
487
488 //    if ( geom->IsInECA(digit->GetId()) && (Calibrate(digit->GetAmp()) > fECAClusteringThreshold  ) ){
489     if (geom->CheckAbsCellId(digit->GetId()) && (Calibrate(digit->GetAmp()+addOn[nSupMod-1][ieta-1][iphi-1]) > fECAClusteringThreshold  ) ){
490 if(addOn[nSupMod-1][ieta-1][iphi-1]>0)cout<<"11 digit, add "<<ieta<<" "<<iphi<<" "<<addOn[nSupMod-1][ieta-1][iphi-1]<<" "<<digit->GetAmp()<<endl;
491 //          cout<<"crossed the threshold "<<endl;
492       Int_t iDigitInECACluster = 0;
493       // start a new Tower RecPoint
494       if(fNumberOfECAClusters >= aECARecPoints->GetSize()) 
495           aECARecPoints->Expand(2*fNumberOfECAClusters+1) ;
496       AliEMCALRecPoint * rp = new  AliEMCALRecPoint("") ; 
497       aECARecPoints->AddAt(rp, fNumberOfECAClusters) ;
498       clu = dynamic_cast<AliEMCALRecPoint *>(aECARecPoints->At(fNumberOfECAClusters)) ; 
499       fNumberOfECAClusters++ ; 
500       clu->AddDigit(*digit, Calibrate(digit->GetAmp()+addOn[nSupMod-1][ieta-1][iphi-1])) ; 
501       clusterECAdigitslist[iDigitInECACluster] = digit->GetIndexInList() ;      
502       iDigitInECACluster++ ; 
503 //    cout<<" 1st setp:cluno, digNo "<<fNumberOfECAClusters<<" "<<iDigitInECACluster<<endl;
504       digitsC->Remove(digit) ; 
505       if (gDebug == 2 ) 
506         printf("MakeClusters: OK id = %d, ene = %f , thre = %f \n", digit->GetId(),Calibrate(digit->GetAmp()), fECAClusteringThreshold) ;  
507       nextdigit.Reset() ;
508       
509       AliEMCALDigit * digitN ; 
510       Int_t index = 0 ;
511
512       // Find the neighbours
513       while (index < iDigitInECACluster){ // scan over digits already in cluster 
514         digit =  (AliEMCALDigit*)digits->At(clusterECAdigitslist[index])  ;      
515         index++ ; 
516         while ( (digitN = (AliEMCALDigit *)nextdigit())) { // scan over the reduced list of digits 
517 //      cout<<"we have new digit "<<endl;
518           // check that the digit is above the min E Cut
519          ////////////////////
520           geom->GetCellIndex(digitN->GetId(), nSupMod,nTower,nIphi,nIeta);
521           geom->GetCellPhiEtaIndexInSModule(nTower,nIphi,nIeta, iphi,ieta);
522           ////////////////
523           if(Calibrate(digitN->GetAmp()+addOn[nSupMod-1][ieta-1][iphi-1]) < fMinECut  )  digitsC->Remove(digitN);
524 //      cout<<" new digit above ECut "<<endl;
525           Int_t ineb = AreNeighbours(digit, digitN);       // call (digit,digitN) in THAT oder !!!!! 
526 //      cout<<" new digit neighbour?? "<<ineb<<endl;
527          switch (ineb ) {
528           case 0 :   // not a neighbour
529             break ;
530           case 1 :   // are neighbours 
531 if(addOn[nSupMod-1][ieta-1][iphi-1]>0)cout<<"22 digit, add "<<nSupMod<<" "<<ieta<<" "<<iphi<<" "<<addOn[nSupMod-1][ieta-1][iphi-1]<<" "<<digit->GetAmp()<<endl;
532             clu->AddDigit(*digitN, Calibrate( digitN->GetAmp()+addOn[nSupMod-1][ieta-1][iphi-1]) ) ;
533             clusterECAdigitslist[iDigitInECACluster] = digitN->GetIndexInList() ; 
534             iDigitInECACluster++ ; 
535 //    cout<<"when neighbour: cluno, digNo "<<digit->GetId()<<" "<<fNumberOfECAClusters<<" "<<iDigitInECACluster<<endl;
536             digitsC->Remove(digitN) ;
537 //          break ;
538 //          case 2 :   // too far from each other
539 //Subh      goto endofloop1;   
540 //          cout<<"earlier go to end of loop"<<endl;   
541           } // switch
542     //cout<<"in nextDigit loop "<<fNumberOfECAClusters<<" "<<iDigitInECACluster<<endl;
543         } // while digitN
544         
545 //Sub      endofloop1: ;
546         nextdigit.Reset() ; 
547       } // loop over ECA cluster
548     } // energy threshold
549     else if(Calibrate(digit->GetAmp()+addOn[nSupMod-1][ieta-1][iphi-1]) < fMinECut  ){
550 if(addOn[nSupMod-1][ieta-1][iphi-1]>0)cout<<"33 digit, add  "<<ieta<<" "<<iphi<<" "<<addOn[nSupMod-1][ieta-1][iphi-1]<<" "<<digit->GetAmp()<<endl;
551       digitsC->Remove(digit);
552     }
553     //cout<<"after endofloop: cluno, digNo "<<fNumberOfECAClusters<<endl;
554   } // while digit  
555   delete digitsC ;
556 cout<<"total no of clusters "<<fNumberOfECAClusters<<"from "<<digits->GetEntriesFast()<<" digits"<<endl; 
557 }
558
559 //____________________________________________________________________________
560 void AliEMCALClusterizerv1::MakeUnfolding() const
561 {
562   Fatal("AliEMCALClusterizerv1::MakeUnfolding", "--> Unfolding not implemented") ;
563  
564 }
565
566 //____________________________________________________________________________
567 Double_t  AliEMCALClusterizerv1::ShowerShape(Double_t r)
568
569   // Shape of the shower (see EMCAL TDR)
570   // If you change this function, change also the gradient evaluation in ChiSquare()
571
572   Double_t r4    = r*r*r*r ;
573   Double_t r295  = TMath::Power(r, 2.95) ;
574   Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
575   return shape ;
576 }
577
578 //____________________________________________________________________________
579 void  AliEMCALClusterizerv1::UnfoldCluster(AliEMCALRecPoint * /*iniTower*/, 
580                                            Int_t /*nMax*/, 
581                                            AliEMCALDigit ** /*maxAt*/, 
582                                            Float_t * /*maxAtEnergy*/) const
583 {
584   // Performs the unfolding of a cluster with nMax overlapping showers 
585   
586   Fatal("UnfoldCluster", "--> Unfolding not implemented") ;
587
588 }
589
590 //_____________________________________________________________________________
591 void AliEMCALClusterizerv1::UnfoldingChiSquare(Int_t & /*nPar*/, Double_t * /*Grad*/,
592                                                Double_t & /*fret*/,
593                                                Double_t * /*x*/, Int_t /*iflag*/)
594 {
595   // Calculates the Chi square for the cluster unfolding minimization
596   // Number of parameters, Gradient, Chi squared, parameters, what to do
597   
598   ::Fatal("UnfoldingChiSquare","Unfolding not implemented") ;
599 }
600 //____________________________________________________________________________
601 void AliEMCALClusterizerv1::Print(Option_t * /*option*/)const
602 {
603   // Print clusterizer parameters
604
605   TString message("\n") ; 
606   
607   if( strcmp(GetName(), "") !=0 ){
608     
609     // Print parameters
610  
611     TString taskName(GetName()) ;
612     taskName.ReplaceAll(Version(), "") ;
613     
614     printf("--------------- "); 
615     printf(taskName.Data()) ; 
616     printf(" "); 
617     printf(GetTitle()) ; 
618     printf("-----------\n");  
619     printf("Clusterizing digits from the file: "); 
620     printf(taskName.Data());  
621     printf("\n                           Branch: "); 
622     printf(GetName()); 
623     printf("\n                       ECA Local Maximum cut    = %f", fECALocMaxCut); 
624     printf("\n                       ECA Logarithmic weight   = %f", fECAW0); 
625     if(fToUnfold)
626       printf("\nUnfolding on\n");
627     else
628       printf("\nUnfolding off\n");
629     
630     printf("------------------------------------------------------------------"); 
631   }
632   else
633     printf("AliEMCALClusterizerv1 not initialized ") ;
634 }
635
636 //____________________________________________________________________________
637 void AliEMCALClusterizerv1::PrintRecPoints(Option_t * option)
638 {
639   // Prints list of RecPoints produced at the current pass of AliEMCALClusterizer
640
641   TObjArray * aECARecPoints = AliEMCALGetter::Instance()->ECARecPoints() ; 
642   printf("PrintRecPoints: Clusterization result:") ; 
643   
644   printf("event # %d\n", gAlice->GetEvNumber() ) ;
645   printf("           Found %d ECA Rec Points\n ", 
646          aECARecPoints->GetEntriesFast()) ; 
647
648   fRecPointsInRun +=  aECARecPoints->GetEntriesFast() ; 
649   
650   if(strstr(option,"all")) {
651     Int_t index =0;
652     printf("\n-----------------------------------------------------------------------\n") ;
653     printf("Clusters in ECAL section\n") ;
654     printf("Index    Ene(GeV) Multi Module     phi     r   theta    X    Y      Z   Dispersion Lambda 1   Lambda 2  # of prim  Primaries list\n") ;      
655    Float_t maxE=0; 
656    Float_t maxL1=0; 
657    Float_t maxL2=0; 
658    Float_t maxDis=0; 
659
660     for (index = 0 ; index < aECARecPoints->GetEntries() ; index++) {
661       AliEMCALRecPoint * rp = dynamic_cast<AliEMCALRecPoint * >(aECARecPoints->At(index)) ; 
662       TVector3  globalpos;  
663       //rp->GetGlobalPosition(globalpos);
664       TVector3  localpos;  
665       rp->GetLocalPosition(localpos);
666       Float_t lambda[2]; 
667       rp->GetElipsAxis(lambda);
668       Int_t * primaries; 
669       Int_t nprimaries;
670       primaries = rp->GetPrimaries(nprimaries);
671       printf("\n%6d  %8.4f  %3d     %4.1f    %4.1f %4.1f  %4.1f %4.1f %4.1f    %4.1f   %4f  %4f    %2d     : ", 
672              rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(),
673              globalpos.X(), globalpos.Y(), globalpos.Z(), localpos.X(), localpos.Y(), localpos.Z(), 
674              rp->GetDispersion(), lambda[0], lambda[1], nprimaries) ; 
675   /////////////
676       if(rp->GetEnergy()>maxE){
677               maxE=rp->GetEnergy();
678               maxL1=lambda[0];
679               maxL2=lambda[1];
680               maxDis=rp->GetDispersion();
681       }
682       pointE->Fill(rp->GetEnergy());
683       pointL1->Fill(lambda[0]);
684       pointL2->Fill(lambda[1]);
685       pointDis->Fill(rp->GetDispersion());
686       pointMult->Fill(rp->GetMultiplicity());
687       ///////////// 
688       for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
689         printf("%d ", primaries[iprimary] ) ; 
690       } 
691     }
692
693       MaxE->Fill(maxE);
694       MaxL1->Fill(maxL1);
695       MaxL2->Fill(maxL2);
696       MaxDis->Fill(maxDis);
697
698
699     printf("\n-----------------------------------------------------------------------\n");
700   }
701 }
702   void AliEMCALClusterizerv1::BookHists()
703 {
704         pointE = new TH1F("pointE","point energy", 2000, 0.0, 150.);
705         pointL1 = new TH1F("pointL1","point L1", 1000, 0.0, 3.);
706         pointL2 = new TH1F("pointL2","point L2", 1000, 0.0, 3.);
707         pointDis = new TH1F("pointDis","point Dis", 1000, 0.0, 3.);
708         pointMult = new TH1F("pointMult","point Mult", 100, 0.0, 100.);
709         digitAmp = new TH1F("digitAmp","Digit Amplitude", 2000, 0.0, 5000.);
710         MaxE = new TH1F("maxE","Max point energy", 2000, 0.0, 150.);
711         MaxL1 = new TH1F("maxL1","Max point L1", 1000, 0.0, 3.);
712         MaxL2 = new TH1F("maxL2","Max point L2", 1000, 0.0, 3.);
713         MaxDis = new TH1F("maxDis","Max point Dis", 1000, 0.0, 3.);
714 }
715 void AliEMCALClusterizerv1::SaveHists()
716 {
717  recofile=new TFile("reco.root","RECREATE"); 
718         pointE->Write();
719         pointL1->Write();
720         pointL2->Write();
721         pointDis->Write();
722         pointMult->Write();
723         digitAmp->Write();
724       MaxE->Write();
725       MaxL1->Write();
726       MaxL2->Write();
727       MaxDis->Write();
728 recofile->Close();
729 }
730
731 void AliEMCALClusterizerv1::ReadFile()
732 {
733   return; // 3-jan-05
734         FILE *fp = fopen("hijing1.dat","r");
735         for(Int_t line=0;line<9113;line++){
736          Int_t eg,l1,l2,sm;
737          Int_t ncols0;
738          ncols0 = fscanf(fp,"%d %d %d %d",&sm,&l1,&l2,&eg);
739         // cout<<eg<<" "<<l1<<" "<<l2<<endl;
740          addOn[sm-1][l1-1][l2-1]=eg;
741          //addOn[sm-1][l1-1][l2-1]=0;
742         }
743 }
744