--- calo/flight/FUTILITIES/macros/FCaloADC2MIP.cxx 2006/06/30 12:08:13 1.3 +++ calo/flight/FUTILITIES/macros/FCaloADC2MIP.cxx 2008/09/22 20:18:43 1.4 @@ -66,7 +66,7 @@ #include using namespace std; -void FCaloADC2MIP(TString Filename, TString calcalibfile = "", TString OutDir="", TString flist=""){ +void FCaloADC2MIP(TString Filename, TString calcalibfile = "", TString OutDir="", TString flist="", Int_t fit=1){ const char *pam_calib = pathtocalibration(); if ( !strcmp(OutDir.Data(),"") ){ OutDir = pam_calib; @@ -486,7 +486,7 @@ // for (Int_t i = 0; i < nevents; i++){ evno = i; - if ( i%1000 == 0 && i > 0 ) printf(" %iK \n",i/1000); + if ( i%100000 == 0 && i > 0 ) printf(" %i00K \n",i/100000); // printf(" %i \n",i); // // read from the header of the event the absolute time at which it was recorded @@ -720,6 +720,8 @@ e++; }; // + if ( !fit ) UPYES=0; + // if ( !UPYES ) goto end; printf("\n OK, now I will fit the MIP distribution for each strip \n\n"); // @@ -748,24 +750,29 @@ // Double_t fr[2]; Double_t sv[4], pllo[4], plhi[4], fp[4], fpe[4]; - if ( SNRPeak > 16. && SNRPeak < 35. ){ + // if ( SNRPeak > 16. && SNRPeak < 35. ){ + if ( SNRPeak > 16. && SNRPeak < 35. && fp[3] < 8.){ fr[0] = (Float_t)SNRPeak - 7.; sv[0]= fp[0]; sv[1]= fp[1]; sv[2]= fp[2]; sv[3]= fp[3]; } else { - fr[0] = 19.; + // fr[0] = 19.; + fr[0] = 17.5; sv[0] = 2.8; - sv[1] = 21.0; + // sv[1] = 21.0; + sv[1] = 23.0; sv[2] = 1000.0; sv[3] = 0.1; }; Int_t doitagain = 0; fitting: printf("Fitting strip %i %i %i \n",l,m,n); - fr[1] = 60.; + // fr[1] = 60.; + fr[1] = 50.; pllo[0]=0.5; pllo[1]=5.0; pllo[2]=1.0; pllo[3]=0.2; - plhi[0]=8.0; plhi[1]=50.0; plhi[2]=1000000.0; plhi[3]=8.0; + // plhi[0]=8.0; plhi[1]=50.0; plhi[2]=1000000.0; plhi[3]=8.0; + plhi[0]=15.0; plhi[1]=50.0; plhi[2]=1000000.0; plhi[3]=8.0; Double_t chisqr; Int_t ndf; // @@ -780,11 +787,13 @@ // // // - if ( ( SNRPeak < 0. || (SNRPeak < 16. || SNRPeak > 35.) || chisqr > 100.) && doitagain < 3 ){ + // if ( ( SNRPeak < 0. || (SNRPeak < 16. || SNRPeak > 35.) || chisqr > 100.) && doitagain < 3 ){ + if ( ( SNRPeak < 0. || (SNRPeak < 16. || SNRPeak > 35.) || chisqr > 100.) && doitagain < 4 ){ printf("\n The fit is not good, I will try again, step %i \n\n",doitagain); doitagain++; if ( chisqr > 100. ) { - fr[0] = fr[0] + 5.; + // fr[0] = fr[0] + 5.; + fr[0] = fr[0] + 2.; sv[0] = fp[0]; sv[1] = fp[1]; sv[2] = fp[2]; @@ -2170,7 +2179,7 @@ const char *file2; file2 = filenome.str().c_str(); TFile *hfile = 0; - hfile = new TFile(file2,"UPDATE","Calorimeter CALIBRATION data"); + hfile = new TFile(filevalue.Data(),"UPDATE","Calorimeter CALIBRATION data"); CalorimeterCalibration *calo = 0; TTree *tree; tree = (TTree*)hfile->Get("CaloADC"); @@ -2184,7 +2193,7 @@ file3.str(""); // file3 << OutDir.Data() << "/"; file3 << file; - TFile hfile3(file3.str().c_str()); + TFile hfile3(filename.Data()); Int_t l = 0; TCanvas *c1; Int_t ty = 1; @@ -2312,7 +2321,7 @@ input.str(""); input << tellme; out.str("y"); - if ( !strcmp(input.str().c_str(),stc.str().c_str()) ) { + if ( !strcmp(input.str().c_str(),out.str().c_str()) ) { calo->mip[l][m][n] = (float)SNRPeak; calo->ermip[l][m][n] = (float)ffpe[1]; for (Int_t a = 0; a < 4 ; a++){ @@ -2454,7 +2463,7 @@ const char *file2; file2 = filenome.str().c_str(); TFile *hfile = 0; - hfile = new TFile(file2,"READ","Calorimeter CALIBRATION data"); + hfile = new TFile(filevalue.Data(),"READ","Calorimeter CALIBRATION data"); CalorimeterCalibration *calo = 0; TTree *tree; tree = (TTree*)hfile->Get("CaloADC"); @@ -2841,25 +2850,28 @@ bmippa << " " << n; pfmip[l][m][n] = (TH1F*)temp->Clone(bmippa.str().c_str()); Int_t doitagain = 0; + Int_t ndoitagain = 0; Double_t fr[2]; Double_t sv[4], pllo[4], plhi[4], fp[4], fpe[4]; - if ( SNRPeak > 16. && SNRPeak < 35. ){ + // if ( SNRPeak > 16. && SNRPeak < 35. ){ + if ( SNRPeak > 16. && SNRPeak < 35. && fp[3] < 8. ){ fr[0] = (Float_t)SNRPeak - 7.; sv[0]= fp[0]; sv[1]= fp[1]; sv[2]= fp[2]; sv[3]= fp[3]; } else { - fr[0] = 19.; + fr[0] = 12.5; sv[0] = 2.8; - sv[1] = 21.0; + sv[1] = 23.0; sv[2] = 1000.0; sv[3] = 0.1; }; + fr[1] = 50.; + // fr[1] = 60.; fitting: printf("Fitting strip %i %i %i \n",l,m,n); - fr[1] = 60.; pllo[0]=0.5; pllo[1]=5.0; pllo[2]=1.0; pllo[3]=0.2; - plhi[0]=8.0; plhi[1]=50.0; plhi[2]=1000000.0; plhi[3]=8.0; + plhi[0]=15.0; plhi[1]=50.0; plhi[2]=1000000.0; plhi[3]=8.0; Double_t chisqr; Int_t ndf; pfitsnr[l][m][n] = langaufit(pfmip[l][m][n],fr,sv,pllo,plhi,fp,fpe,&chisqr,&ndf,"QR0"); @@ -2867,41 +2879,53 @@ Double_t SNRPeak = langaupro(fp); printf("\n Conversion factor: %f \n\n",SNRPeak); // + c1->cd(); + pfmip[l][m][n]->DrawCopy(); + pfitsnr[l][m][n]->DrawCopy("lsame"); + c1->Modified(); + c1->Update(); // // - if ( (SNRPeak<0. || (SNRPeak < 16. || SNRPeak > 35.) || chisqr > 100.) && doitagain < 3 ){ + if ( (SNRPeak<0. || (SNRPeak < 16. || SNRPeak > 35.) || chisqr > 100.) && doitagain < 11 ){ printf("\n The fit is not good, I will try again, step %i \n\n",doitagain); doitagain++; if ( chisqr > 100. ) { - fr[0] = fr[0] + 5.; + if ( fr[0] < 20. && !(doitagain%2) ) fr[0] += 1.; + if ( fr[1] > 35. && doitagain%2 ) fr[1] -= 3.; + // if ( doitagain > 1 ) fr[1] = 35.; sv[0] = fp[0]; sv[1] = fp[1]; sv[2] = fp[2]; - sv[3] = fp[3]; + sv[3] = fp[3]; + printf(" chi \n"); goto fitting; }; - if ( doitagain == 1 ) { + ndoitagain++; + if ( ndoitagain == 1 ) { fr[0] = 19.; sv[0] = 2.8; sv[1] = 21.0; sv[2] = 1000.0; sv[3] = 0.1; + printf(" uno \n"); goto fitting; }; - if ( doitagain == 2 ) { + if ( ndoitagain == 2 ) { fr[0] = 22.; sv[0] = 2.8; sv[1] = 25.0; sv[2] = 1000.0; sv[3] = 0.1; + printf(" due \n"); goto fitting; }; - if ( doitagain == 3 ) { + if ( ndoitagain == 3 ) { fr[0] = 12.; sv[0] = 2.8; sv[1] = 15.0; sv[2] = 1000.0; sv[3] = 0.1; + printf(" tre \n"); goto fitting; }; }; @@ -3000,12 +3024,15 @@ for (Int_t k = 0; k < 22; k++ ){ for (Int_t l = 0; l < 96; l++ ){ mip = 0.; - if ( (ccalo->fp[1][m][k][l] > 20. && ccalo->fp[1][m][k][l] < 32.) || ccalo->mask[m][k][l] == 1. ) { + // if ( (ccalo->fp[1][m][k][l] > 20. && ccalo->fp[1][m][k][l] < 32.) || ccalo->mask[m][k][l] == 1. ) { +// if ( (ccalo->fp[1][m][k][l] > 15. && ccalo->fp[1][m][k][l] < 45.) || ccalo->mask[m][k][l] == 1. ) { mip = ccalo->mip[m][k][l]; - } else { - mip = 26. ; - }; - if ( mip == 0 ) mip = 26. ; +// } else { + // mip = 26. ; +// mip = 28. ; +// }; + // if ( mip == 0 ) mip = 26. ; +// if ( mip == 0 ) mip = 28. ; // if ( m == 1 && k == 17 ) printf(" %i mip = %f \n",l,mip); fwrite(&mip,sizeof(mip),1,f); }; @@ -3018,16 +3045,22 @@ FILE *f; f = fopen(txtple.Data(),"rb"); Float_t mip = 0.; + Float_t tmip = 0.; for (Int_t m = 0; m < 2 ; m++ ){ for (Int_t k = 0; k < 22; k++ ){ for (Int_t l = 0; l < 96; l++ ){ mip = 0.; fread(&mip,sizeof(mip),1,f); + tmip += mip; + printf(" m %i k %i l %i mip %f \n",m,k,l,mip); // if ( m == 1 && k == 17 ) printf(" %i mip = %f \n",l,mip); }; }; }; fclose(f); + // + printf(" Average mip is %f \n",tmip/4224.); + // } void FCaloALIG2DAT(TString txtple){