# Extra the data from CMS\_open\_data.root

**URL:** <https://root-forum.cern.ch/t/extra-the-data-from-cms-open-data-root/55444>\
**Category:** Newbie\
**Tags:** tree, root\
**Created:** [June 26, 2023, 10:17pm UTC](https://root-forum.cern.ch/t/extra-the-data-from-cms-open-data-root/55444 "2023-06-26T22:17:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChongYe](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@ChongYe](https://root-forum.cern.ch/u/ChongYe)\
**Post date:** [June 26, 2023, 10:17pm UTC](https://root-forum.cern.ch/t/extra-the-data-from-cms-open-data-root/55444/1 "2023-06-26T22:17:17Z")

</div>

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,

1. 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);  
^~
2. 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

* * *

---

<div class="post-metadata">

**Author:** ![ChongYe](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@ChongYe](https://root-forum.cern.ch/u/ChongYe)\
**Post date:** [June 26, 2023, 10:21pm UTC](https://root-forum.cern.ch/t/extra-the-data-from-cms-open-data-root/55444/2 "2023-06-26T22:21:14Z")

</div>

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();  
}

---

<div class="post-metadata">

**Author:** ![ChongYe](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@ChongYe](https://root-forum.cern.ch/u/ChongYe)\
**Post date:** [June 26, 2023, 10:22pm UTC](https://root-forum.cern.ch/t/extra-the-data-from-cms-open-data-root/55444/3 "2023-06-26T22:22:44Z")

</div>

For the root file, there are many trees (Demo-\>Flow-\>trkPhi), what I want to get should be all the information under trkPhi

---

<div class="post-metadata">

**Author:** ![mczurylo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mczurylo/32/33269_2.png) [@mczurylo](https://root-forum.cern.ch/u/mczurylo)\
**Post date:** [June 29, 2023, 1:06pm UTC](https://root-forum.cern.ch/t/extra-the-data-from-cms-open-data-root/55444/5 "2023-06-29T13:06:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ChongYe](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@ChongYe](https://root-forum.cern.ch/u/ChongYe)\
**Post date:** [June 29, 2023, 4:02pm UTC](https://root-forum.cern.ch/t/extra-the-data-from-cms-open-data-root/55444/6 "2023-06-29T16:02:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mczurylo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mczurylo/32/33269_2.png) [@mczurylo](https://root-forum.cern.ch/u/mczurylo)\
**Post date:** [June 30, 2023, 7:41am UTC](https://root-forum.cern.ch/t/extra-the-data-from-cms-open-data-root/55444/7 "2023-06-30T07:41:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ChongYe](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@ChongYe](https://root-forum.cern.ch/u/ChongYe)\
**Post date:** [June 30, 2023, 2:12pm UTC](https://root-forum.cern.ch/t/extra-the-data-from-cms-open-data-root/55444/9 "2023-06-30T14:12:56Z")

</div>

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~

---

<div class="post-metadata">

**Author:** ![ChongYe](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@ChongYe](https://root-forum.cern.ch/u/ChongYe)\
**Post date:** [July 4, 2023, 6:06pm UTC](https://root-forum.cern.ch/t/extra-the-data-from-cms-open-data-root/55444/10 "2023-07-04T18:06:24Z")

</div>

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.

```c++
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();
}

```
