00001 #include "VisReco/VisPF/interface/VisPFRecTrackTwig.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/Studio/interface/IgDocumentData.h"
00021
00022 #include "Iguana/Studio/interface/IgQtLock.h"
00023
00024 #include <Inventor/nodes/SoMaterial.h>
00025 #include <Inventor/nodes/SoSeparator.h>
00026
00027 #include <qstring.h>
00028 #include <classlib/utils/DebugAids.h>
00029 #include <algorithm>
00030 #include <iostream>
00031 #include <iomanip>
00032
00033 #include "DataFormats/ParticleFlowReco/interface/PFBrem.h"
00034
00035 namespace
00036 {
00037 VisQueuedTwig* createThisTwig(IgState *state, IgTwig *parent,
00038 const std::string &name,
00039 const std::string &friendlyName,
00040 const std::string &modLabel,
00041 const std::string &instanceName,
00042 const std::string &processName)
00043 {
00044 return new VisPFRecTrackTwig(state, parent, name, friendlyName, modLabel, instanceName, processName);
00045 }
00046 }
00047
00048 VisPFRecTrackTwig::VisPFRecTrackTwig(IgState *state, IgTwig *parent,
00049 const std::string &name,
00050 const std::string &friendlyName,
00051 const std::string &moduleLabel,
00052 const std::string &instanceName,
00053 const std::string &processName)
00054 : VisQueuedTwig(state, parent, name),
00055 m_text("No Info"),
00056 m_name(name),
00057 m_friendlyName(friendlyName),
00058 m_moduleLabel(moduleLabel),
00059 m_instanceName(instanceName),
00060 m_processName(processName)
00061 {
00062 VisTwigFactroyService *tfService = VisTwigFactroyService::get(state);
00063
00064 if (! tfService)
00065 {
00066 tfService = new VisTwigFactroyService(state);
00067 }
00068
00069 edm::TypeID pfTracksID(typeid (reco::PFRecTrackCollection));
00070
00071 tfService->registerTwig(pfTracksID.friendlyClassName(), &createThisTwig);
00072 }
00073
00074 void VisPFRecTrackTwig::onNewEvent(const edm::Event &event,
00075 const edm::EventSetup &eventSetup)
00076 {
00077 VisQueuedTwig::onNewEvent(event, eventSetup);
00078
00079 m_tracks.clear();
00080
00081 m_trajectoryPositions.clear();
00082 m_trajectoryDirections.clear();
00083
00084
00085
00086
00087
00088 std::vector<edm::Handle<reco::PFRecTrackCollection> > trackCollections;
00089
00090 try
00091 {
00092 if ( (! m_friendlyName.empty ()) ||
00093 (! m_moduleLabel.empty ()) ||
00094 (! m_instanceName.empty ()) ||
00095 (! m_processName.empty ()) )
00096 {
00097 VisEventSelector visSel(m_friendlyName, m_moduleLabel,
00098 m_instanceName, m_processName);
00099
00100 event.getMany(visSel, trackCollections);
00101 }
00102
00103 else
00104 {
00105 event.getManyByType(trackCollections);
00106 }
00107 }
00108
00109 catch (cms::Exception& e)
00110 {
00111 if (this->m_onCmsException)
00112 this->m_onCmsException(&e);
00113 }
00114
00115 catch (lat::Error &e)
00116 {
00117 if (this->m_onError)
00118 this->m_onError(&e);
00119 }
00120
00121 catch (std::exception &e)
00122 {
00123 if (this->m_onException)
00124 this->m_onException(&e);
00125 }
00126
00127 catch (...)
00128 {
00129 if (this->m_onUnhandledException)
00130 this->m_onUnhandledException();
00131 }
00132
00133 if (! trackCollections.empty())
00134 {
00135 for (std::vector<edm::Handle<reco::PFRecTrackCollection> >::iterator i =
00136 trackCollections.begin(), iEnd = trackCollections.end();
00137 i != iEnd; ++i)
00138 {
00139 const reco::PFRecTrackCollection& c = *(*i);
00140
00141 for (std::vector<reco::PFRecTrack>::const_iterator ipft = c.begin(), ipftEnd = c.end();
00142 ipft != ipftEnd; ++ipft)
00143 {
00144 m_tracks.push_back((*ipft));
00145
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
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 std::vector<SbVec3f> traPos;
00191 std::vector<SbVec3f> traDir;
00192
00193 const std::vector<reco::PFTrajectoryPoint>& points = (*ipft).trajectoryPoints();
00194
00195 for ( unsigned int ipt = 0; ipt < points.size(); ++ipt )
00196 {
00197 if ( points[ipt].isValid() )
00198 {
00199 double x = points[ipt].position().X()/100.0;
00200 double y = points[ipt].position().Y()/100.0;
00201 double z = points[ipt].position().Z()/100.0;
00202
00203 float dirx = points[ipt].momentum().X();
00204 float diry = points[ipt].momentum().Y();
00205 float dirz = points[ipt].momentum().Z();
00206 SbVec3f dir(dirx, diry, dirz);
00207 dir.normalize();
00208
00209 traPos.push_back(SbVec3f(x,y,z));
00210 traDir.push_back(dir);
00211 }
00212 }
00213
00214 unsigned int algoType = (*ipft).algoType();
00215 SbColor color;
00216
00217 if ( algoType == 1 )
00218 color = SbColor(1.0, 52.0/255.0, 179.0/255.0);
00219
00220 else if ( algoType == 2 )
00221 color = SbColor(1.0, 0.0, 1.0);
00222
00223 else if ( algoType == 3)
00224 color = SbColor(1.0, 181.0/255.0, 197.0/255.0);
00225
00226 else
00227 color = SbColor(1.0, 131.0/255.0, 250.0/255.0);
00228
00229 std::pair<SbColor, std::vector<SbVec3f> > posPair(color, traPos);
00230 std::pair<SbColor, std::vector<SbVec3f> > dirPair(color, traDir);
00231
00232 m_trajectoryPositions.push_back(posPair);
00233 m_trajectoryDirections.push_back(dirPair);
00234
00235 }
00236
00237 }
00238 }
00239
00240 else
00241 std::cout<<"DEBUG: trackCollections.empty()"<<std::endl;
00242
00243 VisQueuedTwig::onBaseInvalidate();
00244 }
00245
00246
00247 void VisPFRecTrackTwig::update(Ig3DRep *rep)
00248 {
00249 VisQueuedTwig::update(rep);
00250 IgQtLock();
00251 rep->clear();
00252
00253 SoSeparator* contents = new SoSeparator;
00254
00255 if ( ! m_trajectoryPositions.empty() && ! m_trajectoryDirections.empty() )
00256 {
00257 std::vector<std::pair<SbColor, std::vector<SbVec3f> > >::const_iterator ipos
00258 = m_trajectoryPositions.begin();
00259
00260 std::vector<std::pair<SbColor, std::vector<SbVec3f> > >::const_iterator idir
00261 = m_trajectoryDirections.begin();
00262
00263 for ( unsigned int itrack = 0;
00264 itrack < m_trajectoryPositions.size();
00265 ++itrack )
00266 {
00267 SoMaterial* mat1 = new SoMaterial;
00268 mat1->diffuseColor.setValue(m_trajectoryPositions[itrack].first);
00269 contents->addChild(mat1);
00270
00271 IgSoSimpleTrajectory* obj1 = new IgSoSimpleTrajectory;
00272
00273 int nState = 0;
00274
00275 std::vector<SbVec3f>::const_iterator idd = (*idir).second.begin();
00276
00277 for ( std::vector<SbVec3f>::const_iterator ipp = (*ipos).second.begin();
00278 ipp != (*ipos).second.end(); ++ipp )
00279 {
00280 obj1->controlPoints.set1Value(nState, (*ipp));
00281 obj1->markerPoints.set1Value(nState, (*ipp));
00282
00283 nState++;
00284 idd++;
00285 }
00286
00287 obj1->linePattern = 0xdfff;
00288 obj1->lineWidth = 3.0;
00289
00290 contents->addChild(obj1);
00291
00292 ipos++;
00293 idir++;
00294 }
00295 }
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345 rep->node()->addChild(contents);
00346 }
00347
00348 void VisPFRecTrackTwig::update(IgLegoRep *rep)
00349 {
00350 VisQueuedTwig::update(rep);
00351 }
00352
00353 void VisPFRecTrackTwig::update(IgTextRep *rep)
00354 {
00355 VisQueuedTwig::update(rep);
00356
00357 std::ostringstream text;
00358
00359 text << m_name << " from ";
00360 text << m_text << "<br>";
00361 text << "Total: " << m_tracks.size () << " PFRecTracks.<br>";
00362
00363 text << "<table width='100%' border=1>"
00364 << "<TR align = center>"
00365 << "<TH>Number</TH>"
00366 << "<TH>Algorithm</TH>"
00367 << "<TH>P<SUB>T</TH>"
00368 << "<TH>P (GeV)</TH>"
00369 << "<TH>Rho</TH>"
00370 << "<TH>Z</TH>"
00371 << "<TH># tracker measurements</TH>"
00372 << "<TH># points total</TH>"
00373 << "<TH>Charge</TH>"
00374 << "</TR>";
00375
00376 text << setiosflags (std::ios::showpoint | std::ios::fixed);
00377 text.setf (std::ios::right, std::ios::adjustfield);
00378
00379 try
00380 {
00381 if ( ! m_tracks.empty() )
00382 {
00383 int nTracks = 0;
00384
00385 for ( std::vector<reco::PFRecTrack>::iterator iT = m_tracks.begin();
00386 iT != m_tracks.end(); ++iT )
00387 {
00388 std::string algoString;
00389 unsigned int algoType = (*iT).algoType();
00390 std::string color;
00391
00392 if ( algoType == 1 )
00393 {
00394 algoString = "KF";
00395 color = "<TD bgcolor=\"#ff34b3\">";
00396 }
00397
00398 else if ( algoType == 2 )
00399 {
00400 algoString = "GSF";
00401 color = "<TD bgcolor=\"#ff00ff\">";
00402 }
00403
00404 else if ( algoType == 3)
00405 {
00406 algoString = "KF_ELCAND";
00407 color = "<TD bgcolor=\"#ffb5c5\">";
00408 }
00409
00410 else
00411 {
00412 algoString == "Unknown";
00413 color = "<TD bgcolor=\"#ff83fa\">";
00414 }
00415
00416 const reco::PFTrajectoryPoint& closestApproach =
00417 (*iT).trajectoryPoint(reco::PFTrajectoryPoint::ClosestApproach);
00418
00419 text << "<TR align = right>"
00420 << "<TD>" << std::setw (3) << nTracks++ << "</TD>"
00421 << color << std::setw (2) << std::setprecision (3) << algoString << "</TD>"
00422 << "<TD>" << std::setw (2) << std::setprecision (3) << closestApproach.momentum().Pt() << "</TD>"
00423 << "<TD>" << std::setw (2) << std::setprecision (3) << closestApproach.momentum().P() << "</TD>"
00424 << "<TD>" << std::setw (2) << std::setprecision (3) << closestApproach.position().Rho() << "</TD>"
00425 << "<TD>" << std::setw (2) << std::setprecision (3) << closestApproach.position().Z() << "</TD>"
00426 << "<TD>" << std::setw (2) << std::setprecision (3) << (*iT).nTrajectoryMeasurements() << "</TD>"
00427 << "<TD>" << std::setw (2) << std::setprecision (3) << (*iT).nTrajectoryPoints() << "</TD>"
00428 << "<TD>" << std::setw (2) << std::setprecision (3) << (*iT).charge () << "</TD>"
00429 << "</TR>";
00430 }
00431 }
00432 }
00433
00434 catch (cms::Exception& e)
00435 {
00436 if (this->m_onCmsException)
00437 this->m_onCmsException (&e);
00438 }
00439 catch (lat::Error &e)
00440 {
00441 if (this->m_onError)
00442 this->m_onError (&e);
00443 }
00444 catch (std::exception &e)
00445 {
00446 if (this->m_onException)
00447 this->m_onException (&e);
00448 }
00449 catch (...)
00450 {
00451 if (this->m_onUnhandledException)
00452 this->m_onUnhandledException ();
00453 }
00454
00455 text << "</table>";
00456
00457 IgQtLock();
00458 rep->setText(text.str());
00459 }
00460
00461 void VisPFRecTrackTwig::update(IgRPhiRep *rep)
00462 {
00463 VisQueuedTwig::update (rep);
00464
00465 IgQtLock ();
00466 rep->clear ();
00467
00468 SoSeparator* contents = new SoSeparator;
00469
00470 if ( ! m_trajectoryPositions.empty() && ! m_trajectoryDirections.empty() )
00471 {
00472 std::vector<std::pair<SbColor, std::vector<SbVec3f> > >::const_iterator ipos
00473 = m_trajectoryPositions.begin();
00474
00475 std::vector<std::pair<SbColor, std::vector<SbVec3f> > >::const_iterator idir
00476 = m_trajectoryDirections.begin();
00477
00478 for ( unsigned int itrack = 0;
00479 itrack != m_trajectoryPositions.size();
00480 ++itrack )
00481 {
00482 SoMaterial* mat = new SoMaterial;
00483
00484 mat->diffuseColor.setValue(m_trajectoryPositions[itrack].first);
00485 contents->addChild(mat);
00486
00487 IgSoSimpleTrajectory* obj = new IgSoSimpleTrajectory;
00488
00489 int nState = 0;
00490 float zlayer = 0.1;
00491
00492 std::vector<SbVec3f>::const_iterator idd = (*idir).second.begin();
00493
00494 for ( std::vector<SbVec3f>::const_iterator ipp = (*ipos).second.begin();
00495 ipp != (*ipos).second.end(); ++ipp )
00496 {
00497 SbVec3f rzpos((*ipp)[0], (*ipp)[1], zlayer);
00498 obj->controlPoints.set1Value(nState, rzpos);
00499 obj->markerPoints.set1Value(nState, rzpos);
00500
00501 nState++;
00502 idd++;
00503 }
00504
00505 obj->linePattern = 0xffff;
00506 obj->lineWidth = 3.0;
00507
00508 contents->addChild(obj);
00509
00510 ipos++;
00511 idir++;
00512 }
00513 }
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559 rep->node()->addChild(contents);
00560 }
00561
00562 void VisPFRecTrackTwig::update(IgRZRep *rep)
00563 {
00564 VisQueuedTwig::update(rep);
00565
00566 IgQtLock();
00567 rep->clear();
00568 }
00569
00570