7 #include <TClonesArray.h>
11 #include <TGraphErrors.h>
32 memset(hA,0,
sizeof(hA));
33 memset(grA,0,
sizeof(grA));
38 adcMin=40; adcMax=140;
48 void SmdGains::init(){
53 sprintf(tt1,
"%02d%c",sectID,planeUV);
57 hA[0]=
new TH1F(
"sum"+plCore,plCore+
" Integral from raw spectra; strip ID; total counts",290,0.5,290.5);
58 hA[1]=
new TH1F(
"Lm"+plCore,plCore+
" Mean of Landau fit to average MIP ene (2strip); MPV (MeV)",30,.5,2);
59 hA[2]=
new TH1F(
"Lw"+plCore,plCore+
" Width of Landau fit to average MIP ene (2strip); Width=sigma (MeV)",20,0,1);
63 if(hA[i]) HList->Add(hA[i]);
66 TGraphErrors* gr=
new TGraphErrors;
71 gr->SetMarkerStyle(24);
72 gr->SetName(
"mpvN"+plCore);
73 gr->SetTitle(plCore+
" MPV of Landau fit to N 2-strips; strip ID; MIP energy (MeV)");
78 if(grA[i]) HList->Add(grA[i]);
81 printf(
"cuts for %s : adcMin=%d ,adcMax=%d minSum=%d maxRelEr=%f\n",plCore.Data(),adcMin,adcMax,minSum, maxRelEr);
83 for(i=0;i<mxS;i++) str[i].
id=i+1;
89 TFile* SmdGains::open(TString fn) {
91 assert(fdIn->IsOpen());
99 void SmdGains::doGainCorr(
int str1,
int str2,
int ns,
int pl){
101 TGraphErrors *gr= grA[1];
102 printf(
"doGainCorr() for %s, average over %d-strips pl=%d\n",gr->GetName(),ns,pl);
103 TString nn=gr->GetName();
106 c2=
new TCanvas(nn,nn,300,400);
108 c2=
new TCanvas(nn,nn,600,800);
113 for(i=str1,k=1; i<mxS; i+=ns,k++) {
118 c2->cd(29); hA[1]->Draw();
119 c2->cd(30); hA[2]->Draw();
121 if( pl&1) c2->Print(nn+
".ps");
131 void SmdGains:: avrMipNEne(
int str1,
int ns){
134 assert(str1>0 && ns>0);
138 for(i=str1;i<str1+ns;i++) {
140 sprintf(tit,
"e%s%03d",plCore.Data(),i);
141 TH1F* h= (TH1F*)fdIn->Get(tit); assert(h);
147 hs=(TH1F*) h->Clone();
153 sprintf(tit,
"avr%s%03d",plCore.Data(),str1);
155 TString nn=hs->GetTitle(); nn=
"avr"+nn;
159 float sum=hs->Integral();
161 if(sum<150) hs->Rebin();
166 hs->Fit(
"landau",
"RQ",
"", minMipEne, maxMipEne);
167 TF1* f=hs->GetFunction(
"landau");
169 f->SetLineColor(kRed);
171 double *par=f->GetParameters();
172 const double *epar=f->GetParErrors();
178 hA[2]->Fill(par[2]) ;
180 if(par[1]>0) rerr=empv/mpv;
181 hs->SetAxisRange(0,5.);
183 printf(
"%s MPV=%.2f +/- %.2f (%.1f%c) \n",hs->GetName(),mpv,empv,rerr*100.,37);
186 for(i=str1;i<str1+ns;i++) {
193 TGraphErrors* gr=grA[1];
195 gr->SetPoint(n,x,mpv);
196 gr->SetPointError(n,ns/2.,empv);
204 void SmdGains:: plTGraph(
const Char_t *shpFunc,
int ig,
int pl){
207 TGraphErrors *gr= grA[ig];
209 printf(
"plot %s\n",gr->GetName());
210 TString nn=gr->GetName();
212 c2=
new TCanvas(nn,nn,300,250);
218 gnCorFn=gr->GetFunction(shpFunc); assert(gnCorFn);
219 gnCorFn->SetLineColor(kRed);
220 gnCorFn ->SetLineWidth(2);
223 TList *Lx; TLine *ln;
224 Lx=gr->GetListOfFunctions(); assert(Lx);
225 ln=
new TLine(1,idealMipEne, mxS,idealMipEne); ln->SetLineColor(kBlue); Lx->Add(ln);
229 if( pl&1) c2->Print(nn+
".ps");
230 if( pl&2) c2->Print(nn+
".gif");
236 void SmdGains:: plFGC(){
237 TString nn=
"fgc"+plCore;
238 c2=
new TCanvas(nn,nn,500,400);
241 c2->cd(1); hA[1]->Draw();
242 c2->cd(2); hA[2]->Draw();
243 c2->cd(3); hA[3]->Draw();
244 c2->cd(4); hA[4]->Draw();
252 void SmdGains::fitSlopesSmd(
int str1,
int str2,
int pl) {
255 assert(str1>0 && ns>0);
256 sprintf(tit,
"%02d%c%03d+%d",sectID,planeUV,str1,ns);
257 printf(
"fitSlopes() %s\n",tit);
260 TLine *ln0=
new TLine(0,0,0,5000);
261 ln0->SetLineColor(kGreen);
263 if(c1==0) c1=
new TCanvas(
"aa1",
"aa1",800,700);
275 TList *Lx; TLine *ln;
276 for(i=str1;i<=str2;i++,k++) {
279 sprintf(tit,
"a%s%03d",plCore.Data(),i);
280 TH1F* h= (TH1F*)fdIn->Get(tit); assert(h);
284 h->SetAxisRange(adcMin,adcMax);
285 float sum=h->Integral();
286 h->SetAxisRange(-20,1.5*adcMax);
291 h->Draw(); h->SetLineColor(kBlue);gPad->SetLogy();
292 gPad->SetGridx(0); gPad->SetGridy(0);
293 float ymax=6000-str1*10; h->SetMaximum(ymax);
294 float ymin=100.9-str1/2.7;
299 Lx=h->GetListOfFunctions(); assert(Lx);
300 ln=
new TLine(adcMin,0,adcMin,30000); ln->SetLineColor(kMagenta);ln->SetLineStyle(2);
302 ln=
new TLine(adcMax,0,adcMax,30000); ln->SetLineColor(kMagenta); ln->SetLineStyle(2);
304 if(sum<minSum) { s->flag+=1;
continue;}
305 h->Fit(
"expo",
"RQ",
"",adcMin,adcMax);
308 if(strstr(h->GetName(),
"a02V269")) h->Fit(
"expo",
"RQ",
"",60,130);
309 if(strstr(h->GetName(),
"a06U077")) h->Fit(
"expo",
"RQ",
"",80,150);
312 TF1* f=h->GetFunction(
"expo");
313 f->SetLineColor(kRed);
315 double *par=f->GetParameters();
316 const double *epar=f->GetParErrors();
320 if(epar[1]>maxRelEr *TMath::Abs(par[1])) {
325 if(pl&1) c1->Print(ttC+
".ps");
326 if(pl&2) c1->Print(ttC+
".gif");
334 void SmdGains::fitSlopesTile(
int eta1,
int nEta,
char cT,
int pl) {
336 assert(eta1>0 && nEta>0);
337 sprintf(tit,
"%02d%cA-E%02d+%d",sectID,cT,eta1,nEta);
338 printf(
"fitSlopes() %s\n",tit);
342 if(cT==
'T') { adcMin=15; adcMax=45; }
343 if(c1==0) c1=
new TCanvas(
"aa2",
"aa2",800,700);
355 TList *Lx; TLine *ln;
356 for(i=eta1;i<eta1+nEta;i++) {
358 for(sub=
'A';sub<=
'E';sub++) {
360 sprintf(tit,
"a%02d%c%c%02d",sectID,cT,sub,i);
361 TH1F* h= (TH1F*)fdIn->Get(tit); assert(h);
365 h->SetAxisRange(adcMin,adcMax);
366 float sum=h->Integral();
367 h->SetAxisRange(xLow,1.5*adcMax);
368 if(cT==
'T') h->SetAxisRange(-20,100);
371 h->Draw(); h->SetLineColor(kBlue);
373 gPad->SetGridx(0); gPad->SetGridy(0);
374 h->SetMinimum(.9); h->SetMaximum(9000);
377 Lx=h->GetListOfFunctions(); assert(Lx);
378 ln=
new TLine(adcMin,0,adcMin,30000); ln->SetLineColor(kMagenta); Lx->Add(ln);
379 ln=
new TLine(adcMax,0,adcMax,30000); ln->SetLineColor(kMagenta); Lx->Add(ln);
382 h->Fit(
"expo",
"RQ",
"",adcMin,adcMax);
383 TF1* f=h->GetFunction(
"expo");
384 f->SetLineColor(kRed);
386 double *par=f->GetParameters();
387 const double *epar=f->GetParErrors();
392 printf(
"# %s %.4f %.4f %f\n",h->GetName(),sl,esl,sum);
397 if(pl&1) c1->Print(ttC+
".ps");
398 if(pl&2) c1->Print(ttC+
".gif");
406 void SmdGains:: doSlopesOnly(
float fac){
407 printf(
"working on gains from slopes only, fac=%f\n",fac);
415 s->egc=s->esl*s->gc/TMath::Abs(s->sl);
417 if(s->egc>maxRelEr *s->gc) {
429 void SmdGains:: finish(
int k) {
443 void SmdGains::saveGains(FILE *fd) {
450 rer=100.*s->egc/s->gc;
454 fprintf(fd,
"%s%03d %.1f %.1f (%.1f%c) sum1=%d flag=0x%0x mpv1=%.1f %.1f\n",plCore.Data(),s->id,s->gc,s->egc,rer,37,s->sum1,s->flag,s->mpv1,s->empv1);
456 fprintf(fd,
"#nBad =%d\n",nBad);
461 void SmdGains::saveHisto(
const Char_t *fname){
466 outName=
"smd"+plCore;
468 outName+=
".hist.root";
469 TFile f( outName,
"recreate");
471 printf(
"%d histos are written to '%s' ...\n",HList->GetEntries(),outName.Data());
486 void StripG::clear(){
496 void StripG::print(){
497 if(flag) printf(
"*");
499 printf(
"strip id=%d sl=%f esl=%f gc=%f egc=%f sum1=%d mpv1=%f empv1=%f\n",
id,sl,esl,gc,egc,sum1,mpv1,empv1);
501 printf(
"strip id=%d --- sum1=%d\n",
id,sum1);