1 #include "StRHICfRecoPos.h"
3 StRHICfRecoPos::StRHICfRecoPos()
5 memset(mGSOBarSTable, 0,
sizeof(mGSOBarSTable));
6 memset(mGSOBarTTable, 0,
sizeof(mGSOBarTTable));
8 for(
int it=0; it<kRHICfNtower; it++){
9 for(
int il=0; il<kRHICfNlayer; il++){
10 for(
int ixy=0; ixy<kRHICfNxy; ixy++){
11 int gsobarSize = checkGSOBarSize(it);
13 mGSOBarHist[it][il][ixy] =
new TH1D(
"",
"", gsobarSize, 0, gsobarSize);
14 mGSOBarHistExpend[it][il][ixy] =
new TH1D(
"",
"", gsobarSize+4, -2, gsobarSize+2);
15 mGSOBarGraph[it][il][ixy] =
new TGraphErrors(gsobarSize);
17 mSingleFit[it][il][ixy] =
new TF1(
"SingleFit",
this, &StRHICfRecoPos::getLorenzianSingle, 0.,
double(gsobarSize), 6);
18 mMultiFit[it][il][ixy] =
new TF1(
"MultiFit",
this, &StRHICfRecoPos::getLorenzianMulti, 0.,
double(gsobarSize), 11);
19 mEachFit[it][il][ixy][0] =
new TF1(
"EachFit1",
this, &StRHICfRecoPos::getLorenzianSingle, 0.,
double(gsobarSize), 6);
20 mEachFit[it][il][ixy][1] =
new TF1(
"EachFit2",
this, &StRHICfRecoPos::getLorenzianSingle, 0.,
double(gsobarSize), 6);
22 mSpectrum[it][il][ixy] =
new TSpectrum();
28 StRHICfRecoPos::~StRHICfRecoPos()
30 for(
int it=0; it<kRHICfNtower; it++){
31 for(
int il=0; il<kRHICfNlayer; il++){
32 for(
int ixy=0; ixy<kRHICfNxy; ixy++){
33 delete mGSOBarHist[it][il][ixy];
34 delete mGSOBarHistExpend[it][il][ixy];
35 delete mGSOBarGraph[it][il][ixy];
36 delete mSingleFit[it][il][ixy];
37 delete mMultiFit[it][il][ixy];
38 delete mEachFit[it][il][ixy][0];
39 delete mEachFit[it][il][ixy][1];
41 mGSOBarHist[it][il][ixy] =
nullptr;
42 mGSOBarHistExpend[it][il][ixy] =
nullptr;
43 mGSOBarGraph[it][il][ixy] =
nullptr;
44 mSingleFit[it][il][ixy] =
nullptr;
45 mMultiFit[it][il][ixy] =
nullptr;
46 mEachFit[it][il][ixy][0] =
nullptr;
47 mEachFit[it][il][ixy][1] =
nullptr;
53 void StRHICfRecoPos::init()
55 memset(mWorthy,
false,
sizeof(mWorthy));
56 memset(mOverlap,
false,
sizeof(mOverlap));
57 memset(mGSOMaxLayer, 0,
sizeof(mGSOMaxLayer));
58 memset(mGSOBarSE, 0,
sizeof(mGSOBarSE));
59 memset(mGSOBarTE, 0,
sizeof(mGSOBarTE));
61 for(
int it=0; it<kRHICfNtower; it++){
62 for(
int il=0; il<kRHICfNlayer; il++){
63 for(
int ixy=0; ixy<kRHICfNxy; ixy++){
64 mGSOBarHist[it][il][ixy] -> Reset();
65 mGSOBarHistExpend[it][il][ixy] -> Reset();
66 mGSOBarGraph[it][il][ixy] -> Set(0);
68 for(
int p=0; p<11; p++){
69 mMultiFit[it][il][ixy] -> SetParameter(p, 0);
71 mSingleFit[it][il][ixy] -> SetParameter(p, 0);
72 mEachFit[it][il][ixy][0] -> SetParameter(p, 0);
73 mEachFit[it][il][ixy][1] -> SetParameter(p, 0);
81 void StRHICfRecoPos::setGSOBarEnergy(
int tower,
int layer,
int xy,
int bar, Double_t val)
83 if(tower==0){mGSOBarSE[layer][xy][bar] = val;}
84 if(tower==1){mGSOBarTE[layer][xy][bar] = val;}
87 void StRHICfRecoPos::setGSOBarTable(
int tower,
int layer,
int xy,
int bar, Double_t val)
89 if(tower==0){mGSOBarSTable[layer][xy][bar] = val;}
90 if(tower==1){mGSOBarTTable[layer][xy][bar] = val;}
93 bool StRHICfRecoPos::fillData()
96 int tmpWorthy[kRHICfNxy][kRHICfNtower];
97 memset(tmpWorthy, 0,
sizeof(tmpWorthy));
99 Double_t pedeRMSGeV = mPedADCRMS/(m1000Vto600VFactor*mSpecialFactor*mAvgConvFactor);
101 for(
int it=0; it<kRHICfNtower; it++){
102 for(
int il=0; il<kRHICfNlayer; il++){
103 for(
int ixy=0; ixy<kRHICfNxy; ixy++){
104 mGSOBarHistExpend[it][il][ixy] -> SetBinContent(1, 0.);
105 mGSOBarHistExpend[it][il][ixy] -> SetBinContent(2, 0.);
107 int gsobarSize = checkGSOBarSize(it);
108 for(
int ich=0; ich<gsobarSize; ich++){
109 Double_t gsobarE = 0;
110 Double_t gsobarTable = 0;
112 gsobarE = mGSOBarSE[il][ixy][ich];
113 gsobarTable = mGSOBarSTable[il][ixy][ich];
116 gsobarE = mGSOBarTE[il][ixy][ich];
117 gsobarTable = mGSOBarTTable[il][ixy][ich];
120 mGSOBarHist[it][il][ixy] -> SetBinContent(ich+1, gsobarE);
121 mGSOBarHistExpend[it][il][ixy] -> SetBinContent(ich+3, gsobarE);
122 mGSOBarGraph[it][il][ixy] -> SetPoint(ich, gsobarTable, gsobarE);
123 mGSOBarGraph[it][il][ixy] -> SetPointError(ich, 0., mGSOBarMapError * gsobarE + sqrt(pedeRMSGeV));
126 double edep = mGSOBarHist[it][il][ixy] -> GetBinContent(ich+1);
127 if(edep > mNoiseThreshold){tmpWorthy[ixy][it] += 1;}
129 mGSOBarHistExpend[it][il][ixy] -> SetBinContent(gsobarSize+3, 0.);
130 mGSOBarHistExpend[it][il][ixy] -> SetBinContent(gsobarSize+4, 0.);
135 for(
int it=0; it<kRHICfNtower; it++){
if(tmpWorthy[0][it]>0 && tmpWorthy[1][it]>0) mWorthy[it] =
true;}
138 mGSOBarGraph[0][3][0]->SetPoint(12, mGSOBarSTable[3][0][12], 0.);
139 mGSOBarGraph[0][3][0]->RemovePoint(12);
146 bool StRHICfRecoPos::calculate()
151 std::cout <<
"StRHICfRecoPos::calculate() -- Done " << std::endl;
155 bool StRHICfRecoPos::separateMultiFit(
int tower)
157 for(
int il=0; il<kRHICfNlayer; il++){
158 for(
int ixy=0; ixy<kRHICfNxy; ixy++){
159 Double_t parMulti[11];
160 mMultiFit[tower][il][ixy] -> GetParameters(parMulti);
161 mEachFit[tower][il][ixy][0] -> SetParameters(parMulti[0], parMulti[1], parMulti[2], parMulti[3], parMulti[4], parMulti[5]/2.);
162 mEachFit[tower][il][ixy][1] -> SetParameters(parMulti[6], parMulti[7], parMulti[8], parMulti[9], parMulti[10], parMulti[5]/2.);
168 int StRHICfRecoPos::getGSOMaxLayer(
int tower,
int order){
return mGSOMaxLayer[tower][order];}
170 int StRHICfRecoPos::getMaximumBin(
int tower,
int layer,
int xy)
176 for(
int ich=0; ich<checkGSOBarSize(tower); ich++){
177 if(tower==0){tmpE = mGSOBarSE[layer][xy][ich];}
178 if(tower==1){tmpE = mGSOBarTE[layer][xy][ich];}
187 int StRHICfRecoPos::getEvalHitNum(
int tower)
189 int nHit[kRHICfNlayer][kRHICfNxy];
190 for(
int il=0; il<kRHICfNlayer; il++){
191 for(
int ixy=0; ixy<kRHICfNxy; ixy++){
192 nHit[il][ixy] = getEvalHitNum(tower, il, ixy);
196 bool isNullData =
true;
197 for(
int il=0; il<4; ++il){
198 if(mGSOMaxLayer[tower][0]==il && nHit[il][0] > 0 && nHit[il][1] > 0){isNullData =
false;}
201 mOverlap[tower][0] =
false;
202 mOverlap[tower][1] =
false;
204 if(isNullData ==
true){
return 0;}
206 if(nHit[mGSOMaxLayer[tower][0]][0]==2 && nHit[mGSOMaxLayer[tower][0]][1]==2){
return 2;}
208 if(mMultiFit[tower][mGSOMaxLayer[tower][0]][0]->GetParameter(1) == mMultiFit[tower][mGSOMaxLayer[tower][0]][0]->GetParameter(7) && nHit[mGSOMaxLayer[tower][0]][1] == 2){
209 mOverlap[tower][0] =
true;
212 if(mMultiFit[tower][mGSOMaxLayer[tower][0]][1]->GetParameter(1) == mMultiFit[tower][mGSOMaxLayer[tower][0]][1]->GetParameter(7) && nHit[mGSOMaxLayer[tower][0]][0] == 2){
213 mOverlap[tower][1] =
true;
219 int StRHICfRecoPos::getEvalHitNum(
int tower,
int layer,
int xy)
221 int nHitSingleFit = 0;
222 int nHitMultiFit = 0;
225 if(getSinglePeakHeight(tower, layer, xy) > mNoiseThreshold){nHitSingleFit = 1;}
228 if(getMultiPeakHeight(tower, layer, xy, 0) > mNoiseThreshold){nHitMultiFit++;}
229 if(getMultiPeakHeight(tower, layer, xy, 1) > mNoiseThreshold){nHitMultiFit++;}
232 if(mSpectrum[tower][layer][xy]->GetNPeaks() < 2){
234 mMultiFit[tower][layer][xy] -> SetParameter(7, mMultiFit[tower][layer][xy]->GetParameter(1));
238 Double_t parMulti[11];
239 mMultiFit[tower][layer][xy] -> GetParameters(parMulti);
240 if(abs(parMulti[1] - parMulti[7]) < mPeakDistThreshold){
242 mMultiFit[tower][layer][xy] -> SetParameter(7, mMultiFit[tower][layer][xy]->GetParameter(1));
246 double heightRatio = getMultiPeakHeight(tower, layer, xy, 1)/getMultiPeakHeight(tower, layer, xy, 0);
247 if(heightRatio < mTSpecRatioThreshold){nHitMultiFit = 1;}
249 double chi2Ratio = getSingleChi2(tower, layer, xy)/getMultiChi2(tower, layer, xy);
251 if(nHitMultiFit > 1 && chi2Ratio > 1.0){
return 2;}
252 if(nHitSingleFit > 0){
return 1;}
256 double StRHICfRecoPos::getDepositEnergy(
int tower,
int layer)
258 double edepX = mGSOBarHist[tower][layer][0] -> Integral();
259 double edepY = mGSOBarHist[tower][layer][1] -> Integral();
263 double StRHICfRecoPos::getMultiEnergySum(
int tower,
int layer,
int xy,
int order){
return mEachFit[tower][layer][xy][order] -> Integral(0, checkGSOBarSize(tower));}
265 Double_t StRHICfRecoPos::getSinglePeakPos(
int tower,
int layer,
int xy){
return mSingleFit[tower][layer][xy] -> GetParameter(1);}
267 Double_t StRHICfRecoPos::getMultiPeakPos(
int tower,
int layer,
int xy,
int order)
269 if(order==0){
return mMultiFit[tower][layer][xy] -> GetParameter(1);}
270 else{
return mMultiFit[tower][layer][xy] -> GetParameter(7);}
273 double StRHICfRecoPos::getSinglePeakHeight(
int tower,
int layer,
int xy){
return mSingleFit[tower][layer][xy] ->Eval(getSinglePeakPos(tower, layer, xy));}
275 double StRHICfRecoPos::getMultiPeakHeight(
int tower,
int layer,
int xy,
int order)
278 Double_t multiPar[11];
279 memset(peak, 0,
sizeof(peak));
280 memset(multiPar, 0,
sizeof(multiPar));
282 mMultiFit[tower][layer][xy] -> GetParameters(multiPar);
284 peak[0] = multiPar[2]*(multiPar[4]/pow(multiPar[0], 0.5) + (1 - multiPar[4])/pow(multiPar[3], 0.5))/2. + multiPar[5];
285 peak[1] = multiPar[8]*(multiPar[10]/pow(multiPar[6], 0.5) + (1 - multiPar[10])/pow(multiPar[9], 0.5))/2. + multiPar[5];
287 if(order==0){
return std::max(peak[0], peak[1]);}
288 else{
return std::min(peak[0], peak[1]);}
291 double StRHICfRecoPos::getMultiPeakRaw(
int tower,
int layer,
int xy,
int order)
293 Int_t posBin = mGSOBarHist[tower][layer][xy] -> FindBin(getMultiPeakPos(tower, layer, xy, order));
294 double candidateBins[3] = {mGSOBarHist[tower][layer][xy]->GetBinContent(posBin-1), mGSOBarHist[tower][layer][xy]->GetBinContent(posBin), mGSOBarHist[tower][layer][xy]->GetBinContent(posBin+1)};
295 int maxIdx = TMath::LocMax(3, candidateBins);
296 return candidateBins[maxIdx];
299 double StRHICfRecoPos::getEvalPeakHeight(
int tower,
int layer,
int xy,
int order){
return mEachFit[tower][layer][xy][order] -> Eval(getMultiPeakPos(tower, layer, xy, order));}
301 double StRHICfRecoPos::getSingleChi2(
int tower,
int layer,
int xy)
303 double chi2 = mSingleFit[tower][layer][xy]->GetChisquare();
304 double dof = (double) mSingleFit[tower][layer][xy]->GetNDF();
308 double StRHICfRecoPos::getMultiChi2(
int tower,
int layer,
int xy)
310 double chi2 = mMultiFit[tower][layer][xy]->GetChisquare();
311 double dof = (double) mMultiFit[tower][layer][xy]->GetNDF();
315 bool StRHICfRecoPos::getWorthy(
int tower){
return mWorthy[tower];}
317 bool StRHICfRecoPos::getOverlap(
int tower,
int xy){
return mOverlap[tower][xy];}
319 void StRHICfRecoPos::findMaxLayer()
321 double maxSumBar[kRHICfNtower][kRHICfNlayer];
322 for(
int it=0; it<kRHICfNtower; it++){
323 for(
int il=0; il<kRHICfNlayer; il++){maxSumBar[it][il] = getDepositEnergy(it, il);}
324 mGSOMaxLayer[it][0] = TMath::LocMax(4, maxSumBar[it]);
325 maxSumBar[it][mGSOMaxLayer[it][0]] = 0.;
326 mGSOMaxLayer[it][1] = TMath::LocMax(4, maxSumBar[it]);
330 void StRHICfRecoPos::initSetParamaters()
332 Double_t parInMaxLayer[2][kRHICfNtower][kRHICfNxy][2];
333 Double_t parSingle[kRHICfNtower][kRHICfNlayer][kRHICfNxy][2];
335 memset(parInMaxLayer, 0,
sizeof(parInMaxLayer));
336 memset(parSingle, 0,
sizeof(parSingle));
338 for(
int it=0; it<kRHICfNtower; it++){
339 for(
int il=0; il<kRHICfNlayer; il++){
340 for(
int ixy=0; ixy<kRHICfNxy; ixy++){
341 Double_t posPrime = 0.;
342 Double_t valuePrime = 0.;
343 Double_t posSub = 0.;
344 Double_t valueSub = 0.;
347 mSpectrum[it][il][ixy]->Search(mGSOBarHistExpend[it][il][ixy], mTSpecSigma,
"nodraw goff", mTSpecRatioThreshold);
348 int numHit = mSpectrum[it][il][ixy]->GetNPeaks();
349 auto tSpecPeak = mSpectrum[it][il][ixy]->GetPositionX();
353 Int_t maxBin = mGSOBarHist[it][il][ixy]->GetMaximumBin();
354 Int_t subBin = checkGSOBarSize(it)/2;
356 posPrime = mGSOBarHist[it][il][ixy]->GetBinCenter(maxBin);
357 valuePrime = mGSOBarHist[it][il][ixy]->GetBinContent(maxBin);
358 posSub = Double_t(subBin);
359 valueSub = mGSOBarHist[it][il][ixy]->GetBinContent(subBin);
362 Int_t maxBin = mGSOBarHist[it][il][ixy]->GetXaxis()->FindBin(tSpecPeak[0]);
363 Int_t subBin = checkGSOBarSize(it)/2;
365 posPrime = tSpecPeak[0];
366 valuePrime = mGSOBarHist[it][il][ixy]->GetBinContent(maxBin);
367 posSub = Double_t(subBin);
368 valueSub = mGSOBarHist[it][il][ixy]->GetBinContent(subBin);
371 double bufferPeakValue = 0;
375 for(
int in=0; in<numHit; in++){
376 Int_t bin = mGSOBarHist[it][il][ixy]->GetXaxis()->FindBin(tSpecPeak[in]);
377 Double_t value = mGSOBarHist[it][il][ixy]->GetBinContent(bin);
379 if(value > bufferPeakValue){
380 bufferPeakValue = value;
381 posPrime = tSpecPeak[in];
389 for(
int in=0; in<numHit; in++){
390 if(in == primeIdx){
continue;}
392 Int_t bin = mGSOBarHist[it][il][ixy]->GetXaxis()->FindBin(tSpecPeak[in]);
393 Double_t value = mGSOBarHist[it][il][ixy]->GetBinContent(bin);
395 if(value > bufferPeakValue){
396 bufferPeakValue = value;
397 posSub = tSpecPeak[in];
403 if(valuePrime<0){valuePrime = -valuePrime;}
404 if(valueSub<0){valueSub = -valueSub;}
406 if(getGSOMaxLayer(it, 0) == il){
407 parInMaxLayer[0][it][ixy][0] = posPrime;
408 parInMaxLayer[0][it][ixy][1] = valuePrime;
409 parInMaxLayer[1][it][ixy][0] = posSub;
410 parInMaxLayer[1][it][ixy][1] = valueSub;
412 parSingle[it][il][ixy][0] = posPrime;
413 parSingle[it][il][ixy][1] = valuePrime;
419 for(
int it=0; it<kRHICfNtower; it++){
420 for(
int il=0; il<kRHICfNlayer; il++){
421 for(
int ixy=0; ixy<kRHICfNxy; ixy++){
422 Double_t initParSingle[6] = {mParWidth1, parSingle[it][il][ixy][0], parSingle[it][il][ixy][1], mParWidth2, mParRatio, mParBaseLine};
423 mSingleFit[it][il][ixy] -> SetParameters(initParSingle);
425 mSingleFit[it][il][ixy] -> SetParLimits(0, mParWidth1Min, mParWidth1Max);
426 mSingleFit[it][il][ixy] -> SetParLimits(1, -1., 1. +
double(checkGSOBarSize(it)));
427 mSingleFit[it][il][ixy] -> SetParLimits(2, mParHeightMin, mParHeightMax);
428 mSingleFit[it][il][ixy] -> SetParLimits(3, mParWidth2Min, mParWidth2Max);
429 mSingleFit[it][il][ixy] -> SetParLimits(4, mParRatioMin, mParRatioMax);
431 Double_t initParMulti[11] = {mParWidth1, parInMaxLayer[0][it][ixy][0], parInMaxLayer[0][it][ixy][1], mParWidth2, mParRatio, mParBaseLine, mParWidth1, parInMaxLayer[1][it][ixy][0], parInMaxLayer[1][it][ixy][1], mParWidth2, mParRatio};
432 mMultiFit[it][il][ixy] -> SetParameters(initParMulti);
434 mMultiFit[it][il][ixy] -> SetParLimits(0, mParWidth1Min, mParWidth1Max);
435 mMultiFit[it][il][ixy] -> SetParLimits(1, parInMaxLayer[0][it][ixy][0]-2, parInMaxLayer[0][it][ixy][0]+2);
436 mMultiFit[it][il][ixy] -> SetParLimits(2, mParHeightMin, mParHeightMax);
437 mMultiFit[it][il][ixy] -> SetParLimits(3, mParWidth2Min, mParWidth2Max);
438 mMultiFit[it][il][ixy] -> SetParLimits(4, mParRatioMin, mParRatioMax);
439 mMultiFit[it][il][ixy] -> SetParLimits(6, mParWidth1Min, mParWidth1Max);
440 mMultiFit[it][il][ixy] -> SetParLimits(7, parInMaxLayer[1][it][ixy][0]-2, parInMaxLayer[1][it][ixy][0]+2);
441 mMultiFit[it][il][ixy] -> SetParLimits(8, mParHeightMin, mParHeightMax);
442 mMultiFit[it][il][ixy] -> SetParLimits(9, mParWidth2Min, mParWidth2Max);
443 mMultiFit[it][il][ixy] -> SetParLimits(10, mParRatioMin, mParRatioMax);
449 void StRHICfRecoPos::fitting()
451 for(
int it=0; it<kRHICfNtower; it++){
452 for(
int il=0; il<kRHICfNlayer; il++){
453 for(
int ixy=0; ixy<kRHICfNxy; ixy++){
454 mGSOBarGraph[it][il][ixy] -> Fit(mSingleFit[it][il][ixy],
"QR");
455 mGSOBarGraph[it][il][ixy] -> Fit(mMultiFit[it][il][ixy],
"QR");
461 Double_t StRHICfRecoPos::getLorenzianSingle(Double_t* x, Double_t* par)
463 Double_t val = par[4]*par[0]/pow(((x[0]-par[1])*(x[0]-par[1])+par[0]), 1.5)/2.;
464 Double_t val2 = (1-par[4])*(par[3]/2.)/pow(((x[0]-par[1])*(x[0]-par[1])+par[3]), 1.5);
466 return par[2]*(val+val2) + par[5];
469 Double_t StRHICfRecoPos::getLorenzianMulti(Double_t* x, Double_t* par)
471 Double_t p1val = par[4]*par[0]/pow(((x[0]-par[1])*(x[0]-par[1])+par[0]), 1.5)/2.;
472 Double_t p1val2 = (1.-par[4])*par[3]/pow(((x[0]-par[1])*(x[0]-par[1])+par[3]), 1.5)/2.;
473 Double_t peak1 = par[2]*(p1val+p1val2);
475 Double_t p2val = par[10]*par[6]/pow(((x[0]-par[7])*(x[0]-par[7])+par[6]), 1.5)/2.;
476 Double_t p2val2 = (1.-par[10])*par[9]/pow(((x[0]-par[7])*(x[0]-par[7])+par[9]), 1.5)/2.;
477 Double_t peak2 = par[8]*(p2val+p2val2);
479 return peak1 + peak2 + par[5];