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 //
12 
13 // system include files
14 #include <iostream>
15 #include <cassert>
16 
17 // user include files
18 #include "TGeoBBox.h"
19 
20 #include "TEveElement.h"
21 #include "TEveCompound.h"
22 #include "TEveScene.h"
23 #include "TEvePointSet.h"
24 #include "TEveStraightLineSet.h"
25 #include "TEveGeoNode.h"
26 #include "TEveManager.h"
27 #include "TEveProjectionManager.h"
28 
34 
39 
40 //
41 //
42 //
43 // constants, enums and typedefs
44 //
45 
46 //
47 // static data member definitions
48 //
49 
50 //
51 // constructors and destructor
52 //
54  FWViewGeometryList(context),
55 
56  m_rhoPhiGeo(0),
57  m_rhoZGeo(0),
58 
59  m_pixelBarrelElements(0),
60  m_pixelEndcapElements(0),
61  m_trackerBarrelElements(0),
62  m_trackerEndcapElements(0),
63  m_rpcEndcapElements(0),
64  m_GEMElements(0)
65 {
66  SetElementName("RPZGeomShared");
67 }
68 
69 // FWRPZViewGeometry::FWRPZViewGeometry(const FWRPZViewGeometry& rhs)
70 // {
71 // // do actual copying here;
72 // }
73 
75 {
76  m_rhoPhiGeo->DecDenyDestroy();
77  m_rhoZGeo->DecDenyDestroy();
78 }
79 
80 //______________________________________________________________________________
81 
82 void
84 {
85  assert(m_geom != 0);
86 
87  if (type == FWViewType::kRhoZ)
88  {
89  AddElement(makeMuonGeometryRhoZ());
90  AddElement(makeCaloOutlineRhoZ());
91  }
92  else
93  {
94  AddElement(makeMuonGeometryRhoPhi());
95  AddElement(makeCaloOutlineRhoPhi());
96  }
97 }
98 
99 //______________________________________________________________________________
100 
101 
102 TEveElement*
104 {
105  using namespace fireworks;
106 
107  float ri = m_context.caloZ2()*tan(2*atan(exp(-m_context.caloMaxEta())));
108 
109  TEveStraightLineSet* el = new TEveStraightLineSet( "TrackerRhoZoutline" );
110  el->SetPickable(kFALSE);
112 
113  el->AddLine(0, m_context.caloR1(), -m_context.caloZ1(), 0, m_context.caloR1(), m_context.caloZ1());
114  el->AddLine(0, -m_context.caloR1(), m_context.caloZ1(), 0, -m_context.caloR1(), -m_context.caloZ1());
115 
116  el->AddLine(0, -m_context.caloR2(), m_context.caloZ2(), 0, -ri, m_context.caloZ2());
117  el->AddLine(0, ri, m_context.caloZ2(), 0, m_context.caloR2(), m_context.caloZ2());
118 
119  el->AddLine(0, -m_context.caloR2(), -m_context.caloZ2(), 0, -ri, -m_context.caloZ2());
120  el->AddLine(0, ri, -m_context.caloZ2(), 0, m_context.caloR2(), -m_context.caloZ2());
121 
122  return el;
123 }
124 
125 TEveElement*
127 {
128  TEveStraightLineSet* el = new TEveStraightLineSet( "TrackerRhoPhi" );
130 
132  const unsigned int nSegments = 100;
133  const double r = m_context.caloR1();
134  for ( unsigned int i = 1; i <= nSegments; ++i )
135  el->AddLine(r*sin(TMath::TwoPi()/nSegments*(i-1)), r*cos(TMath::TwoPi()/nSegments*(i-1)), 0,
136  r*sin(TMath::TwoPi()/nSegments*i), r*cos(TMath::TwoPi()/nSegments*i), 0);
137 
138  TEvePointSet* ref = new TEvePointSet("reference");
139  ref->SetTitle("(0,0,0)");
140  ref->SetMarkerStyle(4);
141  ref->SetMarkerColor(kWhite);
142  ref->SetNextPoint(0.,0.,0.);
143  el->AddElement(ref);
144 
145  return el;
146 }
147 
148 //______________________________________________________________________________
149 
150 TEveElement*
152 {
153  Int_t iWheel = 0;
154 
155  // rho-phi view
156  TEveCompound* container = new TEveCompound( "MuonRhoPhi" );
157 
158 
159  for( Int_t iStation = 1; iStation <= 4; ++iStation )
160  {
161  for( Int_t iSector = 1 ; iSector <= 14; ++iSector )
162  {
163  if( iStation < 4 && iSector > 12 ) continue;
164  DTChamberId id( iWheel, iStation, iSector );
165  TEveGeoShape* shape = m_geom->getEveShape( id.rawId() );
166  if( shape )
167  {
168  shape->SetMainColor(m_colorComp[kFWMuonBarrelLineColorIndex]->GetMainColor());
170  container->AddElement( shape );
171  }
172  }
173  }
174  return container;
175 }
176 namespace {
177 
178 //void addLibe
179 
180 }
181 //______________________________________________________________________________
182 
183 TEveElement*
185 {
186  TEveElementList* container = new TEveElementList( "MuonRhoZ" );
187 
188  {
189  TEveCompound* dtContainer = new TEveCompound( "DT" );
190  for( Int_t iWheel = -2; iWheel <= 2; ++iWheel )
191  {
192  for( Int_t iStation = 1; iStation <= 4; ++iStation )
193  {
194  float min_rho(1000), max_rho(0), min_z(2000), max_z(-2000);
195 
196  // This will give us a quarter of DTs
197  // which is enough for our projection
198  for( Int_t iSector = 1; iSector <= 4; ++iSector )
199  {
200  DTChamberId id( iWheel, iStation, iSector );
201  unsigned int rawid = id.rawId();
202  FWGeometry::IdToInfoItr det = m_geom->find( rawid );
203  estimateProjectionSizeDT( *det, min_rho, max_rho, min_z, max_z );
204  }
205  if ( min_rho > max_rho || min_z > max_z ) continue;
206  TEveElement* se = makeShape( min_rho, max_rho, min_z, max_z );
208  dtContainer->AddElement(se);
209  se = makeShape( -max_rho, -min_rho, min_z, max_z );
211  dtContainer->AddElement(se);
212  }
213  }
214 
215  container->AddElement( dtContainer );
216  }
217  {
218  // addcsc
219  TEveCompound* cscContainer = new TEveCompound( "CSC" );
220  std::vector<CSCDetId> ids;
222  {
223  for (int station = 1; station <= 4; ++station)
224  {
225  ids.push_back(CSCDetId(endcap, station, 2, 10, 0 ));//outer ring up
226  ids.push_back(CSCDetId(endcap, station, 2, 11, 0 ));//outer ring up
227 
228  ids.push_back(CSCDetId(endcap, station, 2, 28, 0 ));//outer ring down
229  ids.push_back(CSCDetId(endcap, station, 2, 29, 0 ));//outer ring down
230 
231  ids.push_back(CSCDetId(endcap, station, 1, 5, 0 ));//inner ring up
232  ids.push_back(CSCDetId(endcap, station, 1, 6, 0 )); //inner ring up
233 
234  int off = (station == 1) ? 10:0;
235  ids.push_back(CSCDetId(endcap, station, 1, 15+off, 0 ));//inner ring down
236  ids.push_back(CSCDetId(endcap, station, 1, 16+off, 0 )); //inner ring down
237  }
238  ids.push_back(CSCDetId(endcap, 1, 3, 10, 0 )); // ring 3 down
239  ids.push_back(CSCDetId(endcap, 1, 3, 28, 0 )); // ring 3 down
240  }
241  for (std::vector<CSCDetId>::iterator i = ids.begin(); i != ids.end(); ++i)
242  {
243  unsigned int rawid = i->rawId();
244  TEveGeoShape* shape = m_geom->getEveShape(rawid);
246  shape->SetName(Form(" e:%d r:%d s:%d chamber %d",i->endcap(), i->ring(), i->station(), i->chamber() ));
247  cscContainer->AddElement(shape);
248  }
249  container->AddElement( cscContainer );
250  }
251 
252  return container;
253 }
254 
255 //______________________________________________________________________________
256 
257 TEveGeoShape*
258 FWRPZViewGeometry::makeShape( double min_rho, double max_rho, double min_z, double max_z)
259 {
260  TEveTrans t;
261  t(1,1) = 1; t(1,2) = 0; t(1,3) = 0;
262  t(2,1) = 0; t(2,2) = 1; t(2,3) = 0;
263  t(3,1) = 0; t(3,2) = 0; t(3,3) = 1;
264  t(1,4) = 0; t(2,4) = (min_rho+max_rho)/2; t(3,4) = (min_z+max_z)/2;
265 
266  TEveGeoShape* shape = new TEveGeoShape;
267  shape->SetTransMatrix(t.Array());
268 
269  shape->SetRnrSelf(kTRUE);
270  shape->SetRnrChildren(kTRUE);
271  TGeoBBox* box = new TGeoBBox( 0, (max_rho-min_rho)/2, (max_z-min_z)/2 );
272  shape->SetShape( box );
273 
274  return shape;
275 }
276 
277 //______________________________________________________________________________
278 
279 void
281  float& min_rho, float& max_rho, float& min_z, float& max_z )
282 {
283  // we will test 5 points on both sides ( +/- z)
284  float local[3], global[3];
285 
286  float dX = info.shape[1];
287  float dY = info.shape[2];
288  float dZ = info.shape[3];
289 
290  local[0] = 0; local[1] = 0; local[2] = dZ;
291  m_geom->localToGlobal( info, local, global );
292  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
293 
294  local[0] = dX; local[1] = dY; local[2] = dZ;
295  m_geom->localToGlobal( info, local, global );
296  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
297 
298  local[0] = -dX; local[1] = dY; local[2] = dZ;
299  m_geom->localToGlobal( info, local, global );
300  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
301 
302  local[0] = dX; local[1] = -dY; local[2] = dZ;
303  m_geom->localToGlobal( info, local, global );
304  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
305 
306  local[0] = -dX; local[1] = -dY; local[2] = dZ;
307  m_geom->localToGlobal( info, local, global );
308  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
309 
310  local[0] = 0; local[1] = 0; local[2] = -dZ;
311  m_geom->localToGlobal( info, local, global );
312  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
313 
314  local[0] = dX; local[1] = dY; local[2] = -dZ;
315  m_geom->localToGlobal( info, local, global );
316  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
317 
318  local[0] = -dX; local[1] = dY; local[2] = -dZ;
319  m_geom->localToGlobal( info, local, global );
320  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
321 
322  local[0] = dX; local[1] = -dY; local[2] = -dZ;
323  m_geom->localToGlobal( info, local, global );
324  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
325 
326  local[0] = -dX; local[1] = -dY; local[2] = -dZ;
327  m_geom->localToGlobal( info, local, global );
328  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
329 }
330 
331 
332 void
334  float& min_rho, float& max_rho, float& min_z, float& max_z )
335 {
336  double rho = sqrt(global[0] *global[0]+global[1] *global[1]);
337  if ( min_rho > rho ) min_rho = rho;
338  if ( max_rho < rho ) max_rho = rho;
339  if ( min_z > global[2] ) min_z = global[2];
340  if ( max_z < global[2] ) max_z = global[2];
341 }
342 
343 
344 // ATODO:: check white vertex -> shouldn't be relative to background
345 // when detruction ?
346 
347 
348 // ATODO why color is not set in 3D original, why cast to polygonsetprojected after projected ????
349 // is geom color dynamic --- independent of projection manager
350 
351 // NOTE geomtry MuonRhoZAdanced renamed to MuonRhoZ
352 
353 
354 //==============================================================================
355 //==============================================================================
356 
357 
358 
359 void
361 {
362  if( !m_pixelBarrelElements && show )
363  {
364  m_pixelBarrelElements = new TEveElementList("PixelBarrel");
365  AddElement(m_pixelBarrelElements);
366  std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::PixelBarrel );
367  for( std::vector<unsigned int>::const_iterator id = ids.begin();
368  id != ids.end(); ++id )
369  {
370  TEveGeoShape* shape = m_geom->getEveShape( *id );
371  shape->SetTitle(Form("PixelBarrel %d",*id));
373  m_pixelBarrelElements->AddElement( shape );
374  }
376  }
377 
379  {
380  m_pixelBarrelElements->SetRnrState(show);
381  gEve->Redraw3D();
382  }
383 }
384 
385 void
387 {
388  if( !m_pixelEndcapElements && show )
389  {
390  m_pixelEndcapElements = new TEveElementList("PixelEndcap");
391 
392  std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::PixelEndcap );
393  for( std::vector<unsigned int>::const_iterator id = ids.begin();
394  id != ids.end(); ++id )
395  {
396  TEveGeoShape* shape = m_geom->getEveShape( *id );
397 
398  shape->SetTitle(Form("PixelEndCap %d",*id));
400  m_pixelEndcapElements->AddElement( shape );
401  }
402 
403  AddElement(m_pixelEndcapElements);
405  }
406 
408  {
409  m_pixelEndcapElements->SetRnrState(show);
410  gEve->Redraw3D();
411  }
412 }
413 
414 
415 void
417 {
418  if( !m_trackerBarrelElements && show )
419  {
420  m_trackerBarrelElements = new TEveElementList("TrackerBarrel");
421 
422  std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::TIB );
423  for( std::vector<unsigned int>::const_iterator id = ids.begin();
424  id != ids.end(); ++id )
425  {
426  TEveGeoShape* shape = m_geom->getEveShape( *id );
428  m_trackerBarrelElements->AddElement( shape );
429  }
431  for( std::vector<unsigned int>::const_iterator id = ids.begin();
432  id != ids.end(); ++id )
433  {
434  TEveGeoShape* shape = m_geom->getEveShape( *id );
435 
436  shape->SetTitle(Form("TrackerBarrel %d",*id));
438  m_trackerBarrelElements->AddElement( shape );
439  }
440 
441  AddElement(m_trackerBarrelElements);
443  }
444 
446  {
447  m_trackerBarrelElements->SetRnrState(show);
448  gEve->Redraw3D();
449  }
450 }
451 
452 void
454 {
455  if( !m_trackerEndcapElements && show )
456  {
457  m_trackerEndcapElements = new TEveElementList("TrackerEndcap");
458 
459  std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::TID );
460  for( std::vector<unsigned int>::const_iterator id = ids.begin();
461  id != ids.end(); ++id )
462  {
463  TEveGeoShape* shape = m_geom->getEveShape( *id );
465  m_trackerEndcapElements->AddElement( shape );
466  }
468  for( std::vector<unsigned int>::const_iterator id = ids.begin();
469  id != ids.end(); ++id )
470  {
471  TEveGeoShape* shape = m_geom->getEveShape( *id );
472 
473  shape->SetTitle(Form("TrackerEndcap %d",*id));
475  m_trackerEndcapElements->AddElement( shape );
476  }
477 
478  AddElement(m_trackerEndcapElements);
480  }
481 
483  {
484  m_trackerEndcapElements->SetRnrState(show);
485  gEve->Redraw3D();
486  }
487 }
488 
489 //---------------------------------------------------------
490 void
492 {
493  if( !m_rpcEndcapElements && show )
494  {
495  m_rpcEndcapElements = new TEveElementList("RpcEndcap");
496 
497 
498  std::vector<RPCDetId> ids;
499  int mxSt = m_geom->versionInfo().haveExtraDet("RE4") ? 4:3;
500  for (int region = -1; region <=1; ++ region )
501  {
502  if (region == 0 ) continue;
503  for (int ring = 2; ring <= 3; ++ring) {
504  for (int station = 1; station <= mxSt; ++station ) {
505  int sector = 1;
506  ids.push_back(RPCDetId(region, ring, station, sector, 1, 1, 1));
507  ids.push_back(RPCDetId(region, ring, station, sector, 1, 1, 2));
508  ids.push_back(RPCDetId(region, ring, station, sector, 1, 1, 3));
509  if (ring == 2 && station == 1) { // 2 layers in ring 2 station 1 up
510  ids.push_back(RPCDetId(region, ring, station, sector, 1, 2, 1));
511  ids.push_back(RPCDetId(region, ring, station, sector, 1, 2, 2));
512  ids.push_back(RPCDetId(region, ring, station, sector, 1, 2, 3));
513  }
514  sector = 5;
515  ids.push_back(RPCDetId(region, ring, station, sector, 1, 1, 1));
516  ids.push_back(RPCDetId(region, ring, station, sector, 1, 1, 2));
517  ids.push_back(RPCDetId(region, ring, station, sector, 1, 1, 3));
518 
519  if (ring == 2 && station == 1) { // 2 layers in ring 2 station 1 down
520  ids.push_back(RPCDetId(region, ring, station, sector, 1, 2, 1));
521  ids.push_back(RPCDetId(region, ring, station, sector, 1, 2, 2));
522  ids.push_back(RPCDetId(region, ring, station, sector, 1, 2, 3));
523  }
524  }
525  }
526  }
527 
528  for (std::vector<RPCDetId>::iterator i = ids.begin(); i != ids.end(); ++i)
529  {
530  TEveGeoShape* shape = m_geom->getEveShape(i->rawId());
532  m_rpcEndcapElements->AddElement(shape);
533  gEve->AddToListTree(shape, true);
534  }
535 
536  AddElement(m_rpcEndcapElements);
538  }
539 
541  {
542  m_rpcEndcapElements->SetRnrState(show);
543  gEve->Redraw3D();
544  }
545 }
546 
547 //______________________________________________________________________________
548 
549 void
551 {
552  if( !m_GEMElements && show )
553  {
554  m_GEMElements = new TEveElementList("GEM");
555 
556 
557  std::vector<GEMDetId> ids;
558  int rArr [] = { -1, 1}; // front back region
559  int cArr [] = { 9, 10, 29, 30}; // top bottom chamber
560 
561  for (int ri = 0; ri < 2; ++ri )
562  for (int ci= 0; ci < 4; ++ci) {
563  int minRoll = 2;
564  //if (ci == 1 || ci == 3) minRoll = 2;
565  for (int roll = minRoll; roll <=10; ++roll)
566  for (int layer = 1; layer <=2; ++layer)
567  {
568  GEMDetId id(rArr[ri], 1, 1, layer, cArr[ci], roll);
569  TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
571  m_GEMElements->AddElement( shape );
572  }
573  }
574 
575 
576 
577  AddElement(m_GEMElements);
579  }
580  if (m_GEMElements)
581  {
582  m_GEMElements->SetRnrState(show);
583  gEve->Redraw3D();
584  }
585 }
586 //-------------------------------------
587 
588 void FWRPZViewGeometry::importNew(TEveElementList* x)
589 {
590  TEveProjected* proj = *BeginProjecteds();
591  proj->GetManager()->SubImportElements(x, proj->GetProjectedAsElement());
592 
593 }
const double TwoPi
type
Definition: HCALResponse.h:21
TEveElementList * m_pixelBarrelElements
int i
Definition: DBlmapReader.cc:9
static const TGPicture * info(bool iBackgroundIsBlack)
FWRPZViewGeometry(const fireworks::Context &context)
TEveCompound * m_colorComp[kFWGeomColorSize]
static int minEndcapId()
Definition: CSCDetId.h:249
void estimateProjectionSizeDT(const FWGeometry::GeomDetInfo &info, float &, float &, float &, float &)
IdToInfoItr find(unsigned int) const
Definition: FWGeometry.cc:358
TEveElementList * m_GEMElements
TEveElementList * m_rhoPhiGeo
TEveElement * makeCaloOutlineRhoPhi()
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
FWColorManager * colorManager() const
Definition: Context.h:65
Definition: DDAxes.h:10
static float caloZ2(bool offset=true)
Definition: Context.cc:224
const VersionInfo & versionInfo() const
Definition: FWGeometry.h:117
TEveElementList * m_rpcEndcapElements
void addToCompound(TEveElement *el, FWGeomColorIndex idx, bool applyTransp=true) const
TEveGeoShape * makeShape(double, double, double, double)
void initStdGeoElements(const FWViewType::EType id)
bool haveExtraDet(const char *) const
Definition: FWGeometry.cc:379
static float caloR2(bool offset=true)
Definition: Context.cc:214
TEveElement * makeMuonGeometryRhoPhi()
void importNew(TEveElementList *x)
TEveElementList * m_trackerBarrelElements
void estimateProjectionSize(const float *, float &, float &, float &, float &)
TEveGeoShape * getEveShape(unsigned int id) const
Definition: FWGeometry.cc:253
TEveElementList * m_pixelEndcapElements
T sqrt(T t)
Definition: SSEVec.h:48
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
void localToGlobal(unsigned int id, const float *local, float *global, bool translatep=true) const
Definition: FWGeometry.cc:328
static int maxEndcapId()
Definition: CSCDetId.h:250
static float caloR1(bool offset=true)
Definition: Context.cc:209
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
const FWGeometry * m_geom
TEveElementList * m_rhoZGeo
TEveElement * makeCaloOutlineRhoZ()
void showTrackerBarrel(bool)
TEveElementList * m_trackerEndcapElements
std::vector< unsigned int > getMatchedIds(Detector det, SubDetector subdet) const
Definition: FWGeometry.cc:197
TEveElement * makeMuonGeometryRhoZ()
static double caloMaxEta()
Definition: Context.cc:239
static float caloZ1(bool offset=true)
Definition: Context.cc:219
void showTrackerEndcap(bool)
Definition: DDAxes.h:10
Color_t geomColor(FWGeomColorIndex) const
const fireworks::Context & m_context
virtual ~FWRPZViewGeometry()
std::vector< FWGeometry::GeomDetInfo >::const_iterator IdToInfoItr
Definition: FWGeometry.h:107