Dear all,
I want to get the phi information of all particles under Flow-trkPhi through the root file generated by CMS. There are two problems I don’t quite understand at present, because the first time I contact root,
- When I tried to run the phiread program I wrote, an error occurred:
Error in : Trying to dereference null pointer or trying to call routine taking non-null arguments
Execution of your code was aborted.
In file included from input_line_19:1:
/home/cy/cms_open_data_work/CMSSW_3_9_2_patch5/src/HiForest/HiForestProducer/phiread.cxx:14:4: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
t1->SetBranchAddress(“trkPhi”,&phi);
^~
- The second point is that I queried a lot of read examples, all of which created a Histogram to view the data. If I want to get a phi.data to store all the phi information, which parts of the program should I change? ?
Thank you so much!_
[HiForestAOD_DATA_FlowAnalysis.root|attachment] (21.6 KB)
[phiread.cxx|attachment](570 Bytes)
_ROOT Version:6.28
Platform: Not Provided
Compiler: Not Provided
New users seem to be unable to upload files…
phiread:
void phiread()
{
TFile *f = new TFile(“HiForestAOD_DATA_FlowAnalysis.root”);
TTree t1 = (TTree)f->Get(“Flow”);
Float_t phi;
t1->SetBranchAddress(“trkPhi”,&phi);
TH1F *hphi = new TH1F(“hphi”,“phi distribution”,100,-3,3);
Long64_t nentries = t1->GetEntries();
for (Long64_t i=0;i<nentries;i++) {
t1->GetEntry(i);
hphi->Fill(phi);
}
if (gROOT->IsBatch()) return;
new TBrowser();
t1->StartViewer();
}
For the root file, there are many trees (Demo->Flow->trkPhi), what I want to get should be all the information under trkPhi
Hi @ChongYe,
Welcome to the root forum!
In order to reproduce your problem I will need access to your root file, could you upload it on cernbox, for example, and send me an email with the link?
Cheers,
Marta
Hi @mczurylo
Thank you very much~
But I don’t have a cern account, and I try to log in with a google account and can’t upload files.
I was wondering if it could be sent directly to your email?
Sincerely thanks for your patience, instructions, and help.
Best regards.
Hi @ChongYe,
yes, you can try doing that (if the file is not too big). I have now realised that you are probably using the CMS open data, so you can also just point me to where you downloaded the file from.
Cheers,
Marta
Thanka a lot! It’s not large. But i dont’t know your email actually.
And for CMS, It’s here:github/CesarBernardes/AnalysisTools.
I using the [CMSSW_3_9_2_patch5] Hiforest for calculat.
Multi Thanks~
Hi @mczurylo
Thank you very much~
I have successfully written a c program that exports data by learning other people’s programs.
Still thank you very much for your patience and help~
PS: Below is my successful program.
Best regards.
void phiread()
{
TFile *f = new TFile("HiForestAOD_DATA_FlowAnalysis.root");
TTree *t1 = (TTree*)f->Get("demo/Flow");
int Ntrk;
float trkPhi[2000];
fstream fo;
fo.open("outPhi.dat",ios::out);
t1->SetBranchAddress("trkPhi",&trkPhi);
t1->SetBranchAddress("Ntrk",&Ntrk);
TH1F *hphi = new TH1F("hphi","phi distribution",100,-3,3);
t1->GetEntry(1);
for (int j=0; j< Ntrk; j++){
hphi->Fill(trkPhi[j]);
fo<<trkPhi[j]<<endl;
}
hphi->Write();
fo.close();
if (gROOT->IsBatch()) return;
new TBrowser();
t1->StartViewer();
}
1 Like