StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
GainVoltPmtParameters.cxx
1 #include "GainVoltPmtParameters.h"
2 #include <math.h>
3 
4 int GainVoltPmtParameters::ioMode=2;
5 
8 double GainVoltPmtParameters::_defaultA = 2.56e-29;
9 double GainVoltPmtParameters::_defaultB = 10.71;
10 
11 GainVoltPmtParameters::GainVoltPmtParameters()
12 {}
13 
14 GainVoltPmtParameters::GainVoltPmtParameters(double refVoltage, double gains[5])
15 {
16  set(refVoltage,gains);
17 }
18 
19 GainVoltPmtParameters::GainVoltPmtParameters(int n, double volts[], double gains[])
20 {
21  set(n,volts,gains);
22 }
23 
24 GainVoltPmtParameters::GainVoltPmtParameters(const GainVoltPmtParameters& p)
25 {}
26 
27 GainVoltPmtParameters::~GainVoltPmtParameters()
28 {}
29 
30 GainVoltPmtParameters & GainVoltPmtParameters::operator=(const GainVoltPmtParameters&p)
31 {
32  _id = p._id;
33  _a = p._a;
34  _b = p._b;
35  _data = p._data;
36  return *this;
37 }
38 
42 void GainVoltPmtParameters::set(double refVolt, double gains[5])
43 {
44  if (refVolt<=100)
45  throw runtime_error("GainVoltPmtParameters::set(double,int,double[]) - F - invalid reference voltage");
46  _data[refVolt-100] = gains[0];
47  _data[refVolt- 50] = gains[1];
48  _data[refVolt ] = gains[2];
49  _data[refVolt- 50] = gains[3];
50  _data[refVolt+100] = gains[4];
51 }
52 
57 void GainVoltPmtParameters::set(int n, double volts[], double gains[])
58 {
59  if (n<=0)
60  throw runtime_error("GainVoltPmtParameters::set() - F - invalid number of points");
61  for (int i=0;i<n;i++)
62  {
63  //_data.push_back(pair<double,double>(volts[i],gains[i]));
64  _data[volts[i]] = gains[i];
65  }
66 }
67 
70 {
71 
72  map<double,double>::const_iterator i;
73  for (i=_data.begin();i!=_data.end();i++)
74  {
75  if (i->first<200 || i->second<1)
76  return false;
77  }
78  return true;
79 }
80 
82 {
83  //cout << "GainVoltPmtParameters::fit() - INFO - N points:"<< _data.size()<<endl;
84  if (isValid())
85  {
86  _fit.fit(&_data);
87  _a = _fit.getCoefficient();
88  _b = _fit.getExponent();
89  }
90  else
91  {
92  cout <<"GainVoltPmtParameters::fit() - Default Parameters used for " << *this<<endl;
93  _a = _defaultA;
94  _b = _defaultB;
95  }
96 }
97 
98 ostream& operator<<(ostream& os, GainVoltPmtParameters& object)
99 {
100  os << object._id << "\t";
101  if (object.ioMode&1) os << object._a <<"\t" << object._b<< "\t";
102  if (object.ioMode&2)
103  {
104  map<double,double>::const_iterator i;
105  if (object.ioMode&4)
106  {
107  os << object.getNPoints()<<"\t";
108  for (i=object._data.begin();i!=object._data.end();i++) os << i->first << "\t" << i->second<<"\t";
109  }
110  else
111  {
112  i=object._data.begin(); i++;i++;
113  os << i->first <<"\t";
114  for (i=object._data.begin();i!=object._data.end();i++) os << i->second << "\t";
115  }
116  }
117  os << endl;
118  return os;
119 }
120 
121 istream& operator>>(istream& is, GainVoltPmtParameters& object)
122 {
123  double x,y;
124  is >> object._id;
125  if (object.ioMode&1)
126  {
127  is >> x >> y;
128  object._a = x;
129  object._b = y;
130  }
131  if (object.ioMode&2)
132  {
133  int n;
134  if (object.ioMode&4)
135  {
136  is >> n;
137  for (int i=0;i<n;i++)
138  {
139  is >> x >> y;
140  object._data[x] = y;
141  }
142  }
143  else
144  {
145  double refVolt,gain;
146  is >> refVolt;
147  is >> gain; object._data[refVolt-100] = gain;
148  is >> gain; object._data[refVolt- 50] = gain;
149  is >> gain; object._data[refVolt ] = gain;
150  is >> gain; object._data[refVolt+ 50] = gain;
151  is >> gain; object._data[refVolt+100] = gain;
152  }
153  }
154  else
155  cout << "no data input "<<endl;
156  return is;
157 }
158 
161 {
162  return _a;
163 }
164 
167 {
168  return _b;
169 }
170 
172 double GainVoltPmtParameters::getGain(double voltage) const
173 {
174  if (voltage<=0)
175  throw runtime_error("GainVoltPmtParameters::getGain(double) - F - given voltage<0");
176  return exp(_a+_b*::log(voltage));
177 }
178 
180 double GainVoltPmtParameters::getVoltage(double gain) const
181 {
182  if (gain<=0) return 0;
183  return exp(::log(gain)/_b-_a);
184 }
185 
186 //Get the ChiSquare of the fit
187 //double GainVoltPmtParameters::getChiSquare() const
188 //{
189 // return _chisq;
190 //}
191 
194 {
195  return _data.size();
196 }
197 
200 {
201  cout << "N Points:" << getNPoints() << endl
202  << "Voltage(V) Gain(Relative)"<<endl
203  << "============================="<<endl;
204  map<double,double>::const_iterator i;
205  for (i=_data.begin();i!=_data.end();i++)
206  {
207  cout << i->first << "\t" << i->second<<endl;
208  }
209  cout <<"============================="<<endl
210  << " a : " << _a<< endl
211  << " b : " << _b<< endl;
212 
213 }
214 
216 {
217  return _id;
218 }
219 
220 void GainVoltPmtParameters::setDefaults(double multCoefficient, double exponent)
221 {
222  _defaultA = multCoefficient;
223  _defaultB = exponent;
224 }
static void setDefaults(double multCoefficient, double exponent)
double _a
multiplicative coefficient
double getExponent() const
Get exponent of the power law.
map< double, double > _data
HV/Gain data.
int getNPoints() const
Get the number of data points available and used for this PMT.
double getGain(double voltage) const
Get the gain obtained if the given voltage is applied.
PowerLawFit< double > _fit
Transient Fit Object.
PmtIdentifier & getPmtIdentifier()
Get the PMT identifier.
void set(double refVolt, double gains[5])
Set the voltages and gains.
void print()
Print the information of this PMT.
bool isValid() const
Determine whether the input data are valid.
double getMultConstant() const
Get multiplicative constant.
double getVoltage(double gain) const
Get the voltage need to obtain the given relative gain.