FirstContour.C

Go to the documentation of this file.
00001 // make a contour plot and get the first contour in a TPolyMarker
00002 void FirstContour()
00003 {
00004    //this macro generates a color contour plot by selecting entries
00005    //from an ntuple file.
00006    //The TGraph object corresponding to the first contour line is 
00007    //accessed and displayed into a separate canvas.
00008    //Author: Rene Brun
00009    
00010    TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
00011    dir.ReplaceAll("FirstContour.C","../hsimple.C");
00012    dir.ReplaceAll("/./","/");
00013    if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data());
00014    TFile *file = (TFile*)gROOT->ProcessLineFast("hsimple(1)");
00015    if (!file) return;
00016    TTree *ntuple = (TTree*)file->Get("ntuple");
00017    
00018    TCanvas *c1 = new TCanvas("c1","Contours",10,10,800,600);
00019    gStyle->SetPalette(1);
00020    ntuple->Draw("py:px","px*px+py*py < 20", "contz,list");
00021    
00022    //we must call Update to force the canvas to be painted.  When 
00023    //painting the contour plot, the list of contours is generated
00024    //and a reference to it added to the Root list of special objects
00025    c1->Update();
00026       
00027    TCanvas *c2 = new TCanvas("c2","First contour",100,100,800,600);
00028    
00029    
00030    TObjArray *contours = 
00031       (TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours");
00032    if (!contours) return;
00033    TList *lcontour1 = (TList*)contours->At(0);
00034    if (!lcontour1) return;
00035    TGraph *gc1 = (TGraph*)lcontour1->First();
00036    if (!gc1) return;
00037    if (gc1->GetN() < 10) return;
00038    gc1->SetMarkerStyle(21);
00039    gc1->Draw("alp");
00040    
00041    //We make a TCutG object with the array obtained from this graph
00042    TCutG *cutg = new TCutG("cutg",gc1->GetN(),gc1->GetX(),gc1->GetY());
00043    
00044    //We create a polymarker object with npmax points.
00045    const Int_t npmax = 50000;
00046    TPolyMarker *pm = new TPolyMarker(npmax);
00047    Int_t np = 0;
00048    while(1) {
00049       Double_t x = -4 +8*gRandom->Rndm();
00050       Double_t y = -4 +8*gRandom->Rndm();
00051       if (cutg->IsInside(x,y)) {
00052          pm->SetPoint(np,x,y);
00053          np++;
00054          if (np == npmax) break;
00055       }
00056    }
00057    pm->Draw();      
00058 }          
00059 //--------------end of script contours.C

Generated on Tue Jul 5 15:44:26 2011 for ROOT_528-00b_version by  doxygen 1.5.1