]> git.uio.no Git - u/mrichter/AliRoot.git/blob - OCDB/EMCAL/Calib/AliEMCALFolder.cxx
Extacting the OCDB in a separate module. The detectors have write permission in the...
[u/mrichter/AliRoot.git] / OCDB / EMCAL / Calib / 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: AliEMCALFolder.cxx 24500 2008-03-13 23:39:38Z jklay $ */
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);//For what is this?, commented due to compilation warnings
442 //
443 //}
444
445 //_____________________________________________________________
446 AliEMCALFolder* AliEMCALFolder::ReadFolder(const char *fn, const char *opt)
447
448   //
449   // Jun 27, 2007
450   // Jul 16 - added fgkDirOfRootFiles
451   //
452   printf("<I> AliEMCALFolder::ReadFolder(%s,%s)\n",fn,opt); 
453   AliEMCALFolder* emcal = 0;
454   TH1::AddDirectory(0); // this is obligatory
455
456   TString sfn = fgkDirOfRootFiles;
457   sfn += fn;
458   if(sfn.Contains(".root")==0) sfn += ".root";
459
460   TFile f(sfn.Data(),opt);
461   if(f.IsOpen()) {
462     TList *l = f.GetListOfKeys();
463     printf("<I> The total number of the objects: %d \n File %s\n", l->GetSize(), sfn.Data());
464
465     TKey *key = (TKey*)l->At(0);
466     emcal = (AliEMCALFolder*)key->ReadObj();
467     f.Close();
468     if(emcal) emcal->InitAfterRead();
469   }
470   return emcal;
471 }
472
473 //_____________________________________________________________
474 void  AliEMCALFolder::InitAfterRead()
475
476   // Oct 15, 2007
477   fLobj    = (TList*)FindObject("Objects");
478   if(fLobj) {
479     fLhists = (TList*)fLobj->FindObject("HistsOfEmcal");
480   }
481 }
482
483 //_____________________________________________________________
484 void AliEMCALFolder::DrawQA(const int nsm)
485
486   //
487   // Jun 25, 2007
488   //
489
490   AliEMCALSuperModule* sm = GetSuperModule(nsm);
491   if(sm==0) return;
492   TList *l = sm-> GetHists();
493   Int_t nx=2, ny=2, wh=530, ww=750;
494
495   TCanvas *c = new TCanvas(Form("QA_%i",GetIterationNumber()), Form("QA_%i",GetIterationNumber()),
496                            10, 10, ww, wh);
497   c->Divide(nx,ny);
498
499   int ic=1;
500   c->cd(ic++);
501   TH1 *h1 = (TH1*)l->At(0);
502   sm->FitEffMassHist(); 
503   u::DrawHist(h1,2);
504   h1->SetAxisRange(0.03, 0.28);
505
506   c->cd(ic++);
507   sm->DrawCC(0);  
508   TH1 *hccin = (TH1*)l->At(1);
509   hccin->SetAxisRange(14., 20.);
510
511   gStyle->SetOptStat(1111);
512   c->cd(ic++);
513   TH1 *hmass = (TH1*)l->At(3);
514   u::DrawHist(hmass, 2);
515   hmass->SetAxisRange(0.12, 0.16);
516
517   c->cd(ic++);
518   TH1 *hres = (TH1*)l->At(4);
519   u::DrawHist(hres, 2);
520   hres->SetAxisRange(0.05, 0.120);
521
522   if(ic<nx*ny) {
523     c->cd(ic++);
524     u::DrawHist((TH1*)l->At(5), 2);
525
526     c->cd(ic++);
527     u::DrawHist((TH1*)l->At(6), 2);
528   }
529   c->Update();
530 }
531
532 //_____________________________________________________________
533 TList* AliEMCALFolder::BookHists()
534 {
535   // Oct 15, 2007
536   gROOT->cd();
537   TH1::AddDirectory(1);  
538
539   new TH1F("00_HStat", "hist of common EMCAL statistics", 100, 0.5, 100.5);
540   new TH1F("01_EffMassAll", "effective mass of #gamma,#gamma(m_{#pi^{0}}=134.9766 MeV) - whole EMCAL", 250,0.0,0.5);
541
542   TList *l = AliEMCALHistoUtilities::MoveHistsToList("HistsOfEmcal", kFALSE);
543
544   TH1::AddDirectory(0);
545   return l;
546 }
547
548 //_____________________________________________________________
549 void AliEMCALFolder::CreateCellNtuple()
550 {
551   // Jun 28, 2007
552   if(fCellNtuple) { // Already exist
553     fCellNtuple->Print();
554     return;
555   }
556   // Create ntuple
557   Int_t bsize = int(1.e+5);
558   fCellNtuple = new TNtuple("cells","Cells Ntuple for quick analysis",
559                             "fAbsId:fSupMod:fModule:fPhi:fEta:fPhiCell:fEtaCell:fCcIn:fCcOut", bsize);
560   AliEMCALCell *cell=0;
561   // Fill ntuple
562   AliEMCALSuperModule* sm = GetSuperModule(0);
563   if(sm) printf(" TNtuple was created ! sm0 %s \n", sm->GetName());
564   for(int eta=0; eta<48; eta++) { // eta row
565     TFolder *setEta = dynamic_cast<TFolder*>(sm->FindObject(Form("ETA%2.2i",eta)));
566     if(setEta) {
567       printf(" ***** eta row %s ******\n", setEta->GetName());
568       TList* l = (TList*)setEta->GetListOfFolders();
569       for(int phi=0; phi<l->GetSize(); phi++) { // cycle on cells (phi directions)
570         cell = (AliEMCALCell*)l->At(phi);
571         if(cell) {
572           cell->FillCellNtuple(fCellNtuple);
573           //printf(" fill cell %s : %s \n", cell->GetName(), cell->GetTitle());
574         }
575       }
576     }
577   }
578   fCellNtuple->Print();
579   fLobj->Add(fCellNtuple); 
580 }
581
582 //_____________________________________________________________
583 void AliEMCALFolder::CreateAndFillAdditionalHists()
584 {
585   // Oct 15, 2007
586   CreateCellNtuple();
587   TH1::AddDirectory(0);  
588   fLhists->Add(new TH1F("02_CCoutOnEdge", "cc out on edge of calorimeter (in MeV)", 70, 12., 19.));
589   fLhists->Add(new TH1F("03_CCoutInside", "cc out inside  of calorimeter (in MeV)", 70, 12., 19.));
590   fLhists->Add(new TH1F("04_CCoutOnEdge2", "cc out on edge of calorimeter(2) (in MeV)", 70, 12., 19.));
591   // Fill
592   Float_t* args;
593   for(Int_t i=0; i<(Int_t)fCellNtuple->GetEntries(); i++){
594     fCellNtuple->GetEvent(i);
595     args = fCellNtuple->GetArgs();
596     Int_t phi = (Int_t)args[5];
597     Int_t eta = (Int_t)args[6];
598     Double_t cc = (Double_t)args[8]*1000.;
599     if     ((phi==0||phi==23) || (eta==0||eta==47)) u::FillH1(fLhists, 2, cc);
600     else if((phi==1||phi==22) || (eta==1||eta==46)) u::FillH1(fLhists, 4, cc); // next to edge
601     else                                            u::FillH1(fLhists, 3, cc);
602   }
603   // Drawing
604   Int_t wh=530, ww=750;
605   TCanvas *c = new TCanvas("c_edge","CEDGE", 10, 10, ww, wh);
606
607   gStyle->SetOptStat(1100);
608   gStyle->SetOptFit(111);
609   TH1 *h1 = (TH1*)fLhists->At(3);
610   TF1 *g = u::Gausi("ccInside", 14.7, 16.4, h1);
611   g->SetLineColor(kRed);
612   h1->Fit(g,"Q+","", 14.7, 16.4);
613   u::DrawHist(h1,2);
614   h1->SetTitle("CC distribution after #pi^{0} calibration");
615   h1->SetXTitle("  MeV  ");
616   h1->SetYTitle("  N  ");
617   //  TLatex *lat1 = u::Lat(Form("rel.width = %4.2f%%", 
618   //100.*h1->GetRMS()/ h1->GetMean()), 16.5, 100., 12, 0.045);
619   //TLatex *lat2 = u::Lat(Form("rel.width = %4.2f%% (from fit)", 
620   //                 100.*g->GetParameter(2)/ g->GetParameter(1)), 16.5, 70., 12, 0.045);
621
622   if(0) {
623     TH1 *h2 = (TH1*)fLhists->At(2);
624     u::DrawHist(h2,2,1,"same",2);
625   }
626
627   TH1F *hccFirst = AliEMCALCalibCoefs::GetHistOfCalibTableFromDb("ccTmp");
628   u::DrawHist(hccFirst,2,1,"same",3);
629
630   
631   // Ideal calibration - Jul 18, 2007
632   Double_t adcCHANNELEC = 0.0153, ccIdeal =  adcCHANNELEC*1.e+3;
633   Double_t ym = h1->GetMaximum();
634   TLine *l = new TLine(ccIdeal,-ym*0.05, ccIdeal,ym*1.05);
635   l->SetLineColor(kBlue);
636   l->Draw(); 
637
638   TLegend *leg = new TLegend(0.1,0.6, 0.45,0.85);
639   leg->AddEntry(hccFirst, "Initial cc ", "L");
640   leg->AddEntry(h1, "Final cc", "L");
641   TLegendEntry *le=0;
642   if(l) {
643     le  = leg->AddEntry(l, "Ideal calibration", "L");
644     le->SetTextColor(l->GetLineColor());
645   }
646
647   TH1 *hCcEdge  = (TH1*)fLhists->At(2);
648   TH1 *hCcEdge2 = (TH1*)fLhists->At(4);
649   if(1) {
650     u::DrawHist(hCcEdge,2,kGreen,"same",1);
651     le = leg->AddEntry(hCcEdge , "Edge cell", "L");
652     le->SetTextColor(hCcEdge->GetLineColor());
653
654     u::DrawHist(hCcEdge2,2, 28,"same",1); // 28 - like brown
655     le = leg->AddEntry(hCcEdge2 , "Edge cell (2)", "L");
656     le->SetTextColor(hCcEdge2->GetLineColor());
657     u::DrawHist(h1,2,1,"same");
658   }
659
660   leg->Draw();
661
662   c->Update();
663 }
664
665 //_____________________________________________________________
666 void AliEMCALFolder::TestSMStruct()
667 {
668   // testing May 22, 2007
669   for(int m=0; m<12; m++) {
670     AliEMCALSuperModule *sm = new AliEMCALSuperModule(m);
671     Add(sm);
672     sm->SetParent(this);
673   }
674 }
675