00001
00002
00003 #include "VisReco/VisMuonDT/interface/VisDT4DSegmentTwig.h"
00004 #include "VisFramework/VisFrameworkBase/interface/VisTwigFactroyService.h"
00005 #include "VisFramework/VisFrameworkBase/interface/VisEventSelector.h"
00006 #include "VisFramework/VisFrameworkBase/interface/debug.h"
00007 #include "VisReco/VisRecoGeometry/interface/VisTrackingGeometry.h"
00008 #include "DataFormats/DTRecHit/interface/DTRecHit1D.h"
00009 #include "DataFormats/DTRecHit/interface/DTRecHit1DPair.h"
00010 #include "DataFormats/DTRecHit/interface/DTRecHitCollection.h"
00011
00012 #include "DataFormats/DTRecHit/interface/DTRecSegment4D.h"
00013 #include "DataFormats/DTRecHit/interface/DTRecSegment4DCollection.h"
00014
00015 #include "Geometry/DTGeometry/interface/DTLayer.h"
00016 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00017 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00018
00019 #include "FWCore/Framework/interface/Event.h"
00020 #include "FWCore/Framework/interface/EventSetup.h"
00021 #include "DataFormats/Common/interface/Handle.h"
00022 #include "FWCore/Framework/interface/ESHandle.h"
00023
00024 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00025
00026 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00027 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00028 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00029 #include "Geometry/DTGeometry/interface/DTLayer.h"
00030 #include "Iguana/Models/interface/IgTextRep.h"
00031 #include "Iguana/GLModels/interface/Ig3DRep.h"
00032 #include "Iguana/GLModels/interface/IgLegoRep.h"
00033 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00034 #include "Iguana/GLModels/interface/IgRZRep.h"
00035 #include "Iguana/Studio/interface/IgQtLock.h"
00036 #include "Iguana/Inventor/interface/IgSbColorMap.h"
00037 #include <Inventor/nodes/SoDrawStyle.h>
00038 #include <Inventor/nodes/SoMaterial.h>
00039 #include <Inventor/nodes/SoSeparator.h>
00040 #include <Inventor/nodes/SoPointSet.h>
00041 #include <Inventor/nodes/SoTransform.h>
00042 #include <Inventor/nodes/SoLineSet.h>
00043
00044 #include <qstring.h>
00045 #include <classlib/utils/DebugAids.h>
00046 #include <iostream>
00047 #include <iomanip>
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 using namespace edm;
00059 using namespace std;
00060 using namespace DTEnums;
00061
00062 namespace
00063 {
00064 VisQueuedTwig *
00065 createThisTwig (IgState *state, IgTwig *parent,
00066 const std::string &name,
00067 const std::string &friendlyName,
00068 const std::string &moduleLabel,
00069 const std::string &instanceName,
00070 const std::string &processName)
00071 {
00072 return new VisDT4DSegmentTwig (state, parent, "DT RecSegment4D (" + name + ")",
00073 friendlyName, moduleLabel, instanceName, processName);
00074 }
00075 }
00076
00077
00078
00079
00080 VisDT4DSegmentTwig::VisDT4DSegmentTwig (IgState *state, IgTwig *parent,
00081 const std::string &name ,
00082 const std::string &friendlyName ,
00083 const std::string &moduleLabel ,
00084 const std::string &instanceName ,
00085 const std::string &processName )
00086 : VisQueuedTwig (state, parent, name),
00087 m_text ("no info"),
00088 m_friendlyName (friendlyName),
00089 m_moduleLabel (moduleLabel),
00090 m_instanceName (instanceName),
00091 m_processName (processName)
00092 {
00093 VisTwigFactroyService *tfService = VisTwigFactroyService::get (state);
00094 if (! tfService)
00095 {
00096 tfService = new VisTwigFactroyService (state);
00097 }
00098 edm::TypeID dt4DSegID (typeid (DTRecSegment4DCollection));
00099 tfService->registerTwig (dt4DSegID.friendlyClassName (), &createThisTwig);
00100 }
00101
00102 void
00103 VisDT4DSegmentTwig::onNewEvent (const edm::Event &event,
00104 const edm::EventSetup &eventSetup)
00105 {
00106
00107 VisQueuedTwig::onNewEvent (event, eventSetup);
00108
00109 m_recseg.clear ();
00110 m_text = (QString ("Run # %1, event # %2")
00111 .arg (event.id ().run ())
00112 .arg (event.id ().event ()).latin1 ());
00113
00114
00115 std::vector<edm::Handle<DTRecSegment4DCollection> > recsegCollections;
00116
00117 try
00118 {
00119 if ((! m_friendlyName.empty ()) || (! m_moduleLabel.empty ()) || (! m_instanceName.empty ()) || (! m_processName.empty ()))
00120 {
00121 VisEventSelector visSel (m_friendlyName, m_moduleLabel, m_instanceName, m_processName);
00122 event.getMany (visSel, recsegCollections);
00123 }
00124 else
00125 {
00126 event.getManyByType (recsegCollections);
00127 }
00128
00129 }
00130 catch (cms::Exception& e)
00131 {
00132 if (this->m_onCmsException)
00133 this->m_onCmsException (&e);
00134 }
00135 catch (lat::Error &e)
00136 {
00137 if (this->m_onError)
00138 this->m_onError (&e);
00139 }
00140 catch (std::exception &e)
00141 {
00142 if (this->m_onException)
00143 this->m_onException (&e);
00144 }
00145 catch (...)
00146 {
00147 if (this->m_onUnhandledException)
00148 this->m_onUnhandledException ();
00149 }
00150
00151 try
00152 {
00153 eventSetup.get<MuonGeometryRecord> ().get (m_pDD);
00154 }
00155 catch (cms::Exception& e)
00156 {
00157 if (this->m_onCmsException)
00158 this->m_onCmsException (&e);
00159 }
00160 catch (lat::Error &e)
00161 {
00162 if (this->m_onError)
00163 this->m_onError (&e);
00164 }
00165 catch (std::exception &e)
00166 {
00167 if (this->m_onException)
00168 this->m_onException (&e);
00169 }
00170 catch (...)
00171 {
00172 if (this->m_onUnhandledException)
00173 this->m_onUnhandledException ();
00174 }
00175
00176 if (! recsegCollections.empty ())
00177 {
00178 std::vector<Handle<DTRecSegment4DCollection> >::iterator i;
00179 std::vector<Handle<DTRecSegment4DCollection> >::iterator iEnd;
00180 for (i = recsegCollections.begin (), iEnd = recsegCollections.end (); i != iEnd; ++i)
00181 {
00182 const DTRecSegment4DCollection& c = *(*i);
00183 for (DTRecSegment4DCollection::const_iterator rsi = c.begin (), rsiEnd = c.end ();
00184 rsi != rsiEnd; ++rsi)
00185 {
00186 m_recseg.push_back (*rsi);
00187 }
00188 }
00189 }
00190
00191 VisQueuedTwig::onBaseInvalidate ();
00192 }
00193
00194 void
00195 VisDT4DSegmentTwig::update (IgTextRep *rep)
00196 {
00197
00198 VisQueuedTwig::update (rep);
00199
00200
00201 std::ostringstream text;
00202
00203 text << "<b>Muon Barrel: DT Track 4D Segments</b><br>";
00204
00205 text << "<table width='100%' border=1>"
00206 << "<TR align = center>"
00207 << "<TH>Number</TH>"
00208 << "<TH>nHits</TH>"
00209 << "<TH>Wheel</TH>"
00210 << "<TH>Station</TH>"
00211 << "<TH>Sector</TH>"
00212 << "<TH>position</TH>"
00213 << "<TH>direction</TH>"
00214 << "<TH>r [cm]</TH>"
00215 << "<TH>phi [rad]</TH>"
00216 << "<TH>chi2 / hits</TH>"
00217
00218 << "</TR>";
00219 text << setiosflags (ios::showpoint | ios::fixed);
00220 text.setf (ios::right, ios::adjustfield);
00221
00222 try
00223 {
00224 int nSegments = 0;
00225 for (std::vector< DTRecSegment4D >::const_iterator i = m_recseg.begin (), iEnd = m_recseg.end (); i != iEnd; ++i)
00226 {
00227
00228 std::vector<const TrackingRecHit*> hits = (*i).recHits();
00229 int nHits = 0;
00230 for (std::vector<const TrackingRecHit*>::const_iterator h=hits.begin() ;
00231 h!=hits.end(); ++h) nHits+= (*h)->recHits().size();
00232 DTChamberId chId ((*i).geographicalId ().rawId ());
00233 const DTChamber *chamber = m_pDD->chamber (chId);
00234
00235 LocalVector locDir = (*i).localDirection ();
00236 LocalPoint locPos = (*i).localPosition ();
00237
00238 GlobalVector gloDir = chamber->toGlobal (locDir);
00239 GlobalPoint gloPos = chamber->toGlobal (locPos);
00240
00241 float phi = gloPos.phi ();
00242 phi = (phi < 0) ? 2 * M_PI + phi : phi;
00243
00244 double chi2 = (*i).chi2 ();
00245 int dof = (*i).degreesOfFreedom ();
00246
00247 int sectorIdRs = chId.sector ();
00248 int stationIdRs = chId.station ();
00249 int wheelIdRs = chId.wheel ();
00250
00251 text << "<TR align = right>"
00252 << "<TD>" << setw (2) << nSegments++ << "</TD>"
00253 << "<TD>" << setw (1) << nHits << "</TD>"
00254 << "<TD>" << wheelIdRs << "</TD>"
00255 << "<TD>" << stationIdRs << "</TD>"
00256 << "<TD>" << sectorIdRs << "</TD>"
00257 << "<TD>" << setw (6) << setprecision (2) << gloPos << "</TD>"
00258 << "<TD>" << setw (6) << setprecision (2) << gloDir << "</TD>"
00259 << "<TD>" << setw (5) << setprecision (1) << gloPos.perp() << "</TD>"
00260 << "<TD>" << setw (6) << setprecision (3) << phi << "</TD>"
00261 << "<TD>" << setw (6) << setprecision (2) << chi2/dof << "</TD>"
00262 << "</TR>";
00263 }
00264 }
00265 catch (cms::Exception& e)
00266 {
00267 if (this->m_onCmsException)
00268 this->m_onCmsException (&e);
00269 }
00270 catch (lat::Error &e)
00271 {
00272 if (this->m_onError)
00273 this->m_onError (&e);
00274 }
00275 catch (std::exception &e)
00276 {
00277 if (this->m_onException)
00278 this->m_onException (&e);
00279 }
00280 catch (...)
00281 {
00282 if (this->m_onUnhandledException)
00283 this->m_onUnhandledException ();
00284 }
00285
00286 text << "</table>";
00287
00288 IgQtLock ();
00289 rep->setText (text.str ());
00290 }
00291
00292 void
00293 VisDT4DSegmentTwig::update (Ig3DRep *rep)
00294 {
00295
00296 VisQueuedTwig::update (rep);
00297
00298 IgQtLock ();
00299 rep->clear ();
00300
00301 if ((! m_recseg.empty ()) && m_pDD.isValid ())
00302 {
00303
00304 SoSeparator *sep = new SoSeparator;
00305
00306 try
00307 {
00308 for (std::vector< DTRecSegment4D >::const_iterator i = m_recseg.begin (), iEnd = m_recseg.end (); i != iEnd; ++i)
00309 {
00310 DTChamberId chId ((*i).geographicalId ().rawId ());
00311 const DTChamber *chamber = m_pDD->chamber (chId);
00312
00313 float halfHeight = chamber->surface ().bounds ().thickness () / 2.0;
00314 LocalVector locDir = (*i).localDirection ();
00315 LocalPoint locPos = (*i).localPosition ();
00316
00317 SoVertexProperty *vtx = new SoVertexProperty;
00318
00319 SoLineSet *line = new SoLineSet;
00320 line->numVertices = 2;
00321
00322 GlobalPoint posInner = chamber->toGlobal (locPos + locDir / locDir.mag () * halfHeight / cos (locDir.theta ()));
00323 float x = posInner.x () / 100.0;
00324 float y = posInner.y () / 100.0;
00325 float z = posInner.z () / 100.0;
00326
00327 vtx->vertex.set1Value (0, SbVec3f (x, y, z));
00328
00329 GlobalPoint posOuter = chamber->toGlobal (locPos + locDir / (-locDir.mag ()) * halfHeight / cos (locDir.theta ()));
00330 x = posOuter.x () / 100.0;
00331 y = posOuter.y () / 100.0;
00332 z = posOuter.z () / 100.0;
00333
00334 vtx->vertex.set1Value (1, SbVec3f (x, y, z));
00335
00336 line->vertexProperty = vtx;
00337
00338 SoMaterial *wmat = new SoMaterial;
00339 float rgbcomponents [4];
00340 IgSbColorMap::unpack (0xff000000, rgbcomponents);
00341 wmat->diffuseColor.setValue (SbColor (rgbcomponents));
00342 sep->addChild (wmat);
00343
00344 SoDrawStyle *sty = new SoDrawStyle;
00345 sty->style = SoDrawStyle::LINES;
00346 sty->lineWidth.setValue (4.0);
00347 sep->addChild (sty);
00348
00349 sep->addChild (line);
00350 }
00351 }
00352 catch (cms::Exception& e)
00353 {
00354 if (this->m_onCmsException)
00355 this->m_onCmsException (&e);
00356 }
00357 catch (lat::Error &e)
00358 {
00359 if (this->m_onError)
00360 this->m_onError (&e);
00361 }
00362 catch (std::exception &e)
00363 {
00364 if (this->m_onException)
00365 this->m_onException (&e);
00366 }
00367 catch (...)
00368 {
00369 if (this->m_onUnhandledException)
00370 this->m_onUnhandledException ();
00371 }
00372
00373 rep->node ()->addChild (sep);
00374 }
00375 }
00376
00377 void
00378 VisDT4DSegmentTwig::update (IgLegoRep *rep)
00379 {
00380
00381 VisQueuedTwig::update (rep);
00382
00383 IgQtLock ();
00384 rep->clear ();
00385
00386
00387 }
00388
00389 void
00390 VisDT4DSegmentTwig::update (IgRPhiRep *rep)
00391 {
00392
00393 VisQueuedTwig::update (rep);
00394
00395 IgQtLock ();
00396 rep->clear ();
00397
00398 if ((! m_recseg.empty ()) && m_pDD.isValid ())
00399 {
00400
00401 SoSeparator *sep = new SoSeparator;
00402
00403 try
00404 {
00405 for (std::vector< DTRecSegment4D >::const_iterator i = m_recseg.begin (), iEnd = m_recseg.end (); i != iEnd; ++i)
00406 {
00407 DTChamberId chId ((*i).geographicalId ().rawId ());
00408 const DTChamber* chamber = m_pDD->chamber (chId);
00409
00410 float halfHeight = chamber->surface ().bounds ().thickness () / 2.0;
00411 LocalVector locDir = (*i).localDirection ();
00412 LocalPoint locPos = (*i).localPosition ();
00413
00414 SoVertexProperty *vtx = new SoVertexProperty;
00415
00416 SoLineSet *line = new SoLineSet;
00417 line->numVertices = 2;
00418
00419 GlobalPoint posInner = chamber->toGlobal (locPos + locDir / locDir.mag () * halfHeight / cos (locDir.theta ()));
00420 float x = posInner.x () / 100.0;
00421 float y = posInner.y () / 100.0;
00422 float z = posInner.z () / 100.0;
00423
00424 vtx->vertex.set1Value (0, SbVec3f (x, y, z));
00425
00426 GlobalPoint posOuter = chamber->toGlobal (locPos + locDir / (-locDir.mag ()) * halfHeight / cos (locDir.theta ()));
00427 x = posOuter.x () / 100.0;
00428 y = posOuter.y () / 100.0;
00429 z = posOuter.z () / 100.0;
00430
00431 vtx->vertex.set1Value (1, SbVec3f (x, y, z));
00432
00433 line->vertexProperty = vtx;
00434
00435 SoMaterial *wmat = new SoMaterial;
00436 float rgbcomponents [4];
00437 IgSbColorMap::unpack (0xff000000, rgbcomponents);
00438 wmat->diffuseColor.setValue (SbColor (rgbcomponents));
00439 sep->addChild (wmat);
00440
00441 SoDrawStyle *sty = new SoDrawStyle;
00442 sty->style = SoDrawStyle::LINES;
00443 sty->lineWidth.setValue (4.0);
00444 sep->addChild (sty);
00445
00446 sep->addChild (line);
00447
00448 SoDrawStyle *drawStyle = new SoDrawStyle;
00449 drawStyle->pointSize.setValue (2.0);
00450 sep->addChild (drawStyle);
00451
00452 SoVertexProperty *pti = new SoVertexProperty;
00453 pti->materialBinding = SoVertexProperty::OVERALL;
00454 pti->orderedRGBA = 0x9900cc00;
00455
00456 if ((*i).phiSegment () && (*i).zSegment ())
00457 {
00458 std::vector<DTRecHit1D> segRecHitPhi = (*i).phiSegment ()->specificRecHits ();
00459 std::vector<DTRecHit1D> segRecHitZ = (*i).zSegment ()->specificRecHits ();
00460
00461 int npti = 0;
00462
00463 for (std::vector<DTRecHit1D>::const_iterator rechit = segRecHitPhi.begin (), rechitEnd = segRecHitPhi.end ();
00464 rechit != rechitEnd; ++rechit)
00465 {
00466 DTWireId wireId = rechit->wireId ();
00467 const DTLayer* layer = m_pDD->layer (wireId);
00468
00469 LocalPoint LocalPos = rechit->localPosition ();
00470 GlobalPoint GlobalPos = layer->toGlobal (LocalPos);
00471
00472 pti->vertex.set1Value (npti, SbVec3f (GlobalPos.x () / 100.0,
00473 GlobalPos.y () / 100.0,
00474 GlobalPos.z () / 100.0));
00475 ++npti;
00476 }
00477
00478 for (std::vector<DTRecHit1D>::const_iterator rechit = segRecHitZ.begin (), rechitEnd = segRecHitZ.end ();
00479 rechit != rechitEnd; ++rechit)
00480 {
00481 DTWireId wireId = rechit->wireId ();
00482 const DTLayer *layer = m_pDD->layer (wireId);
00483
00484 LocalPoint LocalPos = rechit->localPosition ();
00485 GlobalPoint GlobalPos = layer->toGlobal (LocalPos);
00486
00487 pti->vertex.set1Value (npti, SbVec3f (GlobalPos.x () / 100.0,
00488 GlobalPos.y () / 100.0,
00489 GlobalPos.z () / 100.0));
00490 ++npti;
00491 }
00492
00493 if (npti > 0)
00494 {
00495 pti->vertex.setNum (npti);
00496 SoPointSet *pset = new SoPointSet;
00497 pset->vertexProperty = pti;
00498 sep->addChild (pset);
00499 }
00500 }
00501 }
00502 }
00503 catch (cms::Exception& e)
00504 {
00505 if (this->m_onCmsException)
00506 this->m_onCmsException (&e);
00507 }
00508 catch (lat::Error &e)
00509 {
00510 if (this->m_onError)
00511 this->m_onError (&e);
00512 }
00513 catch (std::exception &e)
00514 {
00515 if (this->m_onException)
00516 this->m_onException (&e);
00517 }
00518 catch (...)
00519 {
00520 if (this->m_onUnhandledException)
00521 this->m_onUnhandledException ();
00522 }
00523
00524 rep->node ()->addChild (sep);
00525 }
00526 }
00527
00528 void
00529 VisDT4DSegmentTwig::update (IgRZRep *rep)
00530 {
00531
00532 VisQueuedTwig::update (rep);
00533
00534 IgQtLock ();
00535 rep->clear ();
00536
00537 if ((! m_recseg.empty ()) && m_pDD.isValid ())
00538 {
00539 SoSeparator *sep = new SoSeparator;
00540
00541 try
00542 {
00543 for (std::vector< DTRecSegment4D >::const_iterator i = m_recseg.begin (), iEnd = m_recseg.end (); i != iEnd; ++i)
00544 {
00545 DTChamberId chId ((*i).geographicalId ().rawId ());
00546 const DTChamber *chamber = m_pDD->chamber (chId);
00547
00548 float halfHeight = chamber->surface ().bounds ().thickness () / 2.0;
00549 LocalVector locDir = (*i).localDirection ();
00550 LocalPoint locPos = (*i).localPosition ();
00551
00552 SoVertexProperty *vtx = new SoVertexProperty;
00553
00554 SoLineSet *line = new SoLineSet;
00555 line->numVertices = 2;
00556
00557 GlobalPoint posInner = chamber->toGlobal (locPos + locDir / locDir.mag () * halfHeight / cos (locDir.theta ()));
00558 float x = posInner.x () / 100.0;
00559 float y = posInner.y () / 100.0;
00560 float z = posInner.z () / 100.0;
00561
00562 vtx->vertex.set1Value (0, SbVec3f (x, y, z));
00563
00564 GlobalPoint posOuter = chamber->toGlobal (locPos + locDir / (-locDir.mag ()) * halfHeight / cos (locDir.theta ()));
00565 x = posOuter.x () / 100.0;
00566 y = posOuter.y () / 100.0;
00567 z = posOuter.z () / 100.0;
00568
00569 vtx->vertex.set1Value (1, SbVec3f (x, y, z));
00570
00571 line->vertexProperty = vtx;
00572
00573 SoMaterial *wmat = new SoMaterial;
00574 float rgbcomponents [4];
00575 IgSbColorMap::unpack (0xff000000, rgbcomponents);
00576 wmat->diffuseColor.setValue (SbColor (rgbcomponents));
00577 sep->addChild (wmat);
00578
00579 SoDrawStyle *sty = new SoDrawStyle;
00580 sty->style = SoDrawStyle::LINES;
00581 sty->lineWidth.setValue (4.0);
00582 sep->addChild (sty);
00583
00584 sep->addChild (line);
00585 }
00586 }
00587 catch (cms::Exception& e)
00588 {
00589 if (this->m_onCmsException)
00590 this->m_onCmsException (&e);
00591 }
00592 catch (lat::Error &e)
00593 {
00594 if (this->m_onError)
00595 this->m_onError (&e);
00596 }
00597 catch (std::exception &e)
00598 {
00599 if (this->m_onException)
00600 this->m_onException (&e);
00601 }
00602 catch (...)
00603 {
00604 if (this->m_onUnhandledException)
00605 this->m_onUnhandledException ();
00606 }
00607
00608 rep->node ()->addChild (sep);
00609 }
00610 }
00611
00612
00614 void
00615 VisDT4DSegmentTwig::addMaterial (SoSeparator *sep)
00616 {
00617 SoMaterial *segment = new SoMaterial;
00618 segment->diffuseColor.setValue (0., 1., 0.);
00619
00620 sep->addChild (segment);
00621 }