CMS 3D CMS Logo

VisCSCSeg2HETwig.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "VisReco/VisRecoTools/interface/VisCSCSeg2HETwig.h"
00004 #include "DataFormats/CSCRecHit/interface/CSCSegmentCollection.h"
00005 #include "DataFormats/CSCRecHit/interface/CSCSegment.h"
00006 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "FWCore/Framework/interface/EventSetup.h"
00009 #include "FWCore/Framework/interface/ESHandle.h"
00010 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00011 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00012 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00013 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
00014 #include "Geometry/CSCGeometry/interface/CSCLayer.h"
00015 #include "Geometry/CSCGeometry/interface/CSCLayerGeometry.h"
00016 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00017 #include "Iguana/Framework/interface/IgRepSet.h"
00018 #include "Iguana/Models/interface/IgTextRep.h"
00019 #include "Iguana/GLModels/interface/Ig3DRep.h"
00020 #include "Iguana/GLModels/interface/IgLegoRep.h"
00021 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00022 #include "Iguana/GLModels/interface/IgRZRep.h"
00023 #include "Iguana/Framework/interface/IgRepSet.h"
00024 #include "Iguana/Studio/interface/IgQtLock.h"
00025 #include <Inventor/nodes/SoLineSet.h>
00026 #include <Inventor/nodes/SoMaterial.h>
00027 #include <Inventor/nodes/SoSelection.h>
00028 #include <Inventor/nodes/SoCube.h>
00029 #include <Inventor/nodes/SoTranslation.h>
00030 #include <Inventor/nodes/SoSeparator.h>
00031 #include <Inventor/nodes/SoText2.h>
00032 #include <qstring.h>
00033 #include <sstream>
00034 #include <iomanip>
00035 
00036 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00037 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00038 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00039 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00040 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00041 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00042 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00043 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00044 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00045 
00046 VisCSCSeg2HETwig::VisCSCSeg2HETwig (IgState *state, IgTwig *parent,
00047                                     const std::string &name /* = "" */,
00048                                     const edm::Event &event, 
00049                                     const edm::EventSetup &eventSetup)
00050     : VisQueuedTwig (state, parent, name),
00051       m_event (event),
00052       m_eventSetup (eventSetup)
00053 {
00054 }
00055 
00056 void
00057 VisCSCSeg2HETwig::onNewEvent (const edm::Event &event,
00058                               const edm::EventSetup &eventSetup)
00059 {
00060     VisQueuedTwig::onBaseInvalidate ();
00061 
00062     std::vector<edm::Handle<CSCSegmentCollection> > segCollections;
00063     try 
00064     {
00065         event.getManyByType (segCollections);
00066     }
00067     catch (...)
00068     {
00069         std::cout << "Failed to get the segments." << std::endl;
00070     }
00071 
00072     //
00073     if (! segCollections.empty ())
00074     {
00075         std::vector<edm::Handle<CSCSegmentCollection> >::iterator i;
00076         for (i = segCollections.begin (); i != segCollections.end (); i++)
00077         {
00078             const CSCSegmentCollection& c = *(*i);
00079 
00080             CSCSegmentCollection::const_iterator segIt;
00081             for (segIt = c.begin (); segIt != c.end (); ++segIt)
00082             {
00083                 m_segs.push_back (*segIt);
00084             }
00085         }
00086     }
00087 
00088     IgRepSet::invalidate (this, SELF_MASK);
00089 }
00090 
00091 void
00092 VisCSCSeg2HETwig::update (IgTextRep *rep)
00093 {
00094     // Get debugging dump.
00095     VisQueuedTwig::update (rep);
00096 
00097     // Prepare property description.
00098     std::ostringstream  text;
00099 
00100     text << QString ("Run # %1, event # %2")
00101         .arg (m_event.id ().run ())
00102         .arg (m_event.id ().event ()).latin1 () << "<br>";
00103 
00104 //     text << "<table width='100%' border=1>"
00105 //       << "<TR align = center>"
00106 //       << "<TH>E<SUB>em (GeV)</TH>"
00107 //       << "<TH>E<SUB>had</TH>"
00108 //       << "<TH>E<SUB>inv</TH>"
00109 //       << "<TH>E<SUB>aux</TH>"
00110 //       << "<TH>Eta</TH>"
00111 //       << "<TH>Phi</TH>"
00112 //       << "<TH>Particles</TH>"
00113 //       << "</TR>";
00114 //     text << setiosflags (std::ios::showpoint | std::ios::fixed);
00115 //     text.setf (std::ios::right, std::ios::adjustfield);
00116  
00117 //     text << "<TR align = right>"
00118 //       << "<TD>" << std::setw (2) << std::setprecision (3) << eEm << "</TD>"
00119 //       << "<TD>" << std::setw (6) << std::setprecision (3) << eHad << "</TD>"
00120 //       << "<TD>" << std::setw (5) << std::setprecision (3) << eInv << "</TD>"
00121 //       << "<TD>" << std::setw (5) << std::setprecision (3) << eAux << "</TD>"
00122 //       << "<TD>" << std::setw (5) << std::setprecision (3) << m_jet.eta () << "</TD>"
00123 //       << "<TD>" << std::setw (5) << std::setprecision (3) << m_jet.phi () << "</TD>"
00124 //       << "<TD>";
00125 //     text << "</TD></TR>";
00126        
00127 //     text << "</table>";
00128     
00129     // Send it over.
00130     IgQtLock ();
00131 
00132     rep->setText (text.str ());
00133 }
00134 
00135 void
00136 VisCSCSeg2HETwig::update (Ig3DRep *rep)
00137 {
00138     // Get debugging dump.
00139     VisQueuedTwig::update (rep);
00140 
00141     IgQtLock ();
00142 
00143     SoSeparator *sep = new SoSeparator;
00144     SoMaterial *mat = new SoMaterial;
00145     mat->ambientColor.setValue (0.135, 0.2225, 0.1575);
00146     sep->addChild (mat);
00147 
00148     using namespace edm;
00149 
00150     ESHandle<CSCGeometry> pDD;
00151     try 
00152     {
00153         m_eventSetup.get<MuonGeometryRecord> ().get (pDD);
00154     }
00155     catch (...)
00156     {
00157         std::cout << "Failed to get the goemetry." << std::endl;
00158     }
00159     
00160 //     std::vector<CSCSegment> segs;
00161 
00162 //     std::vector<edm::Handle<CSCSegmentCollection> > segCollections;
00163 //     try 
00164 //     {
00165 //      m_event.getManyByType (segCollections);
00166 //     }
00167 //     catch (...)
00168 //     {
00169 //      std::cout << "Failed to get the segments." << std::endl;
00170 //     }
00171 
00172 //     //
00173 //     if (! segCollections.empty ())
00174 //     {
00175 //      std::vector<edm::Handle<CSCSegmentCollection> >::iterator i;
00176 //      for (i = segCollections.begin (); i != segCollections.end (); i++)
00177 //      {
00178 //          const CSCSegmentCollection& c = *(*i);
00179 
00180 //          CSCSegmentCollection::const_iterator segIt;
00181 //          for (segIt = c.begin (); segIt != c.end (); ++segIt)
00182 //          {
00183 //              segs.push_back (*segIt);
00184 //          }
00185 //      }
00186 //     }
00187 //     //
00188 
00189     if (! m_segs.empty () && pDD.isValid ())
00190     {
00191         try 
00192         {
00193             float h ;
00194             std::cout << "== Run # " << m_event.id ().run () << ", event # " << m_event.id ().event () << std::endl; // latin1 *****
00195             for (std::vector<CSCSegment>::const_iterator iseg = m_segs.begin (); iseg != m_segs.end (); iseg++)
00196             {
00197                 h = 5.7;
00198                 const GeomDet *det = pDD->idToDet ((*iseg).cscDetId ());
00199 
00200                 SoVertexProperty *vtx = new SoVertexProperty;
00201                 
00202                 SoLineSet *line = new SoLineSet;
00203                 line->numVertices = 2;
00204 
00205                 // Local pos & dir
00206                 LocalPoint  pos = (*iseg).localPosition();
00207                 LocalVector dir = (*iseg).localDirection();
00208 
00209                 float halfThickness = det->surface ().bounds ().thickness ()/2.;
00210 
00211                 float z1 = halfThickness;
00212                 float x1 = pos.x() + dir.x()*z1/dir.z();
00213                 float y1 = pos.y() + dir.y()*z1/dir.z();
00214                 GlobalPoint g1 = det->surface().toGlobal( LocalPoint(x1,y1,z1) );
00215 
00216                 float z2 = -halfThickness;
00217                 float x2 = pos.x() + dir.x()*z2/dir.z();
00218                 float y2 = pos.y() + dir.y()*z2/dir.z();
00219                 GlobalPoint g2 = det->surface().toGlobal( LocalPoint(x2,y2,z2) );
00220 
00221                 float x = g1.x () / 100.0;  // cm -> m
00222                 float y = g1.y () / 100.0;  // cm -> m
00223                 float z = g1.z () / 100.0;  // cm -> m
00224 
00225                 //std::cout << "\n*** 1st POINT *** (" << x << ", " << y << ", " << z << ")" << std::endl;
00226                 vtx->vertex.set1Value(0,SbVec3f(x,y,z));
00227 
00228                 float X = g2.x () / 100.0;  // cm -> m
00229                 float Y = g2.y () / 100.0;  // cm -> m
00230                 float Z = g2.z () / 100.0;  // cm -> m
00231 
00232                 //std::cout << "\n*** 2nd POINT *** (" << x << ", " << y << ", " << z << ")" << std::endl;
00233         
00234                 h = (z+Z)/2 - h;
00235                 //std::cout << " *** " << h << std::endl;
00236 
00237                 x = (x+X)/2 - (x-X)/(z-Z)*h;
00238                 y = (y+Y)/2 - (y-Y)/(z-Z)*h;
00239                 z = 5.7;
00240 
00241                 vtx->vertex.set1Value(1,SbVec3f(x,y,z));
00242 
00243                 float phi, theta, eta;
00244                 int iphi, ieta;
00245 
00246                 phi = atan2(y,x);
00247                 theta = acos(z/sqrt(x*x+y*y+z*z));
00248 
00249                 if (phi<0) phi += 2*3.141592; // if the range of phi is defined to be from 0 to 2*PI *****1
00250                 eta = -log(tan(theta/2));
00251 
00252                 //std::cout << " ETA!!! = " << eta << std::endl;
00253                 iphi = (int)((phi - 0.087/2)/0.087 + 1); // casting check *****2
00254                 ieta = (int)((eta - 0.087/2)/0.087);
00255 
00256                 //      if (myfile.is_open())
00257                 //      {
00258                 std::cout << "( iphi = " << iphi << ", ieta = " << ieta << " )" << std::endl;
00259                 //      }
00260                 //      else std::cout << "Unable to open file" << std::endl;
00261 
00262                 line->vertexProperty = vtx;
00263                 
00264                 sep->addChild (line);
00265             }
00266         }
00267         catch (...)
00268         {
00269             std::cout << "Muon Endcap Segments Info: Nothing to display: an exception is caught.";
00270         }    
00271     }    
00272 
00273     rep->clear ();
00274     rep->node ()->addChild (sep);
00275 }
00276 
00277 
00278 void
00279 VisCSCSeg2HETwig::update (IgLegoRep *rep)
00280 {}
00281 
00282 void
00283 VisCSCSeg2HETwig::update (IgRPhiRep *rep)
00284 {}
00285 
00286 void
00287 VisCSCSeg2HETwig::update (IgRZRep *rep)
00288 {}

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