00001 #include "VisReco/VisPF/interface/VisTrackingParticleTwig.h"
00002
00003 #include "VisFramework/VisFrameworkBase/interface/VisTwigFactroyService.h"
00004 #include "VisFramework/VisFrameworkBase/interface/VisEventSelector.h"
00005
00006 #include "FWCore/Framework/interface/Event.h"
00007 #include "FWCore/Framework/interface/EventSetup.h"
00008
00009 #include "Iguana/Models/interface/IgTextRep.h"
00010 #include "Iguana/GLModels/interface/Ig3DRep.h"
00011 #include "Iguana/GLModels/interface/IgLegoRep.h"
00012 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00013 #include "Iguana/GLModels/interface/IgRZRep.h"
00014 #include "Iguana/Framework/interface/IgRepSet.h"
00015
00016 #include "Iguana/Inventor/interface/IgSbColorMap.h"
00017 #include "Iguana/Inventor/interface/IgSoArrow.h"
00018 #include "Iguana/Inventor/interface/IgSoSimpleTrajectory.h"
00019 #include "Iguana/Inventor/interface/IgSoIdealTrack.h"
00020 #include "Iguana/Inventor/interface/IgParticleChar.h"
00021
00022 #include "Iguana/Studio/interface/IgDocumentData.h"
00023 #include "Iguana/Studio/interface/IgQtLock.h"
00024
00025 #include <Inventor/nodes/SoMaterial.h>
00026 #include <Inventor/nodes/SoSeparator.h>
00027
00028 #include <qstring.h>
00029 #include <classlib/utils/DebugAids.h>
00030 #include <algorithm>
00031 #include <iostream>
00032 #include <iomanip>
00033
00034 namespace
00035 {
00036 VisQueuedTwig* createThisTwig(IgState *state, IgTwig *parent,
00037 const std::string &name,
00038 const std::string &friendlyName,
00039 const std::string &modLabel,
00040 const std::string &instanceName,
00041 const std::string &processName)
00042 {
00043 return new VisTrackingParticleTwig(state, parent, name, friendlyName, modLabel, instanceName, processName);
00044 }
00045 }
00046
00047 VisTrackingParticleTwig::VisTrackingParticleTwig(IgState *state, IgTwig *parent,
00048 const std::string &name,
00049 const std::string &friendlyName,
00050 const std::string &moduleLabel,
00051 const std::string &instanceName,
00052 const std::string &processName)
00053 : VisQueuedTwig(state, parent, name),
00054 m_text("No Info"),
00055 m_name(name),
00056 m_friendlyName(friendlyName),
00057 m_moduleLabel(moduleLabel),
00058 m_instanceName(instanceName),
00059 m_processName(processName)
00060 {
00061 VisTwigFactroyService *tfService = VisTwigFactroyService::get(state);
00062
00063 if (! tfService)
00064 {
00065 tfService = new VisTwigFactroyService(state);
00066 }
00067
00068 edm::TypeID pfTracksID(typeid(TrackingParticleCollection));
00069
00070 tfService->registerTwig(pfTracksID.friendlyClassName(), &createThisTwig);
00071 }
00072
00073 void VisTrackingParticleTwig::onNewEvent(const edm::Event &event,
00074 const edm::EventSetup &eventSetup)
00075 {
00076 VisQueuedTwig::onNewEvent(event, eventSetup);
00077
00078 std::vector<edm::Handle<TrackingParticleCollection> > trackCollections;
00079
00080
00081 m_tracks.clear();
00082
00083 try
00084 {
00085 if ( (! m_friendlyName.empty ()) ||
00086 (! m_moduleLabel.empty ()) ||
00087 (! m_instanceName.empty ()) ||
00088 (! m_processName.empty ()) )
00089 {
00090 VisEventSelector visSel(m_friendlyName, m_moduleLabel,
00091 m_instanceName, m_processName);
00092
00093 event.getMany(visSel, trackCollections);
00094 }
00095
00096 else
00097 {
00098 event.getManyByType(trackCollections);
00099 }
00100
00101
00102 }
00103
00104 catch (cms::Exception& e)
00105 {
00106 if (this->m_onCmsException)
00107 this->m_onCmsException(&e);
00108 }
00109
00110 catch (lat::Error &e)
00111 {
00112 if (this->m_onError)
00113 this->m_onError(&e);
00114 }
00115
00116 catch (std::exception &e)
00117 {
00118 if (this->m_onException)
00119 this->m_onException(&e);
00120 }
00121
00122 catch (...)
00123 {
00124 if (this->m_onUnhandledException)
00125 this->m_onUnhandledException();
00126 }
00127
00128 if (! trackCollections.empty())
00129 {
00130 for ( std::vector<edm::Handle<TrackingParticleCollection> >::iterator i = trackCollections.begin();
00131 i != trackCollections.end(); ++i )
00132 {
00133 const TrackingParticleCollection& c = *(*i);
00134
00135 for ( std::vector<TrackingParticle>::const_iterator itp = c.begin();
00136 itp != c.end(); ++itp )
00137 {
00138 double x = (*itp).parentVertex()->position().x()/100.0;
00139 double y = (*itp).parentVertex()->position().y()/100.0;
00140 double z = (*itp).parentVertex()->position().z()/100.0;
00141
00142 if ( (*itp).pt() > 1.0 )
00143 {
00144 std::pair<TrackingParticle, SbVec3f> p((*itp), SbVec3f(x,y,z));
00145 m_tracks.push_back(p);
00146 }
00147 }
00148 }
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 VisQueuedTwig::onBaseInvalidate();
00171 }
00172
00173 void VisTrackingParticleTwig::update(Ig3DRep *rep)
00174 {
00175 VisQueuedTwig::update(rep);
00176 IgQtLock();
00177 rep->clear();
00178
00179 if ( ! m_tracks.empty () )
00180 {
00181 SoSeparator *sep = new SoSeparator;
00182
00183 try
00184 {
00185 std::vector<std::pair<TrackingParticle, SbVec3f> >::const_iterator i;
00186
00187 for ( i = m_tracks.begin(); i != m_tracks.end(); ++i )
00188 {
00189
00190
00191
00192
00193
00194
00195
00196
00197 IgSoIdealTrack *kit = new IgSoIdealTrack;
00198
00199 float pt = i->first.pt();
00200
00201 double x0 = (i->second)[0];
00202 double y0 = (i->second)[1];
00203 double z0 = (i->second)[2];
00204
00205 double px = i->first.px();
00206 double py = i->first.py();
00207 double pz = i->first.pz();
00208
00209 switch (i->first.pdgId())
00210 {
00211 case 11:
00212 kit->initialise (x0, y0, z0, px, py, pz,
00213 0.0, IgParticleChar::getByName ("electron"));
00214 sep->addChild (kit);
00215 break;
00216
00217 case -11:
00218 kit->initialise (x0, y0, z0, px, py, pz,
00219 0.0, IgParticleChar::getByName ("positron"));
00220 sep->addChild (kit);
00221 break;
00222
00223 case 211:
00224 kit->initialise(x0, y0, z0, px, py, pz,
00225 0.0, IgParticleChar::getByName ("antipion"));
00226 sep->addChild(kit);
00227 break;
00228 case -211:
00229 kit->initialise(x0, y0, z0, px, py, pz,
00230 0.0, IgParticleChar::getByName ("pion"));
00231 sep->addChild (kit);
00232 break;
00233
00234 case 22:
00235 {
00236 SoSeparator *gammas = new SoSeparator;
00237 SoMaterial *gammaMaterial = new SoMaterial;
00238 gammaMaterial->ambientColor.setValue (0.000, 0.000, 0.000);
00239 gammaMaterial->diffuseColor.setValue (1.000, 1.000, 0.000);
00240 gammaMaterial->emissiveColor.setValue (1.000, 1.000, 0.000);
00241 gammaMaterial->specularColor.setValue (0.000, 0.000, 0.000);
00242 gammaMaterial->shininess = 0.0;
00243 gammaMaterial->transparency = 0.0;
00244 gammas->addChild (gammaMaterial);
00245
00246 IgSoSimpleTrajectory *track = new IgSoSimpleTrajectory;
00247
00248 track->controlPoints.set1Value (0, SbVec3f (x0, y0, z0));
00249 track->markerPoints.set1Value (0, SbVec3f (x0, y0, z0));
00250
00251 double x = x0;
00252 double y = y0;
00253 double z = z0;
00254
00255 do
00256 {
00257 x += 0.1*px;
00258 y += 0.1*py;
00259 z += 0.1*pz;
00260 }
00261 while ( sqrt(x*x+y*y) < 1.24 && fabs(z) < 3.14 );
00262
00263 SbVec3f pos = SbVec3f(x,y,z);
00264
00265 track->controlPoints.set1Value (1, pos);
00266 track->markerPoints.set1Value (1, pos);
00267 gammas->addChild (track);
00268
00269 sep->addChild (gammas);
00270
00271 break;
00272 }
00273
00274
00275 default:
00276 break;
00277 }
00278 }
00279 }
00280
00281 catch (cms::Exception& e)
00282 {
00283 if (this->m_onCmsException)
00284 this->m_onCmsException (&e);
00285 }
00286 catch (lat::Error &e)
00287 {
00288 if (this->m_onError)
00289 this->m_onError (&e);
00290 }
00291 catch (std::exception &e)
00292 {
00293 if (this->m_onException)
00294 this->m_onException (&e);
00295 }
00296 catch (...)
00297 {
00298 if (this->m_onUnhandledException)
00299 this->m_onUnhandledException ();
00300 }
00301
00302 rep->node ()->addChild (sep);
00303 }
00304
00305
00306 }
00307
00308 void VisTrackingParticleTwig::update(IgLegoRep *rep)
00309 {
00310 VisQueuedTwig::update(rep);
00311 }
00312
00313 void VisTrackingParticleTwig::update(IgTextRep *rep)
00314 {
00315 VisQueuedTwig::update(rep);
00316
00317 std::ostringstream text;
00318 text<< m_tracks.size() <<" TrackingParticles";
00319
00320 text << "<table width='100%' border=1>"
00321 << "<TR align = center>"
00322 << "<TH>Number</TH>"
00323 << "<TH>P<SUB>T</TH>"
00324 << "<TH>PDG Code</TH>"
00325 << "</TR>";
00326
00327 text << setiosflags (std::ios::showpoint | std::ios::fixed);
00328 text.setf (std::ios::right, std::ios::adjustfield);
00329
00330 if (! m_tracks.empty())
00331 {
00332 int nTracks = 0;
00333
00334 try
00335 {
00336 std::vector<std::pair<TrackingParticle, SbVec3f> >::const_iterator i;
00337
00338 for ( i = m_tracks.begin(); i != m_tracks.end(); ++i )
00339 {
00340 text << "<TR align = right>"
00341 << "<TD>" << std::setw (3) << nTracks++ << "</TD>"
00342 << "<TD>" << std::setw (3) << i->first.pt() << "</TD>"
00343 << "<TD>" << std::setw (3) << i->first.pdgId() << "</TD></TR>";
00344
00345 }
00346 }
00347 catch (cms::Exception& e)
00348 {
00349 if (this->m_onCmsException)
00350 this->m_onCmsException (&e);
00351 }
00352 catch (lat::Error &e)
00353 {
00354 if (this->m_onError)
00355 this->m_onError (&e);
00356 }
00357 catch (std::exception &e)
00358 {
00359 if (this->m_onException)
00360 this->m_onException (&e);
00361 }
00362 catch (...)
00363 {
00364 if (this->m_onUnhandledException)
00365 this->m_onUnhandledException ();
00366 }
00367 }
00368 text << "</table>";
00369
00370
00371 IgQtLock();
00372 rep->setText(text.str());
00373 }
00374
00375 void VisTrackingParticleTwig::update(IgRPhiRep *rep)
00376 {
00377 VisQueuedTwig::update (rep);
00378
00379 IgQtLock ();
00380 rep->clear ();
00381
00382 if ( ! m_tracks.empty () )
00383 {
00384 SoSeparator *sep = new SoSeparator;
00385
00386 try
00387 {
00388 std::vector<std::pair<TrackingParticle, SbVec3f> >::const_iterator i;
00389
00390 for ( i = m_tracks.begin(); i != m_tracks.end(); ++i )
00391 {
00392
00393 IgSoIdealTrack *kit = new IgSoIdealTrack;
00394
00395 float pt = i->first.pt();
00396
00397 double x0 = (i->second)[0];
00398 double y0 = (i->second)[1];
00399 double z0 = (i->second)[2];
00400
00401 double px = i->first.px();
00402 double py = i->first.py();
00403 double pz = i->first.pz();
00404
00405 switch (i->first.pdgId())
00406 {
00407 case 11:
00408 kit->initialise (x0, y0, z0, px, py, pz,
00409 0.0, IgParticleChar::getByName ("electron"));
00410 sep->addChild (kit);
00411 break;
00412
00413 case -11:
00414 kit->initialise (x0, y0, z0, px, py, pz,
00415 0.0, IgParticleChar::getByName ("positron"));
00416 sep->addChild (kit);
00417 break;
00418
00419 case 211:
00420 kit->initialise(x0, y0, z0, px, py, pz,
00421 0.0, IgParticleChar::getByName ("antipion"));
00422 sep->addChild(kit);
00423 break;
00424 case -211:
00425 kit->initialise(x0, y0, z0, px, py, pz,
00426 0.0, IgParticleChar::getByName ("pion"));
00427 sep->addChild (kit);
00428 break;
00429
00430 case 22:
00431 {
00432 SoSeparator *gammas = new SoSeparator;
00433 SoMaterial *gammaMaterial = new SoMaterial;
00434 gammaMaterial->ambientColor.setValue (0.000, 0.000, 0.000);
00435 gammaMaterial->diffuseColor.setValue (1.000, 1.000, 0.000);
00436 gammaMaterial->emissiveColor.setValue (1.000, 1.000, 0.000);
00437 gammaMaterial->specularColor.setValue (0.000, 0.000, 0.000);
00438 gammaMaterial->shininess = 0.0;
00439 gammaMaterial->transparency = 0.0;
00440 gammas->addChild (gammaMaterial);
00441
00442 IgSoSimpleTrajectory *track = new IgSoSimpleTrajectory;
00443
00444 track->controlPoints.set1Value (0, SbVec3f (x0, y0, z0));
00445 track->markerPoints.set1Value (0, SbVec3f (x0, y0, z0));
00446
00447 double x = x0;
00448 double y = y0;
00449 double z = z0;
00450
00451 do
00452 {
00453 x += 0.1*px;
00454 y += 0.1*py;
00455 z += 0.1*pz;
00456 }
00457 while ( sqrt(x*x+y*y) < 1.24 && fabs(z) < 3.14 );
00458
00459
00460 SbVec3f pos = SbVec3f(x,y,z);
00461
00462 track->controlPoints.set1Value (1, pos);
00463 track->markerPoints.set1Value (1, pos);
00464 gammas->addChild (track);
00465
00466 sep->addChild (gammas);
00467
00468 break;
00469
00470 }
00471
00472
00473 default:
00474 break;
00475 }
00476 }
00477 }
00478
00479 catch (cms::Exception& e)
00480 {
00481 if (this->m_onCmsException)
00482 this->m_onCmsException (&e);
00483 }
00484 catch (lat::Error &e)
00485 {
00486 if (this->m_onError)
00487 this->m_onError (&e);
00488 }
00489 catch (std::exception &e)
00490 {
00491 if (this->m_onException)
00492 this->m_onException (&e);
00493 }
00494 catch (...)
00495 {
00496 if (this->m_onUnhandledException)
00497 this->m_onUnhandledException ();
00498 }
00499
00500 rep->node ()->addChild (sep);
00501 }
00502
00503
00504 }
00505
00506 void VisTrackingParticleTwig::update(IgRZRep *rep)
00507 {
00508 VisQueuedTwig::update(rep);
00509
00510 IgQtLock();
00511 rep->clear();
00512 }
00513
00514