CMS 3D CMS Logo

VisCSCALCTDigiTwig.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "VisReco/VisMuonCSC/interface/VisCSCALCTDigiTwig.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/CSCDigi/interface/CSCALCTDigi.h"
00009 #include "DataFormats/CSCDigi/interface/CSCALCTDigiCollection.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 //
00017 #include "Geometry/CSCGeometry/interface/CSCLayer.h"
00018 #include "Geometry/CSCGeometry/interface/CSCLayerGeometry.h"
00019 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00020 //
00021 #include "Iguana/Models/interface/IgTextRep.h"
00022 #include "Iguana/GLModels/interface/Ig3DRep.h"
00023 #include "Iguana/GLModels/interface/IgLegoRep.h"
00024 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00025 #include "Iguana/GLModels/interface/IgRZRep.h"
00026 #include "Iguana/Inventor/interface/IgSoTower.h"
00027 //
00028 #include "Iguana/Studio/interface/IgQtLock.h"
00029 #include <Inventor/nodes/SoDrawStyle.h>
00030 #include <Inventor/nodes/SoMaterial.h>
00031 #include <Inventor/nodes/SoSeparator.h>
00032 #include <Inventor/nodes/SoCube.h>
00033 #include <Inventor/nodes/SoLineSet.h>
00034 #include <Inventor/nodes/SoTranslation.h>
00035 #include <Inventor/nodes/SoPointSet.h>
00036 #include <Inventor/nodes/SoTransform.h>
00037 #include <Inventor/nodes/SoRotation.h>
00038 #include <classlib/utils/DebugAids.h>
00039 #include <qstring.h>
00040 #include <iostream>
00041 #include <iomanip>
00042 #include <cmath>
00043 
00044 
00045 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00046 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00047 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00048 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00049 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00050 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00051 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00052 
00053 namespace 
00054 {
00055     VisQueuedTwig *
00056     createThisTwig (IgState *state, IgTwig *parent,
00057                     const std::string &name,
00058                     const std::string &friendlyName,
00059                     const std::string &modLabel,
00060                     const std::string &instanceName,
00061                     const std::string &processName)
00062     {
00063         return new VisCSCALCTDigiTwig (state, parent, "ALCT digis (" + name + ")", 
00064                                        friendlyName, modLabel, instanceName, processName);
00065     }
00066 }
00067 
00068 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00069 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00070 
00071 VisCSCALCTDigiTwig::VisCSCALCTDigiTwig (IgState *state, IgTwig *parent,
00072                                         const std::string &name /* = "" */,
00073                                         const std::string &friendlyName /* = "" */,
00074                                         const std::string &moduleLabel /* = "" */,
00075                                         const std::string &instanceName /* = "" */,
00076                                         const std::string &processName /* = "" */)
00077     : VisQueuedTwig (state, parent, name),
00078       m_text (name),
00079       m_friendlyName (friendlyName),
00080       m_moduleLabel (moduleLabel),
00081       m_instanceName (instanceName),
00082       m_processName (processName)
00083 {
00084     VisTwigFactroyService *tfService = VisTwigFactroyService::get (state);
00085     if (! tfService)
00086     {
00087         tfService = new VisTwigFactroyService (state);
00088     }   
00089     edm::TypeID caloJetsID (typeid (CSCALCTDigiCollection));
00090     tfService->registerTwig (caloJetsID.friendlyClassName (), &createThisTwig);
00091 }
00092 
00093 void
00094 VisCSCALCTDigiTwig::onNewEvent (const edm::Event &event,
00095                                 const edm::EventSetup &eventSetup)
00096 {
00097     // Get debugging dump.
00098     VisQueuedTwig::onNewEvent (event, eventSetup);
00099 
00100     m_digis.clear ();
00101     m_text = (QString ("Run # %1, event # %2")
00102               .arg (event.id ().run ())
00103               .arg (event.id ().event ()).latin1 ());
00104 
00105     std::vector<edm::Handle<CSCALCTDigiCollection> > digiCollections;
00106     
00107     try
00108     {
00109         if ((! m_friendlyName.empty ()) || (! m_moduleLabel.empty ()) || (! m_instanceName.empty ()) || (! m_processName.empty ()))
00110         {
00111             VisEventSelector visSel (m_friendlyName, m_moduleLabel, m_instanceName, m_processName);
00112             event.getMany (visSel, digiCollections);
00113         }
00114         else
00115         {
00116             event.getManyByType (digiCollections);
00117         }
00118 
00119         eventSetup.get<MuonGeometryRecord> ().get (m_pDD);
00120     }
00121     catch (cms::Exception& e)
00122     {
00123         if (this->m_onCmsException)
00124             this->m_onCmsException (&e);
00125     }
00126     catch (lat::Error &e) 
00127     {
00128         if (this->m_onError)
00129             this->m_onError (&e);
00130     }
00131     catch (std::exception &e) 
00132     {
00133         if (this->m_onException)
00134             this->m_onException (&e);
00135     }
00136     catch (...) 
00137     {
00138         if (this->m_onUnhandledException)
00139             this->m_onUnhandledException ();
00140     }
00141 
00142     if (! digiCollections.empty ())
00143     {
00144         std::vector<edm::Handle<CSCALCTDigiCollection> >::iterator i;
00145         std::vector<edm::Handle<CSCALCTDigiCollection> >::iterator iEnd;
00146         for (i = digiCollections.begin (), iEnd = digiCollections.end (); i != iEnd; ++i) 
00147         {
00148             const CSCALCTDigiCollection& c = *(*i);
00149     
00150             // Loop over the DetUnits with digis
00151             CSCALCTDigiCollection::DigiRangeIterator detUnitIt;
00152             CSCALCTDigiCollection::DigiRangeIterator detUnitItEnd;
00153             for (detUnitIt = c.begin (), detUnitItEnd = c.end (); detUnitIt != detUnitItEnd; ++detUnitIt)
00154             {
00155                 const CSCDetId &id = (*detUnitIt).first;
00156                 const CSCALCTDigiCollection::Range &range = (*detUnitIt).second;
00157 
00158                 // Loop over the digis of this DetUnit
00159                 for (CSCALCTDigiCollection::const_iterator digiIt = range.first;
00160                      digiIt != range.second;
00161                      ++digiIt)
00162                 {
00163                     std::pair< CSCDetId, CSCALCTDigi > p;
00164                     p.first = id;
00165                     p.second = (*digiIt);
00166 
00167                     m_digis.push_back (p);
00168                 } // for digis in layer
00169             } // for layers
00170         }
00171     }
00172     
00173     VisQueuedTwig::onBaseInvalidate ();
00174 }
00175 
00176 void
00177 VisCSCALCTDigiTwig::update (IgTextRep *rep)
00178 {
00179     // Get debugging dump.
00180     VisQueuedTwig::update (rep);
00181 
00182     // Prepare property description.
00183     std::ostringstream  text;
00184     text << "Total " << m_digis.size () << " CSC A LCT digis: " << m_text << "<br>";
00185 
00186     text << "<table width='100%' border=1>"
00187          << "<TR align = center>"
00188          << "<TH>Number</TH>"
00189          << "<TH>Position</TH>"
00190          << "<TH>Validity</TH>"
00191          << "<TH>Accelerator bit</TH>"
00192          << "<TH>Collision pattern</TH>"
00193          << "<TH>Key wire group</TH>"
00194          << "<TH>BX</TH>"
00195          << "<TH>Track number</TH>"
00196          << "</TR>";
00197     text << setiosflags (std::ios::showpoint | std::ios::fixed);
00198     text.setf (std::ios::right, std::ios::adjustfield);
00199 
00200     if ((! m_digis.empty ()) && m_pDD.isValid ()) 
00201     {
00202     
00203         int nDigis = 0;
00204         try 
00205         {
00206             for (std::vector<std::pair<CSCDetId, CSCALCTDigi> >::const_iterator i = m_digis.begin (), iEnd = m_digis.end (); 
00207                  i != iEnd; ++i) 
00208             {
00209                 Surface::GlobalPoint pos =  (m_pDD->idToDet ((*i).first))->surface ().position ();
00210                 text << "<TR align = right>"
00211                      << "<TD>" << std::setw (3) << nDigis++ << "</TD>"
00212                      << "<TD>" << pos.x () << ", " << pos.y () << ", " << pos.z () << "</TD>"
00213                      << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.isValid () << "</TD>"
00214                      << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.getQuality () << "</TD>" 
00215                      << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.getAccelerator () << "</TD>"
00216                      << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.getCollisionB () << "</TD>"
00217                      << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.getKeyWG () << "</TD>"
00218                      << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.getBX () << "</TD>"
00219                      << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.getTrknmb () << "</TD></TR>";
00220 
00221                 std::cout << "CSCDetId " << (*i).first << std::endl;
00222             }
00223         }
00224         catch (cms::Exception& e)
00225         {
00226             if (this->m_onCmsException)
00227                 this->m_onCmsException (&e);
00228         }
00229         catch (lat::Error &e) 
00230         {
00231             if (this->m_onError)
00232                 this->m_onError (&e);
00233         }
00234         catch (std::exception &e) 
00235         {
00236             if (this->m_onException)
00237                 this->m_onException (&e);
00238         }
00239         catch (...) 
00240         {
00241             if (this->m_onUnhandledException)
00242                 this->m_onUnhandledException ();
00243         }
00244         text << "</table>";
00245     }
00246     
00247     // Send it over.
00248     IgQtLock ();
00249     rep->setText (text.str ());
00250 }
00251 
00252 void
00253 VisCSCALCTDigiTwig::update (Ig3DRep *rep)
00254 {
00255     // Get debugging dump.
00256     VisQueuedTwig::update (rep);
00257 
00258     IgQtLock ();
00259     rep->clear ();
00260     m_dets.clear ();
00261 
00262     if ((! m_digis.empty ()) && m_pDD.isValid ())
00263     {
00264         VisCSCChamberDrawer d;
00265 
00266         const float width  = 0.01; // strip visualization 
00267         const float depth  = 0.01; // strip visualization
00268 
00269         SbColor grey35;
00270         float transparency = 0.0f;
00271         grey35.setPackedValue(static_cast<uint32_t>(0x00595959), transparency);
00272         SoMaterial *mat = new SoMaterial;
00273         mat->diffuseColor.setValue (grey35); // grey35
00274         mat->emissiveColor.setValue(grey35);
00275 
00276         SoDrawStyle *drawStyle = new SoDrawStyle;
00277         drawStyle->pointSize = 5.0; // big point; useful for the centers of the layers
00278     
00279         SoSeparator *sep = new SoSeparator; // global
00280         sep->addChild (mat);
00281         sep->addChild (drawStyle);
00282 
00283         try 
00284         {
00285             SoMaterial *matl = new SoMaterial;
00286             matl->diffuseColor.setValue (0.0, 1.0, 0.0); // green
00287             matl->emissiveColor.setValue(0.0, 1.0, 0.0);          
00288             matl->shininess = 1.;
00289 
00290             SoDrawStyle *drawStylel = new SoDrawStyle;
00291             drawStylel->pointSize = 1.;
00292 
00293             SoSeparator *pulses = new SoSeparator; // strips
00294             pulses->addChild (matl);
00295             pulses->addChild (drawStylel);
00296             
00297             for (std::vector<std::pair<CSCDetId, CSCALCTDigi> >::const_iterator 
00298                      i = m_digis.begin (), iEnd = m_digis.end (); i != iEnd; ++i)
00299             {
00300                 const CSCDetId &id = (*i).first;
00301 
00302                 if (m_dets.find(id) == m_dets.end() )
00303                 {
00304                     m_dets.insert(id);  
00305                     // This is a frame around the (active) layer
00306                     d.getOutline(sep, m_pDD, id);
00307                 }
00308 
00309                 const CSCLayer *layer = m_pDD->chamber (id)->layer (3);
00310                 const CSCLayerGeometry *layerGeom = layer->geometry ();
00311                 int wireGroup_id = ((*i).second).getKeyWG ();
00312                 LocalPoint centerWireGroup = layerGeom->localCenterOfWireGroup (wireGroup_id);
00313                 Surface::GlobalPoint pos = layer->toGlobal (centerWireGroup);
00314                 float x = pos.x () / 100.0;  // cm -> m
00315                 float y = pos.y () / 100.0;  // cm -> m
00316                 float z = pos.z () / 100.0;  // cm -> m
00317 
00318                 SoTranslation *winc = new SoTranslation;
00319                 winc->translation = SbVec3f (x, y, z);
00320                 
00321                 SbVec3f waxis (0., 0., 1.);     
00322                 float wangle = -atan (x / y) - M_PI / 2;
00323                 SbRotation wr (waxis, wangle);
00324                 
00325                 SoTransform *wxform = new SoTransform;
00326                 wxform ->rotation = wr;
00327                 
00328                 SoCube *whit = new SoCube;
00329                 whit->width  = width;
00330                 whit->height = layerGeom->lengthOfWireGroup (wireGroup_id) / 100.;
00331                 whit->depth  = depth;
00332                 
00333                 SoSeparator *wpulse = new SoSeparator;// wire group
00334                 wpulse->addChild (winc);
00335                 wpulse->addChild (wxform);
00336                 wpulse->addChild (whit);
00337                 pulses->addChild (wpulse);
00338                 // Visualize wire groups 
00339                 sep->addChild (pulses);// wire groups
00340             }
00341         }
00342         catch (cms::Exception& e)
00343         {
00344             if (this->m_onCmsException)
00345                 this->m_onCmsException (&e);
00346         }
00347         catch (lat::Error &e) 
00348         {
00349             if (this->m_onError)
00350                 this->m_onError (&e);
00351         }
00352         catch (std::exception &e) 
00353         {
00354             if (this->m_onException)
00355                 this->m_onException (&e);
00356         }
00357         catch (...) 
00358         {
00359             if (this->m_onUnhandledException)
00360                 this->m_onUnhandledException ();
00361         }
00362 
00363         rep->node ()->addChild (sep);
00364     }
00365 }
00366 
00367 void
00368 VisCSCALCTDigiTwig::update (IgLegoRep *rep)
00369 {
00370     // Get debugging dump.
00371     VisQueuedTwig::update (rep);
00372 
00373     IgQtLock ();
00374     rep->clear ();
00375     
00376     SoSeparator *sep = new SoSeparator;    
00377     SoSeparator *posSep = new SoSeparator;    
00378     SoSeparator *negSep = new SoSeparator;
00379 
00380     SoMaterial *mat = new SoMaterial;
00381     mat->diffuseColor.setValue (0.3, 0.8, 0.0);
00382     posSep->addChild (mat);
00383 
00384     SoMaterial *negMat = new SoMaterial;
00385     negMat->diffuseColor.setValue (1.0, 0.0, 0.0);
00386     negSep->addChild (negMat);
00387 
00388     sep->addChild (posSep);
00389     sep->addChild (negSep);
00390 
00391     if ((! m_digis.empty ()) && m_pDD.isValid ()) 
00392     {
00393         try 
00394         {
00395             int n = 0;
00396         
00397             for (std::vector<std::pair<CSCDetId, CSCALCTDigi> >::const_iterator i = m_digis.begin (), iEnd = m_digis.end (); 
00398                  i != iEnd; ++i) 
00399             {
00400                 Surface::GlobalPoint pos =  (m_pDD->idToDet ((*i).first))->surface ().position ();
00401                 // double eta = pos.eta ();
00402                 double phi = pos.phi ();
00403                 if (phi < 0.0) phi = 2 * M_PI + phi; // correction in absence of one convention
00404 
00405                 ++n;
00406             }
00407         }
00408         catch (cms::Exception& e)
00409         {
00410             if (this->m_onCmsException)
00411                 this->m_onCmsException (&e);
00412         }
00413         catch (lat::Error &e) 
00414         {
00415             if (this->m_onError)
00416                 this->m_onError (&e);
00417         }
00418         catch (std::exception &e) 
00419         {
00420             if (this->m_onException)
00421                 this->m_onException (&e);
00422         }
00423         catch (...) 
00424         {
00425             if (this->m_onUnhandledException)
00426                 this->m_onUnhandledException ();
00427         }
00428     }
00429     
00430     rep->node ()->addChild (sep);
00431 }
00432 
00433 void
00434 VisCSCALCTDigiTwig::update (IgRPhiRep *rep)
00435 {
00436     // Get debugging dump.
00437     VisQueuedTwig::update (rep);
00438 
00439     IgQtLock ();
00440     rep->clear ();
00441     
00442     if (! m_digis.empty ()) 
00443     {
00444         SoSeparator *sep = new SoSeparator;    
00445 
00446         SoMaterial *mat = new SoMaterial;
00447         mat->diffuseColor.setValue (0.3, 0.8, 0.0);
00448         sep->addChild (mat);
00449 
00450         try 
00451         {
00452             for (std::vector<std::pair<CSCDetId, CSCALCTDigi> >::const_iterator i = m_digis.begin (), iEnd = m_digis.end (); 
00453                  i != iEnd; ++i) 
00454             {
00455                 //      Surface::GlobalPoint pos =  (m_pDD->idToDet ((*i).first))->surface ().position ();
00456                 //              double phi = pos.phi ();
00457             }
00458         }
00459         catch (cms::Exception& e)
00460         {
00461             if (this->m_onCmsException)
00462                 this->m_onCmsException (&e);
00463         }
00464         catch (lat::Error &e) 
00465         {
00466             if (this->m_onError)
00467                 this->m_onError (&e);
00468         }
00469         catch (std::exception &e) 
00470         {
00471             if (this->m_onException)
00472                 this->m_onException (&e);
00473         }
00474         catch (...) 
00475         {
00476             if (this->m_onUnhandledException)
00477                 this->m_onUnhandledException ();
00478         }
00479     
00480         rep->node ()->addChild (sep);
00481     }
00482 }
00483 
00484 void
00485 VisCSCALCTDigiTwig::update (IgRZRep *rep)
00486 {
00487     // Get debugging dump.
00488     VisQueuedTwig::update (rep);
00489 
00490     IgQtLock ();
00491     rep->clear ();
00492 
00493     if (! m_digis.empty ()) 
00494     {
00495         SoSeparator *sep = new SoSeparator;    
00496         SoMaterial *mat = new SoMaterial;
00497         mat->diffuseColor.setValue (0.3, 0.8, 0.0);
00498         sep->addChild (mat);
00499 
00500         SoDrawStyle *drawStyle = new SoDrawStyle;
00501         drawStyle->pointSize = 3.0;
00502         sep->addChild (drawStyle);
00503     
00504         try 
00505         {
00506             SoVertexProperty *vertices = new SoVertexProperty;
00507             int nVrx = 0;
00508 
00509             for (std::vector<std::pair<CSCDetId, CSCALCTDigi> >::const_iterator i = m_digis.begin (), iEnd = m_digis.end (); 
00510                  i != iEnd; ++i) 
00511             {
00512                 Surface::GlobalPoint pos =  (m_pDD->idToDet ((*i).first))->surface ().position ();
00513             
00514                 float x = pos.x () / 100.0;  // cm -> m
00515                 float y = pos.y () / 100.0;  // cm -> m
00516                 float z = pos.z () / 100.0;  // cm -> m
00517                 
00518                 vertices->vertex.set1Value (nVrx++, SbVec3f (x, y, z));
00519             }
00520             vertices->vertex.setNum (m_digis.size ());
00521 
00522             SoPointSet *points = new SoPointSet;
00523             points->vertexProperty.setValue (vertices);
00524             points->numPoints.setValue (m_digis.size ());
00525             sep->addChild (points);
00526         }    
00527         catch (cms::Exception& e)
00528         {
00529             if (this->m_onCmsException)
00530                 this->m_onCmsException (&e);
00531         }
00532         catch (lat::Error &e) 
00533         {
00534             if (this->m_onError)
00535                 this->m_onError (&e);
00536         }
00537         catch (std::exception &e) 
00538         {
00539             if (this->m_onException)
00540                 this->m_onException (&e);
00541         }
00542         catch (...) 
00543         {
00544             if (this->m_onUnhandledException)
00545                 this->m_onUnhandledException ();
00546         }
00547     
00548         rep->node ()->addChild (sep);
00549     }
00550 }

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