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