00001
00002
00003 #include "VisReco/VisMuonCSC/interface/VisCSCComparatorDigiTwig.h"
00004 #include "VisReco/VisMuonCSC/interface/VisCSCChamberDrawer.h"
00005 #include "VisFramework/VisFrameworkBase/interface/VisTwigFactroyService.h"
00006 #include "VisFramework/VisFrameworkBase/interface/VisEventSelector.h"
00007 #include "VisFramework/VisFrameworkBase/interface/debug.h"
00008 #include "DataFormats/CSCDigi/interface/CSCComparatorDigi.h"
00009 #include "DataFormats/CSCDigi/interface/CSCComparatorDigiCollection.h"
00010 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "FWCore/Framework/interface/EventSetup.h"
00013 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00014 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00015 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00016
00017 #include "Geometry/CSCGeometry/interface/CSCLayer.h"
00018 #include "Geometry/CSCGeometry/interface/CSCLayerGeometry.h"
00019 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00020
00021 #include "Iguana/Models/interface/IgTextRep.h"
00022 #include "Iguana/GLModels/interface/Ig3DRep.h"
00023 #include "Iguana/GLModels/interface/IgLegoRep.h"
00024 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00025 #include "Iguana/GLModels/interface/IgRZRep.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 VisCSCComparatorDigiTwig (state, parent, "Comparator digis (" + name + ")",
00063 friendlyName, modLabel, instanceName, processName);
00064 }
00065 }
00066
00067
00068
00069
00070 VisCSCComparatorDigiTwig::VisCSCComparatorDigiTwig (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 (CSCComparatorDigiCollection));
00089 tfService->registerTwig (caloJetsID.friendlyClassName (), &createThisTwig);
00090 }
00091
00092 void
00093 VisCSCComparatorDigiTwig::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<CSCComparatorDigiCollection> > 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<CSCComparatorDigiCollection> >::iterator i;
00144 std::vector<edm::Handle<CSCComparatorDigiCollection> >::iterator iEnd;
00145 for (i = digiCollections.begin (), iEnd = digiCollections.end (); i != iEnd; ++i)
00146 {
00147 const CSCComparatorDigiCollection& c = *(*i);
00148
00149
00150 CSCComparatorDigiCollection::DigiRangeIterator detUnitIt;
00151 CSCComparatorDigiCollection::DigiRangeIterator detUnitItEnd;
00152 for (detUnitIt = c.begin (), detUnitItEnd = c.end (); detUnitIt != detUnitItEnd; ++detUnitIt)
00153 {
00154 const CSCDetId &id = (*detUnitIt).first;
00155 const CSCComparatorDigiCollection::Range &range = (*detUnitIt).second;
00156
00157
00158 for (CSCComparatorDigiCollection::const_iterator digiIt = range.first;
00159 digiIt != range.second;
00160 ++digiIt)
00161 {
00162 std::pair< CSCDetId, CSCComparatorDigi > 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 VisCSCComparatorDigiTwig::update (IgTextRep *rep)
00177 {
00178
00179 VisQueuedTwig::update (rep);
00180
00181
00182 std::ostringstream text;
00183 text << "Total " << m_digis.size () << " CSC strip 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>Strip</TH>"
00190 << "<TH>Comparator</TH>"
00191 << "<TH>Time bin</TH>"
00192 << "</TR>";
00193 text << setiosflags (std::ios::showpoint | std::ios::fixed);
00194 text.setf (std::ios::right, std::ios::adjustfield);
00195
00196 if ((! m_digis.empty ()) && m_pDD.isValid ())
00197 {
00198 int nDigis = 0;
00199 try
00200 {
00201 for (std::vector<std::pair<CSCDetId, CSCComparatorDigi> >::const_iterator i = m_digis.begin (), iEnd = m_digis.end (); i != iEnd; ++i)
00202 {
00203 Surface::GlobalPoint pos = (m_pDD->idToDet ((*i).first))->surface ().position ();
00204 text << "<TR align = right>"
00205 << "<TD>" << std::setw (3) << ++nDigis << "</TD>"
00206 << "<TD>" << pos.x () << ", " << pos.y () << ", " << pos.z () << "</TD>"
00207 << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.getStrip () << "</TD>"
00208 << "<TD>" << std::setw (6) << std::setprecision (3) << (*i).second.getComparator () << "</TD>"
00209 << "<TD>" << std::setw (5) << std::setprecision (3) << (*i).second.getTimeBin () << "</TD></TR>";
00210 }
00211 }
00212 catch (cms::Exception& e)
00213 {
00214 if (this->m_onCmsException)
00215 this->m_onCmsException (&e);
00216 }
00217 catch (lat::Error &e)
00218 {
00219 if (this->m_onError)
00220 this->m_onError (&e);
00221 }
00222 catch (std::exception &e)
00223 {
00224 if (this->m_onException)
00225 this->m_onException (&e);
00226 }
00227 catch (...)
00228 {
00229 if (this->m_onUnhandledException)
00230 this->m_onUnhandledException ();
00231 }
00232 text << "</table>";
00233 }
00234
00235
00236 IgQtLock ();
00237 rep->setText (text.str ());
00238 }
00239
00240 void
00241 VisCSCComparatorDigiTwig::update (Ig3DRep *rep)
00242 {
00243
00244 VisQueuedTwig::update (rep);
00245
00246 IgQtLock ();
00247 rep->clear ();
00248 m_dets.clear ();
00249
00250 if (! m_digis.empty () && m_pDD.isValid ())
00251 {
00252 VisCSCChamberDrawer d;
00253
00254 const float width = 0.01;
00255 const float depth = 0.01;
00256
00257
00258 SbColor grey35;
00259 float transparency = 0.0f;
00260 grey35.setPackedValue(static_cast<uint32_t>(0x00595959), transparency);
00261 SoMaterial *mat = new SoMaterial;
00262 mat->diffuseColor.setValue (grey35);
00263 mat->emissiveColor.setValue(grey35);
00264
00265 SoDrawStyle *drawStyle = new SoDrawStyle;
00266 drawStyle->pointSize = 5.0;
00267
00268 SoSeparator *sep = new SoSeparator;
00269 sep->addChild (mat);
00270 sep->addChild (drawStyle);
00271
00272 try
00273 {
00274 SoMaterial *matl = new SoMaterial;
00275 matl->diffuseColor.setValue (0.1, 1.0, 0.4);
00276 matl->emissiveColor.setValue(0.1, 1.0, 0.4);
00277 matl->shininess = 1.;
00278
00279 SoDrawStyle *drawStylel = new SoDrawStyle;
00280 drawStylel->pointSize = 1.;
00281
00282 SoSeparator *pulses = new SoSeparator;
00283 pulses->addChild (matl);
00284 pulses->addChild (drawStylel);
00285
00286 for (std::vector<std::pair<CSCDetId, CSCComparatorDigi> >::const_iterator
00287 i = m_digis.begin (), iEnd = m_digis.end (); i != iEnd; ++i)
00288 {
00289 const CSCDetId& id = (*i).first;
00290
00291 if (m_dets.find(id) == m_dets.end() )
00292 {
00293 m_dets.insert(id);
00294
00295 d.getOutline(sep, m_pDD, id);
00296 }
00297 int strip_id = ((*i).second).getStrip ();
00298 const CSCLayer* layer_p = m_pDD->layer (id);
00299 const CSCLayerGeometry* layerGeom = layer_p->geometry ();;
00300 float xstrip = layerGeom->xOfStrip (strip_id);
00301 Surface::GlobalPoint pos = (m_pDD->idToDet (id))->surface ().toGlobal
00302 (LocalPoint (xstrip, 0., 1.));
00303
00304 float x = pos.x () / 100.0;
00305 float y = pos.y () / 100.0;
00306 float z = pos.z () / 100.0;
00307
00308 SoTranslation *inc = new SoTranslation;
00309 inc->translation = SbVec3f (x,y,z);
00310
00311 SbVec3f axis (0., 0., 1.);
00312 float angle = -atan (x / y);
00313 SbRotation r (axis, angle);
00314
00315 SoTransform *xform = new SoTransform;
00316 xform->rotation = r;
00317
00318 layerGeom = layer_p->geometry ();
00319 SoCube *hit = new SoCube;
00320 hit->width = width;
00321 hit->height = layerGeom->length () / 100.;
00322 hit->depth = depth;
00323
00324 SoSeparator *pulse = new SoSeparator;
00325 pulse->addChild (inc);
00326 pulse->addChild (xform);
00327 pulse->addChild (hit);
00328 pulses->addChild (pulse);
00329
00330 sep->addChild (pulses);
00331 }
00332 }
00333 catch (cms::Exception& e)
00334 {
00335 if (this->m_onCmsException)
00336 this->m_onCmsException (&e);
00337 }
00338 catch (lat::Error &e)
00339 {
00340 if (this->m_onError)
00341 this->m_onError (&e);
00342 }
00343 catch (std::exception &e)
00344 {
00345 if (this->m_onException)
00346 this->m_onException (&e);
00347 }
00348 catch (...)
00349 {
00350 if (this->m_onUnhandledException)
00351 this->m_onUnhandledException ();
00352 }
00353
00354 rep->node ()->addChild (sep);
00355 }
00356 }
00357
00358 void
00359 VisCSCComparatorDigiTwig::update (IgLegoRep *rep)
00360 {
00361
00362 VisQueuedTwig::update (rep);
00363
00364 IgQtLock ();
00365 rep->clear ();
00366
00367 SoSeparator *sep = new SoSeparator;
00368 SoSeparator *posSep = new SoSeparator;
00369 SoSeparator *negSep = new SoSeparator;
00370
00371 SoMaterial *mat = new SoMaterial;
00372 mat->diffuseColor.setValue (0.3, 0.8, 0.0);
00373 posSep->addChild (mat);
00374
00375 SoMaterial *negMat = new SoMaterial;
00376 negMat->diffuseColor.setValue (1.0, 0.0, 0.0);
00377 negSep->addChild (negMat);
00378
00379 sep->addChild (posSep);
00380 sep->addChild (negSep);
00381
00382 try
00383 {
00384 int n = 0;
00385
00386 for (std::vector<std::pair<CSCDetId, CSCComparatorDigi> >::const_iterator i = m_digis.begin (), iEnd = m_digis.end ();
00387 i != iEnd; ++i)
00388 {
00389 Surface::GlobalPoint pos = (m_pDD->idToDet ((*i).first))->surface ().position ();
00390
00391 double phi = pos.phi ();
00392 if (phi < 0.0) phi = 2 * M_PI + phi;
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405 ++n;
00406 }
00407 }
00408 catch (cms::Exception& e)
00409 {
00410 if (this->m_onCmsException)
00411 this->m_onCmsException (&e);
00412 }
00413 catch (lat::Error &e)
00414 {
00415 if (this->m_onError)
00416 this->m_onError (&e);
00417 }
00418 catch (std::exception &e)
00419 {
00420 if (this->m_onException)
00421 this->m_onException (&e);
00422 }
00423 catch (...)
00424 {
00425 if (this->m_onUnhandledException)
00426 this->m_onUnhandledException ();
00427 }
00428
00429 rep->node ()->addChild (sep);
00430 }
00431
00432 void
00433 VisCSCComparatorDigiTwig::update (IgRPhiRep *rep)
00434 {
00435
00436 VisQueuedTwig::update (rep);
00437
00438 IgQtLock ();
00439 rep->clear ();
00440
00441 if (! m_digis.empty ())
00442 {
00443 SoSeparator *sep = new SoSeparator;
00444
00445 SoMaterial *mat = new SoMaterial;
00446 mat->diffuseColor.setValue (0.3, 0.8, 0.0);
00447 sep->addChild (mat);
00448
00449 rep->node ()->addChild (sep);
00450 }
00451 }
00452
00453 void
00454 VisCSCComparatorDigiTwig::update (IgRZRep *rep)
00455 {
00456
00457 VisQueuedTwig::update (rep);
00458
00459 IgQtLock ();
00460 rep->clear ();
00461
00462 if (! m_digis.empty () && m_pDD.isValid ())
00463 {
00464 SoSeparator *sep = new SoSeparator;
00465 SoMaterial *mat = new SoMaterial;
00466 mat->diffuseColor.setValue (0.3, 0.8, 0.0);
00467 sep->addChild (mat);
00468
00469 SoDrawStyle *drawStyle = new SoDrawStyle;
00470 drawStyle->pointSize = 3.0;
00471 sep->addChild (drawStyle);
00472
00473 try
00474 {
00475 SoVertexProperty *vertices = new SoVertexProperty;
00476 int nVrx = 0;
00477
00478 for (std::vector<std::pair<CSCDetId, CSCComparatorDigi> >::const_iterator i = m_digis.begin (), iEnd = m_digis.end ();
00479 i != iEnd; ++i)
00480 {
00481 Surface::GlobalPoint pos = (m_pDD->idToDet ((*i).first))->surface ().position ();
00482
00483
00484
00485 float x = pos.x () / 100.0;
00486 float y = pos.y () / 100.0;
00487 float z = pos.z () / 100.0;
00488
00489 vertices->vertex.set1Value (nVrx++, SbVec3f (x, y, z));
00490 }
00491 vertices->vertex.setNum (m_digis.size ());
00492
00493 SoPointSet *points = new SoPointSet;
00494 points->vertexProperty.setValue (vertices);
00495 points->numPoints.setValue (m_digis.size ());
00496 sep->addChild (points);
00497 }
00498 catch (cms::Exception& e)
00499 {
00500 if (this->m_onCmsException)
00501 this->m_onCmsException (&e);
00502 }
00503 catch (lat::Error &e)
00504 {
00505 if (this->m_onError)
00506 this->m_onError (&e);
00507 }
00508 catch (std::exception &e)
00509 {
00510 if (this->m_onException)
00511 this->m_onException (&e);
00512 }
00513 catch (...)
00514 {
00515 if (this->m_onUnhandledException)
00516 this->m_onUnhandledException ();
00517 }
00518
00519 rep->node ()->addChild (sep);
00520 }
00521 }