tests/src/DisplayTrack.cpp

Go to the documentation of this file.
00001 #include "TH3F.h"
00002 #include "MapsTrackManager.hh"
00003 #include "MapsTrack.hh"
00004 #include "MapsSensor.hh"
00005 #include "MapsException.hh"
00006 #include <cmath>
00007 #include <vector>
00008 #include "TRandom2.h"
00009 #include "TFile.h"
00010 #include "TH1F.h"
00011 #include "TH2F.h"
00012 #include "TApplication.h"
00013 #include "TCanvas.h"
00014 #include "TROOT.h"
00015 #include "TSystem.h"
00016 #include "TThread.h"
00017 #include "TStyle.h"
00018 #include "TPaveText.h"
00019 #include "TText.h"
00020 #include "ToString.h"
00021 #include "TVirtualViewer3D.h"
00022 #include "TGeoBBox.h"
00023 #include "Rtypes.h"
00024 #include "TVirtualGeoPainter.h"
00025 #include "TGLViewer.h"
00026 #include <signal.h>
00027 
00028 /** DisplayTrack.cpp
00029  * 
00030  * Use this to interactively display tracks on screen. 
00031  * Use of ROOT's OpenGL viewer is recommended.
00032  * 
00033  * Jamie Ballin, Imperial College London
00034  *              February 2008
00035  * 
00036  * j.ballin06@imperial.ac.uk
00037  */
00038 
00039 TApplication* theApp;
00040 TCanvas * c;
00041 TVirtualViewer3D* v;
00042 TGLViewer* viewer;
00043 
00044 bool continueJob=true;
00045 
00046 void signalHandler(int signal) {
00047         std::cerr << "Process "<< getpid() << " received signal "<< signal
00048                         << std::endl;
00049         continueJob=false;
00050 }
00051 
00052 void startSender(void* inA) {
00053         MapsTrackManager mtm2;
00054         char* input = static_cast<char*>(inA);
00055         mtm2.recreateFromRootFile(input);
00056 
00057         TH3F
00058                         * disp =
00059                                         new TH3F("hDisplay", "Event display;x;y;z", 100, -5.0, 5.0, 100, -5.0, 5.0, 64, 0, 64);
00060         disp->SetMarkerColor(2);
00061         disp->SetMarkerStyle(22);
00062         disp->SetMarkerSize(2.0);
00063 
00064         std::cout << "Iterating..." << std::endl;
00065         std::vector<MapsTrack*>& tracks = mtm2.getTracks();
00066 
00067         for (std::vector<MapsTrack*>::iterator it = tracks.begin(); it
00068                         != tracks.end(); it++) {
00069                 MapsTrack* t = *it;
00070                 t->eraseGlobalHits();
00071                 std::pair<double, double> error(0.1, 0.1);
00072                 t->setTrackError(error);
00073                 disp->Reset();
00074                 
00075 
00076                 if (t->chiSqProb(0) > 0.05 && t->chiSqProb(1) > 0.05 && t->getHits().size() == 4) {
00077                         std::map<MapsSensor*, MapsSensor::physXY > hits =
00078                                         t->getGlobalHits();
00079                         diagnose(std::cout, *t);
00080 
00081                         for (std::map<MapsSensor*, MapsSensor::physXY >::const_iterator h =
00082                                         hits.begin(); h != hits.end(); ++h) {
00083                                 MapsSensor::physXY theHit = (*h).second;
00084                                 disp->Fill(theHit.first, theHit.second, (*h).first->zPosition()+1);
00085                         }
00086                         disp->Draw("ogl");
00087                         TPaveText tp(0.1, 0.1, 0.4, 0.4);
00088                         tp.AddText("Track diagnosis");
00089                         tp.AddText(("p_{x} = " + toString(t->chiSqProb(0))).c_str());
00090                         tp.AddText(("p_{y} = " + toString(t->chiSqProb(1))).c_str());
00091                         tp.AddText(("#theta = " + toString(t->theta())).c_str());
00092                         tp.Draw("ogl");
00093                         c->Modified();
00094                         c->Update();
00095 
00096                         std::cout << "Hit return to display next...\n";
00097                         std::string input;
00098                         std::getline(std::cin, input);
00099 
00100                 }
00101         }
00102 
00103         std::cout << "Finished displaying events. Ctrl-C me. \n";
00104 }
00105 
00106 int main(int argc, const char **argv) {
00107 
00108         for (int d(0); d < argc; d++) {
00109                 std::cout << argv[d] << "\n";
00110         }
00111         if (argc != 2) {
00112                 std::cout << "Usage: DisplayTrack <input file>\n";
00113                 return 0;
00114         }
00115 
00116         signal(SIGINT, signalHandler);
00117         signal(SIGTERM, signalHandler);
00118 
00119         std::cout << "Recreating from root file...\n";
00120         char input[100];
00121         strcpy(input, argv[1]);
00122 
00123         //mtm2.recreateFromRootFile(input);
00124         std::cout << "Constructing ROOT application..." << std::endl;
00125         theApp = new TApplication("App", 0, 0);
00126         gROOT->Reset();
00127         gStyle->SetCanvasPreferGL(kTRUE);
00128         gStyle->SetPalette(1);
00129 
00130         std::cout << "Starting worker thread..." << std::endl;
00131 
00132         c = new TCanvas("c", "The Hello Canvas", 600, 600);
00133 
00134         TThread* guiTh = new TThread("guiTh", startSender, input);
00135         guiTh->Run();
00136 
00137         std::cout << "Starting gui..." << std::endl;
00138         while (!gSystem->ProcessEvents() && continueJob) {
00139                 //c->Modified();
00140                 //c->Update();
00141         }
00142 
00143         std::cout << "Terminating..." << std::endl;
00144 
00145         delete guiTh;
00146         delete theApp;
00147 }
00148 

Generated on Wed Mar 19 17:47:58 2008 for MapsTracks by  doxygen 1.5.2