File indexing completed on 2024-04-06 12:11:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "TEveCaloData.h"
0017 #include "TEveCalo.h"
0018 #include "TH2F.h"
0019
0020 #include "Fireworks/Calo/plugins/FWHGTowerProxyBuilder.h"
0021 #include "Fireworks/Calo/plugins/FWHGTowerSliceSelector.h"
0022 #include "Fireworks/Core/interface/Context.h"
0023 #include "Fireworks/Core/interface/FWEventItem.h"
0024 #include "Fireworks/Core/interface/FWGeometry.h"
0025 #include "Fireworks/Core/interface/FWModelChangeManager.h"
0026 #include "Fireworks/Core/interface/fwLog.h"
0027
0028 FWHGTowerProxyBuilderBase::FWHGTowerProxyBuilderBase()
0029 : m_hits(nullptr),
0030
0031 m_vecData(nullptr) {}
0032
0033 FWHGTowerProxyBuilderBase::~FWHGTowerProxyBuilderBase() {}
0034
0035
0036
0037 void FWHGTowerProxyBuilderBase::setCaloData(const fireworks::Context& ctx) {
0038 m_vecData = ctx.getCaloDataHF();
0039 m_caloData = m_vecData;
0040 }
0041
0042 bool FWHGTowerProxyBuilderBase::assertCaloDataSlice() {
0043 if (m_sliceIndex == -1) {
0044 m_sliceIndex = m_vecData->AddSlice();
0045
0046 m_caloData->RefSliceInfo(m_sliceIndex)
0047 .Setup(item()->name().c_str(),
0048 0.,
0049 item()->defaultDisplayProperties().color(),
0050 item()->defaultDisplayProperties().transparency());
0051
0052
0053 FWFromTEveCaloDataSelector* sel = nullptr;
0054 if (m_caloData->GetUserData()) {
0055 FWFromEveSelectorBase* base = reinterpret_cast<FWFromEveSelectorBase*>(m_caloData->GetUserData());
0056 assert(nullptr != base);
0057 sel = dynamic_cast<FWFromTEveCaloDataSelector*>(base);
0058 assert(nullptr != sel);
0059 } else {
0060 sel = new FWFromTEveCaloDataSelector(m_caloData);
0061
0062 m_caloData->SetUserData(static_cast<FWFromEveSelectorBase*>(sel));
0063 }
0064
0065 sel->addSliceSelector(m_sliceIndex, new FWHGTowerSliceSelector(item(), m_vecData));
0066
0067 return true;
0068 }
0069 return false;
0070 }
0071
0072 void FWHGTowerProxyBuilderBase::build(const FWEventItem* iItem, TEveElementList* el, const FWViewContext* ctx) {
0073 m_hits = nullptr;
0074 if (iItem) {
0075 iItem->get(m_hits);
0076 FWCaloDataProxyBuilderBase::build(iItem, el, ctx);
0077 }
0078 }
0079
0080 void FWHGTowerProxyBuilderBase::itemBeingDestroyed(const FWEventItem* iItem) {
0081 if (nullptr != m_hits) {
0082
0083 std::vector<float>& sliceVals = m_vecData->GetSliceVals(m_sliceIndex);
0084 for (std::vector<float>::iterator i = sliceVals.begin(); i != sliceVals.end(); ++i) {
0085 *i = 0;
0086 }
0087 }
0088 FWCaloDataProxyBuilderBase::itemBeingDestroyed(iItem);
0089 }
0090
0091 void FWHGTowerProxyBuilderBase::fillCaloData() {
0092
0093 std::vector<float>& sliceVals = m_vecData->GetSliceVals(m_sliceIndex);
0094 for (std::vector<float>::iterator i = sliceVals.begin(); i != sliceVals.end(); ++i) {
0095 *i = 0;
0096 }
0097
0098 if (m_hits) {
0099 TEveCaloData::vCellId_t& selected = m_vecData->GetCellsSelected();
0100
0101 if (item()->defaultDisplayProperties().isVisible()) {
0102 assert(item()->size() >= m_hits->size());
0103
0104 unsigned int index = 0;
0105 TEveCaloData::vCellId_t cellId;
0106 for (HGCRecHitCollection::const_iterator it = m_hits->begin(); it != m_hits->end(); ++it, ++index) {
0107 const FWEventItem::ModelInfo& info = item()->modelInfo(index);
0108 if (info.displayProperties().isVisible()) {
0109 unsigned int rawid = (*it).detid().rawId();
0110 int tower = fillTowerForDetId(rawid, (*it).energy());
0111
0112 if (info.isSelected()) {
0113 selected.push_back(TEveCaloData::CellId_t(tower, m_sliceIndex));
0114 }
0115 }
0116 }
0117 }
0118 }
0119 }
0120
0121 int FWHGTowerProxyBuilderBase::fillTowerForDetId(unsigned int rawid, float val) {
0122 using namespace TMath;
0123 const static float upPhiLimit = Pi() - 10 * DegToRad() - 1e-5;
0124
0125 TEveCaloData::vCellId_t cellIds;
0126 const FWGeometry* geom = item()->getGeom();
0127 if (!geom->contains(rawid)) {
0128 fwLog(fwlog::kInfo) << "FWHGTowerProxyBuilderBase cannot get geometry for DetId: " << rawid << ". Ignored.\n";
0129 return -1;
0130 }
0131
0132 const float* corners = geom->getCorners(rawid);
0133 if (!corners) {
0134 fwLog(fwlog::kInfo) << "FWHGTowerProxyBuilderBase cannot get corners for DetId: " << rawid << ". Ignored.\n";
0135 return -1;
0136 }
0137
0138 std::vector<TEveVector> front(4);
0139 float eta[4], phi[4];
0140 bool plusSignPhi = false;
0141 bool minusSignPhi = false;
0142 int j = 0;
0143 for (int i = 0; i < 4; ++i) {
0144 front[i] = TEveVector(corners[j], corners[j + 1], corners[j + 2]);
0145 j += 3;
0146
0147 eta[i] = front[i].Eta();
0148 phi[i] = front[i].Phi();
0149
0150
0151 phi[i] = Sign(phi[i], front[i].fY);
0152
0153 (phi[i] >= 0) ? plusSignPhi = true : minusSignPhi = true;
0154 }
0155
0156
0157 if (plusSignPhi && minusSignPhi) {
0158 for (int i = 0; i < 4; ++i) {
0159 if (phi[i] >= upPhiLimit) {
0160
0161 phi[i] -= TwoPi();
0162 }
0163 }
0164 }
0165
0166 float etaM = -10;
0167 float etam = 10;
0168 float phiM = -4;
0169 float phim = 4;
0170 for (int i = 0; i < 4; ++i) {
0171 etam = Min(etam, eta[i]);
0172 etaM = Max(etaM, eta[i]);
0173 phim = Min(phim, phi[i]);
0174 phiM = Max(phiM, phi[i]);
0175 }
0176
0177
0178
0179
0180
0181
0182
0183 Float_t ceta = (etam + etaM) * 0.5;
0184 Float_t cphi = (phim + phiM) * 0.5;
0185 int tower = -1;
0186 int idx = 0;
0187 for (TEveCaloData::vCellGeom_i i = m_vecData->GetCellGeom().begin(); i != m_vecData->GetCellGeom().end();
0188 ++i, ++idx) {
0189 const TEveCaloData::CellGeom_t& cg = *i;
0190 if ((ceta > cg.fEtaMin && ceta < cg.fEtaMax) && (cphi > cg.fPhiMin && cphi < cg.fPhiMax)) {
0191 tower = idx;
0192 break;
0193 }
0194 }
0195
0196
0197 if (tower == -1) {
0198 tower = m_vecData->AddTower(etam, etaM, phim, phiM);
0199 }
0200
0201 m_vecData->FillSlice(m_sliceIndex, tower, val);
0202 return tower;
0203 }
0204
0205 REGISTER_FWPROXYBUILDER(FWHGTowerProxyBuilderBase,
0206 HGCRecHitCollection,
0207 "HGCalLego",
0208 FWViewType::kLegoHFBit | FWViewType::kAllRPZBits | FWViewType::k3DBit);