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