Skip to content

Inconsistent points size #19

@dudarboh

Description

@dudarboh

Problem

I attempted to display the calorimeter hits with the size of the hit being proportional to its energy.
I have noticed weird inconsistencies in the point sizes, so I did a test.

Reproducible

Append the following code to your Marlin processor.
Note 1: You need MarlinUtil as the dependency.
Note 2: You need to run InitDD4hep processor upstream if you want to draw any geometry

#include "DDMarlinCED.h"

void YourMarlinProcessor::processEvent( EVENT::LCEvent * evt ) {
    DDMarlinCED::newEvent(this);

    dd4hep::Detector& detector = dd4hep::Detector::getInstance();
    DDMarlinCED::drawDD4hepDetector( detector, false, std::vector<std::string>{""} );

    DDCEDPickingHandler& pHandler = DDCEDPickingHandler::getInstance();
    pHandler.update(evt);

    // ced_hit( x, y, z, type, size, color);
    auto x = 800.;
    auto y = 0.;
    auto blue = 0x2f33ba;
    ced_hit(x, y, -1000, CED_HIT_POINT, 0.01, blue);
    ced_hit(x, y, -600, CED_HIT_POINT, 0.1, blue);
    ced_hit(x, y, -200, CED_HIT_POINT, 0.5, blue);
    ced_hit(x, y, 0, CED_HIT_POINT, 1, blue);
    ced_hit(x, y, 200, CED_HIT_POINT, 3.1415, blue);
    ced_hit(x, y, 600, CED_HIT_POINT, 10, blue);
    ced_hit(x, y, 1000, CED_HIT_POINT, 50, blue);

    DDMarlinCED::draw(this, 1);
}

Output

Image

For some reason, the point sizes below 1 (0.01, 0.1, and 0.5) all appear to be the size of the largest point in the event.
In this case, they look like size 50. I have also tried with the last point being the size of 100 and 1000, and points with the size below one change their size to fit the size of the largest point.
The point with size 3.14 is there to make sure that it is not the int/float type problem

Here are the tests with other hit types. The rest look similar to each other.

CED_HIT_CROSS

    ced_hit(x, y, -1000, CED_HIT_CROSS, 0.01, blue);
    ced_hit(x, y, -600, CED_HIT_CROSS, 0.1, blue);
    ced_hit(x, y, -200, CED_HIT_CROSS, 0.5, blue);
    ced_hit(x, y, 0, CED_HIT_CROSS, 1, blue);
    ced_hit(x, y, 200, CED_HIT_CROSS, 10, blue);
    ced_hit(x, y, 600, CED_HIT_CROSS, 100, blue);
    ced_hit(x, y, 1000, CED_HIT_CROSS, 1000, blue);
Image

Notably, the sizes act very differently for CED_HIT_CROSS and CED_HIT_POINT. The sizes below 100 are barely visible, and the CED_HIT_CROSS with the size of 100 is visually is like a CED_HIT_POINT with the size 3.14.

CED_HIT_BOX

    ced_hit(x, y, -1000, CED_HIT_BOX, 0.01, blue);
    ced_hit(x, y, -600, CED_HIT_BOX, 0.1, blue);
    ced_hit(x, y, -200, CED_HIT_BOX, 0.5, blue);
    ced_hit(x, y, 0, CED_HIT_BOX, 1, blue);
    ced_hit(x, y, 200, CED_HIT_BOX, 10, blue);
    ced_hit(x, y, 600, CED_HIT_BOX, 100, blue);
    ced_hit(x, y, 1000, CED_HIT_BOX, 1000, blue);
Image

CED_HIT_VXD

    ced_hit(x, y, -1000, CED_HIT_VXD, 0.01, blue);
    ced_hit(x, y, -600, CED_HIT_VXD, 0.1, blue);
    ced_hit(x, y, -200, CED_HIT_VXD, 0.5, blue);
    ced_hit(x, y, 0, CED_HIT_VXD, 1, blue);
    ced_hit(x, y, 200, CED_HIT_VXD, 10, blue);
    ced_hit(x, y, 600, CED_HIT_VXD, 100, blue);
    ced_hit(x, y, 1000, CED_HIT_VXD, 1000, blue);
Image CED_HIT_VXD didn't work for me at all with any size...

CED_HIT_STAR

    ced_hit(x, y, -1000, CED_HIT_STAR, 0.01, blue);
    ced_hit(x, y, -600, CED_HIT_STAR, 0.1, blue);
    ced_hit(x, y, -200, CED_HIT_STAR, 0.5, blue);
    ced_hit(x, y, 0, CED_HIT_STAR, 1, blue);
    ced_hit(x, y, 200, CED_HIT_STAR, 10, blue);
    ced_hit(x, y, 600, CED_HIT_STAR, 100, blue);
    ced_hit(x, y, 1000, CED_HIT_STAR, 1000, blue);
Image

OpenGL code that draws points:

CED/src/server/ced_srv.cc

Lines 1275 to 1416 in 41166e9

static void ced_draw_hit(CED_Hit *h){
GLfloat d;
CED_Point p_new = fisheye_transform(h->p.x, h->p.y, h->p.z, fisheye_alpha);
float x = p_new.x;
float y = p_new.y;
float z = p_new.z;
if(setting.phi_projection){
//phi_projection is on
y = y > 0 ? sqrt(x*x + y*y) : -1*sqrt(x*x + y*y);
x = 0;
}
if(setting.z_projection){
z=0;
}
//printf("hit on layer: %i\n", h->layer);
if(!IS_VISIBLE(h->layer)){
return;
}
// printf("Draw hit at : %f %f %f type = %d and ced_visible_layers = %d \n",h->p.x,h->p.y,h->p.z,h->type,ced_visible_layers);
ced_color(h->color);
glDisable(GL_BLEND);
// std::cout << " size=" << h->size << " screenshot_sections " << setting.screenshot_sections
// << " type=" << h->type << std::endl;
switch(h->type){
case CED_HIT_CROSS:
case CED_HIT_BOX:
case CED_HIT_VXD:
case CED_HIT_STAR:
//glLineWidth(1.);
glLineWidth(1.);
glBegin(GL_LINES);
if(h->type == CED_HIT_CROSS){
// printf("cross type == %d \n",(h->type & CED_HIT_CROSS));
// d=h->size/2*setting.screenshot_sections;
d=((GLfloat)h->size)/20.*setting.screenshot_sections;
glVertex3f(x-d,y-d,z);
glVertex3f(x+d,y+d,z);
glVertex3f(x+d,y-d,z);
glVertex3f(x-d,y+d,z);
}
else if(h->type == CED_HIT_STAR){
// printf("cross type == %d \n",(h->type & CED_HIT_CROSS));
// d=h->size/2*setting.screenshot_sections;
d=((GLfloat)h->size)/20.*setting.screenshot_sections;
#if 0 // hauke's version
glVertex3f(x-d,y-d,z+d);
glVertex3f(x+d,y+d,z-d);
glVertex3f(x+d,y-d,z+d);
glVertex3f(x-d,y+d,z-d);
glVertex3f(x+d,y+d,z+d);
glVertex3f(x-d,y-d,z-d);
glVertex3f(x-d,y+d,z+d);
glVertex3f(x+d,y-d,z-d);
#else // vassillie's version
glVertex3f(x-d,y,z);
glVertex3f(x+d,y,z);
glVertex3f(x,y-d,z);
glVertex3f(x,y+d,z);
glVertex3f(x,y,z-d);
glVertex3f(x,y,z+d);
#endif
}
else if(h->type == CED_HIT_VXD){
// printf("cross type == %d \n",(h->type & CED_HIT_CROSS));
// d=h->size/2*setting.screenshot_sections;
// d=((GLfloat)h->size)/20.*setting.screenshot_sections;
d=0.005;
#if 1
glVertex3f(x-d,y-d,z+d);
glVertex3f(x+d,y+d,z-d);
glVertex3f(x+d,y-d,z+d);
glVertex3f(x-d,y+d,z-d);
glVertex3f(x+d,y+d,z+d);
glVertex3f(x-d,y-d,z-d);
glVertex3f(x-d,y+d,z+d);
glVertex3f(x+d,y-d,z-d);
#endif
//
// double sizes[3]={0.1, 0.1, 0.1};
// double center[3]={x, y, z};
// ced_geobox( sizes, center, 0xff00ff );
//
#if 0
std::cout << " calling ced_draw_geobox_r_solid..." << std::endl;
CED_GeoBoxR abox;
abox.sizes[0]=0.005 ; abox.sizes[1]=0.015; abox.sizes[2]=0.005;
abox.center[0]=x; abox.center[1]=y; abox.center[2]=z;
abox.color=0xff00ff;
abox.rotate[0]=0.0 ; abox.rotate[1]=0.0; abox.rotate[2]=0.0;
ced_draw_geobox_r_solid(&abox);
#endif
} else {
// printf("star type == %d \n",(h->type & CED_HIT_STAR));
// d=h->size/2.*setting.screenshot_sections;
d=((GLfloat)h->size)/20.*setting.screenshot_sections;
glVertex3f(x-d,y,z);
glVertex3f(x+d,y,z);
glVertex3f(x,y-d,z);
glVertex3f(x,y+d,z);
glVertex3f(x,y,z-d);
glVertex3f(x,y,z+d);
}
glEnd();
break;
default:
glPointSize((GLfloat)h->size*setting.screenshot_sections);
glBegin(GL_POINTS);
//glVertex3fv(&p_new.x);
glVertex3f(x,y,z);
glEnd();
}
//glEnd();
glEnable(GL_BLEND);
ced_add_objmap(&h->p,5,h->lcioID,h->layer,0);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions