00001
00002
00003 #include "VisReco/VisRecoJets/interface/VisGenJetTwig.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/VisFrameworkBase/interface/debug.h"
00008 #include "DataFormats/JetReco/interface/GenJet.h"
00009 #include "FWCore/Framework/interface/Event.h"
00010 #include "FWCore/Framework/interface/EventSetup.h"
00011 #include "FWCore/Utilities/interface/TypeID.h"
00012 #include "Iguana/Inventor/interface/IgSoTower.h"
00013 #include "Iguana/Inventor/interface/IgSbColorMap.h"
00014 #include "Iguana/Inventor/interface/IgSoJet.h"
00015 #include "Iguana/Models/interface/IgTextRep.h"
00016 #include "Iguana/GLModels/interface/Ig3DRep.h"
00017 #include "Iguana/GLModels/interface/IgLegoRep.h"
00018 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00019 #include "Iguana/GLModels/interface/IgRZRep.h"
00020 #include "Iguana/Framework/interface/IgRepSet.h"
00021 #include "Iguana/Studio/interface/IgQtLock.h"
00022 #include "Iguana/Studio/interface/IgQtAppStatusBarService.h"
00023 #include <Inventor/nodes/SoMaterial.h>
00024 #include <Inventor/nodes/SoSelection.h>
00025 #include <Inventor/nodes/SoCube.h>
00026 #include <Inventor/nodes/SoTranslation.h>
00027 #include <Inventor/nodes/SoSeparator.h>
00028 #include <Inventor/nodes/SoMaterial.h>
00029 #include <Inventor/nodes/SoText2.h>
00030 #include <qstring.h>
00031 #include <sstream>
00032 #include <iomanip>
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 VisGenJetTwig::VisGenJetTwig (IgState *state, IgTwig *parent,
00045 const std::string &name ,
00046 const edm::Event &event,
00047 const edm::EventSetup &eventSetup,
00048 const reco::GenJet &jet)
00049 : VisQueuedTwig (state, parent, name),
00050 m_event (event),
00051 m_eventSetup (eventSetup),
00052 m_jet (jet),
00053 m_scale (state, lat::CreateCallback (this, &VisGenJetTwig::scaleChanged)),
00054 m_cut (state, lat::CreateCallback (this, &VisGenJetTwig::scaleChanged)),
00055 m_escale (state, lat::CreateCallback (this, &VisGenJetTwig::scaleChanged)),
00056 m_annotation (state, lat::CreateCallback (this, &VisGenJetTwig::scaleChanged))
00057 {}
00058
00059 void
00060 VisGenJetTwig::scaleChanged (void)
00061 { IgRepSet::invalidate (this, SELF_MASK); }
00062
00063 void
00064 VisGenJetTwig::onNewEvent (const edm::Event &event,
00065 const edm::EventSetup &eventSetup)
00066 {
00067
00068 VisQueuedTwig::onNewEvent (event, eventSetup);
00069 }
00070
00071 void
00072 VisGenJetTwig::update (IgTextRep *rep)
00073 {
00074
00075 VisQueuedTwig::update (rep);
00076
00077
00078 std::ostringstream text;
00079
00080 text << QString ("Run # %1, event # %2")
00081 .arg (m_event.id ().run ())
00082 .arg (m_event.id ().event ()).latin1 () << "<br>";
00083
00084 text << "<table width='100%' border=1>"
00085 << "<TR align = center>"
00086 << "<TH>E<SUB>t (GeV)</TH>"
00087 << "<TH>E<SUB>em (GeV)</TH>"
00088 << "<TH>E<SUB>had</TH>"
00089 << "<TH>E<SUB>inv</TH>"
00090 << "<TH>E<SUB>aux</TH>"
00091 << "<TH>Eta</TH>"
00092 << "<TH>Phi</TH>"
00093 << "</TR>";
00094 text << setiosflags (std::ios::showpoint | std::ios::fixed);
00095 text.setf (std::ios::right, std::ios::adjustfield);
00096
00097 try
00098 {
00099 double jetEt = m_jet.et ();
00100 if (jetEt > m_cut.value ())
00101 {
00102 double eEm = m_jet.emEnergy ();
00103 double eHad = m_jet.hadEnergy ();
00104 double eInv = m_jet.invisibleEnergy ();
00105 double eAux = m_jet.auxiliaryEnergy ();
00106
00107 text << "<TR align = right>"
00108 << "<TD>" << std::setw (2) << std::setprecision (3) << jetEt << "</TD>"
00109 << "<TD>" << std::setw (2) << std::setprecision (3) << eEm << "</TD>"
00110 << "<TD>" << std::setw (6) << std::setprecision (3) << eHad << "</TD>"
00111 << "<TD>" << std::setw (5) << std::setprecision (3) << eInv << "</TD>"
00112 << "<TD>" << std::setw (5) << std::setprecision (3) << eAux << "</TD>"
00113 << "<TD>" << std::setw (5) << std::setprecision (3) << m_jet.eta () << "</TD>"
00114 << "<TD>" << std::setw (5) << std::setprecision (3) << m_jet.phi () << "</TD></TR>";
00115
00116 text << "</table>";
00117 }
00118 else
00119 {
00120 text << "</table><br>The jet energy " << jetEt << "GeV is below an energy cut (" << m_cut.value () << "<br>";
00121 }
00122 }
00123 catch (cms::Exception& e)
00124 {
00125 if (this->m_onCmsException)
00126 this->m_onCmsException (&e);
00127 }
00128 catch (lat::Error &e)
00129 {
00130 if (this->m_onError)
00131 this->m_onError (&e);
00132 }
00133 catch (std::exception &e)
00134 {
00135 if (this->m_onException)
00136 this->m_onException (&e);
00137 }
00138 catch (...)
00139 {
00140 if (this->m_onUnhandledException)
00141 this->m_onUnhandledException ();
00142 }
00143
00144
00145 IgQtLock ();
00146
00147 rep->setText (text.str ());
00148 }
00149
00151 void
00152 VisGenJetTwig::update (Ig3DRep *rep)
00153 {
00154
00155 VisQueuedTwig::update (rep);
00156
00157
00158 IgQtLock ();
00159 rep->clear ();
00160
00161 SoSeparator *contents = new SoSeparator;
00162
00163 SoSeparator *jetsSep = new SoSeparator;
00164 contents->addChild (jetsSep);
00165
00166 SoSeparator *labelSep = new SoSeparator;
00167 contents->addChild (labelSep);
00168
00169 try
00170 {
00171 double jetEt = m_jet.et ();
00172 if (jetEt > m_cut.value ())
00173 {
00174 SoSeparator *sep = new SoSeparator;
00175 jetsSep->addChild (sep);
00176 SoMaterial *mat = new SoMaterial;
00177 float rgbcomponents [4];
00178 IgSbColorMap::unpack (0x66330000, rgbcomponents);
00179 mat->diffuseColor.setValue (rgbcomponents);
00180 sep->addChild (mat);
00181
00182 double jetPhi = m_jet.phi();
00183 if (jetPhi < 0) jetPhi += 2 * M_PI;
00184 double jetEta = m_jet.eta();
00185 double jetTheta = 2.0 * atan (exp (-jetEta));
00186
00187 QString label = QString ("Et = %1 GeV")
00188 .arg (jetEt, 0, 'g', 2);
00189 SoSeparator *labelSep = new SoSeparator;
00190 SoText2 *jetLabel = new SoText2;
00191 jetLabel->string = label.latin1 ();
00192 SoTranslation *jetLabelTranslation = new SoTranslation;
00193
00194 double ct = cos (jetTheta);
00195 double st = sin (jetTheta);
00196 double cp = cos (jetPhi);
00197 double sp = sin (jetPhi);
00198
00199 float length1 = ct ? 4.0 / fabs (ct) : 4.0;
00200 float length2 = st ? 2.0 / fabs (st) : 2.0;
00201 float bodyHeight = length1 < length2 ? length1 : length2;
00202 float hatHeight = 2.0 * jetEt / 100.0;
00203 jetLabelTranslation->translation = SbVec3f ((bodyHeight + hatHeight) * st * cp,
00204 (bodyHeight + hatHeight) * st * sp,
00205 (bodyHeight + hatHeight) * ct);
00206
00207 labelSep->addChild (jetLabelTranslation);
00208 labelSep->addChild (jetLabel);
00209 sep->addChild (labelSep);
00210
00211 IgSoJet *recoJet = new IgSoJet;
00212 recoJet->theta.setValue (jetTheta);
00213 recoJet->phi.setValue (jetPhi);
00214 recoJet->energy.setValue (jetEt);
00215 sep->addChild (recoJet);
00216 }
00217 }
00218 catch (cms::Exception& e)
00219 {
00220 if (this->m_onCmsException)
00221 this->m_onCmsException (&e);
00222 }
00223 catch (lat::Error &e)
00224 {
00225 if (this->m_onError)
00226 this->m_onError (&e);
00227 }
00228 catch (std::exception &e)
00229 {
00230 if (this->m_onException)
00231 this->m_onException (&e);
00232 }
00233 catch (...)
00234 {
00235 if (this->m_onUnhandledException)
00236 this->m_onUnhandledException ();
00237 }
00238
00239 rep->node ()->addChild (contents);
00240 }
00241
00243 void
00244 VisGenJetTwig::update (IgLegoRep *rep)
00245 {
00246
00247 VisQueuedTwig::update (rep);
00248
00249
00250 IgQtLock ();
00251 rep->clear ();
00252
00253 SoSeparator *contents = new SoSeparator;
00254
00255 SoSeparator *jetsSep = new SoSeparator;
00256 contents->addChild (jetsSep);
00257
00258 SoSeparator *labelSep = new SoSeparator;
00259 contents->addChild (labelSep);
00260
00261 try
00262 {
00263 double jetEt = m_jet.et ();
00264 if (jetEt > m_cut.value ())
00265 {
00266 SoSeparator *sep = new SoSeparator;
00267 jetsSep->addChild (sep);
00268 SoMaterial *mat = new SoMaterial;
00269 float rgbcomponents [4];
00270 IgSbColorMap::unpack (0x66330000, rgbcomponents);
00271 mat->diffuseColor.setValue (rgbcomponents);
00272 sep->addChild (mat);
00273
00274 double jetPhi = m_jet.phi();
00275 if (jetPhi < 0) jetPhi += 2 * M_PI;
00276 double jetEta = m_jet.eta ();
00277
00278 QString label = QString ("Et = %1 GeV")
00279 .arg (jetEt, 0, 'g', 2);
00280 SoSeparator *labelSep = new SoSeparator;
00281 SoText2 *jetLabel = new SoText2;
00282 jetLabel->string = label.latin1 ();
00283 SoTranslation *jetLabelTranslation = new SoTranslation;
00284
00285 jetLabelTranslation->translation = SbVec3f (jetPhi, jetEt / m_scale.value () + 0.01, jetEta);
00286
00287 labelSep->addChild (jetLabelTranslation);
00288 labelSep->addChild (jetLabel);
00289 sep->addChild (labelSep);
00290 }
00291 }
00292
00293 catch (cms::Exception& e)
00294 {
00295 if (this->m_onCmsException)
00296 this->m_onCmsException (&e);
00297 }
00298 catch (lat::Error &e)
00299 {
00300 if (this->m_onError)
00301 this->m_onError (&e);
00302 }
00303 catch (std::exception &e)
00304 {
00305 if (this->m_onException)
00306 this->m_onException (&e);
00307 }
00308 catch (...)
00309 {
00310 if (this->m_onUnhandledException)
00311 this->m_onUnhandledException ();
00312 }
00313
00314 rep->node ()->addChild (contents);
00315 }
00316
00317 void
00318 VisGenJetTwig::update (IgRPhiRep *rep)
00319 {}
00320
00321 void
00322 VisGenJetTwig::update (IgRZRep *rep)
00323 {}
00324