16 #include "StEEmcUtil/EEfeeRaw/EEdims.h"
25 if(tFd==0 || !tFd->IsOpen()) {
26 printf(
"file not opened, Ignore\n");
30 printf(
"file '%s' opened\n",fname.Data());
31 HList=
new TObjArray(0);
37 void EEpixPed::findTowerHisto() {
38 assert(tFd->IsOpen());
43 for(i=0;i<MaxSectors ;i++) {
45 for(j=0;j<MaxSubSec;j++) {
46 for(k=0;k<MaxEtaBins;k++) {
48 sprintf(tt1,
"a%2.2dT%c%2.2d",i+1,
'A'+j,k+1);
50 TH1F* h= (TH1F*) tFd->Get(tt1);
57 if (h->GetEntries() < c_minInt) {
62 bool A=strstr(tt1,
"a04TB07");
63 bool B=strstr(tt1,
"a06TA07");
64 bool C=strstr(tt1,
"a08TB07");
74 printf(
"sector %d found histo %d\n ",i+1,n_hist);
80 printf(
"%s() Tower histo initialized, %d found\n",GetName(),ntot_hist);
86 void EEpixPed::findMapmtHisto() {
87 assert(tFd->IsOpen());
92 for(i=0;i<MaxSectors ;i++) {
94 printf(
"searching MAMT histsos for sect %d\n",secID);
96 for(uv=0;uv<MaxSmdPlains;uv++){
97 for(ist=0;ist<MaxSmdStrips;ist++) {
99 sprintf(tt1,
"a%2.2d%c%3.3d",secID,
'U'+uv,ist+1);
101 TH1F* h= (TH1F*) tFd->Get(tt1);
118 for(j=0;j<MaxSubSec;j++) {
119 for(k=0;k<MaxEtaBins;k++) {
124 sprintf(tt1,
"a%2.2d%c%c%2.2d",i+1,preL[l],
'A'+j,k+1);
125 TH1F* h= (TH1F*) tFd->Get(tt1);
136 printf(
"sector %d found histo %d \n ",i+1,n_hist);
142 printf(
"%s() MAPMT histo initialized, %d found\n",GetName(),ntot_hist);
148 void EEpixPed::fitHisto(TString fPath){
149 printf(
"Find pedestal within ADC limits [%d,%d], nMin>%d max+/-%d\n",c_x1,c_x2,c_minInt,c_xFit);
156 TString ouT=fPath+
"T.log";
157 TString ouM=fPath+
"Mpt.log";
158 printf(
"Achtung!!! - static variable xfile = %d\n",xfile);
159 printf(
" outT='%s' outM='%s'\n",ouT.Data(), ouM.Data());
162 { fout=fopen(ouT.Data(),
"w");}
164 { fout=fopen(ouM.Data(),
"w");}
168 fprintf( fout,
"name QA[ILHNWX] Nintegr chi2/ndf amplitude mean sigma erAmpl erMean erSigma\n");
170 TCanvas *c=
new TCanvas(); c=c;
172 TF1* fit =
new TF1(
"fPeak",
"gaus");
173 fit->SetLineColor(kGreen);
177 for(ja=0;ja<HList->GetEntries();ja++) {
178 TH1F* h=(TH1F*)HList->UncheckedAt(ja);
180 int nb=h->GetNbinsX();
181 h->SetAxisRange(c_x1,c_x2);
184 if (h->Integral() < c_minInt) {
185 fprintf(fout,
"%s %8.0f failed\n",h->GetName(), h->Integral());
191 float *x=h->GetArray();
197 for(i=c_x1;i<=c_x2;i++){
198 if(ym>x[i])
continue;
203 float x0=h->GetBinCenter(j);
216 for(i=jfind-5;i<=jfind+5;i++){
223 bool A=strstr(h->GetName(),
"a04TB07");
224 bool B=strstr(h->GetName(),
"a06TA07");
225 bool C=strstr(h->GetName(),
"a08TB07");
234 h->Fit(fit,
"OQ+W",
"",x1,x2);
236 char qaString[7]=
"......";
237 if(h->Integral()<qa_minInt) qaString[0]=
'I';
238 if(fit->GetParameter(1)<qa_pedLow) qaString[1]=
'L';
239 if(fit->GetParameter(1)>qa_pedHigh) qaString[2]=
'H';
240 if(fit->GetParameter(2)<qa_pedSigMin) qaString[3]=
'N';
241 if(fit->GetParameter(2)>qa_pedSigMax) qaString[4]=
'W';
243 fprintf(fout,
"%s %6s %8.0f %8.3f %9.3f %9.3f %8.3f %7.3f %7.3f %7.3f \n",
247 fit->GetChisquare()/fit->GetNDF(),
248 fit->GetParameter(0),
249 fit->GetParameter(1),
250 fit->GetParameter(2),
267 void EEpixPed:: savePedTable(
char *mode, TString fname){
269 printf(
" write file of pedestal values to '%s'\n",fname.Data());
271 for(secID=1;secID<=MaxSectors ;secID++) {
273 sprintf(txt,
"%s.sector%2.2d",fname.Data(),secID);
274 printf(
"%s ....",txt);
275 FILE *fd = fopen(txt,mode);
277 if(mode[0]==
'w') fprintf(fd,
"#sector%2.2d/eemcPMTped\n",secID);
278 sprintf(txt,
"a%2.2d",secID);
283 for(j=0;j<HList->GetEntries();j++) {
284 TH1F* h=(TH1F*)HList->UncheckedAt(j);
286 if(strncmp(txt,h->GetName(),3) )
continue;
287 TF1* ff=h->GetFunction(
"fPeak");
291 fprintf(fd,
"%s %6.2f %6.2f\n", h->GetName()+1,ff->GetParameter(1), ff->GetParameter(2));
295 printf(
" nOK=%d\n",nOK);
301 printf(
" write file of pedestal values by crate to '%s'\n",fname.Data());
307 for(crateID=1;crateID<=MaxCrates ;crateID++) {
309 sprintf(txt,
"%s.crate",fname.Data());
310 if(crateID==1) printf(
"%s ....",txt);
312 FILE *fd = fopen(txt,mode);
314 sprintf(txt,
"%03d",crateID);
318 for(j=0;j<HList->GetEntries();j++) {
319 TH1F* h=(TH1F*)HList->UncheckedAt(j);
323 strcpy(title,h->GetTitle());
325 char *p = strchr(title,
'=');
329 if(crateID != crate)
continue;
331 TF1* ff=h->GetFunction(
"fPeak");
335 fprintf(fd,
"%03d %03d %6.2f %6.2f\n", crate, chan, ff->GetParameter(1), ff->GetParameter(2));
341 printf(
" nOK=%d\n",nOK);
348 void EEpixPed::saveHisto(TString fname) {
351 TFile f(fname.Data(),
"update");
353 printf(
"%d histos are written to '%s' ...\n",HList->GetEntries(),fname.Data());
355 TH1F* h= (TH1F*) tFd->Get(
"info");
360 printf(
" , save Ok \n");