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
00025
00026 #include "Fireworks/Core/interface/FWModelId.h"
00027 #include "Fireworks/Core/interface/FWColorManager.h"
00028 #include "Fireworks/Core/interface/FWGeometry.h"
00029 #include "Fireworks/Core/interface/FWEventItem.h"
00030 #include "Fireworks/Core/interface/CSGAction.h"
00031 #include "Fireworks/Core/interface/FWIntValueListener.h"
00032 #include "Fireworks/Core/interface/FWMagField.h"
00033 #include "Fireworks/Core/interface/fwLog.h"
00034
00035 #include "Fireworks/Electrons/plugins/FWConvTrackHitsDetailView.h"
00036 #include "DataFormats/EgammaCandidates/interface/Conversion.h"
00037 #include "Fireworks/Tracks/interface/TrackUtils.h"
00038
00039 FWConvTrackHitsDetailView::FWConvTrackHitsDetailView ():
00040 m_modules(0),
00041 m_moduleLabels(0),
00042 m_hits(0),
00043 m_slider(0),
00044 m_sliderListener(),
00045 m_legend(0)
00046 {}
00047
00048 FWConvTrackHitsDetailView::~FWConvTrackHitsDetailView ()
00049 {
00050 }
00051
00052 void
00053 FWConvTrackHitsDetailView::build (const FWModelId &id, const reco::Conversion* conv)
00054 {
00055 if (conv->nTracks()<2) return;
00056 const reco::Track* track0 = conv->tracks().at(0).get();
00057 const reco::Track* track1 = conv->tracks().at(1).get();
00058
00059 {
00060 TGCompositeFrame* f = new TGVerticalFrame(m_guiFrame);
00061 m_guiFrame->AddFrame(f);
00062 f->AddFrame(new TGLabel(f, "Module Transparency:"), new TGLayoutHints(kLHintsLeft, 2, 2, 0, 0));
00063 m_slider = new TGHSlider(f, 120, kSlider1 | kScaleNo);
00064 f->AddFrame(m_slider, new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 1, 4));
00065 m_slider->SetRange(0, 100);
00066 m_slider->SetPosition(75);
00067
00068 m_sliderListener = new FWIntValueListener();
00069 TQObject::Connect(m_slider, "PositionChanged(Int_t)", "FWIntValueListenerBase", m_sliderListener, "setValue(Int_t)");
00070 m_sliderListener->valueChanged_.connect(boost::bind(&FWConvTrackHitsDetailView::transparencyChanged,this,_1));
00071 }
00072
00073 {
00074 CSGAction* action = new CSGAction(this, "Show Module Labels");
00075 TGCheckButton* b = new TGCheckButton(m_guiFrame, "Show Module Labels" );
00076 b->SetState(kButtonUp, false);
00077 m_guiFrame->AddFrame(b, new TGLayoutHints( kLHintsNormal, 2, 3, 1, 4));
00078 TQObject::Connect(b, "Clicked()", "CSGAction", action, "activate()");
00079 action->activated.connect(sigc::mem_fun(this, &FWConvTrackHitsDetailView::rnrLabels));
00080 }
00081 {
00082 CSGAction* action = new CSGAction(this, " Pick Camera Center ");
00083 action->createTextButton(m_guiFrame, new TGLayoutHints( kLHintsNormal, 2, 0, 1, 4));
00084 action->setToolTip("Click on object in viewer to set camera center.");
00085 action->activated.connect(sigc::mem_fun(this, &FWConvTrackHitsDetailView::pickCameraCenter));
00086 }
00087
00088
00089 TGCompositeFrame* p = (TGCompositeFrame*)m_guiFrame->GetParent();
00090 p->MapSubwindows();
00091 p->Layout();
00092
00093 m_modules = new TEveElementList( "Modules" );
00094 m_eveScene->AddElement( m_modules );
00095 m_moduleLabels = new TEveElementList( "Modules" );
00096 m_eveScene->AddElement( m_moduleLabels );
00097 m_hits = new TEveElementList( "Hits" );
00098 m_eveScene->AddElement( m_hits );
00099 if( track1->extra().isAvailable())
00100 {
00101 addModules( *track1, id.item(), m_modules, true );
00102 addHits( *track1, id.item(), m_hits, true );
00103 }
00104 if( track0->extra().isAvailable())
00105 {
00106 addModules( *track0, id.item(), m_modules, true );
00107 addHits( *track0, id.item(), m_hits, true );
00108 }
00109 for( TEveElement::List_i i = m_modules->BeginChildren(), end = m_modules->EndChildren(); i != end; ++i )
00110 {
00111 TEveGeoShape* gs = dynamic_cast<TEveGeoShape*>(*i);
00112 if (gs == 0 && (*i != 0)) {
00113 std::cerr << "Got a " << typeid(**i).name() << ", expecting TEveGeoShape. ignoring (it must be the clusters)." << std::endl;
00114 continue;
00115 }
00116 gs->SetMainTransparency(75);
00117 gs->SetPickable(kFALSE);
00118
00119 TString name = gs->GetElementTitle();
00120 if (!name.Contains("BAD") && !name.Contains("INACTIVE") && !name.Contains("LOST")) {
00121 gs->SetMainColor(kBlue);
00122 }
00123 TEveText* text = new TEveText(name.Data());
00124 text->PtrMainTrans()->SetFrom(gs->RefMainTrans().Array());
00125 text->SetFontMode(TGLFont::kPixmap);
00126 text->SetFontSize(12);
00127 m_moduleLabels->AddElement(text);
00128 }
00129 m_moduleLabels->SetRnrChildren(false);
00130
00131 TEveTrackPropagator* prop = new TEveTrackPropagator();
00132 prop->SetMagFieldObj(item()->context().getField(), false);
00133 prop->SetStepper(TEveTrackPropagator::kRungeKutta);
00134 prop->SetMaxR(123);
00135 prop->SetMaxZ(300);
00136 prop->SetMaxStep(1);
00137 prop->SetRnrDaughters(kTRUE);
00138 prop->SetRnrReferences(kTRUE);
00139 prop->SetRnrDecay(kTRUE);
00140 prop->SetRnrFV(kTRUE);
00141
00142 TEveTrack* trk1 = fireworks::prepareTrack( *track1, prop );
00143 trk1->MakeTrack();
00144 trk1->SetLineWidth(2);
00145 trk1->SetTitle( "Track 1 and its ref states" );
00146 trk1->SetMainColor(id.item()->defaultDisplayProperties().color());
00147 m_eveScene->AddElement(trk1);
00148
00149 TEveTrack* trk0 = fireworks::prepareTrack( *track0, prop );
00150 trk0->MakeTrack();
00151 trk0->SetLineWidth(2);
00152 trk0->SetTitle( "Track 0 and its ref states" );
00153 trk0->SetMainColor(id.item()->defaultDisplayProperties().color());
00154 m_eveScene->AddElement(trk0);
00155
00156 viewerGL()->SetStyle(TGLRnrCtx::kOutline);
00157 viewerGL()->SetDrawCameraCenter(kTRUE);
00158 viewerGL()->ResetCamerasAfterNextUpdate();
00159 viewerGL()->UpdateScene(kFALSE);
00160 gEve->Redraw3D();
00161
00162 setTextInfo(id, conv);
00163 }
00164
00165 void
00166 FWConvTrackHitsDetailView::setBackgroundColor(Color_t col)
00167 {
00168
00169
00170 FWColorManager::setColorSetViewer(viewerGL(), col);
00171
00172
00173 if (m_moduleLabels)
00174 {
00175 Color_t x = viewerGL()->GetRnrCtx()->ColorSet().Foreground().GetColorIndex();
00176 for (TEveElement::List_i i=m_moduleLabels->BeginChildren(); i!=m_moduleLabels->EndChildren(); ++i)
00177 (*i)->SetMainColor(x);
00178 }
00179 }
00180
00181 void
00182 FWConvTrackHitsDetailView::pickCameraCenter()
00183 {
00184 viewerGL()->PickCameraCenter();
00185 }
00186
00187 void
00188 FWConvTrackHitsDetailView::transparencyChanged(int x)
00189 {
00190 for (TEveElement::List_i i=m_modules->BeginChildren(); i!=m_modules->EndChildren(); ++i)
00191 {
00192 (*i)->SetMainTransparency(x);
00193 }
00194 gEve->Redraw3D();
00195 }
00196
00197 void
00198 FWConvTrackHitsDetailView::setTextInfo(const FWModelId &id, const reco::Conversion* conv)
00199 {
00200 m_infoCanvas->cd();
00201
00202 float_t x = 0.02;
00203 float y = 0.95;
00204
00205 TLatex* latex = new TLatex( x, y, "" );
00206 const double textsize( 0.07 );
00207 latex->SetTextSize( 2*textsize );
00208
00209 latex->DrawLatex( x, y, id.item()->modelName( id.index()).c_str());
00210 y -= latex->GetTextSize()*0.6;
00211
00212 latex->SetTextSize( textsize );
00213 float lineH = latex->GetTextSize()*0.6;
00214
00215 latex->DrawLatex( x, y, Form("p_{T}=%.1f GeV, #eta=%0.2f, #varphi=%0.2f",
00216 sqrt(conv->pairMomentum().Perp2()), conv->pairMomentum().eta(), conv->pairMomentum().phi() ));
00217 y -= lineH;
00218 latex->DrawLatex( x, y, Form("vtx=(%.1f, %.1f, %.1f) r=%.1f [cm]",
00219 conv->conversionVertex().x(), conv->conversionVertex().y(), conv->conversionVertex().z(),
00220 conv->conversionVertex().position().rho() ));
00221 y -= lineH;
00222 latex->DrawLatex( x, y, Form("#Deltactg#theta=%.3f",
00223 conv->pairCotThetaSeparation() ));
00224 y -= lineH;
00225 latex->DrawLatex( x, y, Form("#Delta#phi_{vtx}=%.3f",
00226 conv->dPhiTracksAtVtx() ));
00227 y -= lineH;
00228 latex->DrawLatex( x, y, Form("dist. min. app.=%.3f cm",
00229 conv->distOfMinimumApproach() ));
00230 y -= lineH;
00231 y -= lineH;
00232
00233
00234 const reco::Track* track0 = conv->tracks().at(0).get();
00235 latex->DrawLatex( x, y, Form("Trk0 q=%i",track0->charge()));
00236 y -= lineH;
00237 latex->DrawLatex( x, y, Form( "p_{T}=%.1f GeV, #eta=%0.2f, #varphi=%0.2f",
00238 track0->pt(), track0->eta(), track0->phi()));
00239 y -= lineH;
00240 const reco::HitPattern& p_tk0 = track0->hitPattern();
00241 int nvalid_tk0=0, ninvalid_tk0=0, npix_tk0=0, nstrip_tk0=0;
00242 for(int i_tk0=0; i_tk0<p_tk0.numberOfHits(); i_tk0++) {
00243 uint32_t hit = p_tk0.getHitPattern(i_tk0);
00244 if(p_tk0.validHitFilter(hit)) {
00245 nvalid_tk0++;
00246 if (p_tk0.pixelHitFilter(hit)) npix_tk0++;
00247 else if (p_tk0.stripHitFilter(hit)) nstrip_tk0++;
00248 } else ninvalid_tk0++;
00249 }
00250 latex->DrawLatex( x, y, Form( "valid hits: %i (pix. %i, str. %i)", nvalid_tk0, npix_tk0, nstrip_tk0) );
00251 y -= lineH;
00252 latex->DrawLatex( x, y, Form( "invalid: %i", ninvalid_tk0) );
00253 y -= lineH;
00254 const reco::HitPattern& p_mhi_tk0 = track0->trackerExpectedHitsInner();
00255 int npix_mhi_tk0=0, nstrip_mhi_tk0=0;
00256 for(int i_mhi_tk0=0; i_mhi_tk0<p_mhi_tk0.numberOfHits(); i_mhi_tk0++) {
00257 uint32_t hit = p_mhi_tk0.getHitPattern(i_mhi_tk0);
00258 if (p_mhi_tk0.pixelHitFilter(hit)) npix_mhi_tk0++;
00259 else if (p_mhi_tk0.stripHitFilter(hit)) nstrip_mhi_tk0++;
00260 }
00261 latex->DrawLatex( x, y, Form("miss. inner hits: pix. %i, str. %i", npix_mhi_tk0, nstrip_mhi_tk0) );
00262
00263 y -= lineH;
00264 y -= lineH;
00265 const reco::Track* track1 = conv->tracks().at(1).get();
00266 latex->DrawLatex( x, y, Form("Trk1 q=%i",track1->charge()));
00267 y -= lineH;
00268 latex->DrawLatex( x, y, Form( "p_{T}=%.1f GeV, #eta=%0.2f, #varphi=%0.2f",
00269 track1->pt(), track1->eta(), track1->phi()));
00270 y -= lineH;
00271 const reco::HitPattern& p_tk1 = track1->hitPattern();
00272 int nvalid_tk1=0, ninvalid_tk1=0, npix_tk1=0, nstrip_tk1=0;
00273 for(int i_tk1=0; i_tk1<p_tk1.numberOfHits(); i_tk1++) {
00274 uint32_t hit = p_tk1.getHitPattern(i_tk1);
00275 if(p_tk1.validHitFilter(hit)) {
00276 nvalid_tk1++;
00277 if (p_tk1.pixelHitFilter(hit)) npix_tk1++;
00278 else if (p_tk1.stripHitFilter(hit)) nstrip_tk1++;
00279 } else ninvalid_tk1++;
00280 }
00281 latex->DrawLatex( x, y, Form( "valid hits: %i (pix. %i, str. %i)", nvalid_tk1, npix_tk1, nstrip_tk1) );
00282 y -= lineH;
00283 latex->DrawLatex( x, y, Form( "invalid: %i", ninvalid_tk1) );
00284 y -= lineH;
00285 const reco::HitPattern& p_mhi_tk1 = track1->trackerExpectedHitsInner();
00286 int npix_mhi_tk1=0, nstrip_mhi_tk1=0;
00287 for(int i_mhi_tk1=0; i_mhi_tk1<p_mhi_tk1.numberOfHits(); i_mhi_tk1++) {
00288 uint32_t hit = p_mhi_tk1.getHitPattern(i_mhi_tk1);
00289 if (p_mhi_tk1.pixelHitFilter(hit)) npix_mhi_tk1++;
00290 else if (p_mhi_tk1.stripHitFilter(hit)) nstrip_mhi_tk1++;
00291 }
00292 latex->DrawLatex( x, y, Form("miss. inner hits: pix. %i, str. %i", npix_mhi_tk1, nstrip_mhi_tk1) );
00293 y -= lineH;
00294 y -= lineH;
00295
00296 latex->DrawLatex( x, y, "Placeholder for symbol legend");
00297 y -= lineH;
00298 latex->DrawLatex( x, y, "and projection buttons");
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
00346 void
00347 FWConvTrackHitsDetailView::makeLegend( void )
00348 {
00349 m_legend = new TLegend( 0.01, 0.01, 0.99, 0.99, 0, "NDC" );
00350 m_legend->SetFillColor(kWhite);
00351 m_legend->SetTextSize( 0.07 );
00352 m_legend->SetBorderSize( 0 );
00353 m_legend->SetMargin( 0.15 );
00354 m_legend->SetEntrySeparation( 0.01 );
00355
00356 TEveStraightLineSet *legend = new TEveStraightLineSet( "siStripCluster" );
00357 legend->SetLineWidth( 3 );
00358 legend->SetLineColor( kGreen );
00359 m_legend->AddEntry( legend, "Exact SiStripCluster", "l");
00360
00361 TEveStraightLineSet *legend2 = new TEveStraightLineSet( "siStripCluster2" );
00362 legend2->SetLineWidth( 3 );
00363 legend2->SetLineColor( kRed );
00364 m_legend->AddEntry( legend2, "Extra SiStripCluster", "l");
00365
00366 TEveStraightLineSet *legend3 = new TEveStraightLineSet( "refStates" );
00367 legend3->SetDepthTest( kFALSE );
00368 legend3->SetMarkerColor( kYellow );
00369 legend3->SetMarkerStyle( kPlus );
00370 legend3->SetMarkerSize( 2 );
00371 m_legend->AddEntry( legend3, "Inner/Outermost States", "p");
00372
00373 TEveStraightLineSet *legend4 = new TEveStraightLineSet( "vertex" );
00374 legend4->SetDepthTest( kFALSE );
00375 legend4->SetMarkerColor( kRed );
00376 legend4->SetMarkerStyle( kFullDotLarge );
00377 legend4->SetMarkerSize( 2 );
00378 m_legend->AddEntry( legend4, "Vertex", "p");
00379
00380 TEveStraightLineSet *legend5 = new TEveStraightLineSet( "cameraCenter" );
00381 legend5->SetDepthTest( kFALSE );
00382 legend5->SetMarkerColor( kCyan );
00383 legend5->SetMarkerStyle( kFullDotLarge );
00384 legend5->SetMarkerSize( 2 );
00385 m_legend->AddEntry( legend5, "Camera center", "p");
00386 }
00387
00388 void
00389 FWConvTrackHitsDetailView::addTrackerHits3D( std::vector<TVector3> &points, class TEveElementList *tList, Color_t color, int size )
00390 {
00391
00392
00393
00394 TEvePointSet* pointSet = new TEvePointSet();
00395 pointSet->SetMarkerSize(size);
00396 pointSet->SetMarkerStyle(4);
00397 pointSet->SetPickable(kTRUE);
00398 pointSet->SetTitle("Pixel Hits");
00399 pointSet->SetMarkerColor(color);
00400
00401 for( std::vector<TVector3>::const_iterator it = points.begin(), itEnd = points.end(); it != itEnd; ++it) {
00402 pointSet->SetNextPoint(it->x(), it->y(), it->z());
00403 }
00404 tList->AddElement(pointSet);
00405 }
00406
00407 void
00408 FWConvTrackHitsDetailView::addHits( const reco::Track& track,
00409 const FWEventItem* iItem,
00410 TEveElement* trkList,
00411 bool addNearbyHits )
00412 {
00413 std::vector<TVector3> pixelPoints;
00414 fireworks::pushPixelHits( pixelPoints, *iItem, track );
00415 TEveElementList* pixels = new TEveElementList( "Pixels" );
00416 trkList->AddElement( pixels );
00417 if( addNearbyHits )
00418 {
00419
00420 std::vector<TVector3> pixelExtraPoints;
00421 fireworks::pushNearbyPixelHits( pixelExtraPoints, *iItem, track );
00422
00423 addTrackerHits3D( pixelExtraPoints, pixels, kRed, 1 );
00424
00425 addTrackerHits3D( pixelPoints, pixels, kGreen, 1 );
00426 }
00427 else
00428 {
00429
00430 addTrackerHits3D( pixelPoints, pixels, iItem->defaultDisplayProperties().color(), 1 );
00431 }
00432
00433
00434 TEveElementList* strips = new TEveElementList( "Strips" );
00435 trkList->AddElement( strips );
00436 fireworks::addSiStripClusters( iItem, track, strips, addNearbyHits, false );
00437 }
00438
00439
00440
00441 void
00442 FWConvTrackHitsDetailView::addModules( const reco::Track& track,
00443 const FWEventItem* iItem,
00444 TEveElement* trkList,
00445 bool addLostHits )
00446 {
00447 std::set<unsigned int> ids;
00448 for( trackingRecHit_iterator recIt = track.recHitsBegin(), recItEnd = track.recHitsEnd();
00449 recIt != recItEnd; ++recIt )
00450 {
00451 DetId detid = (*recIt)->geographicalId();
00452 if( !addLostHits && !(*recIt)->isValid()) continue;
00453 if( detid.rawId() != 0 )
00454 {
00455 TString name("");
00456 switch( detid.det())
00457 {
00458 case DetId::Tracker:
00459 switch( detid.subdetId())
00460 {
00461 case SiStripDetId::TIB:
00462 name = "TIB ";
00463 break;
00464 case SiStripDetId::TOB:
00465 name = "TOB ";
00466 break;
00467 case SiStripDetId::TID:
00468 name = "TID ";
00469 break;
00470 case SiStripDetId::TEC:
00471 name = "TEC ";
00472 break;
00473 case PixelSubdetector::PixelBarrel:
00474 name = "Pixel Barrel ";
00475 break;
00476 case PixelSubdetector::PixelEndcap:
00477 name = "Pixel Endcap ";
00478 default:
00479 break;
00480 }
00481 break;
00482
00483 case DetId::Muon:
00484 switch( detid.subdetId())
00485 {
00486 case MuonSubdetId::DT:
00487 name = "DT";
00488 detid = DetId( DTChamberId( detid ));
00489 break;
00490 case MuonSubdetId::CSC:
00491 name = "CSC";
00492 break;
00493 case MuonSubdetId::RPC:
00494 name = "RPC";
00495 break;
00496 default:
00497 break;
00498 }
00499 break;
00500 default:
00501 break;
00502 }
00503 if( ! ids.insert( detid.rawId()).second ) continue;
00504 if( iItem->getGeom())
00505 {
00506 TEveGeoShape* shape = iItem->getGeom()->getEveShape( detid );
00507 if( 0 != shape )
00508 {
00509 shape->SetMainTransparency( 65 );
00510 shape->SetPickable( kTRUE );
00511 switch(( *recIt )->type())
00512 {
00513 case TrackingRecHit::valid:
00514 shape->SetMainColor( iItem->defaultDisplayProperties().color());
00515 break;
00516 case TrackingRecHit::missing:
00517 name += "LOST ";
00518 shape->SetMainColor( kRed );
00519 break;
00520 case TrackingRecHit::inactive:
00521 name += "INACTIVE ";
00522 shape->SetMainColor( 28 );
00523 break;
00524 case TrackingRecHit::bad:
00525 name += "BAD ";
00526 shape->SetMainColor( 218 );
00527 break;
00528 }
00529 shape->SetTitle( name + ULong_t( detid.rawId()));
00530 trkList->AddElement( shape );
00531 }
00532 else
00533 {
00534 fwLog( fwlog::kInfo ) << "Failed to get shape extract for a tracking rec hit: "
00535 << "\n" << fireworks::info( detid ) << std::endl;
00536 }
00537 }
00538 }
00539 }
00540 }
00541
00542 void
00543 FWConvTrackHitsDetailView::rnrLabels()
00544 {
00545 m_moduleLabels->SetRnrChildren(!m_moduleLabels->GetRnrChildren());
00546 gEve->Redraw3D();
00547 }
00548
00549 REGISTER_FWDETAILVIEW(FWConvTrackHitsDetailView, Conversion);