File indexing completed on 2025-08-06 08:15:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <cmath>
0012 #include <vector>
0013 #include <TFile.h>
0014 #include <TString.h>
0015 #include <TLine.h>
0016 #include <TGraphErrors.h>
0017 #include <TLatex.h>
0018 #include <TGraphErrors.h>
0019 #include <TMultiGraph.h>
0020 #include <TLegend.h>
0021 #include <TF1.h>
0022 #include <cassert>
0023 #include <iostream>
0024 #include <fstream>
0025
0026 #include "SaveCanvas.C"
0027 #include "SetOKStyle.C"
0028 using namespace std;
0029
0030 vector<TGraphErrors *> vg_src;
0031
0032 void
0033 OnlineAnalysis(TString filename =
0034 "/phenix/u/jinhuang/links/sPHENIX_work/Prototype_2016/column3_214x.txt")
0035 {
0036 std::map<int, float> runtoz;
0037
0038 runtoz[2138] = 29.7;
0039 runtoz[2140] = 55.2;
0040 runtoz[2141] = 80.6;
0041 runtoz[2142] = 106.3;
0042 runtoz[2143] = 131.5;
0043 runtoz[2144] = 156.6;
0044 runtoz[2146] = 182.4;
0045
0046 runtoz[2171] = 142.1;
0047 runtoz[2172] = 122.0;
0048 runtoz[2174] = 102.1;
0049 runtoz[2176] = 81.9;
0050 runtoz[2177] = 61.9;
0051 runtoz[2178] = 42.1;
0052 runtoz[2179] = 21.9;
0053
0054 runtoz[2181] = 21.85;
0055 runtoz[2182] = 41.99;
0056 runtoz[2183] = 61.87;
0057 runtoz[2184] = 61.87;
0058 runtoz[2185] = 82.12;
0059 runtoz[2186] = 101.9;
0060 runtoz[2187] = 121.9;
0061 runtoz[2188] = 142.0;
0062 runtoz[2189] = 152.0;
0063 runtoz[2190] = 162.1;
0064 runtoz[2191] = 172.0;
0065 runtoz[2192] = 172.0;
0066
0067 TCanvas *c1 = new TCanvas("c1", "Vertical scan", 640, 480);
0068
0069 TLegend *leg = new TLegend(0.9122257, 0.6483516, 0.9968652, 0.9010989, NULL,
0070 "brNDC");
0071 leg->SetFillColor(0);
0072
0073 int rn;
0074 int tower;
0075 float mpv;
0076 float dmpv;
0077
0078 TGraphErrors *gr[8];
0079
0080 vector<float> v_x[8];
0081 vector<float> v_y[8];
0082 vector<float> v_dx[8];
0083 vector<float> v_dy[8];
0084
0085 ifstream sumfile;
0086 sumfile.open(filename);
0087
0088 std::string line;
0089 int linenum = 0;
0090 int index;
0091 while (sumfile >> rn >> tower >> mpv >> dmpv)
0092 {
0093 index = (tower / 8);
0094 cout << index << " " << rn << " " << runtoz[rn] << " " << mpv << " "
0095 << dmpv << endl;
0096 v_x[index].push_back(runtoz[rn]);
0097 v_dx[index].push_back(0.2);
0098 v_y[index].push_back(mpv);
0099 v_dy[index].push_back(dmpv);
0100 linenum++;
0101 }
0102
0103 TMultiGraph *mg = new TMultiGraph();
0104
0105 TString towername;
0106 int col = 1;
0107 int marker = 21;
0108 for (int i = 0; i < 8; i++)
0109 {
0110 gr[i] = new TGraphErrors(v_x[i].size(), &v_x[i][0], &v_y[i][0],
0111 &v_dx[i][0], &v_dy[i][0]);
0112 gr[i]->SetMarkerStyle(marker);
0113 gr[i]->SetMarkerSize(0.4);
0114 gr[i]->SetLineColor(col);
0115 gr[i]->SetMarkerColor(col);
0116 gr[i]->Fit("expo");
0117 gr[i]->GetFunction("expo")->SetLineColor(col);
0118
0119 vg_src.push_back((TGraphErrors *) gr[i]->Clone());
0120
0121 towername = "Tower ";
0122 towername += i;
0123 leg->AddEntry(gr[i], towername, "LP");
0124 mg->Add(gr[i]);
0125 col++;
0126 marker++;
0127 }
0128
0129 mg->Draw("AP");
0130 TString title = "Longitudinal EMCAL scan (";
0131 title += filename;
0132 title += ")";
0133 mg->SetTitle(title);
0134 mg->GetXaxis()->SetTitle("Vertical table position (mm)");
0135 mg->GetYaxis()->SetTitle("MPV of 200 GeV p (ADC counts)");
0136 leg->Draw();
0137
0138 c1->Update();
0139 c1->Modified();
0140
0141 }
0142
0143 void
0144 FitVerticalScan(const TString input =
0145
0146 "/phenix/u/jinhuang/links/sPHENIX_work/Prototype_2016/getMeanRMS_Summary.root")
0147 {
0148
0149 SetOKStyle();
0150
0151 TFile * _file0 = new TFile(input);
0152 assert(_file0->IsOpen());
0153
0154
0155 TCanvas * c2 = (TCanvas *) _file0->Get("getMeanRMS_Summary");
0156 assert(c2);
0157
0158 c2->Draw();
0159
0160 int i = 2;
0161 vg_src.push_back(
0162 (TGraphErrors *) c2->GetListOfPrimitives()->At(i++)->Clone());
0163 vg_src.push_back(
0164 (TGraphErrors *) c2->GetListOfPrimitives()->At(i++)->Clone());
0165 vg_src.push_back(
0166 (TGraphErrors *) c2->GetListOfPrimitives()->At(i++)->Clone());
0167 vg_src.push_back(
0168 (TGraphErrors *) c2->GetListOfPrimitives()->At(i++)->Clone());
0169 vg_src.push_back(
0170 (TGraphErrors *) c2->GetListOfPrimitives()->At(i++)->Clone());
0171 vg_src.push_back(
0172 (TGraphErrors *) c2->GetListOfPrimitives()->At(i++)->Clone());
0173 vg_src.push_back(
0174 (TGraphErrors *) c2->GetListOfPrimitives()->At(i++)->Clone());
0175 vg_src.push_back(
0176 (TGraphErrors *) c2->GetListOfPrimitives()->At(i++)->Clone());
0177
0178
0179
0180 TGraphErrors * g_final = new TGraphErrors((vg_src[0])->GetN());
0181 g_final->SetMarkerSize(3);
0182 g_final->SetMarkerStyle(kFullCircle);
0183 g_final->SetMarkerColor(kBlue + 3);
0184 g_final->SetFillColor(kWhite);
0185 g_final->SetLineWidth(3);
0186 g_final->SetFillStyle(0);
0187
0188
0189
0190
0191
0192
0193
0194 TF1 * f_att = new TF1("f_att", "(exp(-((13.9-x)/[0])))*[1]", 0, 20);
0195 f_att->SetParameters(105, 1);
0196
0197 f_att->SetLineColor(kBlue + 3);
0198 f_att->SetLineWidth(4);
0199
0200 const int N_rows = 8;
0201
0202 TGraphErrors * g_src = vg_src[0];
0203
0204 for (int j = 0; j < (g_src->GetN()); ++j)
0205 {
0206 assert(g_src);
0207
0208 (g_final->GetY())[j] = 0;
0209 (g_final->GetEY())[j] = 0;
0210 (g_final->GetEX())[j] = 0;
0211 (g_final->GetX())[j] = (g_src->GetX())[j] / 10 - 0.8;
0212 }
0213
0214 for (int i = 0; i < N_rows; ++i)
0215 {
0216 new TCanvas();
0217
0218 TGraphErrors * g_src = vg_src[i];
0219
0220 assert(g_src);
0221
0222
0223 g_src->DrawClone("ap*");
0224
0225 double sum = 0;
0226 for (int j = 0; j < (g_src->GetN()); ++j)
0227 {
0228 sum += (g_src->GetY())[j];
0229 }
0230 double average = sum / g_src->GetN();
0231
0232 for (int j = 0; j < (g_src->GetN()); ++j)
0233 {
0234 (g_src->GetY())[j] /= average;
0235 (g_src->GetEY())[j] /= average;
0236
0237 (g_final->GetY())[j] += (g_src->GetY())[j];
0238 (g_final->GetEY())[j] += (g_src->GetEY())[j] * (g_src->GetEY())[j];
0239 }
0240 }
0241
0242 for (int j = 0; j < (g_src->GetN()); ++j)
0243 {
0244 (g_final->GetY())[j] /= N_rows;
0245 (g_final->GetEY())[j] = sqrt((g_final->GetEY())[j]) / N_rows;
0246 }
0247
0248 TText * t;
0249 TCanvas *c1 = new TCanvas("FitVerticalScan", "FitVerticalScan", 1800, 650);
0250
0251 gPad->SetGridx(0);
0252 gPad->SetGridy(0);
0253 gPad->SetRightMargin(0.99);
0254 gPad->SetLeftMargin(0.15);
0255 gPad->SetBottomMargin(0.2);
0256
0257 TH1 * frame = gPad->DrawFrame(0, .9, 13.9, 1.1);
0258 frame->SetTitle(
0259 ";Beam position along the length of module (cm);MIP amplitude (A. U.)");
0260 frame->GetXaxis()->SetTitleOffset(1);
0261 frame->GetXaxis()->SetTitleSize(0.08);
0262 frame->GetXaxis()->SetLabelSize(0.08);
0263 frame->GetYaxis()->SetTitleOffset(.7);
0264 frame->GetYaxis()->SetTitleSize(0.08);
0265 frame->GetYaxis()->SetLabelSize(0.08);
0266 frame->GetXaxis()->CenterTitle();
0267
0268
0269 g_final->Draw("p");
0270 g_final->Fit(f_att, "MR");
0271
0272 g_final->Print();
0273
0274 TLegend *leg = new TLegend(.15, .7, .8, .9);
0275 leg->AddEntry(g_final, "Data, Averaged over 8 towers","ep");
0276 leg->AddEntry(f_att,
0277 Form("Fit, C#timesExp[ -(13.9 - x) / L_{eff} ], L_{eff} = %.0f#pm%.0f cm",
0278 f_att->GetParameter(0), f_att->GetParError(0)),"l");
0279
0280 leg->Draw();
0281
0282 TLatex latex;
0283 latex.SetTextSize(0.08);
0284 latex.SetTextAlign(12);
0285 latex.DrawLatex(0,0.92,"#leftarrow Mirror side");
0286 latex.SetTextAlign(32);
0287 latex.DrawLatex(13.9,0.92,"Lightguide side #rightarrow");
0288
0289 SaveCanvas(c1, TString(_file0->GetName()) + TString(c1->GetName()), kTRUE);
0290 }
0291