Difference between revisions of "ROOT Tips and Tricks"

From Hall A Wiki
Jump to: navigation, search
 
Line 8: Line 8:
 
1. Make the plot
 
1. Make the plot
  
2. Draw the graphical cut either by using the toolbar at the top of the screen under Edit, or by hard-coding it into your script, via:
+
2. Draw the graphical cut either by using the toolbar at the top of the screen under Edit->Toolbar->GraphicalCut (scissors), or by "hard-coding" it into your script, via:
  
  //snipped
+
  //snipped; this code has the computer wait for you to draw the cut. 
 
  TCutG* cutg;
 
  TCutG* cutg;
 
  cutg=(TCutG*)gPad->WaitPrimitive("CUTG","CutG"); // making cut, store to CUTG
 
  cutg=(TCutG*)gPad->WaitPrimitive("CUTG","CutG"); // making cut, store to CUTG

Latest revision as of 16:06, 20 July 2009

Add any useful code snippets, hints, tutorials, etc you use here!

How to save a graphical cut and implement it in another script:

1. Make the plot

2. Draw the graphical cut either by using the toolbar at the top of the screen under Edit->Toolbar->GraphicalCut (scissors), or by "hard-coding" it into your script, via:

//snipped; this code has the computer wait for you to draw the cut.  
TCutG* cutg;
cutg=(TCutG*)gPad->WaitPrimitive("CUTG","CutG"); // making cut, store to CUTG
c1->Update();                                    //update the canvas
TCutG *tmpg, *mycutg;
tmpg = (TCutG*)gROOT->GetListOfSpecials()->FindObject("CUTG");
mycutg = (TCutG*)(tmpg->Clone("mycutg"));
//NOTE: It is important to update the canvas where specified!

3. Now, save as "mycut" (right-click on the cut->SetName)

4. In command line:

  $ TFile f("filename.root","recreate");  //reconstructs the cut
  $ mycut.Write();                        //saves the cut to "filename.root"

4. In a new session/macro:

   TFile f("filename.root");
   TCutG* mycut = (TCutG*)gRoot->FindObject("mycut");

5. Apply cut as you would if it were a TString.