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

Go to the documentation of this file.
00001 /* @version $Revision: 1598 $ * @modifiedby $Author: gaglione $ * @lastmodified $Date: 2012-03-22 17:31:45 +0100 (Thu, 22 Mar 2012) $ */
00002 #include <map>
00003 #include "TKey.h"
00004 #include <TROOT.h>
00005 #include <TRint.h>
00006 #include <TKey.h>
00007 #include <TTree.h>
00008 #include <TFile.h>
00009 #include <TSystem.h>
00010 #include <iostream>
00011 #include <TF1.h>
00012 #include <TH2.h>
00013 #include <TGraph.h>
00014 #include <sstream>
00015 #include "Log.hh"
00016 #include <fstream>
00017 #include "TCanvas.h"
00018 #include "TApplication.h"
00019 #include "TColor.h"
00020 #include "TStyle.h"
00021 #include "TAxis.h"
00022 #include "TString.h"
00023 #include "TLegend.h"
00024 
00025 #include "MicroException.hh"
00026 
00027 
00028 #include "root/MTRun.hh"
00029 #include "root/MTEvent.hh"
00030 #include "root/MTChannel.hh"
00031 #include "root/MTMicrorocChip.hh"
00032 
00033 #define DISPLAY
00034 
00035 #undef DEBUG
00036 #define PLOT
00037 #define WRITE
00038 
00039 using namespace std;
00040 void usage(char *progname) ;
00041 void set_style_myplain() ;
00042 TStyle *style_myplain=new TStyle("myplain","classic style");
00043 ////////////////////////////////////////////////////////////////////////////////////////////
00044 
00045 int main(int argc, char**argv){
00046 
00047   /*****************************************************************/
00048   /* ARGUMENTS TO THE PROGRAM **************************************/
00049   /* 1 - DIRECTORY OF THE ROOT FILE PRODUCED BY THE RECONSTRUCTION */
00050   /* 2 - NAME OF THE ROOT FILE *************************************/
00051   /* 3 - THRESHOLD THAT IS MOVED DURING THE CALIBRATION ************/
00052   /*    0 -> DAC_0 (LOW THRESHOLD) *********************************/
00053   /*    1 -> DAC_1 (MEDIUM THRESHOLD) ******************************/
00054   /*    2 -> DAC_2 (HIGH THRESHOLD) ********************************/
00055   /*****************************************************************/
00056         if(argc != 4)
00057         {       usage(argv[0]) ;
00058                 return 1 ;
00059         }
00060         string root_directory = argv[1];
00061         string pedestal_arg = argv[2];
00062         string data_arg = argv[3];
00063         
00064         stringstream bad_channels ;
00065 
00066         string pedestal_filename = root_directory + pedestal_arg ;
00067         string data_filename = root_directory + data_arg;
00068         
00069         set_style_myplain() ;
00070         
00071         Int_t crap ; // buffer to read data
00072         string bufferpedestal ;         // buffer to read data
00073         Float_t pedestal[64] ;
00074         string bufferdata ;             // buffer to read data
00075         Float_t data[64] ;
00076         Float_t gain[64] ;
00077         Float_t inputcharge = 50E-15 ;  
00078         
00079         ifstream dataFilePedestal ;
00080         dataFilePedestal.open(pedestal_filename.c_str(),ifstream::in) ;
00081         if (dataFilePedestal.is_open()==false)
00082         {       cerr << "Could not open data file : " << pedestal_filename << endl ;
00083                 exit(1) ;
00084         }
00085         ifstream dataFileData ;
00086         dataFileData.open(data_filename.c_str(),ifstream::in) ;
00087         if (dataFileData.is_open()==false)
00088         {       cerr << "Could not open data file : " << data_filename << endl ;
00089                 exit(1) ;
00090         }
00091         
00092         int ok=0 ;      // var for good chip
00093         int lg=0 ;      // var for low gain chip
00094         
00095         int tab_ok[64] ;
00096         for (int i=0;i<64;i++)
00097         {       tab_ok[i]=0 ;
00098         }
00099         
00100         Float_t lg_limit_low = 0.11 ;
00101         Float_t lg_limit_high = 0.16 ;
00102                 
00103         for (int ich=0;ich<64;ich++)
00104         {       //getline(dataFilePedestal,bufferpedestal) ;
00105                 dataFilePedestal >> crap >> pedestal[ich] ;
00106                 getline(dataFilePedestal,bufferpedestal) ;
00107                 //bufferpedestal >> crap >> pedestal[ich] >> crap >> crap >> crap;
00108                 dataFileData >> crap >> data[ich] ;
00109                 getline(dataFileData,bufferdata) ;
00110                 //bufferdata >> crap >> data[ich]  >> crap >> crap >> crap;
00111                 gain[ich] = (inputcharge * 1E15) / (data[ich] - pedestal[ich]) ;
00112                 if ((gain[ich]<= lg_limit_high) && (gain[ich]>lg_limit_low))
00113                 {       ok++ ;  
00114                         tab_ok[ich]=1 ;
00115                 }
00116                 else bad_channels << ich << " " ;
00117                 if ((gain[ich]>lg_limit_high) && (gain[ich]<0.30)) lg++ ;
00118 //              cout << pedestal[ich] << "\t" << data[ich] << "\t" << gain[ich] << " fC/DAC" << endl ;
00119         }
00120         // from http://www.network-science.de/ascii/ style donut
00121         
00122         TString flag ;
00123         Int_t min_chan_ok = 60 ;
00124         
00125         if (ok==64)
00126         {       cout << "     OOOOOOOOO     KKKKKKKKK    KKKKKKK " << endl ;
00127                 cout << "   OO:::::::::OO   K:::::::K    K:::::K " << endl ;
00128                 cout << " OO:::::::::::::OO K:::::::K    K:::::K " << endl ;
00129                 cout << "O:::::::OOO:::::::OK:::::::K   K::::::K " << endl ;
00130                 cout << "O::::::O   O::::::OKK::::::K  K:::::KKK " << endl ;
00131                 cout << "O:::::O     O:::::O  K:::::K K:::::K    " << endl ;
00132                 cout << "O:::::O     O:::::O  K::::::K:::::K     " << endl ;
00133                 cout << "O:::::O     O:::::O  K:::::::::::K      " << endl ;
00134                 cout << "O:::::O     O:::::O  K:::::::::::K      " << endl ;
00135                 cout << "O:::::O     O:::::O  K::::::K:::::K     " << endl ;
00136                 cout << "O:::::O     O:::::O  K:::::K K:::::K    " << endl ;
00137                 cout << "O::::::O   O::::::OKK::::::K  K:::::KKK " << endl ;
00138                 cout << "O:::::::OOO:::::::OK:::::::K   K::::::K " << endl ;
00139                 cout << " OO:::::::::::::OO K:::::::K    K:::::K " << endl ;
00140                 cout << "   OO:::::::::OO   K:::::::K    K:::::K " << endl ;
00141                 cout << "     OOOOOOOOO     KKKKKKKKK    KKKKKKK " << endl ;
00142                 flag = "_OK" ;
00143                 //return 0;
00144         }
00145         else
00146         {       if (lg==64)
00147                 {
00148                         cout << "*************************************" << endl ;
00149                         cout << "LOW GAIN CHIP, BUT ALL CHANNELS OK ! " << endl ;
00150                         cout << "Channel \t Pedestal \t  Data \t  Gain " << endl ;
00151                         for (int i=0;i<64;i+=8)
00152                         {       if      (tab_ok[i]== 0)
00153                                 {       cout << i << "\t \t" << pedestal[i] << "\t \t" << data[i] << "\t \t" << gain[i] << endl ;
00154                                 }
00155                         }
00156                         cout << "*************************************" << endl ;
00157                         flag = "_LG" ;
00158                 }
00159 /*              else if (ok>=min_chan_ok)
00160                 {       cout << "*************************************" << endl ;
00161                         cout << 64-ok << " bad channels ! Channel(s) " << bad_channels.str() << "has/have bad gain" << endl ;
00162                         cout << "*************************************" << endl ;
00163                         flag = "_LG" ;
00164                 
00165                 }*/
00166                 else
00167                 {
00168                         cout << "*************************************" << endl ;
00169                         //cout << "Chip " << 
00170                         cout << "BAD CHIP: " << 64-ok << " bad channels ! Channel(s) " << bad_channels.str() << "has/have bad gain" << endl ;
00171                         cout << "Channel \tPedestal \tData \t\tGain " << endl ;
00172                         for (int i=0;i<64;i++)
00173                         {       if      (tab_ok[i]== 0)
00174                                 {       cout << i << "\t\t" << pedestal[i] << "\t\t" << data[i] << "\t\t" << gain[i] << endl ;
00175                                 }
00176                         }
00177                         cout << "*************************************" << endl ;
00178                         flag = "_BAD" ;
00179 
00180         /*      cout << "BBBBBBBBBBBBBBBBB               AAA               DDDDDDDDDDDDD                     CCCCCCCCCCCCCHHHHHHHHH     HHHHHHHHHIIIIIIIIIIPPPPPPPPPPPPPPPPP   "  << endl ;
00181                 cout << "B::::::::::::::::B             A:::A              D::::::::::::DDD               CCC::::::::::::CH:::::::H     H:::::::HI::::::::IP::::::::::::::::P   " << endl ;
00182                 cout << "B::::::BBBBBB:::::B           A:::::A             D:::::::::::::::DD           CC:::::::::::::::CH:::::::H     H:::::::HI::::::::IP::::::PPPPPP:::::P  " << endl ;
00183                 cout << "BB:::::B     B:::::B         A:::::::A            DDD:::::DDDDD:::::D         C:::::CCCCCCCC::::CHH::::::H     H::::::HHII::::::IIPP:::::P     P:::::P " << endl ;
00184                 cout << "  B::::B     B:::::B        A:::::::::A             D:::::D    D:::::D       C:::::C       CCCCCC  H:::::H     H:::::H    I::::I    P::::P     P:::::P " << endl ;
00185                 cout << "  B::::B     B:::::B       A:::::A:::::A            D:::::D     D:::::D     C:::::C                H:::::H     H:::::H    I::::I    P::::P     P:::::P " << endl ;
00186                 cout << "  B::::BBBBBB:::::B       A:::::A A:::::A           D:::::D     D:::::D     C:::::C                H::::::HHHHH::::::H    I::::I    P::::PPPPPP:::::P  " << endl ;
00187                 cout << "  B:::::::::::::BB       A:::::A   A:::::A          D:::::D     D:::::D     C:::::C                H:::::::::::::::::H    I::::I    P:::::::::::::PP  " << endl ;
00188                 cout << "  B::::BBBBBB:::::B     A:::::A     A:::::A         D:::::D     D:::::D     C:::::C                H:::::::::::::::::H    I::::I    P::::PPPPPPPPP    " << endl ;
00189                 cout << "  B::::B     B:::::B   A:::::AAAAAAAAA:::::A        D:::::D     D:::::D     C:::::C                H::::::HHHHH::::::H    I::::I    P::::P          " << endl ;  
00190                 cout << "  B::::B     B:::::B  A:::::::::::::::::::::A       D:::::D     D:::::D     C:::::C                H:::::H     H:::::H    I::::I    P::::P          " << endl ;  
00191                 cout << "  B::::B     B:::::B A:::::AAAAAAAAAAAAA:::::A      D:::::D    D:::::D       C:::::C       CCCCCC  H:::::H     H:::::H    I::::I    P::::P         " << endl ;   
00192                 cout << "BB:::::BBBBBB::::::BA:::::A             A:::::A   DDD:::::DDDDD:::::D         C:::::CCCCCCCC::::CHH::::::H     H::::::HHII::::::IIPP::::::PP       " << endl ;   
00193                 cout << "B:::::::::::::::::BA:::::A               A:::::A  D:::::::::::::::DD           CC:::::::::::::::CH:::::::H     H:::::::HI::::::::IP::::::::P       " << endl ;   
00194                 cout << "B::::::::::::::::BA:::::A                 A:::::A D::::::::::::DDD               CCC::::::::::::CH:::::::H     H:::::::HI::::::::IP::::::::P       " << endl ;   
00195                 cout << "BBBBBBBBBBBBBBBBBAAAAAAA                   AAAAAAADDDDDDDDDDDDD                     CCCCCCCCCCCCCHHHHHHHHH     HHHHHHHHHIIIIIIIIIIPPPPPPPPPP      " << endl ;
00196         */
00197                 //return -1;
00198                 }
00199         }
00200 
00201         TString store_file = TString(data_arg) ;
00202 //      store_file.ReplaceAll("parameters_", "gain_");
00203         store_file.ReplaceAll("_data.txt", "");
00204         //TString (data_arg).ReplaceAll("parameters_", "gain_");
00205         TString store_file_full ;
00206         store_file_full = root_directory + store_file + "_gain" + flag + ".txt";
00207         //cout << store_file << endl ;
00208         ofstream out ;
00209         out.open(store_file_full) ;
00210         for (int ich=0;ich<64;ich++)
00211         {                       out << gain[ich] << endl ;
00212         }
00213         
00214     return 0 ;
00215 }
00216 
00217 
00218 
00219 //**********************************************************************************************
00220 //**********************************************************************************************
00221 
00222 
00223 void usage(char *progname)
00224 {
00225         printf("Usage : %s directory pedestals datafile", progname);
00226         printf("        Return gain for each channel");
00227 //      printf("        scurve_rootfile.root is created\n");
00228 }
00229 
00230 //**********************************************************************************************
00231 //**********************************************************************************************
00232 
00233 void set_style_myplain()
00234 {
00235         style_myplain->SetCanvasBorderMode(0);
00236         style_myplain->SetCanvasColor(0);
00237         style_myplain->SetDrawBorder(0);
00238         style_myplain->SetPadBorderMode(0);
00239         style_myplain->SetPadColor(10);
00240         style_myplain->SetFrameLineColor(1);
00241         style_myplain->SetFrameFillColor(5);
00242         style_myplain->SetFrameFillStyle(0);
00243         style_myplain->SetFrameBorderMode(0);
00244 
00245         //style_myplain->SetFrameLineWidth(5); //test for setframelinecolor !
00246 
00247         style_myplain->SetLegendBorderSize(1);
00248 
00249         style_myplain->SetTextColor(231);
00250 
00251 //      style_myplain->SetFillColor(0); // If enable : impossible to fill histo with color !!! see note in the end !
00252         style_myplain->SetLineColor(231);
00253 
00254         style_myplain->SetStatColor(10);
00255         style_myplain->SetStatTextColor(1);
00256         style_myplain->SetStatBorderSize(1) ;
00257         style_myplain->SetStatX(0.9);
00258         style_myplain->SetStatY(0.9);
00259         style_myplain->SetOptStat("");//"emr" by default
00260         style_myplain->SetOptFit(0111);
00261 
00262         style_myplain->SetTitleTextColor(1);
00263         style_myplain->SetTitleBorderSize(0);
00264         style_myplain->SetTitleAlign(23);
00265         style_myplain->SetTitleX(0.5);
00266 
00267         style_myplain->SetAxisColor(1,"x");     // bleu
00268         style_myplain->SetAxisColor(1,"y");
00269         style_myplain->SetAxisColor(1,"z");
00270         style_myplain->SetLabelColor(1,"x");
00271         style_myplain->SetLabelColor(1,"x");
00272         style_myplain->SetLabelColor(1,"y");
00273         style_myplain->SetLabelColor(1,"z");
00274         style_myplain->SetLabelSize(0.03,"x");
00275         style_myplain->SetLabelSize(0.03,"y");
00276         style_myplain->SetLabelSize(0.03,"z");
00277         style_myplain->SetTitleColor(1,"x");
00278         style_myplain->SetTitleColor(1,"y");
00279         style_myplain->SetTitleColor(1,"z");
00280         style_myplain->SetTitleFillColor(10);
00281 
00282         style_myplain->SetHistFillColor(10);
00283         //style_myplain->SetHistFillStyle(0);
00284         style_myplain->SetHistFillStyle(1001);
00285         style_myplain->SetHistLineColor(1);                     // 231 !!!
00286 
00287         style_myplain->SetFuncColor(kOrange+10);        // dark orange
00288         style_myplain->SetPalette(1);                           // température like
00289         
00290 //      style_myplain->SetPaperSize(100,100);  // for Hi Res plots only !
00291 
00292         style_myplain->cd();
00293 
00294         gROOT->SetStyle("myplain"); 
00295 
00296         gROOT->ForceStyle(true);
00297 
00298 
00299 
00300 // frame style not applied ! why ????????
00301 // do it manually : right click on frame then "use current style"
00302 }

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