CMS 3D CMS Logo

VisGsfPFRecTrackTwig.cc

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

Generated on Tue Jun 9 17:50:24 2009 for CMSSW by  doxygen 1.5.4