CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWHFTowerProxyBuilder.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Calo
4 // Class : FWHFTowerProxyBuilder
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author:
10 // Created: Mon May 31 16:41:27 CEST 2010
11 // $Id: FWHFTowerProxyBuilder.cc,v 1.22 2011/09/06 15:07:30 yana Exp $
12 //
13 
14 // system include files
15 
16 // user include files
17 #include "TEveCaloData.h"
18 #include "TEveCalo.h"
19 #include "TH2F.h"
20 
28 
30  m_hits(0),
31  // m_depth(depth),
32  m_vecData(0)
33 {}
34 
36 {}
37 
38 //
39 // member functions
40 void
42 {
43  m_vecData = ctx.getCaloDataHF();// cached to avoid casting
45 }
46 
47 bool
49 {
50  if (m_sliceIndex == -1)
51  {
52  m_sliceIndex = m_vecData->AddSlice();
53  // printf("add slice %d \n",m_sliceIndex );
54  m_caloData->RefSliceInfo(m_sliceIndex).Setup(item()->name().c_str() , 0.,
55  item()->defaultDisplayProperties().color(),
56  item()->defaultDisplayProperties().transparency());
57 
58  // add new selector
60  if (m_caloData->GetUserData())
61  {
62  FWFromEveSelectorBase* base = reinterpret_cast<FWFromEveSelectorBase*>(m_caloData->GetUserData());
63  assert(0!=base);
64  sel = dynamic_cast<FWFromTEveCaloDataSelector*> (base);
65  assert(0!=sel);
66  }
67  else
68  {
70  //make sure it is accessible via the base class
71  m_caloData->SetUserData(static_cast<FWFromEveSelectorBase*>(sel));
72  }
73 
75 
76  return true;
77  }
78  return false;
79 }
80 
81 void
83  TEveElementList* el, const FWViewContext* ctx)
84 {
85  m_hits=0;
86  if (iItem)
87  {
88  iItem->get(m_hits);
89  FWCaloDataProxyBuilderBase::build(iItem, el, ctx);
90  }
91 }
92 
93 void
95 {
96 
97  if(0!=m_hits) {
98 
99  //reset values for this slice
100  std::vector<float>& sliceVals = m_vecData->GetSliceVals(m_sliceIndex);
101  for (std::vector<float>::iterator i = sliceVals.begin(); i!= sliceVals.end(); ++i)
102  {
103  *i = 0;
104  }
105 
106 
107  }
109 }
110 
111 void
113 {
114  //reset values for this slice
115  std::vector<float>& sliceVals = m_vecData->GetSliceVals(m_sliceIndex);
116  for (std::vector<float>::iterator i = sliceVals.begin(); i!= sliceVals.end(); ++i)
117  {
118  *i = 0;
119  }
120 
121  if (m_hits)
122  {
123  TEveCaloData::vCellId_t& selected = m_vecData->GetCellsSelected();
124 
125  if(item()->defaultDisplayProperties().isVisible()) {
126  assert(item()->size() >= m_hits->size());
127 
128  unsigned int index=0;
129  TEveCaloData::vCellId_t cellId;
130  for(HFRecHitCollection::const_iterator it = m_hits->begin(); it != m_hits->end(); ++it,++index)
131  {
132  const FWEventItem::ModelInfo& info = item()->modelInfo(index);
133  if(info.displayProperties().isVisible())
134  {
135  unsigned int rawid = (*it).detid().rawId();
136  int tower = fillTowerForDetId(rawid, (*it).energy());
137 
138  if(info.isSelected())
139  {
140  selected.push_back(TEveCaloData::CellId_t(tower, m_sliceIndex));
141  }
142  }
143  }
144  }
145  }
146 }
147 
148 int
149 FWHFTowerProxyBuilderBase::fillTowerForDetId( unsigned int rawid, float val )
150 {
151  using namespace TMath;
152  const static float upPhiLimit = Pi() -10*DegToRad() -1e-5;
153 
154  TEveCaloData::vCellId_t cellIds;
155  const FWGeometry *geom = item()->getGeom();
156  if( ! geom->contains( rawid ))
157  {
158  fwLog( fwlog::kInfo ) << "FWHFTowerProxyBuilderBase cannot get geometry for DetId: "<< rawid << ". Ignored.\n";
159  return -1;
160  }
161 
162  const float* corners = geom->getCorners( rawid );
163  if( ! corners )
164  {
165  fwLog( fwlog::kInfo ) << "FWHFTowerProxyBuilderBase cannot get corners for DetId: "<< rawid << ". Ignored.\n";
166  return -1;
167  }
168 
169  std::vector<TEveVector> front( 4 );
170  float eta[4], phi[4];
171  bool plusSignPhi = false;
172  bool minusSignPhi = false;
173  int j = 0;
174  for( int i = 0; i < 4; ++i )
175  {
176  front[i] = TEveVector( corners[j], corners[j + 1], corners[j + 2] );
177  j += 3;
178 
179  eta[i] = front[i].Eta();
180  phi[i] = front[i].Phi();
181 
182  // make sure sign around Pi is same as sign of fY
183  phi[i] = Sign( phi[i], front[i].fY );
184 
185  ( phi[i] >= 0 ) ? plusSignPhi = true : minusSignPhi = true;
186  }
187 
188  // check for cell around phi and move up edge to negative side
189  if( plusSignPhi && minusSignPhi )
190  {
191  for( int i = 0; i < 4; ++i )
192  {
193  if( phi[i] >= upPhiLimit )
194  {
195  // printf("over phi max limit %f \n", phi[i]);
196  phi[i] -= TwoPi();
197  }
198  }
199  }
200 
201  float etaM = -10;
202  float etam = 10;
203  float phiM = -4;
204  float phim = 4;
205  for( int i = 0; i < 4; ++i )
206  {
207  etam = Min( etam, eta[i] );
208  etaM = Max( etaM, eta[i] );
209  phim = Min( phim, phi[i] );
210  phiM = Max( phiM, phi[i] );
211  }
212 
213  /*
214  if (phiM - phim > 1)
215  printf("!!! [%.2f %.2f] input(%.3f, %.3f, %.3f, %.3f) \n", phim, phiM, phiRef[0] , phiRef[1] , phiRef[2], phiRef[3]);
216  */
217 
218  // check if tower is there
219  Float_t ceta = (etam+etaM)*0.5;
220  Float_t cphi = (phim+phiM)*0.5;
221  int tower = -1;
222  int idx = 0;
223  for ( TEveCaloData::vCellGeom_i i = m_vecData->GetCellGeom().begin(); i!= m_vecData->GetCellGeom().end(); ++i, ++idx)
224  {
225  const TEveCaloData::CellGeom_t &cg = *i;
226  if ((ceta > cg.fEtaMin && ceta < cg.fEtaMax) && (cphi > cg.fPhiMin && cphi < cg.fPhiMax))
227  {
228  tower = idx;
229  break;
230  }
231  }
232 
233  // add it if not there
234  if (tower == -1 )
235  {
236  tower = m_vecData->AddTower(etam, etaM, phim, phiM);
237  }
238 
239 
240  m_vecData->FillSlice(m_sliceIndex, tower, val);
241  return tower;
242 }
243 
245 
246 
tuple base
Main Program
Definition: newFWLiteAna.py:92
const double TwoPi
const double Pi
int i
Definition: DBlmapReader.cc:9
TEveCaloDataVec * getCaloDataHF() const
Definition: Context.h:82
const FWDisplayProperties & displayProperties() const
Definition: FWEventItem.h:68
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
static const int kAllRPZBits
Definition: FWViewType.h:59
bool isSelected() const
Definition: FWEventItem.h:71
void get(const T *&oData) const
Definition: FWEventItem.h:85
std::vector< T >::const_iterator const_iterator
T eta() const
void addSliceSelector(int iSlice, FWFromSliceSelector *)
const FWEventItem * item() const
virtual void itemBeingDestroyed(const FWEventItem *)
int j
Definition: DBlmapReader.cc:9
const_iterator end() const
virtual void setCaloData(const fireworks::Context &)
#define fwLog(_level_)
Definition: fwLog.h:51
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
size_type size() const
const HFRecHitCollection * m_hits
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:536
int fillTowerForDetId(unsigned int rawid, float)
tuple size
Write out results.
virtual void itemBeingDestroyed(const FWEventItem *)
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:682
const_iterator begin() const
Definition: DDAxes.h:10