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;
106  for (HFRecHitCollection::const_iterator it = m_hits->begin(); it != m_hits->end(); ++it, ++index) {
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",
FWModelChangeManager.h
fwLog
#define fwLog(_level_)
Definition: fwLog.h:45
FWEventItem::modelInfo
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:446
mps_fire.i
i
Definition: mps_fire.py:355
FWHFTowerProxyBuilderBase::setCaloData
void setCaloData(const fireworks::Context &) override
Definition: FWHFTowerProxyBuilder.cc:37
edm::SortedCollection::const_iterator
std::vector< T >::const_iterator const_iterator
Definition: SortedCollection.h:80
fireworks::Context
Definition: Context.h:41
FWHFTowerProxyBuilderBase::m_vecData
TEveCaloDataVec * m_vecData
Definition: FWHFTowerProxyBuilder.h:64
FWGeometry
Definition: FWGeometry.h:27
TwoPi
const double TwoPi
Definition: CosmicMuonParameters.h:19
FWViewType::kAllRPZBits
static const int kAllRPZBits
Definition: FWViewType.h:67
REGISTER_FWPROXYBUILDER
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
Definition: FWProxyBuilderFactory.h:33
FWHFTowerSliceSelector
Definition: FWHFTowerSliceSelector.h:31
FWHFTowerProxyBuilder.h
FWEventItem::get
void get(const T *&oData) const
Definition: FWEventItem.h:78
FWCaloDataProxyBuilderBase::itemBeingDestroyed
void itemBeingDestroyed(const FWEventItem *) override
Definition: FWCaloDataProxyBuilderBase.cc:106
hgcalTowerProducer_cfi.tower
tower
Definition: hgcalTowerProducer_cfi.py:3
Sign
T Sign(T A, T B)
Definition: MathUtil.h:54
cms::cuda::assert
assert(be >=bs)
edm::SortedCollection
Definition: SortedCollection.h:49
edm::SortedCollection::size
size_type size() const
Definition: SortedCollection.h:215
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:152
FWHFTowerProxyBuilderBase
Definition: FWHFTowerProxyBuilder.h:33
training_settings.idx
idx
Definition: training_settings.py:16
fireworks::Context::getCaloDataHF
TEveCaloDataVec * getCaloDataHF() const
Definition: Context.h:70
FWHFTowerProxyBuilderBase::itemBeingDestroyed
void itemBeingDestroyed(const FWEventItem *) override
Definition: FWHFTowerProxyBuilder.cc:80
FWEventItem::ModelInfo
Definition: FWEventItem.h:58
FWCaloDataProxyBuilderBase::m_sliceIndex
Int_t m_sliceIndex
Definition: FWCaloDataProxyBuilderBase.h:56
edm::SortedCollection::begin
const_iterator begin() const
Definition: SortedCollection.h:262
PVValHelper::eta
Definition: PVValidationHelpers.h:69
FWViewType::kLegoHFBit
Definition: FWViewType.h:56
FWHFTowerProxyBuilderBase::assertCaloDataSlice
bool assertCaloDataSlice() override
Definition: FWHFTowerProxyBuilder.cc:42
relativeConstraints.geom
geom
Definition: relativeConstraints.py:72
FWHFTowerProxyBuilderBase::fillCaloData
void fillCaloData() override
Definition: FWHFTowerProxyBuilder.cc:91
FWGeometry.h
FWHFTowerProxyBuilderBase::fillTowerForDetId
int fillTowerForDetId(unsigned int rawid, float)
Definition: FWHFTowerProxyBuilder.cc:121
FWCaloDataProxyBuilderBase::m_caloData
TEveCaloData * m_caloData
Definition: FWCaloDataProxyBuilderBase.h:55
edm::SortedCollection::end
const_iterator end() const
Definition: SortedCollection.h:267
FWHFTowerProxyBuilderBase::FWHFTowerProxyBuilderBase
FWHFTowerProxyBuilderBase()
Definition: FWHFTowerProxyBuilder.cc:28
FWFromTEveCaloDataSelector
Definition: FWFromTEveCaloDataSelector.h:34
FWFromEveSelectorBase
Definition: FWFromEveSelectorBase.h:27
Max
T Max(T a, T b)
Definition: MathUtil.h:44
fwLog.h
FWProxyBuilderBase::build
void build()
Definition: FWProxyBuilderBase.cc:110
FWEventItem.h
FWViewContext
Definition: FWViewContext.h:32
FWEventItem::getGeom
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:548
DDAxes::phi
FWHFTowerProxyBuilderBase::~FWHFTowerProxyBuilderBase
~FWHFTowerProxyBuilderBase() override
Definition: FWHFTowerProxyBuilder.cc:33
FWProxyBuilderBase::item
const FWEventItem * item() const
Definition: FWProxyBuilderBase.h:64
fwlog::kInfo
Definition: fwLog.h:35
FWEventItem
Definition: FWEventItem.h:56
heppy_batch.val
val
Definition: heppy_batch.py:351
FWViewType::k3DBit
Definition: FWViewType.h:50
FWHFTowerSliceSelector.h
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
Pi
const double Pi
Definition: CosmicMuonParameters.h:18
EgammaValidation_Wenu_cff.sel
sel
Definition: EgammaValidation_Wenu_cff.py:33
Min
T Min(T a, T b)
Definition: MathUtil.h:39
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
newFWLiteAna.base
base
Definition: newFWLiteAna.py:92
FWHFTowerProxyBuilderBase::m_hits
const HFRecHitCollection * m_hits
Definition: FWHFTowerProxyBuilder.h:62
Context.h
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37