Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
material2root.cc
Go to the documentation of this file.
1 // Author: David Lawrence June 25, 2004
2 //
3 //
4 // hd_ana.cc
5 //
6 
7 #include "DANA/DApplication.h"
8 using namespace std;
9 
10 #include <DVector3.h>
11 #include <HDGEOMETRY/DRootGeom.h>
12 #include <HDGEOMETRY/DGeometry.h>
13 
14 #include <TROOT.h>
15 #include <TFile.h>
16 #include <TH2D.h>
17 
18 int32_t RUN_NUMBER = -1;
19 
20 void ParseCommandLineArguments(int narg, char *argv[]);
21 void Usage(string mess="");
22 
23 
24 //-----------
25 // main
26 //-----------
27 int main(int narg, char *argv[])
28 {
29 
30  ParseCommandLineArguments(narg, argv);
31 
32 
33  // open ROOT file
34  TFile *f = new TFile("material.root","RECREATE","Produced by material2root");
35  cout<<"Opened ROOT file \""<<"material.root"<<"\" ..."<<endl;
36 
37  DApplication *dapp = new DApplication(narg, argv);
38  DRootGeom *rg = new DRootGeom(dapp);
39  DGeometry *geom = dapp->GetDGeometry(RUN_NUMBER);
40 
41  TH2D *radlen_LL = new TH2D("radlen_LL", "Radiation Length;z (cm); r(cm); rad. length (cm)", 2500, -100.0, 1170.0, 1000, 0.0, 125.0);
42  TH2D *radlen_table = (TH2D*)radlen_LL->Clone("radlen_table");
43  TH2D *radlen_LL_xy = new TH2D("radlen_LL_xy", "Radiation Length;x (cm); y(cm); rad. length (cm)", 900, -10.0, 10.0, 900, -10.0, 10.0);
44  TH2D *radlen_table_xy = (TH2D*)radlen_LL_xy->Clone("radlen_table_xy");
45  TH2D *A_LL = (TH2D*)radlen_LL->Clone("A_LL");
46  TH2D *A_table = (TH2D*)radlen_LL->Clone("A_table");
47  TH2D *Z_LL = (TH2D*)radlen_LL->Clone("Z_LL");
48  TH2D *Z_table = (TH2D*)radlen_LL->Clone("Z_table");
49  TH2D *density_LL = (TH2D*)radlen_LL->Clone("density_LL");
50  density_LL->SetTitle("Density");
51  density_LL->SetXTitle("z (cm)");
52  density_LL->SetYTitle("r (cm)");
53  density_LL->SetZTitle("density (g/cm^3)");
54  TH2D *density_table = (TH2D*)radlen_LL->Clone("density_table");
55 
56  for(int ir = 1; ir<=radlen_LL->GetNbinsY(); ir++){
57  double r = radlen_LL->GetYaxis()->GetBinCenter(ir);
58  for(int iz = 1; iz<=radlen_LL->GetNbinsX(); iz++){
59  double z = radlen_LL->GetXaxis()->GetBinCenter(iz);
60 
61  DVector3 pos(r, 0.0, z);
62  double density, A, Z, RadLen;
63 
64  density = A = Z = RadLen = 0.0;
65 
66  rg->FindMatLL(pos, density, A, Z, RadLen);
67  radlen_LL->Fill(z, r, RadLen);
68  A_LL->Fill(z, r, A);
69  Z_LL->Fill(z, r, Z);
70  density_LL->Fill(z, r, density);
71 
72  density = A = Z = RadLen = 0.0;
73 
74  //rg->FindMatTable(pos, density, A, Z, RadLen);
75  geom->FindMat(pos, density, A, Z, RadLen);
76  radlen_table->Fill(z, r, RadLen);
77  A_table->Fill(z, r, A);
78  Z_table->Fill(z, r, Z);
79  density_table->Fill(z, r, density);
80  }
81  }
82 
83  for(int ix = 1; ix<=radlen_LL_xy->GetNbinsX(); ix++){
84  double x = radlen_LL_xy->GetXaxis()->GetBinCenter(ix);
85  for(int iy = 1; iy<=radlen_LL_xy->GetNbinsX(); iy++){
86  double y = radlen_LL_xy->GetYaxis()->GetBinCenter(iy);
87 
88  DVector3 pos(x, y, 65.0);
89  double density, A, Z, RadLen;
90 
91  rg->FindMatLL(pos, density, A, Z, RadLen);
92  radlen_LL_xy->Fill(x, y, RadLen);
93 
94  //rg->FindMatTable(pos, density, A, Z, RadLen);
95  geom->FindMat(pos, density, A, Z, RadLen);
96  radlen_table_xy->Fill(x, y, RadLen);
97  }
98  }
99 
100  f->Write();
101 
102  return 0;
103 }
104 
105 //-----------
106 // ParseCommandLineArguments
107 //-----------
108 void ParseCommandLineArguments(int narg, char *argv[])
109 {
110  if( narg < 2 ) Usage();
111 
112  for(int i=1; i<narg; i++){
113  string arg = argv[i];
114  string next = (i+1) < narg ? argv[i+1]:"";
115  bool missing_arg = false;
116 
117  if( arg == "-h" || arg =="--help" ) Usage();
118  if( arg == "-r" ){
119  if( next.find("-") != 0){
120  RUN_NUMBER = atoi(next.c_str());
121  }else{ missing_arg = true; }
122  }
123 
124  if(missing_arg) Usage( "argument " + arg + " requires and argument!" );
125  }
126 
127  if(RUN_NUMBER<0) {
128  Usage("Run number MUST be specified with -r option!");
129  }
130 }
131 
132 
133 //-----------
134 // Usage
135 //-----------
136 void Usage(string mess)
137 {
138  cout << endl;
139  cout << "Usage:" << endl;
140  cout << " material2root -r RUN" << endl;
141  cout << endl;
142  cout << mess << endl;
143  cout << endl;
144 
145  exit(0);
146 }
147 
DApplication * dapp
TVector3 DVector3
Definition: DVector3.h:14
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
#define y
jerror_t FindMat(DVector3 &pos, double &rhoZ_overA, double &rhoZ_overA_logI, double &RadLen) const
Definition: DGeometry.cc:327
jerror_t FindMatLL(DVector3 pos, double &rhoZ_overA, double &rhoZ_overA_logI, double &RadLen) const
Definition: DRootGeom.cc:402
TF1 * f
Definition: FitGains.C:21
void ParseCommandLineArguments(int &narg, char *argv[])
Definition: hd_dump.cc:124
DGeometry * GetDGeometry(unsigned int run_number)
static unsigned int RUN_NUMBER
Definition: mc2coda.c:24
void Usage(JApplication &app)
Definition: hd_ana.cc:33
int main(int argc, char *argv[])
Definition: gendoc.cc:6