20 fGain =
new float[32];
62 for(
size_t i=0; i<32; i++){
74 for(
size_t ch=0; ch<32; ch++){
110 for(
size_t p=0;
p<5;
p++){
149 for(
size_t i=0; i<32; i++){
187 for(
size_t i=0; i<
fHistos->size(); i++){
189 const char* hname =
fHistos->at(i)->GetName();
193 const uint8_t nDigitMac = name.find(
"_",name.find(
"_")+1)-name.find(
"_")-1;
194 fMac5 = atoi(name.substr(name.find(
"_")+1,nDigitMac).c_str());
196 const uint8_t nDigitChan = name.size()-name.find(
"_",name.find(
"_")+1)-1;
197 uint8_t chan = atoi(name.substr(name.size()-nDigitChan,nDigitChan).c_str());
198 if(chan>31)
std::cout <<
"ERROR in CrtCal::IndexToMacCHan: channel out of range (" << (short)chan <<
")" << std::endl;
210 std::cout <<
"ActiveChannel scan..." << std::endl;
211 for(
size_t i=0; i<
fHistos->size(); i++){
212 TH1F* h1 = (TH1F*)
fHistos->at(i)->Clone();
213 TH1F* h2 = (TH1F*)
fHistos->at(i)->Clone();
214 TH1F* h3 = (TH1F*)
fHistos->at(i)->Clone();
227 std::cout <<
"found " << nactive <<
" active channels" << std::endl;
234 for(
size_t ch=0; ch<32; ch++){
242 const size_t cutoff = 600;
244 if(h->Integral(h->FindBin(cutoff),h->GetNbinsX())==0) {
254 const size_t low = 300;
255 const size_t high = 1000;
258 h->GetXaxis()->SetRangeUser(low,high);
259 thresh = (int)h->GetBinLowEdge(h->GetMinimumBin());
266 return h->Integral(h->FindBin(thresh),h->GetNbinsX()+1);
273 float* statarr =
new float[8];
274 for(
size_t i=0; i<8; i++){
275 statarr[i] = FLT_MAX;
278 for(
size_t i=0; i<
fHistos->size(); i++){
280 TH1F*
h = (TH1F*)
fHistos->at(i)->Clone();
281 PedFit(h,chan,statarr,
true);
296 std::cout <<
"need ped cal before gain cal!" << std::endl;
301 float** statarr =
new float*[15];
302 for(
size_t i=0; i<15; i++){
303 statarr[i] =
new float[5];
304 for(
size_t j=0; j<5; j++){
305 statarr[i][j] = FLT_MAX;
309 for(
size_t i=0; i<
fHistos->size(); i++){
313 TH1F*
h = (TH1F*)
fHistos->at(i)->Clone();
338 const int low = 1, high = 300;
340 h->GetXaxis()->SetRangeUser(low,high);
342 const int max_bin = h->GetMaximumBin();
343 const int max_val = h->GetMaximum();
344 const int max_adc = h->GetBinLowEdge(max_bin);
347 TF1 *gausfit =
new TF1(
"gausfit",
"[0]*exp(-0.5*((x-[1])/[2])^2)",max_adc-12,max_adc+12);
350 gausfit->SetParName(0,
"Constant");
351 gausfit->SetParName(1,
"Peak value");
352 gausfit->SetParName(2,
"sigma");
355 gausfit->SetParameter(0,max_val);
356 gausfit->SetParLimits(0,0.5*max_val,1000*max_val);
357 gausfit->SetParameter(1,max_adc);
358 gausfit->SetParLimits(1,max_adc-20,max_adc+20);
359 gausfit->SetParameter(2,50.0);
360 gausfit->SetParLimits(2,1,50);
362 TCanvas *c =
new TCanvas();
365 gStyle->Reset(
"Modern");
366 if(h->GetMean()>(high-
low)/2)
367 gStyle->SetStatX(0.4);
369 gStyle->SetStatX(0.9);
371 gStyle->SetStatY(0.89);
372 gStyle->SetStatH(0.45);
373 gStyle->SetStatW(0.28);
374 h->Draw(
"e0samehist");
376 h->Fit(gausfit,
"RMQ");
378 float csq = gausfit->GetChisquare();
379 float ndf = gausfit->GetNDF();
380 float rcsq = csq/ndf;
385 gausfit->SetRange(gausfit->GetParameter(1)-10,gausfit->GetParameter(1)+10);
386 gausfit->SetParameter(0,gausfit->GetParameter(0));
387 gausfit->SetParLimits(0,gausfit->GetParameter(0)-50,gausfit->GetParameter(0)+50);
388 gausfit->SetParameter(1,gausfit->GetParameter(1));
389 gausfit->SetParLimits(1,gausfit->GetParameter(1)-10,gausfit->GetParameter(1)+10);
390 gausfit->SetParameter(2,gausfit->GetParameter(2));
391 gausfit->SetParLimits(2,gausfit->GetParameter(2)-10,gausfit->GetParameter(2)+10);
392 h->Fit(gausfit,
"RMQ");
395 gausfit->Draw(
"same");
398 statsarr[0]=gausfit->GetParameter(0);
399 statsarr[1]=gausfit->GetParError(0);
400 statsarr[2]=gausfit->GetParameter(1);
401 statsarr[3]=gausfit->GetParError(1);
402 statsarr[4]=gausfit->GetParameter(2);
403 statsarr[5]=gausfit->GetParError(2);
404 statsarr[6]=gausfit->GetChisquare();
405 statsarr[7]=gausfit->GetNDF();
410 gStyle->SetOptStat(1111);
411 gStyle->SetOptFit(111);
414 csq = gausfit->GetChisquare();
415 ndf = gausfit->GetNDF();
417 if (rcsq>200.0)
std::cout <<
"warning: possibly bad ped fit mac5 " <<
fMac5 <<
", ch. "
418 << chan <<
" X^2/NDF=" << rcsq <<
" ADC" << std::endl;
424 TString
fname =
"./";
428 if(chan<10) fname+=
"0";
431 while (!gSystem->AccessPathName(fname))
433 fname.Remove(fname.Length()-suff.Length(),fname.Length());
434 fname.Remove(fname.Length()-1,fname.Length());
440 TImage *img = TImage::Create();
442 img->WriteImage(fname);
455 const float gainSeed = 55.0;
456 const Double_t tSpectrumSigma = 1.75;
457 const Double_t tSpectrumThreshold = 0.18;
458 const size_t nPeakMax = 5;
461 h->GetXaxis()->SetRangeUser(350,700);
464 TCanvas* cspec =
new TCanvas();
467 TSpectrum *
s =
new TSpectrum();
469 int nPeak = s->Search(h,tSpectrumSigma,
"",tSpectrumThreshold);
475 float* peakXsqr =
new float[5];
476 float* peakNdf =
new float[5];
477 float* peakSigma =
new float[5];
478 float* peakSigmaErr =
new float[5];
479 float* peakNorm =
new float[5];
480 float* peakNormErr =
new float[5];
481 float* peakMean =
new float[5];
482 float* peakMeanErr =
new float[5];
486 for(
size_t j=0; j<5; j++){
488 peakXsqr[j] = FLT_MAX;
489 peakNdf[j] = FLT_MAX;
490 peakSigma[j] = FLT_MAX;
491 peakSigmaErr[j] = FLT_MAX;
492 peakNorm[j] = FLT_MAX;
493 peakNormErr[j] = FLT_MAX;
494 peakMean[j] = FLT_MAX;
495 peakMeanErr[j] = FLT_MAX;
505 Double_t *peaks = s->GetPositionX();
514 for(
int p=0;
p<nPeak-1;
p++)
515 if(peaks[
p]>peaks[
p+1])
522 }
while( nchanges != 0 );
532 float gy[11], gey[11];
533 int peak_offset = round((peaks[0]-peds[chan])/gainSeed);
535 for (
int j=0; j<nPeak&&j<10; j++)
537 if(peaks[j]<0)
std::cout <<
"bad peak value: " << peaks[j] << std::endl;
538 x[j] = j+peak_offset;
549 gey[0] = pwidths[chan];
556 for (
int g=0 ;
g<nPeak&&
g<(int)nPeakMax;
g++)
559 TF1 *gfit =
new TF1(
"gfit",
"gaus",y[
g]-20,y[
g]+20);
560 gfit->SetParameter(0,h->GetBinContent(h->FindBin(y[
g])));
561 gfit->SetParameter(1,y[g]);
562 gfit->SetParameter(2,12);
563 gfit->SetParLimits(0,0,20000);
564 gfit->SetParLimits(1,y[g]-15,y[g]+15);
565 gfit->SetParLimits(2,8,40);
574 if( y[g]<h->GetBinLowEdge(1)+15) nplow++;
575 if( y[g]>h->GetBinLowEdge(h->GetNbinsX())-15) nphigh++;
578 if( y[g]>h->GetBinLowEdge(1)+15 && y[
g]<h->GetBinLowEdge(h->GetNbinsX())-15&&
abs(y[g] - gfit->GetParameter(1)) < 15)
581 if(g!=0 && g!=nPeak-1
582 && (y[g+1]-y[g]<gainSeed*0.7 || y[g]-y[g-1]<gainSeed*0.7))
585 for (
int j=g; j<nPeak; j++) x[j] = x[j]-1;
590 if(g!=0&&g!=nPeak-1&&y[g+1]-y[g]<gainSeed*1.2&&y[g]-y[g-1]>gainSeed*1.5)
592 for (
int j=g; j<nPeak; j++) x[j] = x[j]+1;
596 if(g==nPeak-1 && (y[g]-y[g-1])/gainSeed >1.5) {
597 x[
g]+=(int)((y[g]-y[g-1])/gainSeed);
601 peakXsqr[gg] = gfit->GetChisquare();
602 peakNdf[gg] = gfit->GetNDF();
603 peakMean[gg] = gfit->GetParameter(1);
604 peakMeanErr[gg] = gfit->GetParError(1);
605 peakNorm[gg] = gfit->GetParameter(0);
606 peakNormErr[gg] = gfit->GetParError(0);
607 peakSigma[gg] = gfit->GetParameter(2);
608 peakSigmaErr[gg] = gfit->GetParError(2);
611 gy[gg] = gfit->GetParameter(1);
612 gey[gg] = sqrt(gx[gg]+gey[0]*gey[0]);
620 if (nplow>0)
for (
int i=1; i<gg; i++) gx[i] = gx[i]-(nplow-1);
623 TGraphErrors* gr_mean =
new TGraphErrors(gg,gx,gy,0,gey);
626 TF1 *fit =
new TF1(
"fit",
"[0] + [1]*x",gx[0]-0.25,gx[gg-1]+0.25);
629 fit->SetParName(1,
"Gain");
630 fit->SetParName(0,
"Pedestal");
631 fit->SetParameter(1,gainSeed);
632 fit->SetParameter(0,peds[chan]);
633 fit->SetParLimits(1,gainSeed-20,gainSeed+20);
634 fit->SetParLimits(0,peds[chan]*0.8,peds[chan]*1.2);
638 gr_mean->Fit(fit,
"QR");
642 if (fit->GetChisquare()/fit->GetNDF()>5.0)
645 chisqr=fit->GetChisquare();
646 for(
int i=1; i<gg; i++) gx[i]+=1;
647 gr_mean =
new TGraphErrors(gg,gx,gy,0,gey);
648 fit->SetRange(gx[0]-0.25,gx[gg-1]+0.25);
649 gr_mean->Fit(fit,
"QR");
650 if (fit->GetChisquare()<chisqr) chisqr=fit->GetChisquare();
653 for(
int i=1; i<gg; i++) gx[i]-=2;
654 gr_mean =
new TGraphErrors(gg,gx,gy,0,gey);
655 fit->SetRange(gx[0]-0.25,gx[gg-1]+0.25);
656 gr_mean->Fit(fit,
"QR");
657 if (fit->GetChisquare()<chisqr) chisqr=fit->GetChisquare();
660 for(
int i=1; i<gg; i++) gx[i]+=1;
661 gr_mean =
new TGraphErrors(gg,gx,gy,0,gey);
662 fit->SetRange(gx[0]-0.25,gx[gg-1]+0.25);
663 gr_mean->Fit(fit,
"QR");
672 gr_mean->SetTitle(grtitle.c_str());
673 gr_mean->GetXaxis()->SetTitle(
"Peak #");
674 gr_mean->GetYaxis()->SetTitle(
"ADC value");
675 gr_mean->SetMarkerColor(4);
676 gr_mean->SetMarkerStyle(20);
677 gr_mean->SetFillColor(0);
679 gr_mean->GetXaxis()->SetRangeUser(gx[0]-0.5,gx[gg-1]+0.5);
684 gStyle->SetOptStat(0100);
685 gStyle->SetOptFit(1111);
689 TCanvas *c2 =
new TCanvas();
693 gStyle->SetStatX(0.5);
694 gStyle->SetStatY(0.9);
695 gStyle->SetStatH(0.15);
696 gStyle->SetStatW(0.2);
699 gr_mean->Draw(
"ALP");
705 statsarr[0][0] = fit->GetParameter(1);
706 statsarr[1][0] = fit->GetParError(1);
707 statsarr[2][0] = fit->GetParameter(0);
708 statsarr[3][0] = fit->GetParError(0);
709 statsarr[4][0] = fit->GetChisquare();
710 statsarr[5][0] = fit->GetNDF();
711 statsarr[6][0] = nPeak;
712 for(
size_t i=0; i<5; i++) {
713 statsarr[7][i] = peakXsqr[i];
714 statsarr[8][i] = peakMean[i];
715 statsarr[9][i] = peakMeanErr[i];
716 statsarr[10][i] = peakNorm[i];
717 statsarr[11][i] = peakNormErr[i];
718 statsarr[12][i] = peakSigma[i];
719 statsarr[13][i] = peakSigmaErr[i];
720 statsarr[14][i] = peakNdf[i];
725 delete[] peakMeanErr;
727 delete[] peakNormErr;
729 delete[] peakSigmaErr;
736 TString suff =
".png";
738 TString fname2 =
fname;
743 if(chan<10) fname+=
"0";
744 if(chan<10) fname2+=
"0";
746 fname2+=
"_peak_fit_spec";
750 while (!gSystem->AccessPathName(fname))
752 fname.Remove(fname.Length()-suff.Length(),fname.Length());
753 fname.Remove(fname.Length()-1,fname.Length());
758 while (!gSystem->AccessPathName(fname2))
760 fname2.Remove(fname2.Length()-suff.Length(),fname2.Length());
761 fname2.Remove(fname2.Length()-1,fname2.Length());
767 TImage *img = TImage::Create();
769 img->WriteImage(fname);
773 img->WriteImage(fname2);
793 float& pedNorm,
float& pedNormErr,
float& pedSigma,
float& pedSigmaErr,
794 float& pedXsqr,
short& pedNdf ){
796 pedNorm = statarr[0];
797 pedNormErr = statarr[1];
800 pedSigma = statarr[4];
801 pedSigmaErr = statarr[5];
802 pedXsqr = statarr[6];
803 pedNdf = (short)statarr[7];
809 float& gainPed,
float& gainPedErr,
short& nPeak,
float* peakXsqr,
810 float* peakMean,
float* peakMeanErr,
float* peakNorm,
float* peakNormErr,
811 float* peakSigma,
float* peakSigmaErr,
short* peakNdf) {
813 gain = statarr[0][0];
814 gainErr = statarr[1][0];
815 gainPed = statarr[2][0];
816 gainPedErr = statarr[3][0];
817 gainXsqr = statarr[4][0];
818 gainNdf = (short)statarr[5][0];
819 nPeak = statarr[6][0];
820 for(
size_t i=0; i<5; i++){
822 peakXsqr[i] = statarr[7][i];
823 peakMean[i] = statarr[8][i];
824 peakMeanErr[i] = statarr[9][i];
825 peakNorm[i] = statarr[10][i];
826 peakNormErr[i] = statarr[11][i];
827 peakSigma[i] = statarr[12][i];
828 peakSigmaErr[i] = statarr[13][i];
829 peakNdf[i] = (short)statarr[14][i];
849 Double_t invsq2pi = 0.3989422804014;
850 Double_t mpshift = -0.22278298;
867 mpc = par[1] - mpshift * par[0];
870 xlow = x[0] - sc * par[3];
871 xupp = x[0] + sc * par[3];
873 step = (xupp-xlow) / np;
876 for(i=1.0; i<=np/2; i++) {
877 xx = xlow + (i-.5) * step;
878 fland = TMath::Landau(xx,mpc,par[0]) / par[0];
879 sum += fland * TMath::Gaus(x[0],xx,par[3]);
881 xx = xupp - (i-.5) * step;
882 fland = TMath::Landau(xx,mpc,par[0]) / par[0];
883 sum += fland * TMath::Gaus(x[0],xx,par[3]);
886 return (par[2] * step * sum * invsq2pi / par[3]);
891 TF1*
CrtCal::langaufit(TH1F *his, Double_t *fitrange, Double_t *startvalues, Double_t *parlimitslo, Double_t *parlimitshi, Double_t *fitparams, Double_t *fiterrors, Double_t *ChiSqr, Int_t *NDF)
913 sprintf(FunName,
"Fitfcn_%s",his->GetName());
918 TF1 *ffit =
new TF1(FunName,
langaufun,fitrange[0],fitrange[1],4);
919 ffit->SetParameters(startvalues);
920 ffit->SetParNames(
"Width",
"MP",
"Area",
"GSigma");
922 for (i=0; i<4; i++) {
923 ffit->SetParLimits(i, parlimitslo[i], parlimitshi[i]);
926 his->Fit(FunName,
"RB0");
928 ffit->GetParameters(fitparams);
929 for (i=0; i<4; i++) {
930 fiterrors[i] = ffit->GetParError(i);
932 ChiSqr[0] = ffit->GetChisquare();
933 NDF[0] = ffit->GetNDF();
939 void CrtCal::langaus_fit(TH1F*
h,
double& lang_lan_wid,
double& lang_lan_wid_err,
double& lang_lan_mp,
double& lang_lan_mp_err,
double& lang_area,
double& lang_area_err,
double& lang_gauss_sigma,
double& lang_gauss_sigma_err,
double& lang_chisq,
double& lang_ndf){
942 Double_t my_fitrange[2] = { 800,4000 };
943 Double_t my_startvalues[4] = { 3, 200, 10000, 150 };
944 Double_t my_parlimitslo[4] = { 0, 100, 1000, 100 };
945 Double_t my_parlimitshi[4] = { 1000, 10000, 10000000, 1000 };
948 Double_t my_fitparams[4], my_fiterrors[4], my_ChiSqr;
951 TF1 *my_langaus =
langaufit(h, my_fitrange, my_startvalues, my_parlimitslo, my_parlimitshi, my_fitparams, my_fiterrors, &my_ChiSqr, &my_NDF);
953 lang_lan_wid = my_fitparams[0]; lang_lan_wid_err = my_fiterrors[0];
954 lang_lan_mp = my_fitparams[1]; lang_lan_mp_err = my_fiterrors[1];
955 lang_area = my_fitparams[2]; lang_area_err = my_fiterrors[2];
956 lang_gauss_sigma = my_fitparams[3]; lang_gauss_sigma_err = my_fiterrors[3];
957 lang_chisq = my_ChiSqr; lang_ndf = my_NDF;
double * GetLangausNdf() const
Double_t langaufun(Double_t *x, Double_t *par)
float * GetPedXsqr() const
CrtCal(const vector< TH1F * > *histos)
map< uint8_t, uint8_t > fChanMap
process_name opflash particleana ie x
long * GetChanStats() const
double * fLangausGaussSigma
void ParseGainStats(float **statarr, float &gainXsqr, short &gainNdf, float &gain, float &gainErr, float &gainPed, float &gainPedErr, short &nPeak, float *peakXsqr, float *peakMean, float *peakMeanErr, float *peakNorm, float *peakNormErr, float *peakSigma, float *peakSigmaErr, short *peakNdf)
void PedFit(TH1F *h, size_t chan, float *statsarr, bool save)
double * fLangausWidthErr
TF1 * langaufit(TH1F *his, Double_t *fitrange, Double_t *startvalues, Double_t *parlimitslo, Double_t *parlimitshi, Double_t *fitparams, Double_t *fiterrors, Double_t *ChiSqr, Int_t *NDF)
double * GetLangausWidthErr() const
double * fLangausLandauMP
void GainFit(TH1F *h, size_t chan, float **statsarr, bool save)
short * GetPedNdf() const
double * GetLangausGaussSigmaErr() const
standard_dbscan3dalg useful for diagnostics hits not in a line will not be clustered on on only for track like only for track like on on the smaller the less shower like tracks low
double * GetLangausLandauMPErr() const
double * fLangausLandauMPErr
float ** GetPeakSigmaErr() const
float * GetPedNormErr() const
double * GetLangausArea() const
float ** GetPeakNorm() const
process_name opflash particleana ie ie y
float * GetGainPed() const
float ** GetPeakMean() const
float ** GetPeakXsqr() const
float * GetGainErr() const
const vector< TH1F * > * fHistos
double * GetLangausWidth() const
float * GetThreshPE() const
int FindNabove(TH1F *h, int thresh)
double * GetLangausLandauMP() const
int * GetThreshADC() const
float * GetPedSigma() const
float * GetPedErr() const
void ParsePedStats(const float *statarr, float &pedXsqr, float &ped, float &pedErr, float &pedNorm, float &pedNormErr, float &pedSigma, float &pedSigmaErr, short &pedNdf)
double * GetLangausXsqr() const
float * GetPedSigmaErr() const
double * fLangausGaussSigmaErr
std::string to_string(WindowPattern const &pattern)
then echo File list $list not found else cat $list while read file do echo $file sed s
int FindThreshADC(TH1F *h)
float ** GetPeakMeanErr() const
double * GetLangausAreaErr() const
float * GetPedNorm() const
void langaus_fit(TH1F *h, double &lang_lan_wid, double &lang_lan_wid_err, double &lang_lan_mp, double &lang_lan_mp_err, double &lang_area, double &lang_area_err, double &lang_gauss_sigma, double &lang_gauss_sigma_err, double &lang_chisq, double &lang_ndf)
short * GetGainNdf() const
float * GetGainPedErr() const
float ** GetPeakNormErr() const
float ** GetPeakSigma() const
short ** GetPeakNdf() const
BEGIN_PROLOG could also be cout
float * GetGainXsqr() const
double * GetLangausGaussSigma() const