StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
trsExample.cc
1 //*******************************************************/
2 // $Id: trsExample.cc,v 1.4 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 // :: To produce a histogram file, define DIAGNOSTICS
10 #define DIAGNOSTICS
11 //
12 // $Log: trsExample.cc,v $
13 // Revision 1.4 2003/09/02 17:59:15 perev
14 // gcc 3.2 updates + WarnOff
15 //
16 // Revision 1.3 1999/01/22 23:36:47 lasiuk
17 // macro TRUE
18 //
19 // Revision 1.2 1999/01/18 20:59:06 lasiuk
20 // function selection
21 //
22 // Revision 1.1 1999/01/18 10:54:48 lasiuk
23 // Initial revision
24 /********************************************************/
25 #include <Stiostream.h>
26 #include <unistd.h> // needed for access()
27 #include "Stiostream.h"
28 
29 #include <string>
30 #include <vector>
31 #include <utility> // pair
32 #include <algorithm> // min() max()
33 
34 // SCL
35 #include "Randomize.h"
36 // General TRS
37 #include "StCoordinates.hh"
38 #include "StTpcCoordinateTransform.hh"
39 
40 // TRS
41 // db
42 #include "StTpcSimpleGeometry.hh"
43 #include "StTpcSimpleSlowControl.hh"
44 #include "StTpcSimpleElectronics.hh"
45 #include "StSimpleMagneticField.hh"
46 #include "StTrsDeDx.hh"
47 
48 // processes
49 #include "StTrsFastChargeTransporter.hh"
50 #include "StTrsSlowAnalogSignalGenerator.hh"
51 #include "StTrsFastDigitalSignalGenerator.hh"
52 
53 // containers
54 #include "StTrsChargeSegment.hh"
55 #include "StTrsMiniChargeSegment.hh"
56 #include "StTrsAnalogSignal.hh"
57 #include "StTrsWireBinEntry.hh"
58 #include "StTrsWireHistogram.hh"
59 
60 #include "StTrsSector.hh"
61 #include "StTrsDigitalSector.hh"
62 
63 #define VERBOSE 1
64 #define ivb if(VERBOSE)
65 
66 /* -------------------------------------------------------------------- */
67 /* Main Program */
68 /* -------------------------------------------------------------------- */
69 int main (int argc,char* argv[])
70 {
71  int breakNumber = 1;
72 
73  int opt = 1;
74  int c;
75  bool usage = (argc > 1 ? false : true);
76  while ((c = getopt(argc, argv,"b:")) != EOF)
77  switch (c) {
78  case 'b':
79  if (argc < ++opt +1)
80  usage = true;
81  breakNumber = atoi(argv[opt++]);
82  break;
83  default:
84  break;
85  }
86 
87  PR(breakNumber);
88 
89  //
90  // Make the DataBase
91  //
92  // Check File access
93  //
94  string geoFile("../run/TPCgeo.conf");
95  if (access(geoFile.c_str(),R_OK)) {
96  cerr << "ERROR:\n" << geoFile << " cannot be opened" << endl;
97  //shell(pwd);
98  cerr << "Exitting..." << endl;
99  exit(1);
100  }
101 
102  string scFile("../run/sc.conf"); // contains B field
103  if (access(scFile.c_str(),R_OK)) {
104  cerr << "ERROR:\n" << scFile << " cannot be opened" << endl;
105  cerr << "Exitting..." << endl;
106  exit(1);
107  }
108 
109  string electronicsFile("../run/electronics.conf");
110  if (access(electronicsFile.c_str(),R_OK)) {
111  cerr << "ERROR:\n" << electronicsFile << " cannot be opened" << endl;
112  cerr << "Exitting..." << endl;
113  exit(1);
114  }
115 
116  string magFile("../run/example.conf"); // contains B field
117  if (access(magFile.c_str(),R_OK)) {
118  cerr << "ERROR:\n" << magFile << " cannot be opened" << endl;
119  cerr << "Exitting..." << endl;
120  exit(1);
121  }
122 
123  //
124  // The DataBases
125  //
126  StTpcGeometry *geomDb =
127  StTpcSimpleGeometry::instance(geoFile.c_str());
128 
129  StTpcSlowControl *scDb =
130  StTpcSimpleSlowControl::instance(scFile.c_str());
131  //scDb->print();
132 
133  StMagneticField *magDb =
134  StSimpleMagneticField::instance(magFile.c_str());
135 
136  StTpcElectronics *electronicsDb =
137  StTpcSimpleElectronics::instance(electronicsFile.c_str());
138 
139  string gas("Ar");
140  StTrsDeDx myEloss(gas);
141  myEloss.print();
142 
143  //
144  // create a Sector: (for analog Siganals)
145  //
146  StTrsSector *sector = new StTrsSector(geomDb);
147 
148  // digital signals (chars)
149  StTrsDigitalSector *digitalSector = new StTrsDigitalSector(geomDb);
150 
151  //
152  // Processes
153  //
154  StTrsChargeTransporter *trsTransporter =
155  StTrsFastChargeTransporter::instance(geomDb, scDb, &myEloss, magDb);
156 // trsTransporter->setChargeAttachment(true);
157 // trsTransporter->setGatingGridTransparency(true);
158 // trsTransporter->setTransverseDiffusion(true);
159 // trsTransporter->setLongitudinalDiffusion(true);
160 // trsTransporter->setExB(false);
161 
162  StTrsWireHistogram *theWirePlane =
163  StTrsWireHistogram::instance(geomDb, scDb);
164 // theWirePlane->setDoGasGain(true); // True by default
165 // theWirePlane->setDoGasGainFluctuations(true);
166 // theWirePlane->setDoTimeDelay(true);
167 
168  StTrsAnalogSignalGenerator *trsAnalogSignalGenerator =
169  StTrsSlowAnalogSignalGenerator::instance(geomDb, scDb, electronicsDb, sector);
170  dynamic_cast<StTrsSlowAnalogSignalGenerator*>(trsAnalogSignalGenerator)->
171  setChargeDistribution(StTrsSlowAnalogSignalGenerator::endo);
172  //setChargeDistribution(StTrsSlowAnalogSignalGenerator::gatti);
173  //setChargeDistribution(StTrsSlowAnalogSignalGenerator::dipole);
174  dynamic_cast<StTrsSlowAnalogSignalGenerator*>(trsAnalogSignalGenerator)->
175  //setElectronicSampler(StTrsSlowAnalogSignalGenerator::delta);
176  setElectronicSampler(StTrsSlowAnalogSignalGenerator::symmetricGaussianApproximation);
177  //setElectronicSampler(StTrsSlowAnalogSignalGenerator::symmetricGaussianExact);
178  //setElectronicSampler(StTrsSlowAnalogSignalGenerator::asymmetricGaussianApproximation);
179  //setElectronicSampler(StTrsSlowAnalogSignalGenerator::realShaper);
180 // trsAnalogSignalGenerator->setDeltaRow(0);
181  trsAnalogSignalGenerator->setDeltaPad(2);
182 // trsAnalogSignalGenerator->setSignalThreshold(.0001);
183 // trsAnalogSignalGenerator->setSuppressEmptyTimeBins(true);
184  // ??should the type of function be an option ???
185 
186  StTrsDigitalSignalGenerator *trsDigitalSignalGenerator =
187  StTrsFastDigitalSignalGenerator::instance(electronicsDb, sector, digitalSector);
188 
189 
190  // Read a charge Segment (g2t) from GEANT:
191  double bg = 3; // minimum ionizing particle
192 
193  // Energy deposited per centimeter:
194  float dE = 2.444*keV; // deposited per cm of Ar
195  float dS = 1.*centimeter;
196  vector<int> all[3];
197 
198  StThreeVector<double> position(0.,1500.*millimeter,200.*millimeter);
199  StThreeVector<double> momentum(1.*GeV,0.,0.);
200 
201  StTrsChargeSegment aSegment(position,
202  momentum,
203  dE,
204  dS);
205 
206  PR(aSegment);
207  list<StTrsMiniChargeSegment> comp;
208  list<StTrsMiniChargeSegment>::iterator iter;
209 
210  aSegment.split(&myEloss, magDb, breakNumber, &comp);
211 
212  copy(comp.begin(), comp.end(), ostream_iterator<StTrsMiniChargeSegment>(cout,"\n"));
213  cout << endl;
214 
215  PR(comp.size());
216 
217  // Loop over the miniSegments
218  for(iter = comp.begin();
219  iter != comp.end();
220  iter++) {
221 
222  cout << endl;
223  PR(*iter);
224  //
225  // TRANSPORT HERE
226  //
227  trsTransporter->transportToWire(*iter);
228 
229 
230  //
231  // CHARGE COLLECTION AND AMPLIFICATION
232  //
233  //PR(*iter);
234  StTrsWireBinEntry anEntry(iter->position(), iter->charge());
235  PR(anEntry);
236  theWirePlane->addEntry(anEntry);
237 
238  }
239 
240  cout << "\a***************************\a\n" << endl;
241 
242 
243 
244  //
245  // Generate the ANALOG Signals on pads
246  //
247  // -- calculate the induced charge on pads
248  trsAnalogSignalGenerator->inducedChargeOnPad(theWirePlane);
249  //
250  // -- sample the ANALOG signals that were induced on pads
251  cout << "sampleAnalogSiganl() " << endl;
252  trsAnalogSignalGenerator->sampleAnalogSignal();
253 
254 
255  //
256  // Digitize the Signals
257  //
258  trsDigitalSignalGenerator->digitizeSignal();
259 
260 
261  //
262  // Write it out!
263  //
264 
265  return 0;
266 }