/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/analyse/root/example.cpp

Go to the documentation of this file.
00001 /* @version $Revision: 2001 $ * @modifiedby $Author: jacquem $ * @lastmodified $Date: 2012-12-18 13:39:25 +0100 (Tue, 18 Dec 2012) $ */
00002 #include <map>
00003 #include "TKey.h"
00004 #include "TList.h"
00005 #include <TROOT.h>
00006 #include <TRint.h>
00007 #include <TKey.h>
00008 #include <TList.h>
00009 #include <TTree.h>
00010 #include <TFile.h>
00011 #include <stdlib.h>
00012 #include <TSystem.h>
00013 #include <iostream>
00014 #include <sstream>
00015 #include "Log.hh"
00016 
00017 #include "MicroException.hh"
00018 #include <string>
00019 
00020 #include "mysql/Mysql.hh"
00021 
00022 
00023 #include "root/MTRun.hh"
00024 #include "root/MTTrack.hh"
00025 #include "root/MTChamber.hh"
00026 #include "root/MTDetector.hh"
00027 #include "root/MTBoard.hh"
00028 #include "root/MTChip.hh"
00029 #include "root/MTChannel.hh"
00030 #include "root/MTEvent.hh"
00031 #include "root/MTDif.hh"
00032 #include "root/MTHardroc1Chip.hh"
00033 #include "root/MTHardroc2Chip.hh"
00034 #include "root/MTDiracChip.hh"
00035 #include "root/MTMicrorocChip.hh"
00036 
00037 
00038 using namespace std;
00039 
00040 
00041 int main(int argc, char**argv){
00042 
00043 /*
00044   Mysql mysql;
00045   MYSQL_ROW row;
00046 
00047   string sql = "SELECT * FROM RUN";
00048 
00049   MYSQL_RES* result = mysql.executeSelect(sql);
00050 
00051   int num_fields = mysql_num_fields(result);
00052 
00053   while ((row = mysql_fetch_row(result)))
00054   {
00055       for( int i = 0; i < num_fields; i++)
00056       {
00057           printf("%s ", row[i] ? row[i] : "NULL");
00058       }
00059       printf("\n");
00060   }
00061 
00062   int id = -1;
00063   try {
00064     id  = mysql.getReconstructionSoftwareId("114");
00065   }
00066   catch (MicroException e) {}
00067 
00068   cout << "Id[" << id << "]" <<endl ;
00069   id = mysql.addReconstructionSoftware("$Revision: 2001 $", "comments");
00070   cout << "Id[" << id << "]" <<endl ;
00071   try {
00072     id  = mysql.getReconstructionSoftwareId("114");
00073   }
00074   catch (MicroException e) {}
00075   cout << "Id[" << id << "]" <<endl ;
00076 
00077 */
00078 
00079    if ( argc !=2  ) {
00080    FILE_LOG(logERROR)  << "usage: example rootFile " << endl;
00081    exit(1);
00082   }
00083 
00084   string rootName;
00085   rootName.assign(argv[1]);
00086   int nbHit = 0;
00087   int nbEvt = 0;
00088 
00089   TFile f(rootName.c_str());
00090   f.ls();
00091 
00092 
00093 
00094   TIter nextkey(f.GetListOfKeys());
00095   TKey *key;
00096   while (key = (TKey*)nextkey()) 
00097   {
00098     TTree *tree = (TTree*)key->ReadObj();                
00099     MTRun *run=NULL;
00100     try 
00101     {
00102       run=dynamic_cast<MTRun *>(tree->GetUserInfo()->First());
00103       cout << "---------------------------- NEW TTREE ---------------------------"<< endl;
00104       nbEvt =0;
00105       nbHit = 0;
00106       //cout << "RunId[" << run->GetRunId() << "]" << endl;
00107 
00108       bool showConfig = false;
00109       if ( run != NULL && showConfig) 
00110       {
00111         run->Info(); 
00112         MTDetector* det = run->GetDetector();
00113         // loop over chamber config
00114           
00115         const std::map<UInt_t,MTChamber*>& chambers = det->GetChambers();
00116         for( std::map<UInt_t,MTChamber*>::const_iterator ii=chambers.begin(); ii!=chambers.end(); ++ii)
00117         {
00118           const MTChamber& chamber= *((*ii).second);
00119           cout << "chamber id: " << chamber.GetId() << endl;
00120           cout << "chamber type: " << chamber.GetType() << endl;
00121 
00122           // loop over dif config
00123           //const std::map<UInt_t,MTDif*>& difs = chamber.GetDifs();
00124           //for( std::map<UInt_t,MTDif*>::const_iterator ii=difs.begin(); ii!=difs.end(); ++ii)
00125           //{
00126             //const MTDif& dif= *((*ii).second);
00127             //dif.Info();
00128           //}
00129           // loop over board config
00130           const std::map<UInt_t,MTBoard*>& boards = chamber.GetBoards();
00131           for( std::map<UInt_t,MTBoard*>::const_iterator ii=boards.begin(); ii!=boards.end(); ++ii)
00132           {
00133             const MTBoard& board= *((*ii).second);
00134             board.Info();
00135 
00136             cout << endl << endl << "\t\t\t**** Chips configuration ****" << endl ;
00137 cout << "DEBUG board.GetChips().size()[" << board.GetChips().size() << "]" << endl; 
00138             map<UInt_t,MTChip*> chips = board.GetChips();
00139             for( map<UInt_t,MTChip*>::const_iterator iiChip=chips.begin(); iiChip!=chips.end(); ++iiChip)
00140             {
00141               const MTChip& chip  = *((*iiChip).second);
00142               cout << "chip[" << chip.GetId() << "] bypass[" << chip.GetBypassed() << "] " << endl;
00143               if ( chip.IsConfigured() )
00144               {
00145               cout << endl << "   -- New Chip configuration:" <<  chip.GetSoftId().toString() << " softId[" << chip.GetSoftId().GetValue() <<"], serial Number[" << chip.GetSerialNumber() << "]"<< endl <<endl  <<endl ;
00146               try {
00147                 const MTDiracChip &diracChip = dynamic_cast<const MTDiracChip &> (chip);
00148                 cout << "   ** Dirac Chip config **" << endl;
00149                 cout << "      threshold B High: " << diracChip.GetBHiThreshold()  << endl;
00150                 cout << "      threshold B Mid : " << diracChip.GetBMidThreshold()  << endl;
00151                 cout << "      threshold B Low : " << diracChip.GetBLoThreshold()  << endl;
00152 
00153                 cout << "      threshold A High :" << diracChip.GetAHiThreshold()  << endl;
00154                 cout << "      threshold A Mid : " << diracChip.GetAMidThreshold()  << endl;
00155                 cout << "      threshold A Low : " << diracChip.GetALoThreshold()  << endl;
00156                 cout << "   ** END Dirac Chip config **" << endl;
00157               }
00158               catch (...) {}
00159 
00160               try{
00161                 const MTHardroc1Chip &hr1Chip = dynamic_cast<const MTHardroc1Chip &> (chip);
00162                 cout << "   ** Hardroc1 Chip config **" << endl;
00163                 cout << "      threshold dac 0: " << hr1Chip.GetThresholdDac_0()  << endl;
00164                 cout << "      threshold dac 1: " << hr1Chip.GetThresholdDac_1()  << endl;
00165                 cout <<    "   gain   :         " << hr1Chip.GetGain() << endl;
00166                 cout << "   ** END Hardroc1 Chip config **" << endl;
00167               }
00168               catch (...) {}
00169 
00170               try{
00171                 const MTHardroc2Chip &hr2Chip = dynamic_cast<const MTHardroc2Chip &> (chip);
00172                 cout << "   ** Hardroc2 Chip config **" << endl;
00173                 cout << "      threshold dac 0: " << hr2Chip.GetThresholdDac_0()  << endl;
00174                 cout << "      threshold dac 1: " << hr2Chip.GetThresholdDac_1()  << endl;
00175                 cout << "      threshold dac 2: " << hr2Chip.GetThresholdDac_2()  << endl;
00176                 cout <<    "   gain   :         " << hr2Chip.GetGain() << endl;
00177                 cout << "   ** END Hardroc2 Chip config **" << endl;
00178               }
00179               catch (...) {}
00180 
00181               try{
00182                 const MTMicrorocChip &micro2Chip = dynamic_cast<const MTMicrorocChip &> (chip);
00183                 cout << "   ** MicrorocChip Chip config **" << endl;
00184                 cout << dec << "      Serial number : " << micro2Chip.GetSerialNumber()  << endl;
00185                 cout << dec << "      low shaper : " << micro2Chip.GetShaper_lg()  << endl;
00186                 cout << dec << "      high shaper : " << micro2Chip.GetShaper_hg()  << endl;
00187                 cout << dec << "      threshold dac 0: " << micro2Chip.GetThresholdDac_0()  << endl;
00188                 cout << dec << "      threshold dac 1: " << micro2Chip.GetThresholdDac_1()  << endl;
00189                 cout << dec << "      threshold dac 2: " << micro2Chip.GetThresholdDac_2()  << endl;
00190                 cout << "   ** END MicrorocChip Chip config **" << endl;
00191               }
00192               catch (...) {}
00193 
00194               cout << endl << endl << "* channels config **" << endl << endl;
00195               cout <<"      Enable channel:" ;
00196               for ( UInt_t num = 0 ; num <=63 ; num++)
00197               {
00198                 cout << "[" << dec <<num << ":"<< chip.GetEnableChannel(num) << "]";
00199               }
00200               cout << endl <<endl << endl <<  "    Stimulate channel:";
00201               for ( UInt_t num = 0 ; num <=63 ; num++)
00202               {
00203                 cout << "[" << dec <<num << ":"<< chip.GetStimulatedChannel(num) << "]";
00204               }
00205 
00206               cout << endl <<endl << endl <<  "    Mask ( Microroc Only  ) channel:";
00207               for ( UInt_t num = 0 ; num <=63 ; num++)
00208               {
00209                 for ( UInt_t index = 0 ; index < 3 ; index++ )
00210                 {
00211                   cout << "[" << dec <<num << ":MASK" << index << "-> "<< chip.GetMaskChannel(num,index) << "]";
00212                 }
00213               }
00214 
00215 
00216               cout << endl <<endl << endl  << "    pedastal correction channel:";
00217               for ( UInt_t num = 0 ; num <=63 ; num++)
00218               {
00219                 cout << "[" <<dec << num << ":"<< chip.GetPedestalChannel(num) << "]";
00220               }
00221               cout << endl << "   -- End Chip configuration:" << endl;
00222               } // end if chip is configured
00223 
00224               }  // end loop for chip
00225                 cout  <<endl << "\t\t\t**** END Chips configuration **** "<< endl  << endl << endl;
00226           }
00227         }
00228       }
00229     }
00230     catch (MicroException e) {}
00231 
00232 
00233   MTEvent *evt =  new MTEvent();
00234   TBranch *branch= tree->GetBranch("MTEvent");
00235   branch->SetAddress(&evt);
00236 
00237   MTChannel* channel =NULL;
00238   int nbEntries = tree->GetEntries();
00239   
00240   for ( int evtNum = 0; evtNum <= nbEntries ; evtNum++)
00241   {
00242     tree->GetEntry(evtNum);
00243     nbEvt++;
00244 
00245     //UInt_t nbPad = 1300;
00246     //UInt_t my_asu;
00247     //UInt_t my_abstime;
00248     //cout<<evt->IsSquare(nbPad,my_asu,my_abstime)<<endl;
00249 
00250 /*
00251   //    cout << "    event num in TTree:" << evtNum <<endl;
00252     cout << "Validity_flag: [0x" << hex << evt->GetValidFlag() << "]" << dec << evt->GetValidFlagString() << endl;
00253 
00254     bool spark = false;
00255     std::map< UInt_t, std::map<UInt_t, UInt_t>* >& nbHitPerAbsTime = evt->GetNbHitPerAbsTime();
00256     for (std::map< UInt_t, std::map<UInt_t, UInt_t>* >::iterator iter = nbHitPerAbsTime.begin(); iter != nbHitPerAbsTime.end(); iter++)
00257     {
00258     map<UInt_t, UInt_t> *byBoard = iter->second;
00259     for ( map<UInt_t,UInt_t>::iterator it = byBoard->begin(); it != byBoard->end(); it++)
00260     {
00261     UInt_t absTime = it->first;
00262     UInt_t nbHit   = it->second;
00263         cout << "Board[" << iter->first << "] Absolute time [" << absTime  << "]nbHit[" << nbHit <<"]"    << endl;
00264     if (nbHit > 1) { spark = true; }
00265     }
00266     }
00267 
00268 */
00269 
00270     //if (!evt->GetCrcIsCorrect())
00271     {
00272     cout << "    event id:" << evt->GetEventId() <<endl;
00273 
00274     cout << "    event Dif suynchro:" << evt->GetDifSynchro() <<endl;
00275     cout << "    event total Trigger counter:" << evt->GetGlobalTriggerCounter() <<endl;
00276     cout << "    event Dif Trigger counter:" << evt->GetDifTriggerCounter() <<endl;
00277     const map<unsigned int , float>& tempAsu1 = evt->GetTemperatureAsu1();
00278     for ( map<unsigned int , float>::const_iterator it = tempAsu1.begin() ; it != tempAsu1.end(); it++)
00279     {
00280       cout << "    temperature difId: " << it->first << " Asu1:" << it->second <<endl;
00281     }
00282     const map<unsigned int , float>& tempAsu2 = evt->GetTemperatureAsu2();
00283     for ( map<unsigned int , float>::const_iterator it = tempAsu2.begin() ; it != tempAsu2.end(); it++)
00284     {
00285       cout << "    temperature difId: " << it->first << " Asu2:" << it->second <<endl;
00286     }
00287 
00288     const map<unsigned int , float>& tempDif = evt->GetTemperatureDif();
00289     cout << "evt->GetTemperatureDif().size[" << evt->GetTemperatureDif().size() << "]" <<endl;
00290     for ( map<unsigned int , float>::const_iterator it = tempDif.begin() ; it != tempDif.end(); it++)
00291     {
00292       cout << "    temperature difId: " << it->first << " dif:" << it->second <<endl;
00293       cout << "DEBUG 1" << endl;
00294     }
00295 cout << "evt->GetTemperatureAsu1().size[" << evt->GetTemperatureAsu1().size() << "]" <<endl;
00296 cout << "evt->GetTemperatureAsu2().size[" << evt->GetTemperatureAsu2().size() << "]" <<endl;
00297     cout << "    temperature:" << evt->GetTemperature() <<endl;
00298     cout << "    pressure:"<< evt->GetPressure() <<endl;
00299     cout << "    timestamp:"<< evt->GetTimestamp() <<endl;
00300     cout << "    dif_synchro:"<< evt->GetDifSynchro() <<endl;
00301     cout << "    CRC is correct:"<< evt->GetCrcIsCorrect() <<endl;
00302 
00303     std::vector<UInt_t>& dtCands = evt->GetDtCandidate();
00304     for ( std::vector<UInt_t>::const_iterator it =dtCands.begin(); it!=dtCands.end(); it++)
00305     {
00306       cout << "dt canditate: [" << *it << "] " << endl; 
00307     }
00308 
00309 
00310     const std::map<UInt_t, std::map<UInt_t, std::map<UInt_t, Float_t>* >* >& meshs = evt->GetMeshVoltage();
00311     for ( std::map<UInt_t, std::map<UInt_t, std::map<UInt_t, Float_t>* >* >::const_iterator iterChamber = meshs.begin(); iterChamber != meshs.end(); iterChamber++)
00312     {
00313       std::map<UInt_t, std::map<UInt_t, Float_t>* >&difContainer = *(iterChamber)->second;
00314       for ( std::map<UInt_t, std::map<UInt_t, Float_t>* >::const_iterator iterDif = difContainer.begin(); iterDif != difContainer.end(); iterDif++)
00315       {
00316         std::map<UInt_t, Float_t> &boardContainer = *(iterDif)->second;
00317         for ( std::map<UInt_t, Float_t>::const_iterator iterVoltage = boardContainer.begin(); iterVoltage != boardContainer.end(); iterVoltage++)
00318         {
00319           cout << "    MeshVoltage for chamber [" << iterChamber->first << "]Dif = ["<< iterDif->first << "] board[" << iterVoltage->first << "] :" <<iterVoltage->second << "]" << endl;
00320         }
00321       }
00322 
00323     }
00324 
00325 
00326     const std::map<UInt_t, std::map<UInt_t, std::map<UInt_t, Float_t>* >* >& drifts = evt->GetDriftVoltage();
00327     for ( std::map<UInt_t, std::map<UInt_t, std::map<UInt_t, Float_t>* >* >::const_iterator iterChamber = drifts.begin(); iterChamber != drifts.end(); iterChamber++)
00328     {
00329     std::map<UInt_t, std::map<UInt_t, Float_t>* >&difContainer = *(iterChamber)->second;
00330     for ( std::map<UInt_t, std::map<UInt_t, Float_t>* >::const_iterator iterDif = difContainer.begin(); iterDif != difContainer.end(); iterDif++)
00331     {
00332     std::map<UInt_t, Float_t> &boardContainer = *(iterDif)->second;
00333     for ( std::map<UInt_t, Float_t>::const_iterator iterVoltage = boardContainer.begin(); iterVoltage != boardContainer.end(); iterVoltage++)
00334     {
00335     // mergedEvt->SetDriftMeshVoltage(iterChamber->first,iterDif->first,iterVoltage->first,iterVoltage->second);
00336     cout << "    DriftVoltage for chamber [" << iterChamber->first << "]Dif = ["<< iterDif->first << "] board[" << iterVoltage->first << "] :" <<iterVoltage->second << "]" << endl;
00337 
00338     }
00339     }
00340 
00341     }
00342     }
00343 /*
00344       if ( run->GetProcessed() == true )
00345 */
00346       {
00347         cout << "    is square[" << evt->GetSquareEvt() << "]"  << endl;
00348         cout << "    is time info correct[" << evt->GetTimeInfo() << "]"  << endl;
00349         MTTrack *track = evt->GetTrack();
00350         if ( track != NULL )
00351         {
00352           cout << "    straight: " << track->GetStraight()
00353           << ", from Strip: " << track->GetFromStrip()
00354           << ", from Pad: " << track->GetFromPad()
00355           << ", single hit: " << track->GetSingleHit()
00356           << ", ax: " << track->GetAx()
00357           << ", bx: " << track->GetBx()
00358           << ", ay: " << track->GetAy()
00359           << ", by: " << track->GetBy()  << endl;
00360         }
00361       }
00362       cout << "    number of channel hit:" << evt->GetNchannel() <<endl;
00363       int nbChannel = evt->GetNchannel();
00364 /*
00365       for(int i=0;i<nbChannel  ;i++)
00366       {
00367         nbHit++;
00368         channel = (MTChannel*)evt->GetChannels()->UncheckedAt(i);
00369 
00370 
00371         cout << "****** Channels Information "<< i+1 << "/" << nbChannel << " ******" <<  endl;
00372         cout << "      Hit num:            " << i << endl;
00373         cout << "      chamber id:         " << channel->GetChamberId() <<endl;
00374         cout << "      dif id:             " << channel->GetDifId() <<endl;
00375         cout << "      boardId id:         " << channel->GetBoardId() <<endl;
00376         cout << "      chip id(format dec):" << dec << channel->GetChipId() <<endl;
00377         cout << "      hard id    :        " << dec << channel->GetHardId() <<endl;
00378         cout << "      row inside chip :   " << channel->GetRowInChip() <<endl;
00379         cout << "      col inside chip:    " << channel->GetColInChip() <<endl ;
00380         cout << "      soft id:            " << channel->GetSoftId().GetValue() << endl<< endl;
00381         cout << "      soft id:            " << channel->GetSoftId().GetValue() << endl<< endl;
00382         cout << "      asu row:            " << channel->GetSoftId().GetBoardRow() << endl<< endl;
00383         cout << "      asu col:            " << channel->GetSoftId().GetBoardCol() << endl<< endl;
00384         cout << "      channel row inside chamber: " << channel->GetRowInChamber() <<endl;
00385         cout << "      channel col inside chamber: " << channel->GetColInChamber() <<endl ;
00386         cout << "      analog value:       " << channel->GetAnalogValue() <<endl;
00387         cout << "      digital value:      " <<  channel->GetDigitalValue() <<endl;
00388         cout << "      x:                  " <<  channel->GetX() <<endl;
00389         cout << "      y:                  " << channel->GetY() <<endl;
00390         cout << "      z:                  " << channel->GetZ() <<endl;
00391         cout << "      order:              " << channel->GetOrder() <<endl;
00392         cout << "      timestamp:          " <<  channel->GetTimestamp() <<endl;
00393         cout << "      bcId abs:           " << channel->GetBcIdAbs() <<endl;
00394         cout << "      bcId dif:           " << channel->GetBcIdDif() <<endl;
00395         cout << "      bcId hit:           " << channel->GetBcIdHit() <<endl;
00396         UInt_t absTime =  channel->GetBcIdAbs() + (channel->GetBcIdDif() - channel->GetBcIdHit() );
00397         cout << "DEBUG      absolute time:bcid_abs - (bcid_dif - bcid_hit)       " << absTime <<endl;
00398         cout << "DEBUG      dt (bcid_dif - bcid_hit)       " << channel->GetBcIdDif() - channel->GetBcIdHit() << endl;
00399         cout << "      nbHit for this absolute time:" << evt->GetNbHitPerAbsTime(channel->GetSoftId().GetBoardId(),absTime)<<endl;
00400         cout << "      bcId hit Fine:      " << channel->GetBcIdHitFine() <<endl;
00401         cout << "      memory order :      " << channel->GetMemoryOrder() <<endl;
00402       } // END LOOP ON CHANNELHIT
00403 */
00404 
00405     } // END LOOP ON EVENT
00406     cout << "End of TTree[" << tree->GetName() << "]" <<endl;
00407     cout << endl << "** Nombre d Event["<< nbEvt <<"] ** "<< endl;
00408     cout << endl << "** Nombre de Hits["<< nbHit <<"] ** "<< endl;
00409 
00410   } // end loop on TKEy
00411 return 0 ;
00412 }
00413 
00414 
00415 
00416 

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