00001
00002
00003 #include "VisReco/VisHcal/interface/VisHFRecHitTwig.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/HFRecHit.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/IgSoRectColHist.h"
00020 #include "Iguana/Inventor/interface/IgSoTower.h"
00021 #include "Iguana/Studio/interface/IgDocumentData.h"
00022 #include "Iguana/Studio/interface/IgQtAppStatusBarService.h"
00023 #include "Iguana/Studio/interface/IgQtLock.h"
00024 #include <Inventor/nodes/SoDrawStyle.h>
00025 #include <Inventor/nodes/SoMaterial.h>
00026 #include <Inventor/nodes/SoSeparator.h>
00027 #include <qapplication.h>
00028 #include <qstring.h>
00029 #include <classlib/utils/DebugAids.h>
00030 #include <algorithm>
00031 #include <iostream>
00032 #include <iomanip>
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 namespace
00043 {
00044 VisQueuedTwig *
00045 createThisTwig (IgState *state, IgTwig *parent,
00046 const std::string &name,
00047 const std::string &friendlyName,
00048 const std::string &modLabel,
00049 const std::string &instanceName,
00050 const std::string &processName)
00051 {
00052 IgTwig *rootTwig = IgDocumentData::get (state)->root ();
00053 IgTwig *eventTwig = 0;
00054 eventTwig = rootTwig->lookup ("/Objects/CMS Event and Detector/HCAL Event/Hcal Forward RecHits");
00055
00056 if (! eventTwig)
00057 eventTwig = parent;
00058
00059 return new VisHFRecHitTwig (state, eventTwig, "[N/A] HF RecHits (" + name + ")",
00060 friendlyName, modLabel, instanceName, processName);
00061 }
00062 }
00063
00064
00065
00066
00067 VisHFRecHitTwig::VisHFRecHitTwig (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 unsigned colour )
00074 : VisQueuedTwig (state, parent, name),
00075 m_name (name),
00076 m_friendlyName (friendlyName),
00077 m_moduleLabel (moduleLabel),
00078 m_instanceName (instanceName),
00079 m_processName (processName),
00080 m_binning (state, lat::CreateCallback (this, &VisHFRecHitTwig::twigChanged)),
00081 m_annotation (state, lat::CreateCallback (this, &VisHFRecHitTwig::twigChanged)),
00082 m_escale (state, lat::CreateCallback (this, &VisHFRecHitTwig::twigChanged)),
00083 m_cut (state, lat::CreateCallback (this, &VisHFRecHitTwig::twigChanged)),
00084 m_scale (state, lat::CreateCallback (this, &VisHFRecHitTwig::twigChanged)),
00085 m_phiStart (state, lat::CreateCallback (this, &VisHFRecHitTwig::twigChanged)),
00086 m_phiDelta (state, lat::CreateCallback (this, &VisHFRecHitTwig::twigChanged)),
00087 m_text ("no info"),
00088 m_recHits (880),
00089 m_rgba (colour)
00090 {
00091 VisTwigFactroyService *tfService = VisTwigFactroyService::get (state);
00092 if (! tfService)
00093 {
00094 tfService = new VisTwigFactroyService (state);
00095 }
00096 edm::TypeID recHitCollID (typeid (HFRecHitCollection));
00097 tfService->registerTwig (recHitCollID.friendlyClassName (), &createThisTwig);
00098 }
00099
00100 void
00101 VisHFRecHitTwig::twigChanged (void)
00102 { IgRepSet::invalidate (this, SELF_MASK); }
00103
00104 void
00105 VisHFRecHitTwig::onNewEvent (const edm::Event &event,
00106 const edm::EventSetup &eventSetup)
00107 {
00108
00109 VisQueuedTwig::onNewEvent (event, eventSetup);
00110
00111 m_recHits.clear ();
00112
00113 m_text = (QString ("Run # %1, event # %2")
00114 .arg (event.id ().run ())
00115 .arg (event.id ().event ()).latin1 ());
00116
00117 std::vector<edm::Handle<HFRecHitCollection> > recHits;
00118 try
00119 {
00120 QApplication::setOverrideCursor (Qt::waitCursor);
00121
00122 if (IgQtAppStatusBarService *sbar = IgQtAppStatusBarService::get (state ()))
00123 sbar->setMessage ("Retrieving an HFRecHitCollection...");
00124
00125 if ((! m_friendlyName.empty ()) || (! m_moduleLabel.empty ()) || (! m_instanceName.empty ()) || (! m_processName.empty ()))
00126 {
00127 VisEventSelector visSel (m_friendlyName, m_moduleLabel, m_instanceName, m_processName);
00128 event.getMany (visSel, recHits);
00129 }
00130
00131 if (IgQtAppStatusBarService *sbar = IgQtAppStatusBarService::get (state ()))
00132 sbar->setMessage ("HFRecHitCollection done.");
00133
00134 QApplication::restoreOverrideCursor ();
00135 }
00136 catch (cms::Exception& e)
00137 {
00138 e.append (" from VisHFRecHitTwig::onNewEvent ");
00139 e.append (this->name ());
00140
00141 if (this->m_onCmsException)
00142 this->m_onCmsException (&e);
00143 }
00144 catch (lat::Error &e)
00145 {
00146 if (this->m_onError)
00147 this->m_onError (&e);
00148 }
00149 catch (std::exception &e)
00150 {
00151 if (this->m_onException)
00152 this->m_onException (&e);
00153 }
00154 catch (...)
00155 {
00156 if (this->m_onUnhandledException)
00157 this->m_onUnhandledException ();
00158 }
00159 if (! recHits.empty ())
00160 {
00161 for (std::vector<edm::Handle<HFRecHitCollection> >::iterator i = recHits.begin (), iEnd = recHits.end (); i != iEnd; ++i)
00162 {
00163 const HFRecHitCollection& c = *(*i);
00164 QString sizeStr = (QString ("%1").arg (c.size ()));
00165 QString nameStr = QString (this->name ());
00166 int ib = nameStr.find ("[");
00167 int ie = nameStr.find ("]");
00168 nameStr.replace (ib + 1, ie - 1, sizeStr);
00169 this->name (nameStr);
00170 for (std::vector<HFRecHit>::const_iterator ci = c.begin (), ciEnd = c.end ();
00171 ci != ciEnd; ++ci)
00172 {
00173 m_recHits.push_back (*ci);
00174 }
00175 }
00176 }
00177
00178 VisQueuedTwig::onBaseInvalidate ();
00179
00180 if (IgQtAppStatusBarService *sbar = IgQtAppStatusBarService::get (state ()))
00181 sbar->setMessage (QString (m_text));
00182 }
00183
00184 void
00185 VisHFRecHitTwig::update (IgTextRep *rep)
00186 {
00187
00188 VisQueuedTwig::update (rep);
00189
00190
00191 std::ostringstream text;
00192 text << this->name () << " from ";
00193 text << m_text << "<br>";
00194
00195 if (m_friendlyName.empty () && m_moduleLabel.empty () && m_instanceName.empty () && m_processName.empty ())
00196 {
00197 text << "Please, select the branches of this Twig for more information.";
00198 }
00199 else
00200 {
00201 text << "Displayed only above " << m_cut.value () << " GeV:<br>";
00202
00203 text << "<table width='100%' border=1>"
00204 << "<TR align = center>"
00205 << "<TH>Number</TH>"
00206 << "<TH>Energy</TH>"
00207 << "<TH>Time</TH>"
00208 << "<TH>Subdetector</TH>"
00209 << "<TH>ietaAbs</TH>"
00210 << "<TH>ieta</TH>"
00211 << "<TH>iphi [rad]</TH>"
00212 << "<TH>Depth</TH>"
00213 << "</TR>";
00214 text << setiosflags (std::ios::showpoint | std::ios::fixed);
00215 text.setf (std::ios::right, std::ios::adjustfield);
00216
00217 int nDigis = 0;
00218 try
00219 {
00220 for (std::vector<HFRecHit>::const_iterator i = m_recHits.begin (), iEnd = m_recHits.end (); i != iEnd; ++i)
00221 {
00222 float energy = (*i).energy ();
00223 if (energy > m_cut.value ())
00224 {
00225 text << "<TR align = right>"
00226 << "<TD>" << std::setw (3) << nDigis++ << "</TD>"
00227 << "<TD>" << std::setw (5) << std::setprecision (3) << energy << "</TD>"
00228 << "<TD>" << std::setw (5) << std::setprecision (3) << (*i).time () << "</TD>"
00229 << "<TD>" << std::setw (2) << VisHcalSubdetector::subDetName ((*i).id ().subdet ()) << "</TD>"
00230 << "<TD>" << std::setw (5) << std::setprecision (3) << (*i).id ().ietaAbs () << "</TD>"
00231 << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).id ().ieta () << "</TD>"
00232 << "<TD>" << std::setw (5) << std::setprecision (3) << (*i).id ().iphi () << "</TD>"
00233 << "<TD>" << std::setw (5) << std::setprecision (3) << (*i).id ().depth() << "</TD>"
00234 << "</TR>";
00235 }
00236 }
00237 }
00238 catch (cms::Exception& e)
00239 {
00240 e.append (" from VisHFRecHitTwig::update(IgTextRep*) ");
00241 e.append (this->name ());
00242
00243 if (this->m_onCmsException)
00244 this->m_onCmsException (&e);
00245 }
00246 catch (lat::Error &e)
00247 {
00248 if (this->m_onError)
00249 this->m_onError (&e);
00250 }
00251 catch (std::exception &e)
00252 {
00253 if (this->m_onException)
00254 this->m_onException (&e);
00255 }
00256 catch (...)
00257 {
00258 if (this->m_onUnhandledException)
00259 this->m_onUnhandledException ();
00260 }
00261
00262 text << "</table>";
00263 }
00264
00265
00266 IgQtLock ();
00267 rep->setText (text.str ());
00268 }
00269
00270 void
00271 VisHFRecHitTwig::update (Ig3DRep *rep)
00272 {
00273
00274 VisQueuedTwig::update (rep);
00275
00276 IgQtLock ();
00277 rep->clear ();
00278
00279 SoSeparator *sep = new SoSeparator;
00280
00281 SoMaterial *mat = new SoMaterial;
00282 float rgbcomponents [4];
00283 IgSbColorMap::unpack (m_rgba, rgbcomponents);
00284 mat->diffuseColor.setValue (SbColor (rgbcomponents));
00285 sep->addChild (mat);
00286
00287 if (! m_recHits.empty ())
00288 {
00289 VisEventSetupService *esService = VisEventSetupService::get (state ());
00290 ASSERT (esService);
00291
00292 try
00293 {
00294 for (std::vector<HFRecHit>::const_iterator i = m_recHits.begin (), iEnd = m_recHits.end (); i != iEnd; ++i)
00295 {
00296 float energy = (*i).energy ();
00297 if (energy > m_cut.value ())
00298 {
00299 const CaloCellGeometry::CornersVec& corners = esService->getCorners ((*i).detid ());
00300 ASSERT (corners.size () == 8);
00301
00302 IgSoCrystalHit *crystalHit = new IgSoCrystalHit;
00303 crystalHit->energy.setValue (energy);
00304
00305 crystalHit->scale.setValue (m_escale.value ());
00306 crystalHit->relativeWidth.setValue (0.9);
00307 crystalHit->drawCrystal.setValue (false);
00308 crystalHit->drawHit.setValue (true);
00309
00310 crystalHit->front1.setValue (corners [0].x () / 100.0, corners [0].y () / 100.0, corners [0].z () / 100.0);
00311 crystalHit->front2.setValue (corners [1].x () / 100.0, corners [1].y () / 100.0, corners [1].z () / 100.0);
00312 crystalHit->front3.setValue (corners [2].x () / 100.0, corners [2].y () / 100.0, corners [2].z () / 100.0);
00313 crystalHit->front4.setValue (corners [3].x () / 100.0, corners [3].y () / 100.0, corners [3].z () / 100.0);
00314
00315 crystalHit->back1.setValue (corners [4].x () / 100.0, corners [4].y () / 100.0, corners [4].z () / 100.0);
00316 crystalHit->back2.setValue (corners [5].x () / 100.0, corners [5].y () / 100.0, corners [5].z () / 100.0);
00317 crystalHit->back3.setValue (corners [6].x () / 100.0, corners [6].y () / 100.0, corners [6].z () / 100.0);
00318 crystalHit->back4.setValue (corners [7].x () / 100.0, corners [7].y () / 100.0, corners [7].z () / 100.0);
00319
00320 sep->addChild (crystalHit);
00321 }
00322 }
00323 }
00324 catch (cms::Exception& e)
00325 {
00326 e.append (" from VisHFRecHitTwig::update(Ig3DRep*) ");
00327 e.append (this->name ());
00328
00329 if (this->m_onCmsException)
00330 this->m_onCmsException (&e);
00331 }
00332 catch (lat::Error &e)
00333 {
00334 if (this->m_onError)
00335 this->m_onError (&e);
00336 }
00337 catch (std::exception &e)
00338 {
00339 if (this->m_onException)
00340 this->m_onException (&e);
00341 }
00342 catch (...)
00343 {
00344 if (this->m_onUnhandledException)
00345 this->m_onUnhandledException ();
00346 }
00347 }
00348
00349 rep->node ()->addChild (sep);
00350 }
00351
00352 void
00353 VisHFRecHitTwig::update (IgLegoRep *rep)
00354 {
00355
00356 VisQueuedTwig::update (rep);
00357
00358 IgQtLock ();
00359 rep->clear ();
00360
00361 SoSeparator *sep = new SoSeparator;
00362
00363 try
00364 {
00365 if (! m_recHits.empty ())
00366 {
00367 for (std::vector<HFRecHit>::const_iterator i = m_recHits.begin (), iEnd = m_recHits.end (); i != iEnd; ++i)
00368 {
00369 float et = (*i).energy ();
00370 if (fabs (et) > m_cut.value ())
00371 {
00372 int iphi = (*i).id ().iphi ();
00373 int ieta = (*i).id ().ieta ();
00374
00375 float phi = (iphi - 1) * 0.087 + 0.087 / 2.0;
00376 float eta = ieta * 0.087 + 0.087 / 2.0;
00377
00378 IgSoTower *tower = new IgSoTower;
00379 tower->position = SbVec2f (phi, eta);
00380 tower->scaleFactor = m_scale.value ();
00381 tower->energy = et;
00382 sep->addChild (tower);
00383 }
00384 }
00385 }
00386 }
00387 catch (cms::Exception& e)
00388 {
00389 e.append (" from VisHFRecHitTwig::update(IgLegoRep *) ");
00390 e.append (this->name ());
00391
00392 if (this->m_onCmsException)
00393 this->m_onCmsException (&e);
00394 }
00395 catch (lat::Error &e)
00396 {
00397 if (this->m_onError)
00398 this->m_onError (&e);
00399 }
00400 catch (std::exception &e)
00401 {
00402 if (this->m_onException)
00403 this->m_onException (&e);
00404 }
00405 catch (...)
00406 {
00407 if (this->m_onUnhandledException)
00408 this->m_onUnhandledException ();
00409 }
00410
00411 rep->node ()->addChild (sep);
00412 }
00413
00414 void
00415 VisHFRecHitTwig::update (IgRPhiRep *rep)
00416 {
00417
00418 VisQueuedTwig::update (rep);
00419 }
00420
00421 void
00422 VisHFRecHitTwig::update (IgRZRep *rep)
00423 {
00424
00425 VisQueuedTwig::update (rep);
00426
00427 IgQtLock ();
00428 rep->clear ();
00429
00430 SoSeparator *sep = new SoSeparator;
00431
00432 SoMaterial *mat = new SoMaterial;
00433 float rgbcomponents [4];
00434 IgSbColorMap::unpack (m_rgba, rgbcomponents);
00435 mat->ambientColor.setValue (SbColor (rgbcomponents));
00436 mat->diffuseColor.setValue (SbColor (rgbcomponents));
00437 mat->specularColor.setValue (SbColor (rgbcomponents));
00438 mat->emissiveColor.setValue (SbColor (rgbcomponents));
00439 sep->addChild (mat);
00440
00441 VisEventSetupService *esService = VisEventSetupService::get (state ());
00442 ASSERT (esService);
00443
00444 unsigned binNumber = 0;
00445 const unsigned nBinsZ = 2;
00446 const unsigned nBinsR = 2*13;
00447 const unsigned nbrOfBins = 2 * (nBinsZ + nBinsR);
00448 const float radiusR = 1.29f;
00449 const float radiusZ = 11.f;
00450
00451
00452
00453 std::vector<float> energies (nbrOfBins * 2);
00454
00455 try
00456 {
00457 if (! m_recHits.empty ())
00458 {
00459 for (std::vector<HFRecHit>::const_iterator i = m_recHits.begin (), iEnd = m_recHits.end (); i != iEnd; ++i)
00460 {
00461 float energy = (*i).energy ();
00462 if (energy > m_cut.value ())
00463 {
00464 binNumber = esService->getBinNumber ((*i).detid (), nBinsR, nBinsZ, radiusR, radiusZ);
00465 if (binNumber < nbrOfBins)
00466 {
00467 if (m_binning.value () == "project")
00468 (energies[binNumber] > energy) ? energies[binNumber] : energies[binNumber] = energy;
00469 else
00470 energies[binNumber] += energy;
00471 }
00472 else
00473 {
00474 std::cerr << "Bin number (" << binNumber << ") exceeds the number of bins (" << nbrOfBins << ")"<< std::endl;
00475 }
00476 }
00477 }
00478
00479 if (*max_element (energies.begin (), energies.end ()) > 0.0)
00480 {
00481 SoMaterial *mat = new SoMaterial;
00482 mat->ambientColor.setValue (0.0, 0.4, 1.0);
00483 mat->diffuseColor.setValue (0.0, 0.1, 1.0);
00484 mat->specularColor.setValue (0.0, 0.1, 1.0);
00485 mat->emissiveColor.setValue (0.0, 0.1, 1.0);
00486
00487 SoDrawStyle *drawStyle = new SoDrawStyle;
00488 drawStyle->lineWidth.setValue (2.0);
00489
00490 IgSoRectColHist* hist = new IgSoRectColHist;
00491 hist->radiusR = radiusR;
00492 hist->radiusZ = radiusZ;
00493 hist->numR = nBinsR;
00494 hist->numZ = nBinsZ;
00495 hist->energies.setValues (0, energies.size(), &energies [0]);
00496 hist->logScale = false;
00497 hist->layer = -5.0;
00498 hist->scaleFactor = m_escale.value ();
00499
00500 std::vector<SbColor> colors (4);
00501 colors[0] = SbColor (0.0, 0.3, 1.0);
00502 colors[1] = SbColor (1.0, 0.0, 1.0);
00503 colors[2] = SbColor (1.0, 0.4, 0.0);
00504 colors[3] = SbColor (1.0, 1.0, 0.0);
00505
00506 hist->faceColors.setValues (0, colors.size (), &colors[0]);
00507 sep->addChild (mat);
00508 sep->addChild (drawStyle);
00509 sep->addChild (hist);
00510 }
00511 }
00512 }
00513 catch (cms::Exception& e)
00514 {
00515 e.append (" from VisHFRecHitTwig::update(IgRZRep*) ");
00516 e.append (this->name ());
00517
00518 if (this->m_onCmsException)
00519 this->m_onCmsException (&e);
00520 }
00521 catch (lat::Error &e)
00522 {
00523 if (this->m_onError)
00524 this->m_onError (&e);
00525 }
00526 catch (std::exception &e)
00527 {
00528 if (this->m_onException)
00529 this->m_onException (&e);
00530 }
00531 catch (...)
00532 {
00533 if (this->m_onUnhandledException)
00534 this->m_onUnhandledException ();
00535 }
00536
00537 rep->node ()->addChild (sep);
00538 }