00001
00002
00003 #include "VisReco/VisMuonCSC/interface/VisCSCCLCTDigiTwig.h"
00004 #include "VisFramework/VisFrameworkBase/interface/VisTwigFactroyService.h"
00005 #include "VisFramework/VisFrameworkBase/interface/VisEventSelector.h"
00006 #include "VisFramework/VisFrameworkBase/interface/debug.h"
00007 #include "DataFormats/CSCDigi/interface/CSCCLCTDigi.h"
00008 #include "DataFormats/CSCDigi/interface/CSCCLCTDigiCollection.h"
00009 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00010 #include "FWCore/Framework/interface/Event.h"
00011 #include "FWCore/Framework/interface/EventSetup.h"
00012 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00013 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00014 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00015
00016 #include "Geometry/CSCGeometry/interface/CSCLayer.h"
00017 #include "Geometry/CSCGeometry/interface/CSCLayerGeometry.h"
00018 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00019
00020 #include "Iguana/Models/interface/IgTextRep.h"
00021 #include "Iguana/GLModels/interface/Ig3DRep.h"
00022 #include "Iguana/GLModels/interface/IgLegoRep.h"
00023 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00024 #include "Iguana/GLModels/interface/IgRZRep.h"
00025 #include "Iguana/Inventor/interface/IgSoCircularHist.h"
00026 #include "Iguana/Inventor/interface/IgSoTower.h"
00027
00028 #include "Iguana/Studio/interface/IgQtLock.h"
00029 #include <Inventor/nodes/SoDrawStyle.h>
00030 #include <Inventor/nodes/SoMaterial.h>
00031 #include <Inventor/nodes/SoSeparator.h>
00032 #include <Inventor/nodes/SoCube.h>
00033 #include <Inventor/nodes/SoLineSet.h>
00034 #include <Inventor/nodes/SoTranslation.h>
00035 #include <Inventor/nodes/SoPointSet.h>
00036 #include <Inventor/nodes/SoTransform.h>
00037 #include <Inventor/nodes/SoRotation.h>
00038 #include <classlib/utils/DebugAids.h>
00039 #include <qstring.h>
00040 #include <iostream>
00041 #include <iomanip>
00042 #include <cmath>
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 namespace
00053 {
00054 VisQueuedTwig *
00055 createThisTwig (IgState *state, IgTwig *parent,
00056 const std::string &name,
00057 const std::string &friendlyName,
00058 const std::string &modLabel,
00059 const std::string &instanceName,
00060 const std::string &processName)
00061 {
00062 return new VisCSCCLCTDigiTwig (state, parent, "CLCT digis (" + name + ")",
00063 friendlyName, modLabel, instanceName, processName);
00064 }
00065 }
00066
00067
00068
00069
00070 VisCSCCLCTDigiTwig::VisCSCCLCTDigiTwig (IgState *state, IgTwig *parent,
00071 const std::string &name ,
00072 const std::string &friendlyName ,
00073 const std::string &moduleLabel ,
00074 const std::string &instanceName ,
00075 const std::string &processName )
00076 : VisQueuedTwig (state, parent, name),
00077 m_text (name),
00078 m_friendlyName (friendlyName),
00079 m_moduleLabel (moduleLabel),
00080 m_instanceName (instanceName),
00081 m_processName (processName)
00082 {
00083 VisTwigFactroyService *tfService = VisTwigFactroyService::get (state);
00084 if (! tfService)
00085 {
00086 tfService = new VisTwigFactroyService (state);
00087 }
00088 edm::TypeID caloJetsID (typeid (CSCCLCTDigiCollection));
00089 tfService->registerTwig (caloJetsID.friendlyClassName (), &createThisTwig);
00090 }
00091
00092 void
00093 VisCSCCLCTDigiTwig::onNewEvent (const edm::Event &event,
00094 const edm::EventSetup &eventSetup)
00095 {
00096
00097 VisQueuedTwig::onNewEvent (event, eventSetup);
00098
00099 m_digis.clear ();
00100 m_text = (QString ("Run # %1, event # %2")
00101 .arg (event.id ().run ())
00102 .arg (event.id ().event ()).latin1 ());
00103
00104 std::vector<edm::Handle<CSCCLCTDigiCollection> > digiCollections;
00105
00106 try
00107 {
00108 if ((! m_friendlyName.empty ()) || (! m_moduleLabel.empty ()) || (! m_instanceName.empty ()) || (! m_processName.empty ()))
00109 {
00110 VisEventSelector visSel (m_friendlyName, m_moduleLabel, m_instanceName, m_processName);
00111 event.getMany (visSel, digiCollections);
00112 }
00113 else
00114 {
00115 event.getManyByType (digiCollections);
00116 }
00117
00118 eventSetup.get<MuonGeometryRecord> ().get (m_pDD);
00119 }
00120 catch (cms::Exception& e)
00121 {
00122 if (this->m_onCmsException)
00123 this->m_onCmsException (&e);
00124 }
00125 catch (lat::Error &e)
00126 {
00127 if (this->m_onError)
00128 this->m_onError (&e);
00129 }
00130 catch (std::exception &e)
00131 {
00132 if (this->m_onException)
00133 this->m_onException (&e);
00134 }
00135 catch (...)
00136 {
00137 if (this->m_onUnhandledException)
00138 this->m_onUnhandledException ();
00139 }
00140
00141 if (! digiCollections.empty ())
00142 {
00143 std::vector<edm::Handle<CSCCLCTDigiCollection> >::iterator i;
00144 std::vector<edm::Handle<CSCCLCTDigiCollection> >::iterator iEnd;
00145 for (i = digiCollections.begin (), iEnd = digiCollections.end (); i != iEnd; ++i)
00146 {
00147 const CSCCLCTDigiCollection& c = *(*i);
00148
00149
00150 CSCCLCTDigiCollection::DigiRangeIterator detUnitIt;
00151 CSCCLCTDigiCollection::DigiRangeIterator detUnitItEnd;
00152 for (detUnitIt = c.begin (), detUnitItEnd = c.end (); detUnitIt != detUnitItEnd; ++detUnitIt)
00153 {
00154 const CSCDetId &id = (*detUnitIt).first;
00155 const CSCCLCTDigiCollection::Range &range = (*detUnitIt).second;
00156
00157
00158 for (CSCCLCTDigiCollection::const_iterator digiIt = range.first;
00159 digiIt != range.second;
00160 ++digiIt)
00161 {
00162 std::pair< CSCDetId, CSCCLCTDigi > p;
00163 p.first = id;
00164 p.second = (*digiIt);
00165
00166 m_digis.push_back (p);
00167 }
00168 }
00169 }
00170 }
00171
00172 VisQueuedTwig::onBaseInvalidate ();
00173 }
00174
00175 void
00176 VisCSCCLCTDigiTwig::update (IgTextRep *rep)
00177 {
00178
00179 VisQueuedTwig::update (rep);
00180
00181
00182 std::ostringstream text;
00183 text << "Total " << m_digis.size () << " CSC CLCT digis: " << m_text << "<br>";
00184
00185 text << "<table width='100%' border=1>"
00186 << "<TR align = center>"
00187 << "<TH>Number</TH>"
00188 << "<TH>Position</TH>"
00189 << "<TH>Validity</TH>"
00190 << "<TH>Quality</TH>"
00191 << "<TH>Pattern</TH>"
00192 << "<TH>Strip</TH>"
00193 << "<TH>Strip type</TH>"
00194 << "<TH>Key strip</TH>"
00195 << "<TH>Track number</TH>"
00196 << "<TH>CFEB</TH>"
00197 << "<TH>Bend</TH>"
00198 << "<TH>BX</TH>"
00199 << "</TR>";
00200 text << setiosflags (std::ios::showpoint | std::ios::fixed);
00201 text.setf (std::ios::right, std::ios::adjustfield);
00202
00203 if ((! m_digis.empty ()) && m_pDD.isValid ())
00204 {
00205 int nDigis = 0;
00206 try
00207 {
00208 for (std::vector<std::pair<CSCDetId, CSCCLCTDigi> >::const_iterator i = m_digis.begin (), iEnd = m_digis.end ();
00209 i != iEnd; ++i)
00210 {
00211 Surface::GlobalPoint pos = (m_pDD->idToDet ((*i).first))->surface ().position ();
00212 text << "<TR align = right>"
00213 << "<TD>" << std::setw (3) << ++nDigis << "</TD>"
00214 << "<TD>" << pos.x () << ", " << pos.y () << ", " << pos.z () << "</TD>"
00215 << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.isValid () << "</TD>"
00216 << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.getQuality () << "</TD>"
00217 << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.getPattern () << "</TD>"
00218 << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.getStrip () << "</TD>"
00219 << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.getStripType () << "</TD>"
00220 << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.getKeyStrip () << "</TD>"
00221 << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.getTrknmb () << "</TD>"
00222 << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.getBend () << "</TD>"
00223 << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.getBX () << "</TD></TR>";
00224
00225 std::cout << "CSCDetId " << (*i).first << std::endl;
00226 }
00227 }
00228 catch (cms::Exception& e)
00229 {
00230 if (this->m_onCmsException)
00231 this->m_onCmsException (&e);
00232 }
00233 catch (lat::Error &e)
00234 {
00235 if (this->m_onError)
00236 this->m_onError (&e);
00237 }
00238 catch (std::exception &e)
00239 {
00240 if (this->m_onException)
00241 this->m_onException (&e);
00242 }
00243 catch (...)
00244 {
00245 if (this->m_onUnhandledException)
00246 this->m_onUnhandledException ();
00247 }
00248 }
00249 text << "</table>";
00250
00251
00252 IgQtLock ();
00253 rep->setText (text.str ());
00254 }
00255
00256 void
00257 VisCSCCLCTDigiTwig::update (Ig3DRep *rep)
00258 {
00259
00260 VisQueuedTwig::update (rep);
00261
00262 IgQtLock ();
00263 rep->clear ();
00264 m_dets.clear ();
00265
00266 if ((! m_digis.empty ()) && m_pDD.isValid ())
00267 {
00268 VisCSCChamberDrawer d;
00269 const float width = 0.01;
00270 const float depth = 0.01;
00271
00272 SbColor grey35;
00273 float transparency = 0.0f;
00274 grey35.setPackedValue(static_cast<uint32_t>(0x00595959), transparency);
00275 SoMaterial *mat = new SoMaterial;
00276 mat->diffuseColor.setValue (grey35);
00277 mat->emissiveColor.setValue(grey35);
00278
00279 SoDrawStyle *drawStyle = new SoDrawStyle;
00280 drawStyle->pointSize = 5.0;
00281
00282 SoSeparator *sep = new SoSeparator;
00283 sep->addChild (mat);
00284 sep->addChild (drawStyle);
00285
00286 try
00287 {
00288 SoMaterial *matl = new SoMaterial;
00289 matl->diffuseColor.setValue (0.0, 1.0, 0.0);
00290 matl->emissiveColor.setValue(0.0, 1.0, 0.0);
00291 matl->shininess = 1.;
00292
00293 SoDrawStyle *drawStylel = new SoDrawStyle;
00294 drawStylel->pointSize = 1.;
00295
00296 SoSeparator *pulses = new SoSeparator;
00297 pulses->addChild (matl);
00298 pulses->addChild (drawStylel);
00299
00300 SoVertexProperty *vertices = new SoVertexProperty;
00301 for (std::vector<std::pair<CSCDetId, CSCCLCTDigi> >::const_iterator
00302 i = m_digis.begin (), iEnd = m_digis.end (); i != iEnd; ++i)
00303 {
00304 const CSCDetId &id = (*i).first;
00305 const CSCLayer *layer = m_pDD->chamber (id)->layer (4);
00306 const CSCLayerGeometry *layerGeom = layer->geometry ();
00307
00308 if (m_dets.find(id) == m_dets.end() )
00309 {
00310 m_dets.insert(id);
00311
00312 d.getOutline(sep, m_pDD, id);
00313
00314 }
00315
00316 int strip_id = ((*i).second).getKeyStrip () / 2;
00317 float xstrip = layerGeom->xOfStrip (strip_id);
00318 Surface::GlobalPoint pos = layer->toGlobal (LocalPoint (xstrip, 0.0, 1.0));
00319
00320 float x = pos.x () / 100.0;
00321 float y = pos.y () / 100.0;
00322 float z = pos.z () / 100.0;
00323
00324 SoTranslation *inc = new SoTranslation;
00325 inc->translation = SbVec3f (x, y, z);
00326
00327 SbVec3f axis (0.0, 0.0, 1.0);
00328 float angle = -atan (x / y);
00329 SbRotation r (axis, angle);
00330
00331 SoTransform *xform = new SoTransform;
00332 xform->rotation = r;
00333
00334 SoCube *hit = new SoCube;
00335 hit->width = width;
00336 hit->height = layerGeom->length () / 100.0;
00337 hit->depth = depth;
00338
00339 SoSeparator *pulse = new SoSeparator;
00340 pulse->addChild (inc);
00341 pulse->addChild (xform);
00342 pulse->addChild (hit);
00343 pulses->addChild (pulse);
00344
00345 sep->addChild (pulses);
00346 }
00347
00348 vertices->vertex.setNum (m_digis.size ());
00349 SoPointSet *points = new SoPointSet;
00350 points->vertexProperty.setValue (vertices);
00351 points->numPoints.setValue (m_digis.size ());
00352
00353
00354 }
00355 catch (cms::Exception& e)
00356 {
00357 if (this->m_onCmsException)
00358 this->m_onCmsException (&e);
00359 }
00360 catch (lat::Error &e)
00361 {
00362 if (this->m_onError)
00363 this->m_onError (&e);
00364 }
00365 catch (std::exception &e)
00366 {
00367 if (this->m_onException)
00368 this->m_onException (&e);
00369 }
00370 catch (...)
00371 {
00372 if (this->m_onUnhandledException)
00373 this->m_onUnhandledException ();
00374 }
00375 rep->node ()->addChild (sep);
00376 }
00377 }
00378
00379 void
00380 VisCSCCLCTDigiTwig::update (IgLegoRep *rep)
00381 {
00382
00383 VisQueuedTwig::update (rep);
00384
00385 IgQtLock ();
00386 rep->clear ();
00387
00388 SoSeparator *sep = new SoSeparator;
00389 SoSeparator *posSep = new SoSeparator;
00390 SoSeparator *negSep = new SoSeparator;
00391
00392 SoMaterial *mat = new SoMaterial;
00393 mat->diffuseColor.setValue (0.3, 0.8, 0.0);
00394 posSep->addChild (mat);
00395
00396 SoMaterial *negMat = new SoMaterial;
00397 negMat->diffuseColor.setValue (1.0, 0.0, 0.0);
00398 negSep->addChild (negMat);
00399
00400 sep->addChild (posSep);
00401 sep->addChild (negSep);
00402
00403 try
00404 {
00405 int n = 0;
00406
00407 for (std::vector<std::pair<CSCDetId, CSCCLCTDigi> >::const_iterator i = m_digis.begin (), iEnd = m_digis.end (); i != iEnd; ++i)
00408 {
00409 Surface::GlobalPoint pos = (m_pDD->idToDet ((*i).first))->surface ().position ();
00410
00411 double phi = pos.phi ();
00412 if (phi < 0.0) phi = 2 * M_PI + phi;
00413 ++n;
00414 }
00415 }
00416 catch (cms::Exception& e)
00417 {
00418 if (this->m_onCmsException)
00419 this->m_onCmsException (&e);
00420 }
00421 catch (lat::Error &e)
00422 {
00423 if (this->m_onError)
00424 this->m_onError (&e);
00425 }
00426 catch (std::exception &e)
00427 {
00428 if (this->m_onException)
00429 this->m_onException (&e);
00430 }
00431 catch (...)
00432 {
00433 if (this->m_onUnhandledException)
00434 this->m_onUnhandledException ();
00435 }
00436
00437 rep->node ()->addChild (sep);
00438 }
00439
00440 void
00441 VisCSCCLCTDigiTwig::update (IgRPhiRep *rep)
00442 {
00443
00444 VisQueuedTwig::update (rep);
00445
00446 IgQtLock ();
00447 rep->clear ();
00448
00449 if (! m_digis.empty ())
00450 {
00451 SoSeparator *sep = new SoSeparator;
00452
00453 SoMaterial *mat = new SoMaterial;
00454 mat->diffuseColor.setValue (0.3, 0.8, 0.0);
00455 sep->addChild (mat);
00456
00457 try
00458 {
00459 for (std::vector<std::pair<CSCDetId, CSCCLCTDigi> >::const_iterator i = m_digis.begin (), iEnd = m_digis.end (); i != iEnd; ++i)
00460 {
00461
00462 }
00463 }
00464 catch (cms::Exception& e)
00465 {
00466 if (this->m_onCmsException)
00467 this->m_onCmsException (&e);
00468 }
00469 catch (lat::Error &e)
00470 {
00471 if (this->m_onError)
00472 this->m_onError (&e);
00473 }
00474 catch (std::exception &e)
00475 {
00476 if (this->m_onException)
00477 this->m_onException (&e);
00478 }
00479 catch (...)
00480 {
00481 if (this->m_onUnhandledException)
00482 this->m_onUnhandledException ();
00483 }
00484
00485 rep->node ()->addChild (sep);
00486 }
00487 }
00488
00489 void
00490 VisCSCCLCTDigiTwig::update (IgRZRep *rep)
00491 {
00492
00493 VisQueuedTwig::update (rep);
00494
00495 IgQtLock ();
00496 rep->clear ();
00497
00498 if (! m_digis.empty ())
00499 {
00500 SoSeparator *sep = new SoSeparator;
00501 SoMaterial *mat = new SoMaterial;
00502 mat->diffuseColor.setValue (0.3, 0.8, 0.0);
00503 sep->addChild (mat);
00504
00505 SoDrawStyle *drawStyle = new SoDrawStyle;
00506 drawStyle->pointSize = 3.0;
00507 sep->addChild (drawStyle);
00508
00509 try
00510 {
00511 SoVertexProperty *vertices = new SoVertexProperty;
00512 int nVrx = 0;
00513
00514 for (std::vector<std::pair<CSCDetId, CSCCLCTDigi> >::const_iterator i = m_digis.begin (), iEnd = m_digis.end (); i != iEnd; ++i)
00515 {
00516 Surface::GlobalPoint pos = (m_pDD->idToDet ((*i).first))->surface ().position ();
00517
00518
00519
00520 float x = pos.x () / 100.0;
00521 float y = pos.y () / 100.0;
00522 float z = pos.z () / 100.0;
00523
00524 vertices->vertex.set1Value (nVrx++, SbVec3f (x, y, z));
00525 }
00526 vertices->vertex.setNum (m_digis.size ());
00527
00528 SoPointSet *points = new SoPointSet;
00529 points->vertexProperty.setValue (vertices);
00530 points->numPoints.setValue (m_digis.size ());
00531 sep->addChild (points);
00532 }
00533 catch (cms::Exception& e)
00534 {
00535 if (this->m_onCmsException)
00536 this->m_onCmsException (&e);
00537 }
00538 catch (lat::Error &e)
00539 {
00540 if (this->m_onError)
00541 this->m_onError (&e);
00542 }
00543 catch (std::exception &e)
00544 {
00545 if (this->m_onException)
00546 this->m_onException (&e);
00547 }
00548 catch (...)
00549 {
00550 if (this->m_onUnhandledException)
00551 this->m_onUnhandledException ();
00552 }
00553
00554 rep->node ()->addChild (sep);
00555 }
00556 }