Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackParamEtaDependence.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrackParamEtaDependence.C
1 int
2 TrackParamEtaDependence( TString csvfile="track_momres_new.csv" )
3 {
4 
5  /* Read data from input file */
6  TTree *tres = new TTree();
7  //ptrue:etatrue:psig:psig_err:pmean:pmean_err:norm
8  tres->ReadFile( csvfile, "", ',' );
9 
10  /* Print read-in tree */
11  tres->Print();
12 
13  /* create frame histograms */
14  TH1F *hframe_par1 = new TH1F("hframe_par1","",10,-4.1,4.1);
15  hframe_par1->GetXaxis()->SetTitle("#eta");
16  hframe_par1->GetYaxis()->SetTitle("Parameter 1");
17  hframe_par1->GetYaxis()->SetRangeUser(0,0.1);
18  hframe_par1->GetYaxis()->SetNdivisions(505);
19 
20  TH1F *hframe_par2 = new TH1F("hframe_par2","",10,-4.1,4.1);
21  hframe_par2->GetXaxis()->SetTitle("#eta");
22  hframe_par2->GetYaxis()->SetTitle("Parameter 2");
23  hframe_par2->GetYaxis()->SetRangeUser(0,0.01);
24  hframe_par2->GetYaxis()->SetNdivisions(505);
25 
26  /* Parameter 1 */
27  TCanvas *c1 = new TCanvas();
28  tres->Draw("par1:eta:par1err:0");
29 
30  /* Create TGraphErrors with selected data from tree */
31  TGraphErrors *gpar1 = new TGraphErrors( tres->GetEntries(),
32  &(tres->GetV2())[0],
33  &(tres->GetV1())[0],
34  &(tres->GetV4())[0],
35  &(tres->GetV3())[0] );
36 
37  hframe_par1->Draw();
38  gpar1->Draw("Psame");
39 
40  TF1* fpar1 = new TF1("fpar1", "[0] + [1] * x**2 + [2] * x**4");
41  fpar1->SetLineColor(kBlue);
42  gpar1->Fit(fpar1, "", "", -2.5, 2.5);
43  gpar1->Fit(fpar1, "", "", -2.5, 2.5);
44  gpar1->Fit(fpar1, "", "", -2.5, 2.5);
45 
46  c1->Print("momres_par1_fit.eps");
47 
48  /* Parameter 2 */
49  TCanvas *c2 = new TCanvas();
50  tres->Draw("par2:eta:par2err:0");
51 
52  /* Create TGraphErrors with selected data from tree */
53  TGraphErrors *gpar2 = new TGraphErrors( tres->GetEntries(),
54  &(tres->GetV2())[0],
55  &(tres->GetV1())[0],
56  &(tres->GetV4())[0],
57  &(tres->GetV3())[0] );
58 
59  hframe_par2->Draw();
60  gpar2->Draw("Psame");
61 
62  TF1* fpar2 = new TF1("fpar2", "[0] + [1] * x**2 + [2] * x**3 + [3] * x**4");
63  fpar2->SetLineColor(kBlue);
64  gpar2->Fit(fpar2, "", "", -2.5, 2.5);
65  gpar2->Fit(fpar2, "", "", -2.5, 2.5);
66  gpar2->Fit(fpar2, "", "", -2.5, 2.5);
67 
68  c2->Print("momres_par2_fit.eps");
69 
70 
71 // /* Create fit function */
72 // //TF1* f_momres = new TF1("f_momres", "[0]*x + [1]*x*x" );
73 // TF1* f_momres = new TF1("f_momres", "sqrt( [0]*[0] + [1]*[1]*x*x )" );
74 //
75 // cout << "\nFit function: " << f_momres->GetTitle() << "\n" << endl;
76 //
77 // /* Create scratch canvas */
78 // TCanvas *cscratch = new TCanvas("cscratch");
79 //
80 // /* Create framehistogram */
81 // TH1F* hframe = new TH1F("hframe","",100,0,40);
82 // hframe->GetYaxis()->SetRangeUser(0,0.15);
83 // hframe->GetXaxis()->SetTitle("Momentum (GeV/c)");
84 // hframe->GetYaxis()->SetTitle("#sigma_{p}/p");
85 //
86 // /* create combined canvas plot */
87 // TCanvas *c1 = new TCanvas();
88 // hframe->Draw();
89 //
90 // /* Create legend */
91 // TLegend* leg_eta = new TLegend( 0.25, 0.40, 0.45, 0.90);
92 //
93 // /* Create ofstream to write fit parameter results */
94 // ofstream ofsfit("track_momres_new.csv");
95 // ofsfit<<"eta,par1,par1err,par2,par2err"<<endl;
96 //
97 // /* Create resolution-vs-momentum plot with fits for each selected theta value */
98 // for ( int i = 0; i < etas.size(); i++ )
99 // {
100 // /* Switch to scratch canvas */
101 // cscratch->cd();
102 //
103 // double eta = etas.at(i);
104 //
105 // /* Calculate pseudorapidity eta */
106 // //double eta = -1 * log( tan( thetas.at(i) / 2. ) );
107 //
108 // cout << "\n***Eta = " << eta << endl;
109 //
110 // /* Define range of theta because float comparison with fixed value doesn't work
111 // too well for cuts in ROOT trees */
112 // double eta_min = eta * 0.999;
113 // double eta_max = eta * 1.001;
114 //
115 // /* Cut for tree */
116 // TCut cutx( Form("ptrue > 1 && ( (etatrue > 0 && (etatrue > %f && etatrue < %f)) || (etatrue < 0 && (etatrue < %f && etatrue > %f)) )", eta_min, eta_max, eta_min, eta_max) );
117 //
118 // /* "Draw" tree on scratch canvas to fill V1...V4 arrays */
119 // //tres->Draw("psig/pmean:ptrue:psig_err/pmean:0", cutx );
120 // tres->Draw("psig:ptrue:psig_err:0", cutx );
121 //
122 //
123 // gres->SetMarkerColor(colors[i]);
124 //
125 // /* Only plot first few lines; if not plotting, still do the fit */
126 // if ( i < etas_plotmax )
127 // {
128 // /* Add graph to legend */
129 // leg_eta->AddEntry(gres, Form("#eta = %.1f", eta), "P");
130 //
131 // /* Add graph to plot */
132 // c1->cd();
133 // gres->Draw("Psame");
134 // f_momres->SetLineColor(colors[i]);
135 // gres->Fit(f_momres);
136 // }
137 // else
138 // {
139 // gres->Fit(f_momres);
140 // }
141 //
142 // /* Write fir results to file */
143 // double par1 = f_momres->GetParameter(0);
144 // double par1err = f_momres->GetParError(0);
145 // double par2 = f_momres->GetParameter(1);
146 // double par2err = f_momres->GetParError(1);
147 // ofsfit << eta << "," << par1 << "," << par1err << "," << par2 << "," << par2err << endl;
148 //
149 // }
150 //
151 // /* Draw legend */
152 // // c1->cd();
153 // TCanvas *c2 = new TCanvas();
154 // //hframe->Draw();
155 // leg_eta->Draw();
156 //
157 // /* Print plots */
158 // c1->Print("track_momres_vareta.eps");
159 // c2->Print("track_momres_vareta_legend.eps");
160 //
161 // /* Close output stream */
162 // ofsfit.close();
163 
164  return 0;
165 }