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

Go to the documentation of this file.
00001 /* @version $Revision: 1740 $ * @modifiedby $Author: gaglione $ * @lastmodified $Date: 2012-05-24 17:32:39 +0200 (Thu, 24 May 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 <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 //#define DEBUG_RND
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 //void set_style_myplain() ;
00044 //TStyle *style_myplain=new TStyle("myplain","classic style");
00045 ////////////////////////////////////////////////////////////////////////////////////////////
00046 
00047 int main(int argc, char**argv){
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 &microChip = 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 }
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 void set_style_myplain()
00280 {
00281         style_myplain->SetCanvasBorderMode(0);
00282         style_myplain->SetCanvasColor(0);
00283         style_myplain->SetDrawBorder(0);
00284         style_myplain->SetPadBorderMode(0);
00285         style_myplain->SetPadColor(10);
00286         style_myplain->SetFrameLineColor(1);
00287         style_myplain->SetFrameFillColor(5);
00288         style_myplain->SetFrameFillStyle(0);
00289         style_myplain->SetFrameBorderMode(0);
00290 
00291         //style_myplain->SetFrameLineWidth(5); //test for setframelinecolor !
00292 
00293         style_myplain->SetLegendBorderSize(1);
00294 
00295         style_myplain->SetTextColor(231);
00296 
00297 //      style_myplain->SetFillColor(0); // If enable : impossible to fill histo with color !!! see note in the end !
00298         style_myplain->SetLineColor(231);
00299 
00300         style_myplain->SetStatColor(10);
00301         style_myplain->SetStatTextColor(1);
00302         style_myplain->SetStatBorderSize(1) ;
00303         style_myplain->SetStatX(0.9);
00304         style_myplain->SetStatY(0.9);
00305         style_myplain->SetOptStat("");//"emr" by default
00306         style_myplain->SetOptFit(0111);
00307 
00308         style_myplain->SetTitleTextColor(1);
00309         style_myplain->SetTitleBorderSize(0);
00310         style_myplain->SetTitleAlign(23);
00311         style_myplain->SetTitleX(0.5);
00312 
00313         style_myplain->SetAxisColor(1,"x");     // bleu
00314         style_myplain->SetAxisColor(1,"y");
00315         style_myplain->SetAxisColor(1,"z");
00316         style_myplain->SetLabelColor(1,"x");
00317         style_myplain->SetLabelColor(1,"x");
00318         style_myplain->SetLabelColor(1,"y");
00319         style_myplain->SetLabelColor(1,"z");
00320         style_myplain->SetLabelSize(0.03,"x");
00321         style_myplain->SetLabelSize(0.03,"y");
00322         style_myplain->SetLabelSize(0.03,"z");
00323         style_myplain->SetTitleColor(1,"x");
00324         style_myplain->SetTitleColor(1,"y");
00325         style_myplain->SetTitleColor(1,"z");
00326         style_myplain->SetTitleFillColor(10);
00327 
00328         style_myplain->SetHistFillColor(10);
00329         //style_myplain->SetHistFillStyle(0);
00330         style_myplain->SetHistFillStyle(1001);
00331         style_myplain->SetHistLineColor(1);                     // 231 !!!
00332 
00333         style_myplain->SetFuncColor(kOrange+10);        // dark orange
00334         style_myplain->SetPalette(1);                           // temp�rature like
00335         
00336 //      style_myplain->SetPaperSize(100,100);  // for Hi Res plots only !
00337 
00338         style_myplain->cd();
00339 
00340         gROOT->SetStyle("myplain"); 
00341 
00342         gROOT->ForceStyle(true);
00343 
00344 
00345 
00346 // frame style not applied ! why ????????
00347 // do it manually : right click on frame then "use current style"
00348 }
00349 */

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