Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
plot_track_deviations.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file plot_track_deviations.C
1 #include "TraceBox.h"
2 #include <cmath>
3 
4 TGraph*
5 graph_delta( TGraph* g1, TGraph* g2 )
6 {
7  /* make sure both graph have smae number of entries- return NULL pointer if they don't */
8  if ( g1->GetN() != g2->GetN() )
9  {
10  cerr << "Mismatch in number of points for graphs in calculating delta!" << endl;
11  return NULL;
12  }
13 
14  TGraph* gdelta = new TGraph( g1->GetN() );// (TGraph*)g1->Clone("gdelta");
15 
16  for ( unsigned i = 0; i < g1->GetN(); i++ )
17  {
18  Double_t x1 = 0;
19  Double_t y1 = 0;
20  Double_t x2 = 0;
21  Double_t y2 = 0;
22 
23  g1->GetPoint( i , x1 , y1 );
24  g2->GetPoint( i , x2 , y2 );
25 
26  Double_t xdelta = x1;
27  Double_t ydelta = y1-y2;
28 
29  gdelta->SetPoint(i, xdelta, ydelta);
30  }
31 
32  return gdelta;
33 }
34 
35 int
37 {
38  /**** Chose input files ****/
39 
40  /* Open iput file with trajectories from GEANT4 */
41  TFile *file_nominal = new TFile( "data_amatrix/G4EICIR_DSTReader_p250_vx0_vy0_theta22mrad.root", "OPEN" );
42  TFile *file_nominal_upper = new TFile( "data_amatrix/G4EICIR_DSTReader_p250_vx0_vy1_theta0mrad.root", "OPEN" ); // +200 MeV pT
43  TFile *file_nominal_lower = new TFile( "data_amatrix/G4EICIR_DSTReader_p250_vx0_vy0_theta10mrad.root", "OPEN" ); // -200 MeV pT
44 
45  TFile *file_trial = new TFile( "data_amatrix/G4EICIR_DSTReader_p250_vx0_vy0_theta10mrad.root", "OPEN" );
46 
47  /* Get tree from file */
48  TTree *tree_nominal = (TTree*)file_nominal->Get("T");
49  TTree *tree_nominal_upper = (TTree*)file_nominal_upper->Get("T");
50  TTree *tree_nominal_lower = (TTree*)file_nominal_lower->Get("T");
51 
52  TTree *tree_trial = (TTree*)file_trial->Get("T");
53 
54  /* get number of hits */
55  int nhits = 0;
56  tree_nominal->SetBranchAddress("n_G4HIT_FWDDISC",&nhits);
57  tree_nominal->GetEntry(0);
58  cout << "hits: " << nhits << endl;
59 
60  /* create graph of nominal beam position (z) */
61  tree_nominal->Draw( "0.5*(G4HIT_FWDDISC.y[][0]+G4HIT_FWDDISC.y[][1]) : 0.5*(G4HIT_FWDDISC.z[][0]+G4HIT_FWDDISC.z[][1])","Entry$==0","");
62  TGraph* g_nominal = new TGraph(nhits, &(tree_nominal->GetV2()[0]), &(tree_nominal->GetV1()[0]));
63  g_nominal->SetName("g_nominal");
64 
65  /* create graph of beam positions relative to nominal */
66  TGraph* g_nominal_delta = graph_delta(g_nominal, g_nominal);
67  if ( ! g_nominal_delta )
68  return 1;
69  g_nominal_delta->SetName("g_nominal_delta");
70  g_nominal_delta->SetLineWidth(2);
71 
72  /* create graph of nominal_upper beam position (z) */
73  tree_nominal_upper->Draw( "0.5*(G4HIT_FWDDISC.y[][0]+G4HIT_FWDDISC.y[][1]) : 0.5*(G4HIT_FWDDISC.z[][0]+G4HIT_FWDDISC.z[][1])","Entry$==0","");
74  TGraph* g_nominal_upper = new TGraph(nhits, &(tree_nominal_upper->GetV2()[0]), &(tree_nominal_upper->GetV1()[0]));
75  g_nominal_upper->SetName("g_nominal_upper");
76 
77  /* create graph of beam positions relative to nominal_upper */
78  TGraph* g_nominal_upper_delta = graph_delta(g_nominal_upper, g_nominal);
79  if ( ! g_nominal_upper_delta )
80  return 1;
81  g_nominal_upper_delta->SetName("g_nominal_upper_delta");
82  g_nominal_upper_delta->SetLineWidth(2);
83  g_nominal_upper_delta->SetLineColor(kBlue);
84 
85  /* create graph of nominal_lower beam position (z) */
86  tree_nominal_lower->Draw( "0.5*(G4HIT_FWDDISC.y[][0]+G4HIT_FWDDISC.y[][1]) : 0.5*(G4HIT_FWDDISC.z[][0]+G4HIT_FWDDISC.z[][1])","Entry$==0","");
87  TGraph* g_nominal_lower = new TGraph(nhits, &(tree_nominal_lower->GetV2()[0]), &(tree_nominal_lower->GetV1()[0]));
88  g_nominal_lower->SetName("g_nominal_lower");
89 
90  /* create graph of beam positions relative to nominal_lower */
91  TGraph* g_nominal_lower_delta = graph_delta(g_nominal_lower, g_nominal);
92  if ( ! g_nominal_lower_delta )
93  return 1;
94  g_nominal_lower_delta->SetName("g_nominal_lower_delta");
95  g_nominal_lower_delta->SetLineWidth(2);
96  g_nominal_lower_delta->SetLineColor(kRed);
97 
98  /* Create Legend */
99 // TLegend* leg = new TLegend(0.3,0.7,0.6,0.9);
100 // leg->AddEntry(g_0,"Nominal beam","l");
101 // leg->AddEntry(g_a11,"a11","p");
102 // leg->AddEntry(g_a21,"a21","p");
103 // leg->AddEntry(g_a12,"a12","p");
104 // leg->AddEntry(g_a22,"a22","p");
105 
106  /* Create frame histogram for plot */
107  TH1F *h1 = new TH1F("h1","",10,0,15000);
108  h1->GetXaxis()->SetRangeUser(0,12000);
109  h1->GetYaxis()->SetRangeUser(-10,10);
110  h1->GetXaxis()->SetTitle("z (cm)");
111  h1->GetYaxis()->SetTitle("#Delta_{x} (mm)");
112 
113  /* Plot frame histogram */
114  TCanvas *c1 = new TCanvas();
115  h1->Draw("AXIS");
116 
117  //leg->Draw();
118 
119  g_nominal_delta->Draw("Lsame");
120  g_nominal_upper_delta->Draw("Lsame");
121  g_nominal_lower_delta->Draw("Lsame");
122 
123  c1->Print("track_deviations_new.eps");
124 
125  return 0;
126 }