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