CMS 3D CMS Logo

VisHBHERecHitTwig.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "VisReco/VisHcal/interface/VisHBHERecHitTwig.h"
00004 #include "VisReco/VisHcal/interface/VisHcalSubdetector.h"
00005 #include "VisFramework/VisFrameworkBase/interface/VisTwigFactroyService.h"
00006 #include "VisFramework/VisFrameworkBase/interface/VisEventSelector.h"
00007 #include "VisFramework/VisEventSetup/interface/VisEventSetupService.h"
00008 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00009 #include "DataFormats/HcalRecHit/interface/HBHERecHit.h"
00010 #include "FWCore/Framework/interface/Event.h"
00011 #include "Iguana/Models/interface/IgTextRep.h"
00012 #include "Iguana/GLModels/interface/Ig3DRep.h"
00013 #include "Iguana/GLModels/interface/IgLegoRep.h"
00014 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00015 #include "Iguana/GLModels/interface/IgRZRep.h"
00016 #include "Iguana/Framework/interface/IgRepSet.h"
00017 #include "Iguana/Inventor/interface/IgSbColorMap.h"
00018 #include "Iguana/Inventor/interface/IgSoCrystalHit.h"
00019 #include "Iguana/Inventor/interface/IgSoCircularHist.h"
00020 #include "Iguana/Inventor/interface/IgSoRectColHist.h"
00021 #include "Iguana/Inventor/interface/IgSoTower.h"
00022 #include "Iguana/Studio/interface/IgDocumentData.h"
00023 #include "Iguana/Studio/interface/IgQtAppStatusBarService.h"
00024 #include "Iguana/Studio/interface/IgQtLock.h"
00025 #include <Inventor/nodes/SoDrawStyle.h>
00026 #include <Inventor/nodes/SoMaterial.h>
00027 #include <Inventor/nodes/SoSeparator.h>
00028 #include <qapplication.h>
00029 #include <qstring.h>
00030 #include <classlib/utils/DebugAids.h>
00031 #include <algorithm>
00032 #include <iostream>
00033 #include <iomanip>
00034 
00035 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00036 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00037 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00038 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00039 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00040 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00041 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00042 
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/HCAL Event/Hcal Barrel and Endcap RecHits");
00056         
00057         if (! eventTwig) 
00058             eventTwig = parent;
00059                 
00060         return new VisHBHERecHitTwig (state, eventTwig, "[N/A] HB and HE RecHits (" + name + ")", 
00061                                       friendlyName, modLabel, instanceName, processName);
00062     }
00063 }
00064 
00065 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00066 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00067 
00068 VisHBHERecHitTwig::VisHBHERecHitTwig (IgState *state, IgTwig *parent,
00069                                       const std::string &name /* = "" */,
00070                                       const std::string &friendlyName /* = "" */,
00071                                       const std::string &moduleLabel /* = "" */,
00072                                       const std::string &instanceName /* = "" */,
00073                                       const std::string &processName /* = "" */,
00074                                       unsigned colour /* = 0x99ff0000 */)
00075     : VisQueuedTwig (state, parent, name),
00076       m_name (name),
00077       m_friendlyName (friendlyName),
00078       m_moduleLabel (moduleLabel),
00079       m_instanceName (instanceName),
00080       m_processName (processName),
00081       m_binning (state, lat::CreateCallback (this, &VisHBHERecHitTwig::twigChanged)),
00082       m_annotation (state, lat::CreateCallback (this, &VisHBHERecHitTwig::twigChanged)),
00083       m_escale (state, lat::CreateCallback (this, &VisHBHERecHitTwig::twigChanged)),
00084       m_cut (state, lat::CreateCallback (this, &VisHBHERecHitTwig::twigChanged)),
00085       m_scale (state, lat::CreateCallback (this, &VisHBHERecHitTwig::twigChanged)),
00086       m_phiStart (state, lat::CreateCallback (this, &VisHBHERecHitTwig::twigChanged)),
00087       m_phiDelta (state, lat::CreateCallback (this, &VisHBHERecHitTwig::twigChanged)),
00088       m_rMax (state, lat::CreateCallback (this, &VisHBHERecHitTwig::twigChanged)),
00089       m_colorCode (state, lat::CreateCallback (this, &VisHBHERecHitTwig::twigChanged)),
00090       m_showHit (state, lat::CreateCallback (this, &VisHBHERecHitTwig::twigChanged)),
00091       m_showTower (state, lat::CreateCallback (this, &VisHBHERecHitTwig::twigChanged)),
00092       m_text ("no info"),
00093       m_recHits (2350),
00094       m_rgba (colour),
00095       m_ncolors (10)
00096 {
00097     VisTwigFactroyService *tfService = VisTwigFactroyService::get (state);
00098     if (! tfService)
00099     {
00100         tfService = new VisTwigFactroyService (state);
00101     }
00102     edm::TypeID recHitCollID (typeid (HBHERecHitCollection));
00103     tfService->registerTwig (recHitCollID.friendlyClassName (), &createThisTwig);
00104     generateColors ();
00105 }
00106 
00107 VisHBHERecHitTwig::~VisHBHERecHitTwig (void) 
00108 {
00109     if (! m_colors.empty ())
00110     {
00111         for (std::vector<SoMaterial *>::iterator it = m_colors.begin (); it != m_colors.end (); ++it)
00112         {
00113             (*it)->unref (); //let OIV collect these
00114         }
00115         m_colors.resize (0);
00116     }
00117 }
00118 
00119 void
00120 VisHBHERecHitTwig::twigChanged (void)
00121 { IgRepSet::invalidate (this, SELF_MASK); }
00122 
00123 void
00124 VisHBHERecHitTwig::onNewEvent (const edm::Event &event,
00125                                const edm::EventSetup &eventSetup)
00126 {
00127     // Get debugging dump.
00128     VisQueuedTwig::onNewEvent (event, eventSetup);
00129 
00130     m_recHits.clear ();
00131     
00132     m_text = (QString ("Run # %1, event # %2")
00133               .arg (event.id ().run ())
00134               .arg (event.id ().event ()).latin1 ());
00135     
00136     std::vector<edm::Handle<HBHERecHitCollection> > barrelRecHits;
00137     try
00138     {
00139         QApplication::setOverrideCursor (Qt::waitCursor);
00140             
00141         if (IgQtAppStatusBarService *sbar = IgQtAppStatusBarService::get (state ()))
00142             sbar->setMessage ("Retrieving an HBHERecHitCollection...");
00143 
00144         if ((! m_friendlyName.empty ()) || (! m_moduleLabel.empty ()) || (! m_instanceName.empty ()) || (! m_processName.empty ()))
00145         {
00146             VisEventSelector visSel (m_friendlyName, m_moduleLabel, m_instanceName, m_processName);
00147             event.getMany (visSel, barrelRecHits);
00148         }
00149 
00150         if (IgQtAppStatusBarService *sbar = IgQtAppStatusBarService::get (state ()))
00151             sbar->setMessage ("HBHERecHitCollection done.");    
00152  
00153         QApplication::restoreOverrideCursor ();
00154     }
00155     catch (cms::Exception& e)
00156     {
00157         e.append (" from VisHBHERecHitTwig::onNewEvent ");
00158         e.append (this->name ());    
00159 
00160         if (this->m_onCmsException)
00161             this->m_onCmsException (&e);
00162     }
00163     catch (lat::Error &e) 
00164     {
00165         if (this->m_onError)
00166             this->m_onError (&e);
00167     }
00168     catch (std::exception &e) 
00169     {
00170         if (this->m_onException)
00171             this->m_onException (&e);
00172     }
00173     catch (...) 
00174     {
00175         if (this->m_onUnhandledException)
00176             this->m_onUnhandledException ();
00177     }
00178     if (! barrelRecHits.empty ())
00179     {
00180         m_maxEnergy = 0;
00181         for (std::vector<edm::Handle<HBHERecHitCollection> >::iterator i = barrelRecHits.begin (), iEnd = barrelRecHits.end (); i != iEnd; ++i) 
00182         {
00183             const HBHERecHitCollection& c = *(*i);
00184             QString sizeStr = (QString ("%1").arg (c.size ()));
00185             QString nameStr = QString (this->name ());
00186             int ib = nameStr.find ("[");
00187             int ie = nameStr.find ("]");
00188             nameStr.replace (ib + 1, ie - 1, sizeStr);
00189             this->name (nameStr);
00190             for (std::vector<HBHERecHit>::const_iterator ibarrel = c.begin (), ibarrelEnd = c.end (); 
00191                  ibarrel != ibarrelEnd; ++ibarrel)
00192             {
00193                 m_recHits.push_back (*ibarrel);
00194                 m_maxEnergy < (*ibarrel).energy () ? m_maxEnergy = (*ibarrel).energy () : m_maxEnergy;
00195             }
00196         }
00197     }
00198 
00199     VisQueuedTwig::onBaseInvalidate ();
00200 
00201     if (IgQtAppStatusBarService *sbar = IgQtAppStatusBarService::get (state ()))
00202         sbar->setMessage (QString (m_text));
00203 }
00204 
00205 void
00206 VisHBHERecHitTwig::update (IgTextRep *rep)
00207 {
00208     // Get debugging dump.
00209     VisQueuedTwig::update (rep);
00210 
00211     // Prepare property description.
00212     std::ostringstream  text;
00213     text << this->name () << " from ";
00214     text << m_text << "<br>";
00215     
00216     if (m_friendlyName.empty () && m_moduleLabel.empty () && m_instanceName.empty () && m_processName.empty ())
00217     {
00218         text << "Please, select the branches of this Twig for more information.";       
00219     }
00220     else
00221     {
00222         text << "Displayed only above  " << m_cut.value () << " GeV:<br>";
00223 
00224         text << "<table width='100%' border=1>"
00225              << "<TR align = center>"
00226              << "<TH>Number</TH>"
00227              << "<TH>Energy</TH>"
00228              << "<TH>Time</TH>"
00229              << "<TH>Subdetector</TH>"
00230              << "<TH>ietaAbs</TH>"
00231              << "<TH>ieta</TH>"
00232              << "<TH>iphi [rad]</TH>"
00233              << "<TH>Depth</TH>"
00234              << "</TR>";
00235         text << setiosflags (std::ios::showpoint | std::ios::fixed);
00236         text.setf (std::ios::right, std::ios::adjustfield);
00237     
00238         int nDigis = 0;
00239         try 
00240         {
00241             for (std::vector<HBHERecHit>::const_iterator i = m_recHits.begin (), iEnd = m_recHits.end (); i != iEnd; ++i) 
00242             {
00243                 float energy = (*i).energy ();
00244                 if (energy > m_cut.value ())
00245                 {
00246                     text << "<TR align = right>"
00247                          << "<TD>" << std::setw (3) << nDigis++ << "</TD>"
00248                          << "<TD>" << std::setw (5) << std::setprecision (3) << energy << "</TD>"
00249                          << "<TD>" << std::setw (5) << std::setprecision (3) << (*i).time () << "</TD>"
00250                          << "<TD>" << std::setw (2) << VisHcalSubdetector::subDetName ((*i).id ().subdet ()) << "</TD>"
00251                          << "<TD>" << std::setw (5) << std::setprecision (3) << (*i).id ().ietaAbs () << "</TD>"
00252                          << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).id ().ieta () << "</TD>"
00253                          << "<TD>" << std::setw (5) << std::setprecision (3) << (*i).id ().iphi () << "</TD>"
00254                          << "<TD>" << std::setw (5) << std::setprecision (3) << (*i).id ().depth() << "</TD>"
00255                          << "</TR>";
00256                 }           
00257             }
00258         }
00259         catch (cms::Exception& e)
00260         {
00261             e.append (" from VisHBHERecHitTwig::update(IgTextRep*) ");
00262             e.append (this->name ());    
00263 
00264             if (this->m_onCmsException)
00265                 this->m_onCmsException (&e);
00266         }
00267         catch (lat::Error &e) 
00268         {
00269             if (this->m_onError)
00270                 this->m_onError (&e);
00271         }
00272         catch (std::exception &e) 
00273         {
00274             if (this->m_onException)
00275                 this->m_onException (&e);
00276         }
00277         catch (...) 
00278         {
00279             if (this->m_onUnhandledException)
00280                 this->m_onUnhandledException ();
00281         }
00282         text << "</table>";
00283     }
00284     
00285     // Send it over.
00286     IgQtLock ();
00287     rep->setText (text.str ());
00288 }
00289 
00290 void
00291 VisHBHERecHitTwig::update (Ig3DRep *rep)
00292 {
00293     // Get debugging dump.
00294     VisQueuedTwig::update (rep);
00295 
00296     IgQtLock ();
00297     rep->clear ();
00298 
00299     SoSeparator *sep = new SoSeparator;
00300 
00301     if (m_colorCode.value () == "mono")
00302     {
00303         SoMaterial *mat = new SoMaterial;
00304         float rgbcomponents [4];
00305         IgSbColorMap::unpack (m_rgba, rgbcomponents);
00306         mat->diffuseColor.setValue (SbColor (rgbcomponents));
00307         sep->addChild (mat);
00308     }
00309     
00310     if (! m_recHits.empty ())
00311     {
00312         VisEventSetupService *esService = VisEventSetupService::get (state ());
00313         ASSERT (esService);
00314 
00315         try 
00316         {
00317             for (std::vector<HBHERecHit>::const_iterator i = m_recHits.begin (), iEnd = m_recHits.end (); i != iEnd; ++i) 
00318             {
00319                 float energy = (*i).energy ();
00320                 if (energy > m_cut.value ()) 
00321                 {
00322                     const CaloCellGeometry::CornersVec& corners = esService->getCorners ((*i).detid ());
00323                     ASSERT (corners.size () == 8);
00324                 
00325                     IgSoCrystalHit *crystalHit = new IgSoCrystalHit;
00326                     crystalHit->energy.setValue (energy);
00327                     
00328                     crystalHit->scale.setValue (m_escale.value ());
00329                     crystalHit->relativeWidth.setValue (0.9);
00330                     crystalHit->drawCrystal.setValue (m_showTower.value ());
00331                     crystalHit->drawHit.setValue (m_showHit.value ());
00332 
00333                     crystalHit->front1.setValue (corners [0].x () / 100.0, corners [0].y () / 100.0, corners [0].z () / 100.0);
00334                     crystalHit->front2.setValue (corners [1].x () / 100.0, corners [1].y () / 100.0, corners [1].z () / 100.0);
00335                     crystalHit->front3.setValue (corners [2].x () / 100.0, corners [2].y () / 100.0, corners [2].z () / 100.0);
00336                     crystalHit->front4.setValue (corners [3].x () / 100.0, corners [3].y () / 100.0, corners [3].z () / 100.0);
00337                     
00338                     crystalHit->back1.setValue  (corners [4].x () / 100.0, corners [4].y () / 100.0, corners [4].z () / 100.0);
00339                     crystalHit->back2.setValue  (corners [5].x () / 100.0, corners [5].y () / 100.0, corners [5].z () / 100.0);
00340                     crystalHit->back3.setValue  (corners [6].x () / 100.0, corners [6].y () / 100.0, corners [6].z () / 100.0);
00341                     crystalHit->back4.setValue  (corners [7].x () / 100.0, corners [7].y () / 100.0, corners [7].z () / 100.0);
00342                     
00343                     if (m_colorCode.value () == "mono")
00344                     {
00345                         sep->addChild (crystalHit);
00346                     }
00347                     else
00348                     {
00349                         SoSeparator *tsep = new SoSeparator; // isolate each hit
00350                         tsep->addChild (energyColor (energy));
00351                         tsep->addChild (crystalHit);
00352                         sep->addChild (tsep);                   
00353                     }               
00354                 }
00355             }
00356         }
00357         catch (cms::Exception& e)
00358         {
00359             e.append (" from VisHBHERecHitTwig::update(Ig3DRep*) ");
00360             e.append (this->name ());    
00361 
00362             if (this->m_onCmsException)
00363                 this->m_onCmsException (&e);
00364         }
00365         catch (lat::Error &e) 
00366         {
00367             if (this->m_onError)
00368                 this->m_onError (&e);
00369         }
00370         catch (std::exception &e) 
00371         {
00372             if (this->m_onException)
00373                 this->m_onException (&e);
00374         }
00375         catch (...) 
00376         {
00377             if (this->m_onUnhandledException)
00378                 this->m_onUnhandledException ();
00379         }
00380     }
00381     
00382     rep->node ()->addChild (sep);
00383 }
00384 
00385 void
00386 VisHBHERecHitTwig::update (IgLegoRep *rep)
00387 {
00388     // Get debugging dump.
00389     VisQueuedTwig::update (rep);
00390 
00391     IgQtLock ();
00392     rep->clear ();
00393     
00394     SoSeparator *sep = new SoSeparator;    
00395 
00396     try 
00397     {
00398         if (! m_recHits.empty ())
00399         {
00400             for (std::vector<HBHERecHit>::const_iterator i = m_recHits.begin (), iEnd = m_recHits.end (); i != iEnd; ++i) 
00401             {
00402                 float et = (*i).energy ();
00403                 if (fabs (et) > m_cut.value ()) 
00404                 {
00405                     int iphi = (*i).id ().iphi ();
00406                     int ieta = (*i).id ().ieta ();
00407                     
00408                     float phi = (iphi - 1) * 0.087 + 0.087 / 2.0;
00409                     float eta = ieta * 0.087 + 0.087 / 2.0;
00410             
00411                     IgSoTower *tower = new IgSoTower;
00412                     tower->position = SbVec2f (phi, eta); // eta, phi
00413                     tower->scaleFactor = m_scale.value ();
00414                     tower->energy = et;
00415                     tower->emFraction = 0.0; // EM/Total 0%
00416                     sep->addChild (tower);
00417                 }
00418             }
00419         }
00420     }
00421     catch (cms::Exception& e)
00422     {
00423         e.append (" from VisHBHERecHitTwig::update(IgLegoRep *) ");
00424         e.append (this->name ());    
00425 
00426         if (this->m_onCmsException)
00427             this->m_onCmsException (&e);
00428     }
00429     catch (lat::Error &e) 
00430     {
00431         if (this->m_onError)
00432             this->m_onError (&e);
00433     }
00434     catch (std::exception &e) 
00435     {
00436         if (this->m_onException)
00437             this->m_onException (&e);
00438     }
00439     catch (...) 
00440     {
00441         if (this->m_onUnhandledException)
00442             this->m_onUnhandledException ();
00443     }
00444     
00445     rep->node ()->addChild (sep);
00446 }
00447 
00448 void
00449 VisHBHERecHitTwig::update (IgRPhiRep *rep)
00450 {
00451     // Get debugging dump.
00452     VisQueuedTwig::update (rep);
00453 
00454     IgQtLock ();
00455     rep->clear ();
00456     
00457     SoSeparator *sep = new SoSeparator;    
00458     SoSeparator *posSep = new SoSeparator;    
00459     SoSeparator *negSep = new SoSeparator;
00460     sep->addChild (posSep);
00461     sep->addChild (negSep);
00462     
00463     SoMaterial *mat = new SoMaterial;
00464     mat->ambientColor.setValue (0.0, 0.4, 1.0);
00465     mat->diffuseColor.setValue (0.0, 0.4, 1.0);
00466     mat->specularColor.setValue (0.0, 0.4, 1.0);
00467     mat->emissiveColor.setValue (0.0, 0.4, 1.0);
00468     posSep->addChild (mat);
00469     
00470     SoMaterial *negMat = new SoMaterial;
00471     negMat->ambientColor.setValue (1.0, 0.0, 0.0);
00472     negMat->diffuseColor.setValue (1.0, 0.0, 0.0);
00473     negMat->specularColor.setValue (1.0, 0.0, 0.0);
00474     negMat->emissiveColor.setValue (1.0, 0.0, 0.0);
00475     negSep->addChild (negMat);
00476 
00477     int nbrOfBins = 72;
00478     int binNumber;
00479 
00480     std::vector<float> bufferPositive (nbrOfBins);
00481     std::vector<float> bufferNegative (nbrOfBins);
00482     try 
00483     {
00484         if (! m_recHits.empty ())
00485         {
00486             for (std::vector<HBHERecHit>::const_iterator i = m_recHits.begin (), iEnd = m_recHits.end (); i != iEnd; ++i) 
00487             {
00488                 float energy = (*i).energy ();
00489                 if (energy > m_cut.value ())
00490                 {
00491                     if (VisHcalSubdetector::subDetName ((*i).id ().subdet ()) == "HcalBarrel")
00492                     {
00493                         int iphi = (*i).id ().iphi ();
00494                         binNumber = iphi - 1;
00495 
00496                         if (binNumber >= 0 && binNumber < 72) 
00497                             if (m_binning.value () == "project")
00498                             {                           
00499                                 if ((energy > 0.0) && (energy > bufferPositive [binNumber]))
00500                                     bufferPositive [binNumber] = energy;
00501                                 else if ((energy < 0.0) && (energy < bufferNegative [binNumber]))
00502                                     bufferNegative [binNumber] = energy;
00503                             }
00504                             else
00505                                 (energy > 0.0) ?  bufferPositive [binNumber] += energy : bufferNegative [binNumber] += energy;
00506                     }
00507                 }
00508             }
00509 
00510             if (*max_element (bufferPositive.begin (), bufferPositive.end ()) > 0.0)
00511             {
00512                 IgSoCircularHist *recHits = new IgSoCircularHist;
00513                 recHits->minRadius = 1.9;
00514                 recHits->maxRadius = m_rMax.value ();
00515                 recHits->scaleFactor = m_escale.value ();
00516                 recHits->numberOfBins = nbrOfBins;
00517                 recHits->energies.setValues (0, nbrOfBins, &bufferPositive [0]);
00518                 recHits->logScale = false;
00519                 recHits->showAnnotations = m_annotation.value ();
00520                 recHits->layer = 5.5;
00521                 posSep->addChild (recHits);
00522             }
00523             
00524             std::vector<float>::const_iterator nfirst = bufferNegative.begin ();
00525             std::vector<float>::const_iterator nlast = bufferNegative.end ();
00526 
00527             if (fabs(*max_element (nfirst, nlast)) > 0.0)
00528             {
00529                 IgSoCircularHist *negRecHits = new IgSoCircularHist;
00530                 negRecHits->minRadius = 1.9;
00531                 negRecHits->maxRadius = -1;
00532                 negRecHits->scaleFactor = m_escale.value ();
00533                 negRecHits->numberOfBins = nbrOfBins;
00534                 negRecHits->energies.setValues (0, nbrOfBins, &bufferNegative [0]);
00535                 negRecHits->logScale = false;
00536                 negRecHits->showAnnotations = m_annotation.value ();
00537                 negRecHits->layer = 5.0;
00538                 negSep->addChild (negRecHits);
00539             }       
00540         }
00541     }
00542     catch (cms::Exception& e)
00543     {
00544         e.append (" from VisHBHERecHitTwig::update (IgRPhiRep*) ");
00545         e.append (this->name ());    
00546 
00547         if (this->m_onCmsException)
00548             this->m_onCmsException (&e);
00549     }
00550     catch (lat::Error &e) 
00551     {
00552         if (this->m_onError)
00553             this->m_onError (&e);
00554     }
00555     catch (std::exception &e) 
00556     {
00557         if (this->m_onException)
00558             this->m_onException (&e);
00559     }
00560     catch (...) 
00561     {
00562         if (this->m_onUnhandledException)
00563             this->m_onUnhandledException ();
00564     }
00565     
00566     rep->node ()->addChild (sep);
00567 }
00568 
00569 void
00570 VisHBHERecHitTwig::update (IgRZRep *rep)
00571 {
00572     // Get debugging dump.
00573     VisQueuedTwig::update (rep);
00574         
00575     IgQtLock ();
00576     rep->clear ();
00577         
00578     SoSeparator *sep = new SoSeparator;    
00579 
00580     SoMaterial *mat = new SoMaterial;
00581     float rgbcomponents [4];
00582     IgSbColorMap::unpack (m_rgba, rgbcomponents);
00583     mat->ambientColor.setValue (SbColor (rgbcomponents));
00584     mat->diffuseColor.setValue (SbColor (rgbcomponents));
00585     mat->specularColor.setValue (SbColor (rgbcomponents));
00586     mat->emissiveColor.setValue (SbColor (rgbcomponents));
00587     sep->addChild (mat);
00588 
00589     VisEventSetupService *esService = VisEventSetupService::get (state ());
00590     ASSERT (esService);
00591 
00592     unsigned binNumber = 0;
00593     const unsigned nBinsZ = 17*2;
00594     const unsigned nBinsR = 13*2;
00595     const unsigned nbrOfBins = 2 * (nBinsZ + nBinsR);
00596     const float radiusR = 1.86f;
00597     const float radiusZ = 3.78f;
00598     const float barrelMaxEta = 1.444f;            // max eta of HCAL Barrel
00599     const float beamPipeTheta = esService->etaToTheta (3.f);
00600     std::vector<float> energies (nbrOfBins * 2);  // times 2 for the other energy (which is not used)
00601 
00602     try 
00603     {
00604         if (! m_recHits.empty ())
00605         {
00606             for (std::vector<HBHERecHit>::const_iterator i = m_recHits.begin (), iEnd = m_recHits.end (); i != iEnd; ++i) 
00607             {
00608                 float energy = (*i).energy ();
00609                 if (energy > m_cut.value ())
00610                 {
00611                     binNumber = esService->getBinNumber ((*i).detid (), nBinsR, nBinsZ, radiusR, radiusZ, barrelMaxEta, beamPipeTheta);
00612 
00613                     if (binNumber < nbrOfBins)
00614                     {
00615                         if (m_binning.value () == "project")
00616                             (energies[binNumber] > energy) ? energies[binNumber] : energies[binNumber] = energy;
00617                         else
00618                             energies[binNumber] += energy;
00619                     }
00620                     else
00621                     {
00622                         std::cerr << "Bin number (" << binNumber << ") exceeds the number of bins (" <<  nbrOfBins << ")"<< std::endl;
00623                     }
00624                 }
00625             }
00626                         
00627             if (*max_element (energies.begin (), energies.end ()) > 0.0)
00628             {
00629                 SoMaterial *mat = new SoMaterial;
00630                 mat->ambientColor.setValue (0.0, 0.4, 1.0);
00631                 mat->diffuseColor.setValue (0.0, 0.4, 1.0);
00632                 mat->specularColor.setValue (0.0, 0.4, 1.0);
00633                 mat->emissiveColor.setValue (0.0, 0.4, 1.0);
00634 
00635                 SoDrawStyle *drawStyle = new SoDrawStyle;
00636                 drawStyle->lineWidth.setValue (2.0);
00637 
00638                 IgSoRectColHist* hist = new IgSoRectColHist;
00639                 hist->radiusR = radiusR;
00640                 hist->radiusZ = radiusZ;
00641                 if (m_rMax.value () > 0) hist->maxDist = m_rMax.value ();               
00642                 hist->numR = nBinsR;
00643                 hist->numZ = nBinsZ;
00644                 hist->energies.setValues (0, energies.size(), &energies [0]);
00645                 hist->logScale = false;
00646                 hist->layer = -5.0;
00647                 hist->scaleFactor = m_escale.value ();
00648                 hist->barrelMaxEta = barrelMaxEta;
00649                 hist->beamPipeTheta = beamPipeTheta;
00650                                 
00651                 std::vector<SbColor> colors (4);
00652                 colors[0] = SbColor (0.0, 0.3, 1.0); // first energy's positive color 
00653                 colors[1] = SbColor (1.0, 0.0, 1.0); // first energy's negative color
00654                 colors[2] = SbColor (1.0, 0.4, 0.0); // second energy's positive color (not used)
00655                 colors[3] = SbColor (1.0, 1.0, 0.0); // second energy's negative color (not used)
00656                                 
00657                 hist->faceColors.setValues (0, colors.size (), &colors[0]);
00658                 sep->addChild (mat);
00659                 sep->addChild (drawStyle);
00660                 sep->addChild (hist);
00661             }
00662         }
00663     }
00664     catch (cms::Exception& e)
00665     {
00666         e.append (" from VisHBHERecHitTwig::update(IgRZRep*) ");
00667         e.append (this->name ());    
00668 
00669         if (this->m_onCmsException)
00670             this->m_onCmsException (&e);
00671     }
00672     catch (lat::Error &e) 
00673     {
00674         if (this->m_onError)
00675             this->m_onError (&e);
00676     }
00677     catch (std::exception &e) 
00678     {
00679         if (this->m_onException)
00680             this->m_onException (&e);
00681     }
00682     catch (...) 
00683     {
00684         if (this->m_onUnhandledException)
00685             this->m_onUnhandledException ();
00686     }
00687     
00688     rep->node ()->addChild (sep);
00689 }
00690 
00691 SoMaterial * 
00692 VisHBHERecHitTwig::energyColor (const float energy)
00693 {
00694     // determine color (energy)
00695     int color_ndx = static_cast<int>((energy - m_cut.value ()) * m_ncolors / (m_maxEnergy - m_cut.value ()));
00696     color_ndx = std::min (color_ndx, m_ncolors - 1);
00697     return m_colors [color_ndx];
00698 }
00699 
00700 void
00701 VisHBHERecHitTwig::generateColors (void)
00702 {
00703     float hue = 0.66667F; // reverse load to get low to high: hue 0 -> red, 2/3->blue
00704     float saturation= 1.0F; 
00705     float value = 1.0F;
00706     SbColor hsvColor;
00707     float delta_hue = hue / m_ncolors;
00708     if (m_colors.empty ())
00709     {
00710         m_colors.reserve (m_ncolors);
00711         for (int i = 0; i < m_ncolors; i++, hue -= delta_hue)
00712         {
00713             hsvColor.setHSVValue (hue, saturation, value);
00714             SoMaterial *material = new SoMaterial;
00715             material->diffuseColor.setValue (hsvColor);
00716             m_colors.push_back (material);
00717             material->ref (); // make sure OIV doesn't garbage collect 
00718         }
00719     }
00720     else
00721     {
00722         for (std::vector<SoMaterial *>::iterator it = m_colors.begin (); it != m_colors.end (); it++, hue -= delta_hue)
00723         {
00724             hsvColor.setHSVValue (hue, saturation, value);
00725             (*it)->diffuseColor.setValue (hsvColor);
00726         }
00727     }
00728 }
00729 
00730 

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