Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:28

0001 // -*- C++ -*-
0002 //
0003 // Package:     Calo
0004 // Class  :     FWMETProxyBuilder
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:
0010 //         Created:  Sun Jan  6 23:57:00 EST 2008
0011 //
0012 
0013 // system include files
0014 #include "TEveGeoNode.h"
0015 #include "TEveGeoShape.h"
0016 #include "TEveScalableStraightLineSet.h"
0017 #include "TGeoTube.h"
0018 #include "TMath.h"
0019 
0020 // user include files
0021 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
0022 #include "Fireworks/Core/interface/FWViewType.h"
0023 #include "Fireworks/Core/interface/BuilderUtils.h"
0024 #include "Fireworks/Core/interface/Context.h"
0025 #include "Fireworks/Core/interface/FWViewEnergyScale.h"
0026 #include "Fireworks/Core/interface/FWEventItem.h"
0027 #include "Fireworks/Calo/interface/scaleMarker.h"
0028 
0029 #include "DataFormats/METReco/interface/MET.h"
0030 
0031 ////////////////////////////////////////////////////////////////////////////////
0032 //
0033 //   RPZ proxy builder with shared MET shape
0034 //
0035 ////////////////////////////////////////////////////////////////////////////////
0036 
0037 class FWMETProxyBuilder : public FWSimpleProxyBuilderTemplate<reco::MET> {
0038 public:
0039   FWMETProxyBuilder() {}
0040   ~FWMETProxyBuilder() override {}
0041 
0042   bool haveSingleProduct() const override { return false; }  // use buildViewType instead of buildView
0043 
0044   bool havePerViewProduct(FWViewType::EType) const override { return true; }  // used energy scaling
0045 
0046   void scaleProduct(TEveElementList* parent, FWViewType::EType, const FWViewContext* vc) override;
0047 
0048   REGISTER_PROXYBUILDER_METHODS();
0049 
0050   FWMETProxyBuilder(const FWMETProxyBuilder&) = delete;                   // stop default
0051   const FWMETProxyBuilder& operator=(const FWMETProxyBuilder&) = delete;  // stop default
0052 
0053 private:
0054   using FWSimpleProxyBuilderTemplate<reco::MET>::buildViewType;
0055   void buildViewType(const reco::MET& iData,
0056                      unsigned int iIndex,
0057                      TEveElement& oItemHolder,
0058                      FWViewType::EType type,
0059                      const FWViewContext*) override;
0060 };
0061 
0062 void FWMETProxyBuilder::scaleProduct(TEveElementList* product, FWViewType::EType type, const FWViewContext* vc) {
0063   int idx = 0;
0064   for (auto& c : product->RefChildren()) {
0065     // line set element is added at the end of the buildViewType function, therefore last child
0066     TEveScalableStraightLineSet* lineSet = dynamic_cast<TEveScalableStraightLineSet*>(c->LastChild());
0067     if (lineSet) {
0068       // compund index in the product is an index of model data in the collection
0069       const void* modelData = item()->modelData(idx);
0070       const reco::MET* met = (const reco::MET*)(modelData);
0071       float value = vc->getEnergyScale()->getPlotEt() ? met->et() : met->energy();
0072       lineSet->SetScale(vc->getEnergyScale()->getScaleFactor3D() * value);
0073       for (TEveProjectable::ProjList_i j = lineSet->BeginProjecteds(); j != lineSet->EndProjecteds(); ++j) {
0074         (*j)->UpdateProjection();
0075       }
0076     }
0077     idx++;
0078   }
0079 }
0080 
0081 void FWMETProxyBuilder::buildViewType(const reco::MET& met,
0082                                       unsigned int iIndex,
0083                                       TEveElement& oItemHolder,
0084                                       FWViewType::EType type,
0085                                       const FWViewContext* vc) {
0086   using namespace TMath;
0087   double phi = met.phi();
0088   double theta = met.theta();
0089   double size = 1.f;
0090 
0091   FWViewEnergyScale* caloScale = vc->getEnergyScale();
0092 
0093   TEveScalableStraightLineSet* marker = new TEveScalableStraightLineSet("MET marker");
0094   marker->SetLineWidth(2);
0095 
0096   if (type == FWViewType::kRhoZ) {
0097     // body
0098     double r0;
0099     if (TMath::Abs(met.eta()) < context().caloTransEta()) {
0100       r0 = context().caloR1() / sin(theta);
0101     } else {
0102       r0 = context().caloZ1() / fabs(cos(theta));
0103     }
0104     marker->SetScaleCenter(0., Sign(r0 * sin(theta), phi), r0 * cos(theta));
0105     double r1 = r0 + 1;
0106     marker->AddLine(0., Sign(r0 * sin(theta), phi), r0 * cos(theta), 0., Sign(r1 * sin(theta), phi), r1 * cos(theta));
0107 
0108     // arrow pointer
0109     double r2 = r1 - 0.1;
0110     double dy = 0.05 * size;
0111     marker->AddLine(0.,
0112                     Sign(r2 * sin(theta) + dy * cos(theta), phi),
0113                     r2 * cos(theta) - dy * sin(theta),
0114                     0.,
0115                     Sign(r1 * sin(theta), phi),
0116                     r1 * cos(theta));
0117     dy = -dy;
0118     marker->AddLine(0.,
0119                     Sign(r2 * sin(theta) + dy * cos(theta), phi),
0120                     r2 * cos(theta) - dy * sin(theta),
0121                     0.,
0122                     Sign(r1 * sin(theta), phi),
0123                     r1 * cos(theta));
0124 
0125     // segment
0126     fireworks::addRhoZEnergyProjection(
0127         this, &oItemHolder, context().caloR1() - 1, context().caloZ1() - 1, theta - 0.04, theta + 0.04, phi);
0128   } else {
0129     // body
0130     double r0 = context().caloR1();
0131     double r1 = r0 + 1;
0132     marker->SetScaleCenter(r0 * cos(phi), r0 * sin(phi), 0);
0133     marker->AddLine(r0 * cos(phi), r0 * sin(phi), 0, r1 * cos(phi), r1 * sin(phi), 0);
0134 
0135     // arrow pointer, xy  rotate offset point ..
0136     double r2 = r1 - 0.1;
0137     double dy = 0.05 * size;
0138 
0139     marker->AddLine(r2 * cos(phi) - dy * sin(phi), r2 * sin(phi) + dy * cos(phi), 0, r1 * cos(phi), r1 * sin(phi), 0);
0140     dy = -dy;
0141     marker->AddLine(r2 * cos(phi) - dy * sin(phi), r2 * sin(phi) + dy * cos(phi), 0, r1 * cos(phi), r1 * sin(phi), 0);
0142 
0143     // segment
0144     double min_phi = phi - M_PI / 36 / 2;
0145     double max_phi = phi + M_PI / 36 / 2;
0146     TEveGeoManagerHolder gmgr(TEveGeoShape::GetGeoMangeur());
0147     TEveGeoShape* element =
0148         fireworks::getShape("spread", new TGeoTubeSeg(r0 - 2, r0, 1, min_phi * 180 / M_PI, max_phi * 180 / M_PI), 0);
0149     element->SetPickable(kTRUE);
0150     setupAddElement(element, &oItemHolder);
0151   }
0152 
0153   marker->SetScale(caloScale->getScaleFactor3D() * (caloScale->getPlotEt() ? met.et() : met.energy()));
0154   setupAddElement(marker, &oItemHolder);
0155 
0156   // printf("add line %s  %f %f .... eta %f theta %f\n", item()->name().c_str(), met.et(), met.energy(), met.eta(), met.theta());
0157 
0158   context().voteMaxEtAndEnergy(met.et(), met.energy());
0159 }
0160 
0161 REGISTER_FWPROXYBUILDER(FWMETProxyBuilder, reco::MET, "recoMET", FWViewType::kAllRPZBits);