void TrackerMap()
{
  int n;
float x1,y1,x2,y2,x3,y3,x4,y4;
int detid;
double x[4],y[4];

  FILE* cfile=fopen("coordinates1.txt","r");
//TPostScript MyPs("TrackerMap.ps",111);
//MyPs.Range(21,29);

  TCanvas *MyC = new TCanvas("MyC", "TrackerMap",3000,1600);
  gPad->SetFillColor(38);

// MyC->setFillColor(10);
gPad->Range(0,0,3000,1600);
  TRandom r;
  Int_t ncolors = gStyle->GetNumberOfColors();
  Int_t nmod = 0;

while( fscanf(cfile,"%i",&n) != EOF) {
  //cout << n << endl;
   nmod++;
   if ( n == 3) 
    {
     fscanf(cfile,"%f %f %f %f %f %f %i",&x1,&y1,&x2,&y2,&x3,&y3,&detid);
    	//cout << x1 << " " << y1 << " " << x2 << endl;
    	x[0]=x1;
    	x[1]=x2;
    	x[2]=x3;
    	y[0]=y1;
    	y[1]=y2;
    	y[2]=y3;

    }

   if ( n == 4) 
      {
	fscanf(cfile,"%f %f %f %f %f %f %f %f %i",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4,&detid);
   	// cout << x1 << " " << y1 << " " << x2 << endl;
    	x[0]=x1;
    	x[1]=x2;
    	x[2]=x3;
    	x[3]=x4;
    	y[0]=y1;
    	y[1]=y2;
    	y[2]=y3;
    	y[3]=y4;
	
      }
TPolyLine* pline = new TPolyLine(n,y,x);
pline->SetFillColor(ncolors*r.Rndm());
	  pline->SetLineWidth(0);
	pline->Draw("f");
        pline->SetUniqueID(detid);
   }
MyC->Print("NewTrackerMap.png");
MyC->AddExec("ex","ModuleClicked()");
//MyPs.Close();
}
void ModuleClicked() {
   //this action function is called whenever you move the mouse
   //it just prints the id of the picked triangle
   //you can add graphics actions instead
   int event = gPad->GetEvent();
   if (event != 11) return; //may be comment this line
   TObject *select = gPad->GetSelected();
   if (!select) return;
   if (select->InheritsFrom("TPolyLine")) {
      TPolyLine *pl = (TPolyLine*)select;
      printf("You have clicked module %d, color=%d\n",
              pl->GetUniqueID(),pl->GetFillColor());
   }
}


