StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
trsDiffusion.cc
1 //**************************************************************/
2 // $Id: trsDiffusion.cc,v 1.3 2003/09/02 17:59:15 perev Exp $
3 //
4 // Author: brian, Oct 1998
5 //
6 // Purpose: Evaluation of the diffusion characteristics of TRS
7 //
8 // $Log: trsDiffusion.cc,v $
9 // Revision 1.3 2003/09/02 17:59:15 perev
10 // gcc 3.2 updates + WarnOff
11 //
12 // Revision 1.2 1998/11/13 00:24:36 lasiuk
13 // TRUE/FALSE, pntrs in Db
14 //
15 // Revision 1.1 1998/11/10 17:12:00 fisyak
16 // Put Brian trs versin into StRoot
17 //
18 // Revision 1.1 1998/11/08 17:44:56 lasiuk
19 // Initial Revision
20 //
21 //**************************************************************/
22 #include <Stiostream.h>
23 #include <unistd.h> // needed for access()
24 
25 #include <string>
26 #include <utility> // pair
27 #include <algorithm> // min() max()
28 
29 // SCL
30 #include "Randomize.h"
31 #include "StHbook.hh"
32 
33 // General TRS
34 #include "StCoordinates.hh"
35 #include "StTpcCoordinateTransform.hh"
36 
37 // TRS
38 // db
39 #include "StTpcSimpleGeometry.hh"
40 #include "StTpcSimpleSlowControl.hh"
41 #include "StTpcSimpleElectronics.hh"
42 #include "StSimpleMagneticField.hh"
43 #include "StTrsDeDx.hh"
44 
45 // processes
46 #include "StTrsFastChargeTransporter.hh"
47 #include "StTrsSlowAnalogSignalGenerator.hh"
48 #include "StTrsFastDigitalSignalGenerator.hh"
49 
50 // containers
51 #include "StTrsAnalogSignal.hh"
52 #include "StTrsWireBinEntry.hh"
53 #include "StTrsWireHistogram.hh"
54 
55 #include "StTrsSector.hh"
56 
57 
58 #define VERBOSE 1
59 #define ivb if(VERBOSE)
60 
61 void printPad(tpcSector& a)
62 {
63  ostream_iterator<StTrsAnalogSignal> out(cout,",");
64 
65  for(int irow=0; irow<a.size(); irow++)
66  cout << irow << " " << "<" << a[irow].size() << "> ";
67 
68 // for(int ipad=0; ipad<a[irow].size(); ipad++) {
69 // cout << irow << " " << ipad << "<" << a[irow][ipad].size() << "> ";
70 // //copy(a[irow][ipad].begin(),a[irow][ipad].end(),out);
71 // cout << endl;
72 // }
73 }
74 
75 // Sort the "analogSignal"s on a pad according to the time
76 // void sortTime(sector& a)
77 // {
78 // for(int irow=0; irow<a.size(); irow++)
79 // for(int ipad=0; ipad<PADS[irow]; ipad++) {
80 // sort(a[irow][ipad].begin(),a[irow][ipad].end(),comp_last());
81 // }
82 // }
83 
84 
85 /* -------------------------------------------------------------------- */
86 /* Main Program */
87 /* -------------------------------------------------------------------- */
88 int main (int argc,char* argv[])
89 {
90  const int tupleSize = 4;
91  StHbookFile hbookFile("hbook");
92  StHbookTuple theTuple("Transport", tupleSize);
93  float tuple[tupleSize];
94  theTuple << "x" << "y" << "z" << "amp" << book;
95 
96  const int tupleSize2 = 5;
97  StHbookTuple secTuple("WireHistogram", tupleSize2);
98  float tuple2[tupleSize2];
99  secTuple << "x" << "y" << "z" << "wire" << "amp" << book;
100 
101  int irow, ipad, itbin; // ctrs
102 
103  //
104  // Make the DataBase
105  //
106  // Check File access
107  //
108  string geoFile("../run/TPCgeo.conf");
109  if (access(geoFile.c_str(),R_OK)) {
110  cerr << "ERROR:\n" << geoFile << " cannot be opened" << endl;
111  //shell(pwd);
112  cerr << "Exitting..." << endl;
113  exit(1);
114  }
115 
116  string scFile("../run/sc.conf");
117  if (access(scFile.c_str(),R_OK)) {
118  cerr << "ERROR:\n" << scFile << " cannot be opened" << endl;
119  cerr << "Exitting..." << endl;
120  exit(1);
121  }
122 
123  string magFile("../run/example.conf"); // contains B field
124  if (access(magFile.c_str(),R_OK)) {
125  cerr << "ERROR:\n" << scFile << " cannot be opened" << endl;
126  cerr << "Exitting..." << endl;
127  exit(1);
128  }
129 
130  string electronicsFile("../run/electronics.conf");
131  if (access(electronicsFile.c_str(),R_OK)) {
132  cerr << "ERROR:\n" << electronicsFile << " cannot be opened" << endl;
133  cerr << "Exitting..." << endl;
134  exit(1);
135  }
136 
137  //
138  // The DataBases
139  //
140  StTpcGeometry *geomDb =
141  StTpcSimpleGeometry::instance(geoFile.c_str());
142 
143  StTpcSlowControl *scDb =
144  StTpcSimpleSlowControl::instance(scFile.c_str());
145 
146  StMagneticField *magDb =
147  StSimpleMagneticField::instance(magFile.c_str());
148 
149  StTpcElectronics *electronicsDb =
150  StTpcSimpleElectronics::instance(electronicsFile.c_str());
151 
152 
153  string gas("Ar");
154  StTrsDeDx myEloss(gas);
155 
156 
157  //
158  // create a Sector:
159  //
160  StTrsSector *sector = new StTrsSector(geomDb);
161 
162  //
163  // Processes
164  //
165  StTrsChargeTransporter *trsTransporter =
166  StTrsFastChargeTransporter::instance(geomDb, scDb, &myEloss, magDb);
167  // set status:
168 // trsTransporter->setChargeAttachment(true);
169 // trsTransporter->setGatingGridTransparency(true);
170  trsTransporter->setTransverseDiffusion(true);
171  trsTransporter->setLongitudinalDiffusion(true);
172 // trsTransporter->setExB(true);
173 
174  StTrsWireHistogram *myWireHistogram =
175  StTrsWireHistogram::instance(geomDb, scDb);
176 // myWireHistogram->setDoGasGain(true); // True by default
177 // myWireHistogram->setDoGasGainFluctuations(false);
178 // myWireHistogram->setDoTimeDelay(false);
179 
180  StTrsAnalogSignalGenerator *trsSignalGenerator =
181  StTrsSlowAnalogSignalGenerator::instance(geomDb, scDb, electronicsDb, sector);
182 // trsSignalGenerator->setDeltaRow(0);
183 // trsSignalGenerator->setDeltaPad(0);
184 // trsSignalGenerator->setSignalThreshold(.0001);
185 // trsSignalGenerator->setSuppressEmptyTimeBins(true);
186  // ??select the type of function?
187 
188  StTrsDigitalSignalGenerator *trsDigitalGenerator =
189  StTrsFastDigitalSignalGenerator::instance(electronicsDb, sector);
190 
191  //
192  // Generate the Ionization
193  //
194 
195  float maxDistance = geomDb->lastOuterSectorAnodeWire();
196  PR(maxDistance);
197  float zPosition = 1.*meter;
198  float position = 52.*centimeter;
199  float dS;
200  do {
201  dS = 5.*myEloss.nextInteraction();
202 // PR(dS);
203  position += dS;
204 
205  if(position>maxDistance) break;
206 
207  double primaryEnergyDistribution;
208  int totalElectrons = myEloss.secondary(&primaryEnergyDistribution) + 1;
209  PR(totalElectrons);
210 
211  // Make a StTrsMiniChargeSegment (the thing that must be transported)
213  aMiniSegment(StThreeVector<double>(0, position, zPosition),
214  totalElectrons, // q
215  0); // dl
216  PR(aMiniSegment);
217 
218  //
219  // TRANSPORT HERE
220  //
221  trsTransporter->transportToWire(aMiniSegment);
222  PR(aMiniSegment);
223 
224  tuple[0] = static_cast<float>(aMiniSegment.position().x());
225  tuple[1] = static_cast<float>(aMiniSegment.position().y());
226  tuple[2] = static_cast<float>(aMiniSegment.position().z());
227  tuple[3] = static_cast<float>(aMiniSegment.charge());
228 
229  theTuple.fill(tuple);
230 
231  //
232  // CHARGE COLLECTION AND AMPLIFICATION
233  //
234  StTrsWireBinEntry anEntry(aMiniSegment.position(), aMiniSegment.charge());
235  PR(anEntry);
236  myWireHistogram->addEntry(anEntry);
237 
238  cout << "okay..." << endl;
239  cout << myWireHistogram->lastEntry() << endl;
240 
241  if(myWireHistogram->lastEntry() != 0) {
242  tuple2[0] = static_cast<float>(myWireHistogram->lastEntry()->position().x());
243  tuple2[1] = static_cast<float>(myWireHistogram->lastEntry()->position().y());
244  tuple2[2] = static_cast<float>(myWireHistogram->lastEntry()->position().z());
245  tuple2[3] = static_cast<float>(myWireHistogram->lastWire());
246  tuple2[4] = static_cast<float>(myWireHistogram->lastEntry()->numberOfElectrons());
247 
248  secTuple.fill(tuple2);
249  }
250 
251  cout << "*********" << endl;
252  }while(true);
253 
254  hbookFile.saveAndClose();
255 
256  return 0;
257 }