00001
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
00037
00038
00039
00040
00041
00042
00043
00044
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
00095 VisQueuedTwig::update (rep);
00096
00097
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
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 IgQtLock ();
00131
00132 rep->setText (text.str ());
00133 }
00134
00135 void
00136 VisCSCSeg2HETwig::update (Ig3DRep *rep)
00137 {
00138
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
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 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;
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
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;
00222 float y = g1.y () / 100.0;
00223 float z = g1.z () / 100.0;
00224
00225
00226 vtx->vertex.set1Value(0,SbVec3f(x,y,z));
00227
00228 float X = g2.x () / 100.0;
00229 float Y = g2.y () / 100.0;
00230 float Z = g2.z () / 100.0;
00231
00232
00233
00234 h = (z+Z)/2 - h;
00235
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;
00250 eta = -log(tan(theta/2));
00251
00252
00253 iphi = (int)((phi - 0.087/2)/0.087 + 1);
00254 ieta = (int)((eta - 0.087/2)/0.087);
00255
00256
00257
00258 std::cout << "( iphi = " << iphi << ", ieta = " << ieta << " )" << std::endl;
00259
00260
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 {}