CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/Fireworks/Calo/src/FWTauProxyBuilderBase.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Calo
00004 // Class  :     FWTauProxyBuilderBase
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  Alja Mrak-Tadel
00010 //         Created:  Thu Oct 21 20:40:28 CEST 2010
00011 // $Id: FWTauProxyBuilderBase.cc,v 1.5 2012/03/23 00:08:29 amraktad Exp $
00012 //
00013 
00014 // system include files
00015 
00016 // user include files
00017 #include "TGeoTube.h"
00018 #include "TEveJetCone.h"
00019 #include "TEveGeoNode.h"
00020 #include "TEveScalableStraightLineSet.h"
00021 #include "TEveTrack.h"
00022 
00023 #include "Fireworks/Calo/interface/FWTauProxyBuilderBase.h"
00024 #include "Fireworks/Calo/interface/makeEveJetCone.h"
00025 #include "Fireworks/Core/interface/Context.h"
00026 #include "Fireworks/Calo/interface/thetaBins.h"
00027 #include "Fireworks/Core/interface/BuilderUtils.h"
00028 #include "Fireworks/Core/interface/FWEventItem.h"
00029 #include "Fireworks/Core/interface/FWViewEnergyScale.h"
00030 
00031 #include "Fireworks/Tracks/interface/TrackUtils.h"
00032 
00033 #include "DataFormats/TauReco/interface/BaseTau.h"
00034 #include "DataFormats/TrackReco/interface/Track.h"
00035 
00036 
00037 FWTauProxyBuilderBase::FWTauProxyBuilderBase():
00038    m_minTheta(0),
00039    m_maxTheta(0)
00040 {
00041 }
00042 
00043 FWTauProxyBuilderBase::~FWTauProxyBuilderBase()
00044 {
00045 }
00046 
00047 void
00048 FWTauProxyBuilderBase::buildBaseTau( const reco::BaseTau& iTau, const reco::Jet* iJet, TEveElement* comp, FWViewType::EType type, const FWViewContext* vc)
00049 {
00050    // track
00051    addLeadTrack( iTau, comp );
00052    addConstituentTracks( iTau, comp );
00053  
00054    // projected markers
00055    if (FWViewType::isProjected(type))
00056    {
00057       double phi   = iTau.phi();
00058       double theta = iTau.theta();
00059       double size  = 1;
00060 
00061       bool  barrel = (theta< context().caloTransAngle() || theta > (TMath::Pi() - context().caloTransAngle()));
00062       float ecalR  = barrel ? context().caloR1() : context().caloR2();
00063       float ecalZ  = barrel ? context().caloZ1() : context().caloZ2();
00064   
00065       TEveScalableStraightLineSet* marker = new TEveScalableStraightLineSet( "energy" );
00066      
00067       if( type == FWViewType::kRhoZ )
00068       {
00069          double r(0);
00070          ( theta <  context().caloTransAngle() || M_PI-theta < context().caloTransAngle()) ?
00071             r = ecalZ/fabs(cos(theta)) :
00072             r = ecalR/sin(theta);
00073    
00074          fireworks::addRhoZEnergyProjection( this, comp, ecalR, ecalZ, m_minTheta-0.003, m_maxTheta+0.003, phi);
00075 
00076          marker->SetScaleCenter( 0., (phi>0 ? r*fabs(sin(theta)) : -r*fabs(sin(theta))), r*cos(theta) );
00077          marker->AddLine(0., (phi>0 ? r*fabs(sin(theta)) : -r*fabs(sin(theta))), r*cos(theta),
00078                          0., (phi>0 ? (r+size)*fabs(sin(theta)) : -(r+size)*fabs(sin(theta))), (r+size)*cos(theta) );
00079 
00080       }
00081       else
00082       {
00083          std::pair<double,double> phiRange = fireworks::getPhiRange( m_phis, phi );
00084          double min_phi = phiRange.first-M_PI/36/2;
00085          double max_phi = phiRange.second+M_PI/36/2;
00086          if( fabs(phiRange.first-phiRange.first)<1e-3 ) {
00087             min_phi = phi-M_PI/36/2;
00088             max_phi = phi+M_PI/36/2;
00089          }
00090          TEveGeoManagerHolder gmgr(TEveGeoShape::GetGeoMangeur());
00091          TGeoBBox *sc_box = new TGeoTubeSeg(ecalR - 1, ecalR + 1, 1, min_phi * 180 / M_PI, max_phi * 180 / M_PI);
00092          TEveGeoShape *shape = fireworks::getShape( "spread", sc_box, item()->defaultDisplayProperties().color() );
00093          shape->SetPickable(kTRUE);
00094          setupAddElement( shape, comp );
00095 
00096          marker->SetScaleCenter(ecalR*cos(phi), ecalR*sin(phi), 0);      
00097          marker->AddLine( ecalR*cos( phi ), ecalR*sin( phi ), 0,
00098                           ( ecalR+size )*cos( phi ), ( ecalR+size )*sin( phi ), 0);
00099       }
00100       marker->SetLineWidth(4);  
00101       FWViewEnergyScale* caloScale = vc->getEnergyScale();    
00102       marker->SetScale(caloScale->getScaleFactor3D()*(caloScale->getPlotEt() ?  iTau.et() : iTau.energy()));
00103       setupAddElement( marker, comp );
00104       m_lines.push_back(fireworks::scaleMarker(marker, iTau.et(), iTau.energy(), vc));
00105 
00106       context().voteMaxEtAndEnergy( iTau.et(), iTau.energy());
00107    }
00108    else if (iJet)
00109    {
00110       // jet
00111       TEveJetCone* cone = fireworks::makeEveJetCone(*iJet, context());
00112       const FWDisplayProperties &dp = item()->defaultDisplayProperties();
00113       cone->SetFillColor(dp.color());
00114       cone->SetLineColor(dp.color());
00115       setupAddElement( cone, comp );
00116       cone->SetMainTransparency(TMath::Min(100, 80 + dp.transparency() / 5)); 
00117    }
00118 }
00119 
00120 // Tracks which passed quality cuts and are inside a tracker signal cone around leading Track
00121 void
00122 FWTauProxyBuilderBase::addConstituentTracks( const reco::BaseTau &tau, class TEveElement* product )
00123 {
00124    for( reco::TrackRefVector::iterator i = tau.signalTracks().begin(), iEnd = tau.signalTracks().end();
00125         i != iEnd; ++i ) {
00126       TEveTrack* track( 0 );
00127       if( i->isAvailable() ) {
00128          track = fireworks::prepareTrack( **i, context().getTrackPropagator() );
00129          track->MakeTrack();
00130          setupAddElement( track, product );
00131       }
00132    }    
00133 }
00134 
00135 // Leading Track
00136 void
00137 FWTauProxyBuilderBase::addLeadTrack( const reco::BaseTau &tau, class TEveElement *product ) 
00138 {
00139    const reco::TrackRef leadTrack = tau.leadTrack();
00140    if( !leadTrack ) return;
00141 
00142    TEveTrack* track = fireworks::prepareTrack( *leadTrack, context().getTrackPropagator() );
00143    if( track ) 
00144    {
00145       track->MakeTrack();
00146       setupAddElement( track, product );
00147    }
00148 }
00149 
00150 void
00151 FWTauProxyBuilderBase::localModelChanges(const FWModelId& iId, TEveElement* iCompound,
00152                                          FWViewType::EType viewType, const FWViewContext* vc)
00153 {
00154    if (FWViewType::isProjected(viewType))
00155       increaseComponentTransparency(iId.index(), iCompound, "TEveJetCone", 80);
00156 }
00157 
00158 void
00159 FWTauProxyBuilderBase::scaleProduct(TEveElementList* parent, FWViewType::EType viewType, const FWViewContext* vc)
00160 { 
00161    if (FWViewType::isProjected(viewType))
00162    {
00163       typedef std::vector<fireworks::scaleMarker> Lines_t;  
00164       FWViewEnergyScale* caloScale = vc->getEnergyScale();
00165       // printf("%p -> %f\n", this,caloScale->getValToHeight() );
00166       for (Lines_t::iterator i = m_lines.begin(); i!= m_lines.end(); ++ i)
00167       {
00168          if (vc == (*i).m_vc)
00169          { 
00170             float value = caloScale->getPlotEt() ? (*i).m_et : (*i).m_energy;      
00171             (*i).m_ls->SetScale(caloScale->getScaleFactor3D()*value);
00172             TEveProjected* proj = *(*i).m_ls->BeginProjecteds();
00173             proj->UpdateProjection();
00174          }
00175       }
00176    }
00177 }
00178 
00179 void
00180 FWTauProxyBuilderBase::cleanLocal()
00181 {
00182    m_lines.clear();
00183 }