Difference between revisions of "File:Pion pro.jpg"
From Nuclear Physics Group Documentation Pages
Jump to navigationJump to search (edep vs. p for pions and protons) |
|||
| Line 1: | Line 1: | ||
| − | + | <pre> | |
| + | // | ||
| + | // Kyle Snavely June 30, 2008 | ||
| + | // | ||
| + | // This script reads in rootfiles and makes a plot of Edep | ||
| + | // vs. p for protons and pions on a canvas of three pads. | ||
| + | // | ||
| + | // -------------------------------------------------------- | ||
| + | // | ||
| + | |||
| + | |||
| + | // All my standard ROOT includes... | ||
| + | #include <TString.h> | ||
| + | #include <string> | ||
| + | #include <fstream> | ||
| + | #include <iostream> | ||
| + | #include <TCanvas.h> | ||
| + | #include <TH1.h> | ||
| + | #include <TH2.h> | ||
| + | #include <TF1.h> | ||
| + | #include <TH3F.h> | ||
| + | #include <TFile.h> | ||
| + | #include <TTree.h> | ||
| + | #include <TROOT.h> | ||
| + | #include <TStyle.h> | ||
| + | #include <TApplication.h> | ||
| + | #include <TPaveText.h> | ||
| + | #include <TPaveStats.h> | ||
| + | #include <TPaveLabel.h> | ||
| + | #include <vector> | ||
| + | #include <TProfile.h> | ||
| + | #include <TF1.h> | ||
| + | #include <TGraphErrors.h> | ||
| + | #include <TMultiGraph.h> | ||
| + | #include <TGraph.h> | ||
| + | #include <TDatime.h> | ||
| + | #include <TLegend.h> | ||
| + | #include <TAxis.h> | ||
| + | #include <TGaxis.h> | ||
| + | #include <TPad.h> | ||
| + | #include <TLatex.h> | ||
| + | #include <TRandom.h> | ||
| + | #include <stdio.h> | ||
| + | #include <stdlib.h> | ||
| + | #include <math.h> | ||
| + | #include <TMath.h> | ||
| + | #include <TMinuit.h> | ||
| + | #include <TStopwatch.h> | ||
| + | #include <TSpectrum.h> | ||
| + | #include "TMath.h" | ||
| + | |||
| + | |||
| + | // Interactive includes | ||
| + | #include <TRint.h> | ||
| + | #include <TApplication.h> | ||
| + | #include <TGX11.h> | ||
| + | #include <TVirtualX.h> | ||
| + | #include <TFriendElement.h> | ||
| + | |||
| + | using namespace std ; | ||
| + | |||
| + | // Make tree a global variable so that we can access it outside this function. | ||
| + | // You can then also access it from the command line. | ||
| + | TTree *tree; | ||
| + | |||
| + | // ************ The main program starts here. ****************// | ||
| + | |||
| + | int main(int argc, char** argv) | ||
| + | { | ||
| + | |||
| + | /////////////////////////////////////////// | ||
| + | // Initialize root, get our files and // | ||
| + | // make them friends, create our canvas. // | ||
| + | /////////////////////////////////////////// | ||
| + | TApplication theApp("App", &argc, argv); | ||
| + | // gStyle->SetOptFit(0111); | ||
| + | gROOT->SetStyle("Plain"); | ||
| + | gStyle->SetFillColor(10); | ||
| + | |||
| + | // Open Root file | ||
| + | TFile *f = new TFile("$DATA/proton_500000.root"); | ||
| + | //Get bst tree | ||
| + | TTree *bst = (TTree*)f->Get("bstT"); | ||
| + | bst->AddFriend("genT", "$DATA/proton_500000.root"); | ||
| + | |||
| + | TFile *g = new TFile("$DATA/pion_500000.root"); | ||
| + | TTree *bst_pi = (TTree*)g->Get("bstT"); | ||
| + | bst_pi->AddFriend("genT", "$DATA/pion_500000.root"); | ||
| + | |||
| + | // Make your canvas | ||
| + | TCanvas* MyCanvas1 = new TCanvas("MyCanvas1", "Some Graphs", 1); | ||
| + | MyCanvas1->SetFillColor(10); | ||
| + | TPaveLabel *title1 = NULL; | ||
| + | title1 = new TPaveLabel(0.1,0.96,0.9,0.99,"A Plot! Yay!"); | ||
| + | title1->SetFillColor(10); | ||
| + | //title1->Draw(); | ||
| + | TDatime *now1; | ||
| + | now1 = new TDatime(); | ||
| + | TPaveLabel *date1 = new TPaveLabel(0.7,0.01,0.9,0.03,now1->AsString()); | ||
| + | date1->SetFillColor(10); | ||
| + | //date1->Draw(); | ||
| + | //TPad* graphPad1 = new TPad("Graphs","Graphs",0.01,0.05,0.95,0.95); | ||
| + | TPad* graphPad1 = new TPad("Graphs","Graphs",0.0,0.0,1.0,1.0); | ||
| + | graphPad1->SetFillColor(10); | ||
| + | graphPad1->Draw(); | ||
| + | graphPad1->cd(); | ||
| + | graphPad1->Divide(3); | ||
| + | |||
| + | /////////////////////////////////////////// | ||
| + | // Create and fill our histos // | ||
| + | /////////////////////////////////////////// | ||
| + | TH2F *edep_p = new TH2F("edep_p","edep vs p (Protons)",100,0.0,4000.0,100,0.0,2.2); | ||
| + | edep_p->SetMarkerColor(40); | ||
| + | edep_p->SetMarkerSize(20.0); | ||
| + | bst->Draw("Edep:p>>edep_p","Edep<2"); | ||
| + | |||
| + | TH2F *edep_p_pi = new TH2F("edep_p_pi","edep vs p (Pions)",100,0.0,4000.0,100,0.0,2.2); | ||
| + | edep_p_pi->SetMarkerColor(12); | ||
| + | edep_p_pi->SetMarkerSize(20.0); | ||
| + | bst_pi->Draw("Edep:genT.p>>edep_p_pi","Edep<2"); | ||
| + | |||
| + | TH2F *pion_pro = new TH2F("pion_pro","edep vs p (Pions and Protons)",100,0.0,4000.0,100,0.0,2.2); | ||
| + | pion_pro->SetMarkerColor(46); | ||
| + | pion_pro->SetMarkerSize(20.0); | ||
| + | TList *list = new TList; | ||
| + | list->Add(edep_p); | ||
| + | list->Add(edep_p_pi); | ||
| + | pion_pro->Merge(list); | ||
| + | |||
| + | /////////////////////////////////////////// | ||
| + | // Draw our graphs // | ||
| + | /////////////////////////////////////////// | ||
| + | graphPad1->Clear(); | ||
| + | graphPad1->Divide(3); | ||
| + | gStyle->SetPalette(1,0); | ||
| + | |||
| + | graphPad1->cd(1); | ||
| + | pion_pro->Draw("colz"); | ||
| + | graphPad1->cd(2); | ||
| + | edep_p->Draw(); | ||
| + | graphPad1->cd(3); | ||
| + | edep_p_pi->Draw(); | ||
| + | |||
| + | // Draw a legend | ||
| + | TLegend *leg = new TLegend(0.4,0.6,0.89,0.89); | ||
| + | leg->SetTextSize(.03); | ||
| + | leg->AddEntry(pion_pro,"Protons and Pions","p"); | ||
| + | leg->AddEntry(edep_p,"Proton","p"); | ||
| + | leg->AddEntry(edep_p_pi,"Pion","p"); | ||
| + | leg->SetFillColor(0); | ||
| + | leg->Draw(); | ||
| + | |||
| + | // ------------------------------------------------ | ||
| + | |||
| + | // Main application eventloop. Calls system dependent eventloop | ||
| + | // -> runs an interactive interface | ||
| + | theApp.Run(); | ||
| + | |||
| + | return(0); | ||
| + | |||
| + | } /********** End of main *************/ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | </pre> | ||
Latest revision as of 18:33, 28 July 2008
//
// Kyle Snavely June 30, 2008
//
// This script reads in rootfiles and makes a plot of Edep
// vs. p for protons and pions on a canvas of three pads.
//
// --------------------------------------------------------
//
// All my standard ROOT includes...
#include <TString.h>
#include <string>
#include <fstream>
#include <iostream>
#include <TCanvas.h>
#include <TH1.h>
#include <TH2.h>
#include <TF1.h>
#include <TH3F.h>
#include <TFile.h>
#include <TTree.h>
#include <TROOT.h>
#include <TStyle.h>
#include <TApplication.h>
#include <TPaveText.h>
#include <TPaveStats.h>
#include <TPaveLabel.h>
#include <vector>
#include <TProfile.h>
#include <TF1.h>
#include <TGraphErrors.h>
#include <TMultiGraph.h>
#include <TGraph.h>
#include <TDatime.h>
#include <TLegend.h>
#include <TAxis.h>
#include <TGaxis.h>
#include <TPad.h>
#include <TLatex.h>
#include <TRandom.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <TMath.h>
#include <TMinuit.h>
#include <TStopwatch.h>
#include <TSpectrum.h>
#include "TMath.h"
// Interactive includes
#include <TRint.h>
#include <TApplication.h>
#include <TGX11.h>
#include <TVirtualX.h>
#include <TFriendElement.h>
using namespace std ;
// Make tree a global variable so that we can access it outside this function.
// You can then also access it from the command line.
TTree *tree;
// ************ The main program starts here. ****************//
int main(int argc, char** argv)
{
///////////////////////////////////////////
// Initialize root, get our files and //
// make them friends, create our canvas. //
///////////////////////////////////////////
TApplication theApp("App", &argc, argv);
// gStyle->SetOptFit(0111);
gROOT->SetStyle("Plain");
gStyle->SetFillColor(10);
// Open Root file
TFile *f = new TFile("$DATA/proton_500000.root");
//Get bst tree
TTree *bst = (TTree*)f->Get("bstT");
bst->AddFriend("genT", "$DATA/proton_500000.root");
TFile *g = new TFile("$DATA/pion_500000.root");
TTree *bst_pi = (TTree*)g->Get("bstT");
bst_pi->AddFriend("genT", "$DATA/pion_500000.root");
// Make your canvas
TCanvas* MyCanvas1 = new TCanvas("MyCanvas1", "Some Graphs", 1);
MyCanvas1->SetFillColor(10);
TPaveLabel *title1 = NULL;
title1 = new TPaveLabel(0.1,0.96,0.9,0.99,"A Plot! Yay!");
title1->SetFillColor(10);
//title1->Draw();
TDatime *now1;
now1 = new TDatime();
TPaveLabel *date1 = new TPaveLabel(0.7,0.01,0.9,0.03,now1->AsString());
date1->SetFillColor(10);
//date1->Draw();
//TPad* graphPad1 = new TPad("Graphs","Graphs",0.01,0.05,0.95,0.95);
TPad* graphPad1 = new TPad("Graphs","Graphs",0.0,0.0,1.0,1.0);
graphPad1->SetFillColor(10);
graphPad1->Draw();
graphPad1->cd();
graphPad1->Divide(3);
///////////////////////////////////////////
// Create and fill our histos //
///////////////////////////////////////////
TH2F *edep_p = new TH2F("edep_p","edep vs p (Protons)",100,0.0,4000.0,100,0.0,2.2);
edep_p->SetMarkerColor(40);
edep_p->SetMarkerSize(20.0);
bst->Draw("Edep:p>>edep_p","Edep<2");
TH2F *edep_p_pi = new TH2F("edep_p_pi","edep vs p (Pions)",100,0.0,4000.0,100,0.0,2.2);
edep_p_pi->SetMarkerColor(12);
edep_p_pi->SetMarkerSize(20.0);
bst_pi->Draw("Edep:genT.p>>edep_p_pi","Edep<2");
TH2F *pion_pro = new TH2F("pion_pro","edep vs p (Pions and Protons)",100,0.0,4000.0,100,0.0,2.2);
pion_pro->SetMarkerColor(46);
pion_pro->SetMarkerSize(20.0);
TList *list = new TList;
list->Add(edep_p);
list->Add(edep_p_pi);
pion_pro->Merge(list);
///////////////////////////////////////////
// Draw our graphs //
///////////////////////////////////////////
graphPad1->Clear();
graphPad1->Divide(3);
gStyle->SetPalette(1,0);
graphPad1->cd(1);
pion_pro->Draw("colz");
graphPad1->cd(2);
edep_p->Draw();
graphPad1->cd(3);
edep_p_pi->Draw();
// Draw a legend
TLegend *leg = new TLegend(0.4,0.6,0.89,0.89);
leg->SetTextSize(.03);
leg->AddEntry(pion_pro,"Protons and Pions","p");
leg->AddEntry(edep_p,"Proton","p");
leg->AddEntry(edep_p_pi,"Pion","p");
leg->SetFillColor(0);
leg->Draw();
// ------------------------------------------------
// Main application eventloop. Calls system dependent eventloop
// -> runs an interactive interface
theApp.Run();
return(0);
} /********** End of main *************/
File history
Click on a date/time to view the file as it appeared at that time.
| Date/Time | Thumbnail | Dimensions | User | Comment | |
|---|---|---|---|---|---|
| current | 19:04, 30 June 2008 | 1,134 × 540 (305 KB) | Kyle (talk | contribs) | edep vs. p for pions and protons |
You cannot overwrite this file.
File usage
The following page uses this file: