StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VoltCalibrator.cxx
1 #include "VoltCalibrator.h"
33 #include "GainVoltCoeffCalculator.h"
34 #include "PmtIdentifier.h"
35 #include "GainVoltPmtParameters.h"
36 ClassImp(VoltCalibrator)
37 
39 {}
40 
41 VoltCalibrator::~VoltCalibrator()
42 {}
43 
44 void VoltCalibrator::setRefFile(const char * name)
45 {
46  refFile = name;
47 }
48 
49 void VoltCalibrator::setGainFile(const char *name)
50 {
51  gainFile = name;
52 }
53 
54 void VoltCalibrator::setVoltInputFile(const char *name)
55 {
56  currentVoltFile = name;
57 }
58 
59 void VoltCalibrator::setVoltOutputFile(const char *name)
60 {
61  newVoltFile = name;
62 }
63 
64 void VoltCalibrator::process()
65 {
66  // open files
67  ifstream ref;
68  ifstream gain;
69  ifstream currentVolt;
70  ofstream coeff;
71  ofstream newVolt;
72  ref.open(refFile);
73  gain.open(gainFile);
74  currentVolt.open(currentVoltFile);
75  newVolt.open(newVoltFile);
76  coeff.open("hvGainCoeff.dat");
77 
78  // read the reference file, calculate the coefficients
79  GainVoltCoeffCalculator calculator;
80  ref >> calculator;
81  calculator.process();
82  coeff << calculator;
83 
84  // loop on all channels, read current volt, read requested gain change
85  // calculate new voltage, write voltage
86  PmtIdentifier pmtId;
87  PmtIdentifier pmtIdCurrent;
88  double mygain[4800];
89  double g,v,newV,cGain;
90 
91  // read all gains from file and save in this vector
92  while(!gain.eof())
93  {
94  gain >> pmtId >>g;
95  mygain[pmtId._softId-1]=g;
96  }
97 
98  // loop over current voltage database file
99  while(!currentVolt.eof())
100  {
101  currentVolt >> pmtIdCurrent >> v;
102  long soft = pmtIdCurrent._softId;
103  long serial = pmtIdCurrent._serial;
104  g = mygain[soft-1];
105  if(g==0 || g==1) newV = v;
106  else
107  {
108  vector<GainVoltPmtParameters*>::iterator i;
109  for (i=calculator.begin();i!=calculator.end();i++)
110  {
111  PmtIdentifier identifier = (*i)->getPmtIdentifier();
112  if(identifier._serial==serial)
113  {
114  cout <<"PMT found in DB | ";
115  cGain = (*i)->getGain(v);
116  newV = (*i)->getVoltage(g*cGain);
117  goto NEXT;
118  }
119  }
120  double A = 2.56e-29;
121  double B = 10.71;
122  cGain = exp(A+B*log(v));
123  newV = exp(log(cGain*g)/B-A);
124  cout <<"PMT is not in DB | ";
125  }
126  NEXT:
127  cout <<"id = "<<soft<<" pmtId = "<<pmtIdCurrent<<" V = "<<v<<" cGain = "<<cGain<<" newV = "<<newV<<" corr = "<<g<<endl;
128  newVolt<<pmtIdCurrent<<"\t"<<newV<<endl;
129  }
130 
131  ref.close();
132  gain.close();
133  currentVolt.close();
134  newVolt.close();
135  coeff.close();
136 }
137 
142 {
143  // open files
144  ifstream ref;
145  ofstream gain;
146  ofstream volt;
147  ref.open(refFile);
148  gain.open("gainTemplate.dat");
149  volt.open("hvTemplate.dat");
150  // read the reference file, calculate the coefficients
151  GainVoltCoeffCalculator calculator;
152  ref >> calculator;
153  vector<GainVoltPmtParameters*>::iterator i;
154  for (i=calculator.begin();i!=calculator.end();i++)
155  {
156  cout << (*i)->getPmtIdentifier() << "\t" << 1 << endl;
157  gain << (*i)->getPmtIdentifier() << "\t" << 1 << endl;
158  volt << (*i)->getPmtIdentifier() << "\t" << 777 << endl;
159  }
160  ref.close();
161  gain.close();
162  volt.close();
163 }
const char * currentVoltFile
Current Voltage Setting File.
const char * refFile
Reference Gain/Volt File.
const char * gainFile
Requested Relative Gain Change File.
const char * newVoltFile
New Voltage Setting File.