Creating TEveBoxSet from existing elements of geometry

Hi, I am trying to write a simple event display using Eve. The geometry is quite simple: a calorimeter made of cubic crystals and segmented scintillators all around, so basically all the base shapes are TGeoBBox objects.
At first I thought of painting the volumes of the geometry according to energy deposition in the specific element, but this means that I have to modify the geometry scene and I won’t be taking advantage of the event scene (and the commodity of easily reset it when painting a new event).
So I would like to convert a set of hit infos (volume hit, energy deposition) to a TEveBoxSet for display in the event scene of the application, but I found no clear way to do so. I have a unordered_map that uses the volume name to map it to the corresponding TEveGeoNode (in this way I can then access everything, from the corresponding TGeoNode to the TGeoShape of the TGeoVolume underneath). The main problem I can’t seem to solve is positioning the box in the TEveBoxSet, getting its sizes is a bit tricky but not impossible.
Is there any way (a more clever one) to easily create a TEveBox based on the geometry elements?

Cheers,
Valerio

I know of two people who should know: @matevz and @alja!

Hi Valerio,

If you don’t have too many objects I’d still recommend you clone the geometry shapes into TEveGeoShape, as is done here:
http://git.cern.ch/pubweb/AliRoot.git/blob/HEAD:/EVE/macros/data/acorde_raw.C

With TEveBoxSet you’ll also have to enable picking at tell it to always do secondary selection (as is done in commented out section of code in tutorials/eve/boxset.C). This is sufficient if you only want to get simple feedback from eve (tooltip) but if you want to do more with the selected item it will complicate you life a bit.

There are different options for box-set construction, given by enum EBoxType_e, https://root.cern.ch/doc/master/classTEveBoxSet.html The best way to convert geo-boxes to eve-boxes depends on how different individual shapes are and how they are oriented. If they can have arbitrary rotations the best way is probably to get the transformation matrix from tgeo and then multiply the corner vectors by it – using the kBT_FreeBox box type.

  1. The alice example above shows how to extract transformation matrix from tgeo;
  2. You can use TGeoShape::GetBuffer3D to get corners in local frame: https://root.cern.ch/doc/master/classTGeoShape.html#aa11debb662ba4c145bb67629b4839923

Cheers,
Matevz

Hi Matevs,
thanks! This was exactly what I was looking for. In the end I dropped the idea of using a TEveBoxSet since having a collection of TEveGeoShape objects gives me more freedom (i.e. per-element transparency and implementing a custom palette).
The only problem I have left now (and that I experienced even with the TEveBoxSet) is that whatever palette I set with gStyle->SetPalette() doesn’t apply to my display. All I get is a scale-of-blue palette which is not really what I was going for (see attachment).

I am using a custom class derived from TPaletteAxis to manage the value-to-color conversion, but I can assure that even if I use TEveRGBPalette the result is identical.

Essentially in my main (or in some initalization member) I would like to do

gROOT->Macro("~/.rootlogon.C");
gStyle->SetPalette(kInvertedDarkBodyRadiator);
gROOT->ForceStyle();

and have my palette automatically recalling the right colors. Do you have any suggestion on what I’m missing?

Cheers,
Valerio

Hi Valerio,

Just setting the palette will not affect eve objects … you have to add manual assignment of color (as in TEveElement::SetMainColorXXX()).

TEveDigitSet (base class of QuadSet and BoxSet has functionality for mapping colors given a TEveRGBAPalette and an integer “signal” specified per digit. IIRC TEveRGBAPalette can even do callbacks to repaint objects when you change min/max mapped value or action to take on digits below min / above max. This actually looks pretty good, changing the limits in the editor and seeing how objects change colors … see tutorials/eve/quadset.C (with root 6 you have to comment out lines 240 and 241, it seems). Note there is special handling for cases when signal is below or above min/max.

You could get this to work with your own class that knows about the items and loops over them, changing their colors when it receives the signal from the palette. When you change a color of an eve element you need to call element->StampColorSelection() and then gEve->Redraw3D() when you’re done … this will minimize the update and prevent the display from flicking compared to more intrusive scene update methods (esp, gEve->Redrawd3D(false, true) or gEve->FullRedraw3D(false, true)).

You could also scale the rectangles based on the signal value (element->RefMainTrans()->SetScale(sx,sy,sz)).

Cheers,
Matevz

Hi Matevs,
I think I’ve forgot to specify that I already call SetMainColor on the TEveGeoShapes, as you can see in the snippet below. You can see in the comments that before I was building manually a TEveBoxSet but I don’t like placing the Boxes manually, your solution is far more elegant in this sense.
Now _CaloSpaheHits is just a TEveElementList (that I still have to figure out how to reset) that holds the cells to display, and I use the VPalette class (that inherits from TPaletteAxis) to get the appropriate color.
Anyway with both solutions I still see the same result, as displayed in the previous post. What I would like is to have the system palette applied to the signal-to-value conversion.

void MainWindow::LoadEvent(){
  static const std::string routineName("MainWindow::LoadEvent");

  // MakeTransparentScene(95);
  // if( !_CaloHits ){
  //   _CaloHits = new TEveBoxSet("CaloHits");
  //   _CaloPalette = new TEveRGBAPalette(0, 255, 1, 1, 1);
  //   _CaloHits->SetMainTransparency(0);
  // }
  if( !_CaloPalette ){
    _CaloPalette = new VPalette();
  }

  // _CaloHits->Reset(TEveBoxSet::kBT_AABox, kFALSE, 64);
  for (std::pair<std::string, TEveGeoShape*> element : _TEveGeoShapeMap) element.second->SetMainTransparency(100);

  EDApplication* thisApp = (EDApplication*) gApplication;

  //Add crystal signals
  GGSTHitsReader* reader = thisApp->GetFileManager()->GetHitsReader();

  double eMax=0;
  int nHits = reader->GetNHits("Crystal"); //Number of hit crystals for current event
  std::string volName;
  Float_t* volPos;
  GGSTIntHit* thisHit = NULL;
  for (int iHit = 0; iHit < nHits; iHit++) {
    thisHit = reader->GetHit("Crystal", iHit);
    if( thisHit->eDep > eMax ) eMax = thisHit->eDep;
  }
  _CaloPalette->Rebin(0, eMax);

  for (int iHit = 0; iHit < nHits; iHit++) {
    thisHit = reader->GetHit("Crystal", iHit);
    if( thisHit->eDep < 5e-3 ) continue;
    volPos = const_cast<float*>( thisHit->GetVolumePosition() );
    volName = thisApp->GetGeoManager()->FindNode(volPos[0], volPos[1], volPos[2])->GetName();

    _TEveGeoShapeMap[volName]->SetMainColor( _CaloPalette->GetValueColor2(thisHit->eDep) );
    _TEveGeoShapeMap[volName]->SetMainTransparency(50*(1-thisHit->eDep/eMax));
    _CaloShapeList->AddElement(_TEveGeoShapeMap[volName]);


    // ------------------- OLD WAY -------------------
    // double boxDim   = 1 + 2*thisHit->eDep/eMax;
    // double boxShift = 1.5 - (3 - boxDim)/2;
    // _CaloHits->AddBox(
    //   volPos[0]-boxShift, volPos[1]-boxShift, volPos[2]-boxShift,
    //   boxDim, boxDim, boxDim
    // );
    // _CaloHits->DigitValue( TMath::Nint(thisHit->eDep * (255/eMax)) );

    // ------------------- OLD WAY -------------------
  }
  // _CaloHits->RefitPlex();

  // _CaloHits->SetPalette(_CaloPalette);
  // AddElement(_CaloHits);
  gEve->Redraw3D();

Hi Valerio,

Strange … this should work. Can you print out what this returns _CaloPalette->GetValueColor2(thisHit->eDep) … also, what is the return type?

If you want to just drop all the elements you can call _CaloShapeList->DestroyElements() … EVE should take care of cleaning up correctly. If you want to keep them around, call IncRefCount() on the elements and call RemoveElements() on the list. Eve elements are ref-counted so if you remove them from all the containers they will auto-destruct. Alternatively, if you know you’ll need them for every event … why not just keeping them around? You can toggle visibility by calling SetRnrSelf(true/false).

\m

Hi Matevs,

Strange … this should work. Can you print out what this returns _CaloPalette->GetValueColor2(thisHit->eDep) … also, what is the return type?

I basically copied TPaletteAxis::GetColorValue but I modified it not to rely on an external TH1, here’s the snippet

Int_t VPalette::GetValueColor2(Double_t zc){
   Double_t wmin  = _xMin;
   Double_t wmax  = _xMax;
   Double_t wlmin = wmin;
   Double_t wlmax = wmax;

   if (_isLog) {
      if (wmin <= 0 && wmax > 0) wmin = TMath::Min((Double_t)1,
                                                      (Double_t)0.001 * wmax);
      wlmin = TMath::Log10(wmin);
      wlmax = TMath::Log10(wmax);
   }

   Int_t ncolors = gStyle->GetNumberOfColors();
   Int_t ndivz = _nBins;
   if (ndivz == 0) return 0;
   ndivz = TMath::Abs(ndivz);
   Int_t theColor, color;
   Double_t scale = ndivz / (wlmax - wlmin);

   if (_isLog) zc = TMath::Log10(zc);
   if (zc < wlmin) zc = wlmin;

   color = Int_t(0.01 + (zc - wlmin) * scale);

   theColor = Int_t((color + 0.99) * Double_t(ncolors) / Double_t(ndivz));
   return gStyle->GetColorPalette(theColor);
}

Here’s some output from the function (with the percentage being eDep/eMax). what I find even more strange is that if I run boxset.C the palette seems to be correct! But I run that macro in the interpreter, while this is a compiled program, can it be related to the problem?

Crystal_3517  0.614456 %  2260
Crystal_3496  0.555891 %  2259
Crystal_3475  0.943017 %  2266
Crystal_3454  0.165439 %  2241
Crystal_2950  0.640693 %  2261
Crystal_2929  0.633673 %  2261
Crystal_2908  0.613414 %  2260
Crystal_2887  0.746303 %  2263
Crystal_2866  0.660909 %  2261
Crystal_2845  0.583159 %  2259
Crystal_2824  15.7879 %  2307
Crystal_2803  100 %  2234
Crystal_2782  68.7139 %  2328
Crystal_2761  63.4784 %  2327
Crystal_2740  29.5253 %  2316
Crystal_2719  12.8249 %  2304
Crystal_2698  7.25338 %  2296
Crystal_2677  3.71528 %  2286
Crystal_3096  1.44923 %  2272
Crystal_3117  1.44196 %  2272
Crystal_3223  0.49261 %  2257
Crystal_3224  0.37325 %  2253
Crystal_3243  0.173681 %  2242
Crystal_2341  26.3653 %  2314
Crystal_2360  0.194027 %  2243
Crystal_2760  1.61277 %  2274
Crystal_3217  0.121877 %  2237
Crystal_2717  0.584878 %  2259
Crystal_3201  0.859237 %  2265
Crystal_3160  1.07802 %  2268
Crystal_3538  0.156399 %  2240
Crystal_3138  0.673315 %  2261
Crystal_2362  4.81741 %  2290
Crystal_2340  2.80467 %  2282
Crystal_2319  3.62205 %  2286
Crystal_2298  3.81281 %  2286
Crystal_1857  0.684804 %  2262
Crystal_1836  5.01444 %  2290
Crystal_3308  0.111754 %  2235
Crystal_1835  1.89927 %  2276
Crystal_2781  1.4368 %  2272
Crystal_2804  2.09848 %  2278
Crystal_2320  47.4563 %  2323
Crystal_1067  1.31095 %  2271
Crystal_1431  0.387856 %  2253
Crystal_1430  0.985021 %  2267
Crystal_1449  0.110037 %  2235
Crystal_1879  0.621799 %  2260
Crystal_1900  1.13179 %  2269
Crystal_1858  1.97082 %  2277
Crystal_1878  0.660201 %  2261
Crystal_2297  3.54616 %  2285
Crystal_2299  61.4074 %  2327
Crystal_1837  2.51404 %  2281
Crystal_1902  0.221737 %  2245
Crystal_1838  0.729613 %  2263
Crystal_3204  0.819114 %  2264
Crystal_2321  2.78716 %  2282
Crystal_2720  4.49349 %  2289
Crystal_1429  3.15759 %  2284
Crystal_1856  2.49451 %  2280
Crystal_2256  4.77464 %  2290
Crystal_2276  2.64198 %  2281
Crystal_2716  1.17137 %  2269
Crystal_3618  1.40403 %  2272
Crystal_4059  0.398118 %  2254
Crystal_4058  0.770844 %  2263
Crystal_4499  2.4059 %  2280
Crystal_2783  3.38102 %  2284
Crystal_2762  4.42445 %  2288
Crystal_3182  1.49454 %  2273
Crystal_3183  0.47748 %  2256
Crystal_3162  0.923645 %  2266
Crystal_3141  0.729267 %  2263
Crystal_2279  12.1836 %  2303
Crystal_3161  1.37752 %  2272
Crystal_2235  3.71603 %  2286
Crystal_2257  28.6844 %  2315
Crystal_2779  0.343898 %  2252
Crystal_2278  55.3561 %  2325
Crystal_1796  3.08961 %  2283
Crystal_1795  2.78754 %  2282
Crystal_2258  11.7956 %  2303
Crystal_2300  15.6365 %  2307
Crystal_2236  10.1573 %  2301
Crystal_2786  0.246841 %  2247
Crystal_3583  0.318036 %  2250
Crystal_3140  2.54263 %  2281
Crystal_1920  0.15922 %  2241
Crystal_1505  0.208786 %  2244
Crystal_2785  0.132864 %  2238
Crystal_2784  0.279411 %  2248
Crystal_1051  0.111279 %  2235
Crystal_1411  1.46757 %  2273
Crystal_1450  0.35593 %  2252
Crystal_1859  1.52854 %  2273
Crystal_2739  5.29512 %  2291
Crystal_2697  1.92752 %  2277
Crystal_2301  2.04377 %  2277
Crystal_1797  1.00346 %  2267
Crystal_1794  0.529381 %  2258
Crystal_1793  0.318833 %  2250
Crystal_2237  3.54931 %  2285
Crystal_2342  2.88848 %  2283
Crystal_2363  0.866371 %  2265
Crystal_1899  0.389854 %  2253
Crystal_1901  0.819369 %  2264
Crystal_3203  1.43661 %  2272
Crystal_3202  1.31031 %  2271
Crystal_3222  1.49159 %  2273
Crystal_1468  0.186479 %  2243
Crystal_2699  1.81299 %  2275
Crystal_2215  5.42006 %  2292
Crystal_2741  5.83304 %  2293
Crystal_1839  0.241782 %  2246
Crystal_2802  1.2031 %  2270
Crystal_3686  0.102076 %  2234
Crystal_2742  0.347626 %  2252
Crystal_1773  0.475709 %  2256
Crystal_2214  1.70354 %  2275
Crystal_1488  0.220421 %  2245
Crystal_2277  4.83289 %  2290
Crystal_2318  2.42819 %  2280
Crystal_2822  0.350659 %  2252
Crystal_2280  1.16041 %  2269
Crystal_1775  1.21924 %  2270
Crystal_1815  2.63447 %  2281
Crystal_1393  0.206966 %  2244
Crystal_1085  0.237932 %  2246
Crystal_1921  0.258403 %  2248
Crystal_1922  0.139957 %  2239
Crystal_3200  0.908231 %  2266
Crystal_2322  0.269374 %  2248
Crystal_3267  0.142456 %  2239
Crystal_3245  0.32442 %  2251
Crystal_1860  0.367489 %  2253
Crystal_2216  1.67544 %  2275
Crystal_2361  0.690092 %  2262
Crystal_2383  0.166013 %  2241
Crystal_3097  0.82689 %  2264
Crystal_2657  0.835472 %  2264
Crystal_3139  1.17226 %  2269
Crystal_1817  3.12219 %  2284
Crystal_2675  0.174361 %  2242
Crystal_1880  0.695993 %  2262
Crystal_1452  0.104479 %  2234
Crystal_2260  0.192795 %  2243
Crystal_3558  0.132077 %  2238
Crystal_3119  0.900907 %  2266
Crystal_2678  0.841747 %  2264
Crystal_2254  0.268721 %  2248
Crystal_2676  1.63314 %  2274
Crystal_3246  0.121632 %  2237
Crystal_3181  0.571683 %  2259
Crystal_2238  0.605574 %  2260
Crystal_3159  0.458801 %  2256
Crystal_2655  0.396842 %  2253
Crystal_2656  1.25022 %  2270
Crystal_3582  0.239779 %  2246
Crystal_3560  0.504368 %  2257
Crystal_4001  1.22616 %  2270
Crystal_3980  0.402571 %  2254
Crystal_4420  0.384149 %  2253
Crystal_4421  0.249622 %  2247
Crystal_3561  0.140481 %  2239
Crystal_4024  0.85469 %  2265
Crystal_4465  0.33416 %  2251
Crystal_3644  2.56768 %  2281
Crystal_1834  0.370035 %  2253
Crystal_2713  0.103653 %  2234
Crystal_1813  0.949187 %  2266
Crystal_4464  0.169502 %  2241
Crystal_4002  0.122332 %  2237
Crystal_2339  0.339259 %  2252
Crystal_4022  0.159724 %  2241
Crystal_3580  0.173431 %  2242
Crystal_1469  0.147206 %  2239
Crystal_1390  0.42231 %  2255
Crystal_1814  0.346524 %  2252
Crystal_3116  0.322019 %  2251
Crystal_2275  0.36517 %  2252
Crystal_2274  0.111379 %  2235
Crystal_2296  0.449516 %  2255
Crystal_1389  0.162062 %  2241
Crystal_2234  0.501073 %  2257
Crystal_2273  0.187892 %  2243
Crystal_2693  0.186799 %  2243
Crystal_2255  0.332547 %  2251
Crystal_1772  0.862279 %  2265
Crystal_2317  0.172454 %  2242
Crystal_1791  0.455103 %  2255
Crystal_2295  0.114865 %  2236
Crystal_1774  2.77925 %  2282
Crystal_2736  0.245331 %  2247
Crystal_2343  0.211076 %  2244
Crystal_2718  3.96495 %  2287
Crystal_1409  0.351438 %  2252
Crystal_3180  1.0177 %  2267
Crystal_4085  0.601558 %  2260
Crystal_2281  1.97915 %  2277
Crystal_1820  1.92515 %  2277
Crystal_2823  0.129852 %  2237
Crystal_1816  3.49619 %  2285
Crystal_2384  0.157629 %  2240
Crystal_2763  0.297967 %  2250
Crystal_2382  0.135579 %  2238
Crystal_1470  0.199248 %  2244
Crystal_1432  0.212351 %  2244
Crystal_2721  0.770299 %  2263
Crystal_3118  0.401264 %  2254
Crystal_1391  2.39873 %  2280
Crystal_3535  0.18758 %  2243
Crystal_3225  0.362145 %  2252
Crystal_2259  1.01382 %  2267
Crystal_2780  0.16782 %  2241
Crystal_1489  0.342004 %  2252
Crystal_3099  0.159915 %  2241
Crystal_2658  0.287993 %  2249
Crystal_1049  0.284483 %  2249
Crystal_1373  1.39089 %  2272
Crystal_3158  0.153944 %  2240
Crystal_2738  0.785875 %  2264
Crystal_2212  0.164357 %  2241
Crystal_1374  0.279266 %  2248
Crystal_1410  0.293407 %  2249
Crystal_2364  0.263524 %  2248
Crystal_1818  0.559798 %  2259
Crystal_2302  0.394841 %  2253
Crystal_2759  0.466206 %  2256
Crystal_1776  0.450971 %  2255
Crystal_1984  0.126815 %  2237
Crystal_1881  0.167824 %  2241
Crystal_1029  0.117056 %  2236
Crystal_3643  0.337291 %  2251
Crystal_3620  0.677778 %  2261
Crystal_3179  0.121047 %  2237
Crystal_3120  0.13715 %  2238
Crystal_1433  0.102653 %  2234
Crystal_1392  4.1403 %  2288
Crystal_1466  0.102974 %  2234
Crystal_2701  0.270542 %  2248
Crystal_3244  0.136799 %  2238
Crystal_2743  0.342586 %  2252
Crystal_1877  0.18115 %  2242
Crystal_1819  0.443367 %  2255
Crystal_1898  0.212456 %  2244
Crystal_1396  0.145516 %  2239
Crystal_1050  1.46273 %  2273
Crystal_2801  0.521231 %  2257
Crystal_2344  0.177434 %  2242
Crystal_1792  0.418715 %  2254
Crystal_3664  0.123729 %  2237
Crystal_2805  0.103281 %  2234
Crystal_3198  0.180022 %  2242
Crystal_3600  0.116886 %  2236
Crystal_2700  0.540274 %  2258
Crystal_3184  0.176851 %  2242
Crystal_1135  0.124729 %  2237
Crystal_1395  0.141728 %  2239
Crystal_2722  0.18031 %  2242
Crystal_3098  0.302063 %  2250
Crystal_2764  0.115067 %  2236
Crystal_3579  0.302408 %  2250
Crystal_3142  0.170793 %  2241
Crystal_1451  0.281556 %  2249
Crystal_2679  0.356004 %  2252
Crystal_3602  0.222749 %  2245
Crystal_3205  0.180488 %  2242
Crystal_2346  0.108715 %  2235
Crystal_1812  0.173259 %  2242
Crystal_1472  0.132061 %  2238
Crystal_2654  0.396967 %  2253
Crystal_2217  0.381016 %  2253
Crystal_790  0.102124 %  2234
Crystal_3226  0.102042 %  2234
Crystal_3178  0.152015 %  2240
Crystal_3539  0.844345 %  2264
Crystal_3621  0.154991 %  2240
Crystal_2696  0.352202 %  2252
Crystal_1876  0.213815 %  2245
Crystal_1412  0.235303 %  2246
Crystal_3581  0.103324 %  2234
Crystal_1375  1.11251 %  2268
Crystal_1163  0.15885 %  2241
Crystal_3598  0.361279 %  2252
Crystal_3601  0.105045 %  2234
Crystal_1066  0.140957 %  2239
Crystal_786  0.13658 %  2238
Crystal_1394  0.939942 %  2266
Crystal_3599  0.593756 %  2259
Crystal_1506  0.180951 %  2242
Crystal_1523  0.220647 %  2245
Crystal_1771  0.198757 %  2244
Crystal_3540  0.102621 %  2234
Crystal_440  0.322925 %  2251
Crystal_3137  0.123413 %  2237
Crystal_3220  0.171602 %  2241
Crystal_3537  0.131495 %  2238
Crystal_3642  0.181064 %  2242
Crystal_3199  0.173347 %  2242
Crystal_4088  0.116782 %  2236
Crystal_3708  0.274734 %  2248
Crystal_2426  0.123674 %  2237
Crystal_1151  0.161087 %  2241
Crystal_717  0.175693 %  2242
Crystal_4525  0.175613 %  2242
Crystal_2842  0.58438 %  2259
Crystal_2044  0.339033 %  2252
Crystal_3577  0.557862 %  2259
Crystal_4018  0.143151 %  2239
Crystal_3997  2.02271 %  2277
Crystal_3163  0.117739 %  2236
Crystal_3263  0.103876 %  2234
Crystal_2843  0.117613 %  2236
Crystal_1015  0.122196 %  2237
Crystal_1032  0.432234 %  2255
Crystal_730  1.29582 %  2271
Crystal_2222  0.140093 %  2239
Crystal_2664  0.114776 %  2236
Crystal_700  0.127 %  2237
Crystal_715  0.246221 %  2247
Crystal_1832  0.158261 %  2240
Crystal_1544  0.161943 %  2241
Crystal_2371  0.151063 %  2240
Crystal_4038  0.204713 %  2244
Crystal_3562  0.129255 %  2237
Crystal_1086  0.1554 %  2240
Crystal_1524  0.137196 %  2238
Crystal_2776  0.354616 %  2252
Crystal_3239  0.166254 %  2241
Crystal_2733  0.121575 %  2237
Crystal_3587  1.32028 %  2271
Crystal_1034  0.44881 %  2255
Crystal_1033  1.24227 %  2270
Crystal_716  1.19508 %  2270
Crystal_2240  0.198194 %  2244
Crystal_2729  0.723813 %  2263
Crystal_453  0.318109 %  2250
Crystal_731  0.613978 %  2260
Crystal_5829  0.154119 %  2240
Crystal_4455  0.426365 %  2255
Crystal_196  0.25752 %  2247
Crystal_4454  0.129356 %  2237
Crystal_4593  0.10984 %  2235
Crystal_4691  0.163122 %  2241
Crystal_3586  1.12971 %  2269
Crystal_4729  0.154001 %  2240

If you want to just drop all the elements you can call _CaloShapeList->DestroyElements() … EVE should take care of cleaning up correctly. If you want to keep them around, call IncRefCount() on the elements and call RemoveElements() on the list. Eve elements are ref-counted so if you remove them from all the containers they will auto-destruct. Alternatively, if you know you’ll need them for every event … why not just keeping them around? You can toggle visibility by calling SetRnrSelf(true/false).

Ok thanks, it’s my intention to keep them around, I don’t want to recreate them every event I load. But I also don’t want to double count them in the list, or having in the browser a reference on hits that I’m not displaying, so I thought I had to “Reset” somehow the list.

Hi Valerio,

Compiled vs. interpreted shouldn’t matter.

The color index numbers do look strange, I get:

matevz@desire eve> root -l
root [0] gStyle->SetPalette(kInvertedDarkBodyRadiator)
root [1] gStyle->GetNumberOfColors()
(int) 255
root [2] gStyle->GetColorPalette(0)
(int) 1179

The spread of your indices is also relatively small, about 50 … given that the palette has 255 entries.

Also, how come index for 100% is the lowest? GetColorPalette(x) does x = x % number-of-colors.

Ok, I see something strange now, gStyle->GetNumberOfColors() changes from 255 to 100 in the middle of my hashmap generation, in the following function, before I enter the inner loop on the first crystal, even before calling GenerateHashTable on the first child.
Basically this happens when I’m still on the mother volume for all the crystals, I think as soon as iter=BeginChild() is called the number of color is set to 100. I could try to reset it back after I filled the map… but still also the palette is overridden at the same moment (I see GetPaletteColor(0) change from 1179 to 2234 at the same time)

void MainWindow::GenerateHashTable(TEveGeoNode* node){
  static const std::string routineName("MainWindow::GenerateHashTable");
  
  static std::vector<std::string> pathLevels;
  static int level = 0;
  
  std::pair< UOMIterator, bool> mapResult;
  std::string nodeName = node->GetElementName();
  pathLevels.push_back( nodeName );
  std::string path = "";
  for(int il=0; il<pathLevels.size(); il++) path.append(pathLevels[il] + "/");
  path.pop_back();
  
  std::cout << path << std::endl;
  
  if( ! gGeoManager->cd( path.data() ) ){
    COUT(WARNING) << "Node " << path << " not found" << ENDL;
    return;
  }
  
  TString lvlString = "";
  for(int is=0; is<level; is++) lvlString += "-";
  // COUT(DEBUG) << lvlString << " Inserting node " << nodeName << " with value " << node << " (has " << node->NumChildren() << " children) " << ENDL;
  _TEveGeoNodeMap.insert( make_pair(nodeName, node) );
  
  TEveGeoShape* shape = new TEveGeoShape(nodeName.data(), path.data());
  shape->RefMainTrans().SetFrom(*gGeoManager->GetCurrentMatrix());
  shape->SetShape((TGeoShape*) gGeoManager->GetCurrentVolume()->GetShape()->Clone());
  
  _TEveGeoShapeMap.insert( make_pair(nodeName, shape) );
  
  if( node->NumChildren() > 0 ){
    TEveElementList::List_i iter;
    for( iter = node->BeginChildren(); iter != node->EndChildren(); iter++ ){
      level++;
      GenerateHashTable( (TEveGeoNode*) *iter );
      level--;
    }
  }
  
  pathLevels.pop_back();
}

Hmmh, this is strange … this really shouldn’t touch gStyle or TColor at all.

Could there be some memory overwrite lurking somewhere? Can you try valgrind or running in gdb and watching the memory location where TColor stores size of the pallete array?

\m

I’ve been trying, but I can’t seem to find the memory address where the variable is held. Probably due to how the palette is stored in memory (see https://root.cern.ch/doc/master/TColor_8cxx_source.html). Also I’m not an expert in valgrind or gdb, so it’s taking me some time to learn

Cheers,
Valerio

Uh boy, this sure is complicated stuff :slight_smile: Somebody made a double phd on hiding the palette from the outside world.

Here’s how to beat the guy: :wink:

  1. Figure out the name of the local symbol in TColor object file:
matevz@black trunk-build> nm core/base/CMakeFiles/Base.dir/src/TColor.cxx.o|grep Palette
0000000000000078 b _ZGVZN12_GLOBAL__N_1L15TColor__PaletteEvE13globalPalette
0000000000000050 b _ZGVZN12_GLOBAL__N_1L20TColor__PalettesListEvE18globalPalettesList
0000000000000090 t _ZN12_GLOBAL__N_1L15TColor__PaletteEv
0000000000000120 t _ZN12_GLOBAL__N_1L20TColor__PalettesListEv
0000000000001d00 T _ZN6TColor10SetPaletteEiPif
00000000000004f0 T _ZN6TColor15GetColorPaletteEi
0000000000000080 b _ZZN12_GLOBAL__N_1L15TColor__PaletteEvE13globalPalette
0000000000000060 b _ZZN12_GLOBAL__N_1L20TColor__PalettesListEvE18globalPalettesList
0000000000000000 b _ZZN6TColor10SetPaletteEiPifE11paletteType
  1. Fire up your executable in gdb and stop it just before the problematic section, then follow this:
(gdb) p _ZN12_GLOBAL__N_1L15TColor__PaletteEv()
$1 = (TArrayI &) @0x7ffff7b99270: {
  <TArray> = {
    _vptr.TArray = 0x7ffff7b69e48 <vtable for TArrayI+16>,
    fN = 255,
    static fgIsA = {
      _M_b = {
        _M_p = 0x0
      }
    }
  },
  members of TArrayI:
  fArray = 0x65fee0,
  static fgIsA = {
    _M_b = {
      _M_p = 0x0
    }
  }
}
(gdb) p _ZN12_GLOBAL__N_1L15TColor__PaletteEv().fN
$2 = 255
(gdb) p &_ZN12_GLOBAL__N_1L15TColor__PaletteEv().fN
$3 = (Int_t *) 0x7ffff7b99278 <(anonymous namespace)::TColor__Palette()::globalPalette+8>
(gdb) watch *((Int_t *) 0x7ffff7b99278)
Hardware watchpoint 1: *((Int_t *) 0x7ffff7b99278)
(gdb) c
Continuing.

Note, here you should substitute in the name of the static function from the nm dump (depends on compiler) and later the address that you get from dumping the address of fN. This makes it much easier for gdb as it can only watch a memory location and does not have to execute some code on every instruction (I rarely had success by watching anything other that plain memory).

  1. Run the code that does the change … gdb should break and then you can look where this is coming from, e.g.:
root [0] Int_t MyPalette[100];
root [1] Double_t Red[]    = {0., 0.0, 1.0, 1.0, 1.0};
root [2] Double_t Green[]  = {0., 0.0, 0.0, 1.0, 1.0};
root [3] Double_t Blue[]   = {0., 1.0, 0.0, 0.0, 1.0};
root [4] Double_t Length[] = {0., .25, .50, .75, 1.0};
root [5] Int_t FI = TColor::CreateGradientColorTable(5, Length, Red, Green, Blue, 100);

Hardware watchpoint 1: *((Int_t *) 0x7ffff7b99278)

Old value = 255
New value = 100
TArrayI::Set (this=<optimized out>, n=<optimized out>) at /foo/matevz/root-dev/trunk/core/cont/src/TArrayI.cxx:123
123     }
(gdb) bt
#0  TArrayI::Set (this=<optimized out>, n=<optimized out>) at /foo/matevz/root-dev/trunk/core/cont/src/TArrayI.cxx:123
#1  0x00007ffff7780078 in TColor::SetPalette (ncolors=ncolors@entry=100, colors=colors@entry=0x12d4ac0, alpha=alpha@entry=1) at /foo/matevz/root-dev/trunk/core/base/src/TColor.cxx:3008
#2  0x00007ffff778b16a in TColor::CreateGradientColorTable (Number=5, Stops=0x7ffff7ff4240, Red=0x7ffff7ff41b0, Green=0x7ffff7ff41e0, Blue=0x7ffff7ff4210, NColors=100, alpha=1)
    at /foo/matevz/root-dev/trunk/core/base/src/TColor.cxx:2176
#3  0x00007ffff7fe80b1 in ?? ()
#4  0x0000000000000000 in ?? ()
(gdb)

What fun! :slight_smile:

What a ninja move, I’ll try tomorrow with fresh mind!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.