CMS 3D CMS Logo

VisGenJetCollectionTwig.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "VisReco/VisRecoJets/interface/VisGenJetCollectionTwig.h"
00004 #include "VisReco/VisRecoJets/interface/VisGenJetTwig.h"
00005 #include "VisFramework/VisFrameworkBase/interface/VisEventProcessorService.h"
00006 #include "VisFramework/VisFrameworkBase/interface/VisTwigFactroyService.h"
00007 #include "VisFramework/VisFrameworkBase/interface/VisEventSelector.h"
00008 #include "VisFramework/VisFrameworkBase/interface/debug.h"
00009 #include "DataFormats/JetReco/interface/GenJetCollection.h"
00010 #include "FWCore/Framework/interface/Event.h"
00011 #include "FWCore/Framework/interface/EventSetup.h"
00012 #include "FWCore/Utilities/interface/TypeID.h"
00013 #include "Iguana/Inventor/interface/IgSoTower.h"
00014 #include "Iguana/Inventor/interface/IgSbColorMap.h"
00015 #include "Iguana/Inventor/interface/IgSoJet.h"
00016 #include "Iguana/Models/interface/IgTextRep.h"
00017 #include "Iguana/GLModels/interface/Ig3DRep.h"
00018 #include "Iguana/GLModels/interface/IgLegoRep.h"
00019 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00020 #include "Iguana/GLModels/interface/IgRZRep.h"
00021 #include "Iguana/Framework/interface/IgRepSet.h"
00022 #include "Iguana/Studio/interface/IgDocumentData.h"
00023 #include "Iguana/Studio/interface/IgQtLock.h"
00024 #include "Iguana/Studio/interface/IgQtAppStatusBarService.h"
00025 #include <Inventor/nodes/SoMaterial.h>
00026 #include <Inventor/nodes/SoSelection.h>
00027 #include <Inventor/nodes/SoCube.h>
00028 #include <Inventor/nodes/SoTranslation.h>
00029 #include <Inventor/nodes/SoSeparator.h>
00030 #include <Inventor/nodes/SoMaterial.h>
00031 #include <Inventor/nodes/SoText2.h>
00032 #include <qstring.h>
00033 #include <sstream>
00034 #include <iomanip>
00035 
00036 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00037 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00038 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00039 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00040 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00041 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00042 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00043 namespace 
00044 {
00045     VisQueuedTwig *
00046     createThisTwig (IgState *state, IgTwig *parent,
00047                     const std::string &name,
00048                     const std::string &friendlyName,
00049                     const std::string &modLabel,
00050                     const std::string &instanceName,
00051                     const std::string &processName)
00052     {
00053         IgTwig *rootTwig = IgDocumentData::get (state)->root ();
00054         IgTwig *eventTwig = 0;
00055         eventTwig = rootTwig->lookup ("/Objects/CMS Event and Detector/GenJets");
00056         
00057         if (! eventTwig)
00058             eventTwig = parent;
00059 
00060         return new VisGenJetCollectionTwig (state, eventTwig, "[N/A] GenJets (" + name + ")", 
00061                                             friendlyName, modLabel, instanceName, processName);
00062     }
00063 }
00064 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00065 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00066 
00067 VisGenJetCollectionTwig::VisGenJetCollectionTwig (IgState *state, IgTwig *parent,
00068                                                   const std::string &name /* = "" */,
00069                                                   const std::string &friendlyName /* = "" */,
00070                                                   const std::string &moduleLabel /* = "" */,
00071                                                   const std::string &instanceName /* = "" */,
00072                                                   const std::string &processName /* = "" */)
00073     : VisQueuedTwig (state, parent, name),
00074       m_text (name),
00075       m_friendlyName (friendlyName),
00076       m_moduleLabel (moduleLabel),
00077       m_instanceName (instanceName),
00078       m_processName (processName),
00079       m_scale (state, lat::CreateCallback (this, &VisGenJetCollectionTwig::scaleChanged)),
00080       m_cut (state, lat::CreateCallback (this, &VisGenJetCollectionTwig::scaleChanged)),
00081       m_escale (state, lat::CreateCallback (this, &VisGenJetCollectionTwig::scaleChanged)),
00082       m_annotation (state, lat::CreateCallback (this, &VisGenJetCollectionTwig::scaleChanged))
00083 {
00084     VisTwigFactroyService *tfService = VisTwigFactroyService::get (state);
00085     if (! tfService)
00086     {
00087         tfService = new VisTwigFactroyService (state);
00088     }   
00089     edm::TypeID genJetsID (typeid (reco::GenJetCollection));
00090     tfService->registerTwig (genJetsID.friendlyClassName (), &createThisTwig);
00091 }
00092 
00093 void
00094 VisGenJetCollectionTwig::scaleChanged (void)
00095 { IgRepSet::invalidate (this, SELF_MASK); }
00096 
00097 
00098 void
00099 VisGenJetCollectionTwig::onNewEvent (const edm::Event &event,
00100                                      const edm::EventSetup &eventSetup)
00101 {
00102     // Get debugging dump.
00103     VisQueuedTwig::onNewEvent (event, eventSetup);
00104 
00105     if (children ()) destroy ();
00106     
00107     m_text = QString ("Run # %1, event # %2")
00108              .arg (event.id ().run ())
00109              .arg (event.id ().event ()).latin1 ();
00110     
00111     std::vector<edm::Handle<reco::GenJetCollection> > jets;
00112     try 
00113     {
00114         if ((! m_friendlyName.empty ()) || (! m_moduleLabel.empty ()) || (! m_instanceName.empty ()) || (! m_processName.empty ()))
00115         {
00116             VisEventSelector visSel (m_friendlyName, m_moduleLabel, m_instanceName, m_processName);
00117             event.getMany (visSel, jets);
00118         }
00119 //      else
00120 //      {
00121 //          event.getManyByType (jets);
00122 //      }
00123     }
00124     catch (cms::Exception& e)
00125     {
00126         if (this->m_onCmsException)
00127             this->m_onCmsException (&e);
00128     }
00129     catch (lat::Error &e) 
00130     {
00131         if (this->m_onError)
00132             this->m_onError (&e);
00133     }
00134     catch (std::exception &e) 
00135     {
00136         if (this->m_onException)
00137             this->m_onException (&e);
00138     }
00139     catch (...) 
00140     {
00141         if (this->m_onUnhandledException)
00142             this->m_onUnhandledException ();
00143     }
00144     
00145     m_jets.clear ();
00146 
00147     if (! jets.empty ()) 
00148     {
00149         std::vector<edm::Handle<reco::GenJetCollection> >::iterator i;
00150         std::vector<edm::Handle<reco::GenJetCollection> >::iterator iEnd;
00151         for (i = jets.begin (), iEnd = jets.end (); i != iEnd; ++i) 
00152         {
00153             const reco::GenJetCollection& 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             for (reco::GenJetCollection::const_iterator j = c.begin (), jEnd = c.end (); j != jEnd; ++j) 
00163             {
00164                 m_jets.push_back (*j);
00165                 QString name = QString ("GenJet with Et = %1 GeV")
00166                                .arg ((*j).et (), 0, 'f', 2);
00167                 
00168                 new VisGenJetTwig (state (), this, name.latin1 (), event, eventSetup, (*j));
00169             }
00170         }
00171     }
00172             
00173     IgRepSet::invalidate (this->parent (), IgTwig::SELF_MASK | IgTwig::STRUCTURE_MASK);
00174 }
00175 
00176 void
00177 VisGenJetCollectionTwig::update (IgTextRep *rep)
00178 {
00179     // Get debugging dump.
00180     VisQueuedTwig::update (rep);
00181 
00182     // Prepare property description.
00183     std::ostringstream  text;
00184 
00185     text << m_text << "<br>";
00186 
00187     text << "<table width='100%' border=1>"
00188          << "<TR align = center>"
00189          << "<TH>Number</TH>"
00190          << "<TH>E<SUB>t (GeV)</TH>"
00191          << "<TH>E<SUB>em (GeV)</TH>"
00192          << "<TH>E<SUB>had</TH>"
00193          << "<TH>E<SUB>inv</TH>"
00194          << "<TH>E<SUB>aux</TH>"
00195          << "<TH>Eta</TH>"
00196          << "<TH>Phi</TH>"
00197          << "</TR>";
00198     text << setiosflags (std::ios::showpoint | std::ios::fixed);
00199     text.setf (std::ios::right, std::ios::adjustfield);
00200     
00201     int nJets = 0;
00202     if (! m_jets.empty ()) 
00203     {
00204         try 
00205         {
00206             for (reco::GenJetCollection::const_iterator it = m_jets.begin (), itEnd = m_jets.end (); 
00207                  it != itEnd; ++it)
00208             {
00209                 double jetEt = (*it).et ();
00210                 if (jetEt > m_cut.value ())
00211                 {
00212                     double eEm = (*it).emEnergy ();
00213                     double eHad = (*it).hadEnergy ();
00214                     double eInv = (*it).invisibleEnergy ();
00215                     double eAux = (*it).auxiliaryEnergy ();
00216         
00217                     text << "<TR align = right>"
00218                          << "<TD>" << std::setw (3) << nJets++ << "</TD>"
00219                          << "<TD>" << std::setw (2) << std::setprecision (3) << jetEt << "</TD>"
00220                          << "<TD>" << std::setw (2) << std::setprecision (3) << eEm << "</TD>"
00221                          << "<TD>" << std::setw (6) << std::setprecision (3) << eHad << "</TD>"
00222                          << "<TD>" << std::setw (5) << std::setprecision (3) << eInv << "</TD>"
00223                          << "<TD>" << std::setw (5) << std::setprecision (3) << eAux << "</TD>"
00224                          << "<TD>" << std::setw (5) << std::setprecision (3) << (*it).eta () << "</TD>"
00225                          << "<TD>" << std::setw (5) << std::setprecision (3) << (*it).phi () << "</TD></TR>";
00226                 }
00227             }
00228         }
00229         catch (cms::Exception& e)
00230         {
00231             if (this->m_onCmsException)
00232                 this->m_onCmsException (&e);
00233         }
00234         catch (lat::Error &e) 
00235         {
00236             if (this->m_onError)
00237                 this->m_onError (&e);
00238         }
00239         catch (std::exception &e) 
00240         {
00241             if (this->m_onException)
00242                 this->m_onException (&e);
00243         }
00244         catch (...) 
00245         {
00246             if (this->m_onUnhandledException)
00247                 this->m_onUnhandledException ();
00248         }
00249     }
00250     
00251     text << "</table>";
00252     
00253     // Send it over.
00254     IgQtLock ();
00255 
00256     rep->setText (text.str ());
00257 }
00258 
00260 void
00261 VisGenJetCollectionTwig::update (Ig3DRep *rep)
00262 {
00263     // Get debugging dump.
00264     VisQueuedTwig::update (rep);
00265     
00266     // Lock the Qt application.
00267     IgQtLock ();
00268     SoGroup *contents = rep->node ();
00269     contents->removeAllChildren ();
00270     
00271     SoSeparator *jetsSep = new SoSeparator;
00272     contents->addChild (jetsSep);
00273     
00274     SoSeparator *labelSep = new SoSeparator;
00275     contents->addChild (labelSep);
00276     
00277     try 
00278     {
00279         unsigned colour [10] = { 0xff000000, 0xffff0000, 0x00ff0000, // red yellow green
00280                                  0xff00ff00, 0x00ffff00, 0xd0dfff00, // magenta cyan
00281                                  0xff000fff, 0x00ffff00, 0xe00fff00,
00282                                  0xff00ee00};
00283         int i = 0;
00284         
00285         for (reco::GenJetCollection::const_iterator it = m_jets.begin (); 
00286              it != m_jets.end (); it++)
00287         {
00288             if (i == 10) i = 0;
00289             
00290             SoSeparator *sep = new SoSeparator;
00291             jetsSep->addChild (sep);
00292             SoMaterial *mat = new SoMaterial;
00293             float rgbcomponents [4];
00294             IgSbColorMap::unpack (colour [i++], rgbcomponents);
00295             mat->diffuseColor.setValue (rgbcomponents);
00296             sep->addChild (mat);
00297             
00298             double jetEt = (*it).et ();
00299             double jetPhi = (*it).phi();
00300             if (jetPhi < 0) jetPhi += 2 * M_PI;
00301             double jetEta = (*it).eta ();
00302             double jetTheta = 2.0 * atan (exp (-jetEta));
00303             
00304             QString label = QString ("Et = %1 GeV")
00305                             .arg (jetEt, 0, 'f', 2);
00306             SoSeparator *labelSep = new SoSeparator;
00307             SoText2  *jetLabel = new SoText2;
00308             jetLabel->string = label.latin1 ();
00309             SoTranslation *jetLabelTranslation = new SoTranslation;
00310             
00311             double ct = cos (jetTheta);
00312             double st = sin (jetTheta);
00313             double cp = cos (jetPhi);
00314             double sp = sin (jetPhi);
00315             
00316             float length1 = ct ? 4.0 / fabs (ct) : 4.0;
00317             float length2 = st ? 2.0 / fabs (st) : 2.0;
00318             float bodyHeight = length1 < length2 ? length1 : length2;
00319             float hatHeight = 2.0 * jetEt / 100.0;
00320             jetLabelTranslation->translation = SbVec3f ((bodyHeight + hatHeight) * st * cp,
00321                                                         (bodyHeight + hatHeight) * st * sp,
00322                                                         (bodyHeight + hatHeight) * ct);
00323             
00324             labelSep->addChild (jetLabelTranslation);
00325             labelSep->addChild (jetLabel);
00326             sep->addChild (labelSep);
00327             
00328             IgSoJet *recoJet = new IgSoJet;
00329             recoJet->theta.setValue (jetTheta);
00330             recoJet->phi.setValue (jetPhi);
00331             recoJet->energy.setValue (jetEt);
00332             sep->addChild (recoJet); 
00333         }
00334     }
00335     catch (...)
00336     {   
00337         if (IgQtAppStatusBarService *sbar = IgQtAppStatusBarService::get (state ()))
00338         {
00339             sbar->setMessage ("EXCEPTION VisGenJetTwig::update (Ig3DRep *rep) : Cannot show GenJets.");
00340         }
00341     }
00342 }
00343 
00345 void
00346 VisGenJetCollectionTwig::update (IgLegoRep *rep)
00347 {
00348     // Get debugging dump.
00349     VisQueuedTwig::update (rep);
00350     
00351     // Lock the Qt application.
00352     IgQtLock ();
00353     rep->clear ();
00354 
00355     SoSeparator *contents = new SoSeparator;
00356     
00357     SoSeparator *jetsSep = new SoSeparator;
00358     contents->addChild (jetsSep);
00359     
00360     SoSeparator *labelSep = new SoSeparator;
00361     contents->addChild (labelSep);
00362     
00363     if (! m_jets.empty ()) 
00364     {
00365         try 
00366         {
00367             unsigned colour [10] = { 0xff000000, 0xffff0000, 0x00ff0000, // red yellow green
00368                                      0xff00ff00, 0x00ffff00, 0xd0dfff00, // magenta cyan
00369                                      0xff000fff, 0x00ffff00, 0xe00fff00,
00370                                      0xff00ee00};
00371             int i = 0;
00372         
00373             for (reco::GenJetCollection::const_iterator it = m_jets.begin (), itEnd = m_jets.end (); 
00374                  it != itEnd; ++it)
00375             {
00376                 double jetEt = (*it).et ();
00377                 if (jetEt > m_cut.value ()) 
00378                 {
00379                     if (i == 10) i = 0;
00380             
00381                     SoSeparator *sep = new SoSeparator;
00382                     jetsSep->addChild (sep);
00383                     SoMaterial *mat = new SoMaterial;
00384                     float rgbcomponents [4];
00385                     IgSbColorMap::unpack (colour [i++], rgbcomponents);
00386                     mat->diffuseColor.setValue (rgbcomponents);
00387                     sep->addChild (mat);
00388             
00389                     double jetPhi = (*it).phi();
00390                     if (jetPhi < 0) jetPhi += 2 * M_PI;
00391                     double jetEta = (*it).eta ();
00392             
00393                     QString label = QString ("Et = %1 GeV")
00394                                     .arg (jetEt, 0, 'f', 2);
00395                     SoSeparator *labelSep = new SoSeparator;
00396                     SoText2  *jetLabel = new SoText2;
00397                     jetLabel->string = label.latin1 ();
00398                     SoTranslation *jetLabelTranslation = new SoTranslation;
00399             
00400                     jetLabelTranslation->translation = SbVec3f (jetPhi, jetEt / m_scale.value () + 0.01, jetEta);
00401             
00402                     labelSep->addChild (jetLabelTranslation);
00403                     labelSep->addChild (jetLabel);
00404                     sep->addChild (labelSep);
00405             
00406                     //      std::vector<CaloTowerDetId> caloTowers = (*it).getTowerIndices ();
00407             
00408                     //      for (std::vector<CaloTowerDetId>::const_iterator j = caloTowers.begin (); 
00409                     //           j != caloTowers.end (); j++) 
00410                     //      {
00411                     //          for (std::vector <std::pair < CaloTowerDetId, CaloTower> >::const_iterator i = m_towers.begin ();
00412                     //               i != m_towers.end (); i++)
00413                     //          {
00414                     //              if ((*i).first == (*j))
00415                     //              {
00416                     //                  double eta = (*i).second.eta ();
00417                     //                  double phi = (*i).second.phi ();
00418                     //                  if (phi < 0) phi += 2 * M_PI;
00419                     //                  double et = (*i).second.et ();
00420 
00421                     //                  SoSeparator *tsep = new SoSeparator;
00422                     
00423                     //                  SoTranslation *localTransl = new SoTranslation;
00424                     //                  localTransl->translation.setValue (SbVec3f (phi, et / (2 * 20.0), eta)); // m_scale.value ()
00425                     
00426                     //                  SoCube *towerBox = new SoCube;
00427                     //                  towerBox->height = et / 20.0 + 0.001; // m_scale.value ()
00428                     //                  if (fabs(eta) > 1.74) towerBox->width = 0.176f;
00429                     //                  else towerBox->width  = 0.089;
00430                     //                  towerBox->depth  = VisHcalGrid::phi4eta (fabs(eta)) + 0.002;
00431                     
00432                     //                  tsep->addChild (localTransl);
00433                     //                  tsep->addChild (towerBox);
00434                     //                  sep->addChild (tsep);
00435                     //              }
00436                     //                 } 
00437                     //      }
00438                 }
00439             }
00440         }
00441         catch (cms::Exception& e)
00442         {
00443             if (this->m_onCmsException)
00444                 this->m_onCmsException (&e);
00445         }
00446         catch (lat::Error &e) 
00447         {
00448             if (this->m_onError)
00449                 this->m_onError (&e);
00450         }
00451         catch (std::exception &e) 
00452         {
00453             if (this->m_onException)
00454                 this->m_onException (&e);
00455         }
00456         catch (...) 
00457         {
00458             if (this->m_onUnhandledException)
00459                 this->m_onUnhandledException ();
00460         }
00461     }
00462 
00463     rep->node ()->addChild (contents);
00464 }
00465 
00466 void
00467 VisGenJetCollectionTwig::update (IgRPhiRep *rep) 
00468 {}
00469 
00470 void
00471 VisGenJetCollectionTwig::update (IgRZRep *rep) 
00472 {}
00473 

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