CMS 3D CMS Logo

IgSoRZHist Class Reference

#include <Iguana/Inventor/interface/IgSoRZHist.h>

Inheritance diagram for IgSoRZHist:

IgSoShapeKit

List of all members.

Public Member Functions

 IgSoRZHist (void)

Static Public Member Functions

static void initClass (void)

Public Attributes

SoSFFloat deltaEta
SoMFFloat energies
SoSFFloat layer
SoSFBool logScale
SoSFFloat maxRadius
SoSFFloat minRadius
SoSFFloat scaleFactor
SoSFBool showAnnotations
SoSFBool upper

Protected Member Functions

virtual void refresh (void)

Private Member Functions

 SO_KIT_CATALOG_ENTRY_HEADER (ruler)
 SO_KIT_CATALOG_ENTRY_HEADER (lines)
 SO_KIT_CATALOG_ENTRY_HEADER (faceSet)
 SO_KIT_CATALOG_ENTRY_HEADER (shapeHints)
 SO_KIT_HEADER (IgSoRZHist)


Detailed Description

Definition at line 20 of file IgSoRZHist.h.


Constructor & Destructor Documentation

IgSoRZHist::IgSoRZHist ( void   ) 

Definition at line 179 of file IgSoRZHist.cc.

References deltaEta, energies, FALSE, layer, logScale, maxRadius, minRadius, scaleFactor, IgSoShapeKit::setUpConnections(), showAnnotations, TRUE, and upper.

00180 {
00181     SO_KIT_CONSTRUCTOR (IgSoRZHist);
00182     // parameters of the constructor
00183     SO_KIT_ADD_FIELD (minRadius,                (1.806));
00184     SO_KIT_ADD_FIELD (maxRadius,                (2.864));
00185     SO_KIT_ADD_FIELD (upper,                    (true));
00186     SO_KIT_ADD_FIELD (energies,                 (0.0));
00187     SO_KIT_ADD_FIELD (logScale,                 (false));
00188     SO_KIT_ADD_FIELD (layer,                    (0.0));
00189     SO_KIT_ADD_FIELD (scaleFactor,              (0.1));
00190     SO_KIT_ADD_FIELD (showAnnotations,          (false));
00191     SO_KIT_ADD_FIELD (deltaEta,                 (0.087));
00192     SO_KIT_ADD_CATALOG_ENTRY (shapeHints, SoShapeHints, FALSE, separator,\x0, TRUE);
00193     SO_KIT_ADD_CATALOG_ENTRY (faceSet, SoIndexedFaceSet, FALSE, separator,\x0, TRUE);
00194     SO_KIT_ADD_CATALOG_ENTRY (lines, SoIndexedLineSet, FALSE, separator,\x0, TRUE);
00195     SO_KIT_ADD_CATALOG_ENTRY (ruler, SoSeparator, FALSE, separator,\x0, TRUE);
00196 
00197     SO_KIT_INIT_INSTANCE ();
00198     setUpConnections (true, true);
00199 }


Member Function Documentation

void IgSoRZHist::initClass ( void   )  [static]

Reimplemented from IgSoShapeKit.

Definition at line 176 of file IgSoRZHist.cc.

Referenced by initNodes(), and initShapes().

00177 { SO_KIT_INIT_CLASS (IgSoRZHist, IgSoShapeKit, "IgSoShapeKit"); }

void IgSoRZHist::refresh ( void   )  [protected, virtual]

Reimplemented from IgSoShapeKit.

Definition at line 202 of file IgSoRZHist.cc.

References convertCoordinates(), deltaEta, energies, relval_parameters_module::energy, generateLowerVertexData(), generateUpperVertexData(), i, int, label, layer, funct::log(), logScale, maxRadius, minRadius, NULL, offset, scaleFactor, showAnnotations, upper, and w.

00203 {
00204     int         nbrOfBins  = energies.getNum ();
00205     if (nbrOfBins == 0)
00206     {
00207         setPart ("shapeHints", NULL);
00208         setPart ("faceSet",    NULL);
00209         setPart ("lines",      NULL);
00210         setPart ("ruler",      NULL);
00211         return;
00212     }
00213 
00214     float       maxEn      = 0.0;
00215     int         maxEnIndex = -1;
00216     for (int i = 0; i < nbrOfBins; i++)
00217     {
00218         if (energies [i] > maxEn)
00219         {
00220             maxEn = energies [i];
00221             maxEnIndex = i;
00222         }
00223     }
00224     
00225     SoIndexedFaceSet*   faceSet         = new SoIndexedFaceSet;
00226     SoIndexedLineSet*   lineSet         = new SoIndexedLineSet;
00227     SoShapeHints*       shapeHints      = new SoShapeHints;
00228     SoVertexProperty*   vtx             = new SoVertexProperty;
00229     
00230     float               rMin            = minRadius.getValue ();
00231     float               rMax            = maxRadius.getValue ();
00232     float               zLayer          = layer.getValue ();
00233     float               factor          = scaleFactor.getValue ();
00234     bool                logarithmic     = logScale.getValue ();
00235     bool                up              = upper.getValue ();
00236     float               dEta            = deltaEta.getValue ();
00237    
00238     shapeHints->faceType = SoShapeHints::CONVEX;
00239 
00240     // prepare space for  a local copy of the energy vector
00241     std::vector <float> energy (nbrOfBins);
00242     
00243     // for logscale  apply  log to contents of the energy vector
00244     if (logarithmic)
00245     {
00246         for (int i = 0; i < nbrOfBins; i++)
00247         {
00248             energy [i] = factor  * log (energies [i] + 1.0);
00249         }
00250     }
00251     else
00252     {
00253         for (int i = 0; i < nbrOfBins; i++)
00254         {
00255             energy [i] = energies[i];
00256         }
00257     }
00258     
00259     /* building  vector containing the vertices for the faces of the shape*/
00260     std::vector<SbVec3f> vertexData (3 * nbrOfBins + 1);
00261 
00262     if (up)
00263     {
00264         vertexData = generateUpperVertexData (energy, rMin, rMax, dEta, zLayer, maxEn, logarithmic, factor);
00265         shapeHints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
00266     }
00267     else
00268     {
00269         vertexData = generateLowerVertexData (energy, rMin, rMax, dEta, zLayer, maxEn, logarithmic, factor);
00270         shapeHints->vertexOrdering = SoShapeHints::CLOCKWISE;
00271     }
00272     
00273     /* building  vector indicating the vertices belonging to each face, however care for faces with energy = 0 , do not draw these*/
00274     int nbrOfDrawnFaces = 0;
00275     std::vector<int> faceIndices (nbrOfBins * 5);
00276     
00277     if (! (energy [0] == 0))
00278     {
00279         faceIndices [0] = 0;
00280         faceIndices [1] = 1;
00281         faceIndices [2] = 2;
00282         faceIndices [3] = 3;
00283         faceIndices [4] = SO_END_FACE_INDEX;
00284         nbrOfDrawnFaces++;
00285     }
00286     
00287     for (int i = 1; i < nbrOfBins; i++)
00288     {
00289         if (! (energy [i] == 0))
00290         {
00291             faceIndices [nbrOfDrawnFaces * 5] = (i - 1) * 3 + 1;
00292             faceIndices [nbrOfDrawnFaces * 5 + 1] = (i - 1) * 3 + 4;
00293             faceIndices [nbrOfDrawnFaces * 5 + 2] = (i - 1) * 3 + 5;
00294             faceIndices [nbrOfDrawnFaces * 5 + 3] = (i - 1) * 3 + 6;
00295             faceIndices [nbrOfDrawnFaces * 5 + 4] = SO_END_FACE_INDEX;
00296             nbrOfDrawnFaces++;
00297         }
00298     }
00299     
00300     vtx->vertex.setValues (0, nbrOfBins * 3 + 1 , &vertexData [0]);
00301     vtx->materialBinding = SoMaterialBinding::PER_FACE_INDEXED;
00302     
00303     faceSet->coordIndex.setValues (0, nbrOfDrawnFaces * 5, &faceIndices [0]);
00304     faceSet->vertexProperty = vtx;
00305 
00306     // building  vector indication the vertices belonging to each line
00307     std::vector<int>  lineIndices (2 * nbrOfBins + 1 + 1);
00308 
00309     for (int i = 0; i < nbrOfBins; i++)
00310     {
00311         lineIndices [2 * i] = 3 * i + 3;
00312         lineIndices [2 * i + 1] = 3 * i + 2;
00313     }
00314 
00315     lineIndices [2 * nbrOfBins] = 3 * nbrOfBins - 2;
00316     lineIndices [2 * nbrOfBins + 1] = 0;
00317     
00318     SoVertexProperty* lineVtx = new SoVertexProperty;
00319     lineVtx->vertex.setValues (0, nbrOfBins * 3 + 1, &vertexData [0]);
00320     
00321     lineSet->coordIndex.setValues (0, 2 * nbrOfBins + 2, &lineIndices [0]);
00322     lineSet->vertexProperty = lineVtx;
00323 
00324     // building the scene graph for the histogram faces and outline
00325     if (nbrOfDrawnFaces)
00326     {
00327         setPart ("shapeHints", shapeHints);
00328         setPart ("faceSet", faceSet);
00329         setPart ("lines", lineSet);
00330     }
00331 
00335 
00336     // if there is at least one bin with energy > 0 and  annotations are requested
00337     if (nbrOfDrawnFaces && showAnnotations.getValue ())
00338     {
00339         float offset;
00340         int nbrOfDivisions;
00341         float divisionLength;
00342         float  rulerAngle = (dEta * nbrOfBins / 2 - dEta * (maxEnIndex + 0.5));
00343         float  rulerHeight;
00344 
00345         if (up)
00346         {
00347             rulerAngle = -rulerAngle;
00348         }
00349         
00350         // find the appropriate length for the ruler
00351         if (! logarithmic)
00352         {
00353             // if unconstrained linear scale is used, the length is proportional to the maximum found energy sum otherwise to (rMax - rMin)
00354             rulerHeight = (rMax == -1 ) ? factor * maxEn : rulerHeight = rMax - rMin;
00355             if (! up)
00356             {
00357                 rulerHeight = -rulerHeight;
00358             }
00359         }
00360         else
00361         {
00362             if ((rMax > rMin) || (rMax == -1))
00363             {
00364                 rulerHeight = (up) ? factor * log (maxEn + 1.0) : -factor * log (maxEn + 1.0);
00365             }
00366             else
00367             {
00368                 rulerHeight = (up) ? -factor * log (maxEn + 1.0) : factor * log (maxEn + 1.0);
00369             }
00370         }
00371 
00372         // if the axis is not too small, prepare drawing
00373         if ((rulerHeight > 0.1)|| (rulerHeight < -0.1))
00374         {
00375             // ingredients for the ruler
00376             SoSeparator* ruler = new  SoSeparator;
00377             SoMaterial* axisMaterial = new SoMaterial;
00378 
00379             // define the material for the axis
00380             axisMaterial->diffuseColor.setValue (0.0, 0.0, 0.0); // orange
00381             
00382             // the offset has to be computed in order to compute the correct division length
00383             offset = (rulerHeight >= 0.0) ? (rulerHeight * (1.0 -  floor (0.1 * maxEn) / (maxEn * 0.1))) : (-rulerHeight * (1.0 -  floor (0.1 * maxEn) / (maxEn * 0.1)));
00384             
00385             //determin number of division markers and length of a single division
00386             if (! logarithmic)
00387             {
00388                 nbrOfDivisions = (int) floor (maxEn * 0.1);// factor removed
00389                 if (nbrOfDivisions == 0)
00390                 {
00391                     nbrOfDivisions = 1;
00392                     divisionLength = rulerHeight;
00393                 }
00394                 else
00395                 {
00396                     divisionLength = (rulerHeight - offset) / nbrOfDivisions;
00397                     if (! (offset == 0) && (offset > 0.1 * rulerHeight * rulerHeight))
00398                     {
00399                         nbrOfDivisions += 1;
00400                     }
00401                 }
00402             }
00403             //our axis is not able to display logarithmic scale, so in logScale case we do not draw division markers
00404             else
00405             {
00406                 nbrOfDivisions = 1;
00407                 divisionLength = rulerHeight;
00408             }
00409             
00410             if ((divisionLength * divisionLength) < 0.01)
00411             {
00412                 nbrOfDivisions = 1;
00413                 divisionLength = rulerHeight;
00414             }
00415             
00416             float zDist = -0.05;
00417             float w = dEta;
00418 
00419             std::vector<SbVec3f>  rulerVtx (7 + 4 * nbrOfDivisions );
00420             float rMinSigned = (up) ? rMin : -rMin;
00421             rulerVtx [0] = convertCoordinates (SbVec3f (rMinSigned,                            rulerAngle - w /  8.0, zLayer + zDist));
00422             rulerVtx [1] = convertCoordinates (SbVec3f (rMinSigned + 9.0 / 10.0 * rulerHeight, rulerAngle - w / 16.0, zLayer + zDist));
00423             rulerVtx [2] = convertCoordinates (SbVec3f (rMinSigned + 9.0 / 10.0 * rulerHeight, rulerAngle + w / 16.0, zLayer + zDist));
00424             rulerVtx [3] = convertCoordinates (SbVec3f (rMinSigned,                            rulerAngle + w /  8.0, zLayer + zDist));
00425             rulerVtx [4] = convertCoordinates (SbVec3f (rMinSigned + 9.0 / 10.0 * rulerHeight, rulerAngle - w /  8.0, zLayer + zDist));
00426             rulerVtx [5] = convertCoordinates (SbVec3f (rMinSigned + rulerHeight,              rulerAngle,            zLayer + zDist));
00427             rulerVtx [6] = convertCoordinates (SbVec3f (rMinSigned + 9.0 / 10.0 * rulerHeight, rulerAngle + w /  8.0, zLayer + zDist));
00428             
00429             for (int i = 1; i < nbrOfDivisions; i++)
00430             {
00431                 rulerVtx [3 + i * 4]     = convertCoordinates (SbVec3f (rMinSigned + divisionLength * i - 0.001, rulerAngle - w / 3.0, zLayer + zDist));
00432                 rulerVtx [3 + i * 4 + 1] = convertCoordinates (SbVec3f (rMinSigned + divisionLength * i + 0.001, rulerAngle - w / 3.0, zLayer + zDist));
00433                 rulerVtx [3 + i * 4 + 2] = convertCoordinates (SbVec3f (rMinSigned + divisionLength * i + 0.001, rulerAngle + w / 3.0, zLayer + zDist));
00434                 rulerVtx [3 + i * 4 + 3] = convertCoordinates (SbVec3f (rMinSigned + divisionLength * i - 0.001, rulerAngle + w / 3.0, zLayer + zDist));
00435             }
00436             
00437             SoCoordinate3* rulerCoords = new SoCoordinate3;
00438             rulerCoords->point.setValues (0, 7 + 4 * (nbrOfDivisions - 1) , &rulerVtx [0]);
00439             
00440             std::vector <int>  numVtx (1 + nbrOfDivisions);
00441             numVtx [0] = 4;
00442             numVtx [1] = 3;
00443             for (int i = 0; i < (nbrOfDivisions - 1); i++)
00444             {
00445                 numVtx [2 + i] = 4;
00446             }
00447             
00448             SoFaceSet* rulerFaceSet = new SoFaceSet;
00449             rulerFaceSet->numVertices.setValues (0, 2 + nbrOfDivisions - 1 , &numVtx [0]);
00450 
00451             // finally label the axis with appropriate unit
00452             char label [50];
00453             if (maxEn >= 100.0)
00454             {
00455                 sprintf (label, "Emax = %.1f TeV ", maxEn / 1000.0);
00456             }
00457             else
00458             {
00459                 sprintf (label, "Emax = %.1f GeV ", maxEn);
00460             }
00461 
00462             SoText2* labelText = new SoText2;
00463             labelText->string = label;
00464             labelText->justification = SoText2::CENTER;
00465             
00466             SoFont* labelFont = new SoFont;
00467             labelFont->size.setValue (16.0);
00468             labelFont->name.setValue ("Times-Roman");
00469             SoTranslation* labelTrans = new SoTranslation;
00470             
00471             if ((rMax >= rMin)|| (rMax == -1))
00472             {
00473                 labelTrans->translation.setValue (convertCoordinates (SbVec3f (1.1 * (rMinSigned + rulerHeight), rulerAngle, zLayer + zDist)));
00474             }
00475             else
00476             {
00477                 labelTrans->translation.setValue (convertCoordinates (SbVec3f (0.9 * (rMinSigned + rulerHeight), rulerAngle, zLayer + zDist)));
00478             }
00479             
00480             // build the ruler and add it to the scene graph
00481             ruler->addChild (axisMaterial);
00482             ruler->addChild (rulerCoords);
00483             ruler->addChild (rulerFaceSet);
00484             ruler->addChild (labelFont);
00485             ruler->addChild (labelTrans);
00486             ruler->addChild (labelText);
00487             
00488             setPart ("ruler",   ruler);
00489         }
00490     }
00491 }

IgSoRZHist::SO_KIT_CATALOG_ENTRY_HEADER ( ruler   )  [private]

IgSoRZHist::SO_KIT_CATALOG_ENTRY_HEADER ( lines   )  [private]

IgSoRZHist::SO_KIT_CATALOG_ENTRY_HEADER ( faceSet   )  [private]

IgSoRZHist::SO_KIT_CATALOG_ENTRY_HEADER ( shapeHints   )  [private]

IgSoRZHist::SO_KIT_HEADER ( IgSoRZHist   )  [private]


Member Data Documentation

SoSFFloat IgSoRZHist::deltaEta

Definition at line 42 of file IgSoRZHist.h.

Referenced by IgSoRZHist(), refresh(), and VisPCaloHitTwig::update().

SoMFFloat IgSoRZHist::energies

Definition at line 37 of file IgSoRZHist.h.

Referenced by IgSoRZHist(), refresh(), and VisPCaloHitTwig::update().

SoSFFloat IgSoRZHist::layer

Definition at line 39 of file IgSoRZHist.h.

Referenced by IgSoRZHist(), refresh(), and VisPCaloHitTwig::update().

SoSFBool IgSoRZHist::logScale

Definition at line 38 of file IgSoRZHist.h.

Referenced by IgSoRZHist(), refresh(), and VisPCaloHitTwig::update().

SoSFFloat IgSoRZHist::maxRadius

Definition at line 35 of file IgSoRZHist.h.

Referenced by IgSoRZHist(), refresh(), and VisPCaloHitTwig::update().

SoSFFloat IgSoRZHist::minRadius

Definition at line 34 of file IgSoRZHist.h.

Referenced by IgSoRZHist(), refresh(), and VisPCaloHitTwig::update().

SoSFFloat IgSoRZHist::scaleFactor

Definition at line 40 of file IgSoRZHist.h.

Referenced by IgSoRZHist(), and refresh().

SoSFBool IgSoRZHist::showAnnotations

Definition at line 41 of file IgSoRZHist.h.

Referenced by IgSoRZHist(), refresh(), and VisPCaloHitTwig::update().

SoSFBool IgSoRZHist::upper

Definition at line 36 of file IgSoRZHist.h.

Referenced by IgSoRZHist(), refresh(), and VisPCaloHitTwig::update().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:25:44 2009 for CMSSW by  doxygen 1.5.4