1 #include "StEmcEqualMaker.h"
5 #include "StEventTypes.h"
7 #include "StEmcUtil/geometry/StEmcGeom.h"
8 #include "StDbLib/StDbManager.hh"
9 #include "StDbLib/StDbTable.h"
10 #include "StDbLib/StDbConfigNode.hh"
11 #include "tables/St_emcCalib_Table.h"
21 StEmcEqualMaker::~StEmcEqualMaker()
25 Int_t StEmcEqualMaker::Init()
28 mA =
new TH1F(
"mA",
"",getNChannel(),0.5,getNChannel()+0.5);
29 mB =
new TH1F(
"mB",
"",getNChannel(),0.5,getNChannel()+0.5);
30 mADistr =
new TH1F(
"mADistr",
"",200,0,10);
31 mBDistr =
new TH1F(
"mBDistr",
"",200,-10,10);
32 mStatus =
new TH1F(
"mStatus",
"",getNChannel(),0.5,getNChannel()+0.5);
33 mRefSlopes =
new TH1F(
"mRefSlopes",
"",getNChannel(),0.5,getNChannel()+0.5);
34 mRefAmps =
new TH1F(
"mRefAmps",
"",getNChannel(),0.5,getNChannel()+0.5);
35 mSlopes =
new TH1F(
"mSlopes",
"",getNChannel(),0.5,getNChannel()+0.5);
36 mAmps =
new TH1F(
"mAmps",
"",getNChannel(),0.5,getNChannel()+0.5);
37 mSlopesTheta =
new TH2F(
"mSlopesTheta",
"",40,45*pi/180,135*pi/180,100,0,100);
39 mSpecName =
"mSpecEqual";
40 mAcceptName =
"mAcceptEqual";
41 return StEmcCalibMaker::Init();
50 if(!accept())
return kStOk;
52 for(
int i=0;i<mNChannel;i++)
55 float rms = getCalib()->getPedRms(mDetector,
id);
56 float adc = (float) getCalib()->getADCPedSub(mDetector,
id);
57 if(adc!=0 && adc>3*rms) fill(
id,adc);
65 saveHist((
char*)mFileName.Data());
69 void StEmcEqualMaker::equalize(
int mode,
int DeltaEta,
bool Et)
80 TF1 *f=
new TF1(
"slopes",
"22*TMath::Sin(x)");
82 for(
int eta0 = -Neta; eta0<Neta; eta0+=DeltaEta)
89 if(eta0<0) { m1 = 61; m2 = 120; }
90 if(DeltaEta == 2*Neta){ m1=1; m2=120;}
91 for(
int j = 0;j<DeltaEta;j++)
95 cout <<
"etabin = "<<etabin<<
" eta = "<<eta<<endl;
98 for(
int m = m1;m<=m2;m++)
100 for(
int sub = 1;sub<=Nsub;sub++)
103 g->getId(m,eta,sub,
id);
104 TH1D * h = getSpec(
id);
108 getMeanAndRms(h,MIN,MAX,&m1,&r1);
123 for(
int m = m1;m<=m2;m++)
for(
int j = 0;j<DeltaEta;j++)
for(
int sub = 1;sub<=Nsub;sub++)
129 g->getId(m,eta,sub,
id);
130 if(avg[
id-1]>0 && fabs(avg[
id-1]-AVG)<DCA) { DCA = fabs(avg[
id-1]-AVG); ID = id;}
134 cout <<
"Reference found id = "<<ID<<
" avg = "<<avg[ID-1]<<endl;
135 cout <<
"Equalizing eta bin ..."<<endl;
136 for(
int m = m1;m<=m2;m++)
for(
int j = 0;j<DeltaEta;j++)
for(
int sub = 1;sub<=Nsub;sub++)
142 g->getId(m,eta,sub,
id);
143 if(mode!=5) equalizeRelative(ID,
id,mode,Et);
144 else equalizeToFunction(
id,f);
154 void StEmcEqualMaker::equalizeRelative(
int ref,
int channel,
int mode,
bool Et)
163 TH1D *h1 = getSpec(ref,
"ref");
164 TH1D *h2 = getSpec(channel,
"channel");
166 float integral1 = h1->Integral();
167 float integral2 = h2->Integral();
169 mA->SetBinContent(channel,0);
170 mB->SetBinContent(channel,0);
171 mStatus->SetBinContent(channel,0);
172 mRefSlopes->SetBinContent(channel,0);
173 mRefAmps->SetBinContent(channel,0);
174 mSlopes->SetBinContent(channel,0);
175 mAmps->SetBinContent(channel,0);
184 if((integral1==0 || integral2==0) && h1!=h2)
190 if((integral1==0 || integral2==0) && h1==h2)
206 if(mode>=0 && mode <=3)
209 if(mode==0 || mode==1)
211 getMeanAndRms(h1,MIN,MAX,&m1,&r1);
212 getMeanAndRms(h2,MIN,MAX,&m2,&r2);
214 if(mode==2 || mode==3)
216 getLogMeanAndRms(h1,MIN,MAX,&m1,&r1);
217 getLogMeanAndRms(h2,MIN,MAX,&m2,&r2);
219 if(mode==0 || mode==2)
224 if(mode==1 || mode==3)
230 cout <<
" id = "<<channel<<
" ref = "<<ref<<
" mean = "<<m1<<
" , "<<m2
231 <<
" rms = "<<r1<<
" , "<<r2
232 <<
" a = "<<a<<
" b = "<<b<<endl;
235 float m1=0,m2=0,A1=0,A2=0;
238 TF1 *f=
new TF1(
"ff",
"[0]*exp(-x/[1])",MIN,MAX);
239 float I1 = h1->Integral(h1->FindBin(MIN),h1->FindBin(MAX));
240 f->SetParameter(1,10);
242 m1 = f->GetParameter(1);
243 A1 = f->GetParameter(0);
244 mRefSlopes->SetBinContent(channel,m1);
245 mRefAmps->SetBinContent(channel,A1);
247 float I2 = h2->Integral(h2->FindBin(MIN),h2->FindBin(MAX));
249 m2 = f->GetParameter(1);
250 A2 = f->GetParameter(0);
251 mSlopes->SetBinContent(channel,m2);
252 mAmps->SetBinContent(channel,A2);
255 b=-::log((A2*I1)/(A1*I2));
257 if(!finite(a) || !finite(b) || a<=0 || b>1000) {EqDone =
false; a = 0;}
259 cout <<
" id = "<<channel<<
" ref = "<<ref<<
" slopes = "<<m2<<
" , "<<m1
260 <<
" a = "<<a<<
" b = "<<b<<
" EQDONE = "<<(Int_t)EqDone<<endl;
266 mA->SetBinContent(channel,a);
267 mB->SetBinContent(channel,b);
270 mStatus->SetBinContent(channel,1);
274 getGeom()->
getBin(channel,mod,eta,sub);
275 getGeom()->getTheta(mod,eta,theta);
276 mSlopesTheta->Fill(theta,m2);
279 else mStatus->SetBinContent(channel,2);
286 void StEmcEqualMaker::equalizeToFunction(
int channel,TF1 *func)
288 TH1D *h2 = getSpec(channel,
"channel");
290 float integral2 = h2->Integral();
292 mA->SetBinContent(channel,0);
293 mB->SetBinContent(channel,0);
294 mStatus->SetBinContent(channel,0);
295 mRefSlopes->SetBinContent(channel,0);
296 mRefAmps->SetBinContent(channel,0);
297 mSlopes->SetBinContent(channel,0);
298 mAmps->SetBinContent(channel,0);
306 mA->SetBinContent(channel,0);
307 mB->SetBinContent(channel,0);
316 getGeom()->
getBin(channel,mod,eta,sub);
317 getGeom()->getTheta(mod,eta,theta);
319 float m1=0,m2=0,A1=0,A2=0;
320 TF1 *f=
new TF1(
"ff",
"[0]*exp(-x/[1])",MIN,MAX);
321 f->SetParameter(1,10);
323 m1 = func->Eval(theta);
324 mRefSlopes->SetBinContent(channel,m1);
325 mRefAmps->SetBinContent(channel,A1);
331 m2 = f->GetParameter(1);
332 A2 = f->GetParameter(0);
333 mSlopes->SetBinContent(channel,m2);
334 mAmps->SetBinContent(channel,A2);
341 if(!finite(a) || !finite(b) || a<=0.01 || b>1000 || a > 10) { EqDone =
false; a = 0;}
343 cout <<
" id = "<<channel<<
" slopes = "<<m2<<
" , "<<m1
344 <<
" a = "<<a<<
" b = "<<b<<
" EQDONE = "<<(Int_t)EqDone<<endl;
349 mA->SetBinContent(channel,a);
350 mB->SetBinContent(channel,b);
353 mStatus->SetBinContent(channel,1);
355 mSlopesTheta->Fill(theta,m2);
358 else mStatus->SetBinContent(channel,2);
364 void StEmcEqualMaker::calcSlopes()
371 mSlopesTheta->Reset();
372 TF1 *f=
new TF1(
"ff",
"[0]*exp(-x/[1])",MIN,MAX);
375 for(
int channel = 1;channel<=getNChannel();channel++)
377 TH1D *h2 = getSpec(channel,
"channel");
378 float I2 = h2->Integral(h2->FindBin(MIN),h2->FindBin(MAX));
383 g->
getBin(channel,mod,eta,sub);
384 g->getTheta(mod,eta,theta);
388 f->SetParameter(1,10);
390 m2 = f->GetParameter(1);
391 A2 = f->GetParameter(0);
392 mSlopes->SetBinContent(channel,m2);
393 mAmps->SetBinContent(channel,A2);
395 mSlopesTheta->Fill(theta,m2);
396 cout <<
"Slope for channel "<<channel<<
" is "<<m2<<endl;
405 void StEmcEqualMaker::saveEqual(
int date,
int time)
408 TString n[] = {
"bemcEqual",
"bprsEqual",
"bsmdeEqual",
"bsmdpEqual"};
409 sprintf(ts,
"%s.%08d.%06d.root",n[getDetector()-1].Data(),date,time);
410 TFile *f =
new TFile(ts,
"RECREATE");
411 if(getSpec()) getSpec()->Write();
414 if(mADistr) mADistr->Write();
415 if(mBDistr) mBDistr->Write();
416 if(mStatus) mStatus->Write();
417 if(mRefSlopes) mRefSlopes->Write();
418 if(mRefAmps) mRefAmps->Write();
419 if(mSlopes) mSlopes->Write();
420 if(mAmps) mAmps->Write();
421 if(mSlopesTheta) mSlopesTheta->Write();
427 void StEmcEqualMaker::loadEqual(
char* file)
429 TFile *f =
new TFile(file);
439 mSlopesTheta->Reset();
442 if(f->Get(
"mSpec;1")) getSpec()->Add((TH2F*)f->Get(
"mSpec;1"),1);
443 if(f->Get(
"mA;1")) mA->Add((TH1F*)f->Get(
"mA;1"),1);
444 if(f->Get(
"mB;1")) mB->Add((TH1F*)f->Get(
"mB;1"),1);
445 if(f->Get(
"mADistr;1")) mADistr->Add((TH1F*)f->Get(
"mADistr;1"),1);
446 if(f->Get(
"mBDistr;1")) mBDistr->Add((TH1F*)f->Get(
"mBDistr;1"),1);
447 if(f->Get(
"mStatus;1")) mStatus->Add((TH1F*)f->Get(
"mStatus;1"),1);
448 if(f->Get(
"mRefSlopes;1")) mRefSlopes->Add((TH1F*)f->Get(
"mRefSlopes;1"),1);
449 if(f->Get(
"mRefAmps;1")) mRefAmps->Add((TH1F*)f->Get(
"mRefAmps;1"),1);
450 if(f->Get(
"mSlopes;1")) mSlopes->Add((TH1F*)f->Get(
"mSlopes;1"),1);
451 if(f->Get(
"mAmps;1")) mAmps->Add((TH1F*)f->Get(
"mAmps;1"),1);
452 if(f->Get(
"mSlopesTheta;1")) mSlopesTheta->Add((TH2F*)f->Get(
"mSlopesTheta;1"),1);
458 TH1F* StEmcEqualMaker::getEtaBinSpec(
int eta0,
int eta1,TH2F* SPEC)
461 if(!SPEC) spec = getSpec();
else spec = SPEC;
462 if(!spec)
return NULL;
475 int ns = getGeom()->NSub();
478 TH1F *hist = (TH1F*)spec->ProjectionY(
"etabin",1,1);
481 for(
int m=mi;m<=mf;m++)
483 for(
int e=e0;e<=e1;e++)
485 for(
int s=1;s<=ns;s++)
488 getGeom()->getId(m,e,s,
id);
490 sprintf(name,
"Tower %d",
id);
491 TH1F* tmp = rebin(
id,name,spec);
495 delete tmp; tmp = NULL;
503 TH1F* StEmcEqualMaker::rebin(
int id,
const char *name, TH2F* SPEC)
506 if(!SPEC) spec = getSpec();
else spec = SPEC;
507 if(!spec)
return NULL;
510 float a = mA->GetBinContent(
id);
511 float b = mB->GetBinContent(
id);
514 if(a<=0)
return NULL;
516 TH1F *h = (TH1F*)spec->ProjectionY(name,
id,
id);
517 if(a==1 && b==0)
return h;
519 float deltaBin=h->GetBinWidth(1)/seg;
520 int nbins=h->GetNbinsX();
523 for(
int i=0;i<4096;i++) Y[i] = 0;
524 for(
int i=1;i<=nbins;i++) Y[i] = h->GetBinContent(i);
528 for(
int i=1;i<=nbins;i++)
530 float x = h->GetBinLowEdge(i);
532 for(
int j=0;j<(int)seg;j++)
534 float x1 = x+((float)j+0.5)*deltaBin;
546 void StEmcEqualMaker::drawEtaBin(
int eta0,
int eta1,TH2F* SPEC)
549 if(!SPEC) spec = getSpec();
else spec = SPEC;
563 int ns = getGeom()->NSub();
569 for(
int m=mi;m<=mf;m++)
571 for(
int e=e0;e<=e1;e++)
573 for(
int s=1;s<=ns;s++)
576 getGeom()->getId(m,e,s,
id);
578 sprintf(name,
"Tower %d",
id);
579 TH1F* tmp = rebin(
id,name,spec);
582 if(first) { tmp->Draw(); first =
false;}
else tmp->Draw(
"same");
virtual void Clear(Option_t *option="")
User defined functions.
Int_t getBin(const Float_t phi, const Float_t eta, Int_t &m, Int_t &e, Int_t &s) const