StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTpcDbElectronics.cc
1 /*****************************************************************
2  *
3  * $Id: StTpcDbElectronics.cc,v 1.7 2008/08/02 14:33:09 fisyak Exp $
4  *
5  * Author: Manuel Calderon de la Barca Sanchez & Brian Lasiuk Sept 13, 1999
6  *
7  *****************************************************************
8  * Description: Electronics parameters for TRS taken from DB for
9  * the STAR Main TPC
10  *
11  *****************************************************************
12  *
13  * $Log: StTpcDbElectronics.cc,v $
14  * Revision 1.7 2008/08/02 14:33:09 fisyak
15  * new interface to tpcT0
16  *
17  * Revision 1.6 2008/06/20 15:01:12 fisyak
18  * move from StTrsData to StTpcRawData
19  *
20  * Revision 1.5 2000/03/15 17:39:48 calderon
21  * Remove beeps
22  *
23  * Revision 1.4 2000/02/10 01:21:49 calderon
24  * Switch to use StTpcDb.
25  * Coordinates checked for consistency.
26  * Fixed problems with StTrsIstream & StTrsOstream.
27  *
28  * Revision 1.3 2000/01/10 23:14:29 lasiuk
29  * Include MACROS for compatiblity with SUN CC5
30  *
31  * Revision 1.2 1999/12/08 02:10:41 calderon
32  * Modified to eliminate warnings on Linux.
33  *
34  * Revision 1.1 1999/10/11 23:55:20 calderon
35  * Version with Database Access and persistent file.
36  * Not fully tested due to problems with cons, it
37  * doesn't find the local files at compile time.
38  * Yuri suggests forcing commit to work directly with
39  * files in repository.
40  *
41  ******************************************************************/
42 #include "SystemOfUnits.h"
43 #include "StTpcDbElectronics.hh"
44 //#include "StUtilities/StMessMgr.h"
45 #include "StTpcDb/StTpcDb.h"
46 
47 #ifndef ST_NO_EXCEPTIONS
48 # include <stdexcept>
49 # if !defined(ST_NO_NAMESPACES)
50  using std::invalid_argument;
51 # endif
52 #endif
53 
54 StTpcElectronics* StTpcDbElectronics::mInstance = 0; // static data member
55 
56 StTpcDbElectronics::StTpcDbElectronics() { /* nopt */ }
57 
58 StTpcDbElectronics::StTpcDbElectronics(StTpcDb* globalDbPointer)
59 {
60  gTpcDbPtr = globalDbPointer;
61  mNominalGain = gTpcDbPtr->Electronics()->nominalGain();
62  mSamplingFrequency = gTpcDbPtr->Electronics()->samplingFrequency();
63  mTZero = gTpcDbPtr->Electronics()->tZero();
64  mAdcConversion = gTpcDbPtr->Electronics()->adcConversion();
65  mAdcConversionCharge = gTpcDbPtr->Electronics()->adcCharge();
66  mNumberOfTimeBins = gTpcDbPtr->Electronics()->numberOfTimeBins();
67  mAveragePedestal = static_cast<int>(gTpcDbPtr->Electronics()->averagePedestal());
68  mShapingTime = gTpcDbPtr->Electronics()->shapingTime();
69  mTau = gTpcDbPtr->Electronics()->tau();
70 
71 #ifndef ST_NO_NAMESPACES
72  using namespace units;
73 #endif
74 
75  //Units Integrity
76  mNominalGain *= (millivolt)/(coulomb*1.e-15); // mV/fC
77  mSamplingFrequency *= MHz;
78  mTZero *= microsecond;
79  mAdcConversion *= (millivolt);
80  mAdcConversionCharge *= (coulomb*1.e-15);
81  mShapingTime *= nanosecond;
82  mTau *= nanosecond;
83 }
84 
86 StTpcDbElectronics::instance()
87 {
88  if (!mInstance) {
89 #ifndef ST_NO_EXCEPTIONS
90  throw invalid_argument("StTpcDbElectronics::getInstance(): Argument Missing!");
91 #else
92  std::cerr << "StTpcDbElectronics::getInstance(): Argument Missing!" << endl;
93  std::cerr << "No arguments for instantiantion" << endl;
94  std::cerr << "Exiting..." << endl;
95 #endif
96  }
97  return mInstance;
98 }
99 
101 StTpcDbElectronics::instance(StTpcDb* gTpcDbPtr)
102 {
103  if (!mInstance) {
104  mInstance = new StTpcDbElectronics(gTpcDbPtr);
105  }
106  else {
107  std::cerr << "StTpcDbElectronics::instance()" << endl;
108  std::cerr << "\tWARNING:" << endl;
109  std::cerr << "\tSingleton class is already instantiated" << endl;
110  std::cerr << "\tArgument ignored!!" << endl;
111  std::cerr << "\tContinuing..." << endl;
112  }
113  return mInstance;
114 }
115 
116 double StTpcDbElectronics::channelGain(int sector, int row, int pad) const
117 {
118  // This should be where channel by channel gains are looked up
119  // Note: the DB has getGain(), getOnlineGain(), getNominalGain(), and
120  // getRelativeGain(). We use Nominal gain I believe.
121  return 1.;//gTpcDbPtr->Gain(sector)->getNominalGain(row,pad);
122 }
123 
124 double StTpcDbElectronics::channelGain(StTpcPadCoordinate& coord) const
125 {
126  return channelGain(coord.sector(), coord.row(), (Int_t) coord.pad());
127 }
128 
129 int StTpcDbElectronics::pedestal(int sector, int row, int pad, int timeB) const
130 {
131  return averagePedestal();
132 }
133 
134 int StTpcDbElectronics::pedestal(StTpcPadCoordinate& coord) const
135 {
136  return pedestal(coord.sector(), coord.row(), (Int_t) coord.pad(), (Int_t) coord.timeBucket());
137 }
138 double StTpcDbElectronics::tZero(int sector, int row, int pad) const
139 {
140  return gTpcDbPtr->tpcT0()->T0(sector,row,pad);
141 }
142 double StTpcDbElectronics::tZero(StTpcPadCoordinate& coord) const
143 {
144  return tZero(coord.sector(), coord.row(), (Int_t) coord.pad());
145 }
146 void StTpcDbElectronics::print(ostream& os) const
147 {
148 #ifndef ST_NO_NAMESPACES
149  using namespace units;
150 #endif
151  os << "Electronics Data Base Parameters" << endl;
152  os << "=======================================" << endl;
153  os << "Analog:" << endl;
154  os << "nominalGain: " << mNominalGain/((volt*.001)/(coulomb*1.e-15)) << " mV/fC" << endl;
155  os << "samplingFrequency: " << mSamplingFrequency/MHz << " MHz" << endl;
156  os << "tZero: " << mTZero/microsecond << " us" << endl;
157  os << "shapingTime: " << mShapingTime/nanosecond << " ns" << endl;
158  os << "shapingTime2: " << mTau/nanosecond << " ns" << endl;
159 
160  os << "\nDigital:" << endl;
161  os << "adcConversion: " << mAdcConversion/(volt*.001) << " mV/channel" << endl;
162  os << "adcConversionCharge: " << mAdcConversionCharge/(coulomb*1.e-15) << " mV/fC" << endl;
163  os << "numberOfTimeBins: " << mNumberOfTimeBins << endl;
164  os << "averagePedestal: " << mAveragePedestal << " channels" << endl;
165  os << endl;
166 // os << "Example of Gain per pad for Sector 1, Row 1" << endl;
167 // os << " Row Pad Gain for this Pad" << endl;
168 // os << "==========================================" << endl;
169 // for(int i=0; i<gTpcDbPtr->PadPlaneGeometry()->numberOfPadsAtRow(1); i++) {
170 // os.width(3);
171 // os.setf(ios::right,ios::adjustfield);
172 // os << 1;
173 // os.width(9);
174 // os << i+1;
175 // os.width(15);
176 // os << channelGain(1,1,i+1) << endl;
177 // }
178 // os << endl;
179 }