00001 #include <iostream>
00002 #include <fstream>
00003 #include <map>
00004 #include "TKey.h"
00005 #include <TROOT.h>
00006 #include <TRint.h>
00007 #include <TKey.h>
00008 #include <TTree.h>
00009 #include <TFile.h>
00010 #include <TSystem.h>
00011 #include <TreeClass.hh>
00012 #include <TF1.h>
00013 #include <TH1I.h>
00014 #include <TH2I.h>
00015 #include <TH3F.h>
00016 #include <TH2F.h>
00017 #include <TGraph.h>
00018 #include <sstream>
00019 #include <vector>
00020 #include "Log.hh"
00021
00022 #include "MicroException.hh"
00023
00024
00025 using namespace std;
00026
00027
00028 int main(int argc, char**argv){
00029
00030
00031 bool verbose_steerfile = 0;
00032 bool verbose_runloop = 0;
00033 bool verbose_ped_file = 0;
00034 bool verbose_offset = 1;
00035
00036 int nsigma_adc_cut = 2;
00037
00038
00039
00040 if (argc!=2){
00041
00042 cout<<endl;
00043 cout<<"Number of argument invalid"<<endl;
00044 cout<<" 1 -> steerfile"<<endl;
00045 cout<<endl;}
00046
00047 else{
00048
00049
00050
00051
00052
00053 TString ped_gas_string;
00054 TString ped_m2_string;
00055 TString data_string;
00056
00057 int i = 0;
00058 int j = 0;
00059 int run = 0;
00060 int nrun = 0;
00061
00062 vector <TString> ped_gas_file_vector;
00063 vector <TString> ped_m2_file_vector;
00064 vector <TString> data_file_vector;
00065
00066 ifstream steerfile(argv[1]);
00067
00068 while(steerfile>>ped_gas_string>>ped_m2_string>>data_string){
00069
00070 if (ped_gas_string=="end_fo_file"){break;}
00071
00072 else{
00073
00074 nrun++;
00075 ped_gas_file_vector.push_back(ped_gas_string);
00076 ped_m2_file_vector.push_back(ped_m2_string);
00077 data_file_vector.push_back(data_string);}}
00078
00079 if (verbose_steerfile){
00080
00081 cout<<endl;
00082 cout<<"Number of runs = "<<nrun<<endl;
00083 cout<<endl;
00084 for (i=0;i<nrun;i++){
00085 cout<<"Pedestal gassiplex file = "<<ped_gas_file_vector[i]<<endl;
00086 cout<<"Pedestal m2 prototype file = "<<ped_m2_file_vector[i]<<endl;
00087 cout<<"ROOT data file = "<<data_file_vector[i]<<endl;
00088 cout<<endl;}
00089 cout<<endl;}
00090
00091
00092
00093
00094
00095
00096 int chn,chb,xpos,ypos;
00097 float ped,ped_err,width,width_err,gain;
00098
00099
00100
00101 int nchn_m2 = 9216;
00102 float ped_m2_tab[nchn_m2];
00103 float ped_err_m2_tab[nchn_m2];
00104 float width_m2_tab[nchn_m2];
00105 float width_err_m2_tab[nchn_m2];
00106 float gain_m2_tab[nchn_m2];
00107
00108
00109
00110 int nchb_gas = 4;
00111 int nchn_gas = 384;
00112 float ped_gas_tab[nchb_gas][nchn_gas];
00113 float ped_err_gas_tab[nchb_gas][nchn_gas];
00114 float width_gas_tab[nchb_gas][nchn_gas];
00115 float width_err_gas_tab[nchb_gas][nchn_gas];
00116 float thr_gas_tab[nchb_gas][nchn_gas];
00117 float gain_gas_tab[nchb_gas][nchn_gas];
00118
00119
00120
00121
00122
00123
00124
00125 for (run=0;run<1;run++){
00126
00127 if (verbose_runloop){
00128
00129 cout<<endl;
00130 cout<<"Analysis of run "<<run+1<<endl;
00131 cout<<endl;
00132 cout<<"Pedestal gassiplex file = "<<ped_gas_file_vector[run]<<endl;
00133 cout<<"Pedestal m2 prototype file = "<<ped_m2_file_vector[run]<<endl;
00134 cout<<"ROOT data file = "<<data_file_vector[run]<<endl;
00135 cout<<endl;}
00136
00137
00138
00139
00140
00141
00142
00143
00144 for (i=0;i<nchb_gas;i++){
00145 for (j=0;j<nchn_gas;j++){
00146
00147 ped_gas_tab[i][j] = 0;
00148 ped_err_gas_tab[i][j] = 0;
00149 width_gas_tab[i][j] = 0;
00150 width_err_gas_tab[i][j] = 0;
00151 gain_gas_tab[i][j] = 0;
00152 thr_gas_tab[i][j] = 0;}}
00153
00154
00155
00156 for (i=0;i<nchn_m2;i++){
00157
00158 ped_m2_tab[i] = 0;
00159 ped_err_m2_tab[i] = 0;
00160 width_m2_tab[i] = 0;
00161 width_err_m2_tab[i] = 0;
00162 gain_m2_tab[i] = 0;}
00163
00164 ifstream ped_gas_file(ped_gas_file_vector[run].Data());
00165 ifstream ped_m2_file(ped_m2_file_vector[run].Data());
00166
00167 if(verbose_ped_file){cout<<"Read gassiplex pedestal file "<<ped_gas_file_vector[run]<<endl;}
00168 while(ped_gas_file>>chn>>xpos>>ypos>>chb>>ped>>ped_err>>width>>width_err>>gain){
00169
00170 if (gain!=0){
00171
00172 if (verbose_ped_file){cout<<chn<<"\t"<<xpos<<"\t"<<ypos<<"\t"<<chb<<"\t"<<ped<<"\t"<<ped_err<<"\t"<<width<<"\t"<<width_err<<"\t"<<gain<<"\r"<<flush;}
00173
00174 ped_gas_tab[chb-1][chn] = ped;
00175 ped_err_gas_tab[chb-1][chn] = ped_err;
00176 width_gas_tab[chb-1][chn] = width;
00177 width_err_gas_tab[chb-1][chn] = width_err;
00178 gain_gas_tab[chb-1][chn] = gain;
00179 thr_gas_tab[chb-1][chn] = floor(ped + nsigma_adc_cut * width + 1);}}
00180
00181 if(verbose_ped_file){cout<<endl;cout<<"Read m2 prototype pedestal file "<<ped_m2_file_vector[run]<<endl;}
00182 while(ped_m2_file>>chn>>xpos>>ypos>>chb>>ped>>ped_err>>width>>width_err>>gain){
00183
00184 if (gain!=0){
00185
00186 if (verbose_ped_file){cout<<chn<<"\t"<<xpos<<"\t"<<ypos<<"\t"<<chb<<"\t"<<ped<<"\t"<<ped_err<<"\t"<<width<<"\t"<<width_err<<"\t"<<gain<<"\r"<<flush;}
00187
00188 ped_m2_tab[chn] = ped;
00189 ped_err_m2_tab[chn] = ped_err;
00190 width_m2_tab[chn] = width;
00191 width_err_m2_tab[chn] = width_err;
00192 gain_m2_tab[chn] = gain;}}
00193
00194 if(verbose_ped_file){cout<<endl;}
00195
00196
00197
00198
00199
00200
00201
00202
00203 int ntrigger = 0;
00204
00205 TFile * rootfile = new TFile(data_file_vector[run]);
00206
00207 if (verbose_offset){cout<<endl;cout<<"Reading ROOT file "<<data_file_vector[run]<<endl;}
00208
00209 TIter nextkey(rootfile->GetListOfKeys());
00210 TKey *key;
00211
00212 while (key = (TKey*)nextkey()) {
00213
00214 TTree *tree = (TTree*)key->ReadObj();
00215 MTRun* run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun");
00216
00217 ntrigger = tree->GetEntries();
00218
00219 MTEvent *evt = new MTEvent();
00220 TBranch *branch= tree->GetBranch("MTEvent");
00221 branch->SetAddress(&evt);
00222
00223 if (verbose_offset){cout<<"Number of recorded triggers = "<<ntrigger<<endl;cout<<endl;}
00224 }
00225
00226
00227
00228
00229
00230
00231
00232
00233 }
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 }
00247
00248
00249 return 0;}