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