/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/analyse/Renaud/analyze_noise.cpp

Go to the documentation of this file.
00001 
00002 
00003 // compile with:
00004 // gcc `root-config --cflags` `root-config --glibs` analyze_noise.cpp -o analyze_noise
00005 /////////////////////////////////////////////////////////////////////////
00006 // The first file contian noise from pedestal on the square meter
00007 // The second contains threshold for each chip
00008 
00009 #include <map>
00010 #include "TKey.h"
00011 #include <TROOT.h>
00012 #include <TStyle.h>
00013 #include <TRint.h>
00014 #include <TKey.h>
00015 #include <TTree.h>
00016 #include <TCanvas.h>
00017 #include "TH1.h"
00018 #include "TF1.h"
00019 #include <TH1I.h>
00020 #include <TH2I.h>
00021 #include <TFile.h>
00022 #include <stdlib.h>
00023 #include <TSystem.h>
00024 #include <iostream>
00025 #include "TApplication.h"
00026 #include <sstream>
00027 //#include "Log.hh"
00028 #include <Rtypes.h>
00029 #include <TCanvas.h>
00030 #include "TColor.h"
00031 #include "TFunction.h"
00032 #include "TAttLine.h"
00033 #include "TPaveStats.h"
00034 //#include "MicroException.hh"
00035 #include <string>
00036 #include "Riostream.h"
00037 
00038 using namespace std;
00039 
00040 
00041 int main(int argc, char**argv)
00042 //analyze_prod(const Int_t prod)
00043 {       
00044         gROOT->Reset();
00045 
00046 //      gROOT->SetStyle("Plain");
00047         gStyle->SetFrameFillStyle(0);
00048         gStyle->SetPalette(1);
00049         gStyle->SetOptStat(111111);
00050         gStyle->SetFrameFillStyle(0);
00051         gStyle->SetOptStat("");
00052         gStyle->SetOptFit(0111);
00053         gStyle->SetStatX(0.9);
00054         gStyle->SetStatY(0.9);
00055         gStyle->SetStatH(0.1);
00056         gStyle->SetStatW(0.1);
00057 
00058 //      gStyle->SetOptStat("") ;
00059 //      gStyle->SetOptFit(0000);        
00060         
00061         gStyle->SetOptStat("");
00062         gStyle->SetOptFit(10001);
00063         
00064         if (argc !=4)
00065         {
00066                 cout << "usage: " << argv[0] << " file_scurve_noise file_offset_correction file_threshold " << endl ;
00067                 exit(-1) ;
00068         }
00069 
00070         TString noise_filename_arg = argv[1] ;
00071         TString offset_filename_arg = argv[2] ;
00072         TString threshold_filename_arg = argv[3] ;
00073         
00074         const TString directory = "/gpfs/LAPP-DATA/LC/Detecteurs/MicroMegas/data/MICROROC/MR1/TEST_NOISE/";
00075         const TString noise_filename = directory + noise_filename_arg ;//Form("%s%s", directory, noise_filename_arg) ;
00076         const TString offset_filename = directory + offset_filename_arg ;
00077         const TString threshold_filename = directory + threshold_filename_arg ;//Form("%s%s", directory, threshold_filename_arg) ;
00078 
00079         cout << directory << endl ;
00080         
00081         const Int_t NbOfChip = 48 ;
00082         const Int_t NbOfChannels = 64 ;
00083         const Double_t thr_conv_ratio = 0.14 ; // fC / thrDAC
00084         const Double_t off_conv_ratio = 1.66 ; // thrDAC / off  /// = 0.602 offDAC / thrDAC
00085         TApplication theApp("App", &argc, argv);                                        // see $ROOTSYS/test/hworld.cxx
00086         //TApplication *theApp  = NULL;                         // from Jean
00087         //theApp  = new TRint("App",NULL,NULL );        // from Jean
00088         
00089 //      for (Int_t chip=start;chip<=stop;chip++)
00090 //      {       
00091 //              const TString name_file_gain = directory +  Form("chip_%d_gain_OK.txt", chip) ;
00092 //              const TString name_file_gain = Form("%schip_%d_gain_OK.txt", directory, chip) ;
00093 //              cout << name_file_gain << endl ;
00094 //      }
00095         ////////////////////////////////////////////////////////////////////////////////////////
00096         //          REMAINDER
00097         ////////////////////////////////////////////////////////////////////////////////////////
00098         // CONV ration : 0.14 fC / thrDACunit
00099         // DAC ratio : 1.92 THRDAC / OFFSET DAC
00100         ////////////////////////////////////////////////////////////////////////////////////////
00101         //          READ FIRST and SECOND FILE (pedestal)
00102         ////////////////////////////////////////////////////////////////////////////////////////
00103 
00104         ifstream file_noise, file_offset ;
00105         // data
00106         file_noise.open(noise_filename.Data()) ;
00107         if (!file_noise.good())
00108         {       cout << "Error opening" << noise_filename.Data() << endl ;
00109         }
00110         // offset
00111         file_offset.open(offset_filename.Data()) ;
00112         if (!file_offset.good())
00113         {       cout << "Error opening" << offset_filename.Data() << endl ;
00114         }
00115         // vars to read file
00116         Double_t chip, channel, crapoffset, pedestal_inflex, pedestal_inflex_err, pedestal_noise, pedestal_noise_err, offset ; // to read text file     
00117         Double_t noise_data_corr[NbOfChip][NbOfChannels]; // with offset corretion
00118         Double_t noise_data[NbOfChip][NbOfChannels];
00119         for (Int_t ichip=0;ichip<NbOfChip;ichip++)
00120         {       for (Int_t ichan=0;ichan<NbOfChannels;ichan++)
00121                 {       if (!file_noise.good()) break;
00122                         if (!file_offset.good()) break;
00123                         file_noise >> chip >> channel >> crapoffset >> pedestal_inflex >> pedestal_inflex_err >> pedestal_noise >> pedestal_noise_err ;
00124                         file_offset >> chip >> channel >> offset ;
00125                         noise_data_corr[ichip][ichan] = pedestal_inflex - offset*off_conv_ratio ;
00126                         noise_data[ichip][ichan] = pedestal_inflex + offset*off_conv_ratio ;
00127                         //cout << pedestal_inflex << endl ;
00128                 }
00129         }
00130         file_noise.close() ;
00131         file_offset.close() ;
00132         
00133         ////////////////////////////////////////////////////////////////////////////////////////
00134         //          READ SECOND and third FILE
00135         ////////////////////////////////////////////////////////////////////////////////////////
00136         ifstream file_threshold ;
00137         file_threshold.open(threshold_filename.Data()) ;
00138         if (!file_threshold.good())
00139         {       cout << "Error opening" << threshold_filename.Data() << endl ;
00140         }
00141         Double_t threshold ;
00142         Double_t threshold_data[NbOfChip] ;
00143         for (Int_t ichip=0;ichip<NbOfChip;ichip++)
00144         {       if (!file_threshold.good()) break;
00145                 file_threshold >> chip >> threshold ;
00146                 threshold_data[ichip] = threshold ;
00147         }
00148         file_offset.close() ;
00149         
00150         ////////////////////////////////////////////////////////////////////////////////////////
00151         //          Threshold difference
00152         ////////////////////////////////////////////////////////////////////////////////////////
00153         
00154         TH1F * h_thr = new TH1F ("h_thr", "+0", 100, 0, 10) ;
00155         h_thr->SetXTitle("Threshold [fC]");
00156         h_thr->SetYTitle("count");
00157         
00158         TH1F * h_thr2 = new TH1F ("h_thr2", "+3", 100, 0, 10) ;
00159         h_thr2->SetXTitle("Threshold [fC]");
00160         h_thr2->SetYTitle("count");
00161         
00162         TH1F * h_thr3 = new TH1F ("h_thr3", "without offset compensation", 100, -5, 5) ;
00163         h_thr3->SetXTitle("Threshold [fC]");
00164         h_thr3->SetYTitle("count");
00165         
00166         for (Int_t ichip=0;ichip<NbOfChip;ichip++)
00167         {       for (Int_t ichan=0;ichan<NbOfChannels;ichan++)
00168                 {       h_thr->Fill((threshold_data[ichip] - noise_data_corr[ichip][ichan])*thr_conv_ratio) ;
00169                         h_thr2->Fill((threshold_data[ichip] - noise_data_corr[ichip][ichan]+3)*thr_conv_ratio) ;
00170                         h_thr3->Fill((threshold_data[ichip] - noise_data[ichip][ichan]+3)*thr_conv_ratio) ;
00171                 }
00172         }
00173         TCanvas * c1 = new TCanvas("c1","");
00174         h_thr->Draw() ;
00175         
00176         TCanvas * c2 = new TCanvas("c2","");
00177         c2->cd() ;
00178         h_thr2->Draw() ;
00179         
00180         TCanvas * c3 = new TCanvas("c3","");
00181         c3->cd() ;
00182         h_thr3->Draw() ;        
00183         
00184 //      ////////////////////////////////////////////////////////////////////////////////////////
00185 //      
00186 //      
00187 //      
00188 //      TCanvas * c1 = new TCanvas("c1","MICROROC gain");
00189 //      h_gain->SetLineColor(kBlue+1);
00190 //      h_gain->Draw("");
00191 //      h_gain->Fit("gaus","RQ", "SAME", 0.13 , 0.15);
00192 //      h_gain->GetFunction("gaus")->SetLineColor(kRed);
00193 //      h_gain->GetXaxis()->SetTitle("Conversion ratio [fCV/DACu]");
00194 //      h_gain->GetYaxis()->SetTitle("Count");
00195 //      
00196 //      
00197 //      ////////////////////////////////////////////////////////////////////////////////////////
00198 //      TCanvas * c2 = new TCanvas("c2","MICROROC data and pedestal");
00199 //      c2->cd() ;
00200 
00201 //      h_ped->Draw("");
00202 //      //h_ped->SetLineColor(kBlue+1);
00203 //      h_ped->Fit("gaus","RQ", "SAME", 160, 210);
00204 //      h_ped->GetFunction("gaus")->SetLineColor(kBlue+1);
00205 
00206 //      h_data->Draw("SAMES");
00207 //      //h_data->SetLineColor(kGreen+1);
00208 //      h_data->Fit("gaus","RQ", "SAME", 500, 580);
00209 //      h_data->GetFunction("gaus")->SetLineColor(kOrange+5);
00210 
00211 //      c2->Update(); // to create TGraph !!! COMPULSORY !!
00212 
00213 //      TPaveStats * p1 = (TPaveStats*) h_ped->GetListOfFunctions()->FindObject("stats");
00214 //      h_ped->GetListOfFunctions()->Print();
00215 ////    p1->Print();
00216 //      h_ped->GetListOfFunctions()->Remove(p1);
00217 //      h_ped->SetStats(0);
00218 //      p1->SetTextColor(kBlue+1);
00219 //      p1->SetX1NDC(0.75);
00220 //      p1->SetY1NDC(0.8);
00221 //      p1->SetY2NDC(0.9);
00222 //      p1->Draw();
00223 
00224 
00225 //      // NEED SAMES (!=SAME) in Drawin histo !!!!! http://root.cern.ch/root/html/THistPainter.html#THistPainter:Paint find sames in text
00226 //      //h_data->GetListOfFunctions()->Print();
00227 //      TPaveStats * p2 = (TPaveStats*) h_data->GetListOfFunctions()->FindObject("stats");
00228 //      p2->Print();
00229 //      h_data->GetListOfFunctions()->Remove(p2);
00230 //      h_data->SetStats(0);
00231 //      p2->SetTextColor(kOrange+5);
00232 //      p2->SetX1NDC(0.75);
00233 //      p2->SetX2NDC(0.9);
00234 //      p2->SetY1NDC(0.7);
00235 //      p2->SetY2NDC(0.8);
00236 //      p2->Draw();
00237 
00238 
00239 
00240         theApp.Run(kTRUE) ;
00241         //theApp->Run();
00242         //delete theApp;
00243         return 0 ;
00244 
00245 }

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