00001
00002
00003 #include "VisReco/VisHcal/interface/VisHcalDetTwig.h"
00004 #include "Iguana/Framework/interface/IgRepSet.h"
00005 #include "Iguana/Models/interface/IgTextRep.h"
00006 #include "Iguana/GLModels/interface/IgLegoRep.h"
00007 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00008 #include "Iguana/GLModels/interface/IgRZRep.h"
00009 #include "Iguana/GLBrowsers/interface/Ig3DShapeManager.h"
00010 #include "Iguana/Studio/interface/IgQtLock.h"
00011 #include <Inventor/nodes/SoIndexedLineSet.h>
00012 #include <Inventor/nodes/SoSeparator.h>
00013 #include <Inventor/nodes/SoText2.h>
00014 #include <Inventor/nodes/SoTranslation.h>
00015 #include <Inventor/SoInput.h>
00016 #include <qfileinfo.h>
00017 #include <qmessagebox.h>
00018 #include <sstream>
00019 #include <iostream>
00020 #include <iomanip>
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 VisHcalDetTwig::VisHcalDetTwig (IgState *state, IgTwig *parent)
00033 : VisQueuedTwig (state, parent, "HCAL Detector"),
00034 m_scale (state, lat::CreateCallback (this, &VisHcalDetTwig::scaleChanged))
00035 {
00036 Ig3DShapeManager *shapeManager = Ig3DShapeManager::get (state);
00037 ASSERT (shapeManager);
00038
00039 m_det = shapeManager->lookup ("hcalbarrel.iv");
00040 m_legoDet = buildLegoDet ();
00041 m_legoDet->ref ();
00042 }
00043
00044 void
00045 VisHcalDetTwig::scaleChanged (void)
00046 {
00047 IgRepSet::invalidate (this, SELF_MASK);
00048 }
00049
00050 SoNode*
00051 VisHcalDetTwig::buildLegoDet (void)
00052 {
00053 SoSeparator *gridSep = new SoSeparator;
00054
00055
00056 float etaHFBins [43] = { 0, 0.087, 0.174, 0.261, 0.348, 0.435, 0.522, 0.609,
00057 0.696, 0.783, 0.87, 0.957, 1.044, 1.131, 1.218, 1.305,
00058 1.392, 1.479, 1.566, 1.653, 1.74, 1.83, 1.93, 2.043,
00059 2.172, 2.322, 2.5, 2.65, 3,
00060 2.853, 2.964, 3.139, 3.314,
00061 3.486, 3.664, 3.839, 4.013,
00062 4.191, 4.363, 4.538, 4.716,
00063 4.889, 5.191};
00064
00065 SoVertexProperty *vtx = new SoVertexProperty;
00066 SoIndexedLineSet *grid = new SoIndexedLineSet;
00067 SoMFInt32 coords;
00068 int vertex = 6;
00069 int coord = 0;
00070 int tick = 0;
00071
00072 float x = float (2 * M_PI);
00073 float z = 5.191;
00074
00075 vtx->vertex.set1Value (0, SbVec3f (0, 0, -z));
00076 vtx->vertex.set1Value (1, SbVec3f (0, 0, z));
00077 vtx->vertex.set1Value (2, SbVec3f (x, 0, z));
00078 vtx->vertex.set1Value (3, SbVec3f (x, 0, -z));
00079 vtx->vertex.set1Value (4, SbVec3f (0, 0, -z));
00080 vtx->vertex.set1Value (5, SbVec3f (0, 1, -z));
00081
00082 for (coord = 0; coord < vertex; coord++)
00083 coords.set1Value (coord, coord);
00084 coords.set1Value (coord++, SO_END_LINE_INDEX);
00085
00086 for (tick = 0; tick < 43; tick++)
00087 {
00088 vtx->vertex.set1Value (vertex, SbVec3f (0, 0, etaHFBins [tick]));
00089 coords.set1Value (coord++, vertex++);
00090 vtx->vertex.set1Value (vertex, SbVec3f (x, 0, etaHFBins [tick]));
00091 coords.set1Value (coord++, vertex++);
00092 coords.set1Value (coord++, SO_END_LINE_INDEX);
00093
00094 vtx->vertex.set1Value (vertex, SbVec3f (0, 0, -etaHFBins [tick]));
00095 coords.set1Value (coord++, vertex++);
00096 vtx->vertex.set1Value (vertex, SbVec3f (x, 0, -etaHFBins [tick]));
00097 coords.set1Value (coord++, vertex++);
00098 coords.set1Value (coord++, SO_END_LINE_INDEX);
00099 }
00100
00101 int ticks = 36;
00102 x = 0;
00103
00104 for (tick = 0; tick < ticks; tick++)
00105 {
00106 x = tick * M_PI / 18.0;
00107 vtx->vertex.set1Value (vertex, SbVec3f (x, 0, -z));
00108 coords.set1Value (coord++, vertex++);
00109 vtx->vertex.set1Value (vertex, SbVec3f (x, 0, z));
00110 coords.set1Value (coord++, vertex++);
00111 coords.set1Value (coord++, SO_END_LINE_INDEX);
00112
00113 for (int ttow = 1; ttow < 2; ttow++)
00114 {
00115 vtx->vertex.set1Value (vertex, SbVec3f (x + ttow * 0.087, 0, -1.74));
00116 coords.set1Value (coord++, vertex++);
00117 vtx->vertex.set1Value (vertex, SbVec3f (x + ttow * 0.087, 0, 1.74));
00118 coords.set1Value (coord++, vertex++);
00119 coords.set1Value (coord++, SO_END_LINE_INDEX);
00120 }
00121 }
00122
00123 grid->vertexProperty = vtx;
00124 grid->coordIndex = coords;
00125
00126 gridSep->addChild (grid);
00127
00128 SoSeparator *phiLabels = new SoSeparator;
00129 SoText2 *text;
00130 SoText2 *phiLabelText [8];
00131 SoTranslation *phiStart = new SoTranslation;
00132 SoTranslation *phiTranslation = new SoTranslation;
00133
00134 z = 5.191;
00135
00136 phiStart->translation = SbVec3f (M_PI / 4, 0, -z - 0.6);
00137 phiTranslation->translation = SbVec3f (M_PI / 4, 0, 0);
00138 phiLabels->addChild (phiStart);
00139
00140 for (tick = 0; tick < 8; tick ++)
00141 {
00142 text = phiLabelText [tick] = new SoText2;
00143 phiLabels->addChild (text);
00144 phiLabels->addChild (phiTranslation);
00145 }
00146
00147 phiLabelText [0]->string = "PI/4";
00148 phiLabelText [1]->string = "PI/2";
00149 phiLabelText [2]->string = "3PI/4";
00150 phiLabelText [3]->string = "PI";
00151 phiLabelText [4]->string = "5PI/4";
00152 phiLabelText [5]->string = "3PI/2";
00153 phiLabelText [6]->string = "7PI/4";
00154 phiLabelText [7]->string = "2PI";
00155
00156 gridSep->addChild (phiLabels);
00157
00158 z = -5.191;
00159
00160
00161 SoSeparator *labelScale = new SoSeparator;
00162 SoText2 *labelScaleText = new SoText2;
00163 SoTranslation *labelScaleOffset = new SoTranslation;
00164
00165 char scaleChars [12] = "1.0 GeV";
00166 sprintf (scaleChars, "%.2G GeV", m_scale.value ());
00167 labelScaleText->string = scaleChars;
00168 labelScaleOffset->translation
00169 = SbVec3f (-0.6, 1, z - 0.6);
00170 labelScale->addChild (labelScaleOffset);
00171 labelScale->addChild (labelScaleText);
00172 gridSep->addChild (labelScale);
00173
00174 SoSeparator *etaLabels = new SoSeparator;
00175 SoTranslation *etaStart = new SoTranslation;
00176 SoTranslation *etaTranslation = new SoTranslation;
00177
00178 etaStart->translation = SbVec3f (-0.6, 0, -5.0);
00179 etaTranslation->translation = SbVec3f (0, 0, 1);
00180 etaLabels->addChild (etaStart);
00181
00182 for (tick = 0; tick < 11; tick++, z++)
00183 {
00184 text = new SoText2;
00185 char textLabel [5];
00186 sprintf (textLabel, "%.0f", z);
00187 text->string = textLabel;
00188 etaLabels->addChild (text);
00189 etaLabels->addChild (etaTranslation);
00190 }
00191 gridSep->addChild (etaLabels);
00192
00193 return gridSep;
00194 }
00195
00196 void
00197 VisHcalDetTwig::update (IgTextRep *rep)
00198 {
00199
00200 VisQueuedTwig::update (rep);
00201
00202
00203 std::ostringstream text;
00204
00205 text << "<table width='100%'><tr><td>HCAL detector</td><td>";
00206
00207 text << "</td></tr></table>";
00208
00209
00210 IgQtLock ();
00211
00212 rep->setText (text.str ());
00213 }
00214
00215 void
00216 VisHcalDetTwig::update (IgLegoRep *rep)
00217 {
00218
00219 VisQueuedTwig::update (rep);
00220
00221 IgQtLock ();
00222
00223 rep->clear ();
00224 m_legoDet = buildLegoDet ();
00225 rep->node ()->addChild (m_legoDet);
00226 }
00227
00228 void
00229 VisHcalDetTwig::update (IgRPhiRep *rep)
00230 {
00231
00232 VisQueuedTwig::update (rep);
00233
00234 IgQtLock ();
00235
00236 rep->clear ();
00237 rep->node ()->addChild (m_det);
00238 }
00239
00240 void
00241 VisHcalDetTwig::update (IgRZRep *rep)
00242 {
00243
00244 VisQueuedTwig::update (rep);
00245
00246 IgQtLock ();
00247
00248 rep->clear ();
00249 rep->node ()->addChild (m_det);
00250 }