00001
00002
00003 #include "VisReco/VisTracker/interface/VisTrackerPiRechitTwig.h"
00004 #include "VisFramework/VisFrameworkBase/interface/debug.h"
00005 #include "VisFramework/VisFrameworkBase/interface/VisTwigFactroyService.h"
00006 #include "VisFramework/VisFrameworkBase/interface/VisEventSelector.h"
00007 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
00008 #include "FWCore/Framework/interface/Event.h"
00009 #include "FWCore/Framework/interface/EventSetup.h"
00010 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00011 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00012 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00013 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00014 #include "Iguana/Inventor/interface/IgSoTower.h"
00015 #include "Iguana/Models/interface/IgTextRep.h"
00016 #include "Iguana/GLModels/interface/Ig3DRep.h"
00017 #include "Iguana/GLModels/interface/IgLegoRep.h"
00018 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00019 #include "Iguana/GLModels/interface/IgRZRep.h"
00020 #include "Iguana/Framework/interface/IgRepSet.h"
00021 #include "Iguana/Studio/interface/IgQtLock.h"
00022 #include <Inventor/nodes/SoSeparator.h>
00023 #include <Inventor/nodes/SoDrawStyle.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 return new VisTrackerPiRechitTwig (state, parent, name, friendlyName, modLabel, instanceName, processName);
00052 }
00053 }
00054
00055 VisTrackerPiRechitTwig::VisTrackerPiRechitTwig (IgState *state, IgTwig *parent,
00056 const std::string &name ,
00057 const std::string &friendlyName ,
00058 const std::string &moduleLabel ,
00059 const std::string &instanceName ,
00060 const std::string &processName )
00061 : VisQueuedTwig (state, parent, name),
00062 m_text (name),
00063 m_friendlyName (friendlyName),
00064 m_moduleLabel (moduleLabel),
00065 m_instanceName (instanceName),
00066 m_processName (processName)
00067 {
00068 VisTwigFactroyService *tfService = VisTwigFactroyService::get (state);
00069 if (! tfService)
00070 {
00071 tfService = new VisTwigFactroyService (state);
00072 }
00073 edm::TypeID pixelrechitCollID (typeid (SiPixelRecHitCollection));
00074 tfService->registerTwig (pixelrechitCollID.friendlyClassName (), &createThisTwig);
00075 }
00076
00077
00078 void
00079 VisTrackerPiRechitTwig::onNewEvent (const edm::Event &event,
00080 const edm::EventSetup &eventSetup)
00081 {
00082
00083 VisQueuedTwig::onNewEvent (event, eventSetup);
00084
00085 rtemp.clear();
00086
00087 m_text = (QString ("Run # %1, event # %2")
00088 .arg (event.id ().run ())
00089 .arg (event.id ().event ()).latin1 ());
00090
00091 std::vector< edm::Handle<SiPixelRecHitCollection> > pixelrechit_collections;
00092 try
00093 {
00094 if ((! m_friendlyName.empty ()) || (! m_moduleLabel.empty ()) || (! m_instanceName.empty ()) || (! m_processName.empty ()))
00095 {
00096 VisEventSelector visSel (m_friendlyName, m_moduleLabel, m_instanceName, m_processName);
00097 event.getMany (visSel, pixelrechit_collections);
00098 }
00099 else
00100 {
00101 event.getManyByType (pixelrechit_collections);
00102 }
00103 eventSetup.get<TrackerDigiGeometryRecord> ().get (m_pDD);
00104 }
00105 catch (cms::Exception& e)
00106 {
00107 e.append (" from VisTrackerPiRechitTwig: ");
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 if (! pixelrechit_collections.empty ())
00130 {
00131 std::vector< edm::Handle<SiPixelRecHitCollection> >::iterator i;
00132 for (i = pixelrechit_collections.begin (); i != pixelrechit_collections.end (); i++)
00133 {
00134 const SiPixelRecHitCollection&c = *(*i);
00135
00136 SiPixelRecHitCollection::id_iterator detUnitIt;
00137 for (detUnitIt = c.id_begin(); detUnitIt != c.id_end(); ++detUnitIt)
00138 {
00139 SiPixelRecHitCollection::range range = c.get((*detUnitIt));
00140 for (SiPixelRecHitCollection::const_iterator pixel_rechit = range.first; pixel_rechit!=range.second; ++pixel_rechit)
00141 {
00142 DetId detectorId = (*pixel_rechit).geographicalId();
00143 unsigned int id = detectorId.rawId();
00144
00145 DetId detIdObject(id);
00146
00147 LocalPoint position;
00148 if((*pixel_rechit).hasPositionAndError())
00149 position=(*pixel_rechit).localPosition(); else break;
00150
00151
00152
00153 int clusterCharge = 0;
00154
00155
00156
00157
00158
00159
00160
00161 std::pair<std::pair<DetId, LocalPoint>, int> pxd;
00162 pxd.first.first = detIdObject;
00163
00164 pxd.first.second = position;
00165 pxd.second =clusterCharge;
00166 rtemp.push_back(pxd);
00167 }
00168 }
00169 }
00170 }
00171 VisQueuedTwig::onBaseInvalidate ();
00172 }
00173
00174 void
00175 VisTrackerPiRechitTwig::update (IgTextRep *rep)
00176 {
00177
00178 VisQueuedTwig::update (rep);
00179
00180
00181 std::ostringstream text;
00182 text << "Total " << rtemp.size () << " Silicon Pixel rechits from";
00183 if(rtemp.size() > 100){
00184 text << " input file: printing only first 100 " << "<br>";
00185 }else text << " input file: " << m_text << "<br>";
00186
00187 text << "<table width='100%' border=1>"
00188 << "<TR align = center>"
00189 << "<TH>Number</TH>"
00190 << "<TH>GeomdetId</TH>"
00191 << "<TH>Position</TH>"
00192 << "</TR>";
00193
00194 text << setiosflags (std::ios::showpoint | std::ios::fixed);
00195 text.setf (std::ios::right, std::ios::adjustfield);
00196
00197 if ((! rtemp.empty ()) && m_pDD.isValid ())
00198 {
00199
00200 int nRecHits = 0;
00201 try
00202 {
00203 for (std::vector<std::pair<std::pair<DetId, LocalPoint>, int> >::const_iterator i = rtemp.begin (); i != rtemp.end (); ++i)
00204 {
00205 GlobalPoint pos = (m_pDD->idToDet ((*i).first.first))->surface().toGlobal((*i).first.second);
00206 text << "<TR align = right>"
00207 << "<TD>" << std::setw (3) << nRecHits++ << "</TD>"
00208 << "<TD>" << std::setw (11) << ((*i).first.first).rawId()<< "</TD>"
00209 << "<TD>" << pos.x()/100 << ", " << pos.y()/100 << ", " << pos.z()/100 << "</TD>";
00210 if (nRecHits>100) break;
00211 }
00212 }
00213 catch (cms::Exception& e)
00214 {
00215 e.append (" from VisTrackerPiRechitTwig: ");
00216 e.append (this->name ());
00217
00218 if (this->m_onCmsException)
00219 this->m_onCmsException (&e);
00220 }
00221 catch (lat::Error &e)
00222 {
00223 if (this->m_onError)
00224 this->m_onError (&e);
00225 }
00226 catch (std::exception &e)
00227 {
00228 if (this->m_onException)
00229 this->m_onException (&e);
00230 }
00231 catch (...)
00232 {
00233 if (this->m_onUnhandledException)
00234 this->m_onUnhandledException ();
00235 }
00236 text << "</table>";
00237 }
00238
00239
00240 IgQtLock ();
00241 rep->setText (text.str ());
00242 }
00243
00244
00245 void
00246 VisTrackerPiRechitTwig::update (Ig3DRep *rep)
00247 {
00248
00249 VisQueuedTwig::update (rep);
00250 IgQtLock ();
00251 rep->clear ();
00252
00253 if (!rtemp.empty())
00254 {
00255 SoMaterial *mat = new SoMaterial;
00256 mat->diffuseColor.setValue (1.0, 0.0, 0.0);
00257 mat->emissiveColor.setValue(1.0, 0.0, 0.0);
00258
00259 SoDrawStyle *drawStyle = new SoDrawStyle;
00260 drawStyle->pointSize = 4.0;
00261
00262 SoSeparator *sep = new SoSeparator;
00263 sep->addChild (mat);
00264 sep->addChild (drawStyle);
00265
00266 try
00267 {
00268 SoVertexProperty *vertices = new SoVertexProperty;
00269 int nVrtx = 0;
00270
00271 for (std::vector<std::pair<std::pair<DetId, LocalPoint>, int> >::const_iterator
00272 i = rtemp.begin (); i != rtemp.end (); ++i)
00273 {
00274 GlobalPoint pos = (m_pDD->idToDet ((*i).first.first))->surface().toGlobal((*i).first.second);
00275 float x = pos.x () / 100.0;
00276 float y = pos.y () / 100.0;
00277 float z = pos.z () / 100.0;
00278
00279 vertices->vertex.set1Value (nVrtx++, SbVec3f (x, y, z));
00280 }
00281
00282 vertices->vertex.setNum (nVrtx);
00283 SoPointSet *points = new SoPointSet;
00284 points->vertexProperty.setValue (vertices);
00285 points->numPoints.setValue (nVrtx);
00286
00287 sep->addChild (points);
00288 }
00289 catch (cms::Exception& e)
00290 {
00291 e.append (" from VisTrackerPiRechitTwig: ");
00292 e.append (this->name ());
00293
00294 if (this->m_onCmsException)
00295 this->m_onCmsException (&e);
00296 }
00297 catch (lat::Error &e)
00298 {
00299 if (this->m_onError)
00300 this->m_onError (&e);
00301 }
00302 catch (std::exception &e)
00303 {
00304 if (this->m_onException)
00305 this->m_onException (&e);
00306 }
00307 catch (...)
00308 {
00309 if (this->m_onUnhandledException)
00310 this->m_onUnhandledException ();
00311 }
00312 rep->node ()->addChild (sep);
00313 }
00314 }
00315
00316 void
00317 VisTrackerPiRechitTwig::update (IgLegoRep *rep)
00318 {
00319
00320 VisQueuedTwig::update (rep);
00321
00322 IgQtLock ();
00323 rep->clear ();
00324
00325 SoSeparator *sep = new SoSeparator;
00326
00327 try
00328 {
00329 for (std::vector<std::pair<std::pair<DetId, LocalPoint>, int> >::const_iterator i = rtemp.begin (); i != rtemp.end (); ++i)
00330 {
00331 GlobalPoint pos = (m_pDD->idToDet ((*i).first.first))->surface().toGlobal((*i).first.second);
00332
00333 double eta = pos.eta ();
00334 double phi = pos.phi ();
00335 if (phi < 0.0) phi = 2 * M_PI + phi;
00336
00337 int recCharge =(*i).second;
00338
00339 IgSoTower *tower = new IgSoTower;
00340 tower->position = SbVec2f (phi, eta);
00341 tower->scaleFactor = 20.0;
00342 tower->energy = recCharge;
00343 sep->addChild (tower);
00344 }
00345 }
00346 catch (cms::Exception& e)
00347 {
00348 e.append (" from VisTrackerPiRechitTwig: ");
00349 e.append (this->name ());
00350
00351 if (this->m_onCmsException)
00352 this->m_onCmsException (&e);
00353 }
00354 catch (lat::Error &e)
00355 {
00356 if (this->m_onError)
00357 this->m_onError (&e);
00358 }
00359 catch (std::exception &e)
00360 {
00361 if (this->m_onException)
00362 this->m_onException (&e);
00363 }
00364 catch (...)
00365 {
00366 if (this->m_onUnhandledException)
00367 this->m_onUnhandledException ();
00368 }
00369 rep->node ()->addChild (sep);
00370 }
00371
00372
00373 void
00374 VisTrackerPiRechitTwig::update (IgRPhiRep *rep)
00375 {
00376
00377 VisQueuedTwig::update (rep);
00378
00379 IgQtLock ();
00380 rep->clear ();
00381
00382 if (! rtemp.empty ())
00383 {
00384 SoSeparator *sep = new SoSeparator;
00385
00386 SoMaterial *mat = new SoMaterial;
00387 mat->diffuseColor.setValue (1.0, 0.0, 0.0);
00388 sep->addChild (mat);
00389
00390 SoDrawStyle *drawStyle = new SoDrawStyle;
00391 drawStyle->pointSize = 4.0;
00392 sep->addChild (drawStyle);
00393
00394 try
00395 {
00396 SoVertexProperty *vertices = new SoVertexProperty;
00397 int nVrtx = 0;
00398 for (std::vector<std::pair<std::pair<DetId, LocalPoint>, int> >::const_iterator i = rtemp.begin (); i != rtemp.end (); ++i)
00399 {
00400 GlobalPoint pos = (m_pDD->idToDet ((*i).first.first))->surface().toGlobal((*i).first.second);
00401 float x = pos.x () / 100.0;
00402 float y = pos.y () / 100.0;
00403 float z = pos.z () / 100.0;
00404
00405 vertices->vertex.set1Value (nVrtx++, SbVec3f (x, y, z));
00406 }
00407
00408 vertices->vertex.setNum (nVrtx);
00409 SoPointSet *points = new SoPointSet;
00410 points->vertexProperty.setValue (vertices);
00411 points->numPoints.setValue (nVrtx);
00412
00413 sep->addChild (points);
00414 }
00415 catch (cms::Exception& e)
00416 {
00417 e.append (" from VisTrackerPiRechitTwig: ");
00418 e.append (this->name ());
00419
00420 if (this->m_onCmsException)
00421 this->m_onCmsException (&e);
00422 }
00423 catch (lat::Error &e)
00424 {
00425 if (this->m_onError)
00426 this->m_onError (&e);
00427 }
00428 catch (std::exception &e)
00429 {
00430 if (this->m_onException)
00431 this->m_onException (&e);
00432 }
00433 catch (...)
00434 {
00435 if (this->m_onUnhandledException)
00436 this->m_onUnhandledException ();
00437 }
00438 rep->node ()->addChild (sep);
00439 }
00440 }
00441
00442
00443 void
00444 VisTrackerPiRechitTwig::update (IgRZRep *rep)
00445 {
00446
00447 VisQueuedTwig::update (rep);
00448
00449 IgQtLock ();
00450 rep->clear ();
00451
00452 if (! rtemp.empty ())
00453 {
00454 SoSeparator *sep = new SoSeparator;
00455 SoMaterial *mat = new SoMaterial;
00456 mat->diffuseColor.setValue (1.0, 0.0, 0.0);
00457 sep->addChild (mat);
00458
00459 SoDrawStyle *drawStyle = new SoDrawStyle;
00460 drawStyle->pointSize = 3.0;
00461 sep->addChild (drawStyle);
00462
00463 try
00464 {
00465 SoVertexProperty *vertices = new SoVertexProperty;
00466 int nVrx = 0;
00467
00468 for (std::vector<std::pair<std::pair<DetId, LocalPoint>,int> >::const_iterator i = rtemp.begin (); i != rtemp.end (); ++i)
00469 {
00470 GlobalPoint pos = (m_pDD->idToDet ((*i).first.first))->surface().toGlobal((*i).first.second);
00471 float x = 0.0;
00472 float y = sqrt(pos.x ()*pos.x()+pos.y()*pos.y()) / 100.0; if(pos.y()< 0. )y = - y;
00473 float z = pos.z () / 100.0;
00474
00475 vertices->vertex.set1Value (nVrx++, SbVec3f (x, y, z));
00476 }
00477
00478 vertices->vertex.setNum (rtemp.size());
00479
00480 SoPointSet *points = new SoPointSet;
00481 points->vertexProperty.setValue (vertices);
00482 points->numPoints.setValue (rtemp.size());
00483 sep->addChild (points);
00484 }
00485 catch (cms::Exception& e)
00486 {
00487 e.append (" from VisTrackerPiRechitTwig: ");
00488 e.append (this->name ());
00489
00490 if (this->m_onCmsException)
00491 this->m_onCmsException (&e);
00492 }
00493 catch (lat::Error &e)
00494 {
00495 if (this->m_onError)
00496 this->m_onError (&e);
00497 }
00498 catch (std::exception &e)
00499 {
00500 if (this->m_onException)
00501 this->m_onException (&e);
00502 }
00503 catch (...)
00504 {
00505 if (this->m_onUnhandledException)
00506 this->m_onUnhandledException ();
00507 }
00508 rep->node ()->addChild (sep);
00509 }
00510 }
00511