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