1 #include "StEmcCalibMaker.h"
7 #include <StEventTypes.h>
9 #include <StEmcUtil/geometry/StEmcGeom.h>
10 #include <StEmcUtil/voltageCalib/VoltCalibrator.h>
11 #include <StDbLib/StDbManager.hh>
12 #include <StDbLib/StDbTable.h>
13 #include <StDbLib/StDbConfigNode.hh>
14 #include <tables/St_emcCalib_Table.h>
36 mAcceptName =
"mAccept";
40 StEmcCalibMaker::~StEmcCalibMaker()
44 Int_t StEmcCalibMaker::Init()
46 mSpec =
new TH2F(mSpecName.Data(),
"Equal Spectra",mNChannel,+0.5,(float)mNChannel+0.5,(
int)mRange,-0.5,mRange-0.5);
47 mAccept =
new TH1F(mAcceptName.Data(),
"Accepted events",20,-0.5,19.5);
48 return StMaker::Init();
60 bool StEmcCalibMaker::accept()
64 if(!mCalib)
return false;
67 if(!mCalib->hasDetector(getDetector()))
return false;
70 if(mCalib->getNTracks()<mNMinTracks)
return false;
73 if(mCalib->getNTracks()>mNMaxTracks)
return false;
76 if(GetDate()<mDate) { mDate = GetDate(); mTime = GetTime();}
78 if(!mCalib->isTriggerOk())
return false;
81 long CTB = mCalib->getCTBSum();
82 long ZDC = mCalib->getZDCSum();
84 if(ZDC<mZDCMin || ZDC > mZDCMax)
return false;
87 if(CTB<mCTBMin || CTB > mCTBMax)
return false;
92 if(mNEvents%100==0) saveHist(mFileName.Data());
100 saveHist(mFileName.Data());
104 void StEmcCalibMaker::saveHist(
const Char_t *file)
106 cout <<
"Saving spec to file " << file << endl;
107 TFile *f =
new TFile(file,
"RECREATE");
114 void StEmcCalibMaker::loadHist(
const Char_t *file)
116 TFile *f =
new TFile(file);
117 TString N = mSpec->GetName();
119 TH2F *h = (TH2F*)f->Get(N.Data());
120 if(h){ mSpec->Reset(); mSpec->Add(h,1);}
126 void StEmcCalibMaker::addHist(
const Char_t *file)
128 TFile *f =
new TFile(file);
129 TString N = mSpec->GetName();
131 TH2F *h = (TH2F*)f->Get(N.Data());
132 if(h){ mSpec->Add(h,1);}
138 float StEmcCalibMaker::getTimeInterval(
int refDate,
int refTime)
143 Int_t year = (Int_t)(mDate/10000);
144 t0.tm_year=year-1900;
145 Int_t month = (Int_t)(mDate-year*10000)/100;
147 Int_t day = (Int_t)(mDate-year*10000-month*100);
149 Int_t hour = (Int_t)(mTime/10000);
151 Int_t minute= (Int_t)(mTime-hour*10000)/100;
153 Int_t second= (Int_t)(mTime-hour*10000-minute*100);
157 year = (Int_t)(refDate/10000);
158 t1.tm_year=year-1900;
159 month = (Int_t)(refDate-year*10000)/100;
161 day = (Int_t)(refDate-year*10000-month*100);
163 hour = (Int_t)(refTime/10000);
165 minute= (Int_t)(refTime-hour*10000)/100;
167 second= (Int_t)(refTime-hour*10000-minute*100);
171 time_t ttime0=mktime(&t0);
172 time_t ttime1=mktime(&t1);
173 double diff=difftime(ttime0,ttime1);
177 float ddd=fabs(diff/3600.);
181 void StEmcCalibMaker::getMeanAndRms(TH1D* tmp,
float amin,
float amax,
184 float mean=0,rms=0,sum=0;
185 if(tmp->Integral()>0)
187 Int_t bin0 = tmp->FindBin(amin);
188 Int_t bin1 = tmp->FindBin(amax);
189 for(Int_t j=bin0;j<bin1;j++)
191 float w = tmp->GetBinContent(j);
192 float x = tmp->GetBinCenter(j);
200 rms = ::sqrt(rms/sum-mean*mean);
209 void StEmcCalibMaker::getLogMeanAndRms(TH1D* tmp,
float amin,
float amax,
212 float mean=0,rms=0,sum=0;
214 if(tmp->Integral()>0)
216 Int_t bin0 = tmp->FindBin(amin);
217 Int_t bin1 = tmp->FindBin(amax);
218 for(Int_t j=bin0;j<bin1;j++)
220 float w = tmp->GetBinContent(j);
222 if(w>0) w = ::log(w);
223 float x = tmp->GetBinCenter(j);
231 rms = ::sqrt(rms/sum-mean*mean);
241 return StEmcGeom::instance(getDetector());
244 void StEmcCalibMaker::calcVoltages(TH1F *gain,
char* refFile,
char* voltageInput,
char* voltageOutput)
246 char GainShift[]=
"HVGainShift.dat";
249 ofstream out(GainShift);
250 ifstream inp(voltageInput);
256 inp>>a>>
id>>b>>c>>d>>e>>f>>v;
257 float gainShift = gain->GetBinContent(
id);
258 sprintf(line,
"%2d %5d %5d %5d %5d %5d %5d %7.5f",a,
id,b,c,d,e,f,gainShift);
265 cout <<
"Calculating voltages\n";
270 vc.setRefFile(refFile);
273 vc.setGainFile(GainShift);
275 vc.setVoltInputFile(voltageInput);
277 vc.setVoltOutputFile(voltageOutput);
virtual void Clear(Option_t *option="")
User defined functions.