Using Graphical Cuts (bananas) in your analysis
Graphical cuts, as known as BANANAS, are widely used in Nuclear Physics analysis. Sometimes we want to make calculations with data that are inside a particular region in a 2-D spectrum. In this case, Graphical Cuts are the solution. Next I show an example on how to use them.Program banana.cxx
// Graphical cuts, as known as BANANAS, are // widely used in Nuclear Physics analysis. // Sometimes we want to make calculations with // data that are inside a particular region in // a 2-D spectrum. In this case, Graphical Cuts // are the solution. // // In order to use graphical cuts, you first // need to create them and save in a root file. // You can use PelTools to create such file, // create the graphical cuts and save them // to this file. Each saved cut (banana) will // be identified with an unique name in the file. // Please be aware of spaces and special symbols // that are also included as part of a name. // // After you create the file you need to open // it back, read the graphical cut and use in // your analysis. The program bellow is an // example on how to use graphical cuts in your // analysis program. // // Alexandre Suaide (2008) #include "TH2.h" #include "ScanRoot.h" #include "TCutG.h" TH1F* h1[100]; // I created one global variable named banana1 // that will hold the pointer to the TCutG object // that I will load from file. It is a global // variable in order to use in many functions. TCutG *banana1; void fillHistograms(short npar, float *par) { if(npar==0) return; // The next line tests if a pair of parameters // x=par[2] and y=par[1] is inside of the // geometrical region of the graphical cut // your created. It returns true if is inside. // // In this case, the histogram h1[0] will be // filled *ONLY* if the pair (par[2],par[1]) // is inside the graphical cut. // // The function to use is TCutG::IsInside(x,y) // if(banana1->IsInside(par[2],par[1])) { h1[0]->Fill(par[2]); } } void bookHistograms(ScanRoot* spm) { spm->cd(); h1[0] = new TH1F("h1","h1",10000,1000,2000); spm->fillHistograms = &fillHistograms; // This line opens the root file which contains // all the saved graphical cuts (bananas) // for reading TFile *f = new TFile("banana.root"); // next line loads the graphical cut named // "b1" from the file and store its pointer // in banana1. Note that banana1 is a global // variable in order to use it in other functions banana1 = (TCutG*)f->Get("b1"); // please note the the TFile is not closed. // if you close or delete the TFile, all the // objects inside it will be erased from memory return; }