Changeset 200 in JEM-EUSO


Ignore:
Timestamp:
Sep 27, 2013, 11:34:02 AM (11 years ago)
Author:
dagoret
Message:

class Analysis finished and its compile

Location:
equalization_gain/trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • equalization_gain/trunk/src/PlotScurvesAll-diffFit.cc

    r198 r200  
    220220  }
    221221 
    222   ofstream out(kFnameOut.Data());
     222 
    223223
    224224  // first loop on channels to fill histonames
     
    268268  in_gain.clear();
    269269 
    270 
     270  //----
    271271 
    272   // Open the S-Curve files for each channel and test if the file can be open
     272  // Open the pedestal file and the S-Curve files for each channel and test if the file can be open
    273273
    274274  Int_t trigger=0, trigger_fit=0, trigger_mean=0, trigger_sfit=0;
     
    355355   
    356356    // book histograms
     357    // SDC: 27/09/2013 hist_scurve is a pointer on an array of THD, thus the syntax is correct (no new operator)
     358   
    357359
    358360    hist_scurve[ch]      = TH1D(name_hist[ch],name_hist[ch],kNdata-1,
     
    364366    hist_diff_fit[ch]    = TH1D(name_hist_diff_fit[ch],name_hist_diff_fit[ch],
    365367                                kNdataFit,fit_min_scurve,fit_max_scurve);
     368
     369   
     370
     371
    366372
    367373    // read the data for that channel for normal data
     
    692698  ldac_ped_ave_copy->Draw("same");
    693699
     700  ofstream out(kFnameOut.Data());
     701
    694702  Int_t    gain_asic_diff, gain_asic_dacHalf, gain_asic_diff_mean, gain_asic_sfit;
    695703  out << "title  ch  g_asic_dacHalf  g_asic_diff  g_asic_diff_mean  g_asic_sfit  dac_half[ch]  dac_ped[ch]  dac_spe[ch]  dac_half_ave dac_half_spe dac_ped_ave  dac_sfit_ave"
     
    828836
    829837  ReadGainFile(fname_gain,kBoard);
     838
     839// Open the pedestal file and the S-Curve files for each channel and test if the file can be open
     840
     841  trigger=0;
     842  trigger_fit=0;
     843  trigger_mean=0;
     844  trigger_sfit=0;
     845
     846  // Big loop on all the channels : second loop
     847  //--------------------------------------------
     848  // build the input data file name for each channel fname-chXX.dat
     849  for(ch=0;ch<kNch;ch++)
     850    {
     851      ProcessSingleChannel(kDrawCh,fname,fname_ped,dac_half_spe_fix,fname_gain,
     852                           fit_min,fit_max,fit_min_scurve,fit_max_scurve,kBoard,kChRef);
     853      }
     854
     855
     856 
     857  ComputeDACAverage(dac_half_spe_fix ,kChRef,checkAve);
     858  OutputGain(kFnameOut);
     859
     860
     861
    830862}
    831863//--------------------------------------------------------------------------------------------------------
     
    937969//--------------------------------------------------------------------------------------------------------
    938970// Read the gain
     971// input : the gain filename
     972// output the gain_org[ch] array
    939973//--------------------------------------------------------------------------------------------------------
    940974
     
    9721006}
    9731007//--------------------------------------------------------------------------------------------------------
     1008
     1009
     1010
     1011//--------------------------------------------------------------------------------------------------------
     1012// ProcessSingleChannel
     1013//--------------------------------------------------------------------------------------------------------
     1014void Analysis::ProcessSingleChannel(
     1015                Int_t    kDrawCh,
     1016                TString  fname,
     1017                TString  fname_ped, //ASIC_D ped_file
     1018                Double_t dac_half_spe_fix,
     1019                TString  fname_gain,
     1020                Int_t    fit_min,
     1021                Int_t    fit_max,
     1022                Int_t    fit_min_scurve,
     1023                Int_t    fit_max_scurve,
     1024                Bool_t   kBoard, //0:ASIC_C, 1:ASIC_D
     1025                Int_t    kChRef//ASIC_C
     1026                //      Bool_t   checkAve //0:use ref pix, 1:check average)
     1027                                    )
     1028{
     1029    input[ch] += fname;
     1030    input[ch] += "-ch";
     1031    input[ch] += ch;
     1032    input[ch] += ".dat";
     1033    ifstream in(input[ch].Data());
     1034    if(!in.good()){
     1035      cerr << "File " << input[ch] << " open failed!" << endl;
     1036      return;
     1037    }
     1038
     1039    // build the input data file name for each channel fname_ped-chXX.dat
     1040    input_ped[ch] += fname_ped;
     1041    input_ped[ch] += "-ch";
     1042    input_ped[ch] += ch;
     1043    input_ped[ch] += ".dat";
     1044    ifstream in_ped(input_ped[ch].Data());
     1045    if(!in_ped.good()){
     1046      cerr << "File " << input_ped[ch] << " open failed!" << endl;
     1047      return;
     1048    }   
     1049
     1050
     1051   
     1052    //10DAC~10mV
     1053    // determine the DAC range in dac_min, dac_max, step_dac from file input_ped
     1054    // and count the number of events
     1055    Double_t da, dat, dac_min, dac_max, step_dac;
     1056    Int_t count = 0;
     1057    while (in >> da >> dat ){
     1058      if(count==0) dac_min  = da;
     1059      if(count==1) step_dac = da - dac_min;
     1060      dac_max=da;
     1061      count++;
     1062    }     
     1063    in.close();
     1064    in.clear();
     1065
     1066    /*   
     1067    if(ch==43 || ch==47){//for T1 ASIC_C
     1068      cerr << "CHECK " << ch << " " << fit_min_scurve << endl;
     1069      Int_t fit_min_scurve=140;
     1070    } else {
     1071      Int_t fit_min_scurve=kFitMinS;
     1072    }
     1073    */
     1074
     1075    // correct the scale for DAC range
     1076    if(kXmin<dac_min)kXmin=dac_min;
     1077    const Int_t kNdata    = count;
     1078    count = (fit_max_scurve-fit_min_scurve)/step_dac;
     1079    const Int_t kNdataFit = count;
     1080    if(ch==0){
     1081      cerr << "kNdata, dac_min, dac_max, step_dac: "
     1082           << kNdata << " " << dac_min << " " << dac_max << " "
     1083           << step_dac << endl;
     1084    }
     1085   
     1086    Double_t dac_min_ped, dac_max_ped, step_dac_ped;
     1087    count = 0;
     1088    while (in_ped >> da >> dat ){
     1089      if(count==0) dac_min_ped  = da;
     1090      if(count==1) step_dac_ped = da - dac_min_ped;
     1091      dac_max_ped=da;
     1092      count++;
     1093    }
     1094     
     1095    in_ped.close();
     1096    in_ped.clear();
     1097   
     1098
     1099    const Int_t kNdataPed = count;
     1100    if(ch==0){
     1101      cerr << "kNdataPed, dac_min_ped, dac_max_ped, step_dac_ped: "
     1102           << kNdataPed << " " << dac_min_ped << " " << dac_max_ped
     1103           << " " << step_dac_ped << endl;
     1104    }
     1105   
     1106    // book histograms
     1107    // SDC: 27/09/2013 hist_scurve is a pointer on an array of THD, thus the syntax is correct (no new operator)
     1108   
     1109
     1110    hist_scurve[ch]      = TH1D(name_hist[ch],name_hist[ch],kNdata-1,
     1111                                dac_min,dac_max);
     1112    hist_scurve_ped[ch]  = TH1D(name_hist_ped[ch],name_hist_ped[ch],
     1113                                kNdataPed-1,dac_min_ped,dac_max_ped);
     1114    hist_diff[ch]        = TH1D(name_hist_diff[ch],name_hist_diff[ch],
     1115                                kNdata-2,dac_min,dac_max);
     1116    hist_diff_fit[ch]    = TH1D(name_hist_diff_fit[ch],name_hist_diff_fit[ch],
     1117                                kNdataFit,fit_min_scurve,fit_max_scurve);
     1118
     1119   
     1120
     1121
     1122
     1123    // read the data for that channel for normal data
     1124    in.open(input[ch].Data());
     1125    Double_t       data[kNdata], dac[kNdata], dac_fit[kNdataFit], data_fit[kNdataFit];
     1126    while (in >> da >> dat ){
     1127      hist_scurve[ch].Fill(da,dat); // fill the histograms of the s-curve
     1128    }
     1129    in.close();
     1130    in.clear();
     1131
     1132    // read the data for pedestal data
     1133    in_ped.open(input_ped[ch].Data());
     1134    while (in_ped >> da >> dat ){
     1135      hist_scurve_ped[ch].Fill(da,dat); // fill the histogram for pedestal data
     1136    }
     1137    in_ped.close();
     1138    in_ped.clear();
     1139
     1140    //dac_ped[ch]  = hist_scurve_ped[ch].GetMaximumBin()+dac_min_ped; //absolute value
     1141    dac_ped[ch]  = hist_scurve_ped[ch].GetBinCenter(hist_scurve_ped[ch].GetMaximumBin()); //absolute value
     1142    dac_ped_sum += dac_ped[ch]; //absolute value
     1143    //cerr << "dac_ped[" << ch << "] dac_ped_sum " << dac_ped[ch]
     1144    //<< " " << dac_ped_sum << endl;
     1145   
     1146
     1147    hist_scurve[ch].Smooth(3); // Smooth the S curve
     1148    Int_t binx=0;
     1149    //hist_scurve[ch].GetBinWithContent(kHalfMax,binx,kXmin-dac_min+1,
     1150    //                                  dac_max-dac_min+1,kHalfMax/2.);
     1151
     1152    // ??????
     1153    hist_scurve[ch].GetBinWithContent(kHalfMax,binx,kXmin-dac_min+1,
     1154                                      dac_max-dac_min+1,2000);
     1155    dac_half[ch] = hist_scurve[ch].GetBinCenter(binx); //absolute value
     1156    if(dac_half[ch]<kXmin)dac_half[ch]=-1;
     1157   
     1158    // put the histograms of the smoothed S-Curves into two arrays (dac, data)
     1159    //-------------------------------------------------------------------------
     1160    Int_t i=0;
     1161    for(i=0;i<kNdata;i++){
     1162      dac[i]  = hist_scurve[ch].GetBinCenter(i+1);
     1163      data[i] = hist_scurve[ch].GetBinContent(i+1);
     1164    }
     1165   
     1166    /*** compute derive diff on S-Curve ***/
     1167    Double_t diff[kNdata-1], dac_diff[kNdata-1];
     1168    Int_t trigger_diff=0;
     1169    for(i=0;i<kNdata-1;i++){
     1170      diff[i]     = (data[i]-data[i+1])/step_dac;
     1171      dac_diff[i] = dac[i]+step_dac/2;
     1172      hist_diff[ch].Fill(dac_diff[i],diff[i]); // fills differentiated histograms of smoothed s-curves which is the single photoelectron spectrum
     1173      if(dac_diff[i]>=fit_min){
     1174        diff_sum += diff[i]*dac_diff[i];
     1175        //cerr << "diff[" << i << "], dac_diff[" << i << "] "
     1176        //<< diff[i] << " " << dac_diff[i] << endl;
     1177        trigger_diff+=diff[i];
     1178      }
     1179    }
     1180    //mean_diff[ch] = diff_sum/trigger_diff;
     1181    hist_diff[ch].GetXaxis()->SetRangeUser(fit_min,fit_max);
     1182    mean_diff[ch] = hist_diff[ch].GetMean();
     1183    //cerr << "trigger_diff, mean_diff[" << ch << "] "
     1184    //<< trigger_diff << " " << mean_diff[ch] << endl;
     1185   
     1186   
     1187    /******************* GRAPHICS *****************/
     1188
     1189
     1190    // Now start the analysis which consist in finding the peak in the differentiated spectrum
     1191    c1->cd(ch+1);   
     1192    /*** fit scurves  ***/
     1193    cerr << "ch " << ch;
     1194
     1195    //    SDC 24/09/2013 :: Need to declare outside this variable in a compiled program
     1196    TF1 *fit_pol ;
     1197
     1198
     1199    // Fit a polynomial curve in a given range on the s-curve directly. This is a kind of DEBUG procedure.
     1200
     1201    //if(ch==43 || ch==47){ // SDC: 25/09/2013 Why a special channel : the fit pol4 is performed for another DAC range
     1202 /*   if(ch==170){
     1203      fit_pol      = new TF1("fit_pol","pol4",150,fit_max_scurve);
     1204      hist_scurve[ch].Fit(fit_pol,"","",150,fit_max_scurve);
     1205    }else{ */
     1206      fit_pol      = new TF1("fit_pol","pol4",fit_min_scurve,fit_max_scurve);
     1207      hist_scurve[ch].Fit(fit_pol,"","",fit_min_scurve,fit_max_scurve);
     1208   // }
     1209
     1210   
     1211
     1212    Double_t fit_par_pol4[5]; // container for fit parameter results
     1213    fit_pol->GetParameters(fit_par_pol4);
     1214    sfit_chiS[ch] =  fit_pol->GetChisquare(); // chi squared
     1215    TF1 *func               = hist_scurve[ch].GetFunction("fit_pol");
     1216    Double_t data_diff_fit;
     1217    for(i=0;i<kNdataFit;i++){
     1218      //if(ch==43 || ch==47){
     1219      if(ch==170){
     1220        dac_fit[i]  = hist_scurve[ch].GetBinCenter(i)+150-dac_min;
     1221        data_fit[i] = func->Eval(hist_scurve[ch].GetBinCenter(i)+150-dac_min); // get the value of the fitted function
     1222      }else{
     1223        dac_fit[i]  = hist_scurve[ch].GetBinCenter(i)+fit_min_scurve-dac_min;
     1224        data_fit[i] = func->Eval(hist_scurve[ch].GetBinCenter(i)+fit_min_scurve-dac_min); // get the value of the fitted function
     1225        //cerr << "dac_fit[" << i << "], data_fit[" << i << "] "
     1226        //<< dac_fit[i] << " " << data_fit[i] << endl;
     1227      }
     1228    }
     1229
     1230    // derive the fitted function on the S-curve to obtain the SPE
     1231    Double_t dac_diff_fit;
     1232    for(i=0;i<kNdataFit-1;i++){
     1233      data_diff_fit = (data_fit[i]-data_fit[i+1])/step_dac;
     1234      hist_diff_fit[ch].Fill(dac_fit[i],data_diff_fit); // Fill differentiated fitted S-curve
     1235    }
     1236
     1237    TLine *lhalf_max   = new TLine(dac[0],kHalfMax,dac[kNdata-1],kHalfMax);
     1238    TLine *ldac_half   = new TLine(dac_half[ch],0,dac_half[ch],
     1239                                   (Double_t)kDrawMax);
     1240    hist_scurve[ch].SetMaximum(kDrawMax);
     1241    hist_scurve[ch].GetXaxis()->SetRangeUser(kDrawDacMin,kDrawDacMax);
     1242    hist_scurve[ch].Draw();
     1243    lhalf_max->Draw("same"); 
     1244    ldac_half->Draw("same");
     1245    if(dac_half[ch]>0){
     1246      dac_half_sum += dac_half[ch]-dac_ped[ch]; //relative absolute value
     1247      trigger++;
     1248    }
     1249
     1250    /*** Differential plot from scurve fitting function  ***/
     1251    c5->cd(ch+1);
     1252    hist_diff_fit[ch].GetXaxis()->SetRangeUser(fit_min_scurve,fit_max_scurve-2*step_dac);
     1253    Double_t dac_sfit_max=hist_diff_fit[ch].GetBinCenter(hist_diff_fit[ch].GetMaximumBin());
     1254    //if(dac_sfit_max<=fit_min_scurve+4*step_dac){
     1255    if(dac_sfit_max<=fit_min_scurve+2*step_dac){
     1256      hist_diff_fit[ch].GetXaxis()->SetRangeUser(fit_min_scurve+kFitSadj,fit_max_scurve-2*step_dac);
     1257      dac_sfit[ch]  =  hist_diff_fit[ch].GetBinCenter(hist_diff_fit[ch].GetMaximumBin());
     1258      //if(dac_sfit[ch]<=fit_min_scurve+kFitSadj+4*step_dac)dac_sfit[ch]=-1;
     1259      if(dac_sfit[ch]<fit_min_scurve+kFitSadj+step_dac){
     1260        dac_sfit[ch]=-1;
     1261        //dac_sfit[ch]=dac_half[ch];
     1262        flag_fit[ch] = -1;
     1263        cerr << "flag_fit[" << ch << "] " << flag_fit[ch]  << endl;
     1264      }
     1265    }else {
     1266      dac_sfit[ch]  =  hist_diff_fit[ch].GetBinCenter(hist_diff_fit[ch].GetMaximumBin());
     1267    }
     1268
     1269    if(dac_sfit[ch]>fit_min_scurve+5){
     1270      dac_sfit_sum += dac_sfit[ch]-dac_ped[ch];
     1271      trigger_sfit++;
     1272    }else{
     1273      //dac_sfit[ch] = fit_min_scurve+10;
     1274      dac_sfit[ch] = -1;
     1275    }
     1276    //cerr << "dac_sfit[" << ch << "] " << dac_sfit[ch] << endl;
     1277    TLine *ldac_sfit      = new TLine(dac_sfit[ch],0,dac_sfit[ch],kDrawMaxFit);
     1278    TLine *ldac_sfit_copy = new TLine(dac_sfit[ch],0,dac_sfit[ch],kDrawMax);
     1279    ldac_sfit->SetLineColor(kMagenta);
     1280    ldac_sfit_copy->SetLineColor(kMagenta);
     1281    hist_diff_fit[ch].SetMaximum(kDrawMaxFit);
     1282    hist_diff_fit[ch].SetMinimum(0);
     1283    hist_diff_fit[ch].Draw();
     1284    ldac_sfit->Draw("same");
     1285   
     1286    /**** differential plot ****/
     1287    c2->cd(ch+1);
     1288    //hist_diff[ch].Rebin(8);
     1289    hist_diff[ch].Rebin(3);
     1290    fit_sdiff     = new TF1("fit_sdiff","gaus",dac_min,dac_max);
     1291    //fit_sdiff->SetLineWidth(1);
     1292    //if(ch==8 || ch==18 || ch==44 || ch==56)
     1293    mean_sum += mean_diff[ch]-dac_ped[ch];
     1294    trigger_mean++;
     1295
     1296    // fit the derivated polynom fit
     1297    Double_t fit_par[3];
     1298    //hist_diff[ch].Fit(fit_sdiff,"RQ0","",fit_min,fit_max);
     1299    hist_diff[ch].Fit(fit_sdiff,"","",fit_min,fit_max);
     1300    hist_diff[ch].GetXaxis()->SetRangeUser(kDrawDacMin,kDrawDacMax);
     1301    hist_diff[ch].SetMinimum(0);
     1302    hist_diff[ch].SetMaximum(kDrawMaxDiff);
     1303    //hist_diff[ch].Rebin();
     1304    hist_diff[ch].Draw();
     1305    fit_sdiff->GetParameters(fit_par); // get the parameters for this fit
     1306    dac_spe[ch] = fit_par[1];
     1307    if(dac_spe[ch]>fit_min){
     1308      dac_spe_sum += dac_spe[ch]-dac_ped[ch];
     1309      //cerr << "dac_spe[" << ch << "] " << dac_spe[ch] << endl;
     1310      trigger_fit++;
     1311    }else{
     1312      dac_spe[ch] = fit_min+10;
     1313    }
     1314    //cerr << "dac_spe[" << ch << "] " << dac_spe[ch] << endl;
     1315    TLine *ldac_spe    = new TLine(dac_spe[ch],0,dac_spe[ch],
     1316                                 (Double_t)kDrawMaxDiff);
     1317    ldac_spe->SetLineColor(kRed);
     1318    TLine *lmean_diff  = new TLine(mean_diff[ch],0,mean_diff[ch],
     1319                                   (Double_t)kDrawMaxDiff);
     1320    lmean_diff->SetLineColor(kCyan);
     1321    TLine *lfit_min    = new TLine(fit_min,0,fit_min,kDrawMaxDiff);
     1322    lfit_min->SetLineColor(kGray);
     1323
     1324    ldac_spe->Draw();
     1325    lmean_diff->Draw("same");
     1326    lfit_min->Draw("same");
     1327   
     1328    c3->cd(1);
     1329    if(ch==0){
     1330      hist_scurve[ch].SetMaximum(kDrawMax);
     1331      hist_scurve[ch].Draw();
     1332    }else{
     1333    /*if(ch==8 || ch==18 || ch==44 || ch==56)*/
     1334      hist_scurve[ch].Draw("same");
     1335    }
     1336    if(ch==kDrawCh){
     1337      c3->cd(2);
     1338      hist_scurve[ch].SetMaximum(kDrawMax);
     1339      hist_scurve[kDrawCh].Draw();
     1340      lhalf_max->Draw("same"); 
     1341      ldac_half->Draw("same");
     1342      ldac_sfit_copy->Draw("same");
     1343      c3->cd(3);
     1344      hist_diff[kDrawCh].Draw();     
     1345      ldac_spe->Draw();
     1346      lmean_diff->Draw("same");
     1347      lfit_min->Draw("same");
     1348      c3->cd(4);
     1349      hist_diff_fit[kDrawCh].Draw();
     1350       ldac_sfit->Draw("same");
     1351      }
     1352    /*
     1353    if(ch<32){
     1354      c6->cd(ch/4+1);
     1355      hist_scurve[ch].SetMaximum(kDrawMax);
     1356      if(ch%4==0){
     1357        hist_scurve[ch].Draw();
     1358      }else{
     1359        hist_scurve[ch].Draw("same");
     1360      }
     1361      ldac_sfit_copy->Draw("same");
     1362    }else{
     1363      c7->cd(ch/4-7);
     1364      hist_scurve[ch].SetMaximum(kDrawMax);
     1365      if(ch%4==0){
     1366        hist_scurve[ch].Draw();
     1367      }else{
     1368        hist_scurve[ch].Draw("same");
     1369      }
     1370      ldac_sfit_copy->Draw("same");
     1371      }
     1372    */
     1373   
     1374    c4->cd();
     1375    if(ch==0){
     1376      hist_scurve_ped[ch].SetMaximum(kDrawMaxPed);
     1377      hist_scurve_ped[ch].Draw("l");
     1378    }else{
     1379      hist_scurve_ped[ch].Draw("lsame");
     1380    }
     1381   
     1382  }// end of process single  channels
     1383
     1384//---------------------------------------------------------------------------------------------------
     1385
     1386
     1387//---------------------------------------------------------------------------------------------------
     1388
     1389//---------------------------------------------------------------------------------------------------
     1390void Analysis::ComputeDACAverage(Double_t dac_half_spe_fix ,Int_t    kChRef, Bool_t   checkAve )//0:use ref pix, 1:check average
     1391{
     1392
     1393 // SDC 24/09/2013 :: In a compiled program, I have to declare the following variables outside the parenthesis
     1394
     1395 
     1396  mean_diff_ave = 252.5; //dac_sfit of ch31 of ASIC_C with the 180 for lower gain pixels
     1397 
     1398  if(!checkAve){
     1399    dac_ped_ave   = dac_ped[kChRef]; //absolute value
     1400    dac_half_ave  = dac_half[kChRef];
     1401    dac_spe_ave   = dac_spe[kChRef];
     1402    dac_sfit_ave  = dac_sfit[kChRef];
     1403    //Float_t dac_sfit_ave  = 252.5; //dac_sfit of ch31 of ASIC_C with the 180 for lower gain pixels
     1404    mean_diff_ave = mean_diff[kChRef];
     1405  }else{
     1406    dac_ped_ave  = dac_ped_sum/(Float_t)kNch; //absolute value
     1407    dac_half_ave = dac_half_sum/(Float_t)trigger+dac_ped_ave;
     1408    dac_spe_ave  = dac_spe_sum/(Float_t)trigger_fit+dac_ped_ave;
     1409    mean_diff_ave = mean_sum/(Float_t)trigger_mean+dac_ped_ave;
     1410    dac_sfit_ave = dac_sfit_sum/(Float_t)trigger_sfit+dac_ped_ave;
     1411  }
     1412
     1413
     1414// SDC 24/09/2013 :: In a compiled program, I have to declare the following variables outside the parenthesis
     1415
     1416
     1417  //trigger_mean=4;
     1418  if(dac_half_spe_fix!=-1) {
     1419    dac_half_spe = dac_half_spe_fix;
     1420  } else {
     1421    //Double_t dac_half_spe = dac_half_ave;
     1422    dac_half_spe = dac_spe_ave;
     1423  }
     1424
     1425  TLine *ldac_ped_ave   = new TLine(dac_ped_ave,0,dac_ped_ave,
     1426                                   (Double_t)kDrawMax);
     1427  TLine *ldac_ped_ave_copy = new TLine(dac_ped_ave,0,dac_ped_ave,
     1428                                   (Double_t)kDrawMaxDiff);
     1429  TLine *ldac_half_ave  = new TLine(dac_half_ave,0,dac_half_ave,
     1430                                   (Double_t)kDrawMax);
     1431  TLine *ldac_half_spe  = new TLine(dac_half_spe,0,dac_half_spe,
     1432                                   (Double_t)kDrawMax);
     1433  TLine *lmean_diff_ave = new TLine(mean_diff_ave,0,mean_diff_ave,
     1434                                   (Double_t)kDrawMax);
     1435  TLine *ldac_sfit_ave  = new TLine(dac_sfit_ave,0,dac_sfit_ave,
     1436                                   (Double_t)kDrawMax);
     1437  ldac_ped_ave->SetLineColor(kOrange);
     1438  ldac_half_ave->SetLineColor(kRed);
     1439  lmean_diff_ave->SetLineColor(kCyan);
     1440  //ldac_half_spe->SetLineColor(kGreen);
     1441  ldac_sfit_ave->SetLineColor(kMagenta); 
     1442
     1443  c3->cd(1);
     1444  ldac_ped_ave->Draw("same");
     1445  ldac_half_ave->Draw("same");
     1446  // lhalf_max->Draw("same");  SDC (24/09/2013) :: Not declared
     1447  ldac_half_spe->Draw("same");
     1448  lmean_diff_ave->Draw("same");
     1449  ldac_sfit_ave->Draw("same");
     1450
     1451  c3->cd(3);
     1452  ldac_ped_ave_copy->SetLineColor(kOrange);
     1453  ldac_ped_ave_copy->Draw("same");
     1454
     1455 
     1456
     1457}
     1458
     1459//---------------------------------------------------------------------------------------------------
     1460
     1461//---------------------------------------------------------------------------------------------------
     1462void Analysis::OutputGain(const TString fname_out)
     1463{
     1464
     1465 ofstream out(fname_out.Data());
     1466
     1467 Int_t    gain_asic_diff, gain_asic_dacHalf, gain_asic_diff_mean, gain_asic_sfit;
     1468  out << "title  ch  g_asic_dacHalf  g_asic_diff  g_asic_diff_mean  g_asic_sfit  dac_half[ch]  dac_ped[ch]  dac_spe[ch]  dac_half_ave dac_half_spe dac_ped_ave  dac_sfit_ave"
     1469       << endl;
     1470
     1471
     1472  // loop 3 on all channels to make final computations on the gain
     1473  for(ch=0;ch<kNch;ch++){
     1474    /*
     1475    if(ch==8 || ch==44 || ch==56 || ch==18){
     1476      gain_asic_diff_mean=(Int_t)((mean_diff_ave-dac_ped_ave)/
     1477                                  (mean_diff[ch]-dac_ped[ch])*gain_org[ch]);
     1478    }else{
     1479      gain_asic_diff_mean=0;
     1480    }
     1481    */
     1482    if(dac_half[ch]<0){
     1483      gain_asic_dacHalf   = 0;
     1484      gain_asic_diff      = 0;
     1485      gain_asic_diff_mean = 0;
     1486      gain_asic_sfit      = 0;
     1487    }else{
     1488      gain_asic_dacHalf  =(Int_t)((dac_half_ave-dac_ped_ave)/
     1489                                (dac_half[ch]-dac_ped[ch])*gain_org[ch]);
     1490      gain_asic_diff     =(Int_t)((dac_half_spe-dac_ped_ave)/
     1491                             (dac_spe[ch]-dac_ped[ch])*gain_org[ch]);
     1492      gain_asic_diff_mean=(Int_t)((mean_diff_ave-dac_ped_ave)/
     1493                                  (mean_diff[ch]-dac_ped[ch])*gain_org[ch]);
     1494      gain_asic_sfit     =(Int_t)((dac_sfit_ave-dac_ped_ave)/
     1495                             (dac_sfit[ch]-dac_ped[ch])*gain_org[ch]);
     1496      //cerr << ch << " " << gain_org[ch] << endl;
     1497    }
     1498
     1499   
     1500
     1501    out << "OUT_TABLE    "
     1502         << ch << "    "
     1503         << gain_asic_dacHalf   << "    "
     1504         << gain_asic_diff      << "    "
     1505         << gain_asic_diff_mean << "    "
     1506         << gain_asic_sfit      << "    "
     1507         << dac_half[ch]        << "    "
     1508         << dac_ped[ch]         << "    "
     1509         << (Int_t)dac_spe[ch]  << "    "
     1510         << dac_half_ave        << "    "
     1511         << dac_half_spe        << "    "
     1512         << dac_ped_ave         << "    "
     1513         << dac_sfit_ave        << "    "
     1514         << sfit_chiS[ch]       << "    "
     1515         << ch                  << "    "
     1516         << flag_fit[ch]       
     1517         << endl;
     1518      std::cout << "channel " << ch << " old gain " << gain_org[ch] << " new gain " << gain_asic_sfit << std::endl;
     1519  }
     1520  out.close();
     1521
     1522}
  • equalization_gain/trunk/src/PlotScurvesAll-diffFit.h

    r197 r200  
    7171 void FillHistoName();
    7272 void ReadGainFile(const TString,Bool_t);
     73 void ProcessSingleChannel(
     74                Int_t    kDrawCh,
     75                TString  fname,
     76                TString  fname_ped, //ASIC_D ped_file
     77                Double_t dac_half_spe_fix,
     78                TString  fname_gain,
     79                Int_t    fit_min,
     80                Int_t    fit_max,
     81                Int_t    fit_min_scurve,
     82                Int_t    fit_max_scurve,
     83                Bool_t   kBoard, //0:ASIC_C, 1:ASIC_D
     84                Int_t    kChRef//ASIC_C
     85         );
     86 void ComputeDACAverage(Double_t dac_half_spe_fix ,Int_t    kChRef,Bool_t checkAve); //0:use ref pix, 1:check average)
     87 void OutputGain(const TString fname_out);
    7388
    7489// common variables to the analysis
    7590     TString *input;
    7691     TString *input_ped;
    77      Int_t    ch;
     92     Int_t    ch; // index on current channel under analysis
    7893     Float_t  dac_half_sum; 
    7994     Float_t  dac_ped_sum;   
     
    90105     Double_t dac_sfit[kNch];
    91106     Double_t mean_diff[kNch];
    92      Double_t gain_org[kNch];
     107     Double_t gain_org[kNch]; // array containing the initial gain values
    93108     Double_t sfit_chiS[kNch];
    94109     Double_t flag_fit[kNch];
     
    115130     TF1     *fit_sdiff;  // function fitted on differentiated histograms of fitted s-curves
    116131
    117 
     132     Int_t trigger;
     133     Int_t trigger_fit;
     134     Int_t trigger_mean;
     135     Int_t trigger_sfit;
    118136     
     137     Float_t dac_ped_ave  ; //absolute value
     138     Float_t dac_half_ave  ;
     139     Float_t dac_spe_ave   ;
     140     Float_t dac_sfit_ave;
     141     Float_t mean_diff_ave ;//dac_sfit of ch31 of ASIC_C with the 180 for lower gain pixels
     142 
     143     Double_t dac_half_spe;
    119144
    120145};
  • equalization_gain/trunk/src/PlotScurvesAll-diffFitConst.h

    r191 r200  
    7373
    7474// Output file
    75 const TString kFnameOut="output.dat";
     75const TString kFnameOut="gain-output.dat";
    7676
    7777//Int_t kFitMin = 160; //T1 ASIC_D it0, default
Note: See TracChangeset for help on using the changeset viewer.