Go to the documentation of this file.00001 #include "Fireworks/Calo/plugins/FWCaloRecHitDigitSetProxyBuilder.h"
00002 #include "TEveBoxSet.h"
00003 #include "FWCaloRecHitDigitSetProxyBuilder.h"
00004 #include "Fireworks/Core/interface/FWDigitSetProxyBuilder.h"
00005 #include "Fireworks/Core/interface/FWEventItem.h"
00006 #include "Fireworks/Core/interface/FWGeometry.h"
00007 #include "Fireworks/Core/interface/BuilderUtils.h"
00008 #include "Fireworks/Core/interface/FWViewEnergyScale.h"
00009 #include "DataFormats/CaloRecHit/interface/CaloRecHit.h"
00010
00011 #include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h"
00012
00013 FWCaloRecHitDigitSetProxyBuilder::FWCaloRecHitDigitSetProxyBuilder()
00014 : m_invertBox(false), m_ignoreGeoShapeSize(false)
00015 {}
00016
00017
00018
00019 void FWCaloRecHitDigitSetProxyBuilder::setItem(const FWEventItem* iItem)
00020 {
00021 FWProxyBuilderBase::setItem(iItem);
00022
00023 }
00024
00025
00026 void FWCaloRecHitDigitSetProxyBuilder::viewContextBoxScale( const float* corners, float scale, bool plotEt, std::vector<float>& scaledCorners, const CaloRecHit*)
00027 {
00028 if ( m_ignoreGeoShapeSize)
00029 {
00030
00031
00032 for( int i = 0; i < 24; ++i )
00033 scaledCorners[i] = corners[i];
00034
00035
00036 if( m_invertBox )
00037 {
00038
00039
00040 for( unsigned int i = 0; i < 12; i += 3 )
00041 {
00042 m_vector.Set( corners[i] - corners[i + 12], corners[i + 1] - corners[i + 13], corners[i + 2] - corners[i + 14] );
00043 m_vector.Normalize();
00044 m_vector *= scale;
00045
00046 scaledCorners[i] = corners[i] + m_vector.fX;
00047 scaledCorners[i + 1] = corners[i + 1] + m_vector.fY;
00048 scaledCorners[i + 2] = corners[i + 2] + m_vector.fZ;
00049 }
00050 }
00051 else
00052 {
00053 for( unsigned int i = 0; i < 12; i += 3 )
00054 {
00055 m_vector.Set( corners[i + 12] - corners[i], corners[i + 13] - corners[i + 1], corners[i + 14] - corners[i + 2] );
00056 m_vector.Normalize();
00057 m_vector *= scale;
00058
00059 scaledCorners[i] = corners[i + 12];
00060 scaledCorners[i + 1] = corners[i + 13];
00061 scaledCorners[i + 2] = corners[i + 14];
00062
00063 scaledCorners[i + 12] = corners[i + 12] + m_vector.fX;
00064 scaledCorners[i + 13] = corners[i + 13] + m_vector.fY;
00065 scaledCorners[i + 14] = corners[i + 14] + m_vector.fZ;
00066 }
00067 }
00068 }
00069 else {
00070
00071
00072
00073 m_vector.Set(0.f, 0.f, 0.f);
00074 for( unsigned int i = 0; i < 24; i += 3 )
00075 {
00076 m_vector[0] += corners[i];
00077 m_vector[1] += corners[i + 1];
00078 m_vector[2] += corners[i + 2];
00079 }
00080 m_vector *= 1.f/8.f;
00081
00082 if (plotEt)
00083 {
00084 scale *= m_vector.Perp()/m_vector.Mag();
00085 }
00086
00087
00088 for( unsigned int i = 0; i < 24; i += 3 )
00089 {
00090 scaledCorners[i] = m_vector[0] + ( corners[i] - m_vector[0] ) * scale;
00091 scaledCorners[i + 1] = m_vector[1] + ( corners[i + 1] - m_vector[1] ) * scale;
00092 scaledCorners[i + 2] = m_vector[2] + ( corners[i + 2] - m_vector[2] ) * scale;
00093 }
00094
00095 if( m_invertBox )
00096 fireworks::invertBox( scaledCorners );
00097 }
00098 }
00099
00100
00101 float FWCaloRecHitDigitSetProxyBuilder::scaleFactor(const FWViewContext* vc)
00102 {
00103
00104 return vc->getEnergyScale()->getScaleFactor3D()/50;
00105 }
00106
00107
00108
00109 void
00110 FWCaloRecHitDigitSetProxyBuilder::scaleProduct(TEveElementList* parent, FWViewType::EType type, const FWViewContext* vc)
00111 {
00112 size_t size = item()->size();
00113 if (!size) return;
00114
00115
00116 std::vector<float> scaledCorners(24);
00117 float scale = scaleFactor(vc);
00118
00119 assert(parent->NumChildren() == 1);
00120 TEveBoxSet* boxSet = static_cast<TEveBoxSet*>(*parent->BeginChildren());
00121
00122 for (int index = 0; index < static_cast<int>(size); ++index)
00123 {
00124 const CaloRecHit* hit = (const CaloRecHit*)item()->modelData(index);
00125 const float* corners = item()->getGeom()->getCorners(hit->detid());
00126 if (corners == 0) continue;
00127
00128 FWDigitSetProxyBuilder::BFreeBox_t* b = (FWDigitSetProxyBuilder::BFreeBox_t*)boxSet->GetPlex()->Atom(index);
00129
00130 viewContextBoxScale(corners, hit->energy()*scale, vc->getEnergyScale()->getPlotEt(), scaledCorners, hit);
00131 memcpy(b->fVertices, &scaledCorners[0], sizeof(b->fVertices));
00132 }
00133 boxSet->ElementChanged();
00134 }
00135
00136
00137 void
00138 FWCaloRecHitDigitSetProxyBuilder::build( const FWEventItem* iItem, TEveElementList* product, const FWViewContext* vc)
00139 {
00140 size_t size = iItem->size();
00141 if (!size) return;
00142
00143
00144
00145 std::vector<float> scaledCorners(24);
00146
00147 float scale = scaleFactor(vc);
00148
00149 TEveBoxSet* boxSet = addBoxSetToProduct(product);
00150 boxSet->SetAntiFlick(kTRUE);
00151 for (int index = 0; index < static_cast<int>(size); ++index)
00152 {
00153 const CaloRecHit* hit = (const CaloRecHit*)item()->modelData(index);
00154
00155 const float* corners = context().getGeom()->getCorners(hit->detid());
00156 if (corners)
00157 {
00158 m_vector.Set(0.f, 0.f, 0.f);
00159 for( unsigned int i = 0; i < 24; i += 3 )
00160 {
00161 m_vector[0] += corners[i];
00162 m_vector[1] += corners[i + 1];
00163 m_vector[2] += corners[i + 2];
00164 }
00165 m_vector.Normalize();
00166 context().voteMaxEtAndEnergy( m_vector.Perp() *hit->energy(), hit->energy());
00167 viewContextBoxScale( corners, hit->energy()*scale, vc->getEnergyScale()->getPlotEt(), scaledCorners, hit);
00168 }
00169
00170 addBox(boxSet, &scaledCorners[0], iItem->modelInfo(index).displayProperties());
00171 }
00172 }
00173
00174