1 #if !defined(__CINT__) || defined(__MAKECINT__)
4 #include "AliPWGHistoTools.h"
5 #include "AliPWGFunc.h"
6 #include "AliLatexTable.h"
11 #include "TDatabasePDG.h"
15 #include "THashList.h"
22 enum {kFitExpPt, kFitLevi, fFitExpMt, kFitBoltzmann, kFitBlastWave, kFitBoseEinstein, kFitFermiDirac};
24 void FitParticle(const char * file, const char * histo, const char * partName, const char * listname=0, Float_t min = 0, Float_t max =3, Float_t scaleHisto = -1., Int_t fitFunc = kFitLevi, Int_t vartype = AliPWGFunc::kdNdpt, const char * fileOut = 0, Bool_t wait = 0) {
26 // Generic Macro to fit any particle using the PWG2/SPECTRA/Fit macros
28 // You have to provide:
29 // - file: file name. If not set, uses gFile
30 // - histo: histogram name name (assumend to be in the main folder of the file)
31 // - listname: if different from 0, histo is looked in this tlist
32 // - partName: it is used to get the mass of the particle from
33 // TDatabasePDG. If you are not sure, just use a part of the name: a
34 // list of names matching it is printed on screen
36 // You can optionally provide:
37 // - min, max: the fit range
38 // - scaleHisto: a scaling factor for the histo. If negative, it is
39 // ignored. If the histo is scaled, the bin width is also
41 // - fitFunc: id of the function, levi is the default
42 // valide options: kFitExpPt, kFitLevi, fFitExpMt, kFitBoltzmann, kFitBlastWave
43 // - varType: the variable used in the pt spectrum (see AliPWGFunc.h)
45 // Author: Michele Floris, CERN
48 gSystem->Load("libTree.so");
49 gSystem->Load("libVMC.so");
50 gSystem->Load("libMinuit.so");
51 gSystem->Load("libSTEERBase.so");
52 gSystem->Load("libESD.so");
53 gSystem->Load("libAOD.so");
54 gSystem->Load("libANALYSIS.so");
55 gSystem->Load("libANALYSISalice.so");
56 gSystem->Load("libCORRFW.so");
57 gSystem->Load("libPWG2spectra.so");
61 AliPWGFunc * fm = new AliPWGFunc;
62 fm->SetVarType(AliPWGFunc::VarType_t(vartype));
63 // fm->SetVarType(AliPWGFunc::VarType_t(0));//FIXME
64 // cout << "Warning: hacked vartype" << endl;
66 if (!TDatabasePDG::Instance()->GetParticle(partName)) {
67 cout << "Wrong particle name " << partName << endl;
69 const THashList * l = TDatabasePDG::Instance()->ParticleList();
70 Int_t npart = l->GetSize();
71 for(Int_t ipart = 0; ipart < npart; ipart++){
72 TString name = l->At(ipart)->GetName();
73 if(name.Contains(partName, TString::kIgnoreCase))
74 cout << " - Did you mean [" << name.Data() << "] ?" << endl;
77 cout << "Try [ TDatabasePDG::Instance()->GetParticle(partName) ] by hand "<< endl;
81 Double_t mass = TDatabasePDG::Instance()->GetParticle(partName)->Mass();
82 cout << "Fitting ["<<partName<<"], mass: " << mass << endl;
85 AliLatexTable * table;
90 if (fitFunc == kFitLevi) {
91 func = fm->GetLevi (mass, 0.4, 20,3);
92 func->SetParLimits(1,0.0001,20000);
93 table = new AliLatexTable(9,"c|cccccccc");
94 table->InsertCustomRow("Part & Func & Yield & FD Slope & $\\Chi^2$/NDF & Min X & Fit Min & Fit Max & Frac Below ");
98 if (fitFunc == kFitExpPt) {
99 func = fm->GetPTExp(0.2, 20);
100 table = new AliLatexTable(9,"c|cccccccc");
101 table->InsertCustomRow("Part & Func & Yield & pT Slope & $\\Chi^2$/NDF & Min X & Fit Min & Fit Max & Frac Below ");
105 if (fitFunc == fFitExpMt) {
106 func = fm->GetMTExp(mass,0.2, 20);
107 table = new AliLatexTable(9,"c|cccccccc");
108 table->InsertCustomRow("Part & Func & Yield & mT Slope & $\\Chi^2$/NDF & Min X & Fit Min & Fit Max & Frac Below ");
112 if (fitFunc == kFitBoltzmann) {
113 func = fm->GetBoltzmann(mass, 0.2, 20);
114 table = new AliLatexTable(9,"c|cccccccc");
115 table->InsertCustomRow("Part & Func & Yield & Bz Slope & $\\Chi^2$/NDF & Min X & Fit Min & Fit Max & Frac Below ");
120 if (fitFunc == kFitBlastWave) {
121 func = fm->GetBGBW(mass,0.6,0.3, 1, 1e5);// beta, T, n, norm
122 table = new AliLatexTable(11,"cc|ccccccccccc");
123 table->InsertCustomRow("Part & Func & Yield & T & beta & n & $\\Chi^2$/NDF & Min X & Fit Min & Fit Max & Frac Below ");
124 func->SetParLimits(1, 0.1, 0.99);
125 func->SetParLimits(2, 0.01, 1);
126 func->SetParLimits(3, 0.01, 2);
130 if (fitFunc == kFitBoseEinstein) {
131 func = fm->GetBoseEinstein(mass,0.3,20);
132 table = new AliLatexTable(9,"c|cccccccc");
133 table->InsertCustomRow("Part & Func & Yield & BE Slope & $\\Chi^2$/NDF & Min X & Fit Min & Fit Max & Frac Below ");
137 if (fitFunc == kFitFermiDirac) {
138 func = fm->GetFermiDirac(mass,0.3,20);
139 table = new AliLatexTable(9,"c|cccccccc");
140 table->InsertCustomRow("Part & Func & Yield & FD Slope & $\\Chi^2$/NDF & Min X & Fit Min & Fit Max & Frac Below ");
146 TFile * f = file ? new TFile(file) : gFile;
149 TList * l = (TList*) gDirectory->Get(listname);
150 h = (TH1*) l->FindObject(histo);
153 h = (TH1*) gDirectory->Get(histo); //
156 if (scaleHisto > 0) h->Scale(scaleHisto, "width");
157 // TH1 * h = AliPWGHistoTools::GetdNdPtFromOneOverPt((TH1*) gDirectory->Get(histo)); // FIXME
158 // cout << "WARNING SCALING2PI" << endl;
159 // h->Scale(2*TMath::Pi());//Fixme
161 h->Fit(func); // FIXME
162 gMinuit->Command("SET STRATEGY 2"); // FIXME
164 if (!AliPWGHistoTools::Fit(h,func,min,max)) {
165 cout << "Fitting error!" << endl;
168 cout << "Drawing" << endl;
170 TCanvas * c = new TCanvas();
179 // Print results nicely
182 Double_t yield=0,yieldE=0;
184 AliPWGHistoTools::GetYield(h,func,yield,yieldE);
185 cout << "YE" << endl;
186 TLatex * l = new TLatex(2,(h->GetMaximum()+h->GetMinimum())/2,Form("%3.3f #pm %3.3f (%s)", yield,yieldE, func->GetName()));
189 if(wait) c->WaitPrimitive();
191 TFile * fout = new TFile(fileOut, "update");
192 c->SetName(Form("c_%s_%s_fit_%2.2f_%2.2f",histo, func->GetName(), min, max));
194 fout->Purge(); // remove old canvases
198 // Float_t yield = func->Integral(0.45,1.05);
199 // Float_t yieldE = func->IntegralError(0.45,1.05);
200 cout << "Slope Par: "<< slopePar << endl;
202 Double_t tslope = func->GetParameter(slopePar);
203 Double_t tslopeE = func->GetParError(slopePar);
205 table->SetNextCol(Form("%s (%s)", partName, h->GetName()));
206 table->SetNextCol(func->GetName());
207 table->SetNextCol(yield,yieldE,-4);
208 table->SetNextCol(tslope,tslopeE,-4);
209 if(fitFunc == kFitBlastWave) {
210 table->SetNextCol(func->GetParameter(1),func->GetParError(1),-4);
211 table->SetNextCol(func->GetParameter(3),func->GetParError(3),-4);
213 // table->SetNextCol(func->GetParameter(1),func->GetParError(1),-4);
214 table->SetNextCol(Form("%2.2f/%d",func->GetChisquare(),func->GetNDF()));
215 Float_t lowestPoint = TMath::Max(AliPWGHistoTools::GetLowestNotEmptyBinEdge(h),min);
216 // Float_t yieldAbove = func->Integral(lowestPoint,100);
217 Float_t yieldBelow = func->Integral(0,lowestPoint);
218 table->SetNextCol(lowestPoint,-3);
219 table->SetNextCol(min,-2);
220 table->SetNextCol(max,-2);
221 table->SetNextCol(yieldBelow/yield,-3);
223 // Float_t mean=0, meane=0;
224 // Float_t mean2=0, mean2e=0;
225 // AliPWGHistoTools::GetMean (func, mean, meane , 0.,100., normPar);
226 // AliPWGHistoTools::GetMeanSquare(func, mean2, mean2e, 0.,100., normPar);
227 // table->SetNextCol(mean, meane ,-4);
228 // table->SetNextCol(mean2, mean2e,-4);
229 // fMean2->IntegralError(0,100)/func->Integral(0,100),-7);
231 table->PrintTable("ASCII");