]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALRecPointsQaESDSelector.cxx
moved component registration to agent; added component configuration/initialization...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALRecPointsQaESDSelector.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 /* History of cvs commits:
16  *
17 * $Log$
18 * Revision 1.6  2007/10/16 14:36:39  pavlinov
19 * fixed code violation (almost)
20 *
21 * Revision 1.5  2007/10/15 18:04:07  pavlinov
22 * quick fix
23 *
24 * Revision 1.4  2007/10/15 15:50:58  pavlinov
25 * fixed code violation
26 *
27 * Revision 1.3  2007/10/09 08:46:10  hristov
28 * The data members fEMCALClusterCluster and fPHOSCluster are removed from AliESDCaloCluster, the fClusterType is used to select PHOS or EMCAL clusters. Changes, needed to use correctly the new AliESDCaloCluster. (Christian)
29 *
30 * Revision 1.2  2007/09/11 19:38:15  pavlinov
31 * added pi0 calibration, linearity, shower profile
32 * co: warning: ` $Log' is obsolescent; use ` * $Log'.
33 * Revision 1.1  2007/08/08 15:58:01  hristov
34 * New calibration classes. (Aleksei)
35  */
36
37 //_________________________________________________________________________
38 // This is selector for making a set of histogramms from ESD for rec.points
39 //--  Authors: Aleksei Pavlinov (WSU) 
40 //--  Feb 17, 2007 - Sep 11, 2007
41 //--  Pi0 calibration
42 //--  Recalibration, linearity, shower profile 
43 //_________________________________________________________________________
44
45 #include "AliEMCALRecPointsQaESDSelector.h"
46 #include "AliEMCALFolder.h"
47 #include "AliEMCALSuperModule.h"
48 #include "AliEMCALCell.h"
49 #include "AliEMCALCellInfo.h"
50 #include "AliEMCALPi0SelectionParam.h"
51 #include "AliEMCALHistoUtilities.h"
52 #include "AliEMCALCalibCoefs.h"
53 #include "AliEMCALGeometry.h"
54 #include "AliLog.h"
55 #include "AliESD.h"
56 #include "AliEMCALRecPoint.h"
57 #include "AliRunLoader.h"
58 #include "AliStack.h"
59 #include "jetfinder/AliEMCALJetMicroDst.h" // Sgpdge
60 #include "AliEMCALDigit.h"
61
62 #include <iostream>
63 #include <iomanip>
64 #include <fstream>
65 #include <assert.h>
66 #include <map>
67 #include <string>
68
69 #include <TROOT.h>
70 #include <TStyle.h>
71 #include <TSystem.h>
72 #include <TCanvas.h>
73 #include <TVector3.h>
74 #include <TLorentzVector.h>
75 #include <TParticle.h>
76 #include <TChain.h>
77 #include <TFile.h>
78 #include <TH1F.h>
79 #include <TH1D.h>
80 #include <TH2F.h>
81 #include <TF1.h>
82 #include <TMath.h>
83 #include <TBrowser.h>
84 #include <TList.h>
85 #include <TCanvas.h>
86 #include <TLine.h>
87 #include <TObjString.h>
88 #include <TArrayI.h>
89 #include <TGraphErrors.h>
90 #include <TLegend.h>
91 #include <TLegendEntry.h>
92 #include <TNtuple.h>
93
94 using namespace std;
95
96 typedef  AliEMCALHistoUtilities u;
97
98 AliEMCALGeometry* AliEMCALRecPointsQaESDSelector::fgEmcalGeo=0;
99 Int_t             AliEMCALRecPointsQaESDSelector::fgNmaxCell = 4*12*24*11;
100
101 Double_t AliEMCALRecPointsQaESDSelector::fgDistEff = 3.;
102 Double_t AliEMCALRecPointsQaESDSelector::fgW0      = 4.5;
103 Double_t AliEMCALRecPointsQaESDSelector::fgSlopePhiShift = 0.01; // ?? just guess
104
105 AliEMCALFolder* AliEMCALRecPointsQaESDSelector::fgEMCAL = 0;
106 AliEMCALFolder* AliEMCALRecPointsQaESDSelector::fgEMCALOld = 0;
107
108 Char_t **AliEMCALRecPointsQaESDSelector::fgAnaOpt=0;
109 Int_t AliEMCALRecPointsQaESDSelector::fgNanaOpt = 0; 
110 enum keyOpt{
111   kCORR1,
112   kRECALIB,
113   kIDEAL,
114   kPI0,
115   kGAMMA,
116   kKINE,
117   kPROF,
118   kFIT,
119  //-- 
120   kEND
121 };
122
123 // Enumeration variables
124 // enum {kUndefined=-1, kLed=0, kBeam=1};
125 // enum {kPatchResponse=0, kClusterResponse=1};
126 // enum {kSkip=0,  kSaveToMemory=1};
127
128 ClassImp(AliEMCALRecPointsQaESDSelector)
129
130 AliEMCALRecPointsQaESDSelector::AliEMCALRecPointsQaESDSelector() :
131   AliSelector(),
132   fPmom(0),
133   fChain(0),
134   fLofHistsPC(0),
135   fLofHistsRP(0),
136   fLKineVsRP(0),
137   fLShowerProfile(0),
138   fCellsInfo(0),
139   fEmcalPool(0),
140   fRunOpts(0),
141   fArrOpts(0),
142   fKeyOpts(0)
143 {
144   //
145   // Constructor. Initialization of pointers
146   //
147   Char_t *anaOpt[]={
148   "CORR1",   // GetCorrectedEnergyForGamma1(Double_t eRec);
149   "RECALIB",
150   "IDEAL",
151   "PI0",
152   "GAMMA",
153   "KINE",   // reading kine file
154   "PROF",   // Shower profile: phi direction now
155   "FIT"     // define parameters : deff, w0 and phislope
156   };
157   
158   fgNanaOpt = sizeof(anaOpt) / sizeof(Char_t*); 
159   fgAnaOpt = new Char_t*[fgNanaOpt];
160   for(int i=0; i<fgNanaOpt; i++) fgAnaOpt[i] = anaOpt[i];
161 }
162
163 AliEMCALRecPointsQaESDSelector::~AliEMCALRecPointsQaESDSelector()
164 {
165   //
166   // Destructor
167   //
168
169   // histograms are in the output list and deleted when the output
170   // list is deleted by the TSelector dtor
171 }
172
173 void AliEMCALRecPointsQaESDSelector::Begin(TTree* tree)
174 {
175   // Begin function
176
177   AliSelector::Begin(tree);
178 }
179
180 void AliEMCALRecPointsQaESDSelector::SlaveBegin(TTree* tree)
181 {
182   // The SlaveBegin() function is called after the Begin() function.
183   // When running with PROOF SlaveBegin() is called on each slave server.
184   // The tree argument is deprecated (on PROOF 0 is passed).
185
186   printf("**** <I> Slave Begin \n **** ");
187
188   AliSelector::SlaveBegin(tree);
189 }
190
191 void AliEMCALRecPointsQaESDSelector::Init(TTree* tree)
192 {
193   // Init function
194
195   AliSelector::Init(tree);
196 }
197 Bool_t AliEMCALRecPointsQaESDSelector::Notify()
198 {
199   // The Notify() function is called when a new file is opened. This
200   // can be either for a new TTree in a TChain or when when a new TTree
201   // is started when using PROOF. Typically here the branch pointers
202   // will be retrieved. It is normaly not necessary to make changes
203   // to the generated code, but the routine can be extended by the
204   // user if needed.
205
206   return AliSelector::Notify();
207 }
208
209 void AliEMCALRecPointsQaESDSelector::InitStructure(Int_t it)
210 {
211   //
212   // Initialize the common structure of selector
213   //
214   fgEmcalGeo = AliEMCALGeometry::GetInstance("SHISH_TRD1_CURRENT_2X2"); // initialize geometry just once
215   fCellsInfo = AliEMCALCellInfo::GetTableForGeometry(fgEmcalGeo);
216
217   if(fRunOpts.Length()>0) CheckRunOpts();
218
219   Int_t key = 0;
220   if(GetKeyOptsValue(kGAMMA)) key = 1;
221   fLofHistsRP = DefineHistsOfRP("RP", fPmom, key);
222   fLofHistsPC = DefineHistsOfRP("PseudoCl", fPmom);
223
224   fEmcalPool = new TFolder("PoolOfEMCAL","");
225   if(it <= 1) {
226     fgEMCAL     = new AliEMCALFolder(it); // folder for first itteration   
227     fEmcalPool->Add(fgEMCAL);
228   }
229   //if(it<=0) SetName("GammaSel"); // For convinience
230   //else      SetName("Pi0Sel");
231   if(GetKeyOptsValue(kKINE)) fLKineVsRP = DefineHistsOfKineVsRP("KineVsRP",fPmom, key);
232   if(GetKeyOptsValue(kPROF)) fLShowerProfile = DefineHistsForShowerProfile("ProfY", fPmom);
233 }
234
235 void AliEMCALRecPointsQaESDSelector::CheckRunOpts()
236 {
237   // Check run options
238   fRunOpts.ToUpper();
239   int nopt = u::ParseString(fRunOpts, fArrOpts);
240   printf("<I> AliEMCALRecPointsQaESDSelector::CheckRunOpts() analyze %i(%i) options : fgNanaOpt %i\n", 
241          nopt, fArrOpts.GetEntries(), fgNanaOpt);  
242   if(nopt <=0) return;
243
244   fKeyOpts = new TArrayI(fgNanaOpt);
245   for(Int_t i=0; i<fgNanaOpt; i++) (*fKeyOpts)[i] = 0;
246
247   for(Int_t i=0; i<fArrOpts.GetEntries(); i++ ) {
248     TObjString *o = (TObjString*)fArrOpts.At(i); 
249
250     TString runOpt = o->String();
251     Int_t indj=-1;
252
253     for(Int_t j=0; j<fgNanaOpt; j++) {
254       TString opt = fgAnaOpt[j];
255       if(runOpt.Contains(opt,TString::kIgnoreCase)) {
256         indj = j;
257         break;
258       }
259     }
260     if(indj<0) {
261       printf("<E> option |%s| unavailable **\n", 
262       runOpt.Data());
263       assert(0);
264     } else {
265       (*fKeyOpts)[indj] = 1;
266       printf("<I> option |%s| is valid : number %i : |%s| \n", 
267              runOpt.Data(), indj, fgAnaOpt[indj]);
268     }
269   }
270 }
271
272 Int_t AliEMCALRecPointsQaESDSelector::GetKeyOptsValue(Int_t key)
273 {
274   // Oct 14, 2007
275   static Int_t val=0;
276   val = 0;
277   if(fKeyOpts && key>=0 && key<fKeyOpts->GetSize()) {
278     val = fKeyOpts->At(key);
279   }
280   // printf(" key %i : val %i : opt %s \n", key, val, fgAnaOpt[key]);
281   return val;
282 }
283
284 Bool_t AliEMCALRecPointsQaESDSelector::Process(Long64_t entry)
285 {
286   // The Process() function is called for each entry in the tree (or possibly
287   // keyed object in the case of PROOF) to be processed. The entry argument
288   // specifies which entry in the currently loaded tree is to be processed.
289   // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
290   // to read either all or the required parts of the data. When processing
291   // keyed objects with PROOF, the object is already loaded and is available
292   // via the fObject pointer.
293   //
294   // This function should contain the "body" of the analysis. It can contain
295   // simple or elaborate selection criteria, run algorithms on the data
296   // of the event and typically fill histograms.
297
298   // WARNING when a selector is used with a TChain, you must use
299   //  the pointer to the current TTree to call GetEntry(entry).
300   //  The entry is always the local entry number in the current tree.
301   //  Assuming that fTree is the pointer to the TChain being processed,
302   //  use fTree->GetTree()->GetEntry(entry).
303
304   if (AliSelector::Process(entry) == kFALSE) {
305     AliDebug(AliLog::kError, Form("Entry %i is not available ",entry));
306     return kFALSE;
307   }
308
309   // esd->ReadFromTree(tree);
310   // AliESDEvent * esd = new AliESDEvent();
311
312   // Check prerequisites
313   if (!fESD)
314   {
315     AliDebug(AliLog::kError, "ESD branch not available");
316     return kFALSE;
317   }
318   
319   static AliEMCALPi0SelectionParRec* rPar = GetEmcalFolder()->GetPi0SelectionParRow(0);
320
321   static Int_t nEmcalClusters, indOfFirstEmcalRP, nEmcalRP,nEmcalPseudoClusters;
322   nEmcalClusters    = fESD->GetNumberOfEMCALClusters();
323   indOfFirstEmcalRP = fESD->GetFirstEMCALCluster();
324   u::FillH1(fLofHistsRP, 1, double(indOfFirstEmcalRP));
325
326   static AliRunLoader* rl = 0;
327   static Int_t nev = 0; // Temporary - 0nly for reading one file now !!
328   
329   static AliESDCaloCluster *cl = 0; 
330   nEmcalRP = nEmcalPseudoClusters = 0;
331   TList *l=0;
332   double eDigi=0;   
333
334   TClonesArray lvM1("TLorentzVector", 100);  // for convenience; 100 is enough now 
335   TArrayI      indLv(100);                   // index of RP
336
337   static TLorentzVector v, vcl;
338   int nrp = 0; // # of RP for gg analysis
339   static Double_t erec=0., ecorr=0.0;
340   for(int i=indOfFirstEmcalRP; i<indOfFirstEmcalRP+nEmcalClusters; i++) {
341     cl = fESD->GetCaloCluster(i);
342     if(cl->GetClusterType() == AliESDCaloCluster::kEMCALPseudoCluster) {
343       nEmcalPseudoClusters++;
344       l = fLofHistsPC;
345     } else if(cl->GetClusterType() == AliESDCaloCluster::kEMCALClusterv1){
346       nEmcalRP++;
347       if(fgEMCAL->GetIterationNumber()>1||GetKeyOptsValue(kIDEAL)||GetKeyOptsValue(kRECALIB)||GetKeyOptsValue(kFIT)) {
348         AliEMCALRecPoint *rp=0;
349         if(GetKeyOptsValue(kFIT) == kFALSE) fgDistEff = -1.; // No fitting ; Sep 4, 2007
350         if(GetKeyOptsValue(kIDEAL)) {
351           rp = AliEMCALFolder::GetRecPoint(cl, fgEMCAL->GetCCFirst(), 0, fLofHistsRP, fgDistEff, fgW0, fgSlopePhiShift);
352         } else {
353           rp = AliEMCALFolder::GetRecPoint(cl, fgEMCAL->GetCCFirst(), fgEMCAL->GetCCIn(), fLofHistsRP, fgDistEff, fgW0, fgSlopePhiShift);
354         }
355         if(GetKeyOptsValue(kPROF)) {
356           FillHistsForShowerProfile( GetListShowerProfile(), rp, GetCellsInfo());
357         }
358         //if(rp->GetPointEnergy()>=rPar->fEOfRpMin && u::GetLorentzVectorFromRecPoint(v, rp)) {
359         if(u::GetLorentzVectorFromRecPoint(v, rp)) { // comparing with RP
360           if(GetKeyOptsValue(kCORR1)) {
361             erec  = v.Rho();
362             ecorr = u::GetCorrectedEnergyForGamma1(erec);
363             v.SetRho(ecorr);
364             v.SetE(ecorr); // This is gamma
365             //printf("<1> erec %f | ecorr %f \n", erec, ecorr);
366           }
367           new(lvM1[nrp]) TLorentzVector(v);
368           indLv[nrp] = i;
369           nrp++;
370           // Conroling of recalibration
371           u::GetLorentzVectorFromESDCluster(vcl, cl);
372           u::FillH1(fLofHistsRP, 11, vcl.P()-v.P());
373           u::FillH1(fLofHistsRP, 12, TMath::RadToDeg()*(vcl.Theta()-v.Theta()));
374           u::FillH1(fLofHistsRP, 13, TMath::RadToDeg()*(vcl.Phi()-v.Phi()));
375
376           u::FillH1(fLofHistsRP, 16, v.P());
377           u::FillH2(fLofHistsRP, 17, vcl.P(), vcl.P()-v.P());
378           l = 0; // no filling
379           if(GetKeyOptsValue(kIDEAL) || GetKeyOptsValue(kRECALIB)) l = fLofHistsRP;
380         }
381         if(rp) delete rp;
382       } else { // first iteration
383         //        if(cl->E()>=rPar->fEOfRpMin && u::GetLorentzVectorFromESDCluster(v, cl)) {
384         if(u::GetLorentzVectorFromESDCluster(v, cl)) { // comparing with RP
385         // cut 0.4 GeV may be high ! 
386           if(GetKeyOptsValue(kCORR1)) {
387             erec  = v.Rho();
388             ecorr = u::GetCorrectedEnergyForGamma1(erec);
389             v.SetRho(ecorr);
390             v.SetE(ecorr); // This is gamma now
391             // printf("<2> erec %f | ecorr %f \n", erec, ecorr);
392             // printf("    v.Rho()  %f \n", v.Rho());
393           }
394           new(lvM1[nrp]) TLorentzVector(v);
395           indLv[nrp] = i;
396           nrp++;
397           l = fLofHistsRP;
398         }
399       }
400       
401     } else {
402       printf(" wrong cluster type : %i\n", cl->GetClusterType());
403       assert(0);
404     }
405     u::FillH1(l, 2, double(cl->GetClusterType()));
406
407     u::FillH1(l, 3, double(cl->GetNumberOfDigits()));  
408     u::FillH1(l, 4, double(cl->E()));  
409     // Cycle on digits (towers)
410     Short_t *digiAmpl  = cl->GetDigitAmplitude()->GetArray();
411     Short_t *digiTime  = cl->GetDigitTime()->GetArray();
412     Short_t *digiAbsId = cl->GetDigitIndex()->GetArray();
413     for(int id=0; id<cl->GetNumberOfDigits(); id++) {
414       eDigi = double(digiAmpl[id]) / 500.; // See AliEMCALClusterizerv1
415       //      if(eDigi <= 0.0) { // sometimes it is happen
416       //if(eDigi > 10.0 && cl->GetClusterType() == AliESDCaloCluster::kEMCALClusterv1) {
417       // printf(" %i digiAmpl %i : %f \n", id, int(digiAmpl[id]), eDigi);
418       //}
419       u::FillH1(l, 5, eDigi);
420       u::FillH1(l, 6, double(digiTime[id]));
421       u::FillH1(l, 7, double(digiAbsId[id]));
422       if(int(digiAbsId[id]) >= fgNmaxCell) {
423         printf(" id %i :  digiAbsId[id] %i (%i) : %s \n", 
424                id, int(digiAbsId[id]), fgNmaxCell, l->GetName());
425       }
426     }
427   }
428   u::FillH1(fLofHistsRP, 0, double(nEmcalRP));
429   u::FillH1(fLofHistsPC, 0, double(nEmcalPseudoClusters));
430
431   static TLorentzVector *lv1=0, *lv2=0, lgg;
432   for(int i1=0; i1<nrp; i1++){
433     lv1 = (TLorentzVector*)lvM1.At(i1);
434     u::FillH1(fLofHistsRP, 18, lv1->P());
435   }
436   static Double_t mgg, pgg;
437   mgg = pgg = 0.;
438   nrp = lvM1.GetEntriesFast(); 
439   if(nrp >= 2) {
440     // eff.mass analysis
441     for(int i1=0; i1<nrp-1; i1++){
442       lv1 = (TLorentzVector*)lvM1.At(i1);
443       for(int i2=i1+1; i2<nrp; i2++){
444         lv2 = (TLorentzVector*)lvM1.At(i2);
445         lgg = (*lv1) + (*lv2);
446         mgg = lgg.M();  // eff.mass
447         pgg = lgg.P();  // momentum
448         u::FillH1(fLofHistsRP, 8, mgg);
449  
450         if((mgg>=rPar->fMassGGMin && mgg<=rPar->fMassGGMax)) {// pi0 candidates
451           if((pgg>=rPar->fMomPi0Min && pgg>=rPar->fMomPi0Min)) {
452             if(fgEMCAL && fgEMCAL->GetIterationNumber()>=1) {
453               fgEMCAL->FillPi0Candidate(mgg,fESD->GetCaloCluster(indLv[i1]),fESD->GetCaloCluster(indLv[i2]));
454               u::FillH1(fLofHistsRP, 9, pgg); 
455               u::FillH1(fLofHistsRP,10, lv1->P());
456               u::FillH1(fLofHistsRP,10, lv2->P());
457             }
458           }
459         }
460       }
461     }
462   }
463
464   //  static Int_t fileNumber = 0;
465   static TString curFileName;
466   //  if(GetKeyOptsValue(kKINE) && nev<fChain->GetEntries()) {
467   if(GetKeyOptsValue(kKINE)) {
468   // Get galice.root file in current directory
469     if(nev%1000==0) {
470       printf(" current file |%s|\n", fChain->GetCurrentFile()->GetName());
471       curFileName = fChain->GetCurrentFile()->GetName();
472       curFileName.ReplaceAll("AliESDs.","galice."); 
473     }
474     rl = u::InitKinematics(nev, curFileName.Data());
475   // Compare kineamtics vs EMCal clusters
476     FillHistsOfKineVsRP(fLKineVsRP, rl, lvM1);
477   }
478
479   lvM1.Delete();
480
481   if(nEmcalClusters != (nEmcalRP+nEmcalPseudoClusters))
482     Info("Process","nEmcalClusters %i : RP %i + PC %i ",nEmcalClusters, nEmcalRP, nEmcalPseudoClusters); 
483
484   nev++;
485
486   return kTRUE;
487 }
488
489 void AliEMCALRecPointsQaESDSelector::SlaveTerminate()
490 {
491   // The SlaveTerminate() function is called after all entries or objects
492   // have been processed. When running with PROOF SlaveTerminate() is called
493   // on each slave server.
494
495   AliSelector::SlaveTerminate();
496
497   // Add the histograms to the output on each slave server
498   if (!fOutput)
499   {
500     AliDebug(AliLog::kError, Form("ERROR: Output list not initialized."));
501     return;
502   }
503
504   // fOutput->Add(fMultiplicity);
505 }
506
507 void AliEMCALRecPointsQaESDSelector::Terminate()
508 {
509   // The Terminate() function is the last function to be called during
510   // a query. It always runs on the client, it can be used to present
511   // the results graphically or save the results to file.
512
513   AliSelector::Terminate();
514
515   PrintInfo();
516 }
517
518 //
519 TList *AliEMCALRecPointsQaESDSelector::DefineHistsOfRP(const char *name,Double_t p,Int_t keyOpt)
520 {
521   //
522   // Define histogramms of rec.points
523   //
524   printf("<I> DefineHistsOfRP :%s : p %f : keyOpt %i \n", name, p, keyOpt);
525   Double_t adcChannelEC = 0.0153; // ~15mev per adc count
526   Double_t xma = p*1.4, xmi=0.0, step=0.0, xmic=xmi, xmac = xma;
527   if(xma<0) xma = 20.;
528   Int_t nmax=1000, scale=4, nmaxc = nmax;
529
530   gROOT->cd();
531   TH1::AddDirectory(1);
532   new TH1F("00_EmcalMultiplicity", "multiplicity of EMCAL  ", 201, -0.5, 200.5); // real and pseudo
533   new TH1F("01_IndexOfFirstEmcal", "index of first emcal rec.points ", 201, -0.5, 200.5);
534
535   new TH1F("02_NumberOf", "number of  ", 6, -0.5, 5.5);
536   new TH1F("03_NumberOfDigitsIn", "number of digits(towers) in rec.points ", 101, -0.5, 100.5);
537
538   if(keyOpt==1 && p>0.1) {
539     if   (p>=100.)  scale=12;
540     else if(p>=50.) scale=10;
541     else if(p>=30.) scale=8;  
542     xma = p + scale*(0.15*TMath::Sqrt(p));
543     xmi = p - scale*(0.15*TMath::Sqrt(p));
544     step = (xma-xmi)/nmax;
545   }
546
547   if(step < 0.0153) {
548     nmax = int((xma-xmi) / adcChannelEC)+1;
549     xma =  xmi + adcChannelEC*nmax;
550   } 
551   new TH1F("04_EnergyOf", "energy of ", nmax, xmi, xma);
552   nmaxc = nmax; xmic=xmi; xmac = xma;
553
554   nmax = 10000;
555   xmi  = adcChannelEC/2.; xma = xmi + adcChannelEC*nmax;
556   // All energy(momentum) unit is GeV if don't notice
557   new TH1F("05_DigitEnergyIn", "digit energy in ", nmaxc, xmic, xmac);
558   new TH1F("06_DigitTimeIn", "digit time in 10ps(0.01ns) ", 1000, 0.0, 3.e+3); // ns/100 = 10 ps
559   new TH1F("07_DigitAbsIdIn", "digit abs id in ", fgNmaxCell, -0.5, double(fgNmaxCell)-0.5);
560   new TH1F("08_EffMass", "effective mass of #gamma,#gamma(m_{#pi^{0}}=134.9766 MeV)", 100, 0.0, 0.5);
561   new TH1F("09_MomOfPi0Candidate", "momentum of #pi^{0} candidates (0.085 <mgg<0.185)", 600, 0.0, 30.0);
562   new TH1F("10_MomOfRpPi0Candidate", "momentum of RP for #pi^{0} candidates (0.085 <mgg<0.185)", 600, 0.0, 30.0);
563   // Recalibration staf
564   Double_t pmax=11., dpmax=0.20;
565   if(p>0.1) {
566     pmax=p*1.2;
567     dpmax *= p;
568   }
569   new TH1F("11_MomClESD-RpRecalib", "difference of momentum cl(ESD) - rp(Recalib)", 100, -.01, dpmax);
570   new TH1F("12_ThetaClESD-RpRecalib", "difference of #theta cl(ESD) - rp(Recalib) in degree", 100, -0.05, +0.05);
571   new TH1F("13_PhiClESD-RpRecalib", "difference of #phi cl(ESD) - rp(Recalib) in degree ", 100, -0.05, +0.05);
572   // Digi
573   new TH1F("14_EDigiRecalib", "energy of digits after recalibration", 2000, 0.0, 20.);
574   //  AliEMCALGeometry* g = AliEMCALGeometry::GetInstance();
575   new TH1F("15_AbsIdRecalib", "abs Id of digits after recalibration", fgEmcalGeo->GetNCells(),-0.5,Double_t(fgEmcalGeo->GetNCells())-0.5);
576   new TH1F("16_EnergyOfRecalibRp_", "energy of recalibrated rec.points", nmaxc, xmic, xmac); // Jul 12, 2007
577   new TH2F("17_ShiftRecalib_", "E(clESD) - E(recalib)", 110,0.0, pmax, 50,0.0,dpmax); // Jul 13, 2007
578   
579   // Corrected staff
580   new TH1F("18_EnergyOfCorrectedLV", "energy of corrected LV", nmaxc, xmic, xmac);
581
582   TString st = Form("ListOfHists%s_P=%5.1f",name,p);
583   st.ReplaceAll(" ","");
584   TList *l = u::MoveHistsToList(st.Data(), kFALSE);
585   st = Form("%s_P=%5.1f",name,p);
586   st.ReplaceAll(" ","");
587   u::AddToNameAndTitleToList(l, st.Data(), st.Data());
588
589   return l;
590 }
591
592 TList* AliEMCALRecPointsQaESDSelector::DefineHistsOfKineVsRP(const char *name,  Double_t p, Int_t keyOpt)
593 {
594   //
595   // Define histogramms for comparing a initial kinematics with rec.points
596   //
597  printf("<I>  DefineHistsOfKineVsRP :%s : p %f : keyOpt %i \n", name, p, keyOpt);
598
599   gROOT->cd();
600   TH1::AddDirectory(1);
601   new TH1F("00_hVx",Form("Vx of primary vertex"), 100, -5., +5.);   // 00
602   new TH1F("01_hVy",Form("Vy of primary vertex"), 100, -5., +5.);   // 01
603   new TH1F("02_hVz",Form("Vz of primary vertex"), 100, -50., +50.); // 02
604
605   //  Double_t adcChannelEC = 0.0153; // ~15mev per adc count
606   Double_t xma = p*1.4, xmi=0.0, sig=0.15*TMath::Sqrt(p);
607   //  Double_t step=0.0, xmic=xmi, xmac = xma;
608   if(xma<0) xma = 20.;
609   //Int_t nmax=1000;
610   // scale=4, nmaxc = nmax;
611
612   new TH1F("03_hGidPrimar", "Geant Id of primary particle ", 101, 0.5, 100.5);   // 03
613   new TH1F("04_hPmomPrim","momentum of primary particle", 100, xmi, xma);        // 04
614   new TH1F("05_hEtaPrim","#eta of primary particle ", 200, -1., 1.);             // 05
615   new TH1F("06_hPhiPrim","#phi of primary particle ", 63*2, 0.0,TMath::Pi()*2.); // 06
616   new TH1F("07_hThetaPrim","#theta of primary particle", 63, 0.0,TMath::Pi());   // 07 
617   new TH1F("08_hPhiPrimInDegree","#phi of primary particle in degree", 120, 75.0, 195.0);  // 08
618   new TH1F("09_hThetaPrimInDegree","#theta of primary particle in degree", 90, 45., 135.); // 09
619
620   // Particle vs cluster
621   new TH1F("10_hE(P)-E(RP)"," E(p) - E(RP) ", 100, -10.*sig, 10.*sig);   // 10
622
623   new TH1F("11_hPvsRpAngleInDegree","angle between P and RP (in degree)", 110, 0.0, 1.0); // 11
624   double dphi=0.5; // for fitting
625   new TH1F("12_hPvsRpDPhiInDegree","dif(#phi) between P and RP (in degree)", 100, -dphi, dphi); // 12
626   new TH1F("13_hPvsRpDThetaInDegree","dif(#theta) between P and RP (in degree)", 100, -0.5, 0.5); // 13
627
628   new TH1F("14_hPvsRpDPhiInDegree","dif(#phi) between P and RP (in degree) right part of SM", 100, -dphi, +dphi); // 14
629   new TH1F("15_hPvsRpDPhiInDegree","dif(#phi) between P and RP (in degree) left part of SM", 100, -dphi, dphi); // 15
630
631   new TH1F("16_hPvsRpDThetaInDegree","dif(#theta) between P and RP (even index)", 100, -0.5, 0.5); // 16
632   new TH1F("17_hPvsRpDThetaInDegree","dif(#theta) between P and RP (odd  index)", 100, -0.5, 0.5); // 17
633
634   TString st = Form("ListOfHists%s_P=%5.1f",name,p);
635   st.ReplaceAll(" ","");
636   TList *l = u::MoveHistsToList(st.Data(), kFALSE);
637   st = Form("%s_P=%5.1f",name,p);
638   st.ReplaceAll(" ","");
639   u::AddToNameAndTitleToList(l, st.Data(), st.Data());
640   return l;
641 }
642
643 TList *AliEMCALRecPointsQaESDSelector::DefineHistsForShowerProfile(const char *name, Double_t p)
644 {
645   // Aug 1, 2007 - shower profile business as in testbeam analysis
646   //               Phi direction here is Y direction in testbeam 
647   printf("<I> DefineHistsForShowerProfile: %s : p %f \n", 
648   name, p);
649
650   gROOT->cd();
651   TH1::AddDirectory(1);
652
653   // Cell unit
654   new TH1F("00_hPHiMean"," mean in #phi direction ", 24*10, 0.0, 24.);
655   new TH1F("01_hPHiLog"," mean with log in #phi direction ", 24*10, 0.0, 24.);
656   new TH2F("02_XmeanVsXlog", "xmean vs xlog", 240,0.0, 24.,240,0.0, 24.);
657   new TH2F("03_XmeanVsXlog", "xmean vs xlog (system of cell with max energy, first half on #eta)", 
658   50,-0.5,+0.5, 100,-1.,+1.);
659   new TH2F("04_XmeanVsXlog", "xmean vs xlog (system of cell with max energy, second half on #eta)", 
660   50,-0.5,+0.5, 100,-1.,+1.);
661
662   new TH2F("05_PhiShowerProfile", " #phi shower profile - cumulative distribution",
663   6*25,-3.,3., 201, -0.0025, 1.0025);   // 00; x direction in cell unit
664
665   TString st = Form("L%s_P=%5.1f",name,p);
666   st.ReplaceAll(" ","");
667   TList *l = u::MoveHistsToList(st.Data(), kFALSE);
668   st = Form("%s_P=%5.1f",name,p);
669   st.ReplaceAll(" ","");
670   u::AddToNameAndTitleToList(l, st.Data(), st.Data());
671
672   return l;
673 }
674
675 void AliEMCALRecPointsQaESDSelector::FillHistsOfKineVsRP(TList *l, AliRunLoader* rl,  TClonesArray &lvM)
676 {
677   //
678   // lvM - array of TLorentzVector's which was cretaef from AliESDCaloCluster's
679   //
680
681   if(l==0 || rl==0) return;
682
683   // TNtuple for qucik analysis
684   static TNtuple *nt=0;
685   if(nt==0) {
686     gROOT->cd();
687     Int_t bsize = int(1.e+7);
688     nt = new TNtuple("angle","angle ntuple for quick analysis",
689     "dPhi:dTheta:phiP:thetaP", bsize);
690     gROOT->GetListOfBrowsables()->Add(nt);
691   }
692   static AliStack* st=0;
693   static TParticle *p=0;
694   static Int_t gid=0, ic=0, pdg=0, i=0;
695   gid = ic = pdg = 0;
696
697   st = rl->Stack();
698   if(st == 0) return;
699   // first primary particle
700   p = st->Particle(0);
701   if(p == 0) return;
702
703   u::FillH1(l, ic++, p->Vx());
704   u::FillH1(l, ic++, p->Vy());
705   u::FillH1(l, ic++, p->Vz());
706
707   pdg = p->GetPdgCode();
708   //gid = gMC->IdFromPDG(pdg); // gMc should be defined
709   AliEMCALJetMicroDst::Sgpdge(pdg,gid); // temporary
710
711   u::FillH1(l, ic++, Double_t(gid));
712   u::FillH1(l, ic++, p->P());
713   u::FillH1(l, ic++, p->Eta());
714   u::FillH1(l, ic++, TVector2::Phi_0_2pi(p->Phi()) );
715   u::FillH1(l, ic++, p->Theta());
716   // In degree
717   u::FillH1(l, ic++, TVector2::Phi_0_2pi(p->Phi())*TMath::RadToDeg());
718   u::FillH1(l, ic++, p->Theta()*TMath::RadToDeg()); // 09
719
720   if(lvM.GetEntriesFast() == 0) return;
721   //
722   // Initial kinematics vs Calo clusters
723   //
724   static TLorentzVector *lv = 0, lvp;
725   lvp.SetPxPyPzE(p->Px(),p->Py(),p->Pz(),p->Energy()); // Particle 
726
727   Double_t angle = 0.0, angleMin = 180.0, eDiff=0.0, dPhi=0., dTheta=0., phiP=0.0, thetaP=0.0;
728   Int_t indMin = 0;
729   phiP   = lvp.Phi() * TMath::RadToDeg();
730   if (phiP<81. || phiP>99.)  return;     // cut phi boundaries
731   thetaP = lvp.Theta() * TMath::RadToDeg();
732   if (thetaP<56. || thetaP>89.)  return; // cut theta boundaries
733
734   for(i=0; i<lvM.GetEntriesFast(); i++) {
735     lv = (TLorentzVector*)lvM.At(i);
736     angle = lv->Angle(lvp.Vect())*TMath::RadToDeg();
737     if(angleMin > angle) {
738       angleMin = angle;
739       indMin   = i;
740     }
741   }
742   lv = (TLorentzVector*)lvM.At(indMin);
743   eDiff   = lvp.E() - lv->E();
744   u::FillH1(l, ic++, eDiff); 
745
746   dPhi    = TVector2::Phi_mpi_pi(lvp.Phi()-lv->Phi())*TMath::RadToDeg();
747   dTheta  = TVector2::Phi_mpi_pi(lvp.Theta()-lv->Theta())*TMath::RadToDeg();
748   u::FillH1(l, ic++, angleMin);
749   u::FillH1(l, ic++, dPhi); 
750   u::FillH1(l, ic++, dTheta); 
751
752   if       (phiP>=81. && phiP<=90.) {
753     u::FillH1(l, 14, dPhi); 
754   } else if(phiP> 90. && phiP<=99.) {
755     u::FillH1(l, 15, dPhi); 
756   }
757   // Unfinished - have to get absid of digit with max energy 
758   u::FillH1(l, 16, dTheta); 
759   u::FillH1(l, 17, dTheta); 
760   if(nt) {
761     nt->Fill(dPhi,dTheta,phiP,thetaP);
762     /*
763      tv__tree = (TTree *) gROOT->FindObject("angle");
764      tv__tree->Draw("dPhi:phiP","abs(dPhi)<0.5","", 9182, 0);
765      tv__tree->Draw("dTheta:thetaP","abs(dTheta)<0.5","", 9182, 0);
766      */
767   }
768 }
769
770 void AliEMCALRecPointsQaESDSelector::FillHistsForShowerProfile
771 (TList *l, AliEMCALRecPoint *rp, AliEMCALCellInfo * t)
772 {
773   // Aug 1, 2007
774   if(l==0 || rp==0 || t==0) return;
775   // --
776   static Double_t xmean=0., xlog=0.;
777   static AliEMCALCellIndexes rMax;
778   static Int_t phiSize;
779
780   if(rp->GetPointEnergy() < 1.0) return;
781   //if(rp->GetPointEnergy() > 8.0) return; // discard merged clusters for pi0 case
782
783   EvalLocalPhiPosition(1.,  rp, t, xmean, phiSize, rMax);
784   if(phiSize == 0) return; // just one row in cell directions
785
786   EvalLocalPhiPosition(5.5, rp, t, xlog, phiSize, rMax);
787   if(rMax.fIPhi>1.5&&rMax.fIPhi<21.5 && rMax.fIEta>1.5&&rMax.fIEta<46.5) { 
788     u::FillH1(l, 0, xmean); 
789     u::FillH1(l, 1, xlog); 
790     u::FillH2(l, 2, xlog, xmean);
791     // Select two central modules
792     if((rMax.fIPhim==5 || rMax.fIPhim==6)){
793     // Transition to system of cell with max energy
794       xmean -= (double(rMax.fIPhi)+0.5);  
795       xlog  -= (double(rMax.fIPhi)+0.5);  
796       if(rMax.fIEtam>=2 && rMax.fIEtam<=12){ // approximatively first half on eta 
797         u::FillH2(l, 3, xlog, xmean);
798       } else {// approximatively second half on eta 
799         u::FillH2(l, 4, xlog, xmean);
800       }
801     }
802   }
803 }
804
805 void   AliEMCALRecPointsQaESDSelector::EvalLocalPhiPosition(const Double_t wlog, const AliEMCALRecPoint *rp, const AliEMCALCellInfo* t, Double_t &xcog, Int_t &phiSize, AliEMCALCellIndexes &rMax)
806 {
807   // wlog = 1 - usual center of gravity; >1 - with logarithmic weight.
808   // digits - array of digits
809   // t      - 
810   //==
811   // xcog - position of center of gravity in cell unit 
812   if(wlog<1.0 || rp==0 || t==0) return;
813   xcog = 0;
814
815   static Double_t wtot=0., w=0., edigi=0., e=0., edigiMax=0.;
816   static Int_t absid = 0, phiMin=0, phiMax=0;
817   static AliEMCALCellIndexes* r=0;
818
819   e = rp->GetPointEnergy();
820   wtot = 0.0;
821   edigiMax=0.;
822
823   phiMin = 23; phiMax = 0;
824   for(Int_t iDigit=0; iDigit<rp->GetMultiplicity(); iDigit++) {
825     absid = rp->GetAbsId()[iDigit];
826     edigi = rp->GetEnergiesList()[iDigit];
827     if(wlog > 1.0)  w = TMath::Max( 0., wlog + TMath::Log(edigi/e));
828     else            w = edigi; // just energy
829
830     r     = t->GetTable(absid);
831     xcog += w*(Double_t(r->fIPhi) + 0.5);
832     wtot += w;
833     if(edigi > edigiMax) {
834       edigiMax = edigi;
835       rMax = (*r);
836     }
837     if(phiMin > r->fIPhi) phiMin = r->fIPhi; 
838     if(phiMax < r->fIPhi) phiMax = r->fIPhi; 
839   }
840   xcog /= wtot;
841   phiSize = phiMax - phiMin;
842   //  printf("phiSize %i \n", phiSize); 
843 }
844 /* unused now
845 TList *AliEMCALRecPointsQaESDSelector::DefineHistsOfTowers(const char *name)
846 {
847   //
848   // ESD: towers information was saved to pseudo clusters
849   // 
850   gROOT->cd();
851   TH1::AddDirectory(1);
852   new TH1F("00_EmcalMultiplicity", "multiplicity of EMCAL  ", 201, -0.5, 200.5); // number of pseudo RP
853
854   new TH1F("01_EnergyOf", "energy of ", 1000, 0.0, 100.);
855
856   TList *l = u::MoveHistsToList(Form("ListOfHists%s",name, " - ESD"), kFALSE);
857   u::AddToNameAndTitleToList(l, name, name);
858
859   return l;
860 }
861 */
862
863 void AliEMCALRecPointsQaESDSelector::FitEffMassHist()
864 {
865   TH1* h = (TH1*)fLofHistsRP->At(8);
866   AliEMCALCell::FitHist(h, GetName(), "draw");
867 }
868
869 void AliEMCALRecPointsQaESDSelector::PrintInfo()
870 {
871   // Service routine
872   printf("\n %i Entrie(s) | Option(s) |%s| \n", GetOptsArray().GetEntries(), fRunOpts.Data());  
873   for(int i=0; i<fgNanaOpt; i++) {
874     if(GetKeyOptsValue(i)) printf(" %i |%s| \n", i, fgAnaOpt[i]);
875   }
876
877   TList *l[2] = {fLofHistsPC, fLofHistsRP};
878   printf("\n");
879   for(int i=0; i<2; i++){
880     TH1F *h = (TH1F*)l[i]->At(2);
881     printf(" %s \t: %i \n", h->GetTitle(), int(h->GetEntries()));
882   }
883   printf(" fgDistEff %f fgW0 %f fgSlopePhiShift %f \n", fgDistEff, fgW0, fgSlopePhiShift);
884 }
885
886 void  AliEMCALRecPointsQaESDSelector::SetMomentum(Double_t p) 
887 { // Jul 9, 2007
888   fPmom = p;
889   //  SetName(Form("%s_p_%f5.1", GetName(), p));
890 }
891
892
893 AliEMCALFolder*  AliEMCALRecPointsQaESDSelector::CreateEmcalFolder(const Int_t it)
894 {
895   //
896   // Create emcal folder for iteration number it
897   //
898   AliEMCALFolder* newFolder = new AliEMCALFolder(it); // folder for iteration #it   
899   if(it>1) {
900     fgEMCALOld = fgEMCAL; 
901     AliEMCALCalibCoefs* tabOldOut = fgEMCALOld->GetCCOut();
902     AliEMCALCalibCoefs* tabNewIn = new AliEMCALCalibCoefs(*tabOldOut);
903     tabNewIn->SetName(AliEMCALFolder::GetCCinName().Data());
904     newFolder->Add(tabNewIn);
905   } 
906   fEmcalPool->Add(newFolder);
907   fgEMCAL = newFolder;
908
909   return fgEMCAL;
910 }
911
912 AliEMCALFolder* AliEMCALRecPointsQaESDSelector::GetEmcalOldFolder(const Int_t nsm)
913 {
914   // Return emcal folder with number nsm
915   AliEMCALFolder* folder=0;
916   if(fEmcalPool) folder =  (AliEMCALFolder*)fEmcalPool->FindObject(Form("EMCAL_%2.2i",nsm));
917   return folder;
918 }
919
920
921 void AliEMCALRecPointsQaESDSelector::SetEmcalFolder(AliEMCALFolder* folder)
922 {
923   fgEMCAL = folder;
924   fEmcalPool->Add(fgEMCAL);
925 }
926
927 void AliEMCALRecPointsQaESDSelector::SetEmcalOldFolder(AliEMCALFolder* folder)
928 {
929   fgEMCALOld = folder;
930   fEmcalPool->Add(fgEMCALOld);
931 }
932
933 void AliEMCALRecPointsQaESDSelector::Browse(TBrowser* b)
934 {
935   // What we see at browser
936   if(fESD)        b->Add(fESD);
937   if(fChain)      b->Add(fChain);
938   if(fEmcalPool)  b->Add(fEmcalPool);
939   if(fgEmcalGeo) b->Add(fgEmcalGeo);
940   if(fCellsInfo)  b->Add(fCellsInfo);
941   //
942   if(fLofHistsPC) b->Add(fLofHistsPC);
943   if(fLofHistsRP) b->Add(fLofHistsRP);
944   if(fLKineVsRP)  b->Add(fLKineVsRP);
945   if(fLShowerProfile) b->Add(fLShowerProfile);
946   //  if(u) b->Add(u);
947 }
948
949 Bool_t AliEMCALRecPointsQaESDSelector::IsFolder() const
950 {
951   if(fESD || fLofHistsRP || fEmcalPool) return kTRUE;
952   return kFALSE;
953 }
954
955 void AliEMCALRecPointsQaESDSelector::Save(Int_t ver, const char *optIO)
956
957   // Aug 3, 2007
958   // Save selector to file
959   TString dir("/home/pavlinov/ALICE/SHISHKEBAB/RF/CALIB/"); // Root directory for saving
960   TString nf=dir;
961   if(GetKeyOptsValue(kPROF)) {
962     nf += "PROF/PROFILE_";
963     nf += ver;
964     nf += ".root";
965     TFile f(nf.Data(), optIO);
966     if(f.IsOpen()) {
967       this->Write();
968       f.Close();
969       printf("<I> Save selectort to file |%s| : optIO %s \n",nf.Data(), optIO);
970     } else {
971       printf("<W> File %s exits ! Increase version : ver %i !\n", nf.Data(), ver);
972     }
973   } else {
974     printf("No PROF option -> no saving now !\n");
975   }
976 }
977
978 AliEMCALRecPointsQaESDSelector* AliEMCALRecPointsQaESDSelector::ReadSelector(const char* nf)
979 {
980   // Read selector to file
981   AliEMCALRecPointsQaESDSelector* selector=0;
982
983   TH1::AddDirectory(0);
984   TFile f(nf,"READ");
985   if(f.IsOpen()) {
986     TObject *o = f.Get("AliEMCALRecPointsQaESDSelector");
987     if(o) selector = dynamic_cast<AliEMCALRecPointsQaESDSelector *>(o);
988   }
989   // printf("<I> read selector %p : file |%s| \n", selector, nf);
990   return selector;
991 }
992
993 void AliEMCALRecPointsQaESDSelector::ReadAllEmcalFolders()
994 {
995   // Oct 14, 2007
996   if(fEmcalPool==0) {
997     fEmcalPool = new TFolder("PoolOfEMCAL","");
998     for(Int_t it=1; it<=10; it++){
999       AliEMCALFolder* fold = AliEMCALFolder::ReadFolder(Form("EMCALFOLDER_It%i_fit.root",it), "READ");
1000       //      AliEMCALFolder* fold = AliEMCALFolder::Read(Form("EMCALFOLDER_It%i_fit.root",it), "READ");
1001       if(fold) fEmcalPool->Add(fold);
1002     }
1003   }
1004 }
1005
1006 void AliEMCALRecPointsQaESDSelector::PictVsIterNumber(const Int_t ind, const Int_t nsm)
1007 {
1008   // Jun 27, 2007 - unfinished; which picture is the best
1009   if(ind<0 || ind>5) return;
1010   gROOT->cd();
1011   TH1::AddDirectory(1);
1012
1013   Int_t itMax = 10, it=0;
1014   map <int, char*> indName;
1015   indName[0] = "eff.mass";
1016   indName[3] = "mass of #pi_{0}";
1017   indName[4] = "resolution of #pi_{0}";
1018   indName[5] = "chi^{2}/ndf";
1019
1020   TH1F *hout = new TH1F(indName[ind], indName[ind], itMax, 0.5, double(itMax)+0.5); 
1021    
1022   TH1::AddDirectory(0);
1023   Double_t content, error;
1024   TList* col = (TList*)fEmcalPool->GetListOfFolders();
1025   for(Int_t i=0; i<col->GetSize(); i++) { // cycle on EMCAL folders
1026     AliEMCALFolder* folder = static_cast<AliEMCALFolder*>(col->At(i));
1027     if(folder==0) continue;
1028     it = folder->GetIterationNumber();
1029
1030     AliEMCALSuperModule* sm = folder->GetSuperModule(nsm);
1031     if(sm==0) continue;
1032
1033     TList* l = sm->GetHists();
1034     if(l==0) continue;
1035
1036     TH1F *hin = (TH1F*)l->At(ind);
1037     if(hin==0) continue;
1038
1039     if(ind !=0 ) {
1040       content = hin->GetMean();
1041       error   = hin->GetRMS();
1042     } else {
1043       sm->FitEffMassHist();
1044       TF1 *f = (TF1*)hin->GetListOfFunctions()->At(0);
1045       content = error = -1.;
1046       if(f) {
1047         //        content = f->GetParameter(1);
1048         //error   = f->GetParameter(2);
1049         content = f->GetParameter(2);
1050         error   = f->GetParError(2);
1051       }
1052     }
1053
1054     if(content > 0.0) {
1055       hout->SetBinContent(it, content);
1056       hout->SetBinError(it, error);
1057       printf(" it %i content %f +/- %f \n", it, content, error);
1058     }
1059   }
1060
1061   u::DrawHist(hout,2);
1062   hout->SetMinimum(0.0);
1063
1064 }
1065
1066 TH1F* AliEMCALRecPointsQaESDSelector::FitHistOfRecPointEnergy(const char *opt)
1067 {
1068   // Fit hist of rec.point energy
1069   TH1::AddDirectory(0);
1070
1071   TString sopt(opt);
1072   sopt.ToUpper();
1073
1074   Int_t ind = 4, ind2 = 16;
1075   if(GetKeyOptsValue(kIDEAL)) {
1076     ind  = 16; // Jul 12, 2007
1077     ind2 =  4;
1078   } else if(GetKeyOptsValue(kCORR1)) {
1079     ind  = 18;
1080     ind2 =  4;
1081   }
1082   TH1F *hold = (TH1F*)fLofHistsRP->At(ind), *h=0;
1083   if(hold == 0) return 0;
1084   if(hold->GetEntries() <10.) return hold;
1085
1086   if(sopt.Contains("CLONE")) {
1087     TString newName(Form("C_%s",hold->GetName()));
1088     h = (TH1F*)hold->Clone(newName.Data());
1089     printf(" Clone hist %s -> |%s|%s| \n",hold->GetName(),h->GetName(),h->GetTitle()); 
1090   } else {
1091     h = hold;
1092   }
1093   TH1F* h2 = (TH1F*)fLofHistsRP->At(ind2);
1094
1095   Double_t xmax = h->GetXaxis()->GetXmax(), xmin = 0.4*xmax;;
1096   TF1 *g = u::Gausi("fRecPointE", xmin, xmax, h);
1097   g->SetLineColor(kRed);
1098   gStyle->SetOptFit(111);
1099
1100   h->Fit(g,"N","", xmin, xmax);
1101   printf(" (1) xmin %f : xmax %f \n", xmin, xmax);
1102
1103   xmin = g->GetParameter(1) - 4.*g->GetParameter(2);
1104   xmax = g->GetParameter(1) + 4.*g->GetParameter(2);
1105   h->Fit(g,"Q+","", xmin, xmax);
1106   u::DrawHist(h2,1, 1, "same",2);
1107   printf(" (2) xmin %f : xmax %f \n", xmin, xmax);
1108
1109   return h;
1110 }
1111
1112 TCanvas *AliEMCALRecPointsQaESDSelector::Linearity(TList *l, int ifun)
1113
1114   // Jul 10, 2007
1115   // Draw picture of EMCal linearity 
1116   if(l==0) {
1117     printf("<E> AliEMCALRecPointsQaESDSelector::Linearity :TList is zero ! Bye ! \n");
1118     return 0;
1119   }
1120   Double_t p[9]={0.5, 1., 3., 5., 10., 20., 30., 50., 100.}, ep[9];
1121   // see macro rHits.C ->defineSampleFraction
1122   TH1F* hErecOverEin = new TH1F("hErecOverEin","Ratio E_{rec}/E_{#gamma} vs E_{#gamma}", 101,0.5,101.5);
1123   // Fill hist
1124   TArrayD invRat(9), eInvRat(9), erec(9),derec(9), residual(9);
1125   TArrayD res(9), eres(9); // resolution
1126   Int_t np=9;
1127   for(Int_t var=0; var<9; var++){
1128     TH1F *h = (TH1F*)l->At(var);
1129     TF1  *f = (TF1*)h->GetListOfFunctions()->At(0);
1130     Double_t  mean = f->GetParameter(1);
1131     Double_t emean = f->GetParError(1);
1132
1133     Int_t bin = hErecOverEin->FindBin(p[var]);
1134     hErecOverEin->SetBinContent(bin, mean/p[var]);
1135     hErecOverEin->SetBinError(bin,  emean/p[var]); 
1136     //
1137     invRat[var]  = p[var]/mean;
1138     eInvRat[var] = emean/p[var]*invRat[var];
1139     erec[var]    = mean;
1140     derec[var]   = emean;
1141     // Resolution in %
1142     res[var]  = 100.*f->GetParameter(2)/p[var];
1143     eres[var] = 100.*f->GetParError(2)/p[var];
1144     ep[var] = 0.0;
1145   }
1146
1147   TCanvas *c = new TCanvas("Linearity","Linearity", 20,20, 700, 500);
1148   gStyle->SetOptStat(0);
1149   if(0) { // E(rec) / E(gamma)
1150     u::DrawHist(hErecOverEin,2);
1151     hErecOverEin->SetMinimum(0.984);
1152     hErecOverEin->SetMaximum(1.001);
1153   }
1154   Int_t markerColor=1;
1155   char *fun="", *optFit="";
1156   TF1 *f = 0;
1157   if(0) {
1158     if(ifun==-5) {
1159       fun = "fun5"; optFit="R+";
1160       f = new TF1(fun,"([0]*(x-7.5)*(x-7.5))*exp([1]+[2]*x+[3]*x*x)+1.", 0.0, 100.);
1161       f->FixParameter(0, 1.95380e-05);
1162       //      f->SetParameter(0, 1.95380e-05);
1163       //      f->SetParameter(1, 1.0);
1164     } else if(ifun==-4) {
1165       fun = "fun4"; optFit="R+";
1166       f = new TF1(fun,"([0]*(x-7.5)*(x-7.5))*([1]+[2]*abs(x)+[3]*(x-[4])*(x-[4]))+1.", 0.0, 100.);
1167       f->FixParameter(0, 1.95380e-05);
1168       f->SetParameter(4, 50.);
1169       //      f = new TF1(fun,"exp(([0]+[1]*x)*(x-[2])*(x-[3]))", 0.0, 100.);
1170       //f = new TF1(fun,"([0]+[1]*x)*(x-[2])*(x-[3])", 0.0, 100.);
1171       //f->SetParameter(0, 1.);
1172       //f->SetParameter(1, 1.);
1173
1174       //      f->SetParameter(2, 5.);
1175       //f->SetParLimits(2, 3.,8.);
1176       //f->SetParameter(3, 10.);
1177       //f->SetParLimits(3, 9.,15.);
1178       //f->SetParameter(2, 2.e-4);
1179     } else if(ifun==-3) {
1180       fun = "fun3"; optFit="R+";
1181       f = new TF1(fun,"[0]+[1]*x+[2]*x*x+[3]*x*x*x", 0.0, 11.);
1182     } else if(ifun==-2) {
1183       fun = "fun2"; optFit="R+";
1184
1185       /*
1186       f = new TF1(fun,"[0]*(x-7.5)+[1]*(x-7.5)*(x-7.5)+[2]", 0.0, 10.1); 
1187       f->SetParameter(0, 5.98727e-04);
1188       f->SetParameter(1, 2.12045e-04);
1189       f->SetParameter(2, 1.);
1190       */
1191       f = new TF1(fun,"[0]+[1]*x+[2]*x*x", 9.0, 100.1); 
1192     } else if(ifun==-1) {
1193       fun = "fun0"; optFit="R+";
1194       f = new TF1(fun,"[0]", 0.0, 100.1); 
1195     } else if(ifun>=2) {
1196       fun = Form("pol%i",ifun); 
1197       optFit="+";
1198     }
1199     TGraphErrors *gr = u::DrawGraphErrors(np, erec.GetArray(),invRat.GetArray(),derec.GetArray(),eInvRat.GetArray(),
1200    //    markerColor,21+markerColor,"AP", " Ratio E_{#gamma}/E_{Rec} ", "E_{Rec}  ","   E_{#gamma}/E_{Rec}",
1201  markerColor,21+markerColor,"AP", " Ratio E_{#gamma}/E_{Rec}^{corr} ", "E_{Rec}^{corr}  ","   E_{#gamma}/E_{Rec}^{corr}",
1202                                           ifun, optFit, fun);
1203     gr->GetHistogram()->SetAxisRange(0.0,100.);
1204     //    double xmi=0.999, xma=1.017;
1205     double xmi=0.995, xma=1.005;
1206     gr->GetHistogram()->SetMaximum(xma);
1207     gr->GetHistogram()->SetMinimum(xmi);
1208     gr->GetHistogram()->SetTitleOffset(1.4,"y");
1209     if(ifun==0) {
1210       f = new TF1("fres", "AliEMCALHistoUtilities::EnergyCorrectionForGamma1(x)", 0., 101.); 
1211       f->Draw("same");
1212     }
1213   }
1214   TLine *line = new TLine(0.0,1.0, 100.,1.0);
1215   line->Draw();
1216
1217   if(0) {
1218     c->Clear();
1219     for(int i=0; i<9; i++) {
1220       residual[i] =  100.*(invRat[i] - u::GetCorrectionCoefficientForGamma1(erec[i])); // in percent
1221       printf(" erec %f : residual %5.3f \n", erec[i], residual[i]);
1222     }
1223     markerColor = 2;
1224     TGraphErrors *gr2=u::DrawGraphErrors(np, erec.GetArray(),residual.GetArray(),derec.GetArray(),eInvRat.GetArray(),
1225                   markerColor,21+markerColor,"AP"," residual in %, rec.point level", "E_{Rec}  ","  residual in %",
1226     -1, "", 0);
1227     gr2->GetHistogram()->SetAxisRange(0.0,100.);
1228     gr2->GetHistogram()->SetMaximum(0.2);
1229     gr2->GetHistogram()->SetMinimum(-0.1);
1230     line = new TLine(0.0,0.0, 101.,0.0);
1231     line->Draw();
1232     TLatex *lat = u::Lat("linearity better 0.2% after correction",20., 0.15, 12, 0.06, 1); 
1233     if(lat);
1234   }
1235   if(1) {
1236     TString latexName;
1237     c->Clear();
1238     gStyle->SetOptFit(111);
1239     markerColor = 1;
1240     ifun        = -11;
1241     f = u::GetResolutionFunction("FRES2", latexName);  
1242     f->SetNpx(10000);
1243     f->SetLineColor(kBlack);
1244
1245     TGraphErrors *gr3=u::DrawGraphErrors(np, p,res.GetArray(), ep, eres.GetArray(),
1246     markerColor,21+markerColor,"AP"," resolution in %, rec.point level","E_{#gamma} "," resolution in %",
1247                                          ifun, "+", f->GetName());
1248     gr3->GetHistogram()->SetAxisRange(0.0,101.);
1249     gr3->GetHistogram()->SetMaximum(14.);
1250     gr3->GetHistogram()->SetMinimum(0.0);
1251     gr3->SetMarkerSize(1.5);
1252
1253     TLatex *lat = u::Lat(latexName.Data(),82., 11., 12, 0.06, 1);
1254     if(lat);
1255     // Exp. data
1256     TF1 *fexp = new TF1(*f);
1257     fexp->SetName("fexp");
1258     fexp->SetParameter(0, 2.168);
1259     fexp->SetParameter(1, 8.818);
1260     fexp->SetLineWidth(1);
1261     fexp->SetLineColor(kRed);
1262     fexp->SetLineStyle(1);
1263     fexp->Draw("same");
1264
1265     TLegend *leg = new TLegend(0.21,0.36, 0.68,0.82);
1266     leg->AddEntry(gr3,  "MC data", "P");
1267     leg->AddEntry(f,    "fit of MC data", "L");
1268     TLegendEntry *ent3 = leg->AddEntry(fexp, "#splitline{fit of exp.data}{FNAL, Nov 2005}", "L");
1269     ent3->SetTextColor(fexp->GetLineColor());
1270     leg->Draw();
1271   }
1272   c->Update();
1273
1274   return c;
1275 }
1276
1277 TCanvas *AliEMCALRecPointsQaESDSelector::DrawKineVsRP(TList *l)
1278
1279   //Jul 25, 2007
1280   if(l==0) {
1281     printf("<W> AliEMCALRecPointsQaESDSelector::DrawKineVsRP : TList is zero ! \n");
1282     return 0;
1283   }
1284   TCanvas *c = new TCanvas("KineVsRP","KineVsRP", 20,20, 700, 500);
1285   gStyle->SetOptStat(1110);
1286   c->Divide(2,2);
1287
1288   c->cd(1);
1289   TH1F* h1 = (TH1F*)l->At(10);
1290   u::DrawHist(h1,2);
1291
1292   c->cd(2);
1293   TH1F* h2 = (TH1F*)l->At(11);
1294   u::DrawHist(h2,2);
1295
1296   c->cd(3);
1297   TH1F* h3 = (TH1F*)l->At(12);
1298   u::DrawHist(h3,2);
1299   u::DrawHist((TH1F*)l->At(14), 1,kRed,"same");
1300   u::DrawHist((TH1F*)l->At(15), 1,kGreen,"same");
1301
1302   c->cd(4);
1303   TH1F* h4 = (TH1F*)l->At(13);
1304   u::DrawHist(h4, 2);
1305   u::DrawHist((TH1F*)l->At(16), 1,kRed,"same");
1306   u::DrawHist((TH1F*)l->At(17), 1,kGreen,"same");
1307
1308   /*
1309   TH1F* h2 = (TH1F*)l->At(11);
1310   u::DrawHist(h2,2);
1311   */
1312
1313   c->Update();
1314   return c;
1315 }
1316
1317 TCanvas* AliEMCALRecPointsQaESDSelector::DrawMeanVsLog(TH2F *h2)
1318 {
1319   // h - input histogramm : mean vds log coordinates 
1320   if(h2==0) return 0;
1321
1322   TCanvas *c = new TCanvas("KineVsRP","KineVsRP", 20,20, 700, 500);
1323
1324   TH1F *hid1 = new TH1F("h1","h1 title ", h2->GetNbinsX(), 
1325   h2->GetXaxis()->GetXmin(), h2->GetXaxis()->GetXmax());  
1326
1327   gROOT->cd();
1328   TH1::AddDirectory(1);
1329   TString newName;
1330   for(int ix=1; ix<=h2->GetNbinsX();ix++) {
1331     newName = "hd_"; newName += ix;
1332     TH1D *hd = h2->ProjectionY(newName.Data(),ix,ix);
1333     if(hd->Integral()>=4.) {
1334       //      lhd->Add(hd);
1335       hid1->SetBinContent(ix, hd->GetMean());
1336       hid1->SetBinError(ix, hd->GetRMS());
1337     }
1338   }
1339   TF1 *f1 = new TF1("fcg", "0.5*TMath::SinH(x/[0])/TMath::SinH(0.5/[0])", -0.5, 0.5);
1340   f1->SetParameter(0,0.13);
1341   f1->SetLineColor(kRed);
1342   f1->SetLineWidth(1);
1343
1344   gStyle->SetOptStat(0);
1345   gStyle->SetOptFit(111);
1346   hid1->Fit(f1,"R+");
1347
1348   u::DrawHist(hid1,2);
1349
1350 //u::DrawHist(h2,2);
1351
1352   c->Update();
1353   return c;
1354 }
1355
1356 TCanvas* AliEMCALRecPointsQaESDSelector::DrawPhiEtaAnglesDistribution(const char* gn)
1357
1358   // Aug 6, 2007
1359   // Proper geometry should be defined already 
1360   // dTheta distibution has two peaks which coresponding different cells inside module ! 
1361
1362   TCanvas *c = new TCanvas("Geometry","Geometry", 20,20, 700, 500);
1363   c->Divide(2,2);
1364
1365   if(fgEmcalGeo==0) fgEmcalGeo = AliEMCALGeometry::GetInstance(gn);
1366
1367   gROOT->cd();
1368   TH1::AddDirectory(1);
1369   TH1F *hDtheta  = new TH1F("hDtheta","#Delta#theta in one SM", 60, -2.0, +1.0); // in degree
1370   TH2F *hDtheta2 = new TH2F("hDtheta2","#Delta#theta vs fIEta of cell", 48, -0.5, 47.5, 60,-2.0,+1.0);
1371
1372   TH1F *hDphi  = new TH1F("hDphi","#Delta#ph in one SM", 2000, -10.0, +10.0); // in degree
1373
1374   TVector3 vg3;
1375   AliEMCALCellInfo* t = GetCellsInfo();
1376   Double_t thetaCell=0., thetaModule=0.;
1377   Double_t phiCell=0., dphi=0.;
1378
1379   for(int absid=0; absid<12*24*4; absid++){
1380     AliEMCALCellIndexes *r = t->GetTable(absid);
1381     fgEmcalGeo->GetGlobal(absid, vg3);
1382
1383     thetaCell   = vg3.Theta()*TMath::RadToDeg();
1384     thetaModule = 90. - 1.5*r->fIEtam;
1385     hDtheta->Fill(thetaCell - thetaModule);
1386     hDtheta2->Fill(double(r->fIEta), thetaCell - thetaModule);
1387
1388     phiCell   = vg3.Phi()*TMath::RadToDeg();
1389     dphi      = phiCell - 90.;
1390     hDphi->Fill(dphi);
1391   }
1392
1393   c->cd(1);
1394   u::DrawHist(hDtheta,2);
1395   c->cd(2);
1396   u::DrawHist(hDtheta2,2);
1397   c->cd(3);
1398   u::DrawHist(hDphi,2);
1399
1400   c->Update();
1401   return c;
1402 }
1403
1404 TCanvas* AliEMCALRecPointsQaESDSelector::DrawDeffVsEnergy()
1405 {
1406   // Aug 31, 2007 - obsolete
1407   Double_t p[]={0.5, 1.0, 3., 5., 10., 20.,30.,50.,100.};
1408   Double_t ep[]={0., 0., 0., 0., 0., 0., 0., 0., 0.};
1409   // 2 pars
1410   Double_t  deff[]={9.07515, 10.0835, 11.2032, 11.4229, 12.3578, 13.0332, 13.3281, 13.7910, 14.3319};
1411   Double_t edeff[]={2.69645e-03, 3.52180e-03, 4.19236e-02, 1.21201e-01, 1.58886e-01, 3.96680e-01, 3.29985e-02, 1.17113e-01, 5.22763e-01};
1412   //
1413   Double_t w0[]={3.44679e+00, 3.82714e+00, 4.15035e+0, 4.36650e+00, 4.51511e+00, 4.65590, 4.63289e+00, 4.66568, 4.68125};
1414   Double_t ew0[]={7.58982e-01, 1.26420e-02, 2.36129e-10, 1.21201e-01, 2.12999e-01, 7.95650e-02, 6.15307e-03, 1.88803e-01, 5.18022e-05};
1415   int np=sizeof(p)/sizeof(Double_t);
1416   printf("<I> AliEMCALRecPointsQaESDSelector::DrawDeffVsEnergy() | np %i \n", np);
1417
1418   TCanvas *c = new TCanvas("Deff","Deff", 20,20, 700, 500);
1419   c->Divide(2,1);
1420
1421   Int_t markerColor=1;
1422   c->cd(1);
1423   TF1 *fdeff= new TF1("fdeff","[0]+[1]*log(x)",0.4, 100.4);
1424   if(fdeff);
1425   TGraphErrors *gr = u::DrawGraphErrors(np, p,deff, ep, edeff,
1426     markerColor,21+markerColor,"AP"," D_{eff} vs E_{#gamma} ","E_{#gamma}         "," D_{eff} in cm ",
1427                                         -1, "", 0);
1428   //                                    -1, "+", fdeff->GetName());
1429   gr->GetHistogram()->SetMaximum(15.);
1430   gPad->SetLogx(1);
1431
1432   c->cd(2);
1433   TGraphErrors *gr2 = u::DrawGraphErrors(np, p,w0, ep, ew0,
1434     markerColor,21+markerColor,"AP"," w_{0} vs E_{#gamma} ","E_{#gamma}         "," w_{0}    ",
1435     -1, "", 0);
1436
1437   gr2->GetHistogram()->SetMaximum(5.);
1438   gPad->SetLogx(1); 
1439
1440   c->Update();
1441   return c;
1442 }
1443
1444 TCanvas* AliEMCALRecPointsQaESDSelector::DrawDeffVsEnergy2(const char *opt)
1445 {
1446   // Aug 28, 2008 - read pars and pars errors from files
1447   Double_t p[]={0.5, 1.0, 3., 5., 10., 20.,30.,50.,100.};
1448   Double_t ep[]={0., 0., 0., 0., 0., 0., 0., 0., 0.};
1449   // 2 pars
1450   Double_t deff[9], edeff[9], w0[9], ew0[9]; // max size now 
1451   TString sopt(opt);
1452
1453   int np = sizeof(p)/sizeof(Double_t);
1454   printf("<I> AliEMCALRecPointsQaESDSelector::DrawDeffVsEnergy2() | np %i \n", np);
1455   ReadParsDeffAndW0("/data/r22b/ALICE/CALIB/FIT/", deff, edeff, w0, ew0, 1);
1456
1457   TCanvas *c = new TCanvas("Deff","Deff", 20,20, 700, 500);
1458   c->Divide(2,1);
1459
1460   TF1 *fdeff = 0, *fw0 = 0;
1461   TString optFit(""), funName("");
1462   if(sopt.Contains("fit1")) {
1463     fdeff= new TF1("fdeff","[0]+[1]*log(x)",0.1, 101.);
1464     fdeff->SetLineColor(kRed);
1465     fdeff->SetLineWidth(1);
1466
1467     /* good description - "[0]/(1.+exp([1]*x))"
1468    1  p0           4.82208e+00   9.93617e-04  -0.00000e+00   7.16648e-06
1469    2  p1          -7.79655e-01   4.07500e-03  -0.00000e+00   2.01009e-03
1470       better description - "[0]/(1.+exp([1]*(x-[2])))" (like the Woods-Saxon potential)
1471    1  p0           4.83713e+00   1.00437e-03  -6.98984e-10   4.90371e-07
1472    2  p1          -2.77970e-01   3.35587e-03  -1.79239e-09   2.67312e-07
1473    3  p2           4.41116e+00   8.72191e-02   1.82791e-04   1.55643e-05
1474      */
1475     fw0= new TF1("fw0","[0]/(1.+exp([1]*(x+[2])))",0.1, 101.);
1476     fw0->SetLineColor(kRed);
1477     fw0->SetLineWidth(1);
1478     fw0->SetParameter(0, 4.8);
1479     fw0->SetParameter(1, -2.77970e-01);
1480     fw0->SetParameter(2,  4.41116);
1481     optFit = "+";
1482   }
1483   if(fdeff) funName =  fdeff->GetName();
1484
1485   Int_t markerColor=1;
1486   c->cd(1);
1487   gStyle->SetOptFit(111);
1488   TGraphErrors *gr = u::DrawGraphErrors(np, p,deff, ep, edeff,
1489     markerColor,21+markerColor,"AP"," D_{eff} vs E_{#gamma} ","E_{#gamma}         "," D_{eff} in cm ",
1490                                         -1, optFit.Data(), funName.Data());
1491   gr->GetHistogram()->SetMaximum(15.);
1492   gPad->SetLogx(1);
1493   TLegend *leg1 = new TLegend(0.12,0.76, 0.70,0.90);
1494   TLegendEntry *le1 = leg1->AddEntry(fdeff, Form("%s",fdeff->GetTitle()), "lp");
1495   //TLegendEntry *le1 = leg1->AddEntry(fdeff, Form("%4.2f+%4.2f*log(E_{#gamma})",
1496   //fdeff->GetParameter(0),fdeff->GetParameter(1)), "lp");
1497   le1->SetTextColor(fdeff->GetLineColor());
1498   leg1->Draw();
1499
1500   c->cd(2);
1501   gStyle->SetOptFit(111);
1502   if(fw0) funName =  fw0->GetName();
1503   TGraphErrors *gr2 = u::DrawGraphErrors(np, p,w0, ep, ew0,
1504     markerColor,21+markerColor,"AP"," w_{0} vs E_{#gamma} ","E_{#gamma}         "," w_{0}    ",
1505                                         -1, optFit.Data(), funName.Data());
1506
1507   gr2->GetHistogram()->SetMaximum(5.);
1508
1509   TLegend *leg2 = new TLegend(0.17,0.6, 0.99,0.72);
1510   TLegendEntry *le2 = leg2->AddEntry(fw0, Form("%s",fw0->GetTitle()), "lp");
1511   //TLegendEntry *le2 = leg2->AddEntry(fw0, Form("#frac{%4.2f}{1.+exp(%4.2f*(x+%4.2f)}",
1512   //fw0->GetParameter(0),fw0->GetParameter(1),fw0->GetParameter(2)), "lp");
1513   le2->SetTextColor(fw0->GetLineColor());
1514   leg2->Draw();
1515   //gPad->SetLogx(1); 
1516
1517   c->Update();
1518   return c;
1519 }
1520
1521 void AliEMCALRecPointsQaESDSelector::ReadParsDeffAndW0
1522 (const char *dirName, double *deff, double *edeff, double *w0, double *ew0, const Int_t pri)
1523 {
1524   // read pars and W0
1525   int strategy = 0, itmp=0;
1526   char line[100];
1527   for(int var=11; var<=19; var++){
1528     int ind = var -11;
1529     ifstream fin;
1530     TString fname = Form("%s/fitVar%iStrategy%i.txt", dirName, var, strategy);
1531     //printf(" open file %s \n", fname.Data());
1532     fin.open(fname.Data());
1533    
1534     for(int i=1; i<=2; i++) { // skip to lines
1535       fin.getline(line,100).eof();
1536       if(pri>=2) printf("%s \n", line);
1537     }
1538
1539     fin >> itmp >> deff[ind] >> edeff[ind];
1540     fin >> itmp >> w0[ind]   >> ew0[ind];
1541     if(pri>=1) 
1542     printf(" %i def %f+/-%f : def %f+/-%f\n", ind, deff[ind],edeff[ind],w0[ind],ew0[ind]); 
1543     fin.getline(line,100).eof(); // skip last line
1544     fin.close();
1545   }
1546 }
1547
1548 TCanvas* AliEMCALRecPointsQaESDSelector::DrawSpaceResolution()
1549 {
1550   // Sep 4, 2007;
1551   // Space resolution vs optimised space resolution
1552   Double_t p[]={0.5, 1.0, 3., 5., 10., 20.,30.,50.,100.};
1553   Double_t ep[]={0., 0., 0., 0., 0., 0., 0., 0., 0.};
1554   Double_t  spAng[]={0.1877, 0.1351, 0.08144, 0.06331, 0.05384, 0.04876, 0.04706, 0.04656, 0.04726};
1555   Double_t rmsSpAng[]={0.1033, 0.07685, 0.05235, 0.03992, 0.04012, 0.04257, 0.03472, 0.02814, 0.02784};
1556   Double_t  spAngOpt[]={0.1733, 0.1311, 0.07961, 0.06401, 0.05347, 0.04618, 0.04288, 0.04, 0.03802};
1557   Double_t rmsSpAngOpt[]={0.09476, 0.07472, 0.05011, 0.04242, 0.04075, 0.04304, 0.03545, 0.02744, 0.02593};
1558
1559   int np=sizeof(p)/sizeof(Double_t);
1560   printf("<I> AliEMCALRecPointsQaESDSelector::DrawSpaceResolution() | np %i \n", np);
1561
1562   Double_t* eSpAng    = new Double_t[np];
1563   Double_t* eSpAngOpt = new Double_t[np];
1564   Double_t cc=TMath::Sqrt(8000.), cc2 = 1000.*TMath::DegToRad();
1565   for(int i=0; i<np; i++){
1566     spAng[i]       *= cc2;
1567     rmsSpAng[i]    *= cc2;
1568     spAngOpt[i]    *= cc2;
1569     rmsSpAngOpt[i] *= cc2;
1570
1571     eSpAng[i]    = spAng[i]/cc;
1572     eSpAngOpt[i] = spAngOpt[i]/cc;
1573   }
1574
1575   TCanvas *c = new TCanvas("Deff","Deff", 20,20, 700, 500);
1576   //c->Divide(2,1);
1577
1578   c->cd(1);
1579   gStyle->SetOptFit(111);
1580
1581   TGraphErrors *gr = u::DrawGraphErrors(np, p,spAng, ep, eSpAng,
1582   kBlack, 21,"AP","Angle resolution (mrad) vs E_{#gamma} ","E_{#gamma}       "," anlgle resolution (mrad) ",
1583                                         -1, "", 0);
1584   gr->GetHistogram()->SetMaximum(4.);
1585   gr->GetHistogram()->SetMinimum(0.6);
1586   gPad->SetLogx(1);
1587   gPad->SetLogy(1);
1588
1589   TF1 *fang = new TF1("fang","[0]+[1]/sqrt(x)",0.1, 101.);
1590   fang->SetLineColor(kRed);
1591   fang->SetLineWidth(1);
1592
1593   TGraphErrors *gr2 = u::DrawGraphErrors(np, p,spAngOpt, ep, eSpAngOpt,
1594   kRed,22,"P"," space vs E_{#gamma} ","E_{#gamma}         "," anlgle resolution (mrad) ",
1595                                          -1, "+", fang->GetName());
1596   TLegend *leg1 = new TLegend(0.40,0.57, 0.92,0.87);
1597   TLegendEntry *le1 = leg1->AddEntry(gr, "Initial angle resolution", "p");
1598   le1->SetTextColor(gr->GetLineColor());
1599
1600   TLegendEntry *le2 = leg1->AddEntry(gr2, "Optimized angle resolution", "p");
1601   le2->SetTextColor(gr2->GetLineColor());
1602
1603   TLegendEntry *le3 = leg1->AddEntry(fang, 
1604   Form("%3.2f+#frac{%4.2f}{#sqrt{E}}",fang->GetParameter(0),fang->GetParameter(1)), "lp");
1605   le3->SetTextColor(fang->GetLineColor());
1606
1607   leg1->Draw();
1608
1609   c->Update();
1610
1611   return c;
1612 }
1613
1614 void AliEMCALRecPointsQaESDSelector::ResetAllListOfHists()
1615 {
1616   // Reset all list of hits
1617   u::ResetListOfHists(fLofHistsPC);
1618   u::ResetListOfHists(fLofHistsRP);
1619   u::ResetListOfHists(fLKineVsRP);
1620   u::ResetListOfHists(fLShowerProfile);
1621 }
1622
1623 void AliEMCALRecPointsQaESDSelector::ReloadChain(Long64_t entry)
1624
1625   // Oct 14, 2007 - unused now
1626   if(fChain) {
1627     fChain->LoadTree(entry);
1628   }
1629 }
1630
1631 void AliEMCALRecPointsQaESDSelector::GetInitialParsForFit(const Int_t var, Double_t &deff, Double_t &w0, Double_t &phislope, const int phiCase)
1632 {
1633   //  int phiCase=0; // 0 or 1
1634   phislope = 0.001;
1635   if(var==11)         { // stay here
1636     deff = 9.07515;
1637     w0   = 3.44679;
1638   }  else if(var==12) {
1639     deff = 1.00835e+01;
1640     w0   = 3.82714e+00;
1641   }  else if(var==13) {
1642     deff = 1.12032e+01;
1643     w0   = 4.15035e+00;
1644   }  else if(var==14) {
1645     deff = 1.14229e+01;
1646     w0   = 4.36650;
1647   }  else if(var==15) {
1648     deff = 1.21361e+01; 
1649     w0   = 4.72875;
1650   }  else if(var==16) {
1651     deff = 1.28096e+01;
1652     w0   = 4.81753e+00;
1653   }  else if(var==17) {
1654     deff = 1.33281e+01; 
1655     w0   = 4.63289e+00;
1656   }  else if(var==18) {
1657     deff = 1.37910e+01; 
1658     w0   = 4.66568;
1659   }  else if(var==19) {// Aug 15, 2007
1660     switch (phiCase) {
1661     case 0: // phislope was defined than deff and w0 were fixed
1662       deff = 1.43319e+01;
1663       w0   = 4.69279;
1664       phislope = 2.41419e-04;
1665       break;
1666     case 1: // all parameters free
1667       deff = 1.46327e+01;
1668       w0   = 4.68125;
1669       phislope = 8.95559e-04;
1670       break;
1671     }
1672   } else { 
1673     printf("<E> var % i -> no definition ! \n", var);
1674     assert(0);
1675   }
1676   printf("<I> AliEMCALRecPointsQaESDSelector::GetInitialParForFit()\n deff %f w0 %f phislope %f \n", 
1677          deff,w0, phislope);
1678 }