1 /**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //_________________________________________________________________________
19 // Top EMCAL folder which will keep all information about EMCAL itself,
20 // super Modules (SM), modules, towers, set of hists and so on.
22 //*-- Author: Aleksei Pavlinov (WSU, Detroit, USA)
24 #include "AliEMCALFolder.h"
25 #include "AliEMCALHistoUtilities.h"
26 #include "AliEMCALGeometry.h"
27 #include "AliEMCALSuperModule.h"
28 #include "AliEMCALCell.h"
29 #include "AliESDCaloCluster.h"
33 #include "AliEMCALCalibData.h"
34 #include "AliCDBMetaData.h"
36 #include "AliCDBEntry.h"
37 #include "AliCDBManager.h"
38 #include "AliCDBStorage.h"
40 #include "AliEMCALCalibCoefs.h"
41 #include "AliEMCALDigit.h"
42 #include "AliEMCALRecPoint.h"
44 #include "AliEMCALPi0SelectionParam.h"
54 #include <TFileIter.h>
56 #include <TClonesArray.h>
62 const TString AliEMCALFolder::fgkBaseFolderName("EMCAL");
63 const TString AliEMCALFolder::fgkCCFirstName("CCFIRST");
64 const TString AliEMCALFolder::fgkCCinName("CCIN");
65 const TString AliEMCALFolder::fgkCCoutName("CCOUT");
67 typedef AliEMCALHistoUtilities u;
69 ClassImp(AliEMCALFolder)
71 //AliEMCALGeometry* AliEMCALFolder::fGeometry = 0;
75 AliEMCALFolder::AliEMCALFolder() :
77 fCounter(0), fGeometry(0), fNumOfCell(0), fLhists(0), fLofCells(0),fPi0SelPar(0),fCalibData(0),
82 AliEMCALFolder::AliEMCALFolder(const char* name, const char* title, Bool_t putToBrowser) :
84 fCounter(-1), fGeometry(0), fNumOfCell(0), fLhists(0), fLofCells(0),fPi0SelPar(0),fCalibData(0),
91 AliEMCALFolder::AliEMCALFolder(const Int_t it, const char* title, Bool_t putToBrowser) :
92 TObjectSet(Form("%s_%2.2i", AliEMCALFolder::fgkBaseFolderName.Data(),it)),
93 fCounter(it), fGeometry(0), fNumOfCell(0), fLhists(0), fLofCells(0),fPi0SelPar(0),fCalibData(0),
100 AliEMCALFolder::~AliEMCALFolder()
105 void AliEMCALFolder::Init(Bool_t putToBrowser)
108 lObj->SetName("Objects"); // name is good ?
109 this->AddObject((TObject*)lObj, kTRUE);
110 // Get default geometry - "SHISH_77_TRD1_2X2_FINAL_110DEG"; May 29, 2007
111 fGeometry = AliEMCALGeometry::GetInstance(); // should be define before
112 lObj->Add(fGeometry);
114 // Initial cc with decalibration
115 char* dbString = "local:///data/r22b/ALICE/PROD/CALIBRATION_May_2007/PI0/PDSF/10GEV/DECALIB/DeCalibDB"; // hard coded now
116 fCalibData = (AliEMCALCalibData*)
117 (AliCDBManager::Instance()->GetStorage(dbString)
118 ->Get("EMCAL/Calib/Data",gAlice->GetRunNumber())->GetObject());
119 lObj->Add(fCalibData);
121 Add(AliEMCALCalibCoefs::GetCalibTableFromDb(fgkCCFirstName.Data()));
122 if(GetIterationNumber()==1) {
123 Add(AliEMCALCalibCoefs::GetCalibTableFromDb()); // first iteration only
125 // Selection Parameter
126 fPi0SelPar = AliEMCALPi0SelectionParam::Set1();
127 this->Add(fPi0SelPar);
129 fLhists = BookHists();
132 // dimension should be get from geometry - 4*12*24*11);
133 fNumOfCell = fGeometry->GetNCells();
134 fLofCells = new AliEMCALCell*[fNumOfCell];
135 for(int i=0; i<fNumOfCell; i++) fLofCells[i] = 0;
137 printf("<I> Create AliEMCALFolder : it %i : name %s\n ", fCounter, GetName());
139 if(putToBrowser) gROOT->GetListOfBrowsables()->Add(this); // for testing purpuse
142 AliEMCALSuperModule* AliEMCALFolder::GetSuperModule(const Int_t nm)
145 AliEMCALSuperModule *sm = 0;
147 set = FindByName(Form("SM%2.2i",nm));
148 if(set) sm = (AliEMCALSuperModule*)set;
154 AliEMCALCell* AliEMCALFolder::GetCell(const Int_t absId)
156 if(absId<0 || absId >= fNumOfCell) return 0;
157 else return fLofCells[absId];
160 void AliEMCALFolder::SetCell(AliEMCALCell *cell, const Int_t absId)
162 if(absId>=0 && absId < fNumOfCell) {
163 fLofCells[absId] = cell;
167 pi0SelectionParam* AliEMCALFolder::GetPi0SelectionParRow(Int_t nrow)
169 pi0SelectionParam* r=0;
171 r = fPi0SelPar->GetTable(nrow);
176 void AliEMCALFolder::FillPi0Candidate(const Double_t mgg, AliESDCaloCluster* cl1, AliESDCaloCluster* cl2)
178 static Int_t absIdMax, nm1, nm2;
180 u::FillH1(fLhists, 0, 1.); // number entries
181 u::FillH1(fLhists, 1, mgg);
183 nm1 = GetSMNumber(cl1);
184 nm2 = GetSMNumber(cl2);
186 if(nm1==-1 || nm2==-1) assert(0);
188 if(nm1 != nm2) return; // Both cluster should be in the same SM
190 AliESDCaloCluster* cl = cl1;
191 if(cl1->E() < cl2->E()) cl = cl2; // Get cluster with highest energy
193 const Int_t nDigits = cl->GetNumberOfDigits();
194 // const UShort_t* adc = cl->GetDigitAmplitude(); // for future
195 const Short_t* absId = cl->GetDigitIndex()->GetArray();
198 double emax = cl->GetDigitAmplitude()->At(0);
200 for(int i=1; i<nDigits; i++) {
201 if(emax < cl->GetDigitAmplitude()->At(i)) {
203 emax = cl->GetDigitAmplitude()->At(i);
207 if(emax/cl->E() > 0.5) { // more than 50% of cluster energy
208 u::FillH1(fLhists, 0, 2.); // number "good" entries
209 absIdMax = Int_t(absId[indMax]);
210 FillPi0Candidate(mgg, absIdMax, nm1);
214 void AliEMCALFolder::FillPi0Candidate(const Double_t mgg, Int_t absIdMax, Int_t nm)
219 static Int_t nSupModMax, nModuleMax, nIphiMax, nIetaMax, iphiCellMax, ietaCellMax;
220 static AliEMCALCell* cell;
221 static TDataSet *set;
222 static AliEMCALSuperModule *sm;
224 fGeometry->GetCellIndex(absIdMax, nSupModMax, nModuleMax, nIphiMax, nIetaMax);
225 if(nm != nSupModMax) assert(0);
227 fGeometry->GetCellPhiEtaIndexInSModule(nSupModMax, nModuleMax, nIphiMax, nIetaMax, iphiCellMax, ietaCellMax);
232 if(GetCell(absIdMax)==0) {
233 cell = new AliEMCALCell(absIdMax, Form("sm%2.2i:phi%2.2i:eta%2.2i(%4.4i)",nSupModMax,iphiCellMax,ietaCellMax,absIdMax));
234 SetCell(cell, absIdMax);
236 set = FindByName(Form("SM%2.2i",nSupModMax));
238 sm = new AliEMCALSuperModule(nSupModMax);
242 sm = (AliEMCALSuperModule*)set;
244 sm->AddCellToEtaRow(cell, ietaCellMax);
246 cell->SetCCfromCCTable(GetCCIn());
248 cell = GetCell(absIdMax);
249 set = FindByName(Form("SM%2.2i",nm));
250 if(set) sm = (AliEMCALSuperModule*)set;
252 if(sm == 0) assert(0);
253 if(nm != sm->GetSMNumber()) assert(0);
255 u::FillH1(sm->GetHists(), 0, mgg);
256 cell->FillEffMass(mgg);
259 void AliEMCALFolder::FitAllSMs()
261 // Only first SM now - should be changed in the future
262 AliEMCALSuperModule *sm0 = GetSuperModule(0);
263 sm0->FitForAllCells();
264 // Get input calibration table
265 AliEMCALCalibCoefs *ccIn = GetCCIn();
267 printf("<E> no input cc \n");
270 // New calibration table
271 AliEMCALCalibCoefs *ccOut = new AliEMCALCalibCoefs(fgkCCoutName.Data(), ccIn->GetNRows());
272 calibCoef *rIn=0, rOut;
273 for(Int_t i=0; i<ccIn->GetNRows(); i++){
274 rIn = ccIn->GetTable(i);
276 AliEMCALCell* cell = GetCell(rIn->absId);
277 if(cell && cell->GetSupMod() == 0) { // only first module now
278 rOut.cc = cell->GetCcOut();
286 AliEMCALCalibCoefs* AliEMCALFolder::GetCCTable(const char* name)
288 TDataSet *ds = FindByName(name);
289 if(ds) return (AliEMCALCalibCoefs*)ds;
293 Int_t AliEMCALFolder::GetSMNumber(AliESDCaloCluster* cl)
295 static Int_t absId, nSupMod, nModule, nIphi, nIeta;
296 nSupMod = -1; // if negative something wrong
298 absId = Int_t(cl->GetDigitIndex()->At(0));
299 fGeometry->GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
304 // Recalibration staf - Jun 18,2007
305 AliEMCALRecPoint* AliEMCALFolder::GetRecPoint(AliESDCaloCluster *cl, AliEMCALCalibCoefs *tOld,AliEMCALCalibCoefs *tNew,
310 // Get recalibrated rec.point from ESD cluster
312 // printf(" AliEMCALFolder::GetRecPoint() : RECALIBRATION \n");
313 static Double_t ADCCHANNELEC = 0.0153; // Update 24 Apr 2007: 250./16/1024 - width of one ADC channel in GeV
314 static Float_t ECAW0 = 4.5; // hard coded now - see AliEMCALClusterizerv1::InitParameters()
316 Double_t eDigiNew=0.0;
318 AliEMCALRecPoint *rp=0;
319 calibCoef *rOld=0, *rNew=0;
320 if(cl && tOld && tNew){
321 // cl->PrintClusterInfo(1);
322 const Int_t ndg = cl->GetNumberOfDigits();
323 //const Int_t nprim = cl->GetNumberOfPrimaries();
325 const Short_t* prim = cl->GetLabels()->GetArray();
326 const Short_t* dgAbsId = cl->GetDigitIndex()->GetArray();
327 // const UShort_t* dgAmp = cl->GetDigitAmplitude()(); // This is energy - bad definition
329 rp = new AliEMCALRecPoint(""); // opt=""
330 rp->SetClusterType(AliESDCaloCluster::kClusterv1);
332 TClonesArray digits("AliEMCALDigit", ndg);
334 for(Int_t i=0; i<ndg; i++){
335 // Save just abs id and amplitude of digits which will be used for recalculation of
336 // cluster energy and position
337 absId = Int_t(dgAbsId[i]);
338 rOld = tOld->GetTable(absId);
339 rNew = tNew->GetTable(absId);
340 ampDigi = Int_t(cl->GetDigitAmplitude()->At(i) / rOld->cc);
342 new(digits[i]) AliEMCALDigit(Int_t(prim[i]),0,absId, ampDigi, 0.0, i, 0.0);
343 dg = (AliEMCALDigit*)digits[i];
344 eDigiNew = ampDigi * rNew->cc;
345 //eDigiNew = ampDigi * ADCCHANNELEC;
346 //eDigiNew = Double_t(cl->GetDigitAmplitude()->At(i)); // Copy from ESD for checking
347 rp->AddDigit(*dg, Float_t(eDigiNew));
348 u::FillH1(l, 14, eDigiNew);
349 u::FillH1(l, 15, Double_t(absId));
350 //printf("<I> digit %i amp %i rOld->cc %6.5f GeV rNew->cc %6.5f GeV\n", i, ampDigi, rOld->cc, rNew->cc);
352 //printf("<I> recalibration of digits was done ! \n");
353 // rp->EvalAll(ECAW0, &digits);
354 rp->EvalLocalPosition(ECAW0, &digits); // I need just position
357 //rp->Print("print");
361 void AliEMCALFolder::Save(const char *fn, const char *opt)
364 // Jun 5, 2007; See TFileIter and StFMC.cxx
367 if(FN.Contains(".root")==0) FN += ".root";
368 TFileIter f(FN.Data(),opt,"EMCAL object");
369 UInt_t eventNum = 0; // just one object
370 UInt_t runNumber = 0; // 0 now, - may statistics on selectorr
371 f.NextEventPut(this, eventNum, runNumber);
372 printf(" Save %s to file %s\n", GetName(), FN.Data());
375 AliEMCALFolder* AliEMCALFolder::Read(const char *fn, const char *opt)
380 AliEMCALFolder* EMCAL = 0;
381 TH1::AddDirectory(0); // this is obligatory
384 TList *l = f.GetListOfKeys();
385 printf(" The total number of the objects: %d in file %s\n", l->GetSize(), fn);
387 TKey *key = (TKey*)l->At(0);
388 EMCAL = (AliEMCALFolder*)key->ReadObj();
390 if(EMCAL) EMCAL->InitAfterRead();
396 void AliEMCALFolder::InitAfterRead()
399 fLhists = (TList*)lObj->FindObject("HistsOfEmcal");
402 void AliEMCALFolder::DrawQA(const int nsm)
408 AliEMCALSuperModule* sm = GetSuperModule(nsm);
410 TList *l = sm-> GetHists();
411 Int_t nx=2, ny=2, wh=530, ww=750;
413 TCanvas *c = new TCanvas(Form("QA_%i",GetIterationNumber()), Form("QA_%i",GetIterationNumber()),
419 TH1 *h1 = (TH1*)l->At(0);
420 sm->FitEffMassHist();
422 h1->SetAxisRange(0.03, 0.28);
426 TH1 *hccin = (TH1*)l->At(1);
427 hccin->SetAxisRange(14., 20.);
429 gStyle->SetOptStat(1111);
431 TH1 *hmass = (TH1*)l->At(3);
432 u::DrawHist(hmass, 2);
433 hmass->SetAxisRange(0.12, 0.16);
436 TH1 *hres = (TH1*)l->At(4);
437 u::DrawHist(hres, 2);
438 hres->SetAxisRange(0.05, 0.120);
442 u::DrawHist((TH1*)l->At(5), 2);
445 u::DrawHist((TH1*)l->At(6), 2);
450 TList* AliEMCALFolder::BookHists()
453 TH1::AddDirectory(1);
455 new TH1F("00_HStat", "hist of common EMCAL statistics", 100, 0.5, 100.5);
456 new TH1F("01_EffMassAll", "effective mass of #gamma,#gamma(m_{#pi^{0}}=134.9766 MeV) - whole EMCAL", 250,0.0,0.5);
458 TList *l = AliEMCALHistoUtilities::MoveHistsToList("HistsOfEmcal", kFALSE);
460 TH1::AddDirectory(0);
464 void AliEMCALFolder::CreateCellNtuple()
467 if(fCellNtuple) { // Already exist
468 fCellNtuple->Print();
472 Int_t bsize = int(1.e+5);
473 fCellNtuple = new TNtuple("cells","Cells Ntuple for quick analysis",
474 "fAbsId:fSupMod:fModule:fPhi:fEta:fPhiCell:fEtaCell:fCcIn:fCcOut", bsize);
475 AliEMCALCell *cell=0;
477 AliEMCALSuperModule* sm = GetSuperModule(0);
478 if(sm) printf(" TNtuple was created ! sm0 %s \n", sm->GetName());
479 for(int eta=0; eta<48; eta++) { // eta row
480 TDataSet *setEta = sm->FindByName(Form("ETA%2.2i",eta));
482 printf(" ***** eta row %s ******\n", setEta->GetName());
483 for(int phi=0; phi<setEta->GetListSize(); phi++) { // cycle on cells (phi directions)
484 cell = (AliEMCALCell*)setEta->At(phi);
486 cell->FillCellNtuple(fCellNtuple);
487 //printf(" fill cell %s : %s \n", cell->GetName(), cell->GetTitle());
492 fCellNtuple->Print();
493 lObj->Add(fCellNtuple);
495 CreateAndFillAdditionalHists();
498 void AliEMCALFolder::CreateAndFillAdditionalHists()
500 TH1::AddDirectory(0);
501 fLhists->Add(new TH1F("02_CCoutOnEdge", "cc out on edge of calorimeter (in MeV)", 70, 12., 19.));
502 fLhists->Add(new TH1F("03_CCoutInside", "cc out inside of calorimeter (in MeV)", 70, 12., 19.));
505 for(Int_t i=0; i<(Int_t)fCellNtuple->GetEntries(); i++){
506 fCellNtuple->GetEvent(i);
507 args = fCellNtuple->GetArgs();
508 Int_t phi = (Int_t)args[5];
509 Int_t eta = (Int_t)args[6];
510 Double_t cc = (Double_t)args[8]*1000.;
511 if((phi==0||phi==23) || (eta==0||eta==47)) u::FillH1(fLhists, 2, cc);
512 else u::FillH1(fLhists, 3, cc);
515 Int_t wh=530, ww=750;
516 TCanvas *c = new TCanvas("c_edge","CEDGE", 10, 10, ww, wh);
518 gStyle->SetOptStat(1100);
519 gStyle->SetOptFit(111);
520 TH1 *h1 = (TH1*)fLhists->At(3);
521 TF1 *g = u::Gausi("ccInside", 14.7, 16.4, h1);
522 g->SetLineColor(kRed);
523 h1->Fit(g,"Q+","", 14.7, 16.4);
525 h1->SetTitle("CC distribution after #pi^{0} calibration");
526 h1->SetXTitle(" MeV ");
527 h1->SetYTitle(" N ");
528 TLatex *lat1 = u::lat(Form("rel.width = %4.2f%%",
529 100.*h1->GetRMS()/ h1->GetMean()), 16.5, 100., 12, 0.045);
530 TLatex *lat2 = u::lat(Form("rel.width = %4.2f%% (from fit)",
531 100.*g->GetParameter(2)/ g->GetParameter(1)), 16.5, 70., 12, 0.045);
534 TH1 *h2 = (TH1*)fLhists->At(2);
535 u::DrawHist(h2,2,1,"same",2);
538 TH1F *hccFirst = AliEMCALCalibCoefs::GetHistOfCalibTableFromDb("ccTmp");
539 u::DrawHist(hccFirst,2,1,"same",3);
542 TLegend *leg = new TLegend(0.1,0.6, 0.45,0.85);
543 leg->AddEntry(hccFirst, "Initial cc ", "L");
544 leg->AddEntry(h1, "Final cc", "L");
550 void AliEMCALFolder::TestSMStruct()
552 // testing May 22, 2007
553 for(int m=0; m<12; m++) {
554 AliEMCALSuperModule *sm = new AliEMCALSuperModule(m);