00001 #include "Iguana/Inventor/interface/IgSoRectHist.h"
00002 #include <Inventor/nodes/SoText2.h>
00003 #include <Inventor/nodes/SoFont.h>
00004 #include <Inventor/nodes/SoCoordinate3.h>
00005 #include <Inventor/nodes/SoFaceSet.h>
00006 #include <Inventor/nodes/SoTranslation.h>
00007 #include <Inventor/nodes/SoRotation.h>
00008 #include <Inventor/nodes/SoSeparator.h>
00009 #include <Inventor/nodes/SoIndexedFaceSet.h>
00010 #include <Inventor/nodes/SoShapeHints.h>
00011 #include <Inventor/nodes/SoMaterial.h>
00012 #include <Inventor/nodes/SoMaterialBinding.h>
00013 #include <Inventor/nodes/SoIndexedLineSet.h>
00014 #include <Inventor/nodes/SoVertexProperty.h>
00015 #include <Inventor/nodes/SoAnnotation.h>
00016
00017 #include <vector>
00018 #include <cmath>
00019 #include <algorithm>
00020 #include <iostream>
00021
00022
00023
00024
00025
00026 enum n_placement {UPPERRIGHTENDCAP, UPPERBARREL, LEFTENDCAP, LOWERBARREL, LOWERRIGHTENDCAP};
00027
00028
00029
00030
00031
00032 SO_KIT_SOURCE (IgSoRectHist);
00033
00034
00035
00036 n_placement
00037 findBinPlacement(const int nr,
00038 const int nz,
00039 const int binNo)
00040 {
00041
00042 if (binNo < nr/2) return UPPERRIGHTENDCAP;
00043 else if (binNo < nr/2 + nz) return UPPERBARREL;
00044 else if (binNo < 3./2. * nr + nz) return LEFTENDCAP;
00045 else if (binNo < 3./2. * nr + 2 * nz) return LOWERBARREL;
00046 else return LOWERRIGHTENDCAP;
00047 }
00048
00049 void
00050 logScaleEnergies (std::vector<float> & localEnergies,
00051 std::vector<float> & negativeEnergies)
00052 {
00053 for (unsigned int i=0; i<localEnergies.size(); i++) {
00054 if (localEnergies[i]!=0) localEnergies[i]=log(localEnergies[i]+1);
00055 if (negativeEnergies[i]!=0) negativeEnergies[i]=-log(-negativeEnergies[i]+1);
00056 }
00057 }
00058
00059 void
00060 scaleEnergies (std::vector<float> & localEnergies,
00061 std::vector<float> & negativeEnergies,
00062 const float & scaleFactor)
00063 {
00064 for (unsigned int i=0; i<localEnergies.size(); i++)
00065 {
00066 if (localEnergies[i]!=0) localEnergies[i]=localEnergies[i]*scaleFactor;
00067 if (negativeEnergies[i]!=0) negativeEnergies[i]=negativeEnergies[i]*scaleFactor;
00068 }
00069 }
00070
00071 int
00072 findMaxEnergyBin (std::vector<float> & localEnergies)
00073 {
00074 float maxEnergy=0;
00075 unsigned int maxEnergyIndex=0;
00076
00077 for (unsigned int i=0; i<localEnergies.size(); i++)
00078 {
00079 if (localEnergies[i]>maxEnergy)
00080 {
00081 maxEnergy=localEnergies[i];
00082 maxEnergyIndex=i;
00083 }
00084 }
00085
00086 return maxEnergyIndex;
00087 }
00088
00089 void resizeByMaxEnergy (const float maxEt,
00090 std::vector<float> & localEnergies)
00091 {
00092
00093 std::vector<float>::iterator iter;
00094 iter=max_element(localEnergies.begin(), localEnergies.end());
00095 float maxEnergy=*iter;
00096
00097
00098 if (maxEnergy==0)
00099 {
00100 std::cout << "Cannot resize by maximum energy - maximum energy of this RecHit collection is zero" << std::endl;
00101 return;
00102 }
00103
00104 for (unsigned int i=0; i<localEnergies.size() ; i++) localEnergies[i] = localEnergies[i] * maxEt / maxEnergy;
00105
00106 }
00107
00108
00109 SbVec3f
00110 IgSoRectHist::CMStoIgBarrel(const float & deltaTheta,
00111 const float & thetaRight,
00112
00113 const float & thetaIndex,
00114 const float & energy,
00115 const n_lowerUpper upperBarrel)
00116 {
00117 SbVec3f OIcoords;
00118 OIcoords[1]= upperBarrel ?
00119 Rr.getValue() + offsetR.getValue() + energy :
00120 -(Rr.getValue() + offsetR.getValue() + energy);
00121
00122
00123
00124 OIcoords[2] = OIcoords[1]* tan (M_PI/2. - (thetaRight + deltaTheta * (float)thetaIndex));
00125 OIcoords[0] = layer.getValue();
00126
00127 return OIcoords;
00128 }
00129
00130
00131 SbVec3f
00132 IgSoRectHist::CMStoIgEndcap(const float & deltaTheta,
00133 const float & thetaRight,
00134 const float & thetaIndex,
00135 const float & energy,
00136 const n_leftRight leftRight)
00137 {
00138 SbVec3f OIcoords;
00139
00140 OIcoords[2] = leftRight ?
00141 Rz.getValue() + offsetZ.getValue() + energy :
00142 -(Rz.getValue() + offsetZ.getValue() + energy);
00143 OIcoords[1] = leftRight ?
00144 OIcoords[2] * tan (deltaTheta * (float)thetaIndex) :
00145 OIcoords[2] * tan (M_PI - (thetaRight - deltaTheta * (float)thetaIndex) );
00146 OIcoords[0] = layer.getValue();
00147
00148 return OIcoords;
00149 }
00150
00151
00152
00153
00154
00155
00156 std::vector<float>
00157 IgSoRectHist::getNegativeEnergies (std::vector<float> & localEnergies)
00158 {
00159 float _Rz=Rz.getValue();
00160 float _Rr=Rr.getValue();
00161 int _nr=(int)nr.getValue();
00162 int _nz=(int)nz.getValue();
00163 float _offsetR=offsetR.getValue();
00164 float _offsetZ=offsetZ.getValue();
00165
00166 std::vector<float> negativeEnergies(localEnergies.size());
00167
00168
00169 for (int i=0; i<_nr/2; i++)
00170 {
00171 if (localEnergies[i] < 0)
00172 {
00173 negativeEnergies[i]=localEnergies[i];
00174
00175
00176 if (fabs(negativeEnergies[i]) > _Rz+_offsetZ)
00177 {
00178 negativeEnergies[i]=-(_Rz+_offsetZ);
00179 }
00180
00181
00182 localEnergies[i]=0;
00183 }
00184 else negativeEnergies[i]=0;
00185 }
00186
00187 for (int i=_nr/2; i<_nr/2+_nz; i++)
00188 {
00189 if (localEnergies[i] < 0)
00190 {
00191 negativeEnergies[i]=localEnergies[i];
00192
00193
00194 if (fabs(negativeEnergies[i]) > _Rr+_offsetR)
00195 {
00196 negativeEnergies[i]=-(_Rr+_offsetR);
00197 }
00198
00199
00200 localEnergies[i]=0;
00201 }
00202
00203 else negativeEnergies[i]=0;
00204 }
00205
00206 for (int i=_nr/2+_nz; i<_nr*3/2+_nz; i++)
00207 {
00208 if (localEnergies[i] < 0)
00209 {
00210 negativeEnergies[i]=localEnergies[i];
00211
00212
00213 if (fabs(negativeEnergies[i]) > _Rz+_offsetZ)
00214 {
00215 negativeEnergies[i]=-(_Rz+_offsetZ);
00216 }
00217
00218
00219 localEnergies[i]=0;
00220 }
00221
00222 else negativeEnergies[i]=0;
00223 }
00224
00225 for (int i=_nr*3/2+_nz; i<_nr*3/2+2*_nz; i++)
00226 {
00227 if (localEnergies[i] < 0)
00228 {
00229 negativeEnergies[i]=localEnergies[i];
00230
00231
00232 if (fabs(negativeEnergies[i]) > _Rr+_offsetR)
00233 {
00234 negativeEnergies[i]=-(_Rr+_offsetR);
00235 }
00236
00237
00238 localEnergies[i]=0;
00239 }
00240
00241 else negativeEnergies[i]=0;
00242 }
00243
00244 for (int i=_nr*3/2+2*_nz; i<2*_nz+2*_nr; i++)
00245 {
00246 if (localEnergies[i] < 0)
00247 {
00248 negativeEnergies[i]=localEnergies[i];
00249
00250
00251 if (fabs(negativeEnergies[i]) > _Rz+_offsetZ)
00252 {
00253 negativeEnergies[i]=-(_Rz+_offsetZ);
00254 }
00255
00256
00257 localEnergies[i]=0;
00258 }
00259 else negativeEnergies[i]=0;
00260 }
00261 return negativeEnergies;
00262 }
00263
00264
00265
00266 std::vector<SbVec3f>
00267 IgSoRectHist::generateVertexData (std::vector<float> & localEnergies,
00268 const int nOfBins,
00269 const float & deltaThetaEndcap,
00270 const float & deltaThetaBarrel,
00271 const float & thetaRightEndcap,
00272 const float & thetaRightBarrel,
00273 const float & thetaOffset,
00274 const float & scale)
00275 {
00276 float currentEnergy=0, projectedEnergy=0;
00277 int _nr=(int)nr.getValue();
00278 int _nz=(int)nz.getValue();
00279 float _Rr=Rr.getValue();
00280 float _Rz=Rz.getValue();
00281 float _offsetRr=offsetR.getValue();
00282 float _offsetRz=offsetZ.getValue();
00283 float _layer=layer.getValue();
00284 SbVec3f vertexBuffer;
00285 std::vector<SbVec3f> vertexData;
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297 vertexBuffer.setValue(_layer , 0, _Rz+_offsetRz);
00298 vertexData.push_back(vertexBuffer);
00299
00300 for (int i=0; i<_nr/2; i++) {
00301
00302 currentEnergy=localEnergies[i];
00303 projectedEnergy=currentEnergy*cos(i*deltaThetaEndcap+deltaThetaEndcap/2.);
00304
00305
00306 vertexBuffer=CMStoIgEndcap(deltaThetaEndcap, thetaRightEndcap, i, projectedEnergy, RIGHT);
00307 vertexData.push_back(vertexBuffer);
00308
00309
00310 vertexBuffer=CMStoIgEndcap(deltaThetaEndcap, thetaRightEndcap, i+1, projectedEnergy, RIGHT);
00311 vertexData.push_back(vertexBuffer);
00312
00313
00314 vertexBuffer=CMStoIgEndcap(deltaThetaEndcap, thetaRightEndcap, i+1, 0, RIGHT);
00315 vertexData.push_back(vertexBuffer);
00316 }
00317
00318
00319
00320
00321 vertexBuffer.setValue(_layer , _Rr+_offsetRr, _Rz);
00322 vertexData.push_back(vertexBuffer);
00323
00324 for (int i=_nr/2; i<_nr/2+_nz; i++) {
00325
00326 currentEnergy=localEnergies[i];
00327 projectedEnergy=currentEnergy*cos( M_PI/2. - (thetaRightBarrel + (i-(_nr/2))*deltaThetaBarrel + +deltaThetaBarrel/2.));
00328
00329
00330 vertexBuffer=CMStoIgBarrel(deltaThetaBarrel, thetaRightBarrel, i-(_nr/2), projectedEnergy, UPPER);
00331 vertexData.push_back(vertexBuffer);
00332
00333
00334 vertexBuffer=CMStoIgBarrel(deltaThetaBarrel, thetaRightBarrel, i+1-(_nr/2), projectedEnergy, UPPER);
00335 vertexData.push_back(vertexBuffer);
00336
00337
00338 vertexBuffer=CMStoIgBarrel(deltaThetaBarrel, thetaRightBarrel, i+1-(_nr/2), 0, UPPER);
00339 vertexData.push_back(vertexBuffer);
00340
00341 }
00342
00343
00344
00345
00346 vertexBuffer.setValue(_layer, _Rr, -(_Rz + _offsetRz));
00347 vertexData.push_back(vertexBuffer);
00348
00349 for (int i=_nr/2+_nz; i<_nr*3/2+_nz; i++) {
00350
00351 currentEnergy=localEnergies[i];
00352 projectedEnergy=-currentEnergy*cos(M_PI-thetaRightEndcap+deltaThetaEndcap/2.+(i-(_nr/2+_nz))*deltaThetaEndcap);
00353
00354
00355 vertexBuffer=CMStoIgEndcap(deltaThetaEndcap, thetaRightEndcap, i-(_nr/2+_nz), projectedEnergy, LEFT);
00356 vertexData.push_back(vertexBuffer);
00357
00358
00359 vertexBuffer=CMStoIgEndcap(deltaThetaEndcap, thetaRightEndcap, i-(_nr/2+_nz)+1, projectedEnergy, LEFT);
00360 vertexData.push_back(vertexBuffer);
00361
00362
00363 vertexBuffer=CMStoIgEndcap(deltaThetaEndcap, thetaRightEndcap, i-(_nr/2+_nz)+1, 0, LEFT);
00364 vertexData.push_back(vertexBuffer);
00365 }
00366
00367
00368
00369
00370 vertexBuffer.setValue(_layer , -(_Rr+_offsetRr), -_Rz);
00371 vertexData.push_back(vertexBuffer);
00372
00373 for (int i=_nr*3/2+_nz; i<_nr*3/2+2*_nz; i++) {
00374
00375 currentEnergy=localEnergies[i];
00376 projectedEnergy=currentEnergy * cos(M_PI/2. - (thetaRightBarrel + deltaThetaBarrel * (i-(_nr*3/2+_nz)) + deltaThetaBarrel/2.));
00377
00378
00379 vertexBuffer=CMStoIgBarrel(deltaThetaBarrel, thetaRightBarrel, i-(_nr*3./2.+_nz), projectedEnergy, LOWER);
00380 vertexData.push_back(vertexBuffer);
00381
00382
00383 vertexBuffer=CMStoIgBarrel(deltaThetaBarrel, thetaRightBarrel, i+1-(_nr*3./2.+_nz), projectedEnergy, LOWER);
00384 vertexData.push_back(vertexBuffer);
00385
00386
00387 vertexBuffer=CMStoIgBarrel(deltaThetaBarrel, thetaRightBarrel, i+1-(_nr*3./2.+_nz), 0, LOWER);
00388 vertexData.push_back(vertexBuffer);
00389 }
00390
00391
00392
00393
00394 vertexBuffer.setValue(_layer , -_Rr, _Rz+_offsetRz);
00395 vertexData.push_back(vertexBuffer);
00396
00397 for (int i=_nr*3/2+2*_nz; i<2*_nz+2*_nr; i++) {
00398
00399 currentEnergy=localEnergies[i];
00400 projectedEnergy=currentEnergy*cos(-deltaThetaEndcap*(i-(_nr*3/2+2*_nz)-_nr/2)-deltaThetaEndcap/2.);
00401
00402
00403 vertexBuffer=CMStoIgEndcap(deltaThetaEndcap, thetaRightEndcap,i-(_nr*3./2.+2*_nz)-_nr/2, projectedEnergy, RIGHT);
00404 vertexData.push_back(vertexBuffer);
00405
00406
00407 vertexBuffer=CMStoIgEndcap(deltaThetaEndcap, thetaRightEndcap,i-(_nr*3./2.+2*_nz)-_nr/2+1, projectedEnergy, RIGHT);
00408 vertexData.push_back(vertexBuffer);
00409
00410
00411 vertexBuffer=CMStoIgEndcap(deltaThetaEndcap, thetaRightEndcap, i-(_nr*3./2.+2*_nz)-_nr/2+1, 0, RIGHT);
00412 vertexData.push_back(vertexBuffer);
00413 }
00414
00415 return vertexData;
00416 }
00417
00418
00419 SbVec3f
00420 IgSoRectHist::generateLabelCoords (const int binNo,
00421 const float & deltaThetaEndcap,
00422 const float & deltaThetaBarrel,
00423 const float & thetaRightEndcap,
00424 const float & thetaRightBarrel,
00425 const float & energy)
00426 {
00427
00428 int _nr=(int)nr.getValue();
00429 int _nz=(int)nz.getValue();
00430
00431 n_placement placement = findBinPlacement(_nr, _nz, binNo);
00432 SbVec3f coords;
00433
00434 if (placement == UPPERRIGHTENDCAP || placement == LOWERRIGHTENDCAP) {
00435 coords = CMStoIgEndcap (deltaThetaEndcap, thetaRightEndcap, binNo + 0.5, energy, RIGHT);
00436 }
00437
00438 if (placement == UPPERBARREL) {
00439 coords = CMStoIgBarrel (deltaThetaBarrel, thetaRightBarrel, binNo - _nr/2 + 0.5, energy, UPPER);
00440 }
00441
00442 if (placement == LEFTENDCAP) {
00443 coords = CMStoIgEndcap (deltaThetaEndcap, thetaRightEndcap, binNo - (_nr/2 + _nz) + 0.5, energy, LEFT);
00444 }
00445
00446 if (placement == LOWERBARREL) {
00447 coords = CMStoIgBarrel (deltaThetaBarrel, thetaRightBarrel, binNo - (_nr * 3./2. + _nz) + 0.5, energy, LOWER);
00448 }
00449
00450 if (placement == LOWERRIGHTENDCAP) {
00451 coords = CMStoIgEndcap (deltaThetaEndcap, thetaRightEndcap, binNo-(_nr*3./2.+2*_nz)-_nr/2+0.5, energy, RIGHT);
00452 }
00453
00454 return coords;
00455
00456
00457 }
00458
00459
00460 std::vector<int> IgSoRectHist::generateFaceIndices (const std::vector<float> & localEnergies,
00461 const int nr,
00462 const int nz)
00463 {
00464
00465
00466 int a=0;
00467 int b=1;
00468 int c=2;
00469 int d=3;
00470
00471 std::vector<int> faceIndices;
00472
00473
00474 if (localEnergies[0]!=0) {
00475
00476 faceIndices.push_back(0);
00477 faceIndices.push_back(1);
00478 faceIndices.push_back(2);
00479 faceIndices.push_back(3);
00480 faceIndices.push_back(0);
00481 faceIndices.push_back(SO_END_FACE_INDEX);
00482
00483
00484 }
00485
00486 for (int i=1; i < (2*nr + 2*nz); i++) {
00487
00488 if (i==nr/2. || i==(nr/2.+nz) || i==(nr*3./2.+nz) || i==(nr*3./2.+2*nz) ) {
00489 a++; b++; c++; d++;
00490 }
00491
00492 if (localEnergies[i]!=0) {
00493
00494 faceIndices.push_back(i*3+a);
00495 faceIndices.push_back(i*3+b);
00496 faceIndices.push_back(i*3+c);
00497 faceIndices.push_back(i*3+d);
00498 faceIndices.push_back(i*3+a);
00499 faceIndices.push_back(SO_END_FACE_INDEX);
00500
00501 }
00502
00503 }
00504
00505 return faceIndices;
00506 }
00507
00508
00509
00510
00511 void
00512 IgSoRectHist::initClass (void)
00513 { SO_KIT_INIT_CLASS (IgSoRectHist, IgSoShapeKit, "IgSoShapeKit"); }
00514
00515
00516 IgSoRectHist::IgSoRectHist ()
00517 {
00518
00519 SO_KIT_CONSTRUCTOR (IgSoRectHist);
00520
00521
00522 SO_KIT_ADD_FIELD (Rz, (10.));
00523 SO_KIT_ADD_FIELD (Rr, (5.));
00524 SO_KIT_ADD_FIELD (offsetR, (0.));
00525 SO_KIT_ADD_FIELD (offsetZ, (0.));
00526 SO_KIT_ADD_FIELD (nr, (10.));
00527 SO_KIT_ADD_FIELD (nz, (10.));
00528 SO_KIT_ADD_FIELD (energies, (0.0));
00529 SO_KIT_ADD_FIELD (layer, (0.0));
00530
00531 SO_KIT_ADD_FIELD (logScale, (FALSE));
00532 SO_KIT_ADD_FIELD (scaleFactor, (1));
00533 SO_KIT_ADD_FIELD (maxRr, (0.0));
00534 SO_KIT_ADD_FIELD (maxRz, (0.0));
00535
00536 SO_KIT_ADD_FIELD (showAnnotations, (FALSE));
00537
00538 SO_KIT_ADD_CATALOG_ENTRY (shapeHints, SoShapeHints, FALSE, separator,\x0, TRUE);
00539 SO_KIT_ADD_CATALOG_ENTRY (faceSet, SoIndexedFaceSet, FALSE, separator,\x0, TRUE);
00540
00541
00542 SO_KIT_ADD_CATALOG_ENTRY (negativeShapeHints, SoShapeHints, FALSE, separator,\x0, TRUE);
00543 SO_KIT_ADD_CATALOG_ENTRY (negativeMaterial, SoMaterial, FALSE, separator,\x0, TRUE);
00544 SO_KIT_ADD_CATALOG_ENTRY (negativeFaceSet, SoIndexedFaceSet, FALSE, separator,\x0, TRUE);
00545
00546
00547 SO_KIT_ADD_CATALOG_ENTRY (soAnnotation, SoAnnotation, FALSE, separator,\x0,TRUE);
00548
00549 SO_KIT_INIT_INSTANCE ();
00550 setUpConnections (true, true);
00551
00552
00553 lineColor_[0]=0.0;
00554 lineColor_[1]=0.0;
00555 lineColor_[2]=0.0;
00556 }
00557
00558 void
00559 IgSoRectHist::refresh (void)
00560 {
00561
00562 int nOfBins=energies.getNum();
00563
00564 float deltaThetaEndcap = 2*atan(Rr.getValue()/(Rz.getValue()+offsetZ.getValue())) / nr.getValue();
00565 float deltaThetaBarrel = 2*atan(Rz.getValue()/(Rr.getValue()+offsetR.getValue())) / nz.getValue();
00566
00567 float thetaRightEndcap = atan(Rr.getValue() / ( Rz.getValue() + offsetZ.getValue() ) );
00568 float thetaRightBarrel = atan((Rr.getValue() + offsetR.getValue() )/Rz.getValue() );
00569
00570
00571 if (nOfBins == 1) {
00572
00573 setPart ("shapeHints", NULL);
00574 setPart ("faceSet", NULL);
00575 setPart ("negativeShapeHints", NULL);
00576 setPart ("negativeMaterial", NULL);
00577 setPart ("negativeFaceSet", NULL);
00578 setPart ("soAnnotation", NULL);
00579 return;
00580
00581 }
00582
00583
00584 std::vector<float> localEnergies(nOfBins);
00585
00586 for (int i=0; i<nOfBins; i++) {
00587 localEnergies[i]=energies[i];
00588 }
00589
00590
00591 int maxEnergyBin = findMaxEnergyBin(localEnergies);
00592 std::vector<float>::iterator iter;
00593 iter=max_element(localEnergies.begin(), localEnergies.end());
00594 float maxEnergy=*iter;
00595
00596
00597 std::vector<float> negativeEnergies(nOfBins);
00598 negativeEnergies = getNegativeEnergies (localEnergies);
00599
00600
00601 if (scaleFactor.getValue() !=1) {
00602 scaleEnergies (localEnergies, negativeEnergies, scaleFactor.getValue());
00603 }
00604
00605
00606 if (logScale.getValue()) {
00607 logScaleEnergies(localEnergies, negativeEnergies);
00608 }
00609
00610
00611
00612 SoShapeHints* shapeHints = new SoShapeHints;
00613 shapeHints->faceType = SoShapeHints::CONVEX;
00614 shapeHints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
00615
00616 SoShapeHints* negativeShapeHints = new SoShapeHints;
00617 negativeShapeHints->faceType = SoShapeHints::CONVEX;
00618 negativeShapeHints->vertexOrdering = SoShapeHints::CLOCKWISE;
00619
00620
00621
00622 SoMaterial * lineMaterial = new SoMaterial;
00623 SoMaterial * negativeMaterial = new SoMaterial;
00624 lineMaterial->diffuseColor.setValue (lineColor_[0], lineColor_[1] , lineColor_[2] );
00625 negativeMaterial ->diffuseColor.setValue (51.0 / 255.0, 1.0, 102.0 / 255.0);
00626
00627
00628
00629 SoIndexedFaceSet* faceSet = new SoIndexedFaceSet;
00630 SoIndexedFaceSet* negativeFaceSet = new SoIndexedFaceSet;
00631
00632
00633 std::vector<SbVec3f> vertexData = generateVertexData(localEnergies, nOfBins, deltaThetaEndcap, deltaThetaBarrel, thetaRightEndcap, thetaRightBarrel, 0, 1);
00634
00635 std::vector<SbVec3f> negativeVertexData = generateVertexData(negativeEnergies, nOfBins, deltaThetaEndcap, deltaThetaBarrel, thetaRightEndcap, thetaRightBarrel, 0, 1);
00636
00637
00638
00639 SoVertexProperty* vtx = new SoVertexProperty;
00640 SoVertexProperty* negativeVtx = new SoVertexProperty;
00641
00642 vtx->vertex.setValues (0, vertexData.size(), &vertexData[0]);
00643 vtx->materialBinding = SoMaterialBinding::PER_FACE_INDEXED;
00644
00645 negativeVtx->vertex.setValues (0, negativeVertexData.size(), &negativeVertexData[0]);
00646 negativeVtx->materialBinding = SoMaterialBinding::PER_FACE_INDEXED;
00647
00648 faceSet->vertexProperty = vtx;
00649 negativeFaceSet->vertexProperty = negativeVtx;
00650
00651
00652 std::vector< int > faceIndices = generateFaceIndices(localEnergies, (int)nr.getValue(), (int)nz.getValue());
00653 std::vector< int > negativeFaceIndices = generateFaceIndices(negativeEnergies, (int)nr.getValue(), (int)nz.getValue());
00654
00655 faceSet->coordIndex.setValues (0, faceIndices.size(), &faceIndices[0]);
00656 negativeFaceSet->coordIndex.setValues (0, negativeFaceIndices.size(), &negativeFaceIndices[0]);
00657
00658
00659 SoIndexedLineSet* lineSet = new SoIndexedLineSet;
00660
00661
00662 lineSet->vertexProperty = vtx;
00663
00664
00665 lineSet->coordIndex.setValues (0, faceIndices.size(), &faceIndices[0]);
00666
00667
00668
00669
00670 if (showAnnotations.getValue()) {
00671
00672 SoAnnotation * soAnnotation = new SoAnnotation;
00673
00674 char label [50];
00675
00676 SbVec3f labelCoordsVec = generateLabelCoords (maxEnergyBin, deltaThetaEndcap, deltaThetaBarrel, thetaRightEndcap, thetaRightBarrel, maxEnergy);
00677
00678 if (maxEnergy >= 100.0) {
00679 sprintf (label, "Emax = %.1f TeV ", maxEnergy / 1000.0);
00680 }
00681
00682 else {
00683 sprintf (label, "Emax = %.1f GeV ", maxEnergy);
00684 }
00685
00686 SoText2* text = new SoText2;
00687 text->string = label;
00688 text->justification = SoText2::CENTER;
00689
00690 SoFont* labelFont = new SoFont;
00691 labelFont->size.setValue (14.0);
00692 labelFont->name.setValue ("Arial");
00693
00694 SoMaterial * textMaterial = new SoMaterial;
00695 textMaterial->diffuseColor.setValue (0.4, 0.4, 0.4);
00696
00697 SoTranslation* textTranslation = new SoTranslation;
00698 textTranslation->translation.setValue(labelCoordsVec);
00699
00700
00701 soAnnotation->addChild(lineMaterial);
00702 soAnnotation->addChild(lineSet);
00703
00704 soAnnotation->addChild(textMaterial);
00705 soAnnotation->addChild(textTranslation);
00706 soAnnotation->addChild(labelFont);
00707 soAnnotation->addChild(text);
00708
00709 setPart ("soAnnotation", soAnnotation);
00710
00711 }
00712
00713 else setPart ("soAnnotation", NULL);
00714
00715
00716
00717
00718 setPart("shapeHints", shapeHints);
00719 setPart ("faceSet", faceSet);
00720 setPart("lineMaterial", lineMaterial);
00721
00722
00723 setPart ("negativeShapeHints", negativeShapeHints);
00724 setPart ("negativeMaterial", negativeMaterial);
00725 setPart ("negativeFaceSet", negativeFaceSet);
00726 }
00727
00728 void IgSoRectHist::setLineColor (const float& red,
00729 const float& green,
00730 const float& blue)
00731 {
00732 lineColor_[0]=red;
00733 lineColor_[1]=green;
00734 lineColor_[2]=blue;
00735 }