CMS 3D CMS Logo

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 
31 
32 namespace fireworks {
33 
34 struct jetScaleMarker : public scaleMarker {
35  jetScaleMarker(TEveScalableStraightLineSet* ls, float et, float e, const FWViewContext* vc):
36  scaleMarker(ls, et, e, vc) , m_text(0) {}
37 
39 };
40 }
41 
42 static const std::string kJetLabelsRhoPhiOn("Draw Labels in RhoPhi View");
43 static const std::string kJetLabelsRhoZOn("Draw Labels in RhoZ View");
44 static const std::string kJetOffset("Label Offset");
45 static const std::string kJetApexBeamSpot("Place Apex In BeamSpot");
46 
47 
49 {
50 public:
52  virtual ~FWJetProxyBuilder();
53 
54  virtual bool havePerViewProduct(FWViewType::EType) const { return true; }
55  virtual bool haveSingleProduct() const { return false; } // different view types
56  virtual void cleanLocal();
57 
58  virtual void setItem(const FWEventItem* iItem)
59  {
61  if (iItem) {
62  iItem->getConfig()->assertParam(kJetLabelsRhoPhiOn, false);
63  iItem->getConfig()->assertParam(kJetLabelsRhoZOn, false);
64  iItem->getConfig()->assertParam(kJetOffset, 2.1, 1.0, 5.0);
65  iItem->getConfig()->assertParam(kJetApexBeamSpot, false);
66  }
67  }
68 
70 
71 protected:
73  virtual void buildViewType(const reco::Jet& iData, unsigned int iIndex, TEveElement& oItemHolder, FWViewType::EType type , const FWViewContext*);
74 
75 
76  virtual void localModelChanges(const FWModelId& iId, TEveElement* iCompound,
77  FWViewType::EType viewType, const FWViewContext* vc);
78 
79  virtual void scaleProduct(TEveElementList* parent, FWViewType::EType, const FWViewContext* vc);
80 
81 private:
82  typedef std::vector<fireworks::jetScaleMarker> Lines_t;
83 
84  FWJetProxyBuilder( const FWJetProxyBuilder& ); // stop default
85  const FWJetProxyBuilder& operator=( const FWJetProxyBuilder& ); // stop default
86 
87  TEveElementList* requestCommon();
88  void setTextPos(fireworks::jetScaleMarker& s, const FWViewContext* vc, FWViewType::EType);
89 
90  TEveElementList* m_common;
91 
92  std::vector<fireworks::jetScaleMarker> m_lines;
93 };
94 
95 
96 //______________________________________________________________________________
98  m_common(0)
99 {
100  m_common = new TEveElementList( "common electron scene" );
101  m_common->IncDenyDestroy();
102 }
103 
105 {
106  m_common->DecDenyDestroy();
107 }
108 
109 TEveElementList*
111 {
112  if( m_common->HasChildren() == false )
113  {
114  for (int i = 0; i < static_cast<int>(item()->size()); ++i)
115  {
116  TEveJetCone* cone = fireworks::makeEveJetCone(modelData(i), context());
117 
118  if (item()->getConfig()->value<bool>(kJetApexBeamSpot))
119  {
120  FWBeamSpot* bs = context().getBeamSpot();
121  cone->SetApex(TEveVector(bs->x0(), bs->y0(), bs->z0()));
122  }
123  cone->SetFillColor(item()->defaultDisplayProperties().color());
124  cone->SetLineColor(item()->defaultDisplayProperties().color());
125 
126  m_common->AddElement(cone);
127  }
128  }
129  return m_common;
130 }
131 
132 void
133 FWJetProxyBuilder::buildViewType(const reco::Jet& iData, unsigned int iIndex, TEveElement& oItemHolder, FWViewType::EType type , const FWViewContext* vc)
134 {
135  // add cone from shared pool
136  TEveElementList* cones = requestCommon();
137  TEveElement::List_i coneIt = cones->BeginChildren();
138  std::advance(coneIt, iIndex);
139 
141  setupAddElement( *coneIt, &oItemHolder );
142  (*coneIt)->SetMainTransparency(TMath::Min(100, 80 + dp.transparency() / 5));
143 
144  TEveVector p1;
145  TEveVector p2;
146 
147  // scale markers in projected views
148  if (FWViewType::isProjected(type))
149  {
150  m_lines.push_back(fireworks::jetScaleMarker(new TEveScalableStraightLineSet("jetline"), iData.et(), iData.energy(), vc));
151  fireworks::jetScaleMarker& markers = m_lines.back();
152 
153  float size = 1.f; // values are saved in scale
154  double theta = iData.theta();
155  double phi = iData.phi();
156 
157  if ( type == FWViewType::kRhoZ )
158  {
159  static const float_t offr = 4;
160  float r_ecal = context().caloR1() + offr;
161  float z_ecal = context().caloZ1() + offr/tan(context().caloTransAngle());
162  double r(0);
163  if ( theta < context().caloTransAngle() || M_PI-theta < context().caloTransAngle())
164  {
165  z_ecal = context().caloZ2() + offr/tan(context().caloTransAngle());
166  r = z_ecal/fabs(cos(theta));
167  }
168  else
169  {
170  r = r_ecal/sin(theta);
171  }
172 
173  p1.Set( 0., (phi>0 ? r*fabs(sin(theta)) : -r*fabs(sin(theta))), r*cos(theta));
174  p2.Set( 0., (phi>0 ? (r+size)*fabs(sin(theta)) : -(r+size)*fabs(sin(theta))), (r+size)*cos(theta) );
175  }
176  else
177  {
178  float ecalR = context().caloR1() + 4;
179  p1.Set(ecalR*cos(phi), ecalR*sin(phi), 0);
180  p2.Set((ecalR+size)*cos(phi), (ecalR+size)*sin(phi), 0);
181  }
182 
183  if (item()->getConfig()->value<bool>(kJetApexBeamSpot))
184  {
185  FWBeamSpot* bs = context().getBeamSpot();
186  TEveVector bsOff(bs->x0(), bs->y0(), bs->z0());
187  p1 += bsOff;
188  p2 += bsOff;
189  }
190 
191  markers.m_ls->SetScaleCenter(p1.fX, p1.fY, p1.fZ);
192  markers.m_ls->AddLine(p1, p2);
193 
194  markers.m_ls->SetLineWidth(4);
195  markers.m_ls->SetLineColor(dp.color());
196  FWViewEnergyScale* caloScale = vc->getEnergyScale();
197  markers.m_ls->SetScale(caloScale->getScaleFactor3D()*(caloScale->getPlotEt() ? iData.et() : iData.energy()));
198 
199  if ((type == FWViewType::kRhoZ && item()->getConfig()->value<bool>(kJetLabelsRhoZOn))||
200  (type == FWViewType::kRhoPhi && item()->getConfig()->value<bool>(kJetLabelsRhoPhiOn) ) )
201  {
202  markers.m_text = new FWEveText(Form("%.1f", vc->getEnergyScale()->getPlotEt() ? iData.et() : iData.energy()));
203  markers.m_text->SetMainColor( item()->defaultDisplayProperties().color());
204  setTextPos(markers, vc, type);
205  }
206 
207  markers.m_ls->SetMarkerColor(markers.m_ls->GetMainColor());
208  setupAddElement( markers.m_ls, &oItemHolder );
209  if (markers.m_text) setupAddElement( markers.m_text, &oItemHolder , false);
210 
211  }
212  context().voteMaxEtAndEnergy(iData.et(), iData.energy());
213 
214 }
215 
216 void
217 FWJetProxyBuilder::localModelChanges(const FWModelId& iId, TEveElement* iCompound,
218  FWViewType::EType viewType, const FWViewContext* vc)
219 {
220  increaseComponentTransparency(iId.index(), iCompound, "TEveJetCone", 80);
221 
222  for (Lines_t::iterator i = m_lines.begin(); i!= m_lines.end(); ++ i)
223  {
224  TEveStraightLineSetProjected* projLineSet = (TEveStraightLineSetProjected*)(*(*i).m_ls->BeginProjecteds());
225  if (projLineSet) projLineSet->UpdateProjection();
226  }
227 }
228 
229 
230 void
232 {
233  m_lines.clear();
234  m_common->DestroyElements();
235 }
236 
237 void
239 {
240  for (Lines_t::iterator i = m_lines.begin(); i!= m_lines.end(); ++ i)
241  {
242  if (vc == (*i).m_vc)
243  {
244  float value = vc->getEnergyScale()->getPlotEt() ? (*i).m_et : (*i).m_energy;
245 
246  (*i).m_ls->SetScale(vc->getEnergyScale()->getScaleFactor3D() * value );
247  if ((*i).m_text)
248  {
249  (*i).m_text->SetText(Form("%.1f", value));
250  setTextPos(*i, vc, type);
251  }
252  TEveStraightLineSetProjected* projLineSet = (TEveStraightLineSetProjected*)(*(*i).m_ls->BeginProjecteds());
253  projLineSet->UpdateProjection();
254  }
255  }
256 }
257 
258 
260 {
261  TEveChunkManager::iterator li( s.m_ls->GetLinePlex() );
262  li.next();
263  TEveStraightLineSet::Line_t &l = * ( TEveStraightLineSet::Line_t* ) li();
264  TEveVector v(l.fV2[0] - l.fV1[0], l.fV2[1] - l.fV1[1], l.fV2[2] - l.fV1[2] );
265  v.Normalize();
266 
267 
268  double off = item()->getConfig()->value<double>(kJetOffset) -1;
269  float value = vc->getEnergyScale()->getPlotEt() ? s.m_et : s.m_energy;
270  double trs = off * 130 * value/context().getMaxEnergyInEvent(vc->getEnergyScale()->getPlotEt());
271  v *= trs;
272 
273  float x = l.fV1[0] + v[0];
274  float y = l.fV1[1] + v[1];
275  float z = l.fV1[2] + v[2];
276 
278  s.m_text->RefMainTrans().SetPos(x, y, z);
279  if ((s.m_text)->BeginProjecteds() != (s.m_text)->EndProjecteds()) {
280  FWEveTextProjected* textProjected = (FWEveTextProjected*)(*(s.m_text)->BeginProjecteds());
281  textProjected->UpdateProjection();
282  }
283 
284 }
285 
size
Write out results.
type
Definition: HCALResponse.h:21
const fireworks::Context & context() const
FWProxyBuilderConfiguration * getConfig() const
Definition: FWEventItem.h:170
float getScaleFactor3D() const
static const std::string kJetApexBeamSpot("Place Apex In BeamSpot")
const FWDisplayProperties & defaultDisplayProperties() const
Definition: FWEventItem.cc:453
#define REGISTER_PROXYBUILDER_METHODS()
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
virtual void UpdateProjection()
float m_offsetZ
static const std::string kJetLabelsRhoPhiOn("Draw Labels in RhoPhi View")
static const int kAllRPZBits
Definition: FWViewType.h:58
double x0() const
Definition: FWBeamSpot.cc:30
double z0() const
Definition: FWBeamSpot.cc:40
double y0() const
Definition: FWBeamSpot.cc:35
Base class for all types of Jets.
Definition: Jet.h:20
void voteMaxEtAndEnergy(float Et, float energy) const
Definition: Context.cc:183
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
Geom::Theta< T > theta() const
static float caloZ2(bool offset=true)
Definition: Context.cc:223
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
const FWEventItem * item() const
static const int kAll3DBits
Definition: FWViewType.h:59
Color_t color() const
virtual double phi() const final
momentum azimuthal angle
static bool isProjected(int)
Definition: FWViewType.cc:128
virtual double et() const final
transverse energy
virtual void cleanLocal()
virtual double theta() const final
momentum polar angle
Char_t transparency() const
FWBeamSpot * getBeamSpot() const
Definition: Context.h:78
int index() const
Definition: FWModelId.h:49
virtual void setItem(const FWEventItem *iItem)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
virtual double energy() const final
energy
static float caloR1(bool offset=true)
Definition: Context.cc:208
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:199
Definition: value.py:1
double p2[4]
Definition: TauolaWrapper.h:90
virtual bool havePerViewProduct(FWViewType::EType) const
#define M_PI
TEveElementList * m_common
FWGenericParameter< T > * assertParam(const std::string &name, T def)
def ls(path, rec=False)
Definition: eostools.py:348
virtual bool haveSingleProduct() const
size_t size() const
Definition: FWEventItem.cc:550
auto dp
Definition: deltaR.h:22
et
define resolution functions of each parameter
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)
double p1[4]
Definition: TauolaWrapper.h:89
static float caloZ1(bool offset=true)
Definition: Context.cc:218
std::vector< fireworks::jetScaleMarker > m_lines
virtual void scaleProduct(TEveElementList *parent, FWViewType::EType, const FWViewContext *vc)
TEveElementList * requestCommon()
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