{ //includes #include #include #include #include #include #include #include #include #include #include nlines = 0; TFile *f = new TFile("XSec.root","recreate"); TTree *T = new TTree("T","CrossSection Data for Plotting"); const int NParticles = 300; double momentum[NParticles] = {0}; double XSTotal[NParticles] = {0}; double XSElastic[NParticles] = {0}; double XSInelastic[NParticles] = {0}; double ppmomentum[NParticles] = {0}; double ppXSTotal[NParticles] = {0}; double ppXSElastic[NParticles] = {0}; double ppXSInelastic[NParticles] = {0}; T->Branch("momentum" ,momentum,"momentum/D"); T->Branch("XSTotal", XSTotal,"XSTotal/D"); T->Branch("XSElastic", XSElastic, "XSElastic/D"); T->Branch("XSInelastic", XSInelastic,"XSInelastic/D"); T->Branch("ppmomentum", ppmomentum,"ppmomentum/D"); T->Branch("ppXSTotal", ppXSTotal,"ppXSTotal/D"); T->Branch("ppXSElastic", ppXSElastic, "ppXSElastic/D"); T->Branch("ppXSInelastic",ppXSInelastic,"ppXSInelastic/D"); ifstream infile; infile.open("./XSecData.txt"); if (infile.is_open()){ cout << " File is open" << endl; } else {cout << "Unable to open file..." << endl; } while (!infile.eof()){ infile >> momentum[nlines] >> XSTotal[nlines] >> XSElastic[nlines] >> XSInelastic[nlines] >> ppmomentum[nlines] >> ppXSTotal[nlines] >> ppXSElastic[nlines] >> ppXSInelastic[nlines]; nlines = nlines + 1; // cout << nlines << endl; } T->Fill(); TCanvas *c1 = new TCanvas("c1","pp and ppbar Cross-Section",1200,600); c1->SetLogx(); c1->DrawFrame(1,0,2e6,150); c1->Update(); TGraph *gr0 = new TGraph(nlines, momentum, XSTotal); TGraph *gr1 = new TGraph(nlines, momentum, XSElastic); TGraph *gr2 = new TGraph(nlines, momentum, XSInelastic); TGraph *gr3 = new TGraph(nlines, ppmomentum, ppXSTotal); TGraph *gr4 = new TGraph(nlines, ppmomentum, ppXSInelastic); TGraph *gr5 = new TGraph(nlines, ppmomentum, ppXSElastic); gr0->Draw("P"); // Set the TGraph, X and Y titles. gr0->SetTitle("pp and ppbar Cross-Section;sqrt(s);cross-section"); //Or try it the old-fashioned way! // gr0->GetYaxis()->SetTitle("\\sigma [mb]"); /// gr0->GetXaxis()->SetTitle("\\sqrt{s} [GeV]"); gr1->Draw("PSame"); gr2->Draw("PSame"); gr3->Draw("PSame"); gr4->Draw("PSame"); gr5->Draw("PSame"); // Dress it up! gr0->SetMarkerStyle(24); gr0->SetMarkerColor(2); gr1->SetMarkerStyle(20); gr1->SetMarkerColor(3); gr2->SetMarkerStyle(32); gr2->SetMarkerColor(9); gr3->SetMarkerStyle(22); gr3->SetMarkerColor(46); gr4->SetMarkerStyle(33); gr4->SetMarkerColor(26); gr5->SetMarkerStyle(34); gr5->SetMarkerColor(kOrange); // Required so the TLegend works correctly gr0->SetName("gr0"); gr1->SetName("gr1"); gr2->SetName("gr2"); gr3->SetName("gr3"); gr4->SetName("gr4"); gr5->SetName("gr5"); // I am legend! TLegend *leg = new TLegend(0.75,0.55,0.90,0.90); leg->AddEntry("gr0","pp \\sigma Total","p"); leg->AddEntry("gr1","pp \\sigma Elastic","p"); leg->AddEntry("gr2","pp \\sigma Inelastic","p"); leg->AddEntry("gr3","ppbar \\sigma Total","p"); leg->AddEntry("gr4","ppbar \\sigma Elastic","p"); leg->AddEntry("gr5","ppbar \\sigma Inelastic","p"); leg->Draw(); // Remove the Legend shadow. TPave->SetShadowColor(0); c1->Modified(); // Close the input file. infile.close(); f->Write(); }