Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-03 04:09:56

0001 // -*- C++ -*-
0002 //
0003 // Package:     Calo
0004 // Class  :     FWJetProxyBuilder
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Tue Dec  2 14:17:03 EST 2008
0011 //
0012 
0013 #include "TEveJetCone.h"
0014 #include "TEveScalableStraightLineSet.h"
0015 
0016 #include "Fireworks/Core/interface/FWTextProjected.h"
0017 #include "Fireworks/Core/interface/FWEventItem.h"
0018 #include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h"
0019 #include "Fireworks/Core/interface/Context.h"
0020 #include "Fireworks/Core/interface/CmsShowCommon.h"
0021 // user include files
0022 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
0023 #include "Fireworks/Core/interface/FWEventItem.h"
0024 #include "Fireworks/Core/interface/Context.h"
0025 #include "Fireworks/Core/interface/FWViewContext.h"
0026 #include "Fireworks/Core/interface/FWViewEnergyScale.h"
0027 #include "Fireworks/Calo/interface/makeEveJetCone.h"
0028 #include "Fireworks/Calo/interface/scaleMarker.h"
0029 
0030 #include "DataFormats/JetReco/interface/Jet.h"
0031 
0032 namespace fireworks {
0033 
0034   struct jetScaleMarker : public scaleMarker {
0035     jetScaleMarker(TEveScalableStraightLineSet* ls, float et, float e, const FWViewContext* vc)
0036         : scaleMarker(ls, et, e, vc), m_text(nullptr) {}
0037 
0038     FWEveText* m_text;
0039   };
0040 }  // namespace fireworks
0041 
0042 static const std::string kJetLabelsRhoPhiOn("Draw Labels in RhoPhi View");
0043 static const std::string kJetLabelsRhoZOn("Draw Labels in RhoZ View");
0044 static const std::string kJetOffset("Label Offset");
0045 static const std::string kJetApexBeamSpot("Place Apex In BeamSpot");
0046 
0047 class FWJetProxyBuilder : public FWSimpleProxyBuilderTemplate<reco::Jet> {
0048 public:
0049   FWJetProxyBuilder();
0050   ~FWJetProxyBuilder() override;
0051 
0052   bool havePerViewProduct(FWViewType::EType) const override { return true; }
0053   bool haveSingleProduct() const override { return false; }  // different view types
0054   void cleanLocal() override;
0055 
0056   void setItem(const FWEventItem* iItem) override {
0057     FWProxyBuilderBase::setItem(iItem);
0058     if (iItem) {
0059       iItem->getConfig()->assertParam(kJetLabelsRhoPhiOn, false);
0060       iItem->getConfig()->assertParam(kJetLabelsRhoZOn, false);
0061       iItem->getConfig()->assertParam(kJetOffset, 2.1, 1.0, 5.0);
0062     }
0063   }
0064 
0065   REGISTER_PROXYBUILDER_METHODS();
0066 
0067   FWJetProxyBuilder(const FWJetProxyBuilder&) = delete;                   // stop default
0068   const FWJetProxyBuilder& operator=(const FWJetProxyBuilder&) = delete;  // stop default
0069 
0070 protected:
0071   using FWSimpleProxyBuilderTemplate<reco::Jet>::buildViewType;
0072   void buildViewType(const reco::Jet& iData,
0073                      unsigned int iIndex,
0074                      TEveElement& oItemHolder,
0075                      FWViewType::EType type,
0076                      const FWViewContext*) override;
0077 
0078   void localModelChanges(const FWModelId& iId,
0079                          TEveElement* iCompound,
0080                          FWViewType::EType viewType,
0081                          const FWViewContext* vc) override;
0082 
0083   void scaleProduct(TEveElementList* parent, FWViewType::EType, const FWViewContext* vc) override;
0084 
0085 private:
0086   typedef std::vector<fireworks::jetScaleMarker> Lines_t;
0087 
0088   TEveElementList* requestCommon();
0089   void setTextPos(fireworks::jetScaleMarker& s, const FWViewContext* vc, FWViewType::EType);
0090 
0091   TEveElementList* m_common;
0092 };
0093 
0094 //______________________________________________________________________________
0095 FWJetProxyBuilder::FWJetProxyBuilder() : m_common(nullptr) {
0096   m_common = new TEveElementList("common electron scene");
0097   m_common->IncDenyDestroy();
0098 }
0099 
0100 FWJetProxyBuilder::~FWJetProxyBuilder() { m_common->DecDenyDestroy(); }
0101 
0102 TEveElementList* FWJetProxyBuilder::requestCommon() {
0103   if (m_common->HasChildren() == false) {
0104     for (int i = 0; i < static_cast<int>(item()->size()); ++i) {
0105       TEveJetCone* cone = fireworks::makeEveJetCone(modelData(i), context());
0106 
0107       cone->SetFillColor(item()->defaultDisplayProperties().color());
0108       cone->SetLineColor(item()->defaultDisplayProperties().color());
0109 
0110       m_common->AddElement(cone);
0111     }
0112   }
0113   return m_common;
0114 }
0115 
0116 void FWJetProxyBuilder::buildViewType(const reco::Jet& iData,
0117                                       unsigned int iIndex,
0118                                       TEveElement& oItemHolder,
0119                                       FWViewType::EType type,
0120                                       const FWViewContext* vc) {
0121   // add cone from shared pool
0122   TEveElementList* cones = requestCommon();
0123   TEveElement::List_i coneIt = cones->BeginChildren();
0124   std::advance(coneIt, iIndex);
0125 
0126   const FWDisplayProperties& dp = item()->defaultDisplayProperties();
0127   setupAddElement(*coneIt, &oItemHolder);
0128   (*coneIt)->SetMainTransparency(TMath::Min(100, 80 + dp.transparency() / 5));
0129 
0130   TEveVector p1;
0131   TEveVector p2;
0132 
0133   // scale markers in projected views
0134   if (FWViewType::isProjected(type)) {
0135     fireworks::jetScaleMarker markers(new TEveScalableStraightLineSet("jetline"), iData.et(), iData.energy(), vc);
0136 
0137     float size = 1.f;  // values are saved in scale
0138     double theta = iData.theta();
0139     double phi = iData.phi();
0140 
0141     if (type == FWViewType::kRhoZ) {
0142       static const float_t offr = 4;
0143       float r_ecal = context().caloR1() + offr;
0144       float z_ecal = context().caloZ1() + offr / tan(context().caloTransAngle());
0145       double r(0);
0146       if (theta < context().caloTransAngle() || M_PI - theta < context().caloTransAngle()) {
0147         z_ecal = context().caloZ2() + offr / tan(context().caloTransAngle());
0148         r = z_ecal / fabs(cos(theta));
0149       } else {
0150         r = r_ecal / sin(theta);
0151       }
0152 
0153       p1.Set(0., (phi > 0 ? r * fabs(sin(theta)) : -r * fabs(sin(theta))), r * cos(theta));
0154       p2.Set(0., (phi > 0 ? (r + size) * fabs(sin(theta)) : -(r + size) * fabs(sin(theta))), (r + size) * cos(theta));
0155     } else {
0156       float ecalR = context().caloR1() + 4;
0157       p1.Set(ecalR * cos(phi), ecalR * sin(phi), 0);
0158       p2.Set((ecalR + size) * cos(phi), (ecalR + size) * sin(phi), 0);
0159     }
0160 
0161     markers.m_ls->SetScaleCenter(p1.fX, p1.fY, p1.fZ);
0162     markers.m_ls->AddLine(p1, p2);
0163 
0164     markers.m_ls->SetLineWidth(4);
0165     markers.m_ls->SetLineColor(dp.color());
0166     FWViewEnergyScale* caloScale = vc->getEnergyScale();
0167     markers.m_ls->SetScale(caloScale->getScaleFactor3D() * (caloScale->getPlotEt() ? iData.et() : iData.energy()));
0168 
0169     if ((type == FWViewType::kRhoZ && item()->getConfig()->value<bool>(kJetLabelsRhoZOn)) ||
0170         (type == FWViewType::kRhoPhi && item()->getConfig()->value<bool>(kJetLabelsRhoPhiOn))) {
0171       markers.m_text = new FWEveText(Form("%.1f", vc->getEnergyScale()->getPlotEt() ? iData.et() : iData.energy()));
0172       markers.m_text->SetMainColor(item()->defaultDisplayProperties().color());
0173       setTextPos(markers, vc, type);
0174     }
0175 
0176     markers.m_ls->SetMarkerColor(markers.m_ls->GetMainColor());
0177     setupAddElement(markers.m_ls, &oItemHolder);
0178     if (markers.m_text)
0179       setupAddElement(markers.m_text, &oItemHolder, false);
0180   }
0181   context().voteMaxEtAndEnergy(iData.et(), iData.energy());
0182 }
0183 
0184 void FWJetProxyBuilder::localModelChanges(const FWModelId& iId,
0185                                           TEveElement* iCompound,
0186                                           FWViewType::EType viewType,
0187                                           const FWViewContext* vc) {
0188   increaseComponentTransparency(iId.index(), iCompound, "TEveJetCone", 80);
0189 }
0190 
0191 void FWJetProxyBuilder::cleanLocal() { m_common->DestroyElements(); }
0192 
0193 void FWJetProxyBuilder::scaleProduct(TEveElementList* product, FWViewType::EType viewType, const FWViewContext* vc) {
0194   // move jets to eventCenter
0195   fireworks::Context* contextGl = fireworks::Context::getInstance();
0196   TEveVector cv;
0197   contextGl->commonPrefs()->getEventCenter(cv.Arr());
0198   for (TEveElement::List_i i = m_common->BeginChildren(); i != m_common->EndChildren(); ++i) {
0199     TEveJetCone* cone = dynamic_cast<TEveJetCone*>(*i);
0200     if (cone) {
0201       cone->SetApex(cv);
0202     }
0203   }
0204 
0205   // loop compounds in projected product
0206   int idx = 0;
0207   for (auto& c : product->RefChildren()) {
0208     TEveElement* parent = c;
0209     // check the compound has more than one element (the first one is jet)
0210     if (parent->NumChildren() > 1) {
0211       auto compIt = parent->BeginChildren();
0212       compIt++;
0213       TEveScalableStraightLineSet* lineSet = dynamic_cast<TEveScalableStraightLineSet*>(*compIt);
0214       if (lineSet) {
0215         // compund index in the product is an index of model data in the collection
0216         const void* modelData = item()->modelData(idx);
0217         const reco::Jet* jet = (const reco::Jet*)(modelData);
0218         float value = vc->getEnergyScale()->getPlotEt() ? jet->et() : jet->energy();
0219         lineSet->SetScale(vc->getEnergyScale()->getScaleFactor3D() * value);
0220         for (TEveProjectable::ProjList_i j = lineSet->BeginProjecteds(); j != lineSet->EndProjecteds(); ++j) {
0221           (*j)->UpdateProjection();
0222         }
0223       }
0224     }
0225     idx++;
0226   }
0227 }
0228 
0229 void FWJetProxyBuilder::setTextPos(fireworks::jetScaleMarker& s, const FWViewContext* vc, FWViewType::EType type) {
0230   TEveChunkManager::iterator li(s.m_ls->GetLinePlex());
0231   li.next();
0232   TEveStraightLineSet::Line_t& l = *(TEveStraightLineSet::Line_t*)li();
0233   TEveVector v(l.fV2[0] - l.fV1[0], l.fV2[1] - l.fV1[1], l.fV2[2] - l.fV1[2]);
0234   v.Normalize();
0235 
0236   double off = item()->getConfig()->value<double>(kJetOffset) - 1;
0237   float value = vc->getEnergyScale()->getPlotEt() ? s.m_et : s.m_energy;
0238   double trs = off * 130 * value / context().getMaxEnergyInEvent(vc->getEnergyScale()->getPlotEt());
0239   v *= trs;
0240 
0241   float x = l.fV1[0] + v[0];
0242   float y = l.fV1[1] + v[1];
0243   float z = l.fV1[2] + v[2];
0244 
0245   s.m_text->m_offsetZ = value / context().getMaxEnergyInEvent(vc->getEnergyScale()->getPlotEt());
0246   s.m_text->RefMainTrans().SetPos(x, y, z);
0247   if ((s.m_text)->BeginProjecteds() != (s.m_text)->EndProjecteds()) {
0248     FWEveTextProjected* textProjected = (FWEveTextProjected*)(*(s.m_text)->BeginProjecteds());
0249     textProjected->UpdateProjection();
0250   }
0251 }
0252 
0253 REGISTER_FWPROXYBUILDER(FWJetProxyBuilder,
0254                         reco::Jet,
0255                         "Jets",
0256                         FWViewType::kAll3DBits | FWViewType::kAllRPZBits | FWViewType::kGlimpseBit);