00001
00002 #include "TGLFontManager.h"
00003 #include "TEveScene.h"
00004 #include "TEveManager.h"
00005 #include "TEveStraightLineSet.h"
00006 #include "TEveTrack.h"
00007 #include "TEveTrackPropagator.h"
00008 #include "TEveTrans.h"
00009 #include "TEveText.h"
00010 #include "TEveGeoShape.h"
00011 #include "TGSlider.h"
00012 #include "TGButton.h"
00013 #include "TGLabel.h"
00014 #include "TGLViewer.h"
00015 #include "TCanvas.h"
00016 #include "TLatex.h"
00017 #include "TLegend.h"
00018
00019
00020 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
00021 #include "DataFormats/TrackReco/interface/Track.h"
00022 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00023 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
00024 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00025 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00026
00027
00028 #include "Fireworks/Core/interface/FWModelId.h"
00029 #include "Fireworks/Core/interface/FWColorManager.h"
00030 #include "Fireworks/Core/interface/FWGeometry.h"
00031 #include "Fireworks/Core/interface/FWEventItem.h"
00032 #include "Fireworks/Core/interface/CSGAction.h"
00033 #include "Fireworks/Core/interface/FWIntValueListener.h"
00034 #include "Fireworks/Core/interface/FWMagField.h"
00035 #include "Fireworks/Core/interface/fwLog.h"
00036
00037 #include "Fireworks/Tracks/plugins/FWTrackHitsDetailView.h"
00038 #include "Fireworks/Tracks/interface/TrackUtils.h"
00039
00040 FWTrackHitsDetailView::FWTrackHitsDetailView ():
00041 m_modules(0),
00042 m_moduleLabels(0),
00043 m_hits(0),
00044 m_slider(0),
00045 m_sliderListener(),
00046 m_legend(0)
00047 {}
00048
00049 FWTrackHitsDetailView::~FWTrackHitsDetailView ()
00050 {
00051 }
00052
00053 void
00054 FWTrackHitsDetailView::build (const FWModelId &id, const reco::Track* track)
00055 {
00056 {
00057 TGCompositeFrame* f = new TGVerticalFrame(m_guiFrame);
00058 m_guiFrame->AddFrame(f);
00059 f->AddFrame(new TGLabel(f, "Module Transparency:"), new TGLayoutHints(kLHintsLeft, 2, 2, 0, 0));
00060 m_slider = new TGHSlider(f, 120, kSlider1 | kScaleNo);
00061 f->AddFrame(m_slider, new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 1, 4));
00062 m_slider->SetRange(0, 100);
00063 m_slider->SetPosition(75);
00064
00065 m_sliderListener = new FWIntValueListener();
00066 TQObject::Connect(m_slider, "PositionChanged(Int_t)", "FWIntValueListenerBase", m_sliderListener, "setValue(Int_t)");
00067 m_sliderListener->valueChanged_.connect(boost::bind(&FWTrackHitsDetailView::transparencyChanged,this,_1));
00068 }
00069
00070 {
00071 CSGAction* action = new CSGAction(this, "Show Module Labels");
00072 TGCheckButton* b = new TGCheckButton(m_guiFrame, "Show Module Labels" );
00073 b->SetState(kButtonUp, false);
00074 m_guiFrame->AddFrame(b, new TGLayoutHints( kLHintsNormal, 2, 3, 1, 4));
00075 TQObject::Connect(b, "Clicked()", "CSGAction", action, "activate()");
00076 action->activated.connect(sigc::mem_fun(this, &FWTrackHitsDetailView::rnrLabels));
00077 }
00078 {
00079 CSGAction* action = new CSGAction(this, " Pick Camera Center ");
00080 action->createTextButton(m_guiFrame, new TGLayoutHints( kLHintsNormal, 2, 0, 1, 4));
00081 action->setToolTip("Click on object in viewer to set camera center.");
00082 action->activated.connect(sigc::mem_fun(this, &FWTrackHitsDetailView::pickCameraCenter));
00083 }
00084 makeLegend();
00085
00086 TGCompositeFrame* p = (TGCompositeFrame*)m_guiFrame->GetParent();
00087 p->MapSubwindows();
00088 p->Layout();
00089
00090 m_modules = new TEveElementList( "Modules" );
00091 m_eveScene->AddElement( m_modules );
00092 m_moduleLabels = new TEveElementList( "Modules" );
00093 m_eveScene->AddElement( m_moduleLabels );
00094 m_hits = new TEveElementList( "Hits" );
00095 m_eveScene->AddElement( m_hits );
00096 if( track->extra().isAvailable())
00097 {
00098 addModules( *track, id.item(), m_modules, true );
00099 addHits( *track, id.item(), m_hits, true );
00100 }
00101 for( TEveElement::List_i i = m_modules->BeginChildren(), end = m_modules->EndChildren(); i != end; ++i )
00102 {
00103 TEveGeoShape* gs = dynamic_cast<TEveGeoShape*>(*i);
00104 if (gs == 0 && (*i != 0)) {
00105 std::cerr << "Got a " << typeid(**i).name() << ", expecting TEveGeoShape. ignoring (it must be the clusters)." << std::endl;
00106 continue;
00107 }
00108 gs->SetMainTransparency(75);
00109 gs->SetPickable(kFALSE);
00110
00111 TString name = gs->GetElementTitle();
00112 if (!name.Contains("BAD") && !name.Contains("INACTIVE") && !name.Contains("LOST")) {
00113 gs->SetMainColor(kBlue);
00114 }
00115 TEveText* text = new TEveText(name.Data());
00116 text->PtrMainTrans()->SetFrom(gs->RefMainTrans().Array());
00117 text->SetFontMode(TGLFont::kPixmap);
00118 text->SetFontSize(12);
00119 m_moduleLabels->AddElement(text);
00120 }
00121 m_moduleLabels->SetRnrChildren(false);
00122
00123 TEveTrackPropagator* prop = new TEveTrackPropagator();
00124 prop->SetMagFieldObj(item()->context().getField(), false);
00125 prop->SetStepper(TEveTrackPropagator::kRungeKutta);
00126 prop->SetMaxR(123);
00127 prop->SetMaxZ(300);
00128 prop->SetMaxStep(1);
00129 TEveTrack* trk = fireworks::prepareTrack( *track, prop );
00130 trk->MakeTrack();
00131 trk->SetLineWidth(2);
00132 trk->SetTitle( "Track and its ref states" );
00133 prop->SetRnrDaughters(kTRUE);
00134 prop->SetRnrReferences(kTRUE);
00135 prop->SetRnrDecay(kTRUE);
00136 prop->SetRnrFV(kTRUE);
00137 trk->SetMainColor(id.item()->defaultDisplayProperties().color());
00138 m_eveScene->AddElement(trk);
00139
00140 viewerGL()->SetStyle(TGLRnrCtx::kOutline);
00141 viewerGL()->SetDrawCameraCenter(kTRUE);
00142 viewerGL()->ResetCamerasAfterNextUpdate();
00143 viewerGL()->UpdateScene(kFALSE);
00144 gEve->Redraw3D();
00145
00146 setTextInfo(id, track);
00147 }
00148
00149 void
00150 FWTrackHitsDetailView::setBackgroundColor(Color_t col)
00151 {
00152
00153
00154 FWColorManager::setColorSetViewer(viewerGL(), col);
00155
00156
00157 if (m_moduleLabels)
00158 {
00159 Color_t x = viewerGL()->GetRnrCtx()->ColorSet().Foreground().GetColorIndex();
00160 for (TEveElement::List_i i=m_moduleLabels->BeginChildren(); i!=m_moduleLabels->EndChildren(); ++i)
00161 (*i)->SetMainColor(x);
00162 }
00163 }
00164
00165 void
00166 FWTrackHitsDetailView::pickCameraCenter()
00167 {
00168 viewerGL()->PickCameraCenter();
00169 }
00170
00171 void
00172 FWTrackHitsDetailView::transparencyChanged(int x)
00173 {
00174 for (TEveElement::List_i i=m_modules->BeginChildren(); i!=m_modules->EndChildren(); ++i)
00175 {
00176 (*i)->SetMainTransparency(x);
00177 }
00178 gEve->Redraw3D();
00179 }
00180
00181 void
00182 FWTrackHitsDetailView::setTextInfo(const FWModelId &id, const reco::Track* track)
00183 {
00184 m_infoCanvas->cd();
00185
00186 float_t x = 0.02;
00187 float y = 0.95;
00188
00189 TLatex* latex = new TLatex( x, y, "" );
00190 const double textsize( 0.07 );
00191 latex->SetTextSize( 2*textsize );
00192
00193 latex->DrawLatex( x, y, id.item()->modelName( id.index()).c_str());
00194 y -= latex->GetTextSize()*0.6;
00195
00196 latex->SetTextSize( textsize );
00197 float lineH = latex->GetTextSize()*0.6;
00198
00199 latex->DrawLatex( x, y, Form( " P_{T} = %.1f GeV, #eta = %0.2f, #varphi = %0.2f",
00200 track->pt(), track->eta(), track->phi()));
00201 y -= lineH;
00202
00203 if( track->charge() > 0 )
00204 latex->DrawLatex( x, y, " charge = +1" );
00205 else
00206 latex->DrawLatex( x, y, " charge = -1" );
00207 y -= lineH;
00208 y -= lineH;
00209
00210 latex->DrawLatex( x, y, "Track modules:");
00211 y -= lineH;
00212
00213 Double_t pos[4];
00214 pos[0] = x+0.05;
00215 pos[2] = x+0.20;
00216 Double_t boxH = 0.25*textsize;
00217
00218 pos[1] = y; pos[3] = pos[1] + boxH;
00219 FWDetailViewBase::drawCanvasBox( pos, kBlue );
00220 latex->DrawLatex( x + 0.25, y, "Module" );
00221 y -= lineH;
00222
00223 pos[1] = y; pos[3] = pos[1] + boxH;
00224 FWDetailViewBase::drawCanvasBox( pos, kRed );
00225 latex->DrawLatex( x + 0.25, y, "LOST Module" );
00226 y -= lineH;
00227
00228 pos[1] = y; pos[3] = pos[1] + boxH;
00229 FWDetailViewBase::drawCanvasBox( pos, 28 );
00230 latex->DrawLatex( x + 0.25, y, "INACTIVE Module" );
00231 y -= lineH;
00232
00233 pos[1] = y; pos[3] = pos[1] + boxH;
00234 FWDetailViewBase::drawCanvasBox( pos, 218 );
00235 latex->DrawLatex( x + 0.25, y, "BAD Module" );
00236 y -= lineH;
00237
00238 Float_t r = 0.01;
00239 Float_t r2 = 0.02;
00240 y -= lineH;
00241 drawCanvasDot( x + r2, y, r2, kGreen );
00242 y -= r;
00243 latex->DrawLatex( x + 3 * r2, y, "Pixel Hits" );
00244 y -= lineH;
00245
00246 drawCanvasDot( x + r2, y, r2, kRed);
00247 y -= r;
00248 latex->DrawLatex( x + 3 * r2, y, "Extra Pixel Hits" );
00249 y -= lineH;
00250
00251 m_legend->SetY2(y);
00252 m_legend->Draw();
00253 m_legend = 0;
00254 }
00255
00256 void
00257 FWTrackHitsDetailView::makeLegend( void )
00258 {
00259 m_legend = new TLegend( 0.01, 0.01, 0.99, 0.99, 0, "NDC" );
00260 m_legend->SetFillColor(kWhite);
00261 m_legend->SetTextSize( 0.07 );
00262 m_legend->SetBorderSize( 0 );
00263 m_legend->SetMargin( 0.15 );
00264 m_legend->SetEntrySeparation( 0.01 );
00265
00266 TEveStraightLineSet *legend = new TEveStraightLineSet( "siStripCluster" );
00267 legend->SetLineWidth( 3 );
00268 legend->SetLineColor( kGreen );
00269 m_legend->AddEntry( legend, "Exact SiStripCluster", "l");
00270
00271 TEveStraightLineSet *legend2 = new TEveStraightLineSet( "siStripCluster2" );
00272 legend2->SetLineWidth( 3 );
00273 legend2->SetLineColor( kRed );
00274 m_legend->AddEntry( legend2, "Extra SiStripCluster", "l");
00275
00276 TEveStraightLineSet *legend3 = new TEveStraightLineSet( "refStates" );
00277 legend3->SetDepthTest( kFALSE );
00278 legend3->SetMarkerColor( kYellow );
00279 legend3->SetMarkerStyle( kPlus );
00280 legend3->SetMarkerSize( 2 );
00281 m_legend->AddEntry( legend3, "Inner/Outermost States", "p");
00282
00283 TEveStraightLineSet *legend4 = new TEveStraightLineSet( "vertex" );
00284 legend4->SetDepthTest( kFALSE );
00285 legend4->SetMarkerColor( kRed );
00286 legend4->SetMarkerStyle( kFullDotLarge );
00287 legend4->SetMarkerSize( 2 );
00288 m_legend->AddEntry( legend4, "Vertex", "p");
00289
00290 TEveStraightLineSet *legend5 = new TEveStraightLineSet( "cameraCenter" );
00291 legend5->SetDepthTest( kFALSE );
00292 legend5->SetMarkerColor( kCyan );
00293 legend5->SetMarkerStyle( kFullDotLarge );
00294 legend5->SetMarkerSize( 2 );
00295 m_legend->AddEntry( legend5, "Camera center", "p");
00296 }
00297
00298 void
00299 FWTrackHitsDetailView::addTrackerHits3D( std::vector<TVector3> &points, class TEveElementList *tList, Color_t color, int size )
00300 {
00301
00302
00303
00304 TEvePointSet* pointSet = new TEvePointSet();
00305 pointSet->SetMarkerSize(size);
00306 pointSet->SetMarkerStyle(4);
00307 pointSet->SetPickable(kTRUE);
00308 pointSet->SetTitle("Pixel Hits");
00309 pointSet->SetMarkerColor(color);
00310
00311 for( std::vector<TVector3>::const_iterator it = points.begin(), itEnd = points.end(); it != itEnd; ++it) {
00312 pointSet->SetNextPoint(it->x(), it->y(), it->z());
00313 }
00314 tList->AddElement(pointSet);
00315 }
00316
00317 void
00318 FWTrackHitsDetailView::addHits( const reco::Track& track,
00319 const FWEventItem* iItem,
00320 TEveElement* trkList,
00321 bool addNearbyHits )
00322 {
00323 std::vector<TVector3> pixelPoints;
00324 fireworks::pushPixelHits( pixelPoints, *iItem, track );
00325 TEveElementList* pixels = new TEveElementList( "Pixels" );
00326 trkList->AddElement( pixels );
00327 if( addNearbyHits )
00328 {
00329
00330 std::vector<TVector3> pixelExtraPoints;
00331 fireworks::pushNearbyPixelHits( pixelExtraPoints, *iItem, track );
00332
00333 addTrackerHits3D( pixelExtraPoints, pixels, kRed, 1 );
00334
00335 addTrackerHits3D( pixelPoints, pixels, kGreen, 1 );
00336 }
00337 else
00338 {
00339
00340 addTrackerHits3D( pixelPoints, pixels, iItem->defaultDisplayProperties().color(), 1 );
00341 }
00342
00343
00344 TEveElementList* strips = new TEveElementList( "Strips" );
00345 trkList->AddElement( strips );
00346 fireworks::addSiStripClusters( iItem, track, strips, addNearbyHits, false );
00347 }
00348
00349
00350
00351 void
00352 FWTrackHitsDetailView::addModules( const reco::Track& track,
00353 const FWEventItem* iItem,
00354 TEveElement* trkList,
00355 bool addLostHits )
00356 {
00357 std::set<unsigned int> ids;
00358 for( trackingRecHit_iterator recIt = track.recHitsBegin(), recItEnd = track.recHitsEnd();
00359 recIt != recItEnd; ++recIt )
00360 {
00361 DetId detid = (*recIt)->geographicalId();
00362 if( !addLostHits && !(*recIt)->isValid()) continue;
00363 if( detid.rawId() != 0 )
00364 {
00365 TString name("");
00366 switch( detid.det())
00367 {
00368 case DetId::Tracker:
00369 switch( detid.subdetId())
00370 {
00371 case SiStripDetId::TIB:
00372 name = "TIB ";
00373 break;
00374 case SiStripDetId::TOB:
00375 name = "TOB ";
00376 break;
00377 case SiStripDetId::TID:
00378 name = "TID ";
00379 break;
00380 case SiStripDetId::TEC:
00381 name = "TEC ";
00382 break;
00383 case PixelSubdetector::PixelBarrel:
00384 name = "Pixel Barrel ";
00385 {
00386 PXBDetId idid = PXBDetId( detid.rawId() );
00387 unsigned int layer = idid.layer();
00388 unsigned int ladder = idid.ladder();
00389 unsigned int module = idid.module();
00390
00391 name += TString::Format( ": Layer=%u, Ladder=%u, Module=%u \n",
00392 layer, ladder, module );
00393 }
00394 break;
00395 case PixelSubdetector::PixelEndcap:
00396 name = "Pixel Endcap ";
00397 {
00398 PXFDetId idid = PXFDetId( detid.rawId() );
00399 unsigned int side = idid.side();
00400 unsigned int disk = idid.disk();
00401 unsigned int blade = idid.blade();
00402 unsigned int panel = idid.panel();
00403 unsigned int module = idid.module();
00404
00405 name += TString::Format( ": Side=%u, Disk=%u, Blade=%u, Panel=%u, Module=%u \n",
00406 side, disk, blade, panel, module );
00407 }
00408
00409 default:
00410 break;
00411 }
00412 break;
00413
00414 case DetId::Muon:
00415 switch( detid.subdetId())
00416 {
00417 case MuonSubdetId::DT:
00418 name = "DT";
00419 detid = DetId( DTChamberId( detid ));
00420 break;
00421 case MuonSubdetId::CSC:
00422 name = "CSC";
00423 break;
00424 case MuonSubdetId::RPC:
00425 name = "RPC";
00426 break;
00427 default:
00428 break;
00429 }
00430 break;
00431 default:
00432 break;
00433 }
00434 if( ! ids.insert( detid.rawId()).second ) continue;
00435 if( iItem->getGeom())
00436 {
00437 TEveGeoShape* shape = iItem->getGeom()->getEveShape( detid );
00438 if( 0 != shape )
00439 {
00440 shape->SetMainTransparency( 65 );
00441 shape->SetPickable( kTRUE );
00442 switch(( *recIt )->type())
00443 {
00444 case TrackingRecHit::valid:
00445 shape->SetMainColor( iItem->defaultDisplayProperties().color());
00446 break;
00447 case TrackingRecHit::missing:
00448 name += "LOST ";
00449 shape->SetMainColor( kRed );
00450 break;
00451 case TrackingRecHit::inactive:
00452 name += "INACTIVE ";
00453 shape->SetMainColor( 28 );
00454 break;
00455 case TrackingRecHit::bad:
00456 name += "BAD ";
00457 shape->SetMainColor( 218 );
00458 break;
00459 }
00460 shape->SetTitle( name + ULong_t( detid.rawId()));
00461 trkList->AddElement( shape );
00462 }
00463 else
00464 {
00465 fwLog( fwlog::kInfo ) << "Failed to get shape extract for a tracking rec hit: "
00466 << "\n" << fireworks::info( detid ) << std::endl;
00467 }
00468 }
00469 }
00470 }
00471 }
00472
00473 void
00474 FWTrackHitsDetailView::rnrLabels()
00475 {
00476 m_moduleLabels->SetRnrChildren(!m_moduleLabels->GetRnrChildren());
00477 gEve->Redraw3D();
00478 }
00479
00480 REGISTER_FWDETAILVIEW(FWTrackHitsDetailView, Hits);