00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "Stiostream.h"
00034 #include <unistd.h>
00035 #include <vector>
00036 #include <string>
00037
00038 #include "StGlobals.hh"
00039 #include "SystemOfUnits.h"
00040 #include "StThreeVector.hh"
00041
00042 #ifndef ST_NO_NAMESPACES
00043 using namespace units;
00044 #endif
00045
00046 #include "StTrsDeDx.hh"
00047
00048 #define HBOOK__DIAGNOSTIC
00049 #ifdef HBOOK__DIAGNOSTIC
00050 #include "StHbook.hh"
00051 #endif
00052
00053 #ifdef HBOOK__DIAGNOSTIC
00054 StHbookFile *hbookFile;
00055 const int tupleSize1 = 2;
00056 const int tupleSize2 = 5;
00057
00058 float tuple[tupleSize1];
00059 float tuple2[tupleSize2];
00060
00061 StHbookTuple *theTuple;
00062 StHbookTuple *secTuple;
00063 #endif
00064
00065
00066 void init_files(int overWrite, char* fname)
00067 {
00068 cout << "HBOOK file is " << fname << endl;
00069 #ifdef HBOOK__DIAGNOSTIC
00070 cout << "ForceOverwrite: " << overWrite << endl;
00071
00072 if (!overWrite && !access(fname,F_OK|R_OK)) {
00073 cerr << "ERROR: output file '" << fname << "' already exists." << endl;
00074 exit(1);
00075 }
00076
00077
00078
00079
00080 hbookFile = new StHbookFile(fname);
00081
00082 theTuple = new StHbookTuple("ionization", tupleSize1);
00083 *theTuple << "bg" << "i" << book;
00084
00085 secTuple = new StHbookTuple("dedx", tupleSize2);
00086 *secTuple << "event" << "pri" << "sec" << "tot" << "sub" << book;
00087
00088
00089
00090
00091 #endif
00092 }
00093
00094 void cleanup()
00095 {
00096 #ifdef HBOOK__DIAGNOSTIC
00097 cout << "Save and close " << endl;
00098 hbookFile->saveAndClose();
00099 #endif
00100 }
00101
00102 int main(int argc, char* argv[])
00103 {
00104
00105
00106
00107 bool usage = false;
00108 bool forceOverwrite;
00109 int numberOfTracks = 1000;
00110 int numberOfSamples = 45;
00111 float subSegments = 1.;
00112 char* filename = "hbook";
00113
00114 int c, opt=1;
00115 while ((c = getopt(argc, argv,"s:n:t:fh")) != EOF) {
00116 switch (c)
00117 {
00118 case 's':
00119 if (argc < ++opt +1) {
00120 usage = false;
00121 }
00122 numberOfSamples = atoi(argv[opt++]);
00123 break;
00124 case 'n':
00125 if (argc < ++opt +1) {
00126 usage = false;
00127 }
00128 subSegments = atof(argv[opt++]);
00129 break;
00130 case 't':
00131 if (argc < ++opt +1) {
00132 usage = false;
00133 }
00134 numberOfTracks = atoi(argv[opt++]);
00135 case 'h':
00136 usage = true;
00137 break;
00138 case 'f':
00139 forceOverwrite = true;
00140 break;
00141 case 'o':
00142 filename = (char *)strdup (argv[opt++]);\
00143 break;
00144 default:
00145 cerr << "Unknown option" << endl;
00146 cerr << "Exitting..." << endl;
00147 exit(1);
00148 }
00149 }
00150
00151 if (argc > 1)
00152 usage = false;
00153
00154 PR(usage);
00155 if (usage) {
00156 cerr << "Usage: " << argv[0] << " [-s # of samples (1)]\n";
00157 cerr << " [-n # of subsegments][-t tracks][-f forceOverWrite]\n";
00158 cerr << " [-h help] [-o hbookfile]" << endl;
00159 exit(1);
00160 }
00161
00162
00163 PR(subSegments);
00164 PR(numberOfSamples);
00165 PR(numberOfTracks);
00166 PR(filename);
00167
00168
00169 #ifdef HBOOK__DIAGNOSTIC
00170 init_files(forceOverwrite, filename);
00171 #endif
00172
00173 double padLength = 1.95*centimeter;
00174 cout << "subSegments= " << subSegments << endl;
00175
00176
00177 string gas("Ar");
00178 StTrsDeDx myELoss(gas,padLength);
00179 StTrsDeDx subELoss(gas,(padLength/subSegments));
00180
00181 myELoss.print();
00182
00183 int ii,jj,kk;
00184 #ifndef ST_NO_TEMPLATE_DEF_ARGS
00185 vector<int> sum;
00186 #else
00187 vector<int, allocator<int> > sum;
00188 #endif
00189
00190 double bg = .1;
00191
00192 for(jj=1; jj<=5; jj++) {
00193 double increment = bg;
00194 for(kk=1; kk<10; kk++) {
00195 bg+=increment;
00196
00197 tuple[0] = static_cast<float>(bg);
00198 tuple[1] = static_cast<float>(myELoss.betheBloch(bg));
00199
00200 theTuple->fill(tuple);
00201 }
00202 bg+=increment;
00203 }
00204
00205
00206
00207 for(int itrack=0; itrack<numberOfTracks; itrack++) {
00208 for (int isample=0; isample<numberOfSamples; isample++) {
00209
00210 sum.resize((StTrsDeDx::numberOfElectrons),0);
00211
00212 myELoss.electrons(sum);
00213 tuple2[0] = static_cast<float>(itrack);
00214 tuple2[1] = static_cast<float>(sum[StTrsDeDx::primaries]);
00215 tuple2[2] = static_cast<float>(sum[StTrsDeDx::secondaries]);
00216 tuple2[3] = static_cast<float>(sum[StTrsDeDx::total]);
00217
00218 int totalInSubsegment = 0;
00219 for(int isubsample=0; isubsample<subSegments; isubsample++) {
00220 sum.resize((StTrsDeDx::numberOfElectrons),0);
00221 subELoss.electrons(sum);
00222 totalInSubsegment += sum[StTrsDeDx::total];
00223
00224
00225 tuple2[4] = static_cast<float>(totalInSubsegment);
00226 }
00227 secTuple->fill(tuple2);
00228 }
00229 }
00230
00231
00232 cleanup();
00233
00234 return 0;
00235 }