StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTrsFastDigitalSignalGenerator.cc
1 /***************************************************************************
2  *
3  * $Id :StTrsFastDigitalSignalGenerator.cc ,v1.1 1999/10/01 17:15:00 long Exp $$
4  *
5  * Author:
6  ***************************************************************************
7  *
8  * Description: 10 bit to 8 bit translation simulation of digitization
9  *
10  ***************************************************************************
11  *
12  * $Log: StTrsFastDigitalSignalGenerator.cc,v $
13  * Revision 1.31 2008/06/20 15:01:17 fisyak
14  * move from StTrsData to StTpcRawData
15  *
16  * Revision 1.30 2007/07/12 20:25:05 fisyak
17  * Use StarLogger, use time of flight, fix cluster shape
18  *
19  * Revision 1.29 2005/09/09 22:12:49 perev
20  * Bug fix + IdTruth added
21  *
22  * Revision 1.27 2005/07/19 22:23:05 perev
23  * Bug fix
24  *
25  * Revision 1.26 2003/12/24 13:44:53 fisyak
26  * Add (GEANT) track Id information in Trs; propagate it via St_tpcdaq_Maker; account interface change in StTrsZeroSuppressedReaded in StMixerMaker
27  *
28  * Revision 1.25 2000/06/07 02:03:11 lasiuk
29  * exit/abort ultimatum
30  *
31  * Revision 1.24 2000/02/24 16:29:34 long
32  * add 0.5 in digitalization for test
33  *
34  * Revision 1.24 2000/02/23 16:14:30 long
35  * add 0.5 in digitalization for test
36  * Revision 1.23 2000/02/10 01:21:50 calderon
37  * Switch to use StTpcDb.
38  * Coordinates checked for consistency.
39  * Fixed problems with StTrsIstream & StTrsOstream.
40  *
41  * Revision 1.22 2000/01/10 23:14:30 lasiuk
42  * Include MACROS for compatiblity with SUN CC5
43  *
44  * Revision 1.21 1999/12/08 02:10:42 calderon
45  * Modified to eliminate warnings on Linux.
46  *
47  * Revision 1.20 1999/11/10 15:46:25 calderon
48  * Made changes to reduce timing, including:
49  * Made coordinate transfrom a data member of StTrsAnalogSignalGenerator
50  * Added upper-lower bound instead of symmetric cut.
51  * Revived checking if signal is above threshold.
52  *
53  * Revision 1.19 1999/11/05 22:18:16 calderon
54  *
55  * Made private copy constructor and operator= in StTrsDigitalSector.
56  * Renamed DigitalSignalGenerators: Fast -> Old, Parameterized -> Fast
57  * and use new "Fast" as default.
58  * Added StTrsZeroSuppressedReader and StTrsZeroSuppressedReader for DAQ type
59  * data access.
60  * Removed vestigial for loop in sampleAnalogSignal() method.
61  * Write version of data format in .trs data file.
62  *
63  * Revision 1.4 1999/10/22 00:00:14 calderon
64  * -added macro to use Erf instead of erf if we have HP and Root together.
65  * -constructor with char* for StTrsDedx so solaris doesn't complain
66  * -remove mZeros from StTrsDigitalSector. This causes several files to
67  * be modified to conform to the new data format, so only mData remains,
68  * access functions change and digitization procedure is different.
69  *
70  * Revision 1.3 1999/10/06 21:53:19 long
71  * comment out one message output
72  *
73  * Revision 1.2 1999/10/04 15:56:55 long
74  * add 10 to 8 bit transformation
75  *
76  * Revision 1.1 1999/10/04 15:45:27 long
77  * add 10 to 8 bit transformation
78  *
79 
80  *
81  **************************************************************************/
82 #include <unistd.h>
83 #include <utility>
84 
85 #include "StTrsFastDigitalSignalGenerator.hh"
86 
87 StTrsDigitalSignalGenerator* StTrsFastDigitalSignalGenerator::mInstance = 0; // static member
88 
89 
90 StTrsFastDigitalSignalGenerator::StTrsFastDigitalSignalGenerator(StTpcElectronics* el, StTrsSector* sec,double conv)
92 {
93  mSimpleConversion = conv;
94  if (!mSimpleConversion) mSimpleConversion = mElectronicsDb->adcConversion();
95 }
96 StTrsFastDigitalSignalGenerator::~StTrsFastDigitalSignalGenerator() {/* missing */}
97 
98 
100 StTrsFastDigitalSignalGenerator::instance(StTpcElectronics* el, StTrsSector* sec, double conv)
101 {
102  if(!mInstance && !el) {
103  cerr << "StTrsFastDigitalSignalGenerator::instance() Must Supply a File name" << endl;
104  cerr << "Aborting..." << endl;
105  abort();
106  }
107  if(!mInstance) {
108  mInstance = new StTrsFastDigitalSignalGenerator(el, sec, conv);
109  }
110  // else do nothing
111 
112  return mInstance;
113 }
114 
115 
116 unsigned char StTrsFastDigitalSignalGenerator::do10to8Translation(int index)const
117 {
118 
119  if(index<-1.0e-30)index=0;
120  if(index>1023)index=1023;
121  return log10to8_table[index];
122 }
123 void StTrsFastDigitalSignalGenerator::digitizeSignal()
124 {
125 
126  // Loop over the sector
127 
128 
129 
130  // Make a digital Pad!
131  StDigitalTimeBins digPadData;
132  // Remember mSector is the "normal" analog sector!
133  // cout << "StTrsFastDigitalSignalGenerator::digitizeSignal()" << endl;
134  for(int irow=1; irow<=mSector->numberOfRows(); irow++) {
135  for(unsigned int ipad=1; ipad<=mSector->padsOfRow(irow).size(); ipad++) {
136 
137  tpcTimeBins &currentPad = mSector->timeBinsOfRowAndPad(irow,ipad);
138 
139  int currentSize = currentPad.size();
140  if(!currentSize) continue;
141  //cout << "dig() r/p " << irow << '/' << ipad << endl;
142  // Make sure the digital Pad is clear!
143  digPadData.clear();
144  // cout<<irow<<" row "<<ipad<<" pad"<<endl;
145 
146  int currentTimeBin = -2005;
147  for (int icur=0;icur<currentSize;icur++) {
148  float amp = currentPad[icur].amplitude();
149  if (!amp) continue;
150  if (mSimpleConversion>0) amp = amp/mSimpleConversion;//+0.5;
151  int temporary_digitalAmplitude = int(amp);
152  if (!temporary_digitalAmplitude) continue;
153 
154  int timeBinIndex = int(currentPad[icur].time()+1e-3);
155  assert(timeBinIndex > currentTimeBin);
156  if (timeBinIndex != currentTimeBin+1) digPadData.push_back(StDigitalPair(timeBinIndex));
157  currentTimeBin = timeBinIndex;
158 
159  unsigned char digitalAmplitude = do10to8Translation(temporary_digitalAmplitude);
160  int id = currentPad[icur].id();
161  digPadData.back().add(digitalAmplitude,id);
162  } // the iterator (mTimeSequence)
163 //VP currentPad.clear();
164  mDigitalSector->assignTimeBins(irow,ipad,&digPadData);
165 
166  } // pads
167  }// rows
168 }
169 
170 void StTrsFastDigitalSignalGenerator::addCorrelatedNoise()
171 {
172  cerr << "StTrsFastDigitalSignalGenerator::addCorrelatedNoise()" << endl;
173  cerr << "Not Implemented!" << endl;
174 }
175 
176 void StTrsFastDigitalSignalGenerator::addWhiteNoise()
177 {
178  cerr << "StTrsFastDigitalSignalGenerator::addWhiteNoise()" << endl;
179  cerr << "Not Implemented!" << endl;
180 }