Hi Chris,
I do not see any problems with booleans. In the attachment you will
find a variant of the standard tutorial tree1.C with a boolean variable.
You can play with it with the type of selection in your mail.
I take once more this opportunity to request that:
- the ROOT version number and the machine be specified in the mail
- also always specify a subject in the mail. This facilitates the archiving
and the search.
Rene Brun
Chris Roat wrote:
>
> Hello Rooters,
>
> I am not clear on to use booleans work in complex (>1 cut) selection
> expressions. For instance, if I have a tree with 2 floats, floatA and
> floatB, and a bool, boolA, I try the following 4 cases.
>
> Note: In my tree, all floatB's are greater than zero. The cut is included
> to illustrate my problem. boolA's are both true and false.
>
> a) tree->Draw("floatA", "floatB>0")
> b) tree->Draw("floatA", "boolA")
> c) tree->Draw("floatA", "(floatB>0)&&(boolA)")
> d) tree->Draw("floatA", "(floatB>0)*(boolA)")
>
> As expected, a) produces a plot of the full tree.
>
> As expected, b) produces a plot of the tree subset where bool is true.
>
> NOT as expected, c) & d) produced a plot of the whole tree. Somehow my
> bool test is not included in the selection criteria.
>
> What am I doing incorrectly?
>
> Thanks for your help,
> Chris
#include "TFile.h"
#include "TTree.h"
#include "TBrowser.h"
#include "TH2.h"
#include "TRandom.h"
// This example is a variant of hsimple.C but using a TTree instead
// of a TNtuple. It shows :
// -how to fill a Tree with a few simple variables.
// -how to read this Tree
// -how to browse and analyze the Tree via the TBrowser and TTreeViewer
// This example can be run in many different ways:
// way1: .x tree1.C using the CINT interpreter
// way2: .x tree1.C++ using the automatic compiler interface
// way3: .L tree1.C or .L tree1.C++
// tree1()
// One can also run the write and read parts in two separate sessions.
// For example following one of the sessions above, one can start the session:
// .L tree1.C
// tree1r();
//
// Author: Rene Brun
void tree1w()
{
//create a Tree file tree1.root
//create the file, the Tree and a few branches
TFile f("tree1.root","recreate");
TTree t1("t1","a simple Tree with simple variables");
Float_t px, py, pz;
Double_t random;
Int_t ev;
Bool_t boolA;
t1.Branch("px",&px,"px/F");
t1.Branch("py",&py,"py/F");
t1.Branch("pz",&pz,"pz/F");
t1.Branch("random",&random,"random/D");
t1.Branch("ev",&ev,"ev/I");
t1.Branch("boolA",&boolA,"BoolA/b");
//fill the tree
for (Int_t i=0;i<10000;i++) {
gRandom->Rannor(px,py);
pz = px*px + py*py;
random = gRandom->Rndm();
ev = i;
if (i%10 < 3) boolA = kTRUE;
else boolA = kFALSE;
t1.Fill();
}
//save the Tree header. The file will be automatically closed
//when going out of the function scope
t1.Write();
}
void tree1r()
{
//read the Tree generated by tree1w and fill two histograms
//note that we use "new" to create the TFile and TTree objects !
//because we want to keep these objects alive when we leave this function.
TFile *f = new TFile("tree1.root");
TTree *t1 = (TTree*)f->Get("t1");
Float_t px, py, pz;
Double_t random;
Int_t ev;
t1->SetBranchAddress("px",&px);
t1->SetBranchAddress("py",&py);
t1->SetBranchAddress("pz",&pz);
t1->SetBranchAddress("random",&random);
t1->SetBranchAddress("ev",&ev);
//create two histograms
TH1F *hpx = new TH1F("hpx","px distribution",100,-3,3);
TH2F *hpxpy = new TH2F("hpxpy","py vs px",30,-3,3,30,-3,3);
//read all entries and fill the histograms
Int_t nentries = (Int_t)t1->GetEntries();
for (Int_t i=0;i<nentries;i++) {
t1->GetEntry(i);
hpx->Fill(px);
hpxpy->Fill(px,py);
}
//we do not close the file. We want to keep the generated histograms
//we open a browser and the TreeViewer
if (gROOT->IsBatch()) return;
new TBrowser();
t1->StartViewer();
// in the browser, click on "ROOT Files", then on "tree1.root".
// you can click on the histogram icons in the right panel to draw them.
// in the TreeViewer, follow the instructions in the Help button.
}
void tree1() {
tree1w();
tree1r();
}
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:56 MET