]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALHistoUtilities.cxx
increasing the default number of EMCal SuperModules (prep for 2011)
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALHistoUtilities.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2002, 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 // This is a set of histogram
20 // utilities for the EMCAL
21 // to make some common
22 // functions easier
23 //
24 //*-- Authors: J.L. Klay (LLNL) & Aleksei Pavlinov (WSU) 
25
26 #include "AliEMCALHistoUtilities.h"
27
28 #include <iostream>
29 #include <iomanip>
30 #include <fstream>
31
32 #include <TROOT.h>
33 #include <TPad.h>
34 #include <TFile.h>
35 #include <TH1.h>
36 #include <TH2.h>
37 #include <THnSparse.h>
38 #include <TF1.h>
39 #include <TGraph.h>
40 #include <TGraphErrors.h>
41 #include <TLatex.h>
42 #include <TChain.h>
43 #include <TList.h>
44 #include <TObjArray.h>
45 #include <TObjString.h>
46 #include <TRegexp.h>
47 #include <TString.h>
48 #include <TLorentzVector.h>
49 #include <Gtypes.h> // color, line style and so on
50 #include <TArrayF.h>
51
52 //#include "AliESDCaloCluster.h"
53 //#include "AliEMCALRecPoint.h"
54 //#include "AliRunLoader.h"
55 #include "AliHeader.h"
56 #include "AliGenEventHeader.h"
57 #include "AliGenPythiaEventHeader.h"
58
59 using namespace std;
60
61 ClassImp(AliEMCALHistoUtilities)
62
63 AliEMCALHistoUtilities::AliEMCALHistoUtilities(const char *name, const char *tit) : TNamed(name,tit)
64 {
65   // constructor
66 }
67
68 AliEMCALHistoUtilities::~AliEMCALHistoUtilities()
69 {
70         //destructor
71 }  
72
73 TList* AliEMCALHistoUtilities::MoveHistsToList(const char* name, Bool_t putToBrowser)
74 {
75   // Move HIST to list
76   gROOT->cd();
77   TIter nextHist(gDirectory->GetList());
78   TList *list = new TList;
79   list->SetName(name);
80   TObject *objHist;
81   while((objHist=nextHist())){
82     if (!objHist->InheritsFrom("TH1")) continue;
83     ((TH1*)objHist)->SetDirectory(0); // Remove from gROOT
84     list->Add(objHist);
85     gDirectory->GetList()->Remove(objHist);
86   }
87   if(putToBrowser) gROOT->GetListOfBrowsables()->Add((TObject*)list);
88   return list;
89 }
90
91 void AliEMCALHistoUtilities::FillH1(TList *l, Int_t ind, Double_t x, Double_t w, Double_t error)
92 {
93   //fill 1d histogram
94   static TH1* hid=0;
95   static int  bin=0;
96   if(l == 0) return;
97
98   if(ind>=0 && ind < l->GetSize()){
99     hid = (TH1*)l->At(ind);
100     if(error <= 0.0) { // standard way
101       hid->Fill(x,w);
102     } else{
103       bin = hid->FindBin(x);
104       hid->SetBinContent(bin,w);
105       hid->SetBinError(bin,error);
106     }
107   }
108 }
109
110 void AliEMCALHistoUtilities::FillH2(TList *l, Int_t ind, Double_t x, Double_t y, Double_t w)
111 {
112   //fill 2d histogram
113   static TH2* hid=0;
114   if(l == 0) return;
115   if(ind>=0 && ind < l->GetSize()){
116     hid = (TH2*)l->At(ind);
117     hid->Fill(x,y,w);
118   }
119 }
120
121 void AliEMCALHistoUtilities:: FillHnSparse(TList *l, Int_t ind, Double_t* x, Double_t w)
122 {
123   // Nov 02,2010: fill THnSparse hist
124   static THnSparse* hsp=0;
125   if(l==0 || x==0) return;
126   if(ind>=0 && ind < l->GetSize()){
127     hsp = dynamic_cast<THnSparse *>(l->At(ind));
128     if(hsp) hsp->Fill(x,w);
129   }
130 }
131
132 int AliEMCALHistoUtilities::SaveListOfHists(TList *mylist,const char* name,Bool_t kSingleKey,const char* opt)
133 {
134   //write histograms to file
135   printf(" Name of out file |%s|\n", name); 
136   int save = 0;
137   if(mylist && mylist->GetSize() && strlen(name)){
138     TString nf(name); 
139     if(nf.Contains(".root") == kFALSE) nf += ".root";
140     TFile file(nf.Data(),opt);
141     TIter nextHist(mylist);
142     TObject* objHist=0;
143     int nh=0;
144     if(kSingleKey) {
145        file.cd();
146        mylist->Write(mylist->GetName(),TObject::kSingleKey);
147        mylist->ls();
148        save = 1;
149     } else {
150       while((objHist=nextHist())) { // loop over list 
151         if(objHist->InheritsFrom("TH1")) {
152           TH1* hid = (TH1*)objHist;
153           file.cd();
154           hid->Write();
155           nh++;
156           printf("Save hist. %s \n",hid ->GetName());
157         }
158       }
159       printf("%i hists. save to file -> %s\n", nh,file.GetName());
160       if(nh>0) save = 1;
161     }
162     file.Close();
163   } else {
164     printf("AliEMCALHistoUtilities::SaveListOfHists : N O  S A V I N G \n");
165   }
166   return save;
167 }
168
169 void AliEMCALHistoUtilities::AddToNameAndTitle(TNamed *h, const char *name, const char *title)
170 {
171   // Oct 15, 2007
172   if(h==0) return;
173   if(name  && strlen(name))  h->SetName(Form("%s%s",h->GetName(),name));
174   if(title && strlen(title)) h->SetTitle(Form("%s%s",h->GetTitle(),title));
175 }
176
177 void AliEMCALHistoUtilities::AddToNameAndTitleToList(TList *l, const char *name, const char *title)
178 {
179   // Oct 15, 2007
180   if(l==0) return;
181   if(name || title) {
182     for(int i=0; i<l->GetSize(); i++) {
183       TObject *o = l->At(i);
184       if(o->InheritsFrom("TNamed")) {
185         TNamed *h = dynamic_cast<TNamed *>(o);
186         AddToNameAndTitle(h, name, title);
187       }
188     }
189   }
190 }
191
192 void AliEMCALHistoUtilities::ResetListOfHists(TList *l)
193 {
194   // Oct 15, 2007
195   if(l==0) return;
196   for(int i=0; i<l->GetSize(); i++) {
197     TH1F* h = (TH1F*)l->At(i);
198     h->Reset(); 
199   }
200 }
201
202 TLatex *AliEMCALHistoUtilities::Lat(const char *text, Float_t x,Float_t y, Int_t align, Float_t tsize, short tcolor)
203
204   // Oct 15, 2007
205   double y1=y;
206   TLatex *latex = new TLatex;
207   latex->SetTextAlign(align);
208   latex->SetTextSize(tsize);
209   latex->SetTextColor(tcolor);
210   latex->DrawLatex(x, y1, text);
211   printf("<I> AliEMCALHistoUtilities::lat() -> %s gPad->GetLogy() %i\n", 
212   text, gPad->GetLogy());
213   return latex;
214 }
215
216 TGraph *AliEMCALHistoUtilities::DrawGraph(Int_t n, Double_t *x, Double_t *y, Int_t markerColor, 
217 Int_t markerStyle, const char* opt, const char* tit, const char* xTit,const char* yTit, Int_t ifun,  
218 const char *optFit, const char *fun)
219 {
220   /* Drawing options 
221   chopt='L' :  A simple polyline between every points is drawn
222   chopt='F' :  A fill area is drawn ('CF' draw a smooth fill area)
223   chopt='A' :  Axis are drawn around the graph
224   chopt='C' :  A smooth Curve is drawn
225   chopt='*' :  A Star is plotted at each point
226   chopt='P' :  Idem with the current marker
227   chopt='B' :  A Bar chart is drawn at each point
228   chopt='1' :  ylow=rwymin
229   chopt='X+' : The X-axis is drawn on the top side of the plot.
230   chopt='Y+' : The Y-axis is drawn on the right side of the plot.
231
232     Fitting options
233    The list of fit options is given in parameter option.
234       option = "W"  Set all errors to 1
235              = "U" Use a User specified fitting algorithm (via SetFCN)
236              = "Q" Quiet mode (minimum printing)
237              = "V" Verbose mode (default is between Q and V)
238              = "B" Use this option when you want to fix one or more parameters
239                    and the fitting function is like "gaus","expo","poln","landau".
240              = "R" Use the Range specified in the function range
241              = "N" Do not store the graphics function, do not draw
242              = "0" Do not plot the result of the fit. By default the fitted function
243                    is drawn unless the option"N" above is specified.
244              = "+" Add this new fitted function to the list of fitted functions
245                    (by default, any previous function is deleted)
246              = "C" In case of linear fitting, not calculate the chisquare
247                     (saves time)
248              = "F" If fitting a polN, switch to minuit fitter
249              = "ROB" In case of linear fitting, compute the LTS regression
250                      coefficients (robust(resistant) regression), using
251                      the default fraction of good points
252                "ROB=0.x" - compute the LTS regression coefficients, using
253                            0.x as a fraction of good points
254
255   */
256   printf("AliEMCALHistoUtilities::drawGraph started \n");
257   printf("Drawing opt |%s| : Fitting opt |%s|\n", opt, optFit);
258
259     TGraph *gr = new TGraph(n, x, y);
260     gr->SetMarkerColor(markerColor);
261     gr->SetLineColor(markerColor);
262     gr->SetMarkerStyle(markerStyle);
263     gr->SetTitle(tit);
264     gr->Draw(opt);
265
266     TString ctmp(opt);
267     if(ctmp.Contains("A")) {
268        gr->GetHistogram()->SetXTitle(xTit);
269        gr->GetHistogram()->SetYTitle(yTit);
270     }
271     ctmp = optFit; 
272     if(ifun>=0) {
273       TString sf("pol"); sf += ifun;
274       gr->Fit(sf.Data(),optFit);
275       printf("\n ** Fit by Polynomial of degree %i : %s **\n", ifun, sf.Data());
276     } else if(!ctmp.Contains("no",TString::kIgnoreCase)){
277       printf("\n ** ifun %i : %s **\n", ifun, fun);
278       gr->Fit(fun, optFit);
279     }
280
281     return gr;
282 }
283
284 TGraphErrors *AliEMCALHistoUtilities::DrawGraphErrors(const Int_t n,Double_t *x,Double_t *y,Double_t *ex, 
285 Double_t *ey, Int_t markerColor,  Int_t markerStyle, const char* opt, const char* tit, 
286 const char* xTit,const char* yTit, Int_t ifun, const char *optFit, const char *fun)
287 {
288   // Oct 15, 2007
289   printf("AliEMCALHistoUtilities::drawGraphErrors started \n");
290   printf("Drawing opt |%s| : ifun %i: Fitting opt |%s|, fun |%s|\n", 
291          opt, ifun, optFit, fun);
292
293   TGraphErrors *gr = new TGraphErrors(n, x,y,ex,ey);
294   gr->SetMarkerColor(markerColor);
295   gr->SetLineColor(markerColor);
296   gr->SetMarkerStyle(markerStyle);
297   if(tit&&strlen(tit)>0) gr->SetTitle(tit);
298
299   TString ctmp(opt);
300   if(ctmp.Contains("A")) {
301      gr->GetHistogram()->SetXTitle(xTit);
302      gr->GetHistogram()->SetYTitle(yTit);
303   }
304   if(ifun>0) {
305     if(ifun != 999) {
306       TString sf("pol"); sf += ifun;
307       gr->Fit(sf.Data(),optFit);
308       printf("\n ** Fit by Polynomial of degree %i : %s **\n", ifun, sf.Data());
309     } else {
310       gr->Fit(fun, optFit);
311       printf("\n ** Fit by %s **\n", fun);
312     }
313   } else {
314     if(strlen(optFit)) {
315       printf("\n ** ifun %i : %s **\n", ifun, fun);
316       gr->Fit(fun, optFit);
317     }
318   }
319
320   gr->Draw(opt);
321
322   return gr;
323 }
324
325 TF1* AliEMCALHistoUtilities::GetResolutionFunction(const char *opt, TString &latexName)
326 {
327   // Oct 15, 2007
328   TString sopt(opt);
329   sopt.ToUpper();
330   TF1 *fres=0;
331   if      (sopt.Contains("FRES1")) {
332     fres = new TF1("fres","[0]+[1]/sqrt(x)", 0.0, 101.);
333     latexName = "#frac{#sigma_{E}}{E} = A+#frac{B}{#sqrt{E}}";
334   } else if(sopt.Contains("FRES2")) { 
335     fres = new TF1("fres","sqrt([0]*[0]+[1]*[1]/x)", 0.0, 101.);
336     latexName = "#sqrt{A^{2}+#frac{B^{2}}{E}}";
337   }
338   if(fres) {
339     fres->SetParName(0,"A");
340     fres->SetParName(1,"B");
341
342     fres->SetParameter(0, 2.0);
343     fres->SetParameter(1, 6.6);
344     fres->SetLineWidth(2);
345     fres->SetLineColor(kRed);
346   }
347   return fres;
348 }
349
350 void AliEMCALHistoUtilities::InitChain(TChain *chain, const char* nameListOfFiles, Int_t nFileMax)
351 {
352   // Read name of files from text file with nameListOfFiles and added to the chain
353   if(chain==0 || nameListOfFiles==0) return;
354  
355   ifstream fin;
356   fin.open(nameListOfFiles);
357   if (!fin.is_open()) {
358     cout << "Input file "<<nameListOfFiles<<" cannot be opened.\n";
359     return;
360   }
361
362   Int_t nfiles = 0; // number of files in chain
363   char nf[200];     // name of current file
364   while (!fin.getline(nf,200).eof()) {
365     if(!fin.good()) break;
366     chain->Add(nf);
367     nfiles++;
368     cout<<nfiles<<" "<<nf<<endl;
369     if(nFileMax && nfiles>=nFileMax) break;
370   }
371   fin.close();
372   //
373   cout << " \n ********** <I> Accepted file "<< nfiles << "********* \n"<<endl;
374   //  chainEsd->Print();
375   //  chain->Lookup();
376 }
377
378 //AliRunLoader* AliEMCALHistoUtilities::InitKinematics(const Int_t nev, const char* galiceName)
379 //{
380 //  // Oct 15, 2007
381 //  // nev == 0 - new file
382 //  static AliRunLoader *rl = 0;
383 //
384 //  if((rl == 0 || nev==0) && galiceName) {
385 //    //printf("<I> AliEMCALHistoUtilities::InitKinematics() : nev %i : rl %p : %s (IN)\n", 
386 //      // nev, rl, galiceName);  
387 //    if(rl)  {
388 //      rl->UnloadgAlice();
389 //      delete rl;
390 //    }
391 //    rl = AliRunLoader::Open(galiceName,AliConfig::GetDefaultEventFolderName(),"read");
392 //    rl->LoadgAlice(); // obligatory
393 //    //printf("<I> AliEMCALHistoUtilities::InitKinematics() : nev %i : rl %p : %s (OUT)\n", 
394 //       //nev, rl, galiceName);  
395 //  }
396 //  if(rl) {
397 //    rl->GetEvent(nev);
398 //    rl->LoadKinematics();
399 //    /* Get what you need after that
400 //      rl->LoadHits();
401 //      AliStack *stack=rl->Stack();
402 //      AliESDCaloCluster * clus = esd->GetCaloCluster(n);
403 //      Int_t label = clus->GetLabel(); // what is this 
404 //      TParticle *primary=stack->Particle(label); 
405 //    */
406 //  }
407 //  return rl;
408 //}
409
410 //AliRunLoader* AliEMCALHistoUtilities::GetRunLoader(const Int_t nev, const Char_t* galiceName,
411 //                                     const Char_t* eventFolderName, AliRunLoader* rlOld)
412 //{
413 //  // Nov 26, 2007
414 //  // nev == 0 - new file
415 //  AliRunLoader *rl = 0;
416 //
417 //  if(nev==0 && galiceName) {
418 //    printf("<I> AliEMCALHistoUtilities::GetLoader() : nev %i : %s (IN)\n", 
419 //         nev, galiceName);  
420 //    if(rlOld) {
421 //      rlOld->UnloadgAlice();
422 //      delete rlOld;
423 //    }
424 //    TString folderName(eventFolderName);
425 //    if(folderName.Length() == 0) folderName = AliConfig::GetDefaultEventFolderName();
426 //    rl = AliRunLoader::Open(galiceName, folderName.Data(),"read");
427 //    rl->LoadgAlice(); // obligatory
428 //    printf("<I> AliEMCALHistoUtilities::GetLoader() : nev %i : %s : %s (OUT)\n", 
429 //         nev, galiceName, folderName.Data());  
430 //  } else {
431 //    rl = rlOld;
432 //  }
433 //  if(rl) rl->LoadgAlice(); // obligatory
434 //  // if(rl) rl->GetEvent(nev);
435 //  return rl;
436 //}
437
438 Double_t AliEMCALHistoUtilities::GetMomentum(const char* nameListOfFiles)
439 {
440   // Get momentum value from string  - like /....100GEV/.. 
441   Double_t p=-1; // negative if undefined 
442   TString st(nameListOfFiles);
443   if(st.Length()>=5) {
444     st.ToUpper();
445     Ssiz_t ind1 = st.Index("GEV"), ind2=0;
446     if(ind1>0) {
447       for(Int_t i=2; i<=10; i++) {
448         ind2 = st.Index("/",ind1-i);
449         if(ind2>0 && ind2<ind1) break;
450       }
451       TString mom  = st(ind2+1, ind1-ind2-1);
452       if(mom.IsFloat()) p = mom.Atof();
453       printf(" dir |%s| : mom |%s| : p %f : ind2,1 %i->%i\n", st.Data(), mom.Data(), p, ind2, ind1);
454     }
455   }
456   return p;
457 }
458
459 int AliEMCALHistoUtilities::ParseString(const TString &topt, TObjArray &Opt)
460
461   // Moved from AliEMCALGeometry
462   // Feb 06, 2006
463   Ssiz_t begin, index, end, end2;
464   begin = index = end = end2 = 0;
465   TRegexp separator("[^ ;,\\t\\s/]+");
466   while ( (begin < topt.Length()) && (index != kNPOS) ) {
467     // loop over given options
468     index = topt.Index(separator,&end,begin);
469     if (index >= 0 && end >= 1) {
470       TString substring(topt(index,end));
471       Opt.Add(new TObjString(substring.Data()));
472     }
473     begin += end+1;
474   }
475   return Opt.GetEntries();
476 }
477
478 // Analysis utilites
479 //Bool_t AliEMCALHistoUtilities::GetLorentzVectorFromESDCluster(TLorentzVector &v, const AliESDCaloCluster* cl)
480 //{
481 //  // May 8, 2007
482 //  static Double_t e=0.0;
483 //  static Float_t pos[3];
484 //  static TVector3 gpos;
485 //  if(cl==0) return kFALSE;
486 //  
487 //  e = Double_t(cl->E());
488 //  if(e<=0.0) {
489 //    printf(" negative cluster energy : %f \n", e);
490 //    return kFALSE;
491 //  }
492 //  cl->GetPosition(pos);
493 //  gpos.SetXYZ(Double_t(pos[0]), Double_t(pos[1]), Double_t(pos[2]));
494 //  gpos.SetMag(e);
495 //  v.SetVectM(gpos, 0.0);
496 //
497 //  return kTRUE;
498 //}
499
500 //Bool_t AliEMCALHistoUtilities::GetLorentzVectorFromRecPoint(TLorentzVector &v, const AliEMCALRecPoint  *rp)
501 //{
502 //  // Jun 20, 2007
503 //  static Double_t e=0.0;
504 //  static TVector3 gpos;
505 //  if(rp==0) return kFALSE;
506 //  
507 //  e = Double_t(rp->GetPointEnergy());
508 //  if(e<=0.0) {
509 //    printf(" negative rec.point energy : %f \n", e);
510 //    return kFALSE;
511 //  }
512 //  rp->GetGlobalPosition(gpos);
513 //  gpos.SetMag(e);
514 //  v.SetVectM(gpos, 0.0);
515 //
516 //  return kTRUE;
517 //}
518 //
519 //// Drawing:
520 //
521 void AliEMCALHistoUtilities::DrawHist(TH1* hid,int lineWidth,int lineColor,const char* opt, int lineStyle)
522 {
523   // Oct 15, 2007
524   TString sopt;
525   sopt = opt;
526   if(!hid) return;
527   printf(" Hist. %s : option |%s| \n", hid->GetName(), opt);
528   if(hid && hid->GetEntries()>=1.) {
529     if(lineWidth) hid->SetLineWidth(lineWidth);
530     if(lineColor) hid->SetLineColor(lineColor);
531     if(lineStyle) hid->SetLineStyle(lineStyle);
532     if(sopt.Contains("stat",TString::kIgnoreCase)) hid->SetStats(kTRUE);
533     hid->Draw(opt);
534   } else {
535     if   (strcmp(opt,"empty")==0) hid->Draw();
536     else printf(" has fewer entries %i or hid is zero\n", (int) hid->GetEntries());
537   }
538 }
539
540 //
541 //// Fitting:
542 //
543 TF1* AliEMCALHistoUtilities::Gausi(const char *addName,double xmi,double xma,double N,double mean,double sig,double width)
544
545   // Fit by gaus where first parameter is the number of events under ga
546   // Oct 15, 2007
547   TString name("gi");
548   name += addName;
549   TF1 *f = new TF1(name.Data(), Gi, xmi, xma, 4); 
550   f->SetParNames("INTEGRAL","MEAN","SIGMA","WIDTH");
551
552   f->SetParameter(0,N);
553   f->SetParameter(1,mean);
554   f->SetParameter(2,sig);
555
556   f->FixParameter(3,width); // width of histogramm bin
557   return f;
558 }
559
560 TF1* AliEMCALHistoUtilities::Gausi(const char *addName, double xmi, double xma, TH1 *h) 
561 {
562   // You can change parameters after that if you don't like this assumption
563   if(h) return Gausi(addName, xmi, xma, h->Integral(), h->GetMean(),h->GetRMS(), h->GetBinWidth(1));
564   else  return 0; 
565 }
566
567 TF1* AliEMCALHistoUtilities::GausiPol2(const char *addName,double xmi,double xma, TF1 *g, TF1* bg)
568
569   // Fit by gaus where first parameter is the number of events under ga
570   TString name("giPol2");
571   name += addName;
572   TF1 *f = new TF1(name.Data(), GiPol2, xmi, xma, 7); 
573   f->SetParNames("INTEGRAL","MEAN","SIGMA","WIDTH","a0","a1","a2");
574
575   if(g) {
576     for(int i=0; i<4; i++) f->SetParameter(i, g->GetParameter(i));
577     f->FixParameter(3,g->GetParameter(3));
578   }
579
580   if(bg) {
581     for(int i=4; i<7; i++) f->SetParameter(i, bg->GetParameter(i+4));
582   }
583   f->SetLineColor(kRed);
584   return f;
585 }
586
587 Double_t AliEMCALHistoUtilities::Gi(Double_t *x, Double_t *par)
588
589   // First parameter is integral (number events under gaus)
590   // Forth parameter (par[3]) is width of histogram bin 
591   // gaus(0) is a substitute for [0]*exp(-0.5*((x-[1])/[2])**2)
592
593   static Double_t c = TMath::Sqrt(2.*TMath::Pi()), y=0.0, f=0.0; // sqrt(2.*pi)
594
595   y  = (x[0]-par[1])/par[2];
596   f  = par[0]*par[3]/(par[2]*c) * TMath::Exp(-0.5*y*y);
597
598   return f;
599 }
600
601 Double_t AliEMCALHistoUtilities::GiPol2(Double_t *x, Double_t *par)
602
603   // First parameter is integral (number events under gaus)
604   // Forth parameter (par[3]) is width of histogram bin 
605   // gaus(0) is a substitute for [0]*exp(-0.5*((x-[1])/[2])**2)
606   // + pol2 -> 7 parameters
607   static Double_t c = TMath::Sqrt(2.*TMath::Pi()), y=0.0, f=0.0; // sqrt(2.*pi)
608
609   y  = (x[0]-par[1])/par[2];
610   f  = par[0]*par[3]/(par[2]*c) * TMath::Exp(-0.5*y*y);
611
612   f += par[4] + par[5]*x[0] + par[6]*x[0]*x[0];
613
614   return f;
615 }
616
617 // Calibration stuff
618 Double_t AliEMCALHistoUtilities::GetCorrectionCoefficientForGamma1(const Double_t eRec)
619 {
620   // Correction to rec.energy - Jul 15, 2007
621   // E(gamma) = corr * E(eRec);
622   /* corr = p0*(eRec-7.5)+p1*(eRec-7.5)*(eRec-7.5)+p2; 0.0<eRec<10.0
623    1  p0           6.07157e-05   1.15179e-04  -0.00000e+00   1.20997e-03
624    2  p1           1.50019e-04   3.13566e-05  -0.00000e+00   1.22531e-02
625    3  p2           9.99019e-01   4.08251e-04  -0.00000e+00   1.40606e-03
626
627      corr = p3 + p4*eRec + p5*eRec*eRec
628    1  p3           9.97135e-01   5.31970e-04   1.37962e-09   1.68120e-08
629    2  p4           3.15740e-04   2.53371e-05   1.11475e-11   1.74192e-04
630    3  p5          -1.35383e-06   2.19495e-07  -5.82864e-13   4.52277e-02
631   */
632   static Double_t p0=6.07157e-05, p1=1.50019e-04, p2=9.99019e-01;
633   static Double_t p3=9.97135e-01, p4=3.15740e-04, p5=-1.35383e-06;
634   static Double_t corr=1.0;
635   if(eRec>=0.0 && eRec <=10.0) {
636     corr = p0*(eRec-7.5) + p1*(eRec-7.5)*(eRec-7.5) + p2;
637   } else if(eRec>10.0 && eRec <=105.0) {
638     corr = p3 + p4*eRec + p5*eRec*eRec;
639   }
640   //printf(" eRec %f | corr %f \n", eRec, corr);
641   return corr;
642 }
643
644 Double_t AliEMCALHistoUtilities::GetCorrectedEnergyForGamma1(const Double_t eRec)
645 {
646   return GetCorrectionCoefficientForGamma1(eRec) * eRec;
647 }
648
649 // Trigger 
650 TList* AliEMCALHistoUtilities::GetTriggersListOfHists(const Int_t scale, const Int_t nTrig, const Bool_t toBrowser)
651 {
652   // Oct 22, 2007 - trigger technical assurance
653   gROOT->cd();
654   TH1::AddDirectory(1);
655
656   new TH1F("00_hXpos2x2", "X coord. of max Amp 2x2",100, -500., +500.);
657   new TH1F("01_hYpos2x2", "Y coord. of max Amp 2x2",100, -500., +500.);
658   new TH1F("02_hZpos2x2", "Z coord. of max Amp 2x2",100, -500., +500.);
659   new TH1F("03_hXposnxn", "X coord. of max Amp NXN",100, -500., +500.);
660   new TH1F("04_hYposnxn", "Y coord. of max Amp NXN",100, -500., +500.);
661   new TH1F("05_hZposnxn", "Z coord. of max Amp NXN",100, -500., +500.);
662   // May 7, 2008 - jet trigger
663   new TH1F("06_hJetTriggerPhi", "%phi of COG of jet trigger patch", 110, 80., 190.);
664   new TH1F("07_hJetTriggerEta", "%eta of COG of jet trigger patch", 70, -0.7, +0.7);
665   // 
666   new TH1F("08_hMaxAmp2x2", "max Amp 2x2", 1000, 0.0, pow(2.,14.));
667   new TH1F("09_hAmpOutOf2x2", "Amp out of patch 2x2", 1000, 0.0, pow(2.,14.));
668   new TH1F("10_hMaxAmpnxn", "max Amp NXN", 1000, 0.0, pow(2.,14.));
669   new TH1F("11_hAmpOutOfnxn", "Amp out of patch nxn", 1000, 0.0, pow(2.,14.));
670   // May 7, 2008 - jet trigger
671   for(Int_t i=0; i<nTrig; i++) {
672     new TH1F(Form("%2.2i_hJetPatchAmp%2.2i",i+12,i), Form("jet patch amplitude : jet trig %i",i), 
673     1000, 0.0, pow(2.,14.));
674   }
675   // For checking
676   Double_t maxEdigit=100., maxN=1000., maxPC = 200.;
677   if(scale==1) {
678     maxN  *= 10.;
679     maxPC *= 10.;
680   }
681   Int_t ind = 12+nTrig; 
682   new TH1F(Form("%2.2i_hDigitsAmp",ind++), "amplitude of digits (PC)  ", 1001, -0.5, 1000.5);
683   new TH1F(Form("%2.2i_hDigitsE",ind++), " energy of digits (PC)", 1000, 0.0, maxEdigit);
684   new TH1F(Form("%2.2i_hNDigitsInPCs",ind++), " number of digits in PC's", 1000, 0.0, maxN);
685   new TH1F(Form("%2.2i_hEinInPCs",ind++), " energy in PC's", 200, 0.0, maxPC);
686
687   return MoveHistsToList("TriggerLiOfHists", toBrowser);
688 }
689
690 void AliEMCALHistoUtilities::FillTriggersListOfHists(TList *l, TArrayF *triggerPosition, TArrayF *triggerAmplitudes)
691 {
692   // Oct 22, 2007 - trigger technical assurance
693   if(l==0) {
694     printf("<E> FillTriggersListOfHists() : list of hists undefined. \n");
695     return;
696   }
697   for(int i=0; i<triggerPosition->GetSize(); i++) {
698     FillH1(l, i, double(triggerPosition->At(i)));
699   }
700
701   for(int i=0; i<triggerAmplitudes->GetSize(); i++) {
702     FillH1(l, triggerPosition->GetSize() + i, double(triggerAmplitudes->At(i)) );
703   }
704 }
705
706 // Jet(s) kinematics 
707 TList* AliEMCALHistoUtilities::GetJetsListOfHists(Int_t njet, Bool_t toBrowser)
708 {
709   // Oct 30, 2007
710   gROOT->cd();
711   TH1::AddDirectory(1);
712   new TH1F("00_nJet", "number of jets in Pythia",5, -0.5, +4.5);
713   int ic=1;
714   for(Int_t ij=0; ij<njet; ij++)
715   {
716     new TH1F(Form("%2.2i_EtaOfJet%i",ic++,ij), Form("#eta of jet (%i)",ij),80, -2., 2.);
717     new TH1F(Form("%2.2i_ThetaOfJet%i",ic++,ij), Form("#theta(degree) of jet (%i)",ij),
718     180, 0.0, 180.);
719     new TH1F(Form("%2.2i_PhiOfJet%i",ic++,ij), Form("#phi(degree) of jet (%i)",ij),
720     180, 0.0, 360.);
721     new TH1F(Form("%2.2i_PtOfJet%i",ic++,ij), Form(" p_{T} of jet (%i)",ij),
722     200, 0.0, 200.);
723     new TH1F(Form("%2.2i_EOfJet%i",ic++,ij), Form(" E of jet (%i)",ij),
724     200, 0.0, 200.);
725   }
726
727   return MoveHistsToList("JetLiOfHists", toBrowser);
728 }
729
730 //void  AliEMCALHistoUtilities::FillJetKineListOfHists(TList *l, AliRunLoader* rl, TLorentzVector &goodJet)
731 //{
732 //  // Oct 30, 2007; Nov 07;
733 //  // goodJet - output; only one jet with EMCAL acceptance
734 //
735 //  // Bad case
736 //  goodJet.SetPxPyPzE(0., 0., 0., 0.); 
737 //
738 //  if(l==0 || rl==0) return;
739 //  //try to get trigger jet info
740 //  AliHeader* alih = rl->GetHeader();
741 //  if (alih == 0) return;
742 //
743 //  AliGenEventHeader * genh = alih->GenEventHeader();
744 //  if (genh == 0) return;
745 //
746 //  AliGenPythiaEventHeader* genhpy = dynamic_cast<AliGenPythiaEventHeader *>(genh);
747 //  if(genhpy==0) return; // Not Pythia
748 //
749 //  Int_t nj = genhpy->NTriggerJets();
750 //  FillH1(l, 0, double(nj));
751 //
752 //  TLorentzVector* jets[4];
753 //  nj = nj>4?4:nj;
754 //
755 //  int ic=1;
756 //  for (Int_t i=0; i< nj; i++) {
757 //     Float_t p[4];
758 //     genhpy->TriggerJet(i,p);
759 //     jets[i] = new TLorentzVector(p);
760 //     FillH1(l, ic++, jets[i]->Eta());
761 //     FillH1(l, ic++, jets[i]->Theta()*TMath::RadToDeg());
762 //     FillH1(l, ic++, TVector2::Phi_0_2pi(jets[i]->Phi())*TMath::RadToDeg());
763 //     FillH1(l, ic++, jets[i]->Pt());
764 //     FillH1(l, ic++, jets[i]->E());
765 //
766 //     //printf(" %i pj %f %f %f %f : ic %i\n", i, p[0], p[1], p[2], p[3], ic);
767 //     if(ic >= l->GetSize()) break;
768 //  }
769 //  if(nj==1) {
770 //    Double_t eta=jets[0]->Eta(), phi=TVector2::Phi_0_2pi(jets[0]->Phi())*TMath::RadToDeg();
771 //    if(TMath::Abs(eta)<0.5 && (phi>90.&&phi<180.)) {
772 //      goodJet = (*jets[0]);
773 //    }
774 //  }
775 //}