Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Gismo.cxx

Go to the documentation of this file.
00001 //     $Id: Gismo.cxx,v 1.5 2001/01/23 03:41:32 burnett Exp $
00002 // Project: Gismo
00003 //  Author: Toby Burnett
00004 //
00005 
00006 #include "gismo/Gismo.h"
00007 
00008 #include "gui/DisplayControl.h"
00009 #include "gui/DisplayRep.h"
00010 #include "gui/PrintControl.h"
00011 
00012 #include "geometry/Track.h"
00013 #include "geomrep/TrackRep.h"
00014 
00015 
00016 #include "gismo/World.h"
00017 #include "gismo/Generator.h"
00018 #include "gismo/MCParticle.h"
00019 #include "gismo/Material.h"
00020 #include "gismo/PDT.h"
00021 #include <cassert>
00022 
00023 #include <stdio.h>   // for sprintf()
00024 
00026 // classes for display, print of the gismo generator
00027 class ParticleRep : public gui::DisplayRep
00028 {
00029     // Represent the particle trajectory and subsequent shower
00030 public:
00031     ParticleRep(const MCParticle & part);
00032     void update(){} // did it in the constructor
00033 };
00034 
00035 // can no inline because if recursion
00036 ParticleRep::ParticleRep(const MCParticle & part) {
00037   if(part.track() ) {
00038     append( TrackRep(*part.track()) );
00039   }
00040   for(int i=0; i< part.numChildren(); i++)
00041     append(ParticleRep( *(MCParticle*) part.child(i)));
00042 }
00043 
00044 class Gismo::DisplayEvent : public gui::DisplayRep {friend class Gismo;
00045 
00046     DisplayEvent(Gismo* gismo): m_gismo(gismo){}
00047     void update() {
00048         Generator* gen = m_gismo->event();
00049         if( gen ) {
00050             markerAt(gen->position());
00051             append(ParticleRep(*gen));
00052         }
00053     }
00054     Gismo* m_gismo;
00055 };
00056 
00057 class Gismo::PrintEvent : public gui::Command {friend class Gismo;
00058     PrintEvent(std::ostream* out):m_out(out){}
00059     void execute() { Gismo::instance()->event()->printOn(*m_out);}
00060     std::ostream* m_out;
00061 };
00062 class Gismo::PrintPDT : public gui::Command { friend class Gismo;
00063     PrintPDT(std::ostream* out):m_out(out){}
00064     void execute() { Gismo::instance()->event()->thePDT()->printOn(*m_out);}
00065     std::ostream* m_out;
00066 };
00067 class Gismo::PrintMaterials : public gui::Command { friend class Gismo;
00068     PrintMaterials(std::ostream* out):m_out(out){}
00069     void execute() { Material::printAll(*m_out);}
00070     std::ostream* m_out;
00071 };
00073 //  Constructor: setup everything!
00074 
00075 static float ke_cutoff = 0.0005f;   // 0.5 MeV
00076 static float max_step_size = 100; // 1000 cm
00077 
00078 Gismo::Gismo(float size, Generator* gen, gui::DisplayControl* dc)
00079 : m_world(new World(size))
00080 , m_generator(gen)
00081 {
00082     s_instance = this;
00083 
00084 
00085     // generic environment for interactive interface
00086     // ---------------------------------------------
00087 
00088     MCParticle::saveTrack = 10;   // number of generations that will be displayed
00089 
00090 
00091     // Set up display of detector, response, event
00092 
00093     dc->add( m_world->detectorViewer(),"Detector",  -1 );
00094     dc->add( m_world->responseViewer(), "Response",1 );
00095     dc->add( new DisplayEvent(this) ,  "Event"    ,1);
00096 
00097     // setup commands to print event, response
00098     gui::PrintControl* pc= gui::PrintControl::instance();
00099     pc->add( new PrintEvent( pc->out() ),  "Event"   );
00100     pc->add(m_world->responsePrinter(pc->out()), "Response"  );
00101 
00102     setKEcutoff(ke_cutoff);
00103     setMaxStep(max_step_size);
00104     addMaterialPath("PEGS4");
00105 
00106 }
00107 
00108 Gismo& Gismo::addMaterialPath(const char* path)
00109 {
00110     Material::addPath(path);
00111     return *this;
00112 }       
00113 Gismo& Gismo::addInteractor(Interactor* inter)
00114 {
00115     MCParticle::addInteractor(inter);
00116     return *this;
00117 }
00118 Gismo& Gismo::setKEcutoff(float e)
00119 {
00120     m_world->setKECutOff(e);
00121     return *this;
00122 }
00123 Gismo& Gismo::setMaxStep(float step)
00124 {   m_world->setMaxStep(step);
00125     return *this;
00126 }
00127 Gismo& Gismo::setGenerator(Generator* gen)
00128 {
00129     m_generator = gen;
00130     return *this;
00131 }
00132 
00133 Gismo& Gismo::setField(Field* field)
00134 {
00135     m_world->setField(field);
00136     return *this;
00137 }
00138 
00139 
00140 void
00141 Gismo::finishSetup()
00142 {
00143     gui::PrintControl* pc= gui::PrintControl::instance();
00144     pc->add(new PrintMaterials(pc->out()) , "Materials" );
00145     pc->add(new PrintPDT(pc->out()), "PDT"    );
00146 }
00147 
00148 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00149 //         singleton implementation
00150 Gismo* Gismo::s_instance=0;
00151 Gismo* Gismo::instance()
00152 {
00153     assert( s_instance );
00154     return s_instance;
00155 }
00156 
00157 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00158 //       create an event
00159 void Gismo::generate()
00160 {
00161     m_world->processEvent(*m_generator);
00162 }
00163 
00164 static char* itoa(int i)  //little local thing to format integers
00165 {   static char buf[20];
00166     sprintf(buf,"%d",i);
00167     return buf;
00168 }
00169 const char * Gismo::eventTitle()const
00170 {
00171     static std::string title;
00172     title = std::string("Generated  ");
00173     title+= m_generator->name();
00174     title+= ": event ";
00175     title+= itoa(m_generator->eventNumber());
00176     return title.c_str();
00177 }
00178 
00179 
00180 
00181 Generator*
00182 Gismo::event()const
00183 {
00184     return m_generator;
00185 }
00186 
00187 Gismo::~Gismo()
00188 // destructor: delete all Gismo stuff
00189 {
00190     delete GParticle::thePDT();
00191     delete m_world;
00192     Material::deleteAll();
00193 
00194 }

Generated at Wed Nov 21 12:20:25 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000