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