#include <map>
#include "TKey.h"
#include <TROOT.h>
#include <TRint.h>
#include <TTree.h>
#include <TFile.h>
#include <TSystem.h>
#include <iostream>
#include <TH2.h>
#include <TGraph.h>
#include <sstream>
#include "Log.hh"
#include <fstream>
#include "TCanvas.h"
#include "TApplication.h"
#include "TColor.h"
#include "TStyle.h"
#include "TAxis.h"
#include "TString.h"
#include "TLegend.h"
#include "MicroException.hh"
#include "root/MTRun.hh"
#include "root/MTDetector.hh"
#include "root/MTChamber.hh"
#include "root/MTBoard.hh"
#include "root/MTChip.hh"
#include "root/MTEvent.hh"
#include "root/MTChannel.hh"
#include "root/MTMicrorocChip.hh"
Include dependency graph for test_microroc_bonding.cpp:
Go to the source code of this file.
Defines | |
#define | DISPLAY |
#define | PLOT |
#define | WRITE |
Functions | |
void | usage (char *progname) |
int | main (int argc, char **argv) |
#define DISPLAY |
Definition at line 25 of file test_microroc_bonding.cpp.
#define PLOT |
Definition at line 28 of file test_microroc_bonding.cpp.
#define WRITE |
Definition at line 29 of file test_microroc_bonding.cpp.
void usage | ( | char * | progname | ) |
int main | ( | int | argc, | |
char ** | argv | |||
) |
Definition at line 47 of file test_microroc_bonding.cpp.
00047 { 00048 00049 /*****************************************************************/ 00050 /* ARGUMENTS TO THE PROGRAM **************************************/ 00051 /* 1 - DIRECTORY OF THE ROOT FILE PRODUCED BY THE RECONSTRUCTION */ 00052 /* 2 - NAME OF THE ROOT FILE *************************************/ 00053 /* 3 - THRESHOLD THAT IS MOVED DURING THE CALIBRATION ************/ 00054 /* 0 -> DAC_0 (LOW THRESHOLD) *********************************/ 00055 /* 1 -> DAC_1 (MEDIUM THRESHOLD) ******************************/ 00056 /* 2 -> DAC_2 (HIGH THRESHOLD) ********************************/ 00057 /*****************************************************************/ 00058 if(argc != 4) 00059 { usage(argv[0]) ; 00060 return 1 ; 00061 } 00062 //cout << "VERSION PROVISOIRE ! SWITCHER A PARTIR DE CHIP 508 / 528" << endl ; 00063 00064 TString root_directory = argv[1]; 00065 TString root_filename = argv[2]; 00066 int dac = atoi(argv[3]); 00067 00068 //bool display = 0; 00069 //set_style_myplain() ; 00070 TString root_file = root_directory + root_filename; 00071 00072 int nbChannel = 0; 00073 float nbEvt = 0; 00074 int threshold = 0; 00075 //int chipid = 0; 00076 int hardid = 0; 00077 int value = 0; 00078 //int content = 0; 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 // loop over chamber config 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 // loop over board config 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 { //if (evtNum%1000 == 0) {cout<<evtNum/nbEvt*100.<<" %"<<"\r"<<flush;} 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 // The channels wich have not responded are not to zero, BUT DO NOT exist !!!!! -> nonsense to test hardid see line 192, "ok" test is enough 00183 if (difId==1) 00184 { if ( (hardid!=8 && hardid!=42 && value>=1) || hardid==8 || hardid==42) //|| ((hardid==8) && (value>=0)) || ((hardid==42) && (value>=0)) ) 00185 { ok++; 00186 tab_ok[hardid] = 1 ; 00187 } 00188 } 00189 else if (difId==2) 00190 { if ((hardid!=62 && value>=1) || hardid==62)//|| (hardid==62 && value>=1)) 00191 //if ((hardid !=62 && value>=1) || (hardid==62 && value>=0) ) 00192 { ok++; 00193 tab_ok[hardid] = 1 ; 00194 } 00195 } 00196 else if (difId==3) 00197 { //if ((hardid!=62 && value>=1) || hardid==62)//|| (hardid==62 && value>=1)) 00198 if (value>=1) 00199 { ok++; 00200 tab_ok[hardid] = 1 ; 00201 } 00202 } 00203 } 00204 } 00205 00206 /* for (int i=0;i<64;i++) 00207 { cout << i << " " << tab_ok[i] << endl;; 00208 } 00209 */ 00210 if ((difId==1 && ok>=63) || (difId==2 && ok>=64) || (difId==3 && ok>=64)) 00211 // if (ok == 64) 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 // cout << ok << endl ; 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 /* for(int i=0;i<nbChannel;i++) 00240 { channel = (MTChannel*)evt->GetChannels()->UncheckedAt(i); 00241 chipId = channel->GetChipId(); 00242 hardid = channel->GetHardId(); 00243 value = channel->GetDigitalValue(); 00244 if (value != 1) 00245 { cout<< "Chip "<< serial <<" channel " << hardid << " value " << value << endl; 00246 } 00247 //out << "Chip "<< chipId <<" channel " << hardid << " value " << value << endl; 00248 cout << hardid << " " << tab_ok[hardid] << endl ; 00249 if (tab_ok[hardid] != 1) 00250 { out << "Chip "<< chipId <<" channel " << hardid << " value " << value << endl; 00251 cout << "Chip "<< chipId <<" channel " << hardid << " value " << value << endl; 00252 } 00253 }*/ 00254 return 1; 00255 } 00256 } 00257 00258 00259 00260 return 0 ; 00261 }