[quote=âpcanalâ]owEngEvents->Draw("PositionX>>posx","energy >=2.1 && energy <=3.8");
TH1 *posx_histo = (TH1*)gPad->GetListOfPrimitives()->FindObject("pox");
Cheers,
Philippe.[/quote]
That was exactly what I wanted - thank you very much. It seems to be faster to draw a histogram this way than looping though events.
However, I have a small problem/observation:
I tried both these methods and I notice the histograms created look different.
Method 1: Looping though events in a TREE:
[code]TH1I *RH = new TH1I("RH","RSector ID",40,0,39);
Int_t nentries = RootTree->GetEntries();
Int_t eventno=0;
Int_t Xposition;
Float_t energy;
RootTree->SetBranchAddress("energy", &energy);
RootTree->SetBranchAddress("Xposition", &Xposition);
for ( eventno = 0; eventno < nentries; eventno += 1 ) {
RootTree->GetEntry(eventno);
if ((energy >= ELow) && (energy <= EHigh)) {
RH->Fill(Xposition);
}
}
RH->SaveAs("histloop.C");[/code]
Method 2: Using Cuts:
[code] char Conditions[500];
sprintf(Conditions, âenergy >= %fâ,ELow);
sprintf(Conditions, â%s && energy <= %fâ,Conditions,EHigh);
printf ( âCut = %s\nâ,Conditions);
RootTree->Draw("Xposition>>RID",Conditions);
TH1 *rid = (TH1*)gPad->GetListOfPrimitives()->FindObject("RID");
rid->SaveAs("histcuts.C");[/code]
Then I plotted the two output files (histloop.C and histcuts.C) using root:
root [0] .x histcuts.C
root [0] .x histloop.C
and was suprised to see that they actually differ in the x-axis. The one using cuts is offset by half a bin.
The screen shot is shown below:

I added the red line to show the offset between the two methods. The one on the top is the histogram I expect from the data.
Any idea why this happens? How do I fix this so that using cuts has the same histogram as the one using loops.
Many thanks,
Karthik