CMS 3D CMS Logo

VisPixelDigiTwig.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 #include "VisReco/VisTracker/interface/VisPixelDigiTwig.h"
00003 #include "VisFramework/VisFrameworkBase/interface/debug.h"
00004 #include "DataFormats/SiPixelDigi/interface/PixelDigi.h"
00005 #include "DataFormats/SiPixelDigi/interface/PixelDigiCollection.h"
00006 #include "FWCore/Framework/interface/Event.h"
00007 #include "FWCore/Framework/interface/EventSetup.h"
00008 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00009 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00010 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00011 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00012 #include "Iguana/Inventor/interface/IgSoTower.h"
00013 #include "Iguana/Models/interface/IgTextRep.h"
00014 #include "Iguana/GLModels/interface/Ig3DRep.h"
00015 #include "Iguana/GLModels/interface/IgLegoRep.h"
00016 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00017 #include "Iguana/GLModels/interface/IgRZRep.h"
00018 #include "Iguana/Framework/interface/IgRepSet.h"
00019 #include "Iguana/Studio/interface/IgQtLock.h"
00020 #include <Inventor/nodes/SoSeparator.h>
00021 #include <Inventor/nodes/SoTransform.h>
00022 #include <Inventor/nodes/SoCube.h>
00023 #include <Inventor/nodes/SoDrawStyle.h>
00024 #include <Inventor/nodes/SoMaterial.h>
00025 #include <Inventor/nodes/SoPointSet.h>
00026 #include <Inventor/nodes/SoVertexProperty.h>
00027 #include <qstring.h>
00028 #include <iostream>
00029 #include <iomanip>
00030 
00031 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00032 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00033 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00034 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00035 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00036 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00037 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00038 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00039 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00040 
00041 VisPixelDigiTwig::VisPixelDigiTwig (IgState *state, IgTwig *parent,
00042                                     const std::string &name /* = "" */,
00043                                     unsigned int detType, unsigned int subDetType)
00044     : VisQueuedTwig (state, parent, name),
00045       m_text ("no info"),
00046       m_detType (detType),
00047       m_subDetType (subDetType)
00048 {
00049 }
00050 
00051 void
00052 VisPixelDigiTwig::onNewEvent (const edm::Event &event,
00053                               const edm::EventSetup &eventSetup)
00054 {
00055     // Get debugging dump.
00056     VisQueuedTwig::onNewEvent (event, eventSetup);
00057 
00058     m_digis.clear ();
00059     m_text = (QString ("Run # %1, event # %2")
00060               .arg (event.id ().run ())
00061               .arg (event.id ().event ()).latin1 ());
00062 
00063     edm::Handle<PixelDigiCollection> digiCollection;
00064     
00065     try
00066     {
00067         event.getByLabel ("pixdigi", digiCollection);
00068         eventSetup.get<TrackerDigiGeometryRecord> ().get (m_pDD);
00069     }
00070     catch (cms::Exception& e)
00071     {
00072         e.append (" from VisPixelDigiTwig: ");
00073         e.append (this->name ());
00074             
00075         if (this->m_onCmsException)
00076             this->m_onCmsException (&e);
00077     }
00078     catch (lat::Error &e) 
00079     {
00080         if (this->m_onError)
00081             this->m_onError (&e);
00082     }
00083     catch (std::exception &e) 
00084     {
00085         if (this->m_onException)
00086             this->m_onException (&e);
00087     }
00088     catch (...) 
00089     {
00090         if (this->m_onUnhandledException)
00091             this->m_onUnhandledException ();
00092     }
00093 
00094     if (digiCollection.isValid ())
00095     {
00096         // Get vector of detIDs in map
00097         const std::vector<unsigned int> detIDs = digiCollection->detIDs ();
00098 
00099         //--- Loop over detunits.
00100         std::vector<unsigned int>::const_iterator detunit_it;
00101         for (detunit_it  = detIDs.begin (); detunit_it != detIDs.end (); 
00102              detunit_it++) 
00103         {
00104             unsigned int detid = *detunit_it;   // return uint, = rawid
00105 
00106             // Det id
00107             DetId detId = DetId (detid);            // Get the Detid
00108 //          unsigned int detType = detId.det ();    // det type, pixel=1
00109 //          unsigned int subid = detId.subdetId (); //subdetector type, barrel=1
00110      
00111 //          if (detType != m_detType) continue; // look only at pixels
00112             
00113 //          // Subdet it, pix barrel=1
00114 //          if (subid != m_subDetType)
00115 //          {
00116 //              //if (PRINT && subid == 2) cout << " forward hit " << endl;
00117 //              continue; // look only at barrel
00118 //          }
00119 
00120             // Look at digis now
00121             const PixelDigiCollection::Range digiRange = digiCollection->get (detid);
00122             PixelDigiCollection::ContainerIterator di;
00123             // Loop over Digis in this det unit
00124             for (di = digiRange.first; di != digiRange.second; ++di) 
00125             { 
00126 //              int adc = di->adc();    // charge
00127 //              int col = di->column(); // column 
00128 //              int row = di->row();    // row
00129                 //cout <<numberOfDigis<< " Col: " << col << " Row: " << row << " ADC: " 
00130                 //   << adc << endl;
00131 
00132                 std::pair<DetId, PixelDigi> p;
00133                 p.first = detId;
00134                 p.second = (*di);
00135                 //              (*digiIt).print ();
00136 
00137                 m_digis.push_back (p);
00138             } // for digis 
00139         } // for DetId
00140     }
00141     
00142     IgRepSet::invalidate (this, SELF_MASK);
00143 }
00144 
00145 void
00146 VisPixelDigiTwig::update (IgTextRep *rep)
00147 {
00148     // Get debugging dump.
00149     VisQueuedTwig::update (rep);
00150 
00151     // Prepare property description.
00152     std::ostringstream  text;
00153     text << "Total " << m_digis.size () << " Pixel digis from";
00154     text << " Cosmic run: " << m_text << "<br>";
00155 
00156     text << "<table width='100%' border=1>"
00157          << "<TR align = center>"
00158          << "<TH>Number</TH>"
00159          << "<TH>Position</TH>"
00160          << "<TH>Charge</TH>"
00161          << "<TH>Column</TH>"
00162          << "<TH>Row</TH>"
00163          << "</TR>";
00164     text << setiosflags (std::ios::showpoint | std::ios::fixed);
00165     text.setf (std::ios::right, std::ios::adjustfield);
00166 
00167     if ((! m_digis.empty ()) && m_pDD.isValid ()) 
00168     {
00169     
00170     int nDigis = 0;
00171     try 
00172     {
00173         for (std::vector<std::pair<DetId, PixelDigi> >::const_iterator i = m_digis.begin (); i != m_digis.end (); ++i) 
00174         {
00175             Surface::GlobalPoint pos =  (m_pDD->idToDet ((*i).first))->surface ().position ();
00176             text << "<TR align = right>"
00177                  << "<TD>" << std::setw (3) << nDigis++ << "</TD>"
00178                  << "<TD>" << pos.x () << ", " << pos.y () << ", " << pos.z () << "</TD>"
00179                  << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.adc () << "</TD>"
00180                  << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.column () << "</TD>"
00181                  << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.row () << "</TD></TR>";
00182         }
00183     }
00184     catch (...)
00185     {
00186         text << "No Pixel digis.<br>";
00187     }
00188     text << "</table>";
00189     }
00190     
00191     // Send it over.
00192     IgQtLock ();
00193     rep->setText (text.str ());
00194 }
00195 
00196 void
00197 VisPixelDigiTwig::update (Ig3DRep *rep)
00198 {
00199     // Get debugging dump.
00200     VisQueuedTwig::update (rep);
00201     IgQtLock ();
00202     rep->clear ();
00203   
00204     if (! m_digis.empty ())
00205     {
00206         SoMaterial *mat = new SoMaterial;
00207         mat->diffuseColor.setValue (0.0, 0.0, 1.0);
00208         mat->emissiveColor.setValue(0.0, 0.0, 1.0);
00209 
00210         SoMaterial *matcube = new SoMaterial;
00211         matcube->diffuseColor.setValue (0.0, 1.0, 1.0);
00212         matcube->emissiveColor.setValue(0.0, 1.0, 1.0);
00213 
00214         SoDrawStyle *drawStyle = new SoDrawStyle;
00215         drawStyle->pointSize = 6.0;
00216 
00217         SoSeparator *sep = new SoSeparator; // global
00218         sep->addChild (mat);
00219         sep->addChild (drawStyle);
00220 
00221         try 
00222         {
00223             SoVertexProperty *vertices = new SoVertexProperty;
00224             int nVrtx = 0;
00225             for (std::vector<std::pair<DetId, PixelDigi> >::const_iterator 
00226                      i = m_digis.begin (); i != m_digis.end (); ++i)
00227             {
00228                 sepmodule = new SoSeparator;
00229                 sepmodule->addChild (mat);
00230 
00231                 sepcube = new SoSeparator;
00232                 sepcube->addChild (matcube);
00233 
00234                 cubedigi = new SoCube ();
00235 
00236                 const DetId& id = (*i).first;
00237                 const GeomDetUnit *det = m_pDD->idToDetUnit (id);
00238 
00239                 theDet = dynamic_cast<const PixelGeomDetUnit*> (m_pDD->idToDet (id));
00240 
00241                 theTopol = dynamic_cast<const RectangularPixelTopology *>( &(theDet->specificTopology ()));
00242                 const PixelDigi pd = (*i).second;
00243                 theNumOfRow = theTopol->nrows ();      // rows in x
00244                 theNumOfCol = theTopol->ncolumns ();   // cols in y
00245                 std::pair<float, float> pitchxy = theTopol->pitch ();
00246                 thePitchX = pitchxy.first;            // pitch along x
00247                 thePitchY = pitchxy.second;           // pitch along y
00248 
00249                 cubedigi->width = 1./theNumOfRow;
00250                 cubedigi->height =1./theNumOfCol;
00251                 cubedigi->depth =(pd.adc())/10. ;
00252 
00253                 //--- Find the offset
00254                 MeasurementPoint  offset =
00255                   theTopol->measurementPosition( LocalPoint(0., 0.) );
00256                 theOffsetX = offset.x();
00257                 theOffsetY = offset.y();
00258 
00259                 float xlocal = (pd.row()*thePitchX + theOffsetX)/100.0 ;
00260                 float ylocal = (pd.column()*thePitchY + theOffsetY)/100.0 ;
00261                 LocalPoint p = LocalPoint(xlocal, ylocal);
00262 
00263                 //Surface::GlobalPoint pos =  (m_pDD->idToDet (id))->surface ().position ();
00264                 //float x = pos.x () / 100.0;  // cm -> m
00265                 //float y = pos.y () / 100.0;  // cm -> m
00266                 //float z = pos.z () / 100.0;  // cm -> m
00267 
00268                 float x = (m_pDD->idToDet (id))->surface().toGlobal(p).x() / 100.0;  // cm -> m
00269                 float y = (m_pDD->idToDet (id))->surface().toGlobal(p).y() / 100.0;  // cm -> m
00270                 float z = (m_pDD->idToDet (id))->surface().toGlobal(p).z() / 100.0;  // cm -> m
00271 
00272                 vertices->vertex.set1Value (nVrtx++, SbVec3f (x, y, z));
00273 
00274                 digiTransform = new SoTransform;
00275                 digiTransform->translation.setValue (xlocal/(thePitchX*theNumOfRow), ylocal/(thePitchY*theNumOfCol),pd.adc()/20. );
00276                 sepcube->addChild (digiTransform);
00277                 sepcube->addChild (cubedigi);
00278 
00279                 sepmodule->addChild (sepcube);
00280 
00281                 rep->node ()->addChild (sepmodule);
00282             }
00283             
00284             vertices->vertex.setNum (nVrtx);
00285             SoPointSet *points = new SoPointSet;
00286             points->vertexProperty.setValue (vertices);
00287             points->numPoints.setValue (nVrtx);
00288 
00289             sep->addChild (points);
00290         }
00291         catch (...) 
00292         {
00293             std::cout << "No PixelDigi Digis." << std::endl;
00294         }
00295     
00296         rep->node ()->addChild (sep);
00297     }
00298 }
00299 
00300 void
00301 VisPixelDigiTwig::update (IgLegoRep *rep)
00302 {
00303     // Get debugging dump.
00304     VisQueuedTwig::update (rep);
00305 
00306     IgQtLock ();
00307     rep->clear ();
00308     
00309     SoSeparator *sep = new SoSeparator; // global
00310     
00311     try 
00312     {
00313         for (std::vector<std::pair<DetId, PixelDigi> >::const_iterator i = m_digis.begin (); i != m_digis.end (); ++i) 
00314         {
00315             Surface::GlobalPoint pos =  (m_pDD->idToDet ((*i).first))->surface ().position ();
00316             double eta = pos.eta ();
00317             double phi = pos.phi ();
00318             if (phi < 0.0) phi = 2 * M_PI + phi; // correction in absence of one convention
00319 
00320             // int strip = (*i).second.getStrip ();
00321             int adcCounts = (*i).second.adc ();
00322 
00323             IgSoTower *tower = new IgSoTower;
00324             tower->position = SbVec2f (phi, eta); // eta, phi
00325             tower->scaleFactor = 20.0;
00326             tower->energy = adcCounts;
00327             sep->addChild (tower);
00328         }
00329     }
00330     catch (...) 
00331     {
00332         std::cout << "No PixelDigi Digis." << std::endl;
00333     }
00334     
00335     rep->node ()->addChild (sep);
00336 }
00337 
00338 void
00339 VisPixelDigiTwig::update (IgRPhiRep *rep)
00340 {
00341     // Get debugging dump.
00342     VisQueuedTwig::update (rep);
00343 
00344     IgQtLock ();
00345     rep->clear ();
00346     
00347     if (! m_digis.empty ()) 
00348     {
00349         SoSeparator *sep = new SoSeparator;    
00350 
00351         SoMaterial *mat = new SoMaterial;
00352         mat->diffuseColor.setValue (0.0, 0.0, 1.0);
00353         sep->addChild (mat);
00354 
00355         SoDrawStyle *drawStyle = new SoDrawStyle;
00356         drawStyle->pointSize = 6.0;
00357         sep->addChild (drawStyle);
00358 
00359         try 
00360         {
00361             SoVertexProperty *vertices = new SoVertexProperty;
00362             int nVrtx = 0;
00363             for (std::vector<std::pair<DetId, PixelDigi> >::const_iterator 
00364                      i = m_digis.begin (); i != m_digis.end (); ++i)
00365             {
00366                 const DetId& id = (*i).first;
00367 
00368                 Surface::GlobalPoint pos =  (m_pDD->idToDet (id))->surface ().position ();
00369                 float x = pos.x () / 100.0;  // cm -> m
00370                 float y = pos.y () / 100.0;  // cm -> m
00371                 float z = 10.0;  // cm -> m
00372                 vertices->vertex.set1Value (nVrtx++, SbVec3f (x, y, z));
00373             }
00374             
00375             vertices->vertex.setNum (nVrtx);
00376             SoPointSet *points = new SoPointSet;
00377             points->vertexProperty.setValue (vertices);
00378             points->numPoints.setValue (nVrtx);
00379 
00380             sep->addChild (points);
00381         }
00382         catch (...) 
00383         {
00384             std::cout << "No PixelDigi Digis." << std::endl;
00385         }
00386     
00387         rep->node ()->addChild (sep);
00388     }
00389 }
00390 
00391 void
00392 VisPixelDigiTwig::update (IgRZRep *rep)
00393 {
00394     // Get debugging dump.
00395     VisQueuedTwig::update (rep);
00396 
00397     IgQtLock ();
00398     rep->clear ();
00399 
00400     if (! m_digis.empty ()) 
00401     {
00402         SoSeparator *sep = new SoSeparator;    
00403         SoMaterial *mat = new SoMaterial;
00404         mat->diffuseColor.setValue (0.3, 0.8, 0.0);
00405         sep->addChild (mat);
00406 
00407         SoDrawStyle *drawStyle = new SoDrawStyle;
00408         drawStyle->pointSize = 3.0;
00409         sep->addChild (drawStyle);
00410     
00411         try 
00412         {
00413             SoVertexProperty *vertices = new SoVertexProperty;
00414             int nVrx = 0;
00415 
00416             for (std::vector<std::pair<DetId, PixelDigi> >::const_iterator i = m_digis.begin (); i != m_digis.end (); ++i) 
00417             {
00418                 Surface::GlobalPoint pos =  (m_pDD->idToDet ((*i).first))->surface ().position ();
00419 //              int strip = (*i).second.getStrip ();
00420 //              std::vector<int> adcCounts = (*i).second.getADCCounts ();
00421             
00422                 float x = pos.x () / 100.0;  // cm -> m
00423                 float y = pos.y () / 100.0;  // cm -> m
00424                 float z = pos.z () / 100.0;  // cm -> m
00425                 
00426                 vertices->vertex.set1Value (nVrx++, SbVec3f (x, y, z));
00427             }
00428             vertices->vertex.setNum (m_digis.size ());
00429 
00430             SoPointSet *points = new SoPointSet;
00431             points->vertexProperty.setValue (vertices);
00432             points->numPoints.setValue (m_digis.size ());
00433             sep->addChild (points);
00434         }    
00435         catch (...) 
00436         {
00437             std::cout << "No PixelDigi Digis." << std::endl;
00438         }
00439     
00440         rep->node ()->addChild (sep);
00441     }
00442 }

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