CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/Fireworks/Electrons/plugins/FWConvTrackHitsDetailView.cc

Go to the documentation of this file.
00001 
00002 #define protected public
00003 #include "TGLViewer.h" // access to over-all bounding box
00004 #include "TEveCalo.h" // workaround for TEveCalo3D bounding box
00005 #undef protected
00006 #include "TGLFontManager.h"
00007 #include "TEveScene.h"
00008 #include "TEveManager.h"
00009 #include "TEveStraightLineSet.h"
00010 #include "TEveTrack.h"
00011 #include "TEveTrackPropagator.h"
00012 #include "TEveTrans.h"
00013 #include "TEveText.h"
00014 #include "TEveGeoShape.h"
00015 #include "TGSlider.h"
00016 #include "TGButton.h"
00017 #include "TGLabel.h"
00018 #include "TCanvas.h"
00019 #include "TLatex.h"
00020 #include "TLegend.h"
00021 #include "TG3DLine.h"
00022 #include "TEveCaloData.h"
00023 
00024 // CMSSW includes
00025 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
00026 #include "DataFormats/TrackReco/interface/Track.h"
00027 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00028 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
00029 
00030 // Fireworks includes
00031 #include "Fireworks/Core/interface/FWModelId.h"
00032 #include "Fireworks/Core/interface/FWColorManager.h"
00033 #include "Fireworks/Core/interface/FWGeometry.h"
00034 #include "Fireworks/Core/interface/FWEventItem.h"
00035 #include "Fireworks/Core/interface/CSGAction.h"
00036 #include "Fireworks/Core/interface/FWMagField.h"
00037 #include "Fireworks/Core/interface/FWBeamSpot.h"
00038 #include "Fireworks/Core/interface/fwLog.h"
00039 #include "Fireworks/Calo/interface/FWECALDetailViewBuilder.h"
00040 
00041 #include "Fireworks/Electrons/plugins/FWConvTrackHitsDetailView.h"
00042 #include "DataFormats/EgammaCandidates/interface/Conversion.h"
00043 #include "Fireworks/Tracks/interface/TrackUtils.h"
00044 
00045 namespace {
00046 void (FWConvTrackHitsDetailView::*foo)();
00047 }
00048 
00049 FWConvTrackHitsDetailView::FWConvTrackHitsDetailView ():
00050   m_modules(0),
00051   m_moduleLabels(0),
00052   m_hits(0),
00053   m_legend(0),
00054   m_orthographic(false)
00055 {
00056 }
00057 
00058 FWConvTrackHitsDetailView::~FWConvTrackHitsDetailView ()
00059 {
00060 }
00061 
00062 namespace {
00063 void setCameraInit(TGLViewer* v, TGLViewer::ECameraType type, const TEveVectorD b1, TEveVectorD b3, TEveVector center )
00064 { 
00065    TGLCamera& cam = v->RefCamera(type); 
00066    TGLMatrix& trans = cam.RefCamBase();
00067 
00068    trans.Set(trans.GetTranslation(), b3.Arr(), b1.Arr());
00069    cam.Setup(v->fOverallBoundingBox, kTRUE);
00070   
00071    cam.SetExternalCenter(true);
00072    cam.SetCenterVec(center.fX, center.fY, center.fZ);
00073 }
00074    
00075    /*
00076     // alternative to setCameraInit
00077 void setCamera(TGLViewer* v, TGLViewer::ECameraType type, const TEveVectorD b1, TEveVectorD b2,  TEveVectorD b3, TEveVector center )
00078 {
00079    // b1 = fwd, b2 = lft, b3 = up
00080 
00081    TGLCamera& cam = v->RefCamera(type); 
00082    TGLMatrix& trans = cam.RefCamBase();
00083    
00084    trans.SetBaseVec(1, b1.Arr());
00085    trans.SetBaseVec(2, b2.Arr());
00086    trans.SetBaseVec(3, b3.Arr());
00087 
00088    cam.SetExternalCenter(true);
00089    cam.SetCenterVec(center.fX, center.fY, center.fZ);
00090 }
00091     */
00092 }
00093 void
00094 FWConvTrackHitsDetailView::build (const FWModelId &id, const reco::Conversion* conv)
00095 {      
00096    if (conv->nTracks()<2) return;
00097    const reco::Track* track0 = conv->tracks().at(0).get();
00098    const reco::Track* track1 = conv->tracks().at(1).get();
00099    
00100    m_guiFrame->AddFrame(new TGLabel(m_guiFrame, "Camera Views:"), new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2)); 
00101 
00102    {
00103       TGHorizontalFrame* f = new TGHorizontalFrame(m_guiFrame);
00104       m_guiFrame->AddFrame(f,  new TGLayoutHints(kLHintsExpandX, 2, 0, 0, 0));
00105       
00106       {
00107          CSGAction* action = new CSGAction(this, "Top");
00108         TGTextButton* b = new TGTextButton(f,  action->getName().c_str());
00109          f->AddFrame(b, new TGLayoutHints( kLHintsExpandX));
00110          TQObject::Connect(b, "Clicked()", "CSGAction", action, "activate()");
00111          b->SetToolTipText("plane normal: track0 x track1");
00112          action->activated.connect(sigc::mem_fun(this, &FWConvTrackHitsDetailView::camera1Callback));
00113       }
00114 
00115       {
00116          CSGAction* action = new CSGAction(this, "Side");
00117          TGTextButton* b = new TGTextButton(f,  action->getName().c_str());
00118          f->AddFrame(b, new TGLayoutHints( kLHintsExpandX));
00119          TQObject::Connect(b, "Clicked()", "CSGAction", action, "activate()");
00120          b->SetToolTipText("left fir: track1");
00121          action->activated.connect(sigc::mem_fun(this, &FWConvTrackHitsDetailView::camera2Callback));
00122       } 
00123       {
00124          CSGAction* action = new CSGAction(this, "Front");
00125          TGTextButton* b = new TGTextButton(f,  action->getName().c_str());
00126          f->AddFrame(b, new TGLayoutHints( kLHintsExpandX));
00127          TQObject::Connect(b, "Clicked()", "CSGAction", action, "activate()");
00128          action->activated.connect(sigc::mem_fun(this, &FWConvTrackHitsDetailView::camera3Callback));
00129          b->SetToolTipText("plane normal: track1 ");
00130 
00131       }
00132    }
00133    
00134    {
00135       m_camTypeAction = new CSGAction(this, " Set Ortographic Projection ");
00136       m_camTypeAction->createTextButton(m_guiFrame, new TGLayoutHints( kLHintsExpandX, 2, 0, 1, 4));
00137       m_camTypeAction->activated.connect(sigc::mem_fun(this, &FWConvTrackHitsDetailView::switchProjection));
00138    }
00139    
00140    {
00141       CSGAction* action = new CSGAction(this, "Draw Module");
00142       TGCheckButton* b = new TGCheckButton(m_guiFrame, action->getName().c_str() );
00143       b->SetState(kButtonDown, false);
00144       m_guiFrame->AddFrame(b, new TGLayoutHints( kLHintsNormal, 2, 3, 1, 4));
00145       TQObject::Connect(b, "Clicked()", "CSGAction", action, "activate()");
00146       action->activated.connect(sigc::mem_fun(this, &FWConvTrackHitsDetailView::rnrModules));
00147    }
00148    {
00149       CSGAction* action = new CSGAction(this, "Draw Hits");
00150       TGCheckButton* b = new TGCheckButton(m_guiFrame, action->getName().c_str() );
00151       b->SetState(kButtonDown, false);
00152       m_guiFrame->AddFrame(b, new TGLayoutHints( kLHintsNormal, 2, 3, 1, 4));
00153       TQObject::Connect(b, "Clicked()", "CSGAction", action, "activate()");
00154       action->activated.connect(sigc::mem_fun(this, &FWConvTrackHitsDetailView::rnrHits));
00155    }
00156    
00157    TGCompositeFrame* p = (TGCompositeFrame*)m_guiFrame->GetParent();
00158    p->MapSubwindows();
00159    p->Layout();
00160 
00161    m_modules = new TEveElementList( "Modules" );
00162    m_eveScene->AddElement( m_modules );
00163    m_moduleLabels = new TEveElementList( "Modules" );
00164    m_eveScene->AddElement( m_moduleLabels );
00165    m_hits = new TEveElementList( "Hits" );
00166    m_eveScene->AddElement( m_hits );
00167    if( track1->extra().isAvailable())
00168    {
00169       addModules( *track1, id.item(), m_modules, true );
00170       addHits( *track1, id.item(), m_hits, true );
00171    }
00172    if( track0->extra().isAvailable())
00173    {
00174       addModules( *track0, id.item(), m_modules, true );
00175       addHits( *track0, id.item(), m_hits, true );
00176    }
00177    for( TEveElement::List_i i = m_modules->BeginChildren(), end = m_modules->EndChildren(); i != end; ++i )
00178    {
00179       TEveGeoShape* gs = dynamic_cast<TEveGeoShape*>(*i);
00180       if (gs == 0 && (*i != 0)) {
00181          std::cerr << "Got a " << typeid(**i).name() << ", expecting TEveGeoShape. ignoring (it must be the clusters)." << std::endl;
00182          continue;
00183       }
00184      // gs->SetMainTransparency(75);
00185      // gs->SetPickable(kFALSE);
00186 
00187       TString name = gs->GetElementTitle();
00188       if (!name.Contains("BAD") && !name.Contains("INACTIVE") && !name.Contains("LOST")) {
00189          gs->SetMainColor(kBlue);
00190       }
00191       TEveText* text = new TEveText(name.Data());
00192       text->PtrMainTrans()->SetFrom(gs->RefMainTrans().Array());
00193       text->SetFontMode(TGLFont::kPixmap);
00194       text->SetFontSize(12);
00195       m_moduleLabels->AddElement(text); 
00196    }
00197    m_moduleLabels->SetRnrChildren(false);
00198 
00199    TEveTrackPropagator* prop = new TEveTrackPropagator();
00200    prop->SetMagFieldObj(item()->context().getField(), false);
00201    prop->SetStepper(TEveTrackPropagator::kRungeKutta);
00202    prop->SetMaxR(123);
00203    prop->SetMaxZ(300);
00204    prop->SetMaxStep(1);
00205    prop->SetRnrDaughters(kTRUE);
00206    prop->SetRnrReferences(kTRUE);
00207    prop->SetRnrDecay(kTRUE);
00208    
00209    // first-vertex style
00210    prop->SetRnrFV(kTRUE);
00211    prop->RefFVAtt().SetMarkerColor(id.item()->defaultDisplayProperties().color());
00212    prop->RefFVAtt().SetMarkerSize(0.8);
00213 
00214    // path-mark style
00215    prop->RefPMAtt().SetMarkerSize(0.5);
00216    prop->RefPMAtt().SetMarkerColor(id.item()->defaultDisplayProperties().color());
00217 
00218    TEveTrack* trk1 = fireworks::prepareTrack( *track1, prop );
00219    trk1->MakeTrack();
00220    trk1->SetLineWidth(2);
00221    trk1->SetTitle( "Track 1 and its ref states" );
00222    trk1->SetMainColor(id.item()->defaultDisplayProperties().color());
00223    trk1->SetLineStyle(7);
00224    m_eveScene->AddElement(trk1);
00225 
00226    TEveTrack* trk0 = fireworks::prepareTrack( *track0, prop );
00227    trk0->MakeTrack();
00228    trk0->SetLineWidth(2);
00229    trk0->SetTitle( "Track 0 and its ref states" );
00230    trk0->SetMainColor(id.item()->defaultDisplayProperties().color());
00231    m_eveScene->AddElement(trk0);
00232    
00233    // create TEveCalo3D object, fix bounding box
00234    {
00235       float phi = conv->pairMomentum().phi();
00236       float eta = conv->pairMomentum().eta();
00237       
00238       FWECALDetailViewBuilder caloBld( id.item()->getEvent(), id.item()->getGeom(), eta, phi, 30);
00239       TEveCaloData* data = caloBld.buildCaloData(false);
00240        // AMT!!! this is mempry leak, check why it needs to be added
00241       TEveCalo3D* calo3d = new TEveCalo3D(data);
00242       gEve->AddElement(data);
00243       calo3d->SetBarrelRadius(129.00);
00244       calo3d->SetEndCapPos(268.36);
00245       
00246       float theta = TEveCaloData::EtaToTheta(eta);
00247       float eps = data->GetMaxVal(true) * calo3d->GetValToHeight();
00248       if (TMath::Abs(eta) < calo3d->GetTransitionEta())
00249       {
00250         // printf("barrel\n");
00251          float x =   calo3d->GetBarrelRadius() * TMath::Cos(phi);
00252          float y =   calo3d->GetBarrelRadius() * TMath::Sin(phi);
00253          float z =   calo3d->GetBarrelRadius() / TMath::Tan(theta); 
00254          
00255          calo3d->BBoxZero(eps, x, y, z);
00256       }
00257       else
00258       {
00259        //  printf("endcap\n");
00260          float z  = TMath::Sign(calo3d->GetEndCapPos(), eta);
00261          float r =   z*TMath::Tan(theta);
00262          calo3d->BBoxZero(eps, r* TMath::Cos(phi), r*TMath::Sin(phi), z);
00263       }
00264       m_eveScene->AddElement(calo3d);
00265    }
00266    
00267    //  base vectors
00268    TEveVectorD fwd = trk1->GetMomentum().Cross(trk0->GetMomentum());
00269    fwd.Normalize();
00270    TEveVectorD lft =trk1->GetMomentum();
00271    lft.Normalize();
00272    TEveVectorD up = lft.Cross(fwd);
00273 
00274    
00275    TEveVectorD c  = ( trk1->GetVertex() + trk0->GetVertex()) *0.5;
00276    if (1)
00277    { 
00278       setCameraInit(viewerGL(),TGLViewer::kCameraPerspXOZ, fwd, up, c); //default
00279       setCameraInit(viewerGL(),TGLViewer::kCameraPerspYOZ, up,  lft,c);
00280       setCameraInit(viewerGL(),TGLViewer::kCameraPerspXOY, lft, fwd,c);
00281 
00282       setCameraInit(viewerGL(),TGLViewer::kCameraOrthoXOY, fwd,  up,c);
00283       setCameraInit(viewerGL(),TGLViewer::kCameraOrthoXOZ, up, lft,c);
00284       setCameraInit(viewerGL(),TGLViewer::kCameraOrthoZOY, lft, fwd,c); 
00285    }
00286    {
00287       Float_t sfac = 100;
00288       fwd *= sfac;
00289       lft *= sfac;
00290       up  *= sfac;
00291       int transp = 90;
00292       {
00293          TEveStraightLineSet* bls = new TEveStraightLineSet("base1");
00294          bls->AddLine(c, fwd + c);
00295          bls->SetMainColor(kBlue);
00296          bls->SetMainTransparency(transp);
00297          bls->SetPickable(false);
00298          m_eveScene->AddElement(bls);
00299       }
00300 
00301       {
00302          TEveStraightLineSet* bls = new TEveStraightLineSet("base2");
00303          bls->AddLine(c, lft + c);
00304          bls->SetMainColor(kBlue);
00305          bls->SetMainTransparency(transp);
00306          bls->SetPickable(false);
00307          m_eveScene->AddElement(bls);
00308       }
00309 
00310       {
00311          TEveStraightLineSet* bls = new TEveStraightLineSet("base3");
00312          bls->AddLine(c, up + c);
00313          bls->SetMainColor(kBlue);
00314          bls->SetMainTransparency(transp);
00315          bls->SetPickable(false);
00316          m_eveScene->AddElement(bls);
00317       }
00318    }
00319    {
00320       TEveStraightLineSet* bls = new TEveStraightLineSet("Photon", "Photon");
00321       FWBeamSpot* bs =  context().getBeamSpot();
00322       bls->AddLine(c.fX, c.fY, c.fZ, bs->x0(), bs->y0(), bs->z0());
00323       bls->SetMainColor(id.item()->defaultDisplayProperties().color());
00324       bls->SetLineStyle(3);
00325       m_eveScene->AddElement(bls);
00326    }
00327    
00328    viewerGL()->SetStyle(TGLRnrCtx::kOutline);
00329    viewerGL()->ResetCamerasAfterNextUpdate();
00330    viewerGL()->UpdateScene(kFALSE);
00331    gEve->Redraw3D();
00332    
00333    setTextInfo(id, conv);
00334    foo = &FWConvTrackHitsDetailView::camera1Callback; 
00335 }
00336 
00337 void
00338 FWConvTrackHitsDetailView::setTextInfo(const FWModelId &id, const reco::Conversion* conv)
00339 {
00340    m_infoCanvas->cd();
00341 
00342    float_t x  = 0.02;
00343    float   y  = 0.95;
00344 
00345    TLatex* latex = new TLatex( x, y, "" );
00346    const double textsize( 0.07 );
00347    latex->SetTextSize( 2*textsize );
00348 
00349    latex->DrawLatex( x, y, id.item()->modelName( id.index()).c_str());
00350    y -= latex->GetTextSize()*0.6;
00351 
00352    latex->SetTextSize( textsize );
00353    float lineH = latex->GetTextSize()*0.6;
00354 
00355    latex->DrawLatex( x, y, Form("p_{T}=%.1f GeV, #eta=%0.2f, #varphi=%0.2f",
00356                                 sqrt(conv->pairMomentum().Perp2()), conv->pairMomentum().eta(), conv->pairMomentum().phi() ));
00357    y -= lineH;
00358    latex->DrawLatex( x, y, Form("vtx=(%.1f, %.1f, %.1f) r=%.1f [cm]",
00359                                 conv->conversionVertex().x(), conv->conversionVertex().y(), conv->conversionVertex().z(), 
00360                                 conv->conversionVertex().position().rho() ));
00361    y -= lineH;
00362    latex->DrawLatex( x, y, Form("#Deltactg#theta=%.3f",
00363                                 conv->pairCotThetaSeparation() ));
00364    y -= lineH;
00365    latex->DrawLatex( x, y, Form("#Delta#phi_{vtx}=%.3f",
00366                                 conv->dPhiTracksAtVtx() ));
00367    y -= lineH;
00368    latex->DrawLatex( x, y, Form("dist. min. app.=%.3f cm",
00369                                 conv->distOfMinimumApproach() ));
00370    y -= lineH;
00371    y -= lineH;
00372 
00373 
00374    const reco::Track* track0 = conv->tracks().at(0).get();
00375    latex->DrawLatex( x, y, Form("Trk0 q=%i",track0->charge()));
00376    y -= lineH;
00377    latex->DrawLatex( x, y, Form( "p_{T}=%.1f GeV, #eta=%0.2f, #varphi=%0.2f",
00378                                  track0->pt(), track0->eta(), track0->phi()));
00379    y -= lineH;
00380    const reco::HitPattern& p_tk0 = track0->hitPattern();
00381    int nvalid_tk0=0, ninvalid_tk0=0, npix_tk0=0, nstrip_tk0=0;
00382    for(int i_tk0=0; i_tk0<p_tk0.numberOfHits(); i_tk0++) {
00383      uint32_t hit = p_tk0.getHitPattern(i_tk0);
00384      if(p_tk0.validHitFilter(hit)) {
00385        nvalid_tk0++;
00386        if (p_tk0.pixelHitFilter(hit)) npix_tk0++;
00387        else if (p_tk0.stripHitFilter(hit)) nstrip_tk0++;
00388      } else ninvalid_tk0++;
00389    }
00390    latex->DrawLatex( x, y,  Form( "valid hits: %i (pix. %i, str. %i)", nvalid_tk0, npix_tk0, nstrip_tk0) );
00391    y -= lineH;
00392    latex->DrawLatex( x, y,  Form( "invalid: %i", ninvalid_tk0) );
00393    y -= lineH;
00394    const reco::HitPattern& p_mhi_tk0 = track0->trackerExpectedHitsInner();
00395    int npix_mhi_tk0=0, nstrip_mhi_tk0=0;
00396    for(int i_mhi_tk0=0; i_mhi_tk0<p_mhi_tk0.numberOfHits(); i_mhi_tk0++) {
00397      uint32_t hit = p_mhi_tk0.getHitPattern(i_mhi_tk0);
00398      if (p_mhi_tk0.pixelHitFilter(hit)) npix_mhi_tk0++;
00399      else if (p_mhi_tk0.stripHitFilter(hit)) nstrip_mhi_tk0++;
00400    }
00401    latex->DrawLatex( x, y,  Form("miss. inner hits: pix. %i, str. %i", npix_mhi_tk0, nstrip_mhi_tk0) );
00402 
00403    y -= lineH;
00404    y -= lineH;
00405    const reco::Track* track1 = conv->tracks().at(1).get();
00406    latex->DrawLatex( x, y, Form("Trk1 q=%i",track1->charge()));
00407    y -= lineH;
00408    latex->DrawLatex( x, y, Form( "p_{T}=%.1f GeV, #eta=%0.2f, #varphi=%0.2f",
00409                                  track1->pt(), track1->eta(), track1->phi()));
00410    y -= lineH;
00411    const reco::HitPattern& p_tk1 = track1->hitPattern();
00412    int nvalid_tk1=0, ninvalid_tk1=0, npix_tk1=0, nstrip_tk1=0;
00413    for(int i_tk1=0; i_tk1<p_tk1.numberOfHits(); i_tk1++) {
00414      uint32_t hit = p_tk1.getHitPattern(i_tk1);
00415      if(p_tk1.validHitFilter(hit)) {
00416        nvalid_tk1++;
00417        if (p_tk1.pixelHitFilter(hit)) npix_tk1++;
00418        else if (p_tk1.stripHitFilter(hit)) nstrip_tk1++;
00419      } else ninvalid_tk1++;
00420    }
00421    latex->DrawLatex( x, y,  Form( "valid hits: %i (pix. %i, str. %i)", nvalid_tk1, npix_tk1, nstrip_tk1) );
00422    y -= lineH;
00423    latex->DrawLatex( x, y,  Form( "invalid: %i", ninvalid_tk1) );
00424    y -= lineH;
00425    const reco::HitPattern& p_mhi_tk1 = track1->trackerExpectedHitsInner();
00426    int npix_mhi_tk1=0, nstrip_mhi_tk1=0;
00427    for(int i_mhi_tk1=0; i_mhi_tk1<p_mhi_tk1.numberOfHits(); i_mhi_tk1++) {
00428      uint32_t hit = p_mhi_tk1.getHitPattern(i_mhi_tk1);
00429      if (p_mhi_tk1.pixelHitFilter(hit)) npix_mhi_tk1++;
00430      else if (p_mhi_tk1.stripHitFilter(hit)) nstrip_mhi_tk1++;
00431    }
00432    latex->DrawLatex( x, y,  Form("miss. inner hits: pix. %i, str. %i", npix_mhi_tk1, nstrip_mhi_tk1) );
00433    y -= lineH;
00434    y -= lineH;
00435 }
00436 
00437 
00438 void
00439 FWConvTrackHitsDetailView::addTrackerHits3D( std::vector<TVector3> &points, class TEveElementList *tList, Color_t color, int size ) 
00440 {
00441    // !AMT this is  detail view specific, should move to track hits
00442    // detail view
00443 
00444    TEvePointSet* pointSet = new TEvePointSet();
00445    pointSet->SetMarkerSize(size);
00446    pointSet->SetMarkerStyle(4);
00447    pointSet->SetPickable(kTRUE);
00448    pointSet->SetTitle("Pixel Hits");
00449    pointSet->SetMarkerColor(color);
00450                 
00451    for( std::vector<TVector3>::const_iterator it = points.begin(), itEnd = points.end(); it != itEnd; ++it) {
00452       pointSet->SetNextPoint(it->x(), it->y(), it->z());
00453    }
00454    tList->AddElement(pointSet);
00455 }
00456 
00457 void
00458 FWConvTrackHitsDetailView::addHits( const reco::Track& track,
00459                                 const FWEventItem* iItem,
00460                                 TEveElement* trkList,
00461                                 bool addNearbyHits )
00462 {
00463    std::vector<TVector3> pixelPoints;
00464    fireworks::pushPixelHits( pixelPoints, *iItem, track );
00465    TEveElementList* pixels = new TEveElementList( "Pixels" );
00466    trkList->AddElement( pixels );
00467    if( addNearbyHits )
00468    {
00469       // get the extra hits
00470       std::vector<TVector3> pixelExtraPoints;
00471       fireworks::pushNearbyPixelHits( pixelExtraPoints, *iItem, track );
00472       // draw first the others
00473       addTrackerHits3D( pixelExtraPoints, pixels, kRed, 1 );
00474       // then the good ones, so they're on top
00475       addTrackerHits3D( pixelPoints, pixels, kGreen, 1 );
00476    }
00477    else
00478    {
00479       // just add those points with the default color
00480       addTrackerHits3D( pixelPoints, pixels, iItem->defaultDisplayProperties().color(), 1 );
00481    }
00482 
00483    // strips
00484    TEveElementList* strips = new TEveElementList( "Strips" );
00485    trkList->AddElement( strips );
00486    fireworks::addSiStripClusters( iItem, track, strips, addNearbyHits, false );
00487 }
00488 
00489 //______________________________________________________________________________
00490 
00491 void
00492 FWConvTrackHitsDetailView::addModules( const reco::Track& track,
00493                                    const FWEventItem* iItem,
00494                                    TEveElement* trkList,
00495                                    bool addLostHits )
00496 {
00497    std::set<unsigned int> ids;
00498    for( trackingRecHit_iterator recIt = track.recHitsBegin(), recItEnd = track.recHitsEnd();
00499         recIt != recItEnd; ++recIt )
00500    {
00501       DetId detid = (*recIt)->geographicalId();
00502       if( !addLostHits && !(*recIt)->isValid()) continue;
00503       if( detid.rawId() != 0 )
00504       {
00505          TString name("");
00506          switch( detid.det())
00507          {
00508          case DetId::Tracker:
00509             switch( detid.subdetId())
00510             {
00511             case SiStripDetId::TIB:
00512                name = "TIB ";
00513                break;
00514             case SiStripDetId::TOB:
00515                name = "TOB ";
00516                break;
00517             case SiStripDetId::TID:
00518                name = "TID ";
00519                break;
00520             case SiStripDetId::TEC:
00521                name = "TEC ";
00522                break;
00523             case PixelSubdetector::PixelBarrel:
00524                name = "Pixel Barrel ";
00525                break;
00526             case PixelSubdetector::PixelEndcap:
00527                name = "Pixel Endcap ";
00528             default:
00529                break;
00530             }
00531             break;
00532             
00533          case DetId::Muon:
00534             switch( detid.subdetId())
00535             {
00536             case MuonSubdetId::DT:
00537                name = "DT";
00538                detid = DetId( DTChamberId( detid )); // get rid of layer bits
00539                break;
00540             case MuonSubdetId::CSC:
00541                name = "CSC";
00542                break;
00543             case MuonSubdetId::RPC:
00544                name = "RPC";
00545                break;
00546             default:
00547                break;
00548             }
00549             break;
00550          default:
00551             break;
00552          }
00553          if( ! ids.insert( detid.rawId()).second ) continue;
00554          if( iItem->getGeom())
00555          {
00556             TEveGeoShape* shape = iItem->getGeom()->getEveShape( detid );
00557             if( 0 != shape )
00558             {
00559                shape->SetMainTransparency( 65 );
00560                shape->SetPickable( kTRUE );
00561                switch(( *recIt )->type())
00562                {
00563                case TrackingRecHit::valid:
00564                   shape->SetMainColor( iItem->defaultDisplayProperties().color());
00565                   break;
00566                case TrackingRecHit::missing:
00567                   name += "LOST ";
00568                   shape->SetMainColor( kRed );
00569                   break;
00570                case TrackingRecHit::inactive:
00571                   name += "INACTIVE ";
00572                   shape->SetMainColor( 28 );
00573                   break;
00574                case TrackingRecHit::bad:
00575                   name += "BAD ";
00576                   shape->SetMainColor( 218 );
00577                   break;
00578                }
00579                shape->SetTitle( name + ULong_t( detid.rawId()));
00580                trkList->AddElement( shape );
00581             }
00582             else
00583             {
00584                fwLog( fwlog::kInfo ) <<  "Failed to get shape extract for a tracking rec hit: "
00585                                      << "\n" << fireworks::info( detid ) << std::endl;
00586             }
00587          }
00588       }
00589    }
00590 }
00591 
00592 //______________________________________________________________________________
00593 void
00594 FWConvTrackHitsDetailView::pickCameraCenter()
00595 {
00596    viewerGL()->PickCameraCenter();
00597    viewerGL()->SetDrawCameraCenter(kTRUE);
00598 }
00599 
00600 void
00601 FWConvTrackHitsDetailView::switchProjection()
00602 {   
00603    m_orthographic = !m_orthographic;
00604    m_camTypeAction->setName(m_orthographic ? "Set Perspective Projection" : "Set Orthographic Projection");
00605    
00606    (this->*foo) ();
00607    //printf("current isOrthographic : %d \n",  viewerGL()->CurrentCamera().IsOrthographic());
00608 }
00609 
00610 
00611 void
00612 FWConvTrackHitsDetailView::rnrLabels()
00613 {
00614    m_moduleLabels->SetRnrChildren(!m_moduleLabels->GetRnrChildren());
00615    gEve->Redraw3D();
00616 }
00617 
00618 void
00619 FWConvTrackHitsDetailView::rnrModules()
00620 {
00621    m_modules->SetRnrChildren(!m_modules->GetRnrChildren());
00622    gEve->Redraw3D();
00623 }
00624 
00625 void
00626 FWConvTrackHitsDetailView::rnrHits()
00627 {
00628    m_hits->SetRnrChildren(!m_hits->GetRnrChildren());
00629    gEve->Redraw3D();
00630 }
00631 
00632 
00633 void FWConvTrackHitsDetailView::camera1Callback()
00634 {
00635    foo = &FWConvTrackHitsDetailView::camera1Callback; 
00636    
00637    viewerGL()->SetCurrentCamera(m_orthographic ? TGLViewer::kCameraOrthoXOY : TGLViewer::kCameraPerspXOZ);
00638    viewerGL()->ResetCurrentCamera();
00639    viewerGL()->RequestDraw();
00640 }
00641 
00642 void FWConvTrackHitsDetailView::camera2Callback()
00643 {
00644    foo = &FWConvTrackHitsDetailView::camera2Callback; 
00645    
00646    viewerGL()->SetCurrentCamera( m_orthographic ? TGLViewer::kCameraOrthoXOZ : TGLViewer::kCameraPerspYOZ);
00647    viewerGL()->ResetCurrentCamera();
00648    viewerGL()->RequestDraw();
00649 
00650 }
00651 
00652 void FWConvTrackHitsDetailView::camera3Callback()
00653 {
00654    foo = &FWConvTrackHitsDetailView::camera3Callback; 
00655 
00656    viewerGL()->SetCurrentCamera(m_orthographic ? TGLViewer::kCameraOrthoZOY : TGLViewer::kCameraPerspXOY);
00657    viewerGL()->ResetCurrentCamera();
00658    viewerGL()->RequestDraw();
00659 
00660 }
00661 
00662 
00663 REGISTER_FWDETAILVIEW(FWConvTrackHitsDetailView, Conversion);