CMS 3D CMS Logo

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 //
12 
13 // system include files
14 
15 // user include files
16 #include "TEveCaloData.h"
17 #include "TEveCalo.h"
18 #include "TH2F.h"
19 
27 
29  : m_hits(nullptr),
30  // m_depth(depth),
31  m_vecData(nullptr) {}
32 
34 
35 //
36 // member functions
38  m_vecData = ctx.getCaloDataHF(); // cached to avoid casting
40 }
41 
43  if (m_sliceIndex == -1) {
44  m_sliceIndex = m_vecData->AddSlice();
45  // printf("add slice %d \n",m_sliceIndex );
46  m_caloData->RefSliceInfo(m_sliceIndex)
47  .Setup(item()->name().c_str(),
48  0.,
49  item()->defaultDisplayProperties().color(),
50  item()->defaultDisplayProperties().transparency());
51 
52  // add new selector
54  if (m_caloData->GetUserData()) {
55  FWFromEveSelectorBase* base = reinterpret_cast<FWFromEveSelectorBase*>(m_caloData->GetUserData());
56  assert(nullptr != base);
57  sel = dynamic_cast<FWFromTEveCaloDataSelector*>(base);
58  assert(nullptr != sel);
59  } else {
61  //make sure it is accessible via the base class
62  m_caloData->SetUserData(static_cast<FWFromEveSelectorBase*>(sel));
63  }
64 
65  sel->addSliceSelector(m_sliceIndex, new FWHFTowerSliceSelector(item(), m_vecData));
66 
67  return true;
68  }
69  return false;
70 }
71 
72 void FWHFTowerProxyBuilderBase::build(const FWEventItem* iItem, TEveElementList* el, const FWViewContext* ctx) {
73  m_hits = nullptr;
74  if (iItem) {
75  iItem->get(m_hits);
76  FWCaloDataProxyBuilderBase::build(iItem, el, ctx);
77  }
78 }
79 
81  if (nullptr != m_hits) {
82  //reset values for this slice
83  std::vector<float>& sliceVals = m_vecData->GetSliceVals(m_sliceIndex);
84  for (std::vector<float>::iterator i = sliceVals.begin(); i != sliceVals.end(); ++i) {
85  *i = 0;
86  }
87  }
89 }
90 
92  //reset values for this slice
93  std::vector<float>& sliceVals = m_vecData->GetSliceVals(m_sliceIndex);
94  for (std::vector<float>::iterator i = sliceVals.begin(); i != sliceVals.end(); ++i) {
95  *i = 0;
96  }
97 
98  if (m_hits) {
99  TEveCaloData::vCellId_t& selected = m_vecData->GetCellsSelected();
100 
101  if (item()->defaultDisplayProperties().isVisible()) {
102  assert(item()->size() >= m_hits->size());
103 
104  unsigned int index = 0;
105  TEveCaloData::vCellId_t cellId;
108  if (info.displayProperties().isVisible()) {
109  unsigned int rawid = (*it).detid().rawId();
110  int tower = fillTowerForDetId(rawid, (*it).energy());
111 
112  if (info.isSelected()) {
113  selected.push_back(TEveCaloData::CellId_t(tower, m_sliceIndex));
114  }
115  }
116  }
117  }
118  }
119 }
120 
121 int FWHFTowerProxyBuilderBase::fillTowerForDetId(unsigned int rawid, float val) {
122  using namespace TMath;
123  const static float upPhiLimit = Pi() - 10 * DegToRad() - 1e-5;
124 
125  TEveCaloData::vCellId_t cellIds;
126  const FWGeometry* geom = item()->getGeom();
127  if (!geom->contains(rawid)) {
128  fwLog(fwlog::kInfo) << "FWHFTowerProxyBuilderBase cannot get geometry for DetId: " << rawid << ". Ignored.\n";
129  return -1;
130  }
131 
132  const float* corners = geom->getCorners(rawid);
133  if (!corners) {
134  fwLog(fwlog::kInfo) << "FWHFTowerProxyBuilderBase cannot get corners for DetId: " << rawid << ". Ignored.\n";
135  return -1;
136  }
137 
138  std::vector<TEveVector> front(4);
139  float eta[4], phi[4];
140  bool plusSignPhi = false;
141  bool minusSignPhi = false;
142  int j = 0;
143  for (int i = 0; i < 4; ++i) {
144  front[i] = TEveVector(corners[j], corners[j + 1], corners[j + 2]);
145  j += 3;
146 
147  eta[i] = front[i].Eta();
148  phi[i] = front[i].Phi();
149 
150  // make sure sign around Pi is same as sign of fY
151  phi[i] = Sign(phi[i], front[i].fY);
152 
153  (phi[i] >= 0) ? plusSignPhi = true : minusSignPhi = true;
154  }
155 
156  // check for cell around phi and move up edge to negative side
157  if (plusSignPhi && minusSignPhi) {
158  for (int i = 0; i < 4; ++i) {
159  if (phi[i] >= upPhiLimit) {
160  // printf("over phi max limit %f \n", phi[i]);
161  phi[i] -= TwoPi();
162  }
163  }
164  }
165 
166  float etaM = -10;
167  float etam = 10;
168  float phiM = -4;
169  float phim = 4;
170  for (int i = 0; i < 4; ++i) {
171  etam = Min(etam, eta[i]);
172  etaM = Max(etaM, eta[i]);
173  phim = Min(phim, phi[i]);
174  phiM = Max(phiM, phi[i]);
175  }
176 
177  /*
178  if (phiM - phim > 1)
179  printf("!!! [%.2f %.2f] input(%.3f, %.3f, %.3f, %.3f) \n", phim, phiM, phiRef[0] , phiRef[1] , phiRef[2], phiRef[3]);
180  */
181 
182  // check if tower is there
183  Float_t ceta = (etam + etaM) * 0.5;
184  Float_t cphi = (phim + phiM) * 0.5;
185  int tower = -1;
186  int idx = 0;
187  for (TEveCaloData::vCellGeom_i i = m_vecData->GetCellGeom().begin(); i != m_vecData->GetCellGeom().end();
188  ++i, ++idx) {
189  const TEveCaloData::CellGeom_t& cg = *i;
190  if ((ceta > cg.fEtaMin && ceta < cg.fEtaMax) && (cphi > cg.fPhiMin && cphi < cg.fPhiMax)) {
191  tower = idx;
192  break;
193  }
194  }
195 
196  // add it if not there
197  if (tower == -1) {
198  tower = m_vecData->AddTower(etam, etaM, phim, phiM);
199  }
200 
201  m_vecData->FillSlice(m_sliceIndex, tower, val);
202  return tower;
203 }
204 
207  "HFLego",
size
Write out results.
const double TwoPi
const double Pi
static const TGPicture * info(bool iBackgroundIsBlack)
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
void setCaloData(const fireworks::Context &) override
TEveCaloDataVec * getCaloDataHF() const
Definition: Context.h:70
static const int kAllRPZBits
Definition: FWViewType.h:67
size_type size() const
base
Main Program
Definition: newFWLiteAna.py:92
void get(const T *&oData) const
Definition: FWEventItem.h:78
std::vector< T >::const_iterator const_iterator
assert(be >=bs)
void itemBeingDestroyed(const FWEventItem *) override
void itemBeingDestroyed(const FWEventItem *) override
const_iterator begin() const
const_iterator end() const
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:548
#define fwLog(_level_)
Definition: fwLog.h:45
const HFRecHitCollection * m_hits
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:446
const FWEventItem * item() const
int fillTowerForDetId(unsigned int rawid, float)