Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:15:15

0001 #include "../CommonTools.h"
0002 
0003 /*
0004  * This macro compares two versions of ntp_gtrack and makes plots that
0005  * compare typical tracking physics performance. It is called with the
0006  * two file names as arguments, e.g.
0007  * root -l -b -q Compare_ntp_gtrack.C'("file1.root","file2.root")'
0008  * where both root files are the SvtxEvaluator output with ntp_gtrack
0009  *
0010  * The output is some canvases which compare benchmark physics performance
0011  *
0012  */
0013 
0014 void Compare_ntp_gtrack(std::string file1, std::string file2)
0015 {
0016   gStyle->SetOptStat(0);
0017   TFile *df = TFile::Open(file1.c_str());
0018 
0019   TFile *nf = TFile::Open(file2.c_str());
0020 
0021   TNtuple *dt = (TNtuple*)df->Get("ntp_gtrack");
0022   TNtuple *nt = (TNtuple*)nf->Get("ntp_gtrack");
0023   
0024   dt->Draw("gpt>>dtruth(40,0,20)");
0025   nt->Draw("gpt>>ntruth(40,0,20)");
0026   dt->Draw("gpt>>dreco(40,0,20)","quality<10 && ntpc>30");
0027   nt->Draw("gpt>>nreco(40,0,20)","quality<10 && ntpc>30");
0028   dt->Draw("gpt>>drecomaps(40,0,20)","quality<10 && nmaps>2 && ntpc>30");
0029   nt->Draw("gpt>>nrecomaps(40,0,20)","quality<10 && nmaps>2 && ntpc>30");
0030   
0031   TH1* dtruth = (TH1F*)gDirectory->Get("dtruth");
0032   TH1 *ntruth = (TH1F*)gDirectory->Get("ntruth");
0033   TH1 *dreco = (TH1F*)gDirectory->Get("dreco");
0034   TH1 *nreco = (TH1F*)gDirectory->Get("nreco");
0035   TH1 *drecomaps = (TH1F*)gDirectory->Get("drecomaps");
0036   TH1 *nrecomaps = (TH1F*)gDirectory->Get("nrecomaps");
0037 
0038   dt->Draw("pt/gpt:gpt>>dpt(40,0,40,400,0.5,1.5)","quality<10","colz");
0039   nt->Draw("pt/gpt:gpt>>npt(40,0,40,400,0.5,1.5)","quality<10","colz");
0040   
0041   TH2* dpt = (TH2F*)gDirectory->Get("dpt");
0042   TH2* npt = (TH2F*)gDirectory->Get("npt");
0043 
0044 
0045   dpt->FitSlicesY();
0046   npt->FitSlicesY();
0047   TH1* dptw = (TH1F*)gDirectory->Get("dpt_2");
0048   TH1* dpts = (TH1F*)gDirectory->Get("dpt_1");
0049   TH1* nptw = (TH1F*)gDirectory->Get("npt_2");
0050   TH1 *npts = (TH1F*)gDirectory->Get("npt_1");
0051   
0052   dt->Draw("dca3dxy:gpt>>ddcax(60,0,20,50,-0.01,0.01)","quality<10","colz");
0053   nt->Draw("dca3dxy:gpt>>ndcax(60,0,20,50,-0.01,0.01)","quality<10","colz");
0054   dt->Draw("dca3dz:gpt>>ddcaz(60,0,20,50,-0.01,0.01)","quality<10","colz");
0055   nt->Draw("dca3dz:gpt>>ndcaz(60,0,20,50,-0.01,0.01)","quality<10","colz");
0056   
0057   dt->Draw("ntpc:gpt>>dntpc(20,0,20,60,0,60)","quality<10","colz");
0058   dt->Draw("nintt:gpt>>dnintt(20,0,20,8,0,8)","quality<10","colz");
0059   dt->Draw("nmaps:gpt>>dnmaps(20,0,20,5,0,5)","quality<10","colz");
0060   nt->Draw("ntpc:gpt>>nntpc(20,0,20,60,0,60)","quality<10","colz");
0061   nt->Draw("nintt:gpt>>nnintt(20,0,20,8,0,8)","quality<10","colz");
0062   nt->Draw("nmaps:gpt>>nnmaps(20,0,20,5,0,5)","quality<10","colz");
0063   
0064   dt->Draw("ntpc>>dntpc1(60,0,60)","quality<10","colz");
0065   dt->Draw("nintt>>dnintt1(6,0,6)","quality<10","colz");
0066   dt->Draw("nmaps>>dnmaps1(6,0,6)","quality<10","colz");
0067   nt->Draw("ntpc>>nntpc1(60,0,60)","quality<10","colz");
0068   nt->Draw("nintt>>nnintt1(6,0,6)","quality<10","colz");
0069   nt->Draw("nmaps>>nnmaps1(6,0,6)","quality<10","colz");
0070   
0071   TH1 *dntpc1 = (TH1F*)gDirectory->Get("dntpc1");
0072   TH1 *dnintt1 = (TH1F*)gDirectory->Get("dnintt1");
0073   TH1 *dnmaps1 = (TH1F*)gDirectory->Get("dnmaps1");
0074   TH1 *nntpc1 = (TH1F*)gDirectory->Get("nntpc1");
0075   TH1 *nnintt1 = (TH1F*)gDirectory->Get("nnintt1");
0076   TH1 *nnmaps1 = (TH1F*)gDirectory->Get("nnmaps1");
0077 
0078   TH2 *dntpc = (TH2F*)gDirectory->Get("dntpc");
0079   TH2 *dnintt = (TH2F*)gDirectory->Get("dnintt");
0080   TH2 *dnmaps = (TH2F*)gDirectory->Get("dnmaps");
0081   TH2 *nntpc = (TH2F*)gDirectory->Get("nntpc");
0082   TH2 *nnintt = (TH2F*)gDirectory->Get("nnintt");
0083   TH2 *nnmaps = (TH2F*)gDirectory->Get("nnmaps");
0084 
0085   TCanvas *tpc1can = new TCanvas("tpc1can","tpc1can",200,200,600,600);
0086   nntpc1->SetLineColor(kRed);
0087   dntpc1->Scale(1./dntpc1->GetEntries());
0088   nntpc1->Scale(1./nntpc1->GetEntries());
0089   dntpc1->Draw("hist");
0090   nntpc1->Draw("histsame");
0091   
0092   TCanvas *intt1can = new TCanvas("intt1can","intt1can",200,200,600,600);
0093   nnintt1->SetLineColor(kRed);
0094   dnintt1->Scale(1./dnintt1->GetEntries());
0095   nnintt1->Scale(1./nnintt1->GetEntries());
0096   dnintt1->Draw("hist");
0097   nnintt1->Draw("histsame");
0098 
0099   TCanvas *maps1can = new TCanvas("maps1can","maps1can",200,200,600,600);
0100   nnmaps1->SetLineColor(kRed);
0101   dnmaps1->Scale(1./dnmaps1->GetEntries());
0102   nnmaps1->Scale(1./nnmaps1->GetEntries());
0103   dnmaps1->Draw("hist");
0104   nnmaps1->Draw("histsame");
0105 
0106   TCanvas *tpccan = new TCanvas("tpccan","tpccan",200,200,600,600);
0107   tpccan->Divide(2,1);
0108   tpccan->cd(1);
0109   dntpc->GetYaxis()->SetTitle("ntpc");
0110   dntpc->GetXaxis()->SetTitle("gpt");
0111   dntpc->Draw("colz");
0112   tpccan->cd(2);
0113   nntpc->Draw("colz");
0114 
0115   TCanvas *inttcan = new TCanvas("inttcan","inttcan",200,200,600,600);
0116   inttcan->Divide(2,1);
0117   inttcan->cd(1);
0118   dnintt->GetYaxis()->SetTitle("nintt");
0119   dnintt->GetXaxis()->SetTitle("gpt");
0120   dnintt->Draw("colz");
0121   inttcan->cd(2);
0122   nnintt->Draw("colz");
0123 
0124   TCanvas *mapscan = new TCanvas("mapscan","mapscan",200,200,600,600);
0125   mapscan->Divide(2,1);
0126   mapscan->cd(1);
0127   dnmaps->GetYaxis()->SetTitle("nmaps");
0128   dnmaps->GetXaxis()->SetTitle("gpt");
0129   dnmaps->Draw("colz");
0130   mapscan->cd(2);
0131   nnmaps->Draw("colz");
0132 
0133   TH2 *ddcax = (TH2F*)gDirectory->Get("ddcax");
0134   TH2 *ddcaz = (TH2F*)gDirectory->Get("ddcaz");
0135   TH2 *ndcax = (TH2F*)gDirectory->Get("ndcax");
0136   TH2 *ndcaz = (TH2F*)gDirectory->Get("ndcaz");
0137   
0138   ddcax->FitSlicesY();
0139   ddcaz->FitSlicesY();
0140   ndcax->FitSlicesY();
0141   ndcaz->FitSlicesY();
0142   
0143   TH1 *ddcaxw = (TH1F*)gDirectory->Get("ddcax_2");
0144   TH1 *ddcazw = (TH1F*)gDirectory->Get("ddcaz_2");
0145   TH1 *ndcaxw = (TH1F*)gDirectory->Get("ndcax_2");
0146   TH1 *ndcazw = (TH1F*)gDirectory->Get("ndcaz_2");
0147   
0148   nptw->SetMarkerColor(kRed); nptw->SetLineColor(kRed);
0149   npts->SetMarkerColor(kRed); npts->SetLineColor(kRed);
0150   ndcaxw->SetMarkerColor(kRed); ndcaxw->SetLineColor(kRed);
0151   ndcazw->SetMarkerColor(kRed); ndcazw->SetLineColor(kRed);
0152   
0153   TCanvas *ptcan = new TCanvas("ptcan","ptcan",200,200,600,600);
0154   ptcan->Divide(2,1);
0155   ptcan->cd(1);
0156   dpt->Draw("colz");
0157   myText(0.1,0.03,kBlack,"File 1");
0158   ptcan->cd(2);
0159   npt->Draw("colz");
0160   myText(0.1,0.03,kBlack,"File 2");
0161   
0162   TCanvas *dcaxcan2 = new TCanvas("dcaxcan2","dcaxcan2",200,200,600,600);
0163   dcaxcan2->Divide(2,1);
0164   dcaxcan2->cd(1);
0165 
0166   ddcax->Draw("colz");
0167   myText(0.1,0.03,kBlack,"File 1");
0168   dcaxcan2->cd(2);
0169   ndcax->Draw("colz");
0170   myText(0.1,0.03,kBlack,"File 2");
0171 
0172   TCanvas *dcazcan2 = new TCanvas("dcazcan2","dcazcan2",200,200,600,600);
0173   dcazcan2->Divide(2,1);
0174   dcazcan2->cd(1);
0175   ddcaz->Draw("colz");
0176   myText(0.1,0.03,kBlack,"File 1");
0177   dcazcan2->cd(2);
0178   ndcaz->Draw("colz");
0179   myText(0.1,0.03,kBlack,"File 2");
0180 
0181   TCanvas *ptwcan = new TCanvas("ptwcan","ptwcan",200,200,600,600);
0182   nptw->GetYaxis()->SetTitle("#sigma(p_{T})/p_{T}");
0183   nptw->GetXaxis()->SetTitle("p_{T} [GeV]");
0184   //nptw->Divide(dptw);
0185   nptw->Draw("ep");
0186   dptw->Draw("epsame");
0187   myText(0.21,0.85,kBlack,"File 1");
0188   myText(0.21,0.77,kRed,"File 2");
0189   
0190   
0191   TCanvas *ptscan = new TCanvas("ptscan","ptscan",200,200,600,600);
0192   npts->GetYaxis()->SetTitle("#LTp_{T}^{true}/p_{T}^{reco}#GT");
0193   npts->GetXaxis()->SetTitle("p_{T} [GeV]");
0194   npts->Draw("ep");
0195   dpts->Draw("epsame");
0196   myText(0.21,0.85,kBlack,"File 1");
0197   myText(0.21,0.77,kRed,"File 2");
0198  
0199 
0200   TCanvas *dcaxcan = new TCanvas("dcaxcan","dcaxcan",200,200,600,600);
0201   ndcaxw->GetYaxis()->SetTitle("#sigma(DCA_{xy}) [cm]");
0202   ndcaxw->GetXaxis()->SetTitle("p_{T} [GeV]");
0203   ndcaxw->Draw("ep");
0204   ddcaxw->Draw("epsame");
0205   myText(0.21,0.85,kBlack,"File 1");
0206   myText(0.21,0.77,kRed,"File 2");
0207  
0208 
0209   TCanvas *dcazcan = new TCanvas("dcazcan","dcazcan",200,200,600,600);
0210   ndcazw->GetYaxis()->SetTitle("#sigma(DCA_{z}) [cm]");
0211   ndcazw->GetXaxis()->SetTitle("p_{T} [GeV]");
0212   ndcazw->Draw("ep");
0213   ddcazw->Draw("epsame");
0214   myText(0.21,0.85,kBlack,"File 1");
0215   myText(0.21,0.77,kRed,"File 2");
0216 
0217 
0218 
0219   dtruth->GetYaxis()->SetTitle("Eff");
0220   dtruth->GetXaxis()->SetTitle("p_{T} [GeV]");
0221   dtruth->GetYaxis()->SetRangeUser(0,1);
0222   TEfficiency *deff = new TEfficiency(*dreco,*dtruth);
0223   TEfficiency *neff = new TEfficiency(*nreco,*ntruth);
0224   TEfficiency *deffmaps = new TEfficiency(*drecomaps,*dtruth);
0225   TEfficiency *neffmaps = new TEfficiency(*nrecomaps,*ntruth);
0226   
0227 
0228   TCanvas *effcan = new TCanvas("effcan","effcan",200,200,600,600);
0229   neff->SetMarkerColor(kRed); neff->SetLineColor(kRed);
0230   neffmaps->SetMarkerColor(kRed); neffmaps->SetLineColor(kRed);
0231   neffmaps->SetMarkerStyle(24); deffmaps->SetMarkerStyle(24);
0232 
0233   deff->Draw("ap");
0234   neff->Draw("psame");
0235   deffmaps->Draw("psame");
0236   neffmaps->Draw("psame");
0237   TLegend *effleg = new TLegend(0.4,0.4,0.6,0.7);
0238   effleg->AddEntry(deff,"File 1 qual<10","P");
0239   effleg->AddEntry(neff,"File 2 qual<10","p");
0240   effleg->AddEntry(deffmaps,"File 1 nmaps>2","P");
0241   effleg->AddEntry(neffmaps,"File 2 nmaps>2","P");
0242   
0243   effleg->Draw("same");
0244 
0245 
0246 
0247 
0248   TFile *outfile = new TFile("compoutfile.root","recreate");
0249   dpt->Write();
0250   npt->Write();
0251   outfile->Close();
0252 }