File indexing completed on 2024-04-06 12:11:52
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Fireworks/Calo/interface/FWHeatmapProxyBuilderTemplate.h"
0010 #include "Fireworks/Core/interface/Context.h"
0011 #include "Fireworks/Core/interface/FWGeometry.h"
0012 #include "SimDataFormats/CaloAnalysis/interface/CaloParticle.h"
0013 #include "SimDataFormats/CaloAnalysis/interface/CaloParticleFwd.h"
0014 #include "SimDataFormats/CaloAnalysis/interface/SimCluster.h"
0015
0016 #include "TEveBoxSet.h"
0017
0018 class FWCaloParticleProxyBuilder : public FWHeatmapProxyBuilderTemplate<CaloParticle> {
0019 public:
0020 FWCaloParticleProxyBuilder(void) {}
0021 ~FWCaloParticleProxyBuilder(void) override {}
0022
0023 REGISTER_PROXYBUILDER_METHODS();
0024
0025
0026 FWCaloParticleProxyBuilder(const FWCaloParticleProxyBuilder &) = delete;
0027
0028 const FWCaloParticleProxyBuilder &operator=(const FWCaloParticleProxyBuilder &) = delete;
0029
0030 private:
0031 void build(const CaloParticle &iData, unsigned int iIndex, TEveElement &oItemHolder, const FWViewContext *) override;
0032 };
0033
0034 void FWCaloParticleProxyBuilder::build(const CaloParticle &iData,
0035 unsigned int iIndex,
0036 TEveElement &oItemHolder,
0037 const FWViewContext *) {
0038 const long layer = item()->getConfig()->value<long>("Layer");
0039 const double saturation_energy = item()->getConfig()->value<double>("EnergyCutOff");
0040 const bool heatmap = item()->getConfig()->value<bool>("Heatmap");
0041 const bool z_plus = item()->getConfig()->value<bool>("Z+");
0042 const bool z_minus = item()->getConfig()->value<bool>("Z-");
0043
0044 bool h_hex(false);
0045 TEveBoxSet *hex_boxset = new TEveBoxSet();
0046 if (!heatmap)
0047 hex_boxset->UseSingleColor();
0048 hex_boxset->SetPickable(true);
0049 hex_boxset->Reset(TEveBoxSet::kBT_Hex, true, 64);
0050 hex_boxset->SetAntiFlick(true);
0051
0052 bool h_box(false);
0053 TEveBoxSet *boxset = new TEveBoxSet();
0054 if (!heatmap)
0055 boxset->UseSingleColor();
0056 boxset->SetPickable(true);
0057 boxset->Reset(TEveBoxSet::kBT_FreeBox, true, 64);
0058 boxset->SetAntiFlick(true);
0059
0060 for (const auto &c : iData.simClusters()) {
0061 for (const auto &it : (*c).hits_and_fractions()) {
0062 if (heatmap && hitmap->find(it.first) == hitmap->end())
0063 continue;
0064
0065 const bool z = (it.first >> 25) & 0x1;
0066
0067
0068 if (((z_plus & z_minus) != 1) && (((z_plus | z_minus) == 0) || !(z == z_minus || z == !z_plus)))
0069 continue;
0070
0071 const float *corners = item()->getGeom()->getCorners(it.first);
0072 const float *parameters = item()->getGeom()->getParameters(it.first);
0073 const float *shapes = item()->getGeom()->getShapePars(it.first);
0074
0075 if (corners == nullptr || parameters == nullptr || shapes == nullptr) {
0076 continue;
0077 }
0078
0079 const int total_points = parameters[0];
0080 const bool isScintillator = (total_points == 4);
0081 const uint8_t type = ((it.first >> 28) & 0xF);
0082
0083 uint8_t ll = layer;
0084 if (layer > 0) {
0085 if (layer > 28) {
0086 if (type == 8) {
0087 continue;
0088 }
0089 ll -= 28;
0090 } else {
0091 if (type != 8) {
0092 continue;
0093 }
0094 }
0095
0096 if (ll != ((it.first >> (isScintillator ? 17 : 20)) & 0x1F))
0097 continue;
0098 }
0099
0100
0101 if (isScintillator) {
0102 const int total_vertices = 3 * total_points;
0103
0104 std::vector<float> pnts(24);
0105 for (int i = 0; i < total_points; ++i) {
0106 pnts[i * 3 + 0] = corners[i * 3];
0107 pnts[i * 3 + 1] = corners[i * 3 + 1];
0108 pnts[i * 3 + 2] = corners[i * 3 + 2];
0109
0110 pnts[(i * 3 + 0) + total_vertices] = corners[i * 3];
0111 pnts[(i * 3 + 1) + total_vertices] = corners[i * 3 + 1];
0112 pnts[(i * 3 + 2) + total_vertices] = corners[i * 3 + 2] + shapes[3];
0113 }
0114 boxset->AddBox(&pnts[0]);
0115 if (heatmap) {
0116 const uint8_t colorFactor = gradient_steps * (fmin(hitmap->at(it.first)->energy() / saturation_energy, 1.0f));
0117 boxset->DigitColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor]);
0118 }
0119
0120 h_box = true;
0121 }
0122
0123 else {
0124 const int offset = 9;
0125
0126 float centerX = (corners[6] + corners[6 + offset]) / 2;
0127 float centerY = (corners[7] + corners[7 + offset]) / 2;
0128 float radius = fabs(corners[6] - corners[6 + offset]) / 2;
0129 hex_boxset->AddHex(TEveVector(centerX, centerY, corners[2]), radius, shapes[2], shapes[3]);
0130 if (heatmap) {
0131 const uint8_t colorFactor = gradient_steps * (fmin(hitmap->at(it.first)->energy() / saturation_energy, 1.0f));
0132 hex_boxset->DigitColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor]);
0133 }
0134
0135 h_hex = true;
0136 }
0137 }
0138 }
0139
0140 if (h_hex) {
0141 hex_boxset->RefitPlex();
0142
0143 hex_boxset->CSCTakeAnyParentAsMaster();
0144 if (!heatmap) {
0145 hex_boxset->CSCApplyMainColorToMatchingChildren();
0146 hex_boxset->CSCApplyMainTransparencyToMatchingChildren();
0147 hex_boxset->SetMainColor(item()->modelInfo(iIndex).displayProperties().color());
0148 hex_boxset->SetMainTransparency(item()->defaultDisplayProperties().transparency());
0149 }
0150 oItemHolder.AddElement(hex_boxset);
0151 }
0152
0153 if (h_box) {
0154 boxset->RefitPlex();
0155
0156 boxset->CSCTakeAnyParentAsMaster();
0157 if (!heatmap) {
0158 boxset->CSCApplyMainColorToMatchingChildren();
0159 boxset->CSCApplyMainTransparencyToMatchingChildren();
0160 boxset->SetMainColor(item()->modelInfo(iIndex).displayProperties().color());
0161 boxset->SetMainTransparency(item()->defaultDisplayProperties().transparency());
0162 }
0163 oItemHolder.AddElement(boxset);
0164 }
0165 }
0166
0167 REGISTER_FWPROXYBUILDER(FWCaloParticleProxyBuilder,
0168 CaloParticle,
0169 "CaloParticle",
0170 FWViewType::kAll3DBits | FWViewType::kAllRPZBits);