3 static const int NS=21;
4 static const int NID=NQ*NL*NS;
6 static const int NCUT1=6;
7 static const int NCUT2=6;
9 TH2F* mH2[NQ][NL][NCUT1];
10 TH1F* mHd[NQ][NL][NCUT1];
11 TH2F* mHd2[NQ][NL][NCUT1];
17 static TString* FILENAME;
21 const int col1[NCUT1]={1,2,4,6,8,9};
22 const char* CCUT1[NCUT1]={
"All",
"E>6GeV",
"gamma",
"hadron",
"electron",
"others"};
25 const int col2[NCUT2]={1,2,4,6,8,9};
26 const char* CCUT2[NCUT2]={
"All/50",
"E1,E2>6GeV,E>20GeV",
"gg",
"hh",
"ee",
"others"};
28 static const float zfms=730.0;
36 static float FIT[NID];
37 static float SIG[NID];
38 static float GEOM[NID];
40 int getSlatid(
int q,
int l,
int s){
41 return (q-1)*NL*NS + (l-1)*NS + s-1;
44 int getQLS(
int slatid,
int *q,
int *l,
int *s){
46 l = (slatid/NQ)%NL + 1;
47 q = (slatid/NQ/NL)%NQ + 1;
50 float project(
float x,
float z,
float zp,
float vz){
52 return x/(z-vz)*(zp-vz);
55 void readFpsPosition(
char* input=
"fpsgeom.txt"){
56 FILE *FP = fopen(input,
"r");
57 if(!FP) { printf(
"Could not open %s\n",input); exit;}
58 printf(
"Reading %s\n",input);
61 float ix,iy,iz,idx,idy,idz;
62 while(fgets(line,1000,FP)!=NULL){
63 sscanf(line,
"%d %d %d %d %f %f %f %f %f %f",
64 &slatid,&q,&l,&s,&idx,&idy,&idz,&ix,&iy,&iz);
75 printf(
"Id=%3d Q=%3d L=%3d S=%3d x=%9.4f %9.4f %9.4f d=%9.4f %9.4f %9.4f\n",
77 xx[slatid],yy[slatid],zz[slatid],
78 dx[slatid],dy[slatid],dz[slatid]);
81 printf(
"Found %d entries\n",n);
84 void plotd(
int quad=0,
int layer=0,
int cut=0){
85 gStyle->SetOptStat(0);
88 if(quad>0 || layer>0) {pad = c1->cd(0);}
89 for(
int l=1; l<=NL; l++){
90 if(layer>0 && layer!=l)
continue;
91 if(layer==0){c1->Clear();}
92 if(quad==0) {c1->Divide(2,2);}
93 for(
int q=1; q<=NQ; q++){
94 if(quad>0 && quad!=q)
continue;
95 if(quad==0) {pad=c1->cd(q);}
97 mHd[q-1][l-1][cut]->Draw();
99 if(layer==0){c1->SaveAs(Form(
"plot2/fmsfpsd_L%1d.png",layer));}
101 if(quad>0 || layer>0) {c1->SaveAs(Form(
"plot2/fmsfpsd_Q%1dL%1d.png",quad,layer));}
104 void plot2d(
int quad=0,
int layer=0,
int slat=0,
int cut=0,
int val=0,
int scale=1,
int slice=1){
105 gStyle->SetOptStat(0);
108 if(quad>0 || layer>0) {pad = c1->cd(0);}
109 for(
int l=1; l<=NL; l++){
110 if(layer>0 && layer!=l)
continue;
111 if(layer==0){c1->Clear();}
112 if(slice==0 && quad==0) {c1->Divide(2,2);}
113 for(
int q=1; q<=NQ; q++){
114 if(quad>0 && quad!=q)
continue;
115 if(quad==0) {pad=c1->cd(q);}
118 if(val==0) h=mH2[q-1][l-1][cut];
119 if(val==1) h=mHd2[q-1][l-1][cut];
120 TH1D* projx=h->ProjectionX();
121 TH2F* h2=(TH2F*)h->Clone(Form(
"Q%1dL%1d_scaled",q,l)); h2->Reset();
122 int nx=h->GetNbinsX();
123 int ny=h->GetNbinsY();
124 for(
int x=0; x<=nx+1; x++){
125 float w=projx->GetBinContent(x);
126 for(
int y=0; y<=ny+1; y++){
127 int bin=h->GetBin(x,y);
128 float v=h->GetBinContent(bin);
131 h2->SetBinContent(bin,newv);
137 if(scale) {h2->Draw(
"colz");}
138 else {h->Draw(
"colz");}
141 if(slat==0) {c1->Divide(3,7);}
142 for(
int s=1; s<=NS; s++){
143 int slatid=getSlatid(q,l,s);
144 if(slat>0 && s!=slat)
continue;
145 if(s>19 && (q==2 || q==4))
continue;
147 sprintf(cc,
"Q%1dL%1dS%02d",q,l,s);
148 TH1D *hp = h2->ProjectionX(cc,s,s);
153 xxx=xx[slatid]; dxx=dx[slatid];
154 if(q<=2) xxx=xxx/1.02 - 0.5;
155 if(q>=3) xxx=xxx*1.015 + 1.5;
157 xxx=yy[slatid]; dxx=dy[slatid];
160 xxx=yy[slatid]; dxx=dy[slatid];
167 xxx=xx[slatid]; dxx=dx[slatid];
168 if(q<=2) xxx=xxx/factor;
170 if(q>=3) xxx=xxx/factor;
172 xxx=yy[slatid]; dxx=dy[slatid];
175 xxx=yy[slatid]; dxx=dy[slatid];
180 float xmin=xxx-3.0*dxx;
181 float xmax=xxx+3.0*dxx;
182 printf(
"xmin/xmax=%f %f\n",xmin,xmax);
183 int bmin=hp->FindBin(xmin);
184 int bmax=hp->FindBin(xmax);
185 printf(
"bmin/bmax=%f %f\n",bmin,bmax);
186 hp->GetXaxis()->SetRange(bmin,bmax);
187 float min=hp->GetMinimum(0.02);
188 float max=hp->GetMaximum();
190 float peak=hp->GetBinCenter(hp->GetMaximumBin());
191 float avg=hp->Integral(bmin,bmax)/(bmax-bmin+1);
192 float sig=dxx/2.0/2.0;
194 float ymin=min-delta*0.1;
195 float ymax=max+delta*0.3;
201 pad->SetRightMargin(mergin); pad->SetLeftMargin(mergin);
202 pad->SetTopMargin(mergin); pad->SetBottomMargin(0.01);
204 if(q==1 || quad>0 || slat>0) {hp->Draw();}
205 else {hp->Draw(
"same");}
207 for(
int i=-1; i<2; i++){
208 float proj=xxx+i*dxx*0.5;
209 if(i==0) GEOM[slatid]=proj;
211 TLine *ll =
new TLine(proj,ymin,proj,ymax);
212 ll->SetLineColor(kBlue); ll->SetLineWidth(2);
216 TF1 *f=
new TF1(
"ff",
"gaus(0)+[3]", xmin, xmax);
221 f->SetParameter(0,max-avg);
223 f->SetParameter(1,peak);
224 f->SetParameter(2,sig);
225 f->SetParameter(3,avg);
226 int res = hp->Fit(
"ff",
"0R");
227 FIT[slatid]=f->GetParameter(1);
228 SIG[slatid]=f->GetParameter(2);
230 f->SetLineColor(kRed);
233 c1->SaveAs(Form(
"plot2/fmsfps2_Q%1dL%1d_cut%d_slice.png",q,layer,cut));
236 if(slice==0) c1->SaveAs(Form(
"plot2/fmsfps2_Q%1dL%1d_cut%d.png",quad,layer,cut));
239 if(slice==1 && slat==0){
240 for(
int l=1; l<=NL; l++){
241 if(layer>0 && l!=layer)
continue;
243 if(quad==0) c2->Divide(2,2);
244 for(
int q=1; q<=NQ; q++){
245 if(quad>0 && q!=quad)
continue;
246 if(quad==0) c2->cd(q);
247 TGraphErrors *g=
new TGraphErrors(1);
249 sprintf(t,
"Q%1dL%1d Fit-DB vs slat",q,l);
252 int pm[NQ][NL]={{1,1,1},{1,-1,-1},{-1,1,1},{-1,-1,-1}};
253 if(pm[q-1][l-1]==1) {x1=-10.0; x2=110.0;}
254 else {x1=-110.0; x2=10.0;}
255 TH2F *frame=
new TH2F(t,t,1,x1,x2,1,-10.0,10.0);
258 for(
int s=1; s<=NS; s++){
259 int slatid=getSlatid(q,l,s);
260 double d=FIT[slatid]-GEOM[slatid];
261 if(fabs(d)<2.0 && SIG[slatid]>0.5 && SIG[slatid]<6.0){
262 g->SetPoint(np,GEOM[slatid],d);
263 g->SetPointError(np,0.0,SIG[slatid]);
267 g->SetMarkerStyle(20); g->SetMarkerColor(kRed);
270 TF1 *f2=
new TF1(
"f2",
"[0]+[1]*x", -100, 100);
271 f2->SetParameter(0,0.0);
272 f2->SetParameter(1,0.0);
273 int res = g->Fit(
"f2",
"0RQ");
274 f2->SetLineColor(kBlue);
277 c2->SaveAs(Form(
"plot2/fmsfps2_Q%1dL%1d_cut%d_align.png",quad,layer,cut));
282 void pltcut(
char* name, TCanvas* c,
int div,
int log=0,
int legend=0){
285 if(log==0) c->cd(div);
286 if(log==1) c->cd(div)->SetLogy();
288 for(
int cut=0; cut<NCUT1; cut++){
289 sprintf(cc,
"%s_c%d",name,cut);
290 TH1* h=(TH1*)mTFile->Get(cc);
291 if(cut==0 && hname.Contains(
"p_")) h->Scale(0.05);
292 h->SetLineColor(col1[cut]); h->SetMarkerColor(col1[cut]);
293 if(log==1) h->SetMinimum(0.1);
294 if(name==
"NP") h->SetMaximum(h->GetMaximum()*10.0);
296 if(cut>0) opt+=
"same";
301 for(
int cut=0; cut<NCUT1; cut++){
302 TText* t=
new TText(0.7,0.6-0.07*cut,CCUT1[cut]);
303 t->SetTextSize(0.07); t->SetNDC(); t->SetTextColor(col1[cut]);
309 void pltcut2(
char* name, TCanvas* c,
int div,
int log=0,
int legend=0){
312 if(log==0) c->cd(div);
313 if(log==1) c->cd(div)->SetLogy();
314 if(log==2) c->cd(div)->SetLogz();
316 for(
int cut=0; cut<NCUT2; cut++){
317 if(name==
"p_pid" && cut==0)
continue;
318 sprintf(cc,
"%s_c%d",name,cut);
319 TH1* h=(TH1*)mTFile->Get(cc);
320 if(cut==0) h->Scale(1/40.0);
321 if(cut==3 && name==
"p_m1") h->Scale(20.0);
322 if(cut==4 && name==
"p_m1") h->Scale(40.0);
323 h->SetLineColor(col2[cut]); h->SetMarkerColor(col2[cut]);
324 if(log==1) h->SetMinimum(0.1);
325 if(name==
"p_NP") h->SetMaximum(h->GetMaximum()*1000.0);
327 if(cut>0) opt+=
"same";
329 if(name==
"p_pid") opt+=
"colz";
334 for(
int cut=0; cut<NCUT2; cut++){
335 TText* t=
new TText(0.7,0.6-0.07*cut,CCUT2[cut]);
336 t->SetTextSize(0.07); t->SetNDC(); t->SetTextColor(col2[cut]);
345 pltcut(
"NP", c1,1,1,1);
347 pltcut(
"elo",c1,3,1);
348 pltcut(
"pt", c1,4,1);
349 pltcut(
"ept",c1,5,0);
350 pltcut(
"eta",c1,6,1);
351 c1->SaveAs(
"plot2/fms1.png");
355 pltcut(
"phi", c2,1,1,1);
358 pltcut(
"xy", c2,4,0);
359 pltcut(
"pid", c2,5,0);
360 pltcut(
"pid2",c2,6,0);
361 c2->SaveAs(
"plot2/fms2.png");
365 c3->cd(1); xy_c0->Draw(
"");
366 c3->cd(2); xy_c1->Draw(
"");
367 c3->cd(3); xy_c2->Draw(
"");
368 c3->cd(4); xy_c3->Draw(
"");
369 c3->cd(5); xy_c4->Draw(
"");
370 c3->cd(6); xy_c5->Draw(
"");
371 c2->SaveAs(
"plot2/fms3.png");
377 pltcut2(
"p_NP", c1, 1, 1);
378 pltcut2(
"p_e", c1, 2, 1);
379 pltcut2(
"p_pt", c1, 3, 1);
380 pltcut2(
"p_ept", c1, 4, 0);
381 pltcut2(
"p_eta", c1, 5, 1);
382 pltcut2(
"p_phi", c1, 6, 1, 1);
383 c1->SaveAs(
"plot2/pair1.png");
387 pltcut2(
"p_m1", c2, 1, 0);
388 pltcut2(
"p_m2", c2, 2, 1);
389 pltcut2(
"p_zgg", c2, 3, 1);
390 pltcut2(
"p_r30", c2, 4, 1);
391 pltcut2(
"p_r100", c2, 5, 1, 1);
392 pltcut2(
"p_pid", c2, 6, 2);
393 c2->SaveAs(
"plotpair2.png");
396 void readfile(
int file=0){
398 case 0: mTFile =
new TFile(
"hist/fmsps.root",
"old");
break;
399 case 1: mTFile =
new TFile(
"sim/test_electron.fmsfps.root");
break;
400 case 2: mTFile =
new TFile(
"sim/test_pion.fmsfps.root");
break;
401 case 3: mTFile =
new TFile(
"sim/test_gamma.fmsfps.root");
break;
402 case 4: mTFile =
new TFile(
"sim/test_pi0.fmsfps.root");
break;
403 case 5: mTFile =
new TFile(
"sim/test_mu-.fmsfps.root");
break;
406 for(
int cut=0; cut<NCUT1; cut++){
407 for(
int q=0; q<NQ; q++){
408 for(
int l=0; l<NL; l++){
409 sprintf(c,
"FMSFPS_Q%1dL%1d_c%d",q+1,l+1,cut);
410 mH2[q][l][cut]=(TH2F*)mTFile->Get(c);
411 sprintf(c,
"FMS-FPS_Q%1dL%1d_c%d",q+1,l+1,cut);
412 mHd[q][l][cut]=(TH1F*)mTFile->Get(c);
413 sprintf(c,
"FMSFPSd_Q%1dL%1d_c%d",q+1,l+1,cut);
414 mHd2[q][l][cut]=(TH2F*)mTFile->Get(c);
421 c1 =
new TCanvas(
"FPS",
"FPS",50,10,700,800);
422 c2 =
new TCanvas(
"FPS2",
"FPS2",750,10,700,800);
423 c3 =
new TCanvas(
"FPS3",
"FPS3",1450,10,700,800);
424 gStyle->SetPalette(1);
425 gStyle->SetStatW(0.4);
428 void plot(
int file=0,
int plt=0,
int quad=0,
int layer=0,
int slat=0,
int cut=0,
int log=0){
433 if(plt==1 || plt==0) plotfms();
434 if(plt==2 || plt==0) plotfmsPair();
435 if(plt==3 || plt==0) plot2d(quad,layer,slat,cut,0,1,0);
436 if(plt==4 || plt==0) plot2d(quad,layer,slat,cut,0,1,1);
437 if(plt==5 || plt==0){
438 for(
int l=1; l<=NL; l++){
439 plot2d(0,l,0,cut,0,1,0);
440 plot2d(0,l,0,cut,0,1,1);