00001
00002
00003
00004
00005 #include "MicroException.hh"
00006 #include "Mysql.hh"
00007 #include "Toolbox.hh"
00008 #include "CaloRun.hh"
00009 #include "CaloEvent.hh"
00010 #include "CaloHit.hh"
00011
00012 #include "TKey.h"
00013 #include <TKey.h>
00014 #include <TList.h>
00015 #include <TTree.h>
00016 #include <TFile.h>
00017
00018 #include "XMLTool.hh"
00019 #include "geometry/Detector.hh"
00020 #include "geometry/Chamber.hh"
00021 #include "Log.hh"
00022
00023 #include <iostream>
00024 #include <iomanip>
00025
00026
00027
00028
00029 int main(int argc, char**argv){
00030 if ( argc !=2 ) {
00031 FILE_LOG(logERROR) << "usage: caloExample rootFile " << endl;
00032 exit(1);
00033 }
00034
00035
00036 Detector detector;
00037
00038 string rootName;
00039 rootName.assign(argv[1]);
00040 int nbHit = 0;
00041 int nbEvt = 0;
00042
00043 TFile f(rootName.c_str());
00044 TIter nextkey(f.GetListOfKeys());
00045 TKey *key;
00046
00047 while (key = (TKey*)nextkey())
00048 {
00049
00050 TString keyname = key->GetName();
00051
00052 TTree *tree = (TTree*)key->ReadObj();
00053 cout << "---------------------------- NEW TTREE ---------------------------"<< endl;
00054 nbEvt =0;
00055 nbHit = 0;
00056
00057 unsigned int runId = 0;
00058 try {
00059 CaloRun *run=dynamic_cast<CaloRun *>(tree->GetUserInfo()->First());
00060 if ( run != NULL)
00061 {
00062 runId = run->GetRunId() ;
00063 cout << "RunId[" << run->GetRunId() << "] " << endl ;
00064 }
00065 }
00066 catch ( ... ) {}
00067 Detector detector;
00068 Toolbox::getDetector(runId,detector);
00069
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 Int_t layer = hit->GetLayer();
00088 Chamber& chamber = detector.getChamberById(layer);
00089 cout << "Hit in chamber id " << layer <<", chamber type " << chamber.getType() << endl;
00090
00091 cout << "\t Nw Hit " << endl;
00092 hit->GetSolftId().ToString();
00093 cout << "new hit layer[" << hit->GetLayer() << endl;
00094 cout << "\thit abs row [" << hit->GetRowInChamber() << setprecision(12) << "], posX[" << xpos << "]" << endl;
00095 cout << "\thit abs col [" << hit->GetColInChamber() << setprecision(12) << "], posY[" << ypos << "]" << endl;
00096 }
00097
00098
00099 }
00100
00101
00102 }
00103
00104 return 0;
00105 }