Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
plot_compare_fun4all_eicroot.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file plot_compare_fun4all_eicroot.C
1 #include "TraceBox.h"
2 
3 int
5 {
6  /**** Chose input files ****/
7  /* File with IR mangets configuration*/
8  TString fname_irmag("example/proton-magnets-250GeV-opt2.dat");
9  /* File with Fun4All output*/
10  TString fname_fun4all("example/eRHIC_proton-magnets-250GeV-opt2_250GeV_0mrad.root");
11  /* File with EICROOT output*/
12  TString fname_eicroot("example/eicroot-track_proton-magnets-250GeV-opt2_250GeV_0mrad.txt");
13 
14  /* Open iput file with trajectories from GEANT4 */
15  TFile *fin = new TFile(fname_fun4all);
16 
17  /* Get tree from file */
18  TTree *tin = (TTree*)fin->Get("T");
19 
20  int nhits = 0;
21  tin->SetBranchAddress("n_G4HIT_FWDDISC",&nhits);
22 
23  /* create graph of particle trajectory */
24  /* Use only first event (for now) */
25  tin->GetEntry(0);
26  cout << "hits: " << nhits << endl;
27 
28  tin->Draw("G4HIT_FWDDISC.x:G4HIT_FWDDISC.z","Entry$==0","");
29 
30  TGraph* g1 = new TGraph(nhits*2, &(tin->GetV2()[0]), &(tin->GetV1()[0]));
31  g1->SetMarkerStyle(7);
32  g1->SetMarkerSize(1);
33  g1->SetMarkerColor(kRed);
34 
35  /* Get tree from file */
36  TTree *tin2 = new TTree();
37  tin2->ReadFile(fname_eicroot,"x/F:y:z");
38 
39  int nhits = tin2->GetEntries();
40  tin2->Draw("x:z","","");
41 
42  TGraph* g2 = new TGraph(nhits, &(tin2->GetV2()[0]), &(tin2->GetV1()[0]));
43  g2->SetMarkerStyle(7);
44  g2->SetMarkerSize(1);
45  g2->SetMarkerColor(kGreen+1);
46 
47  /* Create frame histogram for plot */
48  TH1F *h1 = new TH1F("h1","",10,0,15000);
49  h1->GetXaxis()->SetRangeUser(0,5000);
50  h1->GetYaxis()->SetRangeUser(-50,70);
51  h1->GetXaxis()->SetTitle("Z(cm)");
52  h1->GetYaxis()->SetTitle("X(cm)");
53 
54  /* Plot frame histogram */
55  TCanvas *c1 = new TCanvas();
56  h1->Draw("AXIS");
57 
58  /* Read IR configuration file- this needs to go somewhere else using parameters and a .root file to store them */
59  ifstream irstream(fname_irmag);
60 
61  if(!irstream.is_open())
62  {
63  cout << "ERROR: Could not open IR configuration file " << fname_irmag << endl;
64  return -1;
65  }
66 
67  while(!irstream.eof()){
68  string str;
69  getline(irstream, str);
70  if(str[0] == '#') continue; //for comments
71  stringstream ss(str);
72 
73  string name;
74  double center_z, center_x, center_y, aperture_radius, length, angle, B, gradient;
75 
76  ss >> name >> center_z >> center_x >> center_y >> aperture_radius >> length >> angle >> B >> gradient;
77 
78  if ( name == "" ) continue; //for empty lines
79 
80  // convert units from m to cm
81  center_x *= 100;
82  center_y *= 100;
83  center_z *= 100;
84  aperture_radius *= 100;
85  length *= 100;
86 
87  // define magnet outer radius
88  float outer_radius = 30.0; // cm
89 
90  //flip sign of dipole field component- positive y axis in Geant4 is defined as 'up',
91  // positive z axis as the hadron-going direction
92  // in a right-handed coordinate system x,y,z
93  B *= -1;
94 
95  // convert angle from millirad to rad
96  angle = (angle / 1000.);
97 
98  // Place IR component
99  cout << "New IR component: " << name << " at z = " << center_z << endl;
100 
101  string volname = "IRMAGNET_";
102  volname.append(name);
103 
104  /* Draw box for magnet position on canvas */
105  TPolyLine *b1 = TraceBox( angle, center_z, center_x, length, aperture_radius, outer_radius ); //upper box
106  TPolyLine *b2 = TraceBox( angle, center_z, center_x, length, -1 * aperture_radius, -1 * outer_radius ); //lower box
107 
108  if(B != 0 && gradient == 0.0){
109  //dipole magnet
110  b1->SetFillColor(kOrange+1);
111  b2->SetFillColor(kOrange+1);
112  }
113  else if( B == 0 && gradient != 0.0){
114  //quad magnet
115  b1->SetFillColor(kBlue+1);
116  b2->SetFillColor(kBlue+1);
117  }
118  else{
119  //placeholder magnet
120  b1->SetFillColor(kGray+1);
121  b2->SetFillColor(kGray+1);
122  }
123  b1->Draw("Fsame");
124  b2->Draw("Fsame");
125  }
126 
127  /* draw particle trajectory */
128  g2->Draw("LPsame");
129  g1->Draw("LPsame");
130 
131  return 0;
132 }