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 <TH2.h>
00012 #include <TGraph.h>
00013 #include <sstream>
00014 #include "Log.hh"
00015 #include <fstream>
00016 #include "TCanvas.h"
00017 #include "TApplication.h"
00018 #include "TColor.h"
00019 #include "TStyle.h"
00020 #include "TAxis.h"
00021 #include "TString.h"
00022 #include "TLegend.h"
00023 #include "MicroException.hh"
00024
00025 #define DISPLAY
00026 #undef DEBUG_RND
00027
00028 #define PLOT
00029 #define WRITE
00030
00031
00032 #include "root/MTRun.hh"
00033 #include "root/MTDetector.hh"
00034 #include "root/MTChamber.hh"
00035 #include "root/MTBoard.hh"
00036 #include "root/MTChip.hh"
00037 #include "root/MTEvent.hh"
00038 #include "root/MTChannel.hh"
00039 #include "root/MTMicrorocChip.hh"
00040
00041 using namespace std;
00042 void usage(char *progname) ;
00043
00044
00045
00046
00047 int main(int argc, char**argv){
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 if(argc != 4)
00059 { usage(argv[0]) ;
00060 return 1 ;
00061 }
00062
00063
00064 TString root_directory = argv[1];
00065 TString root_filename = argv[2];
00066 int dac = atoi(argv[3]);
00067
00068
00069
00070 TString root_file = root_directory + root_filename;
00071
00072 int nbChannel = 0;
00073 float nbEvt = 0;
00074 int threshold = 0;
00075
00076 int hardid = 0;
00077 int value = 0;
00078
00079 Double_t content = 0;
00080 UInt_t chipId ;
00081
00082 TH1I * hvalue = new TH1I("hvalue","",5,0,5);
00083 TH1I * hnpulse_threshold = new TH1I("hnpulse_threshold","",1024,0,1024);
00084
00085 TH1I * hscurve[64];
00086 TString name,title;
00087
00088 for (int j=0;j<64;j++)
00089 { name = Form("hscurve_%i",j);
00090 title = Form("SCurve from channel %i",j);
00091 hscurve[j] = new TH1I(name,title,1024,0,1024);
00092 }
00093
00094 int tab_ok[64] ;
00095 for (int i=0;i<64;i++)
00096 { tab_ok[i]=0 ;
00097 }
00098 int serial ;
00099 int difId=0 ;
00100
00101 TFile f(root_file);
00102 TIter nextkey(f.GetListOfKeys());
00103 TKey *key;
00104 while (key = (TKey*)nextkey())
00105 { TTree *tree = (TTree*)key->ReadObj();
00106 MTRun* run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun");
00107
00108
00109
00110 MTDetector* det = run->GetDetector();
00111
00112
00113 const std::map<UInt_t,MTChamber*>& chambers = det->GetChambers();
00114 for( std::map<UInt_t,MTChamber*>::const_iterator ii=chambers.begin(); ii!=chambers.end(); ++ii)
00115 {
00116 const MTChamber& chamber= *((*ii).second);
00117
00118 const std::map<UInt_t,MTBoard*>& boards = chamber.GetBoards();
00119 for( std::map<UInt_t,MTBoard*>::const_iterator ii=boards.begin(); ii!=boards.end(); ++ii)
00120 {
00121 const MTBoard& board= *((*ii).second);
00122
00123 map<UInt_t,MTChip*> chips = board.GetChips();
00124 for( map<UInt_t,MTChip*>::const_iterator iiChip=chips.begin(); iiChip!=chips.end(); ++iiChip)
00125 {
00126 const MTChip& chip = *((*iiChip).second);
00127 serial = chip.GetSerialNumber() ;
00128 if ( chip.IsConfigured() )
00129 {
00130 difId = chip.GetSoftId().GetDifId() ;
00131 }
00132
00133 #ifdef DEBUG_RND
00134 cout << endl << " --Chip:" << chip.GetSoftId().toString() << " softId[" << chip.GetSoftId().GetValue() <<"]"<< endl;
00135 cout << " pedastal channel:";
00136 for ( UInt_t num = 0 ; num <=63 ; num++)
00137 { cout << "[" << num << ":"<< chip.GetPedestalChannel(num) << "]";
00138 }
00139 cout << endl ;
00140 #endif
00141
00142 try
00143 { const MTMicrorocChip µChip = dynamic_cast<const MTMicrorocChip &> (chip);
00144 if (dac==0){threshold = microChip.GetThresholdDac_0();}
00145 if (dac==1){threshold = microChip.GetThresholdDac_1();}
00146 if (dac==2){threshold = microChip.GetThresholdDac_2();}
00147 #ifdef DEBUG_RND
00148 cout << "Threshold: " << threshold << endl ;
00149 #endif
00150 }
00151 catch (...) {}
00152 }
00153 }
00154 }
00155 MTEvent *evt = new MTEvent();
00156 TBranch *branch= tree->GetBranch("MTEvent");
00157 branch->SetAddress(&evt);
00158 MTChannel* channel = NULL;
00159 nbEvt = tree->GetEntries();
00160 #ifdef DEBUG_RND
00161 cout << "Number of events in the tree: " << nbEvt << endl ;
00162 #endif
00163 hnpulse_threshold->SetBinContent(threshold+1,nbEvt);
00164
00165 int ok=0 ;
00166 for( int evtNum = 0; evtNum < nbEvt ; evtNum++)
00167 {
00168 tree->GetEntry(evtNum);
00169 nbChannel = evt->GetNchannel();
00170 #ifdef DEBUG_RND
00171 cout << "Found " << nbChannel << " in this Tree" << endl ;
00172 #endif
00173 for(int i=0;i<nbChannel;i++)
00174 { channel = (MTChannel*)evt->GetChannels()->UncheckedAt(i);
00175 chipId = channel->GetChipId();
00176 hardid = channel->GetHardId();
00177 value = channel->GetDigitalValue();
00178 #ifdef DEBUG_RND
00179 cout << "Chip "<< chipId <<" channel " << hardid << " value " << value << endl;
00180 #endif
00181 hvalue->Fill(value);
00182
00183 if (difId==1)
00184 { if ( (hardid!=8 && hardid!=42 && value>=1) || hardid==8 || hardid==42)
00185 { ok++;
00186 tab_ok[hardid] = 1 ;
00187 }
00188 }
00189 else if (difId==2)
00190 { if ((hardid!=62 && value>=1) || hardid==62)
00191
00192 { ok++;
00193 tab_ok[hardid] = 1 ;
00194 }
00195 }
00196 else if (difId==3)
00197 {
00198 if (value>=1)
00199 { ok++;
00200 tab_ok[hardid] = 1 ;
00201 }
00202 }
00203 }
00204 }
00205
00206
00207
00208
00209
00210 if ((difId==1 && ok>=63) || (difId==2 && ok>=64) || (difId==3 && ok>=64))
00211
00212 { cout << "Chip " << serial << " on test board " << difId << " has bonding OK !!! (EXPERT INFO: Channels " ;
00213 for (int i=0;i<64;i++)
00214 { if (tab_ok[i]==0) cout << i << " " ;
00215 }
00216 cout << "have not been tested on (DIF " << difId << ")" << endl ;
00217 return 0;
00218 }
00219 else
00220 {
00221 cout << "*************************************************************************" << endl ;
00222 cout << "!!! Chip " << serial << " on test board " << difId << " has "<< 64-ok << " BAD BONDING on channel(s) " ;
00223 for (int i=0;i<64;i++)
00224 { if (tab_ok[i]==0) cout << i << " " ;
00225 }
00226 cout << endl ;
00227 cout << "*************************************************************************" << endl ;
00228
00229
00230 root_filename.ReplaceAll(".root", "");
00231 TString bad_file = root_directory + "../RESULTS/" + root_filename + + "_BAD" +".txt";
00232 ofstream out ;
00233 out.open(bad_file) ;
00234 for (int i=0;i<64;i++)
00235 if (tab_ok[i] != 1)
00236 { out << i<< " " << tab_ok[i] << endl;
00237 }
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 return 1;
00255 }
00256 }
00257
00258
00259
00260 return 0 ;
00261 }
00262
00263
00264
00265
00266
00267
00268
00269 void usage(char *progname)
00270 {
00271 printf("Usage : %s directory rootfile [0|1|2]", progname);
00272 printf(" Where [0|1|2] is the dac number\n");
00273 printf(" Test if all input have switched\n");
00274 }
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349