StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
plBbc.C
1 TFile *fd=0;
2 TCanvas *c;
3 class TPad;
4 TPad *pad=0;
5 
6 
7 //==========================
8 //==========================
9 
10 void plBbc( int page=21,TString fName="aa3" ) {
11  int pr=0;
12 
13  TString outDir="../outBbc/";
14 
15  gROOT->Reset();
16  gStyle->SetOptStat(1111111);
17  gStyle->SetOptFit(1111111);
18 
19  gStyle->SetPalette(1,0);
20 
21  // Connect the input file and get the histogram
22  TString name2=outDir+fName+".hist.root";
23  printf("opening '%s'\n",name2.Data());
24  fd=new TFile(name2);
25  if(!fd->IsOpen()) {
26  printf("NOT found file=%s, STOP\n",hName.Data());
27  return ;
28  }
29  assert(fd->IsOpen());
30  // fd->ls();
31 
32  TString ctit=fName+"_"; ctit+=page;
33  c=new TCanvas(ctit,ctit,450,350);
34 
35 #if 0
36  c->Range(0,0,1,1);
37  TPad *pad0 = new TPad("pad0", "apd0",0.0,0.95,1.,1.);
38  pad0->Draw();
39  pad0->cd();
40 
41  TPaveText *pt = new TPaveText(0,0.,1,1,"br");
42  pt->Draw();
43  TDatime dt;
44  TString txt2=fName+", page="+page+", ";
45  txt2+=dt.AsString();
46  pt->AddText(txt2);
47  txt2="--";
48  pt->AddText(txt2);
49 
50  c->cd();
51  pad = new TPad("pad1", "apd1",0.0,0.0,1,.95);
52  pad->Draw();
53 #endif
54  pad=c;
55 
56  //fd->ls();
57  gStyle->SetOptStat(11111 );
58 
59  switch(page) {
60  //..........................................
61  //..........................................
62  case 0: {
63  pad->Divide(1,1);
64  pad->cd(1);
65  TH1* h= (TH1*)fd->Get("vd"); assert(h);
66  h->Fit("gaus","R","",-60,60);
67  } break;
68 
69  //..........................................
70  //..........................................
71  case 1: {
72  pad->Divide(2,2);
73  int i;
74  char *namex[]={"vk","va","vt","vv"};
75  for(i=0;i<4;i++){
76  pad->cd(i+1);
77  TH1* h= (TH1*)fd->Get(namex[i]); assert(h);
78  h->Draw("colz");
79  }
80  } break;
81  //..........................................
82  //..........................................
83  case 2: {
84  pad->Divide(2,3);
85  int i;
86  char *namex[]={"vk","va","vt","vE","vv","vd","vW"};
87  for(i=0;i<7;i++){
88  pad->cd(i+1);
89  TH1* h= (TH1*)fd->Get(namex[i]); assert(h);
90  if(i!=5)h->Draw("box");
91  else h->Fit("gaus");
92  }
93  } break;
94  //..........................................
95  //..........................................
96  case 3: {
97  pad->Divide(1,1);
98  pad->cd(1);
99  TString tt="vv";
100  TH2F*h2= (TH2F*)gROOT->FindObject(tt);
101  assert(h2);
102  h2->FitSlicesY();
103  TH1D*hd= (TH1D*)gROOT->FindObject(tt+"_1");
104 
105  h2->Draw("colz");
106  hd->SetMarkerStyle(20);
107  char *cFunc="pol1";
108  hd->Fit(cFunc,"R","same",220,280);
109  TF1* f1=hd->GetFunction(cFunc);
110  f1->SetLineColor(kYellow);
111  f1->SetLineWidth(2.);
112  } break;
113 
114  //..........................................
115  //..........................................
116  case 21:
117  case 22:
118  calT(pad,fd,page-21); // time offset
119  break;
120  //..........................................
121  //..........................................
122  case 31:
123  case 32:
124  calW(pad,fd,page-31); // time walk
125  break;
126  //..........................................
127  //..........................................
128  default: printf("page %d not defined\n",page);
129  pr=0;
130  }
131 
132  if(pr) {
133  TString outF=fName+"_"+page+".ps";
134  //TString outF=fName+".ps";
135 
136  c->Print(outF);
137  outF.ReplaceAll(".ps",".gif");
138  c->Print(outF);
139  return;
140  }
141 
142  return;
143 }
144 
145 //==========================
146 //==========================
147 calT(TPad *pad, TFile *fd, int iew=0) {
148  char cEW[2]={'E','W'};
149  int pm=-1+2*iew;
150  int nok=0;
151  ln0=new TLine(0,0,0,200); ln0->SetLineColor(kGreen);
152  pad->Divide(3,4);
153  for(int ih=0;ih<16;ih++) {
154  char tt1[100];
155  int iT=ih;
156  sprintf(tt1,"w%c%02d",cEW[iew],iT+1);
157  pad->cd(ih+1);
158  TH2* h2= (TH2*)fd->Get(tt1);
159  if(h2==0) break;
160  assert(h2);
161  // h2->Draw("box");
162  printf("pmt=%s neve=%.0f mean=%f\n",tt1,h2->GetEntries(),h2->GetMean(1));
163  if(h2->GetEntries()<50) continue;
164  TH1D *hd=h2->ProjectionY();
165  hd->Fit("gaus");
166  ln0->Draw();
167  f=hd->GetFunction("gaus");
168  f->SetLineColor(kRed);
169  f->SetLineWidth(2.);
170  nok++;
171  sprintf(tt1,"bbc%c%02d",cEW[iew],iT+1);
172  printf("#2 pmt=%s dz/cm=%.1f + / - %.1f sigDZ/cm %.1f + / - %.1f\n",tt1,f->GetParameter(1),f->GetParError(1),f->GetParameter(2),f->GetParError(2));
173  // output in TDC
174  float fac=2; //(1chan=2 cm)
175  printf("#1 %s %.1f + / - %.1f N=%.0f\n",tt1,pm*f->GetParameter(1)/fac,f->GetParError(1)/fac, h2->GetEntries());
176  }
177  printf("#1# found %d pmt in bbc%c, sign= %.1f\n",nok,cEW[iew],pm);
178 
179 }
180 
181 //==========================
182 //==========================
183 calW(TPad *pad, TFile *fd, int iew=0) {// time walk
184  char cEW[2]={'E','W'};
185  int nok=0;
186  int pm=-1+2*iew;
187  pad->Divide(1,1);
188 
189  TH2F *hs=0;
190  for(int ih=0;ih<16 ;ih++) {
191  char tt1[100];
192  int iT=ih;
193  // if(iT<6) continue;
194  sprintf(tt1,"w%c%02d",cEW[iew],iT+1);
195  pad->cd(ih+1);
196  TH2* h2= (TH2*)fd->Get(tt1); assert(h2);
197  // h2->Draw("box");
198  printf("pmt=%s neve=%.0f mean=%f\n",tt1,h2->GetEntries(),h2->GetMean(1));
199  if(h2->GetEntries()<400) continue;
200  twFit(h2);
201  TString tt=h2->GetName();
202  pad->Print(tt+".gif");
203  nok++;
204  }
205  printf("#1# added %d pmt in bbc%c\n",nok,cEW[iew]);
206 }
207 
208 //==========================
209 //==========================
210 twFit( TH2* h2) {
211 
212  ln0=new TLine(0,0,200,0); ln0->SetLineColor(kGreen);
213  TString tt=h2->GetName();
214 
215  TF1 *f1 = new TF1(tt+"fit",timeWalkFunc,-100,120,4);
216  // f1->SetParameters(-25,50,0.01 1.5);// East
217  f1->SetParameters(-50,40,0.01 0.1);// East #8
218  //f1->SetParameters(-80,30,1,0.1);// West
219  f1->SetLineColor(kRed);
220  f1->SetLineWidth(2.);
221 
222  h2->FitSlicesY();
223  TH1D*hd= (TH1D*)gROOT->FindObject(tt+"_1");
224  hd->SetMaximum(100);
225  hd->SetMinimum(-100);
226  hd->SetMarkerStyle(20);
227  h2->Draw("colz");
228  hd->Fit(tt+"fit","R","same",4,200);
229 
230  ln0->Draw();
231 
232  //........ draw +/- 1 sig error band for projection
233  Stat_t er1[1000];
234  memset(er1,0,sizeof(er1));
235 
236  TH1D *he= (TH1D*)gROOT->FindObject(tt+"_2");
237  TH1D *yu=(TH1D*) hd->Clone(); yu->SetLineColor(kMagenta);
238  yu->Add(he); yu->SetError(er1);
239  yu->Draw("same");
240 
241  TH1D *yd=(TH1D*) hd->Clone();
242  yd->Add(he,-1); yd->SetError(er1); yd->SetLineColor(kMagenta);
243  yd->Draw("same");
244 
245  double *par=f1->GetParameters();
246  double *parE=f1->GetParErrors();
247  int i;
248 
249  float fac=2.16; // 1tdc ch = 2 cm
250  float pm= 1; // use - for E
251  printf("#1 bbc%s %g %g %g %g \n",h2->GetName()+1,pm*par[0]/fac,pm*par[1]/fac,par[2],par[3]);
252 }
253 
254 //==========================
255 //==========================
256 
257 Double_t timeWalkFunc(Double_t *x, Double_t *par){
258  float maxAdc=80;
259  Float_t xx =x[0];
260  if(xx>maxAdc) xx=maxAdc; // ADC cut-off
261  Double_t f = par[0] + par[1]*exp(-par[2]*pow(xx,par[3]));
262  //Double_t f = par[0] + par[1]*xx;
263  return f;
264 }
265 
266 
267