CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/Fireworks/Calo/plugins/FWJetProxyBuilder.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Calo
00004 // Class  :     FWJetProxyBuilder
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Tue Dec  2 14:17:03 EST 2008
00011 // $Id: FWJetProxyBuilder.cc,v 1.29 2010/11/26 20:24:46 amraktad Exp $
00012 //
00013 
00014 #include "TEveJetCone.h"
00015 #include "TEveScalableStraightLineSet.h"
00016 
00017 // user include files
00018 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
00019 #include "Fireworks/Core/interface/FWEventItem.h"
00020 #include "Fireworks/Core/interface/Context.h"
00021 #include "Fireworks/Core/interface/FWViewContext.h"
00022 #include "Fireworks/Core/interface/FWViewEnergyScale.h"
00023 #include "Fireworks/Calo/interface/makeEveJetCone.h"
00024 #include "Fireworks/Calo/interface/scaleMarker.h"
00025 
00026 #include "DataFormats/JetReco/interface/Jet.h"
00027 
00028 class FWJetProxyBuilder : public FWSimpleProxyBuilderTemplate<reco::Jet>
00029 {
00030 public:
00031    FWJetProxyBuilder();
00032    virtual ~FWJetProxyBuilder();
00033 
00034    virtual bool havePerViewProduct(FWViewType::EType) const { return true; }
00035    virtual bool haveSingleProduct() const { return false; } // different view types
00036    virtual void cleanLocal();
00037 
00038    REGISTER_PROXYBUILDER_METHODS();
00039    
00040 protected:
00041    virtual void buildViewType(const reco::Jet& iData, unsigned int iIndex, TEveElement& oItemHolder, FWViewType::EType type , const FWViewContext*);
00042 
00043 
00044    virtual void localModelChanges(const FWModelId& iId, TEveElement* iCompound,
00045                                   FWViewType::EType viewType, const FWViewContext* vc);
00046 
00047    virtual void scaleProduct(TEveElementList* parent, FWViewType::EType, const FWViewContext* vc);
00048 
00049 private:
00050    FWJetProxyBuilder( const FWJetProxyBuilder& ); // stop default
00051    const FWJetProxyBuilder& operator=( const FWJetProxyBuilder& ); // stop default
00052 
00053    TEveElementList* requestCommon();
00054    TEveElementList* m_common;
00055 
00056    std::vector<fireworks::scaleMarker> m_lines;
00057 };
00058 
00059 //______________________________________________________________________________
00060 FWJetProxyBuilder::FWJetProxyBuilder():
00061    m_common(0)
00062 {
00063    m_common = new TEveElementList( "common electron scene" );
00064    m_common->IncDenyDestroy();
00065 }
00066 
00067 FWJetProxyBuilder::~FWJetProxyBuilder()
00068 {
00069    m_common->DecDenyDestroy();
00070 }
00071 
00072 TEveElementList*
00073 FWJetProxyBuilder::requestCommon()
00074 {
00075    if( m_common->HasChildren() == false )
00076    {
00077       for (int i = 0; i < static_cast<int>(item()->size()); ++i)
00078       {
00079          TEveJetCone* cone = fireworks::makeEveJetCone(modelData(i), context());
00080 
00081          m_common->AddElement(cone);
00082          cone->SetFillColor(item()->defaultDisplayProperties().color());
00083          cone->SetLineColor(item()->defaultDisplayProperties().color());
00084 
00085       }
00086    }
00087    return m_common;
00088 }
00089 
00090 void
00091 FWJetProxyBuilder::buildViewType(const reco::Jet& iData, unsigned int iIndex, TEveElement& oItemHolder, FWViewType::EType type , const FWViewContext* vc)
00092 {
00093    // add cone from shared pool
00094    TEveElementList*    cones = requestCommon();
00095    TEveElement::List_i coneIt = cones->BeginChildren();
00096    std::advance(coneIt, iIndex);
00097 
00098    const FWDisplayProperties &dp = item()->defaultDisplayProperties();
00099    setupAddElement( *coneIt, &oItemHolder );
00100    (*coneIt)->SetMainTransparency(TMath::Min(100, 80 + dp.transparency() / 5)); 
00101 
00102    // scale markers in projected views
00103    if (FWViewType::isProjected(type))
00104    {
00105       TEveScalableStraightLineSet* marker =new TEveScalableStraightLineSet("jet lineset");
00106       float size = 1.f; // values are saved in scale
00107       double theta = iData.theta();
00108       double phi = iData.phi();
00109 
00110       if ( type == FWViewType::kRhoZ )
00111       {  
00112          static const float_t offr = 4;
00113          float r_ecal = context().caloR1() + offr;
00114          float z_ecal = context().caloZ1() + offr/tan(context().caloTransAngle());
00115 
00116          double r(0);
00117          if ( theta < context().caloTransAngle() || M_PI-theta < context().caloTransAngle())
00118          {
00119             z_ecal = context().caloZ2() + offr/tan(context().caloTransAngle());
00120             r = z_ecal/fabs(cos(theta));
00121          }
00122          else
00123          {
00124             r = r_ecal/sin(theta);
00125          }
00126 
00127          marker->SetScaleCenter( 0., (phi>0 ? r*fabs(sin(theta)) : -r*fabs(sin(theta))), r*cos(theta) );
00128          marker->AddLine( 0., (phi>0 ? r*fabs(sin(theta)) : -r*fabs(sin(theta))), r*cos(theta),
00129                           0., (phi>0 ? (r+size)*fabs(sin(theta)) : -(r+size)*fabs(sin(theta))), (r+size)*cos(theta) );
00130       }
00131       else
00132       {
00133          float ecalR = context().caloR1() + 4;
00134          marker->SetScaleCenter(ecalR*cos(phi), ecalR*sin(phi), 0);
00135          marker->AddLine(ecalR*cos(phi), ecalR*sin(phi), 0, (ecalR+size)*cos(phi), (ecalR+size)*sin(phi), 0);
00136       }
00137 
00138       marker->SetLineWidth(4);  
00139 
00140       marker->SetLineColor(dp.color());
00141 
00142       FWViewEnergyScale* caloScale = vc->getEnergyScale();    
00143       marker->SetScale(caloScale->getScaleFactor3D()*(caloScale->getPlotEt() ?  iData.et() : iData.energy()));
00144       setupAddElement( marker, &oItemHolder );
00145       m_lines.push_back(fireworks::scaleMarker(marker, iData.et(), iData.energy(), vc));
00146 
00147       context().voteMaxEtAndEnergy(iData.et(), iData.energy());
00148    }
00149 }
00150 
00151 void
00152 FWJetProxyBuilder::localModelChanges(const FWModelId& iId, TEveElement* iCompound,
00153                                            FWViewType::EType viewType, const FWViewContext* vc)
00154 {
00155    increaseComponentTransparency(iId.index(), iCompound, "TEveJetCone", 80);
00156 }
00157 
00158 void
00159 FWJetProxyBuilder::cleanLocal()
00160 {
00161    m_lines.clear();
00162    m_common->DestroyElements();
00163 }
00164 
00165 void
00166 FWJetProxyBuilder::scaleProduct(TEveElementList* parent, FWViewType::EType type, const FWViewContext* vc)
00167 { 
00168    typedef std::vector<fireworks::scaleMarker> Lines_t;  
00169    for (Lines_t::iterator i = m_lines.begin(); i!= m_lines.end(); ++ i)
00170    {
00171       if (vc == (*i).m_vc)
00172       { 
00173          float value = vc->getEnergyScale()->getPlotEt() ? (*i).m_et : (*i).m_energy;      
00174          (*i).m_ls->SetScale(vc->getEnergyScale()->getScaleFactor3D() *value);
00175          TEveProjected* proj = *(*i).m_ls->BeginProjecteds();
00176          proj->UpdateProjection();
00177       }
00178    }
00179 }
00180 
00181 REGISTER_FWPROXYBUILDER( FWJetProxyBuilder, reco::Jet, "Jets", FWViewType::kAll3DBits  | FWViewType::kAllRPZBits | FWViewType::kGlimpseBit);