CMS 3D CMS Logo

VisCSCRecHit2DTwig.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "VisReco/VisMuonCSC/interface/VisCSCRecHit2DTwig.h"
00004 #include "VisFramework/VisFrameworkBase/interface/VisTwigFactroyService.h"
00005 #include "VisFramework/VisFrameworkBase/interface/VisEventSelector.h"
00006 #include "VisFramework/VisFrameworkBase/interface/debug.h"
00007 #include "DataFormats/CSCRecHit/interface/CSCRecHit2DCollection.h"
00008 #include "DataFormats/CSCRecHit/interface/CSCRecHit2D.h"
00009 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00010 #include "FWCore/Framework/interface/Event.h"
00011 #include "FWCore/Framework/interface/EventSetup.h"
00012 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00013 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00014 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00015 #include "Geometry/CSCGeometry/interface/CSCLayer.h"
00016 #include "Geometry/CSCGeometry/interface/CSCLayerGeometry.h"
00017 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00018 #include "Iguana/Models/interface/IgTextRep.h"
00019 #include "Iguana/GLModels/interface/Ig3DRep.h"
00020 #include "Iguana/GLModels/interface/IgLegoRep.h"
00021 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00022 #include "Iguana/GLModels/interface/IgRZRep.h"
00023 #include "Iguana/Inventor/interface/IgSo3DErrorBar.h"
00024 #include "Iguana/Studio/interface/IgQtLock.h"
00025 #include <Inventor/nodes/SoDrawStyle.h>
00026 #include <Inventor/nodes/SoMaterial.h>
00027 #include <Inventor/nodes/SoSeparator.h>
00028 #include <classlib/utils/DebugAids.h>
00029 #include <qstring.h>
00030 #include <iostream>
00031 #include <sstream>
00032 #include <iomanip>
00033 
00034 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00035 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00036 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00037 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00038 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00039 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00040 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00041 
00042 namespace 
00043 {
00044     VisQueuedTwig *
00045     createThisTwig (IgState *state, IgTwig *parent,
00046                     const std::string &name,
00047                     const std::string &friendlyName,
00048                     const std::string &modLabel,
00049                     const std::string &instanceName,
00050                     const std::string &processName)
00051     {
00052         return new VisCSCRecHit2DTwig (state, parent, "CSC Rec Hits 2D (" + name + ")", 
00053                                        friendlyName, modLabel, instanceName, processName);
00054     }
00055 }
00056 
00057 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00058 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00059 
00060 VisCSCRecHit2DTwig::VisCSCRecHit2DTwig (IgState *state, IgTwig *parent,
00061                                         const std::string &name /* = "" */,
00062                                         const std::string &friendlyName /* = "" */,
00063                                         const std::string &moduleLabel /* = "" */,
00064                                         const std::string &instanceName /* = "" */,
00065                                         const std::string &processName /* = "" */)
00066     : VisQueuedTwig (state, parent, name),
00067       m_text (name),
00068       m_friendlyName (friendlyName),
00069       m_moduleLabel (moduleLabel),
00070       m_instanceName (instanceName),
00071       m_processName (processName)
00072 {
00073     VisTwigFactroyService *tfService = VisTwigFactroyService::get (state);
00074     if (! tfService)
00075     {
00076         tfService = new VisTwigFactroyService (state);
00077     }   
00078     edm::TypeID digiCollID (typeid (CSCRecHit2DCollection));
00079     tfService->registerTwig (digiCollID.friendlyClassName (), &createThisTwig);
00080 }
00081 
00082 void
00083 VisCSCRecHit2DTwig::onNewEvent (const edm::Event &event,
00084                                const edm::EventSetup &eventSetup)
00085 {
00086     // Get debugging dump.
00087     VisQueuedTwig::onNewEvent (event, eventSetup);
00088 
00089     m_rechits.clear ();
00090     m_text = (QString ("Run # %1, event # %2")
00091               .arg (event.id ().run ())
00092               .arg (event.id ().event ()).latin1 ());
00093 
00094     std::vector<edm::Handle<CSCRecHit2DCollection> > hitCollections;
00095     
00096     try
00097     {
00098         if ((! m_friendlyName.empty ()) || (! m_moduleLabel.empty ()) || (! m_instanceName.empty ()) || (! m_processName.empty ()))
00099         {
00100             VisEventSelector visSel (m_friendlyName, m_moduleLabel, m_instanceName, m_processName);
00101             event.getMany (visSel, hitCollections);
00102         }
00103         else
00104         {
00105             event.getManyByType (hitCollections);
00106         }
00107 
00108         eventSetup.get<MuonGeometryRecord> ().get (m_pDD);
00109     }
00110     catch (cms::Exception& e)
00111     {
00112         if (this->m_onCmsException)
00113             this->m_onCmsException (&e);
00114     }
00115     catch (lat::Error &e) 
00116     {
00117         if (this->m_onError)
00118             this->m_onError (&e);
00119     }
00120     catch (std::exception &e) 
00121     {
00122         if (this->m_onException)
00123             this->m_onException (&e);
00124     }
00125     catch (...) 
00126     {
00127         if (this->m_onUnhandledException)
00128             this->m_onUnhandledException ();
00129     }
00130 
00131     if (! hitCollections.empty ())
00132     {
00133         std::vector<edm::Handle<CSCRecHit2DCollection> >::iterator i;
00134         std::vector<edm::Handle<CSCRecHit2DCollection> >::iterator iEnd;
00135         for (i = hitCollections.begin (), iEnd = hitCollections.end (); i != iEnd; ++i) 
00136         {
00137             const CSCRecHit2DCollection& c = *(*i);
00138     
00139             CSCRecHit2DCollection::const_iterator hitIt;
00140             CSCRecHit2DCollection::const_iterator hitItEnd;
00141             for (hitIt = c.begin (), hitItEnd = c.end (); hitIt != hitItEnd; ++hitIt)
00142             {
00143                 m_rechits.push_back (*hitIt);
00144             }
00145         }
00146     }
00147     
00148     VisQueuedTwig::onBaseInvalidate ();
00149 }
00150 
00152 void
00153 VisCSCRecHit2DTwig::update (IgTextRep *rep) 
00154 {
00155     // Get debugging dump.
00156     VisQueuedTwig::update (rep);
00157 
00158     // Prepare the property description.
00159     std::ostringstream text;
00160     text << "Muon Endcap: CSC Rec Hits 2D<br>";
00161 
00162     text << "<table width='100%' border=1>"
00163          << "<TR align = center>"
00164          << "<TH>Number</TH>"
00165          << "<TH>position</TH>"
00166          << "<TH>Error Within Strip</TH>"
00167          << "</TR>";
00168     text << setiosflags (std::ios::showpoint | std::ios::fixed);
00169     text.setf (std::ios::right,std::ios::adjustfield);
00170 
00171     if (! m_rechits.empty () && m_pDD.isValid ())
00172     {
00173         try 
00174         {
00175             int nRecHits = 0;
00176         
00177             for (std::vector<CSCRecHit2D>::const_iterator ihit = m_rechits.begin (), ihitEnd = m_rechits.end (); ihit != ihitEnd; ++ihit) 
00178             {
00179                 const GeomDetUnit *det = m_pDD->idToDetUnit ((*ihit).cscDetId ());
00180                 
00181                 GlobalPoint pos = det->surface ().toGlobal ((*ihit).localPosition ());
00182             
00183                 text << "<TR align = right>"
00184                      << "<TD>" << std::setw (2) << nRecHits++ << "</TD>"
00185                      << "<TD>" << std::setw (6) << std::setprecision (2) << pos << "</TD>"
00186                      << "<TD>" << std::setw (6) << std::setprecision (2) << (*ihit).errorWithinStrip () << "</TD>"
00187                      << "</TR>";    
00188             }
00189         }
00190         catch (cms::Exception& e)
00191         {
00192             if (this->m_onCmsException)
00193                 this->m_onCmsException (&e);
00194         }
00195         catch (lat::Error &e) 
00196         {
00197             if (this->m_onError)
00198                 this->m_onError (&e);
00199         }
00200         catch (std::exception &e) 
00201         {
00202             if (this->m_onException)
00203                 this->m_onException (&e);
00204         }
00205         catch (...) 
00206         {
00207             if (this->m_onUnhandledException)
00208                 this->m_onUnhandledException ();
00209         }
00210     }
00211     text << "</table>";
00212     
00213     // Send it over.
00214     IgQtLock ();
00215     rep->setText (text.str ());
00216 }
00217 
00219 void
00220 VisCSCRecHit2DTwig::update (Ig3DRep *rep)
00221 {
00222     // Get debugging dump.
00223     VisQueuedTwig::update (rep);
00224 
00225     IgQtLock ();
00226 
00227     SoSeparator *sep = new SoSeparator;
00228     SoMaterial *mat = new SoMaterial;
00229     mat->ambientColor.setValue (0.135, 0.2225, 0.1575);
00230     mat->diffuseColor.setValue (0.54, 0.89, 0.63); // pale green
00231     mat->specularColor.setValue (0.316228, 0.316228, 0.316228);
00232     mat->emissiveColor.setValue(0.0, 0.0, 0.0);
00233     mat->shininess = 0.1;
00234     sep->addChild (mat);
00235     
00236     if (! m_rechits.empty () && m_pDD.isValid ())
00237     {
00238         try 
00239         {
00240             //
00241             // Muon Endcap Rechits
00242             // 
00243         
00244             for (std::vector<CSCRecHit2D>::const_iterator is = m_rechits.begin (), isEnd = m_rechits.end (); is != isEnd; ++is) 
00245             {
00246                 const GeomDetUnit *det = m_pDD->idToDetUnit ((*is).cscDetId ());
00247                 
00248 //              GlobalPoint pos = det->surface ().toGlobal ((*is).localPosition ());
00249             
00250 //              float x = pos.x () / 100.0;  // cm -> m
00251 //              float y = pos.y () / 100.0;  // cm -> m
00252 //              float z = pos.z () / 100.0;  // cm -> m
00253                 
00254                 LocalPoint xyzLocal = is->localPosition ();
00255                 float x = xyzLocal.x ();
00256                 float y = xyzLocal.y ();
00257                 float z = xyzLocal.z ();
00258                 float dx = std::sqrt( is->localPositionError ().xx () );
00259                 float dy = std::sqrt( is->localPositionError ().yy () );
00260                 
00261                 IgSo3DErrorBar *errorBar = new IgSo3DErrorBar;
00262                 GlobalPoint gp;
00263                 gp = det->surface ().toGlobal (LocalPoint (x - dx, y, z));
00264                 errorBar->u1.setValue (gp.x () / 100.0, gp.y () / 100.0, gp.z () / 100.0);
00265                 gp = det->surface ().toGlobal (LocalPoint (x + dx, y, z));
00266                 errorBar->u2.setValue (gp.x () / 100.0, gp.y () / 100.0, gp.z () / 100.0);
00267                 gp = det->surface ().toGlobal (LocalPoint (x, y - dy, z));
00268                 errorBar->v1.setValue (gp.x () / 100.0, gp.y () / 100.0, gp.z () / 100.0);
00269                 gp = det->surface ().toGlobal (LocalPoint (x, y + dy, z));
00270                 errorBar->v2.setValue (gp.x () / 100.0, gp.y () / 100.0, gp.z () / 100.0);
00271                 gp = det->surface ().toGlobal (xyzLocal); // no error in z
00272                 errorBar->w1.setValue (gp.x () / 100.0, gp.y () / 100.0, gp.z () / 100.0);
00273                 errorBar->w2.setValue (gp.x () / 100.0, gp.y () / 100.0, gp.z () / 100.0);
00274 
00275                 errorBar->lineWidth.setValue (1.0);
00276                 
00277                 sep->addChild (errorBar);
00278             }
00279         }
00280         catch (cms::Exception& e)
00281         {
00282             if (this->m_onCmsException)
00283                 this->m_onCmsException (&e);
00284         }
00285         catch (lat::Error &e) 
00286         {
00287             if (this->m_onError)
00288                 this->m_onError (&e);
00289         }
00290         catch (std::exception &e) 
00291         {
00292             if (this->m_onException)
00293                 this->m_onException (&e);
00294         }
00295         catch (...) 
00296         {
00297             if (this->m_onUnhandledException)
00298                 this->m_onUnhandledException ();
00299         }
00300     }
00301     
00302     rep->clear ();
00303     rep->node ()->addChild (sep);
00304 }
00305 
00307 void
00308 VisCSCRecHit2DTwig::update (IgLegoRep *rep)
00309 {}
00310 
00312 void
00313 VisCSCRecHit2DTwig::update (IgRPhiRep *rep)
00314 {
00315 
00316     // Get debugging dump.
00317     VisQueuedTwig::update (rep);
00318 
00319     IgQtLock ();
00320 
00321     SoSeparator *sep = new SoSeparator;
00322     SoMaterial *mat = new SoMaterial;
00323     mat->ambientColor.setValue (0.135, 0.2225, 0.1575);
00324     mat->diffuseColor.setValue (0.54, 0.89, 0.63);
00325     mat->specularColor.setValue (0.316228, 0.316228, 0.316228);
00326     mat->emissiveColor.setValue(0.0, 0.0, 0.0);
00327     mat->shininess = 0.1;
00328     sep->addChild (mat);
00329     
00330     if (! m_rechits.empty () && m_pDD.isValid ())
00331     {
00332         try 
00333         {
00334             //
00335             // Muon Endcap Rechits
00336             // 
00337         
00338             for (std::vector<CSCRecHit2D>::const_iterator is = m_rechits.begin (), isEnd = m_rechits.end (); is != isEnd; ++is) 
00339             {
00340                 const GeomDetUnit *det = m_pDD->idToDetUnit ((*is).cscDetId ());
00341                 
00342 //              GlobalPoint pos = det->surface ().toGlobal ((*is).localPosition ());
00343             
00344 //              float x = pos.x () / 100.0;  // cm -> m
00345 //              float y = pos.y () / 100.0;  // cm -> m
00346 //              float z = pos.z () / 100.0;  // cm -> m
00347                 
00348                 LocalPoint xyzLocal = is->localPosition ();
00349                 float x = xyzLocal.x ();
00350                 float y = xyzLocal.y ();
00351                 float z = xyzLocal.z ();
00352                 float dx = std::sqrt( is->localPositionError ().xx () );
00353                 float dy = std::sqrt( is->localPositionError ().yy () );
00354                 
00355                 IgSo3DErrorBar *errorBar = new IgSo3DErrorBar;
00356                 GlobalPoint gp;
00357                 gp = det->surface ().toGlobal (LocalPoint (x - dx, y, z));
00358                 errorBar->u1.setValue (gp.x () / 100.0, gp.y () / 100.0, gp.z () / 100.0);
00359                 gp = det->surface ().toGlobal (LocalPoint (x + dx, y, z));
00360                 errorBar->u2.setValue (gp.x () / 100.0, gp.y () / 100.0, gp.z () / 100.0);
00361                 gp = det->surface ().toGlobal (LocalPoint (x, y - dy, z));
00362                 errorBar->v1.setValue (gp.x () / 100.0, gp.y () / 100.0, gp.z () / 100.0);
00363                 gp = det->surface ().toGlobal (LocalPoint (x, y + dy, z));
00364                 errorBar->v2.setValue (gp.x () / 100.0, gp.y () / 100.0, gp.z () / 100.0);
00365                 gp = det->surface ().toGlobal (xyzLocal); // no error in z
00366                 errorBar->w1.setValue (gp.x () / 100.0, gp.y () / 100.0, gp.z () / 100.0);
00367                 errorBar->w2.setValue (gp.x () / 100.0, gp.y () / 100.0, gp.z () / 100.0);
00368 
00369                 errorBar->lineWidth.setValue (1.0);
00370                 
00371                 sep->addChild (errorBar);
00372             }
00373         }
00374         catch (cms::Exception& e)
00375         {
00376             if (this->m_onCmsException)
00377                 this->m_onCmsException (&e);
00378         }
00379         catch (lat::Error &e) 
00380         {
00381             if (this->m_onError)
00382                 this->m_onError (&e);
00383         }
00384         catch (std::exception &e) 
00385         {
00386             if (this->m_onException)
00387                 this->m_onException (&e);
00388         }
00389         catch (...) 
00390         {
00391             if (this->m_onUnhandledException)
00392                 this->m_onUnhandledException ();
00393         }
00394     }
00395     
00396     rep->clear ();
00397     rep->node ()->addChild (sep);
00398 }
00399 
00401 void
00402 VisCSCRecHit2DTwig::update (IgRZRep *rep)
00403 {
00404     // Get debugging dump.
00405     VisQueuedTwig::update (rep);
00406 
00407     IgQtLock ();
00408 
00409     SoSeparator *sep = new SoSeparator;
00410     SoMaterial *mat = new SoMaterial;
00411     mat->ambientColor.setValue (0.135, 0.2225, 0.1575);
00412     mat->diffuseColor.setValue (0.54, 0.89, 0.63);
00413     mat->specularColor.setValue (0.316228, 0.316228, 0.316228);
00414     mat->emissiveColor.setValue(0.0, 0.0, 0.0);
00415     mat->shininess = 0.1;
00416     sep->addChild (mat);
00417     
00418     if (! m_rechits.empty () && m_pDD.isValid ())
00419     {
00420         try 
00421         {
00422             //
00423             // Muon Endcap Rechits
00424             // 
00425         
00426             for (std::vector<CSCRecHit2D>::const_iterator is = m_rechits.begin (), isEnd = m_rechits.end (); is != isEnd; ++is) 
00427             {
00428                 const GeomDetUnit *det = m_pDD->idToDetUnit ((*is).cscDetId ());
00429                 
00430 //              GlobalPoint pos = det->surface ().toGlobal ((*is).localPosition ());
00431             
00432 //              float x = pos.x () / 100.0;  // cm -> m
00433 //              float y = pos.y () / 100.0;  // cm -> m
00434 //              float z = pos.z () / 100.0;  // cm -> m
00435                 
00436                 LocalPoint xyzLocal = is->localPosition ();
00437                 float x = xyzLocal.x ();
00438                 float y = xyzLocal.y ();
00439                 float z = xyzLocal.z ();
00440                 float dx = std::sqrt( is->localPositionError ().xx () );
00441                 float dy = std::sqrt( is->localPositionError ().yy () );
00442                 
00443                 IgSo3DErrorBar *errorBar = new IgSo3DErrorBar;
00444                 GlobalPoint gp;
00445                 gp = det->surface ().toGlobal (LocalPoint (x - dx, y, z));
00446                 errorBar->u1.setValue (gp.x () / 100.0, gp.y () / 100.0, gp.z () / 100.0);
00447                 gp = det->surface ().toGlobal (LocalPoint (x + dx, y, z));
00448                 errorBar->u2.setValue (gp.x () / 100.0, gp.y () / 100.0, gp.z () / 100.0);
00449                 gp = det->surface ().toGlobal (LocalPoint (x, y - dy, z));
00450                 errorBar->v1.setValue (gp.x () / 100.0, gp.y () / 100.0, gp.z () / 100.0);
00451                 gp = det->surface ().toGlobal (LocalPoint (x, y + dy, z));
00452                 errorBar->v2.setValue (gp.x () / 100.0, gp.y () / 100.0, gp.z () / 100.0);
00453                 gp = det->surface ().toGlobal (xyzLocal); // no error in z
00454                 errorBar->w1.setValue (gp.x () / 100.0, gp.y () / 100.0, gp.z () / 100.0);
00455                 errorBar->w2.setValue (gp.x () / 100.0, gp.y () / 100.0, gp.z () / 100.0);
00456 
00457                 errorBar->lineWidth.setValue (1.0);
00458                 
00459                 sep->addChild (errorBar);
00460             }
00461         }
00462         catch (cms::Exception& e)
00463         {
00464             if (this->m_onCmsException)
00465                 this->m_onCmsException (&e);
00466         }
00467         catch (lat::Error &e) 
00468         {
00469             if (this->m_onError)
00470                 this->m_onError (&e);
00471         }
00472         catch (std::exception &e) 
00473         {
00474             if (this->m_onException)
00475                 this->m_onException (&e);
00476         }
00477         catch (...) 
00478         {
00479             if (this->m_onUnhandledException)
00480                 this->m_onUnhandledException ();
00481         }
00482     }
00483     
00484     rep->clear ();
00485     rep->node ()->addChild (sep);
00486 }
00487 

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