[ROOT] Simple event display using TGeo classes

From: paolo maestro (paolo.maestro@pi.infn.it)
Date: Fri Dec 05 2003 - 17:16:35 MET


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();
	 }
     }
      
}

   



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:17 MET