00001
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
00049
00050
00051
00052
00053
00054
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 ;
00072 string bufferpedestal ;
00073 Float_t pedestal[64] ;
00074 string bufferdata ;
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 ;
00093 int lg=0 ;
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 {
00105 dataFilePedestal >> crap >> pedestal[ich] ;
00106 getline(dataFilePedestal,bufferpedestal) ;
00107
00108 dataFileData >> crap >> data[ich] ;
00109 getline(dataFileData,bufferdata) ;
00110
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
00119 }
00120
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
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
00160
00161
00162
00163
00164
00165
00166 else
00167 {
00168 cout << "*************************************" << endl ;
00169
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
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 }
00199 }
00200
00201 TString store_file = TString(data_arg) ;
00202
00203 store_file.ReplaceAll("_data.txt", "");
00204
00205 TString store_file_full ;
00206 store_file_full = root_directory + store_file + "_gain" + flag + ".txt";
00207
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
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
00246
00247 style_myplain->SetLegendBorderSize(1);
00248
00249 style_myplain->SetTextColor(231);
00250
00251
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("");
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");
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
00284 style_myplain->SetHistFillStyle(1001);
00285 style_myplain->SetHistLineColor(1);
00286
00287 style_myplain->SetFuncColor(kOrange+10);
00288 style_myplain->SetPalette(1);
00289
00290
00291
00292 style_myplain->cd();
00293
00294 gROOT->SetStyle("myplain");
00295
00296 gROOT->ForceStyle(true);
00297
00298
00299
00300
00301
00302 }