AliPhysics  aaf9c62 (aaf9c62)
FitEmpirical.C
Go to the documentation of this file.
1 void FitEmpirical(Bool_t update=false)
2 {
3  const char* path="$ALICE_PHYSICS_SOURCE/OADB/PWGLF/FORWARD/EMPIRICAL";
4  Int_t runNo=138190;
5  const char* which="default";
6 
7  TFile* file = TFile::Open(Form("%s/empirical_%09d.root",path,runNo),
8  (update ? "UPDATE" : "READ"));
9  if (!file) return 0;
10  Printf("File opened: %s", file->GetPath());
11 
12  TObject* obj = file->Get(Form("Forward/%s", which));
13  if (!obj) return 0;
14 
15  if (!obj->IsA()->InheritsFrom(TH1::Class())) return 0;
16 
17  TH1* h = static_cast<TH1*>(obj);
18  h->SetDirectory(0);
19  h->Draw();
20 
21  TF1* fc0 = new TF1("fc0", "pol3", -3.5, -1.7);
22  fc0->SetLineColor(kRed+1);
23  fc0->SetParNames("C10","C11","C12","C13");
24  h->Fit(fc0, "+R");
25 
26  TF1* fa0 = new TF1("fa0", "pol3", 1.7, 2.075);
27  fa0->SetLineColor(kGreen+3);
28  fa0->SetParNames("A00","A01","A02","A03","A04");
29  h->Fit(fa0, "+R");
30 
31  TF1* fa1 = new TF1("fa1", "pol2", fa0->GetXmax(), 2.3);
32  fa1->SetLineColor(kGreen+2);
33  fa1->SetParNames("A10","A11","A12","A13","A14");
34  h->Fit(fa1, "+R");
35 
36  TF1* fa2 = new TF1("fa2", "pol4", fa1->GetXmax(), 3.7);
37  fa2->SetLineColor(kGreen+1);
38  fa2->SetParNames("A20","A21","A22","A23","A24");
39  h->Fit(fa2, "+R");
40 
41  TF1* fa3 = new TF1("fa3", "pol4", fa2->GetXmax(), 5);
42  fa3->SetLineColor(kBlue+1);
43  fa3->SetParNames("A30","A31","A32","A33","A34");
44  h->Fit(fa3, "+R");
45 
46  TArrayD pars(30);
47  TObjArray names(30);
48  TString formula;
49  Int_t j = 0;
50  TF1* fs[] = { fc0, fa0, fa1, fa2, fa3, 0 };
51  TF1** fp = fs;
52  while (*fp) {
53  TF1* ft = *fp;
54  fp++;
55  // if (ft == fa1) continue;
56  Printf("Function %p: %s [%f,%f] %d", ft, ft->GetTitle(),
57  ft->GetXmin(), ft->GetXmax(), ft->GetNpar());
58  Double_t x1 = ft->GetXmin(); // if (x1 < -3) x1 = -3.5;
59  Double_t x2 = ft->GetXmax();
60  Bool_t incl = (x2 < 0) || x2 > 4.5;
61  // if (ft == fa0) { x2 = 2.3; fa0->SetRange(x1,x2); }
62  // if (ft == fa2) { x1 = 2.1; fa2->SetRange(x1,x2); }
63  const char* expr = ft->GetTitle();
64  if (!formula.IsNull()) formula.Append("+");
65  formula.Append(Form("(%5.2f<=x&&x<%s%5.2f)*%s(%2d)",
66  x1, (incl ? "=" : ""), x2, expr, j));
67  for (Int_t i = 0; i < ft->GetNpar(); i++, j++) {
68  pars[j] = ft->GetParameter(i);
69  names.AddAt(new TObjString(ft->GetParName(i)), j);
70  }
71  }
72 
73 
74  TF1* f = new TF1("param", formula.Data(), -4, 6);
75  f->SetLineColor(kGray+1);
76  for (Int_t i = 0; i < j; i++) {
77  f->SetParName(i, names.At(i)->GetName());
78  f->SetParameter(i, pars[i]);
79  }
80  // h->Fit(f,"+ME");
81  f->Draw("Same");
82  f->SetNpx(1000);
83 
84  file->cd("Forward");
85  gDirectory->ls();
86  if (update) f->Write();
87  gDirectory->ls();
88 
89 
90 }
double Double_t
Definition: External.C:58
void FitEmpirical(Bool_t update=false)
Definition: FitEmpirical.C:1
int Int_t
Definition: External.C:63
TFile * file
TList with histograms for a given trigger.
bool Bool_t
Definition: External.C:53
Definition: External.C:196