CMS 3D CMS Logo

VisTrackerDigiTwig.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 #include "VisReco/VisTracker/interface/VisTrackerDigiTwig.h"
00003 #include "VisFramework/VisFrameworkBase/interface/debug.h"
00004 #include "VisFramework/VisFrameworkBase/interface/VisTwigFactroyService.h"
00005 #include "VisFramework/VisFrameworkBase/interface/VisEventSelector.h"
00006 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
00007 #include "DataFormats/Common/interface/DetSetVector.h"
00008 #include "FWCore/Framework/interface/Event.h"
00009 #include "FWCore/Framework/interface/EventSetup.h"
00010 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00011 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00012 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
00013 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00014 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00015 #include "Geometry/CommonTopologies/interface/StripTopology.h"
00016 #include "Iguana/Inventor/interface/IgSbColorMap.h"
00017 #include "Iguana/Inventor/interface/IgSoTower.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/Framework/interface/IgRepSet.h"
00024 #include "Iguana/Studio/interface/IgDocumentData.h"
00025 #include "Iguana/Studio/interface/IgQtLock.h"
00026 #include <Inventor/nodes/SoSeparator.h>
00027 #include <Inventor/nodes/SoTransform.h>
00028 #include <Inventor/nodes/SoCube.h>
00029 #include <Inventor/nodes/SoDrawStyle.h>
00030 #include <Inventor/nodes/SoMaterial.h>
00031 #include <Inventor/nodes/SoPointSet.h>
00032 #include <Inventor/nodes/SoVertexProperty.h>
00033 #include <qstring.h>
00034 #include <iostream>
00035 #include <iomanip>
00036 
00037 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00038 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00039 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00040 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00041 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00042 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00043 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00044 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00045 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00046 
00047 namespace 
00048 {
00049     VisQueuedTwig *
00050     createThisTwig (IgState *state, IgTwig *parent,
00051                     const std::string &name,
00052                     const std::string &friendlyName,
00053                     const std::string &modLabel,
00054                     const std::string &instanceName,
00055                     const std::string &processName)
00056     {
00057         IgTwig *rootTwig = IgDocumentData::get (state)->root ();
00058         IgTwig *eventTwig = 0;
00059         eventTwig = rootTwig->lookup ("/Objects/CMS Event and Detector/Tracker Event/SiStrip Digis");
00060         
00061         if (! eventTwig)
00062             eventTwig = parent;
00063 
00064         return new VisTrackerDigiTwig (state, eventTwig, "[N/A] SiStrip Digi (" + name + ")", 
00065                                        friendlyName, modLabel, instanceName, processName);
00066     }
00067 }
00068 
00069 VisTrackerDigiTwig::VisTrackerDigiTwig (IgState *state, IgTwig *parent,
00070                                         const std::string &name /* = "" */,
00071                                         const std::string &friendlyName /* = "" */,
00072                                         const std::string &moduleLabel /* = "" */,
00073                                         const std::string &instanceName /* = "" */,
00074                                         const std::string &processName /* = "" */)
00075     : VisQueuedTwig (state, parent, name),
00076       m_text (name),
00077       m_friendlyName (friendlyName),
00078       m_moduleLabel (moduleLabel),
00079       m_instanceName (instanceName),
00080       m_processName (processName),
00081       m_scale (state, lat::CreateCallback (this, &VisTrackerDigiTwig::twigChanged))      
00082 {
00083     VisTwigFactroyService *tfService = VisTwigFactroyService::get (state);
00084     if (! tfService)
00085     {
00086         tfService = new VisTwigFactroyService (state);
00087     }   
00088     edm::TypeID siDigiCollID (typeid (edm::DetSetVector<SiStripDigi>));
00089     tfService->registerTwig (siDigiCollID.friendlyClassName (), &createThisTwig);
00090 }
00091 
00092 void
00093 VisTrackerDigiTwig::twigChanged (void)
00094 { IgRepSet::invalidate (this, SELF_MASK); }
00095 
00096 void
00097 VisTrackerDigiTwig::onNewEvent (const edm::Event &event,
00098                                 const edm::EventSetup &eventSetup)
00099 {
00100     // Get debugging dump.
00101     VisQueuedTwig::onNewEvent (event, eventSetup);
00102 
00103     m_digis.clear ();
00104   
00105     m_text = QString ("Run %1, Event %2, LS %3, Orbit %4, BX %5")
00106              .arg (event.id ().run ())
00107              .arg (event.id ().event ())
00108              .arg (event.luminosityBlock ())
00109              .arg (event.orbitNumber ())
00110              .arg (event.bunchCrossing ())
00111              .latin1 ();
00112 
00113     std::vector< edm::Handle<edm::DetSetVector<SiStripDigi> > > collections;
00114     try
00115     {
00116         if ((! m_friendlyName.empty ()) || (! m_moduleLabel.empty ()) || (! m_instanceName.empty ()) || (! m_processName.empty ()))
00117         {
00118             VisEventSelector visSel (m_friendlyName, m_moduleLabel, m_instanceName, m_processName);
00119             event.getMany (visSel, collections);
00120         }
00121         eventSetup.get<TrackerDigiGeometryRecord> ().get (m_pDD);
00122     }
00123     catch (lat::Error& e)
00124     {
00125         if (this->m_onError)
00126             this->m_onError (&e);
00127     }
00128     catch (cms::Exception& e)
00129     {
00130         e.append (" from VisTrackerDigiTwig: ");
00131         e.append (this->name ());    
00132         
00133         if (this->m_onCmsException)
00134             this->m_onCmsException (&e);
00135     }
00136     catch (std::exception& e)
00137     {
00138         if (this->m_onException)
00139             this->m_onException (&e);
00140     }
00141     catch (...)
00142     {
00143         if (this->m_onUnhandledException)
00144             this->m_onUnhandledException ();
00145     }
00146 
00147     if (! collections.empty ())
00148     {
00149         std::vector< edm::Handle<edm::DetSetVector<SiStripDigi> > >::iterator i;
00150         std::vector< edm::Handle<edm::DetSetVector<SiStripDigi> > >::iterator iEnd;
00151         for (i = collections.begin (), iEnd = collections.end (); i != iEnd; ++i) 
00152         {
00153             const edm::DetSetVector<SiStripDigi> &c = *(*i);
00154             QString sizeStr = (QString ("%1").arg (c.size ()));
00155             QString nameStr = QString (this->name ());
00156             int ib = nameStr.find ("[");
00157             int ie = nameStr.find ("]");
00158             nameStr.replace (ib + 1, ie - 1, sizeStr);
00159             
00160             this->name (nameStr);
00161           
00162             edm::DetSetVector<SiStripDigi>::const_iterator DSViter = c.begin ();
00163             edm::DetSetVector<SiStripDigi>::const_iterator DSViterEnd = c.end ();
00164 
00165             LOG (2, trace, LFfwvis, "There are " <<  c.size () << "SiStrip digis\n");
00166 
00167             for (; DSViter != DSViterEnd; ++DSViter)
00168             {
00169                 edm::DetSet<SiStripDigi> ds = *DSViter;
00170                 if (ds.data.size ())
00171                 {
00172                     const uint32_t& detID = ds.id;
00173                     DetId detid (detID);
00174                     edm::DetSet<SiStripDigi>::const_iterator idigi = ds.data.begin ();
00175                     edm::DetSet<SiStripDigi>::const_iterator idigiEnd = ds.data.end ();
00176                     for(; idigi != idigiEnd; ++idigi)
00177                     { 
00178                         std::pair<DetId, SiStripDigi> p;
00179                         p.first = detid;
00180                         p.second = (*idigi);
00181                         m_digis.push_back (p);
00182                     } // for digis 
00183                 }
00184             }
00185         }
00186     }
00187 
00188     IgRepSet::invalidate (this, IgTwig::SELF_MASK | IgTwig::STRUCTURE_MASK);
00189 }
00190 
00191 void
00192 VisTrackerDigiTwig::update (IgTextRep *rep)
00193 {
00194     // Get debugging dump.
00195     VisQueuedTwig::update (rep);
00196   
00197     // Prepare property description.
00198     std::ostringstream  text;
00199 
00200     text << m_text << "<br>";
00201   
00202     text << "Total " << m_digis.size () << " Silicon Strip digis from ";
00203     text << m_text << "<br>";
00204 
00205     if (m_digis.size () > 100) 
00206     {
00207         text << "Printing only first 100." << "<br>";
00208     } 
00209     
00210     text << "<table width='100%' border=1>"
00211          << "<TR align = center>"
00212          << "<TH>Number</TH>"
00213          << "<TH>GeomdetId</TH>"
00214          << "<TH>Position</TH>"
00215          << "<TH>Charge</TH>"
00216          << "<TH>Strip</TH>"
00217          << "</TR>";
00218     text << setiosflags (std::ios::showpoint | std::ios::fixed);
00219     text.setf (std::ios::right, std::ios::adjustfield);
00220   
00221     if ((! m_digis.empty ()) && m_pDD.isValid ()) 
00222     {
00223         int nSDigis = 0;
00224         try 
00225         {
00226             for (std::vector<std::pair<DetId, SiStripDigi> >::const_iterator i = m_digis.begin (), iEnd = m_digis.end (); i != iEnd; ++i) 
00227             {
00228                 const DetId& id = (*i).first;
00229                 const StripGeomDetUnit*  theStripDet = dynamic_cast<const StripGeomDetUnit*>(m_pDD->idToDet (id));
00230                 const StripTopology * theStripTopol = dynamic_cast<const StripTopology *>( &(theStripDet->specificTopology ()));
00231                 int strip = (*i).second.strip ();
00232                 GlobalPoint pos =  (m_pDD->idToDet (id))->surface().toGlobal(theStripTopol->localPosition(strip));
00233               
00234                 text << "<TR align = right>"
00235                      << "<TD>" << std::setw (3) << nSDigis++ << "</TD>"
00236                      << "<TD>" << std::setw (11) << ((*i).first).rawId ()<< "</TD>"
00237                      << "<TD>" << pos.x () << ", " << pos.y () << ", " << pos.z () << "</TD>"
00238                      << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.adc () << "</TD>"
00239                      << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.strip () << "</TD>";
00240                 if (nSDigis > 100) break;
00241             }
00242         }
00243         catch (cms::Exception& e)
00244         {
00245             e.append (" from VisTrackerDigiTwig: ");
00246             e.append (this->name ());    
00247         
00248             if (this->m_onCmsException)
00249                 this->m_onCmsException (&e);
00250         }
00251         catch (lat::Error &e) 
00252         {
00253             if (this->m_onError)
00254                 this->m_onError (&e);
00255         }
00256         catch (std::exception &e) 
00257         {
00258             if (this->m_onException)
00259                 this->m_onException (&e);
00260         }
00261         catch (...) 
00262         {
00263             if (this->m_onUnhandledException)
00264                 this->m_onUnhandledException ();
00265         }
00266     }
00267   
00268     text << "</table>";
00269 
00270     // Send it over.
00271     IgQtLock ();
00272     rep->setText (text.str ());
00273 }
00274 
00275 void
00276 VisTrackerDigiTwig::update (Ig3DRep *rep)
00277 {
00278     // Get debugging dump.
00279     VisQueuedTwig::update (rep);
00280     IgQtLock ();
00281     rep->clear ();
00282   
00283     if (! m_digis.empty () && m_pDD.isValid ())
00284     {
00285         SoMaterial *mat = new SoMaterial;
00286         float rgbcomponents [4];
00287         IgSbColorMap::unpack (0x03C03C00, rgbcomponents); // Dark pastel green
00288         mat->diffuseColor.setValue (SbColor (rgbcomponents));
00289       
00290         SoDrawStyle *drawStyle = new SoDrawStyle;
00291         drawStyle->pointSize = 4.0;
00292       
00293         SoSeparator *sep = new SoSeparator; // global
00294         sep->addChild (mat);
00295         sep->addChild (drawStyle);
00296       
00297         try 
00298         {
00299             SoVertexProperty *vertices = new SoVertexProperty;
00300             int nVrtx = 0;
00301           
00302             for (std::vector<std::pair<DetId, SiStripDigi> >::const_iterator 
00303                      i = m_digis.begin (), iEnd = m_digis.end (); i != iEnd; ++i)
00304             {
00305                 const DetId& id = (*i).first;
00306                 const StripGeomDetUnit*  theStripDet = dynamic_cast<const StripGeomDetUnit*>(m_pDD->idToDet (id));
00307                 const StripTopology * theStripTopol = dynamic_cast<const StripTopology *>( &(theStripDet->specificTopology ()));
00308                 int strip=(*i).second.strip ();
00309                 GlobalPoint pos =  (m_pDD->idToDet (id))->surface().toGlobal(theStripTopol->localPosition(strip));
00310                 float x = pos.x () / 100.0;  // cm -> m
00311                 float y = pos.y () / 100.0;  // cm -> m
00312                 float z = pos.z () / 100.0;  // cm -> m
00313                 vertices->vertex.set1Value (nVrtx++, SbVec3f (x, y, z));
00314             }
00315             vertices->vertex.setNum (nVrtx);
00316             SoPointSet *points = new SoPointSet;
00317             points->vertexProperty.setValue (vertices);
00318             points->numPoints.setValue (nVrtx);
00319           
00320             sep->addChild (points);
00321         }
00322         catch (cms::Exception& e)
00323         {
00324             e.append (" from VisTrackerDigiTwig: ");
00325             e.append (this->name ());    
00326         
00327             if (this->m_onCmsException)
00328                 this->m_onCmsException (&e);
00329         }
00330         catch (lat::Error &e) 
00331         {
00332             if (this->m_onError)
00333                 this->m_onError (&e);
00334         }
00335         catch (std::exception &e) 
00336         {
00337             if (this->m_onException)
00338                 this->m_onException (&e);
00339         }
00340         catch (...) 
00341         {
00342             if (this->m_onUnhandledException)
00343                 this->m_onUnhandledException ();
00344         }
00345 
00346         rep->node ()->addChild (sep);
00347     }
00348 }
00349 
00350 void
00351 VisTrackerDigiTwig::update (IgLegoRep *rep)
00352 {
00353     // Get debugging dump.
00354     VisQueuedTwig::update (rep);
00355   
00356     IgQtLock ();
00357     rep->clear ();
00358   
00359     SoSeparator *sep = new SoSeparator; // global
00360     try 
00361     {
00362         for (std::vector<std::pair<DetId, SiStripDigi> >::const_iterator i = m_digis.begin (), iEnd = m_digis.end (); i != iEnd; ++i) 
00363         {
00364             const DetId& id = (*i).first;
00365             const StripGeomDetUnit*  theStripDet = dynamic_cast<const StripGeomDetUnit*>(m_pDD->idToDet (id));
00366             const StripTopology * theStripTopol = dynamic_cast<const StripTopology *>( &(theStripDet->specificTopology ()));
00367             int strip=(*i).second.strip ();
00368             GlobalPoint pos =  (m_pDD->idToDet (id))->surface().toGlobal(theStripTopol->localPosition(strip));
00369             double eta = pos.eta ();
00370             double phi = pos.phi ();
00371             if (phi < 0.0) phi = 2 * M_PI + phi; // correction in absence of one convention
00372             int adcCounts = (*i).second.adc ();
00373           
00374             IgSoTower *tower = new IgSoTower;
00375             tower->position = SbVec2f (phi, eta); // eta, phi
00376             tower->etaWidth = 0.01;
00377             tower->phiWidth = 0.01;
00378             tower->scaleFactor = m_scale.value ();
00379             tower->energy = adcCounts * 250.0 * 3.61e-09;
00380             tower->orderedRGBA.set1Value (6, SbColor (0.0, 1.0, 0.0).getPackedValue ());
00381             sep->addChild (tower);
00382         }
00383     }
00384     catch (cms::Exception& e)
00385     {
00386         e.append (" from VisTrackerDigiTwig: ");
00387         e.append (this->name ());    
00388         
00389         if (this->m_onCmsException)
00390             this->m_onCmsException (&e);
00391     }
00392     catch (lat::Error &e) 
00393     {
00394         if (this->m_onError)
00395             this->m_onError (&e);
00396     }
00397     catch (std::exception &e) 
00398     {
00399         if (this->m_onException)
00400             this->m_onException (&e);
00401     }
00402     catch (...) 
00403     {
00404         if (this->m_onUnhandledException)
00405             this->m_onUnhandledException ();
00406     }
00407 
00408     rep->node ()->addChild (sep);
00409 }
00410 
00411 void
00412 VisTrackerDigiTwig::update (IgRPhiRep *rep)
00413 {
00414     // Get debugging dump.
00415     VisQueuedTwig::update (rep);
00416   
00417     IgQtLock ();
00418     rep->clear ();
00419   
00420     if (! m_digis.empty () && m_pDD.isValid ()) 
00421     {
00422         SoSeparator *sep = new SoSeparator;    
00423       
00424         SoMaterial *mat = new SoMaterial;
00425         float rgbcomponents [4];
00426         IgSbColorMap::unpack (0x03C03C00, rgbcomponents); // Dark pastel green
00427         mat->diffuseColor.setValue (SbColor (rgbcomponents));
00428       
00429         SoDrawStyle *drawStyle = new SoDrawStyle;
00430         drawStyle->pointSize = 4.0;
00431         sep->addChild (drawStyle);
00432       
00433         try 
00434         {
00435             SoVertexProperty *vertices = new SoVertexProperty;
00436             int nVrtx = 0;
00437           
00438             for (std::vector<std::pair<DetId, SiStripDigi> >::const_iterator 
00439                      i = m_digis.begin (), iEnd = m_digis.end (); i != iEnd; ++i)
00440             {
00441                 const DetId& id = (*i).first;
00442                 const StripGeomDetUnit*  theStripDet = dynamic_cast<const StripGeomDetUnit *>(m_pDD->idToDet (id));
00443                 // Draw only if in barrel.
00444                 int subdet = theStripDet->geographicalId ().subdetId ();
00445                 if (subdet == 1 || subdet == 3 || subdet == 5)
00446                 {
00447                     const StripTopology * theStripTopol = dynamic_cast<const StripTopology *>( &(theStripDet->specificTopology ()));
00448                     int strip = (*i).second.strip ();
00449                     GlobalPoint pos =  (m_pDD->idToDet (id))->surface ().toGlobal(theStripTopol->localPosition (strip));
00450                     float x = pos.x () / 100.0;  // cm -> m
00451                     float y = pos.y () / 100.0;  // cm -> m
00452                     float z = 2.0;  // Z layer
00453                     vertices->vertex.set1Value (nVrtx++, SbVec3f (x, y, z));
00454                 }
00455             }
00456           
00457             vertices->vertex.setNum (nVrtx);
00458             SoPointSet *points = new SoPointSet;
00459             points->vertexProperty.setValue (vertices);
00460             points->numPoints.setValue (nVrtx);
00461           
00462             sep->addChild (points);
00463         }
00464         catch (cms::Exception& e)
00465         {
00466             e.append (" from VisTrackerDigiTwig: ");
00467             e.append (this->name ());    
00468         
00469             if (this->m_onCmsException)
00470                 this->m_onCmsException (&e);
00471         }
00472         catch (lat::Error &e) 
00473         {
00474             if (this->m_onError)
00475                 this->m_onError (&e);
00476         }
00477         catch (std::exception &e) 
00478         {
00479             if (this->m_onException)
00480                 this->m_onException (&e);
00481         }
00482         catch (...) 
00483         {
00484             if (this->m_onUnhandledException)
00485                 this->m_onUnhandledException ();
00486         }
00487 
00488         rep->node ()->addChild (sep);
00489     }
00490 }
00491 
00492 void
00493 VisTrackerDigiTwig::update (IgRZRep *rep)
00494 {
00495     // Get debugging dump.
00496     VisQueuedTwig::update (rep);
00497   
00498     IgQtLock ();
00499     rep->clear ();
00500   
00501     if (! m_digis.empty () && m_pDD.isValid ()) 
00502     {
00503         SoSeparator *sep = new SoSeparator;    
00504         SoMaterial *mat = new SoMaterial;
00505         float rgbcomponents [4];
00506         IgSbColorMap::unpack (0x03C03C00, rgbcomponents); // Dark pastel green
00507         mat->diffuseColor.setValue (SbColor (rgbcomponents));
00508       
00509         SoDrawStyle *drawStyle = new SoDrawStyle;
00510         drawStyle->pointSize = 4.0;
00511         sep->addChild (drawStyle);
00512       
00513         try 
00514         {
00515             SoVertexProperty *vertices = new SoVertexProperty;
00516             int nVrx = 0;
00517             for (std::vector<std::pair<DetId, SiStripDigi> >::const_iterator i = m_digis.begin (), iEnd = m_digis.end (); i != iEnd; ++i) 
00518             {
00519                 const DetId& id = (*i).first;
00520                 const StripGeomDetUnit *theStripDet = dynamic_cast<const StripGeomDetUnit*>(m_pDD->idToDet (id));
00521                 const StripTopology *theStripTopol = dynamic_cast<const StripTopology *>( &(theStripDet->specificTopology ()));
00522                 int strip = (*i).second.strip ();
00523                 GlobalPoint pos =  (m_pDD->idToDet (id))->surface ().toGlobal(theStripTopol->localPosition (strip));
00524                 float x = -2.0;
00525                 float y = sqrt (pos.x () * pos.x () + pos.y () * pos.y ()) / 100.0; 
00526                 if (pos.y () < 0.) y = - y;
00527                 float z = pos.z () / 100.0;  // cm -> m
00528               
00529                 vertices->vertex.set1Value (nVrx++, SbVec3f (x, y, z));
00530             }
00531             vertices->vertex.setNum (m_digis.size ());
00532             SoPointSet *points = new SoPointSet;
00533             points->vertexProperty.setValue (vertices);
00534             points->numPoints.setValue (m_digis.size ());
00535             sep->addChild (points);
00536         }    
00537         catch (cms::Exception& e)
00538         {
00539             e.append (" from VisTrackerDigiTwig: ");
00540             e.append (this->name ());    
00541         
00542             if (this->m_onCmsException)
00543                 this->m_onCmsException (&e);
00544         }
00545         catch (lat::Error &e) 
00546         {
00547             if (this->m_onError)
00548                 this->m_onError (&e);
00549         }
00550         catch (std::exception &e) 
00551         {
00552             if (this->m_onException)
00553                 this->m_onException (&e);
00554         }
00555         catch (...) 
00556         {
00557             if (this->m_onUnhandledException)
00558                 this->m_onUnhandledException ();
00559         }
00560 
00561         rep->node ()->addChild (sep);
00562     }
00563 }

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