EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rad_length.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file rad_length.C
1 //
2 // Shape up and customization of the original rad_length.C script;
3 //
4 
5 // May want to produce plot either vs pseudorapidity or vs theta;
6 #define _ETA_MODE_
7 
8 // [2..178] degrees (theta mode); [-4..+4] (eta mode);
9 #define _THETA_MIN_ 2.0
10 #define _ETA_MAX_ 4.0
11 
12 #define _BIN_NUM_ 200
13 
14 #define _YAXIS_MAX_ 0.12
15 
16 struct {
17  char *name;
18  int color;
19 } dets[] = {
20  // Yes, better to have fixed colors;
21  {"cave", kMagenta},
22  {"pipe", kGray},
23  {"vst", kYellow},
24  {"fst", kGreen},
25  {"bst", kGreen},
26  {"TPC/TpcIfc", kBlue},
27  {"TPC/TpcGas", kCyan},
28  //{"MM", kBlue},
29  //{"TPC/TpcOfc", kBlue},
30  //{"TPC/TpcEndcap", kRed},
31  //{"fgt", kOrange},
32  //{"bgt", kOrange},
33 };
34 
35 TString RemoveCrap(TString &path)
36 {
37  TString ret;
38  unsigned len = path.Length();
39  bool skip = true;
40 
41  // Admittedly this will NOT work for volume names containing underscores;
42  for(unsigned iq=0; iq<len; iq++) {
43  if (path[iq] == '/')
44  skip = false;
45  else if (path[iq] == '_')
46  skip = true;
47 
48  if (!skip) ret += path[iq];
49  } //for iq
50 
51  return ret;
52 } // RemoveCrap()
53 
54 
55 void rad_length() {
56  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
57 
58  TFile* f = new TFile("simparams.root");
59  f->Get("FairBaseParSet");
60 
61  // NB: CAVE material is not really accounted (so only subdetectors);
62  TString cavePrefix = "/cave";
63  int cave = -1;
64 
65  vector <TString> subs;
66  for(int i=0; i<sizeof(dets)/sizeof(dets[0]); i++)
67  if (!strcmp(dets[i].name, "cave")) {
68  subs.push_back(cavePrefix);
69  cave = i;
70  }
71  else
72  subs.push_back(cavePrefix + "/" + dets[i].name);
73 
74  // Yes, this way it works in CINT (but can not use sizeof(dets) trick directly);
75  const int NSUB = subs.size();
76 
77  TH1F* h[NSUB];
78  for (int i = 0; i < NSUB; i++) {
79 #ifdef _ETA_MODE_
80  TH1F* tmp = h[i] = new TH1F(dets[i].name, dets[i].name, _BIN_NUM_, -_ETA_MAX_, _ETA_MAX_);
81 #else
82  TH1F* tmp = h[i] = new TH1F(dets[i].name, dets[i].name, _BIN_NUM_, _THETA_MIN_, 180.0 - _THETA_MIN_);
83 #endif
84 
85  tmp->SetMarkerStyle(21);
86  tmp->SetMarkerColor(dets[i].color);
87  tmp->SetMarkerSize(1.0);
88  tmp->SetFillColor(dets[i].color);
89  }
90 
91  for (Int_t i = 0; i < _BIN_NUM_; i++) {
92  // The trick is that I do not want to account cave air beyond the last tracking element
93  // along this theta line; makes sense?;
94  double caveAccu = 0.0;
95 
96 #ifdef _ETA_MODE_
97  double eta_bin_width = 2 * _ETA_MAX_/_BIN_NUM_;
98  double eta = -_ETA_MAX_ + (i - 0.5)*eta_bin_width;
99  double theta = 2 * atan(exp(-eta));
100 #else
101  double theta_bin_width = (180.0 - 2*_THETA_MIN_)/_BIN_NUM_;
102  double theta = (_THETA_MIN_ + (i - 0.5)*theta_bin_width)*TMath::Pi()/180.;
103 #endif
104  printf("bin# %3d (of %3d) ...\n", i, _BIN_NUM_);
105 
106  double xx[3] = {0.0, 0.0, 0.1}, nn[3] = {TMath::Sin(theta), 0.0, TMath::Cos(theta)};
107  gGeoManager->SetCurrentPoint (xx);
108  gGeoManager->SetCurrentDirection(nn);
109 
110  for(TGeoNode *node = gGeoManager->GetCurrentNode(); ; ) {
111  TGeoMaterial *material = node->GetVolume()->GetMaterial();
112  double radlen = material->GetRadLen();
113 
114  gGeoManager->FindNextBoundary();
115  double thickness = gGeoManager->GetStep();
116 
117  // Well, basically want to convert /cave_1/fstAir06_77/fst@06_6 to
118  // /cave/fstAir06/fst@06, etc;
119  TString path = RemoveCrap(gGeoManager->GetPath());
120 
121  // See whether I'm interested in such a part; NB: first match wins!;
122  for (int iii = 0; iii < NSUB; iii++)
123  if (iii == cave && path.EqualTo( cavePrefix )) {
124  // Pending approval ...;
125  caveAccu += thickness/radlen;
126  break;
127  }
128  else if (iii != cave && path.BeginsWith( subs[iii] )) {
129  if (caveAccu) {
130  h[cave]->SetBinContent(i+1, h[cave]->GetBinContent(i+1) + caveAccu);
131  caveAccu = 0.0;
132  } //if
133 
134  h[iii]->SetBinContent(i+1, h[iii]->GetBinContent(i+1) + thickness/radlen);
135  break;
136  } //for..if
137 
138  // Switch to next node along {xx, nn[]} 3D line;
139  node = gGeoManager->Step();
140  assert(gGeoManager->IsEntering());
141 
142  // Once out of volume, break;
143  if (gGeoManager->IsOutside()) break;
144  } //for inf
145  } //for i
146 
147  THStack *hs = new THStack("hs","EIC Detector Geometry: Radiation Length Scan");
148  for (int i = 0; i < NSUB; i++) {
149  hs->Add( h[i] );
150  }
151 
152  TCanvas* c1 = new TCanvas("c1","c1", 800, 600);
153  c1->SetFrameBorderSize(0);
154  hs->Draw();
155 
156 #ifdef _ETA_MODE_
157  hs->GetXaxis()->SetTitle("Pseudorapidity");
158 #else
159  hs->GetXaxis()->SetTitle("Theta");
160 #endif
161  hs->GetXaxis()->SetLabelSize(0.03);
162  hs->GetYaxis()->SetTitle("radiation length, X / X0");
163  hs->GetYaxis()->SetLabelSize(0.03);
164  hs->SetMaximum(_YAXIS_MAX_);
165 
166  TLegend *legend=new TLegend(0.38,0.88 - NSUB*.04,0.62,0.88);
167  legend->SetTextFont(72);
168  legend->SetTextSize(0.03);
169  for (int i = 0; i < NSUB; i++) {
170  legend->AddEntry(h[ NSUB - i - 1 ], dets[NSUB - i - 1].name,"p");
171  }
172  legend->Draw();
173 
174  c1->SaveAs("radlen.gif");
175  //exit(0);
176 }