CMS 3D CMS Logo

VisCandidateTwig.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "VisReco/VisRecoJets/interface/VisCandidateTwig.h"
00004 #include "VisFramework/VisFrameworkBase/interface/VisEventProcessorService.h"
00005 #include "VisFramework/VisFrameworkBase/interface/VisTwigFactroyService.h"
00006 #include "VisFramework/VisFrameworkBase/interface/VisEventSelector.h"
00007 #include "VisFramework/VisEventSetup/interface/VisEventSetupService.h"
00008 #include "VisFramework/VisFrameworkBase/interface/debug.h"
00009 #include "DataFormats/Candidate/interface/Candidate.h"
00010 #include "FWCore/Framework/interface/Event.h"
00011 #include "FWCore/Framework/interface/EventSetup.h"
00012 #include "Iguana/Models/interface/IgTextRep.h"
00013 #include "Iguana/GLModels/interface/Ig3DRep.h"
00014 #include "Iguana/GLModels/interface/IgLegoRep.h"
00015 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00016 #include "Iguana/GLModels/interface/IgRZRep.h"
00017 #include "Iguana/Framework/interface/IgRepSet.h"
00018 #include "Iguana/Studio/interface/IgDocumentData.h"
00019 #include "Iguana/Inventor/interface/IgSbColorMap.h"
00020 #include "Iguana/Inventor/interface/IgSoArrow.h"
00021 #include "Iguana/Studio/interface/IgQtLock.h"
00022 #include "Iguana/Studio/interface/IgQtAppStatusBarService.h"
00023 #include <Inventor/nodes/SoFont.h>
00024 #include <Inventor/nodes/SoCube.h>
00025 #include <Inventor/nodes/SoText2.h>
00026 #include <Inventor/nodes/SoTranslation.h>
00027 #include <Inventor/nodes/SoSeparator.h>
00028 #include <Inventor/nodes/SoMaterial.h>
00029 #include <qstring.h>
00030 #include <sstream>
00031 #include <iomanip>
00032 
00033 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00034 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00035 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00036 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00037 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00038 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00039 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00040 
00041 namespace 
00042 {
00043     VisQueuedTwig *
00044     createThisTwig (IgState *state, IgTwig *parent,
00045                     const std::string &name,
00046                     const std::string &friendlyName,
00047                     const std::string &modLabel,
00048                     const std::string &instanceName,
00049                     const std::string &processName)
00050     {
00051         IgTwig *rootTwig = IgDocumentData::get (state)->root ();
00052         IgTwig *eventTwig = 0;
00053         eventTwig = rootTwig->lookup ("/Objects/CMS Event and Detector/Candidates");
00054         
00055         if (! eventTwig)
00056             eventTwig = parent;
00057         return new VisCandidateTwig (state, eventTwig, "[N/A] Candidate (" + name + ")", 
00058                                      friendlyName, modLabel, instanceName, processName);
00059     }
00060 }
00061 
00062 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00063 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00064 
00065 VisCandidateTwig::VisCandidateTwig (IgState *state, IgTwig *parent,
00066                                     const std::string &name /* = "" */,
00067                                     const std::string &friendlyName /* = "" */,
00068                                     const std::string &moduleLabel /* = "" */,
00069                                     const std::string &instanceName /* = "" */,
00070                                     const std::string &processName /* = "" */)
00071     : VisQueuedTwig (state, parent, name),
00072       m_text (name),
00073       m_friendlyName (friendlyName),
00074       m_moduleLabel (moduleLabel),
00075       m_instanceName (instanceName),
00076       m_processName (processName),
00077       m_scale (state, lat::CreateCallback (this, &VisCandidateTwig::scaleChanged)),
00078       m_cut (state, lat::CreateCallback (this, &VisCandidateTwig::scaleChanged)),
00079       m_escale (state, lat::CreateCallback (this, &VisCandidateTwig::scaleChanged)),
00080       m_annotation (state, lat::CreateCallback (this, &VisCandidateTwig::scaleChanged))
00081 {    
00082     VisTwigFactroyService *tfService = VisTwigFactroyService::get (state);
00083     if (! tfService)
00084     {
00085         tfService = new VisTwigFactroyService (state);
00086     }   
00087     edm::TypeID candID (typeid (reco::CandidateCollection));
00088     tfService->registerTwig (candID.friendlyClassName (), &createThisTwig);
00089 }
00090 
00091 void
00092 VisCandidateTwig::scaleChanged (void)
00093 { IgRepSet::invalidate (this, SELF_MASK); }
00094 
00095 
00096 void
00097 VisCandidateTwig::onNewEvent (const edm::Event &event,
00098                               const edm::EventSetup &eventSetup)
00099 {
00100     // Get debugging dump.
00101     VisQueuedTwig::onNewEvent (event, eventSetup);
00102 
00103     m_text = QString ("Run # %1, event # %2")
00104              .arg (event.id ().run ())
00105              .arg (event.id ().event ()).latin1 ();
00106     m_candidates.clear ();
00107     
00108     edm::Handle<reco::CandidateCollection> collections;
00109     try 
00110     {
00111         if ((! m_friendlyName.empty ()) || (! m_moduleLabel.empty ()) || (! m_instanceName.empty ()) || (! m_processName.empty ()))
00112         {
00113             VisEventSelector visSel (m_friendlyName, m_moduleLabel, m_instanceName, m_processName);
00114             event.get (visSel, collections);
00115         }
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     if (collections.isValid ())
00138     {
00139         QString sizeStr = (QString ("%1").arg (collections->size ()));
00140         QString nameStr = QString (this->name ());
00141         int ib = nameStr.find ("[");
00142         int ie = nameStr.find ("]");
00143         nameStr.replace (ib + 1, ie - 1, sizeStr);          
00144         this->name (nameStr);
00145 
00146         for (reco::CandidateCollection::const_iterator it = collections->begin (), itEnd = collections->end (); it != itEnd; ++it) 
00147         {
00148             m_candidates.push_back ((*it).clone ());
00149         }
00150     }
00151 
00152     VisQueuedTwig::onBaseInvalidate ();
00153 }
00154 
00155 void
00156 VisCandidateTwig::update (IgTextRep *rep)
00157 {
00158     // Get debugging dump.
00159     VisQueuedTwig::update (rep);
00160 
00161     // Prepare property description.
00162     std::ostringstream  text;
00163 
00164     text << m_text << "<br>";
00165 
00166     text << "<table width='100%' border=1>"
00167          << "<TR align = center>"
00168          << "<TH>Number</TH>"
00169          << "<TH>E<SUB>T (GeV)</TH>"
00170          << "<TH>eta</TH>"
00171          << "<TH>phi [rad]</TH>"
00172          << "</TR>";
00173     text << setiosflags (std::ios::showpoint | std::ios::fixed);
00174     text.setf (std::ios::right, std::ios::adjustfield);
00175     
00176     int n = 0;
00177     if (! m_candidates.empty ()) 
00178     {
00179         try 
00180         {
00181             for (std::vector<const reco::Candidate *>::const_iterator it = m_candidates.begin (), itEnd = m_candidates.end (); it != itEnd; ++it) 
00182             {
00183                 double et = (*it)->et ();           
00184                 double phi = (*it)->phi ();
00185                 double eta = (*it)->eta ();
00186         
00187                 text << "<TR align = right>"
00188                      << "<TD>" << std::setw (3) << n++ << "</TD>"
00189                      << "<TD>" << std::setw (2) << std::setprecision (3) << et << "</TD>"
00190                      << "<TD>" << std::setw (6) << std::setprecision (3) << eta << "</TD>"
00191                      << "<TD>" << std::setw (5) << std::setprecision (3) << phi << "</TD>"
00192                      << "</TR>";
00193             }
00194         }
00195         catch (cms::Exception& e)
00196         {
00197             if (this->m_onCmsException)
00198                 this->m_onCmsException (&e);
00199         }
00200         catch (lat::Error &e) 
00201         {
00202             if (this->m_onError)
00203                 this->m_onError (&e);
00204         }
00205         catch (std::exception &e) 
00206         {
00207             if (this->m_onException)
00208                 this->m_onException (&e);
00209         }
00210         catch (...) 
00211         {
00212             if (this->m_onUnhandledException)
00213                 this->m_onUnhandledException ();
00214         }
00215     }   
00216        
00217     text << "</table>";
00218     
00219     // Send it over.
00220     IgQtLock ();
00221 
00222     rep->setText (text.str ());
00223 }
00224 
00226 void
00227 VisCandidateTwig::update (Ig3DRep *rep)
00228 {
00229     // Get debugging dump.
00230     VisQueuedTwig::update (rep);
00231     
00232     // Lock the Qt application.
00233     IgQtLock ();
00234     rep->clear ();
00235     
00236     SoSeparator *contents = new SoSeparator;
00237     SoSeparator *candSep = new SoSeparator;
00238     contents->addChild (candSep);
00239     
00240     SoSeparator *labelSep = new SoSeparator;
00241     contents->addChild (labelSep);
00242     
00243     if (! m_candidates.empty ()) 
00244     {
00245         try 
00246         {
00247             unsigned colour [10] = { 0xff000000, 0x00ff0000, 0xffff0000, // red green yellow
00248                                      0xff00ff00, 0x00ffff00, 0xd0dfff00, // magenta cyan
00249                                      0xff000fff, 0x00ffff00, 0xe00fff00,
00250                                      0xff00ee00};
00251             int i = 0;
00252         
00253             for (std::vector<const reco::Candidate *>::const_iterator it = m_candidates.begin (), itEnd = m_candidates.end (); it != itEnd; ++it)
00254             {
00255                 double et = (*it)->et ();
00256                 if (et > m_cut.value ()) 
00257                 {
00258                     SbVec3f tipPos (SbVec3f ((*it)->px () / 100.0, (*it)->py () / 100.0, (*it)->pz () / 100.0));
00259                     SbVec3f tailPos (SbVec3f ((*it)->vx () / 100.0, (*it)->vy () / 100.0, (*it)->vz () / 100.0));
00260                     IgSoArrow* arrow = new IgSoArrow;
00261                     arrow->tail.setValue (tailPos);
00262                     arrow->tip.setValue (tipPos);       
00263                     candSep->addChild (arrow);
00264                 }
00265             }
00266         }
00267         catch (cms::Exception& e)
00268         {
00269             if (this->m_onCmsException)
00270                 this->m_onCmsException (&e);
00271         }
00272         catch (lat::Error &e) 
00273         {
00274             if (this->m_onError)
00275                 this->m_onError (&e);
00276         }
00277         catch (std::exception &e) 
00278         {
00279             if (this->m_onException)
00280                 this->m_onException (&e);
00281         }
00282         catch (...) 
00283         {
00284             if (this->m_onUnhandledException)
00285                 this->m_onUnhandledException ();
00286         }
00287     }
00288 
00289     rep->node ()->addChild (contents);
00290 }
00291 
00293 void
00294 VisCandidateTwig::update (IgLegoRep *rep)
00295 {
00296     // Get debugging dump.
00297     VisQueuedTwig::update (rep);
00298     
00299     // Lock the Qt application.
00300     IgQtLock ();
00301 
00302     rep->clear ();
00303 
00304     VisEventSetupService *esService = VisEventSetupService::get (state ());
00305     ASSERT (esService);
00306 
00307     SoSeparator *contents = new SoSeparator;
00308     
00309     SoSeparator *candSep = new SoSeparator;
00310     contents->addChild (candSep);
00311     
00312     SoSeparator *labelSep = new SoSeparator;
00313     contents->addChild (labelSep);
00314     
00315     if (! m_candidates.empty ()) 
00316     {
00317         try 
00318         {
00319             unsigned colour [10] = { 0xff000000, 0x00ff0000, 0xffff0000, // red green yellow 
00320                                      0xff00ff00, 0x00ffff00, 0xd0dfff00, // magenta cyan
00321                                      0xff000fff, 0x00ffff00, 0xe00fff00,
00322                                      0xff00ee00};
00323             int i = 0;
00324 
00325             for (std::vector<const reco::Candidate *>::const_iterator it = m_candidates.begin (), itEnd = m_candidates.end (); it != itEnd; ++it)
00326             {
00327                 double et = (*it)->et ();
00328                 if (et > m_cut.value ()) 
00329                 {
00330                     if (i == 10) i = 0;
00331             
00332                     SoSeparator *sep = new SoSeparator;
00333                     candSep->addChild (sep);
00334                     SoMaterial *mat = new SoMaterial;
00335                     float rgbcomponents [4];
00336                     IgSbColorMap::unpack (colour [i++], rgbcomponents);
00337                     mat->diffuseColor.setValue (rgbcomponents);
00338                     sep->addChild (mat);
00339 
00340                     SoFont *font = new SoFont;
00341                     font->name = "Times-Roman";
00342                     font->size = 14.0;
00343                     sep->addChild (font);
00344             
00345                     double eta = (*it)->eta ();
00346                     double phi = (*it)->phi ();
00347                     if (phi < 0) phi += 2 * M_PI;
00348 
00349                     if (m_annotation.value ())
00350                     {                   
00351                         QString label = QString ("Et = %1 GeV")
00352                                         .arg (et, 0, 'f', 2);
00353                         SoSeparator *labelSep = new SoSeparator;
00354                         SoText2  *labelText = new SoText2;
00355                         labelText->string = label.latin1 ();
00356                         SoTranslation *labelTranslation = new SoTranslation;
00357                         double labelHight = et / m_scale.value () + 0.2;
00358             
00359                         labelTranslation->translation = SbVec3f (phi, labelHight, eta); //m_scale.value ()
00360             
00361                         labelSep->addChild (labelTranslation);
00362                         labelSep->addChild (labelText);
00363                         sep->addChild (labelSep);
00364                     }
00365             
00366                     SoSeparator *tsep = new SoSeparator;
00367                     
00368                     SoTranslation *localTransl = new SoTranslation;
00369                     localTransl->translation.setValue (SbVec3f (phi, et / (2 * m_scale.value ()), eta));
00370                     
00371                     SoCube *towerBox = new SoCube;
00372                     towerBox->height = et / m_scale.value () + 0.001;
00373                     if (fabs(eta) > 1.74) towerBox->width = 0.176f;
00374                     else towerBox->width  = 0.089;
00375                     towerBox->depth  = esService->phi4eta (fabs(eta)) + 0.002;
00376                     
00377                     tsep->addChild (localTransl);
00378                     tsep->addChild (towerBox);
00379                     sep->addChild (tsep);
00380                 }
00381             }
00382         }
00383         catch (cms::Exception& e)
00384         {
00385             if (this->m_onCmsException)
00386                 this->m_onCmsException (&e);
00387         }
00388         catch (lat::Error &e) 
00389         {
00390             if (this->m_onError)
00391                 this->m_onError (&e);
00392         }
00393         catch (std::exception &e) 
00394         {
00395             if (this->m_onException)
00396                 this->m_onException (&e);
00397         }
00398         catch (...) 
00399         {
00400             if (this->m_onUnhandledException)
00401                 this->m_onUnhandledException ();
00402         }
00403     }
00404 
00405     rep->node ()->addChild (contents);
00406 }
00407 
00408 void
00409 VisCandidateTwig::update (IgRPhiRep *rep) 
00410 {}
00411 
00412 void
00413 VisCandidateTwig::update (IgRZRep *rep) 
00414 {}
00415 

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