CMS 3D CMS Logo

VisCSCSegmentTwig.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "VisReco/VisMuonCSC/interface/VisCSCSegmentTwig.h"
00004 #include "VisReco/VisMuonCSC/interface/VisCSCChamberDrawer.h"
00005 #include "VisFramework/VisFrameworkBase/interface/VisTwigFactroyService.h"
00006 #include "VisFramework/VisFrameworkBase/interface/VisEventSelector.h"
00007 #include "VisFramework/VisFrameworkBase/interface/debug.h"
00008 #include "DataFormats/CSCRecHit/interface/CSCSegmentCollection.h"
00009 #include "DataFormats/CSCRecHit/interface/CSCSegment.h"
00010 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "FWCore/Framework/interface/EventSetup.h"
00013 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00014 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00015 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00016 #include "Geometry/CSCGeometry/interface/CSCLayer.h"
00017 #include "Geometry/CSCGeometry/interface/CSCLayerGeometry.h"
00018 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00019 #include "Iguana/Models/interface/IgTextRep.h"
00020 #include "Iguana/GLModels/interface/Ig3DRep.h"
00021 #include "Iguana/GLModels/interface/IgLegoRep.h"
00022 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00023 #include "Iguana/GLModels/interface/IgRZRep.h"
00024 #include "Iguana/Inventor/interface/IgSoArrow.h"
00025 #include "Iguana/Studio/interface/IgQtLock.h"
00026 #include <Inventor/nodes/SoCoordinate3.h>
00027 #include <Inventor/nodes/SoDrawStyle.h>
00028 #include <Inventor/nodes/SoMaterial.h>
00029 #include <Inventor/nodes/SoSeparator.h>
00030 #include <Inventor/nodes/SoLineSet.h>
00031 #include <classlib/utils/DebugAids.h>
00032 #include <qstring.h>
00033 #include <iostream>
00034 #include <iomanip>
00035 
00036 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00037 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00038 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00039 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00040 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00041 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00042 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00043 
00044 namespace 
00045 {
00046     VisQueuedTwig *
00047     createThisTwig (IgState *state, IgTwig *parent,
00048                     const std::string &name,
00049                     const std::string &friendlyName,
00050                     const std::string &modLabel,
00051                     const std::string &instanceName,
00052                     const std::string &processName)
00053     {
00054         return new VisCSCSegmentTwig (state, parent, "CSC Segments (" + name + ")", 
00055                                       friendlyName, modLabel, instanceName, processName);
00056     }
00057 }
00058 
00059 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00060 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00061 
00062 VisCSCSegmentTwig::VisCSCSegmentTwig (IgState *state, IgTwig *parent,
00063                                       const std::string &name /* = "" */,
00064                                       const std::string &friendlyName /* = "" */,
00065                                       const std::string &moduleLabel /* = "" */,
00066                                       const std::string &instanceName /* = "" */,
00067                                       const std::string &processName /* = "" */)
00068     : VisQueuedTwig (state, parent, name),
00069       m_text (name),
00070       m_friendlyName (friendlyName),
00071       m_moduleLabel (moduleLabel),
00072       m_instanceName (instanceName),
00073       m_processName (processName),
00074       m_lineThickness(0.F),
00075       m_lineThicknessEnvelope(2.0F),
00076       m_lineColor(0xFF000000),
00077       m_lineColorEnvelope(0xFF000000),
00078       m_envelopeFlag(true)
00079 {    
00080     VisTwigFactroyService *tfService = VisTwigFactroyService::get (state);
00081     if (! tfService)
00082     {
00083         tfService = new VisTwigFactroyService (state);
00084     }   
00085     edm::TypeID digiCollID (typeid (CSCSegmentCollection));
00086     tfService->registerTwig (digiCollID.friendlyClassName (), &createThisTwig);
00087 }
00088 
00089 void
00090 VisCSCSegmentTwig::onNewEvent (const edm::Event &event,
00091                                const edm::EventSetup &eventSetup)
00092 {
00093     // Get debugging dump.
00094     VisQueuedTwig::onNewEvent (event, eventSetup);
00095 
00096     m_segs.clear ();
00097     m_text = (QString ("Run # %1, event # %2")
00098               .arg (event.id ().run ())
00099               .arg (event.id ().event ()).latin1 ());
00100 
00101     std::vector<edm::Handle<CSCSegmentCollection> > segCollections;
00102     
00103     try
00104     {
00105         if ((! m_friendlyName.empty ()) || (! m_moduleLabel.empty ()) || (! m_instanceName.empty ()) || (! m_processName.empty ()))
00106         {
00107             VisEventSelector visSel (m_friendlyName, m_moduleLabel, m_instanceName, m_processName);
00108             event.getMany (visSel, segCollections);
00109         }
00110         else
00111         {
00112             event.getManyByType (segCollections);
00113         }
00114 
00115         eventSetup.get<MuonGeometryRecord> ().get (m_pDD);
00116     }
00117     catch (cms::Exception& e)
00118     {
00119         if (this->m_onCmsException)
00120             this->m_onCmsException (&e);
00121     }
00122     catch (lat::Error &e) 
00123     {
00124         if (this->m_onError)
00125             this->m_onError (&e);
00126     }
00127     catch (std::exception &e) 
00128     {
00129         if (this->m_onException)
00130             this->m_onException (&e);
00131     }
00132     catch (...) 
00133     {
00134         if (this->m_onUnhandledException)
00135             this->m_onUnhandledException ();
00136     }
00137 
00138     if (! segCollections.empty ())
00139     {
00140         std::vector<edm::Handle<CSCSegmentCollection> >::iterator i;
00141         std::vector<edm::Handle<CSCSegmentCollection> >::iterator iEnd;
00142         for (i = segCollections.begin (), iEnd = segCollections.end (); i != iEnd; ++i) 
00143         {
00144             const CSCSegmentCollection& c = *(*i);
00145     
00146             CSCSegmentCollection::const_iterator segIt;
00147             CSCSegmentCollection::const_iterator segItEnd;
00148             for (segIt = c.begin (), segItEnd = c.end (); segIt != segItEnd; ++segIt)
00149             {
00150                 m_segs.push_back (*segIt);
00151             }
00152         }
00153     }
00154     
00155     VisQueuedTwig::onBaseInvalidate ();
00156 }
00157 
00159 void
00160 VisCSCSegmentTwig::update (IgTextRep *rep) 
00161 {
00162     // Get debugging dump.
00163     VisQueuedTwig::update (rep);
00164 
00165     // Prepare the property description.
00166     std::ostringstream text;
00167     text << "Muon Endcap: CSC Track Segments<br>";
00168 
00169     if (! m_segs.empty () && m_pDD.isValid ())
00170     {
00171         try 
00172         {
00173             text << "<table width='100%' border=1>"
00174                  << "<TR align = center>"
00175                  << "<TH>Number</TH>"
00176                  << "<TH>dim</TH>"
00177                  << "<TH>position</TH>"
00178                  << "<TH>direction</TH>"
00179                  << "<TH>z [cm]</TH>"
00180                  << "<TH>phi [rad]</TH>"
00181                  << "<TH>chi2 / hits</TH>"
00182                  << "</TR>";
00183             text << setiosflags (std::ios::showpoint | std::ios::fixed);
00184             text.setf (std::ios::right, std::ios::adjustfield);
00185         
00186             int nSegments = 0;
00187         
00188             for (std::vector<CSCSegment>::const_iterator iseg = m_segs.begin (), isegEnd = m_segs.end (); iseg != isegEnd; ++iseg) 
00189             {
00190                 const GeomDet *det = m_pDD->idToDet ((*iseg).cscDetId ());
00191                 
00192                 GlobalPoint pos = det->surface ().toGlobal ((*iseg).localPosition ());
00193                 GlobalVector dir = det->surface ().toGlobal ((*iseg).localDirection ());
00194             
00195                 text << "<TR align = right>"
00196                      << "<TD>" << std::setw (2) << ++nSegments << "</TD>"
00197                      << "<TD>" << std::setw (1) << "(*iseg).dimension ()" << "</TD>"
00198                      << "<TD>" << std::setw (6) << std::setprecision (2) << pos << "</TD>"
00199                      << "<TD>" << std::setw (6) << std::setprecision (2) << dir << "</TD>"
00200                      << "<TD>" << std::setw (5) << std::setprecision (1) << pos.z () << "</TD>"
00201                      << "<TD>" << std::setw (6) << std::setprecision (3) << pos.phi () << "</TD>"
00202                      << "<TD>" << std::setw (6) << std::setprecision (2) << (*iseg).chi2 () 
00203                      << " / " << (*iseg).nRecHits () << "</TD>"
00204                      << "</TR>";    
00205             }
00206             text << "</table>";
00207         }
00208         catch (cms::Exception& e)
00209         {
00210             if (this->m_onCmsException)
00211                 this->m_onCmsException (&e);
00212         }
00213         catch (lat::Error &e) 
00214         {
00215             if (this->m_onError)
00216                 this->m_onError (&e);
00217         }
00218         catch (std::exception &e) 
00219         {
00220             if (this->m_onException)
00221                 this->m_onException (&e);
00222         }
00223         catch (...) 
00224         {
00225             if (this->m_onUnhandledException)
00226                 this->m_onUnhandledException ();
00227         }
00228     }
00229     
00230     // Send it over.
00231     IgQtLock ();
00232     rep->setText (text.str ());
00233 }
00234 
00236 void
00237 VisCSCSegmentTwig::update (Ig3DRep *rep)
00238 {
00239     // Get debugging dump.
00240     VisQueuedTwig::update (rep);
00241 
00242     IgQtLock ();
00243     rep->clear ();
00244     m_dets.clear ();
00245 
00246     SoSeparator *sep = new SoSeparator;    
00247     
00248     if (! m_segs.empty () && m_pDD.isValid ())
00249     {
00250         VisCSCChamberDrawer d;
00251 
00252         try 
00253         {
00254             //
00255             // Muon Endcap Segment
00256             // 
00257             int nVtx = 0;
00258             SoCoordinate3 *pts = new SoCoordinate3;
00259 
00260             for (std::vector<CSCSegment>::const_iterator iseg = m_segs.begin (), isegEnd = m_segs.end (); iseg != isegEnd; ++iseg) 
00261             {
00262                 const CSCDetId& id = (*iseg).cscDetId();
00263                 const GeomDet *det = m_pDD->idToDet (id);
00264                 
00265                 // This is a frame around the (active) layer
00266                 if (m_dets.find(id) == m_dets.end() )
00267                 {
00268                     m_dets.insert(id);  
00269                     // This is a frame around the (active) layer
00270                     d.getOutline(sep, m_pDD, id);
00271                 }
00272                                     
00273                 // Local pos & dir
00274                 LocalPoint  pos = (*iseg).localPosition();
00275                 LocalVector dir = (*iseg).localDirection();
00276 
00277                 // Chamber thickness (in z)
00278                 float halfThickness = det->surface ().bounds ().thickness () / 2.;
00279                 
00280                 
00281                 float z1 = halfThickness;
00282                 float x1 = pos.x() + dir.x()*z1/dir.z();
00283                 float y1 = pos.y() + dir.y()*z1/dir.z();
00284                 GlobalPoint g1 = det->surface().toGlobal( LocalPoint(x1,y1,z1) );
00285 
00286                 float z2 = -halfThickness;
00287                 float x2 = pos.x() + dir.x()*z2/dir.z();
00288                 float y2 = pos.y() + dir.y()*z2/dir.z();
00289                 GlobalPoint g2 = det->surface().toGlobal( LocalPoint(x2,y2,z2) );
00290                 
00291                 SbVec3f ptA( g1.x(), g1.y(), g1.z() );
00292                 ptA *= 0.01F; // cm -> m
00293                 
00294                 
00295                 pts->point.set1Value ( nVtx++, ptA );
00296                 SbVec3f ptB( g2.x(), g2.y(), g2.z() );
00297                 ptB *= 0.01F; // cm->m
00298                 
00299                 pts->point.set1Value ( nVtx++, ptB );
00300                 
00301             }
00302             sep->addChild(pts);
00303             
00304         }
00305         catch (cms::Exception& e)
00306         {
00307             if (this->m_onCmsException)
00308                 this->m_onCmsException (&e);
00309         }
00310         catch (lat::Error &e) 
00311         {
00312             if (this->m_onError)
00313                 this->m_onError (&e);
00314         }
00315         catch (std::exception &e) 
00316         {
00317             if (this->m_onException)
00318                 this->m_onException (&e);
00319         }
00320         catch (...) 
00321         {
00322             if (this->m_onUnhandledException)
00323                 this->m_onUnhandledException ();
00324         }
00325     }
00326     
00327     rep->clear ();
00328     rep->node ()->addChild (sep);
00329 }
00330 
00332 void
00333 VisCSCSegmentTwig::update (IgLegoRep *rep)
00334 {}
00335 
00337 void
00338 VisCSCSegmentTwig::update (IgRPhiRep *rep)
00339 {
00340    // Get debugging dump.
00341     VisQueuedTwig::update (rep);
00342 
00343     IgQtLock ();
00344 
00345     SoSeparator *sep = new SoSeparator;
00346     SoMaterial *mat = new SoMaterial;
00347     mat->ambientColor.setValue (0.135, 0.2225, 0.1575);
00348 
00349     mat->diffuseColor.setValue (1.00, 0.28, 0.49); // light red
00350 
00351     mat->specularColor.setValue (0.316228, 0.316228, 0.316228);
00352     mat->emissiveColor.setValue(0.0, 0.0, 0.0);
00353     mat->shininess = 0.1;
00354     sep->addChild (mat);
00355 
00356     SoDrawStyle *sty = new SoDrawStyle;
00357     sty->style = SoDrawStyle::LINES;
00358     sty->lineWidth.setValue (1.0);
00359     sep->addChild (sty);
00360     
00361     if (! m_segs.empty () && m_pDD.isValid ())
00362     {
00363         try 
00364         {
00365             //
00366             // Muon Endcap Segment
00367             // 
00368         
00369             for (std::vector<CSCSegment>::const_iterator iseg = m_segs.begin (), isegEnd = m_segs.end (); iseg != isegEnd; ++iseg) 
00370             {
00371                 const GeomDet *det = m_pDD->idToDet ((*iseg).cscDetId ());
00372                 
00373                 // Local pos & dir
00374                 LocalPoint  pos = (*iseg).localPosition ();
00375                 LocalVector dir = (*iseg).localDirection ();
00376 
00377                 // Chamber thickness (in z)
00378                 float halfThickness = det->surface ().bounds ().thickness ()/2.;
00379                 
00380                 SoVertexProperty *vtx = new SoVertexProperty;
00381                 
00382                 SoLineSet *line = new SoLineSet;
00383                 line->numVertices = 2;
00384                 
00385                 float z1 = halfThickness;
00386                 float x1 = pos.x() + dir.x()*z1/dir.z();
00387                 float y1 = pos.y() + dir.y()*z1/dir.z();
00388                 GlobalPoint g1 = det->surface().toGlobal( LocalPoint(x1,y1,z1) );
00389 
00390                 float z2 = -halfThickness;
00391                 float x2 = pos.x() + dir.x()*z2/dir.z();
00392                 float y2 = pos.y() + dir.y()*z2/dir.z();
00393                 GlobalPoint g2 = det->surface().toGlobal( LocalPoint(x2,y2,z2) );
00394                 
00395                 float x = g1.x () / 100.0;  // cm -> m
00396                 float y = g1.y () / 100.0;  // cm -> m
00397                 float z = g1.z () / 100.0;  // cm -> m
00398                 
00399                 vtx->vertex.set1Value(0,SbVec3f(x,y,z));
00400                 
00401                 x = g2.x () / 100.0;  // cm -> m
00402                 y = g2.y () / 100.0;  // cm -> m
00403                 z = g2.z () / 100.0;  // cm -> m
00404                 
00405                 vtx->vertex.set1Value(1,SbVec3f(x,y,z));
00406                 
00407                 line->vertexProperty = vtx;
00408                 
00409                 sep->addChild (line);           
00410             }
00411         }
00412         catch (cms::Exception& e)
00413         {
00414             if (this->m_onCmsException)
00415                 this->m_onCmsException (&e);
00416         }
00417         catch (lat::Error &e) 
00418         {
00419             if (this->m_onError)
00420                 this->m_onError (&e);
00421         }
00422         catch (std::exception &e) 
00423         {
00424             if (this->m_onException)
00425                 this->m_onException (&e);
00426         }
00427         catch (...) 
00428         {
00429             if (this->m_onUnhandledException)
00430                 this->m_onUnhandledException ();
00431         }
00432     }
00433     
00434     rep->clear ();
00435     rep->node ()->addChild (sep);
00436 }
00437 
00439 void
00440 VisCSCSegmentTwig::update (IgRZRep *rep)
00441 {
00442    // Get debugging dump.
00443     VisQueuedTwig::update (rep);
00444 
00445     IgQtLock ();
00446 
00447     SoSeparator *sep = new SoSeparator;
00448     SoMaterial *mat = new SoMaterial;
00449     mat->ambientColor.setValue (0.135, 0.2225, 0.1575);
00450 
00451     mat->diffuseColor.setValue (1.00, 0.28, 0.49); //light red
00452 
00453     mat->specularColor.setValue (0.316228, 0.316228, 0.316228);
00454     mat->emissiveColor.setValue(0.0, 0.0, 0.0);
00455     mat->shininess = 0.1;
00456     sep->addChild (mat);
00457 
00458     SoDrawStyle *sty = new SoDrawStyle;
00459     sty->style = SoDrawStyle::LINES;
00460     sty->lineWidth.setValue (6.0);
00461     sep->addChild (sty);
00462     
00463     if (! m_segs.empty () && m_pDD.isValid ())
00464     {
00465         try 
00466         {
00467             //
00468             // Muon Endcap Segment
00469             // 
00470         
00471             for (std::vector<CSCSegment>::const_iterator iseg = m_segs.begin (), isegEnd = m_segs.end (); iseg != isegEnd; ++iseg) 
00472             {
00473                 const GeomDet *det = m_pDD->idToDet ((*iseg).cscDetId ());
00474                 
00475                 // Local pos & dir
00476                 LocalPoint  pos = (*iseg).localPosition();
00477                 LocalVector dir = (*iseg).localDirection();
00478 
00479                 // Chamber thickness (in z)
00480                 float halfThickness = det->surface ().bounds ().thickness () / 2.;
00481                 
00482                 SoVertexProperty *vtx = new SoVertexProperty;
00483                 
00484                 SoLineSet *line = new SoLineSet;
00485                 line->numVertices = 2;
00486                 
00487                 float z1 = halfThickness;
00488                 float x1 = pos.x() + dir.x()*z1/dir.z();
00489                 float y1 = pos.y() + dir.y()*z1/dir.z();
00490                 GlobalPoint g1 = det->surface().toGlobal( LocalPoint(x1,y1,z1) );
00491 
00492                 float z2 = -halfThickness;
00493                 float x2 = pos.x() + dir.x()*z2/dir.z();
00494                 float y2 = pos.y() + dir.y()*z2/dir.z();
00495                 GlobalPoint g2 = det->surface().toGlobal( LocalPoint(x2,y2,z2) );
00496                 
00497                 float x = g1.x () / 100.0;  // cm -> m
00498                 float y = g1.y () / 100.0;  // cm -> m
00499                 float z = g1.z () / 100.0;  // cm -> m
00500                 
00501                 vtx->vertex.set1Value(0,SbVec3f(x,y,z));
00502                 
00503                 x = g2.x () / 100.0;  // cm -> m
00504                 y = g2.y () / 100.0;  // cm -> m
00505                 z = g2.z () / 100.0;  // cm -> m
00506                 
00507                 vtx->vertex.set1Value(1,SbVec3f(x,y,z));
00508                 
00509                 line->vertexProperty = vtx;
00510                 
00511                 sep->addChild (line);           
00512             }
00513         }
00514         catch (cms::Exception& e)
00515         {
00516             if (this->m_onCmsException)
00517                 this->m_onCmsException (&e);
00518         }
00519         catch (lat::Error &e) 
00520         {
00521             if (this->m_onError)
00522                 this->m_onError (&e);
00523         }
00524         catch (std::exception &e) 
00525         {
00526             if (this->m_onException)
00527                 this->m_onException (&e);
00528         }
00529         catch (...) 
00530         {
00531             if (this->m_onUnhandledException)
00532                 this->m_onUnhandledException ();
00533         }
00534     }
00535     
00536     rep->clear ();
00537     rep->node ()->addChild (sep);
00538 }
00539 

Generated on Tue Jun 9 17:50:21 2009 for CMSSW by  doxygen 1.5.4