Hi Paolo,
Interesting idea to make use of TGeo classes in this way. The package is
however not meant for that and for sure a lego plot would be much more
efficient. On the other hand I agree that you might get some extra
flexibility with 3D objects.
Anyhow, your macro produces a crash because it is not enough to delete
the boxes; the node hierarchy that you have created is still there
having orphan shape pointers. It is not very good to remove shapes after
the geometry is closed.
I propose an other way of doing the same thing - you create all
shapes/volumes at the beginning and then change the size/matrices for
the boxes that represent a hit. Have a look at the attached macro. You
run it once and then call MakeEvents() as many times you want.
Best regards,
Andrei
paolo maestro wrote:
> Hi Rooters,
> I'm trying to do a simple event display for
> a pixels array detector using the ROOT geometry package.
> In each event a parallelepiped is associated to each hit with height
> proportional to the energy deposit and location corresponding
> to the hit pixel. At the end of the event I would like to clear all the
> hits (parallelepipeds).
> I send you the code in attachment with a dummy generation of events.
> The program crashes when it enters the loop aimed to clear the hits.
> Why ? Is there an alternative way to do it?
> Thanks
> Cheers
> Paolo
>
> P.S. I'm using the latest version of ROOT.
>
>
>
>
> ------------------------------------------------------------------------
>
> void EventDisplay()
> {
> //--- Definition of a simple geometry
> TCanvas* c1=new TCanvas("c1","",700,700);
> gSystem->Load("libGeom");
> TGeoManager *gGeoManager = new TGeoManager("ROOT", "Simple geometry");
>
> //--- define materials
> TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0,0,0);
> TGeoMedium *Vacuum = new TGeoMedium("Vacuum",1, matVacuum);
>
> //Experimental hall
> TGeoVolume *EXPH = gGeoManager->MakeBox("EXPH",Vacuum, 600., 600., 600.);
> gGeoManager->SetTopVolume(EXPH);
>
> const Int_t Nrow=56,Ncol=52;
> float xside=1.5,yside=1.3;
>
> //Matrix of pixels
> TGeoVolume *SCDP=gGeoManager->MakeBox("SCDP",Vacuum,xside/2,yside/2,0.04/2);
> SCDP->SetVisibility(1);
> SCDP->SetLineColor(3);
>
> for(int i=0;i<Nrow;i++)
> {
> for(int j=0;j<Ncol;j++)
> {
> float posX=-Ncol*xside/2+(2*j+1)*xside/2;
> float posY=-Nrow*yside/2+(2*i+1)*yside/2;
> float posZ=0;
> EXPH->AddNode(SCDP,i*Ncol+j,new TGeoTranslation(posX,posY,posZ));
> }
> }
>
> gGeoManager->CloseGeometry();
> gGeoManager->SetVisLevel(4);
> EXPH->Draw();
>
>
> //generation of 10 dummy events with at most 20 associated hits
> TGeoVolume *hit[20];
> gRandom->SetSeed(0);
> for(int evt=0;evt<10;evt++)
> {
> int nhit=int(20*gRandom->Rndm());
> cout<<"Nhit "<<nhit<<endl;
> for(int i=0;i<nhit;i++)
> {
> int row=int(Nrow*gRandom->Rndm());
> int col=int(Ncol*gRandom->Rndm());
> float edep=gRandom->Rndm()*10;
> hit[i]=gGeoManager->MakeBox("hit",Vacuum,xside/2,yside/2,edep/2);
>
> hit[i]->SetVisibility(1);
> hit[i]->SetLineColor(2);
> float posX=-Ncol*xside/2+(2*col+1)*xside/2;
> float posY=-Nrow*yside/2+(2*row+1)*yside/2;
> EXPH->AddNode(hit[i],i+1,new TGeoTranslation(posX,posY,edep/2));
> }
>
> for(int i=0;i<nhit;i++)
> {
> char buf[10];
> sprintf(buf,"hit_%d",i+1);
> EXPH->GetNode(buf)->Clear();
> hit[i]->ClearShape();
> }
> }
>
> }
>
>
const Int_t Nrow=56,Ncol=52;
float xside=1.5,yside=1.3;
void EventDisplay()
{
//--- Definition of a simple geometry
TCanvas* c1=new TCanvas("c1","",700,700);
gSystem->Load("libGeom");
TGeoManager *gGeoManager = new TGeoManager("ROOT", "Simple geometry");
//--- define materials
TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0,0,0);
TGeoMedium *Vacuum = new TGeoMedium("Vacuum",1, matVacuum);
//Experimental hall
TGeoVolume *EXPH = gGeoManager->MakeBox("EXPH",Vacuum, 600., 600., 600.);
gGeoManager->SetTopVolume(EXPH);
//Matrix of pixels
// TGeoVolume *SCDP=gGeoManager->MakeBox("SCDP",Vacuum,xside/2,yside/2,0.04/2);
// SCDP->SetVisibility(1);
// SCDP->SetLineColor(3);
TGeoVolume *hit;
TGeoNode *node;
TGeoTranslation *trans;
for(int i=0;i<Nrow;i++)
{
for(int j=0;j<Ncol;j++)
{
float posX=-Ncol*xside/2+(2*j+1)*xside/2;
float posY=-Nrow*yside/2+(2*i+1)*yside/2;
float posZ=0;
hit = gGeoManager->MakeBox("HIT",Vacuum, xside/2,yside/2,0.04/2);
hit->SetLineColor(kGreen);
trans = new TGeoTranslation(posX,posY,posZ);
EXPH->AddNode(hit, i*Ncol+j, trans);
}
}
gGeoManager->CloseGeometry();
MakeEvents();
EXPH->Draw();
// EXPH->Raytrace(); // activate this if you want raytraced-based solid mode in TPad
}
void MakeEvents() {
//generation of 10 dummy events with at most 20 associated hits
ResetDisplay();
TGeoNode *node;
TGeoTranslation *trans;
TGeoVolume *EXPH = gGeoManager->GetVolume("EXPH");
gRandom->SetSeed(0);
for(int evt=0;evt<10;evt++)
{
int nhit=int(20*gRandom->Rndm());
cout<<"Nhit "<<nhit<<endl;
for(int i=0;i<nhit;i++)
{
int row=int(Nrow*gRandom->Rndm());
int col=int(Ncol*gRandom->Rndm());
float edep=gRandom->Rndm()*10;
node = EXPH->GetNode(row*Ncol+col);
box = (TGeoBBox*)(node->GetVolume()->GetShape());
trans = (TGeoTranslation*)node->GetMatrix();
box->SetBoxDimensions(xside/2,yside/2,edep/2);
trans->SetDz(edep/2);
node->GetVolume()->SetLineColor(2);
}
}
EXPH->Voxelize(""); // now the new geometry is valid for tracking, so you can do
// even raytracing
if (gPad) {
gPad->Modified();
gPad->Update();
}
}
void ResetDisplay()
{
TGeoNode *node;
TGeoBBox *box;
TGeoVolume *EXPH = gGeoManager->GetVolume("EXPH");
TGeoTranslation *trans;
for(int i=0;i<Nrow;i++) {
for(int j=0;j<Ncol;j++) {
node = EXPH->GetNode(i*Ncol+j);
box = (TGeoBBox*)(node->GetVolume()->GetShape());
trans = (TGeoTranslation*)node->GetMatrix();
box->SetBoxDimensions(box->GetDX(),box->GetDY(),0.04/2);
trans->SetDz(0);
node->GetVolume()->SetLineColor(kGreen);
}
}
}
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:17 MET