StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
trsIonization.cc
1 //*******************************************************************
2 //
3 // $Id: trsIonization.cc,v 1.3 2003/09/02 17:59:15 perev Exp $
4 //
5 //*******************************************************************
6 //
7 // Description: This programs illustrates the use of the
8 // StTrsDeDx class. It demonstrates the bethe-bloch
9 // parameterization, the primary and secondary electron
10 // as well as the sub segment splitting.
11 //
12 // Usage: trsIonization [-s # of samples][-n # of subsegments][-t tracks]
13 // [-f forceOverWrite] hbookfile
14 //
15 // Example: trsIonization -s 45 -n 1 -t 10 -f hbook
16 //*******************************************************************
17 //
18 // $Log: trsIonization.cc,v $
19 // Revision 1.3 2003/09/02 17:59:15 perev
20 // gcc 3.2 updates + WarnOff
21 //
22 // Revision 1.2 1998/11/13 00:24:36 lasiuk
23 // TRUE/FALSE, pntrs in Db
24 //
25 // Revision 1.1 1998/11/10 17:12:00 fisyak
26 // Put Brian trs versin into StRoot
27 //
28 // Revision 1.1 1998/11/08 17:44:56 lasiuk
29 // Initial Revision
30 //
31 //*******************************************************************
32 
33 #include "Stiostream.h"
34 #include <unistd.h>
35 #include <vector>
36 #include <string>
37 
38 #include "StGlobals.hh"
39 #include "SystemOfUnits.h"
40 #include "StThreeVector.hh"
41 
42 #ifndef ST_NO_NAMESPACES
43 using namespace units;
44 #endif
45 
46 #include "StTrsDeDx.hh"
47 
48 #define HBOOK__DIAGNOSTIC
49 #ifdef HBOOK__DIAGNOSTIC
50 #include "StHbook.hh"
51 #endif
52 
53 #ifdef HBOOK__DIAGNOSTIC
54  StHbookFile *hbookFile;
55  const int tupleSize1 = 2;
56  const int tupleSize2 = 5;
57 
58  float tuple[tupleSize1];
59  float tuple2[tupleSize2];
60 
61  StHbookTuple *theTuple;
62  StHbookTuple *secTuple;
63 #endif
64 
65 // Functions:
66 void init_files(int overWrite, char* fname)
67 {
68  cout << "HBOOK file is " << fname << endl;
69 #ifdef HBOOK__DIAGNOSTIC
70  cout << "ForceOverwrite: " << overWrite << endl;
71 
72  if (!overWrite && !access(fname,F_OK|R_OK)) {
73  cerr << "ERROR: output file '" << fname << "' already exists." << endl;
74  exit(1);
75  }
76 
77  //
78  // Open histogram file and book tuple
79  //
80  hbookFile = new StHbookFile(fname);
81 
82  theTuple = new StHbookTuple("ionization", tupleSize1);
83  *theTuple << "bg" << "i" << book;
84 
85  secTuple = new StHbookTuple("dedx", tupleSize2);
86  *secTuple << "event" << "pri" << "sec" << "tot" << "sub" << book;
87 
88 // *thirdTuple = new StHbookTuple("segments", tupleSize3);
89 // *thirdTuple << "sub" << "pri" << "tot" << book;
90 
91 #endif
92 }
93 
94 void cleanup()
95 {
96 #ifdef HBOOK__DIAGNOSTIC
97  cout << "Save and close " << endl;
98  hbookFile->saveAndClose();
99 #endif
100 }
101 
102 int main(int argc, char* argv[])
103 {
104  // Parse the command line
105 
106  // default arguments
107  bool usage = false;
108  bool forceOverwrite;
109  int numberOfTracks = 1000;
110  int numberOfSamples = 45; // number of pads
111  float subSegments = 1.; // number of pieces to break a sample into
112  char* filename = "hbook";
113 
114  int c, opt=1;
115  while ((c = getopt(argc, argv,"s:n:t:fh")) != EOF) {
116  switch (c)
117  {
118  case 's': // numberOfSamples
119  if (argc < ++opt +1) {
120  usage = false;
121  }
122  numberOfSamples = atoi(argv[opt++]);
123  break;
124  case 'n': // number of 'subSegments'
125  if (argc < ++opt +1) {
126  usage = false;
127  }
128  subSegments = atof(argv[opt++]);
129  break;
130  case 't': // numberOfTracks
131  if (argc < ++opt +1) {
132  usage = false;
133  }
134  numberOfTracks = atoi(argv[opt++]);
135  case 'h':
136  usage = true;
137  break;
138  case 'f':
139  forceOverwrite = true;
140  break;
141  case 'o':
142  filename = (char *)strdup (argv[opt++]);\
143  break;
144  default:
145  cerr << "Unknown option" << endl;
146  cerr << "Exitting..." << endl;
147  exit(1);
148  }
149  }
150 
151  if (argc > 1)
152  usage = false;
153 
154  PR(usage);
155  if (usage) {
156  cerr << "Usage: " << argv[0] << " [-s # of samples (1)]\n";
157  cerr << " [-n # of subsegments][-t tracks][-f forceOverWrite]\n";
158  cerr << " [-h help] [-o hbookfile]" << endl;
159  exit(1);
160  }
161 
162  // DEBUG
163  PR(subSegments);
164  PR(numberOfSamples);
165  PR(numberOfTracks);
166  PR(filename);
167 
168 // Hbook Initialization
169 #ifdef HBOOK__DIAGNOSTIC
170  init_files(forceOverwrite, filename);
171 #endif
172 
173  double padLength = 1.95*centimeter;
174  cout << "subSegments= " << subSegments << endl;
175 
176  //string gas("Ne");
177  string gas("Ar");
178  StTrsDeDx myELoss(gas,padLength);
179  StTrsDeDx subELoss(gas,(padLength/subSegments));
180 
181  myELoss.print();
182 
183  int ii,jj,kk;
184 #ifndef ST_NO_TEMPLATE_DEF_ARGS
185  vector<int> sum;
186 #else
187  vector<int, allocator<int> > sum;
188 #endif
189 
190  double bg = .1;
191 
192  for(jj=1; jj<=5; jj++) {
193  double increment = bg;
194  for(kk=1; kk<10; kk++) {
195  bg+=increment;
196 
197  tuple[0] = static_cast<float>(bg);
198  tuple[1] = static_cast<float>(myELoss.betheBloch(bg));
199 
200  theTuple->fill(tuple);
201  }
202  bg+=increment;
203  }
204 
205 
206  //Create tracks:
207  for(int itrack=0; itrack<numberOfTracks; itrack++) {
208  for (int isample=0; isample<numberOfSamples; isample++) {
209 
210  sum.resize((StTrsDeDx::numberOfElectrons),0);
211  //myELoss.electrons(sum, bg);
212  myELoss.electrons(sum);
213  tuple2[0] = static_cast<float>(itrack);
214  tuple2[1] = static_cast<float>(sum[StTrsDeDx::primaries]);
215  tuple2[2] = static_cast<float>(sum[StTrsDeDx::secondaries]);
216  tuple2[3] = static_cast<float>(sum[StTrsDeDx::total]);
217 
218  int totalInSubsegment = 0;
219  for(int isubsample=0; isubsample<subSegments; isubsample++) {
220  sum.resize((StTrsDeDx::numberOfElectrons),0);
221  subELoss.electrons(sum);
222  totalInSubsegment += sum[StTrsDeDx::total];
223 
224 
225  tuple2[4] = static_cast<float>(totalInSubsegment);
226  }
227  secTuple->fill(tuple2);
228  } // isample
229  } // itrack
230 
231 
232  cleanup();
233 
234  return 0;
235 }