File indexing completed on 2024-04-06 12:11:50
0001 #include "FWPFBlockProxyBuilder.h"
0002 #include "Fireworks/Candidates/interface/FWLegoCandidate.h"
0003
0004
0005 void FWPFBlockProxyBuilder::scaleProduct(TEveElementList *parent, FWViewType::EType viewType, const FWViewContext *vc) {
0006 typedef std::vector<ScalableLines> Lines_t;
0007 FWViewEnergyScale *caloScale = vc->getEnergyScale();
0008
0009 if (viewType == FWViewType::kRhoPhiPF ||
0010 viewType == FWViewType::kRhoZ) {
0011 for (Lines_t::iterator i = m_clusters.begin(); i != m_clusters.end(); ++i) {
0012 if (vc == (*i).m_vc) {
0013 float value = caloScale->getPlotEt() ? (*i).m_et : (*i).m_energy;
0014 (*i).m_ls->SetScale(caloScale->getScaleFactor3D() * value);
0015 TEveProjected *proj = *(*i).m_ls->BeginProjecteds();
0016 proj->UpdateProjection();
0017 }
0018 }
0019 }
0020 else if (viewType == FWViewType::kLego || viewType == FWViewType::kLegoPFECAL) {
0021 for (TEveElement::List_i i = parent->BeginChildren(); i != parent->EndChildren(); ++i) {
0022 if ((*i)->HasChildren()) {
0023 for (TEveElement::List_i j = (*i)->BeginChildren(); j != (*i)->EndChildren(); ++j) {
0024 if (strcmp((*j)->GetElementName(), "BlockCluster") == 0) {
0025 FWLegoCandidate *cluster = dynamic_cast<FWLegoCandidate *>(*j);
0026 cluster->updateScale(vc, context());
0027 }
0028 }
0029 }
0030 }
0031 }
0032 }
0033
0034
0035 void FWPFBlockProxyBuilder::setupTrackElement(const reco::PFBlockElement &blockElement,
0036 TEveElement &oItemHolder,
0037 const FWViewContext *vc,
0038 FWViewType::EType viewType) {
0039 if (blockElement.trackType(reco::PFBlockElement::DEFAULT)) {
0040 reco::Track track = *blockElement.trackRef();
0041 FWPFTrackUtils *trackUtils = new FWPFTrackUtils();
0042
0043 if (viewType == FWViewType::kLego || viewType == FWViewType::kLegoPFECAL)
0044 {
0045 TEveStraightLineSet *legoTrack = trackUtils->setupLegoTrack(track);
0046 setupAddElement(legoTrack, &oItemHolder);
0047 } else if (viewType == FWViewType::kRhoPhiPF)
0048 {
0049 TEveTrack *trk = trackUtils->setupTrack(track);
0050 TEvePointSet *ps = trackUtils->getCollisionMarkers(trk);
0051 setupAddElement(trk, &oItemHolder);
0052 if (ps->GetN() != 0)
0053 setupAddElement(ps, &oItemHolder);
0054 else
0055 delete ps;
0056 } else if (viewType == FWViewType::kRhoZ)
0057 {
0058 TEveTrack *trk = trackUtils->setupTrack(track);
0059 TEvePointSet *markers = trackUtils->getCollisionMarkers(trk);
0060 TEvePointSet *ps = new TEvePointSet();
0061 setupAddElement(trk, &oItemHolder);
0062
0063 Float_t *trackPoints = trk->GetP();
0064 unsigned int last = (trk->GetN() - 1) * 3;
0065 float y = trackPoints[last + 1];
0066 float z = trackPoints[last + 2];
0067
0068
0069 for (signed int i = 0; i < markers->GetN(); ++i) {
0070 Float_t a, b, c;
0071 markers->GetPoint(i, a, b, c);
0072
0073 if (y < 0 && b > 0)
0074 b *= -1;
0075 else if (y > 0 && b < 0)
0076 b *= -1;
0077
0078 if (z < 0 && c > 0)
0079 c *= -1;
0080 else if (z > 0 && c < 0)
0081 c *= -1;
0082
0083 ps->SetNextPoint(a, b, c);
0084 }
0085
0086 if (ps->GetN() != 0)
0087 setupAddElement(ps, &oItemHolder);
0088 else
0089 delete ps;
0090 delete markers;
0091 }
0092
0093 delete trackUtils;
0094 }
0095 }
0096
0097
0098 void FWPFBlockProxyBuilder::setupClusterElement(const reco::PFBlockElement &blockElement,
0099 TEveElement &oItemHolder,
0100 const FWViewContext *vc,
0101 FWViewType::EType viewType,
0102 float r) {
0103
0104 reco::PFCluster cluster = *blockElement.clusterRef();
0105 TEveVector centre = TEveVector(cluster.x(), cluster.y(), cluster.z());
0106 float energy = cluster.energy();
0107 float et = FWPFMaths::calculateEt(centre, energy);
0108 float pt = et;
0109 float eta = cluster.eta();
0110 float phi = cluster.phi();
0111
0112 FWProxyBuilderBase::context().voteMaxEtAndEnergy(et, energy);
0113
0114 if (viewType == FWViewType::kLego || viewType == FWViewType::kLegoPFECAL) {
0115 FWLegoCandidate *legoCluster = new FWLegoCandidate(vc, FWProxyBuilderBase::context(), energy, et, pt, eta, phi);
0116 legoCluster->SetMarkerColor(FWProxyBuilderBase::item()->defaultDisplayProperties().color());
0117 legoCluster->SetElementName("BlockCluster");
0118 setupAddElement(legoCluster, &oItemHolder);
0119 }
0120 if (viewType == FWViewType::kRhoPhiPF) {
0121 const FWDisplayProperties &dp = item()->defaultDisplayProperties();
0122 FWPFClusterRPZUtils *clusterUtils = new FWPFClusterRPZUtils();
0123 TEveScalableStraightLineSet *rpCluster = clusterUtils->buildRhoPhiClusterLineSet(cluster, vc, energy, et, r);
0124 rpCluster->SetLineColor(dp.color());
0125 m_clusters.push_back(ScalableLines(rpCluster, et, energy, vc));
0126 setupAddElement(rpCluster, &oItemHolder);
0127 delete clusterUtils;
0128 } else if (viewType == FWViewType::kRhoZ) {
0129 const FWDisplayProperties &dp = item()->defaultDisplayProperties();
0130 FWPFClusterRPZUtils *clusterUtils = new FWPFClusterRPZUtils();
0131 TEveScalableStraightLineSet *rzCluster = clusterUtils->buildRhoZClusterLineSet(
0132 cluster, vc, context().caloTransAngle(), energy, et, r, context().caloZ1());
0133 rzCluster->SetLineColor(dp.color());
0134 m_clusters.push_back(ScalableLines(rzCluster, et, energy, vc));
0135 setupAddElement(rzCluster, &oItemHolder);
0136 delete clusterUtils;
0137 }
0138 }
0139
0140
0141 void FWPFBlockProxyBuilder::buildViewType(const reco::PFBlock &iData,
0142 unsigned int iIndex,
0143 TEveElement &oItemHolder,
0144 FWViewType::EType viewType,
0145 const FWViewContext *vc) {
0146 const edm::OwnVector<reco::PFBlockElement> &elements = iData.elements();
0147
0148 for (unsigned int i = 0; i < elements.size(); ++i) {
0149 reco::PFBlockElement::Type type = elements[i].type();
0150 switch (type) {
0151 case 1:
0152 if (e_builderType == BASE)
0153 setupTrackElement(elements[i], oItemHolder, vc, viewType);
0154 break;
0155
0156 case 4:
0157 if (e_builderType == ECAL)
0158 setupClusterElement(elements[i], oItemHolder, vc, viewType, FWPFGeom::caloR1());
0159 break;
0160
0161 case 5:
0162 if (e_builderType == HCAL) {
0163 if (viewType == FWViewType::kRhoPhiPF)
0164 setupClusterElement(elements[i], oItemHolder, vc, viewType, FWPFGeom::caloR2());
0165 else
0166 setupClusterElement(elements[i], oItemHolder, vc, viewType, context().caloR1());
0167 }
0168 break;
0169
0170 default:
0171 break;
0172 }
0173 }
0174 }
0175
0176
0177 REGISTER_FWPROXYBUILDER(FWPFBlockProxyBuilder,
0178 reco::PFBlock,
0179 "PF Block",
0180 FWViewType::kRhoPhiPFBit | FWViewType::kLegoBit | FWViewType::kRhoZBit |
0181 FWViewType::kLegoPFECALBit);
0182 REGISTER_FWPROXYBUILDER(FWPFBlockEcalProxyBuilder,
0183 reco::PFBlock,
0184 "PF Block",
0185 FWViewType::kLegoPFECALBit | FWViewType::kRhoPhiPFBit | FWViewType::kRhoZBit);
0186 REGISTER_FWPROXYBUILDER(FWPFBlockHcalProxyBuilder,
0187 reco::PFBlock,
0188 "PF Block",
0189 FWViewType::kLegoBit | FWViewType::kRhoPhiPFBit | FWViewType::kRhoZBit);