00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "VoltCalibrator.h"
00033 #include "GainVoltCoeffCalculator.h"
00034 #include "PmtIdentifier.h"
00035 #include "GainVoltPmtParameters.h"
00036 ClassImp(VoltCalibrator)
00037
00038 VoltCalibrator::VoltCalibrator()
00039 {}
00040
00041 VoltCalibrator::~VoltCalibrator()
00042 {}
00043
00044 void VoltCalibrator::setRefFile(const char * name)
00045 {
00046 refFile = name;
00047 }
00048
00049 void VoltCalibrator::setGainFile(const char *name)
00050 {
00051 gainFile = name;
00052 }
00053
00054 void VoltCalibrator::setVoltInputFile(const char *name)
00055 {
00056 currentVoltFile = name;
00057 }
00058
00059 void VoltCalibrator::setVoltOutputFile(const char *name)
00060 {
00061 newVoltFile = name;
00062 }
00063
00064 void VoltCalibrator::process()
00065 {
00066
00067 ifstream ref;
00068 ifstream gain;
00069 ifstream currentVolt;
00070 ofstream coeff;
00071 ofstream newVolt;
00072 ref.open(refFile);
00073 gain.open(gainFile);
00074 currentVolt.open(currentVoltFile);
00075 newVolt.open(newVoltFile);
00076 coeff.open("hvGainCoeff.dat");
00077
00078
00079 GainVoltCoeffCalculator calculator;
00080 ref >> calculator;
00081 calculator.process();
00082 coeff << calculator;
00083
00084
00085
00086 PmtIdentifier pmtId;
00087 PmtIdentifier pmtIdCurrent;
00088 double mygain[4800];
00089 double g,v,newV,cGain;
00090
00091
00092 while(!gain.eof())
00093 {
00094 gain >> pmtId >>g;
00095 mygain[pmtId._softId-1]=g;
00096 }
00097
00098
00099 while(!currentVolt.eof())
00100 {
00101 currentVolt >> pmtIdCurrent >> v;
00102 long soft = pmtIdCurrent._softId;
00103 long serial = pmtIdCurrent._serial;
00104 g = mygain[soft-1];
00105 if(g==0 || g==1) newV = v;
00106 else
00107 {
00108 vector<GainVoltPmtParameters*>::iterator i;
00109 for (i=calculator.begin();i!=calculator.end();i++)
00110 {
00111 PmtIdentifier identifier = (*i)->getPmtIdentifier();
00112 if(identifier._serial==serial)
00113 {
00114 cout <<"PMT found in DB | ";
00115 cGain = (*i)->getGain(v);
00116 newV = (*i)->getVoltage(g*cGain);
00117 goto NEXT;
00118 }
00119 }
00120 double A = 2.56e-29;
00121 double B = 10.71;
00122 cGain = exp(A+B*log(v));
00123 newV = exp(log(cGain*g)/B-A);
00124 cout <<"PMT is not in DB | ";
00125 }
00126 NEXT:
00127 cout <<"id = "<<soft<<" pmtId = "<<pmtIdCurrent<<" V = "<<v<<" cGain = "<<cGain<<" newV = "<<newV<<" corr = "<<g<<endl;
00128 newVolt<<pmtIdCurrent<<"\t"<<newV<<endl;
00129 }
00130
00131 ref.close();
00132 gain.close();
00133 currentVolt.close();
00134 newVolt.close();
00135 coeff.close();
00136 }
00137
00141 void VoltCalibrator::createTemplates()
00142 {
00143
00144 ifstream ref;
00145 ofstream gain;
00146 ofstream volt;
00147 ref.open(refFile);
00148 gain.open("gainTemplate.dat");
00149 volt.open("hvTemplate.dat");
00150
00151 GainVoltCoeffCalculator calculator;
00152 ref >> calculator;
00153 vector<GainVoltPmtParameters*>::iterator i;
00154 for (i=calculator.begin();i!=calculator.end();i++)
00155 {
00156 cout << (*i)->getPmtIdentifier() << "\t" << 1 << endl;
00157 gain << (*i)->getPmtIdentifier() << "\t" << 1 << endl;
00158 volt << (*i)->getPmtIdentifier() << "\t" << 777 << endl;
00159 }
00160 ref.close();
00161 gain.close();
00162 volt.close();
00163 }