11 TH1F *h1MaP=0,*h1MaT=0;
14 TH2F* h2DinRawP, *h2DinTrP, *h2DinMipP;
15 TH2F* h2DinRawT, *h2DinTrT, *h2DinMipT;
16 TH1F* janDb_mipMean[mxBTile], * janDb_mipSig[mxBTile], * janDb_mipStat[mxBTile];
20 calibBprsBox(
int box=11,
int pmt=5) {
21 gStyle->SetOptStat(1110);
23 gStyle->SetPalette(1,0);
26 char *fname=
"calib-nov-21-2008/sumD43-70V6.hist.root";
27 fd=
new TFile(fname); assert(fd->IsOpen());
28 printf(
"Work with %s\n", fd->GetName());
30 char *fnameO=
"barrelMipSpectV6.hist.root";
31 fout=
new TFile(fnameO,
"update"); assert(fout->IsOpen());
32 printf(
"Write output to %s\n", fout->GetName());
36 sprintf(txt,
"calib-nov-20-2008/mipGainBprs+Btow_v2.hist.root");
37 TFile* fd5=
new TFile(txt); assert(fd5->IsOpen());
39 char *core2[mxBTile]={
"btow",
"bprs"};
40 for(
int ibp=0;ibp<mxBTile;ibp++) {
41 TString tit=core2[ibp]; tit+=
"MipGain";
42 janDb_mipMean[ibp]=(TH1F *)fd5->Get(tit); assert( janDb_mipMean[ibp]);
43 tit=core2[ibp]; tit+=
"MipSig";
44 janDb_mipSig[ibp]=(TH1F *)fd5->Get(tit); assert( janDb_mipSig[ibp]);
45 tit=core2[ibp]; tit+=
"MipStat";
46 janDb_mipStat[ibp]=(TH1F *)fd5->Get(tit); assert( janDb_mipStat[ibp]);
50 h2DinRawP=(TH2F*)fd->Get(
"BPRS_c0"); assert(h2DinRawP);
51 h2DinTrP=(TH2F*)fd->Get(
"mipBprsTr"); assert(h2DinTrP);
52 h2DinMipP=(TH2F*)fd->Get(
"mipBprsTrBt"); assert(h2DinMipP);
54 h2DinRawT=(TH2F*)fd->Get(
"BTOW_c0"); assert(h2DinRawT);
55 h2DinTrT=(TH2F*)fd->Get(
"mipBtowTr"); assert(h2DinTrT);
56 h2DinMipT=(TH2F*)fd->Get(
"mipBtowTrPr"); assert(h2DinMipT);
58 buildSoftList(box,pmt);
61 sprintf(core,
"BPRS PMB=%d pmt=%d",box,pmt);
63 can=
new TCanvas(
"aa",
"aa",800,820);
64 TPad *c=makeTitle(can,core,page);
67 axY=h2DinRawP->GetYaxis();
68 float y1=axY->GetXmin();
69 float y2=axY->GetXmax();
70 int nbY=axY->GetNbins();
71 printf(
"Y-axis range --> [%.1f, %.1f], nb=%d\n",y1,y2,nbY);
73 char tt1[100], tt2[1000];
74 sprintf(tt1,
"rawBPM%d_%d",box,pmt);
75 h2DoutRaw=
new TH2F(tt1,
"aa2;;ADC-ped",16,0.5,16.5,nbY,y1,y2);
76 h2DoutRaw->GetXaxis()->SetTitleSize(0.05);
77 sprintf(tt1,
"mipBPM%d_%d",box,pmt);
78 h2DoutMip=
new TH2F(tt1,
"aa1;;ADC-ped",16,0.5,16.5,nbY,y1,y2);
79 h2DoutMip->GetXaxis()->SetTitleSize(0.05);
81 sprintf(tt1,
"gainBPM%d_%d",box,pmt);
82 sprintf(tt2,
"BPRS gain BPM-%d_%d, all tiles; average MIP (ADC)",box,pmt);
83 h1MaP=
new TH1F(tt1,tt2,40,0,40);
84 h1MaT=
new TH1F(
"aa4",
"BTOW tower: mean MIP; ADC-ped",25,0,50);
85 h2Cr=
new TH2F(
"aa5",
"BPRS comparison (both axis); slope (raw) ; average MIP (fit)",20,-0.15,-0.015,20,0,40);
87 TString xtit=core; xtit+=
"; softID:";
88 for(
int i=0;i<softL.size();i++) {
90 xtit+=softID; xtit+=
" , ";
91 processOne(softID,core,i+1);
96 ln00=
new TLine(0,0,17,0); ln00->SetLineStyle(2);
99 h2DoutRaw->Draw(
"colz"); gPad->SetLogz(); h2DoutRaw->SetAxisRange(-10,60,
"y");
100 tit=core; tit+=
", all values"+xtit;
101 h2DoutRaw->SetTitle(tit);
105 h2DoutMip->Draw(
"colz");
106 tit=core; tit+=
", reqire MIP @ TPC & BTOW"+xtit;
107 h2DoutMip->SetTitle(tit);
108 h2DoutMip->Rebin2D(1,3);
110 h2DoutMip->SetAxisRange(-10,60,
"y");
113 pad =
new TPad(
"pad1",
"apd1",0.0,0.0,1,.95);
126 sprintf(core,
"ps/bprsPmtPix%02d.ps",0);
127 if(doPS==2) sprintf(core,
"ps/bprsBPM%03d_%d.ps", box , pmt);
144 void processOne(
int softID,
char *core0,
int pix) {
145 TString ttx=core0; ttx+=pix;
146 can=
new TCanvas(ttx,ttx,800,700);
148 sprintf(core,
"%s, softID=%d",core0,softID);
150 c=makeTitle(can,core,pix);
154 TH1F * hrP= getSlice( h2DinRawP,softID,
"bprsR");
155 TH1F * htP= getSlice( h2DinTrP,softID,
"bprsT");
156 TH1F * hmP= getSlice( h2DinMipP,softID,
"bprsM");
158 TH1F * hrT= getSlice( h2DinRawT,softID,
"btowR");
159 TH1F * htT= getSlice( h2DinTrT,softID,
"btowT");
160 TH1F * hmT= getSlice( h2DinMipT,softID,
"btowM");
162 hrP->SetTitle(
"BPRS spectrum, all events");
163 hrP->Fit(
"expo",
"",
"R",13,50);
164 TF1 *ff=hrP->GetFunction(
"expo");
165 float slope=ff->GetParameter(1);
166 hrP->Fit(
"gaus",
"+",
"R",-10,10);
168 hmP->SetLineColor(kRed); hmP->SetFillColor(kRed);
169 hmP->SetTitle(
"BPRS spectrum, MIP : TPC, TPC+BTOW");
170 hmP->Fit(
"gaus",
"",
"R",-10,50);
172 TF1 *ff=hmP->GetFunction(
"gaus");
173 ff->SetLineColor(kBlue); ff->SetLineWidth(1);
174 float mean=ff->GetParameter(1);
175 float meanS=ff->GetParameter(2);
178 if(mean>cut_adcL && meanS>cut_sig) {
180 h2Cr->Fill(slope,mean);
183 hrT->SetTitle(
"BTOW spectrum, all events");
184 hrT->Fit(
"expo",
"",
"R",10,40);
185 hmT->SetLineColor(kGreen);hmT->SetFillColor(kGreen);
186 hmT->Fit(
"gaus",
"",
"R",-10,60);
187 TF1 *ffT=hmT->GetFunction(
"gaus");
188 ffT->SetLineColor(kBlue); ffT->SetLineWidth(1);
189 float meanT=ffT->GetParameter(1);
190 float meanST=ffT->GetParameter(2);
193 hmT->SetTitle(
"BTOW spectrum, MIP : TPC, TPC+BPRS");
197 hrP->Draw(); gPad->SetLogy(); hrP->SetMinimum(0.7);
198 hmP->Draw(
"same"); gPad->SetGrid();
199 float xC=mean-meanS,yC=1e7;
200 ln=
new TLine(xC,0,xC,yC); ln->SetLineColor(kMagenta); ln->Draw();
203 hmP->Draw(); hmP->SetMaximum(htP->GetMaximum()/3);
208 hrT->Draw(); gPad->SetLogy(); hrT->SetMinimum(0.7);
209 hmT->Draw(
"same");gPad->SetGrid();
212 hmT->Draw(); hmT->SetMaximum(htT->GetMaximum()/3);
215 ln=
new TLine(10,-3,25,-3); ln->SetLineColor(kMagenta); ln->Draw();ln->SetLineWidth(2);
216 int nb=hmP->GetXaxis()->GetNbins();
217 for(
int b=1;b<=nb;b++) {
218 h2DoutRaw->SetBinContent(pix,b,hrP->GetBinContent(b));
219 h2DoutMip->SetBinContent(pix,b,hmP->GetBinContent(b));
222 FILE *fcsv=fopen(
"bprs+btowMipGain.csv",
"a");
225 fprintf(fcsv,
"%d, %s, %d, , %d, %.2f, %.2f, , %d, %.2f, %.2f\n",
226 softID,core0+9,pix,(
int)hmP->GetEntries(),mean,meanS,
227 (int)hmT->GetEntries(),meanT,meanST );
230 for(
int ibp=0;ibp<mxBTile;ibp++) {
231 float adcL=5., adcH=40.;
233 int statGain=(int)janDb_mipStat[ibp]->GetBinContent(softID);
235 float mean=janDb_mipMean[ibp]->GetBinContent(softID);
236 float sig=janDb_mipSig[ibp]->GetBinContent(softID);
239 if(ibp==0 && adcL<5) adcL=5;
240 if(ibp==1 && adcL<3.5) adcL=3.5;
241 if(adcH>2*mean) adcH=2*mean;
242 printf(
"ibp=%d id=%4d MIP mean=%.1f sig=%.1f adcL=%.1f H=%.1f\n",ibp,softID,mean,sig,adcL,adcH);
245 TH1F *h1=hmT;
if (ibp==1) h1=hmP;
246 Lx=h1->GetListOfFunctions(); assert(Lx);
247 lnL=
new TLine( adcL,0, adcL,y); lnL->SetLineColor(kBlue);lnL->SetLineWidth(2);lnL->SetLineStyle(2);
249 lnH=
new TLine( adcH,0, adcH,y); lnH->SetLineColor(kBlue);lnH->SetLineWidth(2);lnH->SetLineStyle(2);
255 char tt1[100], tt2[1000];
256 sprintf(tt2,
"id=%d %s pix=%d, ",softID,core0,pix);
257 sprintf(tt1,
"bprs%d",softID);
259 TString Tt=tt1, T2=tt2;
260 hrP->SetName(Tt+
"a"); hrP->SetTitle(T2+
"inclusive"); hrP->Write();
261 htP->SetName(Tt+
"t"); htP->SetTitle(T2+
"MIP in TPC"); htP->Write();
262 hmP->SetName(Tt+
"m"); hmP->SetTitle(T2+
"MIP in TPC+BTOW");hmP->Write();
264 sprintf(tt2,
"id=%d BTOW , ",softID);
265 sprintf(tt1,
"btow%d",softID);
267 hrT->SetName(Tt+
"a"); hrT->SetTitle(T2+
"inclusive"); hrT->Write();
268 htT->SetName(Tt+
"t"); htT->SetTitle(T2+
"MIP in TPC"); htT->Write();
269 hmT->SetName(Tt+
"m"); hmT->SetTitle(T2+
"MIP in TPC+BPRS");hmT->Write();
271 sprintf(core,
"softID=%d",softID);
274 sprintf(core,
"ps/bprsPmtPix%02d.ps",pix);
275 if(doPS==2) sprintf(core,
"ps/softID%04d.ps",softID);
284 TH1F * getSlice(TH2F * h2,
int id,
char *ctit) {
286 float x1=axX->GetXmin();
287 float x2=axX->GetXmax();
288 int nbX=axX->GetNbins();
289 printf(
"X-axis range --> [%.1f, %.1f], nb=%d %s\n",x1,x2,nbX,axX->GetTitle());
292 float y1=axY->GetXmin();
293 float y2=axY->GetXmax();
294 int nbY=axY->GetNbins();
295 printf(
"Y-axis range --> [%.1f, %.1f], nb=%d\n",y1,y2,nbY);
297 assert(
id>=1 &&
id<=nbX);
299 char txt1[100], txt2[1000];
300 sprintf(txt1,
"%s_id%d",ctit,
id);
301 sprintf(txt2,
"%s soft id=%d;%s ",ctit,
id,axY->GetTitle());
302 TH1F*h=
new TH1F(txt1,txt2,nbY,y1,y2);
305 for(i=1;i<=nbY;i++) h->SetBinContent(i,h2->GetBinContent(
id,i));
307 h->SetAxisRange(x1,x2);
308 h->SetEntries(h->Integral());
315 void buildSoftList(
int box=11,
int pmt=1) {
316 fd1=
new TFile(
"calib-nov-8-2008/map-softID-bprsPmt-Rory.root"); assert(fd1->IsOpen());
317 printf(
"Opened: %s\n",fd1->GetName()); fd1->ls();
318 TH1I * mapBprsPmt=(TH1I*) fd1->Get(
"bprsPmt"); assert(mapBprsPmt);
322 for(
int b=1;b<=4800;b++) {
323 if(y!=(
int)mapBprsPmt->GetBinContent(b))
continue;
326 printf(
"found pmb=%d pmt=%d Bprs tiles =%d\n",box,pmt,softL.size());
330 TPad *makeTitle(TCanvas *c,
char *core,
int page) {
333 TPad *pad0 =
new TPad(
"pad0",
"apd0",0.0,0.95,1.,1.);
337 TPaveText *pt =
new TPaveText(0,0.,1,1,
"br");
350 pad =
new TPad(
"pad1",
"apd1",0.0,0.0,1,.95);