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
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)
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(" ");
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
Load the Branches ScintParticleKinEn and ScintOutParticleKinEn respectively from the TTree B1Scintparticles and B1ScintOutparticles
Load the Branches ScintParticleTrackEvenID and ScintOutParticleTrackEventID respectively from the TTree B1Scintparticles and B1ScintOutparticles
Associate the entries of the two TTree for which ScintParticleTrackEvenID == ScintOutParticleTrackEventID
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.
Apply the TCut using the condition that ScintParticleKinEn- ScintOutParticleKinEn >1
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:
The first one is: if(NextVol && ThisVol->GetName()=="World" && NextVol->GetName()=="PlasticScintillator") {
…
…
…
}
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);
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.
Error in <TTreeFormula::Compile>: Bad numerical expression : "ScintOutParticleTrackEventID"
Error in <TTreeFormula::Compile>: Bad numerical expression : "ScintOutParticleParentID"
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)
@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.
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.
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.