23 #include "TPostScript.h"
30 void drawTower(TH1D*, Int_t, Int_t, Float_t, Float_t);
31 Bool_t isBadTower(Int_t);
33 void mip_histogram_fitter(
const Char_t* mipRootfile =
"combinedMips.root",
const Char_t* psName =
"mip.ps",
const Char_t* rootFilename =
"towerMipFits.root",
const Char_t* mipOutputName =
"mip.gains")
36 gROOT->Macro(
"loadMuDst.C");
37 StEmcGeom *mEmcGeom = StEmcGeom::instance(
"bemc");
39 const Int_t nTowers = 4800;
40 Int_t towerStatus[nTowers];
41 Double_t fitMean[nTowers], fitMeanError[nTowers];
43 cout <<
"Input Filename: " << mipRootfile << endl;
44 cout <<
"Plot Filename: " << psName << endl;
45 cout <<
"Gain Filename: " << mipOutputName << endl;
47 gStyle->SetCanvasColor(10);
48 gStyle->SetCanvasBorderMode(0);
49 gStyle->SetStatColor(10);
50 gStyle->SetOptTitle(0);
51 gStyle->SetOptDate(0);
52 gStyle->SetOptFit(111);
53 gStyle->SetOptStat(
"e");
54 gStyle->SetPalette(1);
58 TH1D *towerHisto[nTowers];
59 TH2F *etaPhiMean, *etaPhiStatus, *etaPhiRatio;
61 TFile* outfile =
new TFile(rootFilename,
"RECREATE");
62 Float_t pi = TMath::Pi();
65 etaPhiMean =
new TH2F(
"etaPhiMean",
"Fit Means", 40, -1., 1., 120, -pi, pi);
66 etaPhiStatus =
new TH2F(
"etaPhiStatus",
"Status Codes", 40, -1., 1., 120, -pi, pi);
67 etaPhiRatio =
new TH2F(
"etaPhiMeanRatio",
"Mean Ratios", 40, -1., 1., 120, -pi, pi);
68 for (Int_t i = 0; i < nTowers; ++i)
69 towerHisto[i] =
new TH1D(Form(
"towerHisto_%i",i),Form(
"Tower %i",i),250,-50.5,199.5);
71 TFile *rootfile =
new TFile(mipRootfile);
72 for(Int_t y = 0; y < nTowers; ++y)
73 towerHisto[y]->Add((TH1D*)rootfile->Get(Form(
"tower_histo_%i",y+1)));
76 if(rootfile)
delete rootfile;
79 TF1 *towerFit[nTowers];
82 for(Int_t iTow = 0; iTow < nTowers; ++iTow){
83 Int_t softId = iTow+1;
84 Float_t mTowerEta = 0., mTowerPhi = 0.;
85 mEmcGeom->getEta(softId,mTowerEta);
86 mEmcGeom->getPhi(softId,mTowerPhi);
88 towerStatus[iTow] = 0;
90 fitMeanError[iTow] = 0.;
91 towerHisto[iTow]->GetXaxis()->SetRangeUser(6.,100.);
93 if(softId%200 == 0) cout <<
"Now fitting softId: " << softId << endl;
95 sprintf(fitName,
"towerFit_%i",softId);
96 Double_t fitLow = towerHisto[iTow]->GetMean() - towerHisto[iTow]->GetRMS();
97 Double_t fitHigh = towerHisto[iTow]->GetMean() + towerHisto[iTow]->GetRMS()/2.;
98 towerFit[iTow] =
new TF1(fitName,
"[0]*Gaus(x,[1],[2])*Landau(x,[3],[4])",fitLow,fitHigh);
101 towerFit[iTow]->SetParameter(0,towerHisto[iTow]->GetBinContent(towerHisto[iTow]->GetMaximumBin()));
102 towerFit[iTow]->SetParameter(1,towerHisto[iTow]->GetMean());
103 towerFit[iTow]->SetParameter(2,towerHisto[iTow]->GetRMS());
104 towerFit[iTow]->SetParameter(3,towerHisto[iTow]->GetBinCenter(towerHisto[iTow]->GetMaximumBin()));
105 towerFit[iTow]->SetParameter(4,towerHisto[iTow]->GetRMS());
106 towerFit[iTow]->SetLineColor(kBlue);
107 towerFit[iTow]->SetLineWidth(1.5);
110 if(towerHisto[iTow]->Integral(56,156) < 25){
111 towerStatus[iTow] = 13;
112 etaPhiStatus->Fill(mTowerEta,mTowerPhi,towerStatus[iTow]);
116 towerHisto[iTow]->Fit(towerFit[iTow],
"RQ");
117 towerStatus[iTow]+=1;
118 fitMean[iTow] = towerFit[iTow]->Mean(0.,100.);
121 Double_t fitParams[5] = {0.,0.,0.,0.,0.};
122 fitParams[0] = towerFit[iTow]->GetParameter(0);
123 fitParams[1] = towerFit[iTow]->GetParameter(1);
124 fitParams[2] = towerFit[iTow]->GetParameter(2);
125 fitParams[3] = towerFit[iTow]->GetParameter(3);
126 fitParams[4] = towerFit[iTow]->GetParameter(4);
129 Double_t fitVariance = towerFit[iTow]->Variance(0., 100., fitParams);
130 Double_t fitSigma = sqrt(fitVariance);
131 Double_t entriesInFit = towerHisto[iTow]->Integral(51,151);
134 if(fitMean[iTow] < 6) towerStatus[iTow] += 10;
136 if (abs(fitMean[iTow]-towerHisto[iTow]->GetMean()) > 15)
137 towerStatus[iTow]+=8;
140 if(abs(fitMean[iTow]-towerHisto[iTow]->GetMean()) > 10)
141 towerStatus[iTow]+=8;
145 if(isBadTower(softId))
146 towerStatus[iTow] = 7;
149 if (towerStatus[iTow] == 1)
150 fitMeanError[iTow] = fitSigma/sqrt(entriesInFit);
153 if (towerStatus[iTow] == 1){
154 etaPhiMean->Fill(mTowerEta,mTowerPhi,fitMean[iTow]);
155 etaPhiRatio->Fill(mTowerEta,mTowerPhi,fitMean[iTow]/towerHisto[iTow]->GetMean());
157 etaPhiStatus->Fill(mTowerEta,mTowerPhi,towerStatus[iTow]);
162 TPostScript *ps =
new TPostScript(psName);
163 TCanvas *canvas =
new TCanvas(
"can",
"can1",100,100,600.,800.);
166 cout << endl <<
"Begin Tower Drawing Loop" << endl;
167 for (Int_t iTow = 0; iTow < nTowers; ++iTow){
168 Int_t softId = iTow + 1;
169 Float_t mTowerEta = 0., mTowerPhi = 0.;
170 mEmcGeom->getEta(softId,mTowerEta);
171 mEmcGeom->getPhi(softId,mTowerPhi);
173 if (softId%400 == 0) cout <<
"Drawing tower " << softId << endl;
183 if(towerStatus[iTow] > 1)
184 towerHisto[iTow]->SetLineColor(kRed);
187 drawTower(towerHisto[iTow],softId,towerStatus[iTow],mTowerEta,mTowerPhi);
189 Double_t lineMax = towerHisto[iTow]->GetBinContent(towerHisto[iTow]->GetMaximumBin()) + 30;
190 if(towerStatus[iTow] == 1){
191 TLine *avgValueLine =
new TLine(fitMean[iTow],0.,fitMean[iTow],lineMax);
192 avgValueLine->SetLineColor(kBlue);
193 avgValueLine->SetLineWidth(1.25);
194 avgValueLine->Draw(
"same");
204 etaPhiMean->GetXaxis()->SetTitle(
"#eta");
205 etaPhiMean->GetXaxis()->CenterTitle();
206 etaPhiMean->GetYaxis()->SetTitle(
"#phi");
207 etaPhiMean->GetYaxis()->CenterTitle();
208 etaPhiMean->Draw(
"colz");
210 etaPhiStatus->GetZaxis()->SetRangeUser(0,20);
211 etaPhiStatus->GetXaxis()->SetTitle(
"#eta");
212 etaPhiStatus->GetXaxis()->CenterTitle();
213 etaPhiStatus->GetYaxis()->SetTitle(
"#phi");
214 etaPhiStatus->GetYaxis()->CenterTitle();
215 etaPhiStatus->Draw(
"colz");
222 etaPhiRatio->GetXaxis()->SetTitle(
"#eta");
223 etaPhiRatio->GetXaxis()->CenterTitle();
224 etaPhiRatio->GetYaxis()->SetTitle(
"#phi");
225 etaPhiRatio->GetYaxis()->CenterTitle();
226 etaPhiRatio->Draw(
"colz");
228 TH2F *ratioClone = (TH2F*)etaPhiRatio->Clone();
229 ratioClone->GetZaxis()->SetRangeUser(0.7,1.);
230 ratioClone->GetXaxis()->SetTitle(
"#eta");
231 ratioClone->GetXaxis()->CenterTitle();
232 ratioClone->GetYaxis()->SetTitle(
"#phi");
233 ratioClone->GetYaxis()->CenterTitle();
234 ratioClone->Draw(
"colz");
238 cout <<
"Tower Drawing Loop Complete" << endl;
242 ofstream mipOutput(mipOutputName);
247 for(Int_t iTow = 0; iTow < nTowers; ++iTow){
248 Int_t softId = iTow + +1;
249 Double_t mipAdc = fitMean[iTow];
250 Double_t mipError = fitMeanError[iTow];
251 mipOutput << softId <<
" " << mipAdc <<
" " << mipError <<
" " << towerStatus[iTow] << endl;
253 if(towerStatus[iTow]==1)nGood++;
254 if(towerStatus[iTow]==0)nZero++;
262 cout <<
"Finished tower fits" << endl << endl;
263 cout <<
"Number of Good Statuses = " << nGood << endl;
264 cout <<
"Number of Bad Statuses = " << 4800-nGood << endl;
265 cout <<
"Number of Empty Towers = " << nZero << endl;
268 if (mEmcGeom)
delete mEmcGeom;
271 void drawTower(TH1D* histo, Int_t
id, Int_t status, Float_t towerEta, Float_t towerPhi)
274 histo->GetXaxis()->SetTitle(
"ADC");
275 histo->GetXaxis()->CenterTitle();
279 Char_t towerTitle[100];
280 Char_t etaTitle[100];
281 Char_t phiTitle[100];
282 sprintf(etaTitle,
"e:%1.2f",towerEta);
283 sprintf(phiTitle,
"p:%1.2f",towerPhi);
286 etaLatex.SetTextSize(0.1);
287 phiLatex.SetTextSize(0.1);
288 sprintf(towerTitle,
"%i",
id);
290 titleLatex.SetTextSize(0.15);
291 if(status!=1) titleLatex.SetTextColor(kRed);
292 phiLatex.DrawTextNDC(0.55,0.2,phiTitle);
293 etaLatex.DrawTextNDC(0.55,0.33,etaTitle);
294 titleLatex.DrawTextNDC(0.55,0.45,towerTitle);
296 Char_t towerCode[100];
297 sprintf(towerCode,
"%i",status);
299 statusLatex.SetTextSize(0.15);
300 statusLatex.SetTextColor(kRed);
301 statusLatex.DrawTextNDC(0.47,0.78,towerCode);
305 Bool_t isBadTower(Int_t
id)
308 if (
id == 34 ||
id == 106 ||
id == 266 ||
id == 267 ||
id == 282 ||
id == 286 ||
id == 287 ||
id == 410 ||
id == 504 ||
id == 533 ||
309 id == 561 ||
id == 615 ||
id == 616 ||
id == 633 ||
id == 637 ||
id == 638 ||
id == 650 ||
id == 653 ||
id == 657 ||
id == 673 ||
310 id == 789 ||
id == 806 ||
id == 809 ||
id == 812 ||
id == 813 ||
id == 814 ||
id == 821 ||
id == 822 ||
id == 823 ||
id == 824 ||
311 id == 829 ||
id == 830 ||
id == 831 ||
id == 832 ||
id == 837 ||
id == 841 ||
id == 842 ||
id == 843 ||
id == 844 ||
id == 849 ||
312 id == 850 ||
id == 851 ||
id == 852 ||
id == 857 ||
id == 875 ||
id == 899 ||
id == 939 ||
id == 953 ||
id == 954 ||
id == 993 ||
313 id == 1026 ||
id == 1046 ||
id == 1048 ||
id == 1080 ||
id == 1100 ||
id == 1199 ||
id == 1200 ||
id == 1207 ||
id == 1218 ||
id == 1219 ||
314 id == 1222 ||
id == 1223 ||
id == 1224 ||
id == 1198 ||
id == 1237 ||
id == 1241 ||
id == 1242 ||
id == 1243 ||
id == 1244 ||
id == 1257 ||
315 id == 1260 ||
id == 1312 ||
id == 1348 ||
id == 1353 ||
id == 1354 ||
id == 1388 ||
id == 1407 ||
id == 1409 ||
id == 1434 ||
id == 1448 ||
316 id == 1574 ||
id == 1597 ||
id == 1612 ||
id == 1654 ||
id == 1713 ||
id == 1765 ||
id == 1766 ||
id == 1877 ||
id == 1878 ||
id == 2073 ||
317 id == 2077 ||
id == 2092 ||
id == 2093 ||
id == 2097 ||
id == 2409 ||
id == 2589 ||
id == 2590 ||
id == 2969 ||
id == 3070 ||
id == 3071 ||
318 id == 3494 ||
id == 3495 ||
id == 3588 ||
id == 3668 ||
id == 3678 ||
id == 3679 ||
id == 4018 ||
id == 4019 ||
id == 4059 ||
id == 4331 ||
319 id == 4357 ||
id == 4500 ||
id == 4677 ||
id == 4678 ||
id == 4684)