Hi experts,
I am trying to fill a histogram From a leaf of a TTree but it doesn’t work as it should. When trying to fill the Histogram in the interactive mode (just typing root -l and then typing the code to the terminal) it works well. I load my .root file and call the TTree and write
evt->Draw(“TofWHitData.fTime.fTime”)
But then I wanted to write a small code which I want to expand,as I want to make various fits. But there it doesn’t work. My code:
void scratch(){
Double_t x;
TFile* file = TFile::Open("data_s444_main0038.root");
TTree* t1 = (TTree*)file->Get("evt");
TH1D* h_raw_pos = new TH1D("h_raw_pos","SofToFWSingleTcalData.fRawTimeNs",10000,-10,10);
t1->SetBranchAddress("SofToFWSingleTcalData.fRawTimeNs",&x);
Int_t nentries = (Int_t)t1->GetEntries();
for (Int_t i = 0; i<nentries;i++) {
t1->GetEntry(i);
h_raw_pos->Fill(x);
}
TCanvas* c2 = new TCanvas();
h_raw_pos->Draw();
}
Here I get the following Histogram:
All the values are squeezed to 0.
I tried different ways to implement this code but I still don’t know why I can’t access the data of the leaf of the TTree properly. I have read something about MakeClass but I don’t know how that works and if it is the correct way…
Thanks in Advance
Tobias
Attach the oputput from: t1->Print();
See also:
Hi Wile_E_Coyote,
here the output form t1->Print();
******************************************************************************
*Tree :evt : /cbmout *
*Entries : 2810612 : Total = 6686598088 bytes File Size = 581875660 *
* : : Tree compression factor = 11.50 *
******************************************************************************
*Br 0 :EventHeader. : FairEventHeader cbmout.Event.EventHeader. *
*Entries : 2810612 : Total Size= 168664338 bytes File Size = 6085090 *
*Baskets : 257 : Basket Size= 17175531 bytes Compression= 27.72 *
*............................................................................*
*Branch :R3BEventHeader : cbmout.EventHeader.R3BEventHeader *
*Entries : 2810612 : BranchElement (see below) *
*............................................................................*
*Br 1 :R3BEventHeader : BASE cbmout.EventHeader.R3BEventHeader *
*Entries : 2810612 : Total Size= 174286858 bytes File Size = 6622059 *
*Baskets : 264 : Basket Size= 17175531 bytes Compression= 26.32 *
*............................................................................*
*Br 2 :R3BEventHeader.fEventno : *
* | UInt_t cbmout.EventHeader.R3BEventHeader.fEventno *
*Entries : 2810612 : Total Size= 11247137 bytes File Size = 3916534 *
*Baskets : 39 : Basket Size= 673280 bytes Compression= 2.87 *
*............................................................................*
*Br 3 :R3BEventHeader.fTrigger : *
* | UInt_t cbmout.EventHeader.R3BEventHeader.fTrigger *
*Entries : 2810612 : Total Size= 11247137 bytes File Size = 64551 *
*Baskets : 39 : Basket Size= 673280 bytes Compression= 174.22 *
*............................................................................*
*Br 4 :R3BEventHeader.fTimeStamp : *
* | ULong_t cbmout.EventHeader.R3BEventHeader.fTimeStamp *
*Entries : 2810612 : Total Size= 22491336 bytes File Size = 104722 *
*Baskets : 54 : Basket Size= 1346048 bytes Compression= 214.76 *
*............................................................................*
*Br 5 :R3BEventHeader.fTpat : *
* | UShort_t cbmout.EventHeader.R3BEventHeader.fTpat *
*Entries : 2810612 : Total Size= 5625042 bytes File Size = 28324 *
*Baskets : 32 : Basket Size= 336896 bytes Compression= 198.56 *
*............................................................................*
...
*Br 101 :SofToFWSingleTcalData : Int_t cbmout.SofToFW.SofToFWSingleTcalData_*
*Entries : 2810612 : Total Size= 22639827 bytes File Size = 4309622 *
*Baskets : 1068 : Basket Size= 32000 bytes Compression= 5.24 *
*............................................................................*
*Br 102 :SofToFWSingleTcalData.fUniqueID : *
* | UInt_t fUniqueID[cbmout.SofToFW.SofToFWSingleTcalData_] *
*Entries : 2810612 : Total Size= 12312523 bytes File Size = 798450 *
*Baskets : 55 : Basket Size= 1684992 bytes Compression= 15.42 *
*............................................................................*
*Br 103 :SofToFWSingleTcalData.fBits : *
* | UInt_t fBits[cbmout.SofToFW.SofToFWSingleTcalData_] *
*Entries : 2810612 : Total Size= 12312287 bytes File Size = 798579 *
*Baskets : 55 : Basket Size= 1684992 bytes Compression= 15.42 *
*............................................................................*
*Br 104 :SofToFWSingleTcalData.fDetector : *
* | Int_t fDetector[cbmout.SofToFW.SofToFWSingleTcalData_] *
*Entries : 2810612 : Total Size= 12312523 bytes File Size = 949779 *
*Baskets : 55 : Basket Size= 1684992 bytes Compression= 12.96 *
*............................................................................*
*Br 105 :SofToFWSingleTcalData.fRawTofNs : *
* | Double_t fRawTofNs[cbmout.SofToFW.SofToFWSingleTcalData_] *
*Entries : 2810612 : Total Size= 13375377 bytes File Size = 2814216 *
*Baskets : 57 : Basket Size= 1767936 bytes Compression= 4.75 *
*............................................................................*
*Br 106 :SofToFWSingleTcalData.fRawPosNs : *
* | Double_t fRawPosNs[cbmout.SofToFW.SofToFWSingleTcalData_] *
*Entries : 2810612 : Total Size= 13375377 bytes File Size = 2531125 *
*Baskets : 57 : Basket Size= 1767936 bytes Compression= 5.28 *
*............................................................................*
*Br 107 :SofToFWSingleTcalData.fRawTimeNs : *
* | Double_t fRawTimeNs[cbmout.SofToFW.SofToFWSingleTcalData_] *
*Entries : 2810612 : Total Size= 13375438 bytes File Size = 2814518 *
*Baskets : 57 : Basket Size= 1767936 bytes Compression= 4.75 *
*............................................................................*
....
So the TTree has (amongs others) the TBranch " SofToFWSingleTcalData" and this branch has the leaf “SofToFWSingleTcalData.fRawTimeNs”.
Thanks in advance for your help!
Tobias
Try:
{
TH1D *h = new TH1D("h_raw_pos", "SofToFWSingleTcalData fRawTimeNs;time;#counts", 10000, -10., 10.);
TFile *f = TFile::Open("data_s444_main0038.root");
TTree *t; f->GetObject("evt", t);
gROOT->cd(); // where the "h_raw_pos" histogram resides
t->Project("h_raw_pos", "SofToFWSingleTcalData.fRawTimeNs");
TCanvas *c2 = new TCanvas("c2", "c2");
h->Draw(""); // e.g. "" or "HIST"
}
Hi Wile_E_Coyote,
I actually get an unfilled histogram with no entries…
Regards
Tobias
I guess we would need your ROOT file for inspection.
You could also try:
t->Scan("SofToFWSingleTcalData.fRawTimeNs");
t->Scan("fRawTimeNs"); // SofSciTcalData.fRawTimeNs
Hi Wile_E_Coyote,
here is actually a link for my ROOT file: https://www.dropbox.com/s/enhvvwcxbv4a05s/data_s444_main0038.root?dl=0
I also tried to scan both
SofToFWSingleTcalData.fRawTimeNs and fRawTimeNs but I don’t see anything strange there…
Regards
Tobias
I improved my example source code above so that it produces a nonempty “h_raw_pos” histogram.
@pcanal However, I’m afraid that this tree is complex enough that it often requires dictionaries for classes that it uses (i.e. you will not have luck with a simple “MakeClass ” generated code).
Hi Wile_E_Coyote,
thanks a lot, the code snipped:
gROOT->cd();
made the change! For me is still seems some magic …
Thanks again
Tobias
@pcanal The “evt->MakeClass();
” generates some bad variables (maybe one should fix the “MakeClass” and related methods so that they always produce proper names), e.g.:
// "space" inside
const Int_t kMaxcbmout_MWPC0 Cal_Mwpc0CalData = 36;
// "minus" inside
const Int_t kMaxcbmout_TofW-Hit_TofWHitData = 1;
// "spaces" and "dots" inside
UInt_t Mwpc0CalData_fUniqueID[kMaxcbmout_MWPC0 Cal_Mwpc0CalData]; //[cbmout.MWPC0 Cal.Mwpc0CalData_]
// "minuses" and "dots" inside
UInt_t TofWHitData_fUniqueID[kMaxcbmout_TofW-Hit_TofWHitData]; //[cbmout.TofW-Hit.TofWHitData_]
// "space" inside
TBranch *b_cbmout_MWPC0 Cal_Mwpc0CalData_; //!
// "minus" inside
TBranch *b_cbmout_TofW-Hit_TofWHitData_; //!
// "space" inside
fChain->SetBranchAddress("Mwpc0CalData", &Mwpc0CalData_, &b_cbmout_MWPC0 Cal_Mwpc0CalData_);
// "minus" inside
fChain->SetBranchAddress("TofWHitData", &TofWHitData_, &b_cbmout_TofW-Hit_TofWHitData_);
system
Closed
March 13, 2020, 5:25pm
11
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.