00001 {gROOT->Reset();
00002 gROOT->SetStyle("Video");
00003 gStyle->SetOptStat(0);
00004
00005
00006
00007 bool display = 1;
00008 bool write = 1;
00009 bool write_in_tfile = 0;
00010 bool plot = 1;
00011
00012 TString dac = "2";
00013
00014 TString dir = "/lapp_data/LC/Detecteurs/MicroMegas/data/MICROROC/MR1/Root_files/Calibration_Dans_M2/";
00015 TString file = "scurve_noise_offset7_dac0_asu1314";
00016 TString t_file = dir + file + ".root";
00017
00018 cout<<t_file<<endl;
00019
00020
00021
00022
00023 if (write_in_tfile){TFile * tf = new TFile(t_file,"UPDATE");}
00024 else{TFile * tf = new TFile(t_file);}
00025
00026
00027
00028 int threshold = 0;
00029 int chipid = 0;
00030 int hardid = 0;
00031 int value = 0;
00032 int content = 0;
00033
00034 int tmin = 0;
00035 int tmed = 0;
00036 int tmax = 0;
00037 int delta = 0;
00038
00039 TH1I * hscurve[64];
00040
00041 TH1F * hinflex = new TH1F("hinflex","",1000,0,500);
00042 TH1F * hsigma = new TH1F("hsigma","",50,-2,2);
00043
00044 TH1F * hinflex_err = new TH1F("hinflex","",100,0,10);
00045 TH1F * hsigma_err = new TH1F("hsigma","",100,0,2);
00046
00047 TH1F * hc_inflex = new TH1F("hc_inflex","",64,0,64);
00048 TH1F * hc_sigma = new TH1F("hc_sigma","",64,0,64);
00049
00050 TH1F * hc_inflex_err = new TH1F("hc_inflex_err","",64,0,64);
00051 TH1F * hc_sigma_err = new TH1F("hc_sigma_err","",64,0,64);
00052
00053 TH1F * hc_inflex_sigma = new TH1F("hc_inflex_sigma","",64,0,64);
00054
00055 TString name;
00056
00057 for (int j=0;j<64;j++){
00058
00059 name = Form("hscurve_%i",j);
00060 TH1I * h = (TH1I*)tf.Get(name);
00061 hscurve[j] = h;}
00062
00063
00064
00065
00066
00067
00068 TString func = "[0]/(1+exp((x-[1])/[2]))";
00069 TF1 * fermi[64];
00070 float scurve_max = 0;
00071 float scurve_inflex = 0;
00072 float inflex = 0;
00073 float sigma = 0;
00074 float inflex_err = 0;
00075 float sigma_err = 0;
00076 float content0,content1,content2;
00077 float chi2 = 0;
00078 float ndf = 0;
00079
00080
00081
00082 for (int j=0;j<64;j++){
00083
00084 name = Form("fermi_%i",j);
00085
00086 fermi[j] = new TF1(name,func,0,1024);
00087 fermi[j]->SetLineColor(j+1);
00088 fermi[j]->SetLineWidth(0.5);
00089
00090
00091 if (hscurve[j]->GetEntries()!=0){
00092
00093
00094 for (int b=0;b<1024;b++){
00095 content = hscurve[j]->GetBinContent(b+1);
00096 if (content != 0){tmin = b;b = 1024;scurve_max = content;}}
00097
00098
00099 for (int b=1024;b>tmin;b--){
00100 if (hscurve[j]->GetBinContent(b+1) != 0){tmax = b+1;b = tmin;}}
00101
00102
00103 for (int b=tmax;b>=0;b--){
00104 if (hscurve[j]->GetBinContent(b+1) == scurve_max){tmed = b+1;b = -1;}}
00105
00106 scurve_inflex = 0.5*(tmax+tmed);
00107 delta = tmax - tmed;
00108
00109
00110 if (delta==1){
00111
00112 inflex = scurve_inflex;
00113 sigma = 0.;
00114 inflex_err = 0.;
00115 sigma_err = 0.;}
00116
00117 else{
00118
00119
00120 fermi[j]->FixParameter(0,scurve_max);
00121 fermi[j]->SetParameter(1,scurve_inflex);
00122 fermi[j]->SetParameter(2,delta/10.);
00123
00124
00125 hscurve[j]->Fit(fermi[j],"q","",0,tmax+50);
00126
00127
00128 inflex = fermi[j]->GetParameter(1);
00129 sigma = sqrt(pow(fermi[j]->GetParameter(2),2));
00130
00131 inflex_err = sqrt(pow(fermi[j]->GetParError(1),2));
00132 sigma_err = sqrt(pow(fermi[j]->GetParError(2),2));
00133
00134 chi2 = fermi[j]->GetChisquare();
00135 ndf = fermi[j]->GetNDF();}
00136
00137
00138 hc_inflex_sigma->SetBinContent(j+1,inflex);
00139 hc_inflex_sigma->SetBinError(j+1,sigma);
00140
00141 hc_inflex->SetBinContent(j+1,inflex);
00142 hc_sigma->SetBinContent(j+1,sigma);
00143
00144 hc_inflex_err->SetBinContent(j+1,inflex_err);
00145 hc_sigma_err->SetBinContent(j+1,sigma_err);
00146
00147 hinflex->Fill(inflex);
00148 hsigma->Fill(sigma);
00149
00150 if (display){cout<<"Channel\t"<<j<<"\t"<<inflex<<"\t width\t"<<sigma<<"\r"<<flush;}}}
00151
00152
00153
00154
00155
00156 if (write){
00157
00158 TString outfile = dir + "parameters_" + file + ".dat";
00159 ofstream out(outfile.Data());
00160
00161 for (int j=0;j<64;j++){
00162
00163 out<<j<<" "<<hc_inflex->GetBinContent(j+1)<<" "<<hc_inflex_err->GetBinContent(j+1)<<" "<<hc_sigma->GetBinContent(j+1)<<" "<<hc_sigma_err->GetBinContent(j+1)<<endl;}}
00164
00165
00166
00167 if (plot){
00168
00169 TString adj;
00170 if (dac=="0"){adj = "bas";}
00171 if (dac=="1"){adj = "intermediaire";}
00172 if (dac=="2"){adj = "haut";}
00173
00174
00175
00176 if (0){
00177
00178 TCanvas * c0 = new TCanvas("c0","",10,10,500,500);
00179 TString title = "MICROROC pedestals - Seuil " + adj + ";threshold (DAC)";
00180
00181 TH2F * frame = new TH2F("frame",title,100,0,1024,100,0,600);
00182
00183 frame->GetXaxis()->SetRangeUser(140,200);
00184 frame->Draw();
00185
00186 for (int j=0;j<64;j++){fermi[j]->Draw("same");}}}
00187
00188
00189
00190 }
00191
00192