CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWJetProxyBuilder.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Calo
4 // Class : FWJetProxyBuilder
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Tue Dec 2 14:17:03 EST 2008
11 //
12 
13 #include "TEveJetCone.h"
14 #include "TEveScalableStraightLineSet.h"
15 
20 // user include files
28 
30 
31 namespace fireworks {
32 
33 struct jetScaleMarker : public scaleMarker {
34  jetScaleMarker(TEveScalableStraightLineSet* ls, float et, float e, const FWViewContext* vc):
35  scaleMarker(ls, et, e, vc) , m_text(0) {}
36 
38 };
39 }
40 
41 static const std::string kJetLabelsRhoPhiOn("Draw Labels in RhoPhi View");
42 static const std::string kJetLabelsRhoZOn("Draw Labels in RhoZ View");
43 static const std::string kJetOffset("Label Offset");
44 
45 
47 {
48 public:
50  virtual ~FWJetProxyBuilder();
51 
52  virtual bool havePerViewProduct(FWViewType::EType) const { return true; }
53  virtual bool haveSingleProduct() const { return false; } // different view types
54  virtual void cleanLocal();
55 
56  virtual void setItem(const FWEventItem* iItem)
57  {
59  if (iItem) {
60  iItem->getConfig()->assertParam(kJetLabelsRhoPhiOn, false);
61  iItem->getConfig()->assertParam(kJetLabelsRhoZOn, false);
62  iItem->getConfig()->assertParam(kJetOffset, 2.1, 1.0, 5.0);
63  }
64  }
65 
67 
68 protected:
70  virtual void buildViewType(const reco::Jet& iData, unsigned int iIndex, TEveElement& oItemHolder, FWViewType::EType type , const FWViewContext*);
71 
72 
73  virtual void localModelChanges(const FWModelId& iId, TEveElement* iCompound,
74  FWViewType::EType viewType, const FWViewContext* vc);
75 
76  virtual void scaleProduct(TEveElementList* parent, FWViewType::EType, const FWViewContext* vc);
77 
78 private:
79  typedef std::vector<fireworks::jetScaleMarker> Lines_t;
80 
81  FWJetProxyBuilder( const FWJetProxyBuilder& ); // stop default
82  const FWJetProxyBuilder& operator=( const FWJetProxyBuilder& ); // stop default
83 
84  TEveElementList* requestCommon();
86 
87  TEveElementList* m_common;
88 
89  std::vector<fireworks::jetScaleMarker> m_lines;
90 };
91 
92 
93 //______________________________________________________________________________
95  m_common(0)
96 {
97  m_common = new TEveElementList( "common electron scene" );
98  m_common->IncDenyDestroy();
99 }
100 
102 {
103  m_common->DecDenyDestroy();
104 }
105 
106 TEveElementList*
108 {
109  if( m_common->HasChildren() == false )
110  {
111  for (int i = 0; i < static_cast<int>(item()->size()); ++i)
112  {
113  TEveJetCone* cone = fireworks::makeEveJetCone(modelData(i), context());
114 
115  m_common->AddElement(cone);
116  cone->SetFillColor(item()->defaultDisplayProperties().color());
117  cone->SetLineColor(item()->defaultDisplayProperties().color());
118 
119  }
120  }
121  return m_common;
122 }
123 
124 void
125 FWJetProxyBuilder::buildViewType(const reco::Jet& iData, unsigned int iIndex, TEveElement& oItemHolder, FWViewType::EType type , const FWViewContext* vc)
126 {
127  // add cone from shared pool
128  TEveElementList* cones = requestCommon();
129  TEveElement::List_i coneIt = cones->BeginChildren();
130  std::advance(coneIt, iIndex);
131 
133  setupAddElement( *coneIt, &oItemHolder );
134  (*coneIt)->SetMainTransparency(TMath::Min(100, 80 + dp.transparency() / 5));
135 
136 
137  // scale markers in projected views
138  if (FWViewType::isProjected(type))
139  {
140  m_lines.push_back(fireworks::jetScaleMarker(new TEveScalableStraightLineSet("jetline"), iData.et(), iData.energy(), vc));
141  fireworks::jetScaleMarker& markers = m_lines.back();
142 
143  float size = 1.f; // values are saved in scale
144  double theta = iData.theta();
145  double phi = iData.phi();
146 
147  if ( type == FWViewType::kRhoZ )
148  {
149  static const float_t offr = 4;
150  float r_ecal = context().caloR1() + offr;
151  float z_ecal = context().caloZ1() + offr/tan(context().caloTransAngle());
152  double r(0);
153  if ( theta < context().caloTransAngle() || M_PI-theta < context().caloTransAngle())
154  {
155  z_ecal = context().caloZ2() + offr/tan(context().caloTransAngle());
156  r = z_ecal/fabs(cos(theta));
157  }
158  else
159  {
160  r = r_ecal/sin(theta);
161  }
162 
163  markers.m_ls->SetScaleCenter( 0., (phi>0 ? r*fabs(sin(theta)) : -r*fabs(sin(theta))), r*cos(theta) );
164  markers.m_ls->AddLine( 0., (phi>0 ? r*fabs(sin(theta)) : -r*fabs(sin(theta))), r*cos(theta),
165  0., (phi>0 ? (r+size)*fabs(sin(theta)) : -(r+size)*fabs(sin(theta))), (r+size)*cos(theta) );
166  }
167  else
168  {
169  float ecalR = context().caloR1() + 4;
170  markers.m_ls->SetScaleCenter(ecalR*cos(phi), ecalR*sin(phi), 0);
171  markers.m_ls->AddLine(ecalR*cos(phi), ecalR*sin(phi), 0, (ecalR+size)*cos(phi), (ecalR+size)*sin(phi), 0);
172  }
173 
174  markers.m_ls->SetLineWidth(4);
175  markers.m_ls->SetLineColor(dp.color());
176  FWViewEnergyScale* caloScale = vc->getEnergyScale();
177  markers.m_ls->SetScale(caloScale->getScaleFactor3D()*(caloScale->getPlotEt() ? iData.et() : iData.energy()));
178 
179  if ((type == FWViewType::kRhoZ && item()->getConfig()->value<bool>(kJetLabelsRhoZOn))||
180  (type == FWViewType::kRhoPhi && item()->getConfig()->value<bool>(kJetLabelsRhoPhiOn) ) )
181  {
182  markers.m_text = new FWEveText(Form("%.1f", vc->getEnergyScale()->getPlotEt() ? iData.et() : iData.energy()));
183  markers.m_text->SetMainColor( item()->defaultDisplayProperties().color());
184  setTextPos(markers, vc, type);
185  }
186 
187 
188  markers.m_ls->SetMarkerColor(markers.m_ls->GetMainColor());
189  setupAddElement( markers.m_ls, &oItemHolder );
190  if (markers.m_text) setupAddElement( markers.m_text, &oItemHolder , false);
191 
192  }
193  context().voteMaxEtAndEnergy(iData.et(), iData.energy());
194 
195 }
196 
197 void
198 FWJetProxyBuilder::localModelChanges(const FWModelId& iId, TEveElement* iCompound,
199  FWViewType::EType viewType, const FWViewContext* vc)
200 {
201  increaseComponentTransparency(iId.index(), iCompound, "TEveJetCone", 80);
202 
203  for (Lines_t::iterator i = m_lines.begin(); i!= m_lines.end(); ++ i)
204  {
205  TEveStraightLineSetProjected* projLineSet = (TEveStraightLineSetProjected*)(*(*i).m_ls->BeginProjecteds());
206  if (projLineSet) projLineSet->UpdateProjection();
207  }
208 }
209 
210 
211 void
213 {
214  m_lines.clear();
215  m_common->DestroyElements();
216 }
217 
218 void
220 {
221  for (Lines_t::iterator i = m_lines.begin(); i!= m_lines.end(); ++ i)
222  {
223  if (vc == (*i).m_vc)
224  {
225  float value = vc->getEnergyScale()->getPlotEt() ? (*i).m_et : (*i).m_energy;
226 
227  (*i).m_ls->SetScale(vc->getEnergyScale()->getScaleFactor3D() * value );
228  if ((*i).m_text)
229  {
230  (*i).m_text->SetText(Form("%.1f", value));
231  setTextPos(*i, vc, type);
232  }
233  TEveStraightLineSetProjected* projLineSet = (TEveStraightLineSetProjected*)(*(*i).m_ls->BeginProjecteds());
234  projLineSet->UpdateProjection();
235  }
236  }
237 }
238 
239 
241 {
242  TEveChunkManager::iterator li( s.m_ls->GetLinePlex() );
243  li.next();
244  TEveStraightLineSet::Line_t &l = * ( TEveStraightLineSet::Line_t* ) li();
245  TEveVector v(l.fV2[0] - l.fV1[0], l.fV2[1] - l.fV1[1], l.fV2[2] - l.fV1[2] );
246  v.Normalize();
247 
248 
249  double off = item()->getConfig()->value<double>(kJetOffset) -1;
250  float value = vc->getEnergyScale()->getPlotEt() ? s.m_et : s.m_energy;
251  double trs = off * 130 * value/context().getMaxEnergyInEvent(vc->getEnergyScale()->getPlotEt());
252  v *= trs;
253 
254  float x = l.fV1[0] + v[0];
255  float y = l.fV1[1] + v[1];
256  float z = l.fV1[2] + v[2];
257 
259  s.m_text->RefMainTrans().SetPos(x, y, z);
260  if ((s.m_text)->BeginProjecteds() != (s.m_text)->EndProjecteds()) {
261  FWEveTextProjected* textProjected = (FWEveTextProjected*)(*(s.m_text)->BeginProjecteds());
262  textProjected->UpdateProjection();
263  }
264 
265 }
266 
const FWJetProxyBuilder & operator=(const FWJetProxyBuilder &)
type
Definition: HCALResponse.h:21
const fireworks::Context & context() const
FWProxyBuilderConfiguration * getConfig() const
Definition: FWEventItem.h:165
float getScaleFactor3D() const
int i
Definition: DBlmapReader.cc:9
const FWDisplayProperties & defaultDisplayProperties() const
Definition: FWEventItem.cc:451
#define REGISTER_PROXYBUILDER_METHODS()
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
virtual void UpdateProjection()
float m_offsetZ
list parent
Definition: dbtoconf.py:74
static const std::string kJetLabelsRhoPhiOn("Draw Labels in RhoPhi View")
static const int kAllRPZBits
Definition: FWViewType.h:58
virtual double et() const
transverse energy
Base class for all types of Jets.
Definition: Jet.h:20
void voteMaxEtAndEnergy(float Et, float energy) const
Definition: Context.cc:185
void setupAddElement(TEveElement *el, TEveElement *parent, bool set_color=true) const
jetScaleMarker(TEveScalableStraightLineSet *ls, float et, float e, const FWViewContext *vc)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
FWViewEnergyScale * getEnergyScale() const
def ls
Definition: eostools.py:346
Geom::Theta< T > theta() const
static float caloZ2(bool offset=true)
Definition: Context.cc:225
virtual void setItem(const FWEventItem *iItem)
std::vector< fireworks::jetScaleMarker > Lines_t
static const std::string kJetOffset("Label Offset")
T Min(T a, T b)
Definition: MathUtil.h:39
float float float z
const FWEventItem * item() const
static const int kAll3DBits
Definition: FWViewType.h:59
Color_t color() const
static bool isProjected(int)
Definition: FWViewType.cc:128
virtual void cleanLocal()
virtual double energy() const
energy
Char_t transparency() const
int index() const
Definition: FWModelId.h:49
virtual void setItem(const FWEventItem *iItem)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
static float caloR1(bool offset=true)
Definition: Context.cc:210
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
static const std::string kJetLabelsRhoZOn("Draw Labels in RhoZ View")
float getMaxEnergyInEvent(bool isEt) const
Definition: Context.cc:201
#define M_PI
virtual bool havePerViewProduct(FWViewType::EType) const
virtual double theta() const
momentum polar angle
TEveElementList * m_common
FWGenericParameter< T > * assertParam(const std::string &name, T def)
virtual bool haveSingleProduct() const
size_t size() const
Definition: FWEventItem.cc:548
virtual void buildViewType(const reco::Jet &iData, unsigned int iIndex, TEveElement &oItemHolder, FWViewType::EType type, const FWViewContext *)
TEveScalableStraightLineSet * m_ls
Definition: scaleMarker.h:37
virtual void localModelChanges(const FWModelId &iId, TEveElement *iCompound, FWViewType::EType viewType, const FWViewContext *vc)
static float caloZ1(bool offset=true)
Definition: Context.cc:220
std::vector< fireworks::jetScaleMarker > m_lines
virtual void scaleProduct(TEveElementList *parent, FWViewType::EType, const FWViewContext *vc)
TEveElementList * requestCommon()
volatile std::atomic< bool > shutdown_flag false
Definition: DDAxes.h:10
virtual double phi() const
momentum azimuthal angle
tuple size
Write out results.
void setTextPos(fireworks::jetScaleMarker &s, const FWViewContext *vc, FWViewType::EType)
void increaseComponentTransparency(unsigned int index, TEveElement *holder, const std::string &name, Char_t transpOffset)
TEveJetCone * makeEveJetCone(const reco::Jet &iData, const fireworks::Context &context)
bool getPlotEt() const
Definition: DDAxes.h:10