00001
00002 #include <TROOT.h>
00003 #include <TRint.h>
00004 #include <TKey.h>
00005 #include <TCanvas.h>
00006 #include <TTree.h>
00007 #include <TFile.h>
00008 #include <TSystem.h>
00009 #include <TGeoManager.h>
00010 #include <TGeoMatrix.h>
00011 #include <iostream>
00012 #include <sstream>
00013 #include "Log.hh"
00014
00015
00016 #include "Chamber.hh"
00017
00018 #include "Detector.hh"
00019 #include "DiracChamber1.hh"
00020 #include "GassiplexChamber1.hh"
00021 #include "GassiplexChamber4.hh"
00022 #include "Hardroc1Chamber.hh"
00023
00024 #include "MicroException.hh"
00025 #include <iostream>
00026
00027
00028 #include <TApplication.h>
00029 #include <TGClient.h>
00030
00031 #include <TGListBox.h>
00032 #include <TList.h>
00033
00034 #include "root/MTRun.hh"
00035 #include "root/MTEvent.hh"
00036 #include "root/MTChannel.hh"
00037
00038
00039 using namespace std;
00040
00041
00042
00043 int main(int argc, char **argv)
00044
00045 {
00046
00047 FILELog::ReportingLevel() = FILELog::FromString(INFO);
00048
00049
00050 if ( argc != 3 ) {
00051 FILE_LOG(logERROR) << "usage: EventDisplay rootFile eventNum" << endl;
00052 exit(1);
00053 }
00054
00055
00056
00057
00058
00059
00060
00061 string rootName;
00062 rootName.assign(argv[1]);
00063
00064 int eventNum = atoi(argv[2]);
00065
00066 TApplication *theApp;
00067
00068 argc = 1;
00069 theApp = new TRint("App", &argc, argv);
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 TFile *f = new TFile(rootName.c_str());
00081 if ( f->IsZombie()) {
00082 FILE_LOG(logERROR) << "Root file ["<< rootName.c_str() << "] does not exist" << endl;
00083 exit(-1);
00084 }
00085
00086
00087 gSystem->Load("libGeom");
00088 TGeoManager *frame =new TGeoManager("Frame","mM event displayer");
00089 frame->SetMaxVisNodes(40000);
00090
00091
00092 TGeoMaterial *mat = new TGeoMaterial("SomeMaterial",1,1,1);
00093 TGeoMedium *med = new TGeoMedium("SomeMedium",1,mat);
00094
00095
00096
00097
00098 TGeoVolume *world = frame->MakeBox("World", med, 1, 1, 1);
00099
00100 map<string,bool> node;
00101
00102 MTEvent *evt = new MTEvent();
00103 TIter nextkey(f->GetListOfKeys());
00104 TKey *key;
00105 int padNumber = 0;
00106 while ((key = (TKey*)nextkey()))
00107 {
00108 TTree *tree = (TTree*)key->ReadObj();
00109 MTRun* run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun");
00110
00111
00112
00113 TBranch *branch= tree->GetBranch("MTEvent");
00114 branch->SetAddress(&evt);
00115
00116 Int_t globalTriggerCounter = -1;
00117 Int_t nbEvent = tree->GetEntries();
00118 bool find = false;
00119 tree->GetEntry(eventNum);
00120 std::vector<UInt_t>& dtValid = evt->GetDtCandidate();
00121
00122 UInt_t dt = 0;
00123 if (dtValid.size() >0)
00124 {
00125 dt = dtValid[0];
00126 cout << "valid dt [" << dt << "]" << endl;
00127 }
00128
00129 Int_t NC=evt->GetNchannel();
00130 frame->SetMaxVisNodes(NC);
00131
00132 float x,y,z;
00133 for(int i=0;i<NC ;i++)
00134
00135 {
00136
00137
00138 if ( padNumber < 169300)
00139 {
00140 int nodes = world->CountNodes();
00141
00142
00143
00144 MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(i);
00145 UInt_t t2 = channel->GetBcId_Dif();
00146 UInt_t t3 = channel->GetBcId_Hit();
00147 UInt_t dtcurr = t2 - t3;
00148
00149 if ( dtcurr == dt )
00150 {
00151
00152 float xLength = .098 * 4;
00153 float yLength = .098 * 4;
00154 float zLength = .12;
00155
00156 string padID="";
00157 stringstream currentpad;
00158 padNumber++;
00159 currentpad<<padNumber;
00160 padID="pad_"+currentpad.str();
00161
00162
00163 TGeoVolume *pad = frame->MakeBox(padID.c_str(),med,yLength,xLength,zLength );
00164 x=channel->GetX() ;
00165 y=channel->GetY() ;
00166 z=channel->GetZ() ;
00167
00168
00169
00170
00171
00172 cout << "-----> Draw x[" << x << "], y[" << y << "], z[" << z << "]" << endl;
00173
00174 int color;
00175 int sMax = 30;
00176 stringstream ch;
00177 ch<<i;
00178
00179 color = channel->GetAnalogValue()+channel->GetDigitalValue()*10;
00180 ostringstream ox,oy,oz;
00181 ox << x; oy << y; oz <<z ;
00182 string key = "x[" + ox.str() + "]y[" + oy.str() + "]z[" + oz.str() +"]" ;
00183
00184 if ( node[key]==false)
00185 {
00186 world->AddNode(pad,1,new TGeoTranslation(x,y,z));
00187 node[key] = true;
00188 color = color * 2;
00189 }
00190 pad->SetLineColor(color);
00191
00192 }
00193 }
00194 else
00195 {
00196 FILE_LOG(logERROR) << "------------------Too Many Nodes !" << endl<< endl << endl ;
00197 break;
00198 }
00199 }
00200 }
00201 frame->SetTopVolume(world);
00202 frame->CloseGeometry();
00203
00204 world->Draw();
00205
00206 theApp->Run();
00207 delete theApp;
00208
00209
00210 return 0;
00211 }