File indexing completed on 2025-08-05 08:13:04
0001
0002
0003 #include <iostream>
0004 #include <fstream>
0005 #include <vector>
0006 #include <string>
0007 #include <numeric>
0008 #include <sstream>
0009 #include <iomanip>
0010
0011 #include <TFile.h>
0012 #include <TTree.h>
0013 #include <TNtuple.h>
0014 #include <TH1.h>
0015 #include <TH2.h>
0016 #include <TF1.h>
0017 #include <TGraphErrors.h>
0018 #include <TCanvas.h>
0019 #include <TRandom3.h>
0020 #include <TVector3.h>
0021 #include <TColor.h>
0022
0023 int n_dotracking = 0;
0024
0025 using namespace std;
0026 TCanvas *c;
0027
0028 TH2F *h_dphi_nocut;
0029 TH2F *h_dphi_cut;
0030
0031 #include "least_square2.cc"
0032 #include "track_pT.hh"
0033
0034 struct cluster
0035 {
0036 int evt;
0037 uint64_t bco;
0038
0039 double x, y, z, r;
0040 double adc;
0041 double size;
0042 int layer;
0043 TVector3 pos;
0044 int ladder;
0045 int sensor;
0046 double chip_width;
0047
0048 double x_vtx;
0049 double y_vtx;
0050 double zv;
0051 double r_vtx;
0052
0053 double theta_clus;
0054 double phi_clus;
0055
0056 double dca_mean[3];
0057
0058 void set(int Evt, uint64_t Bco, double X, double Y, double Z, double Adc, double Size, int Layer, int Ladder, int Sensor)
0059 {
0060 evt = Evt;
0061 bco = Bco;
0062 x = X;
0063 y = Y;
0064 z = Z;
0065 adc = Adc;
0066 size = Size;
0067 layer = Layer;
0068 pos = TVector3(x, y, z);
0069 r = y / fabs(y) * sqrt(x * x + y * y);
0070
0071
0072
0073
0074
0075 ladder = Ladder;
0076 sensor = Sensor;
0077 if (sensor == 0 || sensor == 2)
0078 chip_width = 16 * 1e-1;
0079
0080 else if (sensor == 1 || sensor == 3)
0081 chip_width = 20 * 1e-1;
0082 }
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092 double getphi_clus()
0093 {
0094 phi_clus = atan2((y - y_vtx), (x - x_vtx));
0095
0096 return phi_clus;
0097 }
0098
0099 double gettheta_clus()
0100 {
0101
0102 theta_clus = atan2((fabs(r) - fabs(r_vtx)), (z - zv));
0103
0104 return theta_clus;
0105 }
0106 };
0107
0108 struct clustEvent
0109 {
0110 int run_nu = 0;
0111 int ievt = 0;
0112
0113 bool mag_on = false;
0114 vector<cluster> vclus;
0115 vector<truth *> vtruth;
0116 vector<track *> vtrack;
0117
0118 double dcaz_max = 9999;
0119 double dcaz_min = -9999;
0120 double dca2d_max = 9999;
0121 double dca2d_min = -9999;
0122
0123
0124 double dca_mean[3] = {0, 0, 0};
0125
0126 void clear()
0127 {
0128 for (auto itr = vtrack.begin(); itr != vtrack.end(); ++itr)
0129 {
0130 delete *itr;
0131 }
0132 vtrack.clear();
0133 }
0134
0135 void makeonetrack()
0136 {
0137 for (unsigned int i = 0; i < vtrack.size(); i++)
0138 {
0139 for (unsigned int j = i + 1; j < vtrack.size(); j++)
0140 {
0141 bool share_point = ((vtrack[i]->p1 == vtrack[j]->p1) || (vtrack[i]->p2 == vtrack[j]->p2));
0142 share_point = share_point || ((vtrack[i]->p1 == vtrack[j]->p2) || (vtrack[i]->p2 == vtrack[j]->p1));
0143 if (share_point)
0144 {
0145 if (fabs(vtrack[i]->dca_2d) > fabs(vtrack[j]->dca_2d))
0146 {
0147 vtrack[i]->is_deleted = true;
0148 continue;
0149 }
0150 else
0151 {
0152 vtrack[j]->is_deleted = true;
0153 }
0154 }
0155 }
0156 }
0157 }
0158
0159 void dca_check(bool Debug)
0160 {
0161 for (unsigned int i = 0; i < vtrack.size(); i++)
0162 {
0163 if (vtrack[i]->dca_2d > dca2d_max)
0164 vtrack[i]->dca2d_range_out = true;
0165 if (vtrack[i]->dca_2d < dca2d_min)
0166 vtrack[i]->dca2d_range_out = true;
0167
0168 if (vtrack[i]->dca[2] > dcaz_max)
0169 vtrack[i]->dcaz_range_out = true;
0170 if (vtrack[i]->dca[2] < dcaz_min)
0171 vtrack[i]->dcaz_range_out = true;
0172
0173 if (vtrack[i]->dcaz_range_out || vtrack[i]->dca2d_range_out)
0174 vtrack[i]->dca_range_out = true;
0175
0176
0177
0178
0179
0180
0181
0182
0183 }
0184 }
0185
0186 void truth_check()
0187 {
0188 for (unsigned int i = 0; i < vtruth.size(); i++)
0189 {
0190 double p = sqrt(vtruth[i]->m_truthpt * vtruth[i]->m_truthpt + vtruth[i]->m_truthpz * vtruth[i]->m_truthpz);
0191
0192 if (vtruth[i]->m_status == 1 && fabs(vtruth[i]->m_trutheta) < 2 && p > (50 * 1e-3))
0193 {
0194 if (fabs(vtruth[i]->m_truthz_out) < 23.)
0195 {
0196 vtruth[i]->is_intt = true;
0197 }
0198 }
0199 }
0200 }
0201
0202 void cluster_check()
0203 {
0204 for (unsigned int itrt = 0; itrt < vtruth.size(); itrt++)
0205 {
0206 for (unsigned int icls = 0; icls < vclus.size(); icls++)
0207 {
0208 if (vclus[icls].layer < 2)
0209 continue;
0210
0211 double d_phi = vclus[icls].getphi_clus() - vtruth[itrt]->m_truthphi;
0212 d_phi -= -2 * (M_PI * (int)(d_phi / (M_PI)));
0213
0214 if (fabs(d_phi) < (0.0014 * 3))
0215 {
0216 vtruth[itrt]->have_cluster = true;
0217 break;
0218 }
0219 }
0220 }
0221 }
0222
0223 void track_check()
0224 {
0225 for (unsigned int i = 0; i < vtruth.size(); i++)
0226 {
0227 for (unsigned int itrk = 0; itrk < vtrack.size(); itrk++)
0228 {
0229 double d_phi = vtrack[itrk]->getphi() - vtruth[i]->m_truthphi;
0230 d_phi -= -2 * (M_PI * (int)(d_phi / (M_PI)));
0231
0232 if (fabs(d_phi) < (3.3e-4 * 3))
0233 {
0234 vtruth[i]->have_track = true;
0235 break;
0236 }
0237 }
0238 }
0239 }
0240
0241 void charge_check()
0242 {
0243 for (unsigned int i = 0; i < vtruth.size(); i++)
0244 {
0245 if ((abs(vtruth[i]->m_truthpid) != 22 && abs(vtruth[i]->m_truthpid) != 2112 && abs(vtruth[i]->m_truthpid) != 130 && abs(vtruth[i]->m_truthpid) != 310 && abs(vtruth[i]->m_truthpid) != 111))
0246 vtruth[i]->is_charged = true;
0247 }
0248 }
0249
0250 void draw_intt(int mode)
0251 {
0252
0253 const double kLayer_radii[4] = {7.1888, 7.800, 9.680, 10.330};
0254 if (mode == 0)
0255 {
0256 for (int i = 0; i < 4; i++)
0257 {
0258 auto circle = new TEllipse(0.0, 0.0, kLayer_radii[i]);
0259 circle->SetLineColorAlpha(kGray, 0.5);
0260 circle->SetLineWidth(2);
0261 circle->SetFillStyle(0);
0262 circle->Draw("same");
0263 }
0264 }
0265 else if (mode == 1)
0266 {
0267 for (int j = 0; j < 2; j++)
0268 {
0269 for (int i = 0; i < 4; i++)
0270 {
0271 TLine *line = new TLine(-23., (2 * j - 1) * kLayer_radii[i], 23., (2 * j - 1) * kLayer_radii[i]);
0272 line->SetLineColorAlpha(kGray, 0.5);
0273 line->SetLineWidth(2);
0274 line->Draw("same");
0275 }
0276 }
0277 }
0278 }
0279
0280 void draw_frame(int mode = 0)
0281 {
0282 TH1 *flame;
0283 string mag;
0284 if (mag_on)
0285 mag = "B-on";
0286 else
0287 mag = "B-off";
0288
0289 string title;
0290
0291 if (mode == 0)
0292 {
0293 if (run_nu == 1)
0294 title = Form("x-y plane {MC(%s) event %d};x[cm];y[cm]", mag.c_str(), ievt);
0295 else
0296 title = Form("x-y plane {run%d(%s) event %d};x[cm];y[cm]", run_nu, mag.c_str(), ievt);
0297 flame = gPad->DrawFrame(-15, -15, 15, 15, title.c_str());
0298 }
0299 else if (mode == 1)
0300 {
0301 if (run_nu == 1)
0302 title = Form("z-r plane {MC(%s) event %d};z[cm];r[cm]", mag.c_str(), ievt);
0303 else
0304 title = Form("z-r plane {run%d(%s) event %d};z[cm];r[cm]", run_nu, mag.c_str(), ievt);
0305 flame = gPad->DrawFrame(-25, -15, 25, 15, title.c_str());
0306 }
0307 }
0308
0309 void draw_tracklets(int mode = 0, bool does_overlay = false, int color = kBlack, bool dca_range_cut = false, bool is_deleted = false, bool reverse = false)
0310 {
0311
0312 bool condition = !reverse;
0313 for (unsigned int i = 0; i < vtrack.size(); i++)
0314 {
0315 if (vtrack[i]->dca_range_out == condition && dca_range_cut == true)
0316 {
0317 continue;
0318 }
0319
0320 if (vtrack[i]->is_deleted == condition && is_deleted == true)
0321 {
0322 continue;
0323 }
0324
0325 TGraph *g_temp = new TGraph();
0326 g_temp->SetMarkerColor(color);
0327 g_temp->SetMarkerStyle(20);
0328 g_temp->SetMarkerSize(0.8);
0329
0330 if (mode == 0)
0331 {
0332 g_temp->SetPoint(0, vtrack[i]->p1.x(), vtrack[i]->p1.y());
0333 g_temp->SetPoint(1, vtrack[i]->p2.x(), vtrack[i]->p2.y());
0334 }
0335 else if (mode == 1)
0336 {
0337 g_temp->SetPoint(0, vtrack[i]->p1.z(), vtrack[i]->getpointr(1));
0338 g_temp->SetPoint(1, vtrack[i]->p2.z(), vtrack[i]->getpointr(2));
0339 }
0340 g_temp->Draw("PLsame");
0341 }
0342 }
0343
0344 void draw_trackline(int mode = 0, bool does_overlay = false, int color = kBlack, bool dca_range_cut = false, bool is_deleted = false, bool reverse = false)
0345 {
0346 bool condition = !reverse;
0347 vector<int> colorset = {kOrange - 3, kOrange + 3, kPink - 3, kPink + 3, kViolet - 3, kViolet + 3, kAzure - 3, kAzure + 3, kTeal - 3, kTeal + 3, kSpring - 3, kSpring + 3};
0348 int color_ = 0;
0349
0350 for (unsigned int i = 0; i < vtrack.size(); i++)
0351 {
0352
0353 if (vtrack[i]->dca_range_out == condition && dca_range_cut == true)
0354 {
0355 continue;
0356 }
0357
0358 if (vtrack[i]->is_deleted == condition && is_deleted == true)
0359 {
0360 continue;
0361 }
0362 color_ = color_ % colorset.size();
0363 TGraph *g_temp = new TGraph();
0364 g_temp->SetMarkerColor(colorset[color_]);
0365
0366 g_temp->SetMarkerStyle(20);
0367 g_temp->SetMarkerSize(0.8);
0368
0369 if (mode == 0)
0370 {
0371 vtrack[i]->track_xy->SetLineColorAlpha(colorset[color_], 0.5);
0372
0373 if (vtrack[i]->dca_mean[0] < vtrack[i]->p1.x())
0374 {
0375 vtrack[i]->track_xy->SetRange(vtrack[i]->dca_mean[0], 15);
0376 }
0377 else
0378 {
0379 vtrack[i]->track_xy->SetRange(-15, vtrack[i]->dca_mean[0]);
0380 }
0381
0382 vtrack[i]->track_xy->Draw("Lsame");
0383 g_temp->SetPoint(0, vtrack[i]->dca_mean[0], vtrack[i]->dca_mean[1]);
0384 g_temp->SetPoint(1, vtrack[i]->p1.x(), vtrack[i]->p1.y());
0385 g_temp->SetPoint(2, vtrack[i]->p2.x(), vtrack[i]->p2.y());
0386 }
0387 else if (mode == 1)
0388 {
0389
0390 if (isinf(vtrack[i]->track_rz->GetParameter(1)))
0391 {
0392 TLine *line = nullptr;
0393 if (vtrack[i]->p1.y() > 0)
0394 line = new TLine(vtrack[i]->dca_mean[2], vtrack[i]->getpointr(3), vtrack[i]->dca_mean[2], 15);
0395 else
0396 line = new TLine(vtrack[i]->dca_mean[2], -15, vtrack[i]->dca_mean[2], vtrack[i]->getpointr(3));
0397
0398 line->SetLineColorAlpha(colorset[color_], 0.5);
0399 line->SetLineWidth(2);
0400 line->Draw("same");
0401 }
0402 else
0403 {
0404
0405 vtrack[i]->track_rz->SetLineColorAlpha(colorset[color_], 0.5);
0406
0407 int y = 0;
0408 if (vtrack[i]->p1.y() > 0)
0409 y = 15;
0410 else
0411 y = -15;
0412
0413 double r1 = vtrack[i]->track_rz_inv->Eval(vtrack[i]->getpointr(3));
0414 double r2 = vtrack[i]->track_rz_inv->Eval(y);
0415
0416 if (r1 <= r2)
0417 vtrack[i]->track_rz->SetRange(r1, r2);
0418 else
0419 vtrack[i]->track_rz->SetRange(r2, r1);
0420
0421 vtrack[i]->track_rz->Draw("Lsame");
0422 }
0423 g_temp->SetPoint(0, vtrack[i]->dca_mean[2], vtrack[i]->getpointr(3));
0424 g_temp->SetPoint(1, vtrack[i]->p1.z(), vtrack[i]->getpointr(1));
0425 g_temp->SetPoint(2, vtrack[i]->p2.z(), vtrack[i]->getpointr(2));
0426 }
0427 g_temp->Draw("Psame");
0428 color_++;
0429 }
0430 }
0431
0432 double rad_deg(double Rad)
0433 {
0434 Rad = Rad / M_PI * 180;
0435 if (Rad < 0)
0436 Rad += 360;
0437
0438 return Rad;
0439 }
0440
0441 void draw_curve2(int mode, double px, double py, double pz, double rad, double cx, double cy, int color)
0442 {
0443 double sign_x = px / fabs(px);
0444 double sign_y = py / fabs(py);
0445
0446 cout << "sign_x : " << sign_x << " " << sign_y << endl;
0447 double x1 = sqrt((rad * rad) - ((sign_y * 15 - cy) * (sign_y * 15 - cy))) + cx;
0448 double x2 = -sqrt((rad * rad) - ((sign_y * 15 - cy) * (sign_y * 15 - cy))) + cx;
0449 double y1 = sqrt((rad * rad) - ((sign_x * 15 - cx) * (sign_x * 15 - cx))) + cy;
0450 double y2 = -sqrt((rad * rad) - ((sign_x * 15 - cx) * (sign_x * 15 - cx))) + cy;
0451 cout << "frame : " << sign_y * 15 << " " << sign_x * 15 << endl;
0452
0453 cout << x1 << " " << x2 << " " << y1 << " " << y2 << " " << endl;
0454
0455
0456 double cross_x1 = px * (x1 - dca_mean[0]) + py * (sign_y * 15 - dca_mean[1]);
0457 double cross_x2 = px * (x2 - dca_mean[0]) + py * (sign_y * 15 - dca_mean[1]);
0458 double cross_y1 = px * (sign_x * 15 - dca_mean[0]) + py * (y1 - dca_mean[1]);
0459 double cross_y2 = px * (sign_x * 15 - dca_mean[0]) + py * (y2 - dca_mean[1]);
0460
0461 cout << "cross : " << cross_x1 << " " << cross_x2 << " " << cross_y1 << " " << cross_y2 << " " << endl;
0462 double temp_x, temp_y;
0463
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474 if (-15 <= x1 && x1 <= 15)
0475 temp_x = x1;
0476 if (-15 <= x2 && x2 <= 15)
0477 temp_x = x2;
0478 if (-15 <= y1 && y1 <= 15)
0479 temp_y = y1;
0480 if (-15 <= y2 && y2 <= 15)
0481 temp_y = y2;
0482
0483 double temp_phix = atan2(sign_y * 15 - cy, temp_x - cx);
0484 double temp_phiy = atan2(temp_y - cy, sign_x * 15 - cx);
0485
0486 temp_phix = rad_deg(temp_phix);
0487 temp_phiy = rad_deg(temp_phiy);
0488
0489 double phi_min, phi_max;
0490 double phic = atan2(0 - cy, 0 - cx);
0491 phic = rad_deg(phic);
0492 double temp_phi;
0493
0494 bool nan_x = ((rad) * (rad) - (sign_x * 15 - cx) * (sign_x * 15 - cx) < 0);
0495 bool nan_y = ((rad) * (rad) - (sign_y * 15 - cy) * (sign_y * 15 - cy) < 0);
0496
0497 if (isnan(temp_phix) && isnan(temp_phiy))
0498 {
0499 temp_phi = phic;
0500 }
0501 else if (isnan(temp_phix))
0502 {
0503 temp_phi = temp_phiy;
0504 }
0505 else if (isnan(temp_phiy))
0506 {
0507 temp_phi = temp_phix;
0508 }
0509 else
0510 {
0511 if (fabs(phic - temp_phix) > fabs(phic - temp_phiy))
0512 temp_phi = temp_phiy;
0513 else
0514 temp_phi = temp_phix;
0515 }
0516
0517 if (phic < temp_phi)
0518 {
0519 phi_min = phic;
0520 phi_max = temp_phi;
0521 }
0522 else
0523 {
0524 phi_min = temp_phi;
0525 phi_max = phic;
0526 }
0527
0528 if (fabs(phi_max - phi_min) > 180)
0529 {
0530 phi_max = -(360 - phi_max);
0531 double temp = phi_min;
0532 phi_min = phi_max;
0533 phi_max = temp;
0534 }
0535
0536 if (mode == 0)
0537 {
0538 TEllipse *circle = new TEllipse(cx, cy, rad, 0, phi_min, phi_max);
0539 circle->SetLineColorAlpha(color, 0.5);
0540 circle->SetFillStyle(0);
0541 circle->SetLineWidth(2);
0542 circle->SetLineStyle(1);
0543 circle->SetNoEdges(1);
0544 circle->Draw("same");
0545
0546
0547
0548
0549
0550
0551
0552 }
0553 else if (mode == 1)
0554 {
0555 TEllipse *circle_truth = new TEllipse(cx, cy, rad, 0, phi_min, phi_max);
0556 circle_truth->SetLineColorAlpha(color, 0.5);
0557 circle_truth->SetFillStyle(0);
0558 circle_truth->SetLineWidth(2);
0559 circle_truth->SetLineStyle(9);
0560 circle_truth->SetNoEdges(1);
0561 circle_truth->Draw("same");
0562 }
0563 }
0564
0565 void draw_trackcurve(int mode = 0, bool does_overlay = false, int color = kBlack, bool dca_range_cut = false, bool is_deleted = false, bool reverse = false)
0566 {
0567 vector<int> colorset = {kOrange - 3, kOrange + 3, kPink - 3, kPink + 3, kViolet - 3, kViolet + 3, kAzure - 3, kAzure + 3, kTeal - 3, kTeal + 3, kSpring - 3, kSpring + 3};
0568 int color_ = 0;
0569 bool condition = !reverse;
0570
0571 for (unsigned int i = 0; i < vtrack.size(); i++)
0572 {
0573 color_ = color_ % colorset.size();
0574
0575 if (vtrack[i]->dca_range_out == condition && dca_range_cut == true)
0576 {
0577 continue;
0578 }
0579
0580 if (vtrack[i]->is_deleted == condition && is_deleted == true)
0581 {
0582 continue;
0583 }
0584
0585 TGraph *g_temp = new TGraph();
0586 g_temp->SetMarkerColor(colorset[color_]);
0587 g_temp->SetLineColor(colorset[color_]);
0588 g_temp->SetMarkerStyle(20);
0589 g_temp->SetMarkerSize(0.8);
0590
0591 if (mode == 0)
0592 {
0593 draw_curve2(0, vtrack[i]->p_reco[0], vtrack[i]->p_reco[1], vtrack[i]->p_reco[2], vtrack[i]->rad, vtrack[i]->cx, vtrack[i]->cy, colorset[color_]);
0594
0595 cout << "p1 : " << vtrack[i]->p1.x() << " " << vtrack[i]->p1.y() << endl;
0596
0597 g_temp->SetPoint(0, vtrack[i]->dca_mean[0], vtrack[i]->dca_mean[1]);
0598 g_temp->SetPoint(1, vtrack[i]->p1.x(), vtrack[i]->p1.y());
0599 g_temp->SetPoint(2, vtrack[i]->p2.x(), vtrack[i]->p2.y());
0600 }
0601
0602 g_temp->Draw("Psame");
0603 color_++;
0604 }
0605 }
0606 void draw_truthcurve(int mode = 0, bool does_overlay = false, int color = kBlack, bool only_far_cluster = false, bool only_far_track = false)
0607 {
0608 for (unsigned int i = 0; i < vtruth.size(); i++)
0609 {
0610 if (vtruth[i]->is_intt == false)
0611 continue;
0612
0613 if (vtruth[i]->is_charged == false)
0614 continue;
0615
0616 if (vtruth[i]->have_track == true && only_far_track)
0617 continue;
0618
0619 if (vtruth[i]->have_cluster == true && only_far_cluster)
0620 continue;
0621
0622 TGraph *g_temp = new TGraph();
0623 g_temp->SetMarkerColor(color);
0624 g_temp->SetLineColor(color);
0625 g_temp->SetMarkerStyle(20);
0626 g_temp->SetMarkerSize(0.8);
0627
0628 if (mode == 0)
0629 {
0630 draw_curve2(1, vtruth[i]->m_truthpx, vtruth[i]->m_truthpy, vtruth[i]->m_truthpz, vtruth[i]->m_rad, vtruth[i]->center[0], vtruth[i]->center[1], color);
0631
0632 g_temp->SetPoint(0, vtruth[i]->m_xvtx, vtruth[i]->m_yvtx);
0633 }
0634
0635 g_temp->Draw("Psame");
0636 }
0637 }
0638
0639 void draw_truthline(int mode = 0, bool does_overlay = false, int color = kBlack, bool only_far_cluster = false, bool only_far_track = false)
0640 {
0641 for (unsigned int i = 0; i < vtruth.size(); i++)
0642 {
0643 if (vtruth[i]->is_intt == false)
0644 continue;
0645
0646 if (vtruth[i]->is_charged == false)
0647 continue;
0648
0649 if (vtruth[i]->have_track == true && only_far_track)
0650 continue;
0651
0652 if (vtruth[i]->have_cluster == true && only_far_cluster)
0653 continue;
0654
0655 TGraph *g_temp = new TGraph();
0656 g_temp->SetMarkerColor(color);
0657 g_temp->SetLineColor(color);
0658 g_temp->SetMarkerStyle(20);
0659 g_temp->SetMarkerSize(0.8);
0660
0661 if (mode == 0)
0662 {
0663 vtruth[i]->truth_xy->SetLineColorAlpha(color, 0.5);
0664 vtruth[i]->truth_xy->SetLineStyle(9);
0665 vtruth[i]->truth_xy->SetLineWidth(2);
0666
0667 if (vtruth[i]->m_truthpx > 0)
0668 {
0669 vtruth[i]->truth_xy->SetRange(vtruth[i]->m_xvtx, 15);
0670 }
0671 else
0672 {
0673 vtruth[i]->truth_xy->SetRange(-15, vtruth[i]->m_xvtx);
0674 }
0675 vtruth[i]->truth_xy->Draw("Lsame");
0676
0677 g_temp->SetPoint(0, vtruth[i]->m_xvtx, vtruth[i]->m_yvtx);
0678 }
0679 else if (mode == 1)
0680 {
0681 vtruth[i]->truth_rz->SetLineColorAlpha(color, 0.5);
0682 vtruth[i]->truth_rz->SetLineStyle(9);
0683 vtruth[i]->truth_rz->SetLineWidth(2);
0684
0685 int y = 0;
0686 if (vtruth[i]->m_truthpy > 0)
0687 y = 15;
0688 else
0689 y = -15;
0690 double r_min = vtruth[i]->truth_rz->GetX(vtruth[i]->getpointr(3));
0691 double r_max = vtruth[i]->truth_rz->GetX(y);
0692 if (r_min < r_max)
0693 vtruth[i]->truth_rz->SetRange(r_min, r_max);
0694 else
0695 vtruth[i]->truth_rz->SetRange(r_max, r_min);
0696
0697 vtruth[i]->truth_rz->Draw("Lsame");
0698 g_temp->SetPoint(0, vtruth[i]->m_zvtx, vtruth[i]->getpointr(3));
0699 }
0700 g_temp->Draw("Psame");
0701 }
0702 }
0703
0704 void draw_clusters(int mode = 0, bool does_overlay = false, int color = kBlack)
0705 {
0706 for (unsigned int i = 0; i < vclus.size(); i++)
0707 {
0708 TGraph *g_temp = new TGraph();
0709 g_temp->SetMarkerColorAlpha(color, 0.5);
0710
0711 g_temp->SetMarkerStyle(20);
0712 g_temp->SetMarkerSize(0.8);
0713
0714 if (mode == 0)
0715 {
0716 g_temp->SetPoint(0, vclus[i].x, vclus[i].y);
0717 }
0718 else if (mode == 1)
0719 {
0720 g_temp->SetPoint(0, vclus[i].z, vclus[i].r);
0721 }
0722 g_temp->Draw("psame");
0723 }
0724 }
0725 };
0726
0727 template <class D>
0728 void erase(vector<D> &vec)
0729 {
0730 vec.erase(vec.begin(), vec.end());
0731 }
0732
0733 template <class D>
0734 void reverse(vector<D> &vec)
0735 {
0736 reverse(vec.begin(), vec.end());
0737 }
0738
0739 bool dotracking(clustEvent &vCluster, double angl)
0740 {
0741 for (unsigned int i = 0; i < vCluster.vclus.size(); i++)
0742 {
0743 cluster c1 = vCluster.vclus[i];
0744 if (2 <= c1.layer)
0745 continue;
0746
0747 for (unsigned int j = i + 1; j < vCluster.vclus.size(); j++)
0748 {
0749 cluster c2 = vCluster.vclus[j];
0750 if (c2.layer <= 1)
0751 continue;
0752
0753 TVector3 beamspot = {vCluster.dca_mean[0], vCluster.dca_mean[1], 0};
0754
0755
0756
0757 TVector3 p1 = c1.pos - beamspot;
0758 TVector3 p2 = c2.pos - beamspot;
0759
0760
0761 TVector3 p1_left(p1.x(), p1.y(), p1.z() - c1.chip_width / 2);
0762 TVector3 p1_right(p1.x(), p1.y(), p1.z() + c1.chip_width / 2);
0763 TVector3 p2_left(p2.x(), p2.y(), p2.z() - c2.chip_width / 2);
0764 TVector3 p2_right(p2.x(), p2.y(), p2.z() + c2.chip_width / 2);
0765
0766
0767 double p1_phi = atan2(p1.y(), p1.x());
0768 double p2_phi = atan2(p2.y(), p2.x());
0769 double d_phi = p2_phi - p1_phi;
0770 d_phi -= -2 * (M_PI * (int)(d_phi / (M_PI)));
0771
0772 double p1_r = sqrt(p1.x() * p1.x() + p1.y() * p1.y());
0773 double p2_r = sqrt(p2.x() * p2.x() + p2.y() * p2.y());
0774 double p1_theta = atan2(p1_r, p1.z());
0775 double p2_theta = atan2(p2_r, p2.z());
0776 double d_theta = p2_theta - p1_theta;
0777
0778 h_dphi_nocut->Fill(p1_phi, d_phi);
0779
0780
0781 if (fabs(d_phi) > angl)
0782 continue;
0783 h_dphi_cut->Fill(p1_phi, d_phi);
0784
0785 TVector3 u = p2 - p1;
0786 TVector3 u_l = p2_right - p1_left;
0787 TVector3 u_r = p2_left - p1_right;
0788 double unorm = sqrt(u.x() * u.x() + u.y() * u.y());
0789
0790 double ux = u.x() / unorm;
0791 double uy = u.y() / unorm;
0792 double uz = u.z() / unorm;
0793 double uz_l = u_l.z() / unorm;
0794 double uz_r = u_r.z() / unorm;
0795
0796 TVector3 p0 = beamspot - p1;
0797
0798 double dca_p0 = p0.x() * uy - p0.y() * ux;
0799 double len_p0 = p0.x() * ux + p0.y() * uy;
0800
0801
0802 double vx = len_p0 * ux + p1.x();
0803 double vy = len_p0 * uy + p1.y();
0804 double vz = len_p0 * uz + p1.z();
0805 double vz_l = len_p0 * uz_l + p1_left.z();
0806 double vz_r = len_p0 * uz_r + p1_right.z();
0807
0808 track *tr = new track();
0809 tr->phi_in = p1_phi;
0810 tr->phi_out = p2_phi;
0811 tr->theta_in = c1.gettheta_clus();
0812 tr->theta_out = c2.gettheta_clus();
0813 tr->d_phi = d_phi;
0814 tr->d_theta = d_theta;
0815 tr->charge = dca_p0 / fabs(dca_p0);
0816
0817
0818 tr->ladder1 = (c1.layer == 0) ? (2 * c1.ladder + 1) : (2 * c1.ladder);
0819 tr->ladder2 = (c2.layer == 2) ? (24 + 2 * c2.ladder + 1) : (24 + 2 * c2.ladder);
0820
0821 tr->dca[0] = vx;
0822 tr->dca[1] = vy;
0823 tr->dca[2] = vz;
0824 tr->dca[3] = vz_l;
0825 tr->dca[4] = vz_r;
0826
0827
0828 tr->p1 = c1.pos;
0829 tr->p2 = c2.pos;
0830
0831 tr->dca_2d = dca_p0;
0832 vCluster.vtrack.push_back(tr);
0833 }
0834 }
0835
0836 return true;
0837 }
0838
0839 double calc_Peak(TH1F *h)
0840 {
0841 int binN_max = h->GetMaximumBin();
0842 double maxbincontent = h->GetBinContent(binN_max);
0843 vector<double> maxbins;
0844 int count = 1;
0845
0846 for (int i = binN_max; i <= h->GetNbinsX(); i++)
0847 {
0848
0849 maxbins.push_back(i);
0850 if (h->GetBinContent(i) == h->GetBinContent(i + 1) && h->GetBinContent(i) == maxbincontent)
0851 {
0852 maxbins.push_back(i + 1);
0853 count++;
0854 }
0855 else
0856 break;
0857 }
0858
0859 double minbinValue = h->GetXaxis()->GetBinLowEdge(*std::min_element(maxbins.begin(), maxbins.end()));
0860 double maxbinValue = h->GetXaxis()->GetBinUpEdge(*std::max_element(maxbins.begin(), maxbins.end()));
0861
0862 double peak = -999.9;
0863 peak = (minbinValue + maxbinValue) / 2;
0864 return peak;
0865 }
0866
0867 double calc_Mean(vector<double> v)
0868 {
0869 double sum = accumulate(v.begin(), v.end(), 0.0);
0870 double mean = -999.9;
0871 mean = sum / v.size();
0872
0873 return mean;
0874 }
0875
0876 double calu_SgmMean(TH1F *h, vector<double> v, int w)
0877 {
0878 double mean = h->GetMean();
0879 double sigma = h->GetStdDev();
0880
0881 double min = mean - w * sigma;
0882 double max = mean + w * sigma;
0883
0884 vector<double> used_value;
0885
0886 for (int itrk = 0; itrk < v.size(); itrk++)
0887 {
0888 if (v[itrk] >= min && v[itrk] <= max)
0889 used_value.push_back(v[itrk]);
0890 }
0891
0892 double sum = accumulate(used_value.begin(), used_value.end(), 0.0);
0893 double sgmmean = -999.9;
0894 sgmmean = sum / used_value.size();
0895
0896
0897 return sgmmean;
0898 }
0899
0900 vector<double> calc_ErrRange(double minRange, double maxRange, double center, bool useSqrt12 = false)
0901 {
0902 double step = 0.05;
0903 vector<double> values;
0904
0905 if (useSqrt12)
0906 {
0907 double rangeWidth = maxRange - minRange;
0908 double newWidth = rangeWidth / sqrt(12);
0909
0910 minRange = center - newWidth / 2.0;
0911 maxRange = center + newWidth / 2.0;
0912
0913 }
0914
0915
0916
0917 for (double value = minRange; value <= maxRange + step; value += step)
0918 {
0919 values.push_back(value);
0920
0921
0922 }
0923
0924 return values;
0925 }
0926
0927 TH1F *fill_ErrRange(vector<double> values)
0928 {
0929 TH1F *hist = new TH1F("hist", "hist", 8000, -200, 200);
0930 for (int nbin = 0; nbin < values.size(); nbin++)
0931 {
0932 hist->Fill(values[nbin]);
0933
0934 }
0935 return hist;
0936 }
0937
0938 void tracking_and_zvtx(bool debug = false, int run_nu = 1, bool sr = false, int BCO = 0)
0939 {
0940 int sigma = 3;
0941 int nloop = 100;
0942 bool mag_on = false;
0943 bool geant = false;
0944 double ang = 0.04;
0945
0946 if (run_nu == 1)
0947 {
0948 geant = true;
0949 double ang = 0.02;
0950 }
0951
0952
0953
0954 int method = 12;
0955 int xsize = 200;
0956 int binw = 1;
0957
0958 string zv_tit[12] = {
0959 "Peak",
0960 "Mean",
0961 "3sigmaMean",
0962 "1sigmaMean",
0963 "Peak_error",
0964 "Mean_error",
0965 "3sigmaMean_error",
0966 "1sigmaMean_error",
0967 "Peak_error_sq12",
0968 "Mean_error_sq12",
0969 "3sigmaMean_error_sq12",
0970 "1sigmaMean_error_sq12",
0971 };
0972
0973
0974 string fname = Form("/sphenix/tg/tg01/commissioning/INTT/work/mahiro/datamacro/inttana_%d.root", run_nu);
0975
0976
0977
0978 if (mag_on)
0979 fname = Form("/sphenix/tg/tg01/commissioning/INTT/work/tsujibata/tracking/F4AInttRead/macro/readdst/AnaTutorial_inttana_%d_mag.root", run_nu);
0980
0981 if (sr)
0982
0983 fname = Form("/sphenix/tg/tg01/commissioning/INTT/work/mahiro/datamacro/streaming_readout/ana/inttana_%d_%d.root", run_nu, BCO);
0984
0985 if (geant)
0986 {
0987 if (mag_on)
0988 {
0989
0990 fname = "/sphenix/tg/tg01/commissioning/INTT/work/tsujibata/tracking/F4AInttRead/macro/macros/detectors/sPHENIX/AnaTutorial_inttana_zvtxwidth10_ptmin0.root";
0991
0992 }
0993
0994 else
0995 fname = "/sphenix/tg/tg01/commissioning/INTT/work/mahiro/datamacro/inttana_sim_nomg.root";
0996
0997 }
0998
0999 TFile *f = TFile::Open(fname.c_str());
1000 cout << "opened file : " << fname << endl;
1001
1002
1003 TString fname_out = fname.substr(fname.find_last_of("/"), fname.size());
1004
1005 fname_out.ReplaceAll("inttana", "zvtx");
1006
1007
1008
1009
1010 if (debug)
1011 fname_out.ReplaceAll(".root", "_debug.root");
1012
1013
1014
1015 fname_out = "result_with_tracking" + fname_out;
1016 cout << "out put file : " << fname_out << endl;
1017
1018 TH1F *h_dcaz_one_ = new TH1F("h_dcaz_one_", "", 100, -200, 200);
1019
1020 TFile *froot = new TFile(fname_out, "recreate");
1021 TH1F *h_nclus = new TH1F("h_nclus", "", 100, 0, 100);
1022
1023 TTree *temp_tree_ = new TTree("temp_tree_", "temp_tree_");
1024
1025 TTree *clus_tree_ = new TTree("clus_tree_", "clus_tree_");
1026 TTree *truth_tree = new TTree("truth_tree", "truth_tree");
1027
1028 TTree *track_tree_ = new TTree("track_tree_", "track_tree_");
1029
1030 h_dphi_nocut = new TH2F("h_dphi_nocut", "d_phi : phi_in;phi_in;d_phi", 200, -3.2, 3.2, 200, -0.1, 0.1);
1031 h_dphi_cut = new TH2F("h_dphi_cut", "d_phi : phi_in;phi_in;d_phi", 200, -3.2, 3.2, 200, -0.1, 0.1);
1032
1033 TH1F *h_dcaz_sigma_one = new TH1F("h_dcaz_sigma_one", "h_dcaz_sigma_one;dcaz sigma of one event;entries", 100, 0, 15);
1034 TH1D *h_xvtx = new TH1D("h_xvtx", "h_xvtx", 100, -0.01, 0.01);
1035 TH1D *h_yvtx = new TH1D("h_yvtx", "h_yvtx", 100, -0.01, 0.01);
1036
1037 TH2D *h_zr[2];
1038
1039 TH1F *h_dcaz_ = new TH1F("h_dcaz_", "dcaz distribution", 200, -200, 200);
1040 TH1F *h_dcaz_err = new TH1F("h_dcaz_err", "dcaz with all range distribution", 8000, -200, 200);
1041 TH1F *h_dcaz_err_sq12 = new TH1F("h_dcaz_err_sq12", "dcaz with error range distribution", 8000, -200, 200);
1042 TH1F *h_zvtx[method];
1043 TH1F *h_zvtx_truth = new TH1F("h_zvtx_truth", "truth zvtx", xsize * 2 / binw, -xsize, xsize);
1044 TH1F *h_zvtx_CW = new TH1F("h_zvtx_CW", "zvtx by CW", xsize * 2 / binw, -xsize, xsize);
1045
1046 for (int i = 0; i < 2; i++)
1047 h_zr[i] = new TH2D(Form("h_zr_%d", i), "h_zr;z;r", 100, -20, 20, 100, -10, 10);
1048
1049 for (int l = 0; l < method; l++)
1050 {
1051 string histName = "hist_" + zv_tit[l];
1052 string histTitle = zv_tit[l];
1053 h_zvtx[l] = new TH1F(histName.c_str(), histTitle.c_str(), xsize * 2 / binw, -xsize, xsize);
1054 }
1055 c = new TCanvas(fname_out.ReplaceAll(".root", ".pdf"), "c", 1200, 1200);
1056 c->Divide(2, 2);
1057 c->cd(1);
1058 c->Print(((string)c->GetName() + "[").c_str());
1059
1060 int evt_temp_;
1061 vector<double> d_phi_;
1062 vector<double> d_theta_;
1063 vector<double> phi_in_;
1064 vector<double> dca_x_;
1065 vector<double> dca_y_;
1066 vector<double> dcaz_;
1067 vector<double> dcaz_l;
1068 vector<double> dcaz_r;
1069 vector<double> dcaz_err;
1070 vector<double> dcaz_err_sq12;
1071 vector<double> dca_2d_;
1072 double zvtx_one_;
1073 double zvtx_sigma_one_;
1074 int evt_all;
1075 int ntrack_all;
1076 vector<int> ladnum_in;
1077 vector<int> ladnum_out;
1078 double zvtx_CW;
1079 double truthzvtx;
1080 double zv_peak;
1081 double zv_mean;
1082 double zv_mean_3sgm;
1083 double zv_mean_1sgm;
1084 double zv_peak_err;
1085 double zv_mean_err;
1086 double zv_mean_3sgm_err;
1087 double zv_mean_1sgm_err;
1088 double zv_peak_err_sq12;
1089 double zv_mean_err_sq12;
1090 double zv_mean_3sgm_err_sq12;
1091 double zv_mean_1sgm_err_sq12;
1092
1093 temp_tree_->Branch("evt_temp_", &evt_temp_, "evt_temp_/I");
1094 temp_tree_->Branch("d_phi_", &d_phi_);
1095 temp_tree_->Branch("d_theta_", &d_theta_);
1096 temp_tree_->Branch("phi_in_", &phi_in_);
1097 temp_tree_->Branch("dca_x_", &dca_x_);
1098 temp_tree_->Branch("dca_y_", &dca_y_);
1099 temp_tree_->Branch("dcaz_", &dcaz_);
1100 temp_tree_->Branch("dcaz_l", &dcaz_l);
1101 temp_tree_->Branch("dcaz_r", &dcaz_r);
1102 temp_tree_->Branch("dcaz_err", &dcaz_err);
1103 temp_tree_->Branch("dcaz_err_sq12", &dcaz_err_sq12);
1104 temp_tree_->Branch("dca_2d_", &dca_2d_);
1105 temp_tree_->Branch("zvtx_one_", &zvtx_one_, "zvtx_one_/D");
1106 temp_tree_->Branch("zvtx_sigma_one_", &zvtx_sigma_one_, "zvtx_sigma_one_/D");
1107 temp_tree_->Branch("evt_all", &evt_all, "evt_all/I");
1108 temp_tree_->Branch("ntrack_all", &ntrack_all, "ntrack_all/I");
1109 temp_tree_->Branch("ladnum_in", &ladnum_in);
1110 temp_tree_->Branch("ladnum_out", &ladnum_out);
1111 temp_tree_->Branch("zvtx_CW", &zvtx_CW, "zvtx_CW/D");
1112 temp_tree_->Branch("truthzvtx", &truthzvtx, "truthzvtx/D");
1113 temp_tree_->Branch("zv_peak", &zv_peak, "zv_peak/D");
1114 temp_tree_->Branch("zv_mean", &zv_mean, "zv_mean/D");
1115 temp_tree_->Branch("zv_mean_3sgm", &zv_mean_3sgm, "zv_mean_3sgm/D");
1116 temp_tree_->Branch("zv_mean_1sgm", &zv_mean_1sgm, "zv_mean_1sgm/D");
1117 temp_tree_->Branch("zv_peak_err", &zv_peak_err, "zv_peal_err/D");
1118 temp_tree_->Branch("zv_mean_err", &zv_mean_err, "zv_mean_err/D");
1119 temp_tree_->Branch("zv_mean_3sgm_err", &zv_mean_3sgm_err, "zv_mean_3sgm_err/D");
1120 temp_tree_->Branch("zv_mean_1sgm_err", &zv_mean_1sgm_err, "zv_mean_1sgm_err/D");
1121 temp_tree_->Branch("zv_peak_err_sq12", &zv_peak_err_sq12, "zv_peak_err_sq12/D");
1122 temp_tree_->Branch("zv_mean_err_sq12", &zv_mean_err_sq12, "zv_mean_err_sq12/D");
1123 temp_tree_->Branch("zv_mean_3sgm_err_sq12", &zv_mean_3sgm_err_sq12, "zv_mean_3sgm_err_sq12/D");
1124 temp_tree_->Branch("zv_mean_1sgm_err_sq12", &zv_mean_1sgm_err_sq12, "zv_mean_1sgm_err_sq12/D");
1125
1126 int evt_clus;
1127 vector<double> x_in;
1128 vector<double> y_in;
1129 vector<double> z_in;
1130 vector<double> r_in;
1131 vector<double> phi_in;
1132 vector<double> theta_in;
1133 vector<double> x_out;
1134 vector<double> y_out;
1135 vector<double> z_out;
1136 vector<double> r_out;
1137 vector<double> phi_out;
1138 vector<double> theta_out;
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156 clus_tree_->Branch("evt_clus", &evt_clus, "evt_clus/I");
1157 clus_tree_->Branch("x_in", &x_in);
1158 clus_tree_->Branch("y_in", &y_in);
1159 clus_tree_->Branch("z_in", &z_in);
1160 clus_tree_->Branch("r_in", &r_in);
1161 clus_tree_->Branch("phi_in", &phi_in);
1162 clus_tree_->Branch("theta_in", &theta_in);
1163 clus_tree_->Branch("x_out", &x_out);
1164 clus_tree_->Branch("y_out", &y_out);
1165 clus_tree_->Branch("z_out", &z_out);
1166 clus_tree_->Branch("r_out", &r_out);
1167 clus_tree_->Branch("phi_out", &phi_out);
1168 clus_tree_->Branch("theta_out", &theta_out);
1169
1170 int evt_track;
1171 int ntrack = 0;
1172 vector<double> slope_rz;
1173 vector<double> slope_xy;
1174 vector<double> phi_tracklets;
1175 vector<double> theta_tracklets;
1176 vector<double> phi_track;
1177 vector<double> theta_track;
1178 vector<double> z_tracklets_out;
1179 vector<double> dca_2d;
1180 vector<double> dca_z;
1181 vector<int> is_deleted;
1182 vector<int> dca_range_out;
1183 vector<int> dca2d_range_out;
1184 vector<int> dcaz_range_out;
1185 vector<double> pT;
1186 vector<double> px_truth;
1187 vector<double> py_truth;
1188 vector<double> pz_truth;
1189 vector<double> px;
1190 vector<double> py;
1191 vector<double> pz;
1192 vector<double> rad;
1193 vector<double> pT_truth;
1194 vector<double> charge;
1195 double x_vertex;
1196 double y_vertex;
1197 double z_vertex;
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230 track_tree_->Branch("evt_track", &evt_track, "evt_track/I");
1231 track_tree_->Branch("ntrack", &ntrack, "ntrack/I");
1232 track_tree_->Branch("phi_tracklets", &phi_tracklets);
1233 track_tree_->Branch("slope_rz", &slope_rz);
1234 track_tree_->Branch("slope_xy", &slope_xy);
1235 track_tree_->Branch("theta_tracklets", &theta_tracklets);
1236 track_tree_->Branch("phi_track", &phi_track);
1237 track_tree_->Branch("theta_track", &theta_track);
1238 track_tree_->Branch("z_tracklets_out", &z_tracklets_out);
1239 track_tree_->Branch("dca_2d", &dca_2d);
1240 track_tree_->Branch("dca_z", &dca_z);
1241 track_tree_->Branch("is_deleted", &is_deleted);
1242 track_tree_->Branch("dca_range_out", &dca_range_out);
1243 track_tree_->Branch("dcaz_range_out", &dcaz_range_out);
1244 track_tree_->Branch("dca2d_range_out", &dca2d_range_out);
1245 track_tree_->Branch("pT", &pT);
1246 track_tree_->Branch("px", &px);
1247 track_tree_->Branch("py", &py);
1248 track_tree_->Branch("pz", &pz);
1249 track_tree_->Branch("px_truth", &px_truth);
1250 track_tree_->Branch("py_truth", &py_truth);
1251 track_tree_->Branch("pz_truth", &pz_truth);
1252 track_tree_->Branch("pT_truth", &pT_truth);
1253 track_tree_->Branch("charge", &charge);
1254 track_tree_->Branch("rad", &rad);
1255 track_tree_->Branch("x_vertex", &x_vertex, "x_vertex/D");
1256 track_tree_->Branch("y_vertex", &y_vertex, "y_vertex/D");
1257 track_tree_->Branch("z_vertex", &z_vertex, "z_vertex/D");
1258
1259 int evt_truth;
1260 int ntruth = 0;
1261 int ntruth_cut = 0;
1262 vector<double> truthpx;
1263 vector<double> truthpy;
1264 vector<double> truthpz;
1265 vector<double> truthpt;
1266 vector<double> trutheta;
1267 vector<double> truththeta;
1268 vector<double> truthphi;
1269 vector<double> truthxvtx;
1270 vector<double> truthyvtx;
1271
1272 vector<double> truthzout;
1273 vector<int> truthpid;
1274 vector<int> status;
1275 truth_tree->Branch("evt_truth", &evt_truth, "evt_truth/I");
1276 truth_tree->Branch("ntruth_cut", &ntruth_cut, "ntruth_cut/I");
1277 truth_tree->Branch("truthpx", &truthpx);
1278 truth_tree->Branch("truthpy", &truthpy);
1279 truth_tree->Branch("truthpz", &truthpz);
1280 truth_tree->Branch("truthpt", &truthpt);
1281 truth_tree->Branch("trutheta", &trutheta);
1282 truth_tree->Branch("truththeta", &truththeta);
1283 truth_tree->Branch("truthphi", &truthphi);
1284 truth_tree->Branch("truthxvtx", &truthxvtx);
1285 truth_tree->Branch("truthyvtx", &truthyvtx);
1286
1287 truth_tree->Branch("truthzout", &truthzout);
1288 truth_tree->Branch("truthpid", &truthpid);
1289 truth_tree->Branch("status", &status);
1290
1291
1292 TNtuple *ntp_clus = (TNtuple *)f->Get("ntp_clus");
1293 TNtuple *ntp_evt = (TNtuple *)f->Get("ntp_evt");
1294
1295
1296
1297 Float_t nclus, nclus2, bco_full, evt, size, adc, x, y, z, lay, lad, sen;
1298
1299 ntp_clus->SetBranchAddress("nclus", &nclus);
1300 ntp_clus->SetBranchAddress("nclus2", &nclus2);
1301 ntp_clus->SetBranchAddress("bco_full", &bco_full);
1302 ntp_clus->SetBranchAddress("evt", &evt);
1303 ntp_clus->SetBranchAddress("size", &size);
1304 ntp_clus->SetBranchAddress("adc", &adc);
1305 ntp_clus->SetBranchAddress("x", &x);
1306 ntp_clus->SetBranchAddress("y", &y);
1307 ntp_clus->SetBranchAddress("z", &z);
1308 ntp_clus->SetBranchAddress("lay", &lay);
1309 ntp_clus->SetBranchAddress("lad", &lad);
1310 ntp_clus->SetBranchAddress("sen", &sen);
1311
1312
1313
1314
1315 Float_t zvsim, zv;
1316 ntp_evt->SetBranchAddress("zv", &zv);
1317 ntp_evt->SetBranchAddress("zvsim", &zvsim);
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336 int sum_event = 0;
1337 int ntrack_ = 0;
1338 for (int icls = 0; icls < ntp_clus->GetEntries(); icls++)
1339 {
1340 cout << Form(" ----- event %d {event gene.} ----- ", sum_event) << endl;
1341
1342 clustEvent event{};
1343 cluster clust{};
1344
1345 ntp_clus->GetEntry(icls);
1346 ntp_evt->GetEntry(sum_event);
1347 clust.set(evt, 0, x, y, z, adc, size, lay, lad, sen);
1348 event.vclus.push_back(clust);
1349
1350 h_dcaz_->Reset();
1351 h_dcaz_err->Reset();
1352 h_dcaz_err_sq12->Reset();
1353
1354 for (int j = 1; j < nclus; j++)
1355 {
1356 ntp_clus->GetEntry(++icls);
1357 cluster clust2{};
1358 clust2.set(evt, 0, x, y, z, adc, size, lay, lad, sen);
1359 event.vclus.push_back(clust2);
1360 }
1361
1362 if (!(geant))
1363 {
1364 event.dca_mean[0] = -0.019;
1365 event.dca_mean[1] = 0.198;
1366 }
1367
1368 dotracking(event, ang);
1369 ntrack_ = event.vtrack.size();
1370 ntrack_all = ntrack_;
1371 h_dcaz_one_->Reset();
1372 if (ntrack_all <= 2)
1373 continue;
1374 for (int itrk = 0; itrk < ntrack_; itrk++)
1375 {
1376 h_dcaz_one_->Fill(event.vtrack[itrk]->dca[2]);
1377 }
1378 zvtx_one_ = h_dcaz_one_->GetMean();
1379 zvtx_sigma_one_ = h_dcaz_one_->GetStdDev();
1380
1381 evt_temp_ = sum_event;
1382 for (int itrk = 0; itrk < ntrack_; itrk++)
1383 {
1384 dca_x_.push_back(event.vtrack[itrk]->dca[0]);
1385 dca_y_.push_back(event.vtrack[itrk]->dca[1]);
1386 dcaz_.push_back(event.vtrack[itrk]->dca[2]);
1387 dcaz_l.push_back(event.vtrack[itrk]->dca[3]);
1388 dcaz_r.push_back(event.vtrack[itrk]->dca[4]);
1389 dca_2d_.push_back(event.vtrack[itrk]->dca_2d);
1390 d_phi_.push_back(event.vtrack[itrk]->d_phi);
1391 d_theta_.push_back(event.vtrack[itrk]->d_theta);
1392 phi_in_.push_back(event.vtrack[itrk]->phi_in);
1393 ladnum_in.push_back(event.vtrack[itrk]->ladder1);
1394 ladnum_out.push_back(event.vtrack[itrk]->ladder2);
1395
1396 h_dcaz_->Fill(dcaz_[itrk]);
1397
1398 vector<double> errRange = calc_ErrRange(dcaz_l[itrk], dcaz_r[itrk], dcaz_[itrk], false);
1399 dcaz_err.insert(dcaz_err.end(), errRange.begin(), errRange.end());
1400 TH1F *Hist_err = fill_ErrRange(dcaz_err);
1401 h_dcaz_err->Add(Hist_err);
1402 delete Hist_err;
1403 errRange.clear();
1404
1405
1406 vector<double> errRangeSq12 = calc_ErrRange(dcaz_l[itrk], dcaz_r[itrk], dcaz_[itrk], true);
1407 dcaz_err_sq12.insert(dcaz_err_sq12.end(), errRangeSq12.begin(), errRangeSq12.end());
1408 TH1F *Hist_err_sq12 = fill_ErrRange(dcaz_err_sq12);
1409 h_dcaz_err_sq12->Add(Hist_err_sq12);
1410 delete Hist_err_sq12;
1411 errRangeSq12.clear();
1412 }
1413
1414 zv_peak = calc_Peak(h_dcaz_);
1415 zv_mean = calc_Mean(dcaz_);
1416 zv_mean_3sgm = calu_SgmMean(h_dcaz_, dcaz_, 3);
1417 zv_mean_1sgm = calu_SgmMean(h_dcaz_, dcaz_, 1);
1418
1419 zv_peak_err = calc_Peak(h_dcaz_err);
1420 zv_mean_err = calc_Mean(dcaz_err);
1421 zv_mean_3sgm_err = calu_SgmMean(h_dcaz_err, dcaz_err, 3);
1422 zv_mean_1sgm_err = calu_SgmMean(h_dcaz_err, dcaz_err, 1);
1423
1424 zv_peak_err_sq12 = calc_Peak(h_dcaz_err_sq12);
1425 zv_mean_err_sq12 = calc_Mean(dcaz_err_sq12);
1426 zv_mean_3sgm_err_sq12 = calu_SgmMean(h_dcaz_err_sq12, dcaz_err_sq12, 3);
1427 zv_mean_1sgm_err_sq12 = calu_SgmMean(h_dcaz_err_sq12, dcaz_err_sq12, 1);
1428
1429 double rzv[12] = {zv_peak, zv_mean, zv_mean_3sgm, zv_mean_1sgm, zv_peak_err, zv_mean_err, zv_mean_3sgm_err, zv_mean_1sgm_err, zv_peak_err_sq12, zv_mean_err_sq12, zv_mean_3sgm_err_sq12, zv_mean_1sgm_err_sq12};
1430
1431 for (int j = 0; j < method; j++)
1432 {
1433 h_zvtx[j]->Fill(rzv[j]);
1434
1435
1436 }
1437
1438 if (geant)
1439 {
1440 truthzvtx = zvsim;
1441 h_zvtx_truth->Fill(truthzvtx);
1442
1443 }
1444
1445 zvtx_CW = zv;
1446 h_zvtx_CW->Fill(zv);
1447
1448
1449 for (unsigned int i = 0; i < event.vclus.size(); i++)
1450 {
1451 if (event.vclus[i].layer < 2)
1452 {
1453 x_in.push_back(event.vclus[i].x);
1454 y_in.push_back(event.vclus[i].y);
1455 z_in.push_back(event.vclus[i].z);
1456 r_in.push_back(event.vclus[i].r);
1457 phi_in.push_back(event.vclus[i].getphi_clus());
1458 theta_in.push_back(event.vclus[i].gettheta_clus());
1459 }
1460 if (1 < event.vclus[i].layer)
1461 {
1462 x_out.push_back(event.vclus[i].x);
1463 y_out.push_back(event.vclus[i].y);
1464 z_out.push_back(event.vclus[i].z);
1465 r_out.push_back(event.vclus[i].r);
1466 phi_out.push_back(event.vclus[i].getphi_clus());
1467 theta_out.push_back(event.vclus[i].gettheta_clus());
1468 }
1469 }
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517 truth_tree->Fill();
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531 temp_tree_->Fill();
1532 erase(dca_x_);
1533 erase(dca_y_);
1534 erase(dcaz_);
1535 erase(dcaz_l);
1536 erase(dcaz_r);
1537 erase(dca_2d_);
1538 erase(d_phi_);
1539 erase(d_theta_);
1540 erase(phi_in_);
1541 erase(ladnum_in);
1542 erase(ladnum_out);
1543 erase(dcaz_err);
1544 erase(dcaz_err_sq12);
1545
1546
1547
1548
1549
1550
1551
1552
1553 clus_tree_->Fill();
1554 erase(x_in);
1555 erase(y_in);
1556 erase(z_in);
1557 erase(r_in);
1558 erase(phi_in);
1559 erase(theta_in);
1560 erase(x_out);
1561 erase(y_out);
1562 erase(z_out);
1563 erase(r_out);
1564 erase(phi_out);
1565 erase(theta_out);
1566
1567
1568 track_tree_->Fill();
1569 erase(slope_rz);
1570 erase(phi_tracklets);
1571 erase(theta_tracklets);
1572 erase(phi_track);
1573 erase(theta_track);
1574 erase(dca_z);
1575 erase(dca_2d);
1576 erase(is_deleted);
1577 erase(dca_range_out);
1578 erase(dca2d_range_out);
1579 erase(dcaz_range_out);
1580 erase(z_tracklets_out);
1581 erase(pT);
1582 erase(px);
1583 erase(py);
1584 erase(pz);
1585 erase(pT_truth);
1586 erase(px_truth);
1587 erase(py_truth);
1588 erase(pz_truth);
1589 erase(charge);
1590 erase(rad);
1591
1592 event.clear();
1593 sum_event++;
1594
1595 if (debug && sum_event > nloop)
1596 break;
1597 }
1598 evt_all = sum_event;
1599
1600
1601 n_dotracking++;
1602 TH1F *h_dcax = new TH1F("h_dcax", "h_dcax", 100, -0.4, 0.4);
1603 temp_tree_->Draw("dca_x_>>h_dcax");
1604 TH1F *h_dcay = new TH1F("h_dcay", "h_dcay", 100, -0.4, 0.4);
1605 temp_tree_->Draw("dca_y_>>h_dcay");
1606 TH1F *h_dcaz = new TH1F("h_dcaz", "h_dcaz;DCA_z[cm]", 60, -150, 150);
1607 temp_tree_->Draw("dcaz_>>h_dcaz");
1608 TH1F *h_dtheta = new TH1F("h_dtheta", "dtheta{inner - outer};dtheta;entries", 100, -3.2, 3.2);
1609 temp_tree_->Draw("d_theta_>>h_dtheta");
1610 TH1F *h_dphi = new TH1F("h_dphi", "#Delta #phi_{AB};#Delta #phi_{AB}", 100, -1, 1);
1611 temp_tree_->Draw("d_phi_>>h_dphi");
1612
1613 TH1F *h_dca2d = new TH1F("h_dca2d", "h_dca", 100, -10, 10);
1614 temp_tree_->Draw("dca_2d_>>h_dca2d");
1615
1616 vector<TH1F *> h_ = {h_dcax, h_dcay, h_dcaz, h_dphi, h_dtheta, h_dca2d};
1617
1618
1619 double dcax_mean = h_dcax->GetMean();
1620 double dcay_mean = h_dcay->GetMean();
1621 if (!(geant))
1622 {
1623 dcax_mean = -0.019;
1624 dcay_mean = 0.198;
1625 }
1626 double dcaz_mean = h_dcaz->GetMean();
1627 double dca2d_mean = h_dca2d->GetMean();
1628
1629 double dcax_sigma = h_dcax->GetStdDev();
1630 double dcay_sigma = h_dcay->GetStdDev();
1631 double dcaz_sigma = h_dcaz->GetStdDev();
1632 double dca2d_sigma = h_dca2d->GetStdDev();
1633
1634 dca2d_sigma *= sigma;
1635 dcaz_sigma *= sigma;
1636
1637 double dca2d_max = dca2d_mean + dca2d_sigma;
1638 double dca2d_min = dca2d_mean - dca2d_sigma;
1639 double dcaz_max = dcaz_mean + dcaz_sigma;
1640 double dcaz_min = dcaz_mean - dcaz_sigma;
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144 if (geant)
2145 h_zvtx_truth->Draw();
2146 else
2147 h_zvtx_CW->Draw();
2148 c->Print(c->GetName());
2149
2150 for (int j = 0; j < method; j++)
2151 {
2152
2153 if (j < 4)
2154 c->cd(j + 1);
2155 else if (j < 8)
2156 c->cd(j - 3);
2157 else if (j < 12)
2158 c->cd(j - 7);
2159
2160
2161
2162
2163
2164 h_zvtx[j]->SetXTitle("z_{vtx}^{INTT} [cm]");
2165 h_zvtx[j]->SetYTitle(Form("Counts / (%dcm)", binw));
2166
2167 h_zvtx[j]->SetLineColor(1);
2168 h_zvtx[j]->Draw();
2169 if (geant)
2170 {
2171 h_zvtx_truth->SetLineColor(TColor::GetColor(50, 205, 50));
2172 h_zvtx_truth->Draw("Same");
2173 h_zvtx[j]->Draw("same");
2174 }
2175 if (j == 3 || j == 7 || j == 11)
2176 c->Print(c->GetName());
2177 }
2178 c->Print(((string)c->GetName() + "]").c_str());
2179
2180 froot->Write();
2181 for (int ihst = 0; ihst < h_.size(); ihst++)
2182 {
2183 froot->WriteTObject(h_[ihst], h_[ihst]->GetName());
2184 }
2185 froot->Close();
2186 }