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

Go to the documentation of this file.
00001 /* @version $Revision: 1831 $ * @modifiedby $Author: lcdet $ * @lastmodified $Date: 2012-08-20 11:48:00 +0200 (Mon, 20 Aug 2012) $ */
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 //#include "Run.hh"
00016 #include "Chamber.hh"
00017 //#include "Event.hh"
00018 #include "Detector.hh"
00019 #include "DiracChamber1.hh"
00020 #include "GassiplexChamber1.hh"
00021 #include "GassiplexChamber4.hh"
00022 #include "Hardroc1Chamber.hh"
00023 //#include "XMLTool.hh"
00024 #include "MicroException.hh"
00025 #include <iostream>
00026 
00027 
00028 #include <TApplication.h>
00029 #include <TGClient.h>
00030 //#include <TGButton.h>
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 {  //un-named script to be run in ROOT framework
00046 
00047   FILELog::ReportingLevel() = FILELog::FromString(INFO);
00048 
00049   //----- Control usage and option
00050   if ( argc != 3  ) {
00051    FILE_LOG(logERROR)  << "usage: EventDisplay  rootFile eventNum" << endl;
00052    exit(1);
00053   }
00054 
00055 
00056 
00057   //string steerName;
00058   //steerName.assign(argv[1]);
00059         //streeName.assign(argv[1]);
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 //cout << "--------max vis node["  <<frame->GetMaxVisNodes() << "]" << endl;
00091 
00092 TGeoMaterial *mat = new TGeoMaterial("SomeMaterial",1,1,1);
00093 TGeoMedium *med = new TGeoMedium("SomeMedium",1,mat);
00094 
00095 //TGeoVolume *world = frame->MakeBox("World", med, xLength, yLength, zLength); // x, y , z size unit cm
00096 
00097 // -----  create World volume who contains all other.
00098 TGeoVolume *world = frame->MakeBox("World", med, 1, 1, 1); // x, y , z size unit cm
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 //    FILE_LOG(logINFO) << "Number of reoncstruct events: " << tree->GetEntries() << endl;
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;//                   694 node MaxMax
00133     for(int i=0;i<NC  ;i++)
00134     //for(int i=0;i<10  ;i++)
00135     {
00136       //if ( padNumber < 693)
00137       //cout << "pad number]" << padNumber << "]" << endl;
00138       if ( padNumber < 169300)
00139       {
00140         int nodes = world->CountNodes();
00141         //cout << "nodes]" << nodes << "]" << endl;
00142 
00143         //the only known way to get the information from the channels number i
00144         MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(i);
00145         UInt_t t2 = channel->GetBcIdDif();
00146         UInt_t t3 = channel->GetBcIdHit();
00147         UInt_t dtcurr = t2 - t3;
00148 
00149         if ( dtcurr == dt )
00150         {
00151 
00152           float xLength = .098 * 4; //cm
00153           float yLength = .098 * 4; // cm
00154           float zLength = .12; // cm
00155           // ChannelPad name
00156           string padID="";
00157           stringstream currentpad;// (stringstream::in | stringstream::out);
00158           padNumber++;
00159           currentpad<<padNumber;
00160           padID="pad_"+currentpad.str();
00161 
00162           //TGeoVolume *pad = frame->MakeBox(padID.c_str(),med,xLength,yLength,zLength );
00163           TGeoVolume *pad = frame->MakeBox(padID.c_str(),med,yLength,xLength,zLength );
00164           x=channel->GetX() ;//+xOffset;
00165           y=channel->GetY() ;//+yOffset;
00166           z=channel->GetZ() ;
00167           /*
00168           z=channel->GetZ();
00169           x=channel->GetX();//+xOffset;
00170           y=channel->GetY();//+yOffset;
00171           */
00172           cout << "-----> Draw x[" << x << "], y[" << y << "], z[" << z << "]"  << endl;
00173           //set now the color of the pad
00174           int color;
00175           int sMax = 30;//set to limit of saturation
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           //cout << "key[" << key <<"]" <<endl;
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     // run ROOT application
00209 
00210     return 0;
00211     }

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