File indexing completed on 2025-08-03 08:14:09
0001 #include <iostream>
0002 using namespace std;
0003
0004 #include "TFile.h"
0005 #include "TTree.h"
0006 #include "TChain.h"
0007 #include "TLegend.h"
0008 #include "math.h"
0009 #include "TH1.h"
0010 #include "TH2.h"
0011 #include "TEfficiency.h"
0012 #include "TLine.h"
0013 #include "TGraphAsymmErrors.h"
0014
0015 TChain* handleFile(string name, string extension, string treename, unsigned int filecount){
0016 TChain *all = new TChain(treename.c_str());
0017 string temp;
0018 for (int i = 0; i < filecount; ++i)
0019 {
0020
0021 ostringstream s;
0022 s<<i;
0023 temp = name+string(s.str())+extension;
0024 all->Add(temp.c_str());
0025 }
0026 return all;
0027 }
0028
0029 void trackpT()
0030 {
0031 float electron_pt[200];
0032 float positron_pt[200];
0033 float electron_reco_pt[200];
0034 float positron_reco_pt[200];
0035 double rVtx[200];
0036 int b_layer[20];
0037 int truth_n;
0038 int reco_n;
0039 int nVtx;
0040
0041
0042 string treePath = "/sphenix/user/vassalli/gammasample/fourembededonlineanalysis";
0043 string treeExtension = ".root";
0044 unsigned int nFiles=100;
0045 TChain *ttree = handleFile(treePath,treeExtension,"ttree",nFiles);
0046 ttree->SetBranchAddress("electron_pt", &electron_pt );
0047 ttree->SetBranchAddress("electron_reco_pt",&electron_reco_pt );
0048 ttree->SetBranchAddress("positron_pt", &positron_pt );
0049 ttree->SetBranchAddress("positron_reco_pt",&positron_reco_pt );
0050 ttree->SetBranchAddress("nTpair", &truth_n );
0051 ttree->SetBranchAddress("nRpair", &reco_n );
0052 ttree->SetBranchAddress("fLayer", &b_layer );
0053 ttree->SetBranchAddress("nVtx", &nVtx );
0054 ttree->SetBranchAddress("rVtx", &rVtx );
0055
0056
0057 string outfilename = "pTeffdists.root";
0058 TFile *out = new TFile(outfilename.c_str(),"RECREATE");
0059
0060 TH1F *h_TepT = new TH1F("TepT","",100,0,30);
0061 TH1F *h_RepT = new TH1F("RepT","",100,0,30);
0062
0063 TH1F *h_rvtx = new TH1F("rvtx","",100,0,30);
0064 TH1F *h_layer = new TH1F("layer","",24,-.5,23.5);
0065
0066 h_TepT->GetXaxis()->SetTitle("pT");
0067 h_TepT->GetYaxis()->SetTitle("N");
0068 h_RepT->GetXaxis()->SetTitle("pT");
0069 h_RepT->GetYaxis()->SetTitle("N");
0070
0071 h_rvtx->GetXaxis()->SetTitle("radius [cm]");
0072 h_rvtx->GetYaxis()->SetTitle("N");
0073
0074 for (int event = 0; event < ttree->GetEntries(); ++event)
0075 {
0076 ttree->GetEvent(event);
0077 for (int i = 0; i < truth_n; ++i)
0078 {
0079 h_RepT->Fill(electron_reco_pt[i]);
0080 h_RepT->Fill(positron_reco_pt[i]);
0081 }
0082 for (int i = 0; i < nVtx; ++i)
0083 {
0084 h_TepT->Fill(electron_pt[i]);
0085 h_TepT->Fill(positron_pt[i]);
0086 h_rvtx->Fill(rVtx[i]);
0087 }
0088 for (int i = 0; i < reco_n; ++i)
0089 {
0090 h_layer->Fill(b_layer[i]);
0091 }
0092 }
0093 out->Write();
0094 out->Close();
0095 delete ttree;
0096 delete out;
0097 }