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