Difference between branches

Hello, I’ve this root file WeTransfer - Send Large Files & Share Photos Online - Up to 2GB Free (it is an example with few events) produced by geant

In the TTree B1Scintparticles I store information about particles entering in the scintillator. In the TTree B1ScintOutParticles I store information about particles outgoing the scintillatore. To know which particle is entering or outgoing the scintillator I used two parameters of geant, the trackID and the eventID then I defined a quantity

trackeventID= trackID+1000*eventID

and I stored this quantity both in the TTree related to the entering and outgoing. The branches are called respectively ScintParticleTrackEvenID and ScintOutParticleTrackEvenID.

Moreover I saved the kineti energy both of entering and outgoing particles. The branches are respectively ScintParticleKinEn and ScintOutParticleKinEn.

Now I’ve to make a plot of ScintParticleKinEn- ScintOutParticleKinEn
with the condition
ScintParticleTrackEvenID==ScintOutParticleTrackEvenID
and with the cut that

ScintParticleKinEn- ScintOutParticleKinEn >1MeV

I was trying to write the macro, starting from another macro using TTree::AddFriend as suggested by @dastudillo in this topic Plotting difference between two branches of two ttree - #2 by dastudillo but

  1. I don’t know how to use the condition that the plot must not be made entry by entry, but it must looks for enetries for wich ScintParticleTrackEvenID==ScintOutParticleTrackEvenID (because, for example a particle A in the first TTree can be stored in the entry 0, but in the second TTree can be stored in the entry 10…then I must apply this condition)

  2. I get error using the macro

Warning in <TCanvas::Constructor>: Deleting canvas with same name: c01
Error in <TTreeFormula::Compile>:  Bad numerical expression : "B1ScintOutparticles.ScintOutParticleKinEn"
Info in <TSelectorDraw::AbortProcess>: Variable compilation failed: {B1Scintparticles.ScintParticleKinEn-B1ScintOutparticles.ScintOutParticleKinEn,B1Scintparticles.ScintParticleKinEn-B1ScintOutparticles.ScintOutParticleKinEn >1}
#0  0x00007fd00965d46c in waitpid () from /lib64/libc.so.6
#1  0x00007fd0095daf62 in do_system () from /lib64/libc.so.6
#2  0x00007fd00a6f0654 in TUnixSystem::StackTrace() () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.24.00/x86_64-centos7-gcc48-opt/lib/libCore.so.6.24
#3  0x00007fd004dab958 in cling::MultiplexInterpreterCallbacks::PrintStackTrace() () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.24.00/x86_64-centos7-gcc48-opt/lib/libCling.so
#4  0x00007fd004da402e in cling_runtime_internal_throwIfInvalidPointer () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.24.00/x86_64-centos7-gcc48-opt/lib/libCling.so
#5  0x00007fd00264f591 in ?? ()
#6  0x00007fff7645dd70 in ?? ()
#7  0x0000000000000000 in ?? ()
Error in <HandleInterpreterException>: 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_34:1:
/data_collamaf/DataFausto/Muon_Collider/III_anno/Tesi/Simulazioni_per_tesi/MAINZ_R=x_gaussian10um_13keV_1urad/Particles_scintillator/W_r=1cm_s=1mm_steel_R=30cm_s=1mm_edep_scint/deltakinene.cpp:44:13: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
            t->GetHistogram()->SetTitle(" ");

deltakinene.cpp (2.7 KB)

maybe @couet or @dastudillo ?


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


It seems you are redefining a canvas with the same name.

hello @couet…no…that warning is just because I runned the macro 2 times without closing and opening again ROOT!

This is the error

root [0] .x deltakinene.cpp
TFile**         B1/B1-build/B1.root
 TFile*         B1/B1-build/B1.root
  KEY: TTree    B1EventVariables;1      Relesed_energy
  KEY: TTree    B1Exitparticles;1       Exit_targets
  KEY: TTree    B1Enteringparticles;1   Entering_targets
  KEY: TTree    B1Enterinregengparticles;1      Entering_regen
  KEY: TTree    B1EnterinPhotonregengparticles;1        Entering_photon_regen
  KEY: TTree    B1Exitregengparticles;1 Exit_regen
  KEY: TTree    B1Scintparticles;1      Ent_scint
  KEY: TTree    B1Dummyparticles;1      Ent_Dummy
  KEY: TTree    B1ParticleNotInteracting;1      Part_not_inter
  KEY: TTree    B1ScintSecCreated;1     Sec_crated
  KEY: TTree    B1ScintOutparticles;1   Ent_scint
Error in <TTreeFormula::Compile>:  Bad numerical expression : "B1ScintOutparticles.ScintOutParticleKinEn"
Info in <TSelectorDraw::AbortProcess>: Variable compilation failed: {B1Scintparticles.ScintParticleKinEn-B1ScintOutparticles.ScintOutParticleKinEn,B1Scintparticles.ScintParticleKinEn-B1ScintOutparticles.ScintOutParticleKinEn >1}
#0  0x00007fc6682c746c in waitpid () from /lib64/libc.so.6
#1  0x00007fc668244f62 in do_system () from /lib64/libc.so.6
#2  0x00007fc66935a654 in TUnixSystem::StackTrace() () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.24.00/x86_64-centos7-gcc48-opt/lib/libCore.so.6.24
#3  0x00007fc663a15958 in cling::MultiplexInterpreterCallbacks::PrintStackTrace() () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.24.00/x86_64-centos7-gcc48-opt/lib/libCling.so
#4  0x00007fc663a0e02e in cling_runtime_internal_throwIfInvalidPointer () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.24.00/x86_64-centos7-gcc48-opt/lib/libCling.so
#5  0x00007fc6612d5591 in ?? ()
#6  0x0000000000000000 in ?? ()
Error in <HandleInterpreterException>: 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_8:1:
/data_collamaf/DataFausto/Muon_Collider/III_anno/Tesi/Simulazioni_per_tesi/MAINZ_R=x_gaussian10um_13keV_1urad/Particles_scintillator/W_r=1cm_s=1mm_steel_R=30cm_s=1mm_edep_scint/deltakinene.cpp:44:13: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
            t->GetHistogram()->SetTitle(" ");

and I think that it is related to the code
B1Scintparticles.ScintParticleKinEn-B1ScintOutparticles.ScintOutParticleKinEn

As I sed I’ve

  1. Load the Branches ScintParticleKinEn and ScintOutParticleKinEn respectively from the TTree B1Scintparticles and B1ScintOutparticles
  2. Load the Branches ScintParticleTrackEvenID and ScintOutParticleTrackEventID respectively from the TTree B1Scintparticles and B1ScintOutparticles
  3. Associate the entries of the two TTree for which ScintParticleTrackEvenID == ScintOutParticleTrackEventID
  4. Calculate the difference of the kinetic energy ScintParticleKinEn- ScintOutParticleKinEn with the condition that entries must have the branches ParticleTrackEvenID == ScintOutParticleTrackEventID. For example if the particles A is stored in the entry 0 in the first TTree and in the entry 10 in the second TTree, the entry 0 and the enrtry 10 of the second one will have ParticleTrackEvenID == ScintOutParticleTrackEventID. Then I’ve to calculate ScintParticleKinEn- ScintOutParticleKinEn using the entry 0 of the first TTree and the the entry 10 of the second one.
  5. Apply the TCut using the condition that ScintParticleKinEn- ScintOutParticleKinEn >1

Is it possible?

hello @couet, do you think is it possible to do what I need?

as it is a TTree related question, I think @pcanal will know better than me.

B1ScintOutparticles and B1Scintparticles are names of trees; you cannot use them in expressions for one tree. You are trying to merge the entries of two trees and that means you cannot operate on any single one, as any of them might have extra entries.

If I were you I would fix the output to not create multiple trees but one with additional branches. Would that be an option? That way you don’t need to correlate entries across multiple trees.

Thank you @couet…then I hope @pcanal knows how to do it

Thank you @Axel , I can save both entering and exiting particles in a single TTree, but I don’t think to solve, because they are two different cases…
I mean to select particles entering in the scintillator and particles exiting from it I need two filters:

  1. The first one is:
    if(NextVol && ThisVol->GetName()=="World" && NextVol->GetName()=="PlasticScintillator") {


}

  1. The second one is:
    if(NextVol && ThisVol->GetName()=="PlasticScintillator" && NextVol->GetName()=="World") {



    }

Then, even if I save both entering and exiting particles particles in the same TTree, entering and exiting particles will not be save in the same entry. The only way to know that I’m selecting a specific particle is to look the Track ID, the Event ID and Parent ID, because if two particles have the same Track ID, the same Event ID and the same Parent ID it means they are the same particle!

Now I’ve to make a plot of ScintParticleKinEn- ScintOutParticleKinEn with the condition
ScintParticleTrackEvenID==ScintOutParticleTrackEvenID
and with the cut that

If you use this as a ‘condition’ or ‘cut’, it will filter away all then entry except for those that are ‘perfectly’ aligned (i.e. this would basically happens only in the case where for the 2 TTree the entries (in term of track and event id) are exactly in the same order).

What you might be needing is actually a “join” (per se). In TTree, this is done by creating a index on the friend tree:

friendtree->BuildIndex("trackID","eventID"); // or friendtree->BuildIndex("trackeventID");
maintree->AddFriend(friendtree);

hello @pcanal I’m note sure to understand…
I wrote:

	TTree *t=0;
		TTree *te=0;
            fin->GetObject("B1Scintparticles",t);
            t->SetScanField(0);
            fin->GetObject("B1ScintOutparticles",te);
            te->SetScanField(0);
            t->BuildIndex("ScintOutParticleTrackEventID","ScintOutParticleParentID"); 
            t->AddFriend(te);

But now, how do I select entries for which ScintOutParticleTrackEventID==ScintParticleTrackEventID and ScintOutParticleParentID==ScintParticleParentID

This is the updated macro

deltakinene.cpp (2.7 KB)

You need to build the index on the friend:

te->BuildIndex("ScintOutParticleTrackEventID","ScintOutParticleParentID"); 
t->AddFriend(te);

This is the order because the operation needed by the join are (implicitly done for you):

(1) read 't' / main-tree value for the branch/column "ScintOutParticleTrackEventID","ScintOutParticleParentID"
(2) lookup in the index the friend entry number corresponding to these values
(3) load that entry in the friend.

Hello @pcanal I fixed the line

te->BuildIndex("ScintOutParticleTrackEventID","ScintOutParticleParentID");

I runned the macro and I got these errors:

Error in <TTreeFormula::Compile>:  Bad numerical expression : "ScintOutParticleTrackEventID"
Error in <TTreeFormula::Compile>:  Bad numerical expression : "ScintOutParticleParentID"

anyway it makes a plot

This is the plot

but it can’t be the right plot …because if a particle entering in the scintillato has kinetic energy Ein, when the particle exits the scintillator its kinetic energy must be Eout<=Ein

Given that I plotted (or at least I wanted to plot)

Scintparticles.ScintParticleKinEn-B1ScintOutparticles.ScintOutParticleKinEn

this difference must be always >=0 …on the contray, in the plot there are negative values!

Here the macro

deltakinene.cpp (2.7 KB)

Those error indicates this 2 branches do not exist in the friend tree…

Hello @pcanal the branches exist…here the print of the TTree


root [0] TFile *fin = TFile::Open("B1.root");
root [1] fin->ls();
TFile**         B1.root
 TFile*         B1.root
  KEY: TTree    B1EventVariables;1      Relesed_energy
  KEY: TTree    B1Exitparticles;1       Exit_targets
  KEY: TTree    B1Enteringparticles;1   Entering_targets
  KEY: TTree    B1Enterinregengparticles;1      Entering_regen
  KEY: TTree    B1EnterinPhotonregengparticles;1        Entering_photon_regen
  KEY: TTree    B1Exitregengparticles;1 Exit_regen
  KEY: TTree    B1Scintparticles;1      Ent_scint
  KEY: TTree    B1Dummyparticles;1      Ent_Dummy
  KEY: TTree    B1ParticleNotInteracting;1      Part_not_inter
  KEY: TTree    B1ScintSecCreated;1     Sec_crated
  KEY: TTree    B1ScintOutparticles;1   Ent_scint
root [2] TTree *t=0;
root [3]  fin->GetObject("B1ScintOutparticles",t);
root [4] t->Print();
******************************************************************************
*Tree    :B1ScintOutparticles: Ent_scint
*
*Entries :   142172 : Total =        35941361 bytes  File  Size =   22539116 *
*        :          : Tree compression factor =   1.59                       *
******************************************************************************
*Br    0 :ScintOutParticleID : Double_t B1ScintOutparticles                  *
*Entries :   142172 : Total  Size=    1711316 bytes  File Size  =     239221 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   7.15     *
*............................................................................*
*Br    1 :ScintOutParticleKinEn : Double_t B1ScintOutparticles               *
*Entries :   142172 : Total  Size=    1711436 bytes  File Size  =    1083011 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   1.58     *
*............................................................................*
*Br    2 :ScintOutParticleMomDir.x : Double_t B1ScintOutparticles            *
*Entries :   142172 : Total  Size=    1711556 bytes  File Size  =    1273158 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   1.34     *
*............................................................................*
*Br    3 :ScintOutParticleMomDir.y : Double_t B1ScintOutparticles            *
*Entries :   142172 : Total  Size=    1711556 bytes  File Size  =    1274020 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   1.34     *
*............................................................................*
*Br    4 :ScintOutParticleMomDir.z : Double_t B1ScintOutparticles            *
*Entries :   142172 : Total  Size=    1711556 bytes  File Size  =    1255171 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   1.36     *
*............................................................................*
*Br    5 :ScintOutParticleVert.x : Double_t B1ScintOutparticles              *
*Entries :   142172 : Total  Size=    1711476 bytes  File Size  =    1274744 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   1.34     *
*............................................................................*
*Br    6 :ScintOutParticleVert.y : Double_t B1ScintOutparticles              *
*Entries :   142172 : Total  Size=    1711476 bytes  File Size  =    1275058 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   1.34     *
*............................................................................*
*Br    7 :ScintOutParticleVert.z : Double_t B1ScintOutparticles              *
*Entries :   142172 : Total  Size=    1711476 bytes  File Size  =    1275749 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   1.34     *
*............................................................................*
*Br    8 :ScintOutParticleTotMom : Double_t B1ScintOutparticles              *
*Entries :   142172 : Total  Size=    1711476 bytes  File Size  =    1083958 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   1.58     *
*............................................................................*
*Br    9 :ScintOutDirection.x : Double_t B1ScintOutparticles                 *
*Entries :   142172 : Total  Size=    1711356 bytes  File Size  =    1262360 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   1.35     *
*............................................................................*
*Br   10 :ScintOutDirection.y : Double_t B1ScintOutparticles                 *
*Entries :   142172 : Total  Size=    1711356 bytes  File Size  =    1268005 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   1.35     *
*............................................................................*
*Br   11 :ScintOutDirection.z : Double_t B1ScintOutparticles                 *
*Entries :   142172 : Total  Size=    1711356 bytes  File Size  =    1221249 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   1.40     *
*............................................................................*
*Br   12 :ScintOutParticleMom.x : Double_t B1ScintOutparticles               *
*Entries :   142172 : Total  Size=    1711436 bytes  File Size  =    1272806 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   1.34     *
*............................................................................*
*Br   13 :ScintOutParticleMom.y : Double_t B1ScintOutparticles               *
*Entries :   142172 : Total  Size=    1711436 bytes  File Size  =    1272439 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   1.34     *
*............................................................................*
*Br   14 :ScintOutParticleMom.z : Double_t B1ScintOutparticles               *
*Entries :   142172 : Total  Size=    1711436 bytes  File Size  =    1274358 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   1.34     *
*............................................................................*
*Br   15 :ScintOutParticleAng.x : Double_t B1ScintOutparticles               *
*Entries :   142172 : Total  Size=    1711436 bytes  File Size  =    1271534 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   1.34     *
*............................................................................*
*Br   16 :ScintOutParticleAng.y : Double_t B1ScintOutparticles               *
*Entries :   142172 : Total  Size=    1711436 bytes  File Size  =    1272534 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   1.34     *
*............................................................................*
*Br   17 :ScintOutParticleTrackID : Double_t B1ScintOutparticles             *
*Entries :   142172 : Total  Size=    1711516 bytes  File Size  =     398949 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   4.29     *
*............................................................................*
*Br   18 :ScintOutParticleEventID : Double_t B1ScintOutparticles             *
*Entries :   142172 : Total  Size=    1711516 bytes  File Size  =     719175 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   2.38     *
*............................................................................*
*Br   19 :ScintOutParticleParentID : Double_t B1ScintOutparticles            *
*Entries :   142172 : Total  Size=    1711556 bytes  File Size  =     405317 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   4.22     *
*............................................................................*
*Br   20 :ScintOutParticleTrackEventID : Double_t B1ScintOutparticles        *
*Entries :   142172 : Total  Size=    1711716 bytes  File Size  =     858084 *
*Baskets :       37 : Basket Size=      32000 bytes  Compression=   1.99     *
*............................................................................*
root [5]

then you see…they are the number 19 and number 20!

Indeed, this is the code in GEANT4 to create the TTree

//ntupla id=10	Particles outgoing the scintillator
  analysisManager->CreateNtuple("B1ScintOutparticles", "Ent_scint");
  analysisManager->CreateNtupleDColumn("ScintOutParticleID");
  analysisManager->CreateNtupleDColumn("ScintOutParticleKinEn");
  analysisManager->CreateNtupleDColumn("ScintOutParticleMomDir.x");
  analysisManager->CreateNtupleDColumn("ScintOutParticleMomDir.y");
  analysisManager->CreateNtupleDColumn("ScintOutParticleMomDir.z");
  analysisManager->CreateNtupleDColumn("ScintOutParticleVert.x");
  analysisManager->CreateNtupleDColumn("ScintOutParticleVert.y");
  analysisManager->CreateNtupleDColumn("ScintOutParticleVert.z");
  analysisManager->CreateNtupleDColumn("ScintOutParticleTotMom");
  analysisManager->CreateNtupleDColumn("ScintOutDirection.x");
  analysisManager->CreateNtupleDColumn("ScintOutDirection.y");
  analysisManager->CreateNtupleDColumn("ScintOutDirection.z");
  analysisManager->CreateNtupleDColumn("ScintOutParticleMom.x");
  analysisManager->CreateNtupleDColumn("ScintOutParticleMom.y");
  analysisManager->CreateNtupleDColumn("ScintOutParticleMom.z");
  analysisManager->CreateNtupleDColumn("ScintOutParticleAng.x");
  analysisManager->CreateNtupleDColumn("ScintOutParticleAng.y");
  analysisManager->CreateNtupleDColumn("ScintOutParticleTrackID");
  analysisManager->CreateNtupleDColumn("ScintOutParticleEventID");
  analysisManager->CreateNtupleDColumn("ScintOutParticleParentID");
  analysisManager->CreateNtupleDColumn("ScintOutParticleTrackEventID");
  analysisManager->FinishNtuple();

@pcanal Can the problem be related to the fact that the “branch name” is different from the “leaf name” (and, from the “t->Print();” output, it seems that all leaves have the same “B1ScintOutparticles” name, which is equal to the “tree name”).

BTW. @faca87 The “dots” in branch names can be devastating, too. You’d better replace them with a “_” character.

Hello @Wile_E_Coyote

Thank you…I will replace the dot by the underscore. Anyway, in this case you know…this isn’t the error reason, because I don’t use in this plot branches with the dot.

What do you mean by this question for @pcanal ?

You might need to use:

te->BuildIndex("ScintOutParticleTrackEventID.B1ScintOutparticles",
               "ScintOutParticleParentID.B1ScintOutparticles");

Hello @pcanal
by substituting the line
te->BuildIndex("ScintOutParticleTrackEventID","ScintOutParticleParentID");

by

te->BuildIndex("ScintOutParticleTrackEventID.B1ScintOutparticles","ScintOutParticleParentID.B1ScintOutparticles");

I get the errors

root [0] .x deltakinene.cpp
TFile**         B1/B1-build/B1.root
 TFile*         B1/B1-build/B1.root
  KEY: TTree    B1EventVariables;1      Relesed_energy
  KEY: TTree    B1Exitparticles;1       Exit_targets
  KEY: TTree    B1Enteringparticles;1   Entering_targets
  KEY: TTree    B1Enterinregengparticles;1      Entering_regen
  KEY: TTree    B1EnterinPhotonregengparticles;1        Entering_photon_regen
  KEY: TTree    B1Exitregengparticles;1 Exit_regen
  KEY: TTree    B1Scintparticles;1      Ent_scint
  KEY: TTree    B1Dummyparticles;1      Ent_Dummy
  KEY: TTree    B1ParticleNotInteracting;1      Part_not_inter
  KEY: TTree    B1ScintSecCreated;1     Sec_crated
  KEY: TTree    B1ScintOutparticles;1   Ent_scint
Error in <TTreeFormula::ParseWithLeaf>: Found a numerical leaf but the name has trailing characters: "B1ScintOutparticles"
Error in <TTreeFormula::Compile>:  Bad numerical expression : "ScintOutParticleTrackEventID.B1ScintOutparticles"
Error in <TTreeFormula::ParseWithLeaf>: Found a numerical leaf but the name has trailing characters: "B1ScintOutparticles"
Error in <TTreeFormula::Compile>:  Bad numerical expression : "ScintOutParticleParentID.B1ScintOutparticles"
Error in <TTreeIndex::TreeIndex>: Cannot build the index with major=ScintOutParticleTrackEventID.B1ScintOutparticles, minor=ScintOutParticleParentID.B1ScintOutparticles
Info in <TCanvas::Print>: png file DeltaKinEne.png has been created
root [1]

It creates the plot (same that using te->BuildIndex("ScintOutParticleTrackEventID","ScintOutParticleParentID");)
but as I explained, this plot is impossible because DeltaKinEne must be >=0.

Try:

// initialize the "t" pointer and then ...
TBranch *b = t->GetBranch("ScintOutParticleTrackEventID");
b->ls();
std::cout << "->" << b->GetName() << "<-\n";
std::cout << "->" << b->GetTitle() << "<-\n";
std::cout << "->" << b->GetFullName() << "<-\n";
TLeaf *l = (TLeaf*)b->GetListOfLeaves()->At(0);
l->ls();
std::cout << "->" << l->GetName() << "<-\n";
std::cout << "->" << l->GetTitle() << "<-\n";
std::cout << "->" << l->GetFullName() << "<-\n";

Hello @Wile_E_Coyote , I added your code in the macro:

TTree *t=0;
		TTree *te=0;
            fin->GetObject("B1Scintparticles",t);
            t->SetScanField(0);
            fin->GetObject("B1ScintOutparticles",te);
            te->SetScanField(0);
            TBranch *b = te->GetBranch("ScintOutParticleTrackEventID");
			b->ls();
			std::cout << "->" << b->GetName() << "<-\n";
			std::cout << "->" << b->GetTitle() << "<-\n";
			std::cout << "->" << b->GetFullName() << "<-\n";
			TLeaf *l = (TLeaf*)b->GetListOfLeaves()->At(0);
			l->ls();
			std::cout << "->" << l->GetName() << "<-\n";
			std::cout << "->" << l->GetTitle() << "<-\n";
			std::cout << "->" << l->GetFullName() << "<-\n";
            te->BuildIndex("ScintOutParticleTrackEventID.B1ScintOutparticles","ScintOutParticleParentID.B1ScintOutparticles");
            t->AddFriend(te);

but I get these errorrs

root [1] .x deltakinene.cpp
TFile**         B1/B1-build/B1.root
 TFile*         B1/B1-build/B1.root
  KEY: TTree    B1EventVariables;1      Relesed_energy
  KEY: TTree    B1Exitparticles;1       Exit_targets
  KEY: TTree    B1Enteringparticles;1   Entering_targets
  KEY: TTree    B1Enterinregengparticles;1      Entering_regen
  KEY: TTree    B1EnterinPhotonregengparticles;1        Entering_photon_regen
  KEY: TTree    B1Exitregengparticles;1 Exit_regen
  KEY: TTree    B1Scintparticles;1      Ent_scint
  KEY: TTree    B1Dummyparticles;1      Ent_Dummy
  KEY: TTree    B1ParticleNotInteracting;1      Part_not_inter
  KEY: TTree    B1ScintSecCreated;1     Sec_crated
  KEY: TTree    B1ScintOutparticles;1   Ent_scint
OBJ: TBranch    ScintOutParticleTrackEventID    B1ScintOutparticles : 0 at: 0x31f53e0
->ScintOutParticleTrackEventID<-
->B1ScintOutparticles<-
->ScintOutParticleTrackEventID<-
OBJ: TLeafD     ScintOutParticleTrackEventID    ScintOutParticleTrackEventID : 0 at: 0x345f200
->ScintOutParticleTrackEventID<-
->ScintOutParticleTrackEventID<-
->ScintOutParticleTrackEventID.ScintOutParticleTrackEventID<-
Error in <TTreeFormula::ParseWithLeaf>: Found a numerical leaf but the name has trailing characters: "B1ScintOutparticles"
Error in <TTreeFormula::Compile>:  Bad numerical expression : "ScintOutParticleTrackEventID.B1ScintOutparticles"
Error in <TTreeFormula::ParseWithLeaf>: Found a numerical leaf but the name has trailing characters: "B1ScintOutparticles"
Error in <TTreeFormula::Compile>:  Bad numerical expression : "ScintOutParticleParentID.B1ScintOutparticles"
Error in <TTreeIndex::TreeIndex>: Cannot build the index with major=ScintOutParticleTrackEventID.B1ScintOutparticles, minor=ScintOutParticleParentID.B1ScintOutparticles
Info in <TCanvas::Print>: png file DeltaKinEne.png has been created
root [2]

deltakinene.cpp (3.2 KB)

Try:

te->BuildIndex("ScintOutParticleTrackEventID.ScintOutParticleTrackEventID",
               "ScintOutParticleParentID.ScintOutParticleParentID");