Re: How to get an Histogram ?

From: Jordi Nadal <jnadal_at_ifae.es>
Date: Thu, 8 Sep 2011 18:52:36 +0200


Hello Eduard,

I think you are complete right.

A delete histo; directly fails… so I am trying to set a different histo each iteration.

Thanks all again.

Cheers,
JOrdi

On Sep 8, 2011, at 4:43 PM, Eduard Avetisyan wrote:

> 
> 
> Hi Jordi,
> 
> Your problem is that the histogram actually doesn't get overwritten in the 
> subsequent calls. In your script, you first draw QCDnorm_corr_mu in 
> histogram named "histo", and then you put the QCDnorm_corr_mu_btag into 
> the SAME histogram. It's true, the contents is overwritten, but the 
> histogram limits are not adjusted to the new variable. It doesn't happen 
> if you wouldn't indicate the histogram name and use the default "htemp" 
> which has the corresponding flag of resetting also the axis with the new 
> data being filled. 
> 
> In short - if you would try in your interactive test the following 
> sequence:
> 
> root [1] HangingTree->Draw("QCDnorm_corr_mu>>histo")
> root [2] histo->GetMean()
> root [1] HangingTree->Draw("QCDnorm_corr_mu_btag>>histo")
> root [2] histo->GetMean()
> 
> you would see the same results as your script produces.
> If you want CORRECT values for the mean, either use different names for 
> the histograms, or take care to actually delete "histo" between fills.
> 
> Hope this helps,
> 
> 	Eduard
> 
> 
> On Thu, 8 Sep 2011, Jordi Nadal wrote:
> 

>> Hi Suvayu,
>>
>> Thanks again for your time.
>>
>> I just ran your macro.
>>
>> [jnadal_at_at305 JetFitter]$ root test.C
>>
>> Welcome to the ATLAS rootlogon.C
>> root [0]
>> Processing test.C...
>> Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
>> QCDnorm_corr_mu -0.157223
>> QCDnorm_corr_mu_btag 0.106851
>> root [1] .q
>> [jnadal_at_at305 JetFitter]$ root PSE/JO_muon_PSE_RbFree/sumRootFile.root
>>
>> Welcome to the ATLAS rootlogon.C
>> root [0]
>> Attaching file PSE/JO_muon_PSE_RbFree/sumRootFile.root as _file0...
>> root [1] HangingTree->Draw("QCDnorm_corr_mu_btag>>histo")
>> Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
>> root [2] histo->GetMean()
>> (const Double_t)1.69030729412928876e-01
>> root [3]
>>
>> My problem is that I don't get the same number using the macro for variable (QCDnorm_corr_mu_btag) than looking at it in the root file.
>>
>> Thanks,
>> Jordi
>>
>>
>> On Sep 8, 2011, at 2:46 PM, suvayu ali wrote:
>>
>>> Hi Jordi,
>>> 
>>> I am not sure about your issue as I don't know what exactly you are
>>> trying to achieve. However after simplifying your example macro I
>>> found two errors:
>>> 
>>> {
>>> int N = 2;
>>> TString parnames[N] = { "QCDnorm_corr_mu", "QCDnorm_corr_mu_btag"};
>>> 
>>> 
>>> TFile *file = TFile::Open("PSE/JO_muon_PSE_RbFree/sumRootFile.root");
>>> TTree* HangingTree = (TTree*) file->Get("HangingTree");
>>> 
>>> for(int i=0; i<N;i++){
>>>   TString raw = parnames[i];
>>>   // here the histograms get overwritten by subsequent calls to Draw()
>>>   HangingTree->Draw(raw+">>histo");
>>>   // this line does multiple declaration of h as the loop proceeds
>>>   // this is not correct C++ but might be forgivable in CINT, not sure
>>>   TH1D *h = (TH1D*) gROOT->FindObject("histo");
>>>   std::cout << raw << " " << h->GetMean() << std::endl;
>>> }
>>> }
>>> 
>>> I hope this helps.
>>> 
>>> -- 
>>> Suvayu
>>> 
>>> Open source is the future. It sets us free.

>>
>>
Received on Thu Sep 08 2011 - 18:52:45 CEST

This archive was generated by hypermail 2.2.0 : Thu Sep 08 2011 - 23:50:01 CEST