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

Go to the documentation of this file.
00001 /* @version $Revision: 1376 $ * @modifiedby $Author: jacquem $ * @lastmodified $Date: 2011-11-18 16:11:02 +0100 (Fri, 18 Nov 2011) $ */
00002 
00003 
00004 
00005 #include "MicroException.hh"
00006 #include "mysql/Mysql.hh"
00007 #include "root/CaloRun.hh"
00008 #include "root/CaloEvent.hh"
00009 #include "root/CaloHit.hh"
00010 
00011 #include "TKey.h"
00012 #include <TKey.h>
00013 #include <TList.h>
00014 #include <TTree.h>
00015 #include <TFile.h>
00016 
00017 #include "XMLTool.hh"
00018 #include "geometry/Detector.hh"
00019 #include "Log.hh"
00020 
00021 #include <iostream>
00022 #include <iomanip>
00023 
00024 //using namespace std;
00025 
00026 
00027 int main(int argc, char**argv){
00028    if ( argc !=2  ) {
00029    FILE_LOG(logERROR)  << "usage: caloExample rootFile " << endl;
00030    exit(1);
00031   }
00032 
00033   // Build detector from XML file
00034   Detector detector;
00035   // Get detector information
00036   
00037   SteerDesc steerDesc;
00038   XMLTool xml;
00039   xml.parse(steerDesc, "/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/SteerFiles/TestBeam2012/calice_cubic_metter.xml");
00040   detector.build(steerDesc);
00041 
00042 
00043   string rootName;
00044   rootName.assign(argv[1]);
00045   int nbHit = 0;
00046   int nbEvt = 0;
00047   
00048   TFile f(rootName.c_str());
00049   TIter nextkey(f.GetListOfKeys());
00050   TKey *key;
00051 
00052   while (key = (TKey*)nextkey()) 
00053   {
00054 
00055     TString keyname = key->GetName();
00056 
00057     TTree *tree = (TTree*)key->ReadObj();                
00058     cout << "---------------------------- NEW TTREE ---------------------------"<< endl;
00059     nbEvt =0;
00060     nbHit = 0;
00061 
00062     try {
00063       CaloRun *run=dynamic_cast<CaloRun *>(tree->GetUserInfo()->First());
00064       if ( run != NULL) 
00065       {
00066         cout << "Run[" << run->GetRunId() << "] " << endl ; 
00067       }
00068     }
00069     catch ( ... ) {}
00070 
00071     CaloEvent *evt =  new CaloEvent();
00072     TBranch *branch= tree->GetBranch("CaloEvent");
00073     branch->SetAddress(&evt);
00074 
00075     CaloHit* hit =NULL;
00076     int nbEntries = tree->GetEntries();
00077     for ( int evtNum = 0; evtNum < nbEntries ; evtNum++)
00078     {
00079       tree->GetEntry(evtNum);
00080       nbEvt++;
00081       int nbHits = evt->GetNHits();
00082       for(int i=0 ; i < nbHits ; i++)
00083       {
00084         hit = (CaloHit*)evt->GetHits()->UncheckedAt(i);
00085         Int_t xpos = hit->GetX();
00086         Int_t ypos = hit->GetY();
00087         cout << "\t Nw Hit " << endl;
00088         hit->GetSolftId().ToString();
00089         cout << "new hit layer[" << hit->GetLayer() << endl;
00090         cout << "\thit abs row [" << hit->GetRowInChamber() << setprecision(12) << "], posX[" << xpos << "]"  << endl;
00091         cout << "\thit abs col [" << hit->GetColInChamber() << setprecision(12) << "], posY[" << ypos << "]"  << endl;
00092       }
00093 
00094 
00095     } // end event
00096 /*
00097 */
00098   } // end run ( TTree )
00099 
00100 return 0;
00101 }

Generated on Mon Jun 11 16:55:46 2012 for MicromegasFramework by  doxygen 1.4.7