Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:11:19

0001 #include <cstdlib>
0002 
0003 float TickSize = 0.03;
0004 float AxisTitleSize = 0.05;
0005 float AxisLabelSize = 0.045;
0006 float LeftMargin = 0.15;
0007 float RightMargin = 0.05;
0008 float TopMargin = 0.08;
0009 float BottomMargin = 0.13;
0010 float textscale = 2.6;
0011 
0012 void recotkl_DCA()
0013 {
0014     // directory to save the output plots; if the directory does not exist, create it using
0015     std::string plotdir = "recotkl_DCA";
0016     system(Form("mkdir -p %s", plotdir.c_str()));
0017 
0018     ROOT::EnableImplicitMT();
0019     ROOT::RDataFrame df("minitree", "/sphenix/tg/tg01/hf/hjheng/ppg02/minitree/TrackletMinitree_Sim_HIJING_ananew_20250130/dRcut0p5_NominalVtxZ_RandomClusSet0_clusAdcCutSet0_clusPhiSizeCutSet0/minitree_00*.root");
0020 
0021     // histogram of reco-tracklet DCA, is is_min_bias
0022     auto h_recotklraw_DCA3d = df.Filter("is_min_bias&&abs(PV_z)<=10").Histo1D({"h_recotklraw_DCA3d", "h_recotklraw_DCA3d:Tracklet DCA (w.r.t event vertex) [cm]:Entries", 200, 0, 10}, "recotklraw_dca3dvtx");
0023     // define 2 new columns for the tracklets dca with the corresponding value in recotkl_isMatchedGChadron is true and is false
0024     auto df_with_matched = df.Define("recotkldca_matched",
0025                                      [](const std::vector<float> &recotklraw_dca3dvtx, const std::vector<bool> &recotkl_isMatchedGChadron)
0026                                      {
0027                                          std::vector<float> recotkl_matched;
0028                                          for (size_t i = 0; i < recotklraw_dca3dvtx.size(); i++)
0029                                          {
0030                                              if (recotkl_isMatchedGChadron[i])
0031                                              {
0032                                                  recotkl_matched.push_back(recotklraw_dca3dvtx[i]);
0033                                              }
0034                                          }
0035                                          return recotkl_matched;
0036                                      },
0037                                      {"recotklraw_dca3dvtx", "recotkl_isMatchedGChadron"})
0038                                .Define("recotkldca_unmatched",
0039                                        [](const std::vector<float> &recotklraw_dca3dvtx, const std::vector<bool> &recotkl_isMatchedGChadron)
0040                                        {
0041                                            std::vector<float> recotkl_unmatched;
0042                                            for (size_t i = 0; i < recotklraw_dca3dvtx.size(); i++)
0043                                            {
0044                                                if (!recotkl_isMatchedGChadron[i])
0045                                                {
0046                                                    recotkl_unmatched.push_back(recotklraw_dca3dvtx[i]);
0047                                                }
0048                                            }
0049                                            return recotkl_unmatched;
0050                                        },
0051                                        {"recotklraw_dca3dvtx", "recotkl_isMatchedGChadron"});
0052 
0053     auto h_recotklraw_DCA3d_matched = df_with_matched.Filter("is_min_bias&&abs(PV_z)<=10").Histo1D({"h_recotklraw_DCA3d_matched", "h_recotklraw_DCA3d_matched:Tracklet DCA (w.r.t event vertex) [cm]:Entries", 200, 0, 10}, "recotkldca_matched");
0054     auto h_recotklraw_DCA3d_unmatched = df_with_matched.Filter("is_min_bias&&abs(PV_z)<=10").Histo1D({"h_recotklraw_DCA3d_unmatched", "h_recotklraw_DCA3d_unmatched:Tracklet DCA (w.r.t event vertex) [cm]:Entries", 200, 0, 10}, "recotkldca_unmatched");
0055 
0056     // draw the histograms on a canvas; split the canvas into two pads, the top pad to draw the two histograms and the bottom pad to draw the ratio plot
0057     TCanvas *c = new TCanvas("c", "c", 800, 700);
0058     gPad->SetTopMargin(TopMargin);
0059     c->cd();
0060     THStack *hs = new THStack("hs", ";Tracklet DCA (w.r.t the event vertex) [cm];Entries");
0061     hs->Draw("hist");
0062     gPad->Modified();
0063     gPad->Update();
0064     h_recotklraw_DCA3d_matched->SetLineColor(kRed);
0065     h_recotklraw_DCA3d_matched->SetLineWidth(0);
0066     h_recotklraw_DCA3d_matched->SetFillColorAlpha(kRed, 0.3);
0067     hs->Add(h_recotklraw_DCA3d_matched.GetPtr());
0068     h_recotklraw_DCA3d_unmatched->SetLineColor(kBlue);
0069     h_recotklraw_DCA3d_unmatched->SetLineWidth(0);
0070     h_recotklraw_DCA3d_unmatched->SetFillColorAlpha(kBlue, 0.3);
0071     hs->Add(h_recotklraw_DCA3d_unmatched.GetPtr());
0072     hs->GetXaxis()->SetTitle("Tracklet DCA (w.r.t the event vertex) [cm]");
0073     hs->SetMaximum(h_recotklraw_DCA3d->GetMaximum()*1.3);
0074     hs->GetYaxis()->SetTitle("Entries");
0075     hs->GetYaxis()->SetTitleOffset(1.6);
0076     gPad->Modified();
0077     gPad->Update();
0078     h_recotklraw_DCA3d->SetLineColor(kBlack);
0079     h_recotklraw_DCA3d->SetLineWidth(2);
0080     h_recotklraw_DCA3d->Draw("hist same");
0081     TLegend *leg = new TLegend(gPad->GetLeftMargin() + 0.02, 1 - gPad->GetTopMargin() - 0.15, gPad->GetLeftMargin() + 0.3, 1 - gPad->GetTopMargin() - 0.04);
0082     leg->SetBorderSize(0);
0083     leg->SetFillStyle(0);
0084     leg->SetTextSize(0.035);
0085     leg->AddEntry(h_recotklraw_DCA3d.GetPtr(), "All tracklets", "l");
0086     leg->AddEntry(h_recotklraw_DCA3d_matched.GetPtr(), "Tracklets matched to primary charged hadrons", "f");
0087     leg->AddEntry(h_recotklraw_DCA3d_unmatched.GetPtr(), "Tracklets not matched to primary charged hadrons", "f");
0088     leg->Draw();
0089     c->SaveAs(Form("%s/recotkl_DCA3d.pdf", plotdir.c_str()));
0090     c->SaveAs(Form("%s/recotkl_DCA3d.png", plotdir.c_str()));
0091 }