From 96008f6efc67c2b0eb209e9bc5afd15039e25e95 Mon Sep 17 00:00:00 2001 From: alja Date: Fri, 19 Jul 2013 17:23:30 -0700 Subject: [PATCH] Improvement of rc-hit visualization --- .../Calo/interface/FWECALDetailViewBuilder.h | 4 +- .../FWCaloRecHitDigitSetProxyBuilder.cc | 174 +++++++++ .../FWCaloRecHitDigitSetProxyBuilder.h | 34 ++ .../plugins/FWCastorRecHitProxyBuilder.cc | 22 +- .../Calo/plugins/FWEcalRecHitProxyBuilder.cc | 83 +--- .../Calo/plugins/FWHBHERecHitProxyBuilder.cc | 77 +--- .../Calo/plugins/FWHFRecHitProxyBuilder.cc | 31 +- .../Calo/plugins/FWHORecHitProxyBuilder.cc | 30 +- .../Calo/plugins/FWZDCRecHitProxyBuilder.cc | 23 +- Fireworks/Calo/src/FWECALDetailViewBuilder.cc | 229 +++++------ .../Core/src/FWProxyBuilderConfiguration.cc | 4 +- .../FWPFCandidateWithHitsProxyBuilder.cc | 359 ++++++++++++++++++ .../FWPFCandidateWithHitsProxyBuilder.h | 39 ++ 13 files changed, 798 insertions(+), 311 deletions(-) create mode 100644 Fireworks/Calo/plugins/FWCaloRecHitDigitSetProxyBuilder.cc create mode 100644 Fireworks/Calo/plugins/FWCaloRecHitDigitSetProxyBuilder.h create mode 100644 Fireworks/ParticleFlow/plugins/FWPFCandidateWithHitsProxyBuilder.cc create mode 100644 Fireworks/ParticleFlow/plugins/FWPFCandidateWithHitsProxyBuilder.h diff --git a/Fireworks/Calo/interface/FWECALDetailViewBuilder.h b/Fireworks/Calo/interface/FWECALDetailViewBuilder.h index 5f3d31a4ae4b8..b9ddf0dc36c10 100644 --- a/Fireworks/Calo/interface/FWECALDetailViewBuilder.h +++ b/Fireworks/Calo/interface/FWECALDetailViewBuilder.h @@ -45,6 +45,8 @@ class FWECALDetailViewBuilder { // draw the ecal information with the preset colors // (if any colors have been preset) TEveCaloLego* build(); + + TEveCaloData* buildCaloData(bool xyEE); // set colors of some predefined detids void setColor(Color_t color, const std::vector &detIds); @@ -65,7 +67,7 @@ class FWECALDetailViewBuilder { // fill data void fillData(const EcalRecHitCollection *hits, - TEveCaloDataVec *data); + TEveCaloDataVec *data, bool xyEE); const edm::EventBase *m_event; // the event const FWGeometry *m_geom; // the geometry float m_eta; // eta position view centred on diff --git a/Fireworks/Calo/plugins/FWCaloRecHitDigitSetProxyBuilder.cc b/Fireworks/Calo/plugins/FWCaloRecHitDigitSetProxyBuilder.cc new file mode 100644 index 0000000000000..0fc1c8f6e2dd3 --- /dev/null +++ b/Fireworks/Calo/plugins/FWCaloRecHitDigitSetProxyBuilder.cc @@ -0,0 +1,174 @@ +#include "Fireworks/Calo/plugins/FWCaloRecHitDigitSetProxyBuilder.h" +#include "TEveBoxSet.h" +#include "FWCaloRecHitDigitSetProxyBuilder.h" +#include "Fireworks/Core/interface/FWDigitSetProxyBuilder.h" +#include "Fireworks/Core/interface/FWEventItem.h" +#include "Fireworks/Core/interface/FWGeometry.h" +#include "Fireworks/Core/interface/BuilderUtils.h" +#include "Fireworks/Core/interface/FWViewEnergyScale.h" +#include "DataFormats/CaloRecHit/interface/CaloRecHit.h" + +#include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h" + +FWCaloRecHitDigitSetProxyBuilder::FWCaloRecHitDigitSetProxyBuilder() + : m_invertBox(false), m_ignoreGeoShapeSize(false) +{} + +//______________________________________________________________________________ + +void FWCaloRecHitDigitSetProxyBuilder::setItem(const FWEventItem* iItem) +{ + FWProxyBuilderBase::setItem(iItem); + // if (iItem) iItem->getConfig()->assertParam( "IgnoreShapeSize", false); +} +//______________________________________________________________________________ + +void FWCaloRecHitDigitSetProxyBuilder::viewContextBoxScale( const float* corners, float scale, bool plotEt, std::vector& scaledCorners, const CaloRecHit*) +{ + if ( m_ignoreGeoShapeSize) + { + // Same functionality as fireworks::energyTower3DCorners() + + for( int i = 0; i < 24; ++i ) + scaledCorners[i] = corners[i]; + + // Coordinates of a front face scaled + if( m_invertBox ) + { + // We know, that an ES rechit geometry in -Z needs correction. + // The back face is actually its front face. + for( unsigned int i = 0; i < 12; i += 3 ) + { + m_vector.Set( corners[i] - corners[i + 12], corners[i + 1] - corners[i + 13], corners[i + 2] - corners[i + 14] ); + m_vector.Normalize(); + m_vector *= scale; + + scaledCorners[i] = corners[i] + m_vector.fX; + scaledCorners[i + 1] = corners[i + 1] + m_vector.fY; + scaledCorners[i + 2] = corners[i + 2] + m_vector.fZ; + } + } + else + { + for( unsigned int i = 0; i < 12; i += 3 ) + { + m_vector.Set( corners[i + 12] - corners[i], corners[i + 13] - corners[i + 1], corners[i + 14] - corners[i + 2] ); + m_vector.Normalize(); + m_vector *= scale; + + scaledCorners[i] = corners[i + 12]; + scaledCorners[i + 1] = corners[i + 13]; + scaledCorners[i + 2] = corners[i + 14]; + + scaledCorners[i + 12] = corners[i + 12] + m_vector.fX; + scaledCorners[i + 13] = corners[i + 13] + m_vector.fY; + scaledCorners[i + 14] = corners[i + 14] + m_vector.fZ; + } + } + } + else { + + // Same functionality as fireworks::energyScaledBox3DCorners(). + + m_vector.Set(0.f, 0.f, 0.f); + for( unsigned int i = 0; i < 24; i += 3 ) + { + m_vector[0] += corners[i]; + m_vector[1] += corners[i + 1]; + m_vector[2] += corners[i + 2]; + } + m_vector *= 1.f/8.f; + + if (plotEt) + { + scale *= m_vector.Perp()/m_vector.Mag(); + } + + // Coordinates for a scaled version of the original box + for( unsigned int i = 0; i < 24; i += 3 ) + { + scaledCorners[i] = m_vector[0] + ( corners[i] - m_vector[0] ) * scale; + scaledCorners[i + 1] = m_vector[1] + ( corners[i + 1] - m_vector[1] ) * scale; + scaledCorners[i + 2] = m_vector[2] + ( corners[i + 2] - m_vector[2] ) * scale; + } + + if( m_invertBox ) + fireworks::invertBox( scaledCorners ); + } +} +//_____________________________________________________________________________ + +float FWCaloRecHitDigitSetProxyBuilder::scaleFactor(const FWViewContext* vc) +{ + // printf("scale face %f \n", vc->getEnergyScale()->getScaleFactor3D()); + return vc->getEnergyScale()->getScaleFactor3D()/50; +} + +//______________________________________________________________________________ + +void +FWCaloRecHitDigitSetProxyBuilder::scaleProduct(TEveElementList* parent, FWViewType::EType type, const FWViewContext* vc) +{ + size_t size = item()->size(); + if (!size) return; + + + std::vector scaledCorners(24); + float scale = scaleFactor(vc); + + assert(parent->NumChildren() == 1); + TEveBoxSet* boxSet = static_cast(*parent->BeginChildren()); + + for (int index = 0; index < static_cast(size); ++index) + { + const CaloRecHit* hit = (const CaloRecHit*)item()->modelData(index); + const float* corners = item()->getGeom()->getCorners(hit->detid()); + if (corners == 0) continue; + + FWDigitSetProxyBuilder::BFreeBox_t* b = (FWDigitSetProxyBuilder::BFreeBox_t*)boxSet->GetPlex()->Atom(index); + + viewContextBoxScale(corners, hit->energy()*scale, vc->getEnergyScale()->getPlotEt(), scaledCorners, hit); + memcpy(b->fVertices, &scaledCorners[0], sizeof(b->fVertices)); + } + boxSet->ElementChanged(); +} +//______________________________________________________________________________ + +void +FWCaloRecHitDigitSetProxyBuilder::build( const FWEventItem* iItem, TEveElementList* product, const FWViewContext* vc) +{ + size_t size = iItem->size(); + if (!size) return; + + // m_ignoreGeoShapeSize = item()->getConfig()->value("IgnoreShapeSize"); + + std::vector scaledCorners(24); + + float scale = scaleFactor(vc); + + TEveBoxSet* boxSet = addBoxSetToProduct(product); + boxSet->SetAntiFlick(kTRUE); + for (int index = 0; index < static_cast(size); ++index) + { + const CaloRecHit* hit = (const CaloRecHit*)item()->modelData(index); + + const float* corners = context().getGeom()->getCorners(hit->detid()); + if (corners) + { + m_vector.Set(0.f, 0.f, 0.f); + for( unsigned int i = 0; i < 24; i += 3 ) + { + m_vector[0] += corners[i]; + m_vector[1] += corners[i + 1]; + m_vector[2] += corners[i + 2]; + } + m_vector.Normalize(); + context().voteMaxEtAndEnergy( m_vector.Perp() *hit->energy(), hit->energy()); + viewContextBoxScale( corners, hit->energy()*scale, vc->getEnergyScale()->getPlotEt(), scaledCorners, hit); + } + + addBox(boxSet, &scaledCorners[0], iItem->modelInfo(index).displayProperties()); + } +} + + diff --git a/Fireworks/Calo/plugins/FWCaloRecHitDigitSetProxyBuilder.h b/Fireworks/Calo/plugins/FWCaloRecHitDigitSetProxyBuilder.h new file mode 100644 index 0000000000000..799237bb772db --- /dev/null +++ b/Fireworks/Calo/plugins/FWCaloRecHitDigitSetProxyBuilder.h @@ -0,0 +1,34 @@ +#ifndef Fireworks_Calo_FWCaloRecHitDigitSetProxyBuilder_h +#define Fireworks_Calo_FWCaloRecHitDigitSetProxyBuilder_h + +#include "TEveVector.h" +#include "Fireworks/Core/interface/FWDigitSetProxyBuilder.h" + +class CaloRecHit; + +class FWCaloRecHitDigitSetProxyBuilder : public FWDigitSetProxyBuilder +{ +public: + FWCaloRecHitDigitSetProxyBuilder(); + virtual ~FWCaloRecHitDigitSetProxyBuilder( void ) {} + + virtual void setItem(const FWEventItem* iItem); + + virtual bool havePerViewProduct(FWViewType::EType) const { return true; } + virtual void scaleProduct(TEveElementList* parent, FWViewType::EType, const FWViewContext* vc); + virtual void build( const FWEventItem* iItem, TEveElementList* product, const FWViewContext* ); + + virtual float scaleFactor(const FWViewContext* vc); + virtual void invertBox(bool x ) { m_invertBox = x ;} + virtual void viewContextBoxScale( const float* corners, float scale, bool plotEt, std::vector& scaledCorners, const CaloRecHit*); + +private: + + FWCaloRecHitDigitSetProxyBuilder( const FWCaloRecHitDigitSetProxyBuilder& ); + const FWCaloRecHitDigitSetProxyBuilder& operator=( const FWCaloRecHitDigitSetProxyBuilder& ); + + bool m_invertBox; + bool m_ignoreGeoShapeSize; + TEveVector m_vector; // internal memeber, to avoid constant recreation +}; +#endif diff --git a/Fireworks/Calo/plugins/FWCastorRecHitProxyBuilder.cc b/Fireworks/Calo/plugins/FWCastorRecHitProxyBuilder.cc index a1ca75f19e549..b07a56c520686 100644 --- a/Fireworks/Calo/plugins/FWCastorRecHitProxyBuilder.cc +++ b/Fireworks/Calo/plugins/FWCastorRecHitProxyBuilder.cc @@ -5,29 +5,30 @@ * Created by Ianna Osborne on 7/8/10. * */ - -#include "Fireworks/Core/interface/FWDigitSetProxyBuilder.h" -#include "Fireworks/Core/interface/FWEventItem.h" -#include "Fireworks/Core/interface/FWGeometry.h" -#include "Fireworks/Core/interface/BuilderUtils.h" -#include "DataFormats/HcalRecHit/interface/CastorRecHit.h" +#include "Fireworks/Calo/plugins/FWCaloRecHitDigitSetProxyBuilder.h" #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" -class FWCastorRecHitProxyBuilder : public FWDigitSetProxyBuilder +class FWCastorRecHitProxyBuilder : public FWCaloRecHitDigitSetProxyBuilder { public: FWCastorRecHitProxyBuilder( void ) {} virtual ~FWCastorRecHitProxyBuilder( void ) {} + + virtual float scaleFactor(const FWViewContext* vc) { return 10 * FWCaloRecHitDigitSetProxyBuilder::scaleFactor(vc); } + REGISTER_PROXYBUILDER_METHODS(); private: FWCastorRecHitProxyBuilder( const FWCastorRecHitProxyBuilder& ); const FWCastorRecHitProxyBuilder& operator=( const FWCastorRecHitProxyBuilder& ); - - virtual void build( const FWEventItem* iItem, TEveElementList* product, const FWViewContext* ); }; +REGISTER_FWPROXYBUILDER( FWCastorRecHitProxyBuilder, CastorRecHitCollection, "Castor RecHit", FWViewType::kISpyBit ); + +// AMT:: scale box round center. Scaleing and e/et added now. Previously used fireworks::energyTower3DCorners(); + +/* void FWCastorRecHitProxyBuilder::build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*) { const CastorRecHitCollection* collection = 0; @@ -50,5 +51,4 @@ void FWCastorRecHitProxyBuilder::build(const FWEventItem* iItem, TEveElementList addBox(boxSet, &scaledCorners[0], iItem->modelInfo(index++).displayProperties()); } } - -REGISTER_FWPROXYBUILDER( FWCastorRecHitProxyBuilder, CastorRecHitCollection, "Castor RecHit", FWViewType::kISpyBit ); +*/ diff --git a/Fireworks/Calo/plugins/FWEcalRecHitProxyBuilder.cc b/Fireworks/Calo/plugins/FWEcalRecHitProxyBuilder.cc index 23dd8db24777f..c887a83917529 100644 --- a/Fireworks/Calo/plugins/FWEcalRecHitProxyBuilder.cc +++ b/Fireworks/Calo/plugins/FWEcalRecHitProxyBuilder.cc @@ -5,94 +5,40 @@ * Created by Ianna Osborne on 5/28/10. * */ -#include "TEveBoxSet.h" -#include "TEveChunkManager.h" -#include "Fireworks/Core/interface/FWDigitSetProxyBuilder.h" -#include "Fireworks/Core/interface/FWEventItem.h" -#include "Fireworks/Core/interface/FWGeometry.h" -#include "Fireworks/Core/interface/FWViewEnergyScale.h" -#include "Fireworks/Core/interface/BuilderUtils.h" #include "DataFormats/EcalDetId/interface/EcalSubdetector.h" +#include "Fireworks/Calo/plugins/FWCaloRecHitDigitSetProxyBuilder.h" #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" -class FWEcalRecHitProxyBuilder : public FWDigitSetProxyBuilder +class FWEcalRecHitProxyBuilder : public FWCaloRecHitDigitSetProxyBuilder { public: - FWEcalRecHitProxyBuilder():FWDigitSetProxyBuilder(), m_plotEt(true) {} + FWEcalRecHitProxyBuilder() {} virtual ~FWEcalRecHitProxyBuilder() {} - virtual bool havePerViewProduct(FWViewType::EType) const { return true; } - virtual void scaleProduct(TEveElementList* parent, FWViewType::EType, const FWViewContext* vc); + virtual void viewContextBoxScale( const float* corners, float scale, bool plotEt, std::vector& scaledCorners, const CaloRecHit*); REGISTER_PROXYBUILDER_METHODS(); private: FWEcalRecHitProxyBuilder( const FWEcalRecHitProxyBuilder& ); const FWEcalRecHitProxyBuilder& operator=( const FWEcalRecHitProxyBuilder& ); - - virtual void build( const FWEventItem* iItem, TEveElementList* product, const FWViewContext* ); - - bool m_plotEt; }; -//______________________________________________________________________________ - - -void -FWEcalRecHitProxyBuilder::scaleProduct(TEveElementList* parent, FWViewType::EType type, const FWViewContext* vc) -{ - - if (m_plotEt != vc->getEnergyScale()->getPlotEt() ) - { - m_plotEt = !m_plotEt; - - const EcalRecHitCollection* collection = 0; - item()->get( collection ); - if (! collection) - return; - - int index = 0; - std::vector scaledCorners(24); - for (std::vector::const_iterator it = collection->begin() ; it != collection->end(); ++it, ++index) - { - const float* corners = item()->getGeom()->getCorners((*it).detid()); - if (corners == 0) - continue; - Float_t scale = 10.0; - bool reflect = false; - if (EcalSubdetector( (*it).detid().subdetId() ) == EcalPreshower) - { - scale = 1000.0; // FIXME: The scale should be taken form somewhere else - reflect = corners[2] < 0; - } +void FWEcalRecHitProxyBuilder::viewContextBoxScale( const float* corners, float scale, bool plotEt, std::vector& scaledCorners, const CaloRecHit* hit) +{ + invertBox((EcalSubdetector( hit->detid().subdetId() ) == EcalPreshower) && (corners[2] < 0)); + FWCaloRecHitDigitSetProxyBuilder::viewContextBoxScale(corners, scale, plotEt, scaledCorners, hit ); +} - FWDigitSetProxyBuilder::BFreeBox_t* b = (FWDigitSetProxyBuilder::BFreeBox_t*)getBoxSet()->GetPlex()->Atom(index); - /* - printf("--------------------scale product \n"); - for (int i = 0; i < 8 ; ++i) - printf("[%f %f %f ]\n",b->fVertices[i][0], b->fVertices[i][1],b->fVertices[i][2] ); - */ - if (m_plotEt) - fireworks::etTower3DCorners(corners, (*it).energy() * scale, scaledCorners, reflect); - else - fireworks::energyTower3DCorners(corners, (*it).energy() * scale, scaledCorners, reflect); +REGISTER_FWPROXYBUILDER( FWEcalRecHitProxyBuilder, EcalRecHitCollection, "Ecal RecHit", FWViewType::kISpyBit ); - memcpy(b->fVertices, &scaledCorners[0], sizeof(b->fVertices)); +// AMT: Scale box round cener. Prviousy used fireworks::energyTower3DCorners(). +// Why differnt scale factor in EcalPreShower ??? - /* - printf("after \n"); - for (int i = 0; i < 8 ; ++i) - printf("[%f %f %f ]\n",b->fVertices[i][0], b->fVertices[i][1],b->fVertices[i][2] ); - */ - } - getBoxSet()->ElementChanged(); - } -} - -//______________________________________________________________________________ +/* void FWEcalRecHitProxyBuilder::build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext* vc) { m_plotEt = vc->getEnergyScale()->getPlotEt(); @@ -127,5 +73,4 @@ void FWEcalRecHitProxyBuilder::build(const FWEventItem* iItem, TEveElementList* addBox(boxSet, &scaledCorners[0], iItem->modelInfo(index++).displayProperties()); } } - -REGISTER_FWPROXYBUILDER( FWEcalRecHitProxyBuilder, EcalRecHitCollection, "Ecal RecHit", FWViewType::kISpyBit ); +*/ diff --git a/Fireworks/Calo/plugins/FWHBHERecHitProxyBuilder.cc b/Fireworks/Calo/plugins/FWHBHERecHitProxyBuilder.cc index 5277b9d620561..4de4ffafc0eba 100644 --- a/Fireworks/Calo/plugins/FWHBHERecHitProxyBuilder.cc +++ b/Fireworks/Calo/plugins/FWHBHERecHitProxyBuilder.cc @@ -1,85 +1,25 @@ -#include "TEveCompound.h" -#include "TEveBoxSet.h" - -#include "Fireworks/Core/interface/FWDigitSetProxyBuilder.h" -#include "Fireworks/Core/interface/FWEventItem.h" -#include "Fireworks/Core/interface/FWGeometry.h" -#include "Fireworks/Core/interface/BuilderUtils.h" -#include "Fireworks/Core/interface/FWViewEnergyScale.h" -#include "DataFormats/HcalRecHit/interface/HBHERecHit.h" +#include "Fireworks/Calo/plugins/FWCaloRecHitDigitSetProxyBuilder.h" #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" -class FWHBHERecHitProxyBuilder : public FWDigitSetProxyBuilder +class FWHBHERecHitProxyBuilder : public FWCaloRecHitDigitSetProxyBuilder { public: - FWHBHERecHitProxyBuilder( void ) - : m_maxEnergy( 0.85 ), m_plotEt(true) - {} - - virtual ~FWHBHERecHitProxyBuilder( void ) - {} - - virtual bool havePerViewProduct(FWViewType::EType) const { return true; } - virtual void scaleProduct(TEveElementList* parent, FWViewType::EType, const FWViewContext* vc); + FWHBHERecHitProxyBuilder( void ) { invertBox(true); } + virtual ~FWHBHERecHitProxyBuilder( void ) {} REGISTER_PROXYBUILDER_METHODS(); private: - virtual void build( const FWEventItem* iItem, TEveElementList* product, const FWViewContext* ); - - Float_t m_maxEnergy; - bool m_plotEt; - FWHBHERecHitProxyBuilder( const FWHBHERecHitProxyBuilder& ); const FWHBHERecHitProxyBuilder& operator=( const FWHBHERecHitProxyBuilder& ); }; -void -FWHBHERecHitProxyBuilder::scaleProduct(TEveElementList* parent, FWViewType::EType type, const FWViewContext* vc) -{ - if (m_plotEt != vc->getEnergyScale()->getPlotEt() ) - { - m_plotEt = !m_plotEt; - - const HBHERecHitCollection* collection = 0; - item()->get( collection ); - if (! collection) - return; - - int index = 0; - std::vector scaledCorners(24); - for (std::vector::const_iterator it = collection->begin() ; it != collection->end(); ++it, ++index) - { - const float* corners = item()->getGeom()->getCorners((*it).detid()); - if (corners == 0) - continue; - FWDigitSetProxyBuilder::BFreeBox_t* b = (FWDigitSetProxyBuilder::BFreeBox_t*)getBoxSet()->GetPlex()->Atom(index); - - /* - printf("--------------------scale product \n"); - for (int i = 0; i < 8 ; ++i) - printf("[%f %f %f ]\n",b->fVertices[i][0], b->fVertices[i][1],b->fVertices[i][2] ); - */ - - if (m_plotEt) - fireworks::etScaledBox3DCorners(corners, (*it).energy(), m_maxEnergy, scaledCorners, true); - else - fireworks::energyScaledBox3DCorners(corners, (*it).energy() / m_maxEnergy, scaledCorners, true); - - /* - printf("after \n"); - for (int i = 0; i < 8 ; ++i) - printf("[%f %f %f ]\n",b->fVertices[i][0], b->fVertices[i][1],b->fVertices[i][2] ); - */ - memcpy(b->fVertices, &scaledCorners[0], sizeof(b->fVertices)); +REGISTER_FWPROXYBUILDER( FWHBHERecHitProxyBuilder, HBHERecHitCollection, "HBHE RecHit", FWViewType::kISpyBit ); - } - getBoxSet()->ElementChanged(); - } -} -//______________________________________________________________________________ +// AMT: Refelct box. Previously used energyScaledBox3DCorners() +/* void FWHBHERecHitProxyBuilder::build( const FWEventItem* iItem, TEveElementList* product, const FWViewContext* vc) { @@ -117,5 +57,4 @@ FWHBHERecHitProxyBuilder::build( const FWEventItem* iItem, TEveElementList* prod addBox(boxSet, &scaledCorners[0], iItem->modelInfo(index++).displayProperties()); } } - -REGISTER_FWPROXYBUILDER( FWHBHERecHitProxyBuilder, HBHERecHitCollection, "HBHE RecHit", FWViewType::kISpyBit ); +*/ diff --git a/Fireworks/Calo/plugins/FWHFRecHitProxyBuilder.cc b/Fireworks/Calo/plugins/FWHFRecHitProxyBuilder.cc index 7ee731e6b2223..d2f37bdbda8ce 100644 --- a/Fireworks/Calo/plugins/FWHFRecHitProxyBuilder.cc +++ b/Fireworks/Calo/plugins/FWHFRecHitProxyBuilder.cc @@ -1,33 +1,25 @@ -#include "Fireworks/Core/interface/FWDigitSetProxyBuilder.h" -#include "Fireworks/Core/interface/FWEventItem.h" -#include "Fireworks/Core/interface/FWGeometry.h" -#include "Fireworks/Core/interface/BuilderUtils.h" -#include "Fireworks/Core/interface/fwLog.h" -#include "DataFormats/HcalRecHit/interface/HFRecHit.h" #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" -#include "TEveCompound.h" +#include "Fireworks/Calo/plugins/FWCaloRecHitDigitSetProxyBuilder.h" -class FWHFRecHitProxyBuilder : public FWDigitSetProxyBuilder +class FWHFRecHitProxyBuilder : public FWCaloRecHitDigitSetProxyBuilder { public: - FWHFRecHitProxyBuilder( void ) - : m_maxEnergy( 5.0 ) - {} - - virtual ~FWHFRecHitProxyBuilder( void ) - {} + FWHFRecHitProxyBuilder( void ) {invertBox(true); } + virtual ~FWHFRecHitProxyBuilder( void ) {} REGISTER_PROXYBUILDER_METHODS(); private: - virtual void build( const FWEventItem* iItem, TEveElementList* product, const FWViewContext* ); - - Float_t m_maxEnergy; - FWHFRecHitProxyBuilder( const FWHFRecHitProxyBuilder& ); const FWHFRecHitProxyBuilder& operator=( const FWHFRecHitProxyBuilder& ); }; + +REGISTER_FWPROXYBUILDER( FWHFRecHitProxyBuilder, HFRecHitCollection, "HF RecHit", FWViewType::kISpyBit ); + +// AMT: Reflect box. Previously used energyScaledBox3DCorners(). Scaling and e/et mode added now. + +/* void FWHFRecHitProxyBuilder::build( const FWEventItem* iItem, TEveElementList* product, const FWViewContext* ) { @@ -66,5 +58,4 @@ FWHFRecHitProxyBuilder::build( const FWEventItem* iItem, TEveElementList* produc addBox(boxSet, &scaledCorners[0], iItem->modelInfo(index++).displayProperties()); } } - -REGISTER_FWPROXYBUILDER( FWHFRecHitProxyBuilder, HFRecHitCollection, "HF RecHit", FWViewType::kISpyBit ); +*/ diff --git a/Fireworks/Calo/plugins/FWHORecHitProxyBuilder.cc b/Fireworks/Calo/plugins/FWHORecHitProxyBuilder.cc index a87bcb88e68bf..eee8a41200936 100644 --- a/Fireworks/Calo/plugins/FWHORecHitProxyBuilder.cc +++ b/Fireworks/Calo/plugins/FWHORecHitProxyBuilder.cc @@ -1,32 +1,25 @@ -#include "Fireworks/Core/interface/FWDigitSetProxyBuilder.h" -#include "Fireworks/Core/interface/FWEventItem.h" -#include "Fireworks/Core/interface/FWGeometry.h" -#include "Fireworks/Core/interface/BuilderUtils.h" -#include "DataFormats/HcalRecHit/interface/HORecHit.h" +#include "Fireworks/Calo/plugins/FWCaloRecHitDigitSetProxyBuilder.h" #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" -#include "TEveCompound.h" -class FWHORecHitProxyBuilder : public FWDigitSetProxyBuilder + +class FWHORecHitProxyBuilder : public FWCaloRecHitDigitSetProxyBuilder { public: - FWHORecHitProxyBuilder( void ) - : m_maxEnergy( 1.0 ) - {} - - virtual ~FWHORecHitProxyBuilder( void ) - {} + FWHORecHitProxyBuilder( void ) { invertBox(true); } + virtual ~FWHORecHitProxyBuilder( void ) {} REGISTER_PROXYBUILDER_METHODS(); private: - virtual void build( const FWEventItem* iItem, TEveElementList* product, const FWViewContext* ); - - Float_t m_maxEnergy; - FWHORecHitProxyBuilder( const FWHORecHitProxyBuilder& ); const FWHORecHitProxyBuilder& operator=( const FWHORecHitProxyBuilder& ); }; +REGISTER_FWPROXYBUILDER( FWHORecHitProxyBuilder, HORecHitCollection, "HO RecHit", FWViewType::kISpyBit ); + +// AMT scale around center, box is inverted. Scaling and e/et mode added now. Previously used fireworks::energyScaledBox3DCorners(). + +/* void FWHORecHitProxyBuilder::build( const FWEventItem* iItem, TEveElementList* product, const FWViewContext* ) { @@ -57,5 +50,4 @@ FWHORecHitProxyBuilder::build( const FWEventItem* iItem, TEveElementList* produc addBox(boxSet, &scaledCorners[0], iItem->modelInfo(index++).displayProperties()); } } - -REGISTER_FWPROXYBUILDER( FWHORecHitProxyBuilder, HORecHitCollection, "HO RecHit", FWViewType::kISpyBit ); +*/ diff --git a/Fireworks/Calo/plugins/FWZDCRecHitProxyBuilder.cc b/Fireworks/Calo/plugins/FWZDCRecHitProxyBuilder.cc index f5eec1bef808f..e3b6e60857e62 100644 --- a/Fireworks/Calo/plugins/FWZDCRecHitProxyBuilder.cc +++ b/Fireworks/Calo/plugins/FWZDCRecHitProxyBuilder.cc @@ -5,15 +5,12 @@ * Created by Ianna Osborne on 7/8/10. * */ -#include "Fireworks/Core/interface/FWDigitSetProxyBuilder.h" -#include "Fireworks/Core/interface/FWEventItem.h" -#include "Fireworks/Core/interface/FWGeometry.h" -#include "Fireworks/Core/interface/BuilderUtils.h" +#include "Fireworks/Calo/plugins/FWCaloRecHitDigitSetProxyBuilder.h" #include "DataFormats/HcalRecHit/interface/ZDCRecHit.h" #include "DataFormats/Common/interface/SortedCollection.h" -#include "TEveBoxSet.h" -class FWZDCRecHitProxyBuilder : public FWDigitSetProxyBuilder + +class FWZDCRecHitProxyBuilder : public FWCaloRecHitDigitSetProxyBuilder { public: FWZDCRecHitProxyBuilder( void ) {} @@ -23,11 +20,15 @@ class FWZDCRecHitProxyBuilder : public FWDigitSetProxyBuilder private: FWZDCRecHitProxyBuilder( const FWZDCRecHitProxyBuilder& ); - - const FWZDCRecHitProxyBuilder& operator=( const FWZDCRecHitProxyBuilder& ); - virtual void build( const FWEventItem* iItem, TEveElementList* product, const FWViewContext* ); + const FWZDCRecHitProxyBuilder& operator=( const FWZDCRecHitProxyBuilder& ); }; + +REGISTER_FWPROXYBUILDER( FWZDCRecHitProxyBuilder, edm::SortedCollection , "ZDC RecHit", FWViewType::kISpyBit ); + +// AMT scale box round center. Scaling and e/et mode added now. Previusly used energyTower3DCorners(). + +/* void FWZDCRecHitProxyBuilder::build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*) { const edm::SortedCollection *collection = 0; @@ -53,6 +54,4 @@ void FWZDCRecHitProxyBuilder::build(const FWEventItem* iItem, TEveElementList* p addBox(boxSet, &scaledCorners[0], iItem->modelInfo(index++).displayProperties()); } -} - -REGISTER_FWPROXYBUILDER( FWZDCRecHitProxyBuilder, edm::SortedCollection , "ZDC RecHit", FWViewType::kISpyBit ); + }*/ diff --git a/Fireworks/Calo/src/FWECALDetailViewBuilder.cc b/Fireworks/Calo/src/FWECALDetailViewBuilder.cc index 8c5654aefa76d..32b0883279da0 100644 --- a/Fireworks/Calo/src/FWECALDetailViewBuilder.cc +++ b/Fireworks/Calo/src/FWECALDetailViewBuilder.cc @@ -25,7 +25,7 @@ #include -TEveCaloLego* FWECALDetailViewBuilder::build() +TEveCaloData* FWECALDetailViewBuilder::buildCaloData(bool xyEE) { // get the hits from the event @@ -104,7 +104,7 @@ TEveCaloLego* FWECALDetailViewBuilder::build() if( handle_hits.isValid() ) { - fillData( hits, data ); + fillData( hits, data, xyEE ); } // axis @@ -115,7 +115,7 @@ TEveCaloLego* FWECALDetailViewBuilder::build() // add dummy background float x = m_size*TMath::DegToRad(); - if (fabs(m_eta) < 1.5) { + if (fabs(m_eta) < 1.5 || xyEE == false) { etaMin = m_eta -x; etaMax = m_eta +x; phiMin = m_phi -x; @@ -144,7 +144,7 @@ TEveCaloLego* FWECALDetailViewBuilder::build() data->GetPhiLimits(phiMin, phiMax); // printf("data rng %f %f %f %f\n",etaMin, etaMax, phiMin, phiMax ); - if (fabs(m_eta) > 1.5) { + if (fabs(m_eta) > 1.5 && xyEE ) { eta_axis = new TAxis(10, etaMin, etaMax); phi_axis = new TAxis(10, phiMin, phiMax); eta_axis->SetTitle("X[cm]"); @@ -180,8 +180,18 @@ TEveCaloLego* FWECALDetailViewBuilder::build() phi_axis->SetNdivisions(510); data->SetEtaBins(eta_axis); data->SetPhiBins(phi_axis); + return data; +} - +//_______________________________________________________________ +TEveCaloLego* FWECALDetailViewBuilder::build() +{ + TEveCaloData* data = buildCaloData(true); + + double etaMin, etaMax, phiMin, phiMax; + data->GetEtaLimits(etaMin, etaMax); + data->GetPhiLimits(phiMin, phiMax); + // lego TEveCaloLego *lego = new TEveCaloLego(data); lego->SetDrawNumberCellPixels(100); @@ -271,13 +281,13 @@ FWECALDetailViewBuilder::showSuperClusters( Color_t color1, Color_t color2 ) void FWECALDetailViewBuilder::fillData( const EcalRecHitCollection *hits, - TEveCaloDataVec *data ) + TEveCaloDataVec *data, bool xyEE ) { const float barrelCR = m_size*0.0172; // barrel cell range - + // loop on all the detids for( EcalRecHitCollection::const_iterator k = hits->begin(), kEnd = hits->end(); - k != kEnd; ++k ) + k != kEnd; ++k ) { // get reco geometry double centerEta = 0; @@ -285,120 +295,121 @@ FWECALDetailViewBuilder::fillData( const EcalRecHitCollection *hits, const float* points = m_geom->getCorners( k->id().rawId()); if( points != 0 ) { - TEveVector v; - int j = 0; - for( int i = 0; i < 8; ++i ) - { - v += TEveVector( points[j], points[j + 1], points[j + 2] ); - j +=3; - } - centerEta = v.Eta(); - centerPhi = v.Phi(); + TEveVector v; + int j = 0; + for( int i = 0; i < 8; ++i ) + { + v += TEveVector( points[j], points[j + 1], points[j + 2] ); + j +=3; + } + centerEta = v.Eta(); + centerPhi = v.Phi(); } else - fwLog( fwlog::kInfo ) << "cannot get geometry for DetId: "<< k->id().rawId() << ". Ignored.\n"; + fwLog( fwlog::kInfo ) << "cannot get geometry for DetId: "<< k->id().rawId() << ". Ignored.\n"; double size = k->energy() / cosh( centerEta ); - + // check what slice to put in int slice = 0; std::map::const_iterator itr = m_detIdsToColor.find(k->id()); if (itr != m_detIdsToColor.end()) slice = itr->second; - + // if in the EB - if( k->id().subdetId() == EcalBarrel ) + if( k->id().subdetId() == EcalBarrel || xyEE == false ) { - // do phi wrapping - if( centerPhi > m_phi + M_PI) centerPhi -= 2 * M_PI; - if( centerPhi < m_phi - M_PI) centerPhi += 2 * M_PI; - - // check if the hit is in the window to be drawn - if( !( fabs( centerEta - m_eta ) < barrelCR - && fabs( centerPhi - m_phi ) < barrelCR )) continue; - - double minEta(10), maxEta(-10), minPhi(4), maxPhi(-4); - if( points != 0 ) - { - // calorimeter crystalls have slightly non-symetrical form in eta-phi projection - // so if we simply get the largest eta and phi, cells will overlap - // therefore we get a smaller eta-phi range representing the inner square - // we also should use only points from the inner face of the crystal, since - // non-projecting direction of crystals leads to large shift in eta on outter - // face. - int j = 0; - for( unsigned int i = 0; i < 8; ++i ) - { - TEveVector crystal( points[j], points[j + 1], points[j + 2] ); - j += 3; - double eta = crystal.Eta(); - double phi = crystal.Phi(); - if ( crystal.Perp() > 135 ) continue; - if ( minEta - eta > 0.01) minEta = eta; - if ( eta - minEta > 0 && eta - minEta < 0.01 ) minEta = eta; - if ( eta - maxEta > 0.01) maxEta = eta; - if ( maxEta - eta > 0 && maxEta - eta < 0.01 ) maxEta = eta; - if ( minPhi - phi > 0.01) minPhi = phi; - if ( phi - minPhi > 0 && phi - minPhi < 0.01 ) minPhi = phi; - if ( phi - maxPhi > 0.01) maxPhi = phi; - if ( maxPhi - phi > 0 && maxPhi - phi < 0.01 ) maxPhi = phi; - } - } - else - { - double delta = 0.0172 * 0.5; - minEta = centerEta - delta; - maxEta = centerEta + delta; - minPhi = centerPhi - delta; - maxPhi = centerPhi + delta; - } - if( minPhi >= ( m_phi - barrelCR ) && maxPhi <= ( m_phi + barrelCR ) && - minEta >= ( m_eta - barrelCR ) && maxEta <= ( m_eta + barrelCR )) - { - data->AddTower( minEta, maxEta, minPhi, maxPhi ); - // printf("EB add %f %f %f %f \n",minEta, maxEta, minPhi, maxPhi ); - data->FillSlice( slice, size ); - } - // otherwise in the EE + // do phi wrapping + if( centerPhi > m_phi + M_PI) centerPhi -= 2 * M_PI; + if( centerPhi < m_phi - M_PI) centerPhi += 2 * M_PI; + + // check if the hit is in the window to be drawn + if( !( fabs( centerEta - m_eta ) < barrelCR + && fabs( centerPhi - m_phi ) < barrelCR )) continue; + + double minEta(10), maxEta(-10), minPhi(4), maxPhi(-4); + if( points != 0 ) + { + // calorimeter crystalls have slightly non-symetrical form in eta-phi projection + // so if we simply get the largest eta and phi, cells will overlap + // therefore we get a smaller eta-phi range representing the inner square + // we also should use only points from the inner face of the crystal, since + // non-projecting direction of crystals leads to large shift in eta on outter + // face. + int j = 0; + float eps = 0.005; + for( unsigned int i = 0; i < 8; ++i ) + { + TEveVector crystal( points[j], points[j + 1], points[j + 2] ); + j += 3; + double eta = crystal.Eta(); + double phi = crystal.Phi(); + if ( ((k->id().subdetId() == EcalBarrel) && (crystal.Perp() > 135) )|| ((k->id().subdetId() == EcalEndcap) && (crystal.Perp() > 155))) continue; + if ( minEta - eta > eps) minEta = eta; + if ( eta - minEta > 0 && eta - minEta < eps ) minEta = eta; + if ( eta - maxEta > eps) maxEta = eta; + if ( maxEta - eta > 0 && maxEta - eta < eps ) maxEta = eta; + if ( minPhi - phi > eps) minPhi = phi; + if ( phi - minPhi > 0 && phi - minPhi < eps ) minPhi = phi; + if ( phi - maxPhi > eps) maxPhi = phi; + if ( maxPhi - phi > 0 && maxPhi - phi < eps ) maxPhi = phi; + } + } + else + { + double delta = 0.0172 * 0.5; + minEta = centerEta - delta; + maxEta = centerEta + delta; + minPhi = centerPhi - delta; + maxPhi = centerPhi + delta; + } + if( minPhi >= ( m_phi - barrelCR ) && maxPhi <= ( m_phi + barrelCR ) && + minEta >= ( m_eta - barrelCR ) && maxEta <= ( m_eta + barrelCR )) + { + // printf("add %f %f %f %f \n",minEta, maxEta, minPhi, maxPhi ); + data->AddTower( minEta, maxEta, minPhi, maxPhi ); + data->FillSlice( slice, size ); + } + // otherwise in the EE } else if( k->id().subdetId() == EcalEndcap ) { - // check if the hit is in the window to be drawn - double crystalSize = m_size * 0.0172; - if( !( fabs( centerEta - m_eta ) < ( crystalSize ) - && fabs( centerPhi - m_phi ) < ( crystalSize ))) - continue; - - if( points != 0 ) - { - double minX(9999), maxX(-9999), minY(9999), maxY(-9999); - int j = 0; - for( unsigned int i = 0; i < 8; ++i ) - { - TEveVector crystal( points[j], points[j + 1], points[j + 2] ); - j += 3; - double x = crystal.fX; - double y = crystal.fY; - if( fabs( crystal.fZ ) > 330 ) continue; - if( minX - x > 0.01 ) minX = x; - if( x - maxX > 0.01 ) maxX = x; - if( minY - y > 0.01 ) minY = y; - if( y - maxY > 0.01 ) maxY = y; - } - data->AddTower( minX, maxX, minY, maxY ); + // check if the hit is in the window to be drawn + double crystalSize = m_size * 0.0172; + if( !( fabs( centerEta - m_eta ) < ( crystalSize ) + && fabs( centerPhi - m_phi ) < ( crystalSize ))) + continue; + + if( points != 0 ) + { + double minX(9999), maxX(-9999), minY(9999), maxY(-9999); + int j = 0; + for( unsigned int i = 0; i < 8; ++i ) + { + TEveVector crystal( points[j], points[j + 1], points[j + 2] ); + j += 3; + double x = crystal.fX; + double y = crystal.fY; + if( fabs( crystal.fZ ) > 330 ) continue; + if( minX - x > 0.01 ) minX = x; + if( x - maxX > 0.01 ) maxX = x; + if( minY - y > 0.01 ) minY = y; + if( y - maxY > 0.01 ) maxY = y; + } + data->AddTower( minX, maxX, minY, maxY ); // printf("EE add %f %f %f %f \n",minX, maxX, minY, maxY ); - } - data->FillSlice( slice, size ); + } + data->FillSlice( slice, size ); } } // end loop on hits - + data->DataChanged(); - } +} double FWECALDetailViewBuilder::makeLegend( double x0, double y0, - Color_t clustered1, Color_t clustered2, - Color_t supercluster - ) + Color_t clustered1, Color_t clustered2, + Color_t supercluster + ) { Double_t fontsize = 0.07; TLatex* latex = new TLatex(); @@ -406,37 +417,37 @@ FWECALDetailViewBuilder::makeLegend( double x0, double y0, Double_t y = y0; Double_t boxH = 0.25*fontsize; Double_t yStep = 0.04; - + y -= yStep; latex->DrawLatex(x, y, "Energy types:"); y -= yStep; - + Double_t pos[4]; pos[0] = x+0.05; pos[2] = x+0.20; - + pos[1] = y; pos[3] = pos[1] + boxH; FWDetailViewBase::drawCanvasBox(pos, m_defaultColor); latex->DrawLatex(x+0.25, y, "unclustered"); y -= yStep; if (clustered1<0) return y; - + pos[1] = y; pos[3] = pos[1] + boxH; FWDetailViewBase::drawCanvasBox(pos, clustered1); latex->DrawLatex(x+0.25, y, "clustered"); y -= yStep; if (clustered2<0) return y; - + pos[1] = y; pos[3] = pos[1] + boxH; FWDetailViewBase::drawCanvasBox(pos, clustered2); latex->DrawLatex(x+0.25, y, "clustered"); y -= yStep; if (supercluster<0) return y; - + pos[1] = y; pos[3] = pos[1] + boxH; FWDetailViewBase::drawCanvasBox(pos, supercluster); latex->DrawLatex(x+0.25, y, "super-cluster"); y -= yStep; - + return y; } diff --git a/Fireworks/Core/src/FWProxyBuilderConfiguration.cc b/Fireworks/Core/src/FWProxyBuilderConfiguration.cc index b28117bf34c8c..519cda89ee8f7 100644 --- a/Fireworks/Core/src/FWProxyBuilderConfiguration.cc +++ b/Fireworks/Core/src/FWProxyBuilderConfiguration.cc @@ -8,7 +8,7 @@ // // Original Author: // Created: Wed Jul 27 00:58:43 CEST 2011 -// $Id: FWProxyBuilderConfiguration.cc,v 1.7 2011/08/16 01:16:05 amraktad Exp $ +// $Id: FWProxyBuilderConfiguration.cc,v 1.8 2011/08/20 03:39:20 amraktad Exp $ // // system include files @@ -147,7 +147,9 @@ template T FWProxyBuilderConfiguration::value(const std::string& pname template bool FWProxyBuilderConfiguration::value(const std::string& name); template long FWProxyBuilderConfiguration::value(const std::string& name); template double FWProxyBuilderConfiguration::value(const std::string& name); +template std::string FWProxyBuilderConfiguration::value(const std::string& name); template FWGenericParameter* FWProxyBuilderConfiguration::assertParam(const std::string& name, bool def); template FWGenericParameterWithRange* FWProxyBuilderConfiguration::assertParam(const std::string& name, long def,long min, long max); template FWGenericParameterWithRange* FWProxyBuilderConfiguration::assertParam(const std::string& name, double def,double min, double max); +template FWGenericParameter* FWProxyBuilderConfiguration::assertParam(const std::string& name, std::string def); diff --git a/Fireworks/ParticleFlow/plugins/FWPFCandidateWithHitsProxyBuilder.cc b/Fireworks/ParticleFlow/plugins/FWPFCandidateWithHitsProxyBuilder.cc new file mode 100644 index 0000000000000..79efc67471aeb --- /dev/null +++ b/Fireworks/ParticleFlow/plugins/FWPFCandidateWithHitsProxyBuilder.cc @@ -0,0 +1,359 @@ + +#define protected public +#include "TEveBoxSet.h" +#undef protected +#include "TEveTrack.h" +#include "TEveTrackPropagator.h" +#include "TEveCompound.h" +#include "TEveStraightLineSet.h" +#include "TEveProjectionBases.h" + +#include "Fireworks/ParticleFlow/plugins/FWPFCandidateWithHitsProxyBuilder.h" +#include "Fireworks/Core/interface/FWEventItem.h" +#include "Fireworks/Core/interface/FWGeometry.h" +#include "Fireworks/Core/interface/BuilderUtils.h" +#include "Fireworks/Core/interface/fwLog.h" +#include "Fireworks/Core/interface/FWViewEnergyScale.h" +#include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h" +#include "Fireworks/ParticleFlow/interface/setTrackTypePF.h" + +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" +#include "DataFormats/ParticleFlowReco/interface/PFBlock.h" +#include "DataFormats/ParticleFlowReco/interface/PFCluster.h" + +#include "DataFormats/FWLite/interface/Handle.h" + +namespace +{ +static std::string kRecHitCollectionName = "RecHitCollection"; +void addLineToLineSet(TEveStraightLineSet* ls, const float* p, int i1, int i2) +{ + i1 *= 3; + i2 *= 3; + ls->AddLine(p[i1], p[i1+1], p[i1+2], p[i2], p[i2+1], p[i2+2]); +} + + +void addBoxAsLines(TEveStraightLineSet* lineset, const float* p) +{ + for (int l = 0; l < 5; l+=4) + { + addLineToLineSet(lineset, p, 0+l, 1+l); + addLineToLineSet(lineset, p, 1+l, 2+l); + addLineToLineSet(lineset, p, 2+l, 3+l); + addLineToLineSet(lineset, p, 3+l, 0+l); + } + for (int l = 0; l < 4; ++l) + addLineToLineSet(lineset, p, 0+l, 4+l); +} + +void editLineInLineSet(TEveChunkManager::iterator& li, const float* p, int i1, int i2) +{ + TEveStraightLineSet::Line_t& line = * (TEveStraightLineSet::Line_t*) li(); + i1 *= 3; + i2 *= 3; + for (int i = 0; i < 3 ; ++i) { + line.fV1[0+i] = p[i1+i]; + line.fV2[0+i] = p[i2+i]; + } + + li.next(); +} + +void editBoxInLineSet(TEveChunkManager::iterator& li, const float* p) +{ + + for (int i = 0; i < 5; i+=4) + { + editLineInLineSet(li, p, 0+i, 1+i); + + editLineInLineSet(li, p, 1+i, 2+i); + editLineInLineSet(li, p, 2+i, 3+i); + editLineInLineSet(li, p, 3+i, 0+i); + } + for (int i = 0; i < 4; ++i) + editLineInLineSet(li, p, 0+i, 4+i); +} +} + + //______________________________________________________________________________ + +void FWPFCandidateWithHitsProxyBuilder::setItem(const FWEventItem* iItem) +{ + + FWProxyBuilderBase::setItem(iItem); + if (iItem) { + std::string defn = "particleFlowRecHitHCAL"; + iItem->getConfig()->assertParam(kRecHitCollectionName, defn); + } +} + +//______________________________________________________________________________ +void +FWPFCandidateWithHitsProxyBuilder::build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext* vc) +{ + // init PFCandiate collection + reco::PFCandidateCollection const * candidates = 0; + iItem->get( candidates ); + if( candidates == 0 ) return; + + Int_t idx = 0; + initPFRecHitsCollections(); + for( reco::PFCandidateCollection::const_iterator it = candidates->begin(), itEnd = candidates->end(); it != itEnd; ++it, ++idx) + { + TEveCompound* comp = createCompound(); + setupAddElement( comp, product ); + // printf("products size %d/%d \n", (int)iItem->size(), product->NumChildren()); + + const reco::PFCandidate& cand = *it; + + // track + { + TEveRecTrack t; + t.fBeta = 1.; + t.fP = TEveVector( cand.px(), cand.py(), cand.pz() ); + t.fV = TEveVector( cand.vertex().x(), cand.vertex().y(), cand.vertex().z() ); + t.fSign = cand.charge(); + TEveTrack* trk = new TEveTrack(&t, context().getTrackPropagator() ); + trk->MakeTrack(); + fireworks::setTrackTypePF( cand, trk ); + setupAddElement( trk, comp); + } + // hits + { + comp->SetMainColor(iItem->defaultDisplayProperties().color()); + addHitsForCandidate(cand, comp, vc); + } + + } +} + +//______________________________________________________________________________ +void FWPFCandidateWithHitsProxyBuilder::initPFRecHitsCollections() +{ + // ref hcal collections + edm::Handle handle_hits; + + + m_collectionHCAL =0; + try + { + std::string scc = item()->getConfig()->value(kRecHitCollectionName); + edm::InputTag tag(scc); + item()->getEvent()->getByLabel(tag, handle_hits); + if (handle_hits.isValid()) + { + m_collectionHCAL = &*handle_hits; + fwLog(fwlog::kInfo) <<"FWPFCandidateWithHitsProxyBuilder, item " << item()->name() <<": Accessed collection with name " << scc << "." << std::endl; + } + else + { + fwLog(fwlog::kError) <<"FWPFCandidateWithHitsProxyBuilder, item " << item()->name() <<": Failed to access collection with name " << scc << "." << std::endl; + } + } + catch (...) + { + fwLog(fwlog::kError) <<"FWPFCandidateWithHitsProxyBuilder, item " << item()->name() <<": Failed to access rechit collection \n"; + } +} + +//______________________________________________________________________________ +void FWPFCandidateWithHitsProxyBuilder::viewContextBoxScale( const float* corners, float scale, bool plotEt, std::vector& scaledCorners, const reco::PFRecHit*) +{ + static TEveVector vtmp; + vtmp.Set(0.f, 0.f, 0.f); + for( unsigned int i = 0; i < 24; i += 3 ) + { + vtmp[0] += corners[i]; + vtmp[1] += corners[i + 1]; + vtmp[2] += corners[i + 2]; + } + vtmp *= 1.f/8.f; + + if (plotEt) + { + scale *= vtmp.Perp()/vtmp.Mag(); + } + + // Coordinates for a scaled version of the original box + for( unsigned int i = 0; i < 24; i += 3 ) + { + scaledCorners[i] = vtmp[0] + ( corners[i] - vtmp[0] ) * scale; + scaledCorners[i + 1] = vtmp[1] + ( corners[i + 1] - vtmp[1] ) * scale; + scaledCorners[i + 2] = vtmp[2] + ( corners[i + 2] - vtmp[2] ) * scale; + } +} + +//______________________________________________________________________________ +const reco::PFRecHit* FWPFCandidateWithHitsProxyBuilder::getHitForDetId(unsigned candIdx) +{ + + for (reco::PFRecHitCollection::const_iterator it = m_collectionHCAL->begin(); it != m_collectionHCAL->end(); ++it) + { + + if ( it->detId() == candIdx) + { + return &(*it); + } + } + return 0; +} + +//______________________________________________________________________________ +void FWPFCandidateWithHitsProxyBuilder::scaleProduct(TEveElementList* parent, FWViewType::EType type, const FWViewContext* vc) +{ + std::vector scaledCorners(24); + + float scale = vc->getEnergyScale()->getScaleFactor3D()/50; + for (TEveElement::List_i i=parent->BeginChildren(); i!=parent->EndChildren(); ++i) + { + if ((*i)->NumChildren() > 1) + { + TEveElement::List_i xx = (*i)->BeginChildren(); ++xx; + TEveBoxSet* boxset = dynamic_cast(*xx); + ++xx; + TEveStraightLineSet* lineset = dynamic_cast(*xx); + TEveChunkManager::iterator li(lineset->GetLinePlex()); + li.next(); + + + TEveChunkManager* plex = boxset->GetPlex(); + if (plex->N()) + { + for (int atomIdx=0; atomIdx < plex->Size(); ++atomIdx) + { + + TEveBoxSet::BFreeBox_t* atom = (TEveBoxSet::BFreeBox_t*)boxset->GetPlex()->Atom(atomIdx); + reco::PFRecHit* hit = (reco::PFRecHit*)boxset->GetUserData(atomIdx); + const float* corners = item()->getGeom()->getCorners(hit->detId()); + viewContextBoxScale(corners, hit->energy()*scale, vc->getEnergyScale()->getPlotEt(), scaledCorners, hit); + memcpy(atom->fVertices, &scaledCorners[0], sizeof(atom->fVertices)); + + editBoxInLineSet(li, &scaledCorners[0]); + } + + for (TEveProjectable::ProjList_i p = lineset->BeginProjecteds(); p != lineset->EndProjecteds(); ++p) + { + TEveStraightLineSetProjected* projLineSet = (TEveStraightLineSetProjected*)(*p); + projLineSet->UpdateProjection(); + } + } + } + } +} +//______________________________________________________________________________ +namespace { +TString boxset_tooltip_callback(TEveDigitSet* ds, Int_t idx) +{ + void* ud = ds->GetUserData(idx); + if (ud); + { + reco::PFRecHit* hit = (reco::PFRecHit*) ud; + // printf("idx %d %p hit data %p\n", idx, (void*)hit, ud); + if (hit) + return TString::Format("RecHit %d energy '%f'", idx, hit->energy()); + else + return "ERROR"; + } +} +} +//______________________________________________________________________________ +void FWPFCandidateWithHitsProxyBuilder::addHitsForCandidate(const reco::PFCandidate& cand, TEveElement* holder, const FWViewContext* vc) +{ + reco::PFCandidate::ElementsInBlocks eleInBlocks = cand.elementsInBlocks(); + + TEveBoxSet* boxset = 0; + TEveStraightLineSet* lineset = 0; + + for(unsigned elIdx=0; elIdx myBlock(blockRef.id(),blockRef.get(), blockRef.key()); + /* + if (myBlock->elements()[indexInBlock].type() == 1) + ieTrack = indexInBlock; + if (myBlock->elements()[indexInBlock].type() == 4) + ieECAL = indexInBlock; + */ + if (myBlock->elements()[indexInBlock].type() == 5) + ieHCAL = indexInBlock; + + + std::vector scaledCorners(24); + float scale = vc->getEnergyScale()->getScaleFactor3D()/50; + if (ieHCAL && m_collectionHCAL) { + reco::PFClusterRef hcalclusterRef=myBlock->elements()[ieHCAL].clusterRef(); + edm::Ptr myCluster(hcalclusterRef.id(),hcalclusterRef.get(), hcalclusterRef.key()); + if (myCluster.get()) + { + const std::vector< std::pair > & hitsandfracs = myCluster->hitsAndFractions(); + + if (!boxset) + { + boxset = new TEveBoxSet(); + boxset->Reset(TEveBoxSet::kBT_FreeBox, true, hitsandfracs.size()); + boxset->SetAntiFlick(true); + boxset->SetAlwaysSecSelect(1); + boxset->SetPickable(1); + boxset->SetTooltipCBFoo(boxset_tooltip_callback); + } + + if (!lineset) + { + lineset = new TEveStraightLineSet(); + } + + bool hitsFound = false; + for ( int ihandf=0, lastIdx=(int)(hitsandfracs.size()); ihandfgetCorners(hitDetId); + const reco::PFRecHit* hit = getHitForDetId(hitDetId); + if (hit) + { + viewContextBoxScale( corners, hit->energy()*scale, vc->getEnergyScale()->getPlotEt(), scaledCorners, hit); + boxset->AddBox( &scaledCorners[0]); + // setup last box + boxset->DigitColor(holder->GetMainColor()); + boxset->DigitUserData((void*)hit); + addBoxAsLines(lineset, &scaledCorners[0]); + hitsFound = true; + } + /* + // AMT: don't add lines if hit is not found becuse of unconsistency of scaling. + else + { + addBoxAsLines(lineset, corners); + } + */ + } + if (!hitsFound) + fwLog(fwlog::kWarning) << Form("Can't find matching hits with for HCAL block %d in RecHit collection. Number of hits %d.\n", elIdx, (int)hitsandfracs.size()); + + + } + else + { + fwLog(fwlog::kInfo) << "empty cluster \n"; + } + } + } // endloop cand.elementsInBlocks(); + + + if (boxset) { + boxset->RefitPlex(); + setupAddElement(boxset, holder); + } + + if (lineset) { + setupAddElement(lineset, holder); + } +} + +REGISTER_FWPROXYBUILDER(FWPFCandidateWithHitsProxyBuilder, reco::PFCandidateCollection,"PF CandidatesWithHits", FWViewType::kAll3DBits | FWViewType::kAllRPZBits ); diff --git a/Fireworks/ParticleFlow/plugins/FWPFCandidateWithHitsProxyBuilder.h b/Fireworks/ParticleFlow/plugins/FWPFCandidateWithHitsProxyBuilder.h new file mode 100644 index 0000000000000..5933614a711cc --- /dev/null +++ b/Fireworks/ParticleFlow/plugins/FWPFCandidateWithHitsProxyBuilder.h @@ -0,0 +1,39 @@ +#include "Fireworks/Core/interface/FWProxyBuilderBase.h" +//#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" +#include "DataFormats/ParticleFlowReco/interface/PFRecHit.h" +#include "DataFormats/ParticleFlowReco/interface/PFRecHitFwd.h" +namespace reco +{ +class PFCandidate; +class PFRecHit; +} +class CaloRecHit; + +class FWPFCandidateWithHitsProxyBuilder : public FWProxyBuilderBase +{ +public: + FWPFCandidateWithHitsProxyBuilder() {} + virtual ~FWPFCandidateWithHitsProxyBuilder(){} + + virtual void build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*); + + virtual bool havePerViewProduct(FWViewType::EType) const { return true; } + + virtual void scaleProduct(TEveElementList* parent, FWViewType::EType type, const FWViewContext* vc); + + virtual void setItem(const FWEventItem* iItem); + + REGISTER_PROXYBUILDER_METHODS(); + +private: + FWPFCandidateWithHitsProxyBuilder( const FWPFCandidateWithHitsProxyBuilder& ); // Stop default + const FWPFCandidateWithHitsProxyBuilder& operator=( const FWPFCandidateWithHitsProxyBuilder& ); // Stop default + + void addHitsForCandidate(const reco::PFCandidate& c, TEveElement* holder, const FWViewContext* vc); + void initPFRecHitsCollections(); + const reco::PFRecHit* getHitForDetId(unsigned detId); + void viewContextBoxScale( const float* corners, float scale, bool plotEt, std::vector& scaledCorners, const reco::PFRecHit*); + + const reco::PFRecHitCollection *m_collectionHCAL; + +};