/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/analyse/TB2010/Testbeam_june_10/Gassiplex/Telescope/Pedestals_study.C

Go to the documentation of this file.
00001 {
00002   gROOT->Reset();
00003   gStyle->SetPalette(1);
00004   gSystem->Load("/home/chefdevi/micromegas_framework_03032011/trunk/libMicro.so");
00005 
00006 
00007   TString file = "p0624_1.root";
00008   TString filename = "/home/chefdevi/lapp_data/LC/Detecteurs/MicroMegas/data/TB2010/SPS_H4_june_2010/Root_files/pro/"+file;
00009 
00010 
00011 
00012 
00013 
00014 
00015   /*Variables*/
00016 
00017   float nEvent = 0;
00018   int nchannel = 0;
00019   int x_channel[4][96*4];
00020   int y_channel[4][96*4];
00021   float ped_mean[4][96*4];
00022   float ped_rms[4][96*4];
00023   float ped_mean_err[4][96*4];
00024   float ped_rms_err[4][96*4];
00025 
00026   TH1F * hped[4][96*4];
00027   TH1F * hc_ped[4];
00028   TH2F * hxy_noise[4];
00029   TH1F * hnoise[4];
00030   TH1F * hc_noise[4];
00031   TString title,name;
00032 
00033   for (int i=0;i<4;i++){
00034 
00035     title = Form("hnoise_%i",i+1);
00036     name = Form("Noise in chamber %i;noise (fC)",i+1);
00037     hnoise[i] = new TH1F(title,name,1000,0,10);
00038 
00039     title = Form("hc_noise_%i",i+1);
00040     name = Form("Noise per channel in chamber %i;channel;noise (fC)",i+1);
00041     hc_noise[i] = new TH1F(title,name,96*4,0,96*4);
00042 
00043     title = Form("hxy_noise_%i",i+1);
00044     name = Form("Noise per channel in chamber %i;y (cm);x (cm);noise (fC)",i+1);
00045     hxy_noise[i] = new TH2F(title,name,32,0,32,32,0,32);
00046 
00047     title = Form("hc_ped_%i",i+1);
00048     name = Form("Pedestal per channel in chamber %i;pedestal (ADC)",i+1);
00049     hc_ped[i] = new TH1F(title,name,96*4,0,96*4);
00050 
00051     for (int j=0;j<96*4;j++){
00052 
00053       ped_mean[i][j] = 0;
00054       ped_rms[i][j] = 0;
00055       ped_mean_err[i][j] = 0;
00056       ped_rms_err[i][j] = 0;
00057       x_channel[i][j] = 0;
00058       y_channel[i][j] = 0;
00059       title = Form("hped_%i_%i",i+1,j); 
00060       name = Form("Pedestal position distribution in chamber %i channel %i;pedetsal (ADC)",i+1,j); 
00061       hped[i][j] = new TH1F(title,name,1024,0,1024);}}
00062 
00063 
00064 
00065 
00066   /*Read pedestal file*/
00067 
00068   TFile *f = new TFile(filename);
00069   cout<<"reading File : "<<filename<<endl;
00070   TIter nextkey(f.GetListOfKeys());
00071   TKey *key;
00072 
00073   while (key = (TKey*)nextkey()) {
00074     
00075     TTree *tree = (TTree*)key->ReadObj();                
00076     MTRun* run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun");
00077 
00078     nEvent = tree.GetEntries();
00079     cout <<"nEvent="<<nEvent<<endl;
00080 
00081     MTEvent *evt = new MTEvent();
00082     TBranch *branch= tree->GetBranch("MTEvent");
00083     branch->SetAddress(&evt);
00084 
00085     for (int i=0;i<nEvent;i++){  
00086 
00087       tree.GetEntry(i);
00088       nchannel = evt->GetNchannel();
00089       if (i%100==0){cout<<i/(1.*nEvent)*100.<<" % \r"<<flush;}
00090 
00091       for (int j=0;j<nchannel;j++){
00092 
00093         MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00094         hped[channel->GetChamberId()-1][channel->GetHardId()]->Fill(channel->GetAnalogValue());
00095         hc_ped[channel->GetChamberId()-1]->SetBinContent(channel->GetHardId()+1,channel->GetAnalogValue());
00096 
00097         if (i==1){
00098           x_channel[channel->GetChamberId()-1][channel->GetHardId()] = channel->GetX();
00099           y_channel[channel->GetChamberId()-1][channel->GetHardId()] = channel->GetY();}}}}
00100 
00101 
00102 
00103 
00104 
00105   /*Read preamp gain file*/
00106 
00107   ifstream in("gassiplex_preamp_gains.dat");
00108   float gain[4][96*4];
00109   float g = 0;
00110 
00111   for (int i=0;i<4;i++){
00112     for (int j=0;j<96*4;j++){
00113       gain[i][j] = 0;}}
00114 
00115   while(in>>j>>g){
00116     if (j<96){gain[0][j] = g;}
00117     else{if (j>=96 && j<96*2){gain[1][j-96] = g;}
00118       else{if (j>=96*2 && j<96*3){gain[2][j-96*2] = g;}
00119         else{gain[3][j-96*3] = g;}}}}
00120 
00121 
00122 
00123 
00124 
00125   /*Calculate noise*/
00126 
00127   TF1 * fped = new TF1("fped","gaus",0,1024);
00128 
00129   for (int i=0;i<4;i++){
00130     for (int j=0;j<96*4;j++){
00131 
00132       if (hped[i][j]->GetEntries()!=0){
00133 
00134         fped->SetParameters(hped[i][j]->GetEntries(),hped[i][j]->GetMean(),hped[i][j]->GetRMS());
00135         hped[i][j]->Fit(fped,"q");
00136         ped_mean[i][j] = fped->GetParameter(1);
00137         ped_mean_err[i][j] = fped->GetParError(1);
00138         ped_rms[i][j] = fped->GetParameter(2);
00139         ped_rms_err[i][j] = fped->GetParError(2);
00140 
00141         if (gain[i][j]!=0){
00142           hnoise[i]->Fill(ped_rms[i][j]/gain[i][j]);
00143           hc_noise[i]->SetBinContent(j+1,ped_rms[i][j]/gain[i][j]);
00144           hxy_noise[i]->SetBinContent(y_channel[i][j]+1,x_channel[i][j]+1,ped_rms[i][j]/gain[i][j]);}
00145 
00146         cout<<i<<" "<<x_channel[i][j]<<" "<<y_channel[i][j]<<" "<<ped_mean[i][j]<<" "<<ped_rms[i][j]<<" \r "<<flush;}}}
00147 
00148   for (int i=0;i<4;i++){
00149 
00150     fped->SetParameters(hnoise[i]->GetEntries(),hnoise[i]->GetMean(),hnoise[i]->GetRMS());
00151     hnoise[i]->Fit(fped,"q");}
00152 
00153 
00154 
00155 
00156   /*Calculate and write threshold in ADC units*/
00157 
00158   TString thr_file;
00159   float thr_adc = 0;
00160   float thr_fc = 0;
00161 
00162   int Nthr0 = 0;
00163   int Nthr = 50;
00164   TH1F * hthr[4][Nthr];
00165   TH1F * hc_thr[4][Nthr];
00166 
00167   for (i=0;i<4;i++){file.Chop();}
00168 
00169   TString ped_file = file+"dat";
00170   ofstream out_ped(ped_file.Data());
00171 
00172   for (int i=0;i<4;i++){
00173     for (int j=0;j<96*4;j++){
00174         if (gain[i][j]!=0){
00175           out_ped<<j<<" "<<x_channel[i][j]<<" "<<y_channel[i][j]<<" "<<i+1<<" "<<ped_mean[i][j]<<" "<<ped_mean_err[i][j]<<" "<<ped_rms[i][j]<<" "<<ped_rms_err[i][j]<<" "<<gain[i][j]<<endl;}}}
00176 
00177 
00178 
00179   /*Plots*/
00180 
00181   if (0){
00182 
00183     gROOT->SetStyle("Video");
00184     gStyle->SetOptStat(0);
00185 
00186     TCanvas * c0 = new TCanvas("c0","",10,10,500,500);
00187 
00188     for (i=0;i<4;i++){
00189       title = Form("chb. %i",i+1);
00190       hc_noise[i]->SetTitle(title);
00191       hc_noise[i]->SetLineWidth(3);
00192       hc_noise[i]->GetYaxis()->SetRangeUser(0,1.2);
00193       if (i<3){hc_noise[i]->GetXaxis()->SetRangeUser(0,96);}
00194 
00195 
00196       hc_noise[i]->Draw();
00197       title_eps = Form("Plots/noise_chb_%i.eps",i+1);
00198       title_png = Form("Plots/noise_chb_%i.png",i+1);
00199       c0->Print(title_eps);
00200       c0->Print(title_png);}
00201 
00202 
00203 
00204   }
00205 
00206 
00207 
00208 
00209 }

Generated on Mon Jan 7 13:15:22 2013 for MicromegasFramework by  doxygen 1.4.7