FairRoot/PandaRoot
dedx_bands.C
Go to the documentation of this file.
1 {
2 
3  // === CHOOSE ==========================
4  int ifile = 4;
5 
6  double mean_inf = 0.39;
7  double mean_sup = 1.23;
8  double sigma_inf = 0.39;
9  double sigma_sup = 1.23;
10 
11  // y upper limit
12  Double_t yup = 30.;
13 
14  // steps for gaussians (e canvas)
15  double nsteps = 50;
16  int cx = 5;
17  int cy = 10;
18  double limit = 100/nsteps;
19  double flimit = floor(100/nsteps);
20  if( limit != flimit){
21  nsteps = 100/flimit;
22  limit = flimit;
23  cout << "changing nsteps to " << nsteps << endl;
24  }
25 
26  TString fundedx = "[0] * (1./x)**2 + [1] * TMath::Log(x) + [2]";
27 
28 
29  // TString fundedx = "pol6(0)";
30  int npardedx = 3;
31 
32 // TString funsig = "pol4(0)";
33 // TString funsig_forsum = "pol4(3)";
34 // int nparsig = 5;
35 
36  TString funsig = "[0] * (1./x)**2 + [1] * TMath::Log(x) + [2]";
37  TString funsig_forsum = "([3] * (1./x)**2 + [4] * TMath::Log(x) + [5])";
38  int nparsig = 3;
39 
40 
41  int npartot = npardedx + nparsig;
42  // ====================================
43 
44  TCanvas *c = new TCanvas("c", "dedx_p");
45 
46  TFile infile("dedx_out.root", "READ");
47 
48  TH2F *h;
49  switch(ifile) {
50  case 0: h = (TH2F*) infile.Get("hdedx_p_e"); break;
51  case 1: h = (TH2F*) infile.Get("hdedx_p_mu"); break;
52  case 2: h = (TH2F*) infile.Get("hdedx_p_pi"); break;
53  case 3: h = (TH2F*) infile.Get("hdedx_p_k"); break;
54  case 4: h = (TH2F*) infile.Get("hdedx_p_p");
55  }
56  c->cd(); h->Draw();
57 
58  // procedure -------------------------------------------
59 
60 
61  TH1D *htemp[nsteps];
62  TF1 *fgaus[nsteps];
64  // array of mean/sigma
66 
67  // gauss
68  TCanvas *c2 = new TCanvas("c2", "slices");
69  c2->Divide(cx, cy);
70 
71  for(int i = 0; i < nsteps; i++) {
72  double stepsize = 1.5/nsteps;
73  x[i] = (i + 0.5) * stepsize;
74 
75  TString name = "htemp"; name += i;
76  TString title = "";
77  TString fname = name;
78  TString fgname = name;
79  switch(ifile) {
80  case 0: fname.Prepend("e_"); fgname.Prepend("fe_"); break;
81  case 1: fname.Prepend("mu_"); fgname.Prepend("fmu_"); break;
82  case 2: fname.Prepend("pi_"); fgname.Prepend("fpi_"); break;
83  case 3: fname.Prepend("k_"); fgname.Prepend("fk_"); break;
84  case 4: fname.Prepend("p_"); fgname.Prepend("fp_");
85  }
86  title = fname; title += "("; title += (x[i] - 0.5 * stepsize); title += ", "; title += (x[i] + 0.5 * stepsize); title += ") GeV"; title += ((i + 1) * limit - 1);
87 
88  htemp[i] = new TH1D(fname, title, 100, 0, yup);
89  h->ProjectionY(fname, limit * i, (i + 1) * limit - 1,"o");
90  c2->cd(i + 1);
91  htemp[i].Draw();
92 
93 
94  double tmpmu = htemp[i]->GetMean() ;
95  double tmpsig = htemp[i]->GetRMS();
96  double gaus_inf = tmpmu - 3 * tmpsig;
97  double gaus_sup = tmpmu + 3 * tmpsig;
98 
99  fgaus[i] = new TF1("fgname", "gaus(0)", gaus_inf, gaus_sup);
100  fgaus[i]->SetParameters(1, tmpmu, tmpsig);
101  htemp[i]->Fit("fgname", "R");
102  mean[i] = fgaus[i]->GetParameter(1);
103  sigma[i] = fgaus[i]->GetParameter(2);
104  meanerr[i] = fgaus[i]->GetParError(1);
105  sigmaerr[i] = fgaus[i]->GetParError(2);
106 }
107 
108  // GRAPHS ========================================================
109  TCanvas *graphs = new TCanvas("graphs", "graphs");
110  graphs->Divide(2, 1);
111 
112  Double_t masses[5] = {0.000510999, 0.1056584, 0.139570, 0.49368, 0.9382723 };
113 
115  for(int istep = 0; istep < nsteps; istep++) xerr[istep] = 0;
116  // ================= MEAN =================
117  TGraphErrors *g = new TGraphErrors(nsteps, x, mean, xerr, meanerr);
118  TF1 *fdedx = new TF1("fdedx", fundedx, mean_inf, mean_sup);
119  fdedx->SetParameters(1, 1, 1);
120  graphs->cd(1);
121  g->Draw("A*P");
122  g->GetYaxis()->SetRangeUser(0, 100);
123  g->Fit("fdedx", "R");
124  Double_t par[npardedx]; fdedx->GetParameters(&par[0]);
125  // =========================================
126 
127  // ================= SIGMA =================
128  for(int i = 0; i < nsteps; i++) sigma[i] = fabs(sigma[i]);
129  TGraphErrors *gs = new TGraphErrors(nsteps, x, sigma, xerr, sigmaerr);
130  TF1 *sfdedx = new TF1("sfdedx", funsig, sigma_inf, sigma_sup);
131  graphs->cd(2);
132  gs->Draw("A*P");
133  gs->GetYaxis()->SetRangeUser(0, 5);
134  gs->Fit("sfdedx", "R");
135  Double_t spar[nparsig]; sfdedx->GetParameters(&spar[0]);
136  // =========================================
137 
138  // ==== DRAW ALL ON SCATTER PLOT ===========
139  TF1 *fdedx2 = new TF1("fdedx2", fundedx, 0., 1.5);
140  fdedx2->SetParameters(par);
141  c->cd(); fdedx2->SetLineColor(kOrange); fdedx2->Draw("SAME");
142 
143  double parcomp[npartot];
144  for(int i = 0; i < npartot; i++) {
145  if(i < npardedx) parcomp[i] = par[i];
146  else parcomp[i] = spar[i - npardedx];
147  }
148  TString funsum = fundedx + " + " + funsig_forsum;
149  TF1 *fsum = new TF1("fsum", funsum, 0., 1.5);
150  fsum->SetParameters(parcomp);
151  TString fundiff = fundedx + " - " + funsig_forsum;
152  TF1 *fdiff = new TF1("fdiff", fundiff, 0., 1.5);
153  fdiff->SetParameters(parcomp);
154  c->cd();
155  fsum->Draw("SAME");
156  fdiff->Draw("SAME");
157  // =========================================
158 
159  // ==== PRINT OUTS =========================
160  cout << "ifile " << ifile << endl;
161  cout << " momentum sampled over " << nsteps << " with step width " << 1.5/nsteps << endl;
162  cout << endl;
163  cout << "MEAN DEDX PARAMETRIZATION" << endl;
164  cout << "mom limits " << mean_inf << " " << mean_sup << endl;
165  cout << "mu: "; for(int param = 0; param < npardedx; param++) cout << fdedx->GetParameter(param) << ", "; cout << endl;
166  cout << endl;
167  cout << "SIGMA DEDX PARAMETRIZATION" << endl;
168  cout << "mom limits " << sigma_inf << " " << sigma_sup << endl;
169  cout << "sig: "; for(int param = 0; param < nparsig; param++) cout << sfdedx->GetParameter(param) << ", " ; cout << endl;
170  // =========================================
171 
172 
173 }
174 
TH2F * h
Definition: dedx_bands.C:48
TString funsig_forsum
Definition: dedx_bands.C:37
TString funsum
Definition: dedx_bands.C:148
Int_t i
Definition: run_full.C:25
int npartot
Definition: dedx_bands.C:41
TFile * g
Double_t par[3]
double sigma_sup
Definition: dedx_bands.C:9
Double_t sigma[nsteps]
Definition: dedx_bands.C:65
double mean_sup
Definition: dedx_bands.C:7
TCanvas * c
Definition: dedx_bands.C:44
double nsteps
Definition: dedx_bands.C:15
TF1 * fsum
Definition: dedx_bands.C:149
TString fundiff
Definition: dedx_bands.C:151
Double_t
TString fundedx
Definition: dedx_bands.C:26
double sigma_inf
Definition: dedx_bands.C:8
int nparsig
Definition: dedx_bands.C:38
Double_t masses[5]
Definition: dedx_bands.C:112
Double_t xerr[nsteps]
Definition: dedx_bands.C:114
TCanvas * c2
Definition: dedx_bands.C:68
TF1 * fdedx2
Definition: draw_bands.C:49
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
Double_t meanerr[nsteps]
Definition: dedx_bands.C:65
Double_t x[nsteps]
Definition: dedx_bands.C:63
TString name
Double_t sigmaerr[nsteps]
Definition: dedx_bands.C:65
double mean_inf
Definition: dedx_bands.C:6
int cy
Definition: dedx_bands.C:17
TF1 * fdiff
Definition: dedx_bands.C:152
int npardedx
Definition: dedx_bands.C:30
Double_t yup
Definition: dedx_bands.C:12
int cx
Definition: dedx_bands.C:16
double flimit
Definition: dedx_bands.C:19
Double_t mean[nsteps]
Definition: dedx_bands.C:65
TString funsig
Definition: dedx_bands.C:36
double limit
Definition: dedx_bands.C:18
TFile infile("dedx_out.root","READ")
TF1 * fgaus[nsteps]
Definition: dedx_bands.C:62
TH1D * htemp[nsteps]
Definition: dedx_bands.C:61
TCanvas * graphs
Definition: dedx_bands.C:109