File indexing completed on 2025-08-06 08:13:58
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
0030 #include "include_tracking/least_square2.cc"
0031 #include "track_pT.hh"
0032
0033 struct cluster
0034 {
0035 int evt;
0036 uint64_t bco;
0037
0038 double x, y, z, r;
0039 double adc;
0040 double size;
0041 int layer;
0042 TVector3 pos;
0043
0044 double x_vtx;
0045 double y_vtx;
0046 double z_vtx;
0047 double r_vtx;
0048 vector<double> zline;
0049 double theta_clus;
0050 double phi_clus;
0051
0052 double dca_mean[3];
0053
0054 void set(int Evt, uint64_t Bco, double X, double Y, double Z, double Adc, double Size, int Layer, double X_vtx, double Y_vtx, double Z_vtx)
0055 {
0056 evt = Evt;
0057 bco = Bco;
0058 x = X;
0059 y = Y;
0060 z = Z;
0061 adc = Adc;
0062 size = Size;
0063 layer = Layer;
0064 pos = TVector3(x, y, z);
0065 r = y / fabs(y) * sqrt(x * x + y * y);
0066 get_zline();
0067
0068 x_vtx = X_vtx;
0069 y_vtx = Y_vtx;
0070 z_vtx = Z_vtx;
0071 r_vtx = (y_vtx / fabs(y_vtx)) * sqrt(x_vtx * x_vtx + y_vtx * y_vtx);
0072
0073 }
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083 double getphi_clus()
0084 {
0085 phi_clus = atan2((y - y_vtx), (x - x_vtx));
0086
0087 return phi_clus;
0088 }
0089
0090 double gettheta_clus()
0091 {
0092
0093 theta_clus = atan2((fabs(r) - fabs(r_vtx)), (z - z_vtx));
0094
0095 return theta_clus;
0096 }
0097
0098 void get_zline()
0099 {
0100 double chip_width;
0101 if (fabs(z) <= 12.8)
0102 chip_width = 0.8;
0103 else
0104 chip_width = 1.;
0105 zline.push_back(z - chip_width);
0106 zline.push_back(z + chip_width);
0107 }
0108 };
0109
0110 struct clustEvent
0111 {
0112 int run_no = 0;
0113 int ievt = 0;
0114
0115 bool mag_on = false;
0116 vector<cluster> vclus;
0117 vector<truth *> vtruth;
0118 vector<track *> vtrack;
0119
0120 double dcaz_max = 9999;
0121 double dcaz_min = -9999;
0122 double dca2d_max = 9999;
0123 double dca2d_min = -9999;
0124
0125 double dca_mean[3] = {0, 0, 0};
0126
0127 void clear()
0128 {
0129 for (auto itr = vtrack.begin(); itr != vtrack.end(); ++itr)
0130 {
0131 delete *itr;
0132 }
0133 vtrack.clear();
0134 }
0135
0136 void makeonetrack()
0137 {
0138 for (unsigned int i = 0; i < vtrack.size(); i++)
0139 {
0140 for (unsigned int j = i + 1; j < vtrack.size(); j++)
0141 {
0142 bool share_point = ((vtrack[i]->p1 == vtrack[j]->p1) || (vtrack[i]->p2 == vtrack[j]->p2));
0143 share_point = share_point || ((vtrack[i]->p1 == vtrack[j]->p2) || (vtrack[i]->p2 == vtrack[j]->p1));
0144 if (share_point)
0145 {
0146 if (fabs(vtrack[i]->dca_2d) > fabs(vtrack[j]->dca_2d))
0147 {
0148 vtrack[i]->is_deleted = true;
0149 continue;
0150 }
0151 else
0152 {
0153 vtrack[j]->is_deleted = true;
0154 }
0155 }
0156 }
0157 }
0158 }
0159
0160 void dca_check(bool Debug)
0161 {
0162 for (unsigned int i = 0; i < vtrack.size(); i++)
0163 {
0164 if (vtrack[i]->dca_2d > dca2d_max)
0165 vtrack[i]->dca2d_range_out = true;
0166 if (vtrack[i]->dca_2d < dca2d_min)
0167 vtrack[i]->dca2d_range_out = true;
0168
0169 if (vtrack[i]->dca[2] > dcaz_max)
0170 vtrack[i]->dcaz_range_out = true;
0171 if (vtrack[i]->dca[2] < dcaz_min)
0172 vtrack[i]->dcaz_range_out = true;
0173
0174 if (vtrack[i]->dcaz_range_out || vtrack[i]->dca2d_range_out)
0175 vtrack[i]->dca_range_out = true;
0176
0177
0178
0179
0180
0181
0182
0183
0184 }
0185 }
0186
0187 void truth_check()
0188 {
0189 for (unsigned int i = 0; i < vtruth.size(); i++)
0190 {
0191 double p = sqrt(vtruth[i]->m_truthpt * vtruth[i]->m_truthpt + vtruth[i]->m_truthpz * vtruth[i]->m_truthpz);
0192
0193 if (vtruth[i]->m_status == 1 && fabs(vtruth[i]->m_trutheta) < 2 && p > (50 * 1e-3))
0194 {
0195 if (fabs(vtruth[i]->m_truthz_out) < 22.8)
0196 {
0197 vtruth[i]->is_intt = true;
0198 }
0199 }
0200 }
0201 }
0202
0203 void cluster_check()
0204 {
0205 for (unsigned int itrt = 0; itrt < vtruth.size(); itrt++)
0206 {
0207 for (unsigned int icls = 0; icls < vclus.size(); icls++)
0208 {
0209 if (vclus[icls].layer < 2)
0210 continue;
0211
0212 double d_phi = vclus[icls].getphi_clus() - vtruth[itrt]->m_truthphi;
0213 d_phi -= -2 * (M_PI * (int)(d_phi / (M_PI)));
0214
0215 if (fabs(d_phi) < (0.0014 * 3))
0216 {
0217 vtruth[itrt]->have_cluster = true;
0218 break;
0219 }
0220 }
0221 }
0222 }
0223
0224 void track_check()
0225 {
0226 for (unsigned int i = 0; i < vtruth.size(); i++)
0227 {
0228 for (unsigned int itrk = 0; itrk < vtrack.size(); itrk++)
0229 {
0230 double d_phi = vtrack[itrk]->getphi() - vtruth[i]->m_truthphi;
0231 d_phi -= -2 * (M_PI * (int)(d_phi / (M_PI)));
0232
0233 if (fabs(d_phi) < (3.3e-4 * 3))
0234 {
0235 vtruth[i]->have_track = true;
0236 break;
0237 }
0238 }
0239 }
0240 }
0241
0242 void charge_check()
0243 {
0244 for (unsigned int i = 0; i < vtruth.size(); i++)
0245 {
0246 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))
0247 vtruth[i]->is_charged = true;
0248 }
0249 }
0250
0251 void draw_intt(int mode)
0252 {
0253
0254 const double kLayer_radii[4] = {7.1888, 7.800, 9.680, 10.330};
0255 if (mode == 0)
0256 {
0257 for (int i = 0; i < 4; i++)
0258 {
0259 auto circle = new TEllipse(0.0, 0.0, kLayer_radii[i]);
0260 circle->SetLineColorAlpha(kGray, 0.5);
0261 circle->SetLineWidth(2);
0262 circle->SetFillStyle(0);
0263 circle->Draw("same");
0264 }
0265 }
0266 else if (mode == 1)
0267 {
0268 for (int j = 0; j < 2; j++)
0269 {
0270 for (int i = 0; i < 4; i++)
0271 {
0272 TLine *line = new TLine(-22.8, (2 * j - 1) * kLayer_radii[i], 22.8, (2 * j - 1) * kLayer_radii[i]);
0273 line->SetLineColorAlpha(kGray, 0.5);
0274 line->SetLineWidth(2);
0275 line->Draw("same");
0276 }
0277 }
0278 }
0279 }
0280
0281 void draw_frame(int mode = 0)
0282 {
0283 TH1 *flame;
0284 string mag;
0285 if (mag_on)
0286 mag = "B-on";
0287 else
0288 mag = "B-off";
0289
0290 string title;
0291
0292 if (mode == 0)
0293 {
0294 if (run_no == 1)
0295 title = Form("x-y plane {MC(%s) event %d};x [cm];y [cm]", mag.c_str(), ievt);
0296 else
0297 title = Form("x-y plane {run%d(%s) event %d};x [cm];y [cm]", run_no, mag.c_str(), ievt);
0298 flame = gPad->DrawFrame(-15, -15, 15, 15, title.c_str());
0299 }
0300 else if (mode == 1)
0301 {
0302 if (run_no == 1)
0303 title = Form("z-r plane {MC(%s) event %d};z [cm];r [cm]", mag.c_str(), ievt);
0304 else
0305 title = Form("z-r plane {run%d(%s) event %d};z [cm];r [cm]", run_no, mag.c_str(), ievt);
0306 flame = gPad->DrawFrame(-25, -15, 25, 15, title.c_str());
0307 }
0308 }
0309
0310 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)
0311 {
0312
0313 bool condition = !reverse;
0314 for (unsigned int i = 0; i < vtrack.size(); i++)
0315 {
0316 if (vtrack[i]->dca_range_out == condition && dca_range_cut == true)
0317 {
0318 continue;
0319 }
0320
0321 if (vtrack[i]->is_deleted == condition && is_deleted == true)
0322 {
0323 continue;
0324 }
0325
0326 TGraph *g_temp = new TGraph();
0327 g_temp->SetMarkerColor(color);
0328 g_temp->SetMarkerStyle(20);
0329 g_temp->SetMarkerSize(0.8);
0330
0331 if (mode == 0)
0332 {
0333 g_temp->SetPoint(0, vtrack[i]->p1.x(), vtrack[i]->p1.y());
0334 g_temp->SetPoint(1, vtrack[i]->p2.x(), vtrack[i]->p2.y());
0335 }
0336 else if (mode == 1)
0337 {
0338 g_temp->SetPoint(0, vtrack[i]->p1.z(), vtrack[i]->getpointr(1));
0339 g_temp->SetPoint(1, vtrack[i]->p2.z(), vtrack[i]->getpointr(2));
0340 }
0341 g_temp->Draw("PLsame");
0342 }
0343 }
0344
0345 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)
0346 {
0347 bool condition = !reverse;
0348 vector<int> colorset = {kOrange - 3, kOrange + 3, kPink - 3, kPink + 3, kAzure - 3, kAzure + 3, kTeal - 3, kTeal + 3, kSpring - 3, kSpring + 3};
0349 int color_ = 0;
0350
0351 for (unsigned int i = 0; i < vtrack.size(); i++)
0352 {
0353
0354 if (vtrack[i]->dca_range_out == condition && dca_range_cut == true)
0355 {
0356 continue;
0357 }
0358
0359 if (vtrack[i]->is_deleted == condition && is_deleted == true)
0360 {
0361 continue;
0362 }
0363 color_ = color_ % colorset.size();
0364 TGraph *g_temp = new TGraph();
0365 g_temp->SetMarkerColor(colorset[color_]);
0366
0367 g_temp->SetMarkerStyle(20);
0368 g_temp->SetMarkerSize(0.8);
0369
0370 if (mode == 0)
0371 {
0372 vtrack[i]->track_xy->SetLineColorAlpha(colorset[color_], 0.5);
0373
0374 if (vtrack[i]->dca_mean[0] < vtrack[i]->p1.x())
0375 {
0376 vtrack[i]->track_xy->SetRange(vtrack[i]->dca_mean[0], 15);
0377 }
0378 else
0379 {
0380 vtrack[i]->track_xy->SetRange(-15, vtrack[i]->dca_mean[0]);
0381 }
0382
0383 vtrack[i]->track_xy->Draw("Lsame");
0384 g_temp->SetPoint(0, vtrack[i]->dca_mean[0], vtrack[i]->dca_mean[1]);
0385 g_temp->SetPoint(1, vtrack[i]->p1.x(), vtrack[i]->p1.y());
0386 g_temp->SetPoint(2, vtrack[i]->p2.x(), vtrack[i]->p2.y());
0387 }
0388 else if (mode == 1)
0389 {
0390
0391 if (isinf(vtrack[i]->track_rz->GetParameter(1)))
0392 {
0393 TLine *line = nullptr;
0394 if (vtrack[i]->p1.y() > 0)
0395 line = new TLine(vtrack[i]->dca_mean[2], vtrack[i]->getpointr(3), vtrack[i]->dca_mean[2], 15);
0396 else
0397 line = new TLine(vtrack[i]->dca_mean[2], -15, vtrack[i]->dca_mean[2], vtrack[i]->getpointr(3));
0398
0399
0400 line->SetLineColorAlpha(colorset[color_], 0.5);
0401 line->SetLineWidth(2);
0402 line->Draw("same");
0403 }
0404 else
0405 {
0406
0407 vtrack[i]->track_rz->SetLineColorAlpha(colorset[color_], 0.5);
0408
0409
0410 int y = 0;
0411 if (vtrack[i]->p1.y() > 0)
0412 y = 15;
0413 else
0414 y = -15;
0415
0416 double r1 = vtrack[i]->track_rz_inv->Eval(vtrack[i]->getpointr(3));
0417 double r2 = vtrack[i]->track_rz_inv->Eval(y);
0418
0419 if (r1 <= r2)
0420 vtrack[i]->track_rz->SetRange(r1, r2);
0421 else
0422 vtrack[i]->track_rz->SetRange(r2, r1);
0423
0424 vtrack[i]->track_rz->Draw("Lsame");
0425 }
0426 g_temp->SetPoint(0, vtrack[i]->dca_mean[2], vtrack[i]->getpointr(3));
0427 vector<TLine *> zlines;
0428 for (int j = 0; j < 2; j++)
0429 {
0430 TLine *line = new TLine(vtrack[i]->zline[j][0], vtrack[i]->getpointr(1 + j), vtrack[i]->zline[j][1], vtrack[i]->getpointr(1 + j));
0431 line->SetLineColor(colorset[color_]);
0432 line->SetLineWidth(3);
0433 zlines.push_back(line);
0434 }
0435 for (int j = 0; j < 2; j++)
0436 zlines[j]->Draw("same");
0437
0438
0439 }
0440 g_temp->Draw("Psame");
0441 color_++;
0442 }
0443 }
0444
0445 double rad_deg(double Rad)
0446 {
0447 Rad = Rad / M_PI * 180;
0448 if (Rad < 0)
0449 Rad += 360;
0450
0451 return Rad;
0452 }
0453
0454 void draw_curve2(int mode, double px, double py, double pz, double rad, double cx, double cy, int color, const vector<double> &V)
0455 {
0456 if (V.size() == 2)
0457 {
0458
0459 double phi1 = atan2(V.at(1) - cy, V.at(0) - cx);
0460 phi1 = rad_deg(phi1);
0461
0462 double phic = atan2(dca_mean[1] - cy, dca_mean[0] - cx);
0463 phic = rad_deg(phic);
0464 double phi_min, phi_max;
0465
0466 phi_min = (phi1 < phic) ? phi1 : phic;
0467 phi_max = (phi1 < phic) ? phic : phi1;
0468 TEllipse *circle = nullptr;
0469
0470 circle = new TEllipse(cx, cy, rad, 0, phi_min, phi_max);
0471 if ((phi_max - phi_min) > 180)
0472 circle = new TEllipse(cx, cy, rad, 0, -(360 - phi_max), phi_min);
0473
0474 if (mode == 0)
0475 {
0476 circle->SetLineColorAlpha(color, 0.5);
0477 circle->SetFillStyle(0);
0478 circle->SetLineWidth(2);
0479 circle->SetLineStyle(1);
0480 circle->SetNoEdges(1);
0481 circle->Draw("same");
0482 }
0483 else if (mode == 1)
0484 {
0485 circle->SetLineColorAlpha(color, 0.9);
0486 circle->SetFillStyle(0);
0487 circle->SetLineWidth(3);
0488 circle->SetLineStyle(9);
0489 circle->SetNoEdges(1);
0490 circle->Draw("same");
0491 }
0492 }
0493
0494
0495
0496
0497
0498
0499
0500
0501 }
0502
0503 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)
0504 {
0505 vector<int> colorset = {kOrange - 3, kOrange + 3, kPink - 3, kPink + 3, kAzure - 3, kAzure + 3, kTeal - 3, kTeal + 3, kSpring - 3, kSpring + 3};
0506 int color_ = 0;
0507 bool condition = !reverse;
0508
0509 for (unsigned int i = 0; i < vtrack.size(); i++)
0510 {
0511 color_ = color_ % colorset.size();
0512
0513 if (vtrack[i]->dca_range_out == condition && dca_range_cut == true)
0514 {
0515 continue;
0516 }
0517
0518 if (vtrack[i]->is_deleted == condition && is_deleted == true)
0519 {
0520 continue;
0521 }
0522
0523 TGraph *g_temp = new TGraph();
0524
0525
0526 g_temp->SetMarkerColor(colorset[color_]);
0527
0528 g_temp->SetMarkerStyle(20);
0529 g_temp->SetMarkerSize(0.8);
0530
0531 if (mode == 0)
0532 {
0533 vector<double> cross_framepoint = get_crossframe(vtrack[i]->cx, vtrack[i]->cy, vtrack[i]->rad, vtrack[i]->p1.x(), vtrack[i]->p1.y());
0534
0535
0536
0537 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_], cross_framepoint);
0538
0539
0540
0541 g_temp->SetPoint(0, vtrack[i]->dca_mean[0], vtrack[i]->dca_mean[1]);
0542 g_temp->SetPoint(1, vtrack[i]->p1.x(), vtrack[i]->p1.y());
0543 g_temp->SetPoint(2, vtrack[i]->p2.x(), vtrack[i]->p2.y());
0544
0545
0546 }
0547
0548 g_temp->Draw("Psame");
0549 color_++;
0550 }
0551 }
0552 void draw_truthcurve(int mode = 0, bool does_overlay = false, int color = kBlack, bool only_far_cluster = false, bool only_far_track = false)
0553 {
0554 for (unsigned int i = 0; i < vtruth.size(); i++)
0555 {
0556 if (vtruth[i]->is_intt == false)
0557 continue;
0558
0559 if (vtruth[i]->is_charged == false)
0560 continue;
0561
0562 if (vtruth[i]->have_track == true && only_far_track)
0563 continue;
0564
0565 if (vtruth[i]->have_cluster == true && only_far_cluster)
0566 continue;
0567
0568 TGraph *g_temp = new TGraph();
0569 g_temp->SetMarkerColor(color);
0570 g_temp->SetLineColor(color);
0571 g_temp->SetMarkerStyle(20);
0572 g_temp->SetMarkerSize(0.8);
0573
0574 if (mode == 0)
0575 {
0576 vector<double> cross_framepoint = get_crossframe(vtruth[i]->center[0], vtruth[i]->center[1], vtruth[i]->m_rad, vtruth[i]->m_truthpx, vtruth[i]->m_truthpy);
0577 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, cross_framepoint);
0578
0579 g_temp->SetPoint(0, vtruth[i]->m_xvtx, vtruth[i]->m_yvtx);
0580 }
0581
0582 g_temp->Draw("Psame");
0583 }
0584 }
0585
0586 void draw_truthline(int mode = 0, bool does_overlay = false, int color = kBlack, bool only_far_cluster = false, bool only_far_track = false)
0587 {
0588 for (unsigned int i = 0; i < vtruth.size(); i++)
0589 {
0590 if (vtruth[i]->is_intt == false)
0591 continue;
0592
0593 if (vtruth[i]->is_charged == false)
0594 continue;
0595
0596 if (vtruth[i]->have_track == true && only_far_track)
0597 continue;
0598
0599 if (vtruth[i]->have_cluster == true && only_far_cluster)
0600 continue;
0601
0602 TGraph *g_temp = new TGraph();
0603 g_temp->SetMarkerColor(color);
0604 g_temp->SetLineColor(color);
0605 g_temp->SetMarkerStyle(20);
0606 g_temp->SetMarkerSize(0.8);
0607
0608 if (mode == 0)
0609 {
0610 vtruth[i]->truth_xy->SetLineColorAlpha(color, 0.8);
0611 vtruth[i]->truth_xy->SetLineStyle(9);
0612 vtruth[i]->truth_xy->SetLineWidth(3);
0613
0614 if (vtruth[i]->m_truthpx > 0)
0615 {
0616 vtruth[i]->truth_xy->SetRange(vtruth[i]->m_xvtx, 15);
0617 }
0618 else
0619 {
0620 vtruth[i]->truth_xy->SetRange(-15, vtruth[i]->m_xvtx);
0621 }
0622 vtruth[i]->truth_xy->Draw("Lsame");
0623
0624 g_temp->SetPoint(0, vtruth[i]->m_xvtx, vtruth[i]->m_yvtx);
0625 }
0626 else if (mode == 1)
0627 {
0628 vtruth[i]->truth_rz->SetLineColorAlpha(color, 0.8);
0629 vtruth[i]->truth_rz->SetLineStyle(9);
0630 vtruth[i]->truth_rz->SetLineWidth(3);
0631
0632 int y = 0;
0633 if (vtruth[i]->m_truthpy > 0)
0634 y = 15;
0635 else
0636 y = -15;
0637 double r_min = vtruth[i]->truth_rz->GetX(vtruth[i]->getpointr(3));
0638 double r_max = vtruth[i]->truth_rz->GetX(y);
0639 if (r_min < r_max)
0640 vtruth[i]->truth_rz->SetRange(r_min, r_max);
0641 else
0642 vtruth[i]->truth_rz->SetRange(r_max, r_min);
0643
0644 vtruth[i]->truth_rz->Draw("Lsame");
0645 g_temp->SetPoint(0, vtruth[i]->m_zvtx, vtruth[i]->getpointr(3));
0646 }
0647 g_temp->Draw("Psame");
0648 }
0649 }
0650
0651 void draw_clusters(int mode = 0, bool does_overlay = false, int color = kBlack)
0652 {
0653 for (unsigned int i = 0; i < vclus.size(); i++)
0654 {
0655 TGraph *g_temp = new TGraph();
0656 g_temp->SetMarkerColorAlpha(color, 0.5);
0657
0658 g_temp->SetMarkerStyle(20);
0659 g_temp->SetMarkerSize(0.8);
0660 TLine *line = new TLine(vclus[i].zline[0], vclus[i].r, vclus[i].zline[1], vclus[i].r);
0661 line->SetLineColorAlpha(color, 0.5);
0662 line->SetLineWidth(3);
0663
0664 if (mode == 0)
0665 {
0666 g_temp->SetPoint(0, vclus[i].x, vclus[i].y);
0667 g_temp->Draw("psame");
0668 }
0669 else if (mode == 1)
0670 {
0671 line->Draw("same");
0672
0673 }
0674
0675 }
0676 }
0677
0678
0679
0680
0681
0682
0683
0684
0685
0686
0687
0688
0689
0690
0691
0692 vector<double> get_crosspoint(const vector<double> &V, double cx, double cy, double rad, double p1_x, double p1_y)
0693 {
0694 vector<double> cross;
0695 double a = V[0];
0696 double b = V[1];
0697 double c = V[2];
0698
0699 double d = fabs(a * cx + b * cy + c) / sqrt(a * a + b * b);
0700
0701
0702 double theta = atan2(b, a);
0703
0704 if (d > rad)
0705 {
0706
0707 }
0708 else if (d == rad)
0709 {
0710
0711
0712 if (a * cx + b * cy + c > 0)
0713 theta += M_PI;
0714 cross.push_back(rad * cos(theta) + cx);
0715 cross.push_back(rad * sin(theta) + cy);
0716 }
0717 else
0718 {
0719
0720 double alpha, beta, phi;
0721 phi = acos(d / rad);
0722 alpha = theta - phi;
0723 beta = theta + phi;
0724 if (a * cx + b * cy + c > 0)
0725 {
0726 alpha += M_PI;
0727 beta += M_PI;
0728 }
0729
0730 vector<vector<double>> temp_cross = {{rad * cos(alpha) + cx, rad * cos(beta) + cx}, {rad * sin(alpha) + cy, rad * sin(beta) + cy}};
0731
0732
0733
0734
0735
0736
0737
0738 cross = get_closestpoint(temp_cross, p1_x, p1_y);
0739 }
0740
0741
0742
0743 return cross;
0744 }
0745
0746 vector<double> get_closestpoint(const vector<vector<double>> VV, double p1_x, double p1_y)
0747 {
0748 vector<double> closest;
0749 double pre_phi = 999;
0750 double phi_p1 = atan2(p1_y - dca_mean[1], p1_x - dca_mean[0]);
0751 for (unsigned int i = 0; i < VV.at(0).size(); i++)
0752 {
0753
0754
0755
0756
0757
0758 double dot = (VV[0][i] - dca_mean[0]) * (p1_x - dca_mean[0]) + (VV[1][i] - dca_mean[1]) * (p1_y - dca_mean[1]);
0759 double temp_phi = atan2(VV[1][i] - dca_mean[1], VV[0][i] - dca_mean[0]);
0760
0761 if (dot > 0)
0762 {
0763 if (fabs(temp_phi - phi_p1) < fabs(pre_phi - phi_p1))
0764 {
0765 closest.erase(closest.begin(), closest.end());
0766
0767 for (int j = 0; j < 2; j++)
0768 closest.push_back(VV[j][i]);
0769 pre_phi = temp_phi;
0770 }
0771 }
0772 }
0773
0774
0775
0776
0777
0778
0779
0780
0781
0782 return closest;
0783 }
0784
0785 vector<double> get_crossframe(double cx, double cy, double rad, double p1_x, double p1_y)
0786 {
0787
0788
0789 double size = 15;
0790 vector<vector<double>> crossframe(2, vector<double>(0));
0791 for (int j = 0; j < 2; j++)
0792 {
0793 for (int i = 0; i < 2; i++)
0794 {
0795 double a_ = (j == 0) ? 1 : 0;
0796 double b_ = (j == 0) ? 0 : 1;
0797 double c_ = (2 * i - 1) * size;
0798
0799 vector<double> co_ = {a_, b_, c_};
0800 vector<double> temp_crossframe = get_crosspoint(co_, cx, cy, rad, p1_x, p1_y);
0801 if (temp_crossframe.size() == 2)
0802 {
0803
0804 crossframe.at(0).push_back(temp_crossframe[0]);
0805 crossframe.at(1).push_back(temp_crossframe[1]);
0806 }
0807 }
0808 }
0809
0810
0811 for (int j = 0; j < crossframe.at(0).size(); j++)
0812 {
0813 for (int i = 0; i < crossframe.size(); i++)
0814 {
0815
0816 }
0817
0818 }
0819 vector<double> result;
0820 if (crossframe.at(0).size() != 0)
0821 result = get_closestpoint(crossframe, p1_x, p1_y);
0822
0823 for (int i = 0; i < result.size(); i++)
0824 {
0825
0826 }
0827
0828
0829
0830 return result;
0831 }
0832 };
0833
0834 template <class D>
0835 void erase(vector<D> &vec)
0836 {
0837 vec.erase(vec.begin(), vec.end());
0838 }
0839
0840 template <class D>
0841 void reverse(vector<D> &vec)
0842 {
0843 reverse(vec.begin(), vec.end());
0844 }
0845
0846 bool dotracking(clustEvent &vCluster)
0847 {
0848 for (unsigned int i = 0; i < vCluster.vclus.size(); i++)
0849 {
0850 cluster c1 = vCluster.vclus[i];
0851 if (2 <= c1.layer)
0852 continue;
0853
0854 for (unsigned int j = i + 1; j < vCluster.vclus.size(); j++)
0855 {
0856 cluster c2 = vCluster.vclus[j];
0857 if (c2.layer <= 1)
0858 continue;
0859
0860 TVector3 beamspot = {vCluster.dca_mean[0], vCluster.dca_mean[1], 0};
0861
0862
0863 TVector3 p1 = c1.pos - beamspot;
0864 TVector3 p2 = c2.pos - beamspot;
0865
0866 double p1_phi = atan2(p1.y(), p1.x());
0867 double p2_phi = atan2(p2.y(), p2.x());
0868 double d_phi = p2_phi - p1_phi;
0869 d_phi -= -2 * (M_PI * (int)(d_phi / (M_PI)));
0870
0871 double p1_r = sqrt(p1.x() * p1.x() + p1.y() * p1.y());
0872 double p2_r = sqrt(p2.x() * p2.x() + p2.y() * p2.y());
0873 double p1_theta = atan2(p1_r, p1.z());
0874 double p2_theta = atan2(p2_r, p2.z());
0875 double d_theta = p2_theta - p1_theta;
0876 if (n_dotracking == 1)
0877 h_dphi_nocut->Fill(p1_phi, d_phi);
0878
0879 if (fabs(d_phi) > 0.04)
0880 continue;
0881
0882 TVector3 u = p2 - p1;
0883 double unorm = sqrt(u.x() * u.x() + u.y() * u.y());
0884
0885 double ux = u.x() / unorm;
0886 double uy = u.y() / unorm;
0887 double uz = u.z() / unorm;
0888
0889 TVector3 p0 = beamspot - p1;
0890
0891 double dca_p0 = p0.x() * uy - p0.y() * ux;
0892 double len_p0 = p0.x() * ux + p0.y() * uy;
0893
0894
0895 double vx = len_p0 * ux + p1.x();
0896 double vy = len_p0 * uy + p1.y();
0897 double vz = len_p0 * uz + p1.z();
0898
0899 track *tr = new track();
0900 tr->phi_in = p1_phi;
0901 tr->phi_out = p2_phi;
0902 tr->theta_in = c1.gettheta_clus();
0903 tr->theta_out = c2.gettheta_clus();
0904 tr->d_phi = d_phi;
0905 tr->d_theta = d_theta;
0906 tr->charge = dca_p0 / fabs(dca_p0);
0907
0908 tr->dca[0] = vx;
0909 tr->dca[1] = vy;
0910 tr->dca[2] = vz;
0911
0912 tr->p1 = c1.pos;
0913 tr->p2 = c2.pos;
0914
0915 tr->zline.at(0) = c1.zline;
0916 tr->zline.at(1) = c2.zline;
0917
0918 tr->dca_2d = dca_p0;
0919 vCluster.vtrack.push_back(tr);
0920 }
0921 }
0922
0923 return true;
0924 }
0925
0926 void tracking_pT(int run_no = 41981, bool mag_on = true, bool debug = false )
0927 {
0928 int sigma = 3;
0929 int nloop = 60;
0930
0931 bool geant = false;
0932 if (run_no == 1)
0933 geant = true;
0934
0935 bool does_reverse = false;
0936
0937
0938 string data_dir = "/sphenix/u/nukazuka/work_now/analysis/tracking/hinakos/work/F4AInttRead/macro/";
0939 string fname = data_dir + Form("InttAna_run%d.root", run_no);
0940
0941
0942
0943
0944
0945
0946
0947 if (geant)
0948 {
0949 if (mag_on)
0950 {
0951
0952 fname = "/sphenix/tg/tg01/commissioning/INTT/work/tsujibata/tracking/F4AInttRead/macro/macros/detectors/sPHENIX/AnaTutorial_inttana_zvtxwidth10_ptmin0.root";
0953
0954 }
0955
0956 else
0957 {
0958 fname = "/sphenix/tg/tg01/commissioning/INTT/work/tsujibata/tracking/F4AInttRead/macro/macros/detectors/sPHENIX/AnaTutorial_inttana_vtx0.root";
0959
0960
0961
0962
0963 }
0964 }
0965
0966 TFile *f = TFile::Open(fname.c_str());
0967 cout << "opened file : " << fname << endl;
0968
0969 string dir_out = "results/tracking/";
0970 TString fname_out = "tracking_run" + to_string( run_no ) + ".root";
0971
0972
0973
0974
0975
0976
0977
0978
0979
0980 fname_out = dir_out + fname_out;
0981 cout << "out put file : " << fname_out << endl;
0982
0983 TH1F *h_dcaz_one_ = new TH1F("h_dcaz_one_", "", 100, -200, 200);
0984
0985 TFile *froot = new TFile(fname_out, "recreate");
0986 TH1F *h_nclus = new TH1F("h_nclus", "", 100, 0, 100);
0987
0988 TTree *temp_tree_ = new TTree("temp_tree_", "temp_tree_");
0989 TTree *clus_tree = new TTree("clus_tree", "clus_tree");
0990 TTree *truth_tree = new TTree("truth_tree", "truth_tree");
0991 TTree *track_tree = new TTree("track_tree", "track_tree");
0992
0993 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);
0994
0995 TH1F *h_dcaz_sigma_one = new TH1F("h_dcaz_sigma_one", "h_dcaz_sigma_one;dca_z sigma of one event;entries", 100, 0, 15);
0996 TH1D *h_xvtx = new TH1D("h_xvtx", "h_xvtx", 100, -0.01, 0.01);
0997 TH1D *h_yvtx = new TH1D("h_yvtx", "h_yvtx", 100, -0.01, 0.01);
0998 TH1D *h_zvtx = new TH1D("h_zvtx", "h_zvtx", 100, -20, 20);
0999 TH2D *h_zr[2];
1000 for (int i = 0; i < 2; i++)
1001 h_zr[i] = new TH2D(Form("h_zr_%d", i), "h_zr;z;r", 100, -20, 20, 100, -10, 10);
1002
1003 c = new TCanvas(fname_out.ReplaceAll(".root", ".pdf"), "c", 1200, 600);
1004 c->Divide(2, 1);
1005 c->cd(1);
1006
1007 int page_counter = 0;
1008 c->Print(((string)c->GetName() + "[").c_str());
1009
1010 int evt_temp_;
1011 vector<double> d_phi_;
1012 vector<double> d_theta_;
1013 vector<double> phi_in_;
1014 vector<double> dca_x_;
1015 vector<double> dca_y_;
1016 vector<double> dca_z_;
1017 vector<double> dca_2d_;
1018 double zvtx_one_;
1019 double zvtx_sigma_one_;
1020 temp_tree_->Branch("evt_temp_", &evt_temp_, "evt_temp_/I");
1021 temp_tree_->Branch("d_phi_", &d_phi_);
1022 temp_tree_->Branch("d_theta_", &d_theta_);
1023 temp_tree_->Branch("phi_in_", &phi_in_);
1024 temp_tree_->Branch("dca_x_", &dca_x_);
1025 temp_tree_->Branch("dca_y_", &dca_y_);
1026 temp_tree_->Branch("dca_z_", &dca_z_);
1027 temp_tree_->Branch("dca_2d_", &dca_2d_);
1028 temp_tree_->Branch("zvtx_one_", &zvtx_one_, "zvtx_one_/D");
1029 temp_tree_->Branch("zvtx_sigma_one_", &zvtx_sigma_one_, "zvtx_sigma_one_/D");
1030
1031 int evt_clus;
1032 vector<double> x_in;
1033 vector<double> y_in;
1034 vector<double> z_in;
1035 vector<double> r_in;
1036 vector<double> phi_in;
1037 vector<double> theta_in;
1038 vector<double> x_out;
1039 vector<double> y_out;
1040 vector<double> z_out;
1041 vector<double> r_out;
1042 vector<double> phi_out;
1043 vector<double> theta_out;
1044 clus_tree->Branch("evt_clus", &evt_clus, "evt_clus/I");
1045 clus_tree->Branch("x_in", &x_in);
1046 clus_tree->Branch("y_in", &y_in);
1047 clus_tree->Branch("z_in", &z_in);
1048 clus_tree->Branch("r_in", &r_in);
1049 clus_tree->Branch("phi_in", &phi_in);
1050 clus_tree->Branch("theta_in", &theta_in);
1051 clus_tree->Branch("x_out", &x_out);
1052 clus_tree->Branch("y_out", &y_out);
1053 clus_tree->Branch("z_out", &z_out);
1054 clus_tree->Branch("r_out", &r_out);
1055 clus_tree->Branch("phi_out", &phi_out);
1056 clus_tree->Branch("theta_out", &theta_out);
1057
1058 int evt_track;
1059 int ntrack = 0;
1060 vector<double> slope_rz;
1061 vector<double> phi_tracklets;
1062 vector<double> theta_tracklets;
1063 vector<double> phi_track;
1064 vector<double> theta_track;
1065 vector<double> z_tracklets_out;
1066 vector<double> dca_2d;
1067 vector<double> dca_z;
1068 vector<int> is_deleted;
1069 vector<int> dca_range_out;
1070 vector<int> dca2d_range_out;
1071 vector<int> dcaz_range_out;
1072 vector<double> pT;
1073 vector<double> px_truth;
1074 vector<double> py_truth;
1075 vector<double> pz_truth;
1076 vector<double> px;
1077 vector<double> py;
1078 vector<double> pz;
1079 vector<double> rad;
1080 vector<double> pT_truth;
1081 vector<double> charge;
1082 double x_vertex;
1083 double y_vertex;
1084 double z_vertex;
1085 track_tree->Branch("evt_track", &evt_track, "evt_track/I");
1086 track_tree->Branch("ntrack", &ntrack, "ntrack/I");
1087 track_tree->Branch("phi_tracklets", &phi_tracklets);
1088 track_tree->Branch("slope_rz", &slope_rz);
1089 track_tree->Branch("theta_tracklets", &theta_tracklets);
1090 track_tree->Branch("phi_track", &phi_track);
1091 track_tree->Branch("theta_track", &theta_track);
1092 track_tree->Branch("z_tracklets_out", &z_tracklets_out);
1093 track_tree->Branch("dca_2d", &dca_2d);
1094 track_tree->Branch("dca_z", &dca_z);
1095 track_tree->Branch("is_deleted", &is_deleted);
1096 track_tree->Branch("dca_range_out", &dca_range_out);
1097 track_tree->Branch("dcaz_range_out", &dcaz_range_out);
1098 track_tree->Branch("dca2d_range_out", &dca2d_range_out);
1099 track_tree->Branch("pT", &pT);
1100 track_tree->Branch("px", &px);
1101 track_tree->Branch("py", &py);
1102 track_tree->Branch("pz", &pz);
1103 track_tree->Branch("px_truth", &px_truth);
1104 track_tree->Branch("py_truth", &py_truth);
1105 track_tree->Branch("pz_truth", &pz_truth);
1106 track_tree->Branch("pT_truth", &pT_truth);
1107 track_tree->Branch("charge", &charge);
1108 track_tree->Branch("rad", &rad);
1109 track_tree->Branch("x_vertex", &x_vertex, "x_vertex/D");
1110 track_tree->Branch("y_vertex", &y_vertex, "y_vertex/D");
1111 track_tree->Branch("z_vertex", &z_vertex, "z_vertex/D");
1112
1113 int evt_truth;
1114 int ntruth = 0;
1115 int ntruth_cut = 0;
1116 vector<double> truthpx;
1117 vector<double> truthpy;
1118 vector<double> truthpz;
1119 vector<double> truthpt;
1120 vector<double> trutheta;
1121 vector<double> truththeta;
1122 vector<double> truthphi;
1123 vector<double> truthxvtx;
1124 vector<double> truthyvtx;
1125 vector<double> truthzvtx;
1126 vector<double> truthzout;
1127 vector<int> truthpid;
1128 vector<int> status;
1129 truth_tree->Branch("evt_truth", &evt_truth, "evt_truth/I");
1130 truth_tree->Branch("ntruth_cut", &ntruth_cut, "ntruth_cut/I");
1131 truth_tree->Branch("truthpx", &truthpx);
1132 truth_tree->Branch("truthpy", &truthpy);
1133 truth_tree->Branch("truthpz", &truthpz);
1134 truth_tree->Branch("truthpt", &truthpt);
1135 truth_tree->Branch("trutheta", &trutheta);
1136 truth_tree->Branch("truththeta", &truththeta);
1137 truth_tree->Branch("truthphi", &truthphi);
1138 truth_tree->Branch("truthxvtx", &truthxvtx);
1139 truth_tree->Branch("truthyvtx", &truthyvtx);
1140 truth_tree->Branch("truthzvtx", &truthzvtx);
1141 truth_tree->Branch("truthzout", &truthzout);
1142 truth_tree->Branch("truthpid", &truthpid);
1143 truth_tree->Branch("status", &status);
1144
1145
1146 TNtuple *ntp_clus = (TNtuple *)f->Get("ntp_clus");
1147 TTree *hepmctree = (TTree *)f->Get("hepmctree");
1148 bool no_mc = true;
1149 if( hepmctree == nullptr )
1150 no_mc = true;
1151 else if( hepmctree->GetEntries() == 0 )
1152 no_mc = true;
1153
1154 cout << "no_mc : " << no_mc << endl;
1155
1156 Float_t nclus, nclus2, bco_full, evt, size, adc, x, y, z, lay, lad, sen, x_vtx, y_vtx, z_vtx;
1157
1158 ntp_clus->SetBranchAddress("nclus", &nclus);
1159 ntp_clus->SetBranchAddress("nclus2", &nclus2);
1160 ntp_clus->SetBranchAddress("bco_full", &bco_full);
1161 ntp_clus->SetBranchAddress("evt", &evt);
1162 ntp_clus->SetBranchAddress("size", &size);
1163 ntp_clus->SetBranchAddress("adc", &adc);
1164 ntp_clus->SetBranchAddress("x", &x);
1165 ntp_clus->SetBranchAddress("y", &y);
1166 ntp_clus->SetBranchAddress("z", &z);
1167 ntp_clus->SetBranchAddress("lay", &lay);
1168 ntp_clus->SetBranchAddress("lad", &lad);
1169 ntp_clus->SetBranchAddress("sen", &sen);
1170 ntp_clus->SetBranchAddress("x_vtx", &x_vtx);
1171 ntp_clus->SetBranchAddress("y_vtx", &y_vtx);
1172 ntp_clus->SetBranchAddress("z_vtx", &z_vtx);
1173
1174 double m_truthpx, m_truthpy, m_truthpz, m_truthpt, m_trutheta, m_truththeta, m_truthphi, m_xvtx, m_yvtx, m_zvtx;
1175 int m_evt, m_status, m_truthpid;
1176
1177 hepmctree->SetBranchAddress("m_evt", &m_evt);
1178 hepmctree->SetBranchAddress("m_status", &m_status);
1179 hepmctree->SetBranchAddress("m_truthpx", &m_truthpx);
1180 hepmctree->SetBranchAddress("m_truthpy", &m_truthpy);
1181 hepmctree->SetBranchAddress("m_truthpz", &m_truthpz);
1182 hepmctree->SetBranchAddress("m_truthpt", &m_truthpt);
1183 hepmctree->SetBranchAddress("m_trutheta", &m_trutheta);
1184 hepmctree->SetBranchAddress("m_truthpid", &m_truthpid);
1185 hepmctree->SetBranchAddress("m_truththeta", &m_truththeta);
1186 hepmctree->SetBranchAddress("m_truthphi", &m_truthphi);
1187 hepmctree->SetBranchAddress("m_xvtx", &m_xvtx);
1188 hepmctree->SetBranchAddress("m_yvtx", &m_yvtx);
1189 hepmctree->SetBranchAddress("m_zvtx", &m_zvtx);
1190
1191 int sum_event = 0;
1192 int ntrack_ = 0;
1193 for (int icls = 0; icls < ntp_clus->GetEntries(); icls++)
1194 {
1195 cout << Form(" ----- event %d {event gene.} ----- ", sum_event) << endl;
1196
1197 clustEvent event{};
1198 cluster clust{};
1199
1200 ntp_clus->GetEntry(icls);
1201 clust.set(evt, 0, x, y, z, adc, size, lay, x_vtx, y_vtx, z_vtx);
1202 event.vclus.push_back(clust);
1203
1204 for (int j = 1; j < nclus; j++)
1205 {
1206 ntp_clus->GetEntry(++icls);
1207 cluster clust2{};
1208 clust2.set(evt, 0, x, y, z, adc, size, lay, x_vtx, y_vtx, z_vtx);
1209 event.vclus.push_back(clust2);
1210 }
1211
1212 dotracking(event);
1213 ntrack_ = event.vtrack.size();
1214 h_dcaz_one_->Reset();
1215 for (int itrk = 0; itrk < ntrack_; itrk++)
1216 {
1217 h_dcaz_one_->Fill(event.vtrack[itrk]->dca[2]);
1218 }
1219 zvtx_one_ = h_dcaz_one_->GetMean();
1220 zvtx_sigma_one_ = h_dcaz_one_->GetStdDev();
1221
1222 evt_temp_ = sum_event;
1223 for (int itrk = 0; itrk < ntrack_; itrk++)
1224 {
1225 dca_x_.push_back(event.vtrack[itrk]->dca[0]);
1226 dca_y_.push_back(event.vtrack[itrk]->dca[1]);
1227 dca_z_.push_back(event.vtrack[itrk]->dca[2]);
1228 dca_2d_.push_back(event.vtrack[itrk]->dca_2d);
1229 d_phi_.push_back(event.vtrack[itrk]->d_phi);
1230 d_theta_.push_back(event.vtrack[itrk]->d_theta);
1231 phi_in_.push_back(event.vtrack[itrk]->phi_in);
1232 }
1233 if (does_reverse)
1234 {
1235 reverse(dca_x_);
1236 reverse(dca_y_);
1237 reverse(dca_z_);
1238 reverse(dca_2d_);
1239 reverse(d_phi_);
1240 reverse(d_theta_);
1241 reverse(phi_in_);
1242 }
1243 temp_tree_->Fill();
1244 erase(dca_x_);
1245 erase(dca_y_);
1246 erase(dca_z_);
1247 erase(dca_2d_);
1248 erase(d_phi_);
1249 erase(d_theta_);
1250 erase(phi_in_);
1251
1252 event.clear();
1253 sum_event++;
1254
1255 if (debug && sum_event > nloop)
1256 break;
1257 }
1258 n_dotracking++;
1259 TH1F *h_dcax = new TH1F("h_dcax", "h_dcax", 100, -0.4, 0.4);
1260 temp_tree_->Draw("dca_x_>>h_dcax");
1261 TH1F *h_dcay = new TH1F("h_dcay", "h_dcay", 100, -0.4, 0.4);
1262 temp_tree_->Draw("dca_y_>>h_dcay");
1263 TH1F *h_dcaz = new TH1F("h_dcaz", "h_dcaz;DCA_z[cm]", 60, -150, 150);
1264 temp_tree_->Draw("dca_z_>>h_dcaz");
1265 TH1F *h_dtheta = new TH1F("h_dtheta", "dtheta{inner - outer};dtheta;entries", 100, -3.2, 3.2);
1266 temp_tree_->Draw("d_theta_>>h_dtheta");
1267 TH1F *h_dphi = new TH1F("h_dphi", "#Delta #phi_{AB};#Delta #phi_{AB}", 100, -1, 1);
1268 temp_tree_->Draw("d_phi_>>h_dphi");
1269
1270 TH1F *h_dca2d = new TH1F("h_dca2d", "h_dca", 100, -10, 10);
1271 temp_tree_->Draw("dca_2d_>>h_dca2d");
1272
1273 vector<TH1F *> h_ = {h_dcax, h_dcay, h_dcaz, h_dphi, h_dtheta, h_dca2d};
1274
1275
1276 double dcax_mean = h_dcax->GetMean();
1277 double dcay_mean = h_dcay->GetMean();
1278 if (!(geant))
1279 {
1280 dcax_mean = -0.019;
1281 dcay_mean = 0.198;
1282 }
1283 double dcaz_mean = h_dcaz->GetMean();
1284 double dca2d_mean = h_dca2d->GetMean();
1285
1286 double dcax_sigma = h_dcax->GetStdDev();
1287 double dcay_sigma = h_dcay->GetStdDev();
1288 double dcaz_sigma = h_dcaz->GetStdDev();
1289 double dca2d_sigma = h_dca2d->GetStdDev();
1290
1291 dca2d_sigma *= sigma;
1292 dcaz_sigma *= sigma;
1293
1294 double dca2d_max = dca2d_mean + dca2d_sigma;
1295 double dca2d_min = dca2d_mean - dca2d_sigma;
1296 double dcaz_max = dcaz_mean + dcaz_sigma;
1297 double dcaz_min = dcaz_mean - dcaz_sigma;
1298
1299
1300 int ihit = 0;
1301 int itruth = 0;
1302 int temp_evt = 0;
1303
1304 for (int ievt = 0; ievt < 100; ievt++, ihit++, itruth++)
1305 {
1306 temp_tree_->GetEntry(ievt);
1307 cout << Form(" ----- event %d ----- ", ievt) << endl;
1308 ntruth = 0;
1309 ntruth_cut = 0;
1310
1311 clustEvent event;
1312 event.ievt = ievt;
1313 event.mag_on = mag_on;
1314 event.run_no = run_no;
1315
1316
1317 if (ihit < ntp_clus->GetEntries())
1318 {
1319 ntp_clus->GetEntry(ihit);
1320
1321 if (!(no_mc))
1322 {
1323 hepmctree->GetEntry(itruth);
1324 while (m_evt != evt)
1325 {
1326 itruth++;
1327 hepmctree->GetEntry(itruth);
1328 }
1329 temp_evt = m_evt;
1330 }
1331 cluster clust{};
1332
1333 clust.set(evt, 0, x, y, z, adc, size, lay, x_vtx, y_vtx, z_vtx);
1334 event.vclus.push_back(clust);
1335
1336 for (int j = 1; j < nclus; j++)
1337 {
1338 ntp_clus->GetEntry(++ihit);
1339 cluster clust2{};
1340
1341 clust2.set(evt, 0, x, y, z, adc, size, lay, x_vtx, y_vtx, z_vtx);
1342 event.vclus.push_back(clust2);
1343 }
1344
1345 if (!(no_mc))
1346 {
1347 while (m_evt == temp_evt)
1348 {
1349 ntruth++;
1350 truth *tru = new truth();
1351 tru->set_truth(m_truthpx, m_truthpy, m_truthpz, m_truthpt, m_status, m_trutheta, m_truthpid, m_truththeta, m_truthphi, m_xvtx, m_yvtx, m_zvtx);
1352 event.vtruth.push_back(tru);
1353 itruth++;
1354 if (itruth == hepmctree->GetEntries())
1355 break;
1356
1357 hepmctree->GetEntry(itruth);
1358 }
1359 itruth--;
1360 }
1361 }
1362
1363 event.dca_mean[0] = dcax_mean;
1364 event.dca_mean[1] = dcay_mean;
1365 event.dca_mean[2] = zvtx_one_;
1366
1367
1368 dotracking(event);
1369 ntrack_ = event.vtrack.size();
1370 evt_clus = ievt;
1371 evt_track = ievt;
1372 evt_truth = ievt;
1373 h_dcaz_one_->Reset();
1374 for (int itrk = 0; itrk < ntrack_; itrk++)
1375 {
1376 h_dcaz_one_->Fill(event.vtrack[itrk]->dca[2]);
1377 }
1378 double dcaz_mean_one = h_dcaz_one_->GetMean();
1379 double dcaz_sigma_one = h_dcaz_one_->GetStdDev();
1380 h_dcaz_sigma_one->Fill(dcaz_sigma_one);
1381 dcaz_sigma_one *= sigma;
1382 double dcaz_max_one = dcaz_mean_one + dcaz_sigma;
1383 double dcaz_min_one = dcaz_mean_one - dcaz_sigma;
1384 zvtx_sigma_one_ *= sigma;
1385
1386
1387
1388 event.dca2d_max = dca2d_max;
1389 event.dca2d_min = dca2d_min;
1390 event.dcaz_max = dcaz_max_one;
1391 event.dcaz_min = dcaz_min_one;
1392
1393 if (!(no_mc))
1394 {
1395 for (int itrt = 0; itrt < ntruth; itrt++)
1396 {
1397 event.vtruth[itrt]->dca_mean[0] = dcax_mean;
1398 event.vtruth[itrt]->dca_mean[1] = dcay_mean;
1399 event.vtruth[itrt]->dca_mean[2] = dcaz_mean_one;
1400
1401 event.vtruth[itrt]->calc_line();
1402 event.vtruth[itrt]->calc_center();
1403 }
1404 }
1405 h_nclus->Fill(event.vclus.size());
1406
1407 for (int iclus = 0; iclus < event.vclus.size(); iclus++)
1408 {
1409 event.vclus[iclus].dca_mean[0] = dcax_mean;
1410 event.vclus[iclus].dca_mean[1] = dcay_mean;
1411 event.vclus[iclus].dca_mean[2] = dcaz_mean_one;
1412
1413 if (event.vclus[iclus].layer < 2)
1414 {
1415 x_in.push_back(event.vclus[iclus].x);
1416 y_in.push_back(event.vclus[iclus].y);
1417 z_in.push_back(event.vclus[iclus].z);
1418 r_in.push_back(event.vclus[iclus].r);
1419 phi_in.push_back(event.vclus[iclus].getphi_clus());
1420 theta_in.push_back(event.vclus[iclus].gettheta_clus());
1421 }
1422 if (1 < event.vclus[iclus].layer)
1423 {
1424 x_out.push_back(event.vclus[iclus].x);
1425 y_out.push_back(event.vclus[iclus].y);
1426 z_out.push_back(event.vclus[iclus].z);
1427 r_out.push_back(event.vclus[iclus].r);
1428 phi_out.push_back(event.vclus[iclus].getphi_clus());
1429 theta_out.push_back(event.vclus[iclus].gettheta_clus());
1430 }
1431 }
1432 if (does_reverse)
1433 {
1434 reverse(x_out);
1435 reverse(y_out);
1436 reverse(z_out);
1437 reverse(r_out);
1438 reverse(phi_out);
1439 reverse(theta_out);
1440
1441 reverse(x_in);
1442 reverse(y_in);
1443 reverse(z_in);
1444 reverse(r_in);
1445 reverse(phi_in);
1446 reverse(theta_in);
1447 }
1448 clus_tree->Fill();
1449 erase(x_in);
1450 erase(y_in);
1451 erase(z_in);
1452 erase(r_in);
1453 erase(phi_in);
1454 erase(theta_in);
1455 erase(x_out);
1456 erase(y_out);
1457 erase(z_out);
1458 erase(r_out);
1459 erase(phi_out);
1460 erase(theta_out);
1461
1462 for (int itrk = 0; itrk < ntrack_; itrk++)
1463 {
1464 event.vtrack[itrk]->dca_mean[0] = dcax_mean;
1465 event.vtrack[itrk]->dca_mean[1] = dcay_mean;
1466 event.vtrack[itrk]->dca_mean[2] = dcaz_mean_one;
1467 event.vtrack[itrk]->calc_line();
1468 event.vtrack[itrk]->calc_inv();
1469 event.vtrack[itrk]->calc_pT();
1470 }
1471 event.dca_check(debug);
1472 event.makeonetrack();
1473
1474 event.charge_check();
1475 event.truth_check();
1476
1477 event.cluster_check();
1478 event.track_check();
1479 ntrack = 0;
1480 for (int itrk = 0; itrk < ntrack_; itrk++)
1481 {
1482 slope_rz.push_back(event.vtrack[itrk]->track_rz->GetParameter(1));
1483 phi_tracklets.push_back(event.vtrack[itrk]->getphi_tracklet());
1484 theta_tracklets.push_back(event.vtrack[itrk]->gettheta_tracklet());
1485 phi_track.push_back(event.vtrack[itrk]->getphi());
1486 theta_track.push_back(event.vtrack[itrk]->gettheta());
1487 dca_z.push_back(event.vtrack[itrk]->dca[2]);
1488 dca_2d.push_back(event.vtrack[itrk]->dca_2d);
1489 z_tracklets_out.push_back(event.vtrack[itrk]->p2.z());
1490 pT.push_back(event.vtrack[itrk]->pT);
1491 px.push_back(event.vtrack[itrk]->p_reco[0]);
1492 py.push_back(event.vtrack[itrk]->p_reco[1]);
1493 pz.push_back(event.vtrack[itrk]->p_reco[2]);
1494 rad.push_back(event.vtrack[itrk]->rad);
1495 charge.push_back(event.vtrack[itrk]->charge);
1496 if (!(no_mc))
1497 {
1498 pT_truth.push_back(event.vtruth[0]->m_truthpt);
1499 px_truth.push_back(event.vtruth[0]->m_truthpx);
1500 py_truth.push_back(event.vtruth[0]->m_truthpy);
1501 pz_truth.push_back(event.vtruth[0]->m_truthpz);
1502 }
1503
1504 is_deleted.push_back(event.vtrack[itrk]->is_deleted);
1505 dca2d_range_out.push_back(event.vtrack[itrk]->dca2d_range_out);
1506 dcaz_range_out.push_back(event.vtrack[itrk]->dcaz_range_out);
1507 dca_range_out.push_back(event.vtrack[itrk]->dca_range_out);
1508
1509 x_vertex = event.vtrack[itrk]->dca_mean[0];
1510 y_vertex = event.vtrack[itrk]->dca_mean[1];
1511 z_vertex = event.vtrack[itrk]->dca_mean[2];
1512
1513 if (event.vtrack[itrk]->is_deleted == true)
1514 continue;
1515 if (event.vtrack[itrk]->dca_range_out == true)
1516 continue;
1517 ntrack++;
1518 h_xvtx->Fill(x_vertex);
1519 h_yvtx->Fill(y_vertex);
1520 h_zvtx->Fill(z_vertex);
1521 }
1522
1523 if (does_reverse)
1524 {
1525 reverse(slope_rz);
1526 reverse(phi_tracklets);
1527 reverse(theta_tracklets);
1528 reverse(phi_track);
1529 reverse(theta_track);
1530 reverse(dca_z);
1531 reverse(dca_2d);
1532 reverse(is_deleted);
1533 reverse(dca_range_out);
1534 reverse(dca2d_range_out);
1535 reverse(dcaz_range_out);
1536 reverse(z_tracklets_out);
1537 reverse(pT);
1538 reverse(px);
1539 reverse(py);
1540 reverse(pz);
1541 reverse(pT_truth);
1542 reverse(px_truth);
1543 reverse(py_truth);
1544 reverse(pz_truth);
1545 reverse(charge);
1546 reverse(rad);
1547 }
1548
1549 track_tree->Fill();
1550
1551 erase(slope_rz);
1552 erase(phi_tracklets);
1553 erase(theta_tracklets);
1554 erase(phi_track);
1555 erase(theta_track);
1556 erase(dca_z);
1557 erase(dca_2d);
1558 erase(is_deleted);
1559 erase(dca_range_out);
1560 erase(dca2d_range_out);
1561 erase(dcaz_range_out);
1562 erase(z_tracklets_out);
1563 erase(pT);
1564 erase(px);
1565 erase(py);
1566 erase(pz);
1567 erase(pT_truth);
1568 erase(px_truth);
1569 erase(py_truth);
1570 erase(pz_truth);
1571 erase(charge);
1572 erase(rad);
1573 if (!(no_mc))
1574 {
1575 for (int itrt = 0; itrt < ntruth; itrt++)
1576 {
1577
1578 if (event.vtruth[itrt]->is_charged == false)
1579 continue;
1580
1581 if (event.vtruth[itrt]->is_intt == false)
1582 continue;
1583 ntruth_cut++;
1584
1585 truthpx.push_back(event.vtruth[itrt]->m_truthpx);
1586 truthpy.push_back(event.vtruth[itrt]->m_truthpy);
1587 truthpz.push_back(event.vtruth[itrt]->m_truthpz);
1588 truthpt.push_back(event.vtruth[itrt]->m_truthpt);
1589 trutheta.push_back(event.vtruth[itrt]->m_trutheta);
1590 truththeta.push_back(event.vtruth[itrt]->m_truththeta);
1591 truthphi.push_back(event.vtruth[itrt]->m_truthphi);
1592 truthpid.push_back(event.vtruth[itrt]->m_truthpid);
1593 status.push_back(event.vtruth[itrt]->m_status);
1594 truthxvtx.push_back(event.vtruth[itrt]->m_xvtx);
1595 truthyvtx.push_back(event.vtruth[itrt]->m_yvtx);
1596 truthzvtx.push_back(event.vtruth[itrt]->m_zvtx);
1597 truthzout.push_back(event.vtruth[itrt]->m_truthz_out);
1598 }
1599 if (does_reverse)
1600 {
1601 reverse(truthpx);
1602 reverse(truthpy);
1603 reverse(truthpz);
1604 reverse(truthpt);
1605 reverse(trutheta);
1606 reverse(truththeta);
1607 reverse(truthphi);
1608 reverse(truthpid);
1609 reverse(status);
1610 reverse(truthxvtx);
1611 reverse(truthyvtx);
1612 reverse(truthzvtx);
1613 reverse(truthzout);
1614 }
1615 truth_tree->Fill();
1616
1617 erase(truthpx);
1618 erase(truthpy);
1619 erase(truthpz);
1620 erase(truthpt);
1621 erase(trutheta);
1622 erase(truththeta);
1623 erase(truthphi);
1624 erase(truthpid);
1625 erase(status);
1626 erase(truthxvtx);
1627 erase(truthyvtx);
1628 erase(truthzvtx);
1629 erase(truthzout);
1630 }
1631
1632
1633
1634
1635 {
1636 if( ievt > 100 )
1637 continue;
1638
1639
1640
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 c->cd(1);
1704
1705 event.draw_frame(0);
1706 event.draw_intt(0);
1707
1708
1709
1710
1711 event.draw_clusters(0, true, kBlack);
1712
1713 if (!(no_mc))
1714 cout << "draw_truth" << endl;
1715 if (mag_on)
1716 {
1717
1718
1719
1720 event.draw_trackcurve(0, true, TColor::GetColor(232, 85, 98), true, true, false);
1721 }
1722 else
1723 {
1724
1725
1726 event.draw_trackline(0, true, TColor::GetColor(232, 85, 98) , true, true, false);
1727
1728
1729 }
1730
1731 c->cd(2);
1732
1733 event.draw_frame(1);
1734 event.draw_intt(1);
1735
1736
1737 event.draw_clusters(1, true, kBlack);
1738
1739
1740 event.draw_trackline(1, true, TColor::GetColor(232, 85, 98), true, true, false);
1741
1742
1743
1744
1745
1746
1747
1748
1749 c->Print(c->GetName());
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 event.clear();
1805
1806
1807 }
1808
1809
1810 c->Print(((string)c->GetName() + "]").c_str());
1811
1812 froot->Write();
1813 for (int ihst = 0; ihst < h_.size(); ihst++)
1814 {
1815 froot->WriteTObject(h_[ihst], h_[ihst]->GetName());
1816 }
1817 froot->Close();
1818 }