File indexing completed on 2025-08-03 08:13:10
0001
0002 #include <TChain.h>
0003 #include <TCanvas.h>
0004 #include <TH1.h>
0005 #include <TH1F.h>
0006 #include <TH2D.h>
0007 #include <TF1.h>
0008 #include <TFile.h>
0009 #include <TGraph.h>
0010 #include <TStyle.h>
0011 #include <TROOT.h>
0012 #include <TLegend.h>
0013 #include <TLine.h>
0014 #include <TLatex.h>
0015 #include <TRandom1.h>
0016 #include <TPolyLine.h>
0017 #include <TColor.h>
0018 #include <iostream>
0019 #include <map>
0020 #include <fstream>
0021 #include <TMath.h>
0022 #include <TLorentzVector.h>
0023 #include <TEfficiency.h>
0024 #include <TGraphAsymmErrors.h>
0025 #include <string.h>
0026 #include <list>
0027
0028
0029 using namespace std;
0030
0031
0032
0033 void cluster_resolution()
0034 {
0035
0036 gROOT->SetStyle("Plain");
0037 gStyle->SetOptStat(0);
0038 gStyle->SetOptFit(0);
0039 gStyle->SetOptTitle(1);
0040 gStyle->SetStatW(0.3);
0041 gStyle->SetStatH(0.3);
0042
0043 bool verbose = false;
0044 int embed_flag = 2;
0045
0046
0047
0048
0049
0050 int n_maps_layers = 3;
0051 int n_intt_layers = 6;
0052
0053 int n_tpc_layers_inner = 16;
0054 int n_tpc_layers_mid = 16;
0055 int n_tpc_layers_outer = 16;
0056 int n_tpc_layers = n_tpc_layers_inner + n_tpc_layers_mid + n_tpc_layers_outer;;
0057
0058 int nlayers = n_maps_layers+n_intt_layers+n_tpc_layers;
0059
0060 double ptmax = 35.0;
0061
0062 int a = 0;
0063 int b = 0;
0064 int c = 0;
0065
0066
0067
0068
0069 cout << "Reading ntuple " << endl;
0070
0071 TH2D *rphi = new TH2D("rphi","Cluster map",2000, -79.0, 79.0, 2000, -79.0, 79.0);
0072 rphi->GetYaxis()->SetTitle("Y (cm)");
0073 rphi->GetXaxis()->SetTitle("X (cm)");
0074
0075 TH2D *zphi = new TH2D("zphi","Cluster z-phi map",120, -120.0, 120.0, 500, -2.0, 5.0);
0076 zphi->GetYaxis()->SetTitle("#phi");
0077 zphi->GetXaxis()->SetTitle("Z (cm)");
0078
0079 TH2D *delta_rphi = new TH2D("delta_rphi","cluster r#phi errors by layer",60.0, 0.0, 60.0, 2000, -0.1, 0.1);
0080 delta_rphi->GetYaxis()->SetTitle("Cluster r#phi Error (cm)");
0081 delta_rphi->GetXaxis()->SetTitle("Tracking Layer");
0082
0083 TH2D *delta_phi = new TH2D("delta_phi","cluster #phi errors by layer",60.0, 0.0, 60.0, 2000, -0.002, 0.002);
0084 delta_phi->GetYaxis()->SetTitle("Cluster #phi Error (rad)");
0085 delta_phi->GetXaxis()->SetTitle("Tracking Layer");
0086
0087 TH2D *delta_phi_gphi = new TH2D("delta_phi_gphi","cluster #phi errors by gphi",2000.0, -0.1, 0.1, 2000, -0.002, 0.002);
0088 delta_phi_gphi->GetYaxis()->SetTitle("Cluster #phi Error (rad)");
0089 delta_phi_gphi->GetXaxis()->SetTitle("Truth #phi");
0090
0091 TH2D *delta_z = new TH2D("delta_z","cluster Z errors by layer",60.0, 0.0, 60.0, 20000, -1.0, 1.0);
0092 delta_z->GetYaxis()->SetTitle("Cluster Z Error (cm)");
0093 delta_z->GetXaxis()->SetTitle("Tracking Layer");
0094
0095 TH2D *cluster_size = new TH2D("cluster_size","cluster size by layer",60.0, 0.0, 60.0, 200, 0.0, 15.0);
0096 cluster_size->GetYaxis()->SetTitle("Cluster Size (hits)");
0097 cluster_size->GetXaxis()->SetTitle("Tracking Layer");
0098
0099 TH2D *clusters_layer = new TH2D("clusters_layer","cluster eta by layer",50.0, 0.0, 50.0, 200, -3.0, 3.0);
0100 clusters_layer->GetYaxis()->SetTitle("Cluster eta");
0101 clusters_layer->GetXaxis()->SetTitle("Tracking Layer");
0102
0103 TH2D *hzsize = new TH2D("hzsize","cluster Z size vs nparticles",100, 0.0, 6.0, 200, 0.0, 7.0);
0104 hzsize->GetXaxis()->SetTitle("Cluster Z Size (cm)");
0105 hzsize->GetYaxis()->SetTitle("nparticles");
0106
0107 int pick_layer = 7;
0108
0109 double nclusters = 0;
0110
0111
0112 for(int i=0;i <100; i++)
0113 {
0114
0115 TChain *ntp_vertex = new TChain("ntp_vertex","clusters");
0116 TChain *ntp_cluster = new TChain("ntp_cluster","clusters");
0117 TChain *ntp_gtrack = new TChain("ntp_gtrack","clusters");
0118 TChain *ntp_track = new TChain("ntp_track","clusters");
0119 TChain *ntp_g4hit = new TChain("ntp_g4hit","clusters");
0120
0121 char name[500];
0122
0123
0124
0125 sprintf(name,"/sphenix/user/frawley/cluster_efficiency/macros/macros/g4simulations/screwed_up_tracks_out/g4svtx_eval_%i.root_g4svtx_eval.root",i);
0126
0127
0128
0129 cout << "Enter file loop with name = " << name << endl;
0130
0131
0132 #include "ntuple_variables.C"
0133
0134
0135
0136 ntp_vertex->Add(name);
0137 int toss_event = 0;
0138 for(int cl=0;cl<ntp_vertex->GetEntries();cl++)
0139 {
0140 ntp_vertex->GetEntry(cl);
0141 if( fabs(evz-egvz) > 0.1)
0142 toss_event++;
0143 }
0144 if(toss_event > 0)
0145 {
0146 cout << " -- bad reco event vertex in one of the events, skip this file. vz = " << evz << " gvz = " << egvz << endl;
0147 delete ntp_vertex;
0148 continue;
0149 }
0150
0151
0152 ntp_cluster->Add(name);
0153
0154
0155 cout << " ntp_cluster entries = " << ntp_cluster->GetEntries() << endl;
0156
0157
0158 for(int p=0;p < ntp_cluster->GetEntries(); p++)
0159 {
0160 ntp_cluster->GetEntry(p);
0161
0162 if(cgembed != embed_flag)
0163 continue;
0164
0165 if(gprimary != 1)
0166 continue;
0167
0168 tphi = atan(gy/gx);
0169 r = sqrt(gx*gx+gy*gy);
0170
0171 double dphi = trphi - tphi;
0172 double drphi = r * dphi;
0173
0174
0175 double dz = z - gz;
0176
0177
0178 {
0179 delta_rphi->Fill( (double) layer, drphi);
0180 delta_phi->Fill( (double) layer, dphi);
0181 delta_z->Fill( (double) layer, dz);
0182 if(layer > 38) delta_phi_gphi->Fill(tphi,dphi);
0183 }
0184 }
0185
0186 delete ntp_vertex;
0187 delete ntp_cluster;
0188
0189 }
0190
0191 char label[500];
0192
0193
0194 TF1 *fg = new TF1("fg","gaus(0)",-0.05,0.05);
0195 fg->SetLineColor(kRed);
0196 fg->SetParameter(0, 100.0);
0197 fg->SetParameter(1, 0.0);
0198 fg->SetParameter(2, 2e-02);
0199
0200
0201 TCanvas *c7 = new TCanvas("c7","c7",50,50,1200,800);
0202 c7->Divide(3,1);
0203 int rebin = 1;
0204 c7->cd(1);
0205 gPad->SetLeftMargin(0.12);
0206 gPad->SetRightMargin(0.01);
0207 TH1D *hpy3 = new TH1D("hpy3","TPC inner clusters",2000,-0.10, 0.10);
0208 delta_rphi->ProjectionY("hpy3",n_maps_layers+n_intt_layers+1,n_maps_layers+n_intt_layers+n_tpc_layers_inner);
0209 hpy3->GetXaxis()->SetRangeUser(-0.04, 0.04);
0210 hpy3->GetXaxis()->SetNdivisions(506);
0211 hpy3->GetXaxis()->SetTitle("r#phi cluster error (cm)");
0212 hpy3->GetXaxis()->SetTitleOffset(1.1);
0213 hpy3->GetXaxis()->SetTitleSize(0.05);
0214 hpy3->GetXaxis()->SetLabelSize(0.06);
0215 hpy3->GetYaxis()->SetLabelSize(0.06);
0216 hpy3->Rebin(rebin);
0217 hpy3->Draw();
0218 hpy3->Fit(fg,"R");
0219
0220 double rms3 = fg->GetParameter(2) * 10000.0;
0221 double rms3_err = fg->GetParError(2) * 10000.0;
0222 sprintf(label,"RMS %.1f #pm %.1f #mu m",rms3, rms3_err);
0223 TLatex *l3 = new TLatex(0.45,0.92,label);
0224 l3->SetNDC(1);
0225 l3->Draw();
0226
0227 c7->cd(2);
0228 gPad->SetLeftMargin(0.12);
0229 gPad->SetRightMargin(0.01);
0230 TH1D *hpy4 = new TH1D("hpy4","TPC mid clusters",2000,-0.10, 0.10);
0231 delta_rphi->ProjectionY("hpy4",n_maps_layers+n_intt_layers+n_tpc_layers_inner+1,n_maps_layers+n_intt_layers+n_tpc_layers_inner+n_tpc_layers_mid);
0232 hpy4->GetXaxis()->SetRangeUser(-0.04, 04);
0233 hpy4->GetXaxis()->SetNdivisions(506);
0234 hpy4->GetXaxis()->SetTitle("r#phi cluster error (cm)");
0235 hpy4->GetXaxis()->SetTitleOffset(1.1);
0236 hpy4->GetXaxis()->SetTitleSize(0.05);
0237 hpy4->GetXaxis()->SetLabelSize(0.06);
0238 hpy4->GetYaxis()->SetLabelSize(0.06);
0239 hpy4->Rebin(rebin);
0240 hpy4->Draw();
0241 hpy4->Fit(fg,"R");
0242
0243 double rms4 = fg->GetParameter(2) * 10000.0;
0244 double rms4_err = fg->GetParError(2) * 10000.0;
0245 sprintf(label,"RMS %.1f #pm %.1f #mu m",rms4, rms4_err);
0246 TLatex *l4 = new TLatex(0.45,0.92,label);
0247 l4->SetNDC(1);
0248 l4->Draw();
0249
0250 c7->cd(3);
0251 gPad->SetLeftMargin(0.12);
0252 gPad->SetRightMargin(0.01);
0253 TH1D *hpy5 = new TH1D("hpy5","TPC outer clusters",2000,-0.10, 0.10);
0254 delta_rphi->ProjectionY("hpy5",n_maps_layers+n_intt_layers+n_tpc_layers_inner+n_tpc_layers_mid+1,n_maps_layers+n_intt_layers+n_tpc_layers_inner+n_tpc_layers_mid+n_tpc_layers_outer);
0255
0256 hpy5->GetXaxis()->SetNdivisions(506);
0257 hpy5->GetXaxis()->SetTitle("r#phi cluster error (cm)");
0258 hpy5->GetXaxis()->SetTitleOffset(1.1);
0259 hpy5->GetXaxis()->SetTitleSize(0.05);
0260 hpy5->GetXaxis()->SetLabelSize(0.06);
0261 hpy5->GetYaxis()->SetLabelSize(0.06);
0262 hpy5->Rebin(rebin);
0263 hpy5->Draw();
0264 hpy5->Fit(fg,"R");
0265
0266 double rms5 = fg->GetParameter(2) * 10000.0;
0267 double rms5_err = fg->GetParError(2) * 10000.0;
0268 sprintf(label,"RMS %.1f #pm %.1f #mu m",rms5, rms5_err);
0269 TLatex *l5 = new TLatex(0.45,0.92,label);
0270 l5->SetNDC(1);
0271 l5->Draw();
0272
0273
0274 TCanvas *c27 = new TCanvas("c27","c27",50,50,1200,800);
0275 c27->Divide(3,2);
0276
0277 c27->cd(1);
0278 gPad->SetLeftMargin(0.12);
0279 gPad->SetRightMargin(0.01);
0280 TH1D *hpz1 = new TH1D("hpz1","MVTX clusters Z",500, -1.0, 1.0);
0281 delta_z->ProjectionY("hpz1",1, n_maps_layers);
0282 hpz1->GetXaxis()->SetTitle("Z cluster error (cm)");
0283 hpz1->SetTitleOffset(0.1,"X");
0284 hpz1->GetXaxis()->SetTitleSize(0.05);
0285 hpz1->GetXaxis()->SetLabelSize(0.06);
0286 hpz1->GetYaxis()->SetLabelSize(0.06);
0287 hpz1->GetXaxis()->SetNdivisions(506);
0288 hpz1->GetXaxis()->SetTitleOffset(1.1);
0289 hpz1->GetXaxis()->SetRangeUser(-0.0016, 0.0016);
0290 hpz1->Draw();
0291 double zrms1 = 10000.0 * hpz1->GetRMS();
0292
0293 sprintf(label,"RMS %.1f #mu m",zrms1);
0294 TLatex *lz1 = new TLatex(0.55,0.92,label);
0295 lz1->SetNDC(1);
0296 lz1->Draw();
0297
0298 c27->cd(2);
0299 gPad->SetLeftMargin(0.12);
0300 gPad->SetRightMargin(0.01);
0301
0302 TH1D *hpz2 = new TH1D("hpz2","INTT clusters Z",500, -0.020, 0.020);
0303 delta_z->ProjectionY("hpz2",n_maps_layers+1,n_maps_layers+1);
0304 hpz2->GetXaxis()->SetRangeUser(-0.02, 0.02);
0305 hpz2->GetXaxis()->SetTitle("Z cluster error (cm)");
0306 hpz2->GetXaxis()->SetTitleOffset(0.6);
0307 hpz2->GetXaxis()->SetTitleSize(0.05);
0308 hpz2->GetXaxis()->SetLabelSize(0.06);
0309 hpz2->GetYaxis()->SetLabelSize(0.06);
0310 hpz2->GetXaxis()->SetNdivisions(506);
0311 hpz2->GetXaxis()->SetTitleOffset(1.1);
0312 hpz2->Draw();
0313 double zrms2 = 10000 * hpz2->GetRMS();
0314 sprintf(label,"RMS %.1f #mu m",zrms2);
0315 TLatex *lz2 = new TLatex(0.55,0.92,label);
0316 lz2->SetNDC(1);
0317 lz2->Draw();
0318
0319 c27->cd(3);
0320 gPad->SetLeftMargin(0.12);
0321 gPad->SetRightMargin(0.01);
0322 TH1D *hpz3 = new TH1D("hpz3","TPC inner clusters Z",500,-0.2, 0.2);
0323 delta_z->ProjectionY("hpz3",n_maps_layers+n_intt_layers+1, n_maps_layers+n_intt_layers+n_tpc_layers_inner);
0324 hpz3->GetXaxis()->SetNdivisions(506);
0325 hpz3->GetXaxis()->SetTitle("Z cluster error (cm)");
0326 hpz3->GetXaxis()->SetTitleOffset(1.1);
0327 hpz3->GetXaxis()->SetTitleSize(0.05);
0328 hpz3->GetXaxis()->SetLabelSize(0.06);
0329 hpz3->GetYaxis()->SetLabelSize(0.06);
0330 hpz3->GetXaxis()->SetRangeUser(-0.2, 0.2);
0331 hpz3->Draw();
0332 double zrms3 = 10000 * hpz3->GetRMS();
0333 sprintf(label,"RMS %.1f #mu m",zrms3);
0334 TLatex *lz3 = new TLatex(0.55,0.92,label);
0335 lz3->SetNDC(1);
0336 lz3->Draw();
0337
0338 c27->cd(4);
0339 gPad->SetLeftMargin(0.12);
0340 gPad->SetRightMargin(0.01);
0341 TH1D *hpz4 = new TH1D("hpz4","TPC mid clusters Z",500,-0.2, 0.2);
0342 delta_z->ProjectionY("hpz4",n_maps_layers+n_intt_layers+n_tpc_layers_inner+1, n_maps_layers+n_intt_layers+n_tpc_layers_inner+n_tpc_layers_mid);
0343 hpz4->GetXaxis()->SetNdivisions(506);
0344 hpz4->GetXaxis()->SetTitle("Z cluster error (cm)");
0345 hpz4->GetXaxis()->SetTitleOffset(1.1);
0346 hpz4->GetXaxis()->SetTitleSize(0.05);
0347 hpz4->GetXaxis()->SetLabelSize(0.06);
0348 hpz4->GetYaxis()->SetLabelSize(0.06);
0349 hpz4->GetXaxis()->SetRangeUser(-0.2, 0.2);
0350 hpz4->Draw();
0351 double zrms4 = 10000 * hpz4->GetRMS();
0352 sprintf(label,"RMS %.1f #mu m",zrms4);
0353 TLatex *lz4 = new TLatex(0.55,0.92,label);
0354 lz4->SetNDC(1);
0355 lz4->Draw();
0356
0357 c27->cd(5);
0358 gPad->SetLeftMargin(0.12);
0359 gPad->SetRightMargin(0.01);
0360 TH1D *hpz5 = new TH1D("hpz5","TPC outer clusters Z",500,-0.2, 0.2);
0361 delta_z->ProjectionY("hpz5",n_maps_layers+n_intt_layers+n_tpc_layers_inner+n_tpc_layers_mid+1, n_maps_layers+n_intt_layers+n_tpc_layers_inner+n_tpc_layers_mid+n_tpc_layers_outer);
0362 hpz5->GetXaxis()->SetNdivisions(506);
0363 hpz5->GetXaxis()->SetTitle("Z cluster error (cm)");
0364 hpz5->GetXaxis()->SetTitleOffset(1.1);
0365 hpz5->GetXaxis()->SetTitleSize(0.05);
0366 hpz5->GetXaxis()->SetLabelSize(0.06);
0367 hpz5->GetYaxis()->SetLabelSize(0.06);
0368 hpz5->GetXaxis()->SetRangeUser(-0.2, 0.2);
0369 hpz5->Draw();
0370 double zrms5 = 10000 * hpz5->GetRMS();
0371 sprintf(label,"RMS %.1f #mu m",zrms5);
0372 TLatex *lz5 = new TLatex(0.55,0.92,label);
0373 lz5->SetNDC(1);
0374 lz5->Draw();
0375
0376
0377
0378 TCanvas *c6 = new TCanvas("c6","c6",50,50,1200,800);
0379 c6->Divide(2,1);
0380 c6->cd(1);
0381 gPad->SetLeftMargin(0.12);
0382 gPad->SetRightMargin(0.01);
0383 TH1D *hpy1 = new TH1D("hpy1","MVTX clusters",2000, -0.05, 0.05);
0384 delta_rphi->ProjectionY("hpy1",1,n_maps_layers);
0385
0386
0387 hpy1->GetXaxis()->SetRangeUser(-0.002, 0.002);
0388 hpy1->GetXaxis()->SetTitle("r#phi cluster error (cm)");
0389 hpy1->SetTitleOffset(0.1,"X");
0390 hpy1->GetXaxis()->SetTitleSize(0.05);
0391 hpy1->GetXaxis()->SetLabelSize(0.06);
0392 hpy1->GetYaxis()->SetLabelSize(0.06);
0393 hpy1->GetXaxis()->SetNdivisions(506);
0394 hpy1->GetXaxis()->SetTitleOffset(1.1);
0395 hpy1->Draw();
0396 double rms1 = 10000.0 * hpy1->GetRMS();
0397 sprintf(label,"RMS %.1f #mu m",rms1);
0398 TLatex *l1 = new TLatex(0.55,0.92,label);
0399 l1->SetNDC(1);
0400 l1->Draw();
0401
0402
0403
0404 c6->cd(2);
0405 gPad->SetLeftMargin(0.12);
0406 gPad->SetRightMargin(0.01);
0407 TH1D *hpy2 = new TH1D("hpy2","INTT clusters (type 1)",2000, -0.05, 0.05);
0408 delta_rphi->ProjectionY("hpy2",n_maps_layers+2,n_maps_layers + n_intt_layers);
0409 hpy2->GetXaxis()->SetRangeUser(-0.011, 0.011);
0410 hpy2->GetXaxis()->SetTitle("r#phi cluster error (cm)");
0411 hpy2->GetXaxis()->SetTitleOffset(0.6);
0412 hpy2->GetXaxis()->SetTitleSize(0.05);
0413 hpy2->GetXaxis()->SetLabelSize(0.06);
0414 hpy2->GetYaxis()->SetLabelSize(0.06);
0415 hpy2->GetXaxis()->SetNdivisions(506);
0416 hpy2->GetXaxis()->SetTitleOffset(1.1);
0417 hpy2->Draw();
0418 double rms2 = 10000 * hpy2->GetRMS();
0419 sprintf(label,"RMS %.1f #mu m",rms2);
0420 TLatex *l2 = new TLatex(0.55,0.92,label);
0421 l2->SetNDC(1);
0422 l2->Draw();
0423
0424
0425
0426
0427
0428
0429
0430
0431
0432
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466
0467
0468
0469 }