GSI Forum
GSI Helmholtzzentrum für Schwerionenforschung

Home » PANDA » PandaRoot » General » Reading a tree HELP!
Reading a tree HELP! Thu, 22 January 2015 15:31
 Mamen Messages: 55Registered: January 2009 Location: Mainz continuous participant From: *kph.uni-mainz.de
Hello everybody!

Sorry for asking stupid questions, but I am now facing a TTree with a new structure for me and I am not sure how to read it.
The output comes from an event generator, and I just want to compare my results with some plots given in a paper.
The event generator generates the process pe->p'e' gamma (where e can be a positron or an electron).
My objective would be to be able to plot for example (Phi_e - Phi_gamma) or M_e-gamma(invariant mass), but right now I have only access to Px, Py and Pz of all particles at once or cutting on the PdgCode.
I include my root file, so you can have a look to the exact structure.

I'm trying the following:

```int size;
//  int fPdgCode[10];

// double branchPz, branchPy;

// double ElectronPhi[5000], GammaPhi[5000];

// double PhiValue=0;

int entries=data->GetEntries();
cout<<entries<<endl;
int w=0;
int k=0;
for ( k=0; k<entries; k++)
{
data->GetEntry(k);
cout << k <<endl;
cout<< w<< endl;
for(w=0; w<size; w++)
{
cout<< "    "  <<w << endl;
// 	//   	if (branchCode[w]==11)
// {
// // 	    ElectronPhi[k]=atan(branchPy[w]/branchPz[w]);
// 	  }
// // 	if(branchCode[w]==22)
// // 	  {
// // 	    GammaPhi[k]=atan(branchPy[w]/branchPz[w]);
// // 	  }
}
//     Delta_phi->Fill(ElectronPhi[k]-GammaPhi[k]);
}
```

Many lines are commented out because I get "break segmentation violation" if they are not commented. I actually don't know how to do the loop over the particles in each event. Any idea?
The next step for me would be to get the PidCode of each particle, to be able to distinguish between electron_phi and gamma_phi, but when I uncomment just the lines to create the branch to PdgCode I get the break segmentation violation. I also tried addressing to an array or not, i.e. "int fPdgCode[10];" or "int fPdgCode;".

Any help there?
Thanks a lot in advance!!! Any comment will be welcomed!!!

Cheers,
Mamen
Re: Reading a tree HELP! [message #17784 is a reply to message #17783] Thu, 22 January 2015 15:48
 asanchez Messages: 350Registered: March 2006 first-grade participant From: *kph.uni-mainz.de
Hi Mamaen,
here you are some lines as example how to get read of
the TParticle Info in a TTree .

TFile *tf1 = new TFile("the file");
TTree *data = (TTree*)tf1->Get("data");
TClonesArray* hit_array=new TClonesArray("TParticle",100);

for (Int_t j=0; j<data->GetEntries(); j++)
{
// if ((j)%100000==0)cout <<"evt: "<<j<<endl;

data->GetEntry(j); // Loop over particles in TClonesArray

for (Int_t iPart=0; iPart < nParts; iPart++) {

TParticle* part = (TParticle*) hit_array->At(iPart);
Int_t pdgType = part->GetPdgCode();

//you can use the member function of TPArticle to get the kinematic information

TLorentzVector lv1;

part->Momentum(lv1);

TVector3 v1;

v1= lv1.Vect();

// Total momentum

Double_t P;

P = part->P();

// theta

Double_t theta;

theta = part->Theta();

}

}
Re: Reading a tree HELP! [message #17785 is a reply to message #17783] Thu, 22 January 2015 15:54
 Ralf Kliemt Messages: 507Registered: May 2007 Location: GSI, Darmstadt first-grade participant From: 106.2.197*
Hi Mamen,

TTree has the opportunity to directly plot distributions from either the root shell or the TreeViewer.

Here an example:

```TFile* file0=new TFile("myfile.root","READ");
TTree* tree = (TTree*)file0->Get("myBranchName");
int nEntries;
nEntries = tree->Draw("myVariable","myCutVariable>3.5");
```

You can print several expressions and opt for combined (use &&) cuts. See
https://root.cern.ch/root/htmldoc/TTree.html#TTree:Draw@2
for more details.

Cheers
Ralf
Re: Reading a tree HELP! [message #17786 is a reply to message #17785] Thu, 22 January 2015 16:10
 Mamen Messages: 55Registered: January 2009 Location: Mainz continuous participant From: *kph.uni-mainz.de
Thank you Ralf,

I already knew this way, unfortunately I need to plot a combination of different variables, but for each of them I need to apply different cuts, so this way is not usable for this particular case.
I mean, it would be something like:

data->Draw("atan(Py/Pz) - atan(Py/Pz)", "cuts"...) for which the first Py and Pz needs a cut on PdgCode==11 and the second pair a cut on PdgCode==22...

If this is possible, could you give an explicit example?, please.

Cheers!
Mamen
Re: Reading a tree HELP! [message #17788 is a reply to message #17784] Thu, 22 January 2015 18:08
 Mamen Messages: 55Registered: January 2009 Location: Mainz continuous participant From: *kph.uni-mainz.de
Thank you, Alicia!

I tried and your solution works

Cheers!
Mamen

Re: Reading a tree HELP! [message #17789 is a reply to message #17788] Fri, 23 January 2015 00:13
 asanchez Messages: 350Registered: March 2006 first-grade participant From: *188.097.pools.vodafone-ip.de
Hi Mamen,
me congratula

cheers Alicia
Re: Reading a tree HELP! [message #17795 is a reply to message #17786] Fri, 23 January 2015 09:40
 Ralf Kliemt Messages: 507Registered: May 2007 Location: GSI, Darmstadt first-grade participant From: *gsi.de
Hi Mamen,

You're right, when you have an array of particles from one event it's tricky. I believe this is not possible to formulate in a TFormula style since you need to refer to one element of the TClonesArray for cutting. The explicit loop by Alicia is the way to , go, then.

Cheers
Ralf
 Previous Topic: Howto for eventdisplay Next Topic: simulation output; sge scripts in macro/prod
Goto Forum:

Current Time: Sat Jul 13 07:34:17 CEST 2024

Total time taken to generate the page: 0.00760 seconds