CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWPFEcalRecHitLegoProxyBuilder.cc
Go to the documentation of this file.
2 
3 //______________________________________________________________________________
4 void
6 {
7  FWViewEnergyScale *caloScale = vc->getEnergyScale();
8  bool b = caloScale->getPlotEt();
9  float maxVal = getMaxVal( b );
10  typedef std::vector<FWPFLegoRecHit*> rh;
11 
12  // printf("FWPFEcalRecHitLegoProxyBuilder::scaleProduct >> scale %f \n", caloScale->getValToHeight());
13  for( rh::iterator i = m_recHits.begin(); i != m_recHits.end(); ++i )
14  { // Tallest tower needs deciding still
15  if( (*i)->isTallest() == false && (*i)->getEtEnergy( b ) == maxVal )
16  (*i)->setIsTallest( true );
17 
18  (*i)->updateScale( vc);
19  }
20 }
21 
22 //______________________________________________________________________________
23 void
25  FWViewType::EType viewType, const FWViewContext *vc )
26 {
27  for (TEveElement::List_i i = parent->BeginChildren(); i!= parent->EndChildren(); ++i)
28  {
29  {
30  TEveStraightLineSet* line = dynamic_cast<TEveStraightLineSet*>(*i);
31  if (line)
32  {
33  const FWDisplayProperties &p = item()->modelInfo( iId.index() ).displayProperties();
34  line->SetMarkerColor( p.color() );
35  }
36  }
37  }
38 }
39 
40 //______________________________________________________________________________
41 TEveVector
42 FWPFEcalRecHitLegoProxyBuilder::calculateCentre( const std::vector<TEveVector> &corners ) const
43 {
44  TEveVector centre;
45 
46  for( size_t i = 0; i < corners.size(); ++i )
47  {
48  centre.fX += corners[i].fX;
49  centre.fY += corners[i].fY; // Get total for x,y,z values
50  centre.fZ += corners[i].fZ;
51  }
52  centre *= 1.f / 8.f;
53 
54  return centre;
55 }
56 
57 //______________________________________________________________________________
58 float
59 FWPFEcalRecHitLegoProxyBuilder::calculateEt( const TEveVector &centre, float E )
60 {
61  TEveVector vec = centre;
62  float et;
63 
64  vec.Normalize();
65  vec *= E;
66  et = vec.Perp();
67 
68  return et;
69 }
70 
71 //______________________________________________________________________________
72 void
73 FWPFEcalRecHitLegoProxyBuilder::build( const FWEventItem *iItem, TEveElementList *product, const FWViewContext *vc )
74 {
75  float maxEnergy = 0.0f;
76  float maxEt = 0.0f;
77  size_t itemSize = iItem->size(); //cache size
78 
79  for( size_t index = 0; index < itemSize; ++index )
80  {
81  TEveCompound *itemHolder = createCompound();
82  product->AddElement( itemHolder );
83 
84  const EcalRecHit &iData = modelData( index );
85  const float *corners = item()->getGeom()->getCorners( iData.detid() );
86  float energy, et;
87  std::vector<TEveVector> etaphiCorners(8);
88  TEveVector centre;
89 
90  if( corners == 0 )
91  continue;
92 
93  int k = 3;
94  for( int i = 0; i < 4; ++i )
95  {
96  int j = k * 3;
97  TEveVector cv = TEveVector( corners[j], corners[j+1], corners[j+2] );
98  etaphiCorners[i].fX = cv.Eta(); // Conversion of rechit X/Y values for plotting in Eta/Phi
99  etaphiCorners[i].fY = cv.Phi();
100  etaphiCorners[i].fZ = 0.0;
101 
102  etaphiCorners[i+4].fX = etaphiCorners[i].fX; // Top can simply be plotted exactly over the top of the bottom face
103  etaphiCorners[i+4].fY = etaphiCorners[i].fY;
104  etaphiCorners[i+4].fZ = 0.001;
105  // printf("%f %f %d \n", etaphiCorners[i].fX, etaphiCorners[i].fY, i);
106  --k;
107  }
108 
109  centre = calculateCentre( etaphiCorners );
110  energy = iData.energy();
111  et = calculateEt( centre, energy );
112  context().voteMaxEtAndEnergy( et, energy );
113 
114  if( energy > maxEnergy )
115  maxEnergy = energy;
116  if( energy > maxEt )
117  maxEt = et;
118 
119  // Stop phi wrap
120  float dPhi1 = etaphiCorners[2].fY - etaphiCorners[1].fY;
121  float dPhi2 = etaphiCorners[3].fY - etaphiCorners[0].fY;
122  float dPhi3 = etaphiCorners[1].fY - etaphiCorners[2].fY;
123  float dPhi4 = etaphiCorners[0].fY - etaphiCorners[3].fY;
124 
125  if( dPhi1 > 1 )
126  etaphiCorners[2].fY = etaphiCorners[2].fY - ( 2 * TMath::Pi() );
127  if( dPhi2 > 1 )
128  etaphiCorners[3].fY = etaphiCorners[3].fY - ( 2 * TMath::Pi() );
129  if( dPhi3 > 1 )
130  etaphiCorners[2].fY = etaphiCorners[2].fY + ( 2 * TMath::Pi() );
131  if( dPhi4 > 1 )
132  etaphiCorners[3].fY = etaphiCorners[3].fY + ( 2 * TMath::Pi() );
133 
134  FWPFLegoRecHit *recHit = new FWPFLegoRecHit( etaphiCorners, itemHolder, this, vc, energy, et );
135  recHit->setSquareColor(item()->defaultDisplayProperties().color());
136  m_recHits.push_back( recHit );
137  }
138 
139  m_maxEnergy = maxEnergy;
140  m_maxEt = maxEt;
141  m_maxEnergyLog = log(maxEnergy);
142  m_maxEtLog = log(maxEt);
143 
144  scaleProduct( product, FWViewType::kLegoPFECAL, vc );
145 }
146 
147 //______________________________________________________________________________
148 void
150 {
151  for( std::vector<FWPFLegoRecHit*>::iterator i = m_recHits.begin(); i != m_recHits.end(); ++i )
152  delete (*i);
153 
154  m_recHits.clear();
155 }
156 
157 //______________________________________________________________________________
const double Pi
type
Definition: HCALResponse.h:22
const fireworks::Context & context() const
int i
Definition: DBlmapReader.cc:9
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
list parent
Definition: dbtoconf.py:74
const DetId & detid() const
Definition: CaloRecHit.h:21
TEveVector calculateCentre(const std::vector< TEveVector > &corners) const
void voteMaxEtAndEnergy(float Et, float energy) const
Definition: Context.cc:185
FWViewEnergyScale * getEnergyScale() const
virtual void scaleProduct(TEveElementList *parent, FWViewType::EType, const FWViewContext *vc)
const FWEventItem * item() const
const EcalRecHit & modelData(int index)
Color_t color() const
int index() const
Definition: FWModelId.h:50
float energy() const
Definition: CaloRecHit.h:19
int j
Definition: DBlmapReader.cc:9
void setSquareColor(Color_t c)
virtual void localModelChanges(const FWModelId &iId, TEveElement *iCompound, FWViewType::EType viewType, const FWViewContext *vc)
int k[5][pyjets_maxn]
float calculateEt(const TEveVector &centre, float E)
const float * getCorners(unsigned int id) const
Definition: FWGeometry.cc:278
Log< T >::type log(const T &t)
Definition: Log.h:22
size_t size() const
Definition: FWEventItem.cc:549
double b
Definition: hdecay.h:120
TEveCompound * createCompound(bool set_color=true, bool propagate_color_to_all_children=false) const
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:536
std::vector< FWPFLegoRecHit * > m_recHits
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:688
bool getPlotEt() const