00001
00002
00003 #include "VisSimulation/VisSimHits/interface/VisSimVertexTwig.h"
00004 #include "VisFramework/VisFrameworkBase/interface/VisTwigFactroyService.h"
00005 #include "VisFramework/VisFrameworkBase/interface/VisEventSelector.h"
00006 #include "VisFramework/VisFrameworkBase/interface/debug.h"
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "FWCore/Framework/interface/EventSetup.h"
00009 #include "SimDataFormats/Vertex/interface/SimVertex.h"
00010 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
00011 #include "Iguana/Studio/interface/IgQtLock.h"
00012 #include "Iguana/Framework/interface/IgRepSet.h"
00013 #include "Iguana/GLModels/interface/Ig3DRep.h"
00014 #include "Iguana/GLModels/interface/IgLegoRep.h"
00015 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00016 #include "Iguana/GLModels/interface/IgRZRep.h"
00017 #include "Iguana/Models/interface/IgTextRep.h"
00018 #include <Inventor/nodes/SoSeparator.h>
00019 #include <Inventor/nodes/SoDrawStyle.h>
00020 #include <Inventor/nodes/SoMaterial.h>
00021 #include <Inventor/nodes/SoPointSet.h>
00022 #include <Inventor/nodes/SoVertexProperty.h>
00023 #include <qstring.h>
00024 #include <iostream>
00025 #include <iomanip>
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 namespace
00037 {
00038 VisQueuedTwig *
00039 createThisTwig (IgState *state, IgTwig *parent,
00040 const std::string &name,
00041 const std::string &friendlyName,
00042 const std::string &modLabel,
00043 const std::string &instanceName,
00044 const std::string &processName)
00045 {
00046 return new VisSimVertexTwig (state, parent, name, friendlyName, modLabel, instanceName, processName);
00047 }
00048 }
00049
00050
00051
00052 VisSimVertexTwig::VisSimVertexTwig (IgState *state, IgTwig *parent, const std::string &name ,
00053 const std::string &friendlyName ,
00054 const std::string &moduleLabel ,
00055 const std::string &instanceName ,
00056 const std::string &processName )
00057 : VisQueuedTwig (state, parent, name),
00058 m_text (name),
00059 m_friendlyName (friendlyName),
00060 m_moduleLabel (moduleLabel),
00061 m_instanceName (instanceName),
00062 m_processName (processName)
00063 {
00064 VisTwigFactroyService *tfService = VisTwigFactroyService::get (state);
00065 if (! tfService)
00066 {
00067 tfService = new VisTwigFactroyService (state);
00068 }
00069 edm::TypeID simVertexID (typeid (edm::SimVertexContainer));
00070 tfService->registerTwig (simVertexID.friendlyClassName (), &createThisTwig);
00071 }
00072
00073 void
00074 VisSimVertexTwig::onNewEvent (const edm::Event &event,
00075 const edm::EventSetup &eventSetup)
00076 {
00077 LOG (1, trace, LFfwvis, "VisSimVertexTwig[" << name ()
00078 << "]::onNewEvent()\n");
00079
00080 VisQueuedTwig::onBaseInvalidate ();
00081
00082 m_vertices.clear ();
00083 m_text = (QString ("Run # %1, event # %2")
00084 .arg (event.id ().run ())
00085 .arg (event.id ().event ()).latin1 ());
00086
00087 std::vector<edm::Handle<edm::SimVertexContainer> > vertexCollections;
00088
00089 try
00090 {
00091 if ((! m_friendlyName.empty ()) || (! m_moduleLabel.empty ()) || (! m_instanceName.empty ()) || (! m_processName.empty ()))
00092 {
00093 VisEventSelector visSel (m_friendlyName, m_moduleLabel, m_instanceName, m_processName);
00094 event.getMany (visSel, vertexCollections);
00095 }
00096 else
00097 {
00098 event.getManyByType (vertexCollections);
00099 }
00100 }
00101 catch (...)
00102 {
00103 }
00104
00105 if (! vertexCollections.empty ())
00106 {
00107 std::vector<edm::Handle<edm::SimVertexContainer> >::iterator i;
00108 for (i = vertexCollections.begin (); i != vertexCollections.end (); i++)
00109 {
00110 const edm::SimVertexContainer& c = *(*i);
00111
00112 for (std::vector<SimVertex>::const_iterator isim = c.begin ();
00113 isim != c.end (); ++isim)
00114 {
00115 m_vertices.push_back ((*isim));
00116 }
00117 }
00118 }
00119
00120 IgRepSet::invalidate (this, SELF_MASK);
00121 }
00122
00123 void
00124 VisSimVertexTwig::update (IgTextRep *rep)
00125 {
00126
00127 VisQueuedTwig::update (rep);
00128
00129
00130 std::ostringstream text;
00131 text << "Total " << m_vertices.size () << " vertices from";
00132 text << " run: " << m_text << "<br>";
00133
00134 text << "<table width='100%' border=1>"
00135 << "<TR align = center>"
00136 << "<TH>Number</TH>"
00137 << "<TH>Position</TH>"
00138 << "<TH>Parent Index</TH>"
00139 << "</TR>";
00140 text << setiosflags (std::ios::showpoint | std::ios::fixed);
00141 text.setf (std::ios::right, std::ios::adjustfield);
00142
00143 if ((! m_vertices.empty ()))
00144 {
00145 int nVertices = 0;
00146 try
00147 {
00148 for (std::vector<SimVertex>::const_iterator i = m_vertices.begin (); i != m_vertices.end (); ++i)
00149 {
00150 text << "<TR align = right>"
00151 << "<TD>" << std::setw (3) << nVertices++ << "</TD>"
00152 << "<TD>" << std::setw (3) << "(" << ((*i).position ().x () / 100.0) << ", "
00153 << ((*i).position ().y () / 100.0) << ", "
00154 << ((*i).position ().z () / 100.0) << ")</TD>"
00155 << "<TD>" << std::setw (3) << (*i).parentIndex () << "</TD></TR>";
00156 }
00157 }
00158 catch (...)
00159 {
00160 text << "No SimVertices.<br>";
00161 }
00162 text << "</table>";
00163 }
00164
00165
00166 IgQtLock ();
00167 rep->setText (text.str ());
00168 }
00169
00170 void
00171 VisSimVertexTwig::update (Ig3DRep *rep)
00172 {
00173
00174 VisQueuedTwig::update (rep);
00175 IgQtLock ();
00176 rep->clear ();
00177
00178 if ((! m_vertices.empty ()))
00179 {
00180 SoMaterial *mat = new SoMaterial;
00181 mat->diffuseColor.setValue (1.0, 0.0, 1.0);
00182 mat->emissiveColor.setValue(1.0, 0.0, 1.0);
00183
00184 SoDrawStyle *drawStyle = new SoDrawStyle;
00185 drawStyle->pointSize = 2.0;
00186
00187 SoSeparator *sep = new SoSeparator;
00188 sep->addChild (mat);
00189 sep->addChild (drawStyle);
00190
00191 try
00192 {
00193 SoVertexProperty *vertices = new SoVertexProperty;
00194 int nVrtx = 0;
00195
00196 for (std::vector<SimVertex>::const_iterator i = m_vertices.begin (); i != m_vertices.end (); ++i)
00197 {
00198 vertices->vertex.set1Value (nVrtx++, SbVec3f ((*i).position ().x () / 100.0, (*i).position ().y () / 100.0, (*i).position ().z () / 100.0));
00199 }
00200 vertices->vertex.setNum (nVrtx);
00201 SoPointSet *points = new SoPointSet;
00202 points->vertexProperty.setValue (vertices);
00203 points->numPoints.setValue (nVrtx);
00204
00205 sep->addChild (points);
00206 }
00207 catch (...)
00208 {
00209 }
00210 rep->node ()->addChild (sep);
00211 }
00212 }
00213
00214 void
00215 VisSimVertexTwig::update (IgLegoRep *rep)
00216 {
00217
00218 VisQueuedTwig::update (rep);
00219 }
00220
00221 void
00222 VisSimVertexTwig::update (IgRPhiRep *rep)
00223 {
00224
00225 VisQueuedTwig::update (rep);
00226 }
00227
00228 void
00229 VisSimVertexTwig::update (IgRZRep *rep)
00230 {
00231
00232 VisQueuedTwig::update (rep);
00233 }
00234