00001
00002
00003 #include "VisReco/VisEcal/interface/VisBasicClusterTwig.h"
00004 #include "VisFramework/VisEventSetup/interface/VisEventSetupService.h"
00005 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00006 #include "FWCore/Framework/interface/Event.h"
00007 #include "Iguana/Models/interface/IgTextRep.h"
00008 #include "Iguana/GLModels/interface/Ig3DRep.h"
00009 #include "Iguana/GLModels/interface/IgLegoRep.h"
00010 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00011 #include "Iguana/GLModels/interface/IgRZRep.h"
00012 #include "Iguana/Framework/interface/IgRepSet.h"
00013 #include "Iguana/Inventor/interface/IgSbColorMap.h"
00014 #include "Iguana/Inventor/interface/IgSoCrystalHit.h"
00015 #include "Iguana/Inventor/interface/IgSoCircularHist.h"
00016 #include "Iguana/Inventor/interface/IgSoRectColHist.h"
00017 #include "Iguana/Inventor/interface/IgSoTower.h"
00018 #include "Iguana/Studio/interface/IgQtLock.h"
00019 #include <Inventor/nodes/SoSeparator.h>
00020 #include <Inventor/nodes/SoMaterial.h>
00021 #include <qstring.h>
00022 #include <classlib/utils/DebugAids.h>
00023 #include <sstream>
00024 #include <iomanip>
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 VisBasicClusterTwig::VisBasicClusterTwig (IgState *state, IgTwig *parent,
00037 const std::string &name,
00038 std::vector <EcalRecHit> &recHits)
00039 : VisQueuedTwig (state, parent, name),
00040 m_name (name),
00041 m_binning (state, lat::CreateCallback (this, &VisBasicClusterTwig::twigChanged)),
00042 m_scale (state, lat::CreateCallback (this, &VisBasicClusterTwig::twigChanged)),
00043 m_cut (state, lat::CreateCallback (this, &VisBasicClusterTwig::twigChanged)),
00044 m_escale (state, lat::CreateCallback (this, &VisBasicClusterTwig::twigChanged)),
00045 m_annotation (state, lat::CreateCallback (this, &VisBasicClusterTwig::twigChanged)),
00046 m_recHits (recHits)
00047 {}
00048
00049 void
00050 VisBasicClusterTwig::twigChanged (void)
00051 { IgRepSet::invalidate (this, SELF_MASK); }
00052
00053 void
00054 VisBasicClusterTwig::onNewEvent (const edm::Event &event,
00055 const edm::EventSetup &eventSetup)
00056 {
00057
00058 VisQueuedTwig::onNewEvent (event, eventSetup);
00059 VisQueuedTwig::onBaseInvalidate ();
00060 }
00061
00062 void
00063 VisBasicClusterTwig::update (IgTextRep *rep)
00064 {
00065
00066 VisQueuedTwig::update (rep);
00067
00068
00069 std::ostringstream text;
00070 text << this->name () << " from ";
00071 text << "Displayed only above " << m_cut.value () << " GeV:<br>";
00072
00073 text << "<table width='100%' border=1>"
00074 << "<TR align = center>"
00075 << "<TH>Number</TH>"
00076 << "<TH>Energy</TH>"
00077 << "<TH>Time</TH>"
00078 << "<TH>Eta</TH>"
00079 << "<TH>Phi</TH>"
00080 << "</TR>";
00081 text << setiosflags (std::ios::showpoint | std::ios::fixed);
00082 text.setf (std::ios::right, std::ios::adjustfield);
00083
00084 int n = 0;
00085 try
00086 {
00087 VisEventSetupService *esService = VisEventSetupService::get (state ());
00088 ASSERT (esService);
00089
00090 for (std::vector<EcalRecHit>::const_iterator it = m_recHits.begin (), itEnd = m_recHits.end (); it != itEnd; ++it)
00091 {
00092 const GlobalPoint& pos = esService->getCellPosition ((*it).detid ());
00093 float eta = pos.eta ();
00094 float phi = pos.phi ();
00095
00096 text << "<TR align = right>"
00097 << "<TD>" << std::setw (3) << n++ << "</TD>"
00098 << "<TD>" << std::setw (5) << std::setprecision (3) << (*it).energy () << "</TD>"
00099 << "<TD>" << std::setw (5) << std::setprecision (3) << (*it).time () << "</TD>"
00100 << "<TD>" << std::setw (5) << std::setprecision (3) << eta << "</TD>"
00101 << "<TD>" << std::setw (5) << std::setprecision (3) << phi << "</TD>"
00102 << "</TR>";
00103 }
00104 }
00105 catch (cms::Exception& e)
00106 {
00107 e.append (" from VisBasicClusterTwig::update(IgTextRep*) ");
00108 e.append (this->name ());
00109
00110 if (this->m_onCmsException)
00111 this->m_onCmsException (&e);
00112 }
00113 catch (lat::Error &e)
00114 {
00115 if (this->m_onError)
00116 this->m_onError (&e);
00117 }
00118 catch (std::exception &e)
00119 {
00120 if (this->m_onException)
00121 this->m_onException (&e);
00122 }
00123 catch (...)
00124 {
00125 if (this->m_onUnhandledException)
00126 this->m_onUnhandledException ();
00127 }
00128
00129 text << "</table>";
00130
00131
00132 IgQtLock ();
00133
00134 rep->setText (text.str ());
00135 }
00136
00137 void
00138 VisBasicClusterTwig::update (Ig3DRep *rep)
00139 {
00140
00141 VisQueuedTwig::update (rep);
00142
00143 IgQtLock ();
00144
00145 rep->clear ();
00146
00147 SoSeparator *sep = new SoSeparator;
00148
00149 SoMaterial *mat = new SoMaterial;
00150 float rgbcomponents [4];
00151 IgSbColorMap::unpack (0xff009c00, rgbcomponents);
00152 mat->diffuseColor.setValue (rgbcomponents);
00153 sep->addChild (mat);
00154
00155 if (! m_recHits.empty ())
00156 {
00157 VisEventSetupService *esService = VisEventSetupService::get (state ());
00158 ASSERT (esService);
00159
00160 try
00161 {
00162 for (std::vector<EcalRecHit>::const_iterator it = m_recHits.begin (), itEnd = m_recHits.end (); it != itEnd; ++it)
00163 {
00164 const CaloCellGeometry::CornersVec& corners = esService->getCorners ((*it).detid ());
00165 ASSERT (corners.size () == 8);
00166
00167 IgSoCrystalHit *crystalHit = new IgSoCrystalHit;
00168 crystalHit->energy.setValue ((*it).energy ());
00169 crystalHit->scale.setValue (m_escale.value ());
00170 crystalHit->relativeWidth.setValue (1.0);
00171 crystalHit->drawCrystal.setValue (true);
00172 crystalHit->drawHit.setValue (true);
00173
00174 crystalHit->front1.setValue (corners [3].x () / 100.0, corners [3].y () / 100.0, corners [3].z () / 100.0);
00175 crystalHit->front2.setValue (corners [2].x () / 100.0, corners [2].y () / 100.0, corners [2].z () / 100.0);
00176 crystalHit->front3.setValue (corners [1].x () / 100.0, corners [1].y () / 100.0, corners [1].z () / 100.0);
00177 crystalHit->front4.setValue (corners [0].x () / 100.0, corners [0].y () / 100.0, corners [0].z () / 100.0);
00178
00179 crystalHit->back1.setValue (corners [7].x () / 100.0, corners [7].y () / 100.0, corners [7].z () / 100.0);
00180 crystalHit->back2.setValue (corners [6].x () / 100.0, corners [6].y () / 100.0, corners [6].z () / 100.0);
00181 crystalHit->back3.setValue (corners [5].x () / 100.0, corners [5].y () / 100.0, corners [5].z () / 100.0);
00182 crystalHit->back4.setValue (corners [4].x () / 100.0, corners [4].y () / 100.0, corners [4].z () / 100.0);
00183
00184 sep->addChild (crystalHit);
00185 }
00186 }
00187 catch (cms::Exception& e)
00188 {
00189 e.append (" from VisBasicClusterTwig::update(Ig3DRep*) ");
00190 e.append (this->name ());
00191
00192 if (this->m_onCmsException)
00193 this->m_onCmsException (&e);
00194 }
00195 catch (lat::Error &e)
00196 {
00197 if (this->m_onError)
00198 this->m_onError (&e);
00199 }
00200 catch (std::exception &e)
00201 {
00202 if (this->m_onException)
00203 this->m_onException (&e);
00204 }
00205 catch (...)
00206 {
00207 if (this->m_onUnhandledException)
00208 this->m_onUnhandledException ();
00209 }
00210 }
00211
00212 rep->node ()->addChild (sep);
00213 }
00214
00215 void
00216 VisBasicClusterTwig::update (IgLegoRep *rep)
00217 {
00218
00219 VisQueuedTwig::update (rep);
00220
00221 IgQtLock ();
00222
00223 rep->clear ();
00224
00225 SoSeparator *sep = new SoSeparator;
00226
00227 if (! m_recHits.empty ())
00228 {
00229 VisEventSetupService *esService = VisEventSetupService::get (state ());
00230 ASSERT (esService);
00231
00232 try
00233 {
00234 std::vector<EcalRecHit>::iterator posCurrent;
00235 std::vector<EcalRecHit>::iterator posEnd;
00236
00237 for (posCurrent = m_recHits.begin (), posEnd = m_recHits.end (); posCurrent != posEnd; ++posCurrent)
00238 {
00239 const GlobalPoint& pos = esService->getCellPosition ((*posCurrent).detid ());
00240 float eta = pos.eta ();
00241 float phi = pos.phi ();
00242 (phi < 0.0) ? phi = 2 * M_PI + phi : phi;
00243
00244 IgSoTower *tower = new IgSoTower;
00245 tower->position = SbVec2f (phi, eta);
00246 tower->scaleFactor = m_scale.value ();
00247 tower->etaWidth = 0.0174;
00248 tower->phiWidth = 0.0174;
00249 tower->energy = (*posCurrent).energy ();
00250 tower->emFraction = 1;
00251 sep->addChild (tower);
00252 }
00253 }
00254 catch (cms::Exception& e)
00255 {
00256 e.append (" from VisBasicClusterTwig::update(IgLegoRep *) ");
00257 e.append (this->name ());
00258
00259 if (this->m_onCmsException)
00260 this->m_onCmsException (&e);
00261 }
00262 catch (lat::Error &e)
00263 {
00264 if (this->m_onError)
00265 this->m_onError (&e);
00266 }
00267 catch (std::exception &e)
00268 {
00269 if (this->m_onException)
00270 this->m_onException (&e);
00271 }
00272 catch (...)
00273 {
00274 if (this->m_onUnhandledException)
00275 this->m_onUnhandledException ();
00276 }
00277 }
00278
00279 rep->node ()->addChild (sep);
00280 }
00281
00282 void
00283 VisBasicClusterTwig::update (IgRPhiRep *rep)
00284 {
00285
00286 VisQueuedTwig::update (rep);
00287
00288 IgQtLock ();
00289
00290 rep->clear ();
00291
00292 SoSeparator *sep = new SoSeparator;
00293 SoSeparator *posSep = new SoSeparator;
00294 SoSeparator *negSep = new SoSeparator;
00295 sep->addChild (posSep);
00296 sep->addChild (negSep);
00297
00298 SoMaterial *mat = new SoMaterial;
00299 mat->ambientColor.setValue (1.0, 0.0, 153.0 / 255.0);
00300 mat->diffuseColor.setValue (1.0, 0.0, 153.0 / 255.0);
00301 mat->specularColor.setValue (1.0, 0.0, 153.0 / 255.0);
00302 mat->emissiveColor.setValue (1.0, 0.0, 153.0 / 255.0);
00303 posSep->addChild (mat);
00304
00305 SoMaterial *negMat = new SoMaterial;
00306 negMat->ambientColor.setValue (51.0 / 255.0, 1.0, 102.0 / 255.0);
00307 negMat->diffuseColor.setValue (51.0 / 255.0, 1.0, 102.0 / 255.0);
00308 negMat->specularColor.setValue (51.0 / 255.0, 1.0, 102.0 / 255.0);
00309 negMat->emissiveColor.setValue (51.0 / 255.0, 1.0, 102.0 / 255.0);
00310 negSep->addChild (negMat);
00311
00312 int nbrOfBins = 360;
00313 int binNumber;
00314
00315 std::vector<float> bufferPositive (nbrOfBins);
00316 std::vector<float> bufferNegative (nbrOfBins);
00317 try
00318 {
00319 if (! m_recHits.empty ())
00320 {
00321 VisEventSetupService *esService = VisEventSetupService::get (state ());
00322 ASSERT (esService);
00323
00324 float radius = 1.29;
00325
00326 std::vector<EcalRecHit>::iterator posCurrent;
00327 std::vector<EcalRecHit>::iterator posEnd;
00328
00329 for (posCurrent = m_recHits.begin (), posEnd = m_recHits.end (); posCurrent != posEnd; ++posCurrent)
00330 {
00331 float energy = (*posCurrent).energy ();
00332 if (energy > m_cut.value ())
00333 {
00334 const GlobalPoint& pos = esService->getCellPosition ((*posCurrent).detid ());
00335
00336 float phi = pos.phi ();
00337 (phi < 0) ? phi = 2 * M_PI + phi : phi;
00338
00339 binNumber = (int) floor (phi / (2 * M_PI / nbrOfBins));
00340 if (binNumber >= 0 && binNumber < nbrOfBins)
00341 if (m_binning.value () == "project")
00342 {
00343 if ((energy > 0.0) && (energy > bufferPositive [binNumber]))
00344 bufferPositive [binNumber] = energy;
00345 else if ((energy < 0.0) && (energy < bufferNegative [binNumber]))
00346 bufferNegative [binNumber] = energy;
00347 }
00348 else
00349 (energy > 0.0) ? bufferPositive [binNumber] += energy : bufferNegative [binNumber] += energy;
00350 }
00351 }
00352
00353 std::vector<float>::const_iterator first = bufferPositive.begin ();
00354 std::vector<float>::const_iterator last = bufferPositive.end ();
00355
00356 if (*max_element (first, last) > 0.0)
00357 {
00358 IgSoCircularHist *recHits = new IgSoCircularHist;
00359 recHits->minRadius = radius;
00360 recHits->maxRadius = -1;
00361 recHits->scaleFactor = m_escale.value ();
00362 recHits->numberOfBins = nbrOfBins;
00363 recHits->energies.setValues (0, nbrOfBins, &bufferPositive [0]);
00364 recHits->logScale = false;
00365 recHits->showAnnotations = m_annotation.value ();
00366 recHits->layer = 5.5;
00367 posSep->addChild (recHits);
00368 }
00369
00370 std::vector<float>::const_iterator nfirst = bufferNegative.begin ();
00371 std::vector<float>::const_iterator nlast = bufferNegative.end ();
00372
00373 if (fabs(*max_element (nfirst, nlast)) > 0.0)
00374 {
00375 IgSoCircularHist *negRecHits = new IgSoCircularHist;
00376 negRecHits->minRadius = radius;
00377 negRecHits->maxRadius = -1;
00378 negRecHits->scaleFactor = m_escale.value ();
00379 negRecHits->numberOfBins = nbrOfBins;
00380 negRecHits->energies.setValues (0, nbrOfBins, &bufferNegative [0]);
00381 negRecHits->logScale = false;
00382 negRecHits->showAnnotations = m_annotation.value ();
00383 negRecHits->layer = 5.0;
00384
00385 negSep->addChild (negRecHits);
00386 }
00387 }
00388 }
00389 catch (cms::Exception& e)
00390 {
00391 e.append (" from VisBasicClusterTwig::update (IgRPhiRep*) ");
00392 e.append (this->name ());
00393
00394 if (this->m_onCmsException)
00395 this->m_onCmsException (&e);
00396 }
00397 catch (lat::Error &e)
00398 {
00399 if (this->m_onError)
00400 this->m_onError (&e);
00401 }
00402 catch (std::exception &e)
00403 {
00404 if (this->m_onException)
00405 this->m_onException (&e);
00406 }
00407 catch (...)
00408 {
00409 if (this->m_onUnhandledException)
00410 this->m_onUnhandledException ();
00411 }
00412
00413 rep->node ()->addChild (sep);
00414 }
00415
00416 void
00417 VisBasicClusterTwig::update (IgRZRep *rep)
00418 {
00419
00420 VisQueuedTwig::update (rep);
00421
00422 IgQtLock ();
00423
00424 rep->clear ();
00425
00426 SoSeparator *sep = new SoSeparator;
00427 SoMaterial *mat = new SoMaterial;
00428 mat->ambientColor.setValue (1.0, 0.0, 153.0 / 255.0);
00429 mat->diffuseColor.setValue (1.0, 0.0, 153.0 / 255.0);
00430 mat->specularColor.setValue (1.0, 0.0, 153.0 / 255.0);
00431 mat->emissiveColor.setValue (1.0, 0.0, 153.0 / 255.0);
00432 sep->addChild (mat);
00433
00434 VisEventSetupService *esService = VisEventSetupService::get (state ());
00435 ASSERT (esService);
00436
00437 unsigned binNumber = 0;
00438 const unsigned nBinsZ = 85*2;
00439 const unsigned nBinsR = 39*2;
00440 const unsigned nbrOfBins = 2 * (nBinsZ + nBinsR);
00441 const float radiusR = 1.29f;
00442 const float radiusZ = 3.17f;
00443 const float barrelMaxEta = 1.479f;
00444 const float beamPipeTheta = 5.7f * M_PI / 180.f;
00445 const float endcapMaxTheta = 25.464f * M_PI / 180.f;
00446
00447 std::vector<float> energies (nbrOfBins * 2);
00448
00449 try
00450 {
00451 if (! m_recHits.empty ())
00452 {
00453 std::vector<EcalRecHit>::iterator posCurrent;
00454 std::vector<EcalRecHit>::iterator posEnd;
00455
00456 for (posCurrent = m_recHits.begin (), posEnd = m_recHits.end (); posCurrent != posEnd; ++posCurrent)
00457 {
00458 float energy = (*posCurrent).energy ();
00459 if (energy > m_cut.value ())
00460 {
00461 binNumber = esService->getBinNumber ((*posCurrent).detid (), nBinsR, nBinsZ, radiusR, radiusZ, barrelMaxEta, beamPipeTheta, endcapMaxTheta);
00462
00463 if (binNumber < nbrOfBins)
00464 {
00465 if (m_binning.value () == "project")
00466 (energies[binNumber] > energy) ? energies[binNumber] : energies[binNumber] = energy;
00467 else
00468 energies[binNumber] += energy;
00469 }
00470 else
00471 {
00472 std::cerr << "Bin number (" << binNumber << ") exceeds the number of bins (" << nbrOfBins << ")"<< std::endl;
00473 }
00474 }
00475 }
00476
00477 if (*max_element (energies.begin (), energies.end ()) > 0.0)
00478 {
00479 IgSoRectColHist* hist = new IgSoRectColHist;
00480 hist->radiusR = radiusR;
00481 hist->radiusZ = radiusZ;
00482 hist->numR = nBinsR;
00483 hist->numZ = nBinsZ;
00484 hist->energies.setValues (0, energies.size(), &energies [0]);
00485 hist->logScale = false;
00486 hist->layer = -5.0;
00487 hist->scaleFactor = m_escale.value ();
00488 hist->barrelMaxEta = barrelMaxEta;
00489 hist->beamPipeTheta = beamPipeTheta;
00490 hist->endcapMaxTheta = endcapMaxTheta;
00491
00492 std::vector<SbColor> colors (4);
00493 colors[0] = SbColor (1.0, 0.0, 153.0 / 255.0);
00494 colors[1] = SbColor (1.0, 1.0, 153.0 / 255.0);
00495 colors[2] = SbColor (51.0 / 255.0, 1.0, 102.0 / 255.0);
00496 colors[3] = SbColor (51.0 / 255.0, 0.0, 102.0 / 255.0);
00497
00498 hist->faceColors.setValues (0, colors.size (), &colors[0]);
00499 sep->addChild (hist);
00500 }
00501 }
00502 }
00503 catch (cms::Exception& e)
00504 {
00505 e.append (" from VisEcalRecHitTwig::update(IgRZRep*) ");
00506 e.append (this->name ());
00507
00508 if (this->m_onCmsException)
00509 this->m_onCmsException (&e);
00510 }
00511 catch (lat::Error &e)
00512 {
00513 if (this->m_onError)
00514 this->m_onError (&e);
00515 }
00516 catch (std::exception &e)
00517 {
00518 if (this->m_onException)
00519 this->m_onException (&e);
00520 }
00521 catch (...)
00522 {
00523 if (this->m_onUnhandledException)
00524 this->m_onUnhandledException ();
00525 }
00526
00527 rep->node ()->addChild (sep);
00528 }