Difference between revisions of "ROOT Tips and Tricks"

From Hall A Wiki
Jump to: navigation, search
(Add any useful code snippets, hints, tutorials, etc you use here!)
Line 22: Line 22:
  
 
4. In command line:  
 
4. In command line:  
   $ TFile f("filename.root","recreate");
+
   $ TFile f("filename.root","recreate"); //reconstructs the cut
   $ mycut.Write();
+
   $ mycut.Write();                       //saves the cut to "filename.root"
  
 
4. In a new session/macro:
 
4. In a new session/macro:

Revision as of 16:05, 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, or by hard-coding it into your script, via:

//snipped
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.