00001
00002
00003 #include "VisReco/VisTracker/interface/VisTrackerRechit2DMatchedTwig.h"
00004 #include "VisFramework/VisFrameworkBase/interface/debug.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/TrackerRecHit2D/interface/SiStripRecHit2D.h"
00009 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2DCollection.h"
00010 #include "FWCore/Framework/interface/Event.h"
00011 #include "Iguana/Inventor/interface/IgSbColorMap.h"
00012 #include "Iguana/Inventor/interface/IgSoTower.h"
00013 #include "Iguana/Models/interface/IgTextRep.h"
00014 #include "Iguana/GLModels/interface/Ig3DRep.h"
00015 #include "Iguana/GLModels/interface/IgLegoRep.h"
00016 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00017 #include "Iguana/GLModels/interface/IgRZRep.h"
00018 #include "Iguana/Framework/interface/IgRepSet.h"
00019 #include "Iguana/Studio/interface/IgDocumentData.h"
00020 #include "Iguana/Studio/interface/IgQtLock.h"
00021 #include <Inventor/nodes/SoSeparator.h>
00022 #include <Inventor/nodes/SoDrawStyle.h>
00023 #include <Inventor/nodes/SoMarkerSet.h>
00024 #include <Inventor/nodes/SoMaterial.h>
00025 #include <Inventor/nodes/SoPointSet.h>
00026 #include <Inventor/nodes/SoVertexProperty.h>
00027 #include <qstring.h>
00028 #include <iostream>
00029 #include <iomanip>
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 namespace
00042 {
00043 VisQueuedTwig *
00044 createThisTwig (IgState *state, IgTwig *parent,
00045 const std::string &name,
00046 const std::string &friendlyName,
00047 const std::string &modLabel,
00048 const std::string &instanceName,
00049 const std::string &processName)
00050 {
00051 IgTwig *rootTwig = IgDocumentData::get (state)->root ();
00052 IgTwig *eventTwig = 0;
00053 eventTwig = rootTwig->lookup ("/Objects/CMS Event and Detector/Tracker Event/SiStrip RecHit 2D Matched");
00054
00055 if (! eventTwig)
00056 eventTwig = parent;
00057
00058 return new VisTrackerRechit2DMatchedTwig (state, eventTwig, "[N/A] SiStrip RecHit 2D Matched (" + name + ")",
00059 friendlyName, modLabel, instanceName, processName);
00060 }
00061 }
00062
00063 VisTrackerRechit2DMatchedTwig::VisTrackerRechit2DMatchedTwig(IgState *state, IgTwig *parent,
00064 const std::string &name ,
00065 const std::string &friendlyName ,
00066 const std::string &moduleLabel ,
00067 const std::string &instanceName ,
00068 const std::string &processName )
00069 : VisQueuedTwig (state, parent, name),
00070 m_text (name),
00071 m_friendlyName (friendlyName),
00072 m_moduleLabel (moduleLabel),
00073 m_instanceName (instanceName),
00074 m_processName (processName),
00075 m_scale (state, lat::CreateCallback (this, &VisTrackerRechit2DMatchedTwig::twigChanged))
00076 {
00077 VisTwigFactroyService *tfService = VisTwigFactroyService::get (state);
00078 if (! tfService)
00079 {
00080 tfService = new VisTwigFactroyService (state);
00081 }
00082 edm::TypeID rechit2DMatchedCollID (typeid (SiStripMatchedRecHit2DCollection));
00083 tfService->registerTwig (rechit2DMatchedCollID.friendlyClassName (), &createThisTwig);
00084 }
00085
00086 void
00087 VisTrackerRechit2DMatchedTwig::twigChanged (void)
00088 { IgRepSet::invalidate (this, SELF_MASK); }
00089
00090 void
00091 VisTrackerRechit2DMatchedTwig::onNewEvent (const edm::Event &event,
00092 const edm::EventSetup &eventSetup)
00093 {
00094
00095 VisQueuedTwig::onNewEvent (event, eventSetup);
00096
00097 m_hits.clear ();
00098
00099 m_text = QString ("Run %1, Event %2, LS %3, Orbit %4, BX %5")
00100 .arg (event.id ().run ())
00101 .arg (event.id ().event ())
00102 .arg (event.luminosityBlock ())
00103 .arg (event.orbitNumber ())
00104 .arg (event.bunchCrossing ())
00105 .latin1 ();
00106
00107 std::vector< edm::Handle<SiStripMatchedRecHit2DCollection> > collections;
00108 try
00109 {
00110 if ((! m_friendlyName.empty ()) || (! m_moduleLabel.empty ()) || (! m_instanceName.empty ()) || (! m_processName.empty ()))
00111 {
00112 VisEventSelector visSel (m_friendlyName, m_moduleLabel, m_instanceName, m_processName);
00113 event.getMany (visSel, collections);
00114 }
00115 }
00116 catch (cms::Exception& e)
00117 {
00118 e.append (" from VisTrackerRechit2DMatchedTwig: ");
00119 e.append (this->name ());
00120
00121 if (this->m_onCmsException)
00122 this->m_onCmsException (&e);
00123 }
00124 catch (lat::Error &e)
00125 {
00126 if (this->m_onError)
00127 this->m_onError (&e);
00128 }
00129 catch (std::exception &e)
00130 {
00131 if (this->m_onException)
00132 this->m_onException (&e);
00133 }
00134 catch (...)
00135 {
00136 if (this->m_onUnhandledException)
00137 this->m_onUnhandledException ();
00138 }
00139
00140 if (! collections.empty ())
00141 {
00142 VisEventSetupService *esService = VisEventSetupService::get (state ());
00143 ASSERT (esService);
00144
00145 std::vector< edm::Handle<SiStripMatchedRecHit2DCollection> >::iterator i;
00146 std::vector< edm::Handle<SiStripMatchedRecHit2DCollection> >::iterator iEnd;
00147 for (i = collections.begin (), iEnd = collections.end (); i != iEnd; ++i)
00148 {
00149 const SiStripMatchedRecHit2DCollection&c = *(*i);
00150 QString sizeStr = (QString ("%1").arg (c.size ()));
00151 QString nameStr = QString (this->name ());
00152 int ib = nameStr.find ("[");
00153 int ie = nameStr.find ("]");
00154 nameStr.replace (ib + 1, ie - 1, sizeStr);
00155
00156 this->name (nameStr);
00157
00158 SiStripMatchedRecHit2DCollection::id_iterator detUnitIt;
00159 SiStripMatchedRecHit2DCollection::id_iterator detUnitItEnd;
00160 for (detUnitIt = c.id_begin (), detUnitItEnd = c.id_end (); detUnitIt != detUnitItEnd; ++detUnitIt)
00161 {
00162 SiStripMatchedRecHit2DCollection::range range = c.get ((*detUnitIt));
00163 for (SiStripMatchedRecHit2DCollection::const_iterator matchedrechit = range.first; matchedrechit != range.second; ++matchedrechit)
00164 {
00165 DetId detectorId = (*matchedrechit).geographicalId ();
00166 unsigned int id = detectorId.rawId ();
00167
00168 std::vector<LocalPoint> points;
00169 esService->localPositions(&(*matchedrechit), points);
00170
00171 DetId detIdObject (id);
00172 const SiStripCluster* Cluster_1 = 0 ;
00173 if ((*matchedrechit).monoHit ()->cluster ().isNonnull ())
00174 Cluster_1 = ((*matchedrechit).monoHit ())->cluster ().get ();
00175 else if ((*matchedrechit).monoHit ()->cluster_regional ().isNonnull ())
00176 Cluster_1 = ((*matchedrechit).monoHit ())->cluster_regional ().get ();
00177 else continue;
00178
00179 LocalPoint & position_1 = points [0];
00180
00181 int clusterCharge = 0;
00182 int clusterCharge_1 = 0;
00183 int cas = Cluster_1->amplitudes ().size ();
00184 for (int j = 0; j < cas; j++)
00185 {
00186 clusterCharge += Cluster_1->amplitudes ()[j];
00187 }
00188 clusterCharge_1 = clusterCharge;
00189
00190 std::pair<GlobalPoint, int> pxd_1;
00191 pxd_1.first = esService->toGlobal (position_1, DetId (Cluster_1->geographicalId ()));
00192 pxd_1.second = clusterCharge_1;
00193 m_hits.push_back (pxd_1);
00194
00195 const SiStripCluster* Cluster_2 = 0;
00196 if ((*matchedrechit).stereoHit ()->cluster ().isNonnull ())
00197 Cluster_2 = ((*matchedrechit).stereoHit ())->cluster ().get ();
00198 else if ((*matchedrechit).stereoHit ()->cluster_regional ().isNonnull ())
00199 Cluster_2 = ((*matchedrechit).stereoHit ())->cluster_regional ().get ();
00200 else continue;
00201
00202 LocalPoint & position_2 = points[1];
00203
00204 int clusterCharge_2 = 0;
00205 int cus = Cluster_2->amplitudes ().size ();
00206 for (int j = 0; j < cus; j++)
00207 {
00208 clusterCharge +=Cluster_2->amplitudes()[j];
00209 }
00210 clusterCharge_2 = clusterCharge - clusterCharge_1;
00211 clusterCharge = clusterCharge / 2;
00212
00213 std::pair<GlobalPoint, int> pxd_2;
00214 pxd_2.first = esService->toGlobal (position_2, DetId (Cluster_2->geographicalId ()));
00215 pxd_2.second = clusterCharge_2;
00216 m_hits.push_back (pxd_2);
00217 }
00218 }
00219 }
00220 }
00221
00222 IgRepSet::invalidate (this, IgTwig::SELF_MASK | IgTwig::STRUCTURE_MASK);
00223 }
00224
00225 void
00226 VisTrackerRechit2DMatchedTwig::update (IgTextRep *rep)
00227 {
00228
00229 VisQueuedTwig::update (rep);
00230
00231
00232 std::ostringstream text;
00233 text << "Total " << m_hits.size () << " Silicon Strip matched 2D rechits from ";
00234 text << m_text << "<br>";
00235 if (m_hits.size () > 100)
00236 {
00237 text << "Printing only first 100." << "<br>";
00238 }
00239
00240 text << "<table width='100%' border=1>"
00241 << "<TR align = center>"
00242 << "<TH>Number</TH>"
00243 << "<TH>Position (m): x, y, z</TH>"
00244 << "<TH>Amplitude</TH>"
00245 << "</TR>";
00246
00247 text << setiosflags (std::ios::showpoint | std::ios::fixed);
00248 text.setf (std::ios::right, std::ios::adjustfield);
00249
00250 if (! m_hits.empty ())
00251 {
00252 int nRecHits = 0;
00253 try
00254 {
00255 for (std::vector<std::pair<GlobalPoint, int> >::const_iterator i = m_hits.begin (), iEnd = m_hits.end (); i != iEnd; ++i)
00256 {
00257 GlobalPoint pos = (*i).first;
00258 text << "<TR align = right>"
00259 << "<TD>" << std::setw (3) << ++nRecHits << "</TD>"
00260 << "<TD>" << pos.x () / 100 << ", " << pos.y () / 100 << ", " << pos.z () / 100 << "</TD>"
00261 << "<TD>" << std::setw (11) << (*i).second << "</TD></TR>";
00262 if (nRecHits > 100) break;
00263 }
00264 }
00265 catch (cms::Exception& e)
00266 {
00267 e.append (" from VisTrackerRechit2DMatchedTwig: ");
00268 e.append (this->name ());
00269
00270 if (this->m_onCmsException)
00271 this->m_onCmsException (&e);
00272 }
00273 catch (lat::Error &e)
00274 {
00275 if (this->m_onError)
00276 this->m_onError (&e);
00277 }
00278 catch (std::exception &e)
00279 {
00280 if (this->m_onException)
00281 this->m_onException (&e);
00282 }
00283 catch (...)
00284 {
00285 if (this->m_onUnhandledException)
00286 this->m_onUnhandledException ();
00287 }
00288
00289 text << "</table>";
00290 }
00291
00292
00293 IgQtLock ();
00294 rep->setText (text.str ());
00295 }
00296
00297
00298 void
00299 VisTrackerRechit2DMatchedTwig::update (Ig3DRep *rep)
00300 {
00301
00302 VisQueuedTwig::update (rep);
00303 IgQtLock ();
00304 rep->clear ();
00305
00306 if (! m_hits.empty ())
00307 {
00308 SoSeparator *sep = new SoSeparator;
00309
00310 SoMaterial *mat = new SoMaterial;
00311 float rgbcomponents [4];
00312 IgSbColorMap::unpack (0x238E2300, rgbcomponents);
00313 mat->diffuseColor.setValue (SbColor (rgbcomponents));
00314 sep->addChild (mat);
00315
00316 SoDrawStyle *drawStyle = new SoDrawStyle;
00317 drawStyle->pointSize = 4.0;
00318 sep->addChild (drawStyle);
00319
00320 try
00321 {
00322 SoVertexProperty *vertices = new SoVertexProperty;
00323 int nVrtx = 0;
00324
00325 for (std::vector<std::pair<GlobalPoint, int> >::const_iterator
00326 i = m_hits.begin (), iEnd = m_hits.end (); i != iEnd; ++i)
00327 {
00328 GlobalPoint pos = (*i).first;
00329 float x = pos.x () / 100.0;
00330 float y = pos.y () / 100.0;
00331 float z = pos.z () / 100.0;
00332
00333 vertices->vertex.set1Value (nVrtx++, SbVec3f (x, y, z));
00334 }
00335
00336 vertices->vertex.setNum (nVrtx);
00337 SoMFInt32 markerIndex;
00338 markerIndex.setValue (SoMarkerSet::CROSS_9_9);
00339
00340 SoMarkerSet *points = new SoMarkerSet;
00341 points->markerIndex = markerIndex;
00342 points->vertexProperty.setValue (vertices);
00343 points->numPoints.setValue (nVrtx);
00344
00345 sep->addChild (points);
00346 }
00347 catch (cms::Exception& e)
00348 {
00349 e.append (" from VisTrackerRechit2DMatchedTwig: ");
00350 e.append (this->name ());
00351
00352 if (this->m_onCmsException)
00353 this->m_onCmsException (&e);
00354 }
00355 catch (lat::Error &e)
00356 {
00357 if (this->m_onError)
00358 this->m_onError (&e);
00359 }
00360 catch (std::exception &e)
00361 {
00362 if (this->m_onException)
00363 this->m_onException (&e);
00364 }
00365 catch (...)
00366 {
00367 if (this->m_onUnhandledException)
00368 this->m_onUnhandledException ();
00369 }
00370
00371 rep->node ()->addChild (sep);
00372 }
00373 }
00374
00375 void
00376 VisTrackerRechit2DMatchedTwig::update (IgLegoRep *rep)
00377 {
00378
00379 VisQueuedTwig::update (rep);
00380
00381 IgQtLock ();
00382 rep->clear ();
00383
00384 SoSeparator *sep = new SoSeparator;
00385
00386 try
00387 {
00388 for (std::vector<std::pair<GlobalPoint, int> >::const_iterator i = m_hits.begin (), iEnd = m_hits.end (); i != iEnd; ++i)
00389 {
00390 GlobalPoint pos = (*i).first;
00391
00392 double eta = pos.eta ();
00393 double phi = pos.phi ();
00394 if (phi < 0.0) phi = 2 * M_PI + phi;
00395
00396 int recCharge = (*i).second;
00397
00398 IgSoTower *tower = new IgSoTower;
00399 tower->position = SbVec2f (phi, eta);
00400 tower->etaWidth = 0.01;
00401 tower->phiWidth = 0.01;
00402 tower->scaleFactor = m_scale.value ();
00403 tower->energy = recCharge * 250.0 * 3.61e-09;
00404 tower->orderedRGBA.set1Value (6, SbColor (0.0, 1.0, 0.0).getPackedValue ());
00405
00406 sep->addChild (tower);
00407 }
00408 }
00409 catch (cms::Exception& e)
00410 {
00411 e.append (" from VisTrackerRechit2DMatchedTwig: ");
00412 e.append (this->name ());
00413
00414 if (this->m_onCmsException)
00415 this->m_onCmsException (&e);
00416 }
00417 catch (lat::Error &e)
00418 {
00419 if (this->m_onError)
00420 this->m_onError (&e);
00421 }
00422 catch (std::exception &e)
00423 {
00424 if (this->m_onException)
00425 this->m_onException (&e);
00426 }
00427 catch (...)
00428 {
00429 if (this->m_onUnhandledException)
00430 this->m_onUnhandledException ();
00431 }
00432
00433 rep->node ()->addChild (sep);
00434
00435 }
00436
00437 void
00438 VisTrackerRechit2DMatchedTwig::update (IgRPhiRep *rep)
00439 {
00440
00441 VisQueuedTwig::update (rep);
00442
00443 IgQtLock ();
00444 rep->clear ();
00445
00446 if (! m_hits.empty ())
00447 {
00448 SoSeparator *sep = new SoSeparator;
00449
00450 SoMaterial *mat = new SoMaterial;
00451 float rgbcomponents [4];
00452 IgSbColorMap::unpack (0x238E2300, rgbcomponents);
00453 mat->diffuseColor.setValue (SbColor (rgbcomponents));
00454 sep->addChild (mat);
00455
00456 SoDrawStyle *drawStyle = new SoDrawStyle;
00457 drawStyle->pointSize = 8.0;
00458 sep->addChild (drawStyle);
00459
00460 try
00461 {
00462 SoVertexProperty *vertices = new SoVertexProperty;
00463 int nVrtx = 0;
00464 for (std::vector<std::pair<GlobalPoint, int> >::const_iterator i = m_hits.begin (), iEnd = m_hits.end (); i != iEnd; ++i)
00465 {
00466 GlobalPoint pos = (*i).first;
00467 float x = pos.x () / 100.0;
00468 float y = pos.y () / 100.0;
00469 float z = 3.2;
00470
00471 vertices->vertex.set1Value (nVrtx++, SbVec3f (x, y, z));
00472 }
00473
00474 vertices->vertex.setNum (nVrtx);
00475
00476 SoMFInt32 markerIndex;
00477 markerIndex.setValue (SoMarkerSet::CROSS_9_9);
00478
00479 SoMarkerSet *points = new SoMarkerSet;
00480 points->markerIndex = markerIndex;
00481 points->vertexProperty.setValue (vertices);
00482 points->numPoints.setValue (nVrtx);
00483
00484 sep->addChild (points);
00485 }
00486 catch (cms::Exception& e)
00487 {
00488 e.append (" from VisTrackerRechit2DMatchedTwig: ");
00489 e.append (this->name ());
00490
00491 if (this->m_onCmsException)
00492 this->m_onCmsException (&e);
00493 }
00494 catch (lat::Error &e)
00495 {
00496 if (this->m_onError)
00497 this->m_onError (&e);
00498 }
00499 catch (std::exception &e)
00500 {
00501 if (this->m_onException)
00502 this->m_onException (&e);
00503 }
00504 catch (...)
00505 {
00506 if (this->m_onUnhandledException)
00507 this->m_onUnhandledException ();
00508 }
00509 rep->node ()->addChild (sep);
00510 }
00511 }
00512
00513
00514 void
00515 VisTrackerRechit2DMatchedTwig::update (IgRZRep *rep)
00516 {
00517
00518 VisQueuedTwig::update (rep);
00519
00520 IgQtLock ();
00521 rep->clear ();
00522
00523 if (! m_hits.empty ())
00524 {
00525 SoSeparator *sep = new SoSeparator;
00526 SoMaterial *mat = new SoMaterial;
00527 float rgbcomponents [4];
00528 IgSbColorMap::unpack (0x238E2300, rgbcomponents);
00529 mat->diffuseColor.setValue (SbColor (rgbcomponents));
00530 sep->addChild (mat);
00531
00532 SoDrawStyle *drawStyle = new SoDrawStyle;
00533 drawStyle->pointSize = 8.0;
00534 sep->addChild (drawStyle);
00535
00536 try
00537 {
00538 SoVertexProperty *vertices = new SoVertexProperty;
00539 int nVrx = 0;
00540
00541 for (std::vector<std::pair<GlobalPoint, int> >::const_iterator i = m_hits.begin (), iEnd = m_hits.end (); i != iEnd; ++i)
00542 {
00543 GlobalPoint pos = (*i).first;
00544 float x = -3.2;
00545 float y = sqrt (pos.x () * pos.x () + pos.y () * pos.y ()) / 100.0;
00546 (pos.y () < 0.) ? y = -y : y;
00547 float z = pos.z () / 100.0;
00548
00549 vertices->vertex.set1Value (nVrx++, SbVec3f (x, y, z));
00550 }
00551
00552 vertices->vertex.setNum (nVrx);
00553 SoMFInt32 markerIndex;
00554 markerIndex.setValue (SoMarkerSet::CROSS_9_9);
00555
00556 SoMarkerSet *points = new SoMarkerSet;
00557 points->markerIndex = markerIndex;
00558 points->vertexProperty.setValue (vertices);
00559 points->numPoints.setValue (nVrx);
00560 sep->addChild (points);
00561 }
00562 catch (cms::Exception& e)
00563 {
00564 e.append (" from VisTrackerRechit2DMatchedTwig: ");
00565 e.append (this->name ());
00566
00567 if (this->m_onCmsException)
00568 this->m_onCmsException (&e);
00569 }
00570 catch (lat::Error &e)
00571 {
00572 if (this->m_onError)
00573 this->m_onError (&e);
00574 }
00575 catch (std::exception &e)
00576 {
00577 if (this->m_onException)
00578 this->m_onException (&e);
00579 }
00580 catch (...)
00581 {
00582 if (this->m_onUnhandledException)
00583 this->m_onUnhandledException ();
00584 }
00585
00586 rep->node ()->addChild (sep);
00587 }
00588 }
00589