CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWRPZViewGeometry.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWRPZViewGeometry
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Alja Mrak-Tadel
10 // Created: Thu Mar 25 20:33:06 CET 2010
11 // $Id: FWRPZViewGeometry.cc,v 1.16 2010/11/04 22:38:55 amraktad Exp $
12 //
13 
14 // system include files
15 #include <iostream>
16 
17 // user include files
18 
19 #include <iostream>
20 #include "TGeoBBox.h"
21 
22 #include "TEveElement.h"
23 #include "TEveCompound.h"
24 #include "TEveScene.h"
25 #include "TEvePointSet.h"
26 #include "TEveStraightLineSet.h"
27 #include "TEveGeoNode.h"
28 
34 
37 
38 //
39 //
40 //
41 // constants, enums and typedefs
42 //
43 
44 //
45 // static data member definitions
46 //
47 
48 //
49 // constructors and destructor
50 //
52  FWViewGeometryList(context),
53  m_rhoPhiGeo(0),
54  m_rhoZGeo(0)
55 {
56  SetElementName("RPZGeomShared");
57 }
58 
59 // FWRPZViewGeometry::FWRPZViewGeometry(const FWRPZViewGeometry& rhs)
60 // {
61 // // do actual copying here;
62 // }
63 
65 {
66  m_rhoPhiGeo->DecDenyDestroy();
67  m_rhoZGeo->DecDenyDestroy();
68 }
69 
70 //______________________________________________________________________________
71 
72 
73 TEveElement*
75 {
76  if( !m_geom ) return ( new TEveCompound( "dummy" ));
77 
78  if (type == FWViewType::kRhoZ)
79  {
80  if ( !m_rhoZGeo)
81  {
82  m_rhoZGeo = new TEveElementList("Geomtery RhoZ");
83 
84  m_rhoZGeo->IncDenyDestroy();
85  m_rhoZGeo->AddElement(makeMuonGeometryRhoZ());
86  m_rhoZGeo->AddElement(makeCaloOutlineRhoZ());
87  }
88  return m_rhoZGeo;
89  }
90  else
91  {
92  if ( !m_rhoPhiGeo)
93  {
94  m_rhoPhiGeo = new TEveElementList("Geomtery RhoPhi");
95  m_rhoPhiGeo->IncDenyDestroy();
96  m_rhoPhiGeo->AddElement(makeMuonGeometryRhoPhi());
97  m_rhoPhiGeo->AddElement(makeCaloOutlineRhoPhi());
98 
99  }
100  return m_rhoPhiGeo;
101  }
102  return 0;
103 }
104 
105 //______________________________________________________________________________
106 
107 
108 TEveElement*
110 {
111  using namespace fireworks;
112 
113  float ri = m_context.caloZ2()*tan(2*atan(exp(-m_context.caloMaxEta())));
114 
115  TEveStraightLineSet* el = new TEveStraightLineSet( "TrackerRhoZoutline" );
116  el->SetPickable(kFALSE);
118 
119  el->AddLine(0, m_context.caloR1(), -m_context.caloZ1(), 0, m_context.caloR1(), m_context.caloZ1());
120  el->AddLine(0, -m_context.caloR1(), m_context.caloZ1(), 0, -m_context.caloR1(), -m_context.caloZ1());
121 
122  el->AddLine(0, -m_context.caloR2(), m_context.caloZ2(), 0, -ri, m_context.caloZ2());
123  el->AddLine(0, ri, m_context.caloZ2(), 0, m_context.caloR2(), m_context.caloZ2());
124 
125  el->AddLine(0, -m_context.caloR2(), -m_context.caloZ2(), 0, -ri, -m_context.caloZ2());
126  el->AddLine(0, ri, -m_context.caloZ2(), 0, m_context.caloR2(), -m_context.caloZ2());
127 
128  return el;
129 }
130 
131 TEveElement*
133 {
134  TEveStraightLineSet* el = new TEveStraightLineSet( "TrackerRhoPhi" );
136 
138  const unsigned int nSegments = 100;
139  const double r = m_context.caloR1();
140  for ( unsigned int i = 1; i <= nSegments; ++i )
141  el->AddLine(r*sin(TMath::TwoPi()/nSegments*(i-1)), r*cos(TMath::TwoPi()/nSegments*(i-1)), 0,
142  r*sin(TMath::TwoPi()/nSegments*i), r*cos(TMath::TwoPi()/nSegments*i), 0);
143 
144  TEvePointSet* ref = new TEvePointSet("reference");
145  ref->SetTitle("(0,0,0)");
146  ref->SetMarkerStyle(4);
147  ref->SetMarkerColor(kWhite);
148  ref->SetNextPoint(0.,0.,0.);
149  el->AddElement(ref);
150 
151  return el;
152 }
153 
154 //______________________________________________________________________________
155 
156 TEveElement*
158 {
159  Int_t iWheel = 0;
160 
161  // rho-phi view
162  TEveCompound* container = new TEveCompound( "MuonRhoPhi" );
163 
164 
165  for( Int_t iStation = 1; iStation <= 4; ++iStation )
166  {
167  for( Int_t iSector = 1 ; iSector <= 14; ++iSector )
168  {
169  if( iStation < 4 && iSector > 12 ) continue;
170  DTChamberId id( iWheel, iStation, iSector );
171  TEveGeoShape* shape = m_geom->getEveShape( id.rawId() );
172  if( shape )
173  {
174  shape->SetMainColor(m_colorComp[kFWMuonBarrelLineColorIndex]->GetMainColor());
176  container->AddElement( shape );
177  }
178  }
179  }
180  return container;
181 }
182 
183 //______________________________________________________________________________
184 
185 TEveElement*
187 {
188  TEveElementList* container = new TEveElementList( "MuonRhoZ" );
189 
190  {
191  TEveCompound* dtContainer = new TEveCompound( "DT" );
192  for( Int_t iWheel = -2; iWheel <= 2; ++iWheel )
193  {
194  for( Int_t iStation = 1; iStation <= 4; ++iStation )
195  {
196  float min_rho(1000), max_rho(0), min_z(2000), max_z(-2000);
197 
198  // This will give us a quarter of DTs
199  // which is enough for our projection
200  for( Int_t iSector = 1; iSector <= 4; ++iSector )
201  {
202  DTChamberId id( iWheel, iStation, iSector );
203  unsigned int rawid = id.rawId();
204  FWGeometry::IdToInfoItr det = m_geom->find( rawid );
205  estimateProjectionSizeDT( *det, min_rho, max_rho, min_z, max_z );
206  }
207  if ( min_rho > max_rho || min_z > max_z ) continue;
208  TEveElement* se = makeShape( min_rho, max_rho, min_z, max_z );
210  dtContainer->AddElement(se);
211  se = makeShape( -max_rho, -min_rho, min_z, max_z );
213  dtContainer->AddElement(se);
214  }
215  }
216 
217  container->AddElement( dtContainer );
218  }
219  {
220  TEveCompound* cscContainer = new TEveCompound( "CSC" );
221 
222  Int_t maxChambers = 36;
223  Int_t step = 9;
224  Int_t iLayer = 0; // chamber
225  for( Int_t iEndcap = 1; iEndcap <= 2; ++iEndcap ) // 1=forward (+Z), 2=backward(-Z)
226  {
227  // Actual CSC geometry:
228  // Station 1 has 4 rings with 36 chambers in each
229  // Station 2: ring 1 has 18 chambers, ring 2 has 36 chambers
230  // Station 3: ring 1 has 18 chambers, ring 2 has 36 chambers
231  // Station 4: ring 1 has 18 chambers
232  for( Int_t iStation = 1; iStation <= 4; ++iStation )
233  {
234  for( Int_t iRing = 1; iRing <= 4; ++iRing )
235  {
236  if( iStation > 1 && iRing > 2 ) continue;
237  if( iStation > 3 && iRing > 1 ) continue;
238  float min_rho(1000), max_rho(0), min_z(2000), max_z(-2000);
239  ( iRing == 1 && iStation > 1 ) ? ( maxChambers = 18 ) : ( maxChambers = 36 );
240  ( iRing == 1 && iStation > 1 ) ? ( step = 5 ) : ( step = 18 );
241 
242  // Skip most of the chambers since they will project
243  // the same way as the two top ones and the two bottom ones
244  for( Int_t iChamber = step; iChamber <= maxChambers; iChamber += step )
245  {
246  CSCDetId id( iEndcap, iStation, iRing, iChamber, iLayer );
247  FWGeometry::IdToInfoItr det = m_geom->find( id.rawId() );
248  estimateProjectionSizeCSC( *det, min_rho, max_rho, min_z, max_z );
249 
250  // and a chamber next to it
251  ++iChamber;
252  CSCDetId nextid( iEndcap, iStation, iRing, iChamber, iLayer );
253  det = m_geom->find( nextid.rawId() );
254  estimateProjectionSizeCSC( *det, min_rho, max_rho, min_z, max_z );
255  }
256  if ( min_rho > max_rho || min_z > max_z ) continue;
257 
258  TEveElement* se = makeShape( min_rho, max_rho, min_z, max_z);
260  cscContainer->AddElement(se);
261 
262  se = makeShape( -max_rho, -min_rho, min_z, max_z );
264  cscContainer->AddElement(se);
265  }
266  }
267  }
268  container->AddElement( cscContainer );
269  }
270  return container;
271 }
272 
273 //______________________________________________________________________________
274 
275 TEveGeoShape*
276 FWRPZViewGeometry::makeShape( double min_rho, double max_rho, double min_z, double max_z)
277 {
278  TEveTrans t;
279  t(1,1) = 1; t(1,2) = 0; t(1,3) = 0;
280  t(2,1) = 0; t(2,2) = 1; t(2,3) = 0;
281  t(3,1) = 0; t(3,2) = 0; t(3,3) = 1;
282  t(1,4) = 0; t(2,4) = (min_rho+max_rho)/2; t(3,4) = (min_z+max_z)/2;
283 
284  TEveGeoShape* shape = new TEveGeoShape;
285  shape->SetTransMatrix(t.Array());
286 
287  shape->SetRnrSelf(kTRUE);
288  shape->SetRnrChildren(kTRUE);
289  TGeoBBox* box = new TGeoBBox( 0, (max_rho-min_rho)/2, (max_z-min_z)/2 );
290  shape->SetShape( box );
291 
292  return shape;
293 }
294 
295 //______________________________________________________________________________
296 
297 void
299  float& min_rho, float& max_rho, float& min_z, float& max_z )
300 {
301  // we will test 5 points on both sides ( +/- z)
302  float local[3], global[3];
303 
304  float dX = info.shape[1];
305  float dY = info.shape[2];
306  float dZ = info.shape[3];
307 
308  local[0] = 0; local[1] = 0; local[2] = dZ;
309  m_geom->localToGlobal( info, local, global );
310  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
311 
312  local[0] = dX; local[1] = dY; local[2] = dZ;
313  m_geom->localToGlobal( info, local, global );
314  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
315 
316  local[0] = -dX; local[1] = dY; local[2] = dZ;
317  m_geom->localToGlobal( info, local, global );
318  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
319 
320  local[0] = dX; local[1] = -dY; local[2] = dZ;
321  m_geom->localToGlobal( info, local, global );
322  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
323 
324  local[0] = -dX; local[1] = -dY; local[2] = dZ;
325  m_geom->localToGlobal( info, local, global );
326  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
327 
328  local[0] = 0; local[1] = 0; local[2] = -dZ;
329  m_geom->localToGlobal( info, local, global );
330  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
331 
332  local[0] = dX; local[1] = dY; local[2] = -dZ;
333  m_geom->localToGlobal( info, local, global );
334  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
335 
336  local[0] = -dX; local[1] = dY; local[2] = -dZ;
337  m_geom->localToGlobal( info, local, global );
338  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
339 
340  local[0] = dX; local[1] = -dY; local[2] = -dZ;
341  m_geom->localToGlobal( info, local, global );
342  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
343 
344  local[0] = -dX; local[1] = -dY; local[2] = -dZ;
345  m_geom->localToGlobal( info, local, global );
346  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
347 }
348 
349 void
351  float& min_rho, float& max_rho, float& min_z, float& max_z )
352 {
353  float local[3], global[3];
354 
355  float dX = info.shape[2] - info.shape[1];
356  float dY = info.shape[4];
357  float ddY = sqrt( 4 * dY * dY + dX * dX ) * 0.5;
358  float dZ = info.shape[3];
359 
360  local[0] = info.shape[2]; local[1] = ddY; local[2] = -dZ;
361  m_geom->localToGlobal( info, local, global );
362  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
363 
364  local[0] = info.shape[1]; local[1] = -ddY; local[2] = -dZ;
365  m_geom->localToGlobal( info, local, global );
366  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
367 
368  local[0] = info.shape[1]; local[1] = -ddY; local[2] = dZ;
369  m_geom->localToGlobal( info, local, global );
370  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
371 
372  local[0] = info.shape[2]; local[1] = ddY; local[2] = dZ;
373  m_geom->localToGlobal( info, local, global );
374  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
375 }
376 
377 void
379  float& min_rho, float& max_rho, float& min_z, float& max_z )
380 {
381  double rho = sqrt(global[0] *global[0]+global[1] *global[1]);
382  if ( min_rho > rho ) min_rho = rho;
383  if ( max_rho < rho ) max_rho = rho;
384  if ( min_z > global[2] ) min_z = global[2];
385  if ( max_z < global[2] ) max_z = global[2];
386 }
387 
388 
389 // ATODO:: check white vertex -> shouldn't be relative to background
390 // when detruction ?
391 
392 
393 // ATODO why color is not set in 3D original, why cast to polygonsetprojected after projected ????
394 // is geom color dynamic --- independent of projection manager
395 
396 // NOTE geomtry MuonRhoZAdanced renamed to MuonRhoZ
397 
398 
const double TwoPi
type
Definition: HCALResponse.h:22
TEveElement * getGeoElements(const FWViewType::EType id)
int i
Definition: DBlmapReader.cc:9
FWRPZViewGeometry(const fireworks::Context &context)
TEveCompound * m_colorComp[kFWGeomColorSize]
void estimateProjectionSizeDT(const FWGeometry::GeomDetInfo &info, float &, float &, float &, float &)
IdToInfoItr find(unsigned int) const
Definition: FWGeometry.cc:355
TEveElementList * m_rhoPhiGeo
TEveElement * makeCaloOutlineRhoPhi()
void estimateProjectionSizeCSC(const FWGeometry::GeomDetInfo &info, float &, float &, float &, float &)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
FWColorManager * colorManager() const
Definition: Context.h:66
Definition: DDAxes.h:10
static float caloZ2(bool offset=true)
Definition: Context.cc:225
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
void localToGlobal(unsigned int id, const float *local, float *global) const
Definition: FWGeometry.cc:326
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
void addToCompound(TEveElement *el, FWGeomColorIndex idx, bool applyTransp=true) const
TEveGeoShape * makeShape(double, double, double, double)
static float caloR2(bool offset=true)
Definition: Context.cc:215
TEveElement * makeMuonGeometryRhoPhi()
void estimateProjectionSize(const float *, float &, float &, float &, float &)
TEveGeoShape * getEveShape(unsigned int id) const
Definition: FWGeometry.cc:251
T sqrt(T t)
Definition: SSEVec.h:28
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
const FWGeometry * m_geom
TEveElementList * m_rhoZGeo
TEveElement * makeCaloOutlineRhoZ()
TEveElement * makeMuonGeometryRhoZ()
static double caloMaxEta()
Definition: Context.cc:240
static float caloZ1(bool offset=true)
Definition: Context.cc:220
Color_t geomColor(FWGeomColorIndex) const
const fireworks::Context & m_context
virtual ~FWRPZViewGeometry()
std::vector< FWGeometry::GeomDetInfo >::const_iterator IdToInfoItr
Definition: FWGeometry.h:96