Changeset 204 in JEM-EUSO


Ignore:
Timestamp:
Sep 27, 2013, 1:23:30 PM (11 years ago)
Author:
dagoret
Message:

working class analysis

Location:
equalization_gain/branches/analclass-Sylvie/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • equalization_gain/branches/analclass-Sylvie/src/PlotScurvesAll-diffFit.cc

    r196 r204  
    1717#include "PlotScurvesAll-diffFitConst.h"
    1818#include "PlotScurvesAll-diffFit.h"
     19
     20//#if defined(__CINT__) && !defined(__MAKECINT__)
     21//#include "PlotScurveAll-diffFit.h"
     22//#else
     23//#include "PlotScurvesAll-diffFit.h"
     24//#endif
    1925
    2026
     
    214220  }
    215221 
    216   ofstream out(kFnameOut.Data());
     222 
    217223
    218224  // first loop on channels to fill histonames
     
    262268  in_gain.clear();
    263269 
    264 
     270  //----
    265271 
    266   // 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
    267273
    268274  Int_t trigger=0, trigger_fit=0, trigger_mean=0, trigger_sfit=0;
     
    349355   
    350356    // 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   
    351359
    352360    hist_scurve[ch]      = TH1D(name_hist[ch],name_hist[ch],kNdata-1,
     
    358366    hist_diff_fit[ch]    = TH1D(name_hist_diff_fit[ch],name_hist_diff_fit[ch],
    359367                                kNdataFit,fit_min_scurve,fit_max_scurve);
     368
     369   
     370
     371
    360372
    361373    // read the data for that channel for normal data
     
    686698  ldac_ped_ave_copy->Draw("same");
    687699
     700  ofstream out(kFnameOut.Data());
     701
    688702  Int_t    gain_asic_diff, gain_asic_dacHalf, gain_asic_diff_mean, gain_asic_sfit;
    689703  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"
     
    737751         << flag_fit[ch]       
    738752         << endl;
     753      std::cout << "channel " << ch << " old gain " << gain_org[ch] << " new gain " << gain_asic_sfit << std::endl;
    739754  }
    740755
     
    759774Analysis::Analysis():ch(0),dac_half_sum(0),dac_spe_sum(0),dac_sfit_sum(0),diff_sum(0),mean_sum(0),maxBinSum(0)
    760775{
    761  
    762    
     776  if(DEBUG)
     777    cout << " >>>>>>> START Analysis Constructor " << endl;
    763778
    764779 /*********************** SIGNAL RUN ********************/
     
    775790  maxBinSum         = 0;
    776791
    777 
     792 if(DEBUG)
     793    cout << " >>>>>>> END Analysis Constructor " << endl;
    778794}
    779795//--------------------------------------------------------------------------------------------------------
     
    786802{
    787803 
     804 if(DEBUG)
     805    cout << " >>>>>>> START Analysis Destructor " << endl;
     806
    788807  if(input!=0) delete input;
    789808  if(input_ped!=0) delete input_ped;
    790809
     810if(DEBUG)
     811    cout << " >>>>>>> END Analysis Destructor " << endl;
    791812
    792813}
     
    797818// Main public function of Analysis
    798819//--------------------------------------------------------------------------------------------------------
     820/*
    799821void Analysis::PlotScurve(
    800822                Int_t    kDrawCh=31,
     
    809831                Bool_t   kBoard=0, //0:ASIC_C, 1:ASIC_D
    810832                Int_t    kChRef=kRefCh,//ASIC_C
    811                 Bool_t   checkAve=0 //0:use ref pix, 1:check average*/
     833                Bool_t   checkAve=0 //0:use ref pix, 1:check average
    812834                )
    813 
    814 {
    815 
     835*/
     836void Analysis:: PlotScurve(
     837                Int_t    kDrawCh,
     838                TString  fname,
     839                TString  fname_ped, //ASIC_D ped_file
     840                Double_t dac_half_spe_fix,
     841                TString  fname_gain,
     842                Int_t    fit_min,
     843                Int_t    fit_max,
     844                Int_t    fit_min_scurve,
     845                Int_t    fit_max_scurve,
     846                Bool_t   kBoard, //0:ASIC_C, 1:ASIC_D
     847                Int_t    kChRef,//ASIC_C
     848                Bool_t   checkAve //0:use ref pix, 1:check average
     849                )
     850
     851
     852
     853{
     854
     855if(DEBUG)
     856{
     857    cout << " >>>>>>> START Analysis::PlotScurve " << endl;
     858    cout << " \t - kDrawCh = " << kDrawCh << endl;
     859    cout << " \t - fname = " << fname << endl;
     860    cout << " \t - fname_ped = " << fname_ped <<endl;
     861    cout << " \t - dac_half_spe_fix = " << dac_half_spe_fix << endl;
     862
     863    cout << " \t - fname_gain = " << fname_gain << endl;
     864    cout << " \t - fit_min = " << fit_min << endl;
     865    cout << " \t - fit_max = " << fit_max << endl;
     866    cout << " \t - fit_min_scurve = " << fit_min_scurve << endl;
     867    cout << " \t - fit_max_scurve = " << fit_max_scurve << endl;
     868    cout << " \t - kBoard = " << kBoard << " 0:ASIC_C, 1:ASIC_D " << endl;
     869    cout << " \t - kChRef = " << kChRef << " ASIC_C " << endl;
     870    cout << " \t - checkAve = " << checkAve << " 0:use ref pix, 1:check average " << endl;     
     871}
    816872  // reset all variables
    817873  Init();
     
    822878
    823879  ReadGainFile(fname_gain,kBoard);
     880
     881// Open the pedestal file and the S-Curve files for each channel and test if the file can be open
     882
     883  trigger=0;
     884  trigger_fit=0;
     885  trigger_mean=0;
     886  trigger_sfit=0;
     887
     888  // Big loop on all the channels : second loop
     889  //--------------------------------------------
     890  // build the input data file name for each channel fname-chXX.dat
     891  for(ch=0;ch<kNch;ch++)
     892    {
     893      ProcessSingleChannel(kDrawCh,fname,fname_ped,dac_half_spe_fix,fname_gain,
     894                           fit_min,fit_max,fit_min_scurve,fit_max_scurve,kBoard,kChRef);
     895      }
     896
     897
     898 
     899  ComputeDACAverage(dac_half_spe_fix ,kChRef,checkAve);
     900  OutputGain(kFnameOut);
     901
     902if(DEBUG)
     903    cout << " >>>>>>> END Analysis::PlotSCurve " << endl;
     904
    824905}
    825906//--------------------------------------------------------------------------------------------------------
     
    832913{
    833914
    834   if(input!=0) delete input;
    835   if(input_ped!=0) delete input_ped;
     915if(DEBUG)
     916    cout << " >>>>>>> START Analysis::Init " << endl;
     917
     918//if(input!=0) delete input;
     919//if(input_ped!=0) delete input_ped;
    836920
    837921  // recreate the name
     
    881965 }
    882966
     967if(DEBUG)
     968    cout << " >>>>>>> END Analysis::Init " << endl;
    883969
    884970 
     
    891977void Analysis::OpenGainFile(const TString fname_gain)
    892978{
     979if(DEBUG)
     980    cout << " >>>>>>> START Analysis::OpenGainFile " << endl;
     981
     982
     983
    893984  TString input_gain(fname_gain);
    894985  ifstream in_gain(input_gain.Data());
     
    900991  in_gain.clear();
    901992
     993if(DEBUG)
     994    cout << " >>>>>>> END Analysis::OpenGainFile " << endl;
     995
     996
    902997}
    903998//--------------------------------------------------------------------------------------------------------
     
    9081003void Analysis::FillHistoName()
    9091004{
     1005
     1006if(DEBUG)
     1007    cout << " >>>>>>> START Analysis::FillHistoName " << endl;
     1008
     1009
    9101010 
    9111011// first loop on channels to fill histonames
     
    9251025  }
    9261026
     1027if(DEBUG)
     1028    cout << " >>>>>>> END Analysis::FillHistoName " << endl;
     1029
     1030
     1031
    9271032}
    9281033//--------------------------------------------------------------------------------------------------------
     
    9311036//--------------------------------------------------------------------------------------------------------
    9321037// Read the gain
     1038// input : the gain filename
     1039// output the gain_org[ch] array
    9331040//--------------------------------------------------------------------------------------------------------
    9341041
    9351042void Analysis::ReadGainFile(const TString fname_gain,Bool_t kBoard)
    9361043{
     1044
     1045if(DEBUG)
     1046{
     1047    cout << " >>>>>>> START Analysis::ReadGainFile " << endl;
     1048    cout << " \t - fname_gain = " << fname_gain << endl;
     1049    cout << " \t - kBoard = " << kBoard << " 0:ASIC_C, 1:ASIC_D " << endl;
     1050       
     1051}
     1052
     1053
     1054
    9371055  TString input_gain(fname_gain);
    9381056  ifstream in_gain(input_gain.Data());
     
    9631081  in_gain.clear();
    9641082 
    965 
    966 }
    967 //--------------------------------------------------------------------------------------------------------
     1083if(DEBUG)
     1084{
     1085    cout << " >>>>>>> END Analysis::ReadGainFile " << endl;
     1086       
     1087}
     1088
     1089}
     1090//--------------------------------------------------------------------------------------------------------
     1091
     1092
     1093
     1094//--------------------------------------------------------------------------------------------------------
     1095// ProcessSingleChannel
     1096//--------------------------------------------------------------------------------------------------------
     1097void Analysis::ProcessSingleChannel(
     1098                Int_t    kDrawCh,
     1099                TString  fname,
     1100                TString  fname_ped, //ASIC_D ped_file
     1101                Double_t dac_half_spe_fix,
     1102                TString  fname_gain,
     1103                Int_t    fit_min,
     1104                Int_t    fit_max,
     1105                Int_t    fit_min_scurve,
     1106                Int_t    fit_max_scurve,
     1107                Bool_t   kBoard, //0:ASIC_C, 1:ASIC_D
     1108                Int_t    kChRef//ASIC_C
     1109                //      Bool_t   checkAve //0:use ref pix, 1:check average)
     1110                                    )
     1111{
     1112
     1113
     1114if(DEBUG)
     1115{
     1116  cout << " >>>>>>> START Analysis::ProcessSingleChannel ch=" << ch << endl;
     1117    cout << " \t - kDrawCh = " << kDrawCh << endl;
     1118    cout << " \t - fname = " << fname << endl;
     1119    cout << " \t - fname_ped = " << fname_ped <<endl;
     1120    cout << " \t - dac_half_spe_fix = " << dac_half_spe_fix << endl;
     1121
     1122    cout << " \t - fname_gain = " << fname_gain << endl;
     1123    cout << " \t - fit_min = " << fit_min << endl;
     1124    cout << " \t - fit_max = " << fit_max << endl;
     1125    cout << " \t - fit_min_scurve = " << fit_min_scurve << endl;
     1126    cout << " \t - fit_max_scurve = " << fit_max_scurve << endl;
     1127    cout << " \t - kBoard = " << kBoard << " 0:ASIC_C, 1:ASIC_D " << endl;
     1128    cout << " \t - kChRef = " << kChRef << " ASIC_C " << endl;
     1129    //    cout << " \t - checkAve = " << checkAve << " 0:use ref pix, 1:check average " << endl;L       
     1130}
     1131
     1132
     1133
     1134    input[ch] += fname;
     1135    input[ch] += "-ch";
     1136    input[ch] += ch;
     1137    input[ch] += ".dat";
     1138    ifstream in(input[ch].Data());
     1139    if(!in.good()){
     1140      cerr << "File " << input[ch] << " open failed!" << endl;
     1141      return;
     1142    }
     1143
     1144    // build the input data file name for each channel fname_ped-chXX.dat
     1145    input_ped[ch] += fname_ped;
     1146    input_ped[ch] += "-ch";
     1147    input_ped[ch] += ch;
     1148    input_ped[ch] += ".dat";
     1149    ifstream in_ped(input_ped[ch].Data());
     1150    if(!in_ped.good()){
     1151      cerr << "File " << input_ped[ch] << " open failed!" << endl;
     1152      return;
     1153    }   
     1154
     1155
     1156   
     1157    //10DAC~10mV
     1158    // determine the DAC range in dac_min, dac_max, step_dac from file input_ped
     1159    // and count the number of events
     1160    Double_t da, dat, dac_min, dac_max, step_dac;
     1161    Int_t count = 0;
     1162    while (in >> da >> dat ){
     1163      if(count==0) dac_min  = da;
     1164      if(count==1) step_dac = da - dac_min;
     1165      dac_max=da;
     1166      count++;
     1167    }     
     1168    in.close();
     1169    in.clear();
     1170
     1171    /*   
     1172    if(ch==43 || ch==47){//for T1 ASIC_C
     1173      cerr << "CHECK " << ch << " " << fit_min_scurve << endl;
     1174      Int_t fit_min_scurve=140;
     1175    } else {
     1176      Int_t fit_min_scurve=kFitMinS;
     1177    }
     1178    */
     1179
     1180    // correct the scale for DAC range
     1181    if(kXmin<dac_min)kXmin=dac_min;
     1182    const Int_t kNdata    = count;
     1183    count = (fit_max_scurve-fit_min_scurve)/step_dac;
     1184    const Int_t kNdataFit = count;
     1185    if(ch==0){
     1186      cerr << "kNdata, dac_min, dac_max, step_dac: "
     1187           << kNdata << " " << dac_min << " " << dac_max << " "
     1188           << step_dac << endl;
     1189    }
     1190   
     1191    Double_t dac_min_ped, dac_max_ped, step_dac_ped;
     1192    count = 0;
     1193    while (in_ped >> da >> dat ){
     1194      if(count==0) dac_min_ped  = da;
     1195      if(count==1) step_dac_ped = da - dac_min_ped;
     1196      dac_max_ped=da;
     1197      count++;
     1198    }
     1199     
     1200    in_ped.close();
     1201    in_ped.clear();
     1202   
     1203
     1204    const Int_t kNdataPed = count;
     1205    if(ch==0){
     1206      cerr << "kNdataPed, dac_min_ped, dac_max_ped, step_dac_ped: "
     1207           << kNdataPed << " " << dac_min_ped << " " << dac_max_ped
     1208           << " " << step_dac_ped << endl;
     1209    }
     1210   
     1211    // book histograms
     1212    // SDC: 27/09/2013 hist_scurve is a pointer on an array of THD, thus the syntax is correct (no new operator)
     1213   
     1214
     1215    hist_scurve[ch]      = TH1D(name_hist[ch],name_hist[ch],kNdata-1,
     1216                                dac_min,dac_max);
     1217    hist_scurve_ped[ch]  = TH1D(name_hist_ped[ch],name_hist_ped[ch],
     1218                                kNdataPed-1,dac_min_ped,dac_max_ped);
     1219    hist_diff[ch]        = TH1D(name_hist_diff[ch],name_hist_diff[ch],
     1220                                kNdata-2,dac_min,dac_max);
     1221    hist_diff_fit[ch]    = TH1D(name_hist_diff_fit[ch],name_hist_diff_fit[ch],
     1222                                kNdataFit,fit_min_scurve,fit_max_scurve);
     1223
     1224   
     1225
     1226
     1227
     1228    // read the data for that channel for normal data
     1229    in.open(input[ch].Data());
     1230    Double_t       data[kNdata], dac[kNdata], dac_fit[kNdataFit], data_fit[kNdataFit];
     1231    while (in >> da >> dat ){
     1232      hist_scurve[ch].Fill(da,dat); // fill the histograms of the s-curve
     1233    }
     1234    in.close();
     1235    in.clear();
     1236
     1237    // read the data for pedestal data
     1238    in_ped.open(input_ped[ch].Data());
     1239    while (in_ped >> da >> dat ){
     1240      hist_scurve_ped[ch].Fill(da,dat); // fill the histogram for pedestal data
     1241    }
     1242    in_ped.close();
     1243    in_ped.clear();
     1244
     1245    //dac_ped[ch]  = hist_scurve_ped[ch].GetMaximumBin()+dac_min_ped; //absolute value
     1246    dac_ped[ch]  = hist_scurve_ped[ch].GetBinCenter(hist_scurve_ped[ch].GetMaximumBin()); //absolute value
     1247    dac_ped_sum += dac_ped[ch]; //absolute value
     1248    //cerr << "dac_ped[" << ch << "] dac_ped_sum " << dac_ped[ch]
     1249    //<< " " << dac_ped_sum << endl;
     1250   
     1251
     1252    hist_scurve[ch].Smooth(3); // Smooth the S curve
     1253    Int_t binx=0;
     1254    //hist_scurve[ch].GetBinWithContent(kHalfMax,binx,kXmin-dac_min+1,
     1255    //                                  dac_max-dac_min+1,kHalfMax/2.);
     1256
     1257    // ??????
     1258    hist_scurve[ch].GetBinWithContent(kHalfMax,binx,kXmin-dac_min+1,
     1259                                      dac_max-dac_min+1,2000);
     1260    dac_half[ch] = hist_scurve[ch].GetBinCenter(binx); //absolute value
     1261    if(dac_half[ch]<kXmin)dac_half[ch]=-1;
     1262   
     1263    // put the histograms of the smoothed S-Curves into two arrays (dac, data)
     1264    //-------------------------------------------------------------------------
     1265    Int_t i=0;
     1266    for(i=0;i<kNdata;i++){
     1267      dac[i]  = hist_scurve[ch].GetBinCenter(i+1);
     1268      data[i] = hist_scurve[ch].GetBinContent(i+1);
     1269    }
     1270   
     1271    /*** compute derive diff on S-Curve ***/
     1272    Double_t diff[kNdata-1], dac_diff[kNdata-1];
     1273    Int_t trigger_diff=0;
     1274    for(i=0;i<kNdata-1;i++){
     1275      diff[i]     = (data[i]-data[i+1])/step_dac;
     1276      dac_diff[i] = dac[i]+step_dac/2;
     1277      hist_diff[ch].Fill(dac_diff[i],diff[i]); // fills differentiated histograms of smoothed s-curves which is the single photoelectron spectrum
     1278      if(dac_diff[i]>=fit_min){
     1279        diff_sum += diff[i]*dac_diff[i];
     1280        //cerr << "diff[" << i << "], dac_diff[" << i << "] "
     1281        //<< diff[i] << " " << dac_diff[i] << endl;
     1282        trigger_diff+=diff[i];
     1283      }
     1284    }
     1285    //mean_diff[ch] = diff_sum/trigger_diff;
     1286    hist_diff[ch].GetXaxis()->SetRangeUser(fit_min,fit_max);
     1287    mean_diff[ch] = hist_diff[ch].GetMean();
     1288    //cerr << "trigger_diff, mean_diff[" << ch << "] "
     1289    //<< trigger_diff << " " << mean_diff[ch] << endl;
     1290   
     1291   
     1292    /******************* GRAPHICS *****************/
     1293
     1294
     1295    // Now start the analysis which consist in finding the peak in the differentiated spectrum
     1296    c1->cd(ch+1);   
     1297    /*** fit scurves  ***/
     1298    cerr << "ch " << ch;
     1299
     1300    //    SDC 24/09/2013 :: Need to declare outside this variable in a compiled program
     1301    TF1 *fit_pol ;
     1302
     1303
     1304    // Fit a polynomial curve in a given range on the s-curve directly. This is a kind of DEBUG procedure.
     1305
     1306    //if(ch==43 || ch==47){ // SDC: 25/09/2013 Why a special channel : the fit pol4 is performed for another DAC range
     1307 /*   if(ch==170){
     1308      fit_pol      = new TF1("fit_pol","pol4",150,fit_max_scurve);
     1309      hist_scurve[ch].Fit(fit_pol,"","",150,fit_max_scurve);
     1310    }else{ */
     1311      fit_pol      = new TF1("fit_pol","pol4",fit_min_scurve,fit_max_scurve);
     1312      hist_scurve[ch].Fit(fit_pol,"","",fit_min_scurve,fit_max_scurve);
     1313   // }
     1314
     1315   
     1316
     1317    Double_t fit_par_pol4[5]; // container for fit parameter results
     1318    fit_pol->GetParameters(fit_par_pol4);
     1319    sfit_chiS[ch] =  fit_pol->GetChisquare(); // chi squared
     1320    TF1 *func               = hist_scurve[ch].GetFunction("fit_pol");
     1321    Double_t data_diff_fit;
     1322    for(i=0;i<kNdataFit;i++){
     1323      //if(ch==43 || ch==47){
     1324      if(ch==170){
     1325        dac_fit[i]  = hist_scurve[ch].GetBinCenter(i)+150-dac_min;
     1326        data_fit[i] = func->Eval(hist_scurve[ch].GetBinCenter(i)+150-dac_min); // get the value of the fitted function
     1327      }else{
     1328        dac_fit[i]  = hist_scurve[ch].GetBinCenter(i)+fit_min_scurve-dac_min;
     1329        data_fit[i] = func->Eval(hist_scurve[ch].GetBinCenter(i)+fit_min_scurve-dac_min); // get the value of the fitted function
     1330        //cerr << "dac_fit[" << i << "], data_fit[" << i << "] "
     1331        //<< dac_fit[i] << " " << data_fit[i] << endl;
     1332      }
     1333    }
     1334
     1335    // derive the fitted function on the S-curve to obtain the SPE
     1336    Double_t dac_diff_fit;
     1337    for(i=0;i<kNdataFit-1;i++){
     1338      data_diff_fit = (data_fit[i]-data_fit[i+1])/step_dac;
     1339      hist_diff_fit[ch].Fill(dac_fit[i],data_diff_fit); // Fill differentiated fitted S-curve
     1340    }
     1341
     1342    TLine *lhalf_max   = new TLine(dac[0],kHalfMax,dac[kNdata-1],kHalfMax);
     1343    TLine *ldac_half   = new TLine(dac_half[ch],0,dac_half[ch],
     1344                                   (Double_t)kDrawMax);
     1345    hist_scurve[ch].SetMaximum(kDrawMax);
     1346    hist_scurve[ch].GetXaxis()->SetRangeUser(kDrawDacMin,kDrawDacMax);
     1347    hist_scurve[ch].Draw();
     1348    lhalf_max->Draw("same"); 
     1349    ldac_half->Draw("same");
     1350    if(dac_half[ch]>0){
     1351      dac_half_sum += dac_half[ch]-dac_ped[ch]; //relative absolute value
     1352      trigger++;
     1353    }
     1354
     1355    /*** Differential plot from scurve fitting function  ***/
     1356    c5->cd(ch+1);
     1357    hist_diff_fit[ch].GetXaxis()->SetRangeUser(fit_min_scurve,fit_max_scurve-2*step_dac);
     1358    Double_t dac_sfit_max=hist_diff_fit[ch].GetBinCenter(hist_diff_fit[ch].GetMaximumBin());
     1359    //if(dac_sfit_max<=fit_min_scurve+4*step_dac){
     1360    if(dac_sfit_max<=fit_min_scurve+2*step_dac){
     1361      hist_diff_fit[ch].GetXaxis()->SetRangeUser(fit_min_scurve+kFitSadj,fit_max_scurve-2*step_dac);
     1362      dac_sfit[ch]  =  hist_diff_fit[ch].GetBinCenter(hist_diff_fit[ch].GetMaximumBin());
     1363      //if(dac_sfit[ch]<=fit_min_scurve+kFitSadj+4*step_dac)dac_sfit[ch]=-1;
     1364      if(dac_sfit[ch]<fit_min_scurve+kFitSadj+step_dac){
     1365        dac_sfit[ch]=-1;
     1366        //dac_sfit[ch]=dac_half[ch];
     1367        flag_fit[ch] = -1;
     1368        cerr << "flag_fit[" << ch << "] " << flag_fit[ch]  << endl;
     1369      }
     1370    }else {
     1371      dac_sfit[ch]  =  hist_diff_fit[ch].GetBinCenter(hist_diff_fit[ch].GetMaximumBin());
     1372    }
     1373
     1374    if(dac_sfit[ch]>fit_min_scurve+5){
     1375      dac_sfit_sum += dac_sfit[ch]-dac_ped[ch];
     1376      trigger_sfit++;
     1377    }else{
     1378      //dac_sfit[ch] = fit_min_scurve+10;
     1379      dac_sfit[ch] = -1;
     1380    }
     1381    //cerr << "dac_sfit[" << ch << "] " << dac_sfit[ch] << endl;
     1382    TLine *ldac_sfit      = new TLine(dac_sfit[ch],0,dac_sfit[ch],kDrawMaxFit);
     1383    TLine *ldac_sfit_copy = new TLine(dac_sfit[ch],0,dac_sfit[ch],kDrawMax);
     1384    ldac_sfit->SetLineColor(kMagenta);
     1385    ldac_sfit_copy->SetLineColor(kMagenta);
     1386    hist_diff_fit[ch].SetMaximum(kDrawMaxFit);
     1387    hist_diff_fit[ch].SetMinimum(0);
     1388    hist_diff_fit[ch].Draw();
     1389    ldac_sfit->Draw("same");
     1390   
     1391    /**** differential plot ****/
     1392    c2->cd(ch+1);
     1393    //hist_diff[ch].Rebin(8);
     1394    hist_diff[ch].Rebin(3);
     1395    fit_sdiff     = new TF1("fit_sdiff","gaus",dac_min,dac_max);
     1396    //fit_sdiff->SetLineWidth(1);
     1397    //if(ch==8 || ch==18 || ch==44 || ch==56)
     1398    mean_sum += mean_diff[ch]-dac_ped[ch];
     1399    trigger_mean++;
     1400
     1401    // fit the derivated polynom fit
     1402    Double_t fit_par[3];
     1403    //hist_diff[ch].Fit(fit_sdiff,"RQ0","",fit_min,fit_max);
     1404    hist_diff[ch].Fit(fit_sdiff,"","",fit_min,fit_max);
     1405    hist_diff[ch].GetXaxis()->SetRangeUser(kDrawDacMin,kDrawDacMax);
     1406    hist_diff[ch].SetMinimum(0);
     1407    hist_diff[ch].SetMaximum(kDrawMaxDiff);
     1408    //hist_diff[ch].Rebin();
     1409    hist_diff[ch].Draw();
     1410    fit_sdiff->GetParameters(fit_par); // get the parameters for this fit
     1411    dac_spe[ch] = fit_par[1];
     1412    if(dac_spe[ch]>fit_min){
     1413      dac_spe_sum += dac_spe[ch]-dac_ped[ch];
     1414      //cerr << "dac_spe[" << ch << "] " << dac_spe[ch] << endl;
     1415      trigger_fit++;
     1416    }else{
     1417      dac_spe[ch] = fit_min+10;
     1418    }
     1419    //cerr << "dac_spe[" << ch << "] " << dac_spe[ch] << endl;
     1420    TLine *ldac_spe    = new TLine(dac_spe[ch],0,dac_spe[ch],
     1421                                 (Double_t)kDrawMaxDiff);
     1422    ldac_spe->SetLineColor(kRed);
     1423    TLine *lmean_diff  = new TLine(mean_diff[ch],0,mean_diff[ch],
     1424                                   (Double_t)kDrawMaxDiff);
     1425    lmean_diff->SetLineColor(kCyan);
     1426    TLine *lfit_min    = new TLine(fit_min,0,fit_min,kDrawMaxDiff);
     1427    lfit_min->SetLineColor(kGray);
     1428
     1429    ldac_spe->Draw();
     1430    lmean_diff->Draw("same");
     1431    lfit_min->Draw("same");
     1432   
     1433    c3->cd(1);
     1434    if(ch==0){
     1435      hist_scurve[ch].SetMaximum(kDrawMax);
     1436      hist_scurve[ch].Draw();
     1437    }else{
     1438    /*if(ch==8 || ch==18 || ch==44 || ch==56)*/
     1439      hist_scurve[ch].Draw("same");
     1440    }
     1441    if(ch==kDrawCh){
     1442      c3->cd(2);
     1443      hist_scurve[ch].SetMaximum(kDrawMax);
     1444      hist_scurve[kDrawCh].Draw();
     1445      lhalf_max->Draw("same"); 
     1446      ldac_half->Draw("same");
     1447      ldac_sfit_copy->Draw("same");
     1448      c3->cd(3);
     1449      hist_diff[kDrawCh].Draw();     
     1450      ldac_spe->Draw();
     1451      lmean_diff->Draw("same");
     1452      lfit_min->Draw("same");
     1453      c3->cd(4);
     1454      hist_diff_fit[kDrawCh].Draw();
     1455       ldac_sfit->Draw("same");
     1456      }
     1457    /*
     1458    if(ch<32){
     1459      c6->cd(ch/4+1);
     1460      hist_scurve[ch].SetMaximum(kDrawMax);
     1461      if(ch%4==0){
     1462        hist_scurve[ch].Draw();
     1463      }else{
     1464        hist_scurve[ch].Draw("same");
     1465      }
     1466      ldac_sfit_copy->Draw("same");
     1467    }else{
     1468      c7->cd(ch/4-7);
     1469      hist_scurve[ch].SetMaximum(kDrawMax);
     1470      if(ch%4==0){
     1471        hist_scurve[ch].Draw();
     1472      }else{
     1473        hist_scurve[ch].Draw("same");
     1474      }
     1475      ldac_sfit_copy->Draw("same");
     1476      }
     1477    */
     1478   
     1479    c4->cd();
     1480    if(ch==0){
     1481      hist_scurve_ped[ch].SetMaximum(kDrawMaxPed);
     1482      hist_scurve_ped[ch].Draw("l");
     1483    }else{
     1484      hist_scurve_ped[ch].Draw("lsame");
     1485    }
     1486
     1487
     1488if(DEBUG)
     1489{
     1490    cout << " >>>>>>> END Analysis::ProcessSingleChannel " << endl;     
     1491}
     1492   
     1493  }// end of process single  channels
     1494//---------------------------------------------------------------------------------------------------
     1495
     1496
     1497//---------------------------------------------------------------------------------------------------
     1498// Compute some averages
     1499//---------------------------------------------------------------------------------------------------
     1500void Analysis::ComputeDACAverage(Double_t dac_half_spe_fix ,Int_t    kChRef, Bool_t   checkAve )//0:use ref pix, 1:check average
     1501{
     1502
     1503
     1504if(DEBUG)
     1505{
     1506  cout << " >>>>>>> START Analysis::ComputeDACAverage " << endl;
     1507 
     1508    cout << " \t - dac_half_spe_fix = " << dac_half_spe_fix << endl;
     1509    cout << " \t - kChRef = " << kChRef << " ASIC_C " << endl;
     1510    cout << " \t - checkAve = " << checkAve << " 0:use ref pix, 1:check average " << endl;     
     1511}
     1512
     1513 // SDC 24/09/2013 :: In a compiled program, I have to declare the following variables outside the parenthesis
     1514
     1515 
     1516  mean_diff_ave = 252.5; //dac_sfit of ch31 of ASIC_C with the 180 for lower gain pixels
     1517 
     1518  if(!checkAve){
     1519    dac_ped_ave   = dac_ped[kChRef]; //absolute value
     1520    dac_half_ave  = dac_half[kChRef];
     1521    dac_spe_ave   = dac_spe[kChRef];
     1522    dac_sfit_ave  = dac_sfit[kChRef];
     1523    //Float_t dac_sfit_ave  = 252.5; //dac_sfit of ch31 of ASIC_C with the 180 for lower gain pixels
     1524    mean_diff_ave = mean_diff[kChRef];
     1525  }else{
     1526    dac_ped_ave  = dac_ped_sum/(Float_t)kNch; //absolute value
     1527    dac_half_ave = dac_half_sum/(Float_t)trigger+dac_ped_ave;
     1528    dac_spe_ave  = dac_spe_sum/(Float_t)trigger_fit+dac_ped_ave;
     1529    mean_diff_ave = mean_sum/(Float_t)trigger_mean+dac_ped_ave;
     1530    dac_sfit_ave = dac_sfit_sum/(Float_t)trigger_sfit+dac_ped_ave;
     1531  }
     1532
     1533
     1534// SDC 24/09/2013 :: In a compiled program, I have to declare the following variables outside the parenthesis
     1535
     1536
     1537  //trigger_mean=4;
     1538  if(dac_half_spe_fix!=-1) {
     1539    dac_half_spe = dac_half_spe_fix;
     1540  } else {
     1541    //Double_t dac_half_spe = dac_half_ave;
     1542    dac_half_spe = dac_spe_ave;
     1543  }
     1544
     1545  TLine *ldac_ped_ave   = new TLine(dac_ped_ave,0,dac_ped_ave,
     1546                                   (Double_t)kDrawMax);
     1547  TLine *ldac_ped_ave_copy = new TLine(dac_ped_ave,0,dac_ped_ave,
     1548                                   (Double_t)kDrawMaxDiff);
     1549  TLine *ldac_half_ave  = new TLine(dac_half_ave,0,dac_half_ave,
     1550                                   (Double_t)kDrawMax);
     1551  TLine *ldac_half_spe  = new TLine(dac_half_spe,0,dac_half_spe,
     1552                                   (Double_t)kDrawMax);
     1553  TLine *lmean_diff_ave = new TLine(mean_diff_ave,0,mean_diff_ave,
     1554                                   (Double_t)kDrawMax);
     1555  TLine *ldac_sfit_ave  = new TLine(dac_sfit_ave,0,dac_sfit_ave,
     1556                                   (Double_t)kDrawMax);
     1557  ldac_ped_ave->SetLineColor(kOrange);
     1558  ldac_half_ave->SetLineColor(kRed);
     1559  lmean_diff_ave->SetLineColor(kCyan);
     1560  //ldac_half_spe->SetLineColor(kGreen);
     1561  ldac_sfit_ave->SetLineColor(kMagenta); 
     1562
     1563  c3->cd(1);
     1564  ldac_ped_ave->Draw("same");
     1565  ldac_half_ave->Draw("same");
     1566  // lhalf_max->Draw("same");  SDC (24/09/2013) :: Not declared
     1567  ldac_half_spe->Draw("same");
     1568  lmean_diff_ave->Draw("same");
     1569  ldac_sfit_ave->Draw("same");
     1570
     1571  c3->cd(3);
     1572  ldac_ped_ave_copy->SetLineColor(kOrange);
     1573  ldac_ped_ave_copy->Draw("same");
     1574
     1575if(DEBUG)
     1576{
     1577  cout << " >>>>>>> END Analysis::ComputeDACAverage " << endl; 
     1578}
     1579 
     1580
     1581}
     1582
     1583//---------------------------------------------------------------------------------------------------
     1584
     1585//---------------------------------------------------------------------------------------------------
     1586void Analysis::OutputGain(const TString fname_out)
     1587{
     1588
     1589if(DEBUG)
     1590{
     1591  cout << " >>>>>>> START Analysis::OutputGain " << endl;
     1592  cout << " \t - fname_out = " << fname_out << endl;   
     1593}
     1594
     1595 ofstream out(fname_out.Data());
     1596
     1597 Int_t    gain_asic_diff, gain_asic_dacHalf, gain_asic_diff_mean, gain_asic_sfit;
     1598  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"
     1599       << endl;
     1600
     1601
     1602  // loop 3 on all channels to make final computations on the gain
     1603  for(ch=0;ch<kNch;ch++){
     1604    /*
     1605    if(ch==8 || ch==44 || ch==56 || ch==18){
     1606      gain_asic_diff_mean=(Int_t)((mean_diff_ave-dac_ped_ave)/
     1607                                  (mean_diff[ch]-dac_ped[ch])*gain_org[ch]);
     1608    }else{
     1609      gain_asic_diff_mean=0;
     1610    }
     1611    */
     1612    if(dac_half[ch]<0){
     1613      gain_asic_dacHalf   = 0;
     1614      gain_asic_diff      = 0;
     1615      gain_asic_diff_mean = 0;
     1616      gain_asic_sfit      = 0;
     1617    }else{
     1618      gain_asic_dacHalf  =(Int_t)((dac_half_ave-dac_ped_ave)/
     1619                                (dac_half[ch]-dac_ped[ch])*gain_org[ch]);
     1620      gain_asic_diff     =(Int_t)((dac_half_spe-dac_ped_ave)/
     1621                             (dac_spe[ch]-dac_ped[ch])*gain_org[ch]);
     1622      gain_asic_diff_mean=(Int_t)((mean_diff_ave-dac_ped_ave)/
     1623                                  (mean_diff[ch]-dac_ped[ch])*gain_org[ch]);
     1624      gain_asic_sfit     =(Int_t)((dac_sfit_ave-dac_ped_ave)/
     1625                             (dac_sfit[ch]-dac_ped[ch])*gain_org[ch]);
     1626      //cerr << ch << " " << gain_org[ch] << endl;
     1627    }
     1628
     1629   
     1630
     1631    out << "OUT_TABLE    "
     1632         << ch << "    "
     1633         << gain_asic_dacHalf   << "    "
     1634         << gain_asic_diff      << "    "
     1635         << gain_asic_diff_mean << "    "
     1636         << gain_asic_sfit      << "    "
     1637         << dac_half[ch]        << "    "
     1638         << dac_ped[ch]         << "    "
     1639         << (Int_t)dac_spe[ch]  << "    "
     1640         << dac_half_ave        << "    "
     1641         << dac_half_spe        << "    "
     1642         << dac_ped_ave         << "    "
     1643         << dac_sfit_ave        << "    "
     1644         << sfit_chiS[ch]       << "    "
     1645         << ch                  << "    "
     1646         << flag_fit[ch]       
     1647         << endl;
     1648      std::cout << "channel " << ch << " old gain " << gain_org[ch] << " new gain " << gain_asic_sfit << std::endl;
     1649  }
     1650  out.close();
     1651
     1652if(DEBUG)
     1653{
     1654  cout << " >>>>>>> END Analysis::OutputGain " << endl;
     1655}
     1656
     1657
     1658}
     1659//--------------------------------------------------------------------------------------------------------
     1660
     1661
     1662
     1663
     1664
     1665
     1666
     1667//--------------------------------------------------------------------------------------------------------
     1668//--------------------------------------------------------------------------------------------------------
     1669void Analysis::Help()
     1670{
     1671
     1672  cout << "This is the Help of the PlotScurveAll-diffFit" <<endl;
     1673  cout << " Version 2.0 from September 27 2013 " <<endl;
     1674  cout << " Main author Hiroko Miyamoto " << endl;
     1675  cout << " Adapted for modularity and compilable program by Sylvie Dagoret " << endl;
     1676  cout << " ==> Please from shell execute directly the compiled program :  " <<endl;
     1677  cout << " ==> ../../src/PlotScurvesAllMain  " << endl;
     1678   
     1679}
     1680//--------------------------------------------------------------------------------------------------------
     1681
     1682//--------------------------------------------------------------------------------------------------------
     1683//--------------------------------------------------------------------------------------------------------
     1684void Analysis::Menu()
     1685{
     1686 cout << "This is the Detailed menu information for running the PlotScurveAll-diffFit" <<endl;
     1687
     1688 cout << " void PlotScurve( " << endl;
     1689 cout << " \t " <<  " Int_t    kDrawCh=31, " << endl;
     1690 cout << " \t " <<  " TString  fname=kFname, " << endl;
     1691 cout << " \t " <<  " TString  fname_ped=kFnamePed, //ASIC_D ped_file " << endl;
     1692 cout << " \t " <<  " Double_t dac_half_spe_fix = -1," << endl;
     1693 cout << " \t " <<  " TString  fname_gain=\"gain-org.txt\"," << endl;
     1694 cout << " \t " <<  " Int_t    fit_min=kFitMin," << endl;
     1695 cout << " \t " <<  " Int_t    fit_max=kFitMax," << endl;
     1696 cout << " \t " <<  " Int_t    fit_min_scurve=kFitMinS," << endl;
     1697 cout << " \t " <<  " Int_t    fit_max_scurve=kFitMaxS," << endl;
     1698 cout << " \t " <<  " Bool_t   kBoard=1, //0:ASIC_C, 1:ASIC_D " << endl;
     1699 cout << " \t " <<  " Int_t    kChRef=kRefCh,//ASIC_C " << endl;
     1700 cout << " \t " <<  " Bool_t   checkAve=0 //0:use ref pix, 1:check average " << endl;
     1701 cout << " ) " << endl;         
     1702 cout << "Set the parameters on the top of the program depending on your analysis:  " << endl;
     1703 cout << "General policy: parameters starting with a \"k\" at the beginning is fixed gloval parameter and usually set in the header file, never change through the program. " << endl;
     1704 cout << " : " << endl;
     1705 cout << " - kDrawCh: channel just you want to check on display. doens't effect the analysis. " << endl;
     1706 
     1707 cout << " - fname, fname_ped (kFname, kFnamePed): \"YOUR DATA FILE\" without .data"  << endl;
     1708 cout << " See examples in the header file. " << endl;
     1709 cout << " - dac_half_spe_fix: set DAC value only when you want to adjust the gain to particular pulse height (DAC value) instead of either average of the pulse height of reference pixel. Usually just leave it -1. " << endl;
     1710 cout << " - fit_min, fit_max (kFitMin, kFitMax): leave them as default, it is not currently used for the analysis."  << endl;
     1711 cout << " - fit_min_scurve, fit_max_scurve (kFitMinS, kFitMaxS): define the range of s-curve fitting. search proper values by yourself with running root program a few times."  << endl;
     1712 cout << " - kBoard: don't forget to change 0(C) or 1(D) depending on which ASIC you're analysing "  << endl;
     1713 cout << " - kChRef (kRefCh): a pixel whose gain remains 64 thorough the gain adjustment. " << endl;
     1714 cout << " - checkAve: for the first run, set this parameter 1, and find a pixel which remains 64. In the case of parameter 1, all the gains are adjusted to the average pulse height. " << endl;
     1715   cout <<  " Once you choose the reference pixel, set the parameter 0, as well as set kRefCh the pixel number. (better to keep in the header file for the record of each PMTs.) " << endl;
     1716
     1717   cout << " Actual configuration " << endl;
     1718   cout << " \t " <<  "TString kFname = " << kFname << endl;
     1719   cout << " \t " <<  "TString  kFnamePed = " << kFnamePed  << endl;
     1720   cout << " \t " <<  "Int_t kFitMin = " << kFitMin << endl;
     1721   cout << " \t " <<  "Int_t kFitMax = " << kFitMax << endl;
     1722
     1723}
     1724
     1725//-------------------------------------------------------------------------------------------------
     1726// Configure (x)emacs for this file ...
     1727// Local Variables:
     1728// mode: c++
     1729// compile-command: "(make;) "
     1730// End:
  • equalization_gain/branches/analclass-Sylvie/src/PlotScurvesAll-diffFit.h

    r196 r204  
    4747  // Main analysis function to be called from outside
    4848
     49  void Menu();
     50  void Help();
     51  void PlotScurve(
     52                Int_t    kDrawCh=31,
     53                TString  fname=kFname,
     54                TString  fname_ped=kFnamePed, //ASIC_D ped_file
     55                Double_t dac_half_spe_fix = -1,
     56                TString  fname_gain="gain-org.txt",
     57                Int_t    fit_min=kFitMin,
     58                Int_t    fit_max=kFitMax,
     59                Int_t    fit_min_scurve=kFitMinS,
     60                Int_t    fit_max_scurve=kFitMaxS,
     61                Bool_t   kBoard=0, //0:ASIC_C, 1:ASIC_D
     62                Int_t    kChRef=kRefCh,//ASIC_C
     63                Bool_t   checkAve=0 //0:use ref pix, 1:check average
     64                );
     65/*
    4966void PlotScurve(
    5067                Int_t    kDrawCh,
     
    6279                );
    6380
    64 
     81*/
    6582
    6683
     
    7188 void FillHistoName();
    7289 void ReadGainFile(const TString,Bool_t);
     90 void ProcessSingleChannel(
     91                Int_t    kDrawCh,
     92                TString  fname,
     93                TString  fname_ped, //ASIC_D ped_file
     94                Double_t dac_half_spe_fix,
     95                TString  fname_gain,
     96                Int_t    fit_min,
     97                Int_t    fit_max,
     98                Int_t    fit_min_scurve,
     99                Int_t    fit_max_scurve,
     100                Bool_t   kBoard, //0:ASIC_C, 1:ASIC_D
     101                Int_t    kChRef//ASIC_C
     102         );
     103 void ComputeDACAverage(Double_t dac_half_spe_fix ,Int_t    kChRef,Bool_t checkAve); //0:use ref pix, 1:check average)
     104 void OutputGain(const TString fname_out);
    73105
    74106// common variables to the analysis
    75107     TString *input;
    76108     TString *input_ped;
    77      Int_t    ch;
     109     Int_t    ch; // index on current channel under analysis
    78110     Float_t  dac_half_sum; 
    79111     Float_t  dac_ped_sum;   
     
    90122     Double_t dac_sfit[kNch];
    91123     Double_t mean_diff[kNch];
    92      Double_t gain_org[kNch];
     124     Double_t gain_org[kNch]; // array containing the initial gain values
    93125     Double_t sfit_chiS[kNch];
    94126     Double_t flag_fit[kNch];
     
    115147     TF1     *fit_sdiff;  // function fitted on differentiated histograms of fitted s-curves
    116148
    117 
     149     Int_t trigger;
     150     Int_t trigger_fit;
     151     Int_t trigger_mean;
     152     Int_t trigger_sfit;
    118153     
     154     Float_t dac_ped_ave  ; //absolute value
     155     Float_t dac_half_ave  ;
     156     Float_t dac_spe_ave   ;
     157     Float_t dac_sfit_ave;
     158     Float_t mean_diff_ave ;//dac_sfit of ch31 of ASIC_C with the 180 for lower gain pixels
     159 
     160     Double_t dac_half_spe;
    119161
    120162};
     
    122164#endif
    123165
     166//-------------------------------------------------------------------------------------------------
     167// Configure (x)emacs for this file ...
     168// Local Variables:
     169// mode: c++
     170// compile-command: "(make;) "
     171// End:
  • equalization_gain/branches/analclass-Sylvie/src/PlotScurvesAll-diffFitConst.h

    r196 r204  
    3535*/
    3636
     37
     38const int DEBUG=1;
    3739
    3840/*** signal file ***/
     
    7375
    7476// Output file
    75 const TString kFnameOut="output.dat";
     77const TString kFnameOut="gain-output.dat";
    7678
    7779//Int_t kFitMin = 160; //T1 ASIC_D it0, default
     
    140142
    141143#endif
     144//-------------------------------------------------------------------------------------------------
     145// Configure (x)emacs for this file ...
     146// Local Variables:
     147// mode: c++
     148// compile-command: "(make;) "
     149// End:
  • equalization_gain/branches/analclass-Sylvie/src/PlotScurvesAllMain.cc

    r196 r204  
    2020   TRint *theApp=new TRint("ROOT-PlotScurvesAll",&argc,argv);
    2121   
    22    Help();
    2322   
    24    PlotScurve();
     23   // SDC (27/09/2013) :: Old fashion of calling the function directly
     24   //PlotScurve();
    2525
    26    //Analysis* pa = new Analysis;
    27    //pa->Print();
     26   // SDC (27/09/2013) :: class analysis working now
     27   Analysis* ana = new Analysis;
     28
     29   ana->Help();
     30   ana->Menu();
     31   ana->PlotScurve();
    2832
    2933    theApp->Run();
    3034}
     35
     36//-------------------------------------------------------------------------------------------------
     37// Configure (x)emacs for this file ...
     38// Local Variables:
     39// mode: c++
     40// compile-command: "(make;) "
     41// End:
Note: See TracChangeset for help on using the changeset viewer.