Skip to content

Commit

Permalink
Add possibility to color by energy reconstructed particles
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Petric committed Nov 6, 2018
1 parent 5bffd7d commit d95cdf5
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 48 deletions.
12 changes: 12 additions & 0 deletions ced2go/ced2go-template-DD4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@
<parameter name="DrawHelixForPFOs" type="int">0 </parameter>
<!--draw a helix for Track objects: -1: none, 0: default, 1: atIP, 2: atFirstHit, 3: atLastHit, 4: atCalorimeter-->
<parameter name="DrawHelixForTrack" type="int">0 </parameter>
<!-- Color recunstructed particle by energy -->
<parameter name="ColorByEnergy" type="bool">false</parameter>
<!-- Minimal value for energy which will be represented as blue -->
<parameter name="ColorByEnergyMin" type="double">0.0</parameter>
<!-- Maximal value for energy which will be represented as red -->
<parameter name="ColorByEnergyMax" type="double">35.0</parameter>
<!-- Hue value that will be used to determine the pallete -->
<parameter name="ColorByEnergySaturation" type="double">1.0</parameter>
<!-- Brigtness value that will be used to determine the pallete -->
<parameter name="ColorByEnergyBrightness" type="double">1.0</parameter>
<!-- Automatically adjust event by event the blue to min energy and red to max energy of event -->
<parameter name="ColorByEnergyAutoColor" type="bool">false</parameter>
<!--Max R (mm) Extent for drawing Helix if UseTPCForLimitsOfHelix false-->
<parameter name="HelixMaxR" type="float">2000 </parameter>
<!--Max Z (mm) Extent for drawing Helix if UseTPCForLimitsOfHelix false-->
Expand Down
16 changes: 16 additions & 0 deletions include/ColorMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@

typedef void (*colorMapFunc)(unsigned int*,float,float,float);

typedef struct RgbColor
{
double r;
double g;
double b;
} RgbColor;

typedef struct HsvColor
{
double h;
double s;
double v;
} HsvColor;

class ColorMap{
public:
static void colorMap(unsigned int *rgb,float value,float min,float max);
Expand All @@ -24,6 +38,8 @@ class ColorMap{
static void blueColorMap(unsigned int *rgb,float value,float min,float max);
static colorMapFunc selectColorMap(int cmp);
static int RGB2HEX(int red, int green, int blue);
static RgbColor HsvToRgb(HsvColor in);
static unsigned long NumberToTemperature(double value, double min, double max, double s, double v);
};

#endif
48 changes: 27 additions & 21 deletions include/DDCEDViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,32 +113,38 @@ class DDCEDViewer : public Processor {
static const int Light = 11 ;
static const int Classic = 12 ;

StringVec _drawCollections ;
StringVec _drawCollectionsLayer ;
std::vector< DrawParameters > drawParameters ;
StringVec _drawCollections{} ;
StringVec _drawCollectionsLayer{} ;
std::vector< DrawParameters > drawParameters{} ;

//general options
int _nRun ;
int _nEvt ;
int _nRun = 0 ;
int _nEvt = 0;
//lcio options
bool _usingParticleGun ;
int _drawHelixForTracks ;
int _colorScheme ;
float _mcpECut ;
float _helix_max_r;
float _helix_max_z;
bool _useTrackerForLimitsOfHelix;
int _waitForKeyboard ;
int _drawHelixForPFOs;
int _useColorForHelixTracks ;
int _drawEllipsoidForPFOClusters ;
IntVec _colors ;
bool _usingParticleGun = false ;
int _drawHelixForTracks = 0 ;
int _colorScheme = 10 ;
bool _colorEnergy = false ;
double _colorEnergyMin = 0.0 ;
double _colorEnergyMax = 35.0 ;
double _colorEnergySaturation = 0.8 ;
double _colorEnergyValue = 0.8 ;
bool _colorEnergyAuto = false ;
float _mcpECut = 0.001 ;
float _helix_max_r = 2000 ;
float _helix_max_z = 2500 ;
bool _useTrackerForLimitsOfHelix = true ;
int _waitForKeyboard = 1 ;
int _drawHelixForPFOs = 0 ;
int _useColorForHelixTracks = 0 ;
int _drawEllipsoidForPFOClusters = 0 ;
IntVec _colors{} ;

//detector options
bool _begin;
StringVec _detailled;
StringVec _jets;
bool _surfaces;
bool _begin = false;
StringVec _detailled{};
StringVec _jets{};
bool _surfaces = false;
} ;


Expand Down
75 changes: 75 additions & 0 deletions src/ColorMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,78 @@ colorMapFunc ColorMap::selectColorMap(int cmp)
return colorMap;
};
}
// taken from https://stackoverflow.com/questions/3018313/algorithm-to-convert-rgb-to-hsv-and-hsv-to-rgb-in-range-0-255-for-both#comment66194776_14733008
RgbColor ColorMap::HsvToRgb(HsvColor in){
double hh, p, q, t, ff;
long i;
RgbColor out;

if(in.s <= 0.0) { // < is bogus, just shuts up warnings
out.r = in.v;
out.g = in.v;
out.b = in.v;
return out;
}
hh = in.h;
if(hh >= 360.0) hh = 0.0;
hh /= 60.0;
i = (long)hh;
ff = hh - i;
p = in.v * (1.0 - in.s);
q = in.v * (1.0 - (in.s * ff));
t = in.v * (1.0 - (in.s * (1.0 - ff)));

switch(i) {
case 0:
out.r = in.v;
out.g = t;
out.b = p;
break;
case 1:
out.r = q;
out.g = in.v;
out.b = p;
break;
case 2:
out.r = p;
out.g = in.v;
out.b = t;
break;

case 3:
out.r = p;
out.g = q;
out.b = in.v;
break;
case 4:
out.r = t;
out.g = p;
out.b = in.v;
break;
case 5:
default:
out.r = in.v;
out.g = p;
out.b = q;
break;
}
return out;
}

// Convert a number between min in max to a color between blue(min) and red(max)
unsigned long ColorMap::NumberToTemperature(double value, double min, double max, double s, double v){
HsvColor hsv;

if( value > max ){
hsv.h = max;
}else if ( value < min ){
hsv.h = min;
}
hsv.h = 270 - ( value - min ) / ( max - min ) * 270;
hsv.s=s;
hsv.v=v;

RgbColor rgb = ColorMap::HsvToRgb(hsv);

return ColorMap::RGB2HEX((int)(rgb.r*255),(int)(rgb.g*255),(int)(rgb.b*255));
}
Loading

0 comments on commit d95cdf5

Please sign in to comment.