Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-03 04:10:01

0001 // -*- C++ -*-
0002 //
0003 // Package:     Electrons
0004 // Class  :     FWElectronProxyBuilder
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 #include "TEveCompound.h"
0013 #include "TEveTrack.h"
0014 #include "TEveScalableStraightLineSet.h"
0015 
0016 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
0017 #include "Fireworks/Core/interface/FWEventItem.h"
0018 #include "Fireworks/Core/interface/FWViewType.h"
0019 
0020 #include "Fireworks/Candidates/interface/CandidateUtils.h"
0021 #include "Fireworks/Tracks/interface/TrackUtils.h"
0022 #include "Fireworks/Electrons/interface/makeSuperCluster.h"
0023 
0024 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0025 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0026 
0027 #include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h"
0028 
0029 ////////////////////////////////////////////////////////////////////////////////
0030 //
0031 //   3D and RPZ proxy builder with shared track list
0032 //
0033 ////////////////////////////////////////////////////////////////////////////////
0034 
0035 class FWElectronProxyBuilder : public FWSimpleProxyBuilderTemplate<reco::GsfElectron> {
0036 public:
0037   FWElectronProxyBuilder();
0038   ~FWElectronProxyBuilder() override;
0039 
0040   using FWProxyBuilderBase::haveSingleProduct;
0041   bool haveSingleProduct() const override { return false; }
0042   using FWProxyBuilderBase::cleanLocal;
0043   void cleanLocal() override;
0044   using FWSimpleProxyBuilderTemplate<reco::GsfElectron>::buildViewType;
0045   void buildViewType(const reco::GsfElectron& iData,
0046                      unsigned int iIndex,
0047                      TEveElement& oItemHolder,
0048                      FWViewType::EType type,
0049                      const FWViewContext*) override;
0050 
0051   using FWSimpleProxyBuilderTemplate<reco::GsfElectron>::setItem;
0052   void setItem(const FWEventItem* iItem) override;
0053 
0054   REGISTER_PROXYBUILDER_METHODS();
0055 
0056   FWElectronProxyBuilder(const FWElectronProxyBuilder&) = delete;                   // stop default
0057   const FWElectronProxyBuilder& operator=(const FWElectronProxyBuilder&) = delete;  // stop default
0058 
0059 private:
0060   TEveElementList* requestCommon();
0061 
0062   TEveElementList* m_common;
0063 };
0064 
0065 FWElectronProxyBuilder::FWElectronProxyBuilder() : m_common(nullptr) {
0066   m_common = new TEveElementList("common electron scene");
0067   m_common->IncDenyDestroy();
0068 }
0069 
0070 FWElectronProxyBuilder::~FWElectronProxyBuilder() { m_common->DecDenyDestroy(); }
0071 
0072 void FWElectronProxyBuilder::setItem(const FWEventItem* iItem) {
0073   FWProxyBuilderBase::setItem(iItem);
0074 
0075   if (iItem) {
0076     iItem->getConfig()->assertParam("LineWidth", long(1), long(1), long(4));
0077   }
0078 }
0079 
0080 TEveElementList* FWElectronProxyBuilder::requestCommon() {
0081   if (m_common->HasChildren() == false) {
0082     int width = item()->getConfig()->value<long>("LineWidth");
0083     for (int i = 0; i < static_cast<int>(item()->size()); ++i) {
0084       const reco::GsfElectron& electron = modelData(i);
0085 
0086       TEveTrack* track(nullptr);
0087       if (electron.gsfTrack().isAvailable())
0088         track = fireworks::prepareTrack(*electron.gsfTrack(), context().getTrackPropagator());
0089       else
0090         track = fireworks::prepareCandidate(electron, context().getTrackPropagator());
0091       track->MakeTrack();
0092       track->SetLineWidth(width);
0093       setupElement(track);
0094       m_common->AddElement(track);
0095     }
0096   }
0097   return m_common;
0098 }
0099 
0100 void FWElectronProxyBuilder::cleanLocal() { m_common->DestroyElements(); }
0101 
0102 void FWElectronProxyBuilder::buildViewType(const reco::GsfElectron& electron,
0103                                            unsigned int iIndex,
0104                                            TEveElement& oItemHolder,
0105                                            FWViewType::EType type,
0106                                            const FWViewContext*) {
0107   TEveElementList* tracks = requestCommon();
0108   TEveElement::List_i trkIt = tracks->BeginChildren();
0109   std::advance(trkIt, iIndex);
0110   setupAddElement(*trkIt, &oItemHolder);
0111 
0112   if (type == FWViewType::kRhoPhi || type == FWViewType::kRhoPhiPF)
0113     fireworks::makeRhoPhiSuperCluster(this, electron.superCluster(), electron.phi(), oItemHolder);
0114   else if (type == FWViewType::kRhoZ)
0115     fireworks::makeRhoZSuperCluster(this, electron.superCluster(), electron.phi(), oItemHolder);
0116 }
0117 
0118 REGISTER_FWPROXYBUILDER(FWElectronProxyBuilder,
0119                         reco::GsfElectron,
0120                         "Electrons",
0121                         FWViewType::kAll3DBits | FWViewType::kAllRPZBits);
0122 
0123 ////////////////////////////////////////////////////////////////////////////////
0124 //
0125 //   GLIMPSE specific proxy builder
0126 //
0127 ////////////////////////////////////////////////////////////////////////////////
0128 
0129 class FWElectronGlimpseProxyBuilder : public FWSimpleProxyBuilderTemplate<reco::GsfElectron> {
0130 public:
0131   FWElectronGlimpseProxyBuilder() {}
0132   ~FWElectronGlimpseProxyBuilder() override {}
0133   using FWSimpleProxyBuilderTemplate<reco::GsfElectron>::build;
0134 
0135   REGISTER_PROXYBUILDER_METHODS();
0136 
0137   FWElectronGlimpseProxyBuilder(const FWElectronGlimpseProxyBuilder&) = delete;  // stop default
0138 
0139   const FWElectronGlimpseProxyBuilder& operator=(const FWElectronGlimpseProxyBuilder&) = delete;  // stop default
0140 
0141 private:
0142   void build(const reco::GsfElectron& iData,
0143              unsigned int iIndex,
0144              TEveElement& oItemHolder,
0145              const FWViewContext*) override;
0146 };
0147 
0148 void FWElectronGlimpseProxyBuilder::build(const reco::GsfElectron& iData,
0149                                           unsigned int iIndex,
0150                                           TEveElement& oItemHolder,
0151                                           const FWViewContext*) {
0152   TEveScalableStraightLineSet* marker = new TEveScalableStraightLineSet("", "");
0153   marker->SetLineWidth(2);
0154   fireworks::addStraightLineSegment(marker, &iData, 1.0);
0155   setupAddElement(marker, &oItemHolder);
0156   //add to scaler at end so that it can scale the line after all ends have been added
0157   // FIXME: It's not a part of a standard FWSimpleProxyBuilderTemplate: the scaler is not set!
0158   //    assert(scaler());
0159   //    scaler()->addElement(marker);
0160 }
0161 REGISTER_FWPROXYBUILDER(FWElectronGlimpseProxyBuilder, reco::GsfElectron, "Electrons", FWViewType::kGlimpseBit);