]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALFolder.cxx
finish clean-up of EMCAL geometry
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALFolder.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2007, 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 //_________________________________________________________________________
19 // Top EMCAL folder which will keep all 
20 // information about EMCAL itself,
21 // super Modules (SM), modules, towers, 
22 // set of hists and so on.
23 //
24 //*-- Author: Aleksei Pavlinov (WSU, Detroit, USA) 
25
26 #include "AliEMCALFolder.h"
27 #include "AliEMCALHistoUtilities.h"
28 #include "AliEMCALGeometry.h"
29 #include "AliEMCALSuperModule.h"
30 #include "AliEMCALCell.h"
31 #include "AliESDCaloCluster.h"
32
33 #include "AliRun.h"
34
35 #include "AliEMCALCalibData.h"
36 #include "AliCDBMetaData.h"
37 #include "AliCDBId.h"
38 #include "AliCDBEntry.h"
39 #include "AliCDBManager.h"
40 #include "AliCDBStorage.h"
41
42 #include "AliEMCALCalibCoefs.h"
43 #include "AliEMCALDigit.h"
44 #include "AliEMCALRecPoint.h"
45
46 #include "AliEMCALPi0SelectionParam.h"
47
48 #include <cassert>
49
50 #include <TROOT.h>
51 #include <TStyle.h>
52 #include <TList.h>
53 #include <TH1.h>
54 #include <TF1.h>
55 #include <TFile.h>
56 #include <TCanvas.h>
57 #include <TClonesArray.h>
58 #include <TKey.h>
59 #include <TNtuple.h>
60 #include <TLegend.h>
61 #include <TLegendEntry.h>
62 #include <TLine.h>
63
64   const TString AliEMCALFolder::fgkBaseFolderName("EMCAL");
65   const TString AliEMCALFolder::fgkCCFirstName("CCFIRST");
66   const TString AliEMCALFolder::fgkCCinName("CCIN");
67   const TString AliEMCALFolder::fgkCCoutName("CCOUT");
68   const TString AliEMCALFolder::fgkDirOfRootFiles("$HOME/ALICE/SHISHKEBAB/RF/CALIB/JUL16/");
69
70 typedef  AliEMCALHistoUtilities u;
71
72 ClassImp(AliEMCALFolder)
73
74 //AliEMCALGeometry* AliEMCALFolder::fGeometry = 0;
75
76 //_____________________________________________________________
77 AliEMCALFolder::AliEMCALFolder() : 
78   TFolder(), 
79   fCounter(0), fGeometry(0), fNumOfCell(0), fLhists(0), fLofCells(0),fPi0SelPar(0),fCalibData(0),
80   fCellNtuple(0),fLobj(0)
81 {
82   //default constructor
83 }
84
85 //_____________________________________________________________
86 AliEMCALFolder::AliEMCALFolder(const AliEMCALFolder& folder) : 
87   TFolder(folder.GetName(),folder.GetTitle()), 
88   fCounter(folder.fCounter), 
89   fGeometry(folder.fGeometry), fNumOfCell(folder.fNumOfCell), 
90   fLhists(folder.fLhists), fLofCells(folder.fLofCells),
91   fPi0SelPar(folder.fPi0SelPar),fCalibData(folder.fCalibData),
92   fCellNtuple(folder.fCellNtuple),fLobj(folder.fLobj)
93 {
94   //copy constructor
95 }
96
97 //_____________________________________________________________
98 AliEMCALFolder::AliEMCALFolder(const char* name, const char* title, Bool_t putToBrowser) : 
99   TFolder(name,title),
100   fCounter(-1), fGeometry(0), fNumOfCell(0), fLhists(0), fLofCells(0),fPi0SelPar(0),fCalibData(0),
101   fCellNtuple(0),fLobj(0)
102 {
103   Init(putToBrowser);
104 }
105
106 //_____________________________________________________________
107 AliEMCALFolder::AliEMCALFolder(const Int_t it, const char* title, Bool_t putToBrowser) : 
108   TFolder(Form("%s_%2.2i", AliEMCALFolder::fgkBaseFolderName.Data(),it),title),
109   fCounter(it), fGeometry(0), fNumOfCell(0), fLhists(0), fLofCells(0),fPi0SelPar(0),fCalibData(0),
110   fCellNtuple(0),fLobj(0)
111 {
112   Init(putToBrowser);
113 }
114
115 //_____________________________________________________________
116 AliEMCALFolder::~AliEMCALFolder()
117 {
118   // dtor
119 }
120
121 //_____________________________________________________________
122 void AliEMCALFolder::Init(Bool_t putToBrowser)
123 {
124   // Initialize all data structure
125   fLobj = new TList;
126   fLobj->SetName("Objects"); // name is good ?
127   this->Add((TObject*)fLobj);
128   //this->AddObject((TObject*)fLobj, kTRUE);
129   // Get default geometry - "SHISH_77_TRD1_2X2_FINAL_110DEG"; May 29, 2007
130   fGeometry = AliEMCALGeometry::GetInstance(); // should be define before 
131   fLobj->Add(fGeometry);
132
133   // Initial cc with decalibration
134   // Jun 13, 2007;
135   // Jul 13 - See ~/macros/ALICE/sim.C  for choice of CDB
136   AliEMCALCalibData *calData[1];
137   // Get from defined arrea;
138   // First table is table which used in rec.points finder.
139   Add(AliEMCALCalibCoefs::GetCalibTableFromDb(fgkCCFirstName.Data(),calData));
140   fCalibData = calData[0];
141   fLobj->Add(fCalibData);
142   if(GetIterationNumber()<=1) {
143     Add(AliEMCALCalibCoefs::GetCalibTableFromDb(fgkCCinName.Data(), calData));
144   }
145
146   // Selection Parameter
147   fPi0SelPar = AliEMCALPi0SelectionParam::Set1();
148   this->Add(fPi0SelPar);
149   //
150   fLhists = BookHists();
151   fLobj->Add(fLhists);
152
153   // dimension should be get from geometry - 4*12*24*11); 
154   fNumOfCell = fGeometry->GetNCells();
155   fLofCells  = new AliEMCALCell*[fNumOfCell];
156   for(int i=0; i<fNumOfCell; i++) fLofCells[i] = 0;
157
158   printf("<I> Create AliEMCALFolder : it %i : name %s\n ", fCounter, GetName());
159
160   if(putToBrowser) gROOT->GetListOfBrowsables()->Add(this); // for testing purpuse
161
162
163 //_____________________________________________________________
164 AliEMCALSuperModule* AliEMCALFolder::GetSuperModule(const Int_t nm)
165 {
166   // Oct 15, 2007
167   AliEMCALSuperModule *sm = 0;
168
169   TObject *set = FindObject(Form("SM%2.2i",nm));
170   if(set) sm = (AliEMCALSuperModule*)set;
171
172   return sm;
173 }
174
175 //_____________________________________________________________
176 AliEMCALCell* AliEMCALFolder::GetCell(const Int_t absId)
177 { // May 30, 2007
178   if(absId<0 || absId >= fNumOfCell) return 0;
179   else return fLofCells[absId];
180 }  
181
182 //_____________________________________________________________
183 void  AliEMCALFolder::SetCell(AliEMCALCell *cell, const Int_t absId) 
184 {
185   // Oct 15, 2007
186   if(absId>=0 && absId < fNumOfCell) {
187     fLofCells[absId] = cell;
188   }
189 }  
190
191 //_____________________________________________________________
192 AliEMCALPi0SelectionParRec* AliEMCALFolder::GetPi0SelectionParRow(Int_t nrow)
193 {
194   // Oct 15, 2007
195   AliEMCALPi0SelectionParRec* r=0;
196   if(fPi0SelPar) {
197     r = fPi0SelPar->GetTable(nrow);
198   }
199   return r;
200 }
201
202 //_____________________________________________________________
203 void AliEMCALFolder::FillPi0Candidate(const Double_t mgg, AliESDCaloCluster* cl1, AliESDCaloCluster* cl2)
204 {
205   // Oct 15, 2007
206   static Int_t absIdMax, nm1, nm2;
207
208   u::FillH1(fLhists, 0, 1.);  // number entries 
209   u::FillH1(fLhists, 1, mgg);
210
211   nm1 = GetSMNumber(cl1);
212   nm2 = GetSMNumber(cl2);
213
214   if(nm1==-1 || nm2==-1) assert(0);
215
216   if(nm1 != nm2) return; // Both cluster should be in the same SM
217
218   AliESDCaloCluster* cl = cl1;
219   if(cl1->E() < cl2->E()) cl = cl2; // Get cluster with highest energy
220
221   const Int_t  kNdigits  = cl->GetNumberOfDigits();
222   const Short_t* absId   = cl->GetDigitIndex()->GetArray();
223
224   AliEMCALCalibCoefs *tFirst = GetCCFirst();
225   AliEMCALCalibCoef *rFirst=0;
226
227   int    indMax = 0, id=0;
228   id = Int_t(absId[0]);
229   rFirst = tFirst->GetTable(id);
230   double emax   = 0;//cl->GetTrueDigitEnergy(indMax, rFirst->fCc);
231   if(kNdigits > 1) {
232     for(int i=1; i<kNdigits; i++) {
233       id = Int_t(absId[i]);
234       rFirst = tFirst->GetTable(id);
235       if(emax < 0){//cl->GetTrueDigitEnergy(i, rFirst->fCc)) {
236         indMax = i;
237         emax   = 0;//cl->GetTrueDigitEnergy(i, rFirst->fCc);
238       }
239     }
240   }
241   if(emax/cl->E() > 0.5) { // more than 50% of cluster energy
242     u::FillH1(fLhists, 0, 2.); // number "good" entries 
243     absIdMax = Int_t(absId[indMax]);
244     FillPi0Candidate(mgg, absIdMax, nm1);
245   }
246 }
247
248 //_____________________________________________________________
249 void AliEMCALFolder::FillPi0Candidate(const Double_t mgg, Int_t absIdMax, Int_t nm)
250 {
251   // Jun 08
252   static Int_t nSupModMax, nModuleMax, nIphiMax, nIetaMax, iphiCellMax, ietaCellMax;
253   static AliEMCALCell* cell;
254   static TFolder *set; 
255   static AliEMCALSuperModule *sm;
256
257   fGeometry->GetCellIndex(absIdMax, nSupModMax, nModuleMax, nIphiMax, nIetaMax);
258   if(nm != nSupModMax) assert(0);
259
260   fGeometry->GetCellPhiEtaIndexInSModule(nSupModMax, nModuleMax, nIphiMax, nIetaMax, iphiCellMax, ietaCellMax);
261
262   cell = 0;
263   set  = 0;
264   sm   = 0;
265   if(GetCell(absIdMax)==0) {
266     cell = new AliEMCALCell(absIdMax, Form("sm%2.2i:phi%2.2i:eta%2.2i(%4.4i)",nSupModMax,iphiCellMax,ietaCellMax,absIdMax));
267     SetCell(cell, absIdMax);
268     // For browser
269     set  = dynamic_cast<TFolder*>(FindObject(Form("SM%2.2i",nSupModMax)));
270     if(set==0) {
271       sm = new  AliEMCALSuperModule(nSupModMax);
272       Add(sm);
273       sm->SetParent(this);
274       sm->Init();
275     } else {
276       sm = dynamic_cast<AliEMCALSuperModule*>(set);
277     }
278     if(sm) {
279       sm->AddCellToEtaRow(cell, ietaCellMax);
280       cell->SetParent(sm);
281     }
282     // 
283     cell->SetCCfromCCTable(GetCCIn());
284   } else {
285     cell = GetCell(absIdMax);
286     set  = dynamic_cast<TFolder*>(FindObject(Form("SM%2.2i",nm)));
287     if(set) sm = (AliEMCALSuperModule*)set;
288   }
289   if(sm == 0) assert(0);
290   if(nm != sm->GetSMNumber()) assert(0);
291
292   u::FillH1(sm->GetHists(), 0, mgg);
293   cell->FillEffMass(mgg);
294 }
295
296 //_____________________________________________________________
297 void AliEMCALFolder::FitAllSMs()
298 { // Jun 14, 2007
299   // Only first SM now - should be changed in the future 
300    AliEMCALSuperModule *sm0 = GetSuperModule(0);
301    sm0->FitForAllCells();
302    // Get input calibration table
303    AliEMCALCalibCoefs *ccIn = GetCCIn();
304    if(ccIn == 0) {
305      printf("<E> no input cc \n"); 
306      return;
307    }
308    // New calibration table
309    AliEMCALCalibCoefs *ccOut = new AliEMCALCalibCoefs(fgkCCoutName.Data(), ccIn->GetNRows());
310    AliEMCALCalibCoef *rIn=0, rOut;
311    for(Int_t i=0; i<ccIn->GetNRows(); i++){
312      rIn  = ccIn->GetTable(i);
313      rOut = (*rIn);
314      AliEMCALCell* cell = GetCell(rIn->fAbsId);
315      if(cell && cell->GetSupMod() == 0) { // only first module now
316        rOut.fCc = cell->GetCcOut();
317      }
318      ccOut->AddAt(&rOut);
319    }
320    ccOut->Purge();
321    Add(ccOut);
322 }
323
324 //_____________________________________________________________
325 AliEMCALCalibCoefs* AliEMCALFolder::GetCCTable(const char* name) const
326 {
327   // Oct 15, 2007
328   TObject *obj = FindObject(name);
329   if(obj) return (AliEMCALCalibCoefs*)obj;
330   else    return 0;
331 }
332
333 //_____________________________________________________________
334 Int_t AliEMCALFolder::GetSMNumber(AliESDCaloCluster* cl)
335 {
336   // Oct 15, 2007
337   static Int_t absId, nSupMod, nModule, nIphi, nIeta;
338   nSupMod = -1; // if negative something wrong
339   if(cl) {
340     absId = Int_t(cl->GetDigitIndex()->At(0));
341     fGeometry->GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
342   }
343   return nSupMod;
344 }
345
346 // Recalibration staf - Jun 18,2007
347 //_____________________________________________________________
348 AliEMCALRecPoint* AliEMCALFolder::GetRecPoint(AliESDCaloCluster *cl, AliEMCALCalibCoefs *tOld,AliEMCALCalibCoefs *tNew,
349 TList *l, Double_t deff, Double_t w0, Double_t phiSlope)
350 {
351   //
352   // Static function;
353   // Get recalibrated rec.point from ESD cluster
354   // If tNew == 0 -> get ideal calibration with  adcCHANNELEC
355   //
356   static Double_t adcCHANNELEC = 0.0153;  // Update 24 Apr 2007: 250./16/1024 - width of one ADC channel in GeV
357   //static Float_t ECAW0 = 4.5; // hard coded now - see AliEMCALClusterizerv1::InitParameters()
358   static Double_t eCAW0 = 5.5; // Beter case for simulation 
359   Int_t ampDigi=0, indMax=-1;
360   Double_t eDigiNew=0.0, eDigiMax=0.0; 
361   static TArrayD ed;
362
363   if(w0 > 0.5) eCAW0 = w0;
364   AliEMCALRecPoint *rp=0;
365   AliEMCALCalibCoef *rOld=0, *rNew=0;
366   //   printf(" AliEMCALFolder::GetRecPoint() : RECALIBRATION : w0 %f eCAW0 %f \n", w0, eCAW0);
367   if(cl && tOld){
368     // cl->PrintClusterInfo(1);
369     const Int_t kNdg   = cl->GetNumberOfDigits();
370     //    const Int_t nkPrim = cl->GetNumberOfPrimaries();
371
372     const Short_t  kPrim    = cl->GetLabel();
373     const Short_t* dgAbsId = cl->GetDigitIndex()->GetArray();
374     //    const UShort_t* dgAmp   = cl->GetDigitAmplitude(); // This is energy - bad definition
375
376     rp = new AliEMCALRecPoint(""); // opt=""
377     rp->SetClusterType(AliESDCaloCluster::kEMCALClusterv1);
378     AliEMCALDigit* dg=0;
379     TClonesArray digits("AliEMCALDigit", kNdg);
380     Int_t absId = 0;
381     ed.Set(kNdg); // resize array
382     for(Int_t i=0; i<kNdg; i++){
383       // Save just abs id and amplitude of digits which will be used for recalculation of
384       // cluster energy and position
385       absId   = Int_t(dgAbsId[i]);
386       rOld    = tOld->GetTable(absId);
387       //ampDigi = cl->GetTrueDigitAmplitude(i, rOld->fCc); // True amplitude
388
389       new(digits[i]) AliEMCALDigit(Int_t(kPrim),0, absId, ampDigi, 0.0, i, 0.0); 
390       dg     =  (AliEMCALDigit*)digits[i];
391
392       if(tNew) rNew = tNew->GetTable(absId);
393       if(rNew) {
394         rNew  = tNew->GetTable(absId);
395         eDigiNew = Double_t(ampDigi) * rNew->fCc;     // Recalibrate with new cc
396       } else {
397         eDigiNew = Double_t(ampDigi) * adcCHANNELEC; // Ideal calibration
398       }
399       //eDigiNew = Double_t(cl->GetTrueDigitEnergy(i)); // Copy from ESD for checking
400       rp->AddDigit(*dg, Float_t(eDigiNew));
401       ed[i] = eDigiNew;
402       if(eDigiMax<eDigiNew) {
403         eDigiMax = eDigiNew;
404         indMax   = i;
405       }
406       u::FillH1(l, 14, eDigiNew);
407       u::FillH1(l, 15, Double_t(absId));
408       //printf("<I> digit %i amp %i rOld->fCc %6.5f GeV rNew->fCc %6.5f GeV\n", i, ampDigi, rOld->fCc, rNew->fCc);
409     }
410     //printf("<I> recalibration of digits was done ! \n");
411     //    rp->EvalAll(eCAW0, &digits);
412     if(indMax>=0) rp->SetIndMaxDigit(indMax);
413     if(deff > 0.0) { // for fit
414       rp->EvalLocalPositionFit(deff, eCAW0, phiSlope, &digits); // I need just position
415     } else { // get w0 and deff from parametrisation - Sep 4, 2007 
416       rp->EvalLocalPosition2(&digits, ed);
417     }
418     digits.Delete();
419   }
420   //rp->Print("print");
421   return rp;
422 }
423
424 //_____________________________________________________________
425 void  AliEMCALFolder::Save(const char *fn, const char *opt)
426
427   //
428   // Jun 5, 2007; See TFileIter and StFMC.cxx
429   // Jul 16 - added fgkDirOfRootFiles
430   // Sep 7, 2007 - should be changed without TFileIter
431   /*
432   TString FN = fgkDirOfRootFiles;
433   FN += fn;
434   if(FN.Contains(".root")==0) FN += ".root";
435   TFileIter f(FN.Data(),opt,"EMCAL object");
436   UInt_t eventNum  = 0; // just one object
437   UInt_t runNumber = 0; // 0 now, - may statistics on selector
438   f.NextEventPut(this, eventNum, runNumber);
439   printf(" Save %s to file %s\n", GetName(), FN.Data());
440   */
441   if(fn || opt);
442 }
443
444 //_____________________________________________________________
445 AliEMCALFolder* AliEMCALFolder::ReadFolder(const char *fn, const char *opt)
446
447   //
448   // Jun 27, 2007
449   // Jul 16 - added fgkDirOfRootFiles
450   //
451   printf("<I> AliEMCALFolder::ReadFolder(%s,%s)\n",fn,opt); 
452   AliEMCALFolder* emcal = 0;
453   TH1::AddDirectory(0); // this is obligatory
454
455   TString sfn = fgkDirOfRootFiles;
456   sfn += fn;
457   if(sfn.Contains(".root")==0) sfn += ".root";
458
459   TFile f(sfn.Data(),opt);
460   if(f.IsOpen()) {
461     TList *l = f.GetListOfKeys();
462     printf("<I> The total number of the objects: %d \n File %s\n", l->GetSize(), sfn.Data());
463
464     TKey *key = (TKey*)l->At(0);
465     emcal = (AliEMCALFolder*)key->ReadObj();
466     f.Close();
467     if(emcal) emcal->InitAfterRead();
468   }
469   return emcal;
470 }
471
472 //_____________________________________________________________
473 void  AliEMCALFolder::InitAfterRead()
474
475   // Oct 15, 2007
476   fLobj    = (TList*)FindObject("Objects");
477   if(fLobj) {
478     fLhists = (TList*)fLobj->FindObject("HistsOfEmcal");
479   }
480 }
481
482 //_____________________________________________________________
483 void AliEMCALFolder::DrawQA(const int nsm)
484
485   //
486   // Jun 25, 2007
487   //
488
489   AliEMCALSuperModule* sm = GetSuperModule(nsm);
490   if(sm==0) return;
491   TList *l = sm-> GetHists();
492   Int_t nx=2, ny=2, wh=530, ww=750;
493
494   TCanvas *c = new TCanvas(Form("QA_%i",GetIterationNumber()), Form("QA_%i",GetIterationNumber()),
495                            10, 10, ww, wh);
496   c->Divide(nx,ny);
497
498   int ic=1;
499   c->cd(ic++);
500   TH1 *h1 = (TH1*)l->At(0);
501   sm->FitEffMassHist(); 
502   u::DrawHist(h1,2);
503   h1->SetAxisRange(0.03, 0.28);
504
505   c->cd(ic++);
506   sm->DrawCC(0);  
507   TH1 *hccin = (TH1*)l->At(1);
508   hccin->SetAxisRange(14., 20.);
509
510   gStyle->SetOptStat(1111);
511   c->cd(ic++);
512   TH1 *hmass = (TH1*)l->At(3);
513   u::DrawHist(hmass, 2);
514   hmass->SetAxisRange(0.12, 0.16);
515
516   c->cd(ic++);
517   TH1 *hres = (TH1*)l->At(4);
518   u::DrawHist(hres, 2);
519   hres->SetAxisRange(0.05, 0.120);
520
521   if(ic<nx*ny) {
522     c->cd(ic++);
523     u::DrawHist((TH1*)l->At(5), 2);
524
525     c->cd(ic++);
526     u::DrawHist((TH1*)l->At(6), 2);
527   }
528   c->Update();
529 }
530
531 //_____________________________________________________________
532 TList* AliEMCALFolder::BookHists()
533 {
534   // Oct 15, 2007
535   gROOT->cd();
536   TH1::AddDirectory(1);  
537
538   new TH1F("00_HStat", "hist of common EMCAL statistics", 100, 0.5, 100.5);
539   new TH1F("01_EffMassAll", "effective mass of #gamma,#gamma(m_{#pi^{0}}=134.9766 MeV) - whole EMCAL", 250,0.0,0.5);
540
541   TList *l = AliEMCALHistoUtilities::MoveHistsToList("HistsOfEmcal", kFALSE);
542
543   TH1::AddDirectory(0);
544   return l;
545 }
546
547 //_____________________________________________________________
548 void AliEMCALFolder::CreateCellNtuple()
549 {
550   // Jun 28, 2007
551   if(fCellNtuple) { // Already exist
552     fCellNtuple->Print();
553     return;
554   }
555   // Create ntuple
556   Int_t bsize = int(1.e+5);
557   fCellNtuple = new TNtuple("cells","Cells Ntuple for quick analysis",
558                             "fAbsId:fSupMod:fModule:fPhi:fEta:fPhiCell:fEtaCell:fCcIn:fCcOut", bsize);
559   AliEMCALCell *cell=0;
560   // Fill ntuple
561   AliEMCALSuperModule* sm = GetSuperModule(0);
562   if(sm) printf(" TNtuple was created ! sm0 %s \n", sm->GetName());
563   for(int eta=0; eta<48; eta++) { // eta row
564     TFolder *setEta = dynamic_cast<TFolder*>(sm->FindObject(Form("ETA%2.2i",eta)));
565     if(setEta) {
566       printf(" ***** eta row %s ******\n", setEta->GetName());
567       TList* l = (TList*)setEta->GetListOfFolders();
568       for(int phi=0; phi<l->GetSize(); phi++) { // cycle on cells (phi directions)
569         cell = (AliEMCALCell*)l->At(phi);
570         if(cell) {
571           cell->FillCellNtuple(fCellNtuple);
572           //printf(" fill cell %s : %s \n", cell->GetName(), cell->GetTitle());
573         }
574       }
575     }
576   }
577   fCellNtuple->Print();
578   fLobj->Add(fCellNtuple); 
579 }
580
581 //_____________________________________________________________
582 void AliEMCALFolder::CreateAndFillAdditionalHists()
583 {
584   // Oct 15, 2007
585   CreateCellNtuple();
586   TH1::AddDirectory(0);  
587   fLhists->Add(new TH1F("02_CCoutOnEdge", "cc out on edge of calorimeter (in MeV)", 70, 12., 19.));
588   fLhists->Add(new TH1F("03_CCoutInside", "cc out inside  of calorimeter (in MeV)", 70, 12., 19.));
589   fLhists->Add(new TH1F("04_CCoutOnEdge2", "cc out on edge of calorimeter(2) (in MeV)", 70, 12., 19.));
590   // Fill
591   Float_t* args;
592   for(Int_t i=0; i<(Int_t)fCellNtuple->GetEntries(); i++){
593     fCellNtuple->GetEvent(i);
594     args = fCellNtuple->GetArgs();
595     Int_t phi = (Int_t)args[5];
596     Int_t eta = (Int_t)args[6];
597     Double_t cc = (Double_t)args[8]*1000.;
598     if     ((phi==0||phi==23) || (eta==0||eta==47)) u::FillH1(fLhists, 2, cc);
599     else if((phi==1||phi==22) || (eta==1||eta==46)) u::FillH1(fLhists, 4, cc); // next to edge
600     else                                            u::FillH1(fLhists, 3, cc);
601   }
602   // Drawing
603   Int_t wh=530, ww=750;
604   TCanvas *c = new TCanvas("c_edge","CEDGE", 10, 10, ww, wh);
605
606   gStyle->SetOptStat(1100);
607   gStyle->SetOptFit(111);
608   TH1 *h1 = (TH1*)fLhists->At(3);
609   TF1 *g = u::Gausi("ccInside", 14.7, 16.4, h1);
610   g->SetLineColor(kRed);
611   h1->Fit(g,"Q+","", 14.7, 16.4);
612   u::DrawHist(h1,2);
613   h1->SetTitle("CC distribution after #pi^{0} calibration");
614   h1->SetXTitle("  MeV  ");
615   h1->SetYTitle("  N  ");
616   //  TLatex *lat1 = u::Lat(Form("rel.width = %4.2f%%", 
617   //100.*h1->GetRMS()/ h1->GetMean()), 16.5, 100., 12, 0.045);
618   //TLatex *lat2 = u::Lat(Form("rel.width = %4.2f%% (from fit)", 
619   //                 100.*g->GetParameter(2)/ g->GetParameter(1)), 16.5, 70., 12, 0.045);
620
621   if(0) {
622     TH1 *h2 = (TH1*)fLhists->At(2);
623     u::DrawHist(h2,2,1,"same",2);
624   }
625
626   TH1F *hccFirst = AliEMCALCalibCoefs::GetHistOfCalibTableFromDb("ccTmp");
627   u::DrawHist(hccFirst,2,1,"same",3);
628
629   
630   // Ideal calibration - Jul 18, 2007
631   Double_t adcCHANNELEC = 0.0153, ccIdeal =  adcCHANNELEC*1.e+3;
632   Double_t ym = h1->GetMaximum();
633   TLine *l = new TLine(ccIdeal,-ym*0.05, ccIdeal,ym*1.05);
634   l->SetLineColor(kBlue);
635   l->Draw(); 
636
637   TLegend *leg = new TLegend(0.1,0.6, 0.45,0.85);
638   leg->AddEntry(hccFirst, "Initial cc ", "L");
639   leg->AddEntry(h1, "Final cc", "L");
640   TLegendEntry *le=0;
641   if(l) {
642     le  = leg->AddEntry(l, "Ideal calibration", "L");
643     le->SetTextColor(l->GetLineColor());
644   }
645
646   TH1 *hCcEdge  = (TH1*)fLhists->At(2);
647   TH1 *hCcEdge2 = (TH1*)fLhists->At(4);
648   if(1) {
649     u::DrawHist(hCcEdge,2,kGreen,"same",1);
650     le = leg->AddEntry(hCcEdge , "Edge cell", "L");
651     le->SetTextColor(hCcEdge->GetLineColor());
652
653     u::DrawHist(hCcEdge2,2, 28,"same",1); // 28 - like brown
654     le = leg->AddEntry(hCcEdge2 , "Edge cell (2)", "L");
655     le->SetTextColor(hCcEdge2->GetLineColor());
656     u::DrawHist(h1,2,1,"same");
657   }
658
659   leg->Draw();
660
661   c->Update();
662 }
663
664 //_____________________________________________________________
665 void AliEMCALFolder::TestSMStruct()
666 {
667   // testing May 22, 2007
668   for(int m=0; m<12; m++) {
669     AliEMCALSuperModule *sm = new AliEMCALSuperModule(m);
670     Add(sm);
671     sm->SetParent(this);
672   }
673 }
674