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